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

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

* empty log message *

File size: 5.2 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 QSettings settings;
36 _casterHostLineEdit = new QLineEdit(settings.value("casterHost").toString());
37 _casterPortLineEdit = new QLineEdit(settings.value("casterPort").toString());
38
39 QHBoxLayout* editLayout = new QHBoxLayout;
40 editLayout->addWidget(_casterHostLabel);
41 editLayout->addWidget(_casterHostLineEdit);
42 editLayout->addWidget(_casterPortLabel);
43 editLayout->addWidget(_casterPortLineEdit);
44 mainLayout->addLayout(editLayout);
45
46 _table = new QTableWidget(this);
47 mainLayout->addWidget(_table);
48
49 _buttonGet = new QPushButton(tr("Get Table"), this);
50 connect(_buttonGet, SIGNAL(clicked()), this, SLOT(slotGetTable()));
51
52 _buttonCancel = new QPushButton(tr("Cancel"), this);
53 connect(_buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
54
55 _buttonOK = new QPushButton(tr("OK"), this);
56 connect(_buttonOK, SIGNAL(clicked()), this, SLOT(accept()));
57
58 QHBoxLayout* buttonLayout = new QHBoxLayout;
59 buttonLayout->addStretch(1);
60 buttonLayout->addWidget(_buttonGet);
61 buttonLayout->addWidget(_buttonCancel);
62 buttonLayout->addWidget(_buttonOK);
63
64 mainLayout->addLayout(buttonLayout);
65}
66
67// Destructor
68////////////////////////////////////////////////////////////////////////////
69bncTableDlg::~bncTableDlg() {
70 if (_table) {
71 for (int ir = 0; ir < _table->rowCount(); ir++) {
72 for (int ic = 0; ic < _table->columnCount(); ic++) {
73 delete _table->item(ir,ic);
74 }
75 }
76 }
77}
78
79// Read Table from Caster
80////////////////////////////////////////////////////////////////////////////
81void bncTableDlg::slotGetTable() {
82
83 QString host = _casterHostLineEdit->text();
84 int port = _casterPortLineEdit->text().toInt();
85 QByteArray mountPoint = "/";
86 QByteArray user;
87 QByteArray password;
88
89 // Send the Request
90 // ----------------
91 QString msg;
92 QTcpSocket* socket = bncGetThread::request(host, port, _proxyHost,
93 _proxyPort, mountPoint,
94 user, password, msg);
95 if (!socket) {
96 QMessageBox::warning(0, "BNC", msg);
97 return;
98 }
99
100 // Read Caster Response
101 // --------------------
102 QStringList allLines;
103 bool first = true;
104 while (true) {
105 if (socket->canReadLine()) {
106 QString line = socket->readLine();
107 if (first) {
108 first = false;
109 if (line.indexOf("SOURCETABLE 200 OK") != 0) {
110 QMessageBox::warning(0, "BNC", "Wrong Caster Response:\n" + line);
111 break;
112 }
113 }
114 else {
115 if (line.indexOf("ENDSOURCETABLE") == 0) {
116 break;
117 }
118 if (line.indexOf("STR") == 0) {
119 allLines.push_back(line);
120 }
121 }
122 }
123 else {
124 const int timeOut = 10*1000;
125 socket->waitForReadyRead(timeOut);
126 if (socket->bytesAvailable() > 0) {
127 continue;
128 }
129 else {
130 QMessageBox::warning(0, "BNC", "Data Timeout");
131 break;
132 }
133 }
134 }
135 delete socket;
136
137 if (allLines.size() > 0) {
138 _table->setSelectionMode(QAbstractItemView::ExtendedSelection);
139 _table->setSelectionBehavior(QAbstractItemView::SelectRows);
140
141 QStringList hlp = allLines[0].split(";");
142 _table->setColumnCount(hlp.size()-1);
143 _table->setRowCount(allLines.size());
144
145 QListIterator<QString> it(allLines);
146 int nRow = -1;
147 while (it.hasNext()) {
148 QStringList columns = it.next().split(";");
149 ++nRow;
150 for (int ic = 0; ic < columns.size()-1; ic++) {
151 _table->setItem(nRow, ic, new QTableWidgetItem(columns[ic+1]));
152 }
153 }
154 }
155}
156
157// Accept slot
158////////////////////////////////////////////////////////////////////////////
159void bncTableDlg::accept() {
160
161 QSettings settings;
162 settings.setValue("casterHost", _casterHostLineEdit->text());
163 settings.setValue("casterPort", _casterPortLineEdit->text());
164
165 QStringList* mountPoints = new QStringList;
166
167 if (_table) {
168 for (int ir = 0; ir < _table->rowCount(); ir++) {
169 QTableWidgetItem* item = _table->item(ir,0);
170 QString format = _table->item(ir,2)->text();
171 format.replace(" ", "_");
172 if (_table->isItemSelected(item)) {
173 QUrl url;
174 url.setHost(_casterHostLineEdit->text());
175 url.setPort(_casterPortLineEdit->text().toInt());
176 url.setPath(item->text());
177
178 mountPoints->push_back(url.toString() + " " + format);
179 }
180 }
181 }
182 emit newMountPoints(mountPoints);
183
184 QDialog::accept();
185}
Note: See TracBrowser for help on using the repository browser.