2 accountselector.cpp - An Accountselector
4 Copyright (c) 2004 by Stefan Gehn <metz AT gehn.net>
6 Kopete (c) 2002-2004 by the Kopete developers <kopete-devel@kde.org>
8 *************************************************************************
10 * This library is free software; you can redistribute it and/or *
11 * modify it under the terms of the GNU Lesser General Public *
12 * License as published by the Free Software Foundation; either *
13 * version 2 of the License, or (at your option) any later version. *
15 *************************************************************************
18 #include "accountselector.h"
19 #include "kopeteaccount.h"
20 #include "kopeteaccountmanager.h"
26 #include <QVBoxLayout>
29 #include <k3listview.h>
31 class AccountListViewItem
: public K3ListViewItem
34 Kopete::Account
*mAccount
;
37 AccountListViewItem(Q3ListView
*parent
, Kopete::Account
*acc
)
38 : K3ListViewItem(parent
)
44 "account name = " << acc->accountId() << endl;*/
46 setText(0, mAccount
->accountId());
47 setPixmap(0, mAccount
->accountIcon());
50 Kopete::Account
*account()
57 // ----------------------------------------------------------------------------
59 class AccountSelectorPrivate
63 Kopete::Protocol
*proto
;
67 AccountSelector::AccountSelector(QWidget
*parent
)
70 //kDebug(14010) << "for no special protocol";
71 d
= new AccountSelectorPrivate
;
77 AccountSelector::AccountSelector(Kopete::Protocol
*proto
, QWidget
*parent
) : QWidget(parent
)
79 //kDebug(14010) << " for protocol " << proto->pluginId();
80 d
= new AccountSelectorPrivate
;
86 AccountSelector::~AccountSelector()
93 void AccountSelector::initUI()
96 QVBoxLayout
*layout
= new QVBoxLayout(this);
97 d
->lv
= new K3ListView(this);
98 d
->lv
->setFullWidth(true);
99 d
->lv
->addColumn(QString::fromLatin1(""));
100 d
->lv
->header()->hide();
101 layout
->addWidget(d
->lv
);
103 kDebug(14010) << "creating list of all accounts";
104 foreach(Kopete::Account
*account
, Kopete::AccountManager::self()->accounts() )
106 if( !d
->proto
|| account
->protocol() == d
->proto
)
107 new AccountListViewItem(d
->lv
, account
);
110 connect(d
->lv
, SIGNAL(selectionChanged(Q3ListViewItem
*)),
111 this, SLOT(slotSelectionChanged(Q3ListViewItem
*)));
115 void AccountSelector::setSelected(Kopete::Account
*account
)
120 Q3ListViewItemIterator
it(d
->lv
);
123 if(static_cast<AccountListViewItem
*>(it
.current())->account() == account
)
125 it
.current()->setSelected(true);
132 bool AccountSelector::isSelected(Kopete::Account
*account
)
137 Q3ListViewItemIterator
it(d
->lv
);
140 if(static_cast<AccountListViewItem
*>(it
.current())->account() == account
)
147 Kopete::Account
*AccountSelector::selectedItem()
151 if (d
->lv
->selectedItem() != 0)
152 return static_cast<AccountListViewItem
*>(d
->lv
->selectedItem())->account();
157 void AccountSelector::slotSelectionChanged(Q3ListViewItem
*item
)
162 Kopete::Account
*account
= static_cast<AccountListViewItem
*>(item
)->account();
165 emit
selectionChanged(account
);
170 emit
selectionChanged(0);
173 #include "accountselector.moc"
174 // vim: set noet ts=4 sts=4 sw=4: