1 | // Part of BNC, a utility for retrieving decoding and
|
---|
2 | // converting GNSS data streams from NTRIP broadcasters.
|
---|
3 | //
|
---|
4 | // Copyright (C) 2007
|
---|
5 | // German Federal Agency for Cartography and Geodesy (BKG)
|
---|
6 | // http://www.bkg.bund.de
|
---|
7 | // Czech Technical University Prague, Department of Geodesy
|
---|
8 | // http://www.fsv.cvut.cz
|
---|
9 | //
|
---|
10 | // Email: euref-ip@bkg.bund.de
|
---|
11 | //
|
---|
12 | // This program is free software; you can redistribute it and/or
|
---|
13 | // modify it under the terms of the GNU General Public License
|
---|
14 | // as published by the Free Software Foundation, version 2.
|
---|
15 | //
|
---|
16 | // This program is distributed in the hope that it will be useful,
|
---|
17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
19 | // GNU General Public License for more details.
|
---|
20 | //
|
---|
21 | // You should have received a copy of the GNU General Public License
|
---|
22 | // along with this program; if not, write to the Free Software
|
---|
23 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
---|
24 |
|
---|
25 | /* -------------------------------------------------------------------------
|
---|
26 | * BKG NTRIP Client
|
---|
27 | * -------------------------------------------------------------------------
|
---|
28 | *
|
---|
29 | * Class: bncTableDlg
|
---|
30 | *
|
---|
31 | * Purpose: Displays the source table, allows mountpoints selection
|
---|
32 | *
|
---|
33 | * Author: L. Mervart
|
---|
34 | *
|
---|
35 | * Created: 24-Dec-2005
|
---|
36 | *
|
---|
37 | * Changes:
|
---|
38 | *
|
---|
39 | * -----------------------------------------------------------------------*/
|
---|
40 |
|
---|
41 | #include <iostream>
|
---|
42 |
|
---|
43 | #include "bnctabledlg.h"
|
---|
44 | #include "bncgetthread.h"
|
---|
45 | #include "bncnetqueryv2.h"
|
---|
46 | #include "bncsettings.h"
|
---|
47 |
|
---|
48 | using namespace std;
|
---|
49 |
|
---|
50 | // Constructor
|
---|
51 | ////////////////////////////////////////////////////////////////////////////
|
---|
52 | bncTableDlg::bncTableDlg(QWidget* parent) : QDialog(parent) {
|
---|
53 |
|
---|
54 | setMinimumSize(600,400);
|
---|
55 | setWindowTitle(tr("Add Streams from Caster"));
|
---|
56 |
|
---|
57 | QVBoxLayout* mainLayout = new QVBoxLayout(this);
|
---|
58 |
|
---|
59 | int ww = QFontMetrics(font()).width('w');
|
---|
60 |
|
---|
61 | _casterPortLineEdit = new QLineEdit();
|
---|
62 | _casterPortLineEdit->setMaximumWidth(9*ww);
|
---|
63 |
|
---|
64 | _casterUserLineEdit = new QLineEdit();
|
---|
65 | _casterUserLineEdit->setMaximumWidth(9*ww);
|
---|
66 |
|
---|
67 | _casterPasswordLineEdit = new QLineEdit();
|
---|
68 | _casterPasswordLineEdit->setMaximumWidth(9*ww);
|
---|
69 | //// _casterPasswordLineEdit->setEchoMode(QLineEdit::Password);
|
---|
70 |
|
---|
71 | _casterHostComboBox = new QComboBox();
|
---|
72 | _casterHostComboBox->setMaxCount(10);
|
---|
73 | _casterHostComboBox->setDuplicatesEnabled(false);
|
---|
74 | _casterHostComboBox->setEditable(true);
|
---|
75 | _casterHostComboBox->setMinimumWidth(20*ww);
|
---|
76 | _casterHostComboBox->setMaximumWidth(20*ww);
|
---|
77 | connect(_casterHostComboBox, SIGNAL(currentIndexChanged(const QString&)),
|
---|
78 | this, SLOT(slotCasterHostChanged(const QString&)));
|
---|
79 | bncSettings settings;
|
---|
80 | settings.remove("casterHostList");
|
---|
81 | settings.remove("casterHost");
|
---|
82 | settings.remove("casterPort");
|
---|
83 | settings.remove("casterUser");
|
---|
84 | settings.remove("casterPassword");
|
---|
85 | QStringList casterUrlList = settings.value("casterUrlList").toStringList();
|
---|
86 | for (int ii = 0; ii < casterUrlList.count(); ii++) {
|
---|
87 | QUrl url(casterUrlList[ii]);
|
---|
88 | _casterHostComboBox->addItem(url.host());
|
---|
89 | }
|
---|
90 |
|
---|
91 | _ntripVersionComboBox = new QComboBox();
|
---|
92 | _ntripVersionComboBox->addItems(QString("1,2,R").split(","));
|
---|
93 | int kk = _ntripVersionComboBox->findText(settings.value("ntripVersion").toString());
|
---|
94 | if (kk != -1) {
|
---|
95 | _ntripVersionComboBox->setCurrentIndex(kk);
|
---|
96 | }
|
---|
97 | _ntripVersionComboBox->setMaximumWidth(5*ww);
|
---|
98 |
|
---|
99 | _buttonCasterTable = new QPushButton(tr("Show"), this);
|
---|
100 | connect(_buttonCasterTable, SIGNAL(clicked()), this, SLOT(slotCasterTable()));
|
---|
101 | _buttonCasterTable->setMaximumWidth(5*ww);
|
---|
102 |
|
---|
103 | // WhatsThis
|
---|
104 | // ---------
|
---|
105 | _casterUserLineEdit->setWhatsThis(tr("<p>Access to some streams on NTRIP broadcasters may be restricted. You'll need to enter a valid 'User ID' and 'Password' for access to these protected streams.</p><p>Accounts are usually provided per NTRIP broadcaster through a registration process. Register through <u>http://igs.bkg.bund.de/index_ntrip_reg.htm</u> for access to protected streams on <u>www.euref-ip.net</u> and <u>www.igs-ip.net</u>.</p>"));
|
---|
106 | _casterHostComboBox->setWhatsThis(tr("<p>Enter the NTRIP broadcaster hostname or IP number.</p><p>Note that EUREF and IGS operate NTRIP broadcasters at <u>http://www.euref-ip.net/home</u> and <u>http://www.igs-ip.net/home</u>.</p>"));
|
---|
107 | _casterPortLineEdit->setWhatsThis(tr("Enter the NTRIP broadcaster port number."));
|
---|
108 | _casterPasswordLineEdit->setWhatsThis(tr("Access to some streams on NTRIP broadcasters may be restricted. You'll need to enter a valid 'Password' for access to these protected streams."));
|
---|
109 |
|
---|
110 | QGridLayout* editLayout = new QGridLayout;
|
---|
111 | editLayout->addWidget(new QLabel(tr("Caster host")), 0, 0);
|
---|
112 | editLayout->addWidget(_casterHostComboBox, 0, 1);
|
---|
113 | editLayout->addWidget(new QLabel(tr(" Caster port")), 0, 2, Qt::AlignRight);
|
---|
114 | editLayout->addWidget(_casterPortLineEdit, 0, 3);
|
---|
115 | editLayout->addWidget(new QLabel(tr("Casters table")), 0, 4, Qt::AlignRight);
|
---|
116 | editLayout->addWidget(_buttonCasterTable, 0, 5);
|
---|
117 | editLayout->addWidget(new QLabel(tr("User")), 1, 0, Qt::AlignRight);
|
---|
118 | editLayout->addWidget(_casterUserLineEdit, 1, 1);
|
---|
119 | editLayout->addWidget(new QLabel(tr("Password")), 1, 2, Qt::AlignRight);
|
---|
120 | editLayout->addWidget(_casterPasswordLineEdit, 1, 3);
|
---|
121 | editLayout->addWidget(new QLabel(tr(" NTRIP Version")),1, 4, Qt::AlignRight);
|
---|
122 | editLayout->addWidget(_ntripVersionComboBox, 1, 5);
|
---|
123 |
|
---|
124 | mainLayout->addLayout(editLayout);
|
---|
125 |
|
---|
126 | _buttonCasterTable->setWhatsThis(tr("<p>Hit 'Show' for a table of known NTRIP broadcaster installations as maintained at <u>www.rtcm-ntrip.org/home.</u></p><p>A window opens which allows to select a broadcaster for stream retrieval.</p>"));
|
---|
127 | _ntripVersionComboBox->setWhatsThis(tr("<p>Select the NTRIP transport protocol version you want to use. Implemented options are:<br> 1: NTRIP version 1, TCP/IP<br> 2: NTRIP version 2, TCP/IP mode<br> R: NTRIP Version 2, RTSP/RTP mode<br>Select option '1' if you are not sure whether the NTRIP broadcaster supports NTRIP version 2.</p><p>Note that RTSP/RTP (option 'R') is sometimes not supported by mobile Internet Service Providers.</p>"));
|
---|
128 |
|
---|
129 | _table = new QTableWidget(this);
|
---|
130 | _table->setWhatsThis(tr("<p>Use the 'Get Table' button to download the sourcetable from the selected NTRIP broadcaster. Select the desired streams line by line, using +Shift and +Ctrl when necessary. Hit 'OK' to return to the main window.</p><p>Pay attention to data field 'format'. Keep in mind that BNC can only decode and convert streams that come in RTCM Version 2.x, RTCM Version 3.x, or RTIGS format. See data field 'format-details' for available message types and their repetition rates in brackets.</p><p>The content of data field 'nmea' tells you whether a stream comes from a virtual reference station (VRS).</p>"));
|
---|
131 | connect(_table, SIGNAL(itemSelectionChanged()),
|
---|
132 | this, SLOT(slotSelectionChanged()));
|
---|
133 | mainLayout->addWidget(_table);
|
---|
134 |
|
---|
135 | _buttonWhatsThis = new QPushButton(tr("Help=Shift+F1"), this);
|
---|
136 | connect(_buttonWhatsThis, SIGNAL(clicked()), this, SLOT(slotWhatsThis()));
|
---|
137 |
|
---|
138 | _buttonGet = new QPushButton(tr("Get table"), this);
|
---|
139 | _buttonGet->setDefault(true);
|
---|
140 | connect(_buttonGet, SIGNAL(clicked()), this, SLOT(slotGetTable()));
|
---|
141 |
|
---|
142 | _buttonCancel = new QPushButton(tr("Cancel"), this);
|
---|
143 | connect(_buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
|
---|
144 |
|
---|
145 | _buttonOK = new QPushButton(tr("OK"), this);
|
---|
146 | connect(_buttonOK, SIGNAL(clicked()), this, SLOT(accept()));
|
---|
147 |
|
---|
148 | QHBoxLayout* buttonLayout = new QHBoxLayout;
|
---|
149 | buttonLayout->addWidget(_buttonWhatsThis);
|
---|
150 | buttonLayout->addStretch(1);
|
---|
151 | buttonLayout->addWidget(_buttonGet);
|
---|
152 | buttonLayout->addWidget(_buttonCancel);
|
---|
153 | buttonLayout->addWidget(_buttonOK);
|
---|
154 |
|
---|
155 | mainLayout->addLayout(buttonLayout);
|
---|
156 | }
|
---|
157 |
|
---|
158 | // Destructor
|
---|
159 | ////////////////////////////////////////////////////////////////////////////
|
---|
160 | bncTableDlg::~bncTableDlg() {
|
---|
161 | delete _casterHostComboBox;
|
---|
162 | delete _casterPortLineEdit;
|
---|
163 | delete _casterUserLineEdit;
|
---|
164 | delete _casterPasswordLineEdit;
|
---|
165 | delete _ntripVersionComboBox;
|
---|
166 | delete _buttonGet;
|
---|
167 | delete _buttonCancel;
|
---|
168 | delete _buttonOK;
|
---|
169 | delete _buttonWhatsThis;
|
---|
170 | delete _buttonCasterTable;
|
---|
171 | delete _table;
|
---|
172 | }
|
---|
173 |
|
---|
174 | // Read full caster table (static)
|
---|
175 | ////////////////////////////////////////////////////////////////////////////
|
---|
176 | t_irc bncTableDlg::getFullTable(const QString& casterHost,
|
---|
177 | int casterPort, QStringList& allLines,
|
---|
178 | bool alwaysRead) {
|
---|
179 |
|
---|
180 | static QMutex mutex;
|
---|
181 | static QMap<QString, QStringList> allTables;
|
---|
182 |
|
---|
183 | QMutexLocker locker(&mutex);
|
---|
184 |
|
---|
185 | if (!alwaysRead && allTables.find(casterHost) != allTables.end()) {
|
---|
186 | allLines = allTables.find(casterHost).value();
|
---|
187 | return success;
|
---|
188 | }
|
---|
189 |
|
---|
190 | allLines.clear();
|
---|
191 |
|
---|
192 | QUrl url;
|
---|
193 | url.setHost(casterHost);
|
---|
194 | url.setPort(casterPort);
|
---|
195 | url.setScheme("http");
|
---|
196 | url.setPath("/");
|
---|
197 |
|
---|
198 | bncNetQueryV2 query;
|
---|
199 | QByteArray outData;
|
---|
200 | query.waitForRequestResult(url, outData);
|
---|
201 | if (query.status() == bncNetQuery::finished) {
|
---|
202 | QTextStream in(outData);
|
---|
203 | QString line = in.readLine();
|
---|
204 | while ( !line.isNull() ) {
|
---|
205 | allLines.append(line);
|
---|
206 | line = in.readLine();
|
---|
207 | }
|
---|
208 | allTables.insert(casterHost, allLines);
|
---|
209 | return success;
|
---|
210 | }
|
---|
211 | else {
|
---|
212 | return failure;
|
---|
213 | }
|
---|
214 | }
|
---|
215 |
|
---|
216 | // Read Table from Caster
|
---|
217 | ////////////////////////////////////////////////////////////////////////////
|
---|
218 | void bncTableDlg::slotGetTable() {
|
---|
219 |
|
---|
220 | _buttonGet->setEnabled(false);
|
---|
221 | _buttonCasterTable->setEnabled(false);
|
---|
222 |
|
---|
223 | if ( getFullTable(_casterHostComboBox->currentText(),
|
---|
224 | _casterPortLineEdit->text().toInt(),
|
---|
225 | _allLines, true) != success ) {
|
---|
226 | QMessageBox::warning(0, "BNC", "Cannot retrieve table of data");
|
---|
227 | _buttonGet->setEnabled(true);
|
---|
228 | return;
|
---|
229 | }
|
---|
230 |
|
---|
231 | static const QStringList labels = QString("mountpoint,identifier,format,"
|
---|
232 | "format-details,carrier,system,network,country,lat,long,"
|
---|
233 | "nmea,solution,generator,compress.,auth.,fee,bitrate,"
|
---|
234 | "misc").split(",");
|
---|
235 |
|
---|
236 | QStringList lines;
|
---|
237 | QStringListIterator it(_allLines);
|
---|
238 | while (it.hasNext()) {
|
---|
239 | QString line = it.next();
|
---|
240 | if (line.indexOf("STR") == 0) {
|
---|
241 | QStringList hlp = line.split(";");
|
---|
242 | if (hlp.size() > labels.size()) {
|
---|
243 | lines.push_back(line);
|
---|
244 | }
|
---|
245 | }
|
---|
246 | }
|
---|
247 |
|
---|
248 | if (lines.size() > 0) {
|
---|
249 | _table->setSelectionMode(QAbstractItemView::ExtendedSelection);
|
---|
250 | _table->setSelectionBehavior(QAbstractItemView::SelectRows);
|
---|
251 | _table->setColumnCount(labels.size());
|
---|
252 | _table->setRowCount(lines.size());
|
---|
253 | for (int nRow = 0; nRow < lines.size(); nRow++) {
|
---|
254 | QStringList columns = lines[nRow].split(";");
|
---|
255 | for (int ic = 1; ic < columns.size(); ic++) {
|
---|
256 | if (ic == 11) {
|
---|
257 | if (columns[ic] == "0") {
|
---|
258 | columns[ic] = "no";
|
---|
259 | } else {
|
---|
260 | columns[ic] = "yes";
|
---|
261 | }
|
---|
262 | }
|
---|
263 | QTableWidgetItem* item = new QTableWidgetItem(columns[ic]);
|
---|
264 | item->setFlags(item->flags() & ~Qt::ItemIsEditable);
|
---|
265 | _table->setItem(nRow, ic-1, item);
|
---|
266 | }
|
---|
267 | }
|
---|
268 | _table->setHorizontalHeaderLabels(labels);
|
---|
269 | _table->setSortingEnabled(true);
|
---|
270 | int ww = QFontMetrics(this->font()).width('w');
|
---|
271 | _table->horizontalHeader()->resizeSection( 0,10*ww);
|
---|
272 | _table->horizontalHeader()->resizeSection( 1,10*ww);
|
---|
273 | _table->horizontalHeader()->resizeSection( 2, 8*ww);
|
---|
274 | _table->horizontalHeader()->resizeSection( 3,22*ww);
|
---|
275 | _table->horizontalHeader()->resizeSection( 4, 5*ww);
|
---|
276 | _table->horizontalHeader()->resizeSection( 5, 8*ww);
|
---|
277 | _table->horizontalHeader()->resizeSection( 6, 8*ww);
|
---|
278 | _table->horizontalHeader()->resizeSection( 7, 7*ww);
|
---|
279 | _table->horizontalHeader()->resizeSection( 8, 6*ww);
|
---|
280 | _table->horizontalHeader()->resizeSection( 9, 6*ww);
|
---|
281 | _table->horizontalHeader()->resizeSection(10, 6*ww);
|
---|
282 | _table->horizontalHeader()->resizeSection(11, 6*ww);
|
---|
283 | _table->horizontalHeader()->resizeSection(12,15*ww);
|
---|
284 | _table->horizontalHeader()->resizeSection(13, 8*ww);
|
---|
285 | _table->horizontalHeader()->resizeSection(14, 5*ww);
|
---|
286 | _table->horizontalHeader()->resizeSection(15, 5*ww);
|
---|
287 | _table->horizontalHeader()->resizeSection(16, 7*ww);
|
---|
288 | _table->horizontalHeader()->resizeSection(17,15*ww);
|
---|
289 | _table->sortItems(0);
|
---|
290 | }
|
---|
291 | }
|
---|
292 |
|
---|
293 | // Accept slot
|
---|
294 | ////////////////////////////////////////////////////////////////////////////
|
---|
295 | void bncTableDlg::accept() {
|
---|
296 |
|
---|
297 | bncSettings settings;
|
---|
298 | settings.setValue("ntripVersion", _ntripVersionComboBox->currentText());
|
---|
299 | QUrl url;
|
---|
300 | url.setScheme("http");
|
---|
301 | url.setHost(_casterHostComboBox->currentText());
|
---|
302 | url.setPort(_casterPortLineEdit->text().toInt());
|
---|
303 | url.setUserName(QUrl::toPercentEncoding(_casterUserLineEdit->text()));
|
---|
304 | url.setPassword(QUrl::toPercentEncoding(_casterPasswordLineEdit->text()));
|
---|
305 | addUrl(url);
|
---|
306 |
|
---|
307 | QStringList* mountPoints = new QStringList;
|
---|
308 |
|
---|
309 | if (_table) {
|
---|
310 | for (int ir = 0; ir < _table->rowCount(); ir++) {
|
---|
311 | QTableWidgetItem* item = _table->item(ir,0);
|
---|
312 | QString format = _table->item(ir,2)->text();
|
---|
313 | QString latitude = _table->item(ir,8)->text();
|
---|
314 | QString longitude = _table->item(ir,9)->text();
|
---|
315 | QString nmea = _table->item(ir,10)->text();
|
---|
316 | QString ntripVersion = _ntripVersionComboBox->currentText();
|
---|
317 | format.replace(" ", "_");
|
---|
318 | if (_table->isItemSelected(item)) {
|
---|
319 | url.setPath(item->text());
|
---|
320 | mountPoints->push_back(url.toString() + " " + format + " " + latitude
|
---|
321 | + " " + longitude + " " + nmea + " " + ntripVersion);
|
---|
322 | }
|
---|
323 | }
|
---|
324 | }
|
---|
325 | emit newMountPoints(mountPoints);
|
---|
326 |
|
---|
327 | QDialog::accept();
|
---|
328 | }
|
---|
329 |
|
---|
330 | // User changed the selection of mountPoints
|
---|
331 | ////////////////////////////////////////////////////////////////////////////
|
---|
332 | void bncTableDlg::slotSelectionChanged() {
|
---|
333 | if (_table->selectedItems().isEmpty()) {
|
---|
334 | }
|
---|
335 | }
|
---|
336 |
|
---|
337 | // Whats This Help
|
---|
338 | void bncTableDlg::slotWhatsThis() {
|
---|
339 | QWhatsThis::enterWhatsThisMode();
|
---|
340 | }
|
---|
341 |
|
---|
342 | // Slot caster table
|
---|
343 | ////////////////////////////////////////////////////////////////////////////
|
---|
344 | void bncTableDlg::slotCasterTable() {
|
---|
345 |
|
---|
346 | _buttonCasterTable->setEnabled(false);
|
---|
347 | _casterHostComboBox->setEnabled(false);
|
---|
348 | _casterPortLineEdit->setEnabled(false);
|
---|
349 | _casterUserLineEdit->setEnabled(false);
|
---|
350 | _casterPasswordLineEdit->setEnabled(false);
|
---|
351 | _ntripVersionComboBox->setEnabled(false);
|
---|
352 | _buttonWhatsThis->setEnabled(false);
|
---|
353 | _buttonGet->setEnabled(false);
|
---|
354 | _buttonCancel->setEnabled(false);
|
---|
355 | _buttonOK->setEnabled(false);
|
---|
356 |
|
---|
357 | bncCasterTableDlg* dlg = new bncCasterTableDlg(this);
|
---|
358 | dlg->move(this->pos().x()+50, this->pos().y()+50);
|
---|
359 | connect(dlg, SIGNAL(newCaster(QString, QString)),
|
---|
360 | this, SLOT(slotNewCaster(QString, QString)));
|
---|
361 | dlg->exec();
|
---|
362 | delete dlg;
|
---|
363 |
|
---|
364 | _buttonCasterTable->setEnabled(true);
|
---|
365 | _casterHostComboBox->setEnabled(true);
|
---|
366 | _casterPortLineEdit->setEnabled(true);
|
---|
367 | _casterUserLineEdit->setEnabled(true);
|
---|
368 | _casterPasswordLineEdit->setEnabled(true);
|
---|
369 | _ntripVersionComboBox->setEnabled(true);
|
---|
370 | _buttonWhatsThis->setEnabled(true);
|
---|
371 | _buttonGet->setEnabled(true);
|
---|
372 | _buttonCancel->setEnabled(true);
|
---|
373 | _buttonOK->setEnabled(true);
|
---|
374 |
|
---|
375 | }
|
---|
376 |
|
---|
377 | // New caster selected
|
---|
378 | ////////////////////////////////////////////////////////////////////////////
|
---|
379 | void bncTableDlg::slotNewCaster(QString newCasterHost, QString newCasterPort) {
|
---|
380 |
|
---|
381 | _casterHostComboBox->insertItem(0, newCasterHost);
|
---|
382 | _casterHostComboBox->setCurrentIndex(0);
|
---|
383 | _casterUserLineEdit->setText("");
|
---|
384 | _casterPasswordLineEdit->setText("");
|
---|
385 | _casterPortLineEdit->setText(newCasterPort);
|
---|
386 |
|
---|
387 | QUrl url;
|
---|
388 | url.setScheme("http");
|
---|
389 | url.setHost(newCasterHost);
|
---|
390 | url.setPort(newCasterPort.toInt());
|
---|
391 | addUrl(url);
|
---|
392 |
|
---|
393 | _casterHostComboBox->setCurrentIndex(0);
|
---|
394 | }
|
---|
395 |
|
---|
396 | // New caster selected
|
---|
397 | ////////////////////////////////////////////////////////////////////////////
|
---|
398 | void bncTableDlg::addUrl(const QUrl& url) {
|
---|
399 | bncSettings settings;
|
---|
400 | QStringList oldUrlList = settings.value("casterUrlList").toStringList();
|
---|
401 | QStringList newUrlList;
|
---|
402 | newUrlList << url.toString();
|
---|
403 | for (int ii = 0; ii < oldUrlList.count(); ii++) {
|
---|
404 | QUrl oldUrl(oldUrlList[ii]);
|
---|
405 | if (url.host() != oldUrl.host()) {
|
---|
406 | newUrlList << oldUrl.toString();
|
---|
407 | }
|
---|
408 | }
|
---|
409 | settings.setValue("casterUrlList", newUrlList);
|
---|
410 | settings.sync();
|
---|
411 | }
|
---|
412 |
|
---|
413 | // New caster selected in combobox
|
---|
414 | ////////////////////////////////////////////////////////////////////////////
|
---|
415 | void bncTableDlg::slotCasterHostChanged(const QString& newHost) {
|
---|
416 | bncSettings settings;
|
---|
417 | QStringList casterUrlList = settings.value("casterUrlList").toStringList();
|
---|
418 | for (int ii = 0; ii < casterUrlList.count(); ii++) {
|
---|
419 | QUrl url(casterUrlList[ii]);
|
---|
420 | if (url.host() == newHost) {
|
---|
421 | _casterUserLineEdit->setText(
|
---|
422 | QUrl::fromPercentEncoding(url.userName().toAscii()));
|
---|
423 | _casterPasswordLineEdit->setText(
|
---|
424 | QUrl::fromPercentEncoding(url.password().toAscii()));
|
---|
425 | if (url.port() > 0) {
|
---|
426 | _casterPortLineEdit->setText(QString("%1").arg(url.port()));
|
---|
427 | }
|
---|
428 | else {
|
---|
429 | _casterPortLineEdit->setText("");
|
---|
430 | }
|
---|
431 | }
|
---|
432 | }
|
---|
433 | }
|
---|
434 |
|
---|
435 | // Caster table
|
---|
436 | ////////////////////////////////////////////////////////////////////////////
|
---|
437 | bncCasterTableDlg::bncCasterTableDlg(QWidget* parent) :
|
---|
438 | QDialog(parent) {
|
---|
439 |
|
---|
440 | static const QStringList labels = QString("host,port,identifier,operator,nmea,country,lat,long,link").split(",");
|
---|
441 |
|
---|
442 | _casterTable = new QTableWidget(this);
|
---|
443 |
|
---|
444 | QUrl url;
|
---|
445 | url.setHost("www.rtcm-ntrip.org");
|
---|
446 | url.setPort(2101);
|
---|
447 | url.setScheme("http");
|
---|
448 | url.setPath("/");
|
---|
449 |
|
---|
450 | bncNetQueryV2 query;
|
---|
451 | QByteArray outData;
|
---|
452 | query.waitForRequestResult(url, outData);
|
---|
453 |
|
---|
454 | QStringList lines;
|
---|
455 | if (query.status() == bncNetQuery::finished) {
|
---|
456 | QTextStream in(outData);
|
---|
457 | QString line = in.readLine();
|
---|
458 | while ( !line.isNull() ) {
|
---|
459 | line = in.readLine();
|
---|
460 | if (line.indexOf("CAS") == 0) {
|
---|
461 | QStringList hlp = line.split(";");
|
---|
462 | if (hlp.size() > labels.size()) {
|
---|
463 | lines.push_back(line);
|
---|
464 | }
|
---|
465 | }
|
---|
466 | }
|
---|
467 | }
|
---|
468 |
|
---|
469 | if (lines.size() > 0) {
|
---|
470 | _casterTable->setSelectionMode(QAbstractItemView::ExtendedSelection);
|
---|
471 | _casterTable->setSelectionBehavior(QAbstractItemView::SelectRows);
|
---|
472 |
|
---|
473 | QStringList hlp = lines[0].split(";");
|
---|
474 | _casterTable->setColumnCount(labels.size());
|
---|
475 | _casterTable->setRowCount(lines.size());
|
---|
476 |
|
---|
477 | for (int nRow = 0; nRow < lines.size(); nRow++) {
|
---|
478 | QStringList columns = lines[nRow].split(";");
|
---|
479 | for (int ic = 1; ic < columns.size(); ic++) {
|
---|
480 | if (ic == 5) {
|
---|
481 | if (columns[ic] == "0") {
|
---|
482 | columns[ic] = "no";
|
---|
483 | } else {
|
---|
484 | columns[ic] = "yes";
|
---|
485 | }
|
---|
486 | }
|
---|
487 | QTableWidgetItem* item = new QTableWidgetItem(columns[ic]);
|
---|
488 | item->setFlags(item->flags() & ~Qt::ItemIsEditable);
|
---|
489 | _casterTable->setItem(nRow, ic-1, item);
|
---|
490 | }
|
---|
491 | }
|
---|
492 | }
|
---|
493 | _casterTable->setHorizontalHeaderLabels(labels);
|
---|
494 | _casterTable->setSortingEnabled(true);
|
---|
495 | _casterTable->sortItems(0);
|
---|
496 | int ww = QFontMetrics(this->font()).width('w');
|
---|
497 | _casterTable->horizontalHeader()->resizeSection(0,15*ww);
|
---|
498 | _casterTable->horizontalHeader()->resizeSection(1, 5*ww);
|
---|
499 | _casterTable->horizontalHeader()->resizeSection(2,15*ww);
|
---|
500 | _casterTable->horizontalHeader()->resizeSection(3,15*ww);
|
---|
501 | _casterTable->horizontalHeader()->resizeSection(4, 5*ww);
|
---|
502 | _casterTable->horizontalHeader()->resizeSection(5, 7*ww);
|
---|
503 | _casterTable->horizontalHeader()->resizeSection(6, 7*ww);
|
---|
504 | _casterTable->horizontalHeader()->resizeSection(7, 7*ww);
|
---|
505 | _casterTable->horizontalHeader()->resizeSection(8,15*ww);
|
---|
506 |
|
---|
507 | _closeButton = new QPushButton("Cancel");
|
---|
508 | connect(_closeButton, SIGNAL(clicked()), this, SLOT(close()));
|
---|
509 | _closeButton->setMinimumWidth(8*ww);
|
---|
510 | _closeButton->setMaximumWidth(8*ww);
|
---|
511 |
|
---|
512 | _okButton = new QPushButton(tr("OK"), this);
|
---|
513 | connect(_okButton, SIGNAL(clicked()), this, SLOT(slotAcceptCasterTable()));
|
---|
514 | _okButton->setMinimumWidth(8*ww);
|
---|
515 | _okButton->setMaximumWidth(8*ww);
|
---|
516 |
|
---|
517 | _whatsThisButton = new QPushButton(tr("Help=Shift+F1"), this);
|
---|
518 | connect(_whatsThisButton, SIGNAL(clicked()), this, SLOT(slotWhatsThis()));
|
---|
519 | _whatsThisButton->setMinimumWidth(12*ww);
|
---|
520 | _whatsThisButton->setMaximumWidth(12*ww);
|
---|
521 |
|
---|
522 | _casterTable->setWhatsThis(tr("<p>Select an NTRIP broadcaster and hit 'OK'.</p><p>See <u>http://www.rtcm-ntrip.org/home</u> for further details on known NTRIP broadcaster installations.</u>."));
|
---|
523 |
|
---|
524 | QGridLayout* dlgLayout = new QGridLayout();
|
---|
525 | dlgLayout->addWidget(new QLabel(" List of NTRIP Broadcasters from www.rtcm-ntrip.org"), 0,0,1,3,Qt::AlignLeft);
|
---|
526 | dlgLayout->addWidget(_casterTable, 1, 0, 1, 3);
|
---|
527 | dlgLayout->addWidget(_whatsThisButton, 2, 0);
|
---|
528 | dlgLayout->addWidget(_closeButton, 2, 1, Qt::AlignRight);
|
---|
529 | dlgLayout->addWidget(_okButton, 2, 2);
|
---|
530 |
|
---|
531 | setMinimumSize(600,400);
|
---|
532 | setWindowTitle(tr("Select Broadcaster"));
|
---|
533 | setLayout(dlgLayout);
|
---|
534 | resize(68*ww, 50*ww);
|
---|
535 | show();
|
---|
536 | }
|
---|
537 |
|
---|
538 | // Caster table destructor
|
---|
539 | ////////////////////////////////////////////////////////////////////////////
|
---|
540 | bncCasterTableDlg::~bncCasterTableDlg() {
|
---|
541 | delete _casterTable;
|
---|
542 | delete _okButton;
|
---|
543 | delete _closeButton;
|
---|
544 | delete _whatsThisButton;
|
---|
545 | }
|
---|
546 |
|
---|
547 | // Caster table what's this
|
---|
548 | ////////////////////////////////////////////////////////////////////////////
|
---|
549 | void bncCasterTableDlg:: slotWhatsThis() {
|
---|
550 | QWhatsThis::enterWhatsThisMode();
|
---|
551 | }
|
---|
552 |
|
---|
553 | // Accept caster table
|
---|
554 | ////////////////////////////////////////////////////////////////////////////
|
---|
555 | void bncCasterTableDlg::slotAcceptCasterTable() {
|
---|
556 | if (_casterTable) {
|
---|
557 | for (int ir = _casterTable->rowCount() - 1; ir >= 0 ; ir--) {
|
---|
558 | if (_casterTable->isItemSelected(_casterTable->item(ir,0))) {
|
---|
559 | emit newCaster(_casterTable->item(ir,0)->text(),
|
---|
560 | _casterTable->item(ir,1)->text());
|
---|
561 | }
|
---|
562 | }
|
---|
563 | }
|
---|
564 | QDialog::accept();
|
---|
565 | }
|
---|
566 |
|
---|