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

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

* empty log message *

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