source: ntrip/trunk/BNC/src/bnctabledlg.cpp@ 6429

Last change on this file since 6429 was 4714, checked in by mervart, 12 years ago
File size: 23.8 KB
RevLine 
[280]1// Part of BNC, a utility for retrieving decoding and
[464]2// converting GNSS data streams from NTRIP broadcasters.
[280]3//
[464]4// Copyright (C) 2007
[280]5// German Federal Agency for Cartography and Geodesy (BKG)
6// http://www.bkg.bund.de
[464]7// Czech Technical University Prague, Department of Geodesy
[280]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.
[35]24
25/* -------------------------------------------------------------------------
[93]26 * BKG NTRIP Client
[35]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
[1493]41#include <iostream>
42
[35]43#include "bnctabledlg.h"
44#include "bncgetthread.h"
[1848]45#include "bncnetqueryv1.h"
[3335]46#include "bncnetqueryv2.h"
[1535]47#include "bncsettings.h"
[2753]48#include "bncmap.h"
[35]49
[1373]50using namespace std;
51
[35]52// Constructor
53////////////////////////////////////////////////////////////////////////////
[90]54bncTableDlg::bncTableDlg(QWidget* parent) : QDialog(parent) {
[35]55
56 setMinimumSize(600,400);
[1611]57 setWindowTitle(tr("Add Streams from Caster"));
[35]58
59 QVBoxLayout* mainLayout = new QVBoxLayout(this);
60
[1474]61 int ww = QFontMetrics(font()).width('w');
62
63 _casterPortLineEdit = new QLineEdit();
64 _casterPortLineEdit->setMaximumWidth(9*ww);
65
66 _casterUserLineEdit = new QLineEdit();
67 _casterUserLineEdit->setMaximumWidth(9*ww);
68
69 _casterPasswordLineEdit = new QLineEdit();
70 _casterPasswordLineEdit->setMaximumWidth(9*ww);
[3294]71 _casterPasswordLineEdit->setEchoMode(QLineEdit::PasswordEchoOnEdit);
[1474]72
73 _casterHostComboBox = new QComboBox();
[1482]74 _casterHostComboBox->setMaxCount(10);
[1474]75 _casterHostComboBox->setDuplicatesEnabled(false);
76 _casterHostComboBox->setEditable(true);
[1477]77 _casterHostComboBox->setMinimumWidth(20*ww);
[1474]78 _casterHostComboBox->setMaximumWidth(20*ww);
79 connect(_casterHostComboBox, SIGNAL(currentIndexChanged(const QString&)),
80 this, SLOT(slotCasterHostChanged(const QString&)));
[1535]81 bncSettings settings;
[1481]82 settings.remove("casterHostList");
83 settings.remove("casterHost");
84 settings.remove("casterPort");
85 settings.remove("casterUser");
86 settings.remove("casterPassword");
[1476]87 QStringList casterUrlList = settings.value("casterUrlList").toStringList();
88 for (int ii = 0; ii < casterUrlList.count(); ii++) {
89 QUrl url(casterUrlList[ii]);
[1474]90 _casterHostComboBox->addItem(url.host());
[1274]91 }
[683]92
[1350]93 _ntripVersionComboBox = new QComboBox();
[3335]94 _ntripVersionComboBox->addItems(QString("1,2,2s,R,U").split(","));
[1350]95 int kk = _ntripVersionComboBox->findText(settings.value("ntripVersion").toString());
96 if (kk != -1) {
97 _ntripVersionComboBox->setCurrentIndex(kk);
98 }
[1459]99 _ntripVersionComboBox->setMaximumWidth(5*ww);
[1350]100
[1459]101 _buttonCasterTable = new QPushButton(tr("Show"), this);
102 connect(_buttonCasterTable, SIGNAL(clicked()), this, SLOT(slotCasterTable()));
103 _buttonCasterTable->setMaximumWidth(5*ww);
104
[683]105 // WhatsThis
106 // ---------
[1459]107 _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>"));
[1474]108 _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>"));
[1459]109 _casterPortLineEdit->setWhatsThis(tr("Enter the NTRIP broadcaster port number."));
110 _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."));
[35]111
[88]112 QGridLayout* editLayout = new QGridLayout;
[1459]113 editLayout->addWidget(new QLabel(tr("Caster host")), 0, 0);
[1474]114 editLayout->addWidget(_casterHostComboBox, 0, 1);
[1459]115 editLayout->addWidget(new QLabel(tr(" Caster port")), 0, 2, Qt::AlignRight);
116 editLayout->addWidget(_casterPortLineEdit, 0, 3);
[1598]117 editLayout->addWidget(new QLabel(tr("Casters table")), 0, 4, Qt::AlignRight);
[1459]118 editLayout->addWidget(_buttonCasterTable, 0, 5);
119 editLayout->addWidget(new QLabel(tr("User")), 1, 0, Qt::AlignRight);
120 editLayout->addWidget(_casterUserLineEdit, 1, 1);
121 editLayout->addWidget(new QLabel(tr("Password")), 1, 2, Qt::AlignRight);
122 editLayout->addWidget(_casterPasswordLineEdit, 1, 3);
123 editLayout->addWidget(new QLabel(tr(" NTRIP Version")),1, 4, Qt::AlignRight);
124 editLayout->addWidget(_ntripVersionComboBox, 1, 5);
[88]125
[35]126 mainLayout->addLayout(editLayout);
127
[1471]128 _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>"));
[3780]129 _ntripVersionComboBox->setWhatsThis(tr("<p>Select the NTRIP transport protocol version you want to use. Implemented options are:<br>&nbsp; 1:&nbsp; NTRIP version 1, TCP/IP<br>&nbsp; 2:&nbsp; NTRIP version 2, TCP/IP mode<br>&nbsp; 2s:&nbsp; NTRIP version 2 TCP/IP mode via SSL<br>&nbsp; R:&nbsp; NTRIP Version 2, RTSP/RTP mode<br>&nbsp; U:&nbsp; NTRIP Version 2, UDP 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') and UDP (option 'U') are not accepted by proxies and sometimes not supported by mobile Internet Service Providers.</p>"));
[1409]130
[35]131 _table = new QTableWidget(this);
[3345]132 _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, or RTCM Version 3.x 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>"));
[195]133 connect(_table, SIGNAL(itemSelectionChanged()),
134 this, SLOT(slotSelectionChanged()));
[35]135 mainLayout->addWidget(_table);
136
[402]137 _buttonWhatsThis = new QPushButton(tr("Help=Shift+F1"), this);
[399]138 connect(_buttonWhatsThis, SIGNAL(clicked()), this, SLOT(slotWhatsThis()));
139
[195]140 _buttonGet = new QPushButton(tr("Get table"), this);
[399]141 _buttonGet->setDefault(true);
[35]142 connect(_buttonGet, SIGNAL(clicked()), this, SLOT(slotGetTable()));
[366]143
[2753]144 _buttonMap = new QPushButton(tr("Map"), this);
145 _buttonMap->setEnabled(false);
146 connect(_buttonMap, SIGNAL(clicked()), this, SLOT(slotShowMap()));
147
[2796]148 _buttonClose = new QPushButton(tr("Close"), this);
149 connect(_buttonClose, SIGNAL(clicked()), this, SLOT(close()));
[35]150
[2796]151 _buttonSelect = new QPushButton(tr("Select"), this);
152 connect(_buttonSelect, SIGNAL(clicked()), this, SLOT(select()));
[35]153
[4709]154 // WhatsThis
155 // ---------
156 _buttonMap->setWhatsThis(tr("<p>Draw distribution map of streams in downloaded caster source-table.</p>"));
157 _buttonGet->setWhatsThis(tr("<p>Download source-table from specified caster.</p>"));
158 _buttonClose->setWhatsThis(tr("<p>Close window.</p>"));
[4710]159 _buttonSelect->setWhatsThis(tr("<p>Select streams highlighted in downloaded source-table for processing.</p>"));
[4709]160
[35]161 QHBoxLayout* buttonLayout = new QHBoxLayout;
[399]162 buttonLayout->addWidget(_buttonWhatsThis);
[35]163 buttonLayout->addStretch(1);
[2753]164 buttonLayout->addWidget(_buttonMap);
[35]165 buttonLayout->addWidget(_buttonGet);
[2796]166 buttonLayout->addWidget(_buttonSelect);
167 buttonLayout->addWidget(_buttonClose);
[35]168
169 mainLayout->addLayout(buttonLayout);
170}
171
172// Destructor
173////////////////////////////////////////////////////////////////////////////
174bncTableDlg::~bncTableDlg() {
[1490]175 delete _casterHostComboBox;
176 delete _casterPortLineEdit;
177 delete _casterUserLineEdit;
178 delete _casterPasswordLineEdit;
[3361]179 bncSettings settings;
180 settings.setValue("ntripVersion", _ntripVersionComboBox->currentText());
[1490]181 delete _ntripVersionComboBox;
[4709]182 delete _buttonMap;
[1490]183 delete _buttonGet;
[2796]184 delete _buttonClose;
185 delete _buttonSelect;
[1490]186 delete _buttonWhatsThis;
187 delete _buttonCasterTable;
188 delete _table;
[35]189}
190
[1493]191// Read full caster table (static)
[35]192////////////////////////////////////////////////////////////////////////////
[3335]193t_irc bncTableDlg::getFullTable(const QString& ntripVersion,
194 const QString& casterHost,
[1376]195 int casterPort, QStringList& allLines,
196 bool alwaysRead) {
[35]197
[299]198 static QMutex mutex;
[298]199 static QMap<QString, QStringList> allTables;
200
[299]201 QMutexLocker locker(&mutex);
202
[298]203 if (!alwaysRead && allTables.find(casterHost) != allTables.end()) {
204 allLines = allTables.find(casterHost).value();
205 return success;
206 }
207
[191]208 allLines.clear();
209
[3335]210 bncNetQuery* query = 0;
[3337]211 if (ntripVersion == "2") {
212 query = new bncNetQueryV2(false);
[3335]213 }
[3337]214 else if (ntripVersion == "2s") {
215 query = new bncNetQueryV2(true);
216 }
[3335]217 else {
218 query = new bncNetQueryV1();
219 }
220
[88]221 QUrl url;
[191]222 url.setHost(casterHost);
223 url.setPort(casterPort);
[1375]224 url.setPath("/");
[3335]225 if (ntripVersion == "2s") {
226 url.setScheme("https");
227 }
228 else {
229 url.setScheme("http");
230 }
[35]231
[1373]232 QByteArray outData;
[3335]233 query->waitForRequestResult(url, outData);
234 if (query->status() == bncNetQuery::finished) {
[1375]235 QTextStream in(outData);
236 QString line = in.readLine();
237 while ( !line.isNull() ) {
238 allLines.append(line);
239 line = in.readLine();
240 }
241 allTables.insert(casterHost, allLines);
[3335]242 delete query;
[1375]243 return success;
244 }
245 else {
[3335]246 delete query;
[191]247 return failure;
[35]248 }
[191]249}
250
251// Read Table from Caster
252////////////////////////////////////////////////////////////////////////////
253void bncTableDlg::slotGetTable() {
254
[555]255 _buttonGet->setEnabled(false);
[2753]256 _buttonMap->setEnabled(true);
[1459]257 _buttonCasterTable->setEnabled(false);
[555]258
[3335]259 if ( getFullTable(_ntripVersionComboBox->currentText(),
260 _casterHostComboBox->currentText(),
[191]261 _casterPortLineEdit->text().toInt(),
[1493]262 _allLines, true) != success ) {
[191]263 QMessageBox::warning(0, "BNC", "Cannot retrieve table of data");
[645]264 _buttonGet->setEnabled(true);
[191]265 return;
266 }
[2753]267
[1493]268 static const QStringList labels = QString("mountpoint,identifier,format,"
269 "format-details,carrier,system,network,country,lat,long,"
270 "nmea,solution,generator,compress.,auth.,fee,bitrate,"
271 "misc").split(",");
272
[191]273 QStringList lines;
[196]274 QStringListIterator it(_allLines);
[191]275 while (it.hasNext()) {
276 QString line = it.next();
277 if (line.indexOf("STR") == 0) {
[1493]278 QStringList hlp = line.split(";");
279 if (hlp.size() > labels.size()) {
280 lines.push_back(line);
281 }
[191]282 }
283 }
284
285 if (lines.size() > 0) {
[35]286 _table->setSelectionMode(QAbstractItemView::ExtendedSelection);
287 _table->setSelectionBehavior(QAbstractItemView::SelectRows);
[1493]288 _table->setColumnCount(labels.size());
289 _table->setRowCount(lines.size());
290 for (int nRow = 0; nRow < lines.size(); nRow++) {
291 QStringList columns = lines[nRow].split(";");
292 for (int ic = 1; ic < columns.size(); ic++) {
293 if (ic == 11) {
294 if (columns[ic] == "0") {
295 columns[ic] = "no";
296 } else {
297 columns[ic] = "yes";
298 }
299 }
300 QTableWidgetItem* item = new QTableWidgetItem(columns[ic]);
301 item->setFlags(item->flags() & ~Qt::ItemIsEditable);
302 _table->setItem(nRow, ic-1, item);
[35]303 }
304 }
[103]305 _table->setHorizontalHeaderLabels(labels);
[104]306 _table->setSortingEnabled(true);
[371]307 int ww = QFontMetrics(this->font()).width('w');
[1493]308 _table->horizontalHeader()->resizeSection( 0,10*ww);
309 _table->horizontalHeader()->resizeSection( 1,10*ww);
310 _table->horizontalHeader()->resizeSection( 2, 8*ww);
311 _table->horizontalHeader()->resizeSection( 3,22*ww);
312 _table->horizontalHeader()->resizeSection( 4, 5*ww);
313 _table->horizontalHeader()->resizeSection( 5, 8*ww);
314 _table->horizontalHeader()->resizeSection( 6, 8*ww);
315 _table->horizontalHeader()->resizeSection( 7, 7*ww);
316 _table->horizontalHeader()->resizeSection( 8, 6*ww);
317 _table->horizontalHeader()->resizeSection( 9, 6*ww);
318 _table->horizontalHeader()->resizeSection(10, 6*ww);
319 _table->horizontalHeader()->resizeSection(11, 6*ww);
[371]320 _table->horizontalHeader()->resizeSection(12,15*ww);
[1493]321 _table->horizontalHeader()->resizeSection(13, 8*ww);
322 _table->horizontalHeader()->resizeSection(14, 5*ww);
323 _table->horizontalHeader()->resizeSection(15, 5*ww);
324 _table->horizontalHeader()->resizeSection(16, 7*ww);
[371]325 _table->horizontalHeader()->resizeSection(17,15*ww);
[1493]326 _table->sortItems(0);
[35]327 }
328}
329
[2753]330// Show world map
331////////////////////////////////////////////////////////////////////////////
332void bncTableDlg::slotShowMap() {
333
[4626]334 t_bncMap* bncMap = new t_bncMap(this);
[4658]335
[4714]336 bncMap->setMinimumSize(800, 600);
[2753]337
[4658]338 for (int ii = 0; ii < _allLines.size(); ii++) {
339 if (_allLines.at(ii).startsWith("STR") == true) {
340 QStringList tmp = _allLines.at(ii).split(';');
341 if (tmp.size() > 10) {
[4627]342 double latDeg = tmp.at(9).toDouble();
343 double lonDeg = tmp.at(10).toDouble();
344 QString name = tmp.at(1);
[4658]345 bncMap->slotNewPoint(name, latDeg, lonDeg);
[4627]346 }
347 }
348 }
[4658]349
350 bncMap->show();
[2753]351}
352
[2796]353// Select slot
[35]354////////////////////////////////////////////////////////////////////////////
[2796]355void bncTableDlg::select() {
[35]356
[3335]357 QString ntripVersion = _ntripVersionComboBox->currentText();
[3336]358
[1476]359 QUrl url;
[3335]360 if (ntripVersion == "2s") {
361 url.setScheme("https");
362 }
363 else {
364 url.setScheme("http");
365 }
[1476]366 url.setHost(_casterHostComboBox->currentText());
367 url.setPort(_casterPortLineEdit->text().toInt());
[1508]368 url.setUserName(QUrl::toPercentEncoding(_casterUserLineEdit->text()));
369 url.setPassword(QUrl::toPercentEncoding(_casterPasswordLineEdit->text()));
[1477]370 addUrl(url);
[1476]371
[35]372 QStringList* mountPoints = new QStringList;
373 if (_table) {
374 for (int ir = 0; ir < _table->rowCount(); ir++) {
[59]375 QTableWidgetItem* item = _table->item(ir,0);
[2753]376 QString site = _table->item(ir,0)->text();
[59]377 QString format = _table->item(ir,2)->text();
[366]378 QString latitude = _table->item(ir,8)->text();
379 QString longitude = _table->item(ir,9)->text();
380 QString nmea = _table->item(ir,10)->text();
[59]381 format.replace(" ", "_");
[35]382 if (_table->isItemSelected(item)) {
383 url.setPath(item->text());
[2796]384 mountPoints->push_back(url.toString() + " " + format + " " + latitude
[1351]385 + " " + longitude + " " + nmea + " " + ntripVersion);
[4627]386
[2796]387 site.resize(4);
[35]388 }
389 }
390 }
391 emit newMountPoints(mountPoints);
392}
[195]393
394// User changed the selection of mountPoints
395////////////////////////////////////////////////////////////////////////////
396void bncTableDlg::slotSelectionChanged() {
397 if (_table->selectedItems().isEmpty()) {
398 }
399}
400
[399]401// Whats This Help
402void bncTableDlg::slotWhatsThis() {
403QWhatsThis::enterWhatsThisMode();
404}
405
[1459]406// Slot caster table
407////////////////////////////////////////////////////////////////////////////
408void bncTableDlg::slotCasterTable() {
409
410 _buttonCasterTable->setEnabled(false);
[1474]411 _casterHostComboBox->setEnabled(false);
[1461]412 _casterPortLineEdit->setEnabled(false);
413 _casterUserLineEdit->setEnabled(false);
414 _casterPasswordLineEdit->setEnabled(false);
415 _ntripVersionComboBox->setEnabled(false);
416 _buttonWhatsThis->setEnabled(false);
417 _buttonGet->setEnabled(false);
[2796]418 _buttonClose->setEnabled(false);
419 _buttonSelect->setEnabled(false);
[1461]420
[3335]421 bncCasterTableDlg* dlg =
422 new bncCasterTableDlg(_ntripVersionComboBox->currentText(), this);
[1459]423 dlg->move(this->pos().x()+50, this->pos().y()+50);
[1474]424 connect(dlg, SIGNAL(newCaster(QString, QString)),
425 this, SLOT(slotNewCaster(QString, QString)));
[1459]426 dlg->exec();
427 delete dlg;
[1461]428
[1459]429 _buttonCasterTable->setEnabled(true);
[1474]430 _casterHostComboBox->setEnabled(true);
[1461]431 _casterPortLineEdit->setEnabled(true);
432 _casterUserLineEdit->setEnabled(true);
433 _casterPasswordLineEdit->setEnabled(true);
434 _ntripVersionComboBox->setEnabled(true);
435 _buttonWhatsThis->setEnabled(true);
436 _buttonGet->setEnabled(true);
[2796]437 _buttonClose->setEnabled(true);
438 _buttonSelect->setEnabled(true);
[399]439
[1459]440}
441
[1492]442// New caster selected
443////////////////////////////////////////////////////////////////////////////
444void bncTableDlg::slotNewCaster(QString newCasterHost, QString newCasterPort) {
445
446 _casterHostComboBox->insertItem(0, newCasterHost);
447 _casterHostComboBox->setCurrentIndex(0);
448 _casterUserLineEdit->setText("");
[1497]449 _casterPasswordLineEdit->setText("");
[1492]450 _casterPortLineEdit->setText(newCasterPort);
451
[3336]452 QString ntripVersion = _ntripVersionComboBox->currentText();
453
[1492]454 QUrl url;
[3336]455 if (ntripVersion == "2s") {
456 url.setScheme("https");
457 }
458 else {
459 url.setScheme("http");
460 }
[1492]461 url.setHost(newCasterHost);
462 url.setPort(newCasterPort.toInt());
463 addUrl(url);
464
465 _casterHostComboBox->setCurrentIndex(0);
466}
467
468// New caster selected
469////////////////////////////////////////////////////////////////////////////
470void bncTableDlg::addUrl(const QUrl& url) {
[1535]471 bncSettings settings;
[1492]472 QStringList oldUrlList = settings.value("casterUrlList").toStringList();
473 QStringList newUrlList;
474 newUrlList << url.toString();
475 for (int ii = 0; ii < oldUrlList.count(); ii++) {
476 QUrl oldUrl(oldUrlList[ii]);
477 if (url.host() != oldUrl.host()) {
478 newUrlList << oldUrl.toString();
479 }
480 }
481 settings.setValue("casterUrlList", newUrlList);
482}
483
484// New caster selected in combobox
485////////////////////////////////////////////////////////////////////////////
486void bncTableDlg::slotCasterHostChanged(const QString& newHost) {
[1535]487 bncSettings settings;
[1492]488 QStringList casterUrlList = settings.value("casterUrlList").toStringList();
489 for (int ii = 0; ii < casterUrlList.count(); ii++) {
490 QUrl url(casterUrlList[ii]);
491 if (url.host() == newHost) {
[1508]492 _casterUserLineEdit->setText(
493 QUrl::fromPercentEncoding(url.userName().toAscii()));
494 _casterPasswordLineEdit->setText(
495 QUrl::fromPercentEncoding(url.password().toAscii()));
[1492]496 if (url.port() > 0) {
497 _casterPortLineEdit->setText(QString("%1").arg(url.port()));
498 }
499 else {
500 _casterPortLineEdit->setText("");
501 }
502 }
503 }
504}
505
[1459]506// Caster table
507////////////////////////////////////////////////////////////////////////////
[3335]508bncCasterTableDlg::bncCasterTableDlg(const QString& ntripVersion,
509 QWidget* parent) :
[1459]510 QDialog(parent) {
511
[1461]512 static const QStringList labels = QString("host,port,identifier,operator,nmea,country,lat,long,link").split(",");
[1459]513
514 _casterTable = new QTableWidget(this);
515
516 QUrl url;
517 url.setHost("www.rtcm-ntrip.org");
518 url.setPath("/");
[3336]519 if (ntripVersion == "2s") {
520 url.setPort(443);
521 url.setScheme("https");
522 }
523 else {
524 url.setPort(2101);
525 url.setScheme("http");
526 }
[1459]527
[3335]528 bncNetQuery* query = 0;
[3337]529 if (ntripVersion == "2") {
530 query = new bncNetQueryV2(false);
[3335]531 }
[3337]532 else if (ntripVersion == "2s") {
533 query = new bncNetQueryV2(true);
534 }
[3335]535 else {
536 query = new bncNetQueryV1();
537 }
538
[1459]539 QByteArray outData;
[3335]540 query->waitForRequestResult(url, outData);
[1494]541
542 QStringList lines;
[3335]543 if (query->status() == bncNetQuery::finished) {
[1459]544 QTextStream in(outData);
545 QString line = in.readLine();
546 while ( !line.isNull() ) {
547 line = in.readLine();
548 if (line.indexOf("CAS") == 0) {
[1494]549 QStringList hlp = line.split(";");
550 if (hlp.size() > labels.size()) {
551 lines.push_back(line);
552 }
[1459]553 }
554 }
555 }
[1494]556
[3335]557 delete query;
558
[1459]559 if (lines.size() > 0) {
560 _casterTable->setSelectionMode(QAbstractItemView::ExtendedSelection);
561 _casterTable->setSelectionBehavior(QAbstractItemView::SelectRows);
562
563 QStringList hlp = lines[0].split(";");
[1494]564 _casterTable->setColumnCount(labels.size());
565 _casterTable->setRowCount(lines.size());
[1459]566
[1494]567 for (int nRow = 0; nRow < lines.size(); nRow++) {
568 QStringList columns = lines[nRow].split(";");
569 for (int ic = 1; ic < columns.size(); ic++) {
570 if (ic == 5) {
571 if (columns[ic] == "0") {
572 columns[ic] = "no";
573 } else {
574 columns[ic] = "yes";
575 }
576 }
577 QTableWidgetItem* item = new QTableWidgetItem(columns[ic]);
578 item->setFlags(item->flags() & ~Qt::ItemIsEditable);
579 _casterTable->setItem(nRow, ic-1, item);
[1459]580 }
581 }
582 }
583 _casterTable->setHorizontalHeaderLabels(labels);
584 _casterTable->setSortingEnabled(true);
[1494]585 _casterTable->sortItems(0);
[1459]586 int ww = QFontMetrics(this->font()).width('w');
587 _casterTable->horizontalHeader()->resizeSection(0,15*ww);
[1494]588 _casterTable->horizontalHeader()->resizeSection(1, 5*ww);
[1459]589 _casterTable->horizontalHeader()->resizeSection(2,15*ww);
590 _casterTable->horizontalHeader()->resizeSection(3,15*ww);
[1494]591 _casterTable->horizontalHeader()->resizeSection(4, 5*ww);
592 _casterTable->horizontalHeader()->resizeSection(5, 7*ww);
593 _casterTable->horizontalHeader()->resizeSection(6, 7*ww);
594 _casterTable->horizontalHeader()->resizeSection(7, 7*ww);
[1459]595 _casterTable->horizontalHeader()->resizeSection(8,15*ww);
596
[1488]597 _closeButton = new QPushButton("Cancel");
[1459]598 connect(_closeButton, SIGNAL(clicked()), this, SLOT(close()));
599 _closeButton->setMinimumWidth(8*ww);
600 _closeButton->setMaximumWidth(8*ww);
601
[1488]602 _okButton = new QPushButton(tr("OK"), this);
[1459]603 connect(_okButton, SIGNAL(clicked()), this, SLOT(slotAcceptCasterTable()));
604 _okButton->setMinimumWidth(8*ww);
605 _okButton->setMaximumWidth(8*ww);
606
[1488]607 _whatsThisButton = new QPushButton(tr("Help=Shift+F1"), this);
608 connect(_whatsThisButton, SIGNAL(clicked()), this, SLOT(slotWhatsThis()));
609 _whatsThisButton->setMinimumWidth(12*ww);
610 _whatsThisButton->setMaximumWidth(12*ww);
[1459]611
[1471]612 _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>."));
[1459]613
614 QGridLayout* dlgLayout = new QGridLayout();
615 dlgLayout->addWidget(new QLabel(" List of NTRIP Broadcasters from www.rtcm-ntrip.org"), 0,0,1,3,Qt::AlignLeft);
[1488]616 dlgLayout->addWidget(_casterTable, 1, 0, 1, 3);
617 dlgLayout->addWidget(_whatsThisButton, 2, 0);
618 dlgLayout->addWidget(_closeButton, 2, 1, Qt::AlignRight);
619 dlgLayout->addWidget(_okButton, 2, 2);
[1459]620
621 setMinimumSize(600,400);
622 setWindowTitle(tr("Select Broadcaster"));
623 setLayout(dlgLayout);
[1504]624 resize(68*ww, 50*ww);
[1459]625 show();
626}
627
[1488]628// Caster table destructor
[1459]629////////////////////////////////////////////////////////////////////////////
[1488]630bncCasterTableDlg::~bncCasterTableDlg() {
631 delete _casterTable;
632 delete _okButton;
633 delete _closeButton;
634 delete _whatsThisButton;
[1459]635}
636
[1488]637// Caster table what's this
[1459]638////////////////////////////////////////////////////////////////////////////
[1488]639void bncCasterTableDlg:: slotWhatsThis() {
640 QWhatsThis::enterWhatsThisMode();
[1459]641}
642
643// Accept caster table
644////////////////////////////////////////////////////////////////////////////
645void bncCasterTableDlg::slotAcceptCasterTable() {
646 if (_casterTable) {
[1489]647 for (int ir = _casterTable->rowCount() - 1; ir >= 0 ; ir--) {
[1474]648 if (_casterTable->isItemSelected(_casterTable->item(ir,0))) {
649 emit newCaster(_casterTable->item(ir,0)->text(),
650 _casterTable->item(ir,1)->text());
[1459]651 }
652 }
653 }
[1474]654 QDialog::accept();
[1459]655}
Note: See TracBrowser for help on using the repository browser.