-rw-r--r-- | libopie/ofiledialog.cc | 81 |
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,156 +1,215 @@ | |||
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 |
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 | #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 | |||
42 | namespace { | ||
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 | * |
39 | * @param caption The caption of the dialog | 75 | * @param caption The caption of the dialog |
40 | * @param wid The parent widget | 76 | * @param wid The parent widget |
41 | * @param mode The mode of the OFileSelector @see OFileSelector | 77 | * @param mode The mode of the OFileSelector @see OFileSelector |
42 | * @param selector The selector of the OFileSelector | 78 | * @param selector The selector of the OFileSelector |
43 | * @param dirName the dir or resource to start from | 79 | * @param dirName the dir or resource to start from |
44 | * @param fileName a proposed or existing filename | 80 | * @param fileName a proposed or existing filename |
45 | * @param mimetypes The mimeTypes | 81 | * @param mimetypes The mimeTypes |
46 | */ | 82 | */ |
47 | OFileDialog::OFileDialog(const QString &caption, | 83 | OFileDialog::OFileDialog(const QString &caption, |
48 | QWidget *wid, int mode, int selector, | 84 | QWidget *wid, int mode, int selector, |
49 | const QString &dirName, | 85 | const QString &dirName, |
50 | const QString &fileName, | 86 | const QString &fileName, |
51 | const QMap<QString,QStringList>& mimetypes ) | 87 | const QMap<QString,QStringList>& mimetypes ) |
52 | : QDialog( wid, "OFileDialog", true ) | 88 | : QDialog( wid, "OFileDialog", true ) |
53 | { | 89 | { |
54 | // QVBoxLayout *lay = new QVBoxLayout(this); | 90 | // QVBoxLayout *lay = new QVBoxLayout(this); |
55 | //showMaximized(); | 91 | //showMaximized(); |
56 | QVBoxLayout *lay = new QVBoxLayout(this ); | 92 | QVBoxLayout *lay = new QVBoxLayout(this ); |
57 | file = new OFileSelector(this , mode, selector, | 93 | file = new OFileSelector(this , mode, selector, |
58 | dirName, fileName, | 94 | dirName, fileName, |
59 | mimetypes ); | 95 | mimetypes ); |
60 | lay->addWidget( file ); | 96 | lay->addWidget( file ); |
61 | 97 | ||
62 | //lay->addWidget( file ); | 98 | //lay->addWidget( file ); |
63 | //showFullScreen(); | 99 | //showFullScreen(); |
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 |
76 | * currently it return QString::null | 115 | * currently it return QString::null |
77 | */ | 116 | */ |
78 | QString OFileDialog::mimetype()const | 117 | QString OFileDialog::mimetype()const |
79 | { | 118 | { |
80 | return QString::null; | 119 | return QString::null; |
81 | } | 120 | } |
82 | 121 | ||
83 | /** | 122 | /** |
84 | * @return the fileName | 123 | * @return the fileName |
85 | */ | 124 | */ |
86 | QString OFileDialog::fileName()const | 125 | QString OFileDialog::fileName()const |
87 | { | 126 | { |
88 | return file->selectedName(); | 127 | return file->selectedName(); |
89 | } | 128 | } |
90 | 129 | ||
91 | /** | 130 | /** |
92 | * return a DocLnk to the current file | 131 | * return a DocLnk to the current file |
93 | */ | 132 | */ |
94 | DocLnk OFileDialog::selectedDocument()const | 133 | DocLnk OFileDialog::selectedDocument()const |
95 | { | 134 | { |
96 | return file->selectedDocument(); | 135 | return file->selectedDocument(); |
97 | } | 136 | } |
98 | 137 | ||
99 | /** | 138 | /** |
100 | * This opens up a filedialog in Open mode | 139 | * This opens up a filedialog in Open mode |
101 | * | 140 | * |
102 | * @param selector the Selector Mode | 141 | * @param selector the Selector Mode |
103 | * @param startDir Where to start from | 142 | * @param startDir Where to start from |
104 | * @param file A proposed filename | 143 | * @param file A proposed filename |
105 | * @param mimes A list of MimeTypes | 144 | * @param mimes A list of MimeTypes |
106 | * @param wid the parent | 145 | * @param wid the parent |
107 | * @param caption of the dialog if QString::null tr("Open") will be used | 146 | * @param caption of the dialog if QString::null tr("Open") will be used |
108 | * @return the fileName or QString::null | 147 | * @return the fileName or QString::null |
109 | */ | 148 | */ |
110 | QString OFileDialog::getOpenFileName(int selector, | 149 | QString 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 | } |
126 | 172 | ||
127 | /** | 173 | /** |
128 | * This opens up a file dialog in save mode | 174 | * This opens up a file dialog in save mode |
129 | * @see getOpenFileName | 175 | * @see getOpenFileName |
130 | */ | 176 | */ |
131 | QString OFileDialog::getSaveFileName(int selector, | 177 | QString 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 | } |
147 | 199 | ||
148 | void OFileDialog::slotFileSelected(const QString & ) | 200 | void OFileDialog::slotFileSelected(const QString & ) |
149 | { | 201 | { |
150 | accept(); | 202 | accept(); |
151 | } | 203 | } |
152 | void OFileDialog::slotDirSelected(const QString & ) | 204 | |
205 | void OFileDialog::slotSelectorOk( ) | ||
206 | { | ||
207 | accept(); | ||
208 | } | ||
209 | |||
210 | void OFileDialog::slotDirSelected(const QString &dir ) | ||
153 | { | 211 | { |
212 | setCaption( dir ); | ||
154 | // if mode | 213 | // if mode |
155 | //accept(); | 214 | //accept(); |
156 | } | 215 | } |