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

Last change on this file since 892 was 855, checked in by mervart, 17 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 delete this;
282}
283
284// About Message
285////////////////////////////////////////////////////////////////////////////
286void bnsWindow::slotAbout() {
287 new bnsAboutDlg(0);
288}
289
290// Help Window
291////////////////////////////////////////////////////////////////////////////
292void bnsWindow::slotHelp() {
293 QUrl url;
294 url.setPath(":bnshelp.html");
295 new bnsHlpDlg(0, url);
296}
297
298// Select Fonts
299////////////////////////////////////////////////////////////////////////////
300void bnsWindow::slotFontSel() {
301 bool ok;
302 QFont newFont = QFontDialog::getFont(&ok, this->font(), this);
303 if (ok) {
304 QSettings settings;
305 settings.setValue("font", newFont.toString());
306 QApplication::setFont(newFont);
307 int ww = QFontMetrics(newFont).width('w');
308 setMinimumSize(77*ww, 65*ww);
309 }
310}
311
312// Whats This Help
313////////////////////////////////////////////////////////////////////////////
314void bnsWindow::slotWhatsThis() {
315QWhatsThis::enterWhatsThisMode();
316}
317
318// Create Menus
319////////////////////////////////////////////////////////////////////////////
320void bnsWindow::CreateMenu() {
321 _menuFile = menuBar()->addMenu(tr("&File"));
322 _menuFile->addAction(_actFontSel);
323 _menuFile->addSeparator();
324 _menuFile->addAction(_actSaveOpt);
325 _menuFile->addSeparator();
326 _menuFile->addAction(_actQuit);
327
328 _menuHlp = menuBar()->addMenu(tr("&Help"));
329 _menuHlp->addAction(_actHelp);
330 _menuHlp->addAction(_actAbout);
331}
332
333// Tool (Command) Bar
334////////////////////////////////////////////////////////////////////////////
335void bnsWindow::AddToolbar() {
336 QToolBar* toolBar = new QToolBar;
337 addToolBar(Qt::BottomToolBarArea, toolBar);
338 toolBar->setMovable(false);
339 toolBar->addAction(_actStart);
340 toolBar->addAction(_actStop);
341 toolBar->addWidget(new QLabel(" "));
342 toolBar->addAction(_actWhatsThis);
343}
344
345// Save Options
346////////////////////////////////////////////////////////////////////////////
347void bnsWindow::slotSaveOptions() {
348 QSettings settings;
349 settings.setValue("ephPort", _ephPortLineEdit->text());
350 settings.setValue("clkPort", _clkPortLineEdit->text());
351 settings.setValue("logFile", _logFileLineEdit->text());
352 settings.setValue("outHost", _outHostLineEdit->text());
353 settings.setValue("outPort", _outPortLineEdit->text());
354 settings.setValue("mountpoint", _mountpointLineEdit->text());
355 settings.setValue("password", _passwordLineEdit->text());
356 settings.setValue("outFile", _outFileLineEdit->text());
357 settings.setValue("rnxPath", _rnxPathLineEdit->text());
358 settings.setValue("rnxIntr", _rnxIntrComboBox->currentText());
359 settings.setValue("rnxSampl", _rnxSamplSpinBox->value());
360 settings.setValue("sp3Path", _sp3PathLineEdit->text());
361 settings.setValue("sp3Intr", _sp3IntrComboBox->currentText());
362 settings.setValue("sp3Sampl", _sp3SamplSpinBox->value());
363}
364
365// Display Program Messages
366////////////////////////////////////////////////////////////////////////////
367void bnsWindow::slotMessage(const QByteArray msg) {
368
369 const int maxBufferSize = 10000;
370
371 QString txt = _log->toPlainText() + "\n" +
372 QDateTime::currentDateTime().toUTC().toString("yy-MM-dd hh:mm:ss ") + msg;
373 _log->clear();
374 _log->append(txt.right(maxBufferSize));
375}
376
377// Delete bns
378////////////////////////////////////////////////////////////////////////////
379void bnsWindow::deleteBns() {
380 _actStart->setEnabled(true);
381 _actStop->setEnabled(false);
382 _bns->terminate();
383 _bns->wait(100);
384 delete _bns;
385 _bns = 0;
386}
387
388// Error in bns
389////////////////////////////////////////////////////////////////////////////
390void bnsWindow::slotError(const QByteArray msg) {
391 slotMessage(msg);
392 deleteBns();
393}
394
395// Stop
396////////////////////////////////////////////////////////////////////////////
397void bnsWindow::slotStop() {
398 int iRet = QMessageBox::question(this, "Stop", "Do you want to stop?",
399 QMessageBox::Yes, QMessageBox::No,
400 QMessageBox::NoButton);
401 if (iRet == QMessageBox::Yes) {
402 deleteBns();
403 }
404}
405
406// Start
407////////////////////////////////////////////////////////////////////////////
408void bnsWindow::slotStart() {
409 slotSaveOptions();
410
411 _actStart->setEnabled(false);
412 _actStop->setEnabled(true);
413
414 _bns = new t_bns(0);
415
416 connect(_bns, SIGNAL(newMessage(QByteArray)),
417 this, SLOT(slotMessage(const QByteArray)));
418
419 connect(_bns, SIGNAL(error(QByteArray)),
420 this, SLOT(slotError(const QByteArray)));
421
422 _bns->start();
423}
Note: See TracBrowser for help on using the repository browser.