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

Last change on this file since 233 was 233, checked in by mervart, 18 years ago

* empty log message *

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