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

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

* empty log message *

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