source: ntrip/branches/BNC_2.12/src/bnctabledlg.cpp@ 10421

Last change on this file since 10421 was 8501, checked in by stuerze, 6 years ago

minor changes to allow requests of user and password detected sourcetables

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