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

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