Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

ofiledialog.cc

Go to the documentation of this file.
00001 /*
00002                =.            This file is part of the OPIE Project
00003              .=l.            Copyright (c)  2002,2003 <zecke@handhelds.org>
00004            .>+-=
00005  _;:,     .>    :=|.         This library is free software; you can
00006 .> <`_,   >  .   <=          redistribute it and/or  modify it under
00007 :`=1 )Y*s>-.--   :           the terms of the GNU Library General Public
00008 .="- .-=="i,     .._         License as published by the Free Software
00009  - .   .-<_>     .<>         Foundation; either version 2 of the License,
00010      ._= =}       :          or (at your option) any later version.
00011     .%`+i>       _;_.
00012     .i_,=:_.      -<s.       This library is distributed in the hope that
00013      +  .  -:.       =       it will be useful,  but WITHOUT ANY WARRANTY;
00014     : ..    .:,     . . .    without even the implied warranty of
00015     =_        +     =;=|`    MERCHANTABILITY or FITNESS FOR A
00016   _.=:.       :    :=>`:     PARTICULAR PURPOSE. See the GNU
00017 ..}^=.=       =       ;      Library General Public License for more
00018 ++=   -.     .`     .:       details.
00019  :     =  ...= . :.=-
00020  -.   .:....=;==+<;          You should have received a copy of the GNU
00021   -_. . .   )=.  =           Library General Public License along with
00022     --        :-=`           this library; see the file COPYING.LIB.
00023                              If not, write to the Free Software Foundation,
00024                              Inc., 59 Temple Place - Suite 330,
00025                              Boston, MA 02111-1307, USA.
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      * helper functions to load the start dir
00042      * and to save it
00043      * helper to extract the dir out of a file name
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() ); // appname
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   //  QVBoxLayout *lay = new QVBoxLayout(this);
00088   //showMaximized();
00089   QVBoxLayout *lay = new QVBoxLayout(this );
00090   file = new OFileSelector(this , mode, selector,
00091                            dirName, fileName,
00092                            mimetypes );
00093   lay->addWidget( file );
00094 
00095   //lay->addWidget( file );
00096   //showFullScreen();
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   // if mode
00211   //accept();
00212 }

Generated on Sat Nov 5 16:18:04 2005 for OPIE by  doxygen 1.4.2