author | mickeyl <mickeyl> | 2003-03-02 18:59:21 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2003-03-02 18:59:21 (UTC) |
commit | 6657040ae54afb2f2378f4db7bfc9e616e6d7b83 (patch) (unidiff) | |
tree | 96617a7e6664c71c20f8ec9bd6a4cca779d54dea | |
parent | e1761268c8820ff24dcb73dbcd4b82bc1e1e34a1 (diff) | |
download | opie-6657040ae54afb2f2378f4db7bfc9e616e6d7b83.zip opie-6657040ae54afb2f2378f4db7bfc9e616e6d7b83.tar.gz opie-6657040ae54afb2f2378f4db7bfc9e616e6d7b83.tar.bz2 |
use filedialogs before loading and saving sessions and logs
-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 | |||
@@ -25,2 +25,3 @@ | |||
25 | #include <qfile.h> | 25 | #include <qfile.h> |
26 | #include <qfileinfo.h> | ||
26 | #include <qiconset.h> | 27 | #include <qiconset.h> |
@@ -35,4 +36,6 @@ | |||
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 |
@@ -104,7 +107,7 @@ WellenreiterMainWindow::WellenreiterMainWindow( QWidget * parent, const char * n | |||
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() ) ); |
@@ -200,12 +203,22 @@ void WellenreiterMainWindow::demoAddStations() | |||
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 | } |
@@ -213,21 +226,51 @@ void WellenreiterMainWindow::fileSaveLog() | |||
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 | } |
@@ -237,17 +280,18 @@ 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 | } |
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 | |||
@@ -48,2 +48,5 @@ class WellenreiterMainWindow: public QMainWindow | |||
48 | 48 | ||
49 | private: | ||
50 | QString getFileName( bool save ); | ||
51 | |||
49 | public slots: | 52 | public slots: |