/* ------------------------------------------------------------------------- * BKG NTRIP Server * ------------------------------------------------------------------------- * * Class: bnsWindow * * Purpose: This class implements the main application window. * * Author: L. Mervart * * Created: 29-Mar-2008 * * Changes: * * -----------------------------------------------------------------------*/ #include #include "bnswindow.h" #include "bnshlpdlg.h" using namespace std; // About Dialog - Constructor //////////////////////////////////////////////////////////////////////////// bnsAboutDlg::bnsAboutDlg(QWidget* parent) : QDialog(parent) { QTextBrowser* tb = new QTextBrowser; QUrl url; url.setPath(":bnsabout.html"); tb->setSource(url); tb->setReadOnly(true); int ww = QFontMetrics(font()).width('w'); QPushButton* _closeButton = new QPushButton("Close"); _closeButton->setMaximumWidth(10*ww); connect(_closeButton, SIGNAL(clicked()), this, SLOT(close())); QGridLayout* dlgLayout = new QGridLayout(); QLabel* img = new QLabel(); img->setPixmap(QPixmap(":ntrip-logo.png")); dlgLayout->addWidget(img, 0,0); dlgLayout->addWidget(new QLabel("BKG NTRIP Server (BNS) Version 1.0"), 0,1); dlgLayout->addWidget(tb,1,0,1,2); dlgLayout->addWidget(_closeButton,2,1,Qt::AlignRight); setLayout(dlgLayout); resize(60*ww, 60*ww); show(); } // About Dialog - Destructor //////////////////////////////////////////////////////////////////////////// bnsAboutDlg::~bnsAboutDlg() { }; // Constructor //////////////////////////////////////////////////////////////////////////// bnsWindow::bnsWindow() { _bns = 0; QSettings settings; QString fontString = settings.value("font").toString(); if ( !fontString.isEmpty() ) { QFont newFont; if (newFont.fromString(fontString)) { this->setFont(newFont); } } int ww = QFontMetrics(this->font()).width('w'); setMinimumSize(77*ww, 65*ww); setWindowTitle(tr("BKG Ntrip Server (BNS) Version 1.0")); setWindowIcon(QPixmap(":ntrip-logo.png")); // Create Actions // -------------- _actHelp = new QAction(tr("&Help Contents"),this); connect(_actHelp, SIGNAL(triggered()), SLOT(slotHelp())); _actAbout = new QAction(tr("&About BNS"),this); connect(_actAbout, SIGNAL(triggered()), SLOT(slotAbout())); _actFontSel = new QAction(tr("Select &Font"),this); connect(_actFontSel, SIGNAL(triggered()), SLOT(slotFontSel())); _actSaveOpt = new QAction(tr("&Save Options"),this); connect(_actSaveOpt, SIGNAL(triggered()), SLOT(slotSaveOptions())); _actQuit = new QAction(tr("&Quit"),this); connect(_actQuit, SIGNAL(triggered()), SLOT(close())); _actWhatsThis= new QAction(tr("Help=Shift+F1"),this); connect(_actWhatsThis, SIGNAL(triggered()), SLOT(slotWhatsThis())); _actStart = new QAction(tr("Sta&rt"),this); connect(_actStart, SIGNAL(triggered()), SLOT(slotStart())); _actStop = new QAction(tr("Sto&p"),this); connect(_actStop, SIGNAL(triggered()), SLOT(slotStop())); _actStop->setEnabled(false); CreateMenu(); AddToolbar(); // Canvas with Editable Fields // --------------------------- _canvas = new QWidget; setCentralWidget(_canvas); _ephHostLineEdit = new QLineEdit(settings.value("ephHost").toString()); _ephHostLineEdit->setWhatsThis(tr("Host for broadcast ephemeris (from BNC)")); _ephPortLineEdit = new QLineEdit(settings.value("ephPort").toString()); _ephPortLineEdit->setWhatsThis(tr("Port for broadcast ephemeris (from BNC)")); _ephPortLineEdit->setMaximumWidth(9*ww); _proxyHostLineEdit = new QLineEdit(settings.value("proxyHost").toString()); _proxyHostLineEdit->setWhatsThis(tr("

If you are running BNS within a protected Local Area Network (LAN), you might need to use a proxy server to access the Internet. Enter your proxy server IP and port number in case one is operated in front of BNC. If you do not know the IP and port of your proxy server, check the proxy server settings in your Internet browser or ask your network administrator.

Note that IP streaming is sometimes not allowed in a LAN. In this case you need to ask your network administrator for an appropriate modification of the local security policy or for the installation of a TCP relay to the NTRIP broadcasters. If these are not possible, you might need to run BNC outside your LAN on a network that has unobstructed connection to the Internet.

")); _proxyPortLineEdit = new QLineEdit(settings.value("proxyPort").toString()); _proxyPortLineEdit->setWhatsThis(tr("

If you are running BNS within a protected Local Area Network (LAN), you might need to use a proxy server to access the Internet. Enter your proxy server IP and port number in case one is operated in front of BNC. If you do not know the IP and port of your proxy server, check the proxy server settings in your Internet browser or ask your network administrator.

Note that IP streaming is sometimes not allowed in a LAN. In this case you need to ask your network administrator for an appropriate modification of the local security policy or for the installation of a TCP relay to the NTRIP broadcasters. If these are not possible, you might need to run BNC outside your LAN on a network that has unobstructed connection to the Internet.

")); _proxyPortLineEdit->setMaximumWidth(9*ww); // TabWidget // --------- QTabWidget* tabs = new QTabWidget(); QWidget* tab_inp = new QWidget(); QWidget* tab_out = new QWidget(); QWidget* tab_proxy = new QWidget(); tabs->addTab(tab_inp, tr("Input")); tabs->addTab(tab_out, tr("Output")); tabs->addTab(tab_proxy,tr("Proxy")); // Input-Tab // --------- QGridLayout* iLayout = new QGridLayout; /// iLayout->setColumnMinimumWidth(0,12*ww); iLayout->addWidget(new QLabel("Input Options"),0, 0, 1, 2, Qt::AlignLeft); iLayout->addWidget(new QLabel("Host (Ephemeris)"),1,0, Qt::AlignLeft); iLayout->addWidget(_ephHostLineEdit,1, 1); iLayout->addWidget(new QLabel("Port (Ephemeris)"),2,0, Qt::AlignLeft); iLayout->addWidget(_ephPortLineEdit,2, 1); tab_inp->setLayout(iLayout); // Proxy-Tab // --------- QGridLayout* pLayout = new QGridLayout; pLayout->setColumnMinimumWidth(0,12*ww); pLayout->addWidget(new QLabel("Settings for the proxy in protected networks, leave the boxes blank if none."),0, 0, 1, 2, Qt::AlignLeft); pLayout->addWidget(new QLabel("Proxy host"),1,0, Qt::AlignLeft); pLayout->addWidget(_proxyHostLineEdit,1, 1); pLayout->addWidget(new QLabel("Proxy port"),2,0, Qt::AlignLeft); pLayout->addWidget(_proxyPortLineEdit,2,1); tab_proxy->setLayout(pLayout); // Log // --- _log = new QTextBrowser(); _log->setReadOnly(true); _log->setWhatsThis(tr("Records of BNS's activities are shown in the Log section.")); // Main Layout // ----------- QVBoxLayout* mainLayout = new QVBoxLayout; mainLayout->addWidget(tabs); mainLayout->addWidget(_log); _canvas->setLayout(mainLayout); } // Destructor //////////////////////////////////////////////////////////////////////////// bnsWindow::~bnsWindow() { } // Close Application gracefully //////////////////////////////////////////////////////////////////////////// void bnsWindow::closeEvent(QCloseEvent* event) { int iRet = QMessageBox::question(this, "Close", "Save Options?", QMessageBox::Yes, QMessageBox::No, QMessageBox::Cancel); if (iRet == QMessageBox::Cancel) { event->ignore(); return; } else if (iRet == QMessageBox::Yes) { slotSaveOptions(); } QMainWindow::closeEvent(event); delete this; } // About Message //////////////////////////////////////////////////////////////////////////// void bnsWindow::slotAbout() { new bnsAboutDlg(0); } // Help Window //////////////////////////////////////////////////////////////////////////// void bnsWindow::slotHelp() { QUrl url; url.setPath(":bnshelp.html"); new bnsHlpDlg(0, url); } // Select Fonts //////////////////////////////////////////////////////////////////////////// void bnsWindow::slotFontSel() { bool ok; QFont newFont = QFontDialog::getFont(&ok, this->font(), this); if (ok) { QSettings settings; settings.setValue("font", newFont.toString()); QApplication::setFont(newFont); int ww = QFontMetrics(newFont).width('w'); setMinimumSize(77*ww, 65*ww); } } // Whats This Help //////////////////////////////////////////////////////////////////////////// void bnsWindow::slotWhatsThis() { QWhatsThis::enterWhatsThisMode(); } // Create Menus //////////////////////////////////////////////////////////////////////////// void bnsWindow::CreateMenu() { _menuFile = menuBar()->addMenu(tr("&File")); _menuFile->addAction(_actFontSel); _menuFile->addSeparator(); _menuFile->addAction(_actSaveOpt); _menuFile->addSeparator(); _menuFile->addAction(_actQuit); _menuHlp = menuBar()->addMenu(tr("&Help")); _menuHlp->addAction(_actHelp); _menuHlp->addAction(_actAbout); } // Tool (Command) Bar //////////////////////////////////////////////////////////////////////////// void bnsWindow::AddToolbar() { QToolBar* toolBar = new QToolBar; addToolBar(Qt::BottomToolBarArea, toolBar); toolBar->setMovable(false); toolBar->addAction(_actStart); toolBar->addAction(_actStop); toolBar->addWidget(new QLabel(" ")); toolBar->addAction(_actWhatsThis); } // Save Options //////////////////////////////////////////////////////////////////////////// void bnsWindow::slotSaveOptions() { QSettings settings; settings.setValue("ephHost", _ephHostLineEdit->text()); settings.setValue("ephPort", _ephPortLineEdit->text()); settings.setValue("proxyHost", _proxyHostLineEdit->text()); settings.setValue("proxyPort", _proxyPortLineEdit->text()); } // Display Program Messages //////////////////////////////////////////////////////////////////////////// void bnsWindow::slotMessage(const QByteArray msg) { const int maxBufferSize = 10000; QString txt = _log->toPlainText() + "\n" + QDateTime::currentDateTime().toUTC().toString("yy-MM-dd hh:mm:ss ") + msg; _log->clear(); _log->append(txt.right(maxBufferSize)); } // Delete bns //////////////////////////////////////////////////////////////////////////// void bnsWindow::deleteBns() { _actStart->setEnabled(true); _actStop->setEnabled(false); _bns->terminate(); _bns->wait(100); delete _bns; _bns = 0; } // Error in bns //////////////////////////////////////////////////////////////////////////// void bnsWindow::slotError(const QByteArray msg) { slotMessage(msg); deleteBns(); } // Stop //////////////////////////////////////////////////////////////////////////// void bnsWindow::slotStop() { int iRet = QMessageBox::question(this, "Stop", "Do you want to stop?", QMessageBox::Yes, QMessageBox::No, QMessageBox::NoButton); if (iRet == QMessageBox::Yes) { deleteBns(); } } // Start //////////////////////////////////////////////////////////////////////////// void bnsWindow::slotStart() { slotSaveOptions(); _actStart->setEnabled(false); _actStop->setEnabled(true); _bns = new t_bns(0); connect(_bns, SIGNAL(newMessage(QByteArray)), this, SLOT(slotMessage(const QByteArray))); connect(_bns, SIGNAL(error(QByteArray)), this, SLOT(slotError(const QByteArray))); _bns->start(); }