-rw-r--r-- | libopie2/opieui/fileselector/ofiledialog.cpp | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/libopie2/opieui/fileselector/ofiledialog.cpp b/libopie2/opieui/fileselector/ofiledialog.cpp index 65648ce..92d4271 100644 --- a/libopie2/opieui/fileselector/ofiledialog.cpp +++ b/libopie2/opieui/fileselector/ofiledialog.cpp | |||
@@ -1,249 +1,258 @@ | |||
1 | /* | 1 | /* |
2 | =. This file is part of the OPIE Project | 2 | =. This file is part of the OPIE Project |
3 | .=l. Copyright (C) Holger Freyther <freyther@handhelds.org> | 3 | .=l. Copyright (C) Holger Freyther <freyther@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 |
7 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 7 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
8 | .="- .-=="i, .._ License as published by the Free Software | 8 | .="- .-=="i, .._ License as published by the Free Software |
9 | - . .-<_> .<> Foundation; either version 2 of the License, | 9 | - . .-<_> .<> Foundation; either version 2 of the License, |
10 | ._= =} : or (at your option) any later version. | 10 | ._= =} : or (at your option) any later version. |
11 | .%`+i> _;_. | 11 | .%`+i> _;_. |
12 | .i_,=:_. -<s. This library is distributed in the hope that | 12 | .i_,=:_. -<s. This library is distributed in the hope that |
13 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 13 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
14 | : .. .:, . . . without even the implied warranty of | 14 | : .. .:, . . . without even the implied warranty of |
15 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 15 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
16 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 16 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
17 | ..}^=.= = ; Library General Public License for more | 17 | ..}^=.= = ; Library General Public License for more |
18 | ++= -. .` .: details. | 18 | ++= -. .` .: details. |
19 | : = ...= . :.=- | 19 | : = ...= . :.=- |
20 | -. .:....=;==+<; You should have received a copy of the GNU | 20 | -. .:....=;==+<; You should have received a copy of the GNU |
21 | -_. . . )=. = Library General Public License along with | 21 | -_. . . )=. = Library General Public License along with |
22 | -- :-=` this library; see the file COPYING.LIB. | 22 | -- :-=` this library; see the file COPYING.LIB. |
23 | If not, write to the Free Software Foundation, | 23 | If not, write to the Free Software Foundation, |
24 | Inc., 59 Temple Place - Suite 330, | 24 | Inc., 59 Temple Place - Suite 330, |
25 | Boston, MA 02111-1307, USA. | 25 | Boston, MA 02111-1307, USA. |
26 | 26 | ||
27 | */ | 27 | */ |
28 | 28 | ||
29 | 29 | ||
30 | /* OPIE */ | 30 | /* OPIE */ |
31 | #include <opie2/ofiledialog.h> | 31 | #include <opie2/ofiledialog.h> |
32 | #include <qpe/applnk.h> | 32 | #include <qpe/applnk.h> |
33 | #include <qpe/config.h> | 33 | #include <qpe/config.h> |
34 | #include <qpe/qpeapplication.h> | 34 | #include <qpe/qpeapplication.h> |
35 | 35 | ||
36 | /* QT */ | 36 | /* QT */ |
37 | #include <qfileinfo.h> | 37 | #include <qfileinfo.h> |
38 | #include <qstring.h> | 38 | #include <qstring.h> |
39 | #include <qapplication.h> | 39 | #include <qapplication.h> |
40 | #include <qlayout.h> | 40 | #include <qlayout.h> |
41 | 41 | ||
42 | 42 | ||
43 | /* TRANSLATOR Opie::Ui::OFileDialog */ | 43 | /* TRANSLATOR Opie::Ui::OFileDialog */ |
44 | 44 | ||
45 | using namespace Opie::Ui; | 45 | using namespace Opie::Ui; |
46 | 46 | ||
47 | namespace | 47 | namespace |
48 | { | 48 | { |
49 | /* | 49 | /* |
50 | * helper functions to load the start dir | 50 | * helper functions to load the start dir |
51 | * and to save it | 51 | * and to save it |
52 | * helper to extract the dir out of a file name | 52 | * helper to extract the dir out of a file name |
53 | */ | 53 | */ |
54 | /** | 54 | /** |
55 | * This method will use Config( argv[0] ); | 55 | * This method will use Config( argv[0] ); |
56 | * @param key The group key used | 56 | * @param key The group key used |
57 | */ | 57 | */ |
58 | QString lastUsedDir( const QString& key ) | 58 | QString lastUsedDir( const QString& key ) |
59 | { | 59 | { |
60 | if ( qApp->argc() < 1 ) | 60 | if ( qApp->argc() < 1 ) |
61 | return QString::null; | 61 | return QString::null; |
62 | 62 | ||
63 | Config cfg( QFileInfo(qApp->argv()[0]).fileName() ); // appname | 63 | Config cfg( QFileInfo(qApp->argv()[0]).fileName() ); // appname |
64 | cfg.setGroup( key ); | 64 | cfg.setGroup( key ); |
65 | return cfg.readEntry("LastDir", QPEApplication::documentDir() ); | 65 | return cfg.readEntry("LastDir", QPEApplication::documentDir() ); |
66 | } | 66 | } |
67 | 67 | ||
68 | void saveLastDir( const QString& key, const QString& file ) | 68 | void saveLastDir( const QString& key, const QString& file ) |
69 | { | 69 | { |
70 | if ( qApp->argc() < 1 ) | 70 | if ( qApp->argc() < 1 ) |
71 | return; | 71 | return; |
72 | 72 | ||
73 | Config cfg( QFileInfo(qApp->argv()[0]).fileName() ); | 73 | Config cfg( QFileInfo(qApp->argv()[0]).fileName() ); |
74 | cfg.setGroup( key ); | 74 | cfg.setGroup( key ); |
75 | QFileInfo inf( file ); | 75 | QFileInfo inf( file ); |
76 | if ( inf.isFile() ) | 76 | if ( inf.isFile() ) |
77 | cfg.writeEntry("LastDir", inf.dirPath( true ) ); | 77 | cfg.writeEntry("LastDir", inf.dirPath( true ) ); |
78 | else | 78 | else |
79 | cfg.writeEntry("LastDir", file ); | 79 | cfg.writeEntry("LastDir", file ); |
80 | } | 80 | } |
81 | }; | 81 | }; |
82 | 82 | ||
83 | /** | 83 | /** |
84 | * This constructs a modal dialog | 84 | * This constructs a modal dialog |
85 | * | 85 | * |
86 | * @param caption The caption of the dialog | 86 | * @param caption The caption of the dialog |
87 | * @param wid The parent widget | 87 | * @param wid The parent widget |
88 | * @param mode The mode of the OFileSelector @see OFileSelector | 88 | * @param mode The mode of the OFileSelector @see OFileSelector |
89 | * @param selector The selector of the OFileSelector | 89 | * @param selector The selector of the OFileSelector |
90 | * @param dirName the dir or resource to start from | 90 | * @param dirName the dir or resource to start from |
91 | * @param fileName a proposed or existing filename | 91 | * @param fileName a proposed or existing filename |
92 | * @param mimetypes The mimeTypes | 92 | * @param mimetypes The mimeTypes |
93 | */ | 93 | */ |
94 | OFileDialog::OFileDialog(const QString &caption, | 94 | OFileDialog::OFileDialog(const QString &caption, |
95 | QWidget *wid, int mode, int selector, | 95 | QWidget *wid, int mode, int selector, |
96 | const QString &dirName, | 96 | const QString &dirName, |
97 | const QString &fileName, | 97 | const QString &fileName, |
98 | const QMap<QString,QStringList>& mimetypes ) | 98 | const QMap<QString,QStringList>& mimetypes ) |
99 | : QDialog( wid, "OFileDialog", true ) | 99 | : QDialog( wid, "OFileDialog", true ) |
100 | { | 100 | { |
101 | // QVBoxLayout *lay = new QVBoxLayout(this); | 101 | // QVBoxLayout *lay = new QVBoxLayout(this); |
102 | //showMaximized(); | 102 | //showMaximized(); |
103 | QVBoxLayout *lay = new QVBoxLayout(this ); | 103 | QVBoxLayout *lay = new QVBoxLayout(this ); |
104 | file = new OFileSelector(this , mode, selector, | 104 | file = new OFileSelector(this , mode, selector, |
105 | dirName, fileName, | 105 | dirName, fileName, |
106 | mimetypes ); | 106 | mimetypes ); |
107 | lay->addWidget( file ); | 107 | lay->addWidget( file ); |
108 | 108 | ||
109 | //lay->addWidget( file ); | 109 | //lay->addWidget( file ); |
110 | //showFullScreen(); | 110 | //showFullScreen(); |
111 | setCaption( caption.isEmpty() ? tr("FileDialog") : caption ); | 111 | setCaption( caption.isEmpty() ? tr("FileDialog") : caption ); |
112 | connect(file, SIGNAL(fileSelected(const QString&) ), | 112 | connect(file, SIGNAL(fileSelected(const QString&) ), |
113 | this, SLOT(slotFileSelected(const QString&) ) ); | 113 | this, SLOT(slotFileSelected(const QString&) ) ); |
114 | connect(file, SIGNAL(ok() ), | 114 | connect(file, SIGNAL(ok() ), |
115 | this, SLOT(slotSelectorOk()) ) ; | 115 | this, SLOT(slotSelectorOk()) ) ; |
116 | 116 | ||
117 | connect(file, SIGNAL(dirSelected(const QString&) ), this, SLOT(slotDirSelected(const QString&) ) ); | 117 | connect(file, SIGNAL(dirSelected(const QString&) ), this, SLOT(slotDirSelected(const QString&) ) ); |
118 | } | 118 | } |
119 | /** | 119 | /** |
120 | * @returns the mimetype of the selected | 120 | * @returns the mimetype of the selected |
121 | * currently it return QString::null | 121 | * currently it return QString::null |
122 | */ | 122 | */ |
123 | QString OFileDialog::mimetype()const | 123 | QString OFileDialog::mimetype()const |
124 | { | 124 | { |
125 | return QString::null; | 125 | return QString::null; |
126 | } | 126 | } |
127 | 127 | ||
128 | /** | 128 | /** |
129 | * @return the fileName | 129 | * @return the fileName |
130 | */ | 130 | */ |
131 | QString OFileDialog::fileName()const | 131 | QString OFileDialog::fileName()const |
132 | { | 132 | { |
133 | return file->selectedName(); | 133 | return file->selectedName(); |
134 | } | 134 | } |
135 | 135 | ||
136 | /** | 136 | /** |
137 | * return a DocLnk to the current file | 137 | * return a DocLnk to the current file |
138 | */ | 138 | */ |
139 | DocLnk OFileDialog::selectedDocument()const | 139 | DocLnk OFileDialog::selectedDocument()const |
140 | { | 140 | { |
141 | return file->selectedDocument(); | 141 | return file->selectedDocument(); |
142 | } | 142 | } |
143 | 143 | ||
144 | /** | 144 | /** |
145 | * This opens up a filedialog in Open mode | 145 | * This opens up a filedialog in Open mode |
146 | * | 146 | * |
147 | * @param selector the Selector Mode | 147 | * @param selector the Selector Mode |
148 | * @param startDir Where to start from | 148 | * @param startDir Where to start from |
149 | * @param file A proposed filename | 149 | * @param file A proposed filename |
150 | * @param mimes A list of MimeTypes | 150 | * @param mimes A list of MimeTypes |
151 | * @param wid the parent | 151 | * @param wid the parent |
152 | * @param caption of the dialog if QString::null tr("Open") will be used | 152 | * @param caption of the dialog if QString::null tr("Open") will be used |
153 | * @return the fileName or QString::null | 153 | * @return the fileName or QString::null |
154 | */ | 154 | */ |
155 | QString OFileDialog::getOpenFileName(int selector, | 155 | QString OFileDialog::getOpenFileName(int selector, |
156 | const QString &_startDir, | 156 | const QString &_startDir, |
157 | const QString &file, | 157 | const QString &file, |
158 | const MimeTypes &mimes, | 158 | const MimeTypes &mimes, |
159 | QWidget *wid, | 159 | QWidget *wid, |
160 | const QString &caption ) | 160 | const QString &caption ) |
161 | { | 161 | { |
162 | QString ret; | 162 | QString ret; |
163 | QString startDir = _startDir; | 163 | QString startDir = _startDir; |
164 | if (startDir.isEmpty() ) | 164 | if (startDir.isEmpty() ) |
165 | startDir = lastUsedDir( "FileDialog-OPEN" ); | 165 | startDir = lastUsedDir( "FileDialog-OPEN" ); |
166 | 166 | ||
167 | 167 | ||
168 | OFileDialog dlg( caption.isEmpty() ? tr("Open") : caption, | 168 | OFileDialog dlg( caption.isEmpty() ? tr("Open") : caption, |
169 | wid, OFileSelector::Open, selector, startDir, file, mimes); | 169 | wid, OFileSelector::Open, selector, startDir, file, mimes); |
170 | if( QPEApplication::execDialog(&dlg ) ) | 170 | if( QPEApplication::execDialog(&dlg ) ) |
171 | { | 171 | { |
172 | ret = dlg.fileName(); | 172 | ret = dlg.fileName(); |
173 | saveLastDir( "FileDialog-OPEN", ret ); | 173 | saveLastDir( "FileDialog-OPEN", ret ); |
174 | } | 174 | } |
175 | 175 | ||
176 | return ret; | 176 | return ret; |
177 | } | 177 | } |
178 | 178 | ||
179 | /** | 179 | /** |
180 | * This opens up a file dialog in save mode | 180 | * This opens up a file dialog in save mode |
181 | * @see getOpenFileName | 181 | * @see getOpenFileName |
182 | */ | 182 | */ |
183 | QString OFileDialog::getSaveFileName(int selector, | 183 | QString OFileDialog::getSaveFileName(int selector, |
184 | const QString &_startDir, | 184 | const QString &_startDir, |
185 | const QString &file, | 185 | const QString &file, |
186 | const MimeTypes &mimes, | 186 | const MimeTypes &mimes, |
187 | QWidget *wid, | 187 | QWidget *wid, |
188 | const QString &caption ) | 188 | const QString &caption ) |
189 | { | 189 | { |
190 | QString ret; | 190 | QString ret; |
191 | QString startDir = _startDir; | 191 | QString startDir = _startDir; |
192 | if (startDir.isEmpty() ) | 192 | if (startDir.isEmpty() ) |
193 | startDir = lastUsedDir( "FileDialog-SAVE" ); | 193 | startDir = lastUsedDir( "FileDialog-SAVE" ); |
194 | 194 | ||
195 | OFileDialog dlg( caption.isEmpty() ? tr("Save") : caption, | 195 | OFileDialog dlg( caption.isEmpty() ? tr("Save") : caption, |
196 | wid, OFileSelector::Save, selector, startDir, file, mimes); | 196 | wid, OFileSelector::Save, selector, startDir, file, mimes); |
197 | |||
198 | /* | ||
199 | * For the save mode we do not want a file to be written | ||
200 | * if the user just clicked on it | ||
201 | * #1522 | ||
202 | */ | ||
203 | dlg.disconnect( dlg.file, SIGNAL(fileSelected(const QString&)) ); | ||
204 | dlg.disconnect( dlg.file, SIGNAL(ok()) ); | ||
205 | |||
197 | if( QPEApplication::execDialog(&dlg) ) | 206 | if( QPEApplication::execDialog(&dlg) ) |
198 | { | 207 | { |
199 | ret = dlg.fileName(); | 208 | ret = dlg.fileName(); |
200 | saveLastDir( "FileDialog-SAVE", ret ); | 209 | saveLastDir( "FileDialog-SAVE", ret ); |
201 | } | 210 | } |
202 | 211 | ||
203 | return ret; | 212 | return ret; |
204 | } | 213 | } |
205 | 214 | ||
206 | /** | 215 | /** |
207 | * This opens up a filedialog in select directory mode | 216 | * This opens up a filedialog in select directory mode |
208 | * | 217 | * |
209 | * @param selector the Selector Mode | 218 | * @param selector the Selector Mode |
210 | * @param startDir Where to start from | 219 | * @param startDir Where to start from |
211 | * @param wid the parent | 220 | * @param wid the parent |
212 | * @param caption of the dialog if QString::null tr("Open") will be used | 221 | * @param caption of the dialog if QString::null tr("Open") will be used |
213 | * @return the directoryName or QString::null | 222 | * @return the directoryName or QString::null |
214 | */ | 223 | */ |
215 | QString OFileDialog::getDirectory(int selector, | 224 | QString OFileDialog::getDirectory(int selector, |
216 | const QString &_startDir, | 225 | const QString &_startDir, |
217 | QWidget *wid, | 226 | QWidget *wid, |
218 | const QString &caption ) | 227 | const QString &caption ) |
219 | { | 228 | { |
220 | QString ret; | 229 | QString ret; |
221 | QString startDir = _startDir; | 230 | QString startDir = _startDir; |
222 | if ( startDir.isEmpty() ) | 231 | if ( startDir.isEmpty() ) |
223 | startDir = lastUsedDir( "FileDialog-SELECTDIR" ); | 232 | startDir = lastUsedDir( "FileDialog-SELECTDIR" ); |
224 | 233 | ||
225 | OFileDialog dlg( caption.isEmpty() ? tr( "Select Directory" ) : caption, | 234 | OFileDialog dlg( caption.isEmpty() ? tr( "Select Directory" ) : caption, |
226 | wid, OFileSelector::DirectorySelector, selector, startDir ); | 235 | wid, OFileSelector::DirectorySelector, selector, startDir ); |
227 | 236 | ||
228 | if ( QPEApplication::execDialog(&dlg) ) | 237 | if ( QPEApplication::execDialog(&dlg) ) |
229 | { | 238 | { |
230 | ret = dlg.fileName(); | 239 | ret = dlg.fileName(); |
231 | saveLastDir( "FileDialog-SELECTDIR", ret ); | 240 | saveLastDir( "FileDialog-SELECTDIR", ret ); |
232 | } | 241 | } |
233 | return ret; | 242 | return ret; |
234 | } | 243 | } |
235 | 244 | ||
236 | void OFileDialog::slotFileSelected(const QString & ) | 245 | void OFileDialog::slotFileSelected(const QString & ) |
237 | { | 246 | { |
238 | accept(); | 247 | accept(); |
239 | } | 248 | } |
240 | 249 | ||
241 | void OFileDialog::slotSelectorOk( ) | 250 | void OFileDialog::slotSelectorOk( ) |
242 | { | 251 | { |
243 | accept(); | 252 | accept(); |
244 | } | 253 | } |
245 | 254 | ||
246 | void OFileDialog::slotDirSelected(const QString &dir ) | 255 | void OFileDialog::slotDirSelected(const QString &dir ) |
247 | { | 256 | { |
248 | setCaption( dir ); | 257 | setCaption( dir ); |
249 | } | 258 | } |