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 | ////////////////////////////////////////////////////////////////////////////
|
---|
23 | bncTableDlg::bncTableDlg(QWidget* parent) : QDialog(parent) {
|
---|
24 |
|
---|
25 | setMinimumSize(600,400);
|
---|
26 |
|
---|
27 | QVBoxLayout* mainLayout = new QVBoxLayout(this);
|
---|
28 |
|
---|
29 | QSettings settings;
|
---|
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);
|
---|
40 |
|
---|
41 | QGridLayout* editLayout = new QGridLayout;
|
---|
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);
|
---|
50 |
|
---|
51 | mainLayout->addLayout(editLayout);
|
---|
52 |
|
---|
53 | _table = new QTableWidget(this);
|
---|
54 | connect(_table, SIGNAL(itemSelectionChanged()),
|
---|
55 | this, SLOT(slotSelectionChanged()));
|
---|
56 | mainLayout->addWidget(_table);
|
---|
57 |
|
---|
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);
|
---|
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;
|
---|
72 | // buttonLayout->addWidget(_buttonSkl);
|
---|
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 | ////////////////////////////////////////////////////////////////////////////
|
---|
83 | bncTableDlg::~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 |
|
---|
93 | // Read Table the caster (static)
|
---|
94 | ////////////////////////////////////////////////////////////////////////////
|
---|
95 | t_irc bncTableDlg::getFullTable(const QString& casterHost,
|
---|
96 | int casterPort, QStringList& allLines) {
|
---|
97 |
|
---|
98 | allLines.clear();
|
---|
99 |
|
---|
100 | QUrl url;
|
---|
101 | url.setHost(casterHost);
|
---|
102 | url.setPort(casterPort);
|
---|
103 |
|
---|
104 | // Send the Request
|
---|
105 | // ----------------
|
---|
106 | const int timeOut = 10*1000;
|
---|
107 | QString msg;
|
---|
108 | QTcpSocket* socket = bncGetThread::request(url, timeOut, msg);
|
---|
109 |
|
---|
110 | if (!socket) {
|
---|
111 | return failure;
|
---|
112 | }
|
---|
113 |
|
---|
114 | // Read Caster Response
|
---|
115 | // --------------------
|
---|
116 | bool first = true;
|
---|
117 | while (true) {
|
---|
118 | if (socket->canReadLine()) {
|
---|
119 | QString line = socket->readLine();
|
---|
120 | allLines.push_back(line);
|
---|
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 |
|
---|
145 | return success;
|
---|
146 | }
|
---|
147 |
|
---|
148 | // Read Table from Caster
|
---|
149 | ////////////////////////////////////////////////////////////////////////////
|
---|
150 | void bncTableDlg::slotGetTable() {
|
---|
151 |
|
---|
152 | _allLines.clear();
|
---|
153 |
|
---|
154 | if ( getFullTable(_casterHostLineEdit->text(),
|
---|
155 | _casterPortLineEdit->text().toInt(),
|
---|
156 | _allLines) != success ) {
|
---|
157 | QMessageBox::warning(0, "BNC", "Cannot retrieve table of data");
|
---|
158 | return;
|
---|
159 | }
|
---|
160 |
|
---|
161 | QStringList lines;
|
---|
162 | QStringListIterator it(_allLines);
|
---|
163 | while (it.hasNext()) {
|
---|
164 | QString line = it.next();
|
---|
165 | if (line.indexOf("STR") == 0) {
|
---|
166 | lines.push_back(line);
|
---|
167 | }
|
---|
168 | }
|
---|
169 |
|
---|
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 |
|
---|
175 | if (lines.size() > 0) {
|
---|
176 | _table->setSelectionMode(QAbstractItemView::ExtendedSelection);
|
---|
177 | _table->setSelectionBehavior(QAbstractItemView::SelectRows);
|
---|
178 |
|
---|
179 | QStringList hlp = lines[0].split(";");
|
---|
180 | _table->setColumnCount(hlp.size()-1);
|
---|
181 | _table->setRowCount(lines.size());
|
---|
182 |
|
---|
183 | QListIterator<QString> it(lines);
|
---|
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++) {
|
---|
189 | QTableWidgetItem* it = new QTableWidgetItem(columns[ic+1]);
|
---|
190 | it->setFlags(it->flags() & ~Qt::ItemIsEditable);
|
---|
191 | _table->setItem(nRow, ic, it);
|
---|
192 | }
|
---|
193 | }
|
---|
194 | _table->sortItems(0);
|
---|
195 | _table->setHorizontalHeaderLabels(labels);
|
---|
196 | _table->setSortingEnabled(true);
|
---|
197 | }
|
---|
198 | }
|
---|
199 |
|
---|
200 | // Accept slot
|
---|
201 | ////////////////////////////////////////////////////////////////////////////
|
---|
202 | void bncTableDlg::accept() {
|
---|
203 |
|
---|
204 | QSettings settings;
|
---|
205 | settings.setValue("casterHost", _casterHostLineEdit->text());
|
---|
206 | settings.setValue("casterPort", _casterPortLineEdit->text());
|
---|
207 | settings.setValue("casterUser", _casterUserLineEdit->text());
|
---|
208 | settings.setValue("casterPassword", _casterPasswordLineEdit->text());
|
---|
209 |
|
---|
210 | QStringList* mountPoints = new QStringList;
|
---|
211 |
|
---|
212 | if (_table) {
|
---|
213 | for (int ir = 0; ir < _table->rowCount(); ir++) {
|
---|
214 | QTableWidgetItem* item = _table->item(ir,0);
|
---|
215 | QString format = _table->item(ir,2)->text();
|
---|
216 | format.replace(" ", "_");
|
---|
217 | if (_table->isItemSelected(item)) {
|
---|
218 | QUrl url;
|
---|
219 | url.setUserName(_casterUserLineEdit->text());
|
---|
220 | url.setPassword(_casterPasswordLineEdit->text());
|
---|
221 | url.setHost(_casterHostLineEdit->text());
|
---|
222 | url.setPort(_casterPortLineEdit->text().toInt());
|
---|
223 | url.setPath(item->text());
|
---|
224 |
|
---|
225 | mountPoints->push_back(url.toString() + " " + format);
|
---|
226 | }
|
---|
227 | }
|
---|
228 | }
|
---|
229 | emit newMountPoints(mountPoints);
|
---|
230 |
|
---|
231 | QDialog::accept();
|
---|
232 | }
|
---|
233 |
|
---|
234 | // User changed the selection of mountPoints
|
---|
235 | ////////////////////////////////////////////////////////////////////////////
|
---|
236 | void bncTableDlg::slotSelectionChanged() {
|
---|
237 | if (_table->selectedItems().isEmpty()) {
|
---|
238 | // _buttonSkl->setEnabled(false);
|
---|
239 | }
|
---|
240 | else {
|
---|
241 | // _buttonSkl->setEnabled(true);
|
---|
242 | }
|
---|
243 | }
|
---|
244 |
|
---|
245 | // Create RINEX skeleton header
|
---|
246 | ////////////////////////////////////////////////////////////////////////////
|
---|
247 | void bncTableDlg::slotSkl() {
|
---|
248 |
|
---|
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();
|
---|
254 |
|
---|
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 |
|
---|
268 | if (!ftpDir.isEmpty()) {
|
---|
269 | QUrl url(ftpDir);
|
---|
270 | QMessageBox::warning(0, "Warning", url.host() + "\n" + url.path() +
|
---|
271 | "\nnot yet implemented");
|
---|
272 | }
|
---|
273 | }
|
---|
274 | }
|
---|
275 | }
|
---|
276 |
|
---|