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 | _ephHostLineEdit = new QLineEdit(settings.value("ephHost").toString());
|
---|
115 | _ephHostLineEdit->setWhatsThis(tr("Host for broadcast ephemeris (from BNC)"));
|
---|
116 | _ephPortLineEdit = new QLineEdit(settings.value("ephPort").toString());
|
---|
117 | _ephPortLineEdit->setWhatsThis(tr("Port for broadcast ephemeris (from BNC)"));
|
---|
118 | _ephPortLineEdit->setMaximumWidth(9*ww);
|
---|
119 |
|
---|
120 | _proxyHostLineEdit = new QLineEdit(settings.value("proxyHost").toString());
|
---|
121 | _proxyHostLineEdit->setWhatsThis(tr("<p>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.</p><p>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.</p>"));
|
---|
122 | _proxyPortLineEdit = new QLineEdit(settings.value("proxyPort").toString());
|
---|
123 | _proxyPortLineEdit->setWhatsThis(tr("<p>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.</p><p>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.</p>"));
|
---|
124 | _proxyPortLineEdit->setMaximumWidth(9*ww);
|
---|
125 |
|
---|
126 | // TabWidget
|
---|
127 | // ---------
|
---|
128 | QTabWidget* tabs = new QTabWidget();
|
---|
129 | QWidget* tab_inp = new QWidget();
|
---|
130 | QWidget* tab_out = new QWidget();
|
---|
131 | QWidget* tab_proxy = new QWidget();
|
---|
132 | tabs->addTab(tab_inp, tr("Input"));
|
---|
133 | tabs->addTab(tab_out, tr("Output"));
|
---|
134 | tabs->addTab(tab_proxy,tr("Proxy"));
|
---|
135 |
|
---|
136 | // Input-Tab
|
---|
137 | // ---------
|
---|
138 | QGridLayout* iLayout = new QGridLayout;
|
---|
139 | /// iLayout->setColumnMinimumWidth(0,12*ww);
|
---|
140 | iLayout->addWidget(new QLabel("Input Options"),0, 0, 1, 2, Qt::AlignLeft);
|
---|
141 | iLayout->addWidget(new QLabel("Host (Ephemeris)"),1,0, Qt::AlignLeft);
|
---|
142 | iLayout->addWidget(_ephHostLineEdit,1, 1);
|
---|
143 | iLayout->addWidget(new QLabel("Port (Ephemeris)"),2,0, Qt::AlignLeft);
|
---|
144 | iLayout->addWidget(_ephPortLineEdit,2, 1);
|
---|
145 | tab_inp->setLayout(iLayout);
|
---|
146 |
|
---|
147 | // Proxy-Tab
|
---|
148 | // ---------
|
---|
149 | QGridLayout* pLayout = new QGridLayout;
|
---|
150 | pLayout->setColumnMinimumWidth(0,12*ww);
|
---|
151 | pLayout->addWidget(new QLabel("Settings for the proxy in protected networks, leave the boxes blank if none."),0, 0, 1, 2, Qt::AlignLeft);
|
---|
152 | pLayout->addWidget(new QLabel("Proxy host"),1,0, Qt::AlignLeft);
|
---|
153 | pLayout->addWidget(_proxyHostLineEdit,1, 1);
|
---|
154 | pLayout->addWidget(new QLabel("Proxy port"),2,0, Qt::AlignLeft);
|
---|
155 | pLayout->addWidget(_proxyPortLineEdit,2,1);
|
---|
156 | tab_proxy->setLayout(pLayout);
|
---|
157 |
|
---|
158 | // Log
|
---|
159 | // ---
|
---|
160 | _log = new QTextBrowser();
|
---|
161 | _log->setReadOnly(true);
|
---|
162 | _log->setWhatsThis(tr("Records of BNS's activities are shown in the Log section."));
|
---|
163 |
|
---|
164 | // Main Layout
|
---|
165 | // -----------
|
---|
166 | QVBoxLayout* mainLayout = new QVBoxLayout;
|
---|
167 | mainLayout->addWidget(tabs);
|
---|
168 | mainLayout->addWidget(_log);
|
---|
169 |
|
---|
170 | _canvas->setLayout(mainLayout);
|
---|
171 | }
|
---|
172 |
|
---|
173 | // Destructor
|
---|
174 | ////////////////////////////////////////////////////////////////////////////
|
---|
175 | bnsWindow::~bnsWindow() {
|
---|
176 | }
|
---|
177 |
|
---|
178 | // Close Application gracefully
|
---|
179 | ////////////////////////////////////////////////////////////////////////////
|
---|
180 | void bnsWindow::closeEvent(QCloseEvent* event) {
|
---|
181 |
|
---|
182 | int iRet = QMessageBox::question(this, "Close", "Save Options?",
|
---|
183 | QMessageBox::Yes, QMessageBox::No,
|
---|
184 | QMessageBox::Cancel);
|
---|
185 |
|
---|
186 | if (iRet == QMessageBox::Cancel) {
|
---|
187 | event->ignore();
|
---|
188 | return;
|
---|
189 | }
|
---|
190 | else if (iRet == QMessageBox::Yes) {
|
---|
191 | slotSaveOptions();
|
---|
192 | }
|
---|
193 |
|
---|
194 | QMainWindow::closeEvent(event);
|
---|
195 |
|
---|
196 | delete this;
|
---|
197 | }
|
---|
198 |
|
---|
199 | // About Message
|
---|
200 | ////////////////////////////////////////////////////////////////////////////
|
---|
201 | void bnsWindow::slotAbout() {
|
---|
202 | new bnsAboutDlg(0);
|
---|
203 | }
|
---|
204 |
|
---|
205 | // Help Window
|
---|
206 | ////////////////////////////////////////////////////////////////////////////
|
---|
207 | void bnsWindow::slotHelp() {
|
---|
208 | QUrl url;
|
---|
209 | url.setPath(":bnshelp.html");
|
---|
210 | new bnsHlpDlg(0, url);
|
---|
211 | }
|
---|
212 |
|
---|
213 | // Select Fonts
|
---|
214 | ////////////////////////////////////////////////////////////////////////////
|
---|
215 | void bnsWindow::slotFontSel() {
|
---|
216 | bool ok;
|
---|
217 | QFont newFont = QFontDialog::getFont(&ok, this->font(), this);
|
---|
218 | if (ok) {
|
---|
219 | QSettings settings;
|
---|
220 | settings.setValue("font", newFont.toString());
|
---|
221 | QApplication::setFont(newFont);
|
---|
222 | int ww = QFontMetrics(newFont).width('w');
|
---|
223 | setMinimumSize(77*ww, 65*ww);
|
---|
224 | }
|
---|
225 | }
|
---|
226 |
|
---|
227 | // Whats This Help
|
---|
228 | ////////////////////////////////////////////////////////////////////////////
|
---|
229 | void bnsWindow::slotWhatsThis() {
|
---|
230 | QWhatsThis::enterWhatsThisMode();
|
---|
231 | }
|
---|
232 |
|
---|
233 | // Create Menus
|
---|
234 | ////////////////////////////////////////////////////////////////////////////
|
---|
235 | void bnsWindow::CreateMenu() {
|
---|
236 | _menuFile = menuBar()->addMenu(tr("&File"));
|
---|
237 | _menuFile->addAction(_actFontSel);
|
---|
238 | _menuFile->addSeparator();
|
---|
239 | _menuFile->addAction(_actSaveOpt);
|
---|
240 | _menuFile->addSeparator();
|
---|
241 | _menuFile->addAction(_actQuit);
|
---|
242 |
|
---|
243 | _menuHlp = menuBar()->addMenu(tr("&Help"));
|
---|
244 | _menuHlp->addAction(_actHelp);
|
---|
245 | _menuHlp->addAction(_actAbout);
|
---|
246 | }
|
---|
247 |
|
---|
248 | // Tool (Command) Bar
|
---|
249 | ////////////////////////////////////////////////////////////////////////////
|
---|
250 | void bnsWindow::AddToolbar() {
|
---|
251 | QToolBar* toolBar = new QToolBar;
|
---|
252 | addToolBar(Qt::BottomToolBarArea, toolBar);
|
---|
253 | toolBar->setMovable(false);
|
---|
254 | toolBar->addAction(_actStart);
|
---|
255 | toolBar->addAction(_actStop);
|
---|
256 | toolBar->addWidget(new QLabel(" "));
|
---|
257 | toolBar->addAction(_actWhatsThis);
|
---|
258 | }
|
---|
259 |
|
---|
260 | // Save Options
|
---|
261 | ////////////////////////////////////////////////////////////////////////////
|
---|
262 | void bnsWindow::slotSaveOptions() {
|
---|
263 | QSettings settings;
|
---|
264 | settings.setValue("ephHost", _ephHostLineEdit->text());
|
---|
265 | settings.setValue("ephPort", _ephPortLineEdit->text());
|
---|
266 | settings.setValue("proxyHost", _proxyHostLineEdit->text());
|
---|
267 | settings.setValue("proxyPort", _proxyPortLineEdit->text());
|
---|
268 | }
|
---|
269 |
|
---|
270 | // Display Program Messages
|
---|
271 | ////////////////////////////////////////////////////////////////////////////
|
---|
272 | void bnsWindow::slotMessage(const QByteArray msg) {
|
---|
273 |
|
---|
274 | const int maxBufferSize = 10000;
|
---|
275 |
|
---|
276 | QString txt = _log->toPlainText() + "\n" +
|
---|
277 | QDateTime::currentDateTime().toUTC().toString("yy-MM-dd hh:mm:ss ") + msg;
|
---|
278 | _log->clear();
|
---|
279 | _log->append(txt.right(maxBufferSize));
|
---|
280 | }
|
---|
281 |
|
---|
282 | // Delete bns
|
---|
283 | ////////////////////////////////////////////////////////////////////////////
|
---|
284 | void bnsWindow::deleteBns() {
|
---|
285 | _actStart->setEnabled(true);
|
---|
286 | _actStop->setEnabled(false);
|
---|
287 | _bns->terminate();
|
---|
288 | _bns->wait(100);
|
---|
289 | delete _bns;
|
---|
290 | _bns = 0;
|
---|
291 | }
|
---|
292 |
|
---|
293 | // Error in bns
|
---|
294 | ////////////////////////////////////////////////////////////////////////////
|
---|
295 | void bnsWindow::slotError(const QByteArray msg) {
|
---|
296 | slotMessage(msg);
|
---|
297 | deleteBns();
|
---|
298 | }
|
---|
299 |
|
---|
300 | // Stop
|
---|
301 | ////////////////////////////////////////////////////////////////////////////
|
---|
302 | void bnsWindow::slotStop() {
|
---|
303 | int iRet = QMessageBox::question(this, "Stop", "Do you want to stop?",
|
---|
304 | QMessageBox::Yes, QMessageBox::No,
|
---|
305 | QMessageBox::NoButton);
|
---|
306 | if (iRet == QMessageBox::Yes) {
|
---|
307 | deleteBns();
|
---|
308 | }
|
---|
309 | }
|
---|
310 |
|
---|
311 | // Start
|
---|
312 | ////////////////////////////////////////////////////////////////////////////
|
---|
313 | void bnsWindow::slotStart() {
|
---|
314 | slotSaveOptions();
|
---|
315 |
|
---|
316 | _actStart->setEnabled(false);
|
---|
317 | _actStop->setEnabled(true);
|
---|
318 |
|
---|
319 | _bns = new t_bns(0);
|
---|
320 |
|
---|
321 | connect(_bns, SIGNAL(newMessage(QByteArray)),
|
---|
322 | this, SLOT(slotMessage(const QByteArray)));
|
---|
323 |
|
---|
324 | connect(_bns, SIGNAL(error(QByteArray)),
|
---|
325 | this, SLOT(slotError(const QByteArray)));
|
---|
326 |
|
---|
327 | _bns->start();
|
---|
328 | }
|
---|