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

Last change on this file since 10230 was 9404, checked in by stoecker, 4 years ago

drop the deprecated www prefix

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