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

Last change on this file since 201 was 199, checked in by weber, 18 years ago

* empty log message *

File size: 17.4 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);
[199]137 _mountPointsTable->horizontalHeader()->setResizeMode(QHeaderView::Interactive);
138 _mountPointsTable->setHorizontalHeaderLabels(labels);
139// _mountPointsTable->horizontalHeader()->hide();
[35]140 _mountPointsTable->verticalHeader()->hide();
[115]141 _mountPointsTable->setGridStyle(Qt::NoPen);
142 _mountPointsTable->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
[35]143 _mountPointsTable->setSelectionMode(QAbstractItemView::ExtendedSelection);
144 _mountPointsTable->setSelectionBehavior(QAbstractItemView::SelectRows);
145 QListIterator<QString> it(settings.value("mountPoints").toStringList());
146 if (!it.hasNext()) {
147 _actGetData->setEnabled(false);
148 }
149 int iRow = 0;
150 while (it.hasNext()) {
[59]151 QStringList hlp = it.next().split(" ");
[83]152 if (hlp.size() <= 1) continue;
[35]153 _mountPointsTable->insertRow(iRow);
[110]154
155 QUrl url(hlp[0]);
156
157 QString fullPath = url.host() + QString(":%1").arg(url.port()) + url.path();
158 QString format(hlp[1]);
159
160 QTableWidgetItem* it;
161 it = new QTableWidgetItem(url.userInfo());
[115]162 it->setFlags(it->flags() & ~Qt::ItemIsEditable);
[110]163 _mountPointsTable->setItem(iRow, 0, it);
164
165 it = new QTableWidgetItem(fullPath);
[115]166 it->setFlags(it->flags() & ~Qt::ItemIsEditable);
[110]167 _mountPointsTable->setItem(iRow, 1, it);
168
169 it = new QTableWidgetItem(format);
170 _mountPointsTable->setItem(iRow, 2, it);
[184]171
172 bncTableItem* bncIt = new bncTableItem();
173 _mountPointsTable->setItem(iRow, 3, bncIt);
174
[35]175 iRow++;
176 }
[111]177 _mountPointsTable->hideColumn(0);
[110]178 _mountPointsTable->sortItems(1);
[35]179
[83]180 connect(_mountPointsTable, SIGNAL(itemSelectionChanged()),
181 SLOT(slotSelectionChanged()));
[35]182
[83]183 _log = new QTextEdit();
184 _log->setReadOnly(true);
[35]185
[199]186 layout->addWidget(new QLabel("Proxy host"), 0, 0, 1, 2);
187 layout->addWidget(_proxyHostLineEdit, 0, 2);
188 layout->addWidget(new QLabel("Proxy port"), 0, 3);
189 layout->addWidget(_proxyPortLineEdit, 0, 4);
[143]190
191 layout->addWidget(new QLabel("Wait for full epoch"), 1, 0, 1, 2);
[135]192 layout->addWidget(_waitTimeSpinBox, 1, 2);
[143]193
194 layout->addWidget(new QLabel("ASCII output file (full path)"), 2, 0, 1, 2);
[106]195 layout->addWidget(_outFileLineEdit, 2, 2, 1, 3);
[143]196
197 layout->addWidget(new QLabel("Port for binary output"), 3, 0, 1, 2);
[106]198 layout->addWidget(_outPortLineEdit, 3, 2);
[143]199
[199]200 layout->addWidget(new QLabel("RINEX directory path"), 4, 0, 1, 2);
[106]201 layout->addWidget(_rnxPathLineEdit, 4, 2, 1, 3);
[143]202
203 layout->addWidget(new QLabel("RINEX script (full path)"), 5, 0, 1, 2);
[106]204 layout->addWidget(_rnxScrpLineEdit, 5, 2, 1, 3);
[143]205
206 layout->addWidget(new QLabel("RINEX file interval"), 6, 0, 1, 2);
[106]207 layout->addWidget(_rnxIntrComboBox, 6, 2);
[143]208 layout->addWidget(new QLabel("Sampling"), 6, 3);
[106]209 layout->addWidget(_rnxSamplSpinBox, 6, 4);
210
[143]211 layout->addWidget(new QLabel("RINEX skeleton extension"), 7, 0, 1, 2);
[106]212 layout->addWidget(_rnxSkelLineEdit, 7, 2);
213
[143]214 layout->addWidget(new QLabel("Mountpoints"), 8, 0, 1, 2);
215 layout->addWidget(_mountPointsTable, 9, 0, 1, 5);
216
[199]217 layout->addWidget(new QLabel("Log file (full path)"), 10, 0, 1, 2);
[143]218 layout->addWidget(_logFileLineEdit, 10, 2, 1, 3);
219 layout->addWidget(_log, 11, 0, 1, 5);
220
[35]221 _bncCaster = 0;
222}
223
224// Destructor
225////////////////////////////////////////////////////////////////////////////
226bncWindow::~bncWindow() {
227}
228
229// Retrieve Table
230////////////////////////////////////////////////////////////////////////////
231void bncWindow::slotAddMountPoints() {
[101]232
233 QSettings settings;
234 QString proxyHost = settings.value("proxyHost").toString();
235 int proxyPort = settings.value("proxyPort").toInt();
236 if (proxyHost != _proxyHostLineEdit->text() ||
237 proxyPort != _proxyPortLineEdit->text().toInt()) {
[102]238 int iRet = QMessageBox::question(this, "Question", "Proxy options "
[101]239 "changed. Use the new ones?",
240 QMessageBox::Yes, QMessageBox::No,
241 QMessageBox::NoButton);
242 if (iRet == QMessageBox::Yes) {
243 settings.setValue("proxyHost", _proxyHostLineEdit->text());
244 settings.setValue("proxyPort", _proxyPortLineEdit->text());
245 }
246 }
247
[90]248 bncTableDlg* dlg = new bncTableDlg(this);
[83]249 dlg->move(this->pos().x()+50, this->pos().y()+50);
[35]250 connect(dlg, SIGNAL(newMountPoints(QStringList*)),
251 this, SLOT(slotNewMountPoints(QStringList*)));
252 dlg->exec();
253 delete dlg;
254
255}
256
257// Delete Selected Mount Points
258////////////////////////////////////////////////////////////////////////////
259void bncWindow::slotDeleteMountPoints() {
[117]260
261 int nRows = _mountPointsTable->rowCount();
262 bool flg[nRows];
263 for (int iRow = 0; iRow < nRows; iRow++) {
[116]264 if (_mountPointsTable->isItemSelected(_mountPointsTable->item(iRow,1))) {
[117]265 flg[iRow] = true;
266 }
267 else {
268 flg[iRow] = false;
269 }
270 }
271 for (int iRow = nRows-1; iRow >= 0; iRow--) {
272 if (flg[iRow]) {
[116]273 _mountPointsTable->removeRow(iRow);
[83]274 }
275 }
276 _actDeleteMountPoints->setEnabled(false);
[183]277
278 if (_mountPointsTable->rowCount() == 0) {
279 _actGetData->setEnabled(false);
280 }
[35]281}
282
283// New Mount Points Selected
284////////////////////////////////////////////////////////////////////////////
285void bncWindow::slotNewMountPoints(QStringList* mountPoints) {
286 int iRow = 0;
287 QListIterator<QString> it(*mountPoints);
288 while (it.hasNext()) {
[59]289 QStringList hlp = it.next().split(" ");
[110]290 QUrl url(hlp[0]);
291 QString fullPath = url.host() + QString(":%1").arg(url.port()) + url.path();
292 QString format(hlp[1]);
293
[35]294 _mountPointsTable->insertRow(iRow);
[110]295
296 QTableWidgetItem* it;
297 it = new QTableWidgetItem(url.userInfo());
[115]298 it->setFlags(it->flags() & ~Qt::ItemIsEditable);
[110]299 _mountPointsTable->setItem(iRow, 0, it);
300
301 it = new QTableWidgetItem(fullPath);
[115]302 it->setFlags(it->flags() & ~Qt::ItemIsEditable);
[110]303 _mountPointsTable->setItem(iRow, 1, it);
304
305 it = new QTableWidgetItem(format);
306 _mountPointsTable->setItem(iRow, 2, it);
[184]307
308 bncTableItem* bncIt = new bncTableItem();
309 _mountPointsTable->setItem(iRow, 3, bncIt);
310
[35]311 iRow++;
312 }
[111]313 _mountPointsTable->hideColumn(0);
[110]314 _mountPointsTable->sortItems(1);
[35]315 if (mountPoints->count() > 0) {
316 _actGetData->setEnabled(true);
317 }
318 delete mountPoints;
319}
320
321// Save Options
322////////////////////////////////////////////////////////////////////////////
323void bncWindow::slotSaveOptions() {
324 QSettings settings;
325 settings.setValue("proxyHost", _proxyHostLineEdit->text());
326 settings.setValue("proxyPort", _proxyPortLineEdit->text());
[135]327 settings.setValue("waitTime", _waitTimeSpinBox->value());
[35]328 settings.setValue("outFile", _outFileLineEdit->text());
329 settings.setValue("outPort", _outPortLineEdit->text());
[83]330 settings.setValue("rnxPath", _rnxPathLineEdit->text());
[106]331 settings.setValue("rnxScript", _rnxScrpLineEdit->text());
332 settings.setValue("rnxIntr", _rnxIntrComboBox->currentText());
333 settings.setValue("rnxSampl", _rnxSamplSpinBox->value());
[83]334 settings.setValue("rnxSkel", _rnxSkelLineEdit->text());
[143]335 settings.setValue("logFile", _logFileLineEdit->text());
[110]336
[35]337 QStringList mountPoints;
[110]338
[35]339 for (int iRow = 0; iRow < _mountPointsTable->rowCount(); iRow++) {
[112]340 QUrl url( "//" + _mountPointsTable->item(iRow, 0)->text() +
341 "@" + _mountPointsTable->item(iRow, 1)->text() );
[110]342
343 mountPoints.append(url.toString() + " " +
344 _mountPointsTable->item(iRow, 2)->text());
[35]345 }
346 settings.setValue("mountPoints", mountPoints);
347}
348
349// All get slots terminated
350////////////////////////////////////////////////////////////////////////////
351void bncWindow::slotGetThreadErrors() {
[83]352 slotMessage("All Get Threads Terminated");
[149]353 ((bncApp*)qApp)->slotMessage("All Get Threads Terminated");
[35]354 _actAddMountPoints->setEnabled(true);
355 _actGetData->setEnabled(true);
356}
357
358// Retrieve Data
359////////////////////////////////////////////////////////////////////////////
360void bncWindow::slotGetData() {
[128]361 slotSaveOptions();
362
[35]363 _actAddMountPoints->setEnabled(false);
364 _actDeleteMountPoints->setEnabled(false);
365 _actGetData->setEnabled(false);
[182]366 _actStop->setEnabled(true);
[35]367
368 _bncCaster = new bncCaster(_outFileLineEdit->text(),
369 _outPortLineEdit->text().toInt());
370
371 connect(_bncCaster, SIGNAL(getThreadErrors()),
372 this, SLOT(slotGetThreadErrors()));
373
[83]374 connect(_bncCaster, SIGNAL(newMessage(const QByteArray&)),
375 this, SLOT(slotMessage(const QByteArray&)));
[149]376 connect(_bncCaster, SIGNAL(newMessage(const QByteArray&)),
377 (bncApp*)qApp, SLOT(slotMessage(const QByteArray&)));
[83]378
[35]379 _bncCaster->start();
380
381 for (int iRow = 0; iRow < _mountPointsTable->rowCount(); iRow++) {
[112]382 QUrl url( "//" + _mountPointsTable->item(iRow, 0)->text() +
383 "@" + _mountPointsTable->item(iRow, 1)->text() );
[110]384
[111]385 QByteArray format = _mountPointsTable->item(iRow, 2)->text().toAscii();
[35]386
[88]387 bncGetThread* getThread = new bncGetThread(url, format);
[83]388
389 connect(getThread, SIGNAL(newMessage(const QByteArray&)),
390 this, SLOT(slotMessage(const QByteArray&)));
[149]391 connect(getThread, SIGNAL(newMessage(const QByteArray&)),
392 (bncApp*)qApp, SLOT(slotMessage(const QByteArray&)));
[83]393
[184]394 connect(getThread, SIGNAL(newObs(const QByteArray&, Observation*)),
395 (bncTableItem*) _mountPointsTable->item(iRow, 3),
396 SLOT(slotNewObs(const QByteArray&, Observation*)));
397
[35]398 _bncCaster->addGetThread(getThread);
399
400 getThread->start();
401 }
402}
[83]403
[182]404// Retrieve Data
405////////////////////////////////////////////////////////////////////////////
406void bncWindow::slotStop() {
407 int iRet = QMessageBox::question(this, "Stop", "Stop retrieving data?",
408 QMessageBox::Yes, QMessageBox::No,
409 QMessageBox::NoButton);
410 if (iRet == QMessageBox::Yes) {
411 _bncCaster->terminate();
[188]412 _bncCaster->wait();
[182]413 delete _bncCaster;
414 _bncCaster = 0;
415 _actGetData->setEnabled(true);
416 _actStop->setEnabled(false);
[183]417 _actAddMountPoints->setEnabled(true);
[182]418 }
419}
420
[83]421// Close Application gracefully
422////////////////////////////////////////////////////////////////////////////
423void bncWindow::closeEvent(QCloseEvent* event) {
424
425 int iRet = QMessageBox::question(this, "Close", "Save Options?",
426 QMessageBox::Yes, QMessageBox::No,
427 QMessageBox::Cancel);
428
429 if (iRet == QMessageBox::Cancel) {
430 event->ignore();
431 return;
432 }
433 else if (iRet == QMessageBox::Yes) {
434 slotSaveOptions();
435 }
436
437 return QMainWindow::closeEvent(event);
438}
439
440// User changed the selection of mountPoints
441////////////////////////////////////////////////////////////////////////////
442void bncWindow::slotSelectionChanged() {
443 if (_mountPointsTable->selectedItems().isEmpty()) {
444 _actDeleteMountPoints->setEnabled(false);
445 }
446 else {
447 _actDeleteMountPoints->setEnabled(true);
448 }
449}
450
451// Display Program Messages
452////////////////////////////////////////////////////////////////////////////
453void bncWindow::slotMessage(const QByteArray& msg) {
454
455 const int maxBufferSize = 10000;
456
[189]457 QString txt = _log->toPlainText() + "\n" +
458 QTime::currentTime().toString("hh:mm:ss ") + msg;
[83]459 _log->clear();
460 _log->append(txt.right(maxBufferSize));
461}
462
[108]463// About Message
464////////////////////////////////////////////////////////////////////////////
465void bncWindow::slotAbout() {
466
[161]467 QTextBrowser* tb = new QTextBrowser;
[169]468 QUrl url; url.setPath(":bncabout.html");
469 tb->setSource(url);
[161]470 tb->setReadOnly(true);
[142]471
[161]472 QDialog dlg(this);
[142]473
[164]474 QGridLayout* dlgLayout = new QGridLayout();
475 QLabel* img = new QLabel();
[173]476 img->setPixmap(QPixmap(":ntrip-logo.png"));
[164]477 dlgLayout->addWidget(img, 0,0);
478 dlgLayout->addWidget(new QLabel("BKG NTRIP Client (BNC), Version 1.0"), 0,1);
479 dlgLayout->addWidget(tb,1,0,1,2);
[161]480
481 dlg.setLayout(dlgLayout);
482 int ww = QFontMetrics(font()).width('w');
483 dlg.resize(60*ww, 60*ww);
484 dlg.exec();
[108]485}
486
487// Help Window
488////////////////////////////////////////////////////////////////////////////
489void bncWindow::slotHelp() {
[177]490 QUrl url;
491 url.setPath(":bnchelp.html");
492 new bncHlpDlg(this, url);
[108]493}
[110]494
495// Select Fonts
496////////////////////////////////////////////////////////////////////////////
497void bncWindow::slotFontSel() {
498 bool ok;
499 QFont newFont = QFontDialog::getFont(&ok, this->font(), this);
500 if (ok) {
[113]501 QSettings settings;
502 settings.setValue("font", newFont.toString());
[110]503 QApplication::setFont(newFont);
[113]504 int ww = QFontMetrics(newFont).width('w');
[152]505 setMinimumSize(60*ww, 80*ww);
506 resize(60*ww, 80*ww);
[110]507 }
508}
Note: See TracBrowser for help on using the repository browser.