kmail
kmfoldercombobox.cppGo to the documentation of this file.00001
00002
00003
00004 #include <config.h>
00005
00006 #include "kmfoldercombobox.h"
00007 #include "kmfoldermgr.h"
00008
00009
00010
00011 KMFolderComboBox::KMFolderComboBox( QWidget *parent, char *name )
00012 : QComboBox( parent, name )
00013 {
00014 init();
00015 }
00016
00017
00018
00019
00020 KMFolderComboBox::KMFolderComboBox( bool rw, QWidget *parent, char *name )
00021 : QComboBox( rw, parent, name )
00022 {
00023 init();
00024 }
00025
00026
00027
00028
00029 void KMFolderComboBox::init()
00030 {
00031 mSpecialIdx = -1;
00032 mOutboxShown = true;
00033 mImapShown = true;
00034 refreshFolders();
00035 connect( this, SIGNAL( activated(int) ),
00036 this, SLOT( slotActivated(int) ) );
00037 connect( kmkernel->folderMgr(), SIGNAL(changed()),
00038 this, SLOT(refreshFolders()) );
00039 connect( kmkernel->dimapFolderMgr(), SIGNAL(changed()),
00040 this, SLOT(refreshFolders()) );
00041 if (mImapShown)
00042 connect( kmkernel->imapFolderMgr(), SIGNAL(changed()),
00043 this, SLOT(refreshFolders()) );
00044 }
00045
00046
00047
00048
00049 void KMFolderComboBox::showOutboxFolder(bool shown)
00050 {
00051 mOutboxShown = shown;
00052 refreshFolders();
00053 }
00054
00055
00056
00057 void KMFolderComboBox::showImapFolders(bool shown)
00058 {
00059 mImapShown = shown;
00060 refreshFolders();
00061 if (shown)
00062 connect( kmkernel->imapFolderMgr(), SIGNAL(changed()),
00063 this, SLOT(refreshFolders()) );
00064 else
00065 disconnect( kmkernel->imapFolderMgr(), SIGNAL(changed()),
00066 this, SLOT(refreshFolders()) );
00067 }
00068
00069
00070
00071 void KMFolderComboBox::createFolderList(QStringList *names,
00072 QValueList<QGuardedPtr<KMFolder> > *folders)
00073 {
00074 kmkernel->folderMgr()->createI18nFolderList( names, folders );
00075 if ( !mOutboxShown ) {
00076 QValueList< QGuardedPtr<KMFolder> >::iterator folderIt = folders->begin();
00077 QStringList::iterator namesIt = names->begin();
00078 for ( ; folderIt != folders->end(); ++folderIt, ++namesIt ) {
00079 KMFolder *folder = *folderIt;
00080 if ( folder == kmkernel->outboxFolder() )
00081 break;
00082 }
00083 if ( folderIt != folders->end() ) {
00084 folders->remove( folderIt );
00085 names->remove( namesIt );
00086 }
00087 }
00088
00089 if (mImapShown)
00090 kmkernel->imapFolderMgr()->createI18nFolderList( names, folders );
00091
00092 kmkernel->dimapFolderMgr()->createI18nFolderList( names, folders );
00093 }
00094
00095
00096
00097 void KMFolderComboBox::refreshFolders()
00098 {
00099 QStringList names;
00100 QValueList<QGuardedPtr<KMFolder> > folders;
00101 createFolderList( &names, &folders );
00102
00103 KMFolder *folder = getFolder();
00104 this->clear();
00105 insertStringList( names );
00106 setFolder( folder );
00107 }
00108
00109
00110
00111 void KMFolderComboBox::setFolder( KMFolder *aFolder )
00112 {
00113 QStringList names;
00114 QValueList<QGuardedPtr<KMFolder> > folders;
00115 createFolderList( &names, &folders );
00116
00117 int idx = folders.findIndex( aFolder );
00118 if (idx == -1)
00119 idx = folders.findIndex( kmkernel->draftsFolder() );
00120 setCurrentItem( idx >= 0 ? idx : 0 );
00121
00122 mFolder = aFolder;
00123 }
00124
00125 void KMFolderComboBox::setFolder( const QString &idString )
00126 {
00127 KMFolder * folder = kmkernel->findFolderById( idString );
00128 if (!folder && !idString.isEmpty())
00129 {
00130 if (mSpecialIdx >= 0)
00131 removeItem(mSpecialIdx);
00132 mSpecialIdx = count();
00133 insertItem(idString, -1);
00134 setCurrentItem(mSpecialIdx);
00135
00136 mFolder = 0;
00137 return;
00138 }
00139 setFolder( folder );
00140 }
00141
00142
00143
00144 KMFolder *KMFolderComboBox::getFolder()
00145 {
00146 if (mFolder)
00147 return mFolder;
00148
00149 QStringList names;
00150 QValueList<QGuardedPtr<KMFolder> > folders;
00151 createFolderList( &names, &folders );
00152
00153 if (currentItem() == mSpecialIdx)
00154 return 0;
00155
00156 QString text = currentText();
00157 int idx = 0;
00158 QStringList::Iterator it;
00159 for ( it = names.begin(); it != names.end(); ++it ) {
00160 if ( ! (*it).compare( text ) )
00161 return *folders.at( idx );
00162 idx++;
00163 }
00164
00165 return kmkernel->draftsFolder();
00166 }
00167
00168
00169
00170 void KMFolderComboBox::slotActivated(int index)
00171 {
00172 QStringList names;
00173 QValueList<QGuardedPtr<KMFolder> > folders;
00174 createFolderList( &names, &folders );
00175
00176 if (index == mSpecialIdx)
00177 {
00178 mFolder = 0;
00179 }
00180 else
00181 {
00182 mFolder = *folders.at( index );
00183 }
00184 }
00185
00186
00187
00188 #include "kmfoldercombobox.moc"
|