23
23
#include "psiaccount.h"
24
24
#include "psicontactlist.h"
26
AccountsComboBox::AccountsComboBox(PsiCon *_psi, QWidget *parent, bool online_only)
27
:QComboBox(parent), onlineOnly(online_only)
26
AccountsComboBox::AccountsComboBox(QWidget* parent)
30
// TODO: Status changes of accounts should be notified when onlineOnly is true
31
connect(psi, SIGNAL(accountCountChanged()), this, SLOT(updateAccounts()));
32
connect(psi, SIGNAL(destroyed()), SLOT(deleteMe()));
32
setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed));
33
33
connect(this, SIGNAL(activated(int)), this, SLOT(changeAccount()));
35
connect(psi, SIGNAL(accountActivityChanged()), this, SLOT(updateAccounts()));
38
setSizePolicy(QSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Fixed ));
40
if(psi->contactList()->haveEnabledAccounts())
41
setAccount(psi->contactList()->enabledAccounts().first());
44
36
AccountsComboBox::~AccountsComboBox()
48
void AccountsComboBox::setAccount(PsiAccount *_pa)
40
PsiAccount* AccountsComboBox::account() const
45
void AccountsComboBox::setAccount(PsiAccount* account)
51
PsiCon* AccountsComboBox::controller() const
56
void AccountsComboBox::setController(PsiCon* controller)
59
disconnect(controller_, SIGNAL(accountCountChanged()), this, SLOT(updateAccounts()));
60
disconnect(controller_, SIGNAL(accountActivityChanged()), this, SLOT(updateAccounts()));
63
controller_ = controller;
66
connect(controller_, SIGNAL(accountCountChanged()), this, SLOT(updateAccounts()));
67
connect(controller_, SIGNAL(accountActivityChanged()), this, SLOT(updateAccounts()));
70
if (controller_->contactList()->haveEnabledAccounts()) {
71
setAccount(controller_->contactList()->enabledAccounts().first());
77
bool AccountsComboBox::onlineOnly() const
82
void AccountsComboBox::setOnlineOnly(bool onlineOnly)
84
onlineOnly_ = onlineOnly;
54
88
void AccountsComboBox::changeAccount()
56
int i = currentItem();
60
foreach(PsiAccount* p, psi->contactList()->enabledAccounts()) {
61
if (!onlineOnly || p->loggedIn()) {
91
if (currentIndex() >= 0 && currentIndex() < accounts().count())
92
account_ = accounts().at(currentIndex());
93
emit activated(account_);
76
96
void AccountsComboBox::updateAccounts()
81
PsiAccount *firstAccount = 0;
82
foreach(PsiAccount* p, psi->contactList()->enabledAccounts()) {
83
if (!onlineOnly || p->loggedIn()) {
84
insertItem(p->nameWithJid());
95
// choose a different account
100
foreach(PsiAccount* account, accounts())
101
insertItem(account->nameWithJid());
103
if (accounts().indexOf(account_) == -1) {
104
account_ = accounts().isEmpty() ? 0 : accounts().first();
105
emit activated(account_);
107
setCurrentIndex(accounts().indexOf(account_));
101
void AccountsComboBox::deleteMe()
110
QList<PsiAccount*> AccountsComboBox::accounts() const
112
QList<PsiAccount*> result;
114
foreach(PsiAccount* account, controller_->contactList()->enabledAccounts())
115
if (!onlineOnly_ || account->isAvailable())