1 |
|
---|
2 | /* -------------------------------------------------------------------------
|
---|
3 | * Bernese NTRIP Client
|
---|
4 | * -------------------------------------------------------------------------
|
---|
5 | *
|
---|
6 | * Class: bncWindow
|
---|
7 | *
|
---|
8 | * Purpose: This class implements the main application window.
|
---|
9 | *
|
---|
10 | * Author: L. Mervart
|
---|
11 | *
|
---|
12 | * Created: 24-Dec-2005
|
---|
13 | *
|
---|
14 | * Changes:
|
---|
15 | *
|
---|
16 | * -----------------------------------------------------------------------*/
|
---|
17 |
|
---|
18 | #include "bncwindow.h"
|
---|
19 | #include "bncgetthread.h"
|
---|
20 | #include "bnctabledlg.h"
|
---|
21 |
|
---|
22 | using namespace std;
|
---|
23 |
|
---|
24 | // Constructor
|
---|
25 | ////////////////////////////////////////////////////////////////////////////
|
---|
26 | bncWindow::bncWindow() {
|
---|
27 |
|
---|
28 | setMinimumSize(600,400);
|
---|
29 |
|
---|
30 | // Create Actions
|
---|
31 | // --------------
|
---|
32 | _actAbout = new QAction(tr("&About"),this);
|
---|
33 | _actAbout->setEnabled(false);
|
---|
34 |
|
---|
35 | _actSaveOpt = new QAction(tr("&Save Options"),this);
|
---|
36 | connect(_actSaveOpt, SIGNAL(triggered()), SLOT(slotSaveOptions()));
|
---|
37 |
|
---|
38 | _actQuit = new QAction(tr("&Quit"),this);
|
---|
39 | connect(_actQuit, SIGNAL(triggered()), SLOT(close()));
|
---|
40 |
|
---|
41 | _actAddMountPoints = new QAction(tr("&Add Mount Points"),this);
|
---|
42 | connect(_actAddMountPoints, SIGNAL(triggered()), SLOT(slotAddMountPoints()));
|
---|
43 |
|
---|
44 | _actDeleteMountPoints = new QAction(tr("&Delete Mount Points"),this);
|
---|
45 | connect(_actDeleteMountPoints, SIGNAL(triggered()), SLOT(slotDeleteMountPoints()));
|
---|
46 |
|
---|
47 | _actGetData = new QAction(tr("&Get Data"),this);
|
---|
48 | connect(_actGetData, SIGNAL(triggered()), SLOT(slotGetData()));
|
---|
49 |
|
---|
50 | // Create Menus
|
---|
51 | // ------------
|
---|
52 | _menuFile = menuBar()->addMenu(tr("&File"));
|
---|
53 | _menuFile->addAction(_actSaveOpt);
|
---|
54 | _menuFile->addSeparator();
|
---|
55 | _menuFile->addAction(_actQuit);
|
---|
56 |
|
---|
57 | _menuHlp = menuBar()->addMenu(tr("&Help"));
|
---|
58 | _menuHlp->addAction(_actAbout);
|
---|
59 |
|
---|
60 | // Tool (Command) Bar
|
---|
61 | // ------------------
|
---|
62 | QToolBar* toolBar = new QToolBar;
|
---|
63 | addToolBar(Qt::BottomToolBarArea, toolBar);
|
---|
64 | toolBar->setMovable(false);
|
---|
65 | toolBar->addAction(_actAddMountPoints);
|
---|
66 | toolBar->addAction(_actDeleteMountPoints);
|
---|
67 | toolBar->addAction(_actGetData);
|
---|
68 |
|
---|
69 | // Canvas with Editable Fields
|
---|
70 | // ---------------------------
|
---|
71 | _canvas = new QWidget;
|
---|
72 | setCentralWidget(_canvas);
|
---|
73 |
|
---|
74 | QGridLayout* layout = new QGridLayout;
|
---|
75 | _canvas->setLayout(layout);
|
---|
76 |
|
---|
77 | _proxyHostLabel = new QLabel("proxy host");
|
---|
78 | _proxyPortLabel = new QLabel("proxy port");
|
---|
79 | _userLabel = new QLabel("user");
|
---|
80 | _passwordLabel = new QLabel("password");
|
---|
81 | _outFileLabel = new QLabel("output file");
|
---|
82 | _outPortLabel = new QLabel("output port");
|
---|
83 | _mountPointsLabel = new QLabel("mount points");
|
---|
84 |
|
---|
85 | QSettings settings;
|
---|
86 |
|
---|
87 | _proxyHostLineEdit = new QLineEdit(settings.value("proxyHost").toString());
|
---|
88 | _proxyPortLineEdit = new QLineEdit(settings.value("proxyPort").toString());
|
---|
89 | _userLineEdit = new QLineEdit(settings.value("user").toString());
|
---|
90 | _passwordLineEdit = new QLineEdit(settings.value("password").toString());
|
---|
91 | _passwordLineEdit->setEchoMode(QLineEdit::Password);
|
---|
92 | _outFileLineEdit = new QLineEdit(settings.value("outFile").toString());
|
---|
93 | _outPortLineEdit = new QLineEdit(settings.value("outPort").toString());
|
---|
94 | _mountPointsTable = new QTableWidget(0,2);
|
---|
95 | _mountPointsTable->setMaximumHeight(100);
|
---|
96 | _mountPointsTable->horizontalHeader()->hide();
|
---|
97 | _mountPointsTable->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
|
---|
98 | _mountPointsTable->verticalHeader()->hide();
|
---|
99 | _mountPointsTable->setGridStyle(Qt::NoPen);
|
---|
100 | _mountPointsTable->setSelectionMode(QAbstractItemView::ExtendedSelection);
|
---|
101 | _mountPointsTable->setSelectionBehavior(QAbstractItemView::SelectRows);
|
---|
102 | QListIterator<QString> it(settings.value("mountPoints").toStringList());
|
---|
103 | if (!it.hasNext()) {
|
---|
104 | _actGetData->setEnabled(false);
|
---|
105 | }
|
---|
106 | int iRow = 0;
|
---|
107 | while (it.hasNext()) {
|
---|
108 | QStringList hlp = it.next().split(" ");
|
---|
109 | QString mPoint = hlp[0];
|
---|
110 | QString format = hlp[1];
|
---|
111 | _mountPointsTable->insertRow(iRow);
|
---|
112 | _mountPointsTable->setItem(iRow, 0, new QTableWidgetItem(mPoint));
|
---|
113 | _mountPointsTable->setItem(iRow, 1, new QTableWidgetItem(format));
|
---|
114 | iRow++;
|
---|
115 | }
|
---|
116 |
|
---|
117 | layout->addWidget(_proxyHostLabel, 0, 0);
|
---|
118 | layout->addWidget(_proxyHostLineEdit, 0, 1);
|
---|
119 | layout->addWidget(_proxyPortLabel, 0, 2);
|
---|
120 | layout->addWidget(_proxyPortLineEdit, 0, 3);
|
---|
121 | layout->addWidget(_userLabel, 1, 0);
|
---|
122 | layout->addWidget(_userLineEdit, 1, 1);
|
---|
123 | layout->addWidget(_passwordLabel, 1, 2);
|
---|
124 | layout->addWidget(_passwordLineEdit, 1, 3);
|
---|
125 | layout->addWidget(_outFileLabel, 2, 0);
|
---|
126 | layout->addWidget(_outFileLineEdit, 2, 1);
|
---|
127 | layout->addWidget(_outPortLabel, 2, 2);
|
---|
128 | layout->addWidget(_outPortLineEdit, 2, 3);
|
---|
129 |
|
---|
130 | layout->addWidget(_mountPointsLabel, 3, 0);
|
---|
131 | layout->addWidget(_mountPointsTable, 3, 1, 1, 3);
|
---|
132 |
|
---|
133 | _bncCaster = 0;
|
---|
134 | }
|
---|
135 |
|
---|
136 | // Destructor
|
---|
137 | ////////////////////////////////////////////////////////////////////////////
|
---|
138 | bncWindow::~bncWindow() {
|
---|
139 | }
|
---|
140 |
|
---|
141 | // Retrieve Table
|
---|
142 | ////////////////////////////////////////////////////////////////////////////
|
---|
143 | void bncWindow::slotAddMountPoints() {
|
---|
144 | bncTableDlg* dlg = new bncTableDlg(this, _proxyHostLineEdit->text(),
|
---|
145 | _proxyPortLineEdit->text().toInt());
|
---|
146 | connect(dlg, SIGNAL(newMountPoints(QStringList*)),
|
---|
147 | this, SLOT(slotNewMountPoints(QStringList*)));
|
---|
148 | dlg->exec();
|
---|
149 | delete dlg;
|
---|
150 |
|
---|
151 | }
|
---|
152 |
|
---|
153 | // Delete Selected Mount Points
|
---|
154 | ////////////////////////////////////////////////////////////////////////////
|
---|
155 | void bncWindow::slotDeleteMountPoints() {
|
---|
156 | _mountPointsTable->clear();
|
---|
157 | _mountPointsTable->setRowCount(0);
|
---|
158 | }
|
---|
159 |
|
---|
160 | // New Mount Points Selected
|
---|
161 | ////////////////////////////////////////////////////////////////////////////
|
---|
162 | void bncWindow::slotNewMountPoints(QStringList* mountPoints) {
|
---|
163 | int iRow = 0;
|
---|
164 | QListIterator<QString> it(*mountPoints);
|
---|
165 | while (it.hasNext()) {
|
---|
166 | QStringList hlp = it.next().split(" ");
|
---|
167 | QString mPoint = hlp[0];
|
---|
168 | QString format = hlp[1];
|
---|
169 | _mountPointsTable->insertRow(iRow);
|
---|
170 | _mountPointsTable->setItem(iRow, 0, new QTableWidgetItem(mPoint));
|
---|
171 | _mountPointsTable->setItem(iRow, 1, new QTableWidgetItem(format));
|
---|
172 | iRow++;
|
---|
173 | }
|
---|
174 | if (mountPoints->count() > 0) {
|
---|
175 | _actGetData->setEnabled(true);
|
---|
176 | }
|
---|
177 | delete mountPoints;
|
---|
178 | }
|
---|
179 |
|
---|
180 | // Save Options
|
---|
181 | ////////////////////////////////////////////////////////////////////////////
|
---|
182 | void bncWindow::slotSaveOptions() {
|
---|
183 | QSettings settings;
|
---|
184 | settings.setValue("proxyHost", _proxyHostLineEdit->text());
|
---|
185 | settings.setValue("proxyPort", _proxyPortLineEdit->text());
|
---|
186 | settings.setValue("user", _userLineEdit->text());
|
---|
187 | settings.setValue("password", _passwordLineEdit->text());
|
---|
188 | settings.setValue("outFile", _outFileLineEdit->text());
|
---|
189 | settings.setValue("outPort", _outPortLineEdit->text());
|
---|
190 | QStringList mountPoints;
|
---|
191 | for (int iRow = 0; iRow < _mountPointsTable->rowCount(); iRow++) {
|
---|
192 | mountPoints.append(_mountPointsTable->item(iRow, 0)->text() +
|
---|
193 | " " + _mountPointsTable->item(iRow, 1)->text());
|
---|
194 | }
|
---|
195 | settings.setValue("mountPoints", mountPoints);
|
---|
196 | }
|
---|
197 |
|
---|
198 | // All get slots terminated
|
---|
199 | ////////////////////////////////////////////////////////////////////////////
|
---|
200 | void bncWindow::slotGetThreadErrors() {
|
---|
201 | QMessageBox::warning(0, "BNC", "All Get Threads Terminated");
|
---|
202 | _actAddMountPoints->setEnabled(true);
|
---|
203 | _actDeleteMountPoints->setEnabled(true);
|
---|
204 | _actGetData->setEnabled(true);
|
---|
205 | }
|
---|
206 |
|
---|
207 | // Retrieve Data
|
---|
208 | ////////////////////////////////////////////////////////////////////////////
|
---|
209 | void bncWindow::slotGetData() {
|
---|
210 | _actAddMountPoints->setEnabled(false);
|
---|
211 | _actDeleteMountPoints->setEnabled(false);
|
---|
212 | _actGetData->setEnabled(false);
|
---|
213 |
|
---|
214 | QString proxyHost = _proxyHostLineEdit->text();
|
---|
215 | int proxyPort = _proxyPortLineEdit->text().toInt();
|
---|
216 | QByteArray user = _userLineEdit->text().toAscii();
|
---|
217 | QByteArray password = _passwordLineEdit->text().toAscii();
|
---|
218 |
|
---|
219 | _bncCaster = new bncCaster(_outFileLineEdit->text(),
|
---|
220 | _outPortLineEdit->text().toInt());
|
---|
221 |
|
---|
222 | connect(_bncCaster, SIGNAL(getThreadErrors()),
|
---|
223 | this, SLOT(slotGetThreadErrors()));
|
---|
224 |
|
---|
225 | _bncCaster->start();
|
---|
226 |
|
---|
227 | for (int iRow = 0; iRow < _mountPointsTable->rowCount(); iRow++) {
|
---|
228 | QUrl url(_mountPointsTable->item(iRow, 0)->text());
|
---|
229 | QByteArray mountPoint = url.path().mid(1).toAscii();
|
---|
230 | QByteArray format = _mountPointsTable->item(iRow, 1)->text().toAscii();
|
---|
231 |
|
---|
232 | bncGetThread* getThread = new bncGetThread(url.host(), url.port(),
|
---|
233 | proxyHost, proxyPort,
|
---|
234 | mountPoint, user, password,
|
---|
235 | format);
|
---|
236 | _bncCaster->addGetThread(getThread);
|
---|
237 |
|
---|
238 | getThread->start();
|
---|
239 | }
|
---|
240 | }
|
---|