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

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