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,1);
|
---|
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 | QString mPoint = it.next();
|
---|
109 | _mountPointsTable->insertRow(iRow);
|
---|
110 | _mountPointsTable->setItem(iRow, 0, new QTableWidgetItem(mPoint));
|
---|
111 | iRow++;
|
---|
112 | }
|
---|
113 |
|
---|
114 | layout->addWidget(_proxyHostLabel, 0, 0);
|
---|
115 | layout->addWidget(_proxyHostLineEdit, 0, 1);
|
---|
116 | layout->addWidget(_proxyPortLabel, 0, 2);
|
---|
117 | layout->addWidget(_proxyPortLineEdit, 0, 3);
|
---|
118 | layout->addWidget(_userLabel, 1, 0);
|
---|
119 | layout->addWidget(_userLineEdit, 1, 1);
|
---|
120 | layout->addWidget(_passwordLabel, 1, 2);
|
---|
121 | layout->addWidget(_passwordLineEdit, 1, 3);
|
---|
122 | layout->addWidget(_outFileLabel, 2, 0);
|
---|
123 | layout->addWidget(_outFileLineEdit, 2, 1);
|
---|
124 | layout->addWidget(_outPortLabel, 2, 2);
|
---|
125 | layout->addWidget(_outPortLineEdit, 2, 3);
|
---|
126 |
|
---|
127 | layout->addWidget(_mountPointsLabel, 3, 0);
|
---|
128 | layout->addWidget(_mountPointsTable, 3, 1, 1, 3);
|
---|
129 |
|
---|
130 | _bncCaster = 0;
|
---|
131 | }
|
---|
132 |
|
---|
133 | // Destructor
|
---|
134 | ////////////////////////////////////////////////////////////////////////////
|
---|
135 | bncWindow::~bncWindow() {
|
---|
136 | }
|
---|
137 |
|
---|
138 | // Retrieve Table
|
---|
139 | ////////////////////////////////////////////////////////////////////////////
|
---|
140 | void bncWindow::slotAddMountPoints() {
|
---|
141 | bncTableDlg* dlg = new bncTableDlg(this, _proxyHostLineEdit->text(),
|
---|
142 | _proxyPortLineEdit->text().toInt());
|
---|
143 | connect(dlg, SIGNAL(newMountPoints(QStringList*)),
|
---|
144 | this, SLOT(slotNewMountPoints(QStringList*)));
|
---|
145 | dlg->exec();
|
---|
146 | delete dlg;
|
---|
147 |
|
---|
148 | }
|
---|
149 |
|
---|
150 | // Delete Selected Mount Points
|
---|
151 | ////////////////////////////////////////////////////////////////////////////
|
---|
152 | void bncWindow::slotDeleteMountPoints() {
|
---|
153 | _mountPointsTable->clear();
|
---|
154 | _mountPointsTable->setRowCount(0);
|
---|
155 | }
|
---|
156 |
|
---|
157 | // New Mount Points Selected
|
---|
158 | ////////////////////////////////////////////////////////////////////////////
|
---|
159 | void bncWindow::slotNewMountPoints(QStringList* mountPoints) {
|
---|
160 | int iRow = 0;
|
---|
161 | QListIterator<QString> it(*mountPoints);
|
---|
162 | while (it.hasNext()) {
|
---|
163 | QString mPoint = it.next();
|
---|
164 | _mountPointsTable->insertRow(iRow);
|
---|
165 | _mountPointsTable->setItem(iRow, 0, new QTableWidgetItem(mPoint));
|
---|
166 | iRow++;
|
---|
167 | }
|
---|
168 | if (mountPoints->count() > 0) {
|
---|
169 | _actGetData->setEnabled(true);
|
---|
170 | }
|
---|
171 | delete mountPoints;
|
---|
172 | }
|
---|
173 |
|
---|
174 | // Save Options
|
---|
175 | ////////////////////////////////////////////////////////////////////////////
|
---|
176 | void bncWindow::slotSaveOptions() {
|
---|
177 | QSettings settings;
|
---|
178 | settings.setValue("proxyHost", _proxyHostLineEdit->text());
|
---|
179 | settings.setValue("proxyPort", _proxyPortLineEdit->text());
|
---|
180 | settings.setValue("user", _userLineEdit->text());
|
---|
181 | settings.setValue("password", _passwordLineEdit->text());
|
---|
182 | settings.setValue("outFile", _outFileLineEdit->text());
|
---|
183 | settings.setValue("outPort", _outPortLineEdit->text());
|
---|
184 | QStringList mountPoints;
|
---|
185 | for (int iRow = 0; iRow < _mountPointsTable->rowCount(); iRow++) {
|
---|
186 | mountPoints.append(_mountPointsTable->item(iRow, 0)->text());
|
---|
187 | }
|
---|
188 | settings.setValue("mountPoints", mountPoints);
|
---|
189 | }
|
---|
190 |
|
---|
191 | // All get slots terminated
|
---|
192 | ////////////////////////////////////////////////////////////////////////////
|
---|
193 | void bncWindow::slotGetThreadErrors() {
|
---|
194 | QMessageBox::warning(0, "BNC", "All Get Threads Terminated");
|
---|
195 | _actAddMountPoints->setEnabled(true);
|
---|
196 | _actDeleteMountPoints->setEnabled(true);
|
---|
197 | _actGetData->setEnabled(true);
|
---|
198 | }
|
---|
199 |
|
---|
200 | // Retrieve Data
|
---|
201 | ////////////////////////////////////////////////////////////////////////////
|
---|
202 | void bncWindow::slotGetData() {
|
---|
203 | _actAddMountPoints->setEnabled(false);
|
---|
204 | _actDeleteMountPoints->setEnabled(false);
|
---|
205 | _actGetData->setEnabled(false);
|
---|
206 |
|
---|
207 | QString proxyHost = _proxyHostLineEdit->text();
|
---|
208 | int proxyPort = _proxyPortLineEdit->text().toInt();
|
---|
209 | QByteArray user = _userLineEdit->text().toAscii();
|
---|
210 | QByteArray password = _passwordLineEdit->text().toAscii();
|
---|
211 |
|
---|
212 | _bncCaster = new bncCaster(_outFileLineEdit->text(),
|
---|
213 | _outPortLineEdit->text().toInt());
|
---|
214 |
|
---|
215 | connect(_bncCaster, SIGNAL(getThreadErrors()),
|
---|
216 | this, SLOT(slotGetThreadErrors()));
|
---|
217 |
|
---|
218 | _bncCaster->start();
|
---|
219 |
|
---|
220 | for (int iRow = 0; iRow < _mountPointsTable->rowCount(); iRow++) {
|
---|
221 | QUrl url(_mountPointsTable->item(iRow, 0)->text());
|
---|
222 | QByteArray mountPoint = url.path().mid(1).toAscii();
|
---|
223 |
|
---|
224 | bncGetThread* getThread = new bncGetThread(url.host(), url.port(),
|
---|
225 | proxyHost, proxyPort,
|
---|
226 | mountPoint, user, password);
|
---|
227 | _bncCaster->addGetThread(getThread);
|
---|
228 |
|
---|
229 | getThread->start();
|
---|
230 | }
|
---|
231 | }
|
---|