summaryrefslogtreecommitdiff
Side-by-side diff
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
@@ -22,8 +22,9 @@
#include <qcombobox.h>
#include <qdatastream.h>
#include <qfile.h>
+#include <qfileinfo.h>
#include <qiconset.h>
#include <qmenubar.h>
#include <qmessagebox.h>
#include <qpopupmenu.h>
@@ -32,10 +33,12 @@
#include <qtoolbutton.h>
#ifdef QWS
#include <qpe/resource.h>
+#include <opie/ofiledialog.h>
#else
#include "resource.h"
+#include <qfiledialog.h>
#endif
WellenreiterMainWindow::WellenreiterMainWindow( QWidget * parent, const char * name, WFlags f )
:QMainWindow( parent, name, f )
@@ -101,13 +104,13 @@ WellenreiterMainWindow::WellenreiterMainWindow( QWidget * parent, const char * n
QMenuBar* mb = menuBar();
QPopupMenu* fileSave = new QPopupMenu( mb );
- fileSave->insertItem( "&Session", this, SLOT( fileSaveSession() ) );
- fileSave->insertItem( "&Log", this, SLOT( fileSaveLog() ) );
+ fileSave->insertItem( "&Session...", this, SLOT( fileSaveSession() ) );
+ fileSave->insertItem( "&Log...", this, SLOT( fileSaveLog() ) );
QPopupMenu* fileLoad = new QPopupMenu( mb );
- fileLoad->insertItem( "&Session", this, SLOT( fileLoadSession() ) );
+ fileLoad->insertItem( "&Session...", this, SLOT( fileLoadSession() ) );
//fileLoad->insertItem( "&Log", this, SLOT( fileLoadLog() ) );
QPopupMenu* file = new QPopupMenu( mb );
id = file->insertItem( "&Load", fileLoad );
@@ -197,60 +200,101 @@ void WellenreiterMainWindow::demoAddStations()
mw->netView()->addNewItem( "adhoc", "ELAN", "00:AA:01:E7:56:62", false, 3, 15 );
mw->netView()->addNewItem( "adhoc", "ELAN", "00:B0:8E:E7:56:E2", false, 3, 20 );
}
-void WellenreiterMainWindow::fileSaveLog()
+QString WellenreiterMainWindow::getFileName( bool save )
{
- const QString fname( "/tmp/log.txt" );
- QFile f( fname );
- if ( f.open(IO_WriteOnly) )
+ QMap<QString, QStringList> map;
+ map.insert( tr("All"), QStringList() );
+ QStringList text;
+ text << "text/*";
+ map.insert(tr("Text"), text );
+ text << "*";
+ map.insert(tr("All"), text );
+
+ QString str;
+ if ( save )
{
- QTextStream t( &f );
- t << mw->logWindow()->getLog();
- f.close();
- qDebug( "Saved log to file '%s'", (const char*) fname );
+ #ifdef QWS
+ str = OFileDialog::getSaveFileName( 2, "/", QString::null, map );
+ #else
+ str = QFileDialog::getSaveFileName();
+ #endif
+ if ( str.isEmpty() || QFileInfo(str).isDir() )
+ return "";
}
else
{
- qDebug( "Problem saving log to file '%s'", (const char*) fname );
+ #ifdef QWS
+ str = OFileDialog::getOpenFileName( 2, "/", QString::null, map );
+ #else
+ str = QFileDialog::getOpenFileName();
+ #endif
+ if ( str.isEmpty() || !QFile(str).exists() || QFileInfo(str).isDir() )
+ return "";
}
-
+ return str;
}
-void WellenreiterMainWindow::fileSaveSession()
+void WellenreiterMainWindow::fileSaveLog()
{
- const QString fname( "/tmp/session.xml" );
- QFile f( fname );
- if ( f.open(IO_WriteOnly) )
+ QString fname = getFileName( true );
+ if ( !fname.isEmpty() )
{
- QDataStream t( &f );
- t << *mw->netView();
- f.close();
- qDebug( "Saved session to file '%s'", (const char*) fname );
+ QFile f( fname );
+ if ( f.open(IO_WriteOnly) )
+ {
+ QTextStream t( &f );
+ t << mw->logWindow()->getLog();
+ f.close();
+ qDebug( "Saved log to file '%s'", (const char*) fname );
+ }
+ else
+ {
+ qDebug( "Problem saving log to file '%s'", (const char*) fname );
+ }
}
- else
+}
+
+void WellenreiterMainWindow::fileSaveSession()
+{
+ QString fname = getFileName( true );
+ if ( !fname.isEmpty() )
{
- qDebug( "Problem saving session to file '%s'", (const char*) fname );
+
+ QFile f( fname );
+ if ( f.open(IO_WriteOnly) )
+ {
+ QDataStream t( &f );
+ t << *mw->netView();
+ f.close();
+ qDebug( "Saved session to file '%s'", (const char*) fname );
+ }
+ else
+ {
+ qDebug( "Problem saving session to file '%s'", (const char*) fname );
+ }
}
}
void WellenreiterMainWindow::fileLoadSession()
{
- const QString fname( "/tmp/session.xml" );
- QFile f( fname );
-
- if ( f.open(IO_ReadOnly) )
+ QString fname = getFileName( false );
+ if ( !fname.isEmpty() )
{
- QDataStream t( &f );
- t >> *mw->netView();
- f.close();
- qDebug( "Loaded session from file '%s'", (const char*) fname );
- }
- else
- {
- qDebug( "Problem loading session from file '%s'", (const char*) fname );
+ QFile f( fname );
+ if ( f.open(IO_ReadOnly) )
+ {
+ QDataStream t( &f );
+ t >> *mw->netView();
+ f.close();
+ qDebug( "Loaded session from file '%s'", (const char*) fname );
+ }
+ else
+ {
+ qDebug( "Problem loading session from file '%s'", (const char*) fname );
+ }
}
-
}
void 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
@@ -45,8 +45,11 @@ class WellenreiterMainWindow: public QMainWindow
protected:
virtual void closeEvent( QCloseEvent* );
+ private:
+ QString getFileName( bool save );
+
public slots:
void showConfigure();
void demoAddStations();
void fileSaveLog();