source: ntrip/trunk/BNC/bnctabledlg.cpp@ 1478

Last change on this file since 1478 was 1478, checked in by mervart, 15 years ago

* empty log message *

File size: 22.2 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 "bncnetqueryv2.h"
46
47using namespace std;
48
49// Constructor
50////////////////////////////////////////////////////////////////////////////
51bncTableDlg::bncTableDlg(QWidget* parent) : QDialog(parent) {
52
53 setMinimumSize(600,400);
54 setWindowTitle(tr("Add Streams"));
55
56 QVBoxLayout* mainLayout = new QVBoxLayout(this);
57
58 int ww = QFontMetrics(font()).width('w');
59
60 _casterPortLineEdit = new QLineEdit();
61 _casterPortLineEdit->setMaximumWidth(9*ww);
62
63 _casterUserLineEdit = new QLineEdit();
64 _casterUserLineEdit->setMaximumWidth(9*ww);
65
66 _casterPasswordLineEdit = new QLineEdit();
67 _casterPasswordLineEdit->setMaximumWidth(9*ww);
68 _casterPasswordLineEdit->setEchoMode(QLineEdit::Password);
69
70 _casterHostComboBox = new QComboBox();
71 _casterHostComboBox->setDuplicatesEnabled(false);
72 _casterHostComboBox->setEditable(true);
73 _casterHostComboBox->setMinimumWidth(20*ww);
74 _casterHostComboBox->setMaximumWidth(20*ww);
75 connect(_casterHostComboBox, SIGNAL(currentIndexChanged(const QString&)),
76 this, SLOT(slotCasterHostChanged(const QString&)));
77 QSettings settings;
78 QStringList casterUrlList = settings.value("casterUrlList").toStringList();
79 for (int ii = 0; ii < casterUrlList.count(); ii++) {
80 QUrl url(casterUrlList[ii]);
81 _casterHostComboBox->addItem(url.host());
82 }
83
84 _ntripVersionComboBox = new QComboBox();
85 _ntripVersionComboBox->addItems(QString("1,2,R").split(","));
86 int kk = _ntripVersionComboBox->findText(settings.value("ntripVersion").toString());
87 if (kk != -1) {
88 _ntripVersionComboBox->setCurrentIndex(kk);
89 }
90 _ntripVersionComboBox->setMaximumWidth(5*ww);
91
92 _buttonCasterTable = new QPushButton(tr("Show"), this);
93 connect(_buttonCasterTable, SIGNAL(clicked()), this, SLOT(slotCasterTable()));
94 _buttonCasterTable->setMaximumWidth(5*ww);
95
96 // WhatsThis
97 // ---------
98 _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>"));
99 _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>"));
100 _casterPortLineEdit->setWhatsThis(tr("Enter the NTRIP broadcaster port number."));
101 _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."));
102
103 QGridLayout* editLayout = new QGridLayout;
104 editLayout->addWidget(new QLabel(tr("Caster host")), 0, 0);
105 editLayout->addWidget(_casterHostComboBox, 0, 1);
106 editLayout->addWidget(new QLabel(tr(" Caster port")), 0, 2, Qt::AlignRight);
107 editLayout->addWidget(_casterPortLineEdit, 0, 3);
108 editLayout->addWidget(new QLabel(tr("Caster table")), 0, 4, Qt::AlignRight);
109 editLayout->addWidget(_buttonCasterTable, 0, 5);
110 editLayout->addWidget(new QLabel(tr("User")), 1, 0, Qt::AlignRight);
111 editLayout->addWidget(_casterUserLineEdit, 1, 1);
112 editLayout->addWidget(new QLabel(tr("Password")), 1, 2, Qt::AlignRight);
113 editLayout->addWidget(_casterPasswordLineEdit, 1, 3);
114 editLayout->addWidget(new QLabel(tr(" NTRIP Version")),1, 4, Qt::AlignRight);
115 editLayout->addWidget(_ntripVersionComboBox, 1, 5);
116
117 mainLayout->addLayout(editLayout);
118
119 _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>"));
120 _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; R:&nbsp; NTRIP Version 2, RTSP/RTP mode<br>Select option '1' if you are not sure whether the NTRIP broadcaster supports NTRIP version 2.</p><p>Note that RTSP/RTP (option 'R') is sometimes not supported by mobile Internet Service Providers.</p>"));
121
122 _table = new QTableWidget(this);
123 _table->setWhatsThis(tr("<p>Use the 'Get Table' button to download the sourcetable from the selected NTRIP broadcaster. Select the desired streams line by line, using +Shift and +Ctrl when necessary. Hit 'OK' to return to the main window.</p><p>Pay attention to data field 'format'. Keep in mind that BNC can only decode and convert streams that come in RTCM Version 2.x, RTCM Version 3.x, or RTIGS format. See data field 'format-details' for available message types and their repetition rates in brackets.</p><p>The content of data field 'nmea' tells you whether a stream comes from a virtual reference station (VRS).</p>"));
124 connect(_table, SIGNAL(itemSelectionChanged()),
125 this, SLOT(slotSelectionChanged()));
126 mainLayout->addWidget(_table);
127
128 _buttonWhatsThis = new QPushButton(tr("Help=Shift+F1"), this);
129 connect(_buttonWhatsThis, SIGNAL(clicked()), this, SLOT(slotWhatsThis()));
130
131 _buttonGet = new QPushButton(tr("Get table"), this);
132 _buttonGet->setDefault(true);
133 connect(_buttonGet, SIGNAL(clicked()), this, SLOT(slotGetTable()));
134
135 _buttonCancel = new QPushButton(tr("Cancel"), this);
136 connect(_buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
137
138 _buttonOK = new QPushButton(tr("OK"), this);
139 connect(_buttonOK, SIGNAL(clicked()), this, SLOT(accept()));
140
141 QHBoxLayout* buttonLayout = new QHBoxLayout;
142 buttonLayout->addWidget(_buttonWhatsThis);
143 buttonLayout->addStretch(1);
144 buttonLayout->addWidget(_buttonGet);
145 buttonLayout->addWidget(_buttonCancel);
146 buttonLayout->addWidget(_buttonOK);
147
148 mainLayout->addLayout(buttonLayout);
149}
150
151// Destructor
152////////////////////////////////////////////////////////////////////////////
153bncTableDlg::~bncTableDlg() {
154 if (_table) {
155 for (int ir = 0; ir < _table->rowCount(); ir++) {
156 for (int ic = 0; ic < _table->columnCount(); ic++) {
157 delete _table->item(ir,ic);
158 }
159 }
160 }
161}
162
163// Read Table the caster (static)
164////////////////////////////////////////////////////////////////////////////
165t_irc bncTableDlg::getFullTable(const QString& casterHost,
166 int casterPort, QStringList& allLines,
167 bool alwaysRead) {
168
169 static QMutex mutex;
170 static QMap<QString, QStringList> allTables;
171
172 QMutexLocker locker(&mutex);
173
174 if (!alwaysRead && allTables.find(casterHost) != allTables.end()) {
175 allLines = allTables.find(casterHost).value();
176 return success;
177 }
178
179 allLines.clear();
180
181 QUrl url;
182 url.setHost(casterHost);
183 url.setPort(casterPort);
184 url.setScheme("http");
185 url.setPath("/");
186
187 bncNetQueryV2 query;
188 QByteArray outData;
189 query.waitForRequestResult(url, outData);
190 if (query.status() == bncNetQuery::finished) {
191 QTextStream in(outData);
192 QString line = in.readLine();
193 while ( !line.isNull() ) {
194 allLines.append(line);
195 line = in.readLine();
196 }
197 allTables.insert(casterHost, allLines);
198 return success;
199 }
200 else {
201 return failure;
202 }
203}
204
205// Read Table from Caster
206////////////////////////////////////////////////////////////////////////////
207void bncTableDlg::slotGetTable() {
208
209 _buttonGet->setEnabled(false);
210 _buttonCasterTable->setEnabled(false);
211
212 _allLines.clear();
213
214 if ( getFullTable(_casterHostComboBox->currentText(),
215 _casterPortLineEdit->text().toInt(),
216 _allLines) != success ) {
217 QMessageBox::warning(0, "BNC", "Cannot retrieve table of data");
218 _buttonGet->setEnabled(true);
219 return;
220 }
221
222 QStringList lines;
223 QStringListIterator it(_allLines);
224 int endSourceTable = 1;
225 while (it.hasNext()) {
226 QString line = it.next();
227 if ((endSourceTable == 1 ) && line.indexOf("ENDSOURCETABLE") == 0) {
228 endSourceTable = 0;
229 }
230 if (line.indexOf("STR") == 0) {
231 lines.push_back(line);
232 }
233 }
234 if (endSourceTable == 1) { printf("ENDSOURCETABLE missing\n");}
235
236 static const QStringList labels = QString("mountpoint,identifier,format,"
237 "format-details,carrier,system,network,country,lat,long,"
238 "nmea,solution,generator,compress.,auth.,fee,bitrate,"
239 "misc").split(",");
240
241 if (lines.size() > 0) {
242 _table->setSelectionMode(QAbstractItemView::ExtendedSelection);
243 _table->setSelectionBehavior(QAbstractItemView::SelectRows);
244
245 QStringList hlp = lines[0].split(";");
246 _table->setColumnCount(hlp.size()-1);
247 _table->setRowCount(lines.size() - endSourceTable);
248
249 QListIterator<QString> it(lines);
250 int nRow = -1;
251 while (it.hasNext()) {
252 QStringList columns = it.next().split(";");
253 ++nRow;
254 for (int ic = 0; ic < columns.size()-1; ic++) {
255
256 if (ic+1 == 11) { if (columns[ic+1] == "0") { columns[ic+1] = "no"; } else { columns[ic+1] = "yes"; }}
257
258 QTableWidgetItem* it = new QTableWidgetItem(columns[ic+1]);
259 it->setFlags(it->flags() & ~Qt::ItemIsEditable);
260 _table->setItem(nRow, ic, it);
261 }
262 }
263 _table->sortItems(0);
264 _table->setHorizontalHeaderLabels(labels);
265 _table->setSortingEnabled(true);
266
267 int ww = QFontMetrics(this->font()).width('w');
268 _table->horizontalHeader()->resizeSection(0,10*ww);
269 _table->horizontalHeader()->resizeSection(1,10*ww);
270 _table->horizontalHeader()->resizeSection(2,8*ww);
271 _table->horizontalHeader()->resizeSection(3,22*ww);
272 _table->horizontalHeader()->resizeSection(4,5*ww);
273 _table->horizontalHeader()->resizeSection(5,8*ww);
274 _table->horizontalHeader()->resizeSection(6,8*ww);
275 _table->horizontalHeader()->resizeSection(7,7*ww);
276 _table->horizontalHeader()->resizeSection(8,6*ww);
277 _table->horizontalHeader()->resizeSection(9,6*ww);
278 _table->horizontalHeader()->resizeSection(10,6*ww);
279 _table->horizontalHeader()->resizeSection(11,6*ww);
280 _table->horizontalHeader()->resizeSection(12,15*ww);
281 _table->horizontalHeader()->resizeSection(13,8*ww);
282 _table->horizontalHeader()->resizeSection(14,5*ww);
283 _table->horizontalHeader()->resizeSection(15,5*ww);
284 _table->horizontalHeader()->resizeSection(16,7*ww);
285 _table->horizontalHeader()->resizeSection(17,15*ww);
286 }
287}
288
289// Accept slot
290////////////////////////////////////////////////////////////////////////////
291void bncTableDlg::accept() {
292
293 QSettings settings;
294 settings.setValue("casterHost", _casterHostComboBox->currentText());
295 settings.setValue("ntripVersion", _ntripVersionComboBox->currentText());
296 settings.sync();
297
298 QUrl url;
299 url.setScheme("http");
300 url.setHost(_casterHostComboBox->currentText());
301 url.setPort(_casterPortLineEdit->text().toInt());
302 url.setUserName(_casterUserLineEdit->text());
303 url.setPassword(_casterPasswordLineEdit->text());
304 addUrl(url);
305
306 QStringList* mountPoints = new QStringList;
307
308 if (_table) {
309 for (int ir = 0; ir < _table->rowCount(); ir++) {
310 QTableWidgetItem* item = _table->item(ir,0);
311 QString format = _table->item(ir,2)->text();
312 QString latitude = _table->item(ir,8)->text();
313 QString longitude = _table->item(ir,9)->text();
314 QString nmea = _table->item(ir,10)->text();
315 QString ntripVersion = _ntripVersionComboBox->currentText();
316 format.replace(" ", "_");
317 if (_table->isItemSelected(item)) {
318 url.setPath(item->text());
319 mountPoints->push_back(url.toString() + " " + format + " " + latitude
320 + " " + longitude + " " + nmea + " " + ntripVersion);
321 }
322 }
323 }
324 emit newMountPoints(mountPoints);
325
326 QDialog::accept();
327}
328
329// User changed the selection of mountPoints
330////////////////////////////////////////////////////////////////////////////
331void bncTableDlg::slotSelectionChanged() {
332 if (_table->selectedItems().isEmpty()) {
333 }
334}
335
336// Create RINEX skeleton header
337////////////////////////////////////////////////////////////////////////////
338void bncTableDlg::slotSkl() {
339
340 int nRows = _table->rowCount();
341 for (int iRow = 0; iRow < nRows; iRow++) {
342 if (_table->isItemSelected(_table->item(iRow,1))) {
343 QString staID = _table->item(iRow,0)->text();
344 QString net = _table->item(iRow,6)->text();
345
346 QString ftpDir;
347 QStringListIterator it(_allLines);
348 while (it.hasNext()) {
349 QString line = it.next();
350 if (line.indexOf("NET") == 0) {
351 QStringList tags = line.split(';');
352 if (tags.at(1) == net) {
353 ftpDir = tags.at(6);
354 break;
355 }
356 }
357 }
358
359 if (!ftpDir.isEmpty()) {
360 QUrl url(ftpDir);
361 QMessageBox::warning(0, "Warning", url.host() + "\n" + url.path() +
362 "\nnot yet implemented");
363 }
364 }
365 }
366}
367
368// Whats This Help
369void bncTableDlg::slotWhatsThis() {
370QWhatsThis::enterWhatsThisMode();
371}
372
373// Slot caster table
374////////////////////////////////////////////////////////////////////////////
375void bncTableDlg::slotCasterTable() {
376
377 _buttonCasterTable->setEnabled(false);
378 _casterHostComboBox->setEnabled(false);
379 _casterPortLineEdit->setEnabled(false);
380 _casterUserLineEdit->setEnabled(false);
381 _casterPasswordLineEdit->setEnabled(false);
382 _ntripVersionComboBox->setEnabled(false);
383 _buttonWhatsThis->setEnabled(false);
384 _buttonGet->setEnabled(false);
385 _buttonCancel->setEnabled(false);
386 _buttonOK->setEnabled(false);
387
388 bncCasterTableDlg* dlg = new bncCasterTableDlg(this);
389 dlg->move(this->pos().x()+50, this->pos().y()+50);
390 connect(dlg, SIGNAL(newCaster(QString, QString)),
391 this, SLOT(slotNewCaster(QString, QString)));
392 dlg->exec();
393 delete dlg;
394
395 _buttonCasterTable->setEnabled(true);
396 _casterHostComboBox->setEnabled(true);
397 _casterPortLineEdit->setEnabled(true);
398 _casterUserLineEdit->setEnabled(true);
399 _casterPasswordLineEdit->setEnabled(true);
400 _ntripVersionComboBox->setEnabled(true);
401 _buttonWhatsThis->setEnabled(true);
402 _buttonGet->setEnabled(true);
403 _buttonCancel->setEnabled(true);
404 _buttonOK->setEnabled(true);
405
406}
407
408// Caster table
409////////////////////////////////////////////////////////////////////////////
410bncCasterTableDlg::bncCasterTableDlg(QWidget* parent) :
411 QDialog(parent) {
412
413 static const QStringList labels = QString("host,port,identifier,operator,nmea,country,lat,long,link").split(",");
414
415 QStringList lines;
416 lines.clear();
417 _casterTable = new QTableWidget(this);
418
419 QUrl url;
420 url.setHost("www.rtcm-ntrip.org");
421 url.setPort(2101);
422 url.setScheme("http");
423 url.setPath("/");
424
425 bncNetQueryV2 query;
426 QByteArray outData;
427 query.waitForRequestResult(url, outData);
428 int endSourceTable = 1;
429 if (query.status() == bncNetQuery::finished) {
430 QTextStream in(outData);
431 QString line = in.readLine();
432 while ( !line.isNull() ) {
433 line = in.readLine();
434 if ((endSourceTable == 1 ) && line.indexOf("ENDSOURCETABLE") == 0) {
435 endSourceTable = 0;
436 }
437 if (line.indexOf("CAS") == 0) {
438 lines.append(line);
439 }
440 }
441 }
442 if (endSourceTable == 1) { printf("ENDSOURCETABLE missing\n");}
443 if (lines.size() > 0) {
444 _casterTable->setSelectionMode(QAbstractItemView::ExtendedSelection);
445 _casterTable->setSelectionBehavior(QAbstractItemView::SelectRows);
446
447 QStringList hlp = lines[0].split(";");
448 _casterTable->setColumnCount(hlp.size()-1);
449 _casterTable->setRowCount(lines.size() - endSourceTable);
450
451 QListIterator<QString> it(lines);
452 int nRow = -1;
453 while (it.hasNext()) {
454 QStringList columns = it.next().split(";");
455 ++nRow;
456 for (int ic = 0; ic < columns.size()-1; ic++) {
457 if (ic+1 == 5) { if (columns[ic+1] == "0") { columns[ic+1] = "no"; } else { columns[ic+1] = "yes"; }}
458 QTableWidgetItem* it = new QTableWidgetItem(columns[ic+1]);
459 it->setFlags(it->flags() & ~Qt::ItemIsEditable);
460 _casterTable->setItem(nRow, ic, it);
461 }
462 }
463 }
464 _casterTable->sortItems(0);
465 _casterTable->setHorizontalHeaderLabels(labels);
466 _casterTable->setSortingEnabled(true);
467
468 int ww = QFontMetrics(this->font()).width('w');
469 _casterTable->horizontalHeader()->resizeSection(0,15*ww);
470 _casterTable->horizontalHeader()->resizeSection(1,5*ww);
471 _casterTable->horizontalHeader()->resizeSection(2,15*ww);
472 _casterTable->horizontalHeader()->resizeSection(3,15*ww);
473 _casterTable->horizontalHeader()->resizeSection(4,5*ww);
474 _casterTable->horizontalHeader()->resizeSection(5,7*ww);
475 _casterTable->horizontalHeader()->resizeSection(6,7*ww);
476 _casterTable->horizontalHeader()->resizeSection(7,7*ww);
477 _casterTable->horizontalHeader()->resizeSection(8,15*ww);
478
479 ww = QFontMetrics(font()).width('w');
480
481 QPushButton* _closeButton = new QPushButton("Cancel");
482 connect(_closeButton, SIGNAL(clicked()), this, SLOT(close()));
483 _closeButton->setMinimumWidth(8*ww);
484 _closeButton->setMaximumWidth(8*ww);
485
486 QPushButton* _okButton = new QPushButton(tr("OK"), this);
487 connect(_okButton, SIGNAL(clicked()), this, SLOT(slotAcceptCasterTable()));
488 _okButton->setMinimumWidth(8*ww);
489 _okButton->setMaximumWidth(8*ww);
490
491 QPushButton* _whatsThisCasterTableButton = new QPushButton(tr("Help=Shift+F1"), this);
492 connect(_whatsThisCasterTableButton, SIGNAL(clicked()), this, SLOT(slotWhatsThisCasterTable()));
493 _whatsThisCasterTableButton->setMinimumWidth(12*ww);
494 _whatsThisCasterTableButton->setMaximumWidth(12*ww);
495
496 _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>."));
497
498 QGridLayout* dlgLayout = new QGridLayout();
499 dlgLayout->addWidget(new QLabel(" List of NTRIP Broadcasters from www.rtcm-ntrip.org"), 0,0,1,3,Qt::AlignLeft);
500 dlgLayout->addWidget(_casterTable, 1, 0, 1, 3);
501 dlgLayout->addWidget(_whatsThisCasterTableButton, 2, 0);
502 dlgLayout->addWidget(_closeButton, 2, 1, Qt::AlignRight);
503 dlgLayout->addWidget(_okButton, 2, 2);
504
505 setMinimumSize(600,400);
506 setWindowTitle(tr("Select Broadcaster"));
507 setLayout(dlgLayout);
508 resize(68*ww, 60*ww);
509 show();
510}
511
512// Caster table what's this
513////////////////////////////////////////////////////////////////////////////
514void bncCasterTableDlg:: slotWhatsThisCasterTable() {
515 QWhatsThis::enterWhatsThisMode();
516}
517
518// Caster table destructor
519////////////////////////////////////////////////////////////////////////////
520bncCasterTableDlg::~bncCasterTableDlg() {
521 if (_casterTable) {
522 for (int ir = 0; ir < _casterTable->rowCount(); ir++) {
523 for (int ic = 0; ic < _casterTable->columnCount(); ic++) {
524 delete _casterTable->item(ir,ic);
525 }
526 }
527 }
528}
529
530// Accept caster table
531////////////////////////////////////////////////////////////////////////////
532void bncCasterTableDlg::slotAcceptCasterTable() {
533 if (_casterTable) {
534 for (int ir = 0; ir < _casterTable->rowCount(); ir++) {
535 if (_casterTable->isItemSelected(_casterTable->item(ir,0))) {
536 emit newCaster(_casterTable->item(ir,0)->text(),
537 _casterTable->item(ir,1)->text());
538 }
539 }
540 }
541 QDialog::accept();
542}
543
544// New caster selected
545////////////////////////////////////////////////////////////////////////////
546void bncTableDlg::slotNewCaster(QString newCasterHost, QString newCasterPort) {
547
548 _casterHostComboBox->insertItem(0, newCasterHost);
549 _casterUserLineEdit->setText("");
550 _casterPortLineEdit->setText(newCasterPort);
551
552 QUrl url;
553 url.setScheme("http");
554 url.setHost(newCasterHost);
555 url.setPort(newCasterPort.toInt());
556 addUrl(url);
557}
558
559// New caster selected
560////////////////////////////////////////////////////////////////////////////
561void bncTableDlg::addUrl(const QUrl& url) {
562 QSettings settings;
563 QStringList oldUrlList = settings.value("casterUrlList").toStringList();
564 QStringList newUrlList;
565 bool replaced = false;
566 for (int ii = 0; ii < oldUrlList.count(); ii++) {
567 QUrl oldUrl(oldUrlList[ii]);
568 if (url.host() == oldUrl.host()) {
569 newUrlList << url.toString();
570 replaced = true;
571 }
572 else {
573 newUrlList << oldUrl.toString();
574 }
575 }
576 if (! replaced) {
577 newUrlList << url.toString();
578 }
579 settings.setValue("casterUrlList", newUrlList);
580 settings.sync();
581}
582
583// New caster selected in combobox
584////////////////////////////////////////////////////////////////////////////
585void bncTableDlg::slotCasterHostChanged(const QString& newHost) {
586 QSettings settings;
587 QStringList casterUrlList = settings.value("casterUrlList").toStringList();
588 for (int ii = 0; ii < casterUrlList.count(); ii++) {
589 QUrl url(casterUrlList[ii]);
590 if (url.host() == newHost) {
591 _casterUserLineEdit->setText(url.userName());
592 if (url.port() > 0) {
593 _casterPortLineEdit->setText(QString("%1").arg(url.port()));
594 }
595 else {
596 _casterPortLineEdit->setText("");
597 }
598 }
599 }
600}
Note: See TracBrowser for help on using the repository browser.