-rw-r--r-- | libopie/ofileselector.cc | 132 | ||||
-rw-r--r-- | libopie/ofileselector.h | 12 |
2 files changed, 132 insertions, 12 deletions
diff --git a/libopie/ofileselector.cc b/libopie/ofileselector.cc index c9abde1..b911d37 100644 --- a/libopie/ofileselector.cc +++ b/libopie/ofileselector.cc | |||
@@ -1,106 +1,110 @@ | |||
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 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 | #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 | #include <qheader.h> | ||
40 | #include <qdir.h> | ||
39 | 41 | ||
42 | #include <qpe/qpeapplication.h> | ||
40 | #include <qpe/fileselector.h> | 43 | #include <qpe/fileselector.h> |
41 | #include <qpe/applnk.h> | 44 | #include <qpe/applnk.h> |
42 | #include <qpe/global.h> | 45 | #include <qpe/global.h> |
46 | #include <qpe/mimetype.h> | ||
43 | 47 | ||
44 | #include "ofileselector.h" | 48 | #include "ofileselector.h" |
45 | 49 | ||
46 | 50 | ||
47 | OFileSelector::OFileSelector(QWidget *wid, int mode, int selector, const QString &dirName, | 51 | OFileSelector::OFileSelector(QWidget *wid, int mode, int selector, const QString &dirName, |
48 | const QString &fileName, const QStringList mimetypes ) : QWidget( wid ) | 52 | const QString &fileName, const QStringList mimetypes ) : QWidget( wid ) |
49 | { | 53 | { |
50 | m_selector = selector; | 54 | m_selector = selector; |
51 | m_currentDir = dirName; | 55 | m_currentDir = dirName; |
52 | m_name = fileName; | 56 | m_name = fileName; |
53 | m_mimetypes = mimetypes; | 57 | m_mimetypes = mimetypes; |
54 | if( mimetypes.isEmpty() ) | 58 | if( mimetypes.isEmpty() ) |
55 | m_autoMime = true; | 59 | m_autoMime = true; |
56 | 60 | ||
57 | m_mode = mode; | 61 | m_mode = mode; |
58 | m_shTool = true; | 62 | m_shTool = true; |
59 | m_shPerm = true; | 63 | m_shPerm = true; |
60 | m_shLne = true; | 64 | m_shLne = true; |
61 | m_shChooser = true; | 65 | m_shChooser = true; |
62 | m_shYesNo = true; | 66 | m_shYesNo = true; |
63 | // for FILESELECTOR only view is interesting | 67 | // for FILESELECTOR only view is interesting |
64 | m_location = 0; | 68 | m_location = 0; |
65 | m_homeButton = 0; | 69 | m_homeButton = 0; |
66 | m_docButton = 0; | 70 | m_docButton = 0; |
67 | m_hideButton = 0; | 71 | m_hideButton = 0; |
68 | m_ok = 0; | 72 | m_ok = 0; |
69 | m_cancel = 0; | 73 | m_cancel = 0; |
70 | m_reread = 0; | 74 | m_reread = 0; |
71 | m_up = 0; | 75 | m_up = 0; |
72 | m_View = 0; | 76 | m_View = 0; |
73 | m_select = 0; | 77 | m_select = 0; |
74 | m_stack = 0; | 78 | m_stack = 0; |
75 | 79 | ||
76 | m_select = 0; | 80 | m_select = 0; |
77 | m_stack = 0; | 81 | m_stack = 0; |
78 | m_lay = 0; | 82 | m_lay = 0; |
79 | m_boxToolbar = 0; | 83 | m_boxToolbar = 0; |
80 | m_boxOk = 0; | 84 | m_boxOk = 0; |
81 | m_edit = 0; | 85 | m_edit = 0; |
82 | 86 | ||
83 | m_fnLabel = 0; | 87 | m_fnLabel = 0; |
84 | m_checkPerm = 0; | 88 | m_checkPerm = 0; |
85 | m_mimeCheck = 0; | 89 | m_mimeCheck = 0; |
86 | m_viewCheck = 0; | 90 | m_viewCheck = 0; |
87 | 91 | ||
88 | m_lay = new QVBoxLayout(this); | 92 | m_lay = new QVBoxLayout(this); |
89 | init(); | 93 | init(); |
90 | m_edit->setText( fileName ); | 94 | m_edit->setText( fileName ); |
91 | } | 95 | } |
92 | 96 | ||
93 | // let's initialize the gui | 97 | // let's initialize the gui |
94 | /** | 98 | /** |
95 | -------------------- | 99 | -------------------- |
96 | | cmbBox Button | | 100 | | cmbBox Button | |
97 | -------------------- | 101 | -------------------- |
98 | | FileSlector | | 102 | | FileSlector | |
99 | | or | | 103 | | or | |
100 | | OSelector | | 104 | | OSelector | |
101 | | | | 105 | | | |
102 | | | | 106 | | | |
103 | ____________________ | 107 | ____________________ |
104 | | LineEdit | | 108 | | LineEdit | |
105 | ____________________ | 109 | ____________________ |
106 | | Permission Bar | | 110 | | Permission Bar | |
@@ -207,207 +211,311 @@ void OFileSelector::setShowChooser( bool show ) | |||
207 | m_viewCheck = 0; | 211 | m_viewCheck = 0; |
208 | } | 212 | } |
209 | updateLay(); | 213 | updateLay(); |
210 | } | 214 | } |
211 | QCheckBox* OFileSelector::permissionCheckbox( ) | 215 | QCheckBox* OFileSelector::permissionCheckbox( ) |
212 | { | 216 | { |
213 | return m_checkPerm; | 217 | return m_checkPerm; |
214 | } | 218 | } |
215 | bool OFileSelector::setPermission( ) const | 219 | bool OFileSelector::setPermission( ) const |
216 | { | 220 | { |
217 | if( m_checkPerm == 0 ) | 221 | if( m_checkPerm == 0 ) |
218 | return false; | 222 | return false; |
219 | else | 223 | else |
220 | return m_checkPerm->isChecked(); | 224 | return m_checkPerm->isChecked(); |
221 | } | 225 | } |
222 | void OFileSelector::setPermissionChecked( bool check ) | 226 | void OFileSelector::setPermissionChecked( bool check ) |
223 | { | 227 | { |
224 | if( m_checkPerm == 0 ) | 228 | if( m_checkPerm == 0 ) |
225 | return; | 229 | return; |
226 | m_checkPerm->setChecked( check ); | 230 | m_checkPerm->setChecked( check ); |
227 | } | 231 | } |
228 | QString OFileSelector::selectedName( ) | 232 | QString OFileSelector::selectedName( ) |
229 | { | 233 | { |
230 | QString string; | 234 | QString string; |
231 | return string; | 235 | return string; |
232 | } | 236 | } |
233 | const DocLnk* OFileSelector::selectedDocument( )const | 237 | const DocLnk* OFileSelector::selectedDocument( )const |
234 | { | 238 | { |
235 | return 0; | 239 | return 0; |
236 | } | 240 | } |
237 | void OFileSelector::updateLay() | 241 | void OFileSelector::updateLay() |
238 | { | 242 | { |
239 | /* if( m_shTool ) | 243 | /* if( m_shTool ) |
240 | // | 244 | // |
241 | else | 245 | else |
242 | // hide | 246 | // hide |
243 | */ | 247 | */ |
244 | // save the state | 248 | // save the state |
245 | bool check = false; | 249 | bool check = false; |
246 | if( m_checkPerm != 0 ) | 250 | if( m_checkPerm != 0 ) |
247 | check = m_checkPerm->isChecked(); | 251 | check = m_checkPerm->isChecked(); |
248 | QString text; | 252 | QString text; |
249 | 253 | ||
250 | if( m_edit != 0 ) | 254 | if( m_edit != 0 ) |
251 | text = m_edit->text(); | 255 | text = m_edit->text(); |
252 | // save current mimetype | 256 | // save current mimetype |
253 | 257 | ||
254 | delItems(); | 258 | delItems(); |
255 | delete m_checkPerm; | 259 | delete m_checkPerm; |
256 | delete m_edit; | 260 | delete m_edit; |
257 | delete m_fnLabel; | 261 | delete m_fnLabel; |
258 | delete m_ok; | 262 | delete m_ok; |
259 | delete m_cancel; | 263 | delete m_cancel; |
260 | delete m_mimeCheck; | 264 | delete m_mimeCheck; |
261 | delete m_viewCheck; | 265 | delete m_viewCheck; |
262 | delete m_select; // test | 266 | delete m_select; // test |
263 | delete m_stack; | 267 | delete m_stack; |
264 | //delete m_list; | 268 | //delete m_list; |
265 | init(); | 269 | init(); |
266 | if( m_shLne ) | 270 | if( m_shLne ) |
267 | m_edit->setText(text ); | 271 | m_edit->setText(text ); |
268 | if( m_shPerm ) | 272 | if( m_shPerm ) |
269 | m_checkPerm->setChecked(check ); | 273 | m_checkPerm->setChecked(check ); |
270 | } | 274 | } |
275 | // let's update the mimetypes. Use the current mimefilter for the 2nd QDir retrieve | ||
276 | // insert QListViewItems with the right options | ||
277 | bool OFileSelector::compliesMime(const QString &path, const QString &mime ) | ||
278 | { | ||
279 | if( mime == "All" ) | ||
280 | return true; | ||
281 | MimeType type( path ); | ||
282 | if( type.id() == mime ) | ||
283 | return true; | ||
284 | return false; | ||
285 | } | ||
286 | |||
271 | void OFileSelector::reparse() | 287 | void OFileSelector::reparse() |
272 | { | 288 | { |
289 | if(m_View== 0) | ||
290 | return; | ||
291 | |||
292 | m_View->clear(); | ||
293 | |||
294 | QDir dir( m_currentDir ); | ||
295 | QString currMime =m_mimeCheck->currentText(); | ||
296 | // update the mimetype now | ||
297 | if( m_autoMime ) { | ||
298 | m_mimetypes.clear(); | ||
299 | m_mimeCheck->clear(); | ||
300 | dir.setFilter( QDir::Files | QDir::Readable ); | ||
301 | dir.setSorting(QDir::Size ); | ||
302 | const QFileInfoList *list = dir.entryInfoList(); | ||
303 | QFileInfoListIterator it( *list ); | ||
304 | QFileInfo *fi; | ||
305 | while( (fi=it.current()) ){ | ||
306 | if(fi->extension() == QString::fromLatin1("desktop") ){ | ||
307 | ++it; | ||
308 | continue; | ||
309 | } | ||
310 | MimeType type(fi->filePath() ); | ||
311 | if( !m_mimetypes.contains( type.id() ) ) | ||
312 | m_mimetypes.append( type.id() ); | ||
313 | |||
314 | ++it; | ||
315 | } | ||
316 | m_mimeCheck->insertStringList(m_mimetypes ); | ||
317 | // set it to the current mimetype | ||
318 | }; | ||
319 | dir.setFilter(QDir::All ); | ||
320 | dir.setSorting(QDir::Name | QDir::DirsFirst ); | ||
321 | const QFileInfoList *list = dir.entryInfoList(); | ||
322 | QFileInfoListIterator it( *list ); | ||
323 | QFileInfo *fi; | ||
324 | while( (fi=it.current()) ){ | ||
325 | if(fi->isSymLink() ){ | ||
326 | QString file = fi->readLink(); | ||
327 | for(int i=0; i<=4; i++ ){ // prepend from dos | ||
328 | QFileInfo info( file ); | ||
329 | if( !info.exists() ){ | ||
330 | addSymlink(m_currentDir, info.fileName(), TRUE ); | ||
331 | break; | ||
332 | }else if( info.isDir() ){ | ||
333 | //addDir( ); | ||
334 | }else if( info.isFile() ){ | ||
335 | |||
336 | }else if( info.isSymLink() ){ | ||
337 | file = info.readLink(); | ||
338 | }else if( i == 4 ){ // just insert it and have the symlink symbol | ||
339 | addSymlink(m_currentDir, info.fileName() ); | ||
340 | } | ||
341 | } | ||
342 | }else if( fi->isDir() ){ | ||
343 | |||
344 | }else if( fi->isFile() ) { // file ? | ||
273 | 345 | ||
346 | |||
347 | } | ||
348 | ++it; | ||
349 | } | ||
274 | } | 350 | } |
275 | QString OFileSelector::directory() | 351 | QString OFileSelector::directory() |
276 | { | 352 | { |
277 | QString string; | 353 | QString string; |
278 | return string; | 354 | return string; |
279 | } | 355 | } |
280 | int OFileSelector::fileCount() | 356 | int OFileSelector::fileCount() |
281 | { | 357 | { |
282 | return 0; | 358 | return 0; |
283 | } | 359 | } |
284 | void OFileSelector::slotOk( ) | 360 | void OFileSelector::slotOk( ) |
285 | { | 361 | { |
286 | emit ok(); | 362 | emit ok(); |
287 | } | 363 | } |
288 | void OFileSelector::slotCancel( ) | 364 | void OFileSelector::slotCancel( ) |
289 | { | 365 | { |
290 | emit cancel(); | 366 | emit cancel(); |
291 | } | 367 | } |
292 | 368 | ||
293 | void OFileSelector::initializeName() | 369 | void OFileSelector::initializeName() |
294 | { | 370 | { |
295 | m_boxName = new QHBoxLayout(this ); | 371 | m_boxName = new QHBoxLayout(this ); |
296 | m_edit = new QLineEdit(this ); | 372 | m_edit = new QLineEdit(this ); |
297 | m_fnLabel = new QLabel(this ); | 373 | m_fnLabel = new QLabel(this ); |
298 | m_fnLabel->setText(tr("Name:") ); | 374 | m_fnLabel->setText(tr("Name:") ); |
299 | m_boxName->addWidget(m_fnLabel ); | 375 | m_boxName->addWidget(m_fnLabel ); |
300 | m_boxName->insertSpacing(1, 8 ); | 376 | m_boxName->insertSpacing(1, 8 ); |
301 | m_boxName->addWidget(m_edit, 100 ); | 377 | m_boxName->addWidget(m_edit, 100 ); |
302 | 378 | ||
303 | m_lay->addLayout(m_boxName); | 379 | m_lay->addLayout(m_boxName); |
304 | } | 380 | } |
305 | void OFileSelector::initializeYes() | 381 | void OFileSelector::initializeYes() |
306 | { | 382 | { |
307 | m_ok = new QPushButton("&Save", this, "save" ); | 383 | m_ok = new QPushButton("&Save", this, "save" ); |
308 | m_cancel = new QPushButton("C&ancel", this, "cancel" ); | 384 | m_cancel = new QPushButton("C&ancel", this, "cancel" ); |
309 | m_boxOk = new QHBoxLayout(this ); | 385 | m_boxOk = new QHBoxLayout(this ); |
310 | m_boxOk->addWidget( m_ok, Qt::AlignHCenter ); | 386 | m_boxOk->addWidget( m_ok, Qt::AlignHCenter ); |
311 | m_boxOk->insertSpacing(1, 8 ); | 387 | m_boxOk->insertSpacing(1, 8 ); |
312 | m_boxOk->addWidget( m_cancel, Qt::AlignHCenter); | 388 | m_boxOk->addWidget( m_cancel, Qt::AlignHCenter); |
313 | m_lay->addLayout(m_boxOk ); | 389 | m_lay->addLayout(m_boxOk ); |
314 | connect(m_ok, SIGNAL(clicked() ), | 390 | connect(m_ok, SIGNAL(clicked() ), |
315 | this, SLOT(slotOk() ) ); | 391 | this, SLOT(slotOk() ) ); |
316 | connect(m_cancel, SIGNAL(clicked() ), | 392 | connect(m_cancel, SIGNAL(clicked() ), |
317 | this, SLOT(slotCancel() ) ); | 393 | this, SLOT(slotCancel() ) ); |
318 | 394 | ||
319 | } | 395 | } |
320 | void OFileSelector::initializeChooser() | 396 | void OFileSelector::initializeChooser() |
321 | { | 397 | { |
322 | m_boxView = new QHBoxLayout(this ); | 398 | m_boxView = new QHBoxLayout(this ); |
323 | 399 | ||
324 | m_mimeCheck = new QComboBox(this, "mime check"); | 400 | m_mimeCheck = new QComboBox(this, "mime check"); |
325 | m_viewCheck = new QComboBox(this, "view check"); | 401 | m_viewCheck = new QComboBox(this, "view check"); |
326 | m_boxView->addWidget(m_viewCheck, 0 ); | 402 | m_boxView->addWidget(m_viewCheck, 0 ); |
327 | m_boxView->insertSpacing(1, 8 ); | 403 | m_boxView->insertSpacing(1, 8 ); |
328 | m_boxView->addWidget(m_mimeCheck, 0 ); | 404 | m_boxView->addWidget(m_mimeCheck, 0 ); |
329 | m_lay->addLayout(m_boxView ); | 405 | m_lay->addLayout(m_boxView ); |
330 | 406 | ||
331 | m_viewCheck->insertItem(tr("Documents") ); | 407 | m_viewCheck->insertItem(tr("Documents") ); |
332 | m_viewCheck->insertItem(tr("Files") ); | 408 | m_viewCheck->insertItem(tr("Files") ); |
333 | m_viewCheck->insertItem(tr("All Files") ); | 409 | m_viewCheck->insertItem(tr("All Files") ); |
334 | 410 | ||
335 | if(!m_autoMime ) | 411 | if(!m_autoMime ) |
336 | m_mimeCheck->insertItem(m_mimetypes.join("," ) ); | 412 | m_mimeCheck->insertItem(m_mimetypes.join("," ) ); |
337 | else{ // check | 413 | else{ // check |
338 | updateMimes(); | 414 | updateMimes(); |
339 | m_mimeCheck->insertStringList( m_mimetypes ); | 415 | m_mimeCheck->insertStringList( m_mimetypes ); |
340 | } | 416 | } |
341 | 417 | ||
342 | connect( m_viewCheck, SIGNAL(activated(const QString &) ), | 418 | connect( m_viewCheck, SIGNAL(activated(const QString &) ), |
343 | this, SLOT(slotViewCheck(const QString & ) ) ); | 419 | this, SLOT(slotViewCheck(const QString & ) ) ); |
344 | 420 | ||
345 | connect( m_mimeCheck, SIGNAL(activated(const QString &) ), | 421 | connect( m_mimeCheck, SIGNAL(activated(const QString &) ), |
346 | this, SLOT(slotMimeCheck(const QString & ) ) ); | 422 | this, SLOT(slotMimeCheck(const QString & ) ) ); |
347 | } | 423 | } |
348 | void OFileSelector::slotMimeCheck(const QString &view ){ | 424 | void OFileSelector::slotMimeCheck(const QString &view ){ |
349 | if(m_selector == NORMAL ){ | 425 | if(m_selector == NORMAL ){ |
350 | delete m_select; | 426 | delete m_select; |
351 | m_select = new FileSelector(view == "All" ? QString::null : view | 427 | m_select = new FileSelector(view == "All" ? QString::null : view |
352 | , m_stack, "fileselector", FALSE, FALSE ); | 428 | , m_stack, "fileselector", FALSE, FALSE ); |
353 | m_stack->addWidget( m_select, NORMAL ); | 429 | m_stack->addWidget( m_select, NORMAL ); |
354 | m_stack->raiseWidget( NORMAL ); | 430 | m_stack->raiseWidget( NORMAL ); |
355 | }else{ | 431 | }else{ |
356 | 432 | ||
357 | 433 | ||
358 | } | 434 | } |
359 | } | 435 | } |
360 | 436 | ||
361 | void OFileSelector::slotViewCheck(const QString &view ){ | 437 | void OFileSelector::slotViewCheck(const QString &view ){ |
362 | qWarning("changed: show %s", view.latin1() ); | 438 | qWarning("changed: show %s", view.latin1() ); |
363 | // if the current view is the one | 439 | // if the current view is the one |
364 | QString currMime = m_mimeCheck->currentText(); | 440 | QString currMime = m_mimeCheck->currentText(); |
365 | if( view == QString::fromLatin1("Documents") ){ | 441 | if( view == QString::fromLatin1("Documents") ){ |
366 | // get the mimetype now | 442 | // get the mimetype now |
367 | // check if we're the current widget and return | 443 | // check if we're the current widget and return |
444 | if( m_View != 0) // delete 0 shouldn't crash but it did :( | ||
445 | delete m_View; | ||
446 | m_View = 0; | ||
368 | delete m_select; | 447 | delete m_select; |
369 | m_select = new FileSelector( currMime == "All" ? QString::null : currMime, | 448 | m_select = new FileSelector( currMime == "All" ? QString::null : currMime, |
370 | m_stack,"fileselector", FALSE, FALSE ); | 449 | m_stack,"fileselector", FALSE, FALSE ); |
371 | m_stack->addWidget( m_select, NORMAL ); | 450 | m_stack->addWidget( m_select, NORMAL ); |
372 | m_stack->raiseWidget( NORMAL ); | 451 | m_stack->raiseWidget( NORMAL ); |
373 | m_selector = NORMAL; | 452 | m_selector = NORMAL; |
374 | 453 | ||
375 | }else if(view == QString::fromLatin1("Files") ){ | 454 | }else if(view == QString::fromLatin1("Files") ){ |
376 | if( m_select != 0 ){ | 455 | // remove from the stack |
377 | // remove from the stack | 456 | delete m_select; |
378 | delete m_select; | 457 | m_select = 0; |
379 | m_select = 0; | 458 | delete m_View; |
380 | m_selector = EXTENDED; | 459 | m_View = 0; |
381 | // create the ListView or IconView | 460 | m_selector = EXTENDED; |
382 | 461 | // create the ListView or IconView | |
383 | reparse(); | 462 | initializeListView(); |
384 | } | 463 | |
464 | reparse(); | ||
385 | }else if(view == QString::fromLatin1("All Files") ) { | 465 | }else if(view == QString::fromLatin1("All Files") ) { |
386 | // remove from the stack | 466 | // remove from the stack |
387 | delete m_select; | 467 | delete m_select; |
388 | m_select = 0; | 468 | m_select = 0; |
469 | delete m_View; | ||
470 | m_View = 0; | ||
389 | m_selector = EXTENDED_ALL; | 471 | m_selector = EXTENDED_ALL; |
390 | 472 | initializeListView(); | |
391 | reparse(); | 473 | reparse(); |
392 | }; | 474 | }; |
393 | }; | 475 | }; |
394 | 476 | ||
395 | 477 | ||
396 | void OFileSelector::updateMimes() // lets check which mode is active | 478 | void OFileSelector::updateMimes() // lets check which mode is active |
397 | // check the current dir for items then | 479 | // check the current dir for items then |
398 | { | 480 | { |
399 | m_mimetypes.clear(); | 481 | m_mimetypes.clear(); |
400 | m_mimetypes.append("All" ); | 482 | m_mimetypes.append("All" ); |
401 | if( m_selector == NORMAL ){ | 483 | if( m_selector == NORMAL ){ |
402 | DocLnkSet set; | 484 | DocLnkSet set; |
403 | Global::findDocuments(&set, QString::null ); | 485 | Global::findDocuments(&set, QString::null ); |
404 | QListIterator<DocLnk> dit( set.children() ); | 486 | QListIterator<DocLnk> dit( set.children() ); |
405 | for ( ; dit.current(); ++dit ) { | 487 | for ( ; dit.current(); ++dit ) { |
406 | if( !m_mimetypes.contains((*dit)->type() ) ) | 488 | if( !m_mimetypes.contains((*dit)->type() ) ) |
407 | m_mimetypes.append( (*dit)->type() ); | 489 | m_mimetypes.append( (*dit)->type() ); |
408 | } | 490 | } |
409 | }else{ | 491 | }else{ |
410 | 492 | // should be allreday updatet | |
411 | 493 | ||
412 | } | 494 | } |
413 | }; | 495 | }; |
496 | void OFileSelector::initializeListView() | ||
497 | { | ||
498 | m_View = new QListView(m_stack, "Extended view" ); | ||
499 | m_stack->addWidget( m_View, EXTENDED ); | ||
500 | m_stack->raiseWidget( EXTENDED ); | ||
501 | QPEApplication::setStylusOperation( m_View->viewport(),QPEApplication::RightOnHold); | ||
502 | // set up the stuff | ||
503 | // Pixmap Name Date Size mime | ||
504 | //(m_View->header() )->hide(); | ||
505 | //m_View->setRootIsDecorated(false); | ||
506 | m_View->addColumn(" "); | ||
507 | m_View->addColumn(tr("Name") ); | ||
508 | m_View->addColumn(tr("Size") ); | ||
509 | m_View->addColumn(tr("Date"), 60 ); | ||
510 | m_View->addColumn(tr("Mime Type") ); | ||
511 | QHeader *header = m_View->header(); | ||
512 | header->hide(); | ||
513 | }; | ||
514 | |||
515 | |||
516 | |||
517 | |||
518 | |||
519 | |||
520 | |||
521 | |||
diff --git a/libopie/ofileselector.h b/libopie/ofileselector.h index 757a960..a90219f 100644 --- a/libopie/ofileselector.h +++ b/libopie/ofileselector.h | |||
@@ -1,176 +1,188 @@ | |||
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 | class QPopupMenu; | ||
62 | |||
61 | 63 | ||
62 | class OFileSelectorItem : public QListViewItem { | 64 | class OFileSelectorItem : public QListViewItem { |
63 | public: | 65 | public: |
64 | OFileSelectorItem(QListView *view, const QPixmap &pixmap, const QString &path, | 66 | OFileSelectorItem(QListView *view, const QPixmap &pixmap, const QString &path, |
65 | const QString &date, const QString &size, | 67 | const QString &date, const QString &size, |
66 | bool isDir=false ): QListViewItem(view) { | 68 | bool isDir=false ): QListViewItem(view) { |
67 | setPixmap(0, pixmap ); | 69 | setPixmap(0, pixmap ); |
68 | setText(1, path ); | 70 | setText(1, path ); |
69 | setText(2, size ); | 71 | setText(2, size ); |
70 | setText(3, date ); | 72 | setText(3, date ); |
71 | dir = isDir; | 73 | dir = isDir; |
72 | } | 74 | } |
73 | bool isDir()const{ | 75 | bool isDir()const{ |
74 | return dir; | 76 | return dir; |
75 | } | 77 | } |
76 | QString path()const{ | 78 | QString path()const{ |
77 | return text(1 ); | 79 | return text(1 ); |
78 | } | 80 | } |
79 | private: | 81 | private: |
80 | bool dir:1; | 82 | bool dir:1; |
81 | }; | 83 | }; |
82 | 84 | ||
83 | class OFileSelector : public QWidget { | 85 | class OFileSelector : public QWidget { |
84 | Q_OBJECT | 86 | Q_OBJECT |
85 | public: | 87 | public: |
86 | enum Mode {OPEN=1, SAVE, FILESELECTOR }; | 88 | enum Mode {OPEN=1, SAVE, FILESELECTOR }; |
87 | enum Selector{NORMAL=1, EXTENDED = 2, EXTENDED_ALL =4 }; | 89 | enum Selector{NORMAL=1, EXTENDED = 2, EXTENDED_ALL =4 }; |
88 | enum View { DIRS = 1, FILES = 2, TREE = 4, ICON = 8 }; | 90 | enum View { DIRS = 1, FILES = 2, TREE = 4, ICON = 8 }; |
89 | OFileSelector(QWidget *wid, int mode, int selector, const QString &dirName, const QString &fileName = QString::null, const QStringList mimetypes = QStringList() ); | 91 | OFileSelector(QWidget *wid, int mode, int selector, const QString &dirName, const QString &fileName = QString::null, const QStringList mimetypes = QStringList() ); |
90 | 92 | ||
91 | bool showToolbar() const { return m_shTool; }; | 93 | bool showToolbar() const { return m_shTool; }; |
92 | bool showPermissionBar() const { return m_shPerm; }; | 94 | bool showPermissionBar() const { return m_shPerm; }; |
93 | bool showLineEdit()const { return m_shLne; }; | 95 | bool showLineEdit()const { return m_shLne; }; |
94 | bool showChooser( )const { return m_shChooser; }; | 96 | bool showChooser( )const { return m_shChooser; }; |
95 | bool showYesCancel()const { return m_shYesNo; }; | 97 | bool showYesCancel()const { return m_shYesNo; }; |
96 | void setShowYesCancel( bool show ); | 98 | void setShowYesCancel( bool show ); |
97 | void setShowToolbar( bool show ); | 99 | void setShowToolbar( bool show ); |
98 | void setShowPermissionBar( bool show ); | 100 | void setShowPermissionBar( bool show ); |
99 | void setShowLineEdit(bool show) ; | 101 | void setShowLineEdit(bool show) ; |
100 | void setShowChooser( bool chooser ); | 102 | void setShowChooser( bool chooser ); |
101 | QCheckBox* permissionCheckbox(); | 103 | QCheckBox* permissionCheckbox(); |
102 | bool setPermission() const; | 104 | bool setPermission() const; |
103 | void setPermissionChecked( bool check ); | 105 | void setPermissionChecked( bool check ); |
104 | void setMode( int ); | 106 | void setMode( int ); |
107 | void setShowDirs(bool dir ) { }; | ||
108 | bool showDirs() {bool turn; return turn; } | ||
105 | int mode()const { return m_mode; }; | 109 | int mode()const { return m_mode; }; |
106 | int selector()const { return m_selector; }; | 110 | int selector()const { return m_selector; }; |
107 | void setSelector( int ); | 111 | void setSelector( int ); |
108 | QString selectedName( ); | 112 | QString selectedName( ); |
113 | void setPopupMenu( const QPopupMenu * ); | ||
114 | |||
109 | const DocLnk* selectedDocument()const; | 115 | const DocLnk* selectedDocument()const; |
110 | void updateLay(); | 116 | void updateLay(); |
111 | 117 | ||
112 | void reparse(); // re reads the dir | 118 | void reparse(); // re reads the dir |
113 | QString directory(); | 119 | QString directory(); |
114 | int fileCount(); | 120 | int fileCount(); |
115 | 121 | ||
116 | signals: | 122 | signals: |
117 | void fileSelected( const DocLnk & ); | 123 | void fileSelected( const DocLnk & ); |
118 | void fileSelected( const QString & ); | 124 | void fileSelected( const QString & ); |
119 | void closeMe(); | 125 | void closeMe(); |
120 | void ok(); | 126 | void ok(); |
121 | void cancel(); | 127 | void cancel(); |
122 | 128 | ||
123 | protected slots: | 129 | protected slots: |
124 | void slotOk(); | 130 | void slotOk(); |
125 | void slotCancel(); | 131 | void slotCancel(); |
126 | void slotViewCheck(const QString & ); | 132 | void slotViewCheck(const QString & ); |
127 | void slotMimeCheck(const QString & ); | 133 | void slotMimeCheck(const QString & ); |
128 | protected: | 134 | protected: |
129 | void init(); | 135 | void init(); |
130 | void updateMimes(); | 136 | void updateMimes(); |
131 | int m_mode, m_selector; | 137 | int m_mode, m_selector; |
132 | QComboBox *m_location, *m_mimeCheck, *m_viewCheck; | 138 | QComboBox *m_location, *m_mimeCheck, *m_viewCheck; |
133 | QPushButton *m_homeButton, *m_docButton, *m_hideButton, *m_ok, *m_cancel; | 139 | QPushButton *m_homeButton, *m_docButton, *m_hideButton, *m_ok, *m_cancel; |
134 | QPushButton *m_reread, *m_up; | 140 | QPushButton *m_reread, *m_up; |
135 | QListView *m_View; | 141 | QListView *m_View; |
136 | QCheckBox *m_checkPerm; | 142 | QCheckBox *m_checkPerm; |
137 | 143 | ||
138 | QString m_currentDir; | 144 | QString m_currentDir; |
139 | QString m_name; | 145 | QString m_name; |
140 | QStringList m_mimetypes; | 146 | QStringList m_mimetypes; |
141 | 147 | ||
142 | FileSelector *m_select; | 148 | FileSelector *m_select; |
143 | QWidgetStack *m_stack; | 149 | QWidgetStack *m_stack; |
144 | QVBoxLayout *m_lay; | 150 | QVBoxLayout *m_lay; |
145 | QGridLayout *m_Oselector; | 151 | QGridLayout *m_Oselector; |
146 | 152 | ||
147 | QHBoxLayout *m_boxToolbar; | 153 | QHBoxLayout *m_boxToolbar; |
148 | QHBoxLayout *m_boxOk; | 154 | QHBoxLayout *m_boxOk; |
149 | QHBoxLayout *m_boxName; | 155 | QHBoxLayout *m_boxName; |
150 | QHBoxLayout *m_boxView; | 156 | QHBoxLayout *m_boxView; |
151 | 157 | ||
152 | QLineEdit *m_edit; | 158 | QLineEdit *m_edit; |
153 | QLabel *m_fnLabel; | 159 | QLabel *m_fnLabel; |
154 | bool m_shTool:1; | 160 | bool m_shTool:1; |
155 | bool m_shPerm:1; | 161 | bool m_shPerm:1; |
156 | bool m_shLne:1; | 162 | bool m_shLne:1; |
157 | bool m_shChooser:1; | 163 | bool m_shChooser:1; |
158 | bool m_shYesNo:1; | 164 | bool m_shYesNo:1; |
159 | bool m_boCheckPerm:1; | 165 | bool m_boCheckPerm:1; |
160 | bool m_autoMime:1; | 166 | bool m_autoMime:1; |
161 | 167 | ||
162 | protected: | 168 | protected: |
163 | 169 | ||
164 | private: | 170 | private: |
171 | // implementation todo | ||
172 | virtual void addFile(const QString &path, const QString &name, bool symlink = FALSE ) {}; | ||
173 | virtual void addDir( const QString &path, const QString &dir , bool symlink = FALSE ){}; | ||
174 | virtual void addSymlink(const QString &path, const QString &name, bool broken = FALSE ){}; | ||
165 | void delItems(); | 175 | void delItems(); |
166 | void initializeName(); | 176 | void initializeName(); |
167 | void initializeYes(); | 177 | void initializeYes(); |
168 | void initializeChooser(); | 178 | void initializeChooser(); |
179 | void initializeListView(); | ||
180 | bool compliesMime(const QString &path, const QString &mime); | ||
169 | 181 | ||
170 | class OFileSelectorPrivate; | 182 | class OFileSelectorPrivate; |
171 | OFileSelectorPrivate *d; | 183 | OFileSelectorPrivate *d; |
172 | 184 | ||
173 | }; | 185 | }; |
174 | 186 | ||
175 | 187 | ||
176 | #endif | 188 | #endif |