| 1 |
|
|---|
| 2 | /* -------------------------------------------------------------------------
|
|---|
| 3 | * BKG NTRIP Server
|
|---|
| 4 | * -------------------------------------------------------------------------
|
|---|
| 5 | *
|
|---|
| 6 | * Class: bnsWindow
|
|---|
| 7 | *
|
|---|
| 8 | * Purpose: This class implements the main application window.
|
|---|
| 9 | *
|
|---|
| 10 | * Author: L. Mervart
|
|---|
| 11 | *
|
|---|
| 12 | * Created: 29-Mar-2008
|
|---|
| 13 | *
|
|---|
| 14 | * Changes:
|
|---|
| 15 | *
|
|---|
| 16 | * -----------------------------------------------------------------------*/
|
|---|
| 17 |
|
|---|
| 18 | #include <iostream>
|
|---|
| 19 |
|
|---|
| 20 | #include "bnswindow.h"
|
|---|
| 21 | #include "bnshlpdlg.h"
|
|---|
| 22 |
|
|---|
| 23 | using namespace std;
|
|---|
| 24 |
|
|---|
| 25 | // About Dialog - Constructor
|
|---|
| 26 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 27 | bnsAboutDlg::bnsAboutDlg(QWidget* parent) :
|
|---|
| 28 | QDialog(parent) {
|
|---|
| 29 |
|
|---|
| 30 | QTextBrowser* tb = new QTextBrowser;
|
|---|
| 31 | QUrl url; url.setPath(":bnsabout.html");
|
|---|
| 32 | tb->setSource(url);
|
|---|
| 33 | tb->setReadOnly(true);
|
|---|
| 34 |
|
|---|
| 35 | int ww = QFontMetrics(font()).width('w');
|
|---|
| 36 | QPushButton* _closeButton = new QPushButton("Close");
|
|---|
| 37 | _closeButton->setMaximumWidth(10*ww);
|
|---|
| 38 | connect(_closeButton, SIGNAL(clicked()), this, SLOT(close()));
|
|---|
| 39 |
|
|---|
| 40 | QGridLayout* dlgLayout = new QGridLayout();
|
|---|
| 41 | QLabel* img = new QLabel();
|
|---|
| 42 | img->setPixmap(QPixmap(":ntrip-logo.png"));
|
|---|
| 43 | dlgLayout->addWidget(img, 0,0);
|
|---|
| 44 | dlgLayout->addWidget(new QLabel("BKG NTRIP Server (BNS) Version 1.0"), 0,1);
|
|---|
| 45 | dlgLayout->addWidget(tb,1,0,1,2);
|
|---|
| 46 | dlgLayout->addWidget(_closeButton,2,1,Qt::AlignRight);
|
|---|
| 47 |
|
|---|
| 48 | setLayout(dlgLayout);
|
|---|
| 49 | resize(60*ww, 60*ww);
|
|---|
| 50 | show();
|
|---|
| 51 | }
|
|---|
| 52 |
|
|---|
| 53 | // About Dialog - Destructor
|
|---|
| 54 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 55 | bnsAboutDlg::~bnsAboutDlg() {
|
|---|
| 56 | };
|
|---|
| 57 |
|
|---|
| 58 | // Constructor
|
|---|
| 59 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 60 | bnsWindow::bnsWindow() {
|
|---|
| 61 |
|
|---|
| 62 | _bns = 0;
|
|---|
| 63 |
|
|---|
| 64 | QSettings settings;
|
|---|
| 65 |
|
|---|
| 66 | QString fontString = settings.value("font").toString();
|
|---|
| 67 | if ( !fontString.isEmpty() ) {
|
|---|
| 68 | QFont newFont;
|
|---|
| 69 | if (newFont.fromString(fontString)) {
|
|---|
| 70 | this->setFont(newFont);
|
|---|
| 71 | }
|
|---|
| 72 | }
|
|---|
| 73 |
|
|---|
| 74 | int ww = QFontMetrics(this->font()).width('w');
|
|---|
| 75 | setMinimumSize(77*ww, 65*ww);
|
|---|
| 76 | setWindowTitle(tr("BKG Ntrip Server (BNS) Version 1.0"));
|
|---|
| 77 | setWindowIcon(QPixmap(":ntrip-logo.png"));
|
|---|
| 78 |
|
|---|
| 79 | // Create Actions
|
|---|
| 80 | // --------------
|
|---|
| 81 | _actHelp = new QAction(tr("&Help Contents"),this);
|
|---|
| 82 | connect(_actHelp, SIGNAL(triggered()), SLOT(slotHelp()));
|
|---|
| 83 |
|
|---|
| 84 | _actAbout = new QAction(tr("&About BNS"),this);
|
|---|
| 85 | connect(_actAbout, SIGNAL(triggered()), SLOT(slotAbout()));
|
|---|
| 86 |
|
|---|
| 87 | _actFontSel = new QAction(tr("Select &Font"),this);
|
|---|
| 88 | connect(_actFontSel, SIGNAL(triggered()), SLOT(slotFontSel()));
|
|---|
| 89 |
|
|---|
| 90 | _actSaveOpt = new QAction(tr("&Save Options"),this);
|
|---|
| 91 | connect(_actSaveOpt, SIGNAL(triggered()), SLOT(slotSaveOptions()));
|
|---|
| 92 |
|
|---|
| 93 | _actQuit = new QAction(tr("&Quit"),this);
|
|---|
| 94 | connect(_actQuit, SIGNAL(triggered()), SLOT(close()));
|
|---|
| 95 |
|
|---|
| 96 | _actWhatsThis= new QAction(tr("Help=Shift+F1"),this);
|
|---|
| 97 | connect(_actWhatsThis, SIGNAL(triggered()), SLOT(slotWhatsThis()));
|
|---|
| 98 |
|
|---|
| 99 | _actStart = new QAction(tr("Sta&rt"),this);
|
|---|
| 100 | connect(_actStart, SIGNAL(triggered()), SLOT(slotStart()));
|
|---|
| 101 |
|
|---|
| 102 | _actStop = new QAction(tr("Sto&p"),this);
|
|---|
| 103 | connect(_actStop, SIGNAL(triggered()), SLOT(slotStop()));
|
|---|
| 104 | _actStop->setEnabled(false);
|
|---|
| 105 |
|
|---|
| 106 | CreateMenu();
|
|---|
| 107 | AddToolbar();
|
|---|
| 108 |
|
|---|
| 109 | // Canvas with Editable Fields
|
|---|
| 110 | // ---------------------------
|
|---|
| 111 | _canvas = new QWidget;
|
|---|
| 112 | setCentralWidget(_canvas);
|
|---|
| 113 |
|
|---|
| 114 | _ephPortLineEdit = new QLineEdit(settings.value("ephPort").toString());
|
|---|
| 115 | _ephPortLineEdit->setWhatsThis(tr("Port for broadcast ephemeris (from BNC)"));
|
|---|
| 116 | _ephPortLineEdit->setMaximumWidth(9*ww);
|
|---|
| 117 |
|
|---|
| 118 | _clkPortLineEdit = new QLineEdit(settings.value("clkPort").toString());
|
|---|
| 119 | _clkPortLineEdit->setWhatsThis(tr("Port for clock results (from RTNET)"));
|
|---|
| 120 | _clkPortLineEdit->setMaximumWidth(9*ww);
|
|---|
| 121 |
|
|---|
| 122 | // TabWidget
|
|---|
| 123 | // ---------
|
|---|
| 124 | QTabWidget* tabs = new QTabWidget();
|
|---|
| 125 | QWidget* tab_inp = new QWidget();
|
|---|
| 126 | QWidget* tab_out = new QWidget();
|
|---|
| 127 | tabs->addTab(tab_inp, tr("INPUT"));
|
|---|
| 128 | tabs->addTab(tab_out, tr("OUTPUT"));
|
|---|
| 129 |
|
|---|
| 130 | // Input-Tab
|
|---|
| 131 | // ---------
|
|---|
| 132 | QGridLayout* iLayout = new QGridLayout;
|
|---|
| 133 | iLayout->addWidget(new QLabel("Port (Ephemeris)"), 0, 0, Qt::AlignLeft);
|
|---|
| 134 | iLayout->addWidget(_ephPortLineEdit, 0, 1);
|
|---|
| 135 | iLayout->addWidget(new QLabel("Port (Clocks)"), 1, 0, Qt::AlignLeft);
|
|---|
| 136 | iLayout->addWidget(_clkPortLineEdit, 1, 1);
|
|---|
| 137 | tab_inp->setLayout(iLayout);
|
|---|
| 138 |
|
|---|
| 139 | // Log
|
|---|
| 140 | // ---
|
|---|
| 141 | _log = new QTextBrowser();
|
|---|
| 142 | _log->setReadOnly(true);
|
|---|
| 143 | _log->setWhatsThis(tr("Records of BNS's activities are shown in the Log section."));
|
|---|
| 144 |
|
|---|
| 145 | // Main Layout
|
|---|
| 146 | // -----------
|
|---|
| 147 | QVBoxLayout* mainLayout = new QVBoxLayout;
|
|---|
| 148 | mainLayout->addWidget(tabs);
|
|---|
| 149 | mainLayout->addWidget(_log);
|
|---|
| 150 |
|
|---|
| 151 | _canvas->setLayout(mainLayout);
|
|---|
| 152 | }
|
|---|
| 153 |
|
|---|
| 154 | // Destructor
|
|---|
| 155 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 156 | bnsWindow::~bnsWindow() {
|
|---|
| 157 | }
|
|---|
| 158 |
|
|---|
| 159 | // Close Application gracefully
|
|---|
| 160 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 161 | void bnsWindow::closeEvent(QCloseEvent* event) {
|
|---|
| 162 |
|
|---|
| 163 | int iRet = QMessageBox::question(this, "Close", "Save Options?",
|
|---|
| 164 | QMessageBox::Yes, QMessageBox::No,
|
|---|
| 165 | QMessageBox::Cancel);
|
|---|
| 166 |
|
|---|
| 167 | if (iRet == QMessageBox::Cancel) {
|
|---|
| 168 | event->ignore();
|
|---|
| 169 | return;
|
|---|
| 170 | }
|
|---|
| 171 | else if (iRet == QMessageBox::Yes) {
|
|---|
| 172 | slotSaveOptions();
|
|---|
| 173 | }
|
|---|
| 174 |
|
|---|
| 175 | QMainWindow::closeEvent(event);
|
|---|
| 176 |
|
|---|
| 177 | delete this;
|
|---|
| 178 | }
|
|---|
| 179 |
|
|---|
| 180 | // About Message
|
|---|
| 181 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 182 | void bnsWindow::slotAbout() {
|
|---|
| 183 | new bnsAboutDlg(0);
|
|---|
| 184 | }
|
|---|
| 185 |
|
|---|
| 186 | // Help Window
|
|---|
| 187 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 188 | void bnsWindow::slotHelp() {
|
|---|
| 189 | QUrl url;
|
|---|
| 190 | url.setPath(":bnshelp.html");
|
|---|
| 191 | new bnsHlpDlg(0, url);
|
|---|
| 192 | }
|
|---|
| 193 |
|
|---|
| 194 | // Select Fonts
|
|---|
| 195 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 196 | void bnsWindow::slotFontSel() {
|
|---|
| 197 | bool ok;
|
|---|
| 198 | QFont newFont = QFontDialog::getFont(&ok, this->font(), this);
|
|---|
| 199 | if (ok) {
|
|---|
| 200 | QSettings settings;
|
|---|
| 201 | settings.setValue("font", newFont.toString());
|
|---|
| 202 | QApplication::setFont(newFont);
|
|---|
| 203 | int ww = QFontMetrics(newFont).width('w');
|
|---|
| 204 | setMinimumSize(77*ww, 65*ww);
|
|---|
| 205 | }
|
|---|
| 206 | }
|
|---|
| 207 |
|
|---|
| 208 | // Whats This Help
|
|---|
| 209 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 210 | void bnsWindow::slotWhatsThis() {
|
|---|
| 211 | QWhatsThis::enterWhatsThisMode();
|
|---|
| 212 | }
|
|---|
| 213 |
|
|---|
| 214 | // Create Menus
|
|---|
| 215 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 216 | void bnsWindow::CreateMenu() {
|
|---|
| 217 | _menuFile = menuBar()->addMenu(tr("&File"));
|
|---|
| 218 | _menuFile->addAction(_actFontSel);
|
|---|
| 219 | _menuFile->addSeparator();
|
|---|
| 220 | _menuFile->addAction(_actSaveOpt);
|
|---|
| 221 | _menuFile->addSeparator();
|
|---|
| 222 | _menuFile->addAction(_actQuit);
|
|---|
| 223 |
|
|---|
| 224 | _menuHlp = menuBar()->addMenu(tr("&Help"));
|
|---|
| 225 | _menuHlp->addAction(_actHelp);
|
|---|
| 226 | _menuHlp->addAction(_actAbout);
|
|---|
| 227 | }
|
|---|
| 228 |
|
|---|
| 229 | // Tool (Command) Bar
|
|---|
| 230 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 231 | void bnsWindow::AddToolbar() {
|
|---|
| 232 | QToolBar* toolBar = new QToolBar;
|
|---|
| 233 | addToolBar(Qt::BottomToolBarArea, toolBar);
|
|---|
| 234 | toolBar->setMovable(false);
|
|---|
| 235 | toolBar->addAction(_actStart);
|
|---|
| 236 | toolBar->addAction(_actStop);
|
|---|
| 237 | toolBar->addWidget(new QLabel(" "));
|
|---|
| 238 | toolBar->addAction(_actWhatsThis);
|
|---|
| 239 | }
|
|---|
| 240 |
|
|---|
| 241 | // Save Options
|
|---|
| 242 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 243 | void bnsWindow::slotSaveOptions() {
|
|---|
| 244 | QSettings settings;
|
|---|
| 245 | settings.setValue("ephPort", _ephPortLineEdit->text());
|
|---|
| 246 | settings.setValue("clkPort", _clkPortLineEdit->text());
|
|---|
| 247 | }
|
|---|
| 248 |
|
|---|
| 249 | // Display Program Messages
|
|---|
| 250 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 251 | void bnsWindow::slotMessage(const QByteArray msg) {
|
|---|
| 252 |
|
|---|
| 253 | const int maxBufferSize = 10000;
|
|---|
| 254 |
|
|---|
| 255 | QString txt = _log->toPlainText() + "\n" +
|
|---|
| 256 | QDateTime::currentDateTime().toUTC().toString("yy-MM-dd hh:mm:ss ") + msg;
|
|---|
| 257 | _log->clear();
|
|---|
| 258 | _log->append(txt.right(maxBufferSize));
|
|---|
| 259 | }
|
|---|
| 260 |
|
|---|
| 261 | // Delete bns
|
|---|
| 262 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 263 | void bnsWindow::deleteBns() {
|
|---|
| 264 | _actStart->setEnabled(true);
|
|---|
| 265 | _actStop->setEnabled(false);
|
|---|
| 266 | _bns->terminate();
|
|---|
| 267 | _bns->wait(100);
|
|---|
| 268 | delete _bns;
|
|---|
| 269 | _bns = 0;
|
|---|
| 270 | }
|
|---|
| 271 |
|
|---|
| 272 | // Error in bns
|
|---|
| 273 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 274 | void bnsWindow::slotError(const QByteArray msg) {
|
|---|
| 275 | slotMessage(msg);
|
|---|
| 276 | deleteBns();
|
|---|
| 277 | }
|
|---|
| 278 |
|
|---|
| 279 | // Stop
|
|---|
| 280 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 281 | void bnsWindow::slotStop() {
|
|---|
| 282 | int iRet = QMessageBox::question(this, "Stop", "Do you want to stop?",
|
|---|
| 283 | QMessageBox::Yes, QMessageBox::No,
|
|---|
| 284 | QMessageBox::NoButton);
|
|---|
| 285 | if (iRet == QMessageBox::Yes) {
|
|---|
| 286 | deleteBns();
|
|---|
| 287 | }
|
|---|
| 288 | }
|
|---|
| 289 |
|
|---|
| 290 | // Start
|
|---|
| 291 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 292 | void bnsWindow::slotStart() {
|
|---|
| 293 | slotSaveOptions();
|
|---|
| 294 |
|
|---|
| 295 | _actStart->setEnabled(false);
|
|---|
| 296 | _actStop->setEnabled(true);
|
|---|
| 297 |
|
|---|
| 298 | _bns = new t_bns(0);
|
|---|
| 299 |
|
|---|
| 300 | connect(_bns, SIGNAL(newMessage(QByteArray)),
|
|---|
| 301 | this, SLOT(slotMessage(const QByteArray)));
|
|---|
| 302 |
|
|---|
| 303 | connect(_bns, SIGNAL(error(QByteArray)),
|
|---|
| 304 | this, SLOT(slotError(const QByteArray)));
|
|---|
| 305 |
|
|---|
| 306 | _bns->start();
|
|---|
| 307 | }
|
|---|