summaryrefslogtreecommitdiff
authormickeyl <mickeyl>2003-03-02 18:59:21 (UTC)
committer mickeyl <mickeyl>2003-03-02 18:59:21 (UTC)
commit6657040ae54afb2f2378f4db7bfc9e616e6d7b83 (patch) (unidiff)
tree96617a7e6664c71c20f8ec9bd6a4cca779d54dea
parente1761268c8820ff24dcb73dbcd4b82bc1e1e34a1 (diff)
downloadopie-6657040ae54afb2f2378f4db7bfc9e616e6d7b83.zip
opie-6657040ae54afb2f2378f4db7bfc9e616e6d7b83.tar.gz
opie-6657040ae54afb2f2378f4db7bfc9e616e6d7b83.tar.bz2
use filedialogs before loading and saving sessions and logs
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/wellenreiter/gui/mainwindow.cpp116
-rw-r--r--noncore/net/wellenreiter/gui/mainwindow.h3
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
@@ -23,6 +23,7 @@
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>
@@ -33,8 +34,10 @@
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
40WellenreiterMainWindow::WellenreiterMainWindow( QWidget * parent, const char * name, WFlags f ) 43WellenreiterMainWindow::WellenreiterMainWindow( QWidget * parent, const char * name, WFlags f )
@@ -102,11 +105,11 @@ WellenreiterMainWindow::WellenreiterMainWindow( QWidget * parent, const char * n
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 );
@@ -198,58 +201,99 @@ void WellenreiterMainWindow::demoAddStations()
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
201void WellenreiterMainWindow::fileSaveLog() 204QString 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
219void WellenreiterMainWindow::fileSaveSession() 238void 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
258void 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
236void WellenreiterMainWindow::fileLoadSession() 279void 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
255void WellenreiterMainWindow::closeEvent( QCloseEvent* e ) 299void WellenreiterMainWindow::closeEvent( QCloseEvent* e )
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
@@ -46,6 +46,9 @@ class WellenreiterMainWindow: public QMainWindow
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();