author | ar <ar> | 2004-08-14 19:17:39 (UTC) |
---|---|---|
committer | ar <ar> | 2004-08-14 19:17:39 (UTC) |
commit | b7e50e77e0b22b3dd0feee43b15d0152d9ca8abb (patch) (unidiff) | |
tree | 8b1812fe843ecde7b7b12f8697ca4cf8f7444c0b | |
parent | 74363a9e1d5688d65286e7fea156227b68a28002 (diff) | |
download | opie-b7e50e77e0b22b3dd0feee43b15d0152d9ca8abb.zip opie-b7e50e77e0b22b3dd0feee43b15d0152d9ca8abb.tar.gz opie-b7e50e77e0b22b3dd0feee43b15d0152d9ca8abb.tar.bz2 |
- add OFileDialog::getDirectory()
this function open a file dialog to select a directory.
it can show Directories and All Directories.
the first one is without and the second is with hidden directories.
-rw-r--r-- | libopie2/opieui/fileselector/ofiledialog.cpp | 33 | ||||
-rw-r--r-- | libopie2/opieui/fileselector/ofiledialog.h | 5 | ||||
-rw-r--r-- | libopie2/opieui/fileselector/ofileselector.cpp | 44 | ||||
-rw-r--r-- | libopie2/opieui/fileselector/ofileselector.h | 3 |
4 files changed, 77 insertions, 8 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 | |||
@@ -72,3 +72,6 @@ void saveLastDir( const QString& key, const QString& file ) | |||
72 | QFileInfo inf( file ); | 72 | QFileInfo inf( file ); |
73 | if ( inf.isFile() ) | ||
73 | cfg.writeEntry("LastDir", inf.dirPath( true ) ); | 74 | cfg.writeEntry("LastDir", inf.dirPath( true ) ); |
75 | else | ||
76 | cfg.writeEntry("LastDir", file ); | ||
74 | } | 77 | } |
@@ -206,2 +209,32 @@ QString OFileDialog::getSaveFileName(int selector, | |||
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 | */ | ||
219 | QString 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 | |||
207 | void OFileDialog::slotFileSelected(const QString & ) | 240 | void OFileDialog::slotFileSelected(const QString & ) |
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 | |||
@@ -91,2 +91,7 @@ public: | |||
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 |
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 | |||
@@ -430,6 +430,9 @@ void OFileViewFileListView::reread( bool all ) | |||
430 | int filter; | 430 | int filter; |
431 | filter = QDir::Dirs; | ||
432 | if ( selector()->mode() != OFileSelector::DIRECTORYSELECTOR ) | ||
433 | filter = filter | QDir::Files | QDir::All; | ||
434 | |||
431 | if (m_all ) | 435 | if (m_all ) |
432 | filter = QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All; | 436 | filter = filter | QDir::Hidden; |
433 | else | 437 | |
434 | filter = QDir::Files | QDir::Dirs | QDir::All; | ||
435 | dir.setFilter( filter ); | 438 | dir.setFilter( filter ); |
@@ -816,3 +819,3 @@ void OFileViewFileSystem::activate( const QString& str) | |||
816 | { | 819 | { |
817 | m_all = (str != QObject::tr("Files") ); | 820 | m_all = ( str.find( "All" ) != -1 ); |
818 | } | 821 | } |
@@ -876,2 +879,5 @@ OFileSelector::OFileSelector( QWidget* parent, int mode, int sel, | |||
876 | case Normal: | 879 | case Normal: |
880 | if ( m_mode == DIRECTORYSELECTOR ) | ||
881 | str = QObject::tr("Directories"); | ||
882 | else | ||
877 | str = QObject::tr("Documents"); | 883 | str = QObject::tr("Documents"); |
@@ -880,8 +886,20 @@ OFileSelector::OFileSelector( QWidget* parent, int mode, int sel, | |||
880 | case Extended: | 886 | case Extended: |
887 | if ( m_mode == DIRECTORYSELECTOR ) | ||
888 | { | ||
889 | str = QObject::tr("Directories"); | ||
890 | m_cmbView->setCurrentItem( 0 ); | ||
891 | } else { | ||
881 | str = QObject::tr("Files"); | 892 | str = QObject::tr("Files"); |
882 | m_cmbView->setCurrentItem( 1 ); | 893 | m_cmbView->setCurrentItem( 1 ); |
894 | } | ||
883 | break; | 895 | break; |
884 | case ExtendedAll: | 896 | case ExtendedAll: |
897 | if ( m_mode == DIRECTORYSELECTOR ) | ||
898 | { | ||
899 | str = QObject::tr("All Directories"); | ||
900 | m_cmbView->setCurrentItem( 1 ); | ||
901 | } else { | ||
885 | str = QObject::tr("All Files"); | 902 | str = QObject::tr("All Files"); |
886 | m_cmbView->setCurrentItem( 2 ); | 903 | m_cmbView->setCurrentItem( 2 ); |
904 | } | ||
887 | break; | 905 | break; |
@@ -987,2 +1005,7 @@ void OFileSelector::initViews() | |||
987 | { | 1005 | { |
1006 | if ( m_mode == OFileSelector::DIRECTORYSELECTOR ) | ||
1007 | { | ||
1008 | m_cmbView->insertItem( QObject::tr("Directories") ); | ||
1009 | m_cmbView->insertItem( QObject::tr("All Directories") ); | ||
1010 | } else { | ||
988 | m_cmbView->insertItem( QObject::tr("Documents") ); | 1011 | m_cmbView->insertItem( QObject::tr("Documents") ); |
@@ -990,2 +1013,4 @@ void OFileSelector::initViews() | |||
990 | m_cmbView->insertItem( QObject::tr("All 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&) ), |
@@ -993,7 +1018,11 @@ void OFileSelector::initViews() | |||
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 ); |
1021 | |||
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) ); | ||
999 | m_views.insert( QObject::tr("Files"), in ); | 1028 | m_views.insert( QObject::tr("Files"), in ); |
@@ -1001,2 +1030,3 @@ void OFileSelector::initViews() | |||
1001 | } | 1030 | } |
1031 | } | ||
1002 | 1032 | ||
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 | |||
@@ -87,4 +87,5 @@ public: | |||
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 }; |