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

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

* empty log message *

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