kmail

accountcombobox.cpp
1/*
2 * Copyright (c) 2004 David Faure <faure@kde.org>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 *
17 * In addition, as a special exception, the copyright holders give
18 * permission to link the code of this program with any edition of
19 * the TQt library by Trolltech AS, Norway (or with modified versions
20 * of TQt that use the same license as TQt), and distribute linked
21 * combinations including the two. You must obey the GNU General
22 * Public License in all respects for all of the code used other than
23 * TQt. If you modify this file, you may extend this exception to
24 * your version of the file, but you are not obligated to do so. If
25 * you do not wish to do so, delete this exception statement from
26 * your version.
27 */
28
29#include "accountcombobox.h"
30#include "kmfolder.h"
31#include "kmfolderdir.h"
32#include "accountmanager.h"
33#include <kdebug.h>
34
35using namespace KMail;
36
37AccountComboBox::AccountComboBox( TQWidget* parent, const char* name )
38 : TQComboBox( parent, name )
39{
40 connect( kmkernel->acctMgr(), TQ_SIGNAL( accountAdded( KMAccount* ) ),
41 this, TQ_SLOT( slotRefreshAccounts() ) );
42 connect( kmkernel->acctMgr(), TQ_SIGNAL( accountRemoved( KMAccount* ) ),
43 this, TQ_SLOT( slotRefreshAccounts() ) );
44 slotRefreshAccounts();
45}
46
47void 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
67void 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
80KMAccount* 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
94TQValueList<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"
folderdiaquotatab.h
Definition: aboutdata.cpp:40