kmail
accountcombobox.cpp
Go to the documentation of this file.00001 00029 #include "accountcombobox.h" 00030 #include "kmfolder.h" 00031 #include "kmfolderdir.h" 00032 #include "accountmanager.h" 00033 #include <kdebug.h> 00034 00035 using namespace KMail; 00036 00037 AccountComboBox::AccountComboBox( QWidget* parent, const char* name ) 00038 : QComboBox( parent, name ) 00039 { 00040 connect( kmkernel->acctMgr(), SIGNAL( accountAdded( KMAccount* ) ), 00041 this, SLOT( slotRefreshAccounts() ) ); 00042 connect( kmkernel->acctMgr(), SIGNAL( accountRemoved( KMAccount* ) ), 00043 this, SLOT( slotRefreshAccounts() ) ); 00044 slotRefreshAccounts(); 00045 } 00046 00047 void AccountComboBox::slotRefreshAccounts() 00048 { 00049 KMAccount* curr = currentAccount(); 00050 clear(); 00051 // Note that this won't take into account newly-created-in-configuredialog accounts 00052 // until clicking OK or Apply. This would make this class much more complex 00053 // (this would have to be different depending on whether this combo is in the 00054 // configuration dialog or not...) 00055 QStringList accountNames; 00056 QValueList<KMAccount *> lst = applicableAccounts(); 00057 QValueList<KMAccount *>::ConstIterator it = lst.begin(); 00058 for ( ; it != lst.end() ; ++it ) 00059 accountNames.append( (*it)->name() ); 00060 kdDebug() << k_funcinfo << accountNames << endl; 00061 insertStringList( accountNames ); 00062 if ( curr ) 00063 setCurrentAccount( curr ); 00064 } 00065 00066 00067 void AccountComboBox::setCurrentAccount( KMAccount* account ) 00068 { 00069 int i = 0; 00070 QValueList<KMAccount *> lst = applicableAccounts(); 00071 QValueList<KMAccount *>::ConstIterator it = lst.begin(); 00072 for ( ; it != lst.end() ; ++it, ++i ) { 00073 if ( (*it) == account ) { 00074 setCurrentItem( i ); 00075 return; 00076 } 00077 } 00078 } 00079 00080 KMAccount* AccountComboBox::currentAccount() const 00081 { 00082 int i = 0; 00083 QValueList<KMAccount *> lst = applicableAccounts(); 00084 QValueList<KMAccount *>::ConstIterator it = lst.begin(); 00085 while ( it != lst.end() && i < currentItem() ) { 00086 ++it; 00087 ++i; 00088 } 00089 if ( it != lst.end() ) 00090 return *it; 00091 return 0; 00092 } 00093 00094 QValueList<KMAccount *> KMail::AccountComboBox::applicableAccounts() const 00095 { 00096 QValueList<KMAccount *> lst; 00097 for( KMAccount *a = kmkernel->acctMgr()->first(); a; 00098 a = kmkernel->acctMgr()->next() ) { 00099 if ( a && a->type() == "cachedimap" ) { 00100 lst.append( a ); 00101 } 00102 } 00103 return lst; 00104 } 00105 00106 #include "accountcombobox.moc"