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

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

* empty log message *

File size: 12.8 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;
134 _rnxIntrComboBox = new QComboBox;
135 _rnxSamplSpinBox = new QSpinBox;
136
137 _sp3PathLineEdit = new QLineEdit;
138 _sp3IntrComboBox = new QComboBox;
139 _sp3SamplSpinBox = new QSpinBox;
140
141 // TabWidget
142 // ---------
143 QTabWidget* tabs = new QTabWidget();
144
145 // Basic Input/Output Tab
146 // ----------------------
147 QWidget* tab_bas = new QWidget();
148 tabs->addTab(tab_bas, "Basic Options");
149
150 QGridLayout* layout_bas = new QGridLayout;
151 layout_bas->setColumnMinimumWidth(2, 9*ww);
152
153 layout_bas->addWidget(new QLabel("Input Ports"), 0, 0, 1, 2);
154 layout_bas->addWidget(new QLabel("Output Files"), 0, 3, 1, 2);
155 layout_bas->addWidget(new QLabel("Ephemeris"), 1, 0, Qt::AlignLeft);
156 layout_bas->addWidget(_ephPortLineEdit, 1, 1);
157 layout_bas->addWidget(new QLabel("Log"), 1, 3, Qt::AlignLeft);
158 layout_bas->addWidget(_logFileLineEdit, 1, 4);
159 layout_bas->addWidget(new QLabel("Clocks"), 2, 0, Qt::AlignLeft);
160 layout_bas->addWidget(_clkPortLineEdit, 2, 1);
161 layout_bas->addWidget(new QLabel("Data"), 2, 3, Qt::AlignLeft);
162 layout_bas->addWidget(_outFileLineEdit, 2, 4);
163 layout_bas->addWidget(new QLabel(""), 3, 0);
164 layout_bas->addWidget(new QLabel(""), 4, 0);
165 layout_bas->addWidget(new QLabel(""), 5, 0);
166
167 tab_bas->setLayout(layout_bas);
168
169 // NTRIP Caster Tab
170 // ----------------
171 QWidget* tab_cas = new QWidget();
172 tabs->addTab(tab_cas, "NTRIP Caster");
173
174 QGridLayout* layout_cas = new QGridLayout;
175 layout_cas->setColumnMinimumWidth(2, 9*ww);
176
177 layout_cas->addWidget(new QLabel(""), 0, 0);
178 layout_cas->addWidget(new QLabel("Host"), 1, 0, Qt::AlignLeft);
179 layout_cas->addWidget(_outHostLineEdit, 1, 1);
180 layout_cas->addWidget(new QLabel("Port"), 1, 3, Qt::AlignLeft);
181 layout_cas->addWidget(_outPortLineEdit, 1, 4);
182 layout_cas->addWidget(new QLabel("Mountpoint"), 2, 0, Qt::AlignLeft);
183 layout_cas->addWidget(_mountpointLineEdit, 2, 1);
184 layout_cas->addWidget(new QLabel("Password"), 2, 3, Qt::AlignLeft);
185 layout_cas->addWidget(_passwordLineEdit, 2, 4);
186 layout_cas->addWidget(new QLabel(""), 3, 0);
187 layout_cas->addWidget(new QLabel(""), 4, 0);
188 layout_cas->addWidget(new QLabel(""), 5, 0);
189
190 tab_cas->setLayout(layout_cas);
191
192 // RINEX and SP3 Tab
193 // -----------------
194 QWidget* tab_rin = new QWidget();
195 tabs->addTab(tab_rin, "RINEX and SP3");
196
197 QGridLayout* layout_rin = new QGridLayout;
198
199 layout_rin->addWidget(new QLabel("Clocks in RINEX Format"), 0, 0, 1, 4);
200 layout_rin->addWidget(new QLabel("Directory"), 1, 0);
201 layout_rin->addWidget(_rnxPathLineEdit, 1, 1, 1, 3);
202 layout_rin->addWidget(new QLabel("Interval"), 2, 0);
203 layout_rin->addWidget(_rnxIntrComboBox, 2, 1);
204 layout_rin->addWidget(new QLabel("Sampling"), 2, 2, Qt::AlignRight);
205 layout_rin->addWidget(_rnxSamplSpinBox, 2, 3, Qt::AlignLeft);
206 layout_rin->addWidget(new QLabel(""), 3, 0);
207 layout_rin->addWidget(new QLabel("Ephemeris in SP3 Format"), 4, 0, 1, 4);
208 layout_rin->addWidget(new QLabel("Directory"), 5, 0);
209 layout_rin->addWidget(_sp3PathLineEdit, 5, 1, 1, 3);
210 layout_rin->addWidget(new QLabel("Interval"), 6, 0);
211 layout_rin->addWidget(_sp3IntrComboBox, 6, 1);
212 layout_rin->addWidget(new QLabel("Sampling"), 6, 2, Qt::AlignRight);
213 layout_rin->addWidget(_sp3SamplSpinBox, 6, 3, Qt::AlignLeft);
214
215 tab_rin->setLayout(layout_rin);
216
217 // Log
218 // ---
219 _log = new QTextBrowser();
220 _log->setReadOnly(true);
221 _log->setWhatsThis(tr("Records of BNS's activities are shown in the Log section."));
222
223 // Main Layout
224 // -----------
225 QVBoxLayout* mainLayout = new QVBoxLayout;
226 mainLayout->addWidget(tabs);
227 mainLayout->addWidget(_log);
228
229 _canvas->setLayout(mainLayout);
230}
231
232// Destructor
233////////////////////////////////////////////////////////////////////////////
234bnsWindow::~bnsWindow() {
235}
236
237// Close Application gracefully
238////////////////////////////////////////////////////////////////////////////
239void bnsWindow::closeEvent(QCloseEvent* event) {
240
241int iRet = QMessageBox::question(this, "Close", "Save Options?",
242 QMessageBox::Yes, QMessageBox::No,
243 QMessageBox::Cancel);
244
245 if (iRet == QMessageBox::Cancel) {
246 event->ignore();
247 return;
248 }
249 else if (iRet == QMessageBox::Yes) {
250 slotSaveOptions();
251 }
252
253 QMainWindow::closeEvent(event);
254
255 delete this;
256}
257
258// About Message
259////////////////////////////////////////////////////////////////////////////
260void bnsWindow::slotAbout() {
261 new bnsAboutDlg(0);
262}
263
264// Help Window
265////////////////////////////////////////////////////////////////////////////
266void bnsWindow::slotHelp() {
267 QUrl url;
268 url.setPath(":bnshelp.html");
269 new bnsHlpDlg(0, url);
270}
271
272// Select Fonts
273////////////////////////////////////////////////////////////////////////////
274void bnsWindow::slotFontSel() {
275 bool ok;
276 QFont newFont = QFontDialog::getFont(&ok, this->font(), this);
277 if (ok) {
278 QSettings settings;
279 settings.setValue("font", newFont.toString());
280 QApplication::setFont(newFont);
281 int ww = QFontMetrics(newFont).width('w');
282 setMinimumSize(77*ww, 65*ww);
283 }
284}
285
286// Whats This Help
287////////////////////////////////////////////////////////////////////////////
288void bnsWindow::slotWhatsThis() {
289QWhatsThis::enterWhatsThisMode();
290}
291
292// Create Menus
293////////////////////////////////////////////////////////////////////////////
294void bnsWindow::CreateMenu() {
295 _menuFile = menuBar()->addMenu(tr("&File"));
296 _menuFile->addAction(_actFontSel);
297 _menuFile->addSeparator();
298 _menuFile->addAction(_actSaveOpt);
299 _menuFile->addSeparator();
300 _menuFile->addAction(_actQuit);
301
302 _menuHlp = menuBar()->addMenu(tr("&Help"));
303 _menuHlp->addAction(_actHelp);
304 _menuHlp->addAction(_actAbout);
305}
306
307// Tool (Command) Bar
308////////////////////////////////////////////////////////////////////////////
309void bnsWindow::AddToolbar() {
310 QToolBar* toolBar = new QToolBar;
311 addToolBar(Qt::BottomToolBarArea, toolBar);
312 toolBar->setMovable(false);
313 toolBar->addAction(_actStart);
314 toolBar->addAction(_actStop);
315 toolBar->addWidget(new QLabel(" "));
316 toolBar->addAction(_actWhatsThis);
317}
318
319// Save Options
320////////////////////////////////////////////////////////////////////////////
321void bnsWindow::slotSaveOptions() {
322 QSettings settings;
323 settings.setValue("ephPort", _ephPortLineEdit->text());
324 settings.setValue("clkPort", _clkPortLineEdit->text());
325 settings.setValue("logFile", _logFileLineEdit->text());
326 settings.setValue("outHost", _outHostLineEdit->text());
327 settings.setValue("outPort", _outPortLineEdit->text());
328 settings.setValue("mountpoint", _mountpointLineEdit->text());
329 settings.setValue("password", _passwordLineEdit->text());
330 settings.setValue("outFile", _outFileLineEdit->text());
331}
332
333// Display Program Messages
334////////////////////////////////////////////////////////////////////////////
335void bnsWindow::slotMessage(const QByteArray msg) {
336
337 const int maxBufferSize = 10000;
338
339 QString txt = _log->toPlainText() + "\n" +
340 QDateTime::currentDateTime().toUTC().toString("yy-MM-dd hh:mm:ss ") + msg;
341 _log->clear();
342 _log->append(txt.right(maxBufferSize));
343}
344
345// Delete bns
346////////////////////////////////////////////////////////////////////////////
347void bnsWindow::deleteBns() {
348 _actStart->setEnabled(true);
349 _actStop->setEnabled(false);
350 _bns->terminate();
351 _bns->wait(100);
352 delete _bns;
353 _bns = 0;
354}
355
356// Error in bns
357////////////////////////////////////////////////////////////////////////////
358void bnsWindow::slotError(const QByteArray msg) {
359 slotMessage(msg);
360 deleteBns();
361}
362
363// Stop
364////////////////////////////////////////////////////////////////////////////
365void bnsWindow::slotStop() {
366 int iRet = QMessageBox::question(this, "Stop", "Do you want to stop?",
367 QMessageBox::Yes, QMessageBox::No,
368 QMessageBox::NoButton);
369 if (iRet == QMessageBox::Yes) {
370 deleteBns();
371 }
372}
373
374// Start
375////////////////////////////////////////////////////////////////////////////
376void bnsWindow::slotStart() {
377 slotSaveOptions();
378
379 _actStart->setEnabled(false);
380 _actStop->setEnabled(true);
381
382 _bns = new t_bns(0);
383
384 connect(_bns, SIGNAL(newMessage(QByteArray)),
385 this, SLOT(slotMessage(const QByteArray)));
386
387 connect(_bns, SIGNAL(error(QByteArray)),
388 this, SLOT(slotError(const QByteArray)));
389
390 _bns->start();
391}
Note: See TracBrowser for help on using the repository browser.