-rw-r--r-- | libopie2/opieui/fileselector/ofiledialog.cpp | 35 | ||||
-rw-r--r-- | libopie2/opieui/fileselector/ofiledialog.h | 5 | ||||
-rw-r--r-- | libopie2/opieui/fileselector/ofileselector.cpp | 66 | ||||
-rw-r--r-- | libopie2/opieui/fileselector/ofileselector.h | 3 |
4 files changed, 89 insertions, 20 deletions
diff --git a/libopie2/opieui/fileselector/ofiledialog.cpp b/libopie2/opieui/fileselector/ofiledialog.cpp index beb4d6c..ebce0ef 100644 --- a/libopie2/opieui/fileselector/ofiledialog.cpp +++ b/libopie2/opieui/fileselector/ofiledialog.cpp | |||
@@ -1,222 +1,255 @@ | |||
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 <zecke@handhelds.org> | 3 | .=l. Copyright (C) Holger Freyther <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 |
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 | using namespace Opie::Ui; | 42 | using namespace Opie::Ui; |
43 | 43 | ||
44 | namespace | 44 | namespace |
45 | { | 45 | { |
46 | /* | 46 | /* |
47 | * helper functions to load the start dir | 47 | * helper functions to load the start dir |
48 | * and to save it | 48 | * and to save it |
49 | * helper to extract the dir out of a file name | 49 | * helper to extract the dir out of a file name |
50 | */ | 50 | */ |
51 | /** | 51 | /** |
52 | * This method will use Config( argv[0] ); | 52 | * This method will use Config( argv[0] ); |
53 | * @param key The group key used | 53 | * @param key The group key used |
54 | */ | 54 | */ |
55 | QString lastUsedDir( const QString& key ) | 55 | QString lastUsedDir( const QString& key ) |
56 | { | 56 | { |
57 | if ( qApp->argc() < 1 ) | 57 | if ( qApp->argc() < 1 ) |
58 | return QString::null; | 58 | return QString::null; |
59 | 59 | ||
60 | Config cfg( QFileInfo(qApp->argv()[0]).fileName() ); // appname | 60 | Config cfg( QFileInfo(qApp->argv()[0]).fileName() ); // appname |
61 | cfg.setGroup( key ); | 61 | cfg.setGroup( key ); |
62 | return cfg.readEntry("LastDir", QPEApplication::documentDir() ); | 62 | return cfg.readEntry("LastDir", QPEApplication::documentDir() ); |
63 | } | 63 | } |
64 | 64 | ||
65 | void saveLastDir( const QString& key, const QString& file ) | 65 | void saveLastDir( const QString& key, const QString& file ) |
66 | { | 66 | { |
67 | if ( qApp->argc() < 1 ) | 67 | if ( qApp->argc() < 1 ) |
68 | return; | 68 | return; |
69 | 69 | ||
70 | Config cfg( QFileInfo(qApp->argv()[0]).fileName() ); | 70 | Config cfg( QFileInfo(qApp->argv()[0]).fileName() ); |
71 | cfg.setGroup( key ); | 71 | cfg.setGroup( key ); |
72 | QFileInfo inf( file ); | 72 | QFileInfo inf( file ); |
73 | cfg.writeEntry("LastDir", inf.dirPath( true ) ); | 73 | if ( inf.isFile() ) |
74 | cfg.writeEntry("LastDir", inf.dirPath( true ) ); | ||
75 | else | ||
76 | cfg.writeEntry("LastDir", file ); | ||
74 | } | 77 | } |
75 | }; | 78 | }; |
76 | 79 | ||
77 | /** | 80 | /** |
78 | * This constructs a modal dialog | 81 | * This constructs a modal dialog |
79 | * | 82 | * |
80 | * @param caption The caption of the dialog | 83 | * @param caption The caption of the dialog |
81 | * @param wid The parent widget | 84 | * @param wid The parent widget |
82 | * @param mode The mode of the OFileSelector @see OFileSelector | 85 | * @param mode The mode of the OFileSelector @see OFileSelector |
83 | * @param selector The selector of the OFileSelector | 86 | * @param selector The selector of the OFileSelector |
84 | * @param dirName the dir or resource to start from | 87 | * @param dirName the dir or resource to start from |
85 | * @param fileName a proposed or existing filename | 88 | * @param fileName a proposed or existing filename |
86 | * @param mimetypes The mimeTypes | 89 | * @param mimetypes The mimeTypes |
87 | */ | 90 | */ |
88 | OFileDialog::OFileDialog(const QString &caption, | 91 | OFileDialog::OFileDialog(const QString &caption, |
89 | QWidget *wid, int mode, int selector, | 92 | QWidget *wid, int mode, int selector, |
90 | const QString &dirName, | 93 | const QString &dirName, |
91 | const QString &fileName, | 94 | const QString &fileName, |
92 | const QMap<QString,QStringList>& mimetypes ) | 95 | const QMap<QString,QStringList>& mimetypes ) |
93 | : QDialog( wid, "OFileDialog", true ) | 96 | : QDialog( wid, "OFileDialog", true ) |
94 | { | 97 | { |
95 | // QVBoxLayout *lay = new QVBoxLayout(this); | 98 | // QVBoxLayout *lay = new QVBoxLayout(this); |
96 | //showMaximized(); | 99 | //showMaximized(); |
97 | QVBoxLayout *lay = new QVBoxLayout(this ); | 100 | QVBoxLayout *lay = new QVBoxLayout(this ); |
98 | file = new OFileSelector(this , mode, selector, | 101 | file = new OFileSelector(this , mode, selector, |
99 | dirName, fileName, | 102 | dirName, fileName, |
100 | mimetypes ); | 103 | mimetypes ); |
101 | lay->addWidget( file ); | 104 | lay->addWidget( file ); |
102 | 105 | ||
103 | //lay->addWidget( file ); | 106 | //lay->addWidget( file ); |
104 | //showFullScreen(); | 107 | //showFullScreen(); |
105 | setCaption( caption.isEmpty() ? tr("FileDialog") : caption ); | 108 | setCaption( caption.isEmpty() ? tr("FileDialog") : caption ); |
106 | connect(file, SIGNAL(fileSelected(const QString&) ), | 109 | connect(file, SIGNAL(fileSelected(const QString&) ), |
107 | this, SLOT(slotFileSelected(const QString&) ) ); | 110 | this, SLOT(slotFileSelected(const QString&) ) ); |
108 | connect(file, SIGNAL(ok() ), | 111 | connect(file, SIGNAL(ok() ), |
109 | this, SLOT(slotSelectorOk()) ) ; | 112 | this, SLOT(slotSelectorOk()) ) ; |
110 | 113 | ||
111 | connect(file, SIGNAL(dirSelected(const QString&) ), this, SLOT(slotDirSelected(const QString&) ) ); | 114 | connect(file, SIGNAL(dirSelected(const QString&) ), this, SLOT(slotDirSelected(const QString&) ) ); |
112 | 115 | ||
113 | #if 0 | 116 | #if 0 |
114 | connect(file, SIGNAL(dirSelected(const QString&) ), | 117 | connect(file, SIGNAL(dirSelected(const QString&) ), |
115 | this, SLOT(slotDirSelected(const QString&) ) ); | 118 | this, SLOT(slotDirSelected(const QString&) ) ); |
116 | #endif | 119 | #endif |
117 | } | 120 | } |
118 | /** | 121 | /** |
119 | * @returns the mimetype of the selected | 122 | * @returns the mimetype of the selected |
120 | * currently it return QString::null | 123 | * currently it return QString::null |
121 | */ | 124 | */ |
122 | QString OFileDialog::mimetype()const | 125 | QString OFileDialog::mimetype()const |
123 | { | 126 | { |
124 | return QString::null; | 127 | return QString::null; |
125 | } | 128 | } |
126 | 129 | ||
127 | /** | 130 | /** |
128 | * @return the fileName | 131 | * @return the fileName |
129 | */ | 132 | */ |
130 | QString OFileDialog::fileName()const | 133 | QString OFileDialog::fileName()const |
131 | { | 134 | { |
132 | return file->selectedName(); | 135 | return file->selectedName(); |
133 | } | 136 | } |
134 | 137 | ||
135 | /** | 138 | /** |
136 | * return a DocLnk to the current file | 139 | * return a DocLnk to the current file |
137 | */ | 140 | */ |
138 | DocLnk OFileDialog::selectedDocument()const | 141 | DocLnk OFileDialog::selectedDocument()const |
139 | { | 142 | { |
140 | return file->selectedDocument(); | 143 | return file->selectedDocument(); |
141 | } | 144 | } |
142 | 145 | ||
143 | /** | 146 | /** |
144 | * This opens up a filedialog in Open mode | 147 | * This opens up a filedialog in Open mode |
145 | * | 148 | * |
146 | * @param selector the Selector Mode | 149 | * @param selector the Selector Mode |
147 | * @param startDir Where to start from | 150 | * @param startDir Where to start from |
148 | * @param file A proposed filename | 151 | * @param file A proposed filename |
149 | * @param mimes A list of MimeTypes | 152 | * @param mimes A list of MimeTypes |
150 | * @param wid the parent | 153 | * @param wid the parent |
151 | * @param caption of the dialog if QString::null tr("Open") will be used | 154 | * @param caption of the dialog if QString::null tr("Open") will be used |
152 | * @return the fileName or QString::null | 155 | * @return the fileName or QString::null |
153 | */ | 156 | */ |
154 | QString OFileDialog::getOpenFileName(int selector, | 157 | QString OFileDialog::getOpenFileName(int selector, |
155 | const QString &_startDir, | 158 | const QString &_startDir, |
156 | const QString &file, | 159 | const QString &file, |
157 | const MimeTypes &mimes, | 160 | const MimeTypes &mimes, |
158 | QWidget *wid, | 161 | QWidget *wid, |
159 | const QString &caption ) | 162 | const QString &caption ) |
160 | { | 163 | { |
161 | QString ret; | 164 | QString ret; |
162 | QString startDir = _startDir; | 165 | QString startDir = _startDir; |
163 | if (startDir.isEmpty() ) | 166 | if (startDir.isEmpty() ) |
164 | startDir = lastUsedDir( "FileDialog-OPEN" ); | 167 | startDir = lastUsedDir( "FileDialog-OPEN" ); |
165 | 168 | ||
166 | 169 | ||
167 | OFileDialog dlg( caption.isEmpty() ? tr("Open") : caption, | 170 | OFileDialog dlg( caption.isEmpty() ? tr("Open") : caption, |
168 | wid, OFileSelector::Open, selector, startDir, file, mimes); | 171 | wid, OFileSelector::Open, selector, startDir, file, mimes); |
169 | dlg.showMaximized(); | 172 | dlg.showMaximized(); |
170 | if( dlg.exec() ) | 173 | if( dlg.exec() ) |
171 | { | 174 | { |
172 | ret = dlg.fileName(); | 175 | ret = dlg.fileName(); |
173 | saveLastDir( "FileDialog-OPEN", ret ); | 176 | saveLastDir( "FileDialog-OPEN", ret ); |
174 | } | 177 | } |
175 | 178 | ||
176 | return ret; | 179 | return ret; |
177 | } | 180 | } |
178 | 181 | ||
179 | /** | 182 | /** |
180 | * This opens up a file dialog in save mode | 183 | * This opens up a file dialog in save mode |
181 | * @see getOpenFileName | 184 | * @see getOpenFileName |
182 | */ | 185 | */ |
183 | QString OFileDialog::getSaveFileName(int selector, | 186 | QString OFileDialog::getSaveFileName(int selector, |
184 | const QString &_startDir, | 187 | const QString &_startDir, |
185 | const QString &file, | 188 | const QString &file, |
186 | const MimeTypes &mimes, | 189 | const MimeTypes &mimes, |
187 | QWidget *wid, | 190 | QWidget *wid, |
188 | const QString &caption ) | 191 | const QString &caption ) |
189 | { | 192 | { |
190 | QString ret; | 193 | QString ret; |
191 | QString startDir = _startDir; | 194 | QString startDir = _startDir; |
192 | if (startDir.isEmpty() ) | 195 | if (startDir.isEmpty() ) |
193 | startDir = lastUsedDir( "FileDialog-SAVE" ); | 196 | startDir = lastUsedDir( "FileDialog-SAVE" ); |
194 | 197 | ||
195 | OFileDialog dlg( caption.isEmpty() ? tr("Save") : caption, | 198 | OFileDialog dlg( caption.isEmpty() ? tr("Save") : caption, |
196 | wid, OFileSelector::Save, selector, startDir, file, mimes); | 199 | wid, OFileSelector::Save, selector, startDir, file, mimes); |
197 | dlg.showMaximized(); | 200 | dlg.showMaximized(); |
198 | if( dlg.exec() ) | 201 | if( dlg.exec() ) |
199 | { | 202 | { |
200 | ret = dlg.fileName(); | 203 | ret = dlg.fileName(); |
201 | saveLastDir( "FileDialog-SAVE", ret ); | 204 | saveLastDir( "FileDialog-SAVE", ret ); |
202 | } | 205 | } |
203 | 206 | ||
204 | return ret; | 207 | return ret; |
205 | } | 208 | } |
206 | 209 | ||
210 | /** | ||
211 | * This opens up a filedialog in select directory mode | ||
212 | * | ||
213 | * @param selector the Selector Mode | ||
214 | * @param startDir Where to start from | ||
215 | * @param wid the parent | ||
216 | * @param caption of the dialog if QString::null tr("Open") will be used | ||
217 | * @return the directoryName or QString::null | ||
218 | */ | ||
219 | QString OFileDialog::getDirectory(int selector, | ||
220 | const QString &_startDir, | ||
221 | QWidget *wid, | ||
222 | const QString &caption ) | ||
223 | { | ||
224 | QString ret; | ||
225 | QString startDir = _startDir; | ||
226 | if ( startDir.isEmpty() ) | ||
227 | startDir = lastUsedDir( "FileDialog-SELECTDIR" ); | ||
228 | |||
229 | OFileDialog dlg( caption.isEmpty() ? tr( "Select Directory" ) : caption, | ||
230 | wid, OFileSelector::DirectorySelector, selector, startDir ); | ||
231 | dlg.showMaximized(); | ||
232 | if ( dlg.exec() ) | ||
233 | { | ||
234 | ret = dlg.fileName(); | ||
235 | saveLastDir( "FileDialog-SELECTDIR", ret ); | ||
236 | } | ||
237 | return ret; | ||
238 | } | ||
239 | |||
207 | void OFileDialog::slotFileSelected(const QString & ) | 240 | void OFileDialog::slotFileSelected(const QString & ) |
208 | { | 241 | { |
209 | accept(); | 242 | accept(); |
210 | } | 243 | } |
211 | 244 | ||
212 | void OFileDialog::slotSelectorOk( ) | 245 | void OFileDialog::slotSelectorOk( ) |
213 | { | 246 | { |
214 | accept(); | 247 | accept(); |
215 | } | 248 | } |
216 | 249 | ||
217 | void OFileDialog::slotDirSelected(const QString &dir ) | 250 | void OFileDialog::slotDirSelected(const QString &dir ) |
218 | { | 251 | { |
219 | setCaption( dir ); | 252 | setCaption( dir ); |
220 | // if mode | 253 | // if mode |
221 | //accept(); | 254 | //accept(); |
222 | } | 255 | } |
diff --git a/libopie2/opieui/fileselector/ofiledialog.h b/libopie2/opieui/fileselector/ofiledialog.h index dfecf3d..569f45c 100644 --- a/libopie2/opieui/fileselector/ofiledialog.h +++ b/libopie2/opieui/fileselector/ofiledialog.h | |||
@@ -1,110 +1,115 @@ | |||
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 zecke <zecke@handhelds.org> | 3 | .=l. Copyright (c) 2002 zecke <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 |
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 | #ifndef OFILEDIALOG_H | 29 | #ifndef OFILEDIALOG_H |
30 | #define OFILEDIALOG_H | 30 | #define OFILEDIALOG_H |
31 | 31 | ||
32 | /* OPIE */ | 32 | /* OPIE */ |
33 | #include <opie2/ofileselector.h> | 33 | #include <opie2/ofileselector.h> |
34 | 34 | ||
35 | /* QT */ | 35 | /* QT */ |
36 | #include <qdialog.h> | 36 | #include <qdialog.h> |
37 | 37 | ||
38 | namespace Opie { | 38 | namespace Opie { |
39 | namespace Ui { | 39 | namespace Ui { |
40 | 40 | ||
41 | /** | 41 | /** |
42 | * This class places a OFileSelector inside a QDialog. | 42 | * This class places a OFileSelector inside a QDialog. |
43 | * It provides static method for letting a user chose | 43 | * It provides static method for letting a user chose |
44 | * a file for either opening or saving. | 44 | * a file for either opening or saving. |
45 | * Most of the time the c'tor will not be used instead using | 45 | * Most of the time the c'tor will not be used instead using |
46 | * the static member functions is prefered. | 46 | * the static member functions is prefered. |
47 | * | 47 | * |
48 | * <pre> | 48 | * <pre> |
49 | * QMap<QString, QStringList> mimeTypes; | 49 | * QMap<QString, QStringList> mimeTypes; |
50 | * QStringList types; | 50 | * QStringList types; |
51 | * types << "text[slash]* "; | 51 | * types << "text[slash]* "; |
52 | * mimeTypes.insert( tr("Text"), types ); | 52 | * mimeTypes.insert( tr("Text"), types ); |
53 | * mimeTypes.insert( tr("All"), " * / * " ); // remove the spaces in the 2nd comment | 53 | * mimeTypes.insert( tr("All"), " * / * " ); // remove the spaces in the 2nd comment |
54 | * QString fileName= OFileDialog::getOpenFileName( OFileSelector::EXTENDED_ALL, | 54 | * QString fileName= OFileDialog::getOpenFileName( OFileSelector::EXTENDED_ALL, |
55 | * "foo","bar", mimeTypes); | 55 | * "foo","bar", mimeTypes); |
56 | * </pre> | 56 | * </pre> |
57 | * | 57 | * |
58 | * @short A small QDialog swalloing a FileSelector | 58 | * @short A small QDialog swalloing a FileSelector |
59 | * @see QDialog | 59 | * @see QDialog |
60 | * @see OFileSelector | 60 | * @see OFileSelector |
61 | * @version 0.1-unfinished | 61 | * @version 0.1-unfinished |
62 | * @author Holger Freyther ( zecke@handhelds.org ) | 62 | * @author Holger Freyther ( zecke@handhelds.org ) |
63 | */ | 63 | */ |
64 | class OFileDialog : public QDialog | 64 | class OFileDialog : public QDialog |
65 | { | 65 | { |
66 | Q_OBJECT | 66 | Q_OBJECT |
67 | public: | 67 | public: |
68 | OFileDialog(const QString &caption, | 68 | OFileDialog(const QString &caption, |
69 | QWidget *, int mode, int selector, | 69 | QWidget *, int mode, int selector, |
70 | const QString &dirName, | 70 | const QString &dirName, |
71 | const QString &fileName = QString::null, | 71 | const QString &fileName = QString::null, |
72 | const MimeTypes &mimetypes = MimeTypes() ); | 72 | const MimeTypes &mimetypes = MimeTypes() ); |
73 | QString mimetype() const; | 73 | QString mimetype() const; |
74 | QString fileName() const; | 74 | QString fileName() const; |
75 | DocLnk selectedDocument()const; | 75 | DocLnk selectedDocument()const; |
76 | 76 | ||
77 | // static methods | 77 | // static methods |
78 | static QString getOpenFileName(int selector, | 78 | static QString getOpenFileName(int selector, |
79 | const QString& startDir = QString::null, | 79 | const QString& startDir = QString::null, |
80 | const QString &fileName = QString::null, | 80 | const QString &fileName = QString::null, |
81 | const MimeTypes& mime = MimeTypes(), | 81 | const MimeTypes& mime = MimeTypes(), |
82 | QWidget *wid = 0, | 82 | QWidget *wid = 0, |
83 | const QString &caption = QString::null ); | 83 | const QString &caption = QString::null ); |
84 | 84 | ||
85 | static QString getSaveFileName(int selector, | 85 | static QString getSaveFileName(int selector, |
86 | const QString& startDir = QString::null, | 86 | const QString& startDir = QString::null, |
87 | const QString& fileName = QString::null, | 87 | const QString& fileName = QString::null, |
88 | const MimeTypes& mimefilter = MimeTypes(), | 88 | const MimeTypes& mimefilter = MimeTypes(), |
89 | QWidget *wid = 0, | 89 | QWidget *wid = 0, |
90 | const QString &caption = QString::null ); | 90 | const QString &caption = QString::null ); |
91 | 91 | ||
92 | static QString getDirectory(int selector, | ||
93 | const QString &startDir = QString::null, | ||
94 | QWidget *wid = 0, | ||
95 | const QString &caption = QString::null ); | ||
96 | |||
92 | //let's OFileSelector catch up first | 97 | //let's OFileSelector catch up first |
93 | //static QString getExistingDirectory(const QString& startDir = QString::null, | 98 | //static QString getExistingDirectory(const QString& startDir = QString::null, |
94 | //QWidget *parent = 0, const QString& caption = QString::null ); | 99 | //QWidget *parent = 0, const QString& caption = QString::null ); |
95 | 100 | ||
96 | private: | 101 | private: |
97 | class OFileDialogPrivate; | 102 | class OFileDialogPrivate; |
98 | OFileDialogPrivate *d; | 103 | OFileDialogPrivate *d; |
99 | OFileSelector *file; | 104 | OFileSelector *file; |
100 | 105 | ||
101 | private slots: | 106 | private slots: |
102 | void slotFileSelected( const QString & ); | 107 | void slotFileSelected( const QString & ); |
103 | void slotDirSelected(const QString & ); | 108 | void slotDirSelected(const QString & ); |
104 | void slotSelectorOk(); | 109 | void slotSelectorOk(); |
105 | }; | 110 | }; |
106 | 111 | ||
107 | } | 112 | } |
108 | } | 113 | } |
109 | 114 | ||
110 | #endif | 115 | #endif |
diff --git a/libopie2/opieui/fileselector/ofileselector.cpp b/libopie2/opieui/fileselector/ofileselector.cpp index b06defd..346eeae 100644 --- a/libopie2/opieui/fileselector/ofileselector.cpp +++ b/libopie2/opieui/fileselector/ofileselector.cpp | |||
@@ -335,196 +335,199 @@ OFileViewFileListView::OFileViewFileListView( QWidget* parent, const QString& st | |||
335 | connect(m_btnNew, SIGNAL(clicked() ), | 335 | connect(m_btnNew, SIGNAL(clicked() ), |
336 | this, SLOT(slotNew() ) ); | 336 | this, SLOT(slotNew() ) ); |
337 | 337 | ||
338 | 338 | ||
339 | m_btnClose = new QToolButton( box ); | 339 | m_btnClose = new QToolButton( box ); |
340 | m_btnClose->setIconSet( Resource::loadIconSet("close") ); | 340 | m_btnClose->setIconSet( Resource::loadIconSet("close") ); |
341 | connect(m_btnClose, SIGNAL(clicked() ), | 341 | connect(m_btnClose, SIGNAL(clicked() ), |
342 | selector(), SIGNAL(closeMe() ) ); | 342 | selector(), SIGNAL(closeMe() ) ); |
343 | 343 | ||
344 | btn = new QToolButton( box ); | 344 | btn = new QToolButton( box ); |
345 | btn->setIconSet( Resource::loadIconSet("cardmon/pcmcia") ); | 345 | btn->setIconSet( Resource::loadIconSet("cardmon/pcmcia") ); |
346 | 346 | ||
347 | /* let's fill device parts */ | 347 | /* let's fill device parts */ |
348 | QPopupMenu* pop = new QPopupMenu(this); | 348 | QPopupMenu* pop = new QPopupMenu(this); |
349 | connect(pop, SIGNAL( activated(int) ), | 349 | connect(pop, SIGNAL( activated(int) ), |
350 | this, SLOT(slotFSActivated(int) ) ); | 350 | this, SLOT(slotFSActivated(int) ) ); |
351 | 351 | ||
352 | StorageInfo storage; | 352 | StorageInfo storage; |
353 | const QList<FileSystem> &fs = storage.fileSystems(); | 353 | const QList<FileSystem> &fs = storage.fileSystems(); |
354 | QListIterator<FileSystem> it(fs); | 354 | QListIterator<FileSystem> it(fs); |
355 | for ( ; it.current(); ++it ) | 355 | for ( ; it.current(); ++it ) |
356 | { | 356 | { |
357 | const QString disk = (*it)->name(); | 357 | const QString disk = (*it)->name(); |
358 | const QString path = (*it)->path(); | 358 | const QString path = (*it)->path(); |
359 | m_dev.insert( disk, path ); | 359 | m_dev.insert( disk, path ); |
360 | pop->insertItem( disk ); | 360 | pop->insertItem( disk ); |
361 | } | 361 | } |
362 | m_fsPop = pop; | 362 | m_fsPop = pop; |
363 | 363 | ||
364 | 364 | ||
365 | btn->setPopup( pop ); | 365 | btn->setPopup( pop ); |
366 | 366 | ||
367 | lay->addWidget( box ); | 367 | lay->addWidget( box ); |
368 | 368 | ||
369 | m_view = new QListView( this ); | 369 | m_view = new QListView( this ); |
370 | 370 | ||
371 | m_view->installEventFilter(this); | 371 | m_view->installEventFilter(this); |
372 | 372 | ||
373 | QPEApplication::setStylusOperation( m_view->viewport(), | 373 | QPEApplication::setStylusOperation( m_view->viewport(), |
374 | QPEApplication::RightOnHold); | 374 | QPEApplication::RightOnHold); |
375 | m_view->addColumn(" " ); | 375 | m_view->addColumn(" " ); |
376 | m_view->addColumn(tr("Name"), 135 ); | 376 | m_view->addColumn(tr("Name"), 135 ); |
377 | m_view->addColumn(tr("Size"), -1 ); | 377 | m_view->addColumn(tr("Size"), -1 ); |
378 | m_view->addColumn(tr("Date"), 60 ); | 378 | m_view->addColumn(tr("Date"), 60 ); |
379 | m_view->addColumn(tr("Mime Type"), -1 ); | 379 | m_view->addColumn(tr("Mime Type"), -1 ); |
380 | 380 | ||
381 | 381 | ||
382 | m_view->setSorting( 1 ); | 382 | m_view->setSorting( 1 ); |
383 | m_view->setAllColumnsShowFocus( TRUE ); | 383 | m_view->setAllColumnsShowFocus( TRUE ); |
384 | 384 | ||
385 | lay->addWidget( m_view, 1000 ); | 385 | lay->addWidget( m_view, 1000 ); |
386 | connectSlots(); | 386 | connectSlots(); |
387 | } | 387 | } |
388 | 388 | ||
389 | OFileViewFileListView::~OFileViewFileListView() | 389 | OFileViewFileListView::~OFileViewFileListView() |
390 | { | 390 | { |
391 | } | 391 | } |
392 | 392 | ||
393 | void OFileViewFileListView::slotNew() | 393 | void OFileViewFileListView::slotNew() |
394 | { | 394 | { |
395 | DocLnk lnk; | 395 | DocLnk lnk; |
396 | emit selector()->newSelected( lnk ); | 396 | emit selector()->newSelected( lnk ); |
397 | } | 397 | } |
398 | 398 | ||
399 | OFileSelectorItem* OFileViewFileListView::currentItem()const | 399 | OFileSelectorItem* OFileViewFileListView::currentItem()const |
400 | { | 400 | { |
401 | QListViewItem* item = m_view->currentItem(); | 401 | QListViewItem* item = m_view->currentItem(); |
402 | if (!item ) | 402 | if (!item ) |
403 | return 0l; | 403 | return 0l; |
404 | 404 | ||
405 | return static_cast<OFileSelectorItem*>(item); | 405 | return static_cast<OFileSelectorItem*>(item); |
406 | } | 406 | } |
407 | 407 | ||
408 | void OFileViewFileListView::reread( bool all ) | 408 | void OFileViewFileListView::reread( bool all ) |
409 | { | 409 | { |
410 | m_view->clear(); | 410 | m_view->clear(); |
411 | 411 | ||
412 | if (selector()->showClose() ) | 412 | if (selector()->showClose() ) |
413 | m_btnClose->show(); | 413 | m_btnClose->show(); |
414 | else | 414 | else |
415 | m_btnClose->hide(); | 415 | m_btnClose->hide(); |
416 | 416 | ||
417 | if (selector()->showNew() ) | 417 | if (selector()->showNew() ) |
418 | m_btnNew->show(); | 418 | m_btnNew->show(); |
419 | else | 419 | else |
420 | m_btnNew->hide(); | 420 | m_btnNew->hide(); |
421 | 421 | ||
422 | m_mimes = selector()->currentMimeType(); | 422 | m_mimes = selector()->currentMimeType(); |
423 | m_all = all; | 423 | m_all = all; |
424 | 424 | ||
425 | QDir dir( m_currentDir ); | 425 | QDir dir( m_currentDir ); |
426 | if (!dir.exists() ) | 426 | if (!dir.exists() ) |
427 | return; | 427 | return; |
428 | 428 | ||
429 | dir.setSorting( QDir::Name | QDir::DirsFirst | QDir::Reversed ); | 429 | dir.setSorting( QDir::Name | QDir::DirsFirst | QDir::Reversed ); |
430 | int filter; | 430 | int filter; |
431 | if (m_all ) | 431 | filter = QDir::Dirs; |
432 | filter = QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All; | 432 | if ( selector()->mode() != OFileSelector::DIRECTORYSELECTOR ) |
433 | else | 433 | filter = filter | QDir::Files | QDir::All; |
434 | filter = QDir::Files | QDir::Dirs | QDir::All; | 434 | |
435 | if ( m_all ) | ||
436 | filter = filter | QDir::Hidden; | ||
437 | |||
435 | dir.setFilter( filter ); | 438 | dir.setFilter( filter ); |
436 | 439 | ||
437 | // now go through all files | 440 | // now go through all files |
438 | const QFileInfoList *list = dir.entryInfoList(); | 441 | const QFileInfoList *list = dir.entryInfoList(); |
439 | if (!list) | 442 | if (!list) |
440 | { | 443 | { |
441 | cdUP(); | 444 | cdUP(); |
442 | return; | 445 | return; |
443 | } | 446 | } |
444 | 447 | ||
445 | QFileInfoListIterator it( *list ); | 448 | QFileInfoListIterator it( *list ); |
446 | QFileInfo *fi; | 449 | QFileInfo *fi; |
447 | while( (fi=it.current() ) ) | 450 | while( (fi=it.current() ) ) |
448 | { | 451 | { |
449 | if( fi->fileName() == QString::fromLatin1("..") || fi->fileName() == QString::fromLatin1(".") ) | 452 | if( fi->fileName() == QString::fromLatin1("..") || fi->fileName() == QString::fromLatin1(".") ) |
450 | { | 453 | { |
451 | ++it; | 454 | ++it; |
452 | continue; | 455 | continue; |
453 | } | 456 | } |
454 | 457 | ||
455 | /* | 458 | /* |
456 | * It is a symlink we try to resolve it now but don't let us attack by DOS | 459 | * It is a symlink we try to resolve it now but don't let us attack by DOS |
457 | * | 460 | * |
458 | */ | 461 | */ |
459 | if( fi->isSymLink() ) | 462 | if( fi->isSymLink() ) |
460 | { | 463 | { |
461 | QString file = fi->dirPath( true ) + "/" + fi->readLink(); | 464 | QString file = fi->dirPath( true ) + "/" + fi->readLink(); |
462 | for( int i = 0; i<=4; i++) | 465 | for( int i = 0; i<=4; i++) |
463 | { // 5 tries to prevent dos | 466 | { // 5 tries to prevent dos |
464 | QFileInfo info( file ); | 467 | QFileInfo info( file ); |
465 | if( !info.exists() ) | 468 | if( !info.exists() ) |
466 | { | 469 | { |
467 | addSymlink( fi, TRUE ); | 470 | addSymlink( fi, TRUE ); |
468 | break; | 471 | break; |
469 | } | 472 | } |
470 | else if( info.isDir() ) | 473 | else if( info.isDir() ) |
471 | { | 474 | { |
472 | addDir( fi, TRUE ); | 475 | addDir( fi, TRUE ); |
473 | break; | 476 | break; |
474 | } | 477 | } |
475 | else if( info.isFile() ) | 478 | else if( info.isFile() ) |
476 | { | 479 | { |
477 | addFile( fi, TRUE ); | 480 | addFile( fi, TRUE ); |
478 | break; | 481 | break; |
479 | } | 482 | } |
480 | else if( info.isSymLink() ) | 483 | else if( info.isSymLink() ) |
481 | { | 484 | { |
482 | file = info.dirPath(true ) + "/" + info.readLink() ; | 485 | file = info.dirPath(true ) + "/" + info.readLink() ; |
483 | break; | 486 | break; |
484 | } | 487 | } |
485 | else if( i == 4) | 488 | else if( i == 4) |
486 | { // couldn't resolve symlink add it as symlink | 489 | { // couldn't resolve symlink add it as symlink |
487 | addSymlink( fi ); | 490 | addSymlink( fi ); |
488 | } | 491 | } |
489 | } // off for loop for symlink resolving | 492 | } // off for loop for symlink resolving |
490 | } | 493 | } |
491 | else if( fi->isDir() ) | 494 | else if( fi->isDir() ) |
492 | addDir( fi ); | 495 | addDir( fi ); |
493 | else if( fi->isFile() ) | 496 | else if( fi->isFile() ) |
494 | addFile( fi ); | 497 | addFile( fi ); |
495 | 498 | ||
496 | ++it; | 499 | ++it; |
497 | } // of while loop | 500 | } // of while loop |
498 | m_view->sort(); | 501 | m_view->sort(); |
499 | 502 | ||
500 | } | 503 | } |
501 | int OFileViewFileListView::fileCount()const | 504 | int OFileViewFileListView::fileCount()const |
502 | { | 505 | { |
503 | return m_view->childCount(); | 506 | return m_view->childCount(); |
504 | } | 507 | } |
505 | 508 | ||
506 | QString OFileViewFileListView::currentDir()const | 509 | QString OFileViewFileListView::currentDir()const |
507 | { | 510 | { |
508 | return m_currentDir; | 511 | return m_currentDir; |
509 | } | 512 | } |
510 | 513 | ||
511 | OFileSelector* OFileViewFileListView::selector() | 514 | OFileSelector* OFileViewFileListView::selector() |
512 | { | 515 | { |
513 | return m_sel; | 516 | return m_sel; |
514 | } | 517 | } |
515 | 518 | ||
516 | bool OFileViewFileListView::eventFilter (QObject *, QEvent *e) | 519 | bool OFileViewFileListView::eventFilter (QObject *, QEvent *e) |
517 | { | 520 | { |
518 | if ( e->type() == QEvent::KeyPress ) | 521 | if ( e->type() == QEvent::KeyPress ) |
519 | { | 522 | { |
520 | QKeyEvent *k = (QKeyEvent *)e; | 523 | QKeyEvent *k = (QKeyEvent *)e; |
521 | if ( (k->key()==Key_Enter) || (k->key()==Key_Return)) | 524 | if ( (k->key()==Key_Enter) || (k->key()==Key_Return)) |
522 | { | 525 | { |
523 | slotClicked( Qt::LeftButton,m_view->currentItem(),QPoint(0,0),0); | 526 | slotClicked( Qt::LeftButton,m_view->currentItem(),QPoint(0,0),0); |
524 | return true; | 527 | return true; |
525 | } | 528 | } |
526 | } | 529 | } |
527 | return false; | 530 | return false; |
528 | } | 531 | } |
529 | 532 | ||
530 | void OFileViewFileListView::connectSlots() | 533 | void OFileViewFileListView::connectSlots() |
@@ -721,376 +724,403 @@ bool OFileViewFileListView::compliesMime( const QString& str) | |||
721 | QRegExp reg( (*it) ); | 724 | QRegExp reg( (*it) ); |
722 | reg.setWildcard( true ); | 725 | reg.setWildcard( true ); |
723 | if ( str.find( reg ) != -1 ) | 726 | if ( str.find( reg ) != -1 ) |
724 | return true; | 727 | return true; |
725 | 728 | ||
726 | } | 729 | } |
727 | return false; | 730 | return false; |
728 | } | 731 | } |
729 | /* | 732 | /* |
730 | * The listView giving access to the file system! | 733 | * The listView giving access to the file system! |
731 | */ | 734 | */ |
732 | 735 | ||
733 | class OFileViewFileSystem : public OFileViewInterface | 736 | class OFileViewFileSystem : public OFileViewInterface |
734 | { | 737 | { |
735 | public: | 738 | public: |
736 | OFileViewFileSystem( OFileSelector* ); | 739 | OFileViewFileSystem( OFileSelector* ); |
737 | ~OFileViewFileSystem(); | 740 | ~OFileViewFileSystem(); |
738 | 741 | ||
739 | QString selectedName() const; | 742 | QString selectedName() const; |
740 | QString selectedPath() const; | 743 | QString selectedPath() const; |
741 | 744 | ||
742 | QString directory()const; | 745 | QString directory()const; |
743 | void reread(); | 746 | void reread(); |
744 | int fileCount()const; | 747 | int fileCount()const; |
745 | 748 | ||
746 | QWidget* widget( QWidget* parent ); | 749 | QWidget* widget( QWidget* parent ); |
747 | void activate( const QString& ); | 750 | void activate( const QString& ); |
748 | private: | 751 | private: |
749 | OFileViewFileListView* m_view; | 752 | OFileViewFileListView* m_view; |
750 | bool m_all : 1; | 753 | bool m_all : 1; |
751 | }; | 754 | }; |
752 | 755 | ||
753 | OFileViewFileSystem::OFileViewFileSystem( OFileSelector* sel) | 756 | OFileViewFileSystem::OFileViewFileSystem( OFileSelector* sel) |
754 | : OFileViewInterface( sel ) | 757 | : OFileViewInterface( sel ) |
755 | { | 758 | { |
756 | m_view = 0; | 759 | m_view = 0; |
757 | m_all = false; | 760 | m_all = false; |
758 | } | 761 | } |
759 | 762 | ||
760 | OFileViewFileSystem::~OFileViewFileSystem() | 763 | OFileViewFileSystem::~OFileViewFileSystem() |
761 | { | 764 | { |
762 | } | 765 | } |
763 | 766 | ||
764 | QString OFileViewFileSystem::selectedName()const | 767 | QString OFileViewFileSystem::selectedName()const |
765 | { | 768 | { |
766 | if (!m_view ) | 769 | if (!m_view ) |
767 | return QString::null; | 770 | return QString::null; |
768 | 771 | ||
769 | QString cFN=currentFileName(); | 772 | QString cFN=currentFileName(); |
770 | if (cFN.startsWith("/")) return cFN; | 773 | if (cFN.startsWith("/")) return cFN; |
771 | return m_view->currentDir() + "/" + cFN; | 774 | return m_view->currentDir() + "/" + cFN; |
772 | } | 775 | } |
773 | 776 | ||
774 | QString OFileViewFileSystem::selectedPath()const | 777 | QString OFileViewFileSystem::selectedPath()const |
775 | { | 778 | { |
776 | return QString::null; | 779 | return QString::null; |
777 | } | 780 | } |
778 | 781 | ||
779 | QString OFileViewFileSystem::directory()const | 782 | QString OFileViewFileSystem::directory()const |
780 | { | 783 | { |
781 | if (!m_view) | 784 | if (!m_view) |
782 | return QString::null; | 785 | return QString::null; |
783 | 786 | ||
784 | OFileSelectorItem* item = m_view->currentItem(); | 787 | OFileSelectorItem* item = m_view->currentItem(); |
785 | if (!item ) | 788 | if (!item ) |
786 | return QString::null; | 789 | return QString::null; |
787 | 790 | ||
788 | return QDir(item->directory() ).absPath(); | 791 | return QDir(item->directory() ).absPath(); |
789 | } | 792 | } |
790 | 793 | ||
791 | void OFileViewFileSystem::reread() | 794 | void OFileViewFileSystem::reread() |
792 | { | 795 | { |
793 | if (!m_view) | 796 | if (!m_view) |
794 | return; | 797 | return; |
795 | 798 | ||
796 | m_view->reread( m_all ); | 799 | m_view->reread( m_all ); |
797 | } | 800 | } |
798 | 801 | ||
799 | int OFileViewFileSystem::fileCount()const | 802 | int OFileViewFileSystem::fileCount()const |
800 | { | 803 | { |
801 | if (!m_view ) | 804 | if (!m_view ) |
802 | return -1; | 805 | return -1; |
803 | return m_view->fileCount(); | 806 | return m_view->fileCount(); |
804 | } | 807 | } |
805 | 808 | ||
806 | QWidget* OFileViewFileSystem::widget( QWidget* parent ) | 809 | QWidget* OFileViewFileSystem::widget( QWidget* parent ) |
807 | { | 810 | { |
808 | if (!m_view ) | 811 | if (!m_view ) |
809 | { | 812 | { |
810 | m_view = new OFileViewFileListView( parent, startDirectory(), selector() ); | 813 | m_view = new OFileViewFileListView( parent, startDirectory(), selector() ); |
811 | } | 814 | } |
812 | return m_view; | 815 | return m_view; |
813 | } | 816 | } |
814 | 817 | ||
815 | void OFileViewFileSystem::activate( const QString& str) | 818 | void OFileViewFileSystem::activate( const QString& str) |
816 | { | 819 | { |
817 | m_all = (str != QObject::tr("Files") ); | 820 | m_all = ( str.find( "All" ) != -1 ); |
818 | } | 821 | } |
819 | 822 | ||
820 | 823 | ||
821 | } | 824 | } |
822 | /* Selector */ | 825 | /* Selector */ |
823 | /** | 826 | /** |
824 | * @short new and complete c'tor | 827 | * @short new and complete c'tor |
825 | * | 828 | * |
826 | * Create a OFileSelector to let the user select a file. It can | 829 | * Create a OFileSelector to let the user select a file. It can |
827 | * either be used to open a file, select a save name in a dir or | 830 | * either be used to open a file, select a save name in a dir or |
828 | * as a dropin for the FileSelector. | 831 | * as a dropin for the FileSelector. |
829 | * | 832 | * |
830 | * <pre> | 833 | * <pre> |
831 | * QMap<QString, QStringList> mimeTypes; | 834 | * QMap<QString, QStringList> mimeTypes; |
832 | * QStringList types; | 835 | * QStringList types; |
833 | * types << "text@slash* "; | 836 | * types << "text@slash* "; |
834 | * types << "audio@slash*"; | 837 | * types << "audio@slash*"; |
835 | * mimeTypes.insert( tr("Audio and Text"), types ); | 838 | * mimeTypes.insert( tr("Audio and Text"), types ); |
836 | * mimeTypes.insert( tr("All"), "*@slash*); | 839 | * mimeTypes.insert( tr("All"), "*@slash*); |
837 | * | 840 | * |
838 | * now you could create your fileselector | 841 | * now you could create your fileselector |
839 | * </pre> | 842 | * </pre> |
840 | * | 843 | * |
841 | * | 844 | * |
842 | * @param parent the parent of this widget | 845 | * @param parent the parent of this widget |
843 | * @param mode The mode from the enum Mode (Open,Save,FILESELECTOR) | 846 | * @param mode The mode from the enum Mode (Open,Save,FILESELECTOR) |
844 | * @param sel The selector to be used | 847 | * @param sel The selector to be used |
845 | * @param dirName The name of the dir to start int | 848 | * @param dirName The name of the dir to start int |
846 | * @param fileName The fileName placed in the fileselector lineedit | 849 | * @param fileName The fileName placed in the fileselector lineedit |
847 | * @param mimetypes The MimeType map of used mimetypes | 850 | * @param mimetypes The MimeType map of used mimetypes |
848 | * @param showNew Show a New Button. Most likely to be used in the FileSelector view. | 851 | * @param showNew Show a New Button. Most likely to be used in the FileSelector view. |
849 | * @param showClose Show a Close Button. Most likely to be used in FileSelector view. | 852 | * @param showClose Show a Close Button. Most likely to be used in FileSelector view. |
850 | * | 853 | * |
851 | */ | 854 | */ |
852 | OFileSelector::OFileSelector( QWidget* parent, int mode, int sel, | 855 | OFileSelector::OFileSelector( QWidget* parent, int mode, int sel, |
853 | const QString& dirName, const QString& fileName, | 856 | const QString& dirName, const QString& fileName, |
854 | const MimeTypes& mimetypes, | 857 | const MimeTypes& mimetypes, |
855 | bool showNew, bool showClose) | 858 | bool showNew, bool showClose) |
856 | :QWidget( parent, "OFileSelector" ) | 859 | :QWidget( parent, "OFileSelector" ) |
857 | { | 860 | { |
858 | m_current = 0; | 861 | m_current = 0; |
859 | m_shNew = showNew; | 862 | m_shNew = showNew; |
860 | m_shClose = showClose; | 863 | m_shClose = showClose; |
861 | m_mimeType = mimetypes; | 864 | m_mimeType = mimetypes; |
862 | m_startDir = dirName; | 865 | m_startDir = dirName; |
863 | 866 | ||
864 | m_mode = mode; | 867 | m_mode = mode; |
865 | m_selector = sel; | 868 | m_selector = sel; |
866 | 869 | ||
867 | initUI(); | 870 | initUI(); |
868 | m_lneEdit->setText( fileName ); | 871 | m_lneEdit->setText( fileName ); |
869 | initMime(); | 872 | initMime(); |
870 | initViews(); | 873 | initViews(); |
871 | 874 | ||
872 | QString str; | 875 | QString str; |
873 | switch ( m_selector ) | 876 | switch ( m_selector ) |
874 | { | 877 | { |
875 | default: | 878 | default: |
876 | case Normal: | 879 | case Normal: |
877 | str = QObject::tr("Documents"); | 880 | if ( m_mode == DIRECTORYSELECTOR ) |
881 | str = QObject::tr("Directories"); | ||
882 | else | ||
883 | str = QObject::tr("Documents"); | ||
878 | m_cmbView->setCurrentItem( 0 ); | 884 | m_cmbView->setCurrentItem( 0 ); |
879 | break; | 885 | break; |
880 | case Extended: | 886 | case Extended: |
881 | str = QObject::tr("Files"); | 887 | if ( m_mode == DIRECTORYSELECTOR ) |
882 | m_cmbView->setCurrentItem( 1 ); | 888 | { |
889 | str = QObject::tr("Directories"); | ||
890 | m_cmbView->setCurrentItem( 0 ); | ||
891 | } else { | ||
892 | str = QObject::tr("Files"); | ||
893 | m_cmbView->setCurrentItem( 1 ); | ||
894 | } | ||
883 | break; | 895 | break; |
884 | case ExtendedAll: | 896 | case ExtendedAll: |
885 | str = QObject::tr("All Files"); | 897 | if ( m_mode == DIRECTORYSELECTOR ) |
886 | m_cmbView->setCurrentItem( 2 ); | 898 | { |
899 | str = QObject::tr("All Directories"); | ||
900 | m_cmbView->setCurrentItem( 1 ); | ||
901 | } else { | ||
902 | str = QObject::tr("All Files"); | ||
903 | m_cmbView->setCurrentItem( 2 ); | ||
904 | } | ||
887 | break; | 905 | break; |
888 | } | 906 | } |
889 | slotViewChange( str ); | 907 | slotViewChange( str ); |
890 | 908 | ||
891 | } | 909 | } |
892 | 910 | ||
893 | 911 | ||
894 | /** | 912 | /** |
895 | * This a convience c'tor to just substitute the use of FileSelector | 913 | * This a convience c'tor to just substitute the use of FileSelector |
896 | */ | 914 | */ |
897 | OFileSelector::OFileSelector( const QString& mimeFilter, QWidget* parent, const char* name, | 915 | OFileSelector::OFileSelector( const QString& mimeFilter, QWidget* parent, const char* name, |
898 | bool showNew, bool showClose ) | 916 | bool showNew, bool showClose ) |
899 | : QWidget( parent, name ) | 917 | : QWidget( parent, name ) |
900 | { | 918 | { |
901 | m_current = 0; | 919 | m_current = 0; |
902 | m_shNew = showNew; | 920 | m_shNew = showNew; |
903 | m_shClose = showClose; | 921 | m_shClose = showClose; |
904 | m_startDir = QPEApplication::documentDir(); | 922 | m_startDir = QPEApplication::documentDir(); |
905 | 923 | ||
906 | if (!mimeFilter.isEmpty() ) | 924 | if (!mimeFilter.isEmpty() ) |
907 | m_mimeType.insert(mimeFilter, QStringList::split(";", mimeFilter ) ); | 925 | m_mimeType.insert(mimeFilter, QStringList::split(";", mimeFilter ) ); |
908 | 926 | ||
909 | m_mode = OFileSelector::FileSelector; | 927 | m_mode = OFileSelector::FileSelector; |
910 | m_selector = OFileSelector::Normal; | 928 | m_selector = OFileSelector::Normal; |
911 | 929 | ||
912 | initUI(); | 930 | initUI(); |
913 | initMime(); | 931 | initMime(); |
914 | initViews(); | 932 | initViews(); |
915 | m_cmbView->setCurrentItem( 0 ); | 933 | m_cmbView->setCurrentItem( 0 ); |
916 | slotViewChange( QObject::tr("Documents") ); | 934 | slotViewChange( QObject::tr("Documents") ); |
917 | } | 935 | } |
918 | 936 | ||
919 | /* | 937 | /* |
920 | * INIT UI will set up the basic GUI | 938 | * INIT UI will set up the basic GUI |
921 | * Layout: Simple VBoxLayout | 939 | * Layout: Simple VBoxLayout |
922 | * On top a WidgetStack containing the Views... | 940 | * On top a WidgetStack containing the Views... |
923 | * - List View | 941 | * - List View |
924 | * - Document View | 942 | * - Document View |
925 | * Below we will have a Label + LineEdit | 943 | * Below we will have a Label + LineEdit |
926 | * Below we will have two ComoBoxes one for choosing the view one for | 944 | * Below we will have two ComoBoxes one for choosing the view one for |
927 | * choosing the mimetype | 945 | * choosing the mimetype |
928 | */ | 946 | */ |
929 | void OFileSelector::initUI() | 947 | void OFileSelector::initUI() |
930 | { | 948 | { |
931 | QVBoxLayout* lay = new QVBoxLayout( this ); | 949 | QVBoxLayout* lay = new QVBoxLayout( this ); |
932 | 950 | ||
933 | m_stack = new QWidgetStack( this ); | 951 | m_stack = new QWidgetStack( this ); |
934 | lay->addWidget( m_stack, 1000 ); | 952 | lay->addWidget( m_stack, 1000 ); |
935 | 953 | ||
936 | m_nameBox = new QHBox( this ); | 954 | m_nameBox = new QHBox( this ); |
937 | (void)new QLabel( tr("Name:"), m_nameBox ); | 955 | (void)new QLabel( tr("Name:"), m_nameBox ); |
938 | m_lneEdit = new QLineEdit( m_nameBox ); | 956 | m_lneEdit = new QLineEdit( m_nameBox ); |
939 | m_lneEdit ->installEventFilter(this); | 957 | m_lneEdit ->installEventFilter(this); |
940 | lay->addWidget( m_nameBox ); | 958 | lay->addWidget( m_nameBox ); |
941 | 959 | ||
942 | m_cmbBox = new QHBox( this ); | 960 | m_cmbBox = new QHBox( this ); |
943 | m_cmbView = new QComboBox( m_cmbBox ); | 961 | m_cmbView = new QComboBox( m_cmbBox ); |
944 | m_cmbMime = new QComboBox( m_cmbBox ); | 962 | m_cmbMime = new QComboBox( m_cmbBox ); |
945 | lay->addWidget( m_cmbBox ); | 963 | lay->addWidget( m_cmbBox ); |
946 | } | 964 | } |
947 | 965 | ||
948 | /* | 966 | /* |
949 | * This will make sure that the return key in the name edit causes dialogs to close | 967 | * This will make sure that the return key in the name edit causes dialogs to close |
950 | */ | 968 | */ |
951 | 969 | ||
952 | bool OFileSelector::eventFilter (QObject *, QEvent *e) | 970 | bool OFileSelector::eventFilter (QObject *, QEvent *e) |
953 | { | 971 | { |
954 | if ( e->type() == QEvent::KeyPress ) | 972 | if ( e->type() == QEvent::KeyPress ) |
955 | { | 973 | { |
956 | QKeyEvent *k = (QKeyEvent *)e; | 974 | QKeyEvent *k = (QKeyEvent *)e; |
957 | if ( (k->key()==Key_Enter) || (k->key()==Key_Return)) | 975 | if ( (k->key()==Key_Enter) || (k->key()==Key_Return)) |
958 | { | 976 | { |
959 | emit ok(); | 977 | emit ok(); |
960 | return true; | 978 | return true; |
961 | } | 979 | } |
962 | } | 980 | } |
963 | return false; | 981 | return false; |
964 | } | 982 | } |
965 | 983 | ||
966 | /* | 984 | /* |
967 | * This will insert the MimeTypes into the Combo Box | 985 | * This will insert the MimeTypes into the Combo Box |
968 | * And also connect the changed signal | 986 | * And also connect the changed signal |
969 | * | 987 | * |
970 | * AutoMimeTyping is disabled for now. It used to reparse a dir and then set available mimetypes | 988 | * AutoMimeTyping is disabled for now. It used to reparse a dir and then set available mimetypes |
971 | */ | 989 | */ |
972 | void OFileSelector::initMime() | 990 | void OFileSelector::initMime() |
973 | { | 991 | { |
974 | MimeTypes::Iterator it; | 992 | MimeTypes::Iterator it; |
975 | for ( it = m_mimeType.begin(); it != m_mimeType.end(); ++it ) | 993 | for ( it = m_mimeType.begin(); it != m_mimeType.end(); ++it ) |
976 | { | 994 | { |
977 | m_cmbMime->insertItem( it.key() ); | 995 | m_cmbMime->insertItem( it.key() ); |
978 | } | 996 | } |
979 | m_cmbMime->setCurrentItem( 0 ); | 997 | m_cmbMime->setCurrentItem( 0 ); |
980 | 998 | ||
981 | connect( m_cmbMime, SIGNAL(activated(int) ), | 999 | connect( m_cmbMime, SIGNAL(activated(int) ), |
982 | this, SLOT(slotMimeTypeChanged() ) ); | 1000 | this, SLOT(slotMimeTypeChanged() ) ); |
983 | 1001 | ||
984 | } | 1002 | } |
985 | 1003 | ||
986 | void OFileSelector::initViews() | 1004 | void OFileSelector::initViews() |
987 | { | 1005 | { |
988 | m_cmbView->insertItem( QObject::tr("Documents") ); | 1006 | if ( m_mode == OFileSelector::DIRECTORYSELECTOR ) |
989 | m_cmbView->insertItem( QObject::tr("Files") ); | 1007 | { |
990 | m_cmbView->insertItem( QObject::tr("All Files") ); | 1008 | m_cmbView->insertItem( QObject::tr("Directories") ); |
1009 | m_cmbView->insertItem( QObject::tr("All Directories") ); | ||
1010 | } else { | ||
1011 | m_cmbView->insertItem( QObject::tr("Documents") ); | ||
1012 | m_cmbView->insertItem( QObject::tr("Files") ); | ||
1013 | m_cmbView->insertItem( QObject::tr("All Files") ); | ||
1014 | } | ||
1015 | |||
991 | connect(m_cmbView, SIGNAL(activated(const QString&) ), | 1016 | connect(m_cmbView, SIGNAL(activated(const QString&) ), |
992 | this, SLOT(slotViewChange(const QString&) ) ); | 1017 | this, SLOT(slotViewChange(const QString&) ) ); |
993 | 1018 | ||
994 | |||
995 | m_views.insert( QObject::tr("Documents"), new ODocumentFileView(this) ); | ||
996 | |||
997 | /* see above why add both */ | 1019 | /* see above why add both */ |
998 | OFileViewInterface* in = new OFileViewFileSystem( this ); | 1020 | OFileViewInterface* in = new OFileViewFileSystem( this ); |
999 | m_views.insert( QObject::tr("Files"), in ); | 1021 | |
1000 | m_views.insert( QObject::tr("All Files"), in ); | 1022 | if ( m_mode == OFileSelector::DIRECTORYSELECTOR ) |
1023 | { | ||
1024 | m_views.insert( QObject::tr("Directories"), in ); | ||
1025 | m_views.insert( QObject::tr("All Directories"), in ); | ||
1026 | } else { | ||
1027 | m_views.insert( QObject::tr("Documents"), new ODocumentFileView(this) ); | ||
1028 | m_views.insert( QObject::tr("Files"), in ); | ||
1029 | m_views.insert( QObject::tr("All Files"), in ); | ||
1030 | } | ||
1001 | } | 1031 | } |
1002 | 1032 | ||
1003 | void OFileSelector::registerView( const Internal::OFileViewInterface* iface ) { | 1033 | void OFileSelector::registerView( const Internal::OFileViewInterface* iface ) { |
1004 | m_viewsPtr.append( iface ); | 1034 | m_viewsPtr.append( iface ); |
1005 | } | 1035 | } |
1006 | 1036 | ||
1007 | 1037 | ||
1008 | /** | 1038 | /** |
1009 | * d'tor | 1039 | * d'tor |
1010 | */ | 1040 | */ |
1011 | OFileSelector::~OFileSelector() | 1041 | OFileSelector::~OFileSelector() |
1012 | { | 1042 | { |
1013 | m_viewsPtr.setAutoDelete( true ); | 1043 | m_viewsPtr.setAutoDelete( true ); |
1014 | m_viewsPtr.clear(); | 1044 | m_viewsPtr.clear(); |
1015 | } | 1045 | } |
1016 | 1046 | ||
1017 | 1047 | ||
1018 | 1048 | ||
1019 | /** | 1049 | /** |
1020 | * Convience function for the fileselector | 1050 | * Convience function for the fileselector |
1021 | * make sure to delete the DocLnk | 1051 | * make sure to delete the DocLnk |
1022 | * | 1052 | * |
1023 | * @see DocLnk | 1053 | * @see DocLnk |
1024 | * @todo remove in ODP | 1054 | * @todo remove in ODP |
1025 | */ | 1055 | */ |
1026 | const DocLnk* OFileSelector::selected() | 1056 | const DocLnk* OFileSelector::selected() |
1027 | { | 1057 | { |
1028 | DocLnk* lnk = new DocLnk( currentView()->selectedDocument() ); | 1058 | DocLnk* lnk = new DocLnk( currentView()->selectedDocument() ); |
1029 | return lnk; | 1059 | return lnk; |
1030 | } | 1060 | } |
1031 | 1061 | ||
1032 | /** | 1062 | /** |
1033 | * | 1063 | * |
1034 | * @return the name of the selected file | 1064 | * @return the name of the selected file |
1035 | */ | 1065 | */ |
1036 | QString OFileSelector::selectedName()const | 1066 | QString OFileSelector::selectedName()const |
1037 | { | 1067 | { |
1038 | return currentView()->selectedName(); | 1068 | return currentView()->selectedName(); |
1039 | } | 1069 | } |
1040 | 1070 | ||
1041 | 1071 | ||
1042 | /** | 1072 | /** |
1043 | * @return the selected path | 1073 | * @return the selected path |
1044 | */ | 1074 | */ |
1045 | QString OFileSelector::selectedPath()const | 1075 | QString OFileSelector::selectedPath()const |
1046 | { | 1076 | { |
1047 | return currentView()->selectedPath(); | 1077 | return currentView()->selectedPath(); |
1048 | } | 1078 | } |
1049 | 1079 | ||
1050 | /** | 1080 | /** |
1051 | * @return the directory name | 1081 | * @return the directory name |
1052 | */ | 1082 | */ |
1053 | QString OFileSelector::directory()const | 1083 | QString OFileSelector::directory()const |
1054 | { | 1084 | { |
1055 | return currentView()->directory(); | 1085 | return currentView()->directory(); |
1056 | } | 1086 | } |
1057 | 1087 | ||
1058 | /** | 1088 | /** |
1059 | * @return a DocLnk for the selected document | 1089 | * @return a DocLnk for the selected document |
1060 | */ | 1090 | */ |
1061 | DocLnk OFileSelector::selectedDocument()const | 1091 | DocLnk OFileSelector::selectedDocument()const |
1062 | { | 1092 | { |
1063 | return currentView()->selectedDocument(); | 1093 | return currentView()->selectedDocument(); |
1064 | } | 1094 | } |
1065 | 1095 | ||
1066 | /** | 1096 | /** |
1067 | * @return the number of items for the current view | 1097 | * @return the number of items for the current view |
1068 | */ | 1098 | */ |
1069 | int OFileSelector::fileCount()const | 1099 | int OFileSelector::fileCount()const |
1070 | { | 1100 | { |
1071 | return currentView()->fileCount(); | 1101 | return currentView()->fileCount(); |
1072 | } | 1102 | } |
1073 | 1103 | ||
1074 | /** | 1104 | /** |
1075 | * @return reparse the file content | 1105 | * @return reparse the file content |
1076 | */ | 1106 | */ |
1077 | void OFileSelector::reread() | 1107 | void OFileSelector::reread() |
1078 | { | 1108 | { |
1079 | return currentView()->reread(); | 1109 | return currentView()->reread(); |
1080 | } | 1110 | } |
1081 | 1111 | ||
1082 | OFileViewInterface* OFileSelector::currentView()const | 1112 | OFileViewInterface* OFileSelector::currentView()const |
1083 | { | 1113 | { |
1084 | return m_current; | 1114 | return m_current; |
1085 | } | 1115 | } |
1086 | 1116 | ||
1087 | bool OFileSelector::showNew()const | 1117 | bool OFileSelector::showNew()const |
1088 | { | 1118 | { |
1089 | return m_shNew; | 1119 | return m_shNew; |
1090 | } | 1120 | } |
1091 | 1121 | ||
1092 | bool OFileSelector::showClose()const | 1122 | bool OFileSelector::showClose()const |
1093 | { | 1123 | { |
1094 | return m_shClose; | 1124 | return m_shClose; |
1095 | } | 1125 | } |
1096 | 1126 | ||
diff --git a/libopie2/opieui/fileselector/ofileselector.h b/libopie2/opieui/fileselector/ofileselector.h index de2b98a..b1cd405 100644 --- a/libopie2/opieui/fileselector/ofileselector.h +++ b/libopie2/opieui/fileselector/ofileselector.h | |||
@@ -1,185 +1,186 @@ | |||
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,2003 Holger Freyther <zecke@handhelds.org> | 3 | .=l. Copyright (C) 2002,2003 Holger Freyther <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 |
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 | This is based on code and ideas of | 30 | This is based on code and ideas of |
31 | L. J. Potter ljp@llornkcor.com | 31 | L. J. Potter ljp@llornkcor.com |
32 | Thanks a lot | 32 | Thanks a lot |
33 | */ | 33 | */ |
34 | 34 | ||
35 | #ifndef OFILESELECTOR_H | 35 | #ifndef OFILESELECTOR_H |
36 | #define OFILESELECTOR_H | 36 | #define OFILESELECTOR_H |
37 | 37 | ||
38 | /* OPIE */ | 38 | /* OPIE */ |
39 | #include <qpe/applnk.h> | 39 | #include <qpe/applnk.h> |
40 | 40 | ||
41 | /* QT */ | 41 | /* QT */ |
42 | #include <qlist.h> | 42 | #include <qlist.h> |
43 | #include <qwidget.h> | 43 | #include <qwidget.h> |
44 | #include <qmap.h> | 44 | #include <qmap.h> |
45 | #include <qvaluelist.h> | 45 | #include <qvaluelist.h> |
46 | #include <qstringlist.h> | 46 | #include <qstringlist.h> |
47 | #include <qlist.h> | 47 | #include <qlist.h> |
48 | 48 | ||
49 | class QLineEdit; | 49 | class QLineEdit; |
50 | class QComboBox; | 50 | class QComboBox; |
51 | class QWidgetStack; | 51 | class QWidgetStack; |
52 | class QHBox; | 52 | class QHBox; |
53 | 53 | ||
54 | typedef QMap<QString, QStringList> MimeTypes; | 54 | typedef QMap<QString, QStringList> MimeTypes; |
55 | 55 | ||
56 | namespace Opie { | 56 | namespace Opie { |
57 | namespace Ui { | 57 | namespace Ui { |
58 | 58 | ||
59 | namespace Internal { | 59 | namespace Internal { |
60 | class OFileViewInterface; | 60 | class OFileViewInterface; |
61 | class OFileViewFileListView; | 61 | class OFileViewFileListView; |
62 | } | 62 | } |
63 | 63 | ||
64 | 64 | ||
65 | /** | 65 | /** |
66 | * @short a dropin replacement for the FileSelector | 66 | * @short a dropin replacement for the FileSelector |
67 | * | 67 | * |
68 | * This class is first used insert the OFileDialog. | 68 | * This class is first used insert the OFileDialog. |
69 | * It supports multiple view and mimetype filtering for now. | 69 | * It supports multiple view and mimetype filtering for now. |
70 | * | 70 | * |
71 | * @see OFileDialog | 71 | * @see OFileDialog |
72 | * @see FileSelector | 72 | * @see FileSelector |
73 | * @author zecke | 73 | * @author zecke |
74 | * @version 0.1 | 74 | * @version 0.1 |
75 | */ | 75 | */ |
76 | class OFileSelector : public QWidget | 76 | class OFileSelector : public QWidget |
77 | { | 77 | { |
78 | Q_OBJECT | 78 | Q_OBJECT |
79 | friend class Internal::OFileViewInterface; | 79 | friend class Internal::OFileViewInterface; |
80 | friend class Internal::OFileViewFileListView; | 80 | friend class Internal::OFileViewFileListView; |
81 | 81 | ||
82 | public: | 82 | public: |
83 | /** | 83 | /** |
84 | * The Mode of the Fileselector | 84 | * The Mode of the Fileselector |
85 | * Open = Open A File | 85 | * Open = Open A File |
86 | * Save = Save a File | 86 | * Save = Save a File |
87 | * FILESELECTOR = As A GUI in a screen to select a file | 87 | * FILESELECTOR = As A GUI in a screen to select a file |
88 | * SelectDir = Select a Directory | ||
88 | */ | 89 | */ |
89 | enum Mode { Open=1, Save=2, FileSelector=4, OPEN=1, SAVE=2, FILESELECTOR=4 }; | 90 | enum Mode { Open = 1, Save = 2, DirectorySelector = 3, FileSelector = 4, OPEN = 1, SAVE = 2, DIRECTORYSELECTOR = 3, FILESELECTOR = 4 }; |
90 | // enum OldMode { OPEN=1, SAVE=2, FILESELECTOR = 4 }; | 91 | // enum OldMode { OPEN=1, SAVE=2, FILESELECTOR = 4 }; |
91 | /** | 92 | /** |
92 | * Normal = The old FileSelector | 93 | * Normal = The old FileSelector |
93 | * Extended = Dir View | 94 | * Extended = Dir View |
94 | * ExtendedAll = Dir View with all hidden files | 95 | * ExtendedAll = Dir View with all hidden files |
95 | * Default = What the vendor considers best | 96 | * Default = What the vendor considers best |
96 | */ | 97 | */ |
97 | enum Selector { Normal = 0, Extended=1, ExtendedAll =2, Default=3, NORMAL=0,EXTENDED=1, EXTENDED_ALL =2, DEFAULT=3 }; | 98 | enum Selector { Normal = 0, Extended=1, ExtendedAll =2, Default=3, NORMAL=0,EXTENDED=1, EXTENDED_ALL =2, DEFAULT=3 }; |
98 | // enum OldSelector { NORMAL = 0, EXTENDED =1, EXTENDED_ALL = 2}; | 99 | // enum OldSelector { NORMAL = 0, EXTENDED =1, EXTENDED_ALL = 2}; |
99 | 100 | ||
100 | OFileSelector(QWidget* parent, int mode, int selector, | 101 | OFileSelector(QWidget* parent, int mode, int selector, |
101 | const QString& dirName, | 102 | const QString& dirName, |
102 | const QString& fileName, | 103 | const QString& fileName, |
103 | const MimeTypes& mimetypes = MimeTypes(), | 104 | const MimeTypes& mimetypes = MimeTypes(), |
104 | bool newVisible = FALSE, bool closeVisible = FALSE ); | 105 | bool newVisible = FALSE, bool closeVisible = FALSE ); |
105 | 106 | ||
106 | OFileSelector(const QString& mimeFilter, QWidget* parent, | 107 | OFileSelector(const QString& mimeFilter, QWidget* parent, |
107 | const char* name = 0, bool newVisible = TRUE, bool closeVisible = FALSE ); | 108 | const char* name = 0, bool newVisible = TRUE, bool closeVisible = FALSE ); |
108 | ~OFileSelector(); | 109 | ~OFileSelector(); |
109 | 110 | ||
110 | const DocLnk* selected(); | 111 | const DocLnk* selected(); |
111 | 112 | ||
112 | QString selectedName()const; | 113 | QString selectedName()const; |
113 | QString selectedPath()const; | 114 | QString selectedPath()const; |
114 | QString directory()const; | 115 | QString directory()const; |
115 | 116 | ||
116 | DocLnk selectedDocument()const; | 117 | DocLnk selectedDocument()const; |
117 | 118 | ||
118 | int fileCount()const; | 119 | int fileCount()const; |
119 | void reread(); | 120 | void reread(); |
120 | 121 | ||
121 | int mode()const; | 122 | int mode()const; |
122 | int selector()const; | 123 | int selector()const; |
123 | 124 | ||
124 | /** | 125 | /** |
125 | * Set the Icon visible | 126 | * Set the Icon visible |
126 | * @param b Show or Hide the New Button | 127 | * @param b Show or Hide the New Button |
127 | */ | 128 | */ |
128 | void setNewVisible( bool b ); | 129 | void setNewVisible( bool b ); |
129 | 130 | ||
130 | /** | 131 | /** |
131 | * Set the Icon visible | 132 | * Set the Icon visible |
132 | */ | 133 | */ |
133 | void setCloseVisible( bool b ); | 134 | void setCloseVisible( bool b ); |
134 | 135 | ||
135 | /** | 136 | /** |
136 | * Set the Name Line visible | 137 | * Set the Name Line visible |
137 | */ | 138 | */ |
138 | void setNameVisible( bool b ); | 139 | void setNameVisible( bool b ); |
139 | 140 | ||
140 | signals: | 141 | signals: |
141 | /** | 142 | /** |
142 | * dirSelected is emitted whenever changed into a different dir | 143 | * dirSelected is emitted whenever changed into a different dir |
143 | */ | 144 | */ |
144 | void dirSelected( const QString& ); | 145 | void dirSelected( const QString& ); |
145 | 146 | ||
146 | /** | 147 | /** |
147 | * fileSelected is emitted when a file is selected | 148 | * fileSelected is emitted when a file is selected |
148 | * it uses a DocLnk as parameter | 149 | * it uses a DocLnk as parameter |
149 | */ | 150 | */ |
150 | void fileSelected( const DocLnk& ); | 151 | void fileSelected( const DocLnk& ); |
151 | 152 | ||
152 | /** | 153 | /** |
153 | * fileSelected is emitted when a file is selected | 154 | * fileSelected is emitted when a file is selected |
154 | * the complete path is a parameter | 155 | * the complete path is a parameter |
155 | */ | 156 | */ |
156 | void fileSelected( const QString& ); | 157 | void fileSelected( const QString& ); |
157 | 158 | ||
158 | /** | 159 | /** |
159 | * Create a new File with a DocLnk | 160 | * Create a new File with a DocLnk |
160 | */ | 161 | */ |
161 | void newSelected( const DocLnk& ); | 162 | void newSelected( const DocLnk& ); |
162 | 163 | ||
163 | void closeMe(); | 164 | void closeMe(); |
164 | 165 | ||
165 | /** | 166 | /** |
166 | * Ok is emitted on a Qt::Key_Return or Q::Key_Enter | 167 | * Ok is emitted on a Qt::Key_Return or Q::Key_Enter |
167 | * in the line edit | 168 | * in the line edit |
168 | */ | 169 | */ |
169 | void ok(); | 170 | void ok(); |
170 | void cancel(); | 171 | void cancel(); |
171 | 172 | ||
172 | /* used by the ViewInterface */ | 173 | /* used by the ViewInterface */ |
173 | private: | 174 | private: |
174 | bool showNew()const; | 175 | bool showNew()const; |
175 | bool showClose()const; | 176 | bool showClose()const; |
176 | MimeTypes mimeTypes()const; | 177 | MimeTypes mimeTypes()const; |
177 | QStringList currentMimeType()const; | 178 | QStringList currentMimeType()const; |
178 | 179 | ||
179 | private: | 180 | private: |
180 | /* inits the Widgets */ | 181 | /* inits the Widgets */ |
181 | void initUI(); | 182 | void initUI(); |
182 | /* inits the MimeType ComboBox content + connects signals and slots */ | 183 | /* inits the MimeType ComboBox content + connects signals and slots */ |
183 | void initMime(); | 184 | void initMime(); |
184 | /* init the Views :) */ | 185 | /* init the Views :) */ |
185 | void initViews(); | 186 | void initViews(); |