summaryrefslogtreecommitdiff
path: root/libopie2
Unidiff
Diffstat (limited to 'libopie2') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opieui/fileselector/ofiledialog.cpp35
-rw-r--r--libopie2/opieui/fileselector/ofiledialog.h5
-rw-r--r--libopie2/opieui/fileselector/ofileselector.cpp66
-rw-r--r--libopie2/opieui/fileselector/ofileselector.h3
4 files changed, 89 insertions, 20 deletions
diff --git a/libopie2/opieui/fileselector/ofiledialog.cpp b/libopie2/opieui/fileselector/ofiledialog.cpp
index beb4d6c..ebce0ef 100644
--- a/libopie2/opieui/fileselector/ofiledialog.cpp
+++ b/libopie2/opieui/fileselector/ofiledialog.cpp
@@ -25,97 +25,100 @@
25 Boston, MA 02111-1307, USA. 25 Boston, MA 02111-1307, USA.
26 26
27*/ 27*/
28 28
29 29
30/* OPIE */ 30/* OPIE */
31#include <opie2/ofiledialog.h> 31#include <opie2/ofiledialog.h>
32#include <qpe/applnk.h> 32#include <qpe/applnk.h>
33#include <qpe/config.h> 33#include <qpe/config.h>
34#include <qpe/qpeapplication.h> 34#include <qpe/qpeapplication.h>
35 35
36/* QT */ 36/* QT */
37#include <qfileinfo.h> 37#include <qfileinfo.h>
38#include <qstring.h> 38#include <qstring.h>
39#include <qapplication.h> 39#include <qapplication.h>
40#include <qlayout.h> 40#include <qlayout.h>
41 41
42using namespace Opie::Ui; 42using namespace Opie::Ui;
43 43
44namespace 44namespace
45{ 45{
46/* 46/*
47 * helper functions to load the start dir 47 * helper functions to load the start dir
48 * and to save it 48 * and to save it
49 * helper to extract the dir out of a file name 49 * helper to extract the dir out of a file name
50 */ 50 */
51/** 51/**
52 * This method will use Config( argv[0] ); 52 * This method will use Config( argv[0] );
53 * @param key The group key used 53 * @param key The group key used
54 */ 54 */
55QString lastUsedDir( const QString& key ) 55QString lastUsedDir( const QString& key )
56{ 56{
57 if ( qApp->argc() < 1 ) 57 if ( qApp->argc() < 1 )
58 return QString::null; 58 return QString::null;
59 59
60 Config cfg( QFileInfo(qApp->argv()[0]).fileName() ); // appname 60 Config cfg( QFileInfo(qApp->argv()[0]).fileName() ); // appname
61 cfg.setGroup( key ); 61 cfg.setGroup( key );
62 return cfg.readEntry("LastDir", QPEApplication::documentDir() ); 62 return cfg.readEntry("LastDir", QPEApplication::documentDir() );
63} 63}
64 64
65void saveLastDir( const QString& key, const QString& file ) 65void saveLastDir( const QString& key, const QString& file )
66{ 66{
67 if ( qApp->argc() < 1 ) 67 if ( qApp->argc() < 1 )
68 return; 68 return;
69 69
70 Config cfg( QFileInfo(qApp->argv()[0]).fileName() ); 70 Config cfg( QFileInfo(qApp->argv()[0]).fileName() );
71 cfg.setGroup( key ); 71 cfg.setGroup( key );
72 QFileInfo inf( file ); 72 QFileInfo inf( file );
73 cfg.writeEntry("LastDir", inf.dirPath( true ) ); 73 if ( inf.isFile() )
74 cfg.writeEntry("LastDir", inf.dirPath( true ) );
75 else
76 cfg.writeEntry("LastDir", file );
74} 77}
75}; 78};
76 79
77/** 80/**
78 * This constructs a modal dialog 81 * This constructs a modal dialog
79 * 82 *
80 * @param caption The caption of the dialog 83 * @param caption The caption of the dialog
81 * @param wid The parent widget 84 * @param wid The parent widget
82 * @param mode The mode of the OFileSelector @see OFileSelector 85 * @param mode The mode of the OFileSelector @see OFileSelector
83 * @param selector The selector of the OFileSelector 86 * @param selector The selector of the OFileSelector
84 * @param dirName the dir or resource to start from 87 * @param dirName the dir or resource to start from
85 * @param fileName a proposed or existing filename 88 * @param fileName a proposed or existing filename
86 * @param mimetypes The mimeTypes 89 * @param mimetypes The mimeTypes
87 */ 90 */
88OFileDialog::OFileDialog(const QString &caption, 91OFileDialog::OFileDialog(const QString &caption,
89 QWidget *wid, int mode, int selector, 92 QWidget *wid, int mode, int selector,
90 const QString &dirName, 93 const QString &dirName,
91 const QString &fileName, 94 const QString &fileName,
92 const QMap<QString,QStringList>& mimetypes ) 95 const QMap<QString,QStringList>& mimetypes )
93 : QDialog( wid, "OFileDialog", true ) 96 : QDialog( wid, "OFileDialog", true )
94{ 97{
95 // QVBoxLayout *lay = new QVBoxLayout(this); 98 // QVBoxLayout *lay = new QVBoxLayout(this);
96 //showMaximized(); 99 //showMaximized();
97 QVBoxLayout *lay = new QVBoxLayout(this ); 100 QVBoxLayout *lay = new QVBoxLayout(this );
98 file = new OFileSelector(this , mode, selector, 101 file = new OFileSelector(this , mode, selector,
99 dirName, fileName, 102 dirName, fileName,
100 mimetypes ); 103 mimetypes );
101 lay->addWidget( file ); 104 lay->addWidget( file );
102 105
103 //lay->addWidget( file ); 106 //lay->addWidget( file );
104 //showFullScreen(); 107 //showFullScreen();
105 setCaption( caption.isEmpty() ? tr("FileDialog") : caption ); 108 setCaption( caption.isEmpty() ? tr("FileDialog") : caption );
106 connect(file, SIGNAL(fileSelected(const QString&) ), 109 connect(file, SIGNAL(fileSelected(const QString&) ),
107 this, SLOT(slotFileSelected(const QString&) ) ); 110 this, SLOT(slotFileSelected(const QString&) ) );
108 connect(file, SIGNAL(ok() ), 111 connect(file, SIGNAL(ok() ),
109 this, SLOT(slotSelectorOk()) ) ; 112 this, SLOT(slotSelectorOk()) ) ;
110 113
111 connect(file, SIGNAL(dirSelected(const QString&) ), this, SLOT(slotDirSelected(const QString&) ) ); 114 connect(file, SIGNAL(dirSelected(const QString&) ), this, SLOT(slotDirSelected(const QString&) ) );
112 115
113#if 0 116#if 0
114 connect(file, SIGNAL(dirSelected(const QString&) ), 117 connect(file, SIGNAL(dirSelected(const QString&) ),
115 this, SLOT(slotDirSelected(const QString&) ) ); 118 this, SLOT(slotDirSelected(const QString&) ) );
116#endif 119#endif
117} 120}
118/** 121/**
119 * @returns the mimetype of the selected 122 * @returns the mimetype of the selected
120 * currently it return QString::null 123 * currently it return QString::null
121 */ 124 */
@@ -159,64 +162,94 @@ QString OFileDialog::getOpenFileName(int selector,
159 const QString &caption ) 162 const QString &caption )
160{ 163{
161 QString ret; 164 QString ret;
162 QString startDir = _startDir; 165 QString startDir = _startDir;
163 if (startDir.isEmpty() ) 166 if (startDir.isEmpty() )
164 startDir = lastUsedDir( "FileDialog-OPEN" ); 167 startDir = lastUsedDir( "FileDialog-OPEN" );
165 168
166 169
167 OFileDialog dlg( caption.isEmpty() ? tr("Open") : caption, 170 OFileDialog dlg( caption.isEmpty() ? tr("Open") : caption,
168 wid, OFileSelector::Open, selector, startDir, file, mimes); 171 wid, OFileSelector::Open, selector, startDir, file, mimes);
169 dlg.showMaximized(); 172 dlg.showMaximized();
170 if( dlg.exec() ) 173 if( dlg.exec() )
171 { 174 {
172 ret = dlg.fileName(); 175 ret = dlg.fileName();
173 saveLastDir( "FileDialog-OPEN", ret ); 176 saveLastDir( "FileDialog-OPEN", ret );
174 } 177 }
175 178
176 return ret; 179 return ret;
177} 180}
178 181
179/** 182/**
180 * This opens up a file dialog in save mode 183 * This opens up a file dialog in save mode
181 * @see getOpenFileName 184 * @see getOpenFileName
182 */ 185 */
183QString OFileDialog::getSaveFileName(int selector, 186QString OFileDialog::getSaveFileName(int selector,
184 const QString &_startDir, 187 const QString &_startDir,
185 const QString &file, 188 const QString &file,
186 const MimeTypes &mimes, 189 const MimeTypes &mimes,
187 QWidget *wid, 190 QWidget *wid,
188 const QString &caption ) 191 const QString &caption )
189{ 192{
190 QString ret; 193 QString ret;
191 QString startDir = _startDir; 194 QString startDir = _startDir;
192 if (startDir.isEmpty() ) 195 if (startDir.isEmpty() )
193 startDir = lastUsedDir( "FileDialog-SAVE" ); 196 startDir = lastUsedDir( "FileDialog-SAVE" );
194 197
195 OFileDialog dlg( caption.isEmpty() ? tr("Save") : caption, 198 OFileDialog dlg( caption.isEmpty() ? tr("Save") : caption,
196 wid, OFileSelector::Save, selector, startDir, file, mimes); 199 wid, OFileSelector::Save, selector, startDir, file, mimes);
197 dlg.showMaximized(); 200 dlg.showMaximized();
198 if( dlg.exec() ) 201 if( dlg.exec() )
199 { 202 {
200 ret = dlg.fileName(); 203 ret = dlg.fileName();
201 saveLastDir( "FileDialog-SAVE", ret ); 204 saveLastDir( "FileDialog-SAVE", ret );
202 } 205 }
203 206
204 return ret; 207 return ret;
205} 208}
206 209
210/**
211 * This opens up a filedialog in select directory mode
212 *
213 * @param selector the Selector Mode
214 * @param startDir Where to start from
215 * @param wid the parent
216 * @param caption of the dialog if QString::null tr("Open") will be used
217 * @return the directoryName or QString::null
218 */
219QString OFileDialog::getDirectory(int selector,
220 const QString &_startDir,
221 QWidget *wid,
222 const QString &caption )
223{
224 QString ret;
225 QString startDir = _startDir;
226 if ( startDir.isEmpty() )
227 startDir = lastUsedDir( "FileDialog-SELECTDIR" );
228
229 OFileDialog dlg( caption.isEmpty() ? tr( "Select Directory" ) : caption,
230 wid, OFileSelector::DirectorySelector, selector, startDir );
231 dlg.showMaximized();
232 if ( dlg.exec() )
233 {
234 ret = dlg.fileName();
235 saveLastDir( "FileDialog-SELECTDIR", ret );
236 }
237 return ret;
238}
239
207void OFileDialog::slotFileSelected(const QString & ) 240void OFileDialog::slotFileSelected(const QString & )
208{ 241{
209 accept(); 242 accept();
210} 243}
211 244
212void OFileDialog::slotSelectorOk( ) 245void OFileDialog::slotSelectorOk( )
213{ 246{
214 accept(); 247 accept();
215} 248}
216 249
217void OFileDialog::slotDirSelected(const QString &dir ) 250void OFileDialog::slotDirSelected(const QString &dir )
218{ 251{
219 setCaption( dir ); 252 setCaption( dir );
220 // if mode 253 // if mode
221 //accept(); 254 //accept();
222} 255}
diff --git a/libopie2/opieui/fileselector/ofiledialog.h b/libopie2/opieui/fileselector/ofiledialog.h
index dfecf3d..569f45c 100644
--- a/libopie2/opieui/fileselector/ofiledialog.h
+++ b/libopie2/opieui/fileselector/ofiledialog.h
@@ -44,67 +44,72 @@ namespace Ui {
44 * a file for either opening or saving. 44 * a file for either opening or saving.
45 * Most of the time the c'tor will not be used instead using 45 * Most of the time the c'tor will not be used instead using
46 * the static member functions is prefered. 46 * the static member functions is prefered.
47 * 47 *
48 * <pre> 48 * <pre>
49 * QMap<QString, QStringList> mimeTypes; 49 * QMap<QString, QStringList> mimeTypes;
50 * QStringList types; 50 * QStringList types;
51 * types << "text[slash]* "; 51 * types << "text[slash]* ";
52 * mimeTypes.insert( tr("Text"), types ); 52 * mimeTypes.insert( tr("Text"), types );
53 * mimeTypes.insert( tr("All"), " * / * " ); // remove the spaces in the 2nd comment 53 * mimeTypes.insert( tr("All"), " * / * " ); // remove the spaces in the 2nd comment
54 * QString fileName= OFileDialog::getOpenFileName( OFileSelector::EXTENDED_ALL, 54 * QString fileName= OFileDialog::getOpenFileName( OFileSelector::EXTENDED_ALL,
55 * "foo","bar", mimeTypes); 55 * "foo","bar", mimeTypes);
56 * </pre> 56 * </pre>
57 * 57 *
58 * @short A small QDialog swalloing a FileSelector 58 * @short A small QDialog swalloing a FileSelector
59 * @see QDialog 59 * @see QDialog
60 * @see OFileSelector 60 * @see OFileSelector
61 * @version 0.1-unfinished 61 * @version 0.1-unfinished
62 * @author Holger Freyther ( zecke@handhelds.org ) 62 * @author Holger Freyther ( zecke@handhelds.org )
63 */ 63 */
64class OFileDialog : public QDialog 64class OFileDialog : public QDialog
65{ 65{
66 Q_OBJECT 66 Q_OBJECT
67public: 67public:
68 OFileDialog(const QString &caption, 68 OFileDialog(const QString &caption,
69 QWidget *, int mode, int selector, 69 QWidget *, int mode, int selector,
70 const QString &dirName, 70 const QString &dirName,
71 const QString &fileName = QString::null, 71 const QString &fileName = QString::null,
72 const MimeTypes &mimetypes = MimeTypes() ); 72 const MimeTypes &mimetypes = MimeTypes() );
73 QString mimetype() const; 73 QString mimetype() const;
74 QString fileName() const; 74 QString fileName() const;
75 DocLnk selectedDocument()const; 75 DocLnk selectedDocument()const;
76 76
77 // static methods 77 // static methods
78 static QString getOpenFileName(int selector, 78 static QString getOpenFileName(int selector,
79 const QString& startDir = QString::null, 79 const QString& startDir = QString::null,
80 const QString &fileName = QString::null, 80 const QString &fileName = QString::null,
81 const MimeTypes& mime = MimeTypes(), 81 const MimeTypes& mime = MimeTypes(),
82 QWidget *wid = 0, 82 QWidget *wid = 0,
83 const QString &caption = QString::null ); 83 const QString &caption = QString::null );
84 84
85 static QString getSaveFileName(int selector, 85 static QString getSaveFileName(int selector,
86 const QString& startDir = QString::null, 86 const QString& startDir = QString::null,
87 const QString& fileName = QString::null, 87 const QString& fileName = QString::null,
88 const MimeTypes& mimefilter = MimeTypes(), 88 const MimeTypes& mimefilter = MimeTypes(),
89 QWidget *wid = 0, 89 QWidget *wid = 0,
90 const QString &caption = QString::null ); 90 const QString &caption = QString::null );
91 91
92 static QString getDirectory(int selector,
93 const QString &startDir = QString::null,
94 QWidget *wid = 0,
95 const QString &caption = QString::null );
96
92 //let's OFileSelector catch up first 97 //let's OFileSelector catch up first
93 //static QString getExistingDirectory(const QString& startDir = QString::null, 98 //static QString getExistingDirectory(const QString& startDir = QString::null,
94 //QWidget *parent = 0, const QString& caption = QString::null ); 99 //QWidget *parent = 0, const QString& caption = QString::null );
95 100
96private: 101private:
97 class OFileDialogPrivate; 102 class OFileDialogPrivate;
98 OFileDialogPrivate *d; 103 OFileDialogPrivate *d;
99 OFileSelector *file; 104 OFileSelector *file;
100 105
101private slots: 106private slots:
102 void slotFileSelected( const QString & ); 107 void slotFileSelected( const QString & );
103 void slotDirSelected(const QString & ); 108 void slotDirSelected(const QString & );
104 void slotSelectorOk(); 109 void slotSelectorOk();
105}; 110};
106 111
107} 112}
108} 113}
109 114
110#endif 115#endif
diff --git a/libopie2/opieui/fileselector/ofileselector.cpp b/libopie2/opieui/fileselector/ofileselector.cpp
index b06defd..346eeae 100644
--- a/libopie2/opieui/fileselector/ofileselector.cpp
+++ b/libopie2/opieui/fileselector/ofileselector.cpp
@@ -383,100 +383,103 @@ OFileViewFileListView::OFileViewFileListView( QWidget* parent, const QString& st
383 m_view->setAllColumnsShowFocus( TRUE ); 383 m_view->setAllColumnsShowFocus( TRUE );
384 384
385 lay->addWidget( m_view, 1000 ); 385 lay->addWidget( m_view, 1000 );
386 connectSlots(); 386 connectSlots();
387} 387}
388 388
389OFileViewFileListView::~OFileViewFileListView() 389OFileViewFileListView::~OFileViewFileListView()
390{ 390{
391} 391}
392 392
393void OFileViewFileListView::slotNew() 393void OFileViewFileListView::slotNew()
394{ 394{
395 DocLnk lnk; 395 DocLnk lnk;
396 emit selector()->newSelected( lnk ); 396 emit selector()->newSelected( lnk );
397} 397}
398 398
399OFileSelectorItem* OFileViewFileListView::currentItem()const 399OFileSelectorItem* OFileViewFileListView::currentItem()const
400{ 400{
401 QListViewItem* item = m_view->currentItem(); 401 QListViewItem* item = m_view->currentItem();
402 if (!item ) 402 if (!item )
403 return 0l; 403 return 0l;
404 404
405 return static_cast<OFileSelectorItem*>(item); 405 return static_cast<OFileSelectorItem*>(item);
406} 406}
407 407
408void OFileViewFileListView::reread( bool all ) 408void OFileViewFileListView::reread( bool all )
409{ 409{
410 m_view->clear(); 410 m_view->clear();
411 411
412 if (selector()->showClose() ) 412 if (selector()->showClose() )
413 m_btnClose->show(); 413 m_btnClose->show();
414 else 414 else
415 m_btnClose->hide(); 415 m_btnClose->hide();
416 416
417 if (selector()->showNew() ) 417 if (selector()->showNew() )
418 m_btnNew->show(); 418 m_btnNew->show();
419 else 419 else
420 m_btnNew->hide(); 420 m_btnNew->hide();
421 421
422 m_mimes = selector()->currentMimeType(); 422 m_mimes = selector()->currentMimeType();
423 m_all = all; 423 m_all = all;
424 424
425 QDir dir( m_currentDir ); 425 QDir dir( m_currentDir );
426 if (!dir.exists() ) 426 if (!dir.exists() )
427 return; 427 return;
428 428
429 dir.setSorting( QDir::Name | QDir::DirsFirst | QDir::Reversed ); 429 dir.setSorting( QDir::Name | QDir::DirsFirst | QDir::Reversed );
430 int filter; 430 int filter;
431 if (m_all ) 431 filter = QDir::Dirs;
432 filter = QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All; 432 if ( selector()->mode() != OFileSelector::DIRECTORYSELECTOR )
433 else 433 filter = filter | QDir::Files | QDir::All;
434 filter = QDir::Files | QDir::Dirs | QDir::All; 434
435 if ( m_all )
436 filter = filter | QDir::Hidden;
437
435 dir.setFilter( filter ); 438 dir.setFilter( filter );
436 439
437 // now go through all files 440 // now go through all files
438 const QFileInfoList *list = dir.entryInfoList(); 441 const QFileInfoList *list = dir.entryInfoList();
439 if (!list) 442 if (!list)
440 { 443 {
441 cdUP(); 444 cdUP();
442 return; 445 return;
443 } 446 }
444 447
445 QFileInfoListIterator it( *list ); 448 QFileInfoListIterator it( *list );
446 QFileInfo *fi; 449 QFileInfo *fi;
447 while( (fi=it.current() ) ) 450 while( (fi=it.current() ) )
448 { 451 {
449 if( fi->fileName() == QString::fromLatin1("..") || fi->fileName() == QString::fromLatin1(".") ) 452 if( fi->fileName() == QString::fromLatin1("..") || fi->fileName() == QString::fromLatin1(".") )
450 { 453 {
451 ++it; 454 ++it;
452 continue; 455 continue;
453 } 456 }
454 457
455 /* 458 /*
456 * It is a symlink we try to resolve it now but don't let us attack by DOS 459 * It is a symlink we try to resolve it now but don't let us attack by DOS
457 * 460 *
458 */ 461 */
459 if( fi->isSymLink() ) 462 if( fi->isSymLink() )
460 { 463 {
461 QString file = fi->dirPath( true ) + "/" + fi->readLink(); 464 QString file = fi->dirPath( true ) + "/" + fi->readLink();
462 for( int i = 0; i<=4; i++) 465 for( int i = 0; i<=4; i++)
463 { // 5 tries to prevent dos 466 { // 5 tries to prevent dos
464 QFileInfo info( file ); 467 QFileInfo info( file );
465 if( !info.exists() ) 468 if( !info.exists() )
466 { 469 {
467 addSymlink( fi, TRUE ); 470 addSymlink( fi, TRUE );
468 break; 471 break;
469 } 472 }
470 else if( info.isDir() ) 473 else if( info.isDir() )
471 { 474 {
472 addDir( fi, TRUE ); 475 addDir( fi, TRUE );
473 break; 476 break;
474 } 477 }
475 else if( info.isFile() ) 478 else if( info.isFile() )
476 { 479 {
477 addFile( fi, TRUE ); 480 addFile( fi, TRUE );
478 break; 481 break;
479 } 482 }
480 else if( info.isSymLink() ) 483 else if( info.isSymLink() )
481 { 484 {
482 file = info.dirPath(true ) + "/" + info.readLink() ; 485 file = info.dirPath(true ) + "/" + info.readLink() ;
@@ -769,166 +772,181 @@ QString OFileViewFileSystem::selectedName()const
769 QString cFN=currentFileName(); 772 QString cFN=currentFileName();
770 if (cFN.startsWith("/")) return cFN; 773 if (cFN.startsWith("/")) return cFN;
771 return m_view->currentDir() + "/" + cFN; 774 return m_view->currentDir() + "/" + cFN;
772} 775}
773 776
774QString OFileViewFileSystem::selectedPath()const 777QString OFileViewFileSystem::selectedPath()const
775{ 778{
776 return QString::null; 779 return QString::null;
777} 780}
778 781
779QString OFileViewFileSystem::directory()const 782QString OFileViewFileSystem::directory()const
780{ 783{
781 if (!m_view) 784 if (!m_view)
782 return QString::null; 785 return QString::null;
783 786
784 OFileSelectorItem* item = m_view->currentItem(); 787 OFileSelectorItem* item = m_view->currentItem();
785 if (!item ) 788 if (!item )
786 return QString::null; 789 return QString::null;
787 790
788 return QDir(item->directory() ).absPath(); 791 return QDir(item->directory() ).absPath();
789} 792}
790 793
791void OFileViewFileSystem::reread() 794void OFileViewFileSystem::reread()
792{ 795{
793 if (!m_view) 796 if (!m_view)
794 return; 797 return;
795 798
796 m_view->reread( m_all ); 799 m_view->reread( m_all );
797} 800}
798 801
799int OFileViewFileSystem::fileCount()const 802int OFileViewFileSystem::fileCount()const
800{ 803{
801 if (!m_view ) 804 if (!m_view )
802 return -1; 805 return -1;
803 return m_view->fileCount(); 806 return m_view->fileCount();
804} 807}
805 808
806QWidget* OFileViewFileSystem::widget( QWidget* parent ) 809QWidget* OFileViewFileSystem::widget( QWidget* parent )
807{ 810{
808 if (!m_view ) 811 if (!m_view )
809 { 812 {
810 m_view = new OFileViewFileListView( parent, startDirectory(), selector() ); 813 m_view = new OFileViewFileListView( parent, startDirectory(), selector() );
811 } 814 }
812 return m_view; 815 return m_view;
813} 816}
814 817
815void OFileViewFileSystem::activate( const QString& str) 818void OFileViewFileSystem::activate( const QString& str)
816{ 819{
817 m_all = (str != QObject::tr("Files") ); 820 m_all = ( str.find( "All" ) != -1 );
818} 821}
819 822
820 823
821} 824}
822/* Selector */ 825/* Selector */
823/** 826/**
824 * @short new and complete c'tor 827 * @short new and complete c'tor
825 * 828 *
826 * Create a OFileSelector to let the user select a file. It can 829 * Create a OFileSelector to let the user select a file. It can
827 * either be used to open a file, select a save name in a dir or 830 * either be used to open a file, select a save name in a dir or
828 * as a dropin for the FileSelector. 831 * as a dropin for the FileSelector.
829 * 832 *
830 * <pre> 833 * <pre>
831 * QMap<QString, QStringList> mimeTypes; 834 * QMap<QString, QStringList> mimeTypes;
832 * QStringList types; 835 * QStringList types;
833 * types << "text@slash* "; 836 * types << "text@slash* ";
834 * types << "audio@slash*"; 837 * types << "audio@slash*";
835 * mimeTypes.insert( tr("Audio and Text"), types ); 838 * mimeTypes.insert( tr("Audio and Text"), types );
836 * mimeTypes.insert( tr("All"), "*@slash*); 839 * mimeTypes.insert( tr("All"), "*@slash*);
837 * 840 *
838 * now you could create your fileselector 841 * now you could create your fileselector
839 * </pre> 842 * </pre>
840 * 843 *
841 * 844 *
842 * @param parent the parent of this widget 845 * @param parent the parent of this widget
843 * @param mode The mode from the enum Mode (Open,Save,FILESELECTOR) 846 * @param mode The mode from the enum Mode (Open,Save,FILESELECTOR)
844 * @param sel The selector to be used 847 * @param sel The selector to be used
845 * @param dirName The name of the dir to start int 848 * @param dirName The name of the dir to start int
846 * @param fileName The fileName placed in the fileselector lineedit 849 * @param fileName The fileName placed in the fileselector lineedit
847 * @param mimetypes The MimeType map of used mimetypes 850 * @param mimetypes The MimeType map of used mimetypes
848 * @param showNew Show a New Button. Most likely to be used in the FileSelector view. 851 * @param showNew Show a New Button. Most likely to be used in the FileSelector view.
849 * @param showClose Show a Close Button. Most likely to be used in FileSelector view. 852 * @param showClose Show a Close Button. Most likely to be used in FileSelector view.
850 * 853 *
851 */ 854 */
852OFileSelector::OFileSelector( QWidget* parent, int mode, int sel, 855OFileSelector::OFileSelector( QWidget* parent, int mode, int sel,
853 const QString& dirName, const QString& fileName, 856 const QString& dirName, const QString& fileName,
854 const MimeTypes& mimetypes, 857 const MimeTypes& mimetypes,
855 bool showNew, bool showClose) 858 bool showNew, bool showClose)
856 :QWidget( parent, "OFileSelector" ) 859 :QWidget( parent, "OFileSelector" )
857{ 860{
858 m_current = 0; 861 m_current = 0;
859 m_shNew = showNew; 862 m_shNew = showNew;
860 m_shClose = showClose; 863 m_shClose = showClose;
861 m_mimeType = mimetypes; 864 m_mimeType = mimetypes;
862 m_startDir = dirName; 865 m_startDir = dirName;
863 866
864 m_mode = mode; 867 m_mode = mode;
865 m_selector = sel; 868 m_selector = sel;
866 869
867 initUI(); 870 initUI();
868 m_lneEdit->setText( fileName ); 871 m_lneEdit->setText( fileName );
869 initMime(); 872 initMime();
870 initViews(); 873 initViews();
871 874
872 QString str; 875 QString str;
873 switch ( m_selector ) 876 switch ( m_selector )
874 { 877 {
875 default: 878 default:
876 case Normal: 879 case Normal:
877 str = QObject::tr("Documents"); 880 if ( m_mode == DIRECTORYSELECTOR )
881 str = QObject::tr("Directories");
882 else
883 str = QObject::tr("Documents");
878 m_cmbView->setCurrentItem( 0 ); 884 m_cmbView->setCurrentItem( 0 );
879 break; 885 break;
880 case Extended: 886 case Extended:
881 str = QObject::tr("Files"); 887 if ( m_mode == DIRECTORYSELECTOR )
882 m_cmbView->setCurrentItem( 1 ); 888 {
889 str = QObject::tr("Directories");
890 m_cmbView->setCurrentItem( 0 );
891 } else {
892 str = QObject::tr("Files");
893 m_cmbView->setCurrentItem( 1 );
894 }
883 break; 895 break;
884 case ExtendedAll: 896 case ExtendedAll:
885 str = QObject::tr("All Files"); 897 if ( m_mode == DIRECTORYSELECTOR )
886 m_cmbView->setCurrentItem( 2 ); 898 {
899 str = QObject::tr("All Directories");
900 m_cmbView->setCurrentItem( 1 );
901 } else {
902 str = QObject::tr("All Files");
903 m_cmbView->setCurrentItem( 2 );
904 }
887 break; 905 break;
888 } 906 }
889 slotViewChange( str ); 907 slotViewChange( str );
890 908
891} 909}
892 910
893 911
894/** 912/**
895 * This a convience c'tor to just substitute the use of FileSelector 913 * This a convience c'tor to just substitute the use of FileSelector
896 */ 914 */
897OFileSelector::OFileSelector( const QString& mimeFilter, QWidget* parent, const char* name, 915OFileSelector::OFileSelector( const QString& mimeFilter, QWidget* parent, const char* name,
898 bool showNew, bool showClose ) 916 bool showNew, bool showClose )
899 : QWidget( parent, name ) 917 : QWidget( parent, name )
900{ 918{
901 m_current = 0; 919 m_current = 0;
902 m_shNew = showNew; 920 m_shNew = showNew;
903 m_shClose = showClose; 921 m_shClose = showClose;
904 m_startDir = QPEApplication::documentDir(); 922 m_startDir = QPEApplication::documentDir();
905 923
906 if (!mimeFilter.isEmpty() ) 924 if (!mimeFilter.isEmpty() )
907 m_mimeType.insert(mimeFilter, QStringList::split(";", mimeFilter ) ); 925 m_mimeType.insert(mimeFilter, QStringList::split(";", mimeFilter ) );
908 926
909 m_mode = OFileSelector::FileSelector; 927 m_mode = OFileSelector::FileSelector;
910 m_selector = OFileSelector::Normal; 928 m_selector = OFileSelector::Normal;
911 929
912 initUI(); 930 initUI();
913 initMime(); 931 initMime();
914 initViews(); 932 initViews();
915 m_cmbView->setCurrentItem( 0 ); 933 m_cmbView->setCurrentItem( 0 );
916 slotViewChange( QObject::tr("Documents") ); 934 slotViewChange( QObject::tr("Documents") );
917} 935}
918 936
919/* 937/*
920 * INIT UI will set up the basic GUI 938 * INIT UI will set up the basic GUI
921 * Layout: Simple VBoxLayout 939 * Layout: Simple VBoxLayout
922 * On top a WidgetStack containing the Views... 940 * On top a WidgetStack containing the Views...
923 * - List View 941 * - List View
924 * - Document View 942 * - Document View
925 * Below we will have a Label + LineEdit 943 * Below we will have a Label + LineEdit
926 * Below we will have two ComoBoxes one for choosing the view one for 944 * Below we will have two ComoBoxes one for choosing the view one for
927 * choosing the mimetype 945 * choosing the mimetype
928 */ 946 */
929void OFileSelector::initUI() 947void OFileSelector::initUI()
930{ 948{
931 QVBoxLayout* lay = new QVBoxLayout( this ); 949 QVBoxLayout* lay = new QVBoxLayout( this );
932 950
933 m_stack = new QWidgetStack( this ); 951 m_stack = new QWidgetStack( this );
934 lay->addWidget( m_stack, 1000 ); 952 lay->addWidget( m_stack, 1000 );
@@ -940,109 +958,121 @@ void OFileSelector::initUI()
940 lay->addWidget( m_nameBox ); 958 lay->addWidget( m_nameBox );
941 959
942 m_cmbBox = new QHBox( this ); 960 m_cmbBox = new QHBox( this );
943 m_cmbView = new QComboBox( m_cmbBox ); 961 m_cmbView = new QComboBox( m_cmbBox );
944 m_cmbMime = new QComboBox( m_cmbBox ); 962 m_cmbMime = new QComboBox( m_cmbBox );
945 lay->addWidget( m_cmbBox ); 963 lay->addWidget( m_cmbBox );
946} 964}
947 965
948/* 966/*
949 * This will make sure that the return key in the name edit causes dialogs to close 967 * This will make sure that the return key in the name edit causes dialogs to close
950 */ 968 */
951 969
952bool OFileSelector::eventFilter (QObject *, QEvent *e) 970bool OFileSelector::eventFilter (QObject *, QEvent *e)
953{ 971{
954 if ( e->type() == QEvent::KeyPress ) 972 if ( e->type() == QEvent::KeyPress )
955 { 973 {
956 QKeyEvent *k = (QKeyEvent *)e; 974 QKeyEvent *k = (QKeyEvent *)e;
957 if ( (k->key()==Key_Enter) || (k->key()==Key_Return)) 975 if ( (k->key()==Key_Enter) || (k->key()==Key_Return))
958 { 976 {
959 emit ok(); 977 emit ok();
960 return true; 978 return true;
961 } 979 }
962 } 980 }
963 return false; 981 return false;
964} 982}
965 983
966/* 984/*
967 * This will insert the MimeTypes into the Combo Box 985 * This will insert the MimeTypes into the Combo Box
968 * And also connect the changed signal 986 * And also connect the changed signal
969 * 987 *
970 * AutoMimeTyping is disabled for now. It used to reparse a dir and then set available mimetypes 988 * AutoMimeTyping is disabled for now. It used to reparse a dir and then set available mimetypes
971 */ 989 */
972void OFileSelector::initMime() 990void OFileSelector::initMime()
973{ 991{
974 MimeTypes::Iterator it; 992 MimeTypes::Iterator it;
975 for ( it = m_mimeType.begin(); it != m_mimeType.end(); ++it ) 993 for ( it = m_mimeType.begin(); it != m_mimeType.end(); ++it )
976 { 994 {
977 m_cmbMime->insertItem( it.key() ); 995 m_cmbMime->insertItem( it.key() );
978 } 996 }
979 m_cmbMime->setCurrentItem( 0 ); 997 m_cmbMime->setCurrentItem( 0 );
980 998
981 connect( m_cmbMime, SIGNAL(activated(int) ), 999 connect( m_cmbMime, SIGNAL(activated(int) ),
982 this, SLOT(slotMimeTypeChanged() ) ); 1000 this, SLOT(slotMimeTypeChanged() ) );
983 1001
984} 1002}
985 1003
986void OFileSelector::initViews() 1004void OFileSelector::initViews()
987{ 1005{
988 m_cmbView->insertItem( QObject::tr("Documents") ); 1006 if ( m_mode == OFileSelector::DIRECTORYSELECTOR )
989 m_cmbView->insertItem( QObject::tr("Files") ); 1007 {
990 m_cmbView->insertItem( QObject::tr("All Files") ); 1008 m_cmbView->insertItem( QObject::tr("Directories") );
1009 m_cmbView->insertItem( QObject::tr("All Directories") );
1010 } else {
1011 m_cmbView->insertItem( QObject::tr("Documents") );
1012 m_cmbView->insertItem( QObject::tr("Files") );
1013 m_cmbView->insertItem( QObject::tr("All Files") );
1014 }
1015
991 connect(m_cmbView, SIGNAL(activated(const QString&) ), 1016 connect(m_cmbView, SIGNAL(activated(const QString&) ),
992 this, SLOT(slotViewChange(const QString&) ) ); 1017 this, SLOT(slotViewChange(const QString&) ) );
993 1018
994
995 m_views.insert( QObject::tr("Documents"), new ODocumentFileView(this) );
996
997 /* see above why add both */ 1019 /* see above why add both */
998 OFileViewInterface* in = new OFileViewFileSystem( this ); 1020 OFileViewInterface* in = new OFileViewFileSystem( this );
999 m_views.insert( QObject::tr("Files"), in ); 1021
1000 m_views.insert( QObject::tr("All Files"), in ); 1022 if ( m_mode == OFileSelector::DIRECTORYSELECTOR )
1023 {
1024 m_views.insert( QObject::tr("Directories"), in );
1025 m_views.insert( QObject::tr("All Directories"), in );
1026 } else {
1027 m_views.insert( QObject::tr("Documents"), new ODocumentFileView(this) );
1028 m_views.insert( QObject::tr("Files"), in );
1029 m_views.insert( QObject::tr("All Files"), in );
1030 }
1001} 1031}
1002 1032
1003void OFileSelector::registerView( const Internal::OFileViewInterface* iface ) { 1033void OFileSelector::registerView( const Internal::OFileViewInterface* iface ) {
1004 m_viewsPtr.append( iface ); 1034 m_viewsPtr.append( iface );
1005} 1035}
1006 1036
1007 1037
1008/** 1038/**
1009 * d'tor 1039 * d'tor
1010 */ 1040 */
1011OFileSelector::~OFileSelector() 1041OFileSelector::~OFileSelector()
1012{ 1042{
1013 m_viewsPtr.setAutoDelete( true ); 1043 m_viewsPtr.setAutoDelete( true );
1014 m_viewsPtr.clear(); 1044 m_viewsPtr.clear();
1015} 1045}
1016 1046
1017 1047
1018 1048
1019/** 1049/**
1020 * Convience function for the fileselector 1050 * Convience function for the fileselector
1021 * make sure to delete the DocLnk 1051 * make sure to delete the DocLnk
1022 * 1052 *
1023 * @see DocLnk 1053 * @see DocLnk
1024 * @todo remove in ODP 1054 * @todo remove in ODP
1025 */ 1055 */
1026const DocLnk* OFileSelector::selected() 1056const DocLnk* OFileSelector::selected()
1027{ 1057{
1028 DocLnk* lnk = new DocLnk( currentView()->selectedDocument() ); 1058 DocLnk* lnk = new DocLnk( currentView()->selectedDocument() );
1029 return lnk; 1059 return lnk;
1030} 1060}
1031 1061
1032/** 1062/**
1033 * 1063 *
1034 * @return the name of the selected file 1064 * @return the name of the selected file
1035 */ 1065 */
1036QString OFileSelector::selectedName()const 1066QString OFileSelector::selectedName()const
1037{ 1067{
1038 return currentView()->selectedName(); 1068 return currentView()->selectedName();
1039} 1069}
1040 1070
1041 1071
1042/** 1072/**
1043 * @return the selected path 1073 * @return the selected path
1044 */ 1074 */
1045QString OFileSelector::selectedPath()const 1075QString OFileSelector::selectedPath()const
1046{ 1076{
1047 return currentView()->selectedPath(); 1077 return currentView()->selectedPath();
1048} 1078}
diff --git a/libopie2/opieui/fileselector/ofileselector.h b/libopie2/opieui/fileselector/ofileselector.h
index de2b98a..b1cd405 100644
--- a/libopie2/opieui/fileselector/ofileselector.h
+++ b/libopie2/opieui/fileselector/ofileselector.h
@@ -40,98 +40,99 @@
40 40
41/* QT */ 41/* QT */
42#include <qlist.h> 42#include <qlist.h>
43#include <qwidget.h> 43#include <qwidget.h>
44#include <qmap.h> 44#include <qmap.h>
45#include <qvaluelist.h> 45#include <qvaluelist.h>
46#include <qstringlist.h> 46#include <qstringlist.h>
47#include <qlist.h> 47#include <qlist.h>
48 48
49class QLineEdit; 49class QLineEdit;
50class QComboBox; 50class QComboBox;
51class QWidgetStack; 51class QWidgetStack;
52class QHBox; 52class QHBox;
53 53
54typedef QMap<QString, QStringList> MimeTypes; 54typedef QMap<QString, QStringList> MimeTypes;
55 55
56namespace Opie { 56namespace Opie {
57namespace Ui { 57namespace Ui {
58 58
59namespace Internal { 59namespace Internal {
60class OFileViewInterface; 60class OFileViewInterface;
61class OFileViewFileListView; 61class OFileViewFileListView;
62} 62}
63 63
64 64
65/** 65/**
66 * @short a dropin replacement for the FileSelector 66 * @short a dropin replacement for the FileSelector
67 * 67 *
68 * This class is first used insert the OFileDialog. 68 * This class is first used insert the OFileDialog.
69 * It supports multiple view and mimetype filtering for now. 69 * It supports multiple view and mimetype filtering for now.
70 * 70 *
71 * @see OFileDialog 71 * @see OFileDialog
72 * @see FileSelector 72 * @see FileSelector
73 * @author zecke 73 * @author zecke
74 * @version 0.1 74 * @version 0.1
75 */ 75 */
76class OFileSelector : public QWidget 76class OFileSelector : public QWidget
77{ 77{
78 Q_OBJECT 78 Q_OBJECT
79 friend class Internal::OFileViewInterface; 79 friend class Internal::OFileViewInterface;
80 friend class Internal::OFileViewFileListView; 80 friend class Internal::OFileViewFileListView;
81 81
82public: 82public:
83 /** 83 /**
84 * The Mode of the Fileselector 84 * The Mode of the Fileselector
85 * Open = Open A File 85 * Open = Open A File
86 * Save = Save a File 86 * Save = Save a File
87 * FILESELECTOR = As A GUI in a screen to select a file 87 * FILESELECTOR = As A GUI in a screen to select a file
88 * SelectDir = Select a Directory
88 */ 89 */
89 enum Mode { Open=1, Save=2, FileSelector=4, OPEN=1, SAVE=2, FILESELECTOR=4 }; 90 enum Mode { Open = 1, Save = 2, DirectorySelector = 3, FileSelector = 4, OPEN = 1, SAVE = 2, DIRECTORYSELECTOR = 3, FILESELECTOR = 4 };
90 // enum OldMode { OPEN=1, SAVE=2, FILESELECTOR = 4 }; 91 // enum OldMode { OPEN=1, SAVE=2, FILESELECTOR = 4 };
91 /** 92 /**
92 * Normal = The old FileSelector 93 * Normal = The old FileSelector
93 * Extended = Dir View 94 * Extended = Dir View
94 * ExtendedAll = Dir View with all hidden files 95 * ExtendedAll = Dir View with all hidden files
95 * Default = What the vendor considers best 96 * Default = What the vendor considers best
96 */ 97 */
97 enum Selector { Normal = 0, Extended=1, ExtendedAll =2, Default=3, NORMAL=0,EXTENDED=1, EXTENDED_ALL =2, DEFAULT=3 }; 98 enum Selector { Normal = 0, Extended=1, ExtendedAll =2, Default=3, NORMAL=0,EXTENDED=1, EXTENDED_ALL =2, DEFAULT=3 };
98 // enum OldSelector { NORMAL = 0, EXTENDED =1, EXTENDED_ALL = 2}; 99 // enum OldSelector { NORMAL = 0, EXTENDED =1, EXTENDED_ALL = 2};
99 100
100 OFileSelector(QWidget* parent, int mode, int selector, 101 OFileSelector(QWidget* parent, int mode, int selector,
101 const QString& dirName, 102 const QString& dirName,
102 const QString& fileName, 103 const QString& fileName,
103 const MimeTypes& mimetypes = MimeTypes(), 104 const MimeTypes& mimetypes = MimeTypes(),
104 bool newVisible = FALSE, bool closeVisible = FALSE ); 105 bool newVisible = FALSE, bool closeVisible = FALSE );
105 106
106 OFileSelector(const QString& mimeFilter, QWidget* parent, 107 OFileSelector(const QString& mimeFilter, QWidget* parent,
107 const char* name = 0, bool newVisible = TRUE, bool closeVisible = FALSE ); 108 const char* name = 0, bool newVisible = TRUE, bool closeVisible = FALSE );
108 ~OFileSelector(); 109 ~OFileSelector();
109 110
110 const DocLnk* selected(); 111 const DocLnk* selected();
111 112
112 QString selectedName()const; 113 QString selectedName()const;
113 QString selectedPath()const; 114 QString selectedPath()const;
114 QString directory()const; 115 QString directory()const;
115 116
116 DocLnk selectedDocument()const; 117 DocLnk selectedDocument()const;
117 118
118 int fileCount()const; 119 int fileCount()const;
119 void reread(); 120 void reread();
120 121
121 int mode()const; 122 int mode()const;
122 int selector()const; 123 int selector()const;
123 124
124 /** 125 /**
125 * Set the Icon visible 126 * Set the Icon visible
126 * @param b Show or Hide the New Button 127 * @param b Show or Hide the New Button
127 */ 128 */
128 void setNewVisible( bool b ); 129 void setNewVisible( bool b );
129 130
130 /** 131 /**
131 * Set the Icon visible 132 * Set the Icon visible
132 */ 133 */
133 void setCloseVisible( bool b ); 134 void setCloseVisible( bool b );
134 135
135 /** 136 /**
136 * Set the Name Line visible 137 * Set the Name Line visible
137 */ 138 */