summaryrefslogtreecommitdiff
path: root/libopie/ofiledialog.cc
Unidiff
Diffstat (limited to 'libopie/ofiledialog.cc') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/ofiledialog.cc81
1 files changed, 70 insertions, 11 deletions
diff --git a/libopie/ofiledialog.cc b/libopie/ofiledialog.cc
index 9e725c2..5511b24 100644
--- a/libopie/ofiledialog.cc
+++ b/libopie/ofiledialog.cc
@@ -2,3 +2,3 @@
2               =. This file is part of the OPIE Project 2               =. This file is part of the OPIE Project
3             .=l. Copyright (c) 2002 <> 3             .=l. Copyright (c) 2002,2003 <zecke@handhelds.org>
4           .>+-= 4           .>+-=
@@ -29,2 +29,6 @@
29#include <qpe/applnk.h> 29#include <qpe/applnk.h>
30#include <qpe/config.h>
31#include <qpe/qpeapplication.h>
32
33#include <qfileinfo.h>
30#include <qstring.h> 34#include <qstring.h>
@@ -33,4 +37,36 @@
33 37
38
34#include "ofiledialog.h" 39#include "ofiledialog.h"
35 40
41
42namespace {
43 /*
44 * helper functions to load the start dir
45 * and to save it
46 * helper to extract the dir out of a file name
47 */
48 /**
49 * This method will use Config( argv[0] );
50 * @param key The group key used
51 */
52 QString lastUsedDir( const QString& key ) {
53 if ( qApp->argc() < 1 )
54 return QString::null;
55
56 Config cfg( QFileInfo(qApp->argv()[0]).fileName() ); // appname
57 cfg.setGroup( key );
58 return cfg.readEntry("LastDir", QPEApplication::documentDir() );
59 }
60
61 void saveLastDir( const QString& key, const QString& file ) {
62 if ( qApp->argc() < 1 )
63 return;
64
65 Config cfg( QFileInfo(qApp->argv()[0]).fileName() );
66 cfg.setGroup( key );
67 QFileInfo inf( file );
68 cfg.writeEntry("LastDir", inf.dirPath( true ) );
69 }
70};
71
36/** 72/**
@@ -66,8 +102,11 @@ OFileDialog::OFileDialog(const QString &caption,
66 this, SLOT(slotFileSelected(const QString&) ) ); 102 this, SLOT(slotFileSelected(const QString&) ) );
103 connect(file, SIGNAL(ok() ),
104 this, SLOT(slotSelectorOk()) ) ;
67 105
106 connect(file, SIGNAL(dirSelected(const QString&) ), this, SLOT(slotDirSelected(const QString&) ) );
107
108#if 0
68 connect(file, SIGNAL(dirSelected(const QString &) ), 109 connect(file, SIGNAL(dirSelected(const QString &) ),
69 this, SLOT(slotDirSelected(const QString &) ) ); 110 this, SLOT(slotDirSelected(const QString &) ) );
70 111#endif
71
72 file->setYesCancelVisible( false ); // relayout
73} 112}
@@ -110,3 +149,3 @@ DocLnk OFileDialog::selectedDocument()const
110QString OFileDialog::getOpenFileName(int selector, 149QString OFileDialog::getOpenFileName(int selector,
111 const QString &startDir, 150 const QString &_startDir,
112 const QString &file, 151 const QString &file,
@@ -117,7 +156,14 @@ QString OFileDialog::getOpenFileName(int selector,
117 QString ret; 156 QString ret;
157 QString startDir = _startDir;
158 if (startDir.isEmpty() )
159 startDir = lastUsedDir( "FileDialog-OPEN" );
160
161
118 OFileDialog dlg( caption.isEmpty() ? tr("Open") : caption, 162 OFileDialog dlg( caption.isEmpty() ? tr("Open") : caption,
119 wid, OFileSelector::OPEN, selector, startDir, file, mimes); 163 wid, OFileSelector::Open, selector, startDir, file, mimes);
120 dlg.showMaximized(); 164 dlg.showMaximized();
121 if( dlg.exec() ) 165 if( dlg.exec() ) {
122 ret = dlg.fileName(); 166 ret = dlg.fileName();
167 saveLastDir( "FileDialog-OPEN", ret );
168 }
123 169
@@ -131,3 +177,3 @@ QString OFileDialog::getOpenFileName(int selector,
131QString OFileDialog::getSaveFileName(int selector, 177QString OFileDialog::getSaveFileName(int selector,
132 const QString &startDir, 178 const QString &_startDir,
133 const QString &file, 179 const QString &file,
@@ -138,7 +184,13 @@ QString OFileDialog::getSaveFileName(int selector,
138 QString ret; 184 QString ret;
185 QString startDir = _startDir;
186 if (startDir.isEmpty() )
187 startDir = lastUsedDir( "FileDialog-SAVE" );
188
139 OFileDialog dlg( caption.isEmpty() ? tr("Save") : caption, 189 OFileDialog dlg( caption.isEmpty() ? tr("Save") : caption,
140 wid, OFileSelector::SAVE, selector, startDir, file, mimes); 190 wid, OFileSelector::Save, selector, startDir, file, mimes);
141 dlg.showMaximized(); 191 dlg.showMaximized();
142 if( dlg.exec() ) 192 if( dlg.exec() ) {
143 ret = dlg.fileName(); 193 ret = dlg.fileName();
194 saveLastDir( "FileDialog-SAVE", ret );
195 }
144 196
@@ -151,4 +203,11 @@ void OFileDialog::slotFileSelected(const QString & )
151} 203}
152void OFileDialog::slotDirSelected(const QString & ) 204
205void OFileDialog::slotSelectorOk( )
206{
207 accept();
208}
209
210void OFileDialog::slotDirSelected(const QString &dir )
153{ 211{
212 setCaption( dir );
154 // if mode 213 // if mode