diff options
author | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
---|---|---|
committer | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
commit | bcb704366cb5e333a626c18c308c7e0448a8e69f (patch) | |
tree | f0d6ab7d78ecdd9207cf46536376b44b91a1ca71 /kopete/libkopete/ui/accountselector.cpp | |
download | tdenetwork-bcb704366cb5e333a626c18c308c7e0448a8e69f.tar.gz tdenetwork-bcb704366cb5e333a626c18c308c7e0448a8e69f.zip |
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdenetwork@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kopete/libkopete/ui/accountselector.cpp')
-rw-r--r-- | kopete/libkopete/ui/accountselector.cpp | 186 |
1 files changed, 186 insertions, 0 deletions
diff --git a/kopete/libkopete/ui/accountselector.cpp b/kopete/libkopete/ui/accountselector.cpp new file mode 100644 index 00000000..2ea8e719 --- /dev/null +++ b/kopete/libkopete/ui/accountselector.cpp @@ -0,0 +1,186 @@ +/* + accountselector.cpp - An Accountselector + + Copyright (c) 2004 by Stefan Gehn <metz AT gehn.net> + + Kopete (c) 2002-2004 by the Kopete developers <kopete-devel@kde.org> + + ************************************************************************* + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + ************************************************************************* +*/ + +#include "accountselector.h" +#include "kopeteaccount.h" +#include "kopeteaccountmanager.h" + +#include <qheader.h> +#include <qlayout.h> +#include <qpixmap.h> + +#include <kdebug.h> +#include <klistview.h> + +class AccountListViewItem : public KListViewItem +{ + private: + Kopete::Account *mAccount; + + public: + AccountListViewItem(QListView *parent, Kopete::Account *acc) + : KListViewItem(parent) + { + if (acc==0) + return; + + /*kdDebug(14010) << k_funcinfo << + "account name = " << acc->accountId() << endl;*/ + mAccount = acc; + setText(0, mAccount->accountId()); + setPixmap(0, mAccount->accountIcon()); + } + + Kopete::Account *account() + { + return mAccount; + } +}; + + +// ---------------------------------------------------------------------------- + +class AccountSelectorPrivate +{ + public: + KListView *lv; + Kopete::Protocol *proto; +}; + + +AccountSelector::AccountSelector(QWidget *parent, const char *name) + : QWidget(parent, name) +{ + //kdDebug(14010) << k_funcinfo << "for no special protocol" << endl; + d = new AccountSelectorPrivate; + d->proto = 0; + initUI(); +} + + +AccountSelector::AccountSelector(Kopete::Protocol *proto, QWidget *parent, + const char *name) : QWidget(parent, name) +{ + //kdDebug(14010) << k_funcinfo << " for protocol " << proto->pluginId() << endl; + d = new AccountSelectorPrivate; + d->proto = proto; + initUI(); +} + + +AccountSelector::~AccountSelector() +{ + kdDebug(14010) << k_funcinfo << endl; + delete d; +} + + +void AccountSelector::initUI() +{ + kdDebug(14010) << k_funcinfo << endl; + (new QVBoxLayout(this))->setAutoAdd(true); + d->lv = new KListView(this); + d->lv->setFullWidth(true); + d->lv->addColumn(QString::fromLatin1("")); + d->lv->header()->hide(); + + if(d->proto != 0) + { + kdDebug(14010) << k_funcinfo << "creating list for a certain protocol" << endl; + QDict<Kopete::Account> accounts = Kopete::AccountManager::self()->accounts(d->proto); + QDictIterator<Kopete::Account> it(accounts); + for(; Kopete::Account *account = it.current(); ++it) + { + new AccountListViewItem(d->lv, account); + } + } + else + { + kdDebug(14010) << k_funcinfo << "creating list of all accounts" << endl; + QPtrList<Kopete::Account> accounts = Kopete::AccountManager::self()->accounts(); + Kopete::Account *account = 0; + for(account = accounts.first(); account; account = accounts.next()) + { + new AccountListViewItem(d->lv, account); + } + } + + connect(d->lv, SIGNAL(selectionChanged(QListViewItem *)), + this, SLOT(slotSelectionChanged(QListViewItem *))); +} + + +void AccountSelector::setSelected(Kopete::Account *account) +{ + if (account==0) + return; + + QListViewItemIterator it(d->lv); + while (it.current()) + { + if(static_cast<AccountListViewItem *>(it.current())->account() == account) + { + it.current()->setSelected(true); + return; + } + } +} + + +bool AccountSelector::isSelected(Kopete::Account *account) +{ + if (account==0) + return false; + + QListViewItemIterator it(d->lv); + while (it.current()) + { + if(static_cast<AccountListViewItem *>(it.current())->account() == account) + return true; + } + return false; +} + + +Kopete::Account *AccountSelector::selectedItem() +{ + //kdDebug(14010) << k_funcinfo << endl; + + if (d->lv->selectedItem() != 0) + return static_cast<AccountListViewItem *>(d->lv->selectedItem())->account(); + return 0; +} + + +void AccountSelector::slotSelectionChanged(QListViewItem *item) +{ + //kdDebug(14010) << k_funcinfo << endl; + if (item != 0) + { + Kopete::Account *account = static_cast<AccountListViewItem *>(item)->account(); + if (account != 0) + { + emit selectionChanged(account); + return; + } + } + + emit selectionChanged(0); +} + +#include "accountselector.moc" +// vim: set noet ts=4 sts=4 sw=4: |