source: ntrip/trunk/BNS/bnswindow.cpp@ 813

Last change on this file since 813 was 813, checked in by mervart, 16 years ago

* empty log message *

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