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

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

* empty log message *

File size: 10.8 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 "bnsapp.h"
22#include "bnshlpdlg.h"
23
24using namespace std;
25
26// About Dialog - Constructor
27////////////////////////////////////////////////////////////////////////////
28bnsAboutDlg::bnsAboutDlg(QWidget* parent) :
29 QDialog(parent) {
30
31 QTextBrowser* tb = new QTextBrowser;
32 QUrl url; url.setPath(":bnsabout.html");
33 tb->setSource(url);
34 tb->setReadOnly(true);
35
36 int ww = QFontMetrics(font()).width('w');
37 QPushButton* _closeButton = new QPushButton("Close");
38 _closeButton->setMaximumWidth(10*ww);
39 connect(_closeButton, SIGNAL(clicked()), this, SLOT(close()));
40
41 QGridLayout* dlgLayout = new QGridLayout();
42 QLabel* img = new QLabel();
43 img->setPixmap(QPixmap(":ntrip-logo.png"));
44 dlgLayout->addWidget(img, 0,0);
45 dlgLayout->addWidget(new QLabel("BKG NTRIP Server (BNS) Version 1.0"), 0,1);
46 dlgLayout->addWidget(tb,1,0,1,2);
47 dlgLayout->addWidget(_closeButton,2,1,Qt::AlignRight);
48
49 setLayout(dlgLayout);
50 resize(60*ww, 60*ww);
51 show();
52}
53
54// About Dialog - Destructor
55////////////////////////////////////////////////////////////////////////////
56bnsAboutDlg::~bnsAboutDlg() {
57};
58
59// Constructor
60////////////////////////////////////////////////////////////////////////////
61bnsWindow::bnsWindow() {
62
63 QSettings settings;
64
65 QString fontString = settings.value("font").toString();
66 if ( !fontString.isEmpty() ) {
67 QFont newFont;
68 if (newFont.fromString(fontString)) {
69 this->setFont(newFont);
70 }
71 }
72
73 int ww = QFontMetrics(this->font()).width('w');
74 setMinimumSize(77*ww, 65*ww);
75 setWindowTitle(tr("BKG Ntrip Server (BNS) Version 1.0"));
76 setWindowIcon(QPixmap(":ntrip-logo.png"));
77
78 // Create Actions
79 // --------------
80 _actHelp = new QAction(tr("&Help Contents"),this);
81 connect(_actHelp, SIGNAL(triggered()), SLOT(slotHelp()));
82
83 _actAbout = new QAction(tr("&About BNS"),this);
84 connect(_actAbout, SIGNAL(triggered()), SLOT(slotAbout()));
85
86 _actFontSel = new QAction(tr("Select &Font"),this);
87 connect(_actFontSel, SIGNAL(triggered()), SLOT(slotFontSel()));
88
89 _actSaveOpt = new QAction(tr("&Save Options"),this);
90 connect(_actSaveOpt, SIGNAL(triggered()), SLOT(slotSaveOptions()));
91
92 _actQuit = new QAction(tr("&Quit"),this);
93 connect(_actQuit, SIGNAL(triggered()), SLOT(close()));
94
95 _actWhatsThis= new QAction(tr("Help=Shift+F1"),this);
96 connect(_actWhatsThis, SIGNAL(triggered()), SLOT(slotWhatsThis()));
97
98 _actStart = new QAction(tr("Sta&rt"),this);
99 connect(_actStart, SIGNAL(triggered()), SLOT(slotStart()));
100
101 _actStop = new QAction(tr("Sto&p"),this);
102 connect(_actStop, SIGNAL(triggered()), SLOT(slotStop()));
103 _actStop->setEnabled(false);
104
105 CreateMenu();
106 AddToolbar();
107
108 // Canvas with Editable Fields
109 // ---------------------------
110 _canvas = new QWidget;
111 setCentralWidget(_canvas);
112
113 _ephHostLineEdit = new QLineEdit(settings.value("ephHost").toString());
114 _ephHostLineEdit->setWhatsThis(tr("Host for broadcast ephemeris (from BNC)"));
115 _ephPortLineEdit = new QLineEdit(settings.value("ephPort").toString());
116 _ephPortLineEdit->setWhatsThis(tr("Port for broadcast ephemeris (from BNC)"));
117 _ephPortLineEdit->setMaximumWidth(9*ww);
118
119 _proxyHostLineEdit = new QLineEdit(settings.value("proxyHost").toString());
120 _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>"));
121 _proxyPortLineEdit = new QLineEdit(settings.value("proxyPort").toString());
122 _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>"));
123 _proxyPortLineEdit->setMaximumWidth(9*ww);
124
125 // TabWidget
126 // ---------
127 QTabWidget* tabs = new QTabWidget();
128 QWidget* tab_inp = new QWidget();
129 QWidget* tab_out = new QWidget();
130 QWidget* tab_proxy = new QWidget();
131 tabs->addTab(tab_inp, tr("Input"));
132 tabs->addTab(tab_out, tr("Output"));
133 tabs->addTab(tab_proxy,tr("Proxy"));
134
135 // Input-Tab
136 // ---------
137 QGridLayout* iLayout = new QGridLayout;
138 /// iLayout->setColumnMinimumWidth(0,12*ww);
139 iLayout->addWidget(new QLabel("Input Options"),0, 0, 1, 2, Qt::AlignLeft);
140 iLayout->addWidget(new QLabel("Host (Ephemeris)"),1,0, Qt::AlignLeft);
141 iLayout->addWidget(_ephHostLineEdit,1, 1);
142 iLayout->addWidget(new QLabel("Port (Ephemeris)"),2,0, Qt::AlignLeft);
143 iLayout->addWidget(_ephPortLineEdit,2, 1);
144 tab_inp->setLayout(iLayout);
145
146 // Proxy-Tab
147 // ---------
148 QGridLayout* pLayout = new QGridLayout;
149 pLayout->setColumnMinimumWidth(0,12*ww);
150 pLayout->addWidget(new QLabel("Settings for the proxy in protected networks, leave the boxes blank if none."),0, 0, 1, 2, Qt::AlignLeft);
151 pLayout->addWidget(new QLabel("Proxy host"),1,0, Qt::AlignLeft);
152 pLayout->addWidget(_proxyHostLineEdit,1, 1);
153 pLayout->addWidget(new QLabel("Proxy port"),2,0, Qt::AlignLeft);
154 pLayout->addWidget(_proxyPortLineEdit,2,1);
155 tab_proxy->setLayout(pLayout);
156
157 // Log
158 // ---
159 _log = new QTextBrowser();
160 _log->setReadOnly(true);
161 _log->setWhatsThis(tr("Records of BNS's activities are shown in the Log section."));
162
163 // Main Layout
164 // -----------
165 QVBoxLayout* mainLayout = new QVBoxLayout;
166 mainLayout->addWidget(tabs);
167 mainLayout->addWidget(_log);
168
169 _canvas->setLayout(mainLayout);
170}
171
172// Destructor
173////////////////////////////////////////////////////////////////////////////
174bnsWindow::~bnsWindow() {
175}
176
177// Close Application gracefully
178////////////////////////////////////////////////////////////////////////////
179void bnsWindow::closeEvent(QCloseEvent* event) {
180
181int iRet = QMessageBox::question(this, "Close", "Save Options?",
182 QMessageBox::Yes, QMessageBox::No,
183 QMessageBox::Cancel);
184
185 if (iRet == QMessageBox::Cancel) {
186 event->ignore();
187 return;
188 }
189 else if (iRet == QMessageBox::Yes) {
190 slotSaveOptions();
191 }
192
193 QMainWindow::closeEvent(event);
194
195 delete this;
196}
197
198// About Message
199////////////////////////////////////////////////////////////////////////////
200void bnsWindow::slotAbout() {
201 new bnsAboutDlg(0);
202}
203
204// Help Window
205////////////////////////////////////////////////////////////////////////////
206void bnsWindow::slotHelp() {
207 QUrl url;
208 url.setPath(":bnshelp.html");
209 new bnsHlpDlg(0, url);
210}
211
212// Select Fonts
213////////////////////////////////////////////////////////////////////////////
214void bnsWindow::slotFontSel() {
215 bool ok;
216 QFont newFont = QFontDialog::getFont(&ok, this->font(), this);
217 if (ok) {
218 QSettings settings;
219 settings.setValue("font", newFont.toString());
220 QApplication::setFont(newFont);
221 int ww = QFontMetrics(newFont).width('w');
222 setMinimumSize(77*ww, 65*ww);
223 }
224}
225
226// Whats This Help
227////////////////////////////////////////////////////////////////////////////
228void bnsWindow::slotWhatsThis() {
229QWhatsThis::enterWhatsThisMode();
230}
231
232// Create Menus
233////////////////////////////////////////////////////////////////////////////
234void bnsWindow::CreateMenu() {
235 _menuFile = menuBar()->addMenu(tr("&File"));
236 _menuFile->addAction(_actFontSel);
237 _menuFile->addSeparator();
238 _menuFile->addAction(_actSaveOpt);
239 _menuFile->addSeparator();
240 _menuFile->addAction(_actQuit);
241
242 _menuHlp = menuBar()->addMenu(tr("&Help"));
243 _menuHlp->addAction(_actHelp);
244 _menuHlp->addAction(_actAbout);
245}
246
247// Tool (Command) Bar
248////////////////////////////////////////////////////////////////////////////
249void bnsWindow::AddToolbar() {
250 QToolBar* toolBar = new QToolBar;
251 addToolBar(Qt::BottomToolBarArea, toolBar);
252 toolBar->setMovable(false);
253 toolBar->addAction(_actStart);
254 toolBar->addAction(_actStop);
255 toolBar->addWidget(new QLabel(" "));
256 toolBar->addAction(_actWhatsThis);
257}
258
259// Save Options
260////////////////////////////////////////////////////////////////////////////
261void bnsWindow::slotSaveOptions() {
262 QSettings settings;
263 settings.setValue("ephHost", _ephHostLineEdit->text());
264 settings.setValue("ephPort", _ephPortLineEdit->text());
265 settings.setValue("proxyHost", _proxyHostLineEdit->text());
266 settings.setValue("proxyPort", _proxyPortLineEdit->text());
267}
268
269// Display Program Messages
270////////////////////////////////////////////////////////////////////////////
271void bnsWindow::slotMessage(const QByteArray msg) {
272
273 ((bnsApp*)qApp)->slotMessage(msg);
274
275 const int maxBufferSize = 10000;
276
277 QString txt = _log->toPlainText() + "\n" +
278 QDateTime::currentDateTime().toUTC().toString("yy-MM-dd hh:mm:ss ") + msg;
279 _log->clear();
280 _log->append(txt.right(maxBufferSize));
281}
282
283// Stop
284////////////////////////////////////////////////////////////////////////////
285void bnsWindow::slotStop() {
286 int iRet = QMessageBox::question(this, "Stop", "Do you want to stop?",
287 QMessageBox::Yes, QMessageBox::No,
288 QMessageBox::NoButton);
289 if (iRet == QMessageBox::Yes) {
290 _actStart->setEnabled(true);
291 _actStop->setEnabled(false);
292 ((bnsApp*)qApp)->stop();
293 }
294}
295
296// Start
297////////////////////////////////////////////////////////////////////////////
298void bnsWindow::slotStart() {
299 slotSaveOptions();
300
301 _actStart->setEnabled(false);
302 _actStop->setEnabled(true);
303
304 slotMessage("============ Start BNS ============");
305
306 ((bnsApp*)qApp)->start();
307}
Note: See TracBrowser for help on using the repository browser.