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
Line 
1
2/* -------------------------------------------------------------------------
3 * BKG NTRIP Client
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"
19#include "bncapp.h"
20#include "bncgetthread.h"
21#include "bnctabledlg.h"
22#include "bnchlpdlg.h"
23#include "bnchtml.h"
24#include "bnctableitem.h"
25
26using namespace std;
27
28// Constructor
29////////////////////////////////////////////////////////////////////////////
30bncWindow::bncWindow() {
31
32 int ww = QFontMetrics(this->font()).width('w');
33
34 static const QStringList labels = QString("account,mountpoint,"
35 "decoder,bytes").split(",");
36
37 setMinimumSize(60*ww, 80*ww);
38
39 // Create Actions
40 // --------------
41 _actHelp = new QAction(tr("&Help Contents"),this);
42 connect(_actHelp, SIGNAL(triggered()), SLOT(slotHelp()));
43
44 _actAbout = new QAction(tr("&About BNC"),this);
45 connect(_actAbout, SIGNAL(triggered()), SLOT(slotAbout()));
46
47 _actFontSel = new QAction(tr("Select &Fonts"),this);
48 connect(_actFontSel, SIGNAL(triggered()), SLOT(slotFontSel()));
49
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
56 _actAddMountPoints = new QAction(tr("Add &Mountpoints"),this);
57 connect(_actAddMountPoints, SIGNAL(triggered()), SLOT(slotAddMountPoints()));
58
59 _actDeleteMountPoints = new QAction(tr("&Delete Mountpoints"),this);
60 connect(_actDeleteMountPoints, SIGNAL(triggered()), SLOT(slotDeleteMountPoints()));
61 _actDeleteMountPoints->setEnabled(false);
62
63 _actGetData = new QAction(tr("Sta&rt"),this);
64 connect(_actGetData, SIGNAL(triggered()), SLOT(slotGetData()));
65
66 _actStop = new QAction(tr("Sto&p"),this);
67 connect(_actStop, SIGNAL(triggered()), SLOT(slotStop()));
68 _actStop->setEnabled(false);
69
70 // Create Menus
71 // ------------
72 _menuFile = menuBar()->addMenu(tr("&File"));
73 _menuFile->addAction(_actFontSel);
74 _menuFile->addSeparator();
75 _menuFile->addAction(_actSaveOpt);
76 _menuFile->addSeparator();
77 _menuFile->addAction(_actQuit);
78
79 _menuHlp = menuBar()->addMenu(tr("&Help"));
80 _menuHlp->addAction(_actHelp);
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);
91 toolBar->addAction(_actStop);
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());
103 _proxyHostLineEdit->setMaximumWidth(12*ww);
104 _proxyPortLineEdit = new QLineEdit(settings.value("proxyPort").toString());
105 _proxyPortLineEdit->setMaximumWidth(9*ww);
106 _waitTimeSpinBox = new QSpinBox();
107 _waitTimeSpinBox->setMinimum(1);
108 _waitTimeSpinBox->setMaximum(30);
109 _waitTimeSpinBox->setSingleStep(1);
110 _waitTimeSpinBox->setSuffix(" sec");
111 _waitTimeSpinBox->setMaximumWidth(9*ww);
112 _waitTimeSpinBox->setValue(settings.value("waitTime").toInt());
113 _outFileLineEdit = new QLineEdit(settings.value("outFile").toString());
114 _outPortLineEdit = new QLineEdit(settings.value("outPort").toString());
115 _outPortLineEdit->setMaximumWidth(9*ww);
116 _rnxPathLineEdit = new QLineEdit(settings.value("rnxPath").toString());
117 _rnxScrpLineEdit = new QLineEdit(settings.value("rnxScript").toString());
118 _rnxSkelLineEdit = new QLineEdit(settings.value("rnxSkel").toString());
119 _rnxSkelLineEdit->setMaximumWidth(5*ww);
120 _rnxIntrComboBox = new QComboBox();
121 _rnxIntrComboBox->setMaximumWidth(9*ww);
122 _rnxIntrComboBox->setEditable(false);
123 _rnxIntrComboBox->addItems(QString("5 min,10 min,15 min,30 min,1 hour,1 day").split(","));
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);
132 _rnxSamplSpinBox->setMaximumWidth(9*ww);
133 _rnxSamplSpinBox->setValue(settings.value("rnxSampl").toInt());
134 _rnxSamplSpinBox->setSuffix(" sec");
135 _logFileLineEdit = new QLineEdit(settings.value("logFile").toString());
136 _mountPointsTable = new QTableWidget(0,4);
137 _mountPointsTable->horizontalHeader()->resizeSection(1,25*ww);
138 _mountPointsTable->horizontalHeader()->setResizeMode(QHeaderView::Interactive);
139 _mountPointsTable->horizontalHeader()->setStretchLastSection(true);
140 _mountPointsTable->setHorizontalHeaderLabels(labels);
141// _mountPointsTable->horizontalHeader()->hide();
142 _mountPointsTable->verticalHeader()->hide();
143 _mountPointsTable->setGridStyle(Qt::NoPen);
144 _mountPointsTable->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
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()) {
153 QStringList hlp = it.next().split(" ");
154 if (hlp.size() <= 1) continue;
155 _mountPointsTable->insertRow(iRow);
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());
164 it->setFlags(it->flags() & ~Qt::ItemIsEditable);
165 _mountPointsTable->setItem(iRow, 0, it);
166
167 it = new QTableWidgetItem(fullPath);
168 it->setFlags(it->flags() & ~Qt::ItemIsEditable);
169 _mountPointsTable->setItem(iRow, 1, it);
170
171 it = new QTableWidgetItem(format);
172 _mountPointsTable->setItem(iRow, 2, it);
173
174 bncTableItem* bncIt = new bncTableItem();
175 _mountPointsTable->setItem(iRow, 3, bncIt);
176
177 iRow++;
178 }
179 _mountPointsTable->hideColumn(0);
180 _mountPointsTable->sortItems(1);
181
182 connect(_mountPointsTable, SIGNAL(itemSelectionChanged()),
183 SLOT(slotSelectionChanged()));
184
185 _log = new QTextEdit();
186 _log->setReadOnly(true);
187
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);
192
193 layout->addWidget(new QLabel("Wait for full epoch"), 1, 0, 1, 2);
194 layout->addWidget(_waitTimeSpinBox, 1, 2);
195
196 layout->addWidget(new QLabel("ASCII output file (full path)"), 2, 0, 1, 2);
197 layout->addWidget(_outFileLineEdit, 2, 2, 1, 3);
198
199 layout->addWidget(new QLabel("Port for binary output"), 3, 0, 1, 2);
200 layout->addWidget(_outPortLineEdit, 3, 2);
201
202 layout->addWidget(new QLabel("RINEX directory path"), 4, 0, 1, 2);
203 layout->addWidget(_rnxPathLineEdit, 4, 2, 1, 3);
204
205 layout->addWidget(new QLabel("RINEX script (full path)"), 5, 0, 1, 2);
206 layout->addWidget(_rnxScrpLineEdit, 5, 2, 1, 3);
207
208 layout->addWidget(new QLabel("RINEX file interval"), 6, 0, 1, 2);
209 layout->addWidget(_rnxIntrComboBox, 6, 2);
210 layout->addWidget(new QLabel("Sampling"), 6, 3);
211 layout->addWidget(_rnxSamplSpinBox, 6, 4);
212
213 layout->addWidget(new QLabel("RINEX skeleton extension"), 7, 0, 1, 2);
214 layout->addWidget(_rnxSkelLineEdit, 7, 2);
215
216 layout->addWidget(new QLabel("Mountpoints"), 8, 0, 1, 2);
217 layout->addWidget(_mountPointsTable, 9, 0, 1, 5);
218
219 layout->addWidget(new QLabel("Log file (full path)"), 10, 0, 1, 2);
220 layout->addWidget(_logFileLineEdit, 10, 2, 1, 3);
221 layout->addWidget(_log, 11, 0, 1, 5);
222
223 _bncCaster = 0;
224}
225
226// Destructor
227////////////////////////////////////////////////////////////////////////////
228bncWindow::~bncWindow() {
229}
230
231// Retrieve Table
232////////////////////////////////////////////////////////////////////////////
233void bncWindow::slotAddMountPoints() {
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()) {
240 int iRet = QMessageBox::question(this, "Question", "Proxy options "
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
250 bncTableDlg* dlg = new bncTableDlg(this);
251 dlg->move(this->pos().x()+50, this->pos().y()+50);
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() {
262
263 int nRows = _mountPointsTable->rowCount();
264 bool flg[nRows];
265 for (int iRow = 0; iRow < nRows; iRow++) {
266 if (_mountPointsTable->isItemSelected(_mountPointsTable->item(iRow,1))) {
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]) {
275 _mountPointsTable->removeRow(iRow);
276 }
277 }
278 _actDeleteMountPoints->setEnabled(false);
279
280 if (_mountPointsTable->rowCount() == 0) {
281 _actGetData->setEnabled(false);
282 }
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()) {
291 QStringList hlp = it.next().split(" ");
292 QUrl url(hlp[0]);
293 QString fullPath = url.host() + QString(":%1").arg(url.port()) + url.path();
294 QString format(hlp[1]);
295
296 _mountPointsTable->insertRow(iRow);
297
298 QTableWidgetItem* it;
299 it = new QTableWidgetItem(url.userInfo());
300 it->setFlags(it->flags() & ~Qt::ItemIsEditable);
301 _mountPointsTable->setItem(iRow, 0, it);
302
303 it = new QTableWidgetItem(fullPath);
304 it->setFlags(it->flags() & ~Qt::ItemIsEditable);
305 _mountPointsTable->setItem(iRow, 1, it);
306
307 it = new QTableWidgetItem(format);
308 _mountPointsTable->setItem(iRow, 2, it);
309
310 bncTableItem* bncIt = new bncTableItem();
311 _mountPointsTable->setItem(iRow, 3, bncIt);
312
313 iRow++;
314 }
315 _mountPointsTable->hideColumn(0);
316 _mountPointsTable->sortItems(1);
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());
329 settings.setValue("waitTime", _waitTimeSpinBox->value());
330 settings.setValue("outFile", _outFileLineEdit->text());
331 settings.setValue("outPort", _outPortLineEdit->text());
332 settings.setValue("rnxPath", _rnxPathLineEdit->text());
333 settings.setValue("rnxScript", _rnxScrpLineEdit->text());
334 settings.setValue("rnxIntr", _rnxIntrComboBox->currentText());
335 settings.setValue("rnxSampl", _rnxSamplSpinBox->value());
336 settings.setValue("rnxSkel", _rnxSkelLineEdit->text());
337 settings.setValue("logFile", _logFileLineEdit->text());
338
339 QStringList mountPoints;
340
341 for (int iRow = 0; iRow < _mountPointsTable->rowCount(); iRow++) {
342 QUrl url( "//" + _mountPointsTable->item(iRow, 0)->text() +
343 "@" + _mountPointsTable->item(iRow, 1)->text() );
344
345 mountPoints.append(url.toString() + " " +
346 _mountPointsTable->item(iRow, 2)->text());
347 }
348 settings.setValue("mountPoints", mountPoints);
349}
350
351// All get slots terminated
352////////////////////////////////////////////////////////////////////////////
353void bncWindow::slotGetThreadErrors() {
354 slotMessage("All Get Threads Terminated");
355 ((bncApp*)qApp)->slotMessage("All Get Threads Terminated");
356 _actAddMountPoints->setEnabled(true);
357 _actGetData->setEnabled(true);
358}
359
360// Retrieve Data
361////////////////////////////////////////////////////////////////////////////
362void bncWindow::slotGetData() {
363 slotSaveOptions();
364
365 _actAddMountPoints->setEnabled(false);
366 _actDeleteMountPoints->setEnabled(false);
367 _actGetData->setEnabled(false);
368 _actStop->setEnabled(true);
369
370 _bncCaster = new bncCaster(_outFileLineEdit->text(),
371 _outPortLineEdit->text().toInt());
372
373 connect(_bncCaster, SIGNAL(getThreadErrors()),
374 this, SLOT(slotGetThreadErrors()));
375
376 connect(_bncCaster, SIGNAL(newMessage(const QByteArray&)),
377 this, SLOT(slotMessage(const QByteArray&)));
378 connect(_bncCaster, SIGNAL(newMessage(const QByteArray&)),
379 (bncApp*)qApp, SLOT(slotMessage(const QByteArray&)));
380
381 _bncCaster->start();
382
383 for (int iRow = 0; iRow < _mountPointsTable->rowCount(); iRow++) {
384 QUrl url( "//" + _mountPointsTable->item(iRow, 0)->text() +
385 "@" + _mountPointsTable->item(iRow, 1)->text() );
386
387 QByteArray format = _mountPointsTable->item(iRow, 2)->text().toAscii();
388
389 bncGetThread* getThread = new bncGetThread(url, format);
390
391 connect(getThread, SIGNAL(newMessage(const QByteArray&)),
392 this, SLOT(slotMessage(const QByteArray&)));
393 connect(getThread, SIGNAL(newMessage(const QByteArray&)),
394 (bncApp*)qApp, SLOT(slotMessage(const QByteArray&)));
395
396 connect(getThread, SIGNAL(newObs(const QByteArray&, Observation*)),
397 (bncTableItem*) _mountPointsTable->item(iRow, 3),
398 SLOT(slotNewObs(const QByteArray&, Observation*)));
399
400 _bncCaster->addGetThread(getThread);
401
402 getThread->start();
403 }
404}
405
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();
414 _bncCaster->wait();
415 delete _bncCaster;
416 _bncCaster = 0;
417 _actGetData->setEnabled(true);
418 _actStop->setEnabled(false);
419 _actAddMountPoints->setEnabled(true);
420 }
421}
422
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
459 QString txt = _log->toPlainText() + "\n" +
460 QTime::currentTime().toString("hh:mm:ss ") + msg;
461 _log->clear();
462 _log->append(txt.right(maxBufferSize));
463}
464
465// About Message
466////////////////////////////////////////////////////////////////////////////
467void bncWindow::slotAbout() {
468
469 QTextBrowser* tb = new QTextBrowser;
470 QUrl url; url.setPath(":bncabout.html");
471 tb->setSource(url);
472 tb->setReadOnly(true);
473
474 QDialog dlg(this);
475
476 QGridLayout* dlgLayout = new QGridLayout();
477 QLabel* img = new QLabel();
478 img->setPixmap(QPixmap(":ntrip-logo.png"));
479 dlgLayout->addWidget(img, 0,0);
480 dlgLayout->addWidget(new QLabel("BKG NTRIP Client (BNC), Version 1.0b"), 0,1);
481 dlgLayout->addWidget(tb,1,0,1,2);
482
483 dlg.setLayout(dlgLayout);
484 int ww = QFontMetrics(font()).width('w');
485 dlg.resize(60*ww, 60*ww);
486 dlg.exec();
487}
488
489// Help Window
490////////////////////////////////////////////////////////////////////////////
491void bncWindow::slotHelp() {
492 QUrl url;
493 url.setPath(":bnchelp.html");
494 new bncHlpDlg(this, url);
495}
496
497// Select Fonts
498////////////////////////////////////////////////////////////////////////////
499void bncWindow::slotFontSel() {
500 bool ok;
501 QFont newFont = QFontDialog::getFont(&ok, this->font(), this);
502 if (ok) {
503 QSettings settings;
504 settings.setValue("font", newFont.toString());
505 QApplication::setFont(newFont);
506 int ww = QFontMetrics(newFont).width('w');
507 setMinimumSize(60*ww, 80*ww);
508 resize(60*ww, 80*ww);
509 }
510}
Note: See TracBrowser for help on using the repository browser.