summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/ofiledialog.cc18
-rw-r--r--libopie/ofiledialog.h18
-rw-r--r--libopie/ofileselector.cc160
-rw-r--r--libopie/ofileselector.h77
4 files changed, 192 insertions, 81 deletions
diff --git a/libopie/ofiledialog.cc b/libopie/ofiledialog.cc
index 164fadd..4783004 100644
--- a/libopie/ofiledialog.cc
+++ b/libopie/ofiledialog.cc
@@ -1,30 +1,30 @@
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 <qpe/applnk.h> 29#include <qpe/applnk.h>
30#include <qstring.h> 30#include <qstring.h>
@@ -32,17 +32,17 @@
32#include <qlayout.h> 32#include <qlayout.h>
33 33
34#include "ofiledialog.h" 34#include "ofiledialog.h"
35 35
36OFileDialog::OFileDialog(const QString &caption, 36OFileDialog::OFileDialog(const QString &caption,
37 QWidget *wid, int mode, int selector, 37 QWidget *wid, int mode, int selector,
38 const QString &dirName, 38 const QString &dirName,
39 const QString &fileName, 39 const QString &fileName,
40 const QStringList &mimetypes ) 40 const QMap<QString,QStringList>& mimetypes )
41 : QDialog( wid, "OFileDialog", true ) 41 : QDialog( wid, "OFileDialog", true )
42{ 42{
43 // QVBoxLayout *lay = new QVBoxLayout(this); 43 // QVBoxLayout *lay = new QVBoxLayout(this);
44 //showMaximized(); 44 //showMaximized();
45 QVBoxLayout *lay = new QVBoxLayout(this ); 45 QVBoxLayout *lay = new QVBoxLayout(this );
46 file = new OFileSelector(this , mode, selector, 46 file = new OFileSelector(this , mode, selector,
47 dirName, fileName, 47 dirName, fileName,
48 mimetypes ); 48 mimetypes );
@@ -52,17 +52,17 @@ OFileDialog::OFileDialog(const QString &caption,
52 //showFullScreen(); 52 //showFullScreen();
53 setCaption( caption.isEmpty() ? tr("FileDialog") : caption ); 53 setCaption( caption.isEmpty() ? tr("FileDialog") : caption );
54 connect(file, SIGNAL(fileSelected(const QString&) ), 54 connect(file, SIGNAL(fileSelected(const QString&) ),
55 this, SLOT(slotFileSelected(const QString&) ) ); 55 this, SLOT(slotFileSelected(const QString&) ) );
56 56
57 connect(file, SIGNAL(dirSelected(const QString &) ), 57 connect(file, SIGNAL(dirSelected(const QString &) ),
58 this, SLOT(slotDirSelected(const QString &) ) ); 58 this, SLOT(slotDirSelected(const QString &) ) );
59 59
60 60
61 file->setYesCancelVisible( false ); // relayout 61 file->setYesCancelVisible( false ); // relayout
62} 62}
63QString OFileDialog::mimetype()const 63QString OFileDialog::mimetype()const
64{ 64{
65 return QString::null; 65 return QString::null;
66} 66}
67QString OFileDialog::fileName()const 67QString OFileDialog::fileName()const
68{ 68{
@@ -70,33 +70,33 @@ QString OFileDialog::fileName()const
70} 70}
71DocLnk OFileDialog::selectedDocument()const 71DocLnk OFileDialog::selectedDocument()const
72{ 72{
73 return file->selectedDocument(); 73 return file->selectedDocument();
74} 74}
75QString OFileDialog::getOpenFileName(int selector, 75QString OFileDialog::getOpenFileName(int selector,
76 const QString &startDir, 76 const QString &startDir,
77 const QString &file, 77 const QString &file,
78 const QStringList &mimes, 78 const MimeTypes &mimes,
79 QWidget *wid, 79 QWidget *wid,
80 const QString &caption ) 80 const QString &caption )
81{ 81{
82 QString ret; 82 QString ret;
83 OFileDialog dlg( caption.isEmpty() ? tr("Open") : caption, 83 OFileDialog dlg( caption.isEmpty() ? tr("Open") : caption,
84 wid, OFileSelector::OPEN, selector, startDir, file, mimes); 84 wid, OFileSelector::OPEN, selector, startDir, file, mimes);
85 dlg.showMaximized(); 85 dlg.showMaximized();
86 if( dlg.exec() ) 86 if( dlg.exec() )
87 ret = dlg.fileName(); 87 ret = dlg.fileName();
88 88
89 return ret; 89 return ret;
90} 90}
91QString OFileDialog::getSaveFileName(int selector, 91QString OFileDialog::getSaveFileName(int selector,
92 const QString &startDir, 92 const QString &startDir,
93 const QString &file, 93 const QString &file,
94 const QStringList &mimes, 94 const MimeTypes &mimes,
95 QWidget *wid, 95 QWidget *wid,
96 const QString &caption ) 96 const QString &caption )
97{ 97{
98 QString ret; 98 QString ret;
99 OFileDialog dlg( caption.isEmpty() ? tr("Save") : caption, 99 OFileDialog dlg( caption.isEmpty() ? tr("Save") : caption,
100 wid, OFileSelector::SAVE, selector, startDir, file, mimes); 100 wid, OFileSelector::SAVE, selector, startDir, file, mimes);
101 dlg.showMaximized(); 101 dlg.showMaximized();
102 if( dlg.exec() ) 102 if( dlg.exec() )
diff --git a/libopie/ofiledialog.h b/libopie/ofiledialog.h
index 40d147e..e14253c 100644
--- a/libopie/ofiledialog.h
+++ b/libopie/ofiledialog.h
@@ -1,30 +1,30 @@
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 zecke <zecke@handhelds.org> 3             .=l. Copyright (c) 2002 zecke <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 29
30#ifndef OpieFileDialog_h 30#ifndef OpieFileDialog_h
@@ -34,35 +34,35 @@
34 34
35#include <opie/ofileselector.h> 35#include <opie/ofileselector.h>
36 36
37class OFileDialog : public QDialog { 37class OFileDialog : public QDialog {
38 Q_OBJECT 38 Q_OBJECT
39 public: 39 public:
40 OFileDialog(const QString &caption, 40 OFileDialog(const QString &caption,
41 QWidget *, int mode, int selector, 41 QWidget *, int mode, int selector,
42 const QString &dirName, 42 const QString &dirName,
43 const QString &fileName = QString::null, 43 const QString &fileName = QString::null,
44 const QStringList &mimetypes = QStringList() ); 44 const MimeTypes &mimetypes = MimeTypes() );
45 QString mimetype() const; 45 QString mimetype() const;
46 QString fileName() const; 46 QString fileName() const;
47 DocLnk selectedDocument()const; 47 DocLnk selectedDocument()const;
48 48
49 // static methods 49 // static methods
50 static QString getOpenFileName(int selector, 50 static QString getOpenFileName(int selector,
51 const QString& startDir = QString::null, 51 const QString& startDir = QString::null,
52 const QString &fileName = QString::null, 52 const QString &fileName = QString::null,
53 const QStringList& mimefilter = QStringList(), 53 const MimeTypes& mime = MimeTypes(),
54 QWidget *wid = 0, 54 QWidget *wid = 0,
55 const QString &caption = QString::null ); 55 const QString &caption = QString::null );
56 56
57 static QString getSaveFileName(int selector, 57 static QString getSaveFileName(int selector,
58 const QString& startDir = QString::null, 58 const QString& startDir = QString::null,
59 const QString& fileName = QString::null, 59 const QString& fileName = QString::null,
60 const QStringList& mimefilter = QStringList(), 60 const MimeTypes& mimefilter = MimeTypes(),
61 QWidget *wid = 0, 61 QWidget *wid = 0,
62 const QString &caption = QString::null ); 62 const QString &caption = QString::null );
63 63
64 //let's OFileSelector catch up first 64 //let's OFileSelector catch up first
65 //static QString getExistingDirectory(const QString& startDir = QString::null, 65 //static QString getExistingDirectory(const QString& startDir = QString::null,
66 // QWidget *parent = 0, 66 // QWidget *parent = 0,
67 // const QString& caption = QString::null ); 67 // const QString& caption = QString::null );
68 private: 68 private:
diff --git a/libopie/ofileselector.cc b/libopie/ofileselector.cc
index 7a67ab2..6c59f89 100644
--- a/libopie/ofileselector.cc
+++ b/libopie/ofileselector.cc
@@ -94,62 +94,68 @@ namespace {
94 bool dir:1; 94 bool dir:1;
95 QString m_dir; 95 QString m_dir;
96 }; 96 };
97}; 97};
98 98
99 99
100OFileSelector::OFileSelector( QWidget *wid, int mode, int selector, 100OFileSelector::OFileSelector( QWidget *wid, int mode, int selector,
101 const QString &dirName, 101 const QString &dirName,
102 const QString &fileName, 102 const QString &fileName,
103 const QStringList &mimeTypes ) 103 const QMap<QString,QStringList>& mimeTypes)
104 : QWidget( wid, "OFileSelector") 104 : QWidget( wid, "OFileSelector")
105{ 105{
106 m_mimetypes = mimeTypes; 106 m_mimetypes = mimeTypes;
107 if (mode == SAVE )
108 m_name = fileName;
107 initVars(); 109 initVars();
108 m_mode = mode; 110 m_mode = mode;
109 m_selector = selector; 111 m_selector = selector;
110 m_currentDir = dirName; 112 m_currentDir = dirName;
111 init(); 113 init();
112QTimer::singleShot(6*1000, this, SLOT( slotTest() ) ); 114 //QTimer::singleShot(6*1000, this, SLOT( slotTest() ) );
113} 115}
114 116
115OFileSelector::OFileSelector(const QString &mimeFilter, QWidget *parent, 117OFileSelector::OFileSelector(const QString &mimeFilter, QWidget *parent,
116 const char *name, bool newVisible, 118 const char *name, bool newVisible,
117 bool closeVisible ) 119 bool closeVisible )
118 : QWidget( parent, name ) 120 : QWidget( parent, name )
119{ 121{
120 m_mimetypes = QStringList::split(";", mimeFilter ); 122 if (!mimeFilter.isEmpty() ) {
123 QStringList list = QStringList::split(";", mimeFilter );
124 m_mimetypes.insert(mimeFilter, list );
125 }
121 initVars(); 126 initVars();
122 m_currentDir = QPEApplication::documentDir(); 127 m_currentDir = QPEApplication::documentDir();
123 m_mode = OPEN; 128 m_mode = OPEN;
124 m_selector = NORMAL; 129 m_selector = NORMAL;
125 m_shClose = closeVisible; 130 m_shClose = closeVisible;
126 m_shNew = newVisible; 131 m_shNew = newVisible;
127 m_shLne = false; 132 m_shLne = false;
128 m_shPerm = false; 133 m_shPerm = false;
129 m_shYesNo = false; 134 m_shYesNo = false;
130 init(); 135 init();
131 136
132 137
133} 138}
134 139
135OFileSelector::~OFileSelector() 140OFileSelector::~OFileSelector()
136{ 141{
137 142
143
138} 144}
139 145
140void OFileSelector::setNewVisible( bool visible ) 146void OFileSelector::setNewVisible( bool visible )
141{ 147{
142 m_shNew = visible; 148 m_shNew = visible;
143 if( m_selector == NORMAL ){ 149 if( m_selector == NORMAL ){
144 delete m_select; 150 delete m_select;
145 // we need to initialize but keep the selected mimetype 151 // we need to initialize but keep the selected mimetype
146 QString mime = m_mimeCheck == 0 ? QString::null : m_mimeCheck->currentText() ; 152 QString mime = currentMimeType();
147 m_select = new FileSelector( m_autoMime ? mime : m_mimetypes.join(";") , 153 m_select = new FileSelector( mime ,
148 m_stack, "fileselector", 154 m_stack, "fileselector",
149 m_shNew, m_shClose); 155 m_shNew, m_shClose);
150 connect(m_select, SIGNAL(fileSelected( const DocLnk & ) ), 156 connect(m_select, SIGNAL(fileSelected( const DocLnk & ) ),
151 this, SLOT( slotFileBridgeSelected(const DocLnk & ) ) ); 157 this, SLOT( slotFileBridgeSelected(const DocLnk & ) ) );
152 //connect to close me and other signals as well 158 //connect to close me and other signals as well
153 m_stack->addWidget( m_select, NORMAL ); 159 m_stack->addWidget( m_select, NORMAL );
154 }else{ 160 }else{
155 m_new->show(); 161 m_new->show();
@@ -336,17 +342,17 @@ QStringList OFileSelector::selectedNames()const
336 if( m_selector == NORMAL ){ 342 if( m_selector == NORMAL ){
337 list << selectedName(); 343 list << selectedName();
338 }else if ( m_selector == EXTENDED || m_selector == EXTENDED_ALL ) { 344 }else if ( m_selector == EXTENDED || m_selector == EXTENDED_ALL ) {
339 list << selectedName(); // FIXME implement multiple Selections 345 list << selectedName(); // FIXME implement multiple Selections
340 } 346 }
341 return list; 347 return list;
342} 348}
343/** If mode is set to the Dir selection this will return the selected path. 349/** If mode is set to the Dir selection this will return the selected path.
344 * 350 *
345 * 351 *
346 */ 352 */
347QString OFileSelector::selectedPath()const 353QString OFileSelector::selectedPath()const
348{ 354{
349 QString path; 355 QString path;
350 if( m_selector == NORMAL ){ 356 if( m_selector == NORMAL ){
351 path = QPEApplication::documentDir(); 357 path = QPEApplication::documentDir();
352 }else if( m_selector == EXTENDED || m_selector == EXTENDED_ALL ){ 358 }else if( m_selector == EXTENDED || m_selector == EXTENDED_ALL ){
@@ -359,17 +365,17 @@ QStringList OFileSelector::selectedPaths() const
359 QStringList list; 365 QStringList list;
360 list << selectedPath(); 366 list << selectedPath();
361 return list; 367 return list;
362} 368}
363QString OFileSelector::directory()const 369QString OFileSelector::directory()const
364{ 370{
365 if( m_selector == NORMAL ) 371 if( m_selector == NORMAL )
366 return QPEApplication::documentDir(); 372 return QPEApplication::documentDir();
367 373
368 return QDir(m_currentDir).absPath(); 374 return QDir(m_currentDir).absPath();
369} 375}
370 376
371int OFileSelector::fileCount() 377int OFileSelector::fileCount()
372{ 378{
373 int count; 379 int count;
374 switch( m_selector ){ 380 switch( m_selector ){
375 case NORMAL: 381 case NORMAL:
@@ -420,58 +426,90 @@ void OFileSelector::slotCancel()
420{ 426{
421 emit cancel(); 427 emit cancel();
422} 428}
423void OFileSelector::slotViewCheck(const QString &sel) 429void OFileSelector::slotViewCheck(const QString &sel)
424{ 430{
425 if( sel == tr("Documents" ) ){ 431 if( sel == tr("Documents" ) ){
426 if( m_select == 0 ){ 432 if( m_select == 0 ){
427 // autMime? fix cause now we use All and not the current 433 // autMime? fix cause now we use All and not the current
428 m_select = new FileSelector(m_autoMime ? QString::null : m_mimetypes.join(";"), 434 // yes currentMime fixes that for us
435 QString mime = currentMimeType();
436 m_select = new FileSelector(mime,
429 m_stack, "fileselector", 437 m_stack, "fileselector",
430 FALSE, FALSE); 438 FALSE, FALSE);
431 connect(m_select, SIGNAL(fileSelected( const DocLnk & ) ), 439 connect(m_select, SIGNAL(fileSelected( const DocLnk & ) ),
432 this, SLOT( slotFileBridgeSelected(const DocLnk & ) ) ); 440 this, SLOT( slotFileBridgeSelected(const DocLnk & ) ) );
433 //connect to close me and other signals as well 441 //connect to close me and other signals as well
434 442
435 m_stack->addWidget( m_select, NORMAL ); 443 m_stack->addWidget( m_select, NORMAL );
436 } 444 }
437 m_stack->raiseWidget( NORMAL ); 445 m_stack->raiseWidget( NORMAL );
438 m_selector = NORMAL; 446 m_selector = NORMAL;
439 }else if( sel == tr("Files") ){ 447 }else if( sel == tr("Files") ){
440 m_selector = EXTENDED; 448 m_selector = EXTENDED;
441 initializeListView(); 449 initializeListView();
442 reparse(); 450 reparse();
443 m_stack->raiseWidget( EXTENDED ); 451 m_stack->raiseWidget( EXTENDED );
444 }else if( sel == tr("All Files") ){ 452 }else if( sel == tr("All Files") ){
445 m_selector = EXTENDED_ALL; 453 m_selector = EXTENDED_ALL;
446 initializeListView(); 454 initializeListView();
447 reparse(); 455 reparse();
448 m_stack->raiseWidget( EXTENDED ); // same widget other QFileFilter 456 m_stack->raiseWidget( EXTENDED ); // same widget other QFileFilter
449 } 457 }
450} 458}
459// not yet finished.....
460QString OFileSelector::currentMimeType() const{
461 QString mime;
462 QString currentText;
463 if (m_shChooser )
464 currentText = m_mimeCheck->currentText();
465
466 if (tr("All") == currentText ) return QString::null;
467 else if (currentText.isEmpty() ) {
468 ;
469 }else {
470 QMap<QString, QStringList>::ConstIterator it;
471 it = m_mimetypes.find( currentText );
472 if ( it == m_mimetypes.end() ) {
473 mime = it.data().join(";");
474 }else{
475 mime = currentText;
476 }
477 }
478 return mime;
479}
451void OFileSelector::slotMimeCheck(const QString &mime) 480void OFileSelector::slotMimeCheck(const QString &mime)
452{ 481{
453 if( m_selector == NORMAL ){ 482 if( m_selector == NORMAL ){
454 if( m_autoMime ){ 483 //if( m_autoMime ){
484 QString newMimeType;
485 if (mime != tr("All") ) {
486 QMap<QString, QStringList>::Iterator it;
487 it = m_mimetypes.find(mime);
488 if ( it != m_mimetypes.end() ) {
489 newMimeType = it.data().join(";");
490 }else{
491 newMimeType = mime;
492 }
493 }
455 delete m_select; 494 delete m_select;
456 m_select = new FileSelector( mime == tr("All") ? QString::null : mime, 495 m_select = new FileSelector( newMimeType,
457 m_stack, "fileselector", 496 m_stack, "fileselector",
458 FALSE, FALSE); 497 FALSE, FALSE);
459 498
460 connect(m_select, SIGNAL(fileSelected( const DocLnk & ) ), 499 connect(m_select, SIGNAL(fileSelected( const DocLnk & ) ),
461 this, SLOT( slotFileBridgeSelected(const DocLnk & ) ) ); 500 this, SLOT( slotFileBridgeSelected(const DocLnk & ) ) );
462 //connect to close me and other signals as well 501 //connect to close me and other signals as well
463 m_stack->addWidget( m_select, NORMAL ); 502 m_stack->addWidget( m_select, NORMAL );
464 m_stack->raiseWidget( NORMAL ); 503 m_stack->raiseWidget( NORMAL );
465 updateMimes(); 504 updateMimes();
466 m_mimeCheck->clear(); 505 updateMimeCheck();
467 m_mimeCheck->insertStringList(m_mimetypes );
468 m_mimeCheck->setCurrentItem(indexByString( m_mimeCheck, mime) ); 506 m_mimeCheck->setCurrentItem(indexByString( m_mimeCheck, mime) );
469 } 507 //}
470 }else{ // others 508 }else{ // others
471 qWarning("Mime %s", mime.latin1() ); 509 qWarning("Mime %s", mime.latin1() );
472 if(m_shChooser ){ 510 if(m_shChooser ){
473 qWarning("Current Text %s", m_mimeCheck->currentText().latin1() ); 511 qWarning("Current Text %s", m_mimeCheck->currentText().latin1() );
474 //m_mimeCheck->setCurrentItem(indexByString( m_mimeCheck, mime) ); 512 //m_mimeCheck->setCurrentItem(indexByString( m_mimeCheck, mime) );
475 } 513 }
476 reparse(); 514 reparse();
477 } 515 }
@@ -507,17 +545,25 @@ void OFileSelector::locationComboChanged()
507} 545}
508void OFileSelector::init() 546void OFileSelector::init()
509{ 547{
510 m_lay = new QVBoxLayout( this ); 548 m_lay = new QVBoxLayout( this );
511 m_lay->setSpacing(0 ); 549 m_lay->setSpacing(0 );
512 550
513 m_stack = new QWidgetStack( this ); 551 m_stack = new QWidgetStack( this );
514 if( m_selector == NORMAL ){ 552 if( m_selector == NORMAL ){
515 m_select = new FileSelector(m_autoMime ? QString::null : m_mimetypes.join(";"), 553 QString mime;
554 if (!m_autoMime) {
555 if (!m_mimetypes.isEmpty() ) {
556 QMap<QString, QStringList>::Iterator it;
557 it = m_mimetypes.begin(); // cause we're in the init
558 mime = it.data().join(";");
559 }
560 }
561 m_select = new FileSelector(mime,
516 m_stack, "fileselector", 562 m_stack, "fileselector",
517 FALSE, FALSE); 563 FALSE, FALSE);
518 564
519 connect(m_select, SIGNAL(fileSelected( const DocLnk & ) ), 565 connect(m_select, SIGNAL(fileSelected( const DocLnk & ) ),
520 this, SLOT( slotFileBridgeSelected(const DocLnk & ) ) ); 566 this, SLOT( slotFileBridgeSelected(const DocLnk & ) ) );
521 //connect to close me and other signals as well 567 //connect to close me and other signals as well
522 568
523 m_stack->addWidget( m_select, NORMAL ); 569 m_stack->addWidget( m_select, NORMAL );
@@ -540,24 +586,24 @@ void OFileSelector::init()
540 586
541 if( m_shYesNo ) // the Yes No button row 587 if( m_shYesNo ) // the Yes No button row
542 initializeYes( ); 588 initializeYes( );
543} 589}
544void OFileSelector::updateMimes() 590void OFileSelector::updateMimes()
545{ 591{
546 if( m_autoMime ){ 592 if( m_autoMime ){
547 m_mimetypes.clear(); 593 m_mimetypes.clear();
548 m_mimetypes.append( tr("All") ); 594 m_mimetypes.insert( tr("All"), QString::null );
549 if( m_selector == NORMAL ){ 595 if( m_selector == NORMAL ){
550 DocLnkSet set; 596 DocLnkSet set;
551 Global::findDocuments(&set, QString::null ); 597 Global::findDocuments(&set, QString::null );
552 QListIterator<DocLnk> dit( set.children() ); 598 QListIterator<DocLnk> dit( set.children() );
553 for( ; dit.current(); ++dit ){ 599 for( ; dit.current(); ++dit ){
554 if( !m_mimetypes.contains( (*dit)->type() ) ) 600 if( !m_mimetypes.contains( (*dit)->type() ) )
555 m_mimetypes.append( (*dit)->type() ); 601 m_mimetypes.insert( (*dit)->type(), (*dit)->type() );
556 } 602 }
557 }// else done in reparse 603 }// else done in reparse
558 } 604 }
559} 605}
560void OFileSelector::initVars() 606void OFileSelector::initVars()
561{ 607{
562 if( m_mimetypes.isEmpty() ) 608 if( m_mimetypes.isEmpty() )
563 m_autoMime = true; 609 m_autoMime = true;
@@ -623,17 +669,17 @@ void OFileSelector::addFile(const QString &mime, QFileInfo *info, bool symlink)
623 pix = Resource::loadPixmap( "UnknownDocument-14"); 669 pix = Resource::loadPixmap( "UnknownDocument-14");
624 dir = info->dirPath( true ); 670 dir = info->dirPath( true );
625 if( symlink ) 671 if( symlink )
626 name = info->fileName() + " -> " +info->dirPath() + "/" + info->readLink(); 672 name = info->fileName() + " -> " +info->dirPath() + "/" + info->readLink();
627 else { 673 else {
628 name = info->fileName(); 674 name = info->fileName();
629 if( ( m_mode == OPEN && !info->isReadable() )|| 675 if( ( m_mode == OPEN && !info->isReadable() )||
630 ( m_mode == SAVE && !info->isWritable() ) ){ 676 ( m_mode == SAVE && !info->isWritable() ) ){
631 677
632 locked = true; pix = Resource::loadPixmap("locked"); 678 locked = true; pix = Resource::loadPixmap("locked");
633 } 679 }
634 } 680 }
635 new OFileSelectorItem( m_View, pix, name, 681 new OFileSelectorItem( m_View, pix, name,
636 info->lastModified().toString(), 682 info->lastModified().toString(),
637 QString::number( info->size() ), 683 QString::number( info->size() ),
638 dir, locked ); 684 dir, locked );
639} 685}
@@ -652,48 +698,49 @@ void OFileSelector::addDir(const QString &mime, QFileInfo *info, bool symlink )
652 else 698 else
653 pix = Resource::loadPixmap("lockedfolder"); 699 pix = Resource::loadPixmap("lockedfolder");
654 }else { // readable 700 }else { // readable
655 pix = symlink ? (*m_pixmaps)["dirsymlink"] : Resource::loadPixmap("folder") ; 701 pix = symlink ? (*m_pixmaps)["dirsymlink"] : Resource::loadPixmap("folder") ;
656 } 702 }
657 name = symlink ? info->fileName() + "->" + info->dirPath(true) + "/" +info->readLink() : info->fileName() ; 703 name = symlink ? info->fileName() + "->" + info->dirPath(true) + "/" +info->readLink() : info->fileName() ;
658 new OFileSelectorItem( m_View, pix, name, 704 new OFileSelectorItem( m_View, pix, name,
659 info->lastModified().toString(), 705 info->lastModified().toString(),
660 QString::number( info->size() ), 706 QString::number( info->size() ),
661 info->dirPath( true ), locked, 707 info->dirPath( true ), locked,
662 true ); 708 true );
663 709
664 }// else CUSTOM View 710 }// else CUSTOM View
665} 711}
666void OFileSelector::delItems() 712void OFileSelector::delItems()
667{ 713{
668 714
669} 715}
670void OFileSelector::initializeName() 716void OFileSelector::initializeName()
671{ 717{
672 /** Name Layout Line 718 /** Name Layout Line
673 * This is the Layout line arranged in 719 * This is the Layout line arranged in
674 * horizontal way each components 720 * horizontal way each components
675 * are next to each other 721 * are next to each other
676 * but we will only do this if 722 * but we will only do this if
677 * we didn't initialize a while ago. 723 * we didn't initialize a while ago.
678 */ 724 */
679 if( m_boxName == 0 ){ 725 if( m_boxName == 0 ){
680 m_boxName = new QHBox( this ); // remove this this? or use a QHBox 726 m_boxName = new QHBox( this ); // remove this this? or use a QHBox
681 m_fnLabel = new QLabel( m_boxName ); 727 m_fnLabel = new QLabel( m_boxName );
682 m_fnLabel->setText( tr("Name:") ); 728 m_fnLabel->setText( tr("Name:") );
683 m_edit = new QLineEdit( m_boxName ); 729 m_edit = new QLineEdit( m_boxName );
730 m_edit->setText( m_name );
684 //m_boxName->addWidget( m_fnLabel ); 731 //m_boxName->addWidget( m_fnLabel );
685 m_boxName->setMargin( 5 ); 732 m_boxName->setMargin( 5 );
686 m_boxName->setSpacing( 8 ); 733 m_boxName->setSpacing( 8 );
687 //m_boxName->setStretchFactor(m_edit, 100 ); // 100 is stretch factor 734 //m_boxName->setStretchFactor(m_edit, 100 ); // 100 is stretch factor
688 735
689 m_lay->addWidget( m_boxName, 0 ); // add it to the topLevel layout 736 m_lay->addWidget( m_boxName, 0 ); // add it to the topLevel layout
690 }// else we already initialized 737 }// else we already initialized
691 // maybe show the components? 738 // maybe show the components?
692 // 739 //
693} 740}
694void OFileSelector::initializeYes() 741void OFileSelector::initializeYes()
695{ 742{
696 /** The Save Cancel bar 743 /** The Save Cancel bar
697 * 744 *
698 */ 745 */
699 if( m_boxOk == 0 ){ 746 if( m_boxOk == 0 ){
@@ -708,54 +755,68 @@ void OFileSelector::initializeYes()
708 m_lay->addWidget( m_boxOk, 0 ); 755 m_lay->addWidget( m_boxOk, 0 );
709 756
710 connect( m_ok, SIGNAL( clicked() ), 757 connect( m_ok, SIGNAL( clicked() ),
711 this, SLOT(slotOk() ) ); 758 this, SLOT(slotOk() ) );
712 connect( m_cancel, SIGNAL( clicked() ), 759 connect( m_cancel, SIGNAL( clicked() ),
713 this, SLOT( slotCancel() ) ); 760 this, SLOT( slotCancel() ) );
714 } 761 }
715} 762}
763/*
764 * OK m_mimeCheck is a QComboBox we now want to fill
765 * out that combobox
766 * if automime we need to update the mimetypes
767 */
768void OFileSelector::updateMimeCheck() {
769 m_mimeCheck->clear();
770 if (m_autoMime ) {
771 //m_mimeCheck->insertItem( tr("All") );
772 updateMimes();
773 }
774
775 QMap<QString, QStringList>::Iterator it;
776 for (it = m_mimetypes.begin(); it != m_mimetypes.end(); ++it ) {
777 m_mimeCheck->insertItem( it.key() );
778 }
779}
780
716void OFileSelector::initializeChooser() 781void OFileSelector::initializeChooser()
717{ 782{
718 if( m_boxView == 0 ){ 783 if( m_boxView == 0 ){
719 m_boxView = new QHBox( this ); 784 m_boxView = new QHBox( this );
720 m_viewCheck = new QComboBox( m_boxView, "view check"); 785 m_viewCheck = new QComboBox( m_boxView, "view check");
721 m_mimeCheck = new QComboBox( m_boxView, "mime check"); 786 m_mimeCheck = new QComboBox( m_boxView, "mime check");
722 m_boxView->setSpacing( 8 ); 787 m_boxView->setSpacing( 8 );
723 m_lay->addWidget(m_boxView, 0 ); 788 m_lay->addWidget(m_boxView, 0 );
724 789
725 m_viewCheck->insertItem( tr("Documents") ); 790 m_viewCheck->insertItem( tr("Documents") );
726 m_viewCheck->insertItem( tr("Files") ); 791 m_viewCheck->insertItem( tr("Files") );
727 m_viewCheck->insertItem( tr("All Files") ); 792 m_viewCheck->insertItem( tr("All Files") );
728 if(!m_autoMime ) 793 updateMimeCheck();
729 m_mimeCheck->insertItem(m_mimetypes.join(",") ); 794
730 else{
731 updateMimes();
732 m_mimeCheck->insertStringList( m_mimetypes );
733 }
734 connect( m_viewCheck, SIGNAL( activated(const QString & ) ), 795 connect( m_viewCheck, SIGNAL( activated(const QString & ) ),
735 this, SLOT( slotViewCheck(const QString & ) ) ); 796 this, SLOT( slotViewCheck(const QString & ) ) );
736 connect( m_mimeCheck, SIGNAL( activated(const QString & ) ), 797 connect( m_mimeCheck, SIGNAL( activated(const QString & ) ),
737 this, SLOT( slotMimeCheck( const QString & ) ) ); 798 this, SLOT( slotMimeCheck( const QString & ) ) );
738 } 799 }
739} 800}
740void OFileSelector::initializeListView() 801void OFileSelector::initializeListView()
741{ 802{
742 if( m_pseudo == 0 ){ 803 if( m_pseudo == 0 ){
743 m_pseudo = new QWidget( m_stack, "Pseudo Widget"); 804 m_pseudo = new QWidget( m_stack, "Pseudo Widget");
744 m_pseudoLayout = new QVBoxLayout( m_pseudo ); 805 m_pseudoLayout = new QVBoxLayout( m_pseudo );
745 // toolbar 806 // toolbar
746 m_boxToolbar = new QHBox( m_pseudo ); 807 m_boxToolbar = new QHBox( m_pseudo );
747 m_boxToolbar->setSpacing(0 ); // next to each other please 808 m_boxToolbar->setSpacing(0 ); // next to each other please
748 809
749 // toolbar members 810 // toolbar members
750 { 811 {
751 // location QComboBox 812 // location QComboBox
752 m_location = new QComboBox( m_boxToolbar ); 813 m_location = new QComboBox( m_boxToolbar );
753 m_location->setEditable( TRUE ); 814 m_location->setEditable( TRUE );
754 m_location->setDuplicatesEnabled( FALSE ); 815 m_location->setDuplicatesEnabled( FALSE );
755 connect( m_location, SIGNAL(activated(const QString &) ), 816 connect( m_location, SIGNAL(activated(const QString &) ),
756 this, SLOT( slotLocationActivated(const QString &) ) ); 817 this, SLOT( slotLocationActivated(const QString &) ) );
757 connect( m_location->lineEdit(), SIGNAL(returnPressed() ), 818 connect( m_location->lineEdit(), SIGNAL(returnPressed() ),
758 this, SLOT(locationComboChanged() ) ); 819 this, SLOT(locationComboChanged() ) );
759 // UP Button 820 // UP Button
760 m_up = new QPushButton(Resource::loadIconSet("up"),"", 821 m_up = new QPushButton(Resource::loadIconSet("up"),"",
761 m_boxToolbar,"cdUpButton"); 822 m_boxToolbar,"cdUpButton");
@@ -826,23 +887,23 @@ void OFileSelector::initializeListView()
826 m_View->setAllColumnsShowFocus( TRUE ); 887 m_View->setAllColumnsShowFocus( TRUE );
827 888
828 connect(m_View, SIGNAL(selectionChanged() ), 889 connect(m_View, SIGNAL(selectionChanged() ),
829 this, SLOT(slotSelectionChanged() ) ); 890 this, SLOT(slotSelectionChanged() ) );
830 891
831 connect(m_View, SIGNAL(currentChanged(QListViewItem *) ), 892 connect(m_View, SIGNAL(currentChanged(QListViewItem *) ),
832 this, SLOT(slotCurrentChanged(QListViewItem * ) ) ); 893 this, SLOT(slotCurrentChanged(QListViewItem * ) ) );
833 894
834 connect(m_View, SIGNAL(mouseButtonClicked(int, QListViewItem*, const QPoint &, int) ), 895 connect(m_View, SIGNAL(mouseButtonClicked(int, QListViewItem*, const QPoint &, int) ),
835 this, SLOT(slotClicked( int, QListViewItem *, const QPoint &, int) ) ); 896 this, SLOT(slotClicked( int, QListViewItem *, const QPoint &, int) ) );
836 897
837 connect(m_View, SIGNAL(mouseButtonPressed(int, QListViewItem *, const QPoint &, int )), 898 connect(m_View, SIGNAL(mouseButtonPressed(int, QListViewItem *, const QPoint &, int )),
838 this, SLOT(slotRightButton(int, QListViewItem *, const QPoint &, int ) ) ); 899 this, SLOT(slotRightButton(int, QListViewItem *, const QPoint &, int ) ) );
839 900
840 m_pseudoLayout->addWidget( m_View, 288 ); 901 m_pseudoLayout->addWidget( m_View, 288 );
841 m_stack->addWidget( m_pseudo, EXTENDED ); 902 m_stack->addWidget( m_pseudo, EXTENDED );
842 } 903 }
843} 904}
844void OFileSelector::initializePerm() 905void OFileSelector::initializePerm()
845{ 906{
846 if( m_checkPerm == 0 ){ 907 if( m_checkPerm == 0 ){
847 m_checkPerm = new QCheckBox(tr("Ser Permission"), this, "perm"); 908 m_checkPerm = new QCheckBox(tr("Ser Permission"), this, "perm");
848 m_checkPerm->setChecked( false ); 909 m_checkPerm->setChecked( false );
@@ -871,17 +932,22 @@ bool OFileSelector::compliesMime( const QString &path, const QString &mime )
871{ 932{
872 if( mime == "All" ) 933 if( mime == "All" )
873 return true; 934 return true;
874 MimeType type( path ); 935 MimeType type( path );
875 if( type.id() == mime ) 936 if( type.id() == mime )
876 return true; 937 return true;
877 return false; 938 return false;
878} 939}
940/* check if the mimetype in mime
941 * complies with the one which is current
942 */
943bool OFileSelector::compliesMime( const QString& mime ) {
879 944
945}
880void OFileSelector::slotFileSelected( const QString &string ) 946void OFileSelector::slotFileSelected( const QString &string )
881{ 947{
882 if( m_shLne ) 948 if( m_shLne )
883 m_edit->setText( string ); 949 m_edit->setText( string );
884 emit fileSelected( string ); 950 emit fileSelected( string );
885} 951}
886void OFileSelector::slotFileBridgeSelected( const DocLnk &lnk ) 952void OFileSelector::slotFileBridgeSelected( const DocLnk &lnk )
887{ 953{
@@ -1045,42 +1111,42 @@ void OFileSelector::reparse()
1045 while( (fi=it.current() ) ) { 1111 while( (fi=it.current() ) ) {
1046 if( fi->extension() == QString::fromLatin1("desktop") ){ 1112 if( fi->extension() == QString::fromLatin1("desktop") ){
1047 ++it; 1113 ++it;
1048 continue; 1114 continue;
1049 } 1115 }
1050 MimeType type( fi->absFilePath() ); 1116 MimeType type( fi->absFilePath() );
1051 if( !m_mimetypes.contains( type.id() ) ){ 1117 if( !m_mimetypes.contains( type.id() ) ){
1052 //qWarning("Type %s", type.id().latin1() ); 1118 //qWarning("Type %s", type.id().latin1() );
1053 m_mimetypes.append( type.id() ); 1119 m_mimetypes.insert( type.id(), type.id() );
1054 } 1120 }
1055 1121
1056 ++it; 1122 ++it;
1057 } 1123 }
1058 // add them to the chooser 1124 // add them to the chooser
1059 m_mimeCheck->insertItem( tr("All") ); 1125 updateMimeCheck();
1060 m_mimeCheck->insertStringList( m_mimetypes );
1061 m_mimeCheck->setCurrentItem( indexByString( m_mimeCheck, currentMimeType ) ); 1126 m_mimeCheck->setCurrentItem( indexByString( m_mimeCheck, currentMimeType ) );
1062 currentMimeType = m_mimeCheck->currentText(); 1127 currentMimeType = m_mimeCheck->currentText();
1063 } 1128 }
1064 }else { // no autoMime 1129 }else { // no autoMime
1065 currentMimeType = m_mimetypes.join(";"); 1130 // let the mimetype be set from out side the m_mimeCheck FEATURE
1131
1066 if( m_shChooser ){ 1132 if( m_shChooser ){
1067 m_mimeCheck->clear(); 1133 currentMimeType = m_mimeCheck->currentText();
1068 m_mimeCheck->insertItem(m_mimetypes.join(",") ); 1134 updateMimeCheck();
1069 } 1135 }
1070 } 1136 }
1071 // now we got our mimetypes we can add the files 1137 // now we got our mimetypes we can add the files
1072 1138
1073 QDir dir( m_currentDir ); 1139 QDir dir( m_currentDir );
1074 1140
1075 int sort; 1141 int sort;
1076 if ( m_case ) 1142 if ( m_case )
1077 sort = (QDir::IgnoreCase | QDir::Name | QDir::DirsFirst | QDir::Reversed); 1143 sort = (QDir::IgnoreCase | QDir::Name | QDir::DirsFirst | QDir::Reversed);
1078 else 1144 else
1079 sort = (QDir::Name | QDir::DirsFirst | QDir::Reversed); 1145 sort = (QDir::Name | QDir::DirsFirst | QDir::Reversed);
1080 dir.setSorting( sort ); 1146 dir.setSorting( sort );
1081 1147
1082 int filter; 1148 int filter;
1083 if( m_selector == EXTENDED_ALL /*|| m_selector ==CUSTOM_ALL */ ){ 1149 if( m_selector == EXTENDED_ALL /*|| m_selector ==CUSTOM_ALL */ ){
1084 filter = QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All; 1150 filter = QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All;
1085 }else 1151 }else
1086 filter = QDir::Files | QDir::Dirs | QDir::All; 1152 filter = QDir::Files | QDir::Dirs | QDir::All;
@@ -1120,15 +1186,15 @@ void OFileSelector::reparse()
1120 }else if( fi->isDir() ){ 1186 }else if( fi->isDir() ){
1121 addDir( currentMimeType, fi ); 1187 addDir( currentMimeType, fi );
1122 }else if( fi->isFile() ){ 1188 }else if( fi->isFile() ){
1123 addFile( currentMimeType, fi ); 1189 addFile( currentMimeType, fi );
1124 } 1190 }
1125 //qWarning( "%s", fi->fileName().latin1() ); 1191 //qWarning( "%s", fi->fileName().latin1() );
1126 ++it; 1192 ++it;
1127 } // of while loop 1193 } // of while loop
1128 m_View->sort(); 1194 m_View->sort();
1129 if( m_shTool ){ 1195 if( m_shTool ){
1130 m_location->insertItem( m_currentDir ); 1196 m_location->insertItem( m_currentDir );
1131 1197
1132 } 1198 }
1133 // reenable painting and updates 1199 // reenable painting and updates
1134} 1200}
diff --git a/libopie/ofileselector.h b/libopie/ofileselector.h
index 47697b9..f2d5f84 100644
--- a/libopie/ofileselector.h
+++ b/libopie/ofileselector.h
@@ -1,35 +1,35 @@
1/* 1/*
2 This is based on code and idea of 2 This is based on code and ideas 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
@@ -38,53 +38,87 @@
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#include <qmap.h> 41#include <qmap.h>
42#include <qvaluelist.h> 42#include <qvaluelist.h>
43 43
44#include <qpe/applnk.h> 44#include <qpe/applnk.h>
45#include <qlistview.h> 45#include <qlistview.h>
46
46/** This is OPIEs FileDialog Widget. You can use it 47/** This is OPIEs FileDialog Widget. You can use it
47 * as a dropin replacement of the fileselector and 48 * as a dropin replacement of the fileselector and
48 * or use any of the new features. 49 * or use any of the new features.
49 * This is also a complete FileSave and FileLoad widget 50 * This is also a complete FileSave and FileLoad widget
50 * If you look for a Dialog check OFileDialog 51 * If you look for a Dialog check OFileDialog
51 * 52 *
52 */ 53 */
53class DocLnk; 54class DocLnk;
54class QCheckBox; 55class QCheckBox;
55class QComboBox; 56class QComboBox;
56class QPushButton; 57class QPushButton;
57class FileSelector; 58class FileSelector;
58class QGridLayout; 59class QGridLayout;
59class QLineEdit; 60class QLineEdit;
60class QLabel; 61class QLabel;
61class QWidgetStack; 62class QWidgetStack;
62class QHBoxLayout; 63class QHBoxLayout;
63class QVBoxLayout; 64class QVBoxLayout;
64class QPopupMenu; 65class QPopupMenu;
65class QFileInfo; 66class QFileInfo;
66class QHBox; 67class QHBox;
67// 68//
68 69
70typedef QMap< QString, QStringList> MimeTypes;
69 71
70class OFileSelector : public QWidget { 72class OFileSelector : public QWidget {
71 Q_OBJECT 73 Q_OBJECT
72 public: 74 public:
75 /**
76 * The mode of the file selector
77 * Either open, save, fileselector or dir browsing mode
78 *
79 */
73 enum Mode {OPEN=1, SAVE=2, FILESELECTOR=4, DIR=8 }; 80 enum Mode {OPEN=1, SAVE=2, FILESELECTOR=4, DIR=8 };
81
82 /**
83 * Selector. Either NORMAL for the one shipped with
84 * libqpe or EXTENDED. for the EXTENDED
85 * EXTENDED_ALL also shows 'hidden' files
86 */
74 enum Selector{NORMAL=0, EXTENDED = 1, EXTENDED_ALL =2 }; 87 enum Selector{NORMAL=0, EXTENDED = 1, EXTENDED_ALL =2 };
88
89 /**
90 * This is reserved for futrue views
91 */
75 enum View { DIRS = 1, FILES = 2, TREE = 4, ICON = 8 }; 92 enum View { DIRS = 1, FILES = 2, TREE = 4, ICON = 8 };
76 93
77 OFileSelector(QWidget *wid, int mode, int selector, 94 /**
95 * A c'tor which should be used for advanced mode
96 * @param wid the parent
97 * @param mode the Mode of the Selector
98 * @param selector the current View of the Selector
99 * @param dirName in which dir to start
100 * @param fileName a proposed filename
101 * @param mimetypes A list of mimetypes \
102 * QString is for a identifier name like "Text files"
103 * the coresponding QStringList is used for the mimetypes
104 * if empty it'll fill the list of mimetypes depending
105 * on the content of the current directory
106 */
107
108 OFileSelector(QWidget *wid, int mode, int selector,
78 const QString &dirName, 109 const QString &dirName,
79 const QString &fileName = QString::null, 110 const QString &fileName = QString::null,
80 const QStringList &mimetypes = QStringList() ); 111 const MimeTypes &mimetypes = MimeTypes() );
81 112
82 113
114 /**
115 * This is a QPE compatible c'tor
116 */
83 OFileSelector(const QString &mimeFilter, QWidget *parent, 117 OFileSelector(const QString &mimeFilter, QWidget *parent,
84 const char *name, bool newVisible = TRUE, 118 const char *name, bool newVisible = TRUE,
85 bool closeVisible = FALSE ); 119 bool closeVisible = FALSE );
86 120
87 ~OFileSelector(); 121 ~OFileSelector();
88 122
89 // currently only for the FILESELECTOR Mode 123 // currently only for the FILESELECTOR Mode
90 void setNewVisible( bool /*b*/ ); 124 void setNewVisible( bool /*b*/ );
@@ -125,17 +159,17 @@ class OFileSelector : public QWidget {
125 bool showFiles()const { return m_files; }; 159 bool showFiles()const { return m_files; };
126 void setShowFiles(bool ); 160 void setShowFiles(bool );
127 bool cd(const QString &path ); 161 bool cd(const QString &path );
128 162
129 163
130 int mode()const { return m_mode; }; 164 int mode()const { return m_mode; };
131 int selector()const { return m_selector; }; 165 int selector()const { return m_selector; };
132 void setSelector( int ); 166 void setSelector( int );
133 167
134 bool showPopup()const { return m_showPopup; }; 168 bool showPopup()const { return m_showPopup; };
135 void setShowPopup( bool pop ) { m_showPopup = pop; }; 169 void setShowPopup( bool pop ) { m_showPopup = pop; };
136 void setPopupMenu( QPopupMenu * ); 170 void setPopupMenu( QPopupMenu * );
137 171
138 // void updateLay(); 172 // void updateLay();
139 173
140 void reparse(); // re reads the dir 174 void reparse(); // re reads the dir
141 175
@@ -170,32 +204,33 @@ class OFileSelector : public QWidget {
170 void slotMimeCheck(const QString & ); 204 void slotMimeCheck(const QString & );
171 void slotLocationActivated(const QString & ); 205 void slotLocationActivated(const QString & );
172 void slotInsertLocationPath(const QString &, int); 206 void slotInsertLocationPath(const QString &, int);
173 void locationComboChanged(); 207 void locationComboChanged();
174 208
175 private: 209 private:
176 void init(); 210 void init();
177 void updateMimes(); 211 void updateMimes();
178 212
179 protected: 213 protected:
180 214
181 private: 215 private:
182 int m_mode, m_selector; 216 int m_mode, m_selector;
183 QComboBox *m_location, *m_mimeCheck, *m_viewCheck; 217 QComboBox *m_location, *m_mimeCheck, *m_viewCheck;
184 QPushButton *m_homeButton, *m_docButton, *m_hideButton, *m_ok, *m_cancel; 218 QPushButton *m_homeButton, *m_docButton, *m_hideButton, *m_ok, *m_cancel;
185 QPushButton *m_reread, *m_up, *m_new, *m_close; 219 QPushButton *m_reread, *m_up, *m_new, *m_close;
186 QListView *m_View; 220 QListView *m_View;
187 QCheckBox *m_checkPerm; 221 QCheckBox *m_checkPerm;
188 QWidget *m_pseudo; 222 QWidget *m_pseudo;
189 QVBoxLayout *m_pseudoLayout; 223 QVBoxLayout *m_pseudoLayout;
190 224
191 QString m_currentDir; 225 QString m_currentDir;
192 QString m_name; 226 QString m_name;
193 QStringList m_mimetypes; 227// QStringList m_mimetypes;
228 QMap<QString, QStringList> m_mimetypes;
194 229
195 FileSelector *m_select; 230 FileSelector *m_select;
196 QWidgetStack *m_stack; 231 QWidgetStack *m_stack;
197 QVBoxLayout *m_lay; 232 QVBoxLayout *m_lay;
198 QGridLayout *m_Oselector; 233 QGridLayout *m_Oselector;
199 234
200 QHBox *m_boxToolbar; 235 QHBox *m_boxToolbar;
201 QHBox *m_boxOk; // (no layout anymore) wait 236 QHBox *m_boxOk; // (no layout anymore) wait
@@ -227,22 +262,32 @@ class OFileSelector : public QWidget {
227 virtual void addSymlink(const QString &, QFileInfo *, bool = FALSE ){}; 262 virtual void addSymlink(const QString &, QFileInfo *, bool = FALSE ){};
228 void delItems(); 263 void delItems();
229 void initializeName(); 264 void initializeName();
230 void initializeYes(); 265 void initializeYes();
231 void initializeChooser(); 266 void initializeChooser();
232 void initializeListView(); 267 void initializeListView();
233 void initializePerm(); 268 void initializePerm();
234 void initPics(); 269 void initPics();
235 bool compliesMime(const QString &path, const QString &mime); 270 bool compliesMime(const QString &path,
236 271 const QString &mime);
272 bool compliesMime(const QString& mime );
273 /**
274 * Updates the QComboBox with the current mimetypes
275 */
276 void updateMimeCheck();
277
278 /**
279 * Returns the current mimetype
280 */
281 QString currentMimeType()const;
237 class OFileSelectorPrivate; 282 class OFileSelectorPrivate;
238 OFileSelectorPrivate *d; 283 OFileSelectorPrivate *d;
239 static QMap<QString,QPixmap> *m_pixmaps; 284 static QMap<QString,QPixmap> *m_pixmaps;
240 285
241private slots: 286private slots:
242 void slotFileSelected(const QString & ); // not really meant to be a slot 287 void slotFileSelected(const QString & ); // not really meant to be a slot
243 void slotFileBridgeSelected( const DocLnk & ); 288 void slotFileBridgeSelected( const DocLnk & );
244 virtual void slotSelectionChanged(); 289 virtual void slotSelectionChanged();
245 virtual void slotCurrentChanged(QListViewItem* ); 290 virtual void slotCurrentChanged(QListViewItem* );
246 virtual void slotClicked( int, QListViewItem *item, const QPoint &, int); 291 virtual void slotClicked( int, QListViewItem *item, const QPoint &, int);
247 virtual void slotRightButton(int, QListViewItem *, const QPoint &, int ); 292 virtual void slotRightButton(int, QListViewItem *, const QPoint &, int );
248 virtual void slotContextMenu( QListViewItem *item); 293 virtual void slotContextMenu( QListViewItem *item);