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

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

* empty log message *

File size: 15.1 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 _proxyHostLineEdit = new QLineEdit(settings.value("proxyHost").toString());
91 _proxyHostLineEdit->setMaximumWidth(12*ww);
92 _proxyPortLineEdit = new QLineEdit(settings.value("proxyPort").toString());
93 _proxyPortLineEdit->setMaximumWidth(9*ww);
94 _timeOutLineEdit = new QLineEdit(settings.value("timeOut").toString());
95 _timeOutLineEdit->setMaximumWidth(9*ww);
96 _outFileLineEdit = new QLineEdit(settings.value("outFile").toString());
97 _outPortLineEdit = new QLineEdit(settings.value("outPort").toString());
98 _outPortLineEdit->setMaximumWidth(9*ww);
99 _rnxPathLineEdit = new QLineEdit(settings.value("rnxPath").toString());
100 _rnxScrpLineEdit = new QLineEdit(settings.value("rnxScript").toString());
101 _rnxSkelLineEdit = new QLineEdit(settings.value("rnxSkel").toString());
102 _rnxSkelLineEdit->setMaximumWidth(5*ww);
103 _rnxIntrComboBox = new QComboBox();
104 _rnxIntrComboBox->setMaximumWidth(9*ww);
105 _rnxIntrComboBox->setEditable(false);
106 _rnxIntrComboBox->addItems(QString("15 min,1 hour,1 day").split(","));
107 int ii = _rnxIntrComboBox->findText(settings.value("rnxIntr").toString());
108 if (ii != -1) {
109 _rnxIntrComboBox->setCurrentIndex(ii);
110 }
111 _rnxSamplSpinBox = new QSpinBox();
112 _rnxSamplSpinBox->setMinimum(0);
113 _rnxSamplSpinBox->setMaximum(60);
114 _rnxSamplSpinBox->setSingleStep(5);
115 _rnxSamplSpinBox->setMaximumWidth(9*ww);
116 _rnxSamplSpinBox->setValue(settings.value("rnxSampl").toInt());
117 _mountPointsTable = new QTableWidget(0,3);
118 _mountPointsTable->setMinimumWidth(60*ww);
119 _mountPointsTable->setMaximumHeight(20*ww);
120 _mountPointsTable->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
121 _mountPointsTable->horizontalHeader()->hide();
122 _mountPointsTable->verticalHeader()->hide();
123 _mountPointsTable->setGridStyle(Qt::NoPen);
124 _mountPointsTable->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
125 _mountPointsTable->setSelectionMode(QAbstractItemView::ExtendedSelection);
126 _mountPointsTable->setSelectionBehavior(QAbstractItemView::SelectRows);
127 QListIterator<QString> it(settings.value("mountPoints").toStringList());
128 if (!it.hasNext()) {
129 _actGetData->setEnabled(false);
130 }
131 int iRow = 0;
132 while (it.hasNext()) {
133 QStringList hlp = it.next().split(" ");
134 if (hlp.size() <= 1) continue;
135 _mountPointsTable->insertRow(iRow);
136
137 QUrl url(hlp[0]);
138
139 QString fullPath = url.host() + QString(":%1").arg(url.port()) + url.path();
140 QString format(hlp[1]);
141
142 QTableWidgetItem* it;
143 it = new QTableWidgetItem(url.userInfo());
144 it->setFlags(it->flags() & ~Qt::ItemIsEditable);
145 _mountPointsTable->setItem(iRow, 0, it);
146
147 it = new QTableWidgetItem(fullPath);
148 it->setFlags(it->flags() & ~Qt::ItemIsEditable);
149 _mountPointsTable->setItem(iRow, 1, it);
150
151 it = new QTableWidgetItem(format);
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
233 int nRows = _mountPointsTable->rowCount();
234 bool flg[nRows];
235 for (int iRow = 0; iRow < nRows; iRow++) {
236 if (_mountPointsTable->isItemSelected(_mountPointsTable->item(iRow,1))) {
237 flg[iRow] = true;
238 }
239 else {
240 flg[iRow] = false;
241 }
242 }
243 for (int iRow = nRows-1; iRow >= 0; iRow--) {
244 if (flg[iRow]) {
245 _mountPointsTable->removeRow(iRow);
246 }
247 }
248 _actDeleteMountPoints->setEnabled(false);
249}
250
251// New Mount Points Selected
252////////////////////////////////////////////////////////////////////////////
253void bncWindow::slotNewMountPoints(QStringList* mountPoints) {
254 int iRow = 0;
255 QListIterator<QString> it(*mountPoints);
256 while (it.hasNext()) {
257 QStringList hlp = it.next().split(" ");
258 QUrl url(hlp[0]);
259 QString fullPath = url.host() + QString(":%1").arg(url.port()) + url.path();
260 QString format(hlp[1]);
261
262 _mountPointsTable->insertRow(iRow);
263
264 QTableWidgetItem* it;
265 it = new QTableWidgetItem(url.userInfo());
266 it->setFlags(it->flags() & ~Qt::ItemIsEditable);
267 _mountPointsTable->setItem(iRow, 0, it);
268
269 it = new QTableWidgetItem(fullPath);
270 it->setFlags(it->flags() & ~Qt::ItemIsEditable);
271 _mountPointsTable->setItem(iRow, 1, it);
272
273 it = new QTableWidgetItem(format);
274 _mountPointsTable->setItem(iRow, 2, it);
275 iRow++;
276 }
277 _mountPointsTable->hideColumn(0);
278 _mountPointsTable->sortItems(1);
279 if (mountPoints->count() > 0) {
280 _actGetData->setEnabled(true);
281 }
282 delete mountPoints;
283}
284
285// Save Options
286////////////////////////////////////////////////////////////////////////////
287void bncWindow::slotSaveOptions() {
288 QSettings settings;
289 settings.setValue("proxyHost", _proxyHostLineEdit->text());
290 settings.setValue("proxyPort", _proxyPortLineEdit->text());
291 settings.setValue("timeOut", _timeOutLineEdit->text());
292 settings.setValue("outFile", _outFileLineEdit->text());
293 settings.setValue("outPort", _outPortLineEdit->text());
294 settings.setValue("rnxPath", _rnxPathLineEdit->text());
295 settings.setValue("rnxScript", _rnxScrpLineEdit->text());
296 settings.setValue("rnxIntr", _rnxIntrComboBox->currentText());
297 settings.setValue("rnxSampl", _rnxSamplSpinBox->value());
298 settings.setValue("rnxSkel", _rnxSkelLineEdit->text());
299
300 QStringList mountPoints;
301
302 for (int iRow = 0; iRow < _mountPointsTable->rowCount(); iRow++) {
303 QUrl url( "//" + _mountPointsTable->item(iRow, 0)->text() +
304 "@" + _mountPointsTable->item(iRow, 1)->text() );
305
306 mountPoints.append(url.toString() + " " +
307 _mountPointsTable->item(iRow, 2)->text());
308 }
309 settings.setValue("mountPoints", mountPoints);
310}
311
312// All get slots terminated
313////////////////////////////////////////////////////////////////////////////
314void bncWindow::slotGetThreadErrors() {
315 slotMessage("All Get Threads Terminated");
316 _actAddMountPoints->setEnabled(true);
317 _actGetData->setEnabled(true);
318}
319
320// Retrieve Data
321////////////////////////////////////////////////////////////////////////////
322void bncWindow::slotGetData() {
323 _actAddMountPoints->setEnabled(false);
324 _actDeleteMountPoints->setEnabled(false);
325 _actGetData->setEnabled(false);
326
327 _bncCaster = new bncCaster(_outFileLineEdit->text(),
328 _outPortLineEdit->text().toInt());
329
330 connect(_bncCaster, SIGNAL(getThreadErrors()),
331 this, SLOT(slotGetThreadErrors()));
332
333 connect(_bncCaster, SIGNAL(newMessage(const QByteArray&)),
334 this, SLOT(slotMessage(const QByteArray&)));
335
336 _bncCaster->start();
337
338 for (int iRow = 0; iRow < _mountPointsTable->rowCount(); iRow++) {
339 QUrl url( "//" + _mountPointsTable->item(iRow, 0)->text() +
340 "@" + _mountPointsTable->item(iRow, 1)->text() );
341
342 QByteArray format = _mountPointsTable->item(iRow, 2)->text().toAscii();
343
344 bncGetThread* getThread = new bncGetThread(url, format);
345
346 connect(getThread, SIGNAL(newMessage(const QByteArray&)),
347 this, SLOT(slotMessage(const QByteArray&)));
348
349 _bncCaster->addGetThread(getThread);
350
351 getThread->start();
352 }
353}
354
355// Close Application gracefully
356////////////////////////////////////////////////////////////////////////////
357void bncWindow::closeEvent(QCloseEvent* event) {
358
359 int iRet = QMessageBox::question(this, "Close", "Save Options?",
360 QMessageBox::Yes, QMessageBox::No,
361 QMessageBox::Cancel);
362
363 if (iRet == QMessageBox::Cancel) {
364 event->ignore();
365 return;
366 }
367 else if (iRet == QMessageBox::Yes) {
368 slotSaveOptions();
369 }
370
371 return QMainWindow::closeEvent(event);
372}
373
374// User changed the selection of mountPoints
375////////////////////////////////////////////////////////////////////////////
376void bncWindow::slotSelectionChanged() {
377 if (_mountPointsTable->selectedItems().isEmpty()) {
378 _actDeleteMountPoints->setEnabled(false);
379 }
380 else {
381 _actDeleteMountPoints->setEnabled(true);
382 }
383}
384
385// Display Program Messages
386////////////////////////////////////////////////////////////////////////////
387void bncWindow::slotMessage(const QByteArray& msg) {
388
389 const int maxBufferSize = 10000;
390
391 QString txt = _log->toPlainText() + "\n" + msg;
392 _log->clear();
393 _log->append(txt.right(maxBufferSize));
394}
395
396// About Message
397////////////////////////////////////////////////////////////////////////////
398void bncWindow::slotAbout() {
399
400 QString str("BKG NTRIP Client\n"
401 "Author: L. Mervart\n"
402 "Version 1.0");
403
404 QMessageBox::information(this, "About", str, QMessageBox::Ok);
405}
406
407// Help Window
408////////////////////////////////////////////////////////////////////////////
409void bncWindow::slotHelp() {
410
411 QString str(
412#include "bnchelp.html"
413 );
414
415 QTextBrowser* tb = new QTextBrowser;
416 tb->setHtml(str);
417 tb->setReadOnly(true);
418 tb->show();
419
420 QDialog* dlg = new QDialog(this);
421
422 QVBoxLayout* dlgLayout = new QVBoxLayout();
423 dlgLayout->addWidget(tb);
424
425 dlg->setLayout(dlgLayout);
426 int ww = QFontMetrics(font()).width('w');
427 dlg->resize(80*ww, 60*ww);
428 dlg->show();
429}
430
431// Select Fonts
432////////////////////////////////////////////////////////////////////////////
433void bncWindow::slotFontSel() {
434 bool ok;
435 QFont newFont = QFontDialog::getFont(&ok, this->font(), this);
436 if (ok) {
437 QSettings settings;
438 settings.setValue("font", newFont.toString());
439 QApplication::setFont(newFont);
440 int ww = QFontMetrics(newFont).width('w');
441 setMinimumSize(90*ww, 80*ww);
442 resize(90*ww, 80*ww);
443 }
444}
Note: See TracBrowser for help on using the repository browser.