summaryrefslogtreecommitdiff
path: root/libopie/ofiledialog.cc
authoreilers <eilers>2003-08-08 15:09:29 (UTC)
committer eilers <eilers>2003-08-08 15:09:29 (UTC)
commitb87b33dc1f6e8e1276a7035ab7a3e53b8ed4bd16 (patch) (unidiff)
treeb0f96db67cfb1b9d2476530ecec9a2ba6eacbab1 /libopie/ofiledialog.cc
parent14d394e6c107b037a09a31a92605034fe50f7813 (diff)
downloadopie-b87b33dc1f6e8e1276a7035ab7a3e53b8ed4bd16.zip
opie-b87b33dc1f6e8e1276a7035ab7a3e53b8ed4bd16.tar.gz
opie-b87b33dc1f6e8e1276a7035ab7a3e53b8ed4bd16.tar.bz2
Merging all changes from BRANCH_1_0.
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
@@ -1,6 +1,6 @@
1/* 1/*
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           .>+-=
5 _;:,     .>    :=|. This library is free software; you can 5 _;:,     .>    :=|. This library is free software; you can
6.> <`_,   >  .   <= redistribute it and/or modify it under 6.> <`_,   >  .   <= redistribute it and/or modify it under
@@ -27,12 +27,48 @@
27*/ 27*/
28 28
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>
31#include <qapplication.h> 35#include <qapplication.h>
32#include <qlayout.h> 36#include <qlayout.h>
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/**
37 * This constructs a modal dialog 73 * This constructs a modal dialog
38 * 74 *
@@ -64,12 +100,15 @@ OFileDialog::OFileDialog(const QString &caption,
64 setCaption( caption.isEmpty() ? tr("FileDialog") : caption ); 100 setCaption( caption.isEmpty() ? tr("FileDialog") : caption );
65 connect(file, SIGNAL(fileSelected(const QString&) ), 101 connect(file, SIGNAL(fileSelected(const QString&) ),
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}
74/** 113/**
75 * @returns the mimetype of the selected 114 * @returns the mimetype of the selected
@@ -108,18 +147,25 @@ DocLnk OFileDialog::selectedDocument()const
108 * @return the fileName or QString::null 147 * @return the fileName or QString::null
109 */ 148 */
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,
113 const MimeTypes &mimes, 152 const MimeTypes &mimes,
114 QWidget *wid, 153 QWidget *wid,
115 const QString &caption ) 154 const QString &caption )
116{ 155{
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
124 return ret; 170 return ret;
125} 171}
@@ -129,18 +175,24 @@ QString OFileDialog::getOpenFileName(int selector,
129 * @see getOpenFileName 175 * @see getOpenFileName
130 */ 176 */
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,
134 const MimeTypes &mimes, 180 const MimeTypes &mimes,
135 QWidget *wid, 181 QWidget *wid,
136 const QString &caption ) 182 const QString &caption )
137{ 183{
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
145 return ret; 197 return ret;
146} 198}
@@ -149,8 +201,15 @@ void OFileDialog::slotFileSelected(const QString & )
149{ 201{
150 accept(); 202 accept();
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
155 //accept(); 214 //accept();
156} 215}