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

Last change on this file since 372 was 371, checked in by weber, 18 years ago

* empty log message *

File size: 11.0 KB
Line 
1// Part of BNC, a utility for retrieving decoding and
2// converting GNSS data streams from NTRIP broadcasters,
3// written by Leos Mervart.
4//
5// Copyright (C) 2006
6// German Federal Agency for Cartography and Geodesy (BKG)
7// http://www.bkg.bund.de
8// Czech Technical University Prague, Department of Advanced Geodesy
9// http://www.fsv.cvut.cz
10//
11// Email: euref-ip@bkg.bund.de
12//
13// This program is free software; you can redistribute it and/or
14// modify it under the terms of the GNU General Public License
15// as published by the Free Software Foundation, version 2.
16//
17// This program is distributed in the hope that it will be useful,
18// but WITHOUT ANY WARRANTY; without even the implied warranty of
19// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20// GNU General Public License for more details.
21//
22// You should have received a copy of the GNU General Public License
23// along with this program; if not, write to the Free Software
24// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25
26/* -------------------------------------------------------------------------
27 * BKG NTRIP Client
28 * -------------------------------------------------------------------------
29 *
30 * Class: bncTableDlg
31 *
32 * Purpose: Displays the source table, allows mountpoints selection
33 *
34 * Author: L. Mervart
35 *
36 * Created: 24-Dec-2005
37 *
38 * Changes:
39 *
40 * -----------------------------------------------------------------------*/
41
42#include "bnctabledlg.h"
43#include "bncgetthread.h"
44
45// Constructor
46////////////////////////////////////////////////////////////////////////////
47bncTableDlg::bncTableDlg(QWidget* parent) : QDialog(parent) {
48
49 setMinimumSize(600,400);
50 setWindowTitle(tr("Add Mountpoints"));
51
52 QVBoxLayout* mainLayout = new QVBoxLayout(this);
53
54 QSettings settings;
55 _casterHostLineEdit = new QLineEdit(settings.value("casterHost").toString());
56 int ww = QFontMetrics(_casterHostLineEdit->font()).width('w');
57 _casterHostLineEdit->setMaximumWidth(18*ww);
58 _casterPortLineEdit = new QLineEdit(settings.value("casterPort").toString());
59 _casterPortLineEdit->setMaximumWidth(9*ww);
60 _casterUserLineEdit = new QLineEdit(settings.value("casterUser").toString());
61 _casterUserLineEdit->setMaximumWidth(9*ww);
62 _casterPasswordLineEdit = new QLineEdit(settings.value("casterPassword").toString());
63 _casterPasswordLineEdit->setMaximumWidth(9*ww);
64 _casterPasswordLineEdit->setEchoMode(QLineEdit::Password);
65
66 QGridLayout* editLayout = new QGridLayout;
67 editLayout->addWidget(new QLabel(tr("Caster host")), 0, 0);
68 editLayout->addWidget(_casterHostLineEdit, 0, 1);
69 editLayout->addWidget(new QLabel(tr("Caster port")), 0, 2);
70 editLayout->addWidget(_casterPortLineEdit, 0, 3);
71 editLayout->addWidget(new QLabel(tr("User")), 1, 0);
72 editLayout->addWidget(_casterUserLineEdit, 1, 1);
73 editLayout->addWidget(new QLabel(tr("Password")), 1, 2);
74 editLayout->addWidget(_casterPasswordLineEdit, 1, 3);
75
76 mainLayout->addLayout(editLayout);
77
78 _table = new QTableWidget(this);
79 connect(_table, SIGNAL(itemSelectionChanged()),
80 this, SLOT(slotSelectionChanged()));
81 mainLayout->addWidget(_table);
82
83 // _buttonSkl = new QPushButton(tr("Create skeleton headers"), this);
84 // _buttonSkl->setEnabled(false);
85 // connect(_buttonSkl, SIGNAL(clicked()), this, SLOT(slotSkl()));
86
87 _buttonGet = new QPushButton(tr("Get table"), this);
88 connect(_buttonGet, SIGNAL(clicked()), this, SLOT(slotGetTable()));
89
90 _buttonCancel = new QPushButton(tr("Cancel"), this);
91 connect(_buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
92
93 _buttonOK = new QPushButton(tr("OK"), this);
94 connect(_buttonOK, SIGNAL(clicked()), this, SLOT(accept()));
95
96 QHBoxLayout* buttonLayout = new QHBoxLayout;
97 // buttonLayout->addWidget(_buttonSkl);
98 buttonLayout->addStretch(1);
99 buttonLayout->addWidget(_buttonGet);
100 buttonLayout->addWidget(_buttonCancel);
101 buttonLayout->addWidget(_buttonOK);
102
103 mainLayout->addLayout(buttonLayout);
104}
105
106// Destructor
107////////////////////////////////////////////////////////////////////////////
108bncTableDlg::~bncTableDlg() {
109 if (_table) {
110 for (int ir = 0; ir < _table->rowCount(); ir++) {
111 for (int ic = 0; ic < _table->columnCount(); ic++) {
112 delete _table->item(ir,ic);
113 }
114 }
115 }
116}
117
118// Read Table the caster (static)
119////////////////////////////////////////////////////////////////////////////
120t_irc bncTableDlg::getFullTable(const QString& casterHost,
121 int casterPort, QStringList& allLines,
122 bool alwaysRead) {
123
124 static QMutex mutex;
125 static QMap<QString, QStringList> allTables;
126
127 QMutexLocker locker(&mutex);
128
129 if (!alwaysRead && allTables.find(casterHost) != allTables.end()) {
130 allLines = allTables.find(casterHost).value();
131 return success;
132 }
133
134 allLines.clear();
135
136 QUrl url;
137 url.setHost(casterHost);
138 url.setPort(casterPort);
139
140 // Send the Request
141 // ----------------
142 const int timeOut = 10*1000;
143 QString msg;
144 QByteArray _latitude;
145 QByteArray _longitude;
146 QByteArray _nmea;
147 QTcpSocket* socket = bncGetThread::request(url, _latitude, _longitude, _nmea, timeOut, msg);
148
149 if (!socket) {
150 return failure;
151 }
152
153 // Read Caster Response
154 // --------------------
155 bool first = true;
156 while (true) {
157 if (socket->canReadLine()) {
158 QString line = socket->readLine();
159 allLines.push_back(line);
160 if (first) {
161 first = false;
162 if (line.indexOf("SOURCETABLE 200 OK") != 0) {
163 break;
164 }
165 }
166 else {
167 if (line.indexOf("ENDSOURCETABLE") == 0) {
168 break;
169 }
170 }
171 }
172 else {
173 socket->waitForReadyRead(timeOut);
174 if (socket->bytesAvailable() > 0) {
175 continue;
176 }
177 else {
178 break;
179 }
180 }
181 }
182 delete socket;
183
184 allTables.insert(casterHost, allLines);
185 return success;
186}
187
188// Read Table from Caster
189////////////////////////////////////////////////////////////////////////////
190void bncTableDlg::slotGetTable() {
191
192 _allLines.clear();
193
194 if ( getFullTable(_casterHostLineEdit->text(),
195 _casterPortLineEdit->text().toInt(),
196 _allLines) != success ) {
197 QMessageBox::warning(0, "BNC", "Cannot retrieve table of data");
198 return;
199 }
200
201 QStringList lines;
202 QStringListIterator it(_allLines);
203 while (it.hasNext()) {
204 QString line = it.next();
205 if (line.indexOf("STR") == 0) {
206 lines.push_back(line);
207 }
208 }
209
210 static const QStringList labels = QString("mountpoint,identifier,format,"
211 "format-details,carrier,system,network,country,latitude,longitude,"
212 "type,solution,generator,compress.,authentic.,fee,bitrate,"
213 "misc").split(",");
214
215 if (lines.size() > 0) {
216 _table->setSelectionMode(QAbstractItemView::ExtendedSelection);
217 _table->setSelectionBehavior(QAbstractItemView::SelectRows);
218
219 QStringList hlp = lines[0].split(";");
220 _table->setColumnCount(hlp.size()-1);
221 _table->setRowCount(lines.size());
222
223 QListIterator<QString> it(lines);
224 int nRow = -1;
225 while (it.hasNext()) {
226 QStringList columns = it.next().split(";");
227 ++nRow;
228 for (int ic = 0; ic < columns.size()-1; ic++) {
229
230 if (ic+1 == 11) { if (columns[ic+1] == "0") { columns[ic+1] = "RS"; } else { columns[ic+1] = "VRS"; }}
231
232 QTableWidgetItem* it = new QTableWidgetItem(columns[ic+1]);
233 it->setFlags(it->flags() & ~Qt::ItemIsEditable);
234 _table->setItem(nRow, ic, it);
235 }
236 }
237 _table->sortItems(0);
238 _table->setHorizontalHeaderLabels(labels);
239 _table->setSortingEnabled(true);
240
241 int ww = QFontMetrics(this->font()).width('w');
242 _table->horizontalHeader()->resizeSection(0,9*ww);
243 _table->horizontalHeader()->resizeSection(2,8*ww);
244 _table->horizontalHeader()->resizeSection(3,15*ww);
245 _table->horizontalHeader()->resizeSection(4,8*ww);
246 _table->horizontalHeader()->resizeSection(5,8*ww);
247 _table->horizontalHeader()->resizeSection(6,8*ww);
248 _table->horizontalHeader()->resizeSection(7,8*ww);
249 _table->horizontalHeader()->resizeSection(8,8*ww);
250 _table->horizontalHeader()->resizeSection(9,8*ww);
251 _table->horizontalHeader()->resizeSection(10,8*ww);
252 _table->horizontalHeader()->resizeSection(11,8*ww);
253 _table->horizontalHeader()->resizeSection(12,15*ww);
254 _table->horizontalHeader()->resizeSection(13,8*ww);
255 _table->horizontalHeader()->resizeSection(14,8*ww);
256 _table->horizontalHeader()->resizeSection(15,8*ww);
257 _table->horizontalHeader()->resizeSection(16,8*ww);
258 _table->horizontalHeader()->resizeSection(17,15*ww);
259 }
260}
261
262// Accept slot
263////////////////////////////////////////////////////////////////////////////
264void bncTableDlg::accept() {
265
266 QSettings settings;
267 settings.setValue("casterHost", _casterHostLineEdit->text());
268 settings.setValue("casterPort", _casterPortLineEdit->text());
269 settings.setValue("casterUser", _casterUserLineEdit->text());
270 settings.setValue("casterPassword", _casterPasswordLineEdit->text());
271
272 QStringList* mountPoints = new QStringList;
273
274 if (_table) {
275 for (int ir = 0; ir < _table->rowCount(); ir++) {
276 QTableWidgetItem* item = _table->item(ir,0);
277 QString format = _table->item(ir,2)->text();
278 QString latitude = _table->item(ir,8)->text();
279 QString longitude = _table->item(ir,9)->text();
280 QString nmea = _table->item(ir,10)->text();
281 format.replace(" ", "_");
282 if (_table->isItemSelected(item)) {
283 QUrl url;
284 url.setUserName(_casterUserLineEdit->text());
285 url.setPassword(_casterPasswordLineEdit->text());
286 url.setHost(_casterHostLineEdit->text());
287 url.setPort(_casterPortLineEdit->text().toInt());
288 url.setPath(item->text());
289
290 mountPoints->push_back(url.toString() + " " + format + " " + latitude + " " + longitude + " " + nmea);
291 }
292 }
293 }
294 emit newMountPoints(mountPoints);
295
296 QDialog::accept();
297}
298
299// User changed the selection of mountPoints
300////////////////////////////////////////////////////////////////////////////
301void bncTableDlg::slotSelectionChanged() {
302 if (_table->selectedItems().isEmpty()) {
303 // _buttonSkl->setEnabled(false);
304 }
305 else {
306 // _buttonSkl->setEnabled(true);
307 }
308}
309
310// Create RINEX skeleton header
311////////////////////////////////////////////////////////////////////////////
312void bncTableDlg::slotSkl() {
313
314 int nRows = _table->rowCount();
315 for (int iRow = 0; iRow < nRows; iRow++) {
316 if (_table->isItemSelected(_table->item(iRow,1))) {
317 QString staID = _table->item(iRow,0)->text();
318 QString net = _table->item(iRow,6)->text();
319
320 QString ftpDir;
321 QStringListIterator it(_allLines);
322 while (it.hasNext()) {
323 QString line = it.next();
324 if (line.indexOf("NET") == 0) {
325 QStringList tags = line.split(';');
326 if (tags.at(1) == net) {
327 ftpDir = tags.at(6);
328 break;
329 }
330 }
331 }
332
333 if (!ftpDir.isEmpty()) {
334 QUrl url(ftpDir);
335 QMessageBox::warning(0, "Warning", url.host() + "\n" + url.path() +
336 "\nnot yet implemented");
337 }
338 }
339 }
340}
341
Note: See TracBrowser for help on using the repository browser.