libopie API Documentation

ofiledialog.cc

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/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      * helper functions to load the start dir
00045      * and to save it
00046      * helper to extract the dir out of a file name
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() ); // appname
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   //  QVBoxLayout *lay = new QVBoxLayout(this);
00091   //showMaximized();
00092   QVBoxLayout *lay = new QVBoxLayout(this );
00093   file = new OFileSelector(this , mode, selector,
00094                dirName, fileName,
00095                mimetypes );
00096   lay->addWidget( file );
00097 
00098   //lay->addWidget( file );
00099   //showFullScreen();
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   // if mode
00214   //accept();
00215 }
KDE Logo
This file is part of the documentation for OPIE Version 1.1.
Documentation copyright © 1997-2003 the KDE developers. 2003 OPIE developers
Generated on Tue Feb 10 20:24:43 2004 by doxygen 1.3.5 written by Dimitri van Heesch, © 1997-2001