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