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 |
|
---|
22 | using namespace std;
|
---|
23 |
|
---|
24 | // Constructor
|
---|
25 | ////////////////////////////////////////////////////////////////////////////
|
---|
26 | bncWindow::bncWindow() {
|
---|
27 |
|
---|
28 | int ww = QFontMetrics(this->font()).width('w');
|
---|
29 |
|
---|
30 | setMinimumSize(90*ww, 80*ww);
|
---|
31 |
|
---|
32 | // Create Actions
|
---|
33 | // --------------
|
---|
34 | _actAbout = new QAction(tr("&About"),this);
|
---|
35 | _actAbout->setEnabled(false);
|
---|
36 |
|
---|
37 | _actSaveOpt = new QAction(tr("&Save Options"),this);
|
---|
38 | connect(_actSaveOpt, SIGNAL(triggered()), SLOT(slotSaveOptions()));
|
---|
39 |
|
---|
40 | _actQuit = new QAction(tr("&Quit"),this);
|
---|
41 | connect(_actQuit, SIGNAL(triggered()), SLOT(close()));
|
---|
42 |
|
---|
43 | _actAddMountPoints = new QAction(tr("&Add Mountpoints"),this);
|
---|
44 | connect(_actAddMountPoints, SIGNAL(triggered()), SLOT(slotAddMountPoints()));
|
---|
45 |
|
---|
46 | _actDeleteMountPoints = new QAction(tr("&Delete Mountpoints"),this);
|
---|
47 | connect(_actDeleteMountPoints, SIGNAL(triggered()), SLOT(slotDeleteMountPoints()));
|
---|
48 | _actDeleteMountPoints->setEnabled(false);
|
---|
49 |
|
---|
50 | _actGetData = new QAction(tr("&Get Data"),this);
|
---|
51 | connect(_actGetData, SIGNAL(triggered()), SLOT(slotGetData()));
|
---|
52 |
|
---|
53 | // Create Menus
|
---|
54 | // ------------
|
---|
55 | _menuFile = menuBar()->addMenu(tr("&File"));
|
---|
56 | _menuFile->addAction(_actSaveOpt);
|
---|
57 | _menuFile->addSeparator();
|
---|
58 | _menuFile->addAction(_actQuit);
|
---|
59 |
|
---|
60 | _menuHlp = menuBar()->addMenu(tr("&Help"));
|
---|
61 | _menuHlp->addAction(_actAbout);
|
---|
62 |
|
---|
63 | // Tool (Command) Bar
|
---|
64 | // ------------------
|
---|
65 | QToolBar* toolBar = new QToolBar;
|
---|
66 | addToolBar(Qt::BottomToolBarArea, toolBar);
|
---|
67 | toolBar->setMovable(false);
|
---|
68 | toolBar->addAction(_actAddMountPoints);
|
---|
69 | toolBar->addAction(_actDeleteMountPoints);
|
---|
70 | toolBar->addAction(_actGetData);
|
---|
71 |
|
---|
72 | // Canvas with Editable Fields
|
---|
73 | // ---------------------------
|
---|
74 | _canvas = new QWidget;
|
---|
75 | setCentralWidget(_canvas);
|
---|
76 |
|
---|
77 | QGridLayout* layout = new QGridLayout;
|
---|
78 | _canvas->setLayout(layout);
|
---|
79 |
|
---|
80 | QSettings settings;
|
---|
81 |
|
---|
82 | _proxyHostLineEdit = new QLineEdit(settings.value("proxyHost").toString());
|
---|
83 | _proxyHostLineEdit->setMaximumWidth(12*ww);
|
---|
84 | _proxyPortLineEdit = new QLineEdit(settings.value("proxyPort").toString());
|
---|
85 | _proxyPortLineEdit->setMaximumWidth(9*ww);
|
---|
86 | _timeOutLineEdit = new QLineEdit(settings.value("timeOut").toString());
|
---|
87 | _timeOutLineEdit->setMaximumWidth(9*ww);
|
---|
88 | _outFileLineEdit = new QLineEdit(settings.value("outFile").toString());
|
---|
89 | _outPortLineEdit = new QLineEdit(settings.value("outPort").toString());
|
---|
90 | _outPortLineEdit->setMaximumWidth(9*ww);
|
---|
91 | _rnxPathLineEdit = new QLineEdit(settings.value("rnxPath").toString());
|
---|
92 | _rnxScrpLineEdit = new QLineEdit(settings.value("rnxScript").toString());
|
---|
93 | _rnxSkelLineEdit = new QLineEdit(settings.value("rnxSkel").toString());
|
---|
94 | _rnxSkelLineEdit->setMaximumWidth(5*ww);
|
---|
95 | _rnxIntrComboBox = new QComboBox();
|
---|
96 | _rnxIntrComboBox->setMaximumWidth(9*ww);
|
---|
97 | _rnxIntrComboBox->setEditable(false);
|
---|
98 | _rnxIntrComboBox->addItems(QString("15 min,1 hour,1 day").split(","));
|
---|
99 | int ii = _rnxIntrComboBox->findText(settings.value("rnxIntr").toString());
|
---|
100 | if (ii != -1) {
|
---|
101 | _rnxIntrComboBox->setCurrentIndex(ii);
|
---|
102 | }
|
---|
103 | _rnxSamplSpinBox = new QSpinBox();
|
---|
104 | _rnxSamplSpinBox->setMinimum(0);
|
---|
105 | _rnxSamplSpinBox->setMaximum(60);
|
---|
106 | _rnxSamplSpinBox->setSingleStep(5);
|
---|
107 | _rnxSamplSpinBox->setMaximumWidth(9*ww);
|
---|
108 | _rnxSamplSpinBox->setValue(settings.value("rnxSampl").toInt());
|
---|
109 | _mountPointsTable = new QTableWidget(0,2);
|
---|
110 | _mountPointsTable->setMinimumWidth(60*ww);
|
---|
111 | _mountPointsTable->setMaximumHeight(20*ww);
|
---|
112 | _mountPointsTable->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
|
---|
113 | _mountPointsTable->horizontalHeader()->hide();
|
---|
114 | _mountPointsTable->verticalHeader()->hide();
|
---|
115 | _mountPointsTable->setGridStyle(Qt::NoPen);
|
---|
116 | _mountPointsTable->setSelectionMode(QAbstractItemView::ExtendedSelection);
|
---|
117 | _mountPointsTable->setSelectionBehavior(QAbstractItemView::SelectRows);
|
---|
118 | QListIterator<QString> it(settings.value("mountPoints").toStringList());
|
---|
119 | if (!it.hasNext()) {
|
---|
120 | _actGetData->setEnabled(false);
|
---|
121 | }
|
---|
122 | int iRow = 0;
|
---|
123 | while (it.hasNext()) {
|
---|
124 | QStringList hlp = it.next().split(" ");
|
---|
125 | if (hlp.size() <= 1) continue;
|
---|
126 | QString mPoint = hlp[0];
|
---|
127 | QString format = hlp[1];
|
---|
128 | _mountPointsTable->insertRow(iRow);
|
---|
129 | _mountPointsTable->setItem(iRow, 0, new QTableWidgetItem(mPoint));
|
---|
130 | _mountPointsTable->setItem(iRow, 1, new QTableWidgetItem(format));
|
---|
131 | iRow++;
|
---|
132 | }
|
---|
133 | _mountPointsTable->sortItems(0);
|
---|
134 |
|
---|
135 | connect(_mountPointsTable, SIGNAL(itemSelectionChanged()),
|
---|
136 | SLOT(slotSelectionChanged()));
|
---|
137 |
|
---|
138 | _log = new QTextEdit();
|
---|
139 | _log->setMaximumHeight(120);
|
---|
140 | _log->setReadOnly(true);
|
---|
141 |
|
---|
142 | layout->addWidget(new QLabel("Proxy host"), 0, 0);
|
---|
143 | layout->addWidget(_proxyHostLineEdit, 0, 1);
|
---|
144 | layout->addWidget(new QLabel("Proxy port"), 0, 2);
|
---|
145 | layout->addWidget(_proxyPortLineEdit, 0, 3);
|
---|
146 | layout->addWidget(new QLabel("timeout (sec)"), 1, 1);
|
---|
147 | layout->addWidget(_timeOutLineEdit, 1, 2);
|
---|
148 | layout->addWidget(new QLabel("ASCII output file (full path)"), 2, 1);
|
---|
149 | layout->addWidget(_outFileLineEdit, 2, 2, 1, 3);
|
---|
150 | layout->addWidget(new QLabel("port for binary output"), 3, 1);
|
---|
151 | layout->addWidget(_outPortLineEdit, 3, 2);
|
---|
152 | layout->addWidget(new QLabel("RINEX path"), 4, 1);
|
---|
153 | layout->addWidget(_rnxPathLineEdit, 4, 2, 1, 3);
|
---|
154 | layout->addWidget(new QLabel("RINEX script (full path)"), 5, 1);
|
---|
155 | layout->addWidget(_rnxScrpLineEdit, 5, 2, 1, 3);
|
---|
156 | layout->addWidget(new QLabel("RINEX file interval"), 6, 1);
|
---|
157 | layout->addWidget(_rnxIntrComboBox, 6, 2);
|
---|
158 |
|
---|
159 | layout->addWidget(new QLabel("sampling (sec)"), 6, 3);
|
---|
160 | layout->addWidget(_rnxSamplSpinBox, 6, 4);
|
---|
161 |
|
---|
162 |
|
---|
163 | layout->addWidget(new QLabel("RINEX skeleton extension"), 7, 1);
|
---|
164 | layout->addWidget(_rnxSkelLineEdit, 7, 2);
|
---|
165 | layout->addWidget(new QLabel("Mountpoints"), 8, 0);
|
---|
166 | layout->addWidget(_mountPointsTable, 8, 1, 1, 4);
|
---|
167 | layout->addWidget(new QLabel("Log"), 9, 0);
|
---|
168 | layout->addWidget(_log, 9, 1, 1, 4);
|
---|
169 |
|
---|
170 | _bncCaster = 0;
|
---|
171 | }
|
---|
172 |
|
---|
173 | // Destructor
|
---|
174 | ////////////////////////////////////////////////////////////////////////////
|
---|
175 | bncWindow::~bncWindow() {
|
---|
176 | }
|
---|
177 |
|
---|
178 | // Retrieve Table
|
---|
179 | ////////////////////////////////////////////////////////////////////////////
|
---|
180 | void bncWindow::slotAddMountPoints() {
|
---|
181 |
|
---|
182 | QSettings settings;
|
---|
183 | QString proxyHost = settings.value("proxyHost").toString();
|
---|
184 | int proxyPort = settings.value("proxyPort").toInt();
|
---|
185 | if (proxyHost != _proxyHostLineEdit->text() ||
|
---|
186 | proxyPort != _proxyPortLineEdit->text().toInt()) {
|
---|
187 | int iRet = QMessageBox::question(this, "Question", "Proxy options "
|
---|
188 | "changed. Use the new ones?",
|
---|
189 | QMessageBox::Yes, QMessageBox::No,
|
---|
190 | QMessageBox::NoButton);
|
---|
191 | if (iRet == QMessageBox::Yes) {
|
---|
192 | settings.setValue("proxyHost", _proxyHostLineEdit->text());
|
---|
193 | settings.setValue("proxyPort", _proxyPortLineEdit->text());
|
---|
194 | }
|
---|
195 | }
|
---|
196 |
|
---|
197 | bncTableDlg* dlg = new bncTableDlg(this);
|
---|
198 | dlg->move(this->pos().x()+50, this->pos().y()+50);
|
---|
199 | connect(dlg, SIGNAL(newMountPoints(QStringList*)),
|
---|
200 | this, SLOT(slotNewMountPoints(QStringList*)));
|
---|
201 | dlg->exec();
|
---|
202 | delete dlg;
|
---|
203 |
|
---|
204 | }
|
---|
205 |
|
---|
206 | // Delete Selected Mount Points
|
---|
207 | ////////////////////////////////////////////////////////////////////////////
|
---|
208 | void bncWindow::slotDeleteMountPoints() {
|
---|
209 | while(1) {
|
---|
210 | bool itemRemoved = false;
|
---|
211 | for (int iRow = 0; iRow < _mountPointsTable->rowCount(); iRow++) {
|
---|
212 | if (_mountPointsTable->isItemSelected(_mountPointsTable->item(iRow,0))) {
|
---|
213 | _mountPointsTable->removeRow(iRow);
|
---|
214 | itemRemoved = true;
|
---|
215 | break;
|
---|
216 | }
|
---|
217 | }
|
---|
218 | if (!itemRemoved) {
|
---|
219 | break;
|
---|
220 | }
|
---|
221 | }
|
---|
222 | _actDeleteMountPoints->setEnabled(false);
|
---|
223 | }
|
---|
224 |
|
---|
225 | // New Mount Points Selected
|
---|
226 | ////////////////////////////////////////////////////////////////////////////
|
---|
227 | void bncWindow::slotNewMountPoints(QStringList* mountPoints) {
|
---|
228 | int iRow = 0;
|
---|
229 | QListIterator<QString> it(*mountPoints);
|
---|
230 | while (it.hasNext()) {
|
---|
231 | QStringList hlp = it.next().split(" ");
|
---|
232 | QString mPoint = hlp[0];
|
---|
233 | QString format = hlp[1];
|
---|
234 | _mountPointsTable->insertRow(iRow);
|
---|
235 | _mountPointsTable->setItem(iRow, 0, new QTableWidgetItem(mPoint));
|
---|
236 | _mountPointsTable->setItem(iRow, 1, new QTableWidgetItem(format));
|
---|
237 | iRow++;
|
---|
238 | }
|
---|
239 | _mountPointsTable->sortItems(0);
|
---|
240 | if (mountPoints->count() > 0) {
|
---|
241 | _actGetData->setEnabled(true);
|
---|
242 | }
|
---|
243 | delete mountPoints;
|
---|
244 | }
|
---|
245 |
|
---|
246 | // Save Options
|
---|
247 | ////////////////////////////////////////////////////////////////////////////
|
---|
248 | void bncWindow::slotSaveOptions() {
|
---|
249 | QSettings settings;
|
---|
250 | settings.setValue("proxyHost", _proxyHostLineEdit->text());
|
---|
251 | settings.setValue("proxyPort", _proxyPortLineEdit->text());
|
---|
252 | settings.setValue("timeOut", _timeOutLineEdit->text());
|
---|
253 | settings.setValue("outFile", _outFileLineEdit->text());
|
---|
254 | settings.setValue("outPort", _outPortLineEdit->text());
|
---|
255 | settings.setValue("rnxPath", _rnxPathLineEdit->text());
|
---|
256 | settings.setValue("rnxScript", _rnxScrpLineEdit->text());
|
---|
257 | settings.setValue("rnxIntr", _rnxIntrComboBox->currentText());
|
---|
258 | settings.setValue("rnxSampl", _rnxSamplSpinBox->value());
|
---|
259 | settings.setValue("rnxSkel", _rnxSkelLineEdit->text());
|
---|
260 | QStringList mountPoints;
|
---|
261 | for (int iRow = 0; iRow < _mountPointsTable->rowCount(); iRow++) {
|
---|
262 | mountPoints.append(_mountPointsTable->item(iRow, 0)->text() +
|
---|
263 | " " + _mountPointsTable->item(iRow, 1)->text());
|
---|
264 | }
|
---|
265 | settings.setValue("mountPoints", mountPoints);
|
---|
266 | }
|
---|
267 |
|
---|
268 | // All get slots terminated
|
---|
269 | ////////////////////////////////////////////////////////////////////////////
|
---|
270 | void bncWindow::slotGetThreadErrors() {
|
---|
271 | slotMessage("All Get Threads Terminated");
|
---|
272 | _actAddMountPoints->setEnabled(true);
|
---|
273 | _actGetData->setEnabled(true);
|
---|
274 | }
|
---|
275 |
|
---|
276 | // Retrieve Data
|
---|
277 | ////////////////////////////////////////////////////////////////////////////
|
---|
278 | void bncWindow::slotGetData() {
|
---|
279 | _actAddMountPoints->setEnabled(false);
|
---|
280 | _actDeleteMountPoints->setEnabled(false);
|
---|
281 | _actGetData->setEnabled(false);
|
---|
282 |
|
---|
283 | _bncCaster = new bncCaster(_outFileLineEdit->text(),
|
---|
284 | _outPortLineEdit->text().toInt());
|
---|
285 |
|
---|
286 | connect(_bncCaster, SIGNAL(getThreadErrors()),
|
---|
287 | this, SLOT(slotGetThreadErrors()));
|
---|
288 |
|
---|
289 | connect(_bncCaster, SIGNAL(newMessage(const QByteArray&)),
|
---|
290 | this, SLOT(slotMessage(const QByteArray&)));
|
---|
291 |
|
---|
292 | _bncCaster->start();
|
---|
293 |
|
---|
294 | for (int iRow = 0; iRow < _mountPointsTable->rowCount(); iRow++) {
|
---|
295 | QUrl url(_mountPointsTable->item(iRow, 0)->text());
|
---|
296 | QByteArray format = _mountPointsTable->item(iRow, 1)->text().toAscii();
|
---|
297 |
|
---|
298 | bncGetThread* getThread = new bncGetThread(url, format);
|
---|
299 |
|
---|
300 | connect(getThread, SIGNAL(newMessage(const QByteArray&)),
|
---|
301 | this, SLOT(slotMessage(const QByteArray&)));
|
---|
302 |
|
---|
303 | _bncCaster->addGetThread(getThread);
|
---|
304 |
|
---|
305 | getThread->start();
|
---|
306 | }
|
---|
307 | }
|
---|
308 |
|
---|
309 | // Close Application gracefully
|
---|
310 | ////////////////////////////////////////////////////////////////////////////
|
---|
311 | void bncWindow::closeEvent(QCloseEvent* event) {
|
---|
312 |
|
---|
313 | int iRet = QMessageBox::question(this, "Close", "Save Options?",
|
---|
314 | QMessageBox::Yes, QMessageBox::No,
|
---|
315 | QMessageBox::Cancel);
|
---|
316 |
|
---|
317 | if (iRet == QMessageBox::Cancel) {
|
---|
318 | event->ignore();
|
---|
319 | return;
|
---|
320 | }
|
---|
321 | else if (iRet == QMessageBox::Yes) {
|
---|
322 | slotSaveOptions();
|
---|
323 | }
|
---|
324 |
|
---|
325 | return QMainWindow::closeEvent(event);
|
---|
326 | }
|
---|
327 |
|
---|
328 | // User changed the selection of mountPoints
|
---|
329 | ////////////////////////////////////////////////////////////////////////////
|
---|
330 | void bncWindow::slotSelectionChanged() {
|
---|
331 | if (_mountPointsTable->selectedItems().isEmpty()) {
|
---|
332 | _actDeleteMountPoints->setEnabled(false);
|
---|
333 | }
|
---|
334 | else {
|
---|
335 | _actDeleteMountPoints->setEnabled(true);
|
---|
336 | }
|
---|
337 | }
|
---|
338 |
|
---|
339 | // Display Program Messages
|
---|
340 | ////////////////////////////////////////////////////////////////////////////
|
---|
341 | void bncWindow::slotMessage(const QByteArray& msg) {
|
---|
342 |
|
---|
343 | const int maxBufferSize = 10000;
|
---|
344 |
|
---|
345 | QString txt = _log->toPlainText() + "\n" + msg;
|
---|
346 | _log->clear();
|
---|
347 | _log->append(txt.right(maxBufferSize));
|
---|
348 | }
|
---|
349 |
|
---|