kmail

accountcombobox.cpp
1 
29 #include "accountcombobox.h"
30 #include "kmfolder.h"
31 #include "kmfolderdir.h"
32 #include "accountmanager.h"
33 #include <kdebug.h>
34 
35 using namespace KMail;
36 
37 AccountComboBox::AccountComboBox( TQWidget* parent, const char* name )
38  : TQComboBox( parent, name )
39 {
40  connect( kmkernel->acctMgr(), TQT_SIGNAL( accountAdded( KMAccount* ) ),
41  this, TQT_SLOT( slotRefreshAccounts() ) );
42  connect( kmkernel->acctMgr(), TQT_SIGNAL( accountRemoved( KMAccount* ) ),
43  this, TQT_SLOT( slotRefreshAccounts() ) );
44  slotRefreshAccounts();
45 }
46 
47 void AccountComboBox::slotRefreshAccounts()
48 {
49  KMAccount* curr = currentAccount();
50  clear();
51  // Note that this won't take into account newly-created-in-configuredialog accounts
52  // until clicking OK or Apply. This would make this class much more complex
53  // (this would have to be different depending on whether this combo is in the
54  // configuration dialog or not...)
55  TQStringList accountNames;
56  TQValueList<KMAccount *> lst = applicableAccounts();
57  TQValueList<KMAccount *>::ConstIterator it = lst.begin();
58  for ( ; it != lst.end() ; ++it )
59  accountNames.append( (*it)->name() );
60  kdDebug() << k_funcinfo << accountNames << endl;
61  insertStringList( accountNames );
62  if ( curr )
63  setCurrentAccount( curr );
64 }
65 
66 
67 void AccountComboBox::setCurrentAccount( KMAccount* account )
68 {
69  int i = 0;
70  TQValueList<KMAccount *> lst = applicableAccounts();
71  TQValueList<KMAccount *>::ConstIterator it = lst.begin();
72  for ( ; it != lst.end() ; ++it, ++i ) {
73  if ( (*it) == account ) {
74  setCurrentItem( i );
75  return;
76  }
77  }
78 }
79 
80 KMAccount* AccountComboBox::currentAccount() const
81 {
82  int i = 0;
83  TQValueList<KMAccount *> lst = applicableAccounts();
84  TQValueList<KMAccount *>::ConstIterator it = lst.begin();
85  while ( it != lst.end() && i < currentItem() ) {
86  ++it;
87  ++i;
88  }
89  if ( it != lst.end() )
90  return *it;
91  return 0;
92 }
93 
94 TQValueList<KMAccount *> KMail::AccountComboBox::applicableAccounts() const
95 {
96  TQValueList<KMAccount *> lst;
97  for( KMAccount *a = kmkernel->acctMgr()->first(); a;
98  a = kmkernel->acctMgr()->next() ) {
99  if ( a && a->type() == "cachedimap" ) {
100  lst.append( a );
101  }
102  }
103  return lst;
104 }
105 
106 #include "accountcombobox.moc"