summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/ofileselector.cc132
-rw-r--r--libopie/ofileselector.h12
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,15 +1,15 @@
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
@@ -27,28 +27,32 @@
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
47OFileSelector::OFileSelector(QWidget *wid, int mode, int selector, const QString &dirName, 51OFileSelector::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() )
@@ -259,27 +263,99 @@ void OFileSelector::updateLay()
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
277bool 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
271void OFileSelector::reparse() 287void 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}
275QString OFileSelector::directory() 351QString OFileSelector::directory()
276{ 352{
277 QString string; 353 QString string;
278 return string; 354 return string;
279} 355}
280int OFileSelector::fileCount() 356int OFileSelector::fileCount()
281{ 357{
282 return 0; 358 return 0;
283} 359}
284void OFileSelector::slotOk( ) 360void OFileSelector::slotOk( )
285{ 361{
@@ -356,58 +432,90 @@ void OFileSelector::slotMimeCheck(const QString &view ){
356 432
357 433
358 } 434 }
359} 435}
360 436
361void OFileSelector::slotViewCheck(const QString &view ){ 437void 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
396void OFileSelector::updateMimes() // lets check which mode is active 478void 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};
496void 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
@@ -49,24 +49,26 @@
49 */ 49 */
50class DocLnk; 50class DocLnk;
51class QCheckBox; 51class QCheckBox;
52class QComboBox; 52class QComboBox;
53class QPushButton; 53class QPushButton;
54class FileSelector; 54class FileSelector;
55class QGridLayout; 55class QGridLayout;
56class QLineEdit; 56class QLineEdit;
57class QLabel; 57class QLabel;
58class QWidgetStack; 58class QWidgetStack;
59class QHBoxLayout; 59class QHBoxLayout;
60class QVBoxLayout; 60class QVBoxLayout;
61class QPopupMenu;
62
61 63
62class OFileSelectorItem : public QListViewItem { 64class 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 }
@@ -93,28 +95,32 @@ class OFileSelector : public QWidget {
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();
@@ -153,24 +159,30 @@ class OFileSelector : public QWidget {
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