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

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

* empty log message *

File size: 15.3 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 "bncgetthread.h"
20#include "bnctabledlg.h"
21
22using namespace std;
23
24// Constructor
25////////////////////////////////////////////////////////////////////////////
26bncWindow::bncWindow() {
27
28 int ww = QFontMetrics(this->font()).width('w');
29
30 setMinimumSize(90*ww, 80*ww);
31
32 // Create Actions
33 // --------------
34 _actHelp = new QAction(tr("&Help Contents"),this);
35 connect(_actHelp, SIGNAL(triggered()), SLOT(slotHelp()));
36
37 _actAbout = new QAction(tr("&About BNC"),this);
38 connect(_actAbout, SIGNAL(triggered()), SLOT(slotAbout()));
39
40 _actFontSel = new QAction(tr("Select &Fonts"),this);
41 connect(_actFontSel, SIGNAL(triggered()), SLOT(slotFontSel()));
42
43 _actSaveOpt = new QAction(tr("&Save Options"),this);
44 connect(_actSaveOpt, SIGNAL(triggered()), SLOT(slotSaveOptions()));
45
46 _actQuit = new QAction(tr("&Quit"),this);
47 connect(_actQuit, SIGNAL(triggered()), SLOT(close()));
48
49 _actAddMountPoints = new QAction(tr("&Add Mountpoints"),this);
50 connect(_actAddMountPoints, SIGNAL(triggered()), SLOT(slotAddMountPoints()));
51
52 _actDeleteMountPoints = new QAction(tr("&Delete Mountpoints"),this);
53 connect(_actDeleteMountPoints, SIGNAL(triggered()), SLOT(slotDeleteMountPoints()));
54 _actDeleteMountPoints->setEnabled(false);
55
56 _actGetData = new QAction(tr("&Get Data"),this);
57 connect(_actGetData, SIGNAL(triggered()), SLOT(slotGetData()));
58
59 // Create Menus
60 // ------------
61 _menuFile = menuBar()->addMenu(tr("&File"));
62 _menuFile->addAction(_actFontSel);
63 _menuFile->addSeparator();
64 _menuFile->addAction(_actSaveOpt);
65 _menuFile->addSeparator();
66 _menuFile->addAction(_actQuit);
67
68 _menuHlp = menuBar()->addMenu(tr("&Help"));
69 _menuHlp->addAction(_actHelp);
70 _menuHlp->addAction(_actAbout);
71
72 // Tool (Command) Bar
73 // ------------------
74 QToolBar* toolBar = new QToolBar;
75 addToolBar(Qt::BottomToolBarArea, toolBar);
76 toolBar->setMovable(false);
77 toolBar->addAction(_actAddMountPoints);
78 toolBar->addAction(_actDeleteMountPoints);
79 toolBar->addAction(_actGetData);
80
81 // Canvas with Editable Fields
82 // ---------------------------
83 _canvas = new QWidget;
84 setCentralWidget(_canvas);
85
86 QGridLayout* layout = new QGridLayout;
87 _canvas->setLayout(layout);
88
89 QSettings settings;
90
91 _proxyHostLineEdit = new QLineEdit(settings.value("proxyHost").toString());
92 _proxyHostLineEdit->setMaximumWidth(12*ww);
93 _proxyPortLineEdit = new QLineEdit(settings.value("proxyPort").toString());
94 _proxyPortLineEdit->setMaximumWidth(9*ww);
95 _timeOutLineEdit = new QLineEdit(settings.value("timeOut").toString());
96 _timeOutLineEdit->setMaximumWidth(9*ww);
97 _outFileLineEdit = new QLineEdit(settings.value("outFile").toString());
98 _outPortLineEdit = new QLineEdit(settings.value("outPort").toString());
99 _outPortLineEdit->setMaximumWidth(9*ww);
100 _rnxPathLineEdit = new QLineEdit(settings.value("rnxPath").toString());
101 _rnxScrpLineEdit = new QLineEdit(settings.value("rnxScript").toString());
102 _rnxSkelLineEdit = new QLineEdit(settings.value("rnxSkel").toString());
103 _rnxSkelLineEdit->setMaximumWidth(5*ww);
104 _rnxIntrComboBox = new QComboBox();
105 _rnxIntrComboBox->setMaximumWidth(9*ww);
106 _rnxIntrComboBox->setEditable(false);
107 _rnxIntrComboBox->addItems(QString("15 min,1 hour,1 day").split(","));
108 int ii = _rnxIntrComboBox->findText(settings.value("rnxIntr").toString());
109 if (ii != -1) {
110 _rnxIntrComboBox->setCurrentIndex(ii);
111 }
112 _rnxSamplSpinBox = new QSpinBox();
113 _rnxSamplSpinBox->setMinimum(0);
114 _rnxSamplSpinBox->setMaximum(60);
115 _rnxSamplSpinBox->setSingleStep(5);
116 _rnxSamplSpinBox->setMaximumWidth(9*ww);
117 _rnxSamplSpinBox->setValue(settings.value("rnxSampl").toInt());
118 _mountPointsTable = new QTableWidget(0,3);
119 _mountPointsTable->setMinimumWidth(60*ww);
120 _mountPointsTable->setMaximumHeight(20*ww);
121 _mountPointsTable->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
122 _mountPointsTable->horizontalHeader()->hide();
123 _mountPointsTable->verticalHeader()->hide();
124 _mountPointsTable->setSelectionMode(QAbstractItemView::ExtendedSelection);
125 _mountPointsTable->setSelectionBehavior(QAbstractItemView::SelectRows);
126 QListIterator<QString> it(settings.value("mountPoints").toStringList());
127 if (!it.hasNext()) {
128 _actGetData->setEnabled(false);
129 }
130 int iRow = 0;
131 while (it.hasNext()) {
132 QStringList hlp = it.next().split(" ");
133 if (hlp.size() <= 1) continue;
134 _mountPointsTable->insertRow(iRow);
135
136 QUrl url(hlp[0]);
137
138 QString fullPath = url.host() + QString(":%1").arg(url.port()) + url.path();
139 QString format(hlp[1]);
140
141 QTableWidgetItem* it;
142 it = new QTableWidgetItem(url.userInfo());
143 it->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
144 _mountPointsTable->setItem(iRow, 0, it);
145
146 it = new QTableWidgetItem(fullPath);
147 it->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
148 _mountPointsTable->setItem(iRow, 1, it);
149
150 it = new QTableWidgetItem(format);
151 it->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable);
152 _mountPointsTable->setItem(iRow, 2, it);
153 iRow++;
154 }
155 _mountPointsTable->hideColumn(0);
156 _mountPointsTable->sortItems(1);
157
158 connect(_mountPointsTable, SIGNAL(itemSelectionChanged()),
159 SLOT(slotSelectionChanged()));
160
161 _log = new QTextEdit();
162 _log->setMaximumHeight(120);
163 _log->setReadOnly(true);
164
165 layout->addWidget(new QLabel("Proxy host"), 0, 0);
166 layout->addWidget(_proxyHostLineEdit, 0, 1);
167 layout->addWidget(new QLabel("Proxy port"), 0, 2);
168 layout->addWidget(_proxyPortLineEdit, 0, 3);
169 layout->addWidget(new QLabel("timeout (sec)"), 1, 1);
170 layout->addWidget(_timeOutLineEdit, 1, 2);
171 layout->addWidget(new QLabel("ASCII output file (full path)"), 2, 1);
172 layout->addWidget(_outFileLineEdit, 2, 2, 1, 3);
173 layout->addWidget(new QLabel("port for binary output"), 3, 1);
174 layout->addWidget(_outPortLineEdit, 3, 2);
175 layout->addWidget(new QLabel("RINEX path"), 4, 1);
176 layout->addWidget(_rnxPathLineEdit, 4, 2, 1, 3);
177 layout->addWidget(new QLabel("RINEX script (full path)"), 5, 1);
178 layout->addWidget(_rnxScrpLineEdit, 5, 2, 1, 3);
179 layout->addWidget(new QLabel("RINEX file interval"), 6, 1);
180 layout->addWidget(_rnxIntrComboBox, 6, 2);
181
182 layout->addWidget(new QLabel("sampling (sec)"), 6, 3);
183 layout->addWidget(_rnxSamplSpinBox, 6, 4);
184
185
186 layout->addWidget(new QLabel("RINEX skeleton extension"), 7, 1);
187 layout->addWidget(_rnxSkelLineEdit, 7, 2);
188 layout->addWidget(new QLabel("Mountpoints"), 8, 0);
189 layout->addWidget(_mountPointsTable, 8, 1, 1, 4);
190 layout->addWidget(new QLabel("Log"), 9, 0);
191 layout->addWidget(_log, 9, 1, 1, 4);
192
193 _bncCaster = 0;
194}
195
196// Destructor
197////////////////////////////////////////////////////////////////////////////
198bncWindow::~bncWindow() {
199}
200
201// Retrieve Table
202////////////////////////////////////////////////////////////////////////////
203void bncWindow::slotAddMountPoints() {
204
205 QSettings settings;
206 QString proxyHost = settings.value("proxyHost").toString();
207 int proxyPort = settings.value("proxyPort").toInt();
208 if (proxyHost != _proxyHostLineEdit->text() ||
209 proxyPort != _proxyPortLineEdit->text().toInt()) {
210 int iRet = QMessageBox::question(this, "Question", "Proxy options "
211 "changed. Use the new ones?",
212 QMessageBox::Yes, QMessageBox::No,
213 QMessageBox::NoButton);
214 if (iRet == QMessageBox::Yes) {
215 settings.setValue("proxyHost", _proxyHostLineEdit->text());
216 settings.setValue("proxyPort", _proxyPortLineEdit->text());
217 }
218 }
219
220 bncTableDlg* dlg = new bncTableDlg(this);
221 dlg->move(this->pos().x()+50, this->pos().y()+50);
222 connect(dlg, SIGNAL(newMountPoints(QStringList*)),
223 this, SLOT(slotNewMountPoints(QStringList*)));
224 dlg->exec();
225 delete dlg;
226
227}
228
229// Delete Selected Mount Points
230////////////////////////////////////////////////////////////////////////////
231void bncWindow::slotDeleteMountPoints() {
232 while(1) {
233 bool itemRemoved = false;
234 for (int iRow = 0; iRow < _mountPointsTable->rowCount(); iRow++) {
235 if (_mountPointsTable->isItemSelected(_mountPointsTable->item(iRow,1))) {
236 _mountPointsTable->removeRow(iRow);
237 itemRemoved = true;
238 break;
239 }
240 }
241 if (!itemRemoved) {
242 break;
243 }
244 }
245 _actDeleteMountPoints->setEnabled(false);
246}
247
248// New Mount Points Selected
249////////////////////////////////////////////////////////////////////////////
250void bncWindow::slotNewMountPoints(QStringList* mountPoints) {
251 int iRow = 0;
252 QListIterator<QString> it(*mountPoints);
253 while (it.hasNext()) {
254 QStringList hlp = it.next().split(" ");
255 QUrl url(hlp[0]);
256 QString fullPath = url.host() + QString(":%1").arg(url.port()) + url.path();
257 QString format(hlp[1]);
258
259 _mountPointsTable->insertRow(iRow);
260
261 QTableWidgetItem* it;
262 it = new QTableWidgetItem(url.userInfo());
263 it->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
264 _mountPointsTable->setItem(iRow, 0, it);
265
266 it = new QTableWidgetItem(fullPath);
267 it->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
268 _mountPointsTable->setItem(iRow, 1, it);
269
270 it = new QTableWidgetItem(format);
271 it->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable);
272 _mountPointsTable->setItem(iRow, 2, it);
273 iRow++;
274 }
275 _mountPointsTable->hideColumn(0);
276 _mountPointsTable->sortItems(1);
277 if (mountPoints->count() > 0) {
278 _actGetData->setEnabled(true);
279 }
280 delete mountPoints;
281}
282
283// Save Options
284////////////////////////////////////////////////////////////////////////////
285void bncWindow::slotSaveOptions() {
286 QSettings settings;
287 settings.setValue("proxyHost", _proxyHostLineEdit->text());
288 settings.setValue("proxyPort", _proxyPortLineEdit->text());
289 settings.setValue("timeOut", _timeOutLineEdit->text());
290 settings.setValue("outFile", _outFileLineEdit->text());
291 settings.setValue("outPort", _outPortLineEdit->text());
292 settings.setValue("rnxPath", _rnxPathLineEdit->text());
293 settings.setValue("rnxScript", _rnxScrpLineEdit->text());
294 settings.setValue("rnxIntr", _rnxIntrComboBox->currentText());
295 settings.setValue("rnxSampl", _rnxSamplSpinBox->value());
296 settings.setValue("rnxSkel", _rnxSkelLineEdit->text());
297
298 QStringList mountPoints;
299
300 for (int iRow = 0; iRow < _mountPointsTable->rowCount(); iRow++) {
301 QUrl url( "//" + _mountPointsTable->item(iRow, 0)->text() + "@" +
302 _mountPointsTable->item(iRow, 1)->text() );
303
304 mountPoints.append(url.toString() + " " +
305 _mountPointsTable->item(iRow, 2)->text());
306 }
307 settings.setValue("mountPoints", mountPoints);
308}
309
310// All get slots terminated
311////////////////////////////////////////////////////////////////////////////
312void bncWindow::slotGetThreadErrors() {
313 slotMessage("All Get Threads Terminated");
314 _actAddMountPoints->setEnabled(true);
315 _actGetData->setEnabled(true);
316}
317
318// Retrieve Data
319////////////////////////////////////////////////////////////////////////////
320void bncWindow::slotGetData() {
321 _actAddMountPoints->setEnabled(false);
322 _actDeleteMountPoints->setEnabled(false);
323 _actGetData->setEnabled(false);
324
325 _bncCaster = new bncCaster(_outFileLineEdit->text(),
326 _outPortLineEdit->text().toInt());
327
328 connect(_bncCaster, SIGNAL(getThreadErrors()),
329 this, SLOT(slotGetThreadErrors()));
330
331 connect(_bncCaster, SIGNAL(newMessage(const QByteArray&)),
332 this, SLOT(slotMessage(const QByteArray&)));
333
334 _bncCaster->start();
335
336 for (int iRow = 0; iRow < _mountPointsTable->rowCount(); iRow++) {
337 QUrl url( _mountPointsTable->item(iRow, 0)->text() + "@" +
338 _mountPointsTable->item(iRow, 1)->text() );
339
340 QByteArray format = _mountPointsTable->item(iRow, 2)->text().toAscii();
341
342 bncGetThread* getThread = new bncGetThread(url, format);
343
344 connect(getThread, SIGNAL(newMessage(const QByteArray&)),
345 this, SLOT(slotMessage(const QByteArray&)));
346
347 _bncCaster->addGetThread(getThread);
348
349 getThread->start();
350 }
351}
352
353// Close Application gracefully
354////////////////////////////////////////////////////////////////////////////
355void bncWindow::closeEvent(QCloseEvent* event) {
356
357 int iRet = QMessageBox::question(this, "Close", "Save Options?",
358 QMessageBox::Yes, QMessageBox::No,
359 QMessageBox::Cancel);
360
361 if (iRet == QMessageBox::Cancel) {
362 event->ignore();
363 return;
364 }
365 else if (iRet == QMessageBox::Yes) {
366 slotSaveOptions();
367 }
368
369 return QMainWindow::closeEvent(event);
370}
371
372// User changed the selection of mountPoints
373////////////////////////////////////////////////////////////////////////////
374void bncWindow::slotSelectionChanged() {
375 if (_mountPointsTable->selectedItems().isEmpty()) {
376 _actDeleteMountPoints->setEnabled(false);
377 }
378 else {
379 _actDeleteMountPoints->setEnabled(true);
380 }
381}
382
383// Display Program Messages
384////////////////////////////////////////////////////////////////////////////
385void bncWindow::slotMessage(const QByteArray& msg) {
386
387 const int maxBufferSize = 10000;
388
389 QString txt = _log->toPlainText() + "\n" + msg;
390 _log->clear();
391 _log->append(txt.right(maxBufferSize));
392}
393
394// About Message
395////////////////////////////////////////////////////////////////////////////
396void bncWindow::slotAbout() {
397
398 QString str("BKG NTRIP Client\n"
399 "Author: L. Mervart\n"
400 "Version 1.0");
401
402 QMessageBox::information(this, "About", str, QMessageBox::Ok);
403}
404
405// Help Window
406////////////////////////////////////////////////////////////////////////////
407void bncWindow::slotHelp() {
408
409 QString str("<h3>BNC Help</h3>"
410 "<p>"
411 "Program bnc can be used in interactive mode or "
412 "in a non-interactive mode."
413 "</p>"
414 "<p>"
415 "Non-interactive mode is invoked by -nw switch."
416 "On Unix (Linux) the standard X-window switches "
417 "like -fn 10x20 work. Program appearance can "
418 "be changed by e.g. -style motif switch."
419 "</p>");
420
421 QTextBrowser* tb = new QTextBrowser;
422 tb->setHtml(str);
423 tb->setReadOnly(true);
424 tb->show();
425
426 QDialog* dlg = new QDialog(this);
427
428 QVBoxLayout* dlgLayout = new QVBoxLayout();
429 dlgLayout->addWidget(tb);
430
431 dlg->setLayout(dlgLayout);
432 dlg->show();
433}
434
435// Select Fonts
436////////////////////////////////////////////////////////////////////////////
437void bncWindow::slotFontSel() {
438 bool ok;
439 QFont newFont = QFontDialog::getFont(&ok, this->font(), this);
440 if (ok) {
441 QApplication::setFont(newFont);
442 }
443}
Note: See TracBrowser for help on using the repository browser.