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/applnk.h>
00030 #include <qpe/config.h>
00031 #include <qpe/qpeapplication.h>
00032
00033 #include <qfileinfo.h>
00034 #include <qstring.h>
00035 #include <qapplication.h>
00036 #include <qlayout.h>
00037
00038
00039 #include "ofiledialog.h"
00040
00041
00042 namespace {
00043
00044
00045
00046
00047
00052 QString lastUsedDir( const QString& key ) {
00053 if ( qApp->argc() < 1 )
00054 return QString::null;
00055
00056 Config cfg( QFileInfo(qApp->argv()[0]).fileName() );
00057 cfg.setGroup( key );
00058 return cfg.readEntry("LastDir", QPEApplication::documentDir() );
00059 }
00060
00061 void saveLastDir( const QString& key, const QString& file ) {
00062 if ( qApp->argc() < 1 )
00063 return;
00064
00065 Config cfg( QFileInfo(qApp->argv()[0]).fileName() );
00066 cfg.setGroup( key );
00067 QFileInfo inf( file );
00068 cfg.writeEntry("LastDir", inf.dirPath( true ) );
00069 }
00070 };
00071
00083 OFileDialog::OFileDialog(const QString &caption,
00084 QWidget *wid, int mode, int selector,
00085 const QString &dirName,
00086 const QString &fileName,
00087 const QMap<QString,QStringList>& mimetypes )
00088 : QDialog( wid, "OFileDialog", true )
00089 {
00090
00091
00092 QVBoxLayout *lay = new QVBoxLayout(this );
00093 file = new OFileSelector(this , mode, selector,
00094 dirName, fileName,
00095 mimetypes );
00096 lay->addWidget( file );
00097
00098
00099
00100 setCaption( caption.isEmpty() ? tr("FileDialog") : caption );
00101 connect(file, SIGNAL(fileSelected(const QString&) ),
00102 this, SLOT(slotFileSelected(const QString&) ) );
00103 connect(file, SIGNAL(ok() ),
00104 this, SLOT(slotSelectorOk()) ) ;
00105
00106 connect(file, SIGNAL(dirSelected(const QString&) ), this, SLOT(slotDirSelected(const QString&) ) );
00107
00108 #if 0
00109 connect(file, SIGNAL(dirSelected(const QString &) ),
00110 this, SLOT(slotDirSelected(const QString &) ) );
00111 #endif
00112 }
00117 QString OFileDialog::mimetype()const
00118 {
00119 return QString::null;
00120 }
00121
00125 QString OFileDialog::fileName()const
00126 {
00127 return file->selectedName();
00128 }
00129
00133 DocLnk OFileDialog::selectedDocument()const
00134 {
00135 return file->selectedDocument();
00136 }
00137
00149 QString OFileDialog::getOpenFileName(int selector,
00150 const QString &_startDir,
00151 const QString &file,
00152 const MimeTypes &mimes,
00153 QWidget *wid,
00154 const QString &caption )
00155 {
00156 QString ret;
00157 QString startDir = _startDir;
00158 if (startDir.isEmpty() )
00159 startDir = lastUsedDir( "FileDialog-OPEN" );
00160
00161
00162 OFileDialog dlg( caption.isEmpty() ? tr("Open") : caption,
00163 wid, OFileSelector::Open, selector, startDir, file, mimes);
00164 dlg.showMaximized();
00165 if( dlg.exec() ) {
00166 ret = dlg.fileName();
00167 saveLastDir( "FileDialog-OPEN", ret );
00168 }
00169
00170 return ret;
00171 }
00172
00177 QString OFileDialog::getSaveFileName(int selector,
00178 const QString &_startDir,
00179 const QString &file,
00180 const MimeTypes &mimes,
00181 QWidget *wid,
00182 const QString &caption )
00183 {
00184 QString ret;
00185 QString startDir = _startDir;
00186 if (startDir.isEmpty() )
00187 startDir = lastUsedDir( "FileDialog-SAVE" );
00188
00189 OFileDialog dlg( caption.isEmpty() ? tr("Save") : caption,
00190 wid, OFileSelector::Save, selector, startDir, file, mimes);
00191 dlg.showMaximized();
00192 if( dlg.exec() ) {
00193 ret = dlg.fileName();
00194 saveLastDir( "FileDialog-SAVE", ret );
00195 }
00196
00197 return ret;
00198 }
00199
00200 void OFileDialog::slotFileSelected(const QString & )
00201 {
00202 accept();
00203 }
00204
00205 void OFileDialog::slotSelectorOk( )
00206 {
00207 accept();
00208 }
00209
00210 void OFileDialog::slotDirSelected(const QString &dir )
00211 {
00212 setCaption( dir );
00213
00214
00215 }