accountcombobox.cpp
00001
00029 #include "accountcombobox.h"
00030 #include "kmkernel.h"
00031 #include "kmfolder.h"
00032 #include "kmfolderdir.h"
00033 #include "kmacctmgr.h"
00034 #include <kdebug.h>
00035
00036 using namespace KMail;
00037
00038 AccountComboBox::AccountComboBox( QWidget* parent, const char* name )
00039 : QComboBox( parent, name )
00040 {
00041 connect( kmkernel->acctMgr(), SIGNAL( accountAdded( KMAccount* ) ),
00042 this, SLOT( slotRefreshAccounts() ) );
00043 connect( kmkernel->acctMgr(), SIGNAL( accountRemoved( KMAccount* ) ),
00044 this, SLOT( slotRefreshAccounts() ) );
00045 slotRefreshAccounts();
00046 }
00047
00048 void AccountComboBox::slotRefreshAccounts()
00049 {
00050 KMAccount* curr = currentAccount();
00051 clear();
00052
00053
00054
00055
00056 QStringList accountNames;
00057 QValueList<KMAccount *> lst = applicableAccounts();
00058 QValueList<KMAccount *>::ConstIterator it = lst.begin();
00059 for ( ; it != lst.end() ; ++it )
00060 accountNames.append( (*it)->name() );
00061 kdDebug() << k_funcinfo << accountNames << endl;
00062 insertStringList( accountNames );
00063 if ( curr )
00064 setCurrentAccount( curr );
00065 }
00066
00067
00068 void AccountComboBox::setCurrentAccount( KMAccount* account )
00069 {
00070 int i = 0;
00071 QValueList<KMAccount *> lst = applicableAccounts();
00072 QValueList<KMAccount *>::ConstIterator it = lst.begin();
00073 for ( ; it != lst.end() ; ++it, ++i ) {
00074 if ( (*it) == account ) {
00075 setCurrentItem( i );
00076 return;
00077 }
00078 }
00079 }
00080
00081 KMAccount* AccountComboBox::currentAccount() const
00082 {
00083 int i = 0;
00084 QValueList<KMAccount *> lst = applicableAccounts();
00085 QValueList<KMAccount *>::ConstIterator it = lst.begin();
00086 while ( it != lst.end() && i < currentItem() ) {
00087 ++it;
00088 ++i;
00089 }
00090 if ( it != lst.end() )
00091 return *it;
00092 return 0;
00093 }
00094
00095 QValueList<KMAccount *> KMail::AccountComboBox::applicableAccounts() const
00096 {
00097 QValueList<KMAccount *> lst;
00098 for( KMAccount *a = kmkernel->acctMgr()->first(); a;
00099 a = kmkernel->acctMgr()->next() ) {
00100 if ( a && a->type() == "cachedimap" ) {
00101 lst.append( a );
00102 }
00103 }
00104 return lst;
00105 }
00106
00107 #include "accountcombobox.moc"
This file is part of the documentation for kmail Library Version 3.3.2.