kmail
folderrequester.cppGo to the documentation of this file.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 "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 )
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 }
00126
00127 #include "folderrequester.moc"
|