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

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

* empty log message *

File size: 6.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
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 mainLayout->addWidget(_table);
55
56 _buttonGet = new QPushButton(tr("Get Table"), this);
57 connect(_buttonGet, SIGNAL(clicked()), this, SLOT(slotGetTable()));
58
59 _buttonCancel = new QPushButton(tr("Cancel"), this);
60 connect(_buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
61
62 _buttonOK = new QPushButton(tr("OK"), this);
63 connect(_buttonOK, SIGNAL(clicked()), this, SLOT(accept()));
64
65 QHBoxLayout* buttonLayout = new QHBoxLayout;
66 buttonLayout->addStretch(1);
67 buttonLayout->addWidget(_buttonGet);
68 buttonLayout->addWidget(_buttonCancel);
69 buttonLayout->addWidget(_buttonOK);
70
71 mainLayout->addLayout(buttonLayout);
72}
73
74// Destructor
75////////////////////////////////////////////////////////////////////////////
76bncTableDlg::~bncTableDlg() {
77 if (_table) {
78 for (int ir = 0; ir < _table->rowCount(); ir++) {
79 for (int ic = 0; ic < _table->columnCount(); ic++) {
80 delete _table->item(ir,ic);
81 }
82 }
83 }
84}
85
86// Read Table from Caster
87////////////////////////////////////////////////////////////////////////////
88void bncTableDlg::slotGetTable() {
89
90 QUrl url;
91 url.setHost(_casterHostLineEdit->text());
92 url.setPort(_casterPortLineEdit->text().toInt());
93
94 // Send the Request
95 // ----------------
96 QString msg;
97 QTcpSocket* socket = bncGetThread::request(url, msg);
98
99 if (!socket) {
100 QMessageBox::warning(0, "BNC", msg);
101 return;
102 }
103
104 // Read Caster Response
105 // --------------------
106 QStringList allLines;
107 bool first = true;
108 while (true) {
109 if (socket->canReadLine()) {
110 QString line = socket->readLine();
111 if (first) {
112 first = false;
113 if (line.indexOf("SOURCETABLE 200 OK") != 0) {
114 QMessageBox::warning(0, "BNC", "Wrong Caster Response:\n" + line);
115 break;
116 }
117 }
118 else {
119 if (line.indexOf("ENDSOURCETABLE") == 0) {
120 break;
121 }
122 if (line.indexOf("STR") == 0) {
123 allLines.push_back(line);
124 }
125 }
126 }
127 else {
128 const int timeOut = 10*1000;
129 socket->waitForReadyRead(timeOut);
130 if (socket->bytesAvailable() > 0) {
131 continue;
132 }
133 else {
134 QMessageBox::warning(0, "BNC", "Data Timeout");
135 break;
136 }
137 }
138 }
139 delete socket;
140
141 static const QStringList labels = QString("mountpoint,identifier,format,"
142 "format-details,carrier,nav-system,network,country,latitude,longitude,"
143 "nmea,solution,generator,compression,authentication,fee,bitrate,"
144 "misc").split(",");
145
146 if (allLines.size() > 0) {
147 _table->setSelectionMode(QAbstractItemView::ExtendedSelection);
148 _table->setSelectionBehavior(QAbstractItemView::SelectRows);
149
150 QStringList hlp = allLines[0].split(";");
151 _table->setColumnCount(hlp.size()-1);
152 _table->setRowCount(allLines.size());
153
154 QListIterator<QString> it(allLines);
155 int nRow = -1;
156 while (it.hasNext()) {
157 QStringList columns = it.next().split(";");
158 ++nRow;
159 for (int ic = 0; ic < columns.size()-1; ic++) {
160 QTableWidgetItem* it = new QTableWidgetItem(columns[ic+1]);
161 it->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
162 _table->setItem(nRow, ic, it);
163 }
164 }
165 _table->sortItems(0);
166 _table->setHorizontalHeaderLabels(labels);
167 _table->setSortingEnabled(true);
168 }
169}
170
171// Accept slot
172////////////////////////////////////////////////////////////////////////////
173void bncTableDlg::accept() {
174
175 QSettings settings;
176 settings.setValue("casterHost", _casterHostLineEdit->text());
177 settings.setValue("casterPort", _casterPortLineEdit->text());
178 settings.setValue("casterUser", _casterUserLineEdit->text());
179 settings.setValue("casterPassword", _casterPasswordLineEdit->text());
180
181 QStringList* mountPoints = new QStringList;
182
183 if (_table) {
184 for (int ir = 0; ir < _table->rowCount(); ir++) {
185 QTableWidgetItem* item = _table->item(ir,0);
186 QString format = _table->item(ir,2)->text();
187 format.replace(" ", "_");
188 if (_table->isItemSelected(item)) {
189 QUrl url;
190 url.setUserName(_casterUserLineEdit->text());
191 url.setPassword(_casterPasswordLineEdit->text());
192 url.setHost(_casterHostLineEdit->text());
193 url.setPort(_casterPortLineEdit->text().toInt());
194 url.setPath(item->text());
195
196 mountPoints->push_back(url.toString() + " " + format);
197 }
198 }
199 }
200 emit newMountPoints(mountPoints);
201
202 QDialog::accept();
203}
Note: See TracBrowser for help on using the repository browser.