summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--libopie2/opieui/fileselector/ofiledialog.cpp33
-rw-r--r--libopie2/opieui/fileselector/ofiledialog.h5
-rw-r--r--libopie2/opieui/fileselector/ofileselector.cpp44
-rw-r--r--libopie2/opieui/fileselector/ofileselector.h3
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 )
QFileInfo inf( file );
+ if ( inf.isFile() )
cfg.writeEntry("LastDir", inf.dirPath( true ) );
+ else
+ cfg.writeEntry("LastDir", file );
}
@@ -206,2 +209,32 @@ QString OFileDialog::getSaveFileName(int selector,
+/**
+ * This opens up a filedialog in select directory mode
+ *
+ * @param selector the Selector Mode
+ * @param startDir Where to start from
+ * @param wid the parent
+ * @param caption of the dialog if QString::null tr("Open") will be used
+ * @return the directoryName or QString::null
+ */
+QString OFileDialog::getDirectory(int selector,
+ const QString &_startDir,
+ QWidget *wid,
+ const QString &caption )
+{
+ QString ret;
+ QString startDir = _startDir;
+ if ( startDir.isEmpty() )
+ startDir = lastUsedDir( "FileDialog-SELECTDIR" );
+
+ OFileDialog dlg( caption.isEmpty() ? tr( "Select Directory" ) : caption,
+ wid, OFileSelector::DirectorySelector, selector, startDir );
+ dlg.showMaximized();
+ if ( dlg.exec() )
+ {
+ ret = dlg.fileName();
+ saveLastDir( "FileDialog-SELECTDIR", ret );
+ }
+ return ret;
+}
+
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:
+ static QString getDirectory(int selector,
+ const QString &startDir = QString::null,
+ QWidget *wid = 0,
+ const QString &caption = QString::null );
+
//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 )
int filter;
+ filter = QDir::Dirs;
+ if ( selector()->mode() != OFileSelector::DIRECTORYSELECTOR )
+ filter = filter | QDir::Files | QDir::All;
+
if (m_all )
- filter = QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All;
- else
- filter = QDir::Files | QDir::Dirs | QDir::All;
+ filter = filter | QDir::Hidden;
+
dir.setFilter( filter );
@@ -816,3 +819,3 @@ void OFileViewFileSystem::activate( const QString& str)
{
- m_all = (str != QObject::tr("Files") );
+ m_all = ( str.find( "All" ) != -1 );
}
@@ -876,2 +879,5 @@ OFileSelector::OFileSelector( QWidget* parent, int mode, int sel,
case Normal:
+ if ( m_mode == DIRECTORYSELECTOR )
+ str = QObject::tr("Directories");
+ else
str = QObject::tr("Documents");
@@ -880,8 +886,20 @@ OFileSelector::OFileSelector( QWidget* parent, int mode, int sel,
case Extended:
+ if ( m_mode == DIRECTORYSELECTOR )
+ {
+ str = QObject::tr("Directories");
+ m_cmbView->setCurrentItem( 0 );
+ } else {
str = QObject::tr("Files");
m_cmbView->setCurrentItem( 1 );
+ }
break;
case ExtendedAll:
+ if ( m_mode == DIRECTORYSELECTOR )
+ {
+ str = QObject::tr("All Directories");
+ m_cmbView->setCurrentItem( 1 );
+ } else {
str = QObject::tr("All Files");
m_cmbView->setCurrentItem( 2 );
+ }
break;
@@ -987,2 +1005,7 @@ void OFileSelector::initViews()
{
+ if ( m_mode == OFileSelector::DIRECTORYSELECTOR )
+ {
+ m_cmbView->insertItem( QObject::tr("Directories") );
+ m_cmbView->insertItem( QObject::tr("All Directories") );
+ } else {
m_cmbView->insertItem( QObject::tr("Documents") );
@@ -990,2 +1013,4 @@ void OFileSelector::initViews()
m_cmbView->insertItem( QObject::tr("All Files") );
+ }
+
connect(m_cmbView, SIGNAL(activated(const QString&) ),
@@ -993,7 +1018,11 @@ void OFileSelector::initViews()
-
- m_views.insert( QObject::tr("Documents"), new ODocumentFileView(this) );
-
/* see above why add both */
OFileViewInterface* in = new OFileViewFileSystem( this );
+
+ if ( m_mode == OFileSelector::DIRECTORYSELECTOR )
+ {
+ m_views.insert( QObject::tr("Directories"), in );
+ m_views.insert( QObject::tr("All Directories"), in );
+ } else {
+ m_views.insert( QObject::tr("Documents"), new ODocumentFileView(this) );
m_views.insert( QObject::tr("Files"), in );
@@ -1001,2 +1030,3 @@ void OFileSelector::initViews()
}
+}
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:
* FILESELECTOR = As A GUI in a screen to select a file
+ * SelectDir = Select a Directory
*/
- enum Mode { Open=1, Save=2, FileSelector=4, OPEN=1, SAVE=2, FILESELECTOR=4 };
+ enum Mode { Open = 1, Save = 2, DirectorySelector = 3, FileSelector = 4, OPEN = 1, SAVE = 2, DIRECTORYSELECTOR = 3, FILESELECTOR = 4 };
// enum OldMode { OPEN=1, SAVE=2, FILESELECTOR = 4 };