source: ntrip/trunk/BNS/bnswindow.cpp@ 950

Last change on this file since 950 was 917, checked in by mervart, 16 years ago

* empty log message *

File size: 14.4 KB
Line 
1
2/* -------------------------------------------------------------------------
3 * BKG NTRIP Server
4 * -------------------------------------------------------------------------
5 *
6 * Class: bnsWindow
7 *
8 * Purpose: This class implements the main application window.
9 *
10 * Author: L. Mervart
11 *
12 * Created: 29-Mar-2008
13 *
14 * Changes:
15 *
16 * -----------------------------------------------------------------------*/
17
18#include <iostream>
19
20#include "bnswindow.h"
21#include "bnshlpdlg.h"
22
23using namespace std;
24
25// About Dialog - Constructor
26////////////////////////////////////////////////////////////////////////////
27bnsAboutDlg::bnsAboutDlg(QWidget* parent) :
28 QDialog(parent) {
29
30 QTextBrowser* tb = new QTextBrowser;
31 QUrl url; url.setPath(":bnsabout.html");
32 tb->setSource(url);
33 tb->setReadOnly(true);
34
35 int ww = QFontMetrics(font()).width('w');
36 QPushButton* _closeButton = new QPushButton("Close");
37 _closeButton->setMaximumWidth(10*ww);
38 connect(_closeButton, SIGNAL(clicked()), this, SLOT(close()));
39
40 QGridLayout* dlgLayout = new QGridLayout();
41 QLabel* img = new QLabel();
42 img->setPixmap(QPixmap(":ntrip-logo.png"));
43 dlgLayout->addWidget(img, 0,0);
44 dlgLayout->addWidget(new QLabel("BKG NTRIP Server (BNS) Version 1.0"), 0,1);
45 dlgLayout->addWidget(tb,1,0,1,2);
46 dlgLayout->addWidget(_closeButton,2,1,Qt::AlignRight);
47
48 setLayout(dlgLayout);
49 resize(60*ww, 60*ww);
50 show();
51}
52
53// About Dialog - Destructor
54////////////////////////////////////////////////////////////////////////////
55bnsAboutDlg::~bnsAboutDlg() {
56};
57
58// Constructor
59////////////////////////////////////////////////////////////////////////////
60bnsWindow::bnsWindow() {
61
62 _bns = 0;
63
64 QSettings settings;
65
66 QString fontString = settings.value("font").toString();
67 if ( !fontString.isEmpty() ) {
68 QFont newFont;
69 if (newFont.fromString(fontString)) {
70 this->setFont(newFont);
71 }
72 }
73
74 int ww = QFontMetrics(this->font()).width('w');
75 setMinimumSize(77*ww, 65*ww);
76 setWindowTitle(tr("BKG Ntrip Server (BNS) Version 1.0"));
77 setWindowIcon(QPixmap(":ntrip-logo.png"));
78
79 // Create Actions
80 // --------------
81 _actHelp = new QAction(tr("&Help Contents"),this);
82 connect(_actHelp, SIGNAL(triggered()), SLOT(slotHelp()));
83
84 _actAbout = new QAction(tr("&About BNS"),this);
85 connect(_actAbout, SIGNAL(triggered()), SLOT(slotAbout()));
86
87 _actFontSel = new QAction(tr("Select &Font"),this);
88 connect(_actFontSel, SIGNAL(triggered()), SLOT(slotFontSel()));
89
90 _actSaveOpt = new QAction(tr("&Save Options"),this);
91 connect(_actSaveOpt, SIGNAL(triggered()), SLOT(slotSaveOptions()));
92
93 _actQuit = new QAction(tr("&Quit"),this);
94 connect(_actQuit, SIGNAL(triggered()), SLOT(close()));
95
96 _actWhatsThis= new QAction(tr("Help=Shift+F1"),this);
97 connect(_actWhatsThis, SIGNAL(triggered()), SLOT(slotWhatsThis()));
98
99 _actStart = new QAction(tr("Sta&rt"),this);
100 connect(_actStart, SIGNAL(triggered()), SLOT(slotStart()));
101
102 _actStop = new QAction(tr("Sto&p"),this);
103 connect(_actStop, SIGNAL(triggered()), SLOT(slotStop()));
104 _actStop->setEnabled(false);
105
106 CreateMenu();
107 AddToolbar();
108
109 // Canvas with Editable Fields
110 // ---------------------------
111 _canvas = new QWidget;
112 setCentralWidget(_canvas);
113
114 _ephPortLineEdit = new QLineEdit(settings.value("ephPort").toString());
115 _ephPortLineEdit->setWhatsThis(tr("Port for broadcast ephemeris (from BNC)"));
116 _ephPortLineEdit->setMaximumWidth(9*ww);
117
118 _clkPortLineEdit = new QLineEdit(settings.value("clkPort").toString());
119 _clkPortLineEdit->setWhatsThis(tr("Port for clock results (from RTNET)"));
120 _clkPortLineEdit->setMaximumWidth(9*ww);
121
122 _logFileLineEdit = new QLineEdit(settings.value("logFile").toString());
123 _outHostLineEdit = new QLineEdit(settings.value("outHost").toString());
124 _outPortLineEdit = new QLineEdit(settings.value("outPort").toString());
125 _outPortLineEdit->setMaximumWidth(9*ww);
126 _mountpointLineEdit = new QLineEdit(settings.value("mountpoint").toString());
127 _mountpointLineEdit->setMaximumWidth(9*ww);
128 _passwordLineEdit = new QLineEdit(settings.value("password").toString());
129 _passwordLineEdit->setMaximumWidth(9*ww);
130 _passwordLineEdit->setEchoMode(QLineEdit::Password);
131 _outFileLineEdit = new QLineEdit(settings.value("outFile").toString());
132
133 _rnxPathLineEdit = new QLineEdit(settings.value("rnxPath").toString());
134 _rnxIntrComboBox = new QComboBox;
135 _rnxIntrComboBox->setMaximumWidth(9*ww);
136 _rnxIntrComboBox->setEditable(false);
137 _rnxIntrComboBox->addItems(QString("1 min,2 min,5 min,10 min,15 min,30 min,1 hour,1 day").split(","));
138 int ii = _rnxIntrComboBox->findText(settings.value("rnxIntr").toString());
139 if (ii != -1) {
140 _rnxIntrComboBox->setCurrentIndex(ii);
141 }
142 _rnxSamplSpinBox = new QSpinBox;
143 _rnxSamplSpinBox->setMinimum(0);
144 _rnxSamplSpinBox->setMaximum(60);
145 _rnxSamplSpinBox->setSingleStep(5);
146 _rnxSamplSpinBox->setMaximumWidth(9*ww);
147 _rnxSamplSpinBox->setValue(settings.value("rnxSampl").toInt());
148 _rnxSamplSpinBox->setSuffix(" sec");
149
150 _sp3PathLineEdit = new QLineEdit(settings.value("sp3Path").toString());
151 _sp3IntrComboBox = new QComboBox;
152 _sp3IntrComboBox->setMaximumWidth(9*ww);
153 _sp3IntrComboBox->setEditable(false);
154 _sp3IntrComboBox->addItems(QString("1 min,2 min,5 min,10 min,15 min,30 min,1 hour,1 day").split(","));
155 ii = _sp3IntrComboBox->findText(settings.value("sp3Intr").toString());
156 if (ii != -1) {
157 _sp3IntrComboBox->setCurrentIndex(ii);
158 }
159 _sp3SamplSpinBox = new QSpinBox;
160 _sp3SamplSpinBox->setMinimum(0);
161 _sp3SamplSpinBox->setMaximum(900);
162 _sp3SamplSpinBox->setSingleStep(60);
163 _sp3SamplSpinBox->setMaximumWidth(9*ww);
164 _sp3SamplSpinBox->setValue(settings.value("sp3Sampl").toInt());
165 _sp3SamplSpinBox->setSuffix(" sec");
166
167 // TabWidget
168 // ---------
169 QTabWidget* tabs = new QTabWidget();
170
171 // Basic Input/Output Tab
172 // ----------------------
173 QWidget* tab_bas = new QWidget();
174 tabs->addTab(tab_bas, "Basic Options");
175
176 QGridLayout* layout_bas = new QGridLayout;
177 layout_bas->setColumnMinimumWidth(2, 9*ww);
178
179 layout_bas->addWidget(new QLabel("Input Ports"), 0, 0, 1, 2);
180 layout_bas->addWidget(new QLabel("Output Files"), 0, 3, 1, 2);
181 layout_bas->addWidget(new QLabel("Ephemeris"), 1, 0, Qt::AlignLeft);
182 layout_bas->addWidget(_ephPortLineEdit, 1, 1);
183 layout_bas->addWidget(new QLabel("Log"), 1, 3, Qt::AlignLeft);
184 layout_bas->addWidget(_logFileLineEdit, 1, 4);
185 layout_bas->addWidget(new QLabel("Clocks"), 2, 0, Qt::AlignLeft);
186 layout_bas->addWidget(_clkPortLineEdit, 2, 1);
187 layout_bas->addWidget(new QLabel("Data"), 2, 3, Qt::AlignLeft);
188 layout_bas->addWidget(_outFileLineEdit, 2, 4);
189 layout_bas->addWidget(new QLabel(""), 3, 0);
190 layout_bas->addWidget(new QLabel(""), 4, 0);
191 layout_bas->addWidget(new QLabel(""), 5, 0);
192
193 tab_bas->setLayout(layout_bas);
194
195 // NTRIP Caster Tab
196 // ----------------
197 QWidget* tab_cas = new QWidget();
198 tabs->addTab(tab_cas, "NTRIP Caster");
199
200 QGridLayout* layout_cas = new QGridLayout;
201 layout_cas->setColumnMinimumWidth(2, 9*ww);
202
203 layout_cas->addWidget(new QLabel(""), 0, 0);
204 layout_cas->addWidget(new QLabel("Host"), 1, 0, Qt::AlignLeft);
205 layout_cas->addWidget(_outHostLineEdit, 1, 1);
206 layout_cas->addWidget(new QLabel("Port"), 1, 3, Qt::AlignLeft);
207 layout_cas->addWidget(_outPortLineEdit, 1, 4);
208 layout_cas->addWidget(new QLabel("Mountpoint"), 2, 0, Qt::AlignLeft);
209 layout_cas->addWidget(_mountpointLineEdit, 2, 1);
210 layout_cas->addWidget(new QLabel("Password"), 2, 3, Qt::AlignLeft);
211 layout_cas->addWidget(_passwordLineEdit, 2, 4);
212 layout_cas->addWidget(new QLabel(""), 3, 0);
213 layout_cas->addWidget(new QLabel(""), 4, 0);
214 layout_cas->addWidget(new QLabel(""), 5, 0);
215
216 tab_cas->setLayout(layout_cas);
217
218 // RINEX and SP3 Tab
219 // -----------------
220 QWidget* tab_rin = new QWidget();
221 tabs->addTab(tab_rin, "RINEX and SP3");
222
223 QGridLayout* layout_rin = new QGridLayout;
224
225 layout_rin->addWidget(new QLabel("Clocks in RINEX Format"), 0, 0, 1, 4);
226 layout_rin->addWidget(new QLabel("Directory"), 1, 0);
227 layout_rin->addWidget(_rnxPathLineEdit, 1, 1, 1, 3);
228 layout_rin->addWidget(new QLabel("Interval"), 2, 0);
229 layout_rin->addWidget(_rnxIntrComboBox, 2, 1);
230 layout_rin->addWidget(new QLabel("Sampling"), 2, 2, Qt::AlignRight);
231 layout_rin->addWidget(_rnxSamplSpinBox, 2, 3, Qt::AlignLeft);
232 layout_rin->addWidget(new QLabel(""), 3, 0);
233 layout_rin->addWidget(new QLabel("Ephemeris in SP3 Format"), 4, 0, 1, 4);
234 layout_rin->addWidget(new QLabel("Directory"), 5, 0);
235 layout_rin->addWidget(_sp3PathLineEdit, 5, 1, 1, 3);
236 layout_rin->addWidget(new QLabel("Interval"), 6, 0);
237 layout_rin->addWidget(_sp3IntrComboBox, 6, 1);
238 layout_rin->addWidget(new QLabel("Sampling"), 6, 2, Qt::AlignRight);
239 layout_rin->addWidget(_sp3SamplSpinBox, 6, 3, Qt::AlignLeft);
240
241 tab_rin->setLayout(layout_rin);
242
243 // Log
244 // ---
245 _log = new QTextBrowser();
246 _log->setReadOnly(true);
247 _log->setWhatsThis(tr("Records of BNS's activities are shown in the Log section."));
248
249 // Main Layout
250 // -----------
251 QVBoxLayout* mainLayout = new QVBoxLayout;
252 mainLayout->addWidget(tabs);
253 mainLayout->addWidget(_log);
254
255 _canvas->setLayout(mainLayout);
256}
257
258// Destructor
259////////////////////////////////////////////////////////////////////////////
260bnsWindow::~bnsWindow() {
261}
262
263// Close Application gracefully
264////////////////////////////////////////////////////////////////////////////
265void bnsWindow::closeEvent(QCloseEvent* event) {
266
267int iRet = QMessageBox::question(this, "Close", "Save Options?",
268 QMessageBox::Yes, QMessageBox::No,
269 QMessageBox::Cancel);
270
271 if (iRet == QMessageBox::Cancel) {
272 event->ignore();
273 return;
274 }
275 else if (iRet == QMessageBox::Yes) {
276 slotSaveOptions();
277 }
278
279 QMainWindow::closeEvent(event);
280}
281
282// About Message
283////////////////////////////////////////////////////////////////////////////
284void bnsWindow::slotAbout() {
285 new bnsAboutDlg(0);
286}
287
288// Help Window
289////////////////////////////////////////////////////////////////////////////
290void bnsWindow::slotHelp() {
291 QUrl url;
292 url.setPath(":bnshelp.html");
293 new bnsHlpDlg(0, url);
294}
295
296// Select Fonts
297////////////////////////////////////////////////////////////////////////////
298void bnsWindow::slotFontSel() {
299 bool ok;
300 QFont newFont = QFontDialog::getFont(&ok, this->font(), this);
301 if (ok) {
302 QSettings settings;
303 settings.setValue("font", newFont.toString());
304 QApplication::setFont(newFont);
305 int ww = QFontMetrics(newFont).width('w');
306 setMinimumSize(77*ww, 65*ww);
307 }
308}
309
310// Whats This Help
311////////////////////////////////////////////////////////////////////////////
312void bnsWindow::slotWhatsThis() {
313QWhatsThis::enterWhatsThisMode();
314}
315
316// Create Menus
317////////////////////////////////////////////////////////////////////////////
318void bnsWindow::CreateMenu() {
319 _menuFile = menuBar()->addMenu(tr("&File"));
320 _menuFile->addAction(_actFontSel);
321 _menuFile->addSeparator();
322 _menuFile->addAction(_actSaveOpt);
323 _menuFile->addSeparator();
324 _menuFile->addAction(_actQuit);
325
326 _menuHlp = menuBar()->addMenu(tr("&Help"));
327 _menuHlp->addAction(_actHelp);
328 _menuHlp->addAction(_actAbout);
329}
330
331// Tool (Command) Bar
332////////////////////////////////////////////////////////////////////////////
333void bnsWindow::AddToolbar() {
334 QToolBar* toolBar = new QToolBar;
335 addToolBar(Qt::BottomToolBarArea, toolBar);
336 toolBar->setMovable(false);
337 toolBar->addAction(_actStart);
338 toolBar->addAction(_actStop);
339 toolBar->addWidget(new QLabel(" "));
340 toolBar->addAction(_actWhatsThis);
341}
342
343// Save Options
344////////////////////////////////////////////////////////////////////////////
345void bnsWindow::slotSaveOptions() {
346 QSettings settings;
347 settings.setValue("ephPort", _ephPortLineEdit->text());
348 settings.setValue("clkPort", _clkPortLineEdit->text());
349 settings.setValue("logFile", _logFileLineEdit->text());
350 settings.setValue("outHost", _outHostLineEdit->text());
351 settings.setValue("outPort", _outPortLineEdit->text());
352 settings.setValue("mountpoint", _mountpointLineEdit->text());
353 settings.setValue("password", _passwordLineEdit->text());
354 settings.setValue("outFile", _outFileLineEdit->text());
355 settings.setValue("rnxPath", _rnxPathLineEdit->text());
356 settings.setValue("rnxIntr", _rnxIntrComboBox->currentText());
357 settings.setValue("rnxSampl", _rnxSamplSpinBox->value());
358 settings.setValue("sp3Path", _sp3PathLineEdit->text());
359 settings.setValue("sp3Intr", _sp3IntrComboBox->currentText());
360 settings.setValue("sp3Sampl", _sp3SamplSpinBox->value());
361}
362
363// Display Program Messages
364////////////////////////////////////////////////////////////////////////////
365void bnsWindow::slotMessage(const QByteArray msg) {
366
367 const int maxBufferSize = 10000;
368
369 QString txt = _log->toPlainText() + "\n" +
370 QDateTime::currentDateTime().toUTC().toString("yy-MM-dd hh:mm:ss ") + msg;
371 _log->clear();
372 _log->append(txt.right(maxBufferSize));
373}
374
375// Delete bns
376////////////////////////////////////////////////////////////////////////////
377void bnsWindow::deleteBns() {
378 _actStart->setEnabled(true);
379 _actStop->setEnabled(false);
380 _bns->terminate();
381 _bns->wait(100);
382 delete _bns;
383 _bns = 0;
384}
385
386// Error in bns
387////////////////////////////////////////////////////////////////////////////
388void bnsWindow::slotError(const QByteArray msg) {
389 slotMessage(msg);
390 deleteBns();
391}
392
393// Stop
394////////////////////////////////////////////////////////////////////////////
395void bnsWindow::slotStop() {
396 int iRet = QMessageBox::question(this, "Stop", "Do you want to stop?",
397 QMessageBox::Yes, QMessageBox::No,
398 QMessageBox::NoButton);
399 if (iRet == QMessageBox::Yes) {
400 deleteBns();
401 }
402}
403
404// Start
405////////////////////////////////////////////////////////////////////////////
406void bnsWindow::slotStart() {
407 slotSaveOptions();
408
409 _actStart->setEnabled(false);
410 _actStop->setEnabled(true);
411
412 _bns = new t_bns(0);
413
414 connect(_bns, SIGNAL(newMessage(QByteArray)),
415 this, SLOT(slotMessage(const QByteArray)));
416
417 connect(_bns, SIGNAL(error(QByteArray)),
418 this, SLOT(slotError(const QByteArray)));
419
420 _bns->start();
421}
Note: See TracBrowser for help on using the repository browser.