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

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

* empty log message *

File size: 6.1 KB
Line 
1
2/* -------------------------------------------------------------------------
3 * Bernese 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, const QString& proxyHost,
24 int proxyPort) : QDialog(parent) {
25
26 _proxyHost = proxyHost;
27 _proxyPort = proxyPort;
28
29 setMinimumSize(600,400);
30
31 QVBoxLayout* mainLayout = new QVBoxLayout(this);
32
33 _casterHostLabel = new QLabel(tr("caster host"));
34 _casterPortLabel = new QLabel(tr("caster port"));
35 _casterUserLabel = new QLabel(tr("user"));
36 _casterPasswordLabel = new QLabel(tr("password"));
37 QSettings settings;
38 _casterHostLineEdit = new QLineEdit(settings.value("casterHost").toString());
39 int ww = QFontMetrics(_casterHostLineEdit->font()).width('w');
40 _casterHostLineEdit->setMaximumWidth(18*ww);
41 _casterPortLineEdit = new QLineEdit(settings.value("casterPort").toString());
42 _casterPortLineEdit->setMaximumWidth(9*ww);
43 _casterUserLineEdit = new QLineEdit(settings.value("casterUser").toString());
44 _casterUserLineEdit->setMaximumWidth(9*ww);
45 _casterPasswordLineEdit = new QLineEdit(settings.value("casterPassword").toString());
46 _casterPasswordLineEdit->setMaximumWidth(9*ww);
47 _casterPasswordLineEdit->setEchoMode(QLineEdit::Password);
48
49 QGridLayout* editLayout = new QGridLayout;
50 editLayout->addWidget(_casterHostLabel, 0, 0);
51 editLayout->addWidget(_casterHostLineEdit, 0, 1);
52 editLayout->addWidget(_casterPortLabel, 0, 2);
53 editLayout->addWidget(_casterPortLineEdit, 0, 3);
54 editLayout->addWidget(_casterUserLabel, 1, 0);
55 editLayout->addWidget(_casterUserLineEdit, 1, 1);
56 editLayout->addWidget(_casterPasswordLabel, 1, 2);
57 editLayout->addWidget(_casterPasswordLineEdit, 1, 3);
58
59 mainLayout->addLayout(editLayout);
60
61 _table = new QTableWidget(this);
62 mainLayout->addWidget(_table);
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->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 from Caster
95////////////////////////////////////////////////////////////////////////////
96void bncTableDlg::slotGetTable() {
97
98 QUrl url;
99 url.setHost(_casterHostLineEdit->text());
100 url.setPort(_casterPortLineEdit->text().toInt());
101
102 // Send the Request
103 // ----------------
104 QString msg;
105 QTcpSocket* socket = bncGetThread::request(url, msg);
106
107 if (!socket) {
108 QMessageBox::warning(0, "BNC", msg);
109 return;
110 }
111
112 // Read Caster Response
113 // --------------------
114 QStringList allLines;
115 bool first = true;
116 while (true) {
117 if (socket->canReadLine()) {
118 QString line = socket->readLine();
119 if (first) {
120 first = false;
121 if (line.indexOf("SOURCETABLE 200 OK") != 0) {
122 QMessageBox::warning(0, "BNC", "Wrong Caster Response:\n" + line);
123 break;
124 }
125 }
126 else {
127 if (line.indexOf("ENDSOURCETABLE") == 0) {
128 break;
129 }
130 if (line.indexOf("STR") == 0) {
131 allLines.push_back(line);
132 }
133 }
134 }
135 else {
136 const int timeOut = 10*1000;
137 socket->waitForReadyRead(timeOut);
138 if (socket->bytesAvailable() > 0) {
139 continue;
140 }
141 else {
142 QMessageBox::warning(0, "BNC", "Data Timeout");
143 break;
144 }
145 }
146 }
147 delete socket;
148
149 if (allLines.size() > 0) {
150 _table->setSelectionMode(QAbstractItemView::ExtendedSelection);
151 _table->setSelectionBehavior(QAbstractItemView::SelectRows);
152
153 QStringList hlp = allLines[0].split(";");
154 _table->setColumnCount(hlp.size()-1);
155 _table->setRowCount(allLines.size());
156
157 QListIterator<QString> it(allLines);
158 int nRow = -1;
159 while (it.hasNext()) {
160 QStringList columns = it.next().split(";");
161 ++nRow;
162 for (int ic = 0; ic < columns.size()-1; ic++) {
163 _table->setItem(nRow, ic, new QTableWidgetItem(columns[ic+1]));
164 }
165 }
166 _table->sortItems(0);
167 }
168}
169
170// Accept slot
171////////////////////////////////////////////////////////////////////////////
172void bncTableDlg::accept() {
173
174 QSettings settings;
175 settings.setValue("casterHost", _casterHostLineEdit->text());
176 settings.setValue("casterPort", _casterPortLineEdit->text());
177 settings.setValue("casterUser", _casterUserLineEdit->text());
178 settings.setValue("casterPassword", _casterPasswordLineEdit->text());
179
180 QStringList* mountPoints = new QStringList;
181
182 if (_table) {
183 for (int ir = 0; ir < _table->rowCount(); ir++) {
184 QTableWidgetItem* item = _table->item(ir,0);
185 QString format = _table->item(ir,2)->text();
186 format.replace(" ", "_");
187 if (_table->isItemSelected(item)) {
188 QUrl url;
189 url.setUserName(_casterUserLineEdit->text());
190 url.setPassword(_casterPasswordLineEdit->text());
191 url.setHost(_casterHostLineEdit->text());
192 url.setPort(_casterPortLineEdit->text().toInt());
193 url.setPath(item->text());
194
195 mountPoints->push_back(url.toString() + " " + format);
196 }
197 }
198 }
199 emit newMountPoints(mountPoints);
200
201 QDialog::accept();
202}
Note: See TracBrowser for help on using the repository browser.