-rw-r--r-- | libopie/libopie.pro | 4 | ||||
-rw-r--r-- | libopie/ofileselector.cc | 353 | ||||
-rw-r--r-- | libopie/ofileselector.h | 65 |
3 files changed, 404 insertions, 18 deletions
diff --git a/libopie/libopie.pro b/libopie/libopie.pro index ab56473..4ba2836 100644 --- a/libopie/libopie.pro +++ b/libopie/libopie.pro | |||
@@ -1,7 +1,7 @@ | |||
1 | TEMPLATE = lib | 1 | TEMPLATE = lib |
2 | CONFIG += qte warn_on release | 2 | CONFIG += qte warn_on release |
3 | HEADERS = tododb.h todoevent.h todoresource.h todovcalresource.h xmltree.h oconfig.h | 3 | HEADERS = ofileselector.h tododb.h todoevent.h todoresource.h todovcalresource.h xmltree.h oconfig.h |
4 | SOURCES = xmltree.cc tododb.cpp todoevent.cpp todovcalresource.cpp oconfig.cpp | 4 | SOURCES = ofileselector.cc xmltree.cc tododb.cpp todoevent.cpp todovcalresource.cpp oconfig.cpp |
5 | TARGET = opie | 5 | TARGET = opie |
6 | INCLUDEPATH += $(OPIEDIR)/include | 6 | INCLUDEPATH += $(OPIEDIR)/include |
7 | DESTDIR = $(QTDIR)/lib$(PROJMAK) | 7 | DESTDIR = $(QTDIR)/lib$(PROJMAK) |
diff --git a/libopie/ofileselector.cc b/libopie/ofileselector.cc new file mode 100644 index 0000000..53616f7 --- a/dev/null +++ b/libopie/ofileselector.cc | |||
@@ -0,0 +1,353 @@ | |||
1 | /* | ||
2 | =. This file is part of the OPIE Project | ||
3 | .=l. Copyright (c) 2002 <> | ||
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 | #include <qnamespace.h> | ||
30 | #include <qpushbutton.h> | ||
31 | #include <qcombobox.h> | ||
32 | #include <qhbox.h> | ||
33 | #include <qvbox.h> | ||
34 | #include <qlayout.h> | ||
35 | #include <qwidgetstack.h> | ||
36 | #include <qlineedit.h> | ||
37 | #include <qcheckbox.h> | ||
38 | #include <qlabel.h> | ||
39 | |||
40 | #include <qpe/fileselector.h> | ||
41 | |||
42 | #include "ofileselector.h" | ||
43 | |||
44 | |||
45 | OFileSelector::OFileSelector(QWidget *wid, int mode, int selector, const QString &dirName, | ||
46 | const QString &fileName, const QStringList mimetypes ) : QWidget( wid ) | ||
47 | { | ||
48 | m_selector = selector; | ||
49 | m_currentDir = dirName; | ||
50 | m_name = fileName; | ||
51 | m_mimetypes = mimetypes; | ||
52 | m_mode = mode; | ||
53 | m_shTool = true; | ||
54 | m_shPerm = true; | ||
55 | m_shLne = true; | ||
56 | m_shChooser = true; | ||
57 | m_shYesNo = true; | ||
58 | // for FILESELECTOR only view is interesting | ||
59 | m_location = 0; | ||
60 | m_homeButton = 0; | ||
61 | m_docButton = 0; | ||
62 | m_hideButton = 0; | ||
63 | m_ok = 0; | ||
64 | m_cancel = 0; | ||
65 | m_reread = 0; | ||
66 | m_up = 0; | ||
67 | m_View = 0; | ||
68 | m_select = 0; | ||
69 | m_stack = 0; | ||
70 | |||
71 | m_select = 0; | ||
72 | m_stack = 0; | ||
73 | m_lay = 0; | ||
74 | m_boxToolbar = 0; | ||
75 | m_boxOk = 0; | ||
76 | m_edit = 0; | ||
77 | |||
78 | m_fnLabel = 0; | ||
79 | m_checkPerm = 0; | ||
80 | m_mimeCheck = 0; | ||
81 | m_viewCheck = 0; | ||
82 | |||
83 | m_lay = new QVBoxLayout(this); | ||
84 | init(); | ||
85 | } | ||
86 | |||
87 | // let's initialize the gui | ||
88 | /** | ||
89 | -------------------- | ||
90 | | cmbBox Button | | ||
91 | -------------------- | ||
92 | | FileSlector | | ||
93 | | or | | ||
94 | | OSelector | | ||
95 | | | | ||
96 | | | | ||
97 | ____________________ | ||
98 | | LineEdit | | ||
99 | ____________________ | ||
100 | | Permission Bar | | ||
101 | ____________________ | ||
102 | | ViewChoose | | ||
103 | ____________________ | ||
104 | | Save Cancel| | ||
105 | ____________________ | ||
106 | */ | ||
107 | void OFileSelector::delItems() | ||
108 | { | ||
109 | QLayoutIterator it = m_lay->iterator(); | ||
110 | while ( it.current() != 0 ){ | ||
111 | it.deleteCurrent(); | ||
112 | } | ||
113 | } | ||
114 | void OFileSelector::init() | ||
115 | { | ||
116 | |||
117 | m_stack = new QWidgetStack(this, "wstack" ); | ||
118 | m_select = new FileSelector(m_mimetypes.join(";"), m_stack, "fileselector", FALSE, FALSE ); | ||
119 | m_stack->addWidget(m_select, NORMAL ); | ||
120 | m_lay->addWidget(m_stack ); | ||
121 | m_stack->raiseWidget(NORMAL ); | ||
122 | |||
123 | if(m_shLne ){ | ||
124 | initializeName(); | ||
125 | } | ||
126 | |||
127 | if(m_shPerm ){ | ||
128 | m_checkPerm = new QCheckBox(tr("Set Permission"), this, "Permission" ); | ||
129 | m_checkPerm->setChecked( false ); | ||
130 | m_lay->addWidget(m_checkPerm ); | ||
131 | } | ||
132 | |||
133 | if( m_shChooser ) | ||
134 | initializeChooser(); | ||
135 | |||
136 | if(m_shYesNo ) | ||
137 | initializeYes(); | ||
138 | |||
139 | |||
140 | }; | ||
141 | |||
142 | void OFileSelector::setShowYesCancel( bool show ) | ||
143 | { | ||
144 | if ( show == m_shYesNo ) | ||
145 | return; | ||
146 | m_shYesNo = show; | ||
147 | if( !show ){ | ||
148 | delete m_ok; | ||
149 | delete m_cancel; | ||
150 | m_ok = 0; | ||
151 | m_cancel = 0; | ||
152 | // delete m_boxOk; all ready deleted in delItems | ||
153 | } | ||
154 | updateLay(); // recreate it and save the other states | ||
155 | } | ||
156 | |||
157 | void OFileSelector::setShowToolbar( bool show ) | ||
158 | { | ||
159 | if ( m_shTool == show ) | ||
160 | return; | ||
161 | /* if( show ){ | ||
162 | |||
163 | }else { | ||
164 | |||
165 | }*/ | ||
166 | } | ||
167 | |||
168 | void OFileSelector::setShowPermissionBar( bool show ) | ||
169 | { | ||
170 | if( show == m_shPerm ) | ||
171 | return; | ||
172 | |||
173 | m_shPerm = show; | ||
174 | |||
175 | updateLay(); | ||
176 | } | ||
177 | void OFileSelector::setShowLineEdit( bool show ) | ||
178 | { | ||
179 | if( show == m_shLne ) | ||
180 | return; | ||
181 | |||
182 | m_shLne = show; | ||
183 | if( !show ){ | ||
184 | delete m_edit; | ||
185 | delete m_fnLabel; | ||
186 | m_edit = 0; | ||
187 | m_fnLabel = 0; | ||
188 | //delete m_boxName; will be deleted | ||
189 | } | ||
190 | updateLay(); | ||
191 | } | ||
192 | void OFileSelector::setShowChooser( bool show ) | ||
193 | { | ||
194 | if( show = m_shChooser ) | ||
195 | return; | ||
196 | m_shChooser = show; | ||
197 | if( !show ){ | ||
198 | delete m_mimeCheck; | ||
199 | delete m_viewCheck; | ||
200 | m_mimeCheck = 0; | ||
201 | m_viewCheck = 0; | ||
202 | } | ||
203 | updateLay(); | ||
204 | } | ||
205 | QCheckBox* OFileSelector::permissionCheckbox( ) | ||
206 | { | ||
207 | return m_checkPerm; | ||
208 | } | ||
209 | bool OFileSelector::setPermission( ) const | ||
210 | { | ||
211 | if( m_checkPerm == 0 ) | ||
212 | return false; | ||
213 | else | ||
214 | return m_checkPerm->isChecked(); | ||
215 | } | ||
216 | void OFileSelector::setPermissionChecked( bool check ) | ||
217 | { | ||
218 | if( m_checkPerm == 0 ) | ||
219 | return; | ||
220 | m_checkPerm->setChecked( check ); | ||
221 | } | ||
222 | QString OFileSelector::selectedName( ) | ||
223 | { | ||
224 | QString string; | ||
225 | return string; | ||
226 | } | ||
227 | const DocLnk* OFileSelector::selectedDocument( )const | ||
228 | { | ||
229 | return 0; | ||
230 | } | ||
231 | void OFileSelector::updateLay() | ||
232 | { | ||
233 | /* if( m_shTool ) | ||
234 | // | ||
235 | else | ||
236 | // hide | ||
237 | */ | ||
238 | // save the state | ||
239 | bool check = false; | ||
240 | if( m_checkPerm != 0 ) | ||
241 | check = m_checkPerm->isChecked(); | ||
242 | QString text; | ||
243 | |||
244 | if( m_edit != 0 ) | ||
245 | text = m_edit->text(); | ||
246 | // save current mimetype | ||
247 | |||
248 | delItems(); | ||
249 | delete m_checkPerm; | ||
250 | delete m_edit; | ||
251 | delete m_fnLabel; | ||
252 | delete m_ok; | ||
253 | delete m_cancel; | ||
254 | delete m_mimeCheck; | ||
255 | delete m_viewCheck; | ||
256 | delete m_select; // test | ||
257 | delete m_stack; | ||
258 | //delete m_list; | ||
259 | init(); | ||
260 | if( m_shLne ) | ||
261 | m_edit->setText(text ); | ||
262 | if( m_shPerm ) | ||
263 | m_checkPerm->setChecked(check ); | ||
264 | } | ||
265 | void OFileSelector::reparse() | ||
266 | { | ||
267 | |||
268 | } | ||
269 | QString OFileSelector::directory() | ||
270 | { | ||
271 | QString string; | ||
272 | return string; | ||
273 | } | ||
274 | int OFileSelector::fileCount() | ||
275 | { | ||
276 | return 0; | ||
277 | } | ||
278 | void OFileSelector::slotOk( ) | ||
279 | { | ||
280 | emit ok(); | ||
281 | } | ||
282 | void OFileSelector::slotCancel( ) | ||
283 | { | ||
284 | emit cancel(); | ||
285 | } | ||
286 | |||
287 | void OFileSelector::initializeName() | ||
288 | { | ||
289 | m_boxName = new QHBoxLayout(this ); | ||
290 | m_edit = new QLineEdit(this ); | ||
291 | m_fnLabel = new QLabel(this ); | ||
292 | m_fnLabel->setText(tr("Name:") ); | ||
293 | m_boxName->addWidget(m_fnLabel ); | ||
294 | m_boxName->insertSpacing(1, 8 ); | ||
295 | m_boxName->addWidget(m_edit, 100 ); | ||
296 | |||
297 | m_lay->addLayout(m_boxName); | ||
298 | } | ||
299 | void OFileSelector::initializeYes() | ||
300 | { | ||
301 | m_ok = new QPushButton("&Save", this, "save" ); | ||
302 | m_cancel = new QPushButton("C&ancel", this, "cancel" ); | ||
303 | m_boxOk = new QHBoxLayout(this ); | ||
304 | m_boxOk->addWidget( m_ok, Qt::AlignHCenter ); | ||
305 | m_boxOk->insertSpacing(1, 8 ); | ||
306 | m_boxOk->addWidget( m_cancel, Qt::AlignHCenter); | ||
307 | m_lay->addLayout(m_boxOk ); | ||
308 | connect(m_ok, SIGNAL(clicked() ), | ||
309 | this, SLOT(slotOk() ) ); | ||
310 | connect(m_cancel, SIGNAL(clicked() ), | ||
311 | this, SLOT(slotCancel() ) ); | ||
312 | |||
313 | } | ||
314 | void OFileSelector::initializeChooser() | ||
315 | { | ||
316 | m_boxView = new QHBoxLayout(this ); | ||
317 | |||
318 | m_mimeCheck = new QComboBox(this, "mime check"); | ||
319 | m_viewCheck = new QComboBox(this, "view check"); | ||
320 | m_boxView->addWidget(m_viewCheck, 0 ); | ||
321 | m_boxView->insertSpacing(1, 8 ); | ||
322 | m_boxView->addWidget(m_mimeCheck, 0 ); | ||
323 | m_lay->addLayout(m_boxView ); | ||
324 | |||
325 | m_viewCheck->insertItem(tr("Documents") ); | ||
326 | m_viewCheck->insertItem(tr("Files") ); | ||
327 | m_viewCheck->insertItem(tr("All Files") ); | ||
328 | |||
329 | connect( m_viewCheck, SIGNAL(activated(const QString &) ), | ||
330 | this, SLOT(slotViewCheck(const QString & ) ) ); | ||
331 | |||
332 | } | ||
333 | |||
334 | |||
335 | void OFileSelector::slotViewCheck(const QString &view ){ | ||
336 | qWarning("changed: show %s", view.latin1() ); | ||
337 | // if the current view is the one | ||
338 | |||
339 | if( view == QString::fromLatin1("Documents") ){ | ||
340 | // get the mimetype now | ||
341 | // check if we're the current widget and return | ||
342 | }else if(view == QString::fromLatin1("Files") ){ | ||
343 | if( m_select != 0 ){ | ||
344 | // remove from the stack | ||
345 | delete m_select; | ||
346 | m_select = 0; | ||
347 | } | ||
348 | }else if(view == QString::fromLatin1("All Files") ) { | ||
349 | // remove from the stack | ||
350 | delete m_select; | ||
351 | m_select = 0; | ||
352 | }; | ||
353 | }; | ||
diff --git a/libopie/ofileselector.h b/libopie/ofileselector.h index 405a3ce..3f53fa9 100644 --- a/libopie/ofileselector.h +++ b/libopie/ofileselector.h | |||
@@ -37,6 +37,7 @@ | |||
37 | #include <qwidget.h> | 37 | #include <qwidget.h> |
38 | #include <qstring.h> | 38 | #include <qstring.h> |
39 | #include <qpixmap.h> | 39 | #include <qpixmap.h> |
40 | #include <qstringlist.h> | ||
40 | 41 | ||
41 | #include <qlistview.h> | 42 | #include <qlistview.h> |
42 | /** This is OPIEs FileDialog Widget. You can use it | 43 | /** This is OPIEs FileDialog Widget. You can use it |
@@ -52,12 +53,17 @@ class QComboBox; | |||
52 | class QPushButton; | 53 | class QPushButton; |
53 | class FileSelector; | 54 | class FileSelector; |
54 | class QGridLayout; | 55 | class QGridLayout; |
56 | class QLineEdit; | ||
57 | class QLabel; | ||
58 | class QWidgetStack; | ||
59 | class QHBoxLayout; | ||
60 | class QVBoxLayout; | ||
55 | 61 | ||
56 | class OFileSelectorItem : public QListViewItem { | 62 | class OFileSelectorItem : public QListViewItem { |
57 | public: | 63 | public: |
58 | OFileSelectorItem(const QPixmap &pixmap, const QString &path, | 64 | OFileSelectorItem(QListView *view, const QPixmap &pixmap, const QString &path, |
59 | const QString &date, const QString &size, | 65 | const QString &date, const QString &size, |
60 | bool isDir=false ){ | 66 | bool isDir=false ): QListViewItem(view) { |
61 | setPixmap(0, pixmap ); | 67 | setPixmap(0, pixmap ); |
62 | setText(1, path ); | 68 | setText(1, path ); |
63 | setText(2, size ); | 69 | setText(2, size ); |
@@ -79,11 +85,14 @@ class OFileSelector : public QWidget { | |||
79 | public: | 85 | public: |
80 | enum Mode {OPEN=1, SAVE, FILESELECTOR }; | 86 | enum Mode {OPEN=1, SAVE, FILESELECTOR }; |
81 | enum Selector{NORMAL=1, EXTENDED }; | 87 | enum Selector{NORMAL=1, EXTENDED }; |
82 | OFileSelector(int mode, const QString &dirName, const QString &fileName = Qtring::null, const QStringList mimetypes = QStringList() ); | 88 | OFileSelector(QWidget *wid, int mode, int selector, const QString &dirName, const QString &fileName = QString::null, const QStringList mimetypes = QStringList() ); |
83 | bool showToolbar() const; | 89 | |
84 | bool showPermissionBar() const; | 90 | bool showToolbar() const { return m_shTool; }; |
85 | bool showLineEdit()const; | 91 | bool showPermissionBar() const { return m_shPerm; }; |
86 | bool showChooser( )const; | 92 | bool showLineEdit()const { return m_shLne; }; |
93 | bool showChooser( )const { return m_shChooser; }; | ||
94 | bool showYesCancel()const { return m_shYesNo; }; | ||
95 | void setShowYesCancel( bool show ); | ||
87 | void setShowToolbar( bool show ); | 96 | void setShowToolbar( bool show ); |
88 | void setShowPermissionBar( bool show ); | 97 | void setShowPermissionBar( bool show ); |
89 | void setShowLineEdit(bool show) ; | 98 | void setShowLineEdit(bool show) ; |
@@ -92,10 +101,12 @@ class OFileSelector : public QWidget { | |||
92 | bool setPermission() const; | 101 | bool setPermission() const; |
93 | void setPermissionChecked( bool check ); | 102 | void setPermissionChecked( bool check ); |
94 | void setMode( int ); | 103 | void setMode( int ); |
95 | int mode()const; | 104 | int mode()const { return m_mode; }; |
96 | 105 | int selector()const { return m_selector; }; | |
106 | void setSelector( int ); | ||
97 | QString selectedName( ); | 107 | QString selectedName( ); |
98 | const DocLnk* selectedDocument()const; | 108 | const DocLnk* selectedDocument()const; |
109 | void updateLay(); | ||
99 | 110 | ||
100 | void reparse(); // re reads the dir | 111 | void reparse(); // re reads the dir |
101 | QString directory(); | 112 | QString directory(); |
@@ -107,29 +118,51 @@ class OFileSelector : public QWidget { | |||
107 | void closeMe(); | 118 | void closeMe(); |
108 | void ok(); | 119 | void ok(); |
109 | void cancel(); | 120 | void cancel(); |
110 | protected: | 121 | |
122 | protected slots: | ||
111 | void slotOk(); | 123 | void slotOk(); |
112 | void slotCancel(); | 124 | void slotCancel(); |
113 | 125 | void slotViewCheck(const QString & ); | |
126 | protected: | ||
127 | void init(); | ||
114 | int m_mode, m_selector; | 128 | int m_mode, m_selector; |
115 | QComboBox *m_location; | 129 | QComboBox *m_location, *m_mimeCheck, *m_viewCheck; |
116 | QPushButton *m_homeButton, *m_docButton, *m_hideButton, *m_ok, *m_cancel; | 130 | QPushButton *m_homeButton, *m_docButton, *m_hideButton, *m_ok, *m_cancel; |
117 | QPushButton *m_reread, *m_up; | 131 | QPushButton *m_reread, *m_up; |
118 | QListView *m_View; | 132 | QListView *m_View; |
133 | QCheckBox *m_checkPerm; | ||
134 | |||
119 | QString m_currentDir; | 135 | QString m_currentDir; |
120 | FileSelector *m_Select; | 136 | QString m_name; |
137 | QStringList m_mimetypes; | ||
138 | |||
139 | FileSelector *m_select; | ||
121 | QWidgetStack *m_stack; | 140 | QWidgetStack *m_stack; |
122 | QGridLayout *m_lay; | 141 | QVBoxLayout *m_lay; |
123 | QHBox *m_toolbar; | 142 | QGridLayout *m_Oselector; |
124 | QHBox *m_ok; | 143 | |
144 | QHBoxLayout *m_boxToolbar; | ||
145 | QHBoxLayout *m_boxOk; | ||
146 | QHBoxLayout *m_boxName; | ||
147 | QHBoxLayout *m_boxView; | ||
148 | |||
149 | QLineEdit *m_edit; | ||
150 | QLabel *m_fnLabel; | ||
125 | bool m_shTool:1; | 151 | bool m_shTool:1; |
126 | bool m_shPerm:1; | 152 | bool m_shPerm:1; |
127 | bool m_shLne:1; | 153 | bool m_shLne:1; |
128 | bool m_shChooser:1; | 154 | bool m_shChooser:1; |
155 | bool m_shYesNo:1; | ||
156 | bool m_boCheckPerm:1; | ||
129 | 157 | ||
130 | protected: | 158 | protected: |
131 | 159 | ||
132 | private: | 160 | private: |
161 | void delItems(); | ||
162 | void initializeName(); | ||
163 | void initializeYes(); | ||
164 | void initializeChooser(); | ||
165 | |||
133 | class OFileSelectorPrivate; | 166 | class OFileSelectorPrivate; |
134 | OFileSelectorPrivate *d; | 167 | OFileSelectorPrivate *d; |
135 | 168 | ||