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

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