-rw-r--r-- | libopie/ofileselector.cc | 64 | ||||
-rw-r--r-- | libopie/ofileselector.h | 6 |
2 files changed, 67 insertions, 3 deletions
diff --git a/libopie/ofileselector.cc b/libopie/ofileselector.cc index 53616f7..c9abde1 100644 --- a/libopie/ofileselector.cc +++ b/libopie/ofileselector.cc | |||
@@ -1,180 +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 <> | 3 | .=l. Copyright (c) 2002 <> |
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 <qnamespace.h> | 29 | #include <qnamespace.h> |
30 | #include <qpushbutton.h> | 30 | #include <qpushbutton.h> |
31 | #include <qcombobox.h> | 31 | #include <qcombobox.h> |
32 | #include <qhbox.h> | 32 | #include <qhbox.h> |
33 | #include <qvbox.h> | 33 | #include <qvbox.h> |
34 | #include <qlayout.h> | 34 | #include <qlayout.h> |
35 | #include <qwidgetstack.h> | 35 | #include <qwidgetstack.h> |
36 | #include <qlineedit.h> | 36 | #include <qlineedit.h> |
37 | #include <qcheckbox.h> | 37 | #include <qcheckbox.h> |
38 | #include <qlabel.h> | 38 | #include <qlabel.h> |
39 | 39 | ||
40 | #include <qpe/fileselector.h> | 40 | #include <qpe/fileselector.h> |
41 | #include <qpe/applnk.h> | ||
42 | #include <qpe/global.h> | ||
41 | 43 | ||
42 | #include "ofileselector.h" | 44 | #include "ofileselector.h" |
43 | 45 | ||
44 | 46 | ||
45 | OFileSelector::OFileSelector(QWidget *wid, int mode, int selector, const QString &dirName, | 47 | OFileSelector::OFileSelector(QWidget *wid, int mode, int selector, const QString &dirName, |
46 | const QString &fileName, const QStringList mimetypes ) : QWidget( wid ) | 48 | const QString &fileName, const QStringList mimetypes ) : QWidget( wid ) |
47 | { | 49 | { |
48 | m_selector = selector; | 50 | m_selector = selector; |
49 | m_currentDir = dirName; | 51 | m_currentDir = dirName; |
50 | m_name = fileName; | 52 | m_name = fileName; |
51 | m_mimetypes = mimetypes; | 53 | m_mimetypes = mimetypes; |
54 | if( mimetypes.isEmpty() ) | ||
55 | m_autoMime = true; | ||
56 | |||
52 | m_mode = mode; | 57 | m_mode = mode; |
53 | m_shTool = true; | 58 | m_shTool = true; |
54 | m_shPerm = true; | 59 | m_shPerm = true; |
55 | m_shLne = true; | 60 | m_shLne = true; |
56 | m_shChooser = true; | 61 | m_shChooser = true; |
57 | m_shYesNo = true; | 62 | m_shYesNo = true; |
58 | // for FILESELECTOR only view is interesting | 63 | // for FILESELECTOR only view is interesting |
59 | m_location = 0; | 64 | m_location = 0; |
60 | m_homeButton = 0; | 65 | m_homeButton = 0; |
61 | m_docButton = 0; | 66 | m_docButton = 0; |
62 | m_hideButton = 0; | 67 | m_hideButton = 0; |
63 | m_ok = 0; | 68 | m_ok = 0; |
64 | m_cancel = 0; | 69 | m_cancel = 0; |
65 | m_reread = 0; | 70 | m_reread = 0; |
66 | m_up = 0; | 71 | m_up = 0; |
67 | m_View = 0; | 72 | m_View = 0; |
68 | m_select = 0; | 73 | m_select = 0; |
69 | m_stack = 0; | 74 | m_stack = 0; |
70 | 75 | ||
71 | m_select = 0; | 76 | m_select = 0; |
72 | m_stack = 0; | 77 | m_stack = 0; |
73 | m_lay = 0; | 78 | m_lay = 0; |
74 | m_boxToolbar = 0; | 79 | m_boxToolbar = 0; |
75 | m_boxOk = 0; | 80 | m_boxOk = 0; |
76 | m_edit = 0; | 81 | m_edit = 0; |
77 | 82 | ||
78 | m_fnLabel = 0; | 83 | m_fnLabel = 0; |
79 | m_checkPerm = 0; | 84 | m_checkPerm = 0; |
80 | m_mimeCheck = 0; | 85 | m_mimeCheck = 0; |
81 | m_viewCheck = 0; | 86 | m_viewCheck = 0; |
82 | 87 | ||
83 | m_lay = new QVBoxLayout(this); | 88 | m_lay = new QVBoxLayout(this); |
84 | init(); | 89 | init(); |
90 | m_edit->setText( fileName ); | ||
85 | } | 91 | } |
86 | 92 | ||
87 | // let's initialize the gui | 93 | // let's initialize the gui |
88 | /** | 94 | /** |
89 | -------------------- | 95 | -------------------- |
90 | | cmbBox Button | | 96 | | cmbBox Button | |
91 | -------------------- | 97 | -------------------- |
92 | | FileSlector | | 98 | | FileSlector | |
93 | | or | | 99 | | or | |
94 | | OSelector | | 100 | | OSelector | |
95 | | | | 101 | | | |
96 | | | | 102 | | | |
97 | ____________________ | 103 | ____________________ |
98 | | LineEdit | | 104 | | LineEdit | |
99 | ____________________ | 105 | ____________________ |
100 | | Permission Bar | | 106 | | Permission Bar | |
101 | ____________________ | 107 | ____________________ |
102 | | ViewChoose | | 108 | | ViewChoose | |
103 | ____________________ | 109 | ____________________ |
104 | | Save Cancel| | 110 | | Save Cancel| |
105 | ____________________ | 111 | ____________________ |
106 | */ | 112 | */ |
107 | void OFileSelector::delItems() | 113 | void OFileSelector::delItems() |
108 | { | 114 | { |
109 | QLayoutIterator it = m_lay->iterator(); | 115 | QLayoutIterator it = m_lay->iterator(); |
110 | while ( it.current() != 0 ){ | 116 | while ( it.current() != 0 ){ |
111 | it.deleteCurrent(); | 117 | it.deleteCurrent(); |
112 | } | 118 | } |
113 | } | 119 | } |
114 | void OFileSelector::init() | 120 | void OFileSelector::init() |
115 | { | 121 | { |
116 | 122 | ||
117 | m_stack = new QWidgetStack(this, "wstack" ); | 123 | m_stack = new QWidgetStack(this, "wstack" ); |
118 | m_select = new FileSelector(m_mimetypes.join(";"), m_stack, "fileselector", FALSE, FALSE ); | 124 | m_select = new FileSelector(m_mimetypes.join(";"), m_stack, "fileselector", FALSE, FALSE ); |
119 | m_stack->addWidget(m_select, NORMAL ); | 125 | m_stack->addWidget(m_select, NORMAL ); |
120 | m_lay->addWidget(m_stack ); | 126 | m_lay->addWidget(m_stack ); |
121 | m_stack->raiseWidget(NORMAL ); | 127 | m_stack->raiseWidget(NORMAL ); |
122 | 128 | ||
123 | if(m_shLne ){ | 129 | if(m_shLne ){ |
124 | initializeName(); | 130 | initializeName(); |
125 | } | 131 | } |
126 | 132 | ||
127 | if(m_shPerm ){ | 133 | if(m_shPerm ){ |
128 | m_checkPerm = new QCheckBox(tr("Set Permission"), this, "Permission" ); | 134 | m_checkPerm = new QCheckBox(tr("Set Permission"), this, "Permission" ); |
129 | m_checkPerm->setChecked( false ); | 135 | m_checkPerm->setChecked( false ); |
130 | m_lay->addWidget(m_checkPerm ); | 136 | m_lay->addWidget(m_checkPerm ); |
131 | } | 137 | } |
132 | 138 | ||
133 | if( m_shChooser ) | 139 | if( m_shChooser ) |
134 | initializeChooser(); | 140 | initializeChooser(); |
135 | 141 | ||
136 | if(m_shYesNo ) | 142 | if(m_shYesNo ) |
137 | initializeYes(); | 143 | initializeYes(); |
138 | 144 | ||
139 | 145 | ||
140 | }; | 146 | }; |
141 | 147 | ||
142 | void OFileSelector::setShowYesCancel( bool show ) | 148 | void OFileSelector::setShowYesCancel( bool show ) |
143 | { | 149 | { |
144 | if ( show == m_shYesNo ) | 150 | if ( show == m_shYesNo ) |
145 | return; | 151 | return; |
146 | m_shYesNo = show; | 152 | m_shYesNo = show; |
147 | if( !show ){ | 153 | if( !show ){ |
148 | delete m_ok; | 154 | delete m_ok; |
149 | delete m_cancel; | 155 | delete m_cancel; |
150 | m_ok = 0; | 156 | m_ok = 0; |
151 | m_cancel = 0; | 157 | m_cancel = 0; |
152 | // delete m_boxOk; all ready deleted in delItems | 158 | // delete m_boxOk; all ready deleted in delItems |
153 | } | 159 | } |
154 | updateLay(); // recreate it and save the other states | 160 | updateLay(); // recreate it and save the other states |
155 | } | 161 | } |
156 | 162 | ||
157 | void OFileSelector::setShowToolbar( bool show ) | 163 | void OFileSelector::setShowToolbar( bool show ) |
158 | { | 164 | { |
159 | if ( m_shTool == show ) | 165 | if ( m_shTool == show ) |
160 | return; | 166 | return; |
161 | /* if( show ){ | 167 | /* if( show ){ |
162 | 168 | ||
163 | }else { | 169 | }else { |
164 | 170 | ||
165 | }*/ | 171 | }*/ |
166 | } | 172 | } |
167 | 173 | ||
168 | void OFileSelector::setShowPermissionBar( bool show ) | 174 | void OFileSelector::setShowPermissionBar( bool show ) |
169 | { | 175 | { |
170 | if( show == m_shPerm ) | 176 | if( show == m_shPerm ) |
171 | return; | 177 | return; |
172 | 178 | ||
173 | m_shPerm = show; | 179 | m_shPerm = show; |
174 | 180 | ||
175 | updateLay(); | 181 | updateLay(); |
176 | } | 182 | } |
177 | void OFileSelector::setShowLineEdit( bool show ) | 183 | void OFileSelector::setShowLineEdit( bool show ) |
178 | { | 184 | { |
179 | if( show == m_shLne ) | 185 | if( show == m_shLne ) |
180 | return; | 186 | return; |
@@ -233,121 +239,175 @@ void OFileSelector::updateLay() | |||
233 | /* if( m_shTool ) | 239 | /* if( m_shTool ) |
234 | // | 240 | // |
235 | else | 241 | else |
236 | // hide | 242 | // hide |
237 | */ | 243 | */ |
238 | // save the state | 244 | // save the state |
239 | bool check = false; | 245 | bool check = false; |
240 | if( m_checkPerm != 0 ) | 246 | if( m_checkPerm != 0 ) |
241 | check = m_checkPerm->isChecked(); | 247 | check = m_checkPerm->isChecked(); |
242 | QString text; | 248 | QString text; |
243 | 249 | ||
244 | if( m_edit != 0 ) | 250 | if( m_edit != 0 ) |
245 | text = m_edit->text(); | 251 | text = m_edit->text(); |
246 | // save current mimetype | 252 | // save current mimetype |
247 | 253 | ||
248 | delItems(); | 254 | delItems(); |
249 | delete m_checkPerm; | 255 | delete m_checkPerm; |
250 | delete m_edit; | 256 | delete m_edit; |
251 | delete m_fnLabel; | 257 | delete m_fnLabel; |
252 | delete m_ok; | 258 | delete m_ok; |
253 | delete m_cancel; | 259 | delete m_cancel; |
254 | delete m_mimeCheck; | 260 | delete m_mimeCheck; |
255 | delete m_viewCheck; | 261 | delete m_viewCheck; |
256 | delete m_select; // test | 262 | delete m_select; // test |
257 | delete m_stack; | 263 | delete m_stack; |
258 | //delete m_list; | 264 | //delete m_list; |
259 | init(); | 265 | init(); |
260 | if( m_shLne ) | 266 | if( m_shLne ) |
261 | m_edit->setText(text ); | 267 | m_edit->setText(text ); |
262 | if( m_shPerm ) | 268 | if( m_shPerm ) |
263 | m_checkPerm->setChecked(check ); | 269 | m_checkPerm->setChecked(check ); |
264 | } | 270 | } |
265 | void OFileSelector::reparse() | 271 | void OFileSelector::reparse() |
266 | { | 272 | { |
267 | 273 | ||
268 | } | 274 | } |
269 | QString OFileSelector::directory() | 275 | QString OFileSelector::directory() |
270 | { | 276 | { |
271 | QString string; | 277 | QString string; |
272 | return string; | 278 | return string; |
273 | } | 279 | } |
274 | int OFileSelector::fileCount() | 280 | int OFileSelector::fileCount() |
275 | { | 281 | { |
276 | return 0; | 282 | return 0; |
277 | } | 283 | } |
278 | void OFileSelector::slotOk( ) | 284 | void OFileSelector::slotOk( ) |
279 | { | 285 | { |
280 | emit ok(); | 286 | emit ok(); |
281 | } | 287 | } |
282 | void OFileSelector::slotCancel( ) | 288 | void OFileSelector::slotCancel( ) |
283 | { | 289 | { |
284 | emit cancel(); | 290 | emit cancel(); |
285 | } | 291 | } |
286 | 292 | ||
287 | void OFileSelector::initializeName() | 293 | void OFileSelector::initializeName() |
288 | { | 294 | { |
289 | m_boxName = new QHBoxLayout(this ); | 295 | m_boxName = new QHBoxLayout(this ); |
290 | m_edit = new QLineEdit(this ); | 296 | m_edit = new QLineEdit(this ); |
291 | m_fnLabel = new QLabel(this ); | 297 | m_fnLabel = new QLabel(this ); |
292 | m_fnLabel->setText(tr("Name:") ); | 298 | m_fnLabel->setText(tr("Name:") ); |
293 | m_boxName->addWidget(m_fnLabel ); | 299 | m_boxName->addWidget(m_fnLabel ); |
294 | m_boxName->insertSpacing(1, 8 ); | 300 | m_boxName->insertSpacing(1, 8 ); |
295 | m_boxName->addWidget(m_edit, 100 ); | 301 | m_boxName->addWidget(m_edit, 100 ); |
296 | 302 | ||
297 | m_lay->addLayout(m_boxName); | 303 | m_lay->addLayout(m_boxName); |
298 | } | 304 | } |
299 | void OFileSelector::initializeYes() | 305 | void OFileSelector::initializeYes() |
300 | { | 306 | { |
301 | m_ok = new QPushButton("&Save", this, "save" ); | 307 | m_ok = new QPushButton("&Save", this, "save" ); |
302 | m_cancel = new QPushButton("C&ancel", this, "cancel" ); | 308 | m_cancel = new QPushButton("C&ancel", this, "cancel" ); |
303 | m_boxOk = new QHBoxLayout(this ); | 309 | m_boxOk = new QHBoxLayout(this ); |
304 | m_boxOk->addWidget( m_ok, Qt::AlignHCenter ); | 310 | m_boxOk->addWidget( m_ok, Qt::AlignHCenter ); |
305 | m_boxOk->insertSpacing(1, 8 ); | 311 | m_boxOk->insertSpacing(1, 8 ); |
306 | m_boxOk->addWidget( m_cancel, Qt::AlignHCenter); | 312 | m_boxOk->addWidget( m_cancel, Qt::AlignHCenter); |
307 | m_lay->addLayout(m_boxOk ); | 313 | m_lay->addLayout(m_boxOk ); |
308 | connect(m_ok, SIGNAL(clicked() ), | 314 | connect(m_ok, SIGNAL(clicked() ), |
309 | this, SLOT(slotOk() ) ); | 315 | this, SLOT(slotOk() ) ); |
310 | connect(m_cancel, SIGNAL(clicked() ), | 316 | connect(m_cancel, SIGNAL(clicked() ), |
311 | this, SLOT(slotCancel() ) ); | 317 | this, SLOT(slotCancel() ) ); |
312 | 318 | ||
313 | } | 319 | } |
314 | void OFileSelector::initializeChooser() | 320 | void OFileSelector::initializeChooser() |
315 | { | 321 | { |
316 | m_boxView = new QHBoxLayout(this ); | 322 | m_boxView = new QHBoxLayout(this ); |
317 | 323 | ||
318 | m_mimeCheck = new QComboBox(this, "mime check"); | 324 | m_mimeCheck = new QComboBox(this, "mime check"); |
319 | m_viewCheck = new QComboBox(this, "view check"); | 325 | m_viewCheck = new QComboBox(this, "view check"); |
320 | m_boxView->addWidget(m_viewCheck, 0 ); | 326 | m_boxView->addWidget(m_viewCheck, 0 ); |
321 | m_boxView->insertSpacing(1, 8 ); | 327 | m_boxView->insertSpacing(1, 8 ); |
322 | m_boxView->addWidget(m_mimeCheck, 0 ); | 328 | m_boxView->addWidget(m_mimeCheck, 0 ); |
323 | m_lay->addLayout(m_boxView ); | 329 | m_lay->addLayout(m_boxView ); |
324 | 330 | ||
325 | m_viewCheck->insertItem(tr("Documents") ); | 331 | m_viewCheck->insertItem(tr("Documents") ); |
326 | m_viewCheck->insertItem(tr("Files") ); | 332 | m_viewCheck->insertItem(tr("Files") ); |
327 | m_viewCheck->insertItem(tr("All Files") ); | 333 | m_viewCheck->insertItem(tr("All Files") ); |
328 | 334 | ||
335 | if(!m_autoMime ) | ||
336 | m_mimeCheck->insertItem(m_mimetypes.join("," ) ); | ||
337 | else{ // check | ||
338 | updateMimes(); | ||
339 | m_mimeCheck->insertStringList( m_mimetypes ); | ||
340 | } | ||
341 | |||
329 | connect( m_viewCheck, SIGNAL(activated(const QString &) ), | 342 | connect( m_viewCheck, SIGNAL(activated(const QString &) ), |
330 | this, SLOT(slotViewCheck(const QString & ) ) ); | 343 | this, SLOT(slotViewCheck(const QString & ) ) ); |
331 | 344 | ||
345 | connect( m_mimeCheck, SIGNAL(activated(const QString &) ), | ||
346 | this, SLOT(slotMimeCheck(const QString & ) ) ); | ||
332 | } | 347 | } |
348 | void OFileSelector::slotMimeCheck(const QString &view ){ | ||
349 | if(m_selector == NORMAL ){ | ||
350 | delete m_select; | ||
351 | m_select = new FileSelector(view == "All" ? QString::null : view | ||
352 | , m_stack, "fileselector", FALSE, FALSE ); | ||
353 | m_stack->addWidget( m_select, NORMAL ); | ||
354 | m_stack->raiseWidget( NORMAL ); | ||
355 | }else{ | ||
333 | 356 | ||
334 | 357 | ||
358 | } | ||
359 | } | ||
360 | |||
335 | void OFileSelector::slotViewCheck(const QString &view ){ | 361 | void OFileSelector::slotViewCheck(const QString &view ){ |
336 | qWarning("changed: show %s", view.latin1() ); | 362 | qWarning("changed: show %s", view.latin1() ); |
337 | // if the current view is the one | 363 | // if the current view is the one |
338 | 364 | QString currMime = m_mimeCheck->currentText(); | |
339 | if( view == QString::fromLatin1("Documents") ){ | 365 | if( view == QString::fromLatin1("Documents") ){ |
340 | // get the mimetype now | 366 | // get the mimetype now |
341 | // check if we're the current widget and return | 367 | // check if we're the current widget and return |
368 | delete m_select; | ||
369 | m_select = new FileSelector( currMime == "All" ? QString::null : currMime, | ||
370 | m_stack,"fileselector", FALSE, FALSE ); | ||
371 | m_stack->addWidget( m_select, NORMAL ); | ||
372 | m_stack->raiseWidget( NORMAL ); | ||
373 | m_selector = NORMAL; | ||
374 | |||
342 | }else if(view == QString::fromLatin1("Files") ){ | 375 | }else if(view == QString::fromLatin1("Files") ){ |
343 | if( m_select != 0 ){ | 376 | if( m_select != 0 ){ |
344 | // remove from the stack | 377 | // remove from the stack |
345 | delete m_select; | 378 | delete m_select; |
346 | m_select = 0; | 379 | m_select = 0; |
380 | m_selector = EXTENDED; | ||
381 | // create the ListView or IconView | ||
382 | |||
383 | reparse(); | ||
347 | } | 384 | } |
348 | }else if(view == QString::fromLatin1("All Files") ) { | 385 | }else if(view == QString::fromLatin1("All Files") ) { |
349 | // remove from the stack | 386 | // remove from the stack |
350 | delete m_select; | 387 | delete m_select; |
351 | m_select = 0; | 388 | m_select = 0; |
389 | m_selector = EXTENDED_ALL; | ||
390 | |||
391 | reparse(); | ||
352 | }; | 392 | }; |
353 | }; | 393 | }; |
394 | |||
395 | |||
396 | void OFileSelector::updateMimes() // lets check which mode is active | ||
397 | // check the current dir for items then | ||
398 | { | ||
399 | m_mimetypes.clear(); | ||
400 | m_mimetypes.append("All" ); | ||
401 | if( m_selector == NORMAL ){ | ||
402 | DocLnkSet set; | ||
403 | Global::findDocuments(&set, QString::null ); | ||
404 | QListIterator<DocLnk> dit( set.children() ); | ||
405 | for ( ; dit.current(); ++dit ) { | ||
406 | if( !m_mimetypes.contains((*dit)->type() ) ) | ||
407 | m_mimetypes.append( (*dit)->type() ); | ||
408 | } | ||
409 | }else{ | ||
410 | |||
411 | |||
412 | } | ||
413 | }; | ||
diff --git a/libopie/ofileselector.h b/libopie/ofileselector.h index 3f53fa9..757a960 100644 --- a/libopie/ofileselector.h +++ b/libopie/ofileselector.h | |||
@@ -1,172 +1,176 @@ | |||
1 | /* | 1 | /* |
2 | This is based on code and idea of | 2 | This is based on code and idea of |
3 | L. J. Potter ljp@llornkcor.com | 3 | L. J. Potter ljp@llornkcor.com |
4 | Thanks a lot | 4 | Thanks a lot |
5 | 5 | ||
6 | 6 | ||
7 | =. This file is part of the OPIE Project | 7 | =. This file is part of the OPIE Project |
8 | .=l. Copyright (c) 2002 Holger Freyther <zecke@handhelds.org> | 8 | .=l. Copyright (c) 2002 Holger Freyther <zecke@handhelds.org> |
9 | .>+-= | 9 | .>+-= |
10 | _;:, .> :=|. This library is free software; you can | 10 | _;:, .> :=|. This library is free software; you can |
11 | .> <`_, > . <= redistribute it and/or modify it under | 11 | .> <`_, > . <= redistribute it and/or modify it under |
12 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 12 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
13 | .="- .-=="i, .._ License as published by the Free Software | 13 | .="- .-=="i, .._ License as published by the Free Software |
14 | - . .-<_> .<> Foundation; either version 2 of the License, | 14 | - . .-<_> .<> Foundation; either version 2 of the License, |
15 | ._= =} : or (at your option) any later version. | 15 | ._= =} : or (at your option) any later version. |
16 | .%`+i> _;_. | 16 | .%`+i> _;_. |
17 | .i_,=:_. -<s. This library is distributed in the hope that | 17 | .i_,=:_. -<s. This library is distributed in the hope that |
18 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 18 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
19 | : .. .:, . . . without even the implied warranty of | 19 | : .. .:, . . . without even the implied warranty of |
20 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 20 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
21 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 21 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
22 | ..}^=.= = ; Library General Public License for more | 22 | ..}^=.= = ; Library General Public License for more |
23 | ++= -. .` .: details. | 23 | ++= -. .` .: details. |
24 | : = ...= . :.=- | 24 | : = ...= . :.=- |
25 | -. .:....=;==+<; You should have received a copy of the GNU | 25 | -. .:....=;==+<; You should have received a copy of the GNU |
26 | -_. . . )=. = Library General Public License along with | 26 | -_. . . )=. = Library General Public License along with |
27 | -- :-=` this library; see the file COPYING.LIB. | 27 | -- :-=` this library; see the file COPYING.LIB. |
28 | If not, write to the Free Software Foundation, | 28 | If not, write to the Free Software Foundation, |
29 | Inc., 59 Temple Place - Suite 330, | 29 | Inc., 59 Temple Place - Suite 330, |
30 | Boston, MA 02111-1307, USA. | 30 | Boston, MA 02111-1307, USA. |
31 | 31 | ||
32 | */ | 32 | */ |
33 | 33 | ||
34 | #ifndef opiefileselector_h | 34 | #ifndef opiefileselector_h |
35 | #define opiefileselector_h | 35 | #define opiefileselector_h |
36 | 36 | ||
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 | #include <qstringlist.h> |
41 | 41 | ||
42 | #include <qlistview.h> | 42 | #include <qlistview.h> |
43 | /** This is OPIEs FileDialog Widget. You can use it | 43 | /** This is OPIEs FileDialog Widget. You can use it |
44 | * as a dropin replacement of the fileselector and | 44 | * as a dropin replacement of the fileselector and |
45 | * or use any of the new features. | 45 | * or use any of the new features. |
46 | * This is also a complete FileSave and FileLoad widget | 46 | * This is also a complete FileSave and FileLoad widget |
47 | * If you look for a Dialog check OFileDialog | 47 | * If you look for a Dialog check OFileDialog |
48 | * | 48 | * |
49 | */ | 49 | */ |
50 | class DocLnk; | 50 | class DocLnk; |
51 | class QCheckBox; | 51 | class QCheckBox; |
52 | class QComboBox; | 52 | class QComboBox; |
53 | class QPushButton; | 53 | class QPushButton; |
54 | class FileSelector; | 54 | class FileSelector; |
55 | class QGridLayout; | 55 | class QGridLayout; |
56 | class QLineEdit; | 56 | class QLineEdit; |
57 | class QLabel; | 57 | class QLabel; |
58 | class QWidgetStack; | 58 | class QWidgetStack; |
59 | class QHBoxLayout; | 59 | class QHBoxLayout; |
60 | class QVBoxLayout; | 60 | class QVBoxLayout; |
61 | 61 | ||
62 | class OFileSelectorItem : public QListViewItem { | 62 | class OFileSelectorItem : public QListViewItem { |
63 | public: | 63 | public: |
64 | OFileSelectorItem(QListView *view, const QPixmap &pixmap, const QString &path, | 64 | OFileSelectorItem(QListView *view, const QPixmap &pixmap, const QString &path, |
65 | const QString &date, const QString &size, | 65 | const QString &date, const QString &size, |
66 | bool isDir=false ): QListViewItem(view) { | 66 | bool isDir=false ): QListViewItem(view) { |
67 | setPixmap(0, pixmap ); | 67 | setPixmap(0, pixmap ); |
68 | setText(1, path ); | 68 | setText(1, path ); |
69 | setText(2, size ); | 69 | setText(2, size ); |
70 | setText(3, date ); | 70 | setText(3, date ); |
71 | dir = isDir; | 71 | dir = isDir; |
72 | } | 72 | } |
73 | bool isDir()const{ | 73 | bool isDir()const{ |
74 | return dir; | 74 | return dir; |
75 | } | 75 | } |
76 | QString path()const{ | 76 | QString path()const{ |
77 | return text(1 ); | 77 | return text(1 ); |
78 | } | 78 | } |
79 | private: | 79 | private: |
80 | bool dir:1; | 80 | bool dir:1; |
81 | }; | 81 | }; |
82 | 82 | ||
83 | class OFileSelector : public QWidget { | 83 | class OFileSelector : public QWidget { |
84 | Q_OBJECT | 84 | Q_OBJECT |
85 | public: | 85 | public: |
86 | enum Mode {OPEN=1, SAVE, FILESELECTOR }; | 86 | enum Mode {OPEN=1, SAVE, FILESELECTOR }; |
87 | enum Selector{NORMAL=1, EXTENDED }; | 87 | enum Selector{NORMAL=1, EXTENDED = 2, EXTENDED_ALL =4 }; |
88 | enum View { DIRS = 1, FILES = 2, TREE = 4, ICON = 8 }; | ||
88 | OFileSelector(QWidget *wid, int mode, int selector, const QString &dirName, const QString &fileName = QString::null, const QStringList mimetypes = QStringList() ); | 89 | OFileSelector(QWidget *wid, int mode, int selector, const QString &dirName, const QString &fileName = QString::null, const QStringList mimetypes = QStringList() ); |
89 | 90 | ||
90 | bool showToolbar() const { return m_shTool; }; | 91 | bool showToolbar() const { return m_shTool; }; |
91 | bool showPermissionBar() const { return m_shPerm; }; | 92 | bool showPermissionBar() const { return m_shPerm; }; |
92 | bool showLineEdit()const { return m_shLne; }; | 93 | bool showLineEdit()const { return m_shLne; }; |
93 | bool showChooser( )const { return m_shChooser; }; | 94 | bool showChooser( )const { return m_shChooser; }; |
94 | bool showYesCancel()const { return m_shYesNo; }; | 95 | bool showYesCancel()const { return m_shYesNo; }; |
95 | void setShowYesCancel( bool show ); | 96 | void setShowYesCancel( bool show ); |
96 | void setShowToolbar( bool show ); | 97 | void setShowToolbar( bool show ); |
97 | void setShowPermissionBar( bool show ); | 98 | void setShowPermissionBar( bool show ); |
98 | void setShowLineEdit(bool show) ; | 99 | void setShowLineEdit(bool show) ; |
99 | void setShowChooser( bool chooser ); | 100 | void setShowChooser( bool chooser ); |
100 | QCheckBox* permissionCheckbox(); | 101 | QCheckBox* permissionCheckbox(); |
101 | bool setPermission() const; | 102 | bool setPermission() const; |
102 | void setPermissionChecked( bool check ); | 103 | void setPermissionChecked( bool check ); |
103 | void setMode( int ); | 104 | void setMode( int ); |
104 | int mode()const { return m_mode; }; | 105 | int mode()const { return m_mode; }; |
105 | int selector()const { return m_selector; }; | 106 | int selector()const { return m_selector; }; |
106 | void setSelector( int ); | 107 | void setSelector( int ); |
107 | QString selectedName( ); | 108 | QString selectedName( ); |
108 | const DocLnk* selectedDocument()const; | 109 | const DocLnk* selectedDocument()const; |
109 | void updateLay(); | 110 | void updateLay(); |
110 | 111 | ||
111 | void reparse(); // re reads the dir | 112 | void reparse(); // re reads the dir |
112 | QString directory(); | 113 | QString directory(); |
113 | int fileCount(); | 114 | int fileCount(); |
114 | 115 | ||
115 | signals: | 116 | signals: |
116 | void fileSelected( const DocLnk & ); | 117 | void fileSelected( const DocLnk & ); |
117 | void fileSelected( const QString & ); | 118 | void fileSelected( const QString & ); |
118 | void closeMe(); | 119 | void closeMe(); |
119 | void ok(); | 120 | void ok(); |
120 | void cancel(); | 121 | void cancel(); |
121 | 122 | ||
122 | protected slots: | 123 | protected slots: |
123 | void slotOk(); | 124 | void slotOk(); |
124 | void slotCancel(); | 125 | void slotCancel(); |
125 | void slotViewCheck(const QString & ); | 126 | void slotViewCheck(const QString & ); |
127 | void slotMimeCheck(const QString & ); | ||
126 | protected: | 128 | protected: |
127 | void init(); | 129 | void init(); |
130 | void updateMimes(); | ||
128 | int m_mode, m_selector; | 131 | int m_mode, m_selector; |
129 | QComboBox *m_location, *m_mimeCheck, *m_viewCheck; | 132 | QComboBox *m_location, *m_mimeCheck, *m_viewCheck; |
130 | QPushButton *m_homeButton, *m_docButton, *m_hideButton, *m_ok, *m_cancel; | 133 | QPushButton *m_homeButton, *m_docButton, *m_hideButton, *m_ok, *m_cancel; |
131 | QPushButton *m_reread, *m_up; | 134 | QPushButton *m_reread, *m_up; |
132 | QListView *m_View; | 135 | QListView *m_View; |
133 | QCheckBox *m_checkPerm; | 136 | QCheckBox *m_checkPerm; |
134 | 137 | ||
135 | QString m_currentDir; | 138 | QString m_currentDir; |
136 | QString m_name; | 139 | QString m_name; |
137 | QStringList m_mimetypes; | 140 | QStringList m_mimetypes; |
138 | 141 | ||
139 | FileSelector *m_select; | 142 | FileSelector *m_select; |
140 | QWidgetStack *m_stack; | 143 | QWidgetStack *m_stack; |
141 | QVBoxLayout *m_lay; | 144 | QVBoxLayout *m_lay; |
142 | QGridLayout *m_Oselector; | 145 | QGridLayout *m_Oselector; |
143 | 146 | ||
144 | QHBoxLayout *m_boxToolbar; | 147 | QHBoxLayout *m_boxToolbar; |
145 | QHBoxLayout *m_boxOk; | 148 | QHBoxLayout *m_boxOk; |
146 | QHBoxLayout *m_boxName; | 149 | QHBoxLayout *m_boxName; |
147 | QHBoxLayout *m_boxView; | 150 | QHBoxLayout *m_boxView; |
148 | 151 | ||
149 | QLineEdit *m_edit; | 152 | QLineEdit *m_edit; |
150 | QLabel *m_fnLabel; | 153 | QLabel *m_fnLabel; |
151 | bool m_shTool:1; | 154 | bool m_shTool:1; |
152 | bool m_shPerm:1; | 155 | bool m_shPerm:1; |
153 | bool m_shLne:1; | 156 | bool m_shLne:1; |
154 | bool m_shChooser:1; | 157 | bool m_shChooser:1; |
155 | bool m_shYesNo:1; | 158 | bool m_shYesNo:1; |
156 | bool m_boCheckPerm:1; | 159 | bool m_boCheckPerm:1; |
160 | bool m_autoMime:1; | ||
157 | 161 | ||
158 | protected: | 162 | protected: |
159 | 163 | ||
160 | private: | 164 | private: |
161 | void delItems(); | 165 | void delItems(); |
162 | void initializeName(); | 166 | void initializeName(); |
163 | void initializeYes(); | 167 | void initializeYes(); |
164 | void initializeChooser(); | 168 | void initializeChooser(); |
165 | 169 | ||
166 | class OFileSelectorPrivate; | 170 | class OFileSelectorPrivate; |
167 | OFileSelectorPrivate *d; | 171 | OFileSelectorPrivate *d; |
168 | 172 | ||
169 | }; | 173 | }; |
170 | 174 | ||
171 | 175 | ||
172 | #endif | 176 | #endif |