Show invite menu in wlm chat window immediately
[kdenetwork.git] / kopete / libkopete / ui / accountselector.cpp
blob1a01472d98362be825a37f0b8356040714459886
1 /*
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 *************************************************************************
9 * *
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. *
14 * *
15 *************************************************************************
18 #include "accountselector.h"
19 #include "kopeteaccount.h"
20 #include "kopeteaccountmanager.h"
22 #include <q3header.h>
23 #include <qlayout.h>
24 #include <qpixmap.h>
25 //Added by qt3to4:
26 #include <QVBoxLayout>
28 #include <kdebug.h>
29 #include <k3listview.h>
31 class AccountListViewItem : public K3ListViewItem
33 private:
34 Kopete::Account *mAccount;
36 public:
37 AccountListViewItem(Q3ListView *parent, Kopete::Account *acc)
38 : K3ListViewItem(parent)
40 if (acc==0)
41 return;
43 /*kDebug(14010) <<
44 "account name = " << acc->accountId() << endl;*/
45 mAccount = acc;
46 setText(0, mAccount->accountId());
47 setPixmap(0, mAccount->accountIcon());
50 Kopete::Account *account()
52 return mAccount;
57 // ----------------------------------------------------------------------------
59 class AccountSelectorPrivate
61 public:
62 K3ListView *lv;
63 Kopete::Protocol *proto;
67 AccountSelector::AccountSelector(QWidget *parent)
68 : QWidget(parent)
70 //kDebug(14010) << "for no special protocol";
71 d = new AccountSelectorPrivate;
72 d->proto = 0;
73 initUI();
77 AccountSelector::AccountSelector(Kopete::Protocol *proto, QWidget *parent) : QWidget(parent)
79 //kDebug(14010) << " for protocol " << proto->pluginId();
80 d = new AccountSelectorPrivate;
81 d->proto = proto;
82 initUI();
86 AccountSelector::~AccountSelector()
88 kDebug(14010) ;
89 delete d;
93 void AccountSelector::initUI()
95 kDebug(14010) ;
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);
102 setLayout(layout);
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)
117 if (account==0)
118 return;
120 Q3ListViewItemIterator it(d->lv);
121 while (it.current())
123 if(static_cast<AccountListViewItem *>(it.current())->account() == account)
125 it.current()->setSelected(true);
126 return;
132 bool AccountSelector::isSelected(Kopete::Account *account)
134 if (account==0)
135 return false;
137 Q3ListViewItemIterator it(d->lv);
138 while (it.current())
140 if(static_cast<AccountListViewItem *>(it.current())->account() == account)
141 return true;
143 return false;
147 Kopete::Account *AccountSelector::selectedItem()
149 //kDebug(14010) ;
151 if (d->lv->selectedItem() != 0)
152 return static_cast<AccountListViewItem *>(d->lv->selectedItem())->account();
153 return 0;
157 void AccountSelector::slotSelectionChanged(Q3ListViewItem *item)
159 //kDebug(14010) ;
160 if (item != 0)
162 Kopete::Account *account = static_cast<AccountListViewItem *>(item)->account();
163 if (account != 0)
165 emit selectionChanged(account);
166 return;
170 emit selectionChanged(0);
173 #include "accountselector.moc"
174 // vim: set noet ts=4 sts=4 sw=4: