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

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

* empty log message *

File size: 8.1 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 <iostream.h>
19
20#include "bnctabledlg.h"
21#include "bncgetthread.h"
22
23// Constructor
24////////////////////////////////////////////////////////////////////////////
25bncTableDlg::bncTableDlg(QWidget* parent) : QDialog(parent) {
26
27 setMinimumSize(600,400);
28
29 QVBoxLayout* mainLayout = new QVBoxLayout(this);
30
31 QSettings settings;
32 _casterHostLineEdit = new QLineEdit(settings.value("casterHost").toString());
33 int ww = QFontMetrics(_casterHostLineEdit->font()).width('w');
34 _casterHostLineEdit->setMaximumWidth(18*ww);
35 _casterPortLineEdit = new QLineEdit(settings.value("casterPort").toString());
36 _casterPortLineEdit->setMaximumWidth(9*ww);
37 _casterUserLineEdit = new QLineEdit(settings.value("casterUser").toString());
38 _casterUserLineEdit->setMaximumWidth(9*ww);
39 _casterPasswordLineEdit = new QLineEdit(settings.value("casterPassword").toString());
40 _casterPasswordLineEdit->setMaximumWidth(9*ww);
41 _casterPasswordLineEdit->setEchoMode(QLineEdit::Password);
42
43 QGridLayout* editLayout = new QGridLayout;
44 editLayout->addWidget(new QLabel(tr("Caster host")), 0, 0);
45 editLayout->addWidget(_casterHostLineEdit, 0, 1);
46 editLayout->addWidget(new QLabel(tr("Caster port")), 0, 2);
47 editLayout->addWidget(_casterPortLineEdit, 0, 3);
48 editLayout->addWidget(new QLabel(tr("User")), 1, 0);
49 editLayout->addWidget(_casterUserLineEdit, 1, 1);
50 editLayout->addWidget(new QLabel(tr("Password")), 1, 2);
51 editLayout->addWidget(_casterPasswordLineEdit, 1, 3);
52
53 mainLayout->addLayout(editLayout);
54
55 _table = new QTableWidget(this);
56 connect(_table, SIGNAL(itemSelectionChanged()),
57 this, SLOT(slotSelectionChanged()));
58 mainLayout->addWidget(_table);
59
60 _buttonSkl = new QPushButton(tr("Create skeleton headers"), this);
61 _buttonSkl->setEnabled(false);
62 connect(_buttonSkl, SIGNAL(clicked()), this, SLOT(slotSkl()));
63
64 _buttonGet = new QPushButton(tr("Get table"), this);
65 connect(_buttonGet, SIGNAL(clicked()), this, SLOT(slotGetTable()));
66
67 _buttonCancel = new QPushButton(tr("Cancel"), this);
68 connect(_buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
69
70 _buttonOK = new QPushButton(tr("OK"), this);
71 connect(_buttonOK, SIGNAL(clicked()), this, SLOT(accept()));
72
73 QHBoxLayout* buttonLayout = new QHBoxLayout;
74 buttonLayout->addWidget(_buttonSkl);
75 buttonLayout->addStretch(1);
76 buttonLayout->addWidget(_buttonGet);
77 buttonLayout->addWidget(_buttonCancel);
78 buttonLayout->addWidget(_buttonOK);
79
80 mainLayout->addLayout(buttonLayout);
81}
82
83// Destructor
84////////////////////////////////////////////////////////////////////////////
85bncTableDlg::~bncTableDlg() {
86 if (_table) {
87 for (int ir = 0; ir < _table->rowCount(); ir++) {
88 for (int ic = 0; ic < _table->columnCount(); ic++) {
89 delete _table->item(ir,ic);
90 }
91 }
92 }
93}
94
95// Read Table the caster (static)
96////////////////////////////////////////////////////////////////////////////
97t_irc bncTableDlg::getFullTable(const QString& casterHost,
98 int casterPort, QStringList& allLines) {
99
100 allLines.clear();
101
102 QUrl url;
103 url.setHost(casterHost);
104 url.setPort(casterPort);
105
106 // Send the Request
107 // ----------------
108 const int timeOut = 10*1000;
109 QString msg;
110 QTcpSocket* socket = bncGetThread::request(url, timeOut, msg);
111
112 if (!socket) {
113 return failure;
114 }
115
116 // Read Caster Response
117 // --------------------
118 bool first = true;
119 while (true) {
120 if (socket->canReadLine()) {
121 QString line = socket->readLine();
122 allLines.push_back(line);
123 if (first) {
124 first = false;
125 if (line.indexOf("SOURCETABLE 200 OK") != 0) {
126 break;
127 }
128 }
129 else {
130 if (line.indexOf("ENDSOURCETABLE") == 0) {
131 break;
132 }
133 }
134 }
135 else {
136 socket->waitForReadyRead(timeOut);
137 if (socket->bytesAvailable() > 0) {
138 continue;
139 }
140 else {
141 break;
142 }
143 }
144 }
145 delete socket;
146
147 return success;
148}
149
150// Read Table from Caster
151////////////////////////////////////////////////////////////////////////////
152void bncTableDlg::slotGetTable() {
153
154 _allLines.clear();
155
156 if ( getFullTable(_casterHostLineEdit->text(),
157 _casterPortLineEdit->text().toInt(),
158 _allLines) != success ) {
159 QMessageBox::warning(0, "BNC", "Cannot retrieve table of data");
160 return;
161 }
162
163 QStringList lines;
164 QStringListIterator it(_allLines);
165 while (it.hasNext()) {
166 QString line = it.next();
167 if (line.indexOf("STR") == 0) {
168 lines.push_back(line);
169 }
170 }
171
172 static const QStringList labels = QString("mountpoint,identifier,format,"
173 "format-details,carrier,nav-system,network,country,latitude,longitude,"
174 "nmea,solution,generator,compression,authentication,fee,bitrate,"
175 "misc").split(",");
176
177 if (lines.size() > 0) {
178 _table->setSelectionMode(QAbstractItemView::ExtendedSelection);
179 _table->setSelectionBehavior(QAbstractItemView::SelectRows);
180
181 QStringList hlp = lines[0].split(";");
182 _table->setColumnCount(hlp.size()-1);
183 _table->setRowCount(lines.size());
184
185 QListIterator<QString> it(lines);
186 int nRow = -1;
187 while (it.hasNext()) {
188 QStringList columns = it.next().split(";");
189 ++nRow;
190 for (int ic = 0; ic < columns.size()-1; ic++) {
191 QTableWidgetItem* it = new QTableWidgetItem(columns[ic+1]);
192 it->setFlags(it->flags() & ~Qt::ItemIsEditable);
193 _table->setItem(nRow, ic, it);
194 }
195 }
196 _table->sortItems(0);
197 _table->setHorizontalHeaderLabels(labels);
198 _table->setSortingEnabled(true);
199 }
200}
201
202// Accept slot
203////////////////////////////////////////////////////////////////////////////
204void bncTableDlg::accept() {
205
206 QSettings settings;
207 settings.setValue("casterHost", _casterHostLineEdit->text());
208 settings.setValue("casterPort", _casterPortLineEdit->text());
209 settings.setValue("casterUser", _casterUserLineEdit->text());
210 settings.setValue("casterPassword", _casterPasswordLineEdit->text());
211
212 QStringList* mountPoints = new QStringList;
213
214 if (_table) {
215 for (int ir = 0; ir < _table->rowCount(); ir++) {
216 QTableWidgetItem* item = _table->item(ir,0);
217 QString format = _table->item(ir,2)->text();
218 format.replace(" ", "_");
219 if (_table->isItemSelected(item)) {
220 QUrl url;
221 url.setUserName(_casterUserLineEdit->text());
222 url.setPassword(_casterPasswordLineEdit->text());
223 url.setHost(_casterHostLineEdit->text());
224 url.setPort(_casterPortLineEdit->text().toInt());
225 url.setPath(item->text());
226
227 mountPoints->push_back(url.toString() + " " + format);
228 }
229 }
230 }
231 emit newMountPoints(mountPoints);
232
233 QDialog::accept();
234}
235
236// User changed the selection of mountPoints
237////////////////////////////////////////////////////////////////////////////
238void bncTableDlg::slotSelectionChanged() {
239 if (_table->selectedItems().isEmpty()) {
240 _buttonSkl->setEnabled(false);
241 }
242 else {
243 _buttonSkl->setEnabled(true);
244 }
245}
246
247// Create RINEX skeleton header
248////////////////////////////////////////////////////////////////////////////
249void bncTableDlg::slotSkl() {
250
251 int nRows = _table->rowCount();
252 for (int iRow = 0; iRow < nRows; iRow++) {
253 if (_table->isItemSelected(_table->item(iRow,1))) {
254 QString staID = _table->item(iRow,0)->text();
255 QString net = _table->item(iRow,6)->text();
256
257 cout << (staID + " " + net).toAscii().data() << endl;
258
259 QString ftpDir;
260 QStringListIterator it(_allLines);
261 while (it.hasNext()) {
262 QString line = it.next();
263 if (line.indexOf("NET") == 0) {
264 QStringList tags = line.split(';');
265 if (tags.at(1) == net) {
266 ftpDir = tags.at(6);
267 break;
268 }
269 }
270 }
271
272 cout << ftpDir.toAscii().data() << endl;
273
274 }
275 }
276
277}
Note: See TracBrowser for help on using the repository browser.