From b7e50e77e0b22b3dd0feee43b15d0152d9ca8abb Mon Sep 17 00:00:00 2001 From: ar Date: Sat, 14 Aug 2004 19:17:39 +0000 Subject: - 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. --- (limited to 'libopie2/opieui/fileselector/ofiledialog.cpp') 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 @@ -70,7 +70,10 @@ void saveLastDir( const QString& key, const QString& file ) 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 ); } }; @@ -204,6 +207,36 @@ QString OFileDialog::getSaveFileName(int selector, 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(); -- cgit v0.9.0.2