summaryrefslogtreecommitdiff
authorar <ar>2004-08-14 19:17:39 (UTC)
committer ar <ar>2004-08-14 19:17:39 (UTC)
commitb7e50e77e0b22b3dd0feee43b15d0152d9ca8abb (patch) (side-by-side diff)
tree8b1812fe843ecde7b7b12f8697ca4cf8f7444c0b
parent74363a9e1d5688d65286e7fea156227b68a28002 (diff)
downloadopie-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.
Diffstat (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
@@ -67,13 +67,16 @@ void saveLastDir( const QString& key, const QString& file )
if ( qApp->argc() < 1 )
return;
Config cfg( QFileInfo(qApp->argv()[0]).fileName() );
cfg.setGroup( key );
QFileInfo inf( file );
- cfg.writeEntry("LastDir", inf.dirPath( true ) );
+ if ( inf.isFile() )
+ cfg.writeEntry("LastDir", inf.dirPath( true ) );
+ else
+ cfg.writeEntry("LastDir", file );
}
};
/**
* This constructs a modal dialog
*
@@ -201,12 +204,42 @@ QString OFileDialog::getSaveFileName(int selector,
saveLastDir( "FileDialog-SAVE", ret );
}
return ret;
}
+/**
+ * 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 & )
{
accept();
}
void OFileDialog::slotSelectorOk( )
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
@@ -86,12 +86,17 @@ public:
const QString& startDir = QString::null,
const QString& fileName = QString::null,
const MimeTypes& mimefilter = MimeTypes(),
QWidget *wid = 0,
const QString &caption = QString::null );
+ static QString getDirectory(int selector,
+ const QString &startDir = QString::null,
+ QWidget *wid = 0,
+ const QString &caption = QString::null );
+
//let's OFileSelector catch up first
//static QString getExistingDirectory(const QString& startDir = QString::null,
//QWidget *parent = 0, const QString& caption = QString::null );
private:
class OFileDialogPrivate;
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
@@ -425,16 +425,19 @@ void OFileViewFileListView::reread( bool all )
QDir dir( m_currentDir );
if (!dir.exists() )
return;
dir.setSorting( QDir::Name | QDir::DirsFirst | QDir::Reversed );
int filter;
- if (m_all )
- filter = QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All;
- else
- filter = QDir::Files | QDir::Dirs | QDir::All;
+ filter = QDir::Dirs;
+ if ( selector()->mode() != OFileSelector::DIRECTORYSELECTOR )
+ filter = filter | QDir::Files | QDir::All;
+
+ if ( m_all )
+ filter = filter | QDir::Hidden;
+
dir.setFilter( filter );
// now go through all files
const QFileInfoList *list = dir.entryInfoList();
if (!list)
{
@@ -811,13 +814,13 @@ QWidget* OFileViewFileSystem::widget( QWidget* parent )
}
return m_view;
}
void OFileViewFileSystem::activate( const QString& str)
{
- m_all = (str != QObject::tr("Files") );
+ m_all = ( str.find( "All" ) != -1 );
}
}
/* Selector */
/**
@@ -871,22 +874,37 @@ OFileSelector::OFileSelector( QWidget* parent, int mode, int sel,
QString str;
switch ( m_selector )
{
default:
case Normal:
- str = QObject::tr("Documents");
+ if ( m_mode == DIRECTORYSELECTOR )
+ str = QObject::tr("Directories");
+ else
+ str = QObject::tr("Documents");
m_cmbView->setCurrentItem( 0 );
break;
case Extended:
- str = QObject::tr("Files");
- m_cmbView->setCurrentItem( 1 );
+ if ( m_mode == DIRECTORYSELECTOR )
+ {
+ str = QObject::tr("Directories");
+ m_cmbView->setCurrentItem( 0 );
+ } else {
+ str = QObject::tr("Files");
+ m_cmbView->setCurrentItem( 1 );
+ }
break;
case ExtendedAll:
- str = QObject::tr("All Files");
- m_cmbView->setCurrentItem( 2 );
+ if ( m_mode == DIRECTORYSELECTOR )
+ {
+ str = QObject::tr("All Directories");
+ m_cmbView->setCurrentItem( 1 );
+ } else {
+ str = QObject::tr("All Files");
+ m_cmbView->setCurrentItem( 2 );
+ }
break;
}
slotViewChange( str );
}
@@ -982,25 +1000,37 @@ void OFileSelector::initMime()
this, SLOT(slotMimeTypeChanged() ) );
}
void OFileSelector::initViews()
{
- m_cmbView->insertItem( QObject::tr("Documents") );
- m_cmbView->insertItem( QObject::tr("Files") );
- m_cmbView->insertItem( QObject::tr("All Files") );
+ 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") );
+ m_cmbView->insertItem( QObject::tr("Files") );
+ m_cmbView->insertItem( QObject::tr("All Files") );
+ }
+
connect(m_cmbView, SIGNAL(activated(const QString&) ),
this, SLOT(slotViewChange(const QString&) ) );
-
- m_views.insert( QObject::tr("Documents"), new ODocumentFileView(this) );
-
/* see above why add both */
OFileViewInterface* in = new OFileViewFileSystem( this );
- m_views.insert( QObject::tr("Files"), in );
- m_views.insert( QObject::tr("All Files"), in );
+
+ 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 );
+ m_views.insert( QObject::tr("All Files"), in );
+ }
}
void OFileSelector::registerView( const Internal::OFileViewInterface* iface ) {
m_viewsPtr.append( iface );
}
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
@@ -82,14 +82,15 @@ class OFileSelector : public QWidget
public:
/**
* The Mode of the Fileselector
* Open = Open A File
* Save = Save a File
* 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 };
/**
* Normal = The old FileSelector
* Extended = Dir View
* ExtendedAll = Dir View with all hidden files
* Default = What the vendor considers best