• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdepim
  • Sitemap
  • Contact Us
 

libkleo

filenamerequester.cpp

Go to the documentation of this file.
00001 /* -*- mode: c++; c-basic-offset:4 -*-
00002     ui/filenamerequester.cpp
00003 
00004     This file is part of Kleopatra, the KDE keymanager
00005     Copyright (c) 2007 Klarälvdalens Datakonsult AB
00006 
00007     Kleopatra is free software; you can redistribute it and/or modify
00008     it under the terms of the GNU General Public License as published by
00009     the Free Software Foundation; either version 2 of the License, or
00010     (at your option) any later version.
00011 
00012     Kleopatra is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015     General Public License for more details.
00016 
00017     You should have received a copy of the GNU General Public License
00018     along with this program; if not, write to the Free Software
00019     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00020 
00021     In addition, as a special exception, the copyright holders give
00022     permission to link the code of this program with any edition of
00023     the Qt library by Trolltech AS, Norway (or with modified versions
00024     of Qt that use the same license as Qt), and distribute linked
00025     combinations including the two.  You must obey the GNU General
00026     Public License in all respects for all of the code used other than
00027     Qt.  If you modify this file, you may extend this exception to
00028     your version of the file, but you are not obligated to do so.  If
00029     you do not wish to do so, delete this exception statement from
00030     your version.
00031 */
00032 
00033 #include "filenamerequester.h"
00034 
00035 #include <KIcon>
00036 #include <KLocale>
00037 
00038 #include <QLayout>
00039 #include <QToolButton>
00040 #include <QLineEdit>
00041 #include <QCompleter>
00042 #include <QDirModel>
00043 #include <QVariant>
00044 #include <QString>
00045 #include <QFileDialog>
00046 
00047 using namespace Kleo;
00048 
00049 class FileNameRequester::Private {
00050     friend class ::Kleo::FileNameRequester;
00051     FileNameRequester * const q;
00052 public:
00053     explicit Private( FileNameRequester * qq );
00054     ~Private();
00055 
00056 private:
00057     void slotButtonClicked();
00058 
00059 private:
00060     QDirModel  dirmodel;
00061     QCompleter completer;
00062 
00063     QLineEdit    lineedit;
00064     QToolButton  button;
00065     QHBoxLayout hlay;
00066 
00067     QString nameFilter;
00068     bool existingOnly;
00069 };
00070 
00071 FileNameRequester::Private::Private( FileNameRequester * qq )
00072     : q( qq ),
00073       dirmodel(),
00074       completer( &dirmodel ),
00075       lineedit( q ),
00076       button( q ),
00077       hlay( q ),
00078       nameFilter(),
00079       existingOnly( true )
00080 {
00081     dirmodel.setObjectName( "dirmodel" );
00082     completer.setObjectName( "completer" );
00083     lineedit.setObjectName( "lineedit" );
00084     button.setObjectName( "button" );
00085     hlay.setObjectName( "hlay" );
00086 
00087     button.setIcon( KIcon("document-open") );
00088     lineedit.setCompleter( &completer );
00089 
00090     hlay.setMargin( 0 );
00091     hlay.addWidget( &lineedit );
00092     hlay.addWidget( &button );
00093 
00094     connect( &button, SIGNAL(clicked()),
00095              q, SLOT(slotButtonClicked()) );
00096     connect( &lineedit, SIGNAL(textChanged(QString)),
00097              q, SIGNAL(fileNameChanged(QString)) );
00098 }
00099 
00100 FileNameRequester::Private::~Private() {}
00101 
00102 FileNameRequester::FileNameRequester( QWidget * p )
00103     : QWidget( p ), d( new Private( this ) )
00104 {
00105 
00106 }
00107 
00108 FileNameRequester::FileNameRequester( QDir::Filters f, QWidget * p )
00109     : QWidget( p ), d( new Private( this ) )
00110 {
00111     d->dirmodel.setFilter( f );
00112 }
00113 
00114 FileNameRequester::~FileNameRequester() {
00115     delete d;
00116 }
00117 
00118 void FileNameRequester::setFileName( const QString & file ) {
00119     d->lineedit.setText( file );
00120 }
00121 
00122 QString FileNameRequester::fileName() const {
00123     return d->lineedit.text();
00124 }
00125 
00126 void FileNameRequester::setExistingOnly( bool on ) {
00127     d->existingOnly = on;
00128 }
00129 
00130 bool FileNameRequester::existingOnly() const {
00131     return d->existingOnly;
00132 }
00133 
00134 void FileNameRequester::setFilter( QDir::Filters f ) {
00135     d->dirmodel.setFilter( f );
00136 }
00137 
00138 QDir::Filters FileNameRequester::filter() const {
00139     return d->dirmodel.filter();
00140 }
00141 
00142 void FileNameRequester::setNameFilter( const QString & nameFilter ) {
00143     d->nameFilter = nameFilter;
00144 }
00145 
00146 QString FileNameRequester::nameFilter() const {
00147     return d->nameFilter;
00148 }
00149 
00150 void FileNameRequester::Private::slotButtonClicked() {
00151     const QString fileName = q->requestFileName();
00152     if ( !fileName.isEmpty() )
00153         q->setFileName( fileName );
00154 }
00155 
00156 QString FileNameRequester::requestFileName() {
00157     const QDir::Filters filters = filter();
00158     if ( (filters & QDir::Dirs) && !(filters & QDir::Files) )
00159         return QFileDialog::getExistingDirectory( this );
00160     else if ( d->existingOnly )
00161         return QFileDialog::getOpenFileName( this, QString(), QString(), d->nameFilter );
00162     else
00163         return QFileDialog::getSaveFileName( this, QString(), QString(), d->nameFilter );
00164 }
00165       
00166 #include "moc_filenamerequester.cpp"

libkleo

Skip menu "libkleo"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

kdepim

Skip menu "kdepim"
  • akonadi
  •   clients
  •   kabc
  •   kcal
  •   kcm
  • akregator
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt
  • kdgantt1
  • kjots
  • kleopatra
  • kmail
  • kmobiletools
  • knode
  • knotes
  • kontact
  • kontactinterfaces
  • korganizer
  •   korgac
  • kpilot
  • ktimetracker
  •   doc
  • libkdepim
  • libkholidays
  • libkleo
  • libkpgp
  • maildir
Generated for kdepim by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal