diff options
author | Alvaro Soliverez <alvaro.soliverez@collabora.co.uk> | 2011-06-03 10:54:49 -0700 |
---|---|---|
committer | Alvaro Soliverez <alvaro.soliverez@collabora.co.uk> | 2011-06-03 10:54:49 -0700 |
commit | 261e6c55b1916af5f2cfb7b66b0c49f495e8a30a (patch) | |
tree | 1064f5f16ed8f87b2f7446f2527ba0d1b20f6d4a | |
parent | 068ba40dfbebe7b271123b1cfe083541716bb59f (diff) |
Check the connection and add known contacts of the account model item after it has been added to the tree and the necessary connections have been made.
This saves some work and avoids having to call addKnownContacts again after the model is created.
-rw-r--r-- | TelepathyQt4Yell/Models/accounts-model-item.cpp | 15 | ||||
-rw-r--r-- | TelepathyQt4Yell/Models/accounts-model-item.h | 2 | ||||
-rw-r--r-- | TelepathyQt4Yell/Models/accounts-model.cpp | 29 |
3 files changed, 19 insertions, 27 deletions
diff --git a/TelepathyQt4Yell/Models/accounts-model-item.cpp b/TelepathyQt4Yell/Models/accounts-model-item.cpp index 6638c2e..1122003 100644 --- a/TelepathyQt4Yell/Models/accounts-model-item.cpp +++ b/TelepathyQt4Yell/Models/accounts-model-item.cpp @@ -63,11 +63,6 @@ void AccountsModelItem::Private::setStatusMessage(const QString &value) AccountsModelItem::AccountsModelItem(const Tp::AccountPtr &account) : mPriv(new Private(account)) { - if (!mPriv->mAccount->connection().isNull()) { - // call the connection changed slot so that signals get connected - onConnectionChanged(mPriv->mAccount->connection()); - } - connect(mPriv->mAccount.data(), SIGNAL(removed()), SLOT(onRemoved())); @@ -125,14 +120,6 @@ AccountsModelItem::AccountsModelItem(const Tp::AccountPtr &account) connect(mPriv->mAccount.data(), SIGNAL(connectionChanged(Tp::ConnectionPtr)), SLOT(onConnectionChanged(Tp::ConnectionPtr))); - - // if connection is valid, connect to the status - if (!mPriv->mAccount->connection().isNull() - && mPriv->mAccount->connection()->isValid()) { - connect(mPriv->mAccount->connection().data(), SIGNAL(statusChanged(Tp::ConnectionStatus)), - SLOT(onStatusChanged(Tp::ConnectionStatus))); - onStatusChanged(mPriv->mAccount->connection()->status()); - } } AccountsModelItem::~AccountsModelItem() @@ -361,6 +348,8 @@ void AccountsModelItem::clearContacts() emit childrenRemoved(this, i, i); } } + } else { + emit childrenRemoved(this, 0, size() - 1); } } diff --git a/TelepathyQt4Yell/Models/accounts-model-item.h b/TelepathyQt4Yell/Models/accounts-model-item.h index 87ffe03..c73dae9 100644 --- a/TelepathyQt4Yell/Models/accounts-model-item.h +++ b/TelepathyQt4Yell/Models/accounts-model-item.h @@ -58,6 +58,7 @@ public: public Q_SLOTS: void addKnownContacts(); + void onConnectionChanged(const Tp::ConnectionPtr &connection); Q_SIGNALS: void connectionStatusChanged(const QString &accountId, int status); @@ -69,7 +70,6 @@ private Q_SLOTS: void onStatusChanged(Tp::ConnectionStatus status); - void onConnectionChanged(const Tp::ConnectionPtr &connection); void onContactManagerStateChanged(Tp::ContactListState state); void onContactsChanged(const Tp::Contacts &added, const Tp::Contacts &removed); diff --git a/TelepathyQt4Yell/Models/accounts-model.cpp b/TelepathyQt4Yell/Models/accounts-model.cpp index 45c897a..dcc0a7c 100644 --- a/TelepathyQt4Yell/Models/accounts-model.cpp +++ b/TelepathyQt4Yell/Models/accounts-model.cpp @@ -64,18 +64,15 @@ AccountsModel::AccountsModel(const Tp::AccountManagerPtr &am, QObject *parent) connect(mPriv->mTree, SIGNAL(childrenRemoved(TreeNode*,int,int)), SLOT(onItemsRemoved(TreeNode*,int,int))); - - foreach (Tp::AccountPtr account, mPriv->mAM->allAccounts()) { - AccountsModelItem *item = new AccountsModelItem(account); - connect(item, SIGNAL(connectionStatusChanged(QString,int)), - this, SIGNAL(accountConnectionStatusChanged(QString,int))); - mPriv->mTree->addChild(item); - } - connect(mPriv->mAM.data(), SIGNAL(newAccount(Tp::AccountPtr)), SLOT(onNewAccount(Tp::AccountPtr))); + // load existing accounts + foreach (Tp::AccountPtr account, mPriv->mAM->allAccounts()) { + onNewAccount(account); + } + QHash<int, QByteArray> roles; roles[ItemRole] = "item"; roles[IdRole] = "id"; @@ -132,12 +129,18 @@ AccountsModel::~AccountsModel() void AccountsModel::onNewAccount(const Tp::AccountPtr &account) { - AccountsModelItem *accountNode = new AccountsModelItem(account); - - connect(accountNode, SIGNAL(connectionStatusChanged(QString,int)), + AccountsModelItem *item = new AccountsModelItem(account); + connect(item, SIGNAL(connectionStatusChanged(QString,int)), this, SIGNAL(accountConnectionStatusChanged(QString,int))); - - onItemsAdded(mPriv->mTree, QList<TreeNode *>() << accountNode); + onItemsAdded(mPriv->mTree, QList<TreeNode *>() << item); + + // this is done here because the item needs to be added to the tree so that the necessary signals + // are in place to detect when adding contacts to the account item + // otherwise, addKnownContacts will be called, but the contacts will not be added to the model + if (!account->connection().isNull() + && account->connection()->isValid()) { + item->onConnectionChanged(account->connection()); + } } void AccountsModel::onItemChanged(TreeNode *node) |