00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include <qpe/config.h>
00030 #include <qpe/qpeapplication.h>
00031
00032 #include <qfileinfo.h>
00033 #include <qlayout.h>
00034
00035
00036 #include "ofiledialog.h"
00037
00038
00039 namespace {
00040
00041
00042
00043
00044
00049 QString lastUsedDir( const QString& key ) {
00050 if ( qApp->argc() < 1 )
00051 return QString::null;
00052
00053 Config cfg( QFileInfo(qApp->argv()[0]).fileName() );
00054 cfg.setGroup( key );
00055 return cfg.readEntry("LastDir", QPEApplication::documentDir() );
00056 }
00057
00058 void saveLastDir( const QString& key, const QString& file ) {
00059 if ( qApp->argc() < 1 )
00060 return;
00061
00062 Config cfg( QFileInfo(qApp->argv()[0]).fileName() );
00063 cfg.setGroup( key );
00064 QFileInfo inf( file );
00065 cfg.writeEntry("LastDir", inf.dirPath( true ) );
00066 }
00067 };
00068
00080 OFileDialog::OFileDialog(const QString &caption,
00081 QWidget *wid, int mode, int selector,
00082 const QString &dirName,
00083 const QString &fileName,
00084 const QMap<QString,QStringList>& mimetypes )
00085 : QDialog( wid, "OFileDialog", true )
00086 {
00087
00088
00089 QVBoxLayout *lay = new QVBoxLayout(this );
00090 file = new OFileSelector(this , mode, selector,
00091 dirName, fileName,
00092 mimetypes );
00093 lay->addWidget( file );
00094
00095
00096
00097 setCaption( caption.isEmpty() ? tr("FileDialog") : caption );
00098 connect(file, SIGNAL(fileSelected(const QString&) ),
00099 this, SLOT(slotFileSelected(const QString&) ) );
00100 connect(file, SIGNAL(ok() ),
00101 this, SLOT(slotSelectorOk()) ) ;
00102
00103 connect(file, SIGNAL(dirSelected(const QString&) ), this, SLOT(slotDirSelected(const QString&) ) );
00104
00105 #if 0
00106 connect(file, SIGNAL(dirSelected(const QString &) ),
00107 this, SLOT(slotDirSelected(const QString &) ) );
00108 #endif
00109 }
00114 QString OFileDialog::mimetype()const
00115 {
00116 return QString::null;
00117 }
00118
00122 QString OFileDialog::fileName()const
00123 {
00124 return file->selectedName();
00125 }
00126
00130 DocLnk OFileDialog::selectedDocument()const
00131 {
00132 return file->selectedDocument();
00133 }
00134
00146 QString OFileDialog::getOpenFileName(int selector,
00147 const QString &_startDir,
00148 const QString &file,
00149 const MimeTypes &mimes,
00150 QWidget *wid,
00151 const QString &caption )
00152 {
00153 QString ret;
00154 QString startDir = _startDir;
00155 if (startDir.isEmpty() )
00156 startDir = lastUsedDir( "FileDialog-OPEN" );
00157
00158
00159 OFileDialog dlg( caption.isEmpty() ? tr("Open") : caption,
00160 wid, OFileSelector::Open, selector, startDir, file, mimes);
00161 dlg.showMaximized();
00162 if( dlg.exec() ) {
00163 ret = dlg.fileName();
00164 saveLastDir( "FileDialog-OPEN", ret );
00165 }
00166
00167 return ret;
00168 }
00169
00174 QString OFileDialog::getSaveFileName(int selector,
00175 const QString &_startDir,
00176 const QString &file,
00177 const MimeTypes &mimes,
00178 QWidget *wid,
00179 const QString &caption )
00180 {
00181 QString ret;
00182 QString startDir = _startDir;
00183 if (startDir.isEmpty() )
00184 startDir = lastUsedDir( "FileDialog-SAVE" );
00185
00186 OFileDialog dlg( caption.isEmpty() ? tr("Save") : caption,
00187 wid, OFileSelector::Save, selector, startDir, file, mimes);
00188 dlg.showMaximized();
00189 if( dlg.exec() ) {
00190 ret = dlg.fileName();
00191 saveLastDir( "FileDialog-SAVE", ret );
00192 }
00193
00194 return ret;
00195 }
00196
00197 void OFileDialog::slotFileSelected(const QString & )
00198 {
00199 accept();
00200 }
00201
00202 void OFileDialog::slotSelectorOk( )
00203 {
00204 accept();
00205 }
00206
00207 void OFileDialog::slotDirSelected(const QString &dir )
00208 {
00209 setCaption( dir );
00210
00211
00212 }