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

Last change on this file since 298 was 298, checked in by mervart, 17 years ago

* empty log message *

File size: 9.6 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 QMap<QString, QStringList> allTables;
125
126 if (!alwaysRead && allTables.find(casterHost) != allTables.end()) {
127 allLines = allTables.find(casterHost).value();
128 return success;
129 }
130
131 allLines.clear();
132
133 QUrl url;
134 url.setHost(casterHost);
135 url.setPort(casterPort);
136
137 // Send the Request
138 // ----------------
139 const int timeOut = 10*1000;
140 QString msg;
141 QTcpSocket* socket = bncGetThread::request(url, timeOut, msg);
142
143 if (!socket) {
144 return failure;
145 }
146
147 // Read Caster Response
148 // --------------------
149 bool first = true;
150 while (true) {
151 if (socket->canReadLine()) {
152 QString line = socket->readLine();
153 allLines.push_back(line);
154 if (first) {
155 first = false;
156 if (line.indexOf("SOURCETABLE 200 OK") != 0) {
157 break;
158 }
159 }
160 else {
161 if (line.indexOf("ENDSOURCETABLE") == 0) {
162 break;
163 }
164 }
165 }
166 else {
167 socket->waitForReadyRead(timeOut);
168 if (socket->bytesAvailable() > 0) {
169 continue;
170 }
171 else {
172 break;
173 }
174 }
175 }
176 delete socket;
177
178 allTables.insert(casterHost, allLines);
179 return success;
180}
181
182// Read Table from Caster
183////////////////////////////////////////////////////////////////////////////
184void bncTableDlg::slotGetTable() {
185
186 _allLines.clear();
187
188 if ( getFullTable(_casterHostLineEdit->text(),
189 _casterPortLineEdit->text().toInt(),
190 _allLines) != success ) {
191 QMessageBox::warning(0, "BNC", "Cannot retrieve table of data");
192 return;
193 }
194
195 QStringList lines;
196 QStringListIterator it(_allLines);
197 while (it.hasNext()) {
198 QString line = it.next();
199 if (line.indexOf("STR") == 0) {
200 lines.push_back(line);
201 }
202 }
203
204 static const QStringList labels = QString("mountpoint,identifier,format,"
205 "format-details,carrier,nav-system,network,country,latitude,longitude,"
206 "nmea,solution,generator,compression,authentication,fee,bitrate,"
207 "misc").split(",");
208
209 if (lines.size() > 0) {
210 _table->setSelectionMode(QAbstractItemView::ExtendedSelection);
211 _table->setSelectionBehavior(QAbstractItemView::SelectRows);
212
213 QStringList hlp = lines[0].split(";");
214 _table->setColumnCount(hlp.size()-1);
215 _table->setRowCount(lines.size());
216
217 QListIterator<QString> it(lines);
218 int nRow = -1;
219 while (it.hasNext()) {
220 QStringList columns = it.next().split(";");
221 ++nRow;
222 for (int ic = 0; ic < columns.size()-1; ic++) {
223 QTableWidgetItem* it = new QTableWidgetItem(columns[ic+1]);
224 it->setFlags(it->flags() & ~Qt::ItemIsEditable);
225 _table->setItem(nRow, ic, it);
226 }
227 }
228 _table->sortItems(0);
229 _table->setHorizontalHeaderLabels(labels);
230 _table->setSortingEnabled(true);
231 }
232}
233
234// Accept slot
235////////////////////////////////////////////////////////////////////////////
236void bncTableDlg::accept() {
237
238 QSettings settings;
239 settings.setValue("casterHost", _casterHostLineEdit->text());
240 settings.setValue("casterPort", _casterPortLineEdit->text());
241 settings.setValue("casterUser", _casterUserLineEdit->text());
242 settings.setValue("casterPassword", _casterPasswordLineEdit->text());
243
244 QStringList* mountPoints = new QStringList;
245
246 if (_table) {
247 for (int ir = 0; ir < _table->rowCount(); ir++) {
248 QTableWidgetItem* item = _table->item(ir,0);
249 QString format = _table->item(ir,2)->text();
250 format.replace(" ", "_");
251 if (_table->isItemSelected(item)) {
252 QUrl url;
253 url.setUserName(_casterUserLineEdit->text());
254 url.setPassword(_casterPasswordLineEdit->text());
255 url.setHost(_casterHostLineEdit->text());
256 url.setPort(_casterPortLineEdit->text().toInt());
257 url.setPath(item->text());
258
259 mountPoints->push_back(url.toString() + " " + format);
260 }
261 }
262 }
263 emit newMountPoints(mountPoints);
264
265 QDialog::accept();
266}
267
268// User changed the selection of mountPoints
269////////////////////////////////////////////////////////////////////////////
270void bncTableDlg::slotSelectionChanged() {
271 if (_table->selectedItems().isEmpty()) {
272 // _buttonSkl->setEnabled(false);
273 }
274 else {
275 // _buttonSkl->setEnabled(true);
276 }
277}
278
279// Create RINEX skeleton header
280////////////////////////////////////////////////////////////////////////////
281void bncTableDlg::slotSkl() {
282
283 int nRows = _table->rowCount();
284 for (int iRow = 0; iRow < nRows; iRow++) {
285 if (_table->isItemSelected(_table->item(iRow,1))) {
286 QString staID = _table->item(iRow,0)->text();
287 QString net = _table->item(iRow,6)->text();
288
289 QString ftpDir;
290 QStringListIterator it(_allLines);
291 while (it.hasNext()) {
292 QString line = it.next();
293 if (line.indexOf("NET") == 0) {
294 QStringList tags = line.split(';');
295 if (tags.at(1) == net) {
296 ftpDir = tags.at(6);
297 break;
298 }
299 }
300 }
301
302 if (!ftpDir.isEmpty()) {
303 QUrl url(ftpDir);
304 QMessageBox::warning(0, "Warning", url.host() + "\n" + url.path() +
305 "\nnot yet implemented");
306 }
307 }
308 }
309}
310
Note: See TracBrowser for help on using the repository browser.