[35] | 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 |
|
---|
[83] | 28 | setMinimumSize(400,600);
|
---|
[35] | 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()));
|
---|
[83] | 46 | _actDeleteMountPoints->setEnabled(false);
|
---|
[35] | 47 |
|
---|
| 48 | _actGetData = new QAction(tr("&Get Data"),this);
|
---|
| 49 | connect(_actGetData, SIGNAL(triggered()), SLOT(slotGetData()));
|
---|
| 50 |
|
---|
| 51 | // Create Menus
|
---|
| 52 | // ------------
|
---|
| 53 | _menuFile = menuBar()->addMenu(tr("&File"));
|
---|
| 54 | _menuFile->addAction(_actSaveOpt);
|
---|
| 55 | _menuFile->addSeparator();
|
---|
| 56 | _menuFile->addAction(_actQuit);
|
---|
| 57 |
|
---|
| 58 | _menuHlp = menuBar()->addMenu(tr("&Help"));
|
---|
| 59 | _menuHlp->addAction(_actAbout);
|
---|
| 60 |
|
---|
| 61 | // Tool (Command) Bar
|
---|
| 62 | // ------------------
|
---|
| 63 | QToolBar* toolBar = new QToolBar;
|
---|
| 64 | addToolBar(Qt::BottomToolBarArea, toolBar);
|
---|
| 65 | toolBar->setMovable(false);
|
---|
| 66 | toolBar->addAction(_actAddMountPoints);
|
---|
| 67 | toolBar->addAction(_actDeleteMountPoints);
|
---|
| 68 | toolBar->addAction(_actGetData);
|
---|
| 69 |
|
---|
| 70 | // Canvas with Editable Fields
|
---|
| 71 | // ---------------------------
|
---|
| 72 | _canvas = new QWidget;
|
---|
| 73 | setCentralWidget(_canvas);
|
---|
| 74 |
|
---|
| 75 | QGridLayout* layout = new QGridLayout;
|
---|
| 76 | _canvas->setLayout(layout);
|
---|
| 77 |
|
---|
[83] | 78 | _userLabel = new QLabel("user");
|
---|
| 79 | _passwordLabel = new QLabel("password");
|
---|
[35] | 80 | _proxyHostLabel = new QLabel("proxy host");
|
---|
| 81 | _proxyPortLabel = new QLabel("proxy port");
|
---|
[83] | 82 | _outFileLabel = new QLabel("ASCII output file (full path)");
|
---|
| 83 | _outPortLabel = new QLabel("port for binary output");
|
---|
| 84 | _rnxPathLabel = new QLabel("RINEX path");
|
---|
| 85 | _rnxSkelLabel = new QLabel("RINEX skeleton extension");
|
---|
| 86 | _rnxIntrLabel = new QLabel("RINEX file interval");
|
---|
[35] | 87 | _mountPointsLabel = new QLabel("mount points");
|
---|
[83] | 88 | _logLabel = new QLabel("log");
|
---|
[35] | 89 |
|
---|
| 90 | QSettings settings;
|
---|
| 91 |
|
---|
| 92 | _proxyHostLineEdit = new QLineEdit(settings.value("proxyHost").toString());
|
---|
[83] | 93 | int ww = QFontMetrics(_proxyHostLineEdit->font()).width('w');
|
---|
| 94 | _proxyHostLineEdit->setMaximumWidth(12*ww);
|
---|
[35] | 95 | _proxyPortLineEdit = new QLineEdit(settings.value("proxyPort").toString());
|
---|
[83] | 96 | _proxyPortLineEdit->setMaximumWidth(9*ww);
|
---|
[35] | 97 | _userLineEdit = new QLineEdit(settings.value("user").toString());
|
---|
[83] | 98 | _userLineEdit->setMaximumWidth(9*ww);
|
---|
[35] | 99 | _passwordLineEdit = new QLineEdit(settings.value("password").toString());
|
---|
[83] | 100 | _passwordLineEdit->setMaximumWidth(9*ww);
|
---|
[35] | 101 | _passwordLineEdit->setEchoMode(QLineEdit::Password);
|
---|
| 102 | _outFileLineEdit = new QLineEdit(settings.value("outFile").toString());
|
---|
| 103 | _outPortLineEdit = new QLineEdit(settings.value("outPort").toString());
|
---|
[83] | 104 | _outPortLineEdit->setMaximumWidth(9*ww);
|
---|
| 105 | _rnxPathLineEdit = new QLineEdit(settings.value("rnxPath").toString());
|
---|
| 106 | _rnxSkelLineEdit = new QLineEdit(settings.value("rnxSkel").toString());
|
---|
| 107 | _rnxSkelLineEdit->setMaximumWidth(5*ww);
|
---|
| 108 | _rnxIntrSpinBox = new QSpinBox();
|
---|
| 109 | _rnxIntrSpinBox->setMaximumWidth(12*ww);
|
---|
| 110 | _rnxIntrSpinBox->setValue(settings.value("rnxIntr").toInt());
|
---|
| 111 | _rnxIntrSpinBox->setSuffix(" hour");
|
---|
| 112 | _rnxIntrSpinBox->setRange(1,24);
|
---|
| 113 | _rnxIntrSpinBox->setSingleStep(23);
|
---|
[59] | 114 | _mountPointsTable = new QTableWidget(0,2);
|
---|
[83] | 115 | _mountPointsTable->setMaximumHeight(140);
|
---|
| 116 | _mountPointsTable->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
|
---|
[35] | 117 | _mountPointsTable->horizontalHeader()->hide();
|
---|
| 118 | _mountPointsTable->verticalHeader()->hide();
|
---|
| 119 | _mountPointsTable->setGridStyle(Qt::NoPen);
|
---|
| 120 | _mountPointsTable->setSelectionMode(QAbstractItemView::ExtendedSelection);
|
---|
| 121 | _mountPointsTable->setSelectionBehavior(QAbstractItemView::SelectRows);
|
---|
| 122 | QListIterator<QString> it(settings.value("mountPoints").toStringList());
|
---|
| 123 | if (!it.hasNext()) {
|
---|
| 124 | _actGetData->setEnabled(false);
|
---|
| 125 | }
|
---|
| 126 | int iRow = 0;
|
---|
| 127 | while (it.hasNext()) {
|
---|
[59] | 128 | QStringList hlp = it.next().split(" ");
|
---|
[83] | 129 | if (hlp.size() <= 1) continue;
|
---|
[59] | 130 | QString mPoint = hlp[0];
|
---|
| 131 | QString format = hlp[1];
|
---|
[35] | 132 | _mountPointsTable->insertRow(iRow);
|
---|
| 133 | _mountPointsTable->setItem(iRow, 0, new QTableWidgetItem(mPoint));
|
---|
[59] | 134 | _mountPointsTable->setItem(iRow, 1, new QTableWidgetItem(format));
|
---|
[35] | 135 | iRow++;
|
---|
| 136 | }
|
---|
[83] | 137 | _mountPointsTable->sortItems(0);
|
---|
[35] | 138 |
|
---|
[83] | 139 | connect(_mountPointsTable, SIGNAL(itemSelectionChanged()),
|
---|
| 140 | SLOT(slotSelectionChanged()));
|
---|
[35] | 141 |
|
---|
[83] | 142 | _log = new QTextEdit();
|
---|
| 143 | _log->setMaximumHeight(120);
|
---|
| 144 | _log->setReadOnly(true);
|
---|
[35] | 145 |
|
---|
[83] | 146 | layout->addWidget(_userLabel, 0, 0);
|
---|
| 147 | layout->addWidget(_userLineEdit, 0, 1);
|
---|
| 148 | layout->addWidget(_passwordLabel, 0, 2);
|
---|
| 149 | layout->addWidget(_passwordLineEdit, 0, 3);
|
---|
| 150 | layout->addWidget(_proxyHostLabel, 1, 0);
|
---|
| 151 | layout->addWidget(_proxyHostLineEdit, 1, 1);
|
---|
| 152 | layout->addWidget(_proxyPortLabel, 1, 2);
|
---|
| 153 | layout->addWidget(_proxyPortLineEdit, 1, 3);
|
---|
| 154 | layout->addWidget(_outFileLabel, 2, 1);
|
---|
| 155 | layout->addWidget(_outFileLineEdit, 2, 2, 1, 2);
|
---|
| 156 | layout->addWidget(_outPortLabel, 3, 1);
|
---|
| 157 | layout->addWidget(_outPortLineEdit, 3, 2);
|
---|
| 158 | layout->addWidget(_rnxPathLabel, 4, 1);
|
---|
| 159 | layout->addWidget(_rnxPathLineEdit, 4, 2, 1, 2);
|
---|
| 160 | layout->addWidget(_rnxSkelLabel, 5, 1);
|
---|
| 161 | layout->addWidget(_rnxSkelLineEdit, 5, 2);
|
---|
| 162 | layout->addWidget(_rnxIntrLabel, 6, 1);
|
---|
| 163 | layout->addWidget(_rnxIntrSpinBox, 6, 2);
|
---|
| 164 | layout->addWidget(_mountPointsLabel, 7, 0);
|
---|
| 165 | layout->addWidget(_mountPointsTable, 7, 1, 1, 3);
|
---|
| 166 | layout->addWidget(_logLabel, 8, 0);
|
---|
| 167 | layout->addWidget(_log, 8, 1, 1, 3);
|
---|
| 168 |
|
---|
[35] | 169 | _bncCaster = 0;
|
---|
| 170 | }
|
---|
| 171 |
|
---|
| 172 | // Destructor
|
---|
| 173 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 174 | bncWindow::~bncWindow() {
|
---|
| 175 | }
|
---|
| 176 |
|
---|
| 177 | // Retrieve Table
|
---|
| 178 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 179 | void bncWindow::slotAddMountPoints() {
|
---|
| 180 | bncTableDlg* dlg = new bncTableDlg(this, _proxyHostLineEdit->text(),
|
---|
| 181 | _proxyPortLineEdit->text().toInt());
|
---|
[83] | 182 | dlg->move(this->pos().x()+50, this->pos().y()+50);
|
---|
[35] | 183 | connect(dlg, SIGNAL(newMountPoints(QStringList*)),
|
---|
| 184 | this, SLOT(slotNewMountPoints(QStringList*)));
|
---|
| 185 | dlg->exec();
|
---|
| 186 | delete dlg;
|
---|
| 187 |
|
---|
| 188 | }
|
---|
| 189 |
|
---|
| 190 | // Delete Selected Mount Points
|
---|
| 191 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 192 | void bncWindow::slotDeleteMountPoints() {
|
---|
[83] | 193 | while(1) {
|
---|
| 194 | bool itemRemoved = false;
|
---|
| 195 | for (int iRow = 0; iRow < _mountPointsTable->rowCount(); iRow++) {
|
---|
| 196 | if (_mountPointsTable->isItemSelected(_mountPointsTable->item(iRow,0))) {
|
---|
| 197 | _mountPointsTable->removeRow(iRow);
|
---|
| 198 | itemRemoved = true;
|
---|
| 199 | break;
|
---|
| 200 | }
|
---|
| 201 | }
|
---|
| 202 | if (!itemRemoved) {
|
---|
| 203 | break;
|
---|
| 204 | }
|
---|
| 205 | }
|
---|
| 206 | _actDeleteMountPoints->setEnabled(false);
|
---|
[35] | 207 | }
|
---|
| 208 |
|
---|
| 209 | // New Mount Points Selected
|
---|
| 210 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 211 | void bncWindow::slotNewMountPoints(QStringList* mountPoints) {
|
---|
| 212 | int iRow = 0;
|
---|
| 213 | QListIterator<QString> it(*mountPoints);
|
---|
| 214 | while (it.hasNext()) {
|
---|
[59] | 215 | QStringList hlp = it.next().split(" ");
|
---|
| 216 | QString mPoint = hlp[0];
|
---|
| 217 | QString format = hlp[1];
|
---|
[35] | 218 | _mountPointsTable->insertRow(iRow);
|
---|
| 219 | _mountPointsTable->setItem(iRow, 0, new QTableWidgetItem(mPoint));
|
---|
[59] | 220 | _mountPointsTable->setItem(iRow, 1, new QTableWidgetItem(format));
|
---|
[35] | 221 | iRow++;
|
---|
| 222 | }
|
---|
[83] | 223 | _mountPointsTable->sortItems(0);
|
---|
[35] | 224 | if (mountPoints->count() > 0) {
|
---|
| 225 | _actGetData->setEnabled(true);
|
---|
| 226 | }
|
---|
| 227 | delete mountPoints;
|
---|
| 228 | }
|
---|
| 229 |
|
---|
| 230 | // Save Options
|
---|
| 231 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 232 | void bncWindow::slotSaveOptions() {
|
---|
| 233 | QSettings settings;
|
---|
| 234 | settings.setValue("proxyHost", _proxyHostLineEdit->text());
|
---|
| 235 | settings.setValue("proxyPort", _proxyPortLineEdit->text());
|
---|
| 236 | settings.setValue("user", _userLineEdit->text());
|
---|
| 237 | settings.setValue("password", _passwordLineEdit->text());
|
---|
| 238 | settings.setValue("outFile", _outFileLineEdit->text());
|
---|
| 239 | settings.setValue("outPort", _outPortLineEdit->text());
|
---|
[83] | 240 | settings.setValue("rnxPath", _rnxPathLineEdit->text());
|
---|
| 241 | settings.setValue("rnxIntr", _rnxIntrSpinBox->value());
|
---|
| 242 | settings.setValue("rnxSkel", _rnxSkelLineEdit->text());
|
---|
[35] | 243 | QStringList mountPoints;
|
---|
| 244 | for (int iRow = 0; iRow < _mountPointsTable->rowCount(); iRow++) {
|
---|
[59] | 245 | mountPoints.append(_mountPointsTable->item(iRow, 0)->text() +
|
---|
| 246 | " " + _mountPointsTable->item(iRow, 1)->text());
|
---|
[35] | 247 | }
|
---|
| 248 | settings.setValue("mountPoints", mountPoints);
|
---|
| 249 | }
|
---|
| 250 |
|
---|
| 251 | // All get slots terminated
|
---|
| 252 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 253 | void bncWindow::slotGetThreadErrors() {
|
---|
[83] | 254 | slotMessage("All Get Threads Terminated");
|
---|
[35] | 255 | _actAddMountPoints->setEnabled(true);
|
---|
| 256 | _actGetData->setEnabled(true);
|
---|
| 257 | }
|
---|
| 258 |
|
---|
| 259 | // Retrieve Data
|
---|
| 260 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 261 | void bncWindow::slotGetData() {
|
---|
| 262 | _actAddMountPoints->setEnabled(false);
|
---|
| 263 | _actDeleteMountPoints->setEnabled(false);
|
---|
| 264 | _actGetData->setEnabled(false);
|
---|
| 265 |
|
---|
| 266 | QString proxyHost = _proxyHostLineEdit->text();
|
---|
| 267 | int proxyPort = _proxyPortLineEdit->text().toInt();
|
---|
| 268 | QByteArray user = _userLineEdit->text().toAscii();
|
---|
| 269 | QByteArray password = _passwordLineEdit->text().toAscii();
|
---|
| 270 |
|
---|
| 271 | _bncCaster = new bncCaster(_outFileLineEdit->text(),
|
---|
| 272 | _outPortLineEdit->text().toInt());
|
---|
| 273 |
|
---|
| 274 | connect(_bncCaster, SIGNAL(getThreadErrors()),
|
---|
| 275 | this, SLOT(slotGetThreadErrors()));
|
---|
| 276 |
|
---|
[83] | 277 | connect(_bncCaster, SIGNAL(newMessage(const QByteArray&)),
|
---|
| 278 | this, SLOT(slotMessage(const QByteArray&)));
|
---|
| 279 |
|
---|
[35] | 280 | _bncCaster->start();
|
---|
| 281 |
|
---|
| 282 | for (int iRow = 0; iRow < _mountPointsTable->rowCount(); iRow++) {
|
---|
| 283 | QUrl url(_mountPointsTable->item(iRow, 0)->text());
|
---|
| 284 | QByteArray mountPoint = url.path().mid(1).toAscii();
|
---|
[59] | 285 | QByteArray format = _mountPointsTable->item(iRow, 1)->text().toAscii();
|
---|
[35] | 286 |
|
---|
| 287 | bncGetThread* getThread = new bncGetThread(url.host(), url.port(),
|
---|
| 288 | proxyHost, proxyPort,
|
---|
[59] | 289 | mountPoint, user, password,
|
---|
| 290 | format);
|
---|
[83] | 291 |
|
---|
| 292 | connect(getThread, SIGNAL(newMessage(const QByteArray&)),
|
---|
| 293 | this, SLOT(slotMessage(const QByteArray&)));
|
---|
| 294 |
|
---|
[35] | 295 | _bncCaster->addGetThread(getThread);
|
---|
| 296 |
|
---|
| 297 | getThread->start();
|
---|
| 298 | }
|
---|
| 299 | }
|
---|
[83] | 300 |
|
---|
| 301 | // Close Application gracefully
|
---|
| 302 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 303 | void bncWindow::closeEvent(QCloseEvent* event) {
|
---|
| 304 |
|
---|
| 305 | int iRet = QMessageBox::question(this, "Close", "Save Options?",
|
---|
| 306 | QMessageBox::Yes, QMessageBox::No,
|
---|
| 307 | QMessageBox::Cancel);
|
---|
| 308 |
|
---|
| 309 | if (iRet == QMessageBox::Cancel) {
|
---|
| 310 | event->ignore();
|
---|
| 311 | return;
|
---|
| 312 | }
|
---|
| 313 | else if (iRet == QMessageBox::Yes) {
|
---|
| 314 | slotSaveOptions();
|
---|
| 315 | }
|
---|
| 316 |
|
---|
| 317 | return QMainWindow::closeEvent(event);
|
---|
| 318 | }
|
---|
| 319 |
|
---|
| 320 | // User changed the selection of mountPoints
|
---|
| 321 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 322 | void bncWindow::slotSelectionChanged() {
|
---|
| 323 | if (_mountPointsTable->selectedItems().isEmpty()) {
|
---|
| 324 | _actDeleteMountPoints->setEnabled(false);
|
---|
| 325 | }
|
---|
| 326 | else {
|
---|
| 327 | _actDeleteMountPoints->setEnabled(true);
|
---|
| 328 | }
|
---|
| 329 | }
|
---|
| 330 |
|
---|
| 331 | // Display Program Messages
|
---|
| 332 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 333 | void bncWindow::slotMessage(const QByteArray& msg) {
|
---|
| 334 |
|
---|
| 335 | const int maxBufferSize = 10000;
|
---|
| 336 |
|
---|
| 337 | QString txt = _log->toPlainText() + "\n" + msg;
|
---|
| 338 | _log->clear();
|
---|
| 339 | _log->append(txt.right(maxBufferSize));
|
---|
| 340 | }
|
---|
| 341 |
|
---|