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

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

* empty log message *

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