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

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

* empty log message *

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