kmail

folderrequester.cpp

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2004 Carsten Burghardt <burghardt@kde.org>
00003  *
00004  *  This program is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; version 2 of the License
00007  *
00008  *  This program is distributed in the hope that it will be useful,
00009  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00010  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011  *  GNU General Public License for more details.
00012  *
00013  *  You should have received a copy of the GNU General Public License
00014  *  along with this program; if not, write to the Free Software
00015  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00016  *
00017  *  In addition, as a special exception, the copyright holders give
00018  *  permission to link the code of this program with any edition of
00019  *  the Qt library by Trolltech AS, Norway (or with modified versions
00020  *  of Qt that use the same license as Qt), and distribute linked
00021  *  combinations including the two.  You must obey the GNU General
00022  *  Public License in all respects for all of the code used other than
00023  *  Qt.  If you modify this file, you may extend this exception to
00024  *  your version of the file, but you are not obligated to do so.  If
00025  *  you do not wish to do so, delete this exception statement from
00026  *  your version.
00027  */
00028 
00029 #include "folderrequester.h"
00030 #include "kmfolder.h"
00031 #include "kmfoldertree.h"
00032 #include "kmfolderseldlg.h"
00033 
00034 #include <kdebug.h>
00035 #include <klineedit.h>
00036 #include <kiconloader.h>
00037 #include <kdialog.h>
00038 
00039 #include <qlayout.h>
00040 #include <qtoolbutton.h>
00041 
00042 namespace KMail {
00043 
00044 FolderRequester::FolderRequester( QWidget *parent, KMFolderTree *tree )
00045   : QWidget( parent ), mFolder( 0 ), mFolderTree( tree ),
00046     mMustBeReadWrite( true ), mShowOutbox( true ), mShowImapFolders( true )
00047 {
00048   QHBoxLayout * hlay = new QHBoxLayout( this, 0, KDialog::spacingHint() );
00049   hlay->setAutoAdd( true );
00050 
00051   edit = new KLineEdit( this );
00052   edit->setReadOnly( true );
00053 
00054   QToolButton* button = new QToolButton( this );
00055   button->setIconSet( KGlobal::iconLoader()->loadIconSet( "folder", KIcon::Small, 0 ) );
00056   connect( button, SIGNAL(clicked()), this, SLOT(slotOpenDialog()) );
00057 
00058   setSizePolicy( QSizePolicy( QSizePolicy::MinimumExpanding,
00059         QSizePolicy::Fixed ) );
00060   setFocusPolicy( QWidget::StrongFocus );
00061 }
00062 
00063 //-----------------------------------------------------------------------------
00064 void FolderRequester::slotOpenDialog()
00065 {
00066   KMFolderSelDlg dlg( this, mFolderTree, i18n("Select Folder"),
00067       mMustBeReadWrite, false );
00068   dlg.setFlags( mMustBeReadWrite, mShowOutbox, mShowImapFolders );
00069   dlg.setFolder( mFolder );
00070 
00071   if (!dlg.exec()) return;
00072   setFolder( dlg.folder() );
00073 }
00074 
00075 //-----------------------------------------------------------------------------
00076 FolderRequester::~FolderRequester()
00077 {
00078 }
00079 
00080 //-----------------------------------------------------------------------------
00081 KMFolder * FolderRequester::folder( void ) const
00082 {
00083   return mFolder;
00084 }
00085 
00086 //-----------------------------------------------------------------------------
00087 void FolderRequester::setFolder( KMFolder *folder )
00088 {
00089   mFolder = folder;
00090   if ( mFolder ) {
00091     edit->setText( mFolder->prettyURL() );
00092     mFolderId = mFolder->idString();
00093   }
00094   else if ( !mMustBeReadWrite ) // the Local Folders root node was selected
00095     edit->setText( i18n("Local Folders") );
00096   emit folderChanged( folder );
00097 }
00098 
00099 //-----------------------------------------------------------------------------
00100 void FolderRequester::setFolder( const QString &idString )
00101 {
00102   KMFolder *folder = kmkernel->findFolderById( idString );
00103   if ( folder ) {
00104     setFolder( folder );
00105   } else {
00106     if ( !idString.isEmpty() ) {
00107       edit->setText( i18n( "Unknown folder '%1'" ).arg( idString ) );
00108     } else {
00109       edit->setText( i18n( "Please select a folder" ) );
00110     }
00111     mFolder = 0;
00112   }
00113   mFolderId = idString;
00114 }
00115 
00116 //-----------------------------------------------------------------------------
00117 void FolderRequester::keyPressEvent( QKeyEvent * e )
00118 {
00119   if ( e->key() == Qt::Key_Space )
00120     slotOpenDialog();
00121   else
00122     e->ignore();
00123 }
00124 
00125 } // namespace KMail
00126 
00127 #include "folderrequester.moc"