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

Last change on this file since 104 was 104, checked in by mervart, 18 years ago

* empty log message *

File size: 6.3 KB
Line 
1
2/* -------------------------------------------------------------------------
3 * BKG NTRIP Client
4 * -------------------------------------------------------------------------
5 *
6 * Class: bncTableDlg
7 *
8 * Purpose: Displays the source table, allows mountpoints selection
9 *
10 * Author: L. Mervart
11 *
12 * Created: 24-Dec-2005
13 *
14 * Changes:
15 *
16 * -----------------------------------------------------------------------*/
17
18#include "bnctabledlg.h"
19#include "bncgetthread.h"
20
21// Constructor
22////////////////////////////////////////////////////////////////////////////
23bncTableDlg::bncTableDlg(QWidget* parent) : QDialog(parent) {
24
25 setMinimumSize(600,400);
26
27 QVBoxLayout* mainLayout = new QVBoxLayout(this);
28
29 _casterHostLabel = new QLabel(tr("caster host"));
30 _casterPortLabel = new QLabel(tr("caster port"));
31 _casterUserLabel = new QLabel(tr("user"));
32 _casterPasswordLabel = new QLabel(tr("password"));
33 QSettings settings;
34 _casterHostLineEdit = new QLineEdit(settings.value("casterHost").toString());
35 int ww = QFontMetrics(_casterHostLineEdit->font()).width('w');
36 _casterHostLineEdit->setMaximumWidth(18*ww);
37 _casterPortLineEdit = new QLineEdit(settings.value("casterPort").toString());
38 _casterPortLineEdit->setMaximumWidth(9*ww);
39 _casterUserLineEdit = new QLineEdit(settings.value("casterUser").toString());
40 _casterUserLineEdit->setMaximumWidth(9*ww);
41 _casterPasswordLineEdit = new QLineEdit(settings.value("casterPassword").toString());
42 _casterPasswordLineEdit->setMaximumWidth(9*ww);
43 _casterPasswordLineEdit->setEchoMode(QLineEdit::Password);
44
45 QGridLayout* editLayout = new QGridLayout;
46 editLayout->addWidget(_casterHostLabel, 0, 0);
47 editLayout->addWidget(_casterHostLineEdit, 0, 1);
48 editLayout->addWidget(_casterPortLabel, 0, 2);
49 editLayout->addWidget(_casterPortLineEdit, 0, 3);
50 editLayout->addWidget(_casterUserLabel, 1, 0);
51 editLayout->addWidget(_casterUserLineEdit, 1, 1);
52 editLayout->addWidget(_casterPasswordLabel, 1, 2);
53 editLayout->addWidget(_casterPasswordLineEdit, 1, 3);
54
55 mainLayout->addLayout(editLayout);
56
57 _table = new QTableWidget(this);
58 mainLayout->addWidget(_table);
59
60 _buttonGet = new QPushButton(tr("Get Table"), this);
61 connect(_buttonGet, SIGNAL(clicked()), this, SLOT(slotGetTable()));
62
63 _buttonCancel = new QPushButton(tr("Cancel"), this);
64 connect(_buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
65
66 _buttonOK = new QPushButton(tr("OK"), this);
67 connect(_buttonOK, SIGNAL(clicked()), this, SLOT(accept()));
68
69 QHBoxLayout* buttonLayout = new QHBoxLayout;
70 buttonLayout->addStretch(1);
71 buttonLayout->addWidget(_buttonGet);
72 buttonLayout->addWidget(_buttonCancel);
73 buttonLayout->addWidget(_buttonOK);
74
75 mainLayout->addLayout(buttonLayout);
76}
77
78// Destructor
79////////////////////////////////////////////////////////////////////////////
80bncTableDlg::~bncTableDlg() {
81 if (_table) {
82 for (int ir = 0; ir < _table->rowCount(); ir++) {
83 for (int ic = 0; ic < _table->columnCount(); ic++) {
84 delete _table->item(ir,ic);
85 }
86 }
87 }
88}
89
90// Read Table from Caster
91////////////////////////////////////////////////////////////////////////////
92void bncTableDlg::slotGetTable() {
93
94 QUrl url;
95 url.setHost(_casterHostLineEdit->text());
96 url.setPort(_casterPortLineEdit->text().toInt());
97
98 // Send the Request
99 // ----------------
100 QString msg;
101 QTcpSocket* socket = bncGetThread::request(url, msg);
102
103 if (!socket) {
104 QMessageBox::warning(0, "BNC", msg);
105 return;
106 }
107
108 // Read Caster Response
109 // --------------------
110 QStringList allLines;
111 bool first = true;
112 while (true) {
113 if (socket->canReadLine()) {
114 QString line = socket->readLine();
115 if (first) {
116 first = false;
117 if (line.indexOf("SOURCETABLE 200 OK") != 0) {
118 QMessageBox::warning(0, "BNC", "Wrong Caster Response:\n" + line);
119 break;
120 }
121 }
122 else {
123 if (line.indexOf("ENDSOURCETABLE") == 0) {
124 break;
125 }
126 if (line.indexOf("STR") == 0) {
127 allLines.push_back(line);
128 }
129 }
130 }
131 else {
132 const int timeOut = 10*1000;
133 socket->waitForReadyRead(timeOut);
134 if (socket->bytesAvailable() > 0) {
135 continue;
136 }
137 else {
138 QMessageBox::warning(0, "BNC", "Data Timeout");
139 break;
140 }
141 }
142 }
143 delete socket;
144
145 static const QStringList labels = QString("mountpoint,identifier,format,"
146 "format-details,carrier,nav-system,network,country,latitude,longitude,"
147 "nmea,solution,generator,compression,authentication,fee,bitrate,"
148 "misc").split(",");
149
150 if (allLines.size() > 0) {
151 _table->setSelectionMode(QAbstractItemView::ExtendedSelection);
152 _table->setSelectionBehavior(QAbstractItemView::SelectRows);
153
154 QStringList hlp = allLines[0].split(";");
155 _table->setColumnCount(hlp.size()-1);
156 _table->setRowCount(allLines.size());
157
158 QListIterator<QString> it(allLines);
159 int nRow = -1;
160 while (it.hasNext()) {
161 QStringList columns = it.next().split(";");
162 ++nRow;
163 for (int ic = 0; ic < columns.size()-1; ic++) {
164 _table->setItem(nRow, ic, new QTableWidgetItem(columns[ic+1]));
165 }
166 }
167 _table->sortItems(0);
168 _table->setHorizontalHeaderLabels(labels);
169 _table->setSortingEnabled(true);
170 }
171}
172
173// Accept slot
174////////////////////////////////////////////////////////////////////////////
175void bncTableDlg::accept() {
176
177 QSettings settings;
178 settings.setValue("casterHost", _casterHostLineEdit->text());
179 settings.setValue("casterPort", _casterPortLineEdit->text());
180 settings.setValue("casterUser", _casterUserLineEdit->text());
181 settings.setValue("casterPassword", _casterPasswordLineEdit->text());
182
183 QStringList* mountPoints = new QStringList;
184
185 if (_table) {
186 for (int ir = 0; ir < _table->rowCount(); ir++) {
187 QTableWidgetItem* item = _table->item(ir,0);
188 QString format = _table->item(ir,2)->text();
189 format.replace(" ", "_");
190 if (_table->isItemSelected(item)) {
191 QUrl url;
192 url.setUserName(_casterUserLineEdit->text());
193 url.setPassword(_casterPasswordLineEdit->text());
194 url.setHost(_casterHostLineEdit->text());
195 url.setPort(_casterPortLineEdit->text().toInt());
196 url.setPath(item->text());
197
198 mountPoints->push_back(url.toString() + " " + format);
199 }
200 }
201 }
202 emit newMountPoints(mountPoints);
203
204 QDialog::accept();
205}
Note: See TracBrowser for help on using the repository browser.