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

Last change on this file since 4544 was 4278, checked in by mervart, 13 years ago
File size: 24.4 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
154 QHBoxLayout* buttonLayout = new QHBoxLayout;
[399]155 buttonLayout->addWidget(_buttonWhatsThis);
[35]156 buttonLayout->addStretch(1);
[2753]157 buttonLayout->addWidget(_buttonMap);
[35]158 buttonLayout->addWidget(_buttonGet);
[2796]159 buttonLayout->addWidget(_buttonSelect);
160 buttonLayout->addWidget(_buttonClose);
[35]161
162 mainLayout->addLayout(buttonLayout);
163}
164
165// Destructor
166////////////////////////////////////////////////////////////////////////////
167bncTableDlg::~bncTableDlg() {
[1490]168 delete _casterHostComboBox;
169 delete _casterPortLineEdit;
170 delete _casterUserLineEdit;
171 delete _casterPasswordLineEdit;
[3361]172 bncSettings settings;
173 settings.setValue("ntripVersion", _ntripVersionComboBox->currentText());
[1490]174 delete _ntripVersionComboBox;
175 delete _buttonGet;
[2796]176 delete _buttonClose;
177 delete _buttonSelect;
[1490]178 delete _buttonWhatsThis;
179 delete _buttonCasterTable;
180 delete _table;
[35]181}
182
[1493]183// Read full caster table (static)
[35]184////////////////////////////////////////////////////////////////////////////
[3335]185t_irc bncTableDlg::getFullTable(const QString& ntripVersion,
186 const QString& casterHost,
[1376]187 int casterPort, QStringList& allLines,
188 bool alwaysRead) {
[35]189
[299]190 static QMutex mutex;
[298]191 static QMap<QString, QStringList> allTables;
192
[299]193 QMutexLocker locker(&mutex);
194
[298]195 if (!alwaysRead && allTables.find(casterHost) != allTables.end()) {
196 allLines = allTables.find(casterHost).value();
197 return success;
198 }
199
[191]200 allLines.clear();
201
[3335]202 bncNetQuery* query = 0;
[3337]203 if (ntripVersion == "2") {
204 query = new bncNetQueryV2(false);
[3335]205 }
[3337]206 else if (ntripVersion == "2s") {
207 query = new bncNetQueryV2(true);
208 }
[3335]209 else {
210 query = new bncNetQueryV1();
211 }
212
[88]213 QUrl url;
[191]214 url.setHost(casterHost);
215 url.setPort(casterPort);
[1375]216 url.setPath("/");
[3335]217 if (ntripVersion == "2s") {
218 url.setScheme("https");
219 }
220 else {
221 url.setScheme("http");
222 }
[35]223
[1373]224 QByteArray outData;
[3335]225 query->waitForRequestResult(url, outData);
226 if (query->status() == bncNetQuery::finished) {
[1375]227 QTextStream in(outData);
228 QString line = in.readLine();
229 while ( !line.isNull() ) {
230 allLines.append(line);
231 line = in.readLine();
232 }
233 allTables.insert(casterHost, allLines);
[3335]234 delete query;
[1375]235 return success;
236 }
237 else {
[3335]238 delete query;
[191]239 return failure;
[35]240 }
[191]241}
242
243// Read Table from Caster
244////////////////////////////////////////////////////////////////////////////
245void bncTableDlg::slotGetTable() {
246
[555]247 _buttonGet->setEnabled(false);
[2753]248 _buttonMap->setEnabled(true);
[1459]249 _buttonCasterTable->setEnabled(false);
[555]250
[3335]251 if ( getFullTable(_ntripVersionComboBox->currentText(),
252 _casterHostComboBox->currentText(),
[191]253 _casterPortLineEdit->text().toInt(),
[1493]254 _allLines, true) != success ) {
[191]255 QMessageBox::warning(0, "BNC", "Cannot retrieve table of data");
[645]256 _buttonGet->setEnabled(true);
[191]257 return;
258 }
[2753]259
[1493]260 static const QStringList labels = QString("mountpoint,identifier,format,"
261 "format-details,carrier,system,network,country,lat,long,"
262 "nmea,solution,generator,compress.,auth.,fee,bitrate,"
263 "misc").split(",");
264
[191]265 QStringList lines;
[196]266 QStringListIterator it(_allLines);
[191]267 while (it.hasNext()) {
268 QString line = it.next();
269 if (line.indexOf("STR") == 0) {
[1493]270 QStringList hlp = line.split(";");
271 if (hlp.size() > labels.size()) {
272 lines.push_back(line);
273 }
[191]274 }
275 }
276
277 if (lines.size() > 0) {
[35]278 _table->setSelectionMode(QAbstractItemView::ExtendedSelection);
279 _table->setSelectionBehavior(QAbstractItemView::SelectRows);
[1493]280 _table->setColumnCount(labels.size());
281 _table->setRowCount(lines.size());
282 for (int nRow = 0; nRow < lines.size(); nRow++) {
283 QStringList columns = lines[nRow].split(";");
284 for (int ic = 1; ic < columns.size(); ic++) {
285 if (ic == 11) {
286 if (columns[ic] == "0") {
287 columns[ic] = "no";
288 } else {
289 columns[ic] = "yes";
290 }
291 }
292 QTableWidgetItem* item = new QTableWidgetItem(columns[ic]);
293 item->setFlags(item->flags() & ~Qt::ItemIsEditable);
294 _table->setItem(nRow, ic-1, item);
[35]295 }
296 }
[103]297 _table->setHorizontalHeaderLabels(labels);
[104]298 _table->setSortingEnabled(true);
[371]299 int ww = QFontMetrics(this->font()).width('w');
[1493]300 _table->horizontalHeader()->resizeSection( 0,10*ww);
301 _table->horizontalHeader()->resizeSection( 1,10*ww);
302 _table->horizontalHeader()->resizeSection( 2, 8*ww);
303 _table->horizontalHeader()->resizeSection( 3,22*ww);
304 _table->horizontalHeader()->resizeSection( 4, 5*ww);
305 _table->horizontalHeader()->resizeSection( 5, 8*ww);
306 _table->horizontalHeader()->resizeSection( 6, 8*ww);
307 _table->horizontalHeader()->resizeSection( 7, 7*ww);
308 _table->horizontalHeader()->resizeSection( 8, 6*ww);
309 _table->horizontalHeader()->resizeSection( 9, 6*ww);
310 _table->horizontalHeader()->resizeSection(10, 6*ww);
311 _table->horizontalHeader()->resizeSection(11, 6*ww);
[371]312 _table->horizontalHeader()->resizeSection(12,15*ww);
[1493]313 _table->horizontalHeader()->resizeSection(13, 8*ww);
314 _table->horizontalHeader()->resizeSection(14, 5*ww);
315 _table->horizontalHeader()->resizeSection(15, 5*ww);
316 _table->horizontalHeader()->resizeSection(16, 7*ww);
[371]317 _table->horizontalHeader()->resizeSection(17,15*ww);
[1493]318 _table->sortItems(0);
[35]319 }
320}
321
[2753]322// Show world map
323////////////////////////////////////////////////////////////////////////////
324void bncTableDlg::slotShowMap() {
325
326 bncMap* winMap = new bncMap(this);
[2796]327 winMap->setGeometry( x(), int(y()+height()*1.3), 880, 440 );
[2753]328
[3292]329 connect(this, SIGNAL(newPoint(QPointF, QString, QPen, double)),
330 winMap, SLOT(slotNewPoint(QPointF, QString, QPen, double)));
[2753]331
[2796]332 connect(this, SIGNAL(fitMap()),
333 winMap, SLOT(slotFitMap() ));
[3292]334
335 connect(this, SIGNAL(fitFont()),
336 winMap, SLOT(slotFitFont() ));
[2796]337
[2753]338 _buttonMap->setEnabled(false);
339 showSourceTable();
340 winMap->exec();
341 _buttonMap->setEnabled(true);
342
[3292]343 disconnect(this, SIGNAL(newPoint(QPointF, QString, QPen, double)),
344 winMap, SLOT(slotNewPoint(QPointF, QString, QPen, double)));
[2753]345
[2796]346 disconnect(this, SIGNAL(fitMap()),
347 winMap, SLOT(slotFitMap() ));
348
[3292]349 disconnect(this, SIGNAL(fitFont()),
350 winMap, SLOT(slotFitFont() ));
351
[2753]352 delete winMap;
353}
354
355// Show world map
356////////////////////////////////////////////////////////////////////////////
357void bncTableDlg::showSourceTable() {
358
359 for( int i = 0; i < _allLines.size(); i++ ){
360
361 if( _allLines.at(i).startsWith("STR") == true ){
362
363 QStringList tmp = _allLines.at(i).split(';');
364 if( tmp.size() > 0 ){
365
366 QPointF point;
367 point.setY( tmp.at(9).toDouble() );
368 point.setX( tmp.at(10).toDouble() );
[2796]369
[2753]370 QString site = tmp.at(1);
371 site.resize(4);
372
[3292]373 emit newPoint(point, site, QPen(QBrush(QColor(0,0,255,200)), 1.5), 1.5 );
[2796]374 }
[2753]375 }
376 }
[2796]377 emit fitMap();
[2753]378}
379
380
[2796]381// Select slot
[35]382////////////////////////////////////////////////////////////////////////////
[2796]383void bncTableDlg::select() {
[35]384
[3335]385 QString ntripVersion = _ntripVersionComboBox->currentText();
[3336]386
[1476]387 QUrl url;
[3335]388 if (ntripVersion == "2s") {
389 url.setScheme("https");
390 }
391 else {
392 url.setScheme("http");
393 }
[1476]394 url.setHost(_casterHostComboBox->currentText());
395 url.setPort(_casterPortLineEdit->text().toInt());
[1508]396 url.setUserName(QUrl::toPercentEncoding(_casterUserLineEdit->text()));
397 url.setPassword(QUrl::toPercentEncoding(_casterPasswordLineEdit->text()));
[1477]398 addUrl(url);
[1476]399
[35]400 QStringList* mountPoints = new QStringList;
401 if (_table) {
402 for (int ir = 0; ir < _table->rowCount(); ir++) {
[59]403 QTableWidgetItem* item = _table->item(ir,0);
[2753]404 QString site = _table->item(ir,0)->text();
[59]405 QString format = _table->item(ir,2)->text();
[366]406 QString latitude = _table->item(ir,8)->text();
407 QString longitude = _table->item(ir,9)->text();
408 QString nmea = _table->item(ir,10)->text();
[59]409 format.replace(" ", "_");
[35]410 if (_table->isItemSelected(item)) {
411 url.setPath(item->text());
[2796]412 mountPoints->push_back(url.toString() + " " + format + " " + latitude
[1351]413 + " " + longitude + " " + nmea + " " + ntripVersion);
[2753]414
[2796]415 site.resize(4);
[2753]416 emit newPoint(QPointF(longitude.toDouble(),latitude.toDouble()), site,
[3292]417 QPen(QBrush(QColor(255,0,0,200)), 3.0), 3.0 );
[35]418 }
419 }
420 }
421 emit newMountPoints(mountPoints);
[3292]422 emit fitFont();
[35]423}
[195]424
425// User changed the selection of mountPoints
426////////////////////////////////////////////////////////////////////////////
427void bncTableDlg::slotSelectionChanged() {
428 if (_table->selectedItems().isEmpty()) {
429 }
430}
431
[399]432// Whats This Help
433void bncTableDlg::slotWhatsThis() {
434QWhatsThis::enterWhatsThisMode();
435}
436
[1459]437// Slot caster table
438////////////////////////////////////////////////////////////////////////////
439void bncTableDlg::slotCasterTable() {
440
441 _buttonCasterTable->setEnabled(false);
[1474]442 _casterHostComboBox->setEnabled(false);
[1461]443 _casterPortLineEdit->setEnabled(false);
444 _casterUserLineEdit->setEnabled(false);
445 _casterPasswordLineEdit->setEnabled(false);
446 _ntripVersionComboBox->setEnabled(false);
447 _buttonWhatsThis->setEnabled(false);
448 _buttonGet->setEnabled(false);
[2796]449 _buttonClose->setEnabled(false);
450 _buttonSelect->setEnabled(false);
[1461]451
[3335]452 bncCasterTableDlg* dlg =
453 new bncCasterTableDlg(_ntripVersionComboBox->currentText(), this);
[1459]454 dlg->move(this->pos().x()+50, this->pos().y()+50);
[1474]455 connect(dlg, SIGNAL(newCaster(QString, QString)),
456 this, SLOT(slotNewCaster(QString, QString)));
[1459]457 dlg->exec();
458 delete dlg;
[1461]459
[1459]460 _buttonCasterTable->setEnabled(true);
[1474]461 _casterHostComboBox->setEnabled(true);
[1461]462 _casterPortLineEdit->setEnabled(true);
463 _casterUserLineEdit->setEnabled(true);
464 _casterPasswordLineEdit->setEnabled(true);
465 _ntripVersionComboBox->setEnabled(true);
466 _buttonWhatsThis->setEnabled(true);
467 _buttonGet->setEnabled(true);
[2796]468 _buttonClose->setEnabled(true);
469 _buttonSelect->setEnabled(true);
[399]470
[1459]471}
472
[1492]473// New caster selected
474////////////////////////////////////////////////////////////////////////////
475void bncTableDlg::slotNewCaster(QString newCasterHost, QString newCasterPort) {
476
477 _casterHostComboBox->insertItem(0, newCasterHost);
478 _casterHostComboBox->setCurrentIndex(0);
479 _casterUserLineEdit->setText("");
[1497]480 _casterPasswordLineEdit->setText("");
[1492]481 _casterPortLineEdit->setText(newCasterPort);
482
[3336]483 QString ntripVersion = _ntripVersionComboBox->currentText();
484
[1492]485 QUrl url;
[3336]486 if (ntripVersion == "2s") {
487 url.setScheme("https");
488 }
489 else {
490 url.setScheme("http");
491 }
[1492]492 url.setHost(newCasterHost);
493 url.setPort(newCasterPort.toInt());
494 addUrl(url);
495
496 _casterHostComboBox->setCurrentIndex(0);
497}
498
499// New caster selected
500////////////////////////////////////////////////////////////////////////////
501void bncTableDlg::addUrl(const QUrl& url) {
[1535]502 bncSettings settings;
[1492]503 QStringList oldUrlList = settings.value("casterUrlList").toStringList();
504 QStringList newUrlList;
505 newUrlList << url.toString();
506 for (int ii = 0; ii < oldUrlList.count(); ii++) {
507 QUrl oldUrl(oldUrlList[ii]);
508 if (url.host() != oldUrl.host()) {
509 newUrlList << oldUrl.toString();
510 }
511 }
512 settings.setValue("casterUrlList", newUrlList);
513}
514
515// New caster selected in combobox
516////////////////////////////////////////////////////////////////////////////
517void bncTableDlg::slotCasterHostChanged(const QString& newHost) {
[1535]518 bncSettings settings;
[1492]519 QStringList casterUrlList = settings.value("casterUrlList").toStringList();
520 for (int ii = 0; ii < casterUrlList.count(); ii++) {
521 QUrl url(casterUrlList[ii]);
522 if (url.host() == newHost) {
[1508]523 _casterUserLineEdit->setText(
524 QUrl::fromPercentEncoding(url.userName().toAscii()));
525 _casterPasswordLineEdit->setText(
526 QUrl::fromPercentEncoding(url.password().toAscii()));
[1492]527 if (url.port() > 0) {
528 _casterPortLineEdit->setText(QString("%1").arg(url.port()));
529 }
530 else {
531 _casterPortLineEdit->setText("");
532 }
533 }
534 }
535}
536
[1459]537// Caster table
538////////////////////////////////////////////////////////////////////////////
[3335]539bncCasterTableDlg::bncCasterTableDlg(const QString& ntripVersion,
540 QWidget* parent) :
[1459]541 QDialog(parent) {
542
[1461]543 static const QStringList labels = QString("host,port,identifier,operator,nmea,country,lat,long,link").split(",");
[1459]544
545 _casterTable = new QTableWidget(this);
546
547 QUrl url;
548 url.setHost("www.rtcm-ntrip.org");
549 url.setPath("/");
[3336]550 if (ntripVersion == "2s") {
551 url.setPort(443);
552 url.setScheme("https");
553 }
554 else {
555 url.setPort(2101);
556 url.setScheme("http");
557 }
[1459]558
[3335]559 bncNetQuery* query = 0;
[3337]560 if (ntripVersion == "2") {
561 query = new bncNetQueryV2(false);
[3335]562 }
[3337]563 else if (ntripVersion == "2s") {
564 query = new bncNetQueryV2(true);
565 }
[3335]566 else {
567 query = new bncNetQueryV1();
568 }
569
[1459]570 QByteArray outData;
[3335]571 query->waitForRequestResult(url, outData);
[1494]572
573 QStringList lines;
[3335]574 if (query->status() == bncNetQuery::finished) {
[1459]575 QTextStream in(outData);
576 QString line = in.readLine();
577 while ( !line.isNull() ) {
578 line = in.readLine();
579 if (line.indexOf("CAS") == 0) {
[1494]580 QStringList hlp = line.split(";");
581 if (hlp.size() > labels.size()) {
582 lines.push_back(line);
583 }
[1459]584 }
585 }
586 }
[1494]587
[3335]588 delete query;
589
[1459]590 if (lines.size() > 0) {
591 _casterTable->setSelectionMode(QAbstractItemView::ExtendedSelection);
592 _casterTable->setSelectionBehavior(QAbstractItemView::SelectRows);
593
594 QStringList hlp = lines[0].split(";");
[1494]595 _casterTable->setColumnCount(labels.size());
596 _casterTable->setRowCount(lines.size());
[1459]597
[1494]598 for (int nRow = 0; nRow < lines.size(); nRow++) {
599 QStringList columns = lines[nRow].split(";");
600 for (int ic = 1; ic < columns.size(); ic++) {
601 if (ic == 5) {
602 if (columns[ic] == "0") {
603 columns[ic] = "no";
604 } else {
605 columns[ic] = "yes";
606 }
607 }
608 QTableWidgetItem* item = new QTableWidgetItem(columns[ic]);
609 item->setFlags(item->flags() & ~Qt::ItemIsEditable);
610 _casterTable->setItem(nRow, ic-1, item);
[1459]611 }
612 }
613 }
614 _casterTable->setHorizontalHeaderLabels(labels);
615 _casterTable->setSortingEnabled(true);
[1494]616 _casterTable->sortItems(0);
[1459]617 int ww = QFontMetrics(this->font()).width('w');
618 _casterTable->horizontalHeader()->resizeSection(0,15*ww);
[1494]619 _casterTable->horizontalHeader()->resizeSection(1, 5*ww);
[1459]620 _casterTable->horizontalHeader()->resizeSection(2,15*ww);
621 _casterTable->horizontalHeader()->resizeSection(3,15*ww);
[1494]622 _casterTable->horizontalHeader()->resizeSection(4, 5*ww);
623 _casterTable->horizontalHeader()->resizeSection(5, 7*ww);
624 _casterTable->horizontalHeader()->resizeSection(6, 7*ww);
625 _casterTable->horizontalHeader()->resizeSection(7, 7*ww);
[1459]626 _casterTable->horizontalHeader()->resizeSection(8,15*ww);
627
[1488]628 _closeButton = new QPushButton("Cancel");
[1459]629 connect(_closeButton, SIGNAL(clicked()), this, SLOT(close()));
630 _closeButton->setMinimumWidth(8*ww);
631 _closeButton->setMaximumWidth(8*ww);
632
[1488]633 _okButton = new QPushButton(tr("OK"), this);
[1459]634 connect(_okButton, SIGNAL(clicked()), this, SLOT(slotAcceptCasterTable()));
635 _okButton->setMinimumWidth(8*ww);
636 _okButton->setMaximumWidth(8*ww);
637
[1488]638 _whatsThisButton = new QPushButton(tr("Help=Shift+F1"), this);
639 connect(_whatsThisButton, SIGNAL(clicked()), this, SLOT(slotWhatsThis()));
640 _whatsThisButton->setMinimumWidth(12*ww);
641 _whatsThisButton->setMaximumWidth(12*ww);
[1459]642
[1471]643 _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]644
645 QGridLayout* dlgLayout = new QGridLayout();
646 dlgLayout->addWidget(new QLabel(" List of NTRIP Broadcasters from www.rtcm-ntrip.org"), 0,0,1,3,Qt::AlignLeft);
[1488]647 dlgLayout->addWidget(_casterTable, 1, 0, 1, 3);
648 dlgLayout->addWidget(_whatsThisButton, 2, 0);
649 dlgLayout->addWidget(_closeButton, 2, 1, Qt::AlignRight);
650 dlgLayout->addWidget(_okButton, 2, 2);
[1459]651
652 setMinimumSize(600,400);
653 setWindowTitle(tr("Select Broadcaster"));
654 setLayout(dlgLayout);
[1504]655 resize(68*ww, 50*ww);
[1459]656 show();
657}
658
[1488]659// Caster table destructor
[1459]660////////////////////////////////////////////////////////////////////////////
[1488]661bncCasterTableDlg::~bncCasterTableDlg() {
662 delete _casterTable;
663 delete _okButton;
664 delete _closeButton;
665 delete _whatsThisButton;
[1459]666}
667
[1488]668// Caster table what's this
[1459]669////////////////////////////////////////////////////////////////////////////
[1488]670void bncCasterTableDlg:: slotWhatsThis() {
671 QWhatsThis::enterWhatsThisMode();
[1459]672}
673
674// Accept caster table
675////////////////////////////////////////////////////////////////////////////
676void bncCasterTableDlg::slotAcceptCasterTable() {
677 if (_casterTable) {
[1489]678 for (int ir = _casterTable->rowCount() - 1; ir >= 0 ; ir--) {
[1474]679 if (_casterTable->isItemSelected(_casterTable->item(ir,0))) {
680 emit newCaster(_casterTable->item(ir,0)->text(),
681 _casterTable->item(ir,1)->text());
[1459]682 }
683 }
684 }
[1474]685 QDialog::accept();
[1459]686}
Note: See TracBrowser for help on using the repository browser.