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