-rw-r--r-- | noncore/net/wellenreiter/gui/mainwindow.cpp | 116 | ||||
-rw-r--r-- | noncore/net/wellenreiter/gui/mainwindow.h | 3 |
2 files changed, 83 insertions, 36 deletions
diff --git a/noncore/net/wellenreiter/gui/mainwindow.cpp b/noncore/net/wellenreiter/gui/mainwindow.cpp index 0ef89d4..9065351 100644 --- a/noncore/net/wellenreiter/gui/mainwindow.cpp +++ b/noncore/net/wellenreiter/gui/mainwindow.cpp | |||
@@ -10,44 +10,47 @@ | |||
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | **********************************************************************/ | 14 | **********************************************************************/ |
15 | 15 | ||
16 | #include "configwindow.h" | 16 | #include "configwindow.h" |
17 | #include "logwindow.h" | 17 | #include "logwindow.h" |
18 | #include "mainwindow.h" | 18 | #include "mainwindow.h" |
19 | #include "wellenreiter.h" | 19 | #include "wellenreiter.h" |
20 | 20 | ||
21 | #include "scanlist.h" | 21 | #include "scanlist.h" |
22 | 22 | ||
23 | #include <qcombobox.h> | 23 | #include <qcombobox.h> |
24 | #include <qdatastream.h> | 24 | #include <qdatastream.h> |
25 | #include <qfile.h> | 25 | #include <qfile.h> |
26 | #include <qfileinfo.h> | ||
26 | #include <qiconset.h> | 27 | #include <qiconset.h> |
27 | #include <qmenubar.h> | 28 | #include <qmenubar.h> |
28 | #include <qmessagebox.h> | 29 | #include <qmessagebox.h> |
29 | #include <qpopupmenu.h> | 30 | #include <qpopupmenu.h> |
30 | #include <qstatusbar.h> | 31 | #include <qstatusbar.h> |
31 | #include <qtextstream.h> | 32 | #include <qtextstream.h> |
32 | #include <qtoolbutton.h> | 33 | #include <qtoolbutton.h> |
33 | 34 | ||
34 | #ifdef QWS | 35 | #ifdef QWS |
35 | #include <qpe/resource.h> | 36 | #include <qpe/resource.h> |
37 | #include <opie/ofiledialog.h> | ||
36 | #else | 38 | #else |
37 | #include "resource.h" | 39 | #include "resource.h" |
40 | #include <qfiledialog.h> | ||
38 | #endif | 41 | #endif |
39 | 42 | ||
40 | WellenreiterMainWindow::WellenreiterMainWindow( QWidget * parent, const char * name, WFlags f ) | 43 | WellenreiterMainWindow::WellenreiterMainWindow( QWidget * parent, const char * name, WFlags f ) |
41 | :QMainWindow( parent, name, f ) | 44 | :QMainWindow( parent, name, f ) |
42 | { | 45 | { |
43 | cw = new WellenreiterConfigWindow( this ); | 46 | cw = new WellenreiterConfigWindow( this ); |
44 | mw = new Wellenreiter( this ); | 47 | mw = new Wellenreiter( this ); |
45 | mw->setConfigWindow( cw ); | 48 | mw->setConfigWindow( cw ); |
46 | setCentralWidget( mw ); | 49 | setCentralWidget( mw ); |
47 | 50 | ||
48 | // setup application icon | 51 | // setup application icon |
49 | 52 | ||
50 | #ifndef QWS | 53 | #ifndef QWS |
51 | setIcon( Resource::loadPixmap( "wellenreiter/appicon-trans" ) ); | 54 | setIcon( Resource::loadPixmap( "wellenreiter/appicon-trans" ) ); |
52 | setIconText( "Wellenreiter/X11" ); | 55 | setIconText( "Wellenreiter/X11" ); |
53 | #endif | 56 | #endif |
@@ -89,37 +92,37 @@ WellenreiterMainWindow::WellenreiterMainWindow( QWidget * parent, const char * n | |||
89 | c->setEnabled( false ); | 92 | c->setEnabled( false ); |
90 | 93 | ||
91 | QToolButton* d = new QToolButton( 0 ); | 94 | QToolButton* d = new QToolButton( 0 ); |
92 | #ifdef QWS | 95 | #ifdef QWS |
93 | d->setAutoRaise( true ); | 96 | d->setAutoRaise( true ); |
94 | #endif | 97 | #endif |
95 | d->setIconSet( *settingsIconSet ); | 98 | d->setIconSet( *settingsIconSet ); |
96 | connect( d, SIGNAL( clicked() ), this, SLOT( showConfigure() ) ); | 99 | connect( d, SIGNAL( clicked() ), this, SLOT( showConfigure() ) ); |
97 | 100 | ||
98 | // setup menu bar | 101 | // setup menu bar |
99 | 102 | ||
100 | int id; | 103 | int id; |
101 | 104 | ||
102 | QMenuBar* mb = menuBar(); | 105 | QMenuBar* mb = menuBar(); |
103 | 106 | ||
104 | QPopupMenu* fileSave = new QPopupMenu( mb ); | 107 | QPopupMenu* fileSave = new QPopupMenu( mb ); |
105 | fileSave->insertItem( "&Session", this, SLOT( fileSaveSession() ) ); | 108 | fileSave->insertItem( "&Session...", this, SLOT( fileSaveSession() ) ); |
106 | fileSave->insertItem( "&Log", this, SLOT( fileSaveLog() ) ); | 109 | fileSave->insertItem( "&Log...", this, SLOT( fileSaveLog() ) ); |
107 | 110 | ||
108 | QPopupMenu* fileLoad = new QPopupMenu( mb ); | 111 | QPopupMenu* fileLoad = new QPopupMenu( mb ); |
109 | fileLoad->insertItem( "&Session", this, SLOT( fileLoadSession() ) ); | 112 | fileLoad->insertItem( "&Session...", this, SLOT( fileLoadSession() ) ); |
110 | //fileLoad->insertItem( "&Log", this, SLOT( fileLoadLog() ) ); | 113 | //fileLoad->insertItem( "&Log", this, SLOT( fileLoadLog() ) ); |
111 | 114 | ||
112 | QPopupMenu* file = new QPopupMenu( mb ); | 115 | QPopupMenu* file = new QPopupMenu( mb ); |
113 | id = file->insertItem( "&Load", fileLoad ); | 116 | id = file->insertItem( "&Load", fileLoad ); |
114 | file->insertItem( "&Save", fileSave ); | 117 | file->insertItem( "&Save", fileSave ); |
115 | 118 | ||
116 | QPopupMenu* view = new QPopupMenu( mb ); | 119 | QPopupMenu* view = new QPopupMenu( mb ); |
117 | view->insertItem( "&Configure..." ); | 120 | view->insertItem( "&Configure..." ); |
118 | 121 | ||
119 | QPopupMenu* sniffer = new QPopupMenu( mb ); | 122 | QPopupMenu* sniffer = new QPopupMenu( mb ); |
120 | sniffer->insertItem( "&Configure..." ); | 123 | sniffer->insertItem( "&Configure..." ); |
121 | sniffer->insertSeparator(); | 124 | sniffer->insertSeparator(); |
122 | 125 | ||
123 | QPopupMenu* demo = new QPopupMenu( mb ); | 126 | QPopupMenu* demo = new QPopupMenu( mb ); |
124 | demo->insertItem( "&Add something", this, SLOT( demoAddStations() ) ); | 127 | demo->insertItem( "&Add something", this, SLOT( demoAddStations() ) ); |
125 | 128 | ||
@@ -185,82 +188,123 @@ WellenreiterMainWindow::~WellenreiterMainWindow() | |||
185 | delete cancelIconSet; | 188 | delete cancelIconSet; |
186 | #else | 189 | #else |
187 | delete startStopIconSet; | 190 | delete startStopIconSet; |
188 | #endif | 191 | #endif |
189 | 192 | ||
190 | }; | 193 | }; |
191 | 194 | ||
192 | void WellenreiterMainWindow::demoAddStations() | 195 | void WellenreiterMainWindow::demoAddStations() |
193 | { | 196 | { |
194 | mw->netView()->addNewItem( "managed", "Vanille", "00:00:20:EF:A6:43", true, 6, 80 ); | 197 | mw->netView()->addNewItem( "managed", "Vanille", "00:00:20:EF:A6:43", true, 6, 80 ); |
195 | mw->netView()->addNewItem( "managed", "Vanille", "00:30:6D:EF:A6:23", true, 11, 10 ); | 198 | mw->netView()->addNewItem( "managed", "Vanille", "00:30:6D:EF:A6:23", true, 11, 10 ); |
196 | mw->netView()->addNewItem( "adhoc", "ELAN", "00:A0:F8:E7:16:22", false, 3, 10 ); | 199 | mw->netView()->addNewItem( "adhoc", "ELAN", "00:A0:F8:E7:16:22", false, 3, 10 ); |
197 | mw->netView()->addNewItem( "adhoc", "ELAN", "00:AA:01:E7:56:62", false, 3, 15 ); | 200 | mw->netView()->addNewItem( "adhoc", "ELAN", "00:AA:01:E7:56:62", false, 3, 15 ); |
198 | mw->netView()->addNewItem( "adhoc", "ELAN", "00:B0:8E:E7:56:E2", false, 3, 20 ); | 201 | mw->netView()->addNewItem( "adhoc", "ELAN", "00:B0:8E:E7:56:E2", false, 3, 20 ); |
199 | } | 202 | } |
200 | 203 | ||
201 | void WellenreiterMainWindow::fileSaveLog() | 204 | QString WellenreiterMainWindow::getFileName( bool save ) |
202 | { | 205 | { |
203 | const QString fname( "/tmp/log.txt" ); | 206 | QMap<QString, QStringList> map; |
204 | QFile f( fname ); | 207 | map.insert( tr("All"), QStringList() ); |
205 | if ( f.open(IO_WriteOnly) ) | 208 | QStringList text; |
209 | text << "text/*"; | ||
210 | map.insert(tr("Text"), text ); | ||
211 | text << "*"; | ||
212 | map.insert(tr("All"), text ); | ||
213 | |||
214 | QString str; | ||
215 | if ( save ) | ||
206 | { | 216 | { |
207 | QTextStream t( &f ); | 217 | #ifdef QWS |
208 | t << mw->logWindow()->getLog(); | 218 | str = OFileDialog::getSaveFileName( 2, "/", QString::null, map ); |
209 | f.close(); | 219 | #else |
210 | qDebug( "Saved log to file '%s'", (const char*) fname ); | 220 | str = QFileDialog::getSaveFileName(); |
221 | #endif | ||
222 | if ( str.isEmpty() || QFileInfo(str).isDir() ) | ||
223 | return ""; | ||
211 | } | 224 | } |
212 | else | 225 | else |
213 | { | 226 | { |
214 | qDebug( "Problem saving log to file '%s'", (const char*) fname ); | 227 | #ifdef QWS |
228 | str = OFileDialog::getOpenFileName( 2, "/", QString::null, map ); | ||
229 | #else | ||
230 | str = QFileDialog::getOpenFileName(); | ||
231 | #endif | ||
232 | if ( str.isEmpty() || !QFile(str).exists() || QFileInfo(str).isDir() ) | ||
233 | return ""; | ||
215 | } | 234 | } |
216 | 235 | return str; | |
217 | } | 236 | } |
218 | 237 | ||
219 | void WellenreiterMainWindow::fileSaveSession() | 238 | void WellenreiterMainWindow::fileSaveLog() |
220 | { | 239 | { |
221 | const QString fname( "/tmp/session.xml" ); | 240 | QString fname = getFileName( true ); |
222 | QFile f( fname ); | 241 | if ( !fname.isEmpty() ) |
223 | if ( f.open(IO_WriteOnly) ) | ||
224 | { | 242 | { |
225 | QDataStream t( &f ); | 243 | QFile f( fname ); |
226 | t << *mw->netView(); | 244 | if ( f.open(IO_WriteOnly) ) |
227 | f.close(); | 245 | { |
228 | qDebug( "Saved session to file '%s'", (const char*) fname ); | 246 | QTextStream t( &f ); |
247 | t << mw->logWindow()->getLog(); | ||
248 | f.close(); | ||
249 | qDebug( "Saved log to file '%s'", (const char*) fname ); | ||
250 | } | ||
251 | else | ||
252 | { | ||
253 | qDebug( "Problem saving log to file '%s'", (const char*) fname ); | ||
254 | } | ||
229 | } | 255 | } |
230 | else | 256 | } |
257 | |||
258 | void WellenreiterMainWindow::fileSaveSession() | ||
259 | { | ||
260 | QString fname = getFileName( true ); | ||
261 | if ( !fname.isEmpty() ) | ||
231 | { | 262 | { |
232 | qDebug( "Problem saving session to file '%s'", (const char*) fname ); | 263 | |
264 | QFile f( fname ); | ||
265 | if ( f.open(IO_WriteOnly) ) | ||
266 | { | ||
267 | QDataStream t( &f ); | ||
268 | t << *mw->netView(); | ||
269 | f.close(); | ||
270 | qDebug( "Saved session to file '%s'", (const char*) fname ); | ||
271 | } | ||
272 | else | ||
273 | { | ||
274 | qDebug( "Problem saving session to file '%s'", (const char*) fname ); | ||
275 | } | ||
233 | } | 276 | } |
234 | } | 277 | } |
235 | 278 | ||
236 | void WellenreiterMainWindow::fileLoadSession() | 279 | void WellenreiterMainWindow::fileLoadSession() |
237 | { | 280 | { |
238 | const QString fname( "/tmp/session.xml" ); | 281 | QString fname = getFileName( false ); |
239 | QFile f( fname ); | 282 | if ( !fname.isEmpty() ) |
240 | |||
241 | if ( f.open(IO_ReadOnly) ) | ||
242 | { | 283 | { |
243 | QDataStream t( &f ); | 284 | QFile f( fname ); |
244 | t >> *mw->netView(); | 285 | if ( f.open(IO_ReadOnly) ) |
245 | f.close(); | 286 | { |
246 | qDebug( "Loaded session from file '%s'", (const char*) fname ); | 287 | QDataStream t( &f ); |
247 | } | 288 | t >> *mw->netView(); |
248 | else | 289 | f.close(); |
249 | { | 290 | qDebug( "Loaded session from file '%s'", (const char*) fname ); |
250 | qDebug( "Problem loading session from file '%s'", (const char*) fname ); | 291 | } |
292 | else | ||
293 | { | ||
294 | qDebug( "Problem loading session from file '%s'", (const char*) fname ); | ||
295 | } | ||
251 | } | 296 | } |
252 | |||
253 | } | 297 | } |
254 | 298 | ||
255 | void WellenreiterMainWindow::closeEvent( QCloseEvent* e ) | 299 | void WellenreiterMainWindow::closeEvent( QCloseEvent* e ) |
256 | { | 300 | { |
257 | if ( mw->isDaemonRunning() ) | 301 | if ( mw->isDaemonRunning() ) |
258 | { | 302 | { |
259 | QMessageBox::warning( this, "Wellenreiter/Opie", "Sniffing in progress!\nPlease stop sniffing before closing." ); | 303 | QMessageBox::warning( this, "Wellenreiter/Opie", "Sniffing in progress!\nPlease stop sniffing before closing." ); |
260 | e->ignore(); | 304 | e->ignore(); |
261 | } | 305 | } |
262 | else | 306 | else |
263 | { | 307 | { |
264 | QMainWindow::closeEvent( e ); | 308 | QMainWindow::closeEvent( e ); |
265 | } | 309 | } |
266 | } | 310 | } |
diff --git a/noncore/net/wellenreiter/gui/mainwindow.h b/noncore/net/wellenreiter/gui/mainwindow.h index 59f259d..850a343 100644 --- a/noncore/net/wellenreiter/gui/mainwindow.h +++ b/noncore/net/wellenreiter/gui/mainwindow.h | |||
@@ -33,25 +33,28 @@ class WellenreiterMainWindow: public QMainWindow | |||
33 | 33 | ||
34 | protected: | 34 | protected: |
35 | Wellenreiter* mw; | 35 | Wellenreiter* mw; |
36 | WellenreiterConfigWindow* cw; | 36 | WellenreiterConfigWindow* cw; |
37 | 37 | ||
38 | QIconSet* startStopIconSet; | 38 | QIconSet* startStopIconSet; |
39 | const QIconSet* searchIconSet; | 39 | const QIconSet* searchIconSet; |
40 | const QIconSet* infoIconSet; | 40 | const QIconSet* infoIconSet; |
41 | const QIconSet* settingsIconSet; | 41 | const QIconSet* settingsIconSet; |
42 | const QIconSet* cancelIconSet; | 42 | const QIconSet* cancelIconSet; |
43 | 43 | ||
44 | QToolButton* startStopButton; | 44 | QToolButton* startStopButton; |
45 | 45 | ||
46 | protected: | 46 | protected: |
47 | virtual void closeEvent( QCloseEvent* ); | 47 | virtual void closeEvent( QCloseEvent* ); |
48 | 48 | ||
49 | private: | ||
50 | QString getFileName( bool save ); | ||
51 | |||
49 | public slots: | 52 | public slots: |
50 | void showConfigure(); | 53 | void showConfigure(); |
51 | void demoAddStations(); | 54 | void demoAddStations(); |
52 | void fileSaveLog(); | 55 | void fileSaveLog(); |
53 | void fileSaveSession(); | 56 | void fileSaveSession(); |
54 | void fileLoadSession(); | 57 | void fileLoadSession(); |
55 | }; | 58 | }; |
56 | 59 | ||
57 | #endif | 60 | #endif |