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