source: ntrip/trunk/BNC/bncwindow.cpp@ 295

Last change on this file since 295 was 295, checked in by mervart, 17 years ago

* empty log message *

File size: 19.2 KB
Line 
1// Part of BNC, a utility for retrieving decoding and
2// converting GNSS data streams from NTRIP broadcasters,
3// written by Leos Mervart.
4//
5// Copyright (C) 2006
6// German Federal Agency for Cartography and Geodesy (BKG)
7// http://www.bkg.bund.de
8// Czech Technical University Prague, Department of Advanced Geodesy
9// http://www.fsv.cvut.cz
10//
11// Email: euref-ip@bkg.bund.de
12//
13// This program is free software; you can redistribute it and/or
14// modify it under the terms of the GNU General Public License
15// as published by the Free Software Foundation, version 2.
16//
17// This program is distributed in the hope that it will be useful,
18// but WITHOUT ANY WARRANTY; without even the implied warranty of
19// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20// GNU General Public License for more details.
21//
22// You should have received a copy of the GNU General Public License
23// along with this program; if not, write to the Free Software
24// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25
26/* -------------------------------------------------------------------------
27 * BKG NTRIP Client
28 * -------------------------------------------------------------------------
29 *
30 * Class: bncWindow
31 *
32 * Purpose: This class implements the main application window.
33 *
34 * Author: L. Mervart
35 *
36 * Created: 24-Dec-2005
37 *
38 * Changes:
39 *
40 * -----------------------------------------------------------------------*/
41
42#include <unistd.h>
43#include "bncwindow.h"
44#include "bncapp.h"
45#include "bncgetthread.h"
46#include "bnctabledlg.h"
47#include "bnchlpdlg.h"
48#include "bnchtml.h"
49#include "bnctableitem.h"
50
51using namespace std;
52
53// Constructor
54////////////////////////////////////////////////////////////////////////////
55bncWindow::bncWindow() {
56
57 int ww = QFontMetrics(this->font()).width('w');
58
59 static const QStringList labels = QString("account,mountpoint,"
60 "decoder,bytes").split(",");
61
62 setMinimumSize(60*ww, 80*ww);
63 setWindowTitle(tr("BKG Ntrip Client (BNC), Version 1.0b"));
64
65 // Create Actions
66 // --------------
67 _actHelp = new QAction(tr("&Help Contents"),this);
68 connect(_actHelp, SIGNAL(triggered()), SLOT(slotHelp()));
69
70 _actAbout = new QAction(tr("&About BNC"),this);
71 connect(_actAbout, SIGNAL(triggered()), SLOT(slotAbout()));
72
73 _actFontSel = new QAction(tr("Select &Font"),this);
74 connect(_actFontSel, SIGNAL(triggered()), SLOT(slotFontSel()));
75
76 _actSaveOpt = new QAction(tr("&Save Options"),this);
77 connect(_actSaveOpt, SIGNAL(triggered()), SLOT(slotSaveOptions()));
78
79 _actQuit = new QAction(tr("&Quit"),this);
80 connect(_actQuit, SIGNAL(triggered()), SLOT(close()));
81
82 _actAddMountPoints = new QAction(tr("Add &Mountpoints"),this);
83 connect(_actAddMountPoints, SIGNAL(triggered()), SLOT(slotAddMountPoints()));
84
85 _actDeleteMountPoints = new QAction(tr("&Delete Mountpoints"),this);
86 connect(_actDeleteMountPoints, SIGNAL(triggered()), SLOT(slotDeleteMountPoints()));
87 _actDeleteMountPoints->setEnabled(false);
88
89 _actGetData = new QAction(tr("Sta&rt"),this);
90 connect(_actGetData, SIGNAL(triggered()), SLOT(slotGetData()));
91
92 _actStop = new QAction(tr("Sto&p"),this);
93 connect(_actStop, SIGNAL(triggered()), SLOT(slotStop()));
94 _actStop->setEnabled(false);
95
96 // Create Menus
97 // ------------
98 _menuFile = menuBar()->addMenu(tr("&File"));
99 _menuFile->addAction(_actFontSel);
100 _menuFile->addSeparator();
101 _menuFile->addAction(_actSaveOpt);
102 _menuFile->addSeparator();
103 _menuFile->addAction(_actQuit);
104
105 _menuHlp = menuBar()->addMenu(tr("&Help"));
106 _menuHlp->addAction(_actHelp);
107 _menuHlp->addAction(_actAbout);
108
109 // Tool (Command) Bar
110 // ------------------
111 QToolBar* toolBar = new QToolBar;
112 addToolBar(Qt::BottomToolBarArea, toolBar);
113 toolBar->setMovable(false);
114 toolBar->addAction(_actAddMountPoints);
115 toolBar->addAction(_actDeleteMountPoints);
116 toolBar->addAction(_actGetData);
117 toolBar->addAction(_actStop);
118
119 // Canvas with Editable Fields
120 // ---------------------------
121 _canvas = new QWidget;
122 setCentralWidget(_canvas);
123
124 QGridLayout* layout = new QGridLayout;
125 _canvas->setLayout(layout);
126
127 QSettings settings;
128 _proxyHostLineEdit = new QLineEdit(settings.value("proxyHost").toString());
129 _proxyHostLineEdit->setMaximumWidth(12*ww);
130 _proxyPortLineEdit = new QLineEdit(settings.value("proxyPort").toString());
131 _proxyPortLineEdit->setMaximumWidth(9*ww);
132 _waitTimeSpinBox = new QSpinBox();
133 _waitTimeSpinBox->setMinimum(1);
134 _waitTimeSpinBox->setMaximum(30);
135 _waitTimeSpinBox->setSingleStep(1);
136 _waitTimeSpinBox->setSuffix(" sec");
137 _waitTimeSpinBox->setMaximumWidth(9*ww);
138 _waitTimeSpinBox->setValue(settings.value("waitTime").toInt());
139 _outFileLineEdit = new QLineEdit(settings.value("outFile").toString());
140 _outPortLineEdit = new QLineEdit(settings.value("outPort").toString());
141 _outPortLineEdit->setMaximumWidth(9*ww);
142 _rnxPathLineEdit = new QLineEdit(settings.value("rnxPath").toString());
143 _rnxScrpLineEdit = new QLineEdit(settings.value("rnxScript").toString());
144 _rnxSkelLineEdit = new QLineEdit(settings.value("rnxSkel").toString());
145 _rnxSkelLineEdit->setMaximumWidth(5*ww);
146 _rnxAppendCheckBox = new QCheckBox();
147 _rnxAppendCheckBox->setCheckState(Qt::CheckState(
148 settings.value("rnxAppend").toInt()));
149 _rnxIntrComboBox = new QComboBox();
150 _rnxIntrComboBox->setMaximumWidth(9*ww);
151 _rnxIntrComboBox->setEditable(false);
152 _rnxIntrComboBox->addItems(QString("5 min,10 min,15 min,30 min,1 hour,1 day").split(","));
153 int ii = _rnxIntrComboBox->findText(settings.value("rnxIntr").toString());
154 if (ii != -1) {
155 _rnxIntrComboBox->setCurrentIndex(ii);
156 }
157 _rnxSamplSpinBox = new QSpinBox();
158 _rnxSamplSpinBox->setMinimum(0);
159 _rnxSamplSpinBox->setMaximum(60);
160 _rnxSamplSpinBox->setSingleStep(5);
161 _rnxSamplSpinBox->setMaximumWidth(9*ww);
162 _rnxSamplSpinBox->setValue(settings.value("rnxSampl").toInt());
163 _rnxSamplSpinBox->setSuffix(" sec");
164 _logFileLineEdit = new QLineEdit(settings.value("logFile").toString());
165 _mountPointsTable = new QTableWidget(0,4);
166 _mountPointsTable->horizontalHeader()->resizeSection(1,25*ww);
167 _mountPointsTable->horizontalHeader()->setResizeMode(QHeaderView::Interactive);
168 _mountPointsTable->horizontalHeader()->setStretchLastSection(true);
169 _mountPointsTable->setHorizontalHeaderLabels(labels);
170// _mountPointsTable->horizontalHeader()->hide();
171// _mountPointsTable->verticalHeader()->hide();
172 _mountPointsTable->setGridStyle(Qt::NoPen);
173 _mountPointsTable->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
174 _mountPointsTable->setSelectionMode(QAbstractItemView::ExtendedSelection);
175 _mountPointsTable->setSelectionBehavior(QAbstractItemView::SelectRows);
176 QListIterator<QString> it(settings.value("mountPoints").toStringList());
177 if (!it.hasNext()) {
178 _actGetData->setEnabled(false);
179 }
180 int iRow = 0;
181 while (it.hasNext()) {
182 QStringList hlp = it.next().split(" ");
183 if (hlp.size() <= 1) continue;
184 _mountPointsTable->insertRow(iRow);
185
186 QUrl url(hlp[0]);
187
188 QString fullPath = url.host() + QString(":%1").arg(url.port()) + url.path();
189 QString format(hlp[1]);
190
191 QTableWidgetItem* it;
192 it = new QTableWidgetItem(url.userInfo());
193 it->setFlags(it->flags() & ~Qt::ItemIsEditable);
194 _mountPointsTable->setItem(iRow, 0, it);
195
196 it = new QTableWidgetItem(fullPath);
197 it->setFlags(it->flags() & ~Qt::ItemIsEditable);
198 _mountPointsTable->setItem(iRow, 1, it);
199
200 it = new QTableWidgetItem(format);
201 _mountPointsTable->setItem(iRow, 2, it);
202
203 bncTableItem* bncIt = new bncTableItem();
204 bncIt->setFlags(bncIt->flags() & ~Qt::ItemIsEditable);
205 _mountPointsTable->setItem(iRow, 3, bncIt);
206
207 iRow++;
208 }
209 _mountPointsTable->hideColumn(0);
210 _mountPointsTable->sortItems(1);
211
212 connect(_mountPointsTable, SIGNAL(itemSelectionChanged()),
213 SLOT(slotSelectionChanged()));
214
215 _log = new QTextEdit();
216 _log->setReadOnly(true);
217
218 layout->addWidget(new QLabel("Proxy host"), 0, 0, 1, 2);
219 layout->addWidget(_proxyHostLineEdit, 0, 2);
220 layout->addWidget(new QLabel("Proxy port"), 0, 3);
221 layout->addWidget(_proxyPortLineEdit, 0, 4);
222
223 layout->addWidget(new QLabel("Wait for full epoch"), 1, 0, 1, 2);
224 layout->addWidget(_waitTimeSpinBox, 1, 2);
225
226 layout->addWidget(new QLabel("ASCII output file (full path)"), 2, 0, 1, 2);
227 layout->addWidget(_outFileLineEdit, 2, 2, 1, 3);
228
229 layout->addWidget(new QLabel("Port for binary output"), 3, 0, 1, 2);
230 layout->addWidget(_outPortLineEdit, 3, 2);
231
232 layout->addWidget(new QLabel("RINEX directory"), 4, 0, 1, 2);
233 layout->addWidget(_rnxPathLineEdit, 4, 2, 1, 3);
234
235 layout->addWidget(new QLabel("RINEX script (full path)"), 5, 0, 1, 2);
236 layout->addWidget(_rnxScrpLineEdit, 5, 2, 1, 3);
237
238 layout->addWidget(new QLabel("RINEX file interval"), 6, 0, 1, 2);
239 layout->addWidget(_rnxIntrComboBox, 6, 2);
240 layout->addWidget(new QLabel("Sampling"), 6, 3);
241 layout->addWidget(_rnxSamplSpinBox, 6, 4);
242
243 layout->addWidget(new QLabel("RINEX skeleton extension"), 7, 0, 1, 2);
244 layout->addWidget(_rnxSkelLineEdit, 7, 2);
245
246 layout->addWidget(new QLabel("Append files"), 7, 3);
247 layout->addWidget(_rnxAppendCheckBox, 7, 4);
248
249 layout->addWidget(new QLabel("Mountpoints"), 8, 0, 1, 2);
250 layout->addWidget(_mountPointsTable, 9, 0, 1, 5);
251
252 layout->addWidget(new QLabel("Log (full path)"), 10, 0, 1, 2);
253 layout->addWidget(_logFileLineEdit, 10, 2, 1, 3);
254 layout->addWidget(_log, 11, 0, 1, 5);
255}
256
257// Destructor
258////////////////////////////////////////////////////////////////////////////
259bncWindow::~bncWindow() {
260}
261
262// Retrieve Table
263////////////////////////////////////////////////////////////////////////////
264void bncWindow::slotAddMountPoints() {
265
266 QSettings settings;
267 QString proxyHost = settings.value("proxyHost").toString();
268 int proxyPort = settings.value("proxyPort").toInt();
269 if (proxyHost != _proxyHostLineEdit->text() ||
270 proxyPort != _proxyPortLineEdit->text().toInt()) {
271 int iRet = QMessageBox::question(this, "Question", "Proxy options "
272 "changed. Use the new ones?",
273 QMessageBox::Yes, QMessageBox::No,
274 QMessageBox::NoButton);
275 if (iRet == QMessageBox::Yes) {
276 settings.setValue("proxyHost", _proxyHostLineEdit->text());
277 settings.setValue("proxyPort", _proxyPortLineEdit->text());
278 }
279 }
280
281 bncTableDlg* dlg = new bncTableDlg(this);
282 dlg->move(this->pos().x()+50, this->pos().y()+50);
283 connect(dlg, SIGNAL(newMountPoints(QStringList*)),
284 this, SLOT(slotNewMountPoints(QStringList*)));
285 dlg->exec();
286 delete dlg;
287
288}
289
290// Delete Selected Mount Points
291////////////////////////////////////////////////////////////////////////////
292void bncWindow::slotDeleteMountPoints() {
293
294 int nRows = _mountPointsTable->rowCount();
295 bool flg[nRows];
296 for (int iRow = 0; iRow < nRows; iRow++) {
297 if (_mountPointsTable->isItemSelected(_mountPointsTable->item(iRow,1))) {
298 flg[iRow] = true;
299 }
300 else {
301 flg[iRow] = false;
302 }
303 }
304 for (int iRow = nRows-1; iRow >= 0; iRow--) {
305 if (flg[iRow]) {
306 _mountPointsTable->removeRow(iRow);
307 }
308 }
309 _actDeleteMountPoints->setEnabled(false);
310
311 if (_mountPointsTable->rowCount() == 0) {
312 _actGetData->setEnabled(false);
313 }
314}
315
316// New Mount Points Selected
317////////////////////////////////////////////////////////////////////////////
318void bncWindow::slotNewMountPoints(QStringList* mountPoints) {
319 int iRow = 0;
320 QListIterator<QString> it(*mountPoints);
321 while (it.hasNext()) {
322 QStringList hlp = it.next().split(" ");
323 QUrl url(hlp[0]);
324 QString fullPath = url.host() + QString(":%1").arg(url.port()) + url.path();
325 QString format(hlp[1]);
326
327 _mountPointsTable->insertRow(iRow);
328
329 QTableWidgetItem* it;
330 it = new QTableWidgetItem(url.userInfo());
331 it->setFlags(it->flags() & ~Qt::ItemIsEditable);
332 _mountPointsTable->setItem(iRow, 0, it);
333
334 it = new QTableWidgetItem(fullPath);
335 it->setFlags(it->flags() & ~Qt::ItemIsEditable);
336 _mountPointsTable->setItem(iRow, 1, it);
337
338 it = new QTableWidgetItem(format);
339 _mountPointsTable->setItem(iRow, 2, it);
340
341 bncTableItem* bncIt = new bncTableItem();
342 _mountPointsTable->setItem(iRow, 3, bncIt);
343
344 iRow++;
345 }
346 _mountPointsTable->hideColumn(0);
347 _mountPointsTable->sortItems(1);
348 if (mountPoints->count() > 0) {
349 _actGetData->setEnabled(true);
350 }
351 delete mountPoints;
352}
353
354// Save Options
355////////////////////////////////////////////////////////////////////////////
356void bncWindow::slotSaveOptions() {
357 QSettings settings;
358 settings.setValue("proxyHost", _proxyHostLineEdit->text());
359 settings.setValue("proxyPort", _proxyPortLineEdit->text());
360 settings.setValue("waitTime", _waitTimeSpinBox->value());
361 settings.setValue("outFile", _outFileLineEdit->text());
362 settings.setValue("outPort", _outPortLineEdit->text());
363 settings.setValue("rnxPath", _rnxPathLineEdit->text());
364 settings.setValue("rnxScript", _rnxScrpLineEdit->text());
365 settings.setValue("rnxIntr", _rnxIntrComboBox->currentText());
366 settings.setValue("rnxSampl", _rnxSamplSpinBox->value());
367 settings.setValue("rnxSkel", _rnxSkelLineEdit->text());
368 settings.setValue("rnxAppend", _rnxAppendCheckBox->checkState());
369 settings.setValue("logFile", _logFileLineEdit->text());
370
371 QStringList mountPoints;
372
373 for (int iRow = 0; iRow < _mountPointsTable->rowCount(); iRow++) {
374 QUrl url( "//" + _mountPointsTable->item(iRow, 0)->text() +
375 "@" + _mountPointsTable->item(iRow, 1)->text() );
376
377 mountPoints.append(url.toString() + " " +
378 _mountPointsTable->item(iRow, 2)->text());
379 }
380 settings.setValue("mountPoints", mountPoints);
381}
382
383// All get slots terminated
384////////////////////////////////////////////////////////////////////////////
385void bncWindow::slotGetThreadErrors() {
386 slotMessage("All Get Threads Terminated");
387 ((bncApp*)qApp)->slotMessage("All Get Threads Terminated");
388 _actAddMountPoints->setEnabled(true);
389 _actGetData->setEnabled(true);
390}
391
392// Retrieve Data
393////////////////////////////////////////////////////////////////////////////
394void bncWindow::slotGetData() {
395 slotSaveOptions();
396
397 _actAddMountPoints->setEnabled(false);
398 _actDeleteMountPoints->setEnabled(false);
399 _actGetData->setEnabled(false);
400 _actStop->setEnabled(true);
401
402 _global_caster = new bncCaster(_outFileLineEdit->text(),
403 _outPortLineEdit->text().toInt());
404
405 connect(_global_caster, SIGNAL(getThreadErrors()),
406 this, SLOT(slotGetThreadErrors()));
407
408 connect(_global_caster, SIGNAL(newMessage(const QByteArray&)),
409 this, SLOT(slotMessage(const QByteArray&)));
410 connect(_global_caster, SIGNAL(newMessage(const QByteArray&)),
411 (bncApp*)qApp, SLOT(slotMessage(const QByteArray&)));
412
413 slotMessage("============ Start BNC ============");
414 ((bncApp*)qApp)->slotMessage("============ Start BNC ============");
415
416 for (int iRow = 0; iRow < _mountPointsTable->rowCount(); iRow++) {
417 QUrl url( "//" + _mountPointsTable->item(iRow, 0)->text() +
418 "@" + _mountPointsTable->item(iRow, 1)->text() );
419
420 QByteArray format = _mountPointsTable->item(iRow, 2)->text().toAscii();
421
422 bncGetThread* getThread = new bncGetThread(url, format, iRow);
423
424 connect(getThread, SIGNAL(newMessage(const QByteArray&)),
425 this, SLOT(slotMessage(const QByteArray&)));
426 connect(getThread, SIGNAL(newMessage(const QByteArray&)),
427 (bncApp*)qApp, SLOT(slotMessage(const QByteArray&)));
428
429 connect(getThread, SIGNAL(newObs(const QByteArray&, Observation*)),
430 (bncTableItem*) _mountPointsTable->item(iRow, 3),
431 SLOT(slotNewObs(const QByteArray&, Observation*)));
432
433 _global_caster->addGetThread(getThread);
434
435 getThread->start();
436#ifndef WIN32
437 usleep(100000); // sleep 0.1 sec
438#endif
439 }
440}
441
442// Retrieve Data
443////////////////////////////////////////////////////////////////////////////
444void bncWindow::slotStop() {
445 int iRet = QMessageBox::question(this, "Stop", "Stop retrieving data?",
446 QMessageBox::Yes, QMessageBox::No,
447 QMessageBox::NoButton);
448 if (iRet == QMessageBox::Yes) {
449 delete _global_caster; _global_caster = 0;
450 _actGetData->setEnabled(true);
451 _actStop->setEnabled(false);
452 _actAddMountPoints->setEnabled(true);
453 }
454}
455
456// Close Application gracefully
457////////////////////////////////////////////////////////////////////////////
458void bncWindow::closeEvent(QCloseEvent* event) {
459
460 int iRet = QMessageBox::question(this, "Close", "Save Options?",
461 QMessageBox::Yes, QMessageBox::No,
462 QMessageBox::Cancel);
463
464 if (iRet == QMessageBox::Cancel) {
465 event->ignore();
466 return;
467 }
468 else if (iRet == QMessageBox::Yes) {
469 slotSaveOptions();
470 }
471
472 return QMainWindow::closeEvent(event);
473}
474
475// User changed the selection of mountPoints
476////////////////////////////////////////////////////////////////////////////
477void bncWindow::slotSelectionChanged() {
478 if (_mountPointsTable->selectedItems().isEmpty()) {
479 _actDeleteMountPoints->setEnabled(false);
480 }
481 else {
482 _actDeleteMountPoints->setEnabled(true);
483 }
484}
485
486// Display Program Messages
487////////////////////////////////////////////////////////////////////////////
488void bncWindow::slotMessage(const QByteArray& msg) {
489
490 const int maxBufferSize = 10000;
491
492 QString txt = _log->toPlainText() + "\n" +
493 QTime::currentTime().toString("hh:mm:ss ") + msg;
494 _log->clear();
495 _log->append(txt.right(maxBufferSize));
496}
497
498// About Message
499////////////////////////////////////////////////////////////////////////////
500void bncWindow::slotAbout() {
501
502 QTextBrowser* tb = new QTextBrowser;
503 QUrl url; url.setPath(":bncabout.html");
504 tb->setSource(url);
505 tb->setReadOnly(true);
506
507 QDialog dlg(this);
508
509 QGridLayout* dlgLayout = new QGridLayout();
510 QLabel* img = new QLabel();
511 img->setPixmap(QPixmap(":ntrip-logo.png"));
512 dlgLayout->addWidget(img, 0,0);
513 dlgLayout->addWidget(new QLabel("BKG NTRIP Client (BNC), Version 1.0b"), 0,1);
514 dlgLayout->addWidget(tb,1,0,1,2);
515
516 dlg.setLayout(dlgLayout);
517 int ww = QFontMetrics(font()).width('w');
518 dlg.resize(60*ww, 60*ww);
519 dlg.exec();
520}
521
522// Help Window
523////////////////////////////////////////////////////////////////////////////
524void bncWindow::slotHelp() {
525 QUrl url;
526 url.setPath(":bnchelp.html");
527 new bncHlpDlg(this, url);
528}
529
530// Select Fonts
531////////////////////////////////////////////////////////////////////////////
532void bncWindow::slotFontSel() {
533 bool ok;
534 QFont newFont = QFontDialog::getFont(&ok, this->font(), this);
535 if (ok) {
536 QSettings settings;
537 settings.setValue("font", newFont.toString());
538 QApplication::setFont(newFont);
539 int ww = QFontMetrics(newFont).width('w');
540 setMinimumSize(60*ww, 80*ww);
541 resize(60*ww, 80*ww);
542 }
543}
Note: See TracBrowser for help on using the repository browser.