diff options
author | Alvaro Soliverez <alvaro.soliverez@collabora.co.uk> | 2011-08-23 10:21:04 -0700 |
---|---|---|
committer | Alvaro Soliverez <alvaro.soliverez@collabora.co.uk> | 2011-08-23 10:21:04 -0700 |
commit | 382f97a6af27b2684b1d3694f68b5604dbf0e60a (patch) | |
tree | 05e529186051ac85214995e400e592ba68b3f6dc | |
parent | baa286833c5558a7385bf8fe445fb9211fca50e3 (diff) |
Removed model classes that will not be maintained on this repository anymore.
20 files changed, 2 insertions, 2037 deletions
@@ -2,16 +2,10 @@ telepathy-qt4-yell 0.1.x ========================= Enhancements: - * Emit a signal when an account item is added to AccountsModel - * Emit a signal on contact item when the caps get updated + * All model classes, with the exception of the conversation-related classes, have been removed from the repository Fixes: - * Report the connection status reason using the Connection object if possible - * On connection invalidated, emit the connection status changed signal to make sure the account model item is updated - * Add constructor to Tpy::ContactCapabilities so it can be really used - * Revert returning UTF-8 for the contact alias and status messages strings - * WARNING: optimization of flat model proxy, dataChanged signal is not hierarchical anymore after we found out it was quite expensive. You need to do explicit hierarchical changes. - * Added hierarchicalDataChanged signal to Tpy::AccountsModel for explicit signalling of changes in account data affecting contacts data (expensive) + * telepathy-qt4-yell 0.1.6 (2011-06-06) ====================================== diff --git a/TelepathyQt4Yell/Models/AccountsModel b/TelepathyQt4Yell/Models/AccountsModel deleted file mode 100644 index b0a08d3..0000000 --- a/TelepathyQt4Yell/Models/AccountsModel +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef _TelepathyQt4Yell_Models_AccountsModel_HEADER_GUARD_ -#define _TelepathyQt4Yell_Models_AccountsModel_HEADER_GUARD_ - -#ifndef IN_TELEPATHY_QT4_YELL_MODELS_HEADER -#define IN_TELEPATHY_QT4_YELL_MODELS_HEADER -#endif - -#include <TelepathyQt4Yell/Models/accounts-model.h> - -#undef IN_TELEPATHY_QT4_YELL_MODELS_HEADER - -#endif // _TelepathyQt4Yell_Models_AccountsModel_HEADER_GUARD_ -// vim:set ft=cpp: diff --git a/TelepathyQt4Yell/Models/AccountsModelItem b/TelepathyQt4Yell/Models/AccountsModelItem deleted file mode 100644 index 0b94a0c..0000000 --- a/TelepathyQt4Yell/Models/AccountsModelItem +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef _TelepathyQt4Yell_Models_AccountsModelItem_HEADER_GUARD_ -#define _TelepathyQt4Yell_Models_AccountsModelItem_HEADER_GUARD_ - -#ifndef IN_TELEPATHY_QT4_YELL_MODELS_HEADER -#define IN_TELEPATHY_QT4_YELL_MODELS_HEADER -#endif - -#include <TelepathyQt4Yell/Models/accounts-model-item.h> - -#undef IN_TELEPATHY_QT4_YELL_MODELS_HEADER - -#endif // _TelepathyQt4Yell_Models_AccountsModelItem_HEADER_GUARD_ -// vim:set ft=cpp: diff --git a/TelepathyQt4Yell/Models/AvatarImageProvider b/TelepathyQt4Yell/Models/AvatarImageProvider deleted file mode 100644 index 53f046f..0000000 --- a/TelepathyQt4Yell/Models/AvatarImageProvider +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef _TelepathyQt4Yell_Models_AvatarImageProvider_HEADER_GUARD_ -#define _TelepathyQt4Yell_Models_AvatarImageProvider_HEADER_GUARD_ - -#ifndef IN_TELEPATHY_QT4_YELL_MODELS_HEADER -#define IN_TELEPATHY_QT4_YELL_MODELS_HEADER -#endif - -#include <TelepathyQt4Yell/Models/avatar-image-provider.h> - -#undef IN_TELEPATHY_QT4_YELL_MODELS_HEADER - -#endif // _TelepathyQt4Yell_Models_AvatarImageProvider_HEADER_GUARD_ -// vim:set ft=cpp: diff --git a/TelepathyQt4Yell/Models/CMakeLists.txt b/TelepathyQt4Yell/Models/CMakeLists.txt index 140c444..4eb3629 100644 --- a/TelepathyQt4Yell/Models/CMakeLists.txt +++ b/TelepathyQt4Yell/Models/CMakeLists.txt @@ -6,61 +6,37 @@ add_definitions(-DBUILDING_TELEPATHY_QT4_YELL_MODELS) # Set source files set(telepathy_qt4_yell_models_SRCS abstract-conversation-model.cpp - accounts-model.cpp - accounts-model-item.cpp - avatar-image-provider.cpp call-event-item.cpp - contact-model-item.cpp custom-event-item.cpp event-item.cpp - flat-model-proxy.cpp session-conversation-model.cpp text-event-item.cpp - tree-node.cpp ) set(telepathy_qt4_yell_models_MOC_SRCS abstract-conversation-model.h - accounts-model.h - accounts-model-item.h - avatar-image-provider.h call-event-item.h - contact-model-item.h custom-event-item.h event-item.h - flat-model-proxy.h session-conversation-model.h text-event-item.h - tree-node.h ) set(telepathy_qt4_yell_models_HEADERS AbstractConversationModel - AccountsModel - AccountsModelItem - AvatarImageProvider CallEventItem - ContactModelItem CustomEventItem EventItem - FlatModelProxy Global SessionConversationModel TextEventItem - TreeNode abstract-conversation-model.h - accounts-model.h - accounts-model-item.h - avatar-image-provider.h call-event-item.h - contact-model-item.h custom-event-item.h event-item.h - flat-model-proxy.h global.h session-conversation-model.h text-event-item.h - tree-node.h ) tpqt4_generate_mocs(${telepathy_qt4_yell_models_MOC_SRCS}) diff --git a/TelepathyQt4Yell/Models/ContactModelItem b/TelepathyQt4Yell/Models/ContactModelItem deleted file mode 100644 index 73082b0..0000000 --- a/TelepathyQt4Yell/Models/ContactModelItem +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef _TelepathyQt4Yell_Models_ContactModelItem_HEADER_GUARD_ -#define _TelepathyQt4Yell_Models_ContactModelItem_HEADER_GUARD_ - -#ifndef IN_TELEPATHY_QT4_YELL_MODELS_HEADER -#define IN_TELEPATHY_QT4_YELL_MODELS_HEADER -#endif - -#include <TelepathyQt4Yell/Models/contact-model-item.h> - -#undef IN_TELEPATHY_QT4_YELL_MODELS_HEADER - -#endif // _TelepathyQt4Yell_Models_ContactModelItem_HEADER_GUARD_ -// vim:set ft=cpp: diff --git a/TelepathyQt4Yell/Models/FlatModelProxy b/TelepathyQt4Yell/Models/FlatModelProxy deleted file mode 100644 index 370e396..0000000 --- a/TelepathyQt4Yell/Models/FlatModelProxy +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef _TelepathyQt4Yell_Models_FlatModelProxy_HEADER_GUARD_ -#define _TelepathyQt4Yell_Models_FlatModelProxy_HEADER_GUARD_ - -#ifndef IN_TELEPATHY_QT4_YELL_MODELS_HEADER -#define IN_TELEPATHY_QT4_YELL_MODELS_HEADER -#endif - -#include <TelepathyQt4Yell/Models/flat-model-proxy.h> - -#undef IN_TELEPATHY_QT4_YELL_MODELS_HEADER - -#endif // _TelepathyQt4Yell_Models_FlatModelProxy_HEADER_GUARD_ -// vim:set ft=cpp: - diff --git a/TelepathyQt4Yell/Models/TreeNode b/TelepathyQt4Yell/Models/TreeNode deleted file mode 100644 index 963d47b..0000000 --- a/TelepathyQt4Yell/Models/TreeNode +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef _TelepathyQt4Yell_Models_TreeNode_HEADER_GUARD_ -#define _TelepathyQt4Yell_Models_TreeNode_HEADER_GUARD_ - -#ifndef IN_TELEPATHY_QT4_YELL_MODELS_HEADER -#define IN_TELEPATHY_QT4_YELL_MODELS_HEADER -#endif - -#include <TelepathyQt4Yell/Models/tree-node.h> - -#undef IN_TELEPATHY_QT4_YELL_MODELS_HEADER - -#endif // _TelepathyQt4Yell_Models_TreeNode_HEADER_GUARD_ -// vim:set ft=cpp: diff --git a/TelepathyQt4Yell/Models/accounts-model-item.cpp b/TelepathyQt4Yell/Models/accounts-model-item.cpp deleted file mode 100644 index 4e423a3..0000000 --- a/TelepathyQt4Yell/Models/accounts-model-item.cpp +++ /dev/null @@ -1,473 +0,0 @@ -/* - * This file is part of TelepathyQt4Yell Models - * - * Copyright (C) 2010 Collabora Ltd. <http://www.collabora.co.uk/> - * - * 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.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include <TelepathyQt4Yell/Models/AccountsModelItem> - -#include "TelepathyQt4Yell/Models/_gen/accounts-model-item.moc.hpp" - -#include <TelepathyQt4Yell/Models/AccountsModel> -#include <TelepathyQt4Yell/Models/AvatarImageProvider> -#include <TelepathyQt4Yell/Models/ContactModelItem> - -#include <TelepathyQt4/Account> -#include <TelepathyQt4/ContactManager> - -namespace Tpy -{ - -struct TELEPATHY_QT4_YELL_MODELS_NO_EXPORT AccountsModelItem::Private -{ - Private(const Tp::AccountPtr &account) - : mAccount(account) - { - } - - void setStatus(const QString &value); - void setStatusMessage(const QString &value); - - Tp::AccountPtr mAccount; - Tp::ContactManagerPtr mManager; -}; - -void AccountsModelItem::Private::setStatus(const QString &value) -{ - Tp::Presence presence = mAccount->currentPresence().barePresence(); - presence.setStatus(Tp::ConnectionPresenceTypeUnset, value, QString()); - mAccount->setRequestedPresence(presence); -} - -void AccountsModelItem::Private::setStatusMessage(const QString &value) -{ - Tp::Presence presence = mAccount->currentPresence().barePresence(); - presence.setStatus(Tp::ConnectionPresenceTypeUnset, QString(), value); - mAccount->setRequestedPresence(presence); -} - -AccountsModelItem::AccountsModelItem(const Tp::AccountPtr &account) - : mPriv(new Private(account)) -{ - connect(mPriv->mAccount.data(), - SIGNAL(removed()), - SLOT(onRemoved())); - connect(mPriv->mAccount.data(), - SIGNAL(serviceNameChanged(QString)), - SLOT(onChanged())); - connect(mPriv->mAccount.data(), - SIGNAL(serviceNameChanged(QString)), - SIGNAL(serviceNameChanged(QString))); - connect(mPriv->mAccount.data(), - SIGNAL(profileChanged(Tp::ProfilePtr)), - SLOT(onChanged())); - connect(mPriv->mAccount.data(), - SIGNAL(profileChanged(Tp::ProfilePtr)), - SIGNAL(profileChanged(Tp::ProfilePtr))); - connect(mPriv->mAccount.data(), - SIGNAL(displayNameChanged(QString)), - SLOT(onChanged())); - connect(mPriv->mAccount.data(), - SIGNAL(displayNameChanged(QString)), - SIGNAL(displayNameChanged(QString))); - connect(mPriv->mAccount.data(), - SIGNAL(iconNameChanged(QString)), - SLOT(onChanged())); - connect(mPriv->mAccount.data(), - SIGNAL(iconNameChanged(QString)), - SIGNAL(iconNameChanged(QString))); - connect(mPriv->mAccount.data(), - SIGNAL(nicknameChanged(QString)), - SLOT(onChanged())); - connect(mPriv->mAccount.data(), - SIGNAL(nicknameChanged(QString)), - SIGNAL(nicknameChanged(QString))); - connect(mPriv->mAccount.data(), - SIGNAL(normalizedNameChanged(QString)), - SLOT(onChanged())); - connect(mPriv->mAccount.data(), - SIGNAL(normalizedNameChanged(QString)), - SIGNAL(normalizedNameChanged(QString))); - connect(mPriv->mAccount.data(), - SIGNAL(validityChanged(bool)), - SLOT(onChanged())); - connect(mPriv->mAccount.data(), - SIGNAL(validityChanged(bool)), - SIGNAL(validityChanged(bool))); - connect(mPriv->mAccount.data(), - SIGNAL(stateChanged(bool)), - SLOT(onChanged())); - connect(mPriv->mAccount.data(), - SIGNAL(stateChanged(bool)), - SIGNAL(stateChanged(bool))); - connect(mPriv->mAccount.data(), - SIGNAL(capabilitiesChanged(Tp::ConnectionCapabilities)), - SLOT(onChanged())); - connect(mPriv->mAccount.data(), - SIGNAL(capabilitiesChanged(Tp::ConnectionCapabilities)), - SIGNAL(capabilitiesChanged(Tp::ConnectionCapabilities))); - connect(mPriv->mAccount.data(), - SIGNAL(connectsAutomaticallyPropertyChanged(bool)), - SLOT(onChanged())); - connect(mPriv->mAccount.data(), - SIGNAL(connectsAutomaticallyPropertyChanged(bool)), - SIGNAL(connectsAutomaticallyPropertyChanged(bool))); - connect(mPriv->mAccount.data(), - SIGNAL(parametersChanged(QVariantMap)), - SLOT(onChanged())); - connect(mPriv->mAccount.data(), - SIGNAL(parametersChanged(QVariantMap)), - SIGNAL(parametersChanged(QVariantMap))); - connect(mPriv->mAccount.data(), - SIGNAL(changingPresence(bool)), - SLOT(onChanged())); - connect(mPriv->mAccount.data(), - SIGNAL(changingPresence(bool)), - SIGNAL(changingPresence(bool))); - connect(mPriv->mAccount.data(), - SIGNAL(automaticPresenceChanged(Tp::Presence)), - SLOT(onChanged())); - connect(mPriv->mAccount.data(), - SIGNAL(automaticPresenceChanged(Tp::Presence)), - SIGNAL(automaticPresenceChanged(Tp::Presence))); - connect(mPriv->mAccount.data(), - SIGNAL(currentPresenceChanged(Tp::Presence)), - SLOT(onChanged())); - connect(mPriv->mAccount.data(), - SIGNAL(currentPresenceChanged(Tp::Presence)), - SIGNAL(currentPresenceChanged(Tp::Presence))); - connect(mPriv->mAccount.data(), - SIGNAL(requestedPresenceChanged(Tp::Presence)), - SLOT(onChanged())); - connect(mPriv->mAccount.data(), - SIGNAL(requestedPresenceChanged(Tp::Presence)), - SIGNAL(requestedPresenceChanged(Tp::Presence))); - connect(mPriv->mAccount.data(), - SIGNAL(onlinenessChanged(bool)), - SLOT(onChanged())); - connect(mPriv->mAccount.data(), - SIGNAL(onlinenessChanged(bool)), - SIGNAL(onlinenessChanged(bool))); - connect(mPriv->mAccount.data(), - SIGNAL(avatarChanged(Tp::Avatar)), - SLOT(onChanged())); - connect(mPriv->mAccount.data(), - SIGNAL(avatarChanged(Tp::Avatar)), - SIGNAL(avatarChanged(Tp::Avatar))); - connect(mPriv->mAccount.data(), - SIGNAL(onlinenessChanged(bool)), - SLOT(onChanged())); - connect(mPriv->mAccount.data(), - SIGNAL(onlinenessChanged(bool)), - SIGNAL(onlinenessChanged(bool))); - connect(mPriv->mAccount.data(), - SIGNAL(connectionChanged(Tp::ConnectionPtr)), - SLOT(onConnectionChanged(Tp::ConnectionPtr))); -} - -AccountsModelItem::~AccountsModelItem() -{ - delete mPriv; -} - -QVariant AccountsModelItem::data(int role) const -{ - switch (role) { - case AccountsModel::ItemRole: - return QVariant::fromValue( - const_cast<QObject *>( - static_cast<const QObject *>(this))); - case AccountsModel::IdRole: - return mPriv->mAccount->uniqueIdentifier(); - case AccountsModel::AvatarRole: - return AvatarImageProvider::urlFor(mPriv->mAccount); - case AccountsModel::ValidRole: - return mPriv->mAccount->isValid(); - case AccountsModel::EnabledRole: - return mPriv->mAccount->isEnabled(); - case AccountsModel::ConnectionManagerNameRole: - return mPriv->mAccount->cmName(); - case AccountsModel::ProtocolNameRole: - return mPriv->mAccount->protocolName(); - case AccountsModel::DisplayNameRole: - case Qt::DisplayRole: - return mPriv->mAccount->displayName(); - case AccountsModel::IconRole: - return mPriv->mAccount->iconName(); - case AccountsModel::NicknameRole: - return mPriv->mAccount->nickname(); - case AccountsModel::ConnectsAutomaticallyRole: - return mPriv->mAccount->connectsAutomatically(); - case AccountsModel::ChangingPresenceRole: - return mPriv->mAccount->isChangingPresence(); - case AccountsModel::AutomaticPresenceRole: - return mPriv->mAccount->automaticPresence().status(); - case AccountsModel::AutomaticPresenceTypeRole: - return mPriv->mAccount->automaticPresence().type(); - case AccountsModel::AutomaticPresenceStatusMessageRole: - return mPriv->mAccount->automaticPresence().statusMessage(); - case AccountsModel::CurrentPresenceRole: - return mPriv->mAccount->currentPresence().status(); - case AccountsModel::CurrentPresenceTypeRole: - return mPriv->mAccount->currentPresence().type(); - case AccountsModel::CurrentPresenceStatusMessageRole: - return mPriv->mAccount->currentPresence().statusMessage(); - case AccountsModel::RequestedPresenceRole: - return mPriv->mAccount->requestedPresence().status(); - case AccountsModel::RequestedPresenceTypeRole: - return mPriv->mAccount->requestedPresence().type(); - case AccountsModel::RequestedPresenceStatusMessageRole: - return mPriv->mAccount->requestedPresence().statusMessage(); - case AccountsModel::ConnectionStatusRole: { - if (!mPriv->mAccount->connection().isNull() - && mPriv->mAccount->connection()->isValid()) { - return mPriv->mAccount->connection()->status(); - } else { - return Tp::ConnectionStatusDisconnected; - } - } - case AccountsModel::ConnectionStatusReasonRole: { - if (!mPriv->mAccount->connection().isNull()) { - return mPriv->mAccount->connection()->statusReason(); - } else { - return mPriv->mAccount->connectionStatusReason(); - } - } - case AccountsModel::ContactListStateRole: { - if (!mPriv->mManager.isNull()) { - return mPriv->mManager->state(); - } else { - return Tp::ContactListStateNone; - } - } - default: - return QVariant(); - } -} - -bool AccountsModelItem::setData(int role, const QVariant &value) -{ - switch (role) { - case AccountsModel::EnabledRole: - setEnabled(value.toBool()); - return true; - case AccountsModel::RequestedPresenceRole: - mPriv->setStatus(value.toString()); - return true; - case AccountsModel::RequestedPresenceStatusMessageRole: - mPriv->setStatusMessage(value.toString()); - return true; - case AccountsModel::NicknameRole: - setNickname(value.toString()); - return true; - default: - return false; - } -} - -Tp::AccountPtr AccountsModelItem::account() const -{ - return mPriv->mAccount; -} - -void AccountsModelItem::setEnabled(bool value) -{ - mPriv->mAccount->setEnabled(value); -} - -void AccountsModelItem::setNickname(const QString &value) -{ - mPriv->mAccount->setNickname(value); -} - -void AccountsModelItem::setAutomaticPresence(int type, const QString &status, const QString &statusMessage) -{ - Tp::Presence presence; - presence.setStatus((Tp::ConnectionPresenceType) type, status, statusMessage); - mPriv->mAccount->setAutomaticPresence(presence); -} - -void AccountsModelItem::setRequestedPresence(int type, const QString &status, const QString &statusMessage) -{ - Tp::Presence presence; - presence.setStatus((Tp::ConnectionPresenceType) type, status, statusMessage); - mPriv->mAccount->setRequestedPresence(presence); -} - -bool AccountsModelItem::isPresenceSupported(int type) const -{ - Tp::PresenceSpecList list = mPriv->mAccount->allowedPresenceStatuses(); - Q_FOREACH (const Tp::PresenceSpec &p, list) { - if (p.presence().type() == type && p.maySetOnSelf()) - return true; - } - return false; -} - -void AccountsModelItem::onRemoved() -{ - int index = parent()->indexOf(this); - emit childrenRemoved(parent(), index, index); -} - -void AccountsModelItem::onChanged() -{ - emit changed(this); -} - -void AccountsModelItem::onContactsChanged(const Tp::Contacts &addedContacts, - const Tp::Contacts &removedContacts) -{ - foreach (const Tp::ContactPtr &contact, removedContacts) { - for (int i = 0; i < size(); ++i) { - ContactModelItem *item = qobject_cast<ContactModelItem *>(childAt(i)); - if (item->contact() == contact) { - emit childrenRemoved(this, i, i); - break; - } - } - } - - // get the list of contact ids in the children - QStringList idList; - int numElems = size(); - for (int i = 0; i < numElems; ++i) { - ContactModelItem *item = qobject_cast<ContactModelItem *>(childAt(i)); - if (item) { - idList.append(item->contact()->id()); - } - } - - QList<TreeNode *> newNodes; - foreach (const Tp::ContactPtr &contact, addedContacts) { - if (!idList.contains(contact->id())) { - newNodes.append(new ContactModelItem(contact)); - } - } - if (newNodes.count()) { - emit childrenAdded(this, newNodes); - } -} - -void AccountsModelItem::onStatusChanged(Tp::ConnectionStatus status) -{ - onChanged(); - emit connectionStatusChanged(mPriv->mAccount->uniqueIdentifier(), status); -} - -void AccountsModelItem::onConnectionChanged(const Tp::ConnectionPtr &connection) -{ - // if the connection is invalid or disconnected, clear the contacts list - if (connection.isNull() - || !connection->isValid() - || connection->status() == Tp::ConnectionStatusDisconnected) { - if (size() > 0) { - emit childrenRemoved(this, 0, size() - 1); - } - return; - } - - connect(connection.data(), SIGNAL(statusChanged(Tp::ConnectionStatus)), - SLOT(onStatusChanged(Tp::ConnectionStatus))); - connect(connection.data(), SIGNAL(invalidated(Tp::DBusProxy*,QString,QString)), - SLOT(onConnectionInvalidated())); - onStatusChanged(connection->status()); - - mPriv->mManager = connection->contactManager(); - connect(mPriv->mManager.data(), - SIGNAL(allKnownContactsChanged(Tp::Contacts,Tp::Contacts, - Tp::Channel::GroupMemberChangeDetails)), - SLOT(onContactsChanged(Tp::Contacts,Tp::Contacts))); - connect(mPriv->mManager.data(), - SIGNAL(stateChanged(Tp::ContactListState)), - SLOT(onContactManagerStateChanged(Tp::ContactListState))); - onContactManagerStateChanged(mPriv->mManager->state()); -} - -void AccountsModelItem::onConnectionInvalidated() -{ - onStatusChanged(Tp::ConnectionStatusDisconnected); -} - -void AccountsModelItem::onContactManagerStateChanged(Tp::ContactListState state) -{ - onChanged(); - if (state == Tp::ContactListStateSuccess) { - clearContacts(); - addKnownContacts(); - } -} - -void AccountsModelItem::clearContacts() -{ - if (!mPriv->mAccount->connection().isNull() && - mPriv->mAccount->connection()->isValid()) { - Tp::ContactManagerPtr manager = mPriv->mAccount->connection()->contactManager(); - Tp::Contacts contacts = manager->allKnownContacts(); - - // remove the items no longer present - for (int i = 0; i < size(); ++i) { - bool exists = false; - ContactModelItem *item = qobject_cast<ContactModelItem *>(childAt(i)); - if (item) { - Tp::ContactPtr itemContact = item->contact(); - if (contacts.contains(itemContact)) { - exists = true; - } - } - if (!exists) { - emit childrenRemoved(this, i, i); - } - } - } else { - emit childrenRemoved(this, 0, size() - 1); - } -} - -void AccountsModelItem::addKnownContacts() -{ - // reload the known contacts if it has a connection - QList<TreeNode *> newNodes; - if (!mPriv->mAccount->connection().isNull() && - mPriv->mAccount->connection()->isValid()) { - Tp::ContactManagerPtr manager = mPriv->mAccount->connection()->contactManager(); - Tp::Contacts contacts = manager->allKnownContacts(); - - // get the list of contact ids in the children - QStringList idList; - int numElems = size(); - for (int i = 0; i < numElems; ++i) { - ContactModelItem *item = qobject_cast<ContactModelItem *>(childAt(i)); - if (item) { - idList.append(item->contact()->id()); - } - } - - // only add the contact item if it is new - foreach (const Tp::ContactPtr &contact, contacts) { - if (!idList.contains(contact->id())) { - newNodes.append(new ContactModelItem(contact)); - } - } - } - - if (newNodes.count() > 0) { - emit childrenAdded(this, newNodes); - } -} - -} diff --git a/TelepathyQt4Yell/Models/accounts-model-item.h b/TelepathyQt4Yell/Models/accounts-model-item.h deleted file mode 100644 index 29c613f..0000000 --- a/TelepathyQt4Yell/Models/accounts-model-item.h +++ /dev/null @@ -1,106 +0,0 @@ -/* - * This file is part of TelepathyQt4Yell Models - * - * Copyright (C) 2010 Collabora Ltd. <http://www.collabora.co.uk/> - * - * 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.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#ifndef _TelepathyQt4Yell_Models_accounts_model_item_h_HEADER_GUARD_ -#define _TelepathyQt4Yell_Models_accounts_model_item_h_HEADER_GUARD_ - -#ifndef IN_TELEPATHY_QT4_YELL_MODELS_HEADER -#error IN_TELEPATHY_QT4_YELL_MODELS_HEADER -#endif - -#include <TelepathyQt4Yell/Models/TreeNode> - -#include <TelepathyQt4/ConnectionCapabilities> -#include <TelepathyQt4/Constants> -#include <TelepathyQt4/Contact> -#include <TelepathyQt4/Types> - -namespace Tpy -{ - -class TELEPATHY_QT4_YELL_MODELS_EXPORT AccountsModelItem : public TreeNode -{ - Q_OBJECT - Q_DISABLE_COPY(AccountsModelItem) - -public: - AccountsModelItem(const Tp::AccountPtr &account); - virtual ~AccountsModelItem(); - - Q_INVOKABLE virtual QVariant data(int role) const; - virtual bool setData(int role, const QVariant &value); - Q_INVOKABLE Tp::AccountPtr account() const; - - void setEnabled(bool value); - - Q_INVOKABLE void setNickname(const QString &value); - - Q_INVOKABLE void setAutomaticPresence(int type, const QString &status, const QString &statusMessage); - Q_INVOKABLE void setRequestedPresence(int type, const QString &status, const QString &statusMessage); - Q_INVOKABLE bool isPresenceSupported(int type) const; - - void clearContacts(); - -public Q_SLOTS: - void addKnownContacts(); - void onConnectionChanged(const Tp::ConnectionPtr &connection); - void onConnectionInvalidated(); - -Q_SIGNALS: - void serviceNameChanged(const QString &serviceName); - void profileChanged(const Tp::ProfilePtr &profile); - void displayNameChanged(const QString &displayName); - void iconNameChanged(const QString &iconName); - void nicknameChanged(const QString &nickname); - void normalizedNameChanged(const QString &normalizedName); - void validityChanged(bool validity); - void stateChanged(bool state); - void capabilitiesChanged(const Tp::ConnectionCapabilities &capabilities); - void connectsAutomaticallyPropertyChanged(bool connectsAutomatically); - void firstOnline(); - void parametersChanged(const QVariantMap ¶meters); - void changingPresence(bool value); - void automaticPresenceChanged(const Tp::Presence &automaticPresence); - void currentPresenceChanged(const Tp::Presence ¤tPresence); - void requestedPresenceChanged(const Tp::Presence &requestedPresence); - void onlinenessChanged(bool online); - void avatarChanged(const Tp::Avatar &avatar); - void connectionStatusChanged(const QString &accountId, int status); - -private Q_SLOTS: - void onRemoved(); - - void onChanged(); - - void onStatusChanged(Tp::ConnectionStatus status); - - void onContactManagerStateChanged(Tp::ContactListState state); - void onContactsChanged(const Tp::Contacts &added, - const Tp::Contacts &removed); - -private: - struct Private; - friend struct Private; - Private *mPriv; -}; - -} - -#endif // _TelepathyQt4Yell_Models_accounts_model_item_h_HEADER_GUARD_ diff --git a/TelepathyQt4Yell/Models/accounts-model.cpp b/TelepathyQt4Yell/Models/accounts-model.cpp deleted file mode 100644 index 2e655d9..0000000 --- a/TelepathyQt4Yell/Models/accounts-model.cpp +++ /dev/null @@ -1,326 +0,0 @@ -/* - * This file is part of TelepathyQt4Yell Models - * - * Copyright (C) 2010 Collabora Ltd. <http://www.collabora.co.uk/> - * - * 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.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include <TelepathyQt4Yell/Models/AccountsModel> - -#include "TelepathyQt4Yell/Models/_gen/accounts-model.moc.hpp" - -#include <TelepathyQt4/ContactManager> -#include <TelepathyQt4/PendingReady> - -#include <TelepathyQt4Yell/Models/AccountsModelItem> -#include <TelepathyQt4Yell/Models/ContactModelItem> - -namespace Tpy -{ - -struct TELEPATHY_QT4_YELL_MODELS_NO_EXPORT AccountsModel::Private -{ - Private(const Tp::AccountManagerPtr &am) - : mAM(am) - { - } - - TreeNode *node(const QModelIndex &index) const; - - Tp::AccountManagerPtr mAM; - TreeNode *mTree; -}; - -TreeNode *AccountsModel::Private::node(const QModelIndex &index) const -{ - TreeNode *node = reinterpret_cast<TreeNode *>(index.internalPointer()); - return node ? node : mTree; -} - -AccountsModel::AccountsModel(const Tp::AccountManagerPtr &am, QObject *parent) - : QAbstractItemModel(parent), - mPriv(new AccountsModel::Private(am)) -{ - mPriv->mTree = new TreeNode; - connect(mPriv->mTree, - SIGNAL(changed(Tpy::TreeNode*)), - SLOT(onItemChanged(Tpy::TreeNode*))); - connect(mPriv->mTree, - SIGNAL(childrenAdded(Tpy::TreeNode*,QList<Tpy::TreeNode*>)), - SLOT(onItemsAdded(Tpy::TreeNode*,QList<Tpy::TreeNode*>))); - connect(mPriv->mTree, - SIGNAL(childrenRemoved(Tpy::TreeNode*,int,int)), - SLOT(onItemsRemoved(Tpy::TreeNode*,int,int))); - connect(mPriv->mAM.data(), - SIGNAL(newAccount(Tp::AccountPtr)), - SLOT(onNewAccount(Tp::AccountPtr))); - - QHash<int, QByteArray> roles; - roles[ItemRole] = "item"; - roles[IdRole] = "id"; - roles[ValidRole] = "valid"; - roles[EnabledRole] = "enabled"; - roles[ConnectionManagerNameRole] = "connectionManager"; - roles[ProtocolNameRole] = "protocol"; - roles[DisplayNameRole] = "displayName"; - roles[IconRole] = "icon"; - roles[NicknameRole] = "nickname"; - roles[ConnectsAutomaticallyRole] = "connectsAutomatically"; - roles[ChangingPresenceRole] = "changingPresence"; - roles[AutomaticPresenceRole] = "automaticStatus"; - roles[AutomaticPresenceTypeRole] = "automaticStatusType"; - roles[AutomaticPresenceStatusMessageRole] = "automaticStatusMessage"; - roles[CurrentPresenceRole] = "status"; - roles[CurrentPresenceTypeRole] = "statusType"; - roles[CurrentPresenceStatusMessageRole] = "statusMessage"; - roles[RequestedPresenceRole] = "requestedStatus"; - roles[RequestedPresenceTypeRole] = "requestedStatusType"; - roles[RequestedPresenceStatusMessageRole] = "requestedStatusMessage"; - roles[ConnectionStatusRole] = "connectionStatus"; - roles[ConnectionStatusReasonRole] = "connectionStatusReason"; - roles[ContactListStateRole] = "contactListState"; - roles[AliasRole] = "aliasName"; - roles[AvatarRole] = "avatar"; - roles[PresenceStatusRole] = "presenceStatus"; - roles[PresenceTypeRole] = "presenceType"; - roles[PresenceMessageRole] = "presenceMessage"; - roles[SubscriptionStateRole] = "subscriptionState"; - roles[PublishStateRole] = "publishState"; - roles[BlockedRole] = "blocked"; - roles[GroupsRole] = "groups"; - roles[TextChatCapabilityRole] = "textChat"; - roles[StreamedMediaCallCapabilityRole] = "streamedMediaCall"; - roles[StreamedMediaAudioCallCapabilityRole] = "streamedMediaAudioCall"; - roles[StreamedMediaVideoCallCapabilityRole] = "streamedMediaVideoCall"; - roles[StreamedMediaVideoCallWithAudioCapabilityRole] = "streamedMediaVideoCallWithAudio"; - roles[StreamedMediaUpgradeCallCapabilityRole] = "streamedMediaUpgradeCall"; - roles[MediaCallCapabilityRole] = "mediaCall"; - roles[AudioCallCapabilityRole] = "audioCall"; - roles[VideoCallCapabilityRole] = "videoCall"; - roles[VideoCallWithAudioCapabilityRole] = "videoCallWithAudio"; - roles[UpgradeCallCapabilityRole] = "upgradeCall"; - roles[FileTransferCapabilityRole] = "fileTransfer"; - setRoleNames(roles); - - QTimer::singleShot(0, this, SLOT(onLoadAccounts())); -} - -AccountsModel::~AccountsModel() -{ - delete mPriv->mTree; - delete mPriv; -} - -void AccountsModel::onLoadAccounts() -{ - // load existing accounts - foreach (Tp::AccountPtr account, mPriv->mAM->allAccounts()) { - onNewAccount(account); - } -} - -void AccountsModel::onNewAccount(const Tp::AccountPtr &account) -{ - AccountsModelItem *item = new AccountsModelItem(account); - connect(item, SIGNAL(connectionStatusChanged(QString,int)), - this, SIGNAL(accountConnectionStatusChanged(QString,int))); - 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()); - } - emit newAccountItem(account->uniqueIdentifier()); -} - -void AccountsModel::onItemChanged(TreeNode *node) -{ - QModelIndex accountIndex = index(node); - emit dataChanged(accountIndex, accountIndex); -} - -void AccountsModel::onItemsAdded(Tpy::TreeNode *parent, const QList<Tpy::TreeNode *> &nodes) -{ - QModelIndex parentIndex = index(parent); - int currentSize = rowCount(parentIndex); - //debug() << "adding rows from" << currentSize << "to" << (currentSize + nodes.size() - 1); - beginInsertRows(parentIndex, currentSize, currentSize + nodes.size() - 1); - foreach (TreeNode *node, nodes) { - parent->addChild(node); - } - endInsertRows(); - emit accountCountChanged(); -} - -void AccountsModel::onItemsRemoved(TreeNode *parent, int first, int last) -{ - QModelIndex parentIndex = index(parent); - QList<TreeNode *> removedItems; - beginRemoveRows(parentIndex, first, last); - for (int i = last; i >= first; i--) { - parent->childAt(i)->remove(); - } - endRemoveRows(); - emit accountCountChanged(); -} - -int AccountsModel::accountCount() const -{ - return mPriv->mTree->size(); -} - -QObject *AccountsModel::accountItemForId(const QString &id) const -{ - for (int i = 0; i < mPriv->mTree->size(); ++i) { - AccountsModelItem *item = qobject_cast<AccountsModelItem*>(mPriv->mTree->childAt(i)); - if (!item) { - continue; - } - - if (item->data(IdRole) == id) { - return item; - } - } - - return 0; -} - -QObject *AccountsModel::contactItemForId(const QString &accountId, const QString &contactId) const -{ - AccountsModelItem *accountItem = qobject_cast<AccountsModelItem*>(accountItemForId(accountId)); - if (!accountItem) { - return 0; - } - - for (int i = 0; i < accountItem->size(); ++i) { - ContactModelItem *item = qobject_cast<ContactModelItem*>(accountItem->childAt(i)); - if (!item) { - continue; - } - - if (item->data(IdRole) == contactId) { - return item; - } - } - - return 0; -} - -int AccountsModel::columnCount(const QModelIndex &parent) const -{ - return 1; -} - -int AccountsModel::rowCount(const QModelIndex &parent) const -{ - return mPriv->node(parent)->size(); -} - -QVariant AccountsModel::data(const QModelIndex &index, int role) const -{ - if (!index.isValid()) { - return QVariant(); - } - - return mPriv->node(index)->data(role); -} - -Tp::AccountPtr AccountsModel::accountForIndex(const QModelIndex &index) const -{ - TreeNode *accountNode = mPriv->node(index); - AccountsModelItem *item = qobject_cast<AccountsModelItem *>(accountNode); - if (item) { - return item->account(); - } else { - return Tp::AccountPtr(); - } -} - -Tp::AccountPtr AccountsModel::accountForContactIndex(const QModelIndex &index) const -{ - TreeNode *contactNode = mPriv->node(index); - AccountsModelItem *item = qobject_cast<AccountsModelItem *>(contactNode->parent()); - if (item) { - return item->account(); - } else { - return Tp::AccountPtr(); - } -} - -Tp::ContactPtr AccountsModel::contactForIndex(const QModelIndex& index) const -{ - TreeNode *contactNode = mPriv->node(index); - ContactModelItem *item = qobject_cast<ContactModelItem *>(contactNode); - if (item) { - return item->contact(); - } else { - return Tp::ContactPtr(); - } -} - -Qt::ItemFlags AccountsModel::flags(const QModelIndex &index) const -{ - if (index.isValid()) { - return Qt::ItemIsEnabled; - } - - return QAbstractItemModel::flags(index) | Qt::ItemIsEditable; -} - -bool AccountsModel::setData(const QModelIndex &index, const QVariant &value, int role) -{ - if (index.isValid()) { - mPriv->node(index)->setData(role, value); - } - - return false; -} - -QModelIndex AccountsModel::index(int row, int column, const QModelIndex &parent) const -{ - TreeNode *parentNode = mPriv->node(parent); - return createIndex(row, column, parentNode->childAt(row)); -} - -QModelIndex AccountsModel::index(TreeNode *node) const -{ - if (node->parent()) { - return createIndex(node->parent()->indexOf(node), 0, node); - } - else { - return QModelIndex(); - } -} - -QModelIndex AccountsModel::parent(const QModelIndex &index) const -{ - if (!index.isValid()) { - return QModelIndex(); - } - - TreeNode *currentNode = mPriv->node(index); - if (currentNode->parent()) { - return AccountsModel::index(currentNode->parent()); - } else { - // no parent: return root node - return QModelIndex(); - } -} - -} diff --git a/TelepathyQt4Yell/Models/accounts-model.h b/TelepathyQt4Yell/Models/accounts-model.h deleted file mode 100644 index 1c2ee66..0000000 --- a/TelepathyQt4Yell/Models/accounts-model.h +++ /dev/null @@ -1,144 +0,0 @@ -/* - * This file is part of TelepathyQt4Yell Models - * - * Copyright (C) 2010 Collabora Ltd. <http://www.collabora.co.uk/> - * - * 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.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#ifndef _TelepathyQt4Yell_Models_accounts_model_h_HEADER_GUARD_ -#define _TelepathyQt4Yell_Models_accounts_model_h_HEADER_GUARD_ - -#ifndef IN_TELEPATHY_QT4_YELL_MODELS_HEADER -#error IN_TELEPATHY_QT4_YELL_MODELS_HEADER -#endif - -#include <TelepathyQt4Yell/Models/AccountsModelItem> - -#include <TelepathyQt4/Account> -#include <TelepathyQt4/AccountManager> -#include <TelepathyQt4/TextChannel> -#include <TelepathyQt4/Types> - -#include <QAbstractListModel> - -namespace Tpy -{ - -class TELEPATHY_QT4_YELL_MODELS_EXPORT AccountsModel : public QAbstractItemModel -{ - Q_OBJECT - Q_DISABLE_COPY(AccountsModel) - Q_PROPERTY(int accountCount READ accountCount NOTIFY accountCountChanged) - Q_ENUMS(Role) - -public: - enum Role { - // general roles - ItemRole = Qt::UserRole, - AvatarRole, - IdRole, - - // account roles - ValidRole, - EnabledRole, - ConnectionManagerNameRole, - ProtocolNameRole, - DisplayNameRole, - IconRole, - NicknameRole, - ConnectsAutomaticallyRole, - ChangingPresenceRole, - AutomaticPresenceRole, - AutomaticPresenceTypeRole, - AutomaticPresenceStatusMessageRole, - CurrentPresenceRole, - CurrentPresenceTypeRole, - CurrentPresenceStatusMessageRole, - RequestedPresenceRole, - RequestedPresenceTypeRole, - RequestedPresenceStatusMessageRole, - ConnectionStatusRole, - ConnectionStatusReasonRole, - ContactListStateRole, - - // contact roles - AliasRole, - PresenceStatusRole, - PresenceTypeRole, - PresenceMessageRole, - SubscriptionStateRole, - PublishStateRole, - BlockedRole, - GroupsRole, - TextChatCapabilityRole, - StreamedMediaCallCapabilityRole, - StreamedMediaAudioCallCapabilityRole, - StreamedMediaVideoCallCapabilityRole, - StreamedMediaVideoCallWithAudioCapabilityRole, - StreamedMediaUpgradeCallCapabilityRole, - MediaCallCapabilityRole, - AudioCallCapabilityRole, - VideoCallCapabilityRole, - VideoCallWithAudioCapabilityRole, - UpgradeCallCapabilityRole, - FileTransferCapabilityRole, - - CustomRole // a placemark for custom roles in inherited models - }; - - explicit AccountsModel(const Tp::AccountManagerPtr &am, QObject *parent = 0); - virtual ~AccountsModel(); - - virtual int rowCount(const QModelIndex &parent = QModelIndex()) const; - virtual int columnCount(const QModelIndex &parent = QModelIndex()) const; - virtual QVariant data(const QModelIndex &index, int role) const; - Tp::AccountPtr accountForIndex(const QModelIndex &index) const; - Tp::AccountPtr accountForContactIndex(const QModelIndex &index) const; - Tp::ContactPtr contactForIndex(const QModelIndex &index) const; - - virtual Qt::ItemFlags flags(const QModelIndex &index) const; - virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole); - virtual QModelIndex index(int row, int column = 0, const QModelIndex &parent = QModelIndex()) const; - virtual QModelIndex index(TreeNode *node) const; - virtual QModelIndex parent(const QModelIndex &index) const; - - int accountCount() const; - Q_INVOKABLE QObject *accountItemForId(const QString &id) const; - Q_INVOKABLE QObject *contactItemForId(const QString &accountId, const QString &contactId) const; - -Q_SIGNALS: - void accountCountChanged(); - void accountConnectionStatusChanged(const QString &accountId, int status); - // expensive operation, updates all children from parents first .. last - void hierarchicalDataChanged(const QModelIndex &first, const QModelIndex &last); - void newAccountItem(const QString &accountId); - -protected Q_SLOTS: - void onLoadAccounts(); - void onNewAccount(const Tp::AccountPtr &account); - void onItemChanged(Tpy::TreeNode *node); - virtual void onItemsAdded(Tpy::TreeNode *parent, const QList<Tpy::TreeNode *> &nodes); - void onItemsRemoved(Tpy::TreeNode *parent, int first, int last); - -private: - struct Private; - friend struct Private; - Private *mPriv; -}; - -} - -#endif // _TelepathyQt4Yell_Models_accounts_model_h_HEADER_GUARD_ diff --git a/TelepathyQt4Yell/Models/avatar-image-provider.cpp b/TelepathyQt4Yell/Models/avatar-image-provider.cpp deleted file mode 100644 index 2ba8ff0..0000000 --- a/TelepathyQt4Yell/Models/avatar-image-provider.cpp +++ /dev/null @@ -1,72 +0,0 @@ -/* - * This file is part of TelepathyQt4Yell Models - * - * Copyright (C) 2010 Collabora Ltd. <http://www.collabora.co.uk/> - * - * 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.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include <TelepathyQt4Yell/Models/AvatarImageProvider> - -#include <TelepathyQt4/Account> -#include <TelepathyQt4/AccountManager> - -namespace Tpy -{ - -struct TELEPATHY_QT4_YELL_MODELS_NO_EXPORT AvatarImageProvider::Private -{ - Private(const Tp::AccountManagerPtr &am) - : mAM(am) - { - } - - Tp::AccountManagerPtr mAM; -}; - -AvatarImageProvider::AvatarImageProvider(const Tp::AccountManagerPtr &am) - : QDeclarativeImageProvider(Image), - mPriv(new Private(am)) -{ -} - -AvatarImageProvider::~AvatarImageProvider() -{ - delete mPriv; -} - -QString AvatarImageProvider::urlFor(const Tp::AccountPtr &account) -{ - return QString::fromLatin1("image://avatars/") + account->uniqueIdentifier(); -} - -void AvatarImageProvider::registerProvider(QDeclarativeEngine *engine, const Tp::AccountManagerPtr &am) -{ - engine->addImageProvider(QString::fromLatin1("avatars"), new AvatarImageProvider(am)); -} - -QImage AvatarImageProvider::requestImage(const QString &id, QSize *size, const QSize &requestedSize) -{ - QString path = QString::fromLatin1(TELEPATHY_ACCOUNT_OBJECT_PATH_BASE "/") + id; - Tp::AccountPtr account = mPriv->mAM->accountForPath(path); - QImage image; - image.loadFromData(account->avatar().avatarData); - if (size) { - *size = image.size(); - } - return image; -} - -} diff --git a/TelepathyQt4Yell/Models/avatar-image-provider.h b/TelepathyQt4Yell/Models/avatar-image-provider.h deleted file mode 100644 index f34b460..0000000 --- a/TelepathyQt4Yell/Models/avatar-image-provider.h +++ /dev/null @@ -1,59 +0,0 @@ -/* - * This file is part of TelepathyQt4Yell Models - * - * Copyright (C) 2010 Collabora Ltd. <http://www.collabora.co.uk/> - * - * 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.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#ifndef _TelepathyQt4Yell_Models_avatar_image_provider_h_HEADER_GUARD_ -#define _TelepathyQt4Yell_Models_avatar_image_provider_h_HEADER_GUARD_ - -#ifndef IN_TELEPATHY_QT4_YELL_MODELS_HEADER -#error IN_TELEPATHY_QT4_YELL_MODELS_HEADER -#endif - -#include <TelepathyQt4Yell/Models/Global> - -#include <TelepathyQt4/Types> - -#include <QDeclarativeImageProvider> -#include <QDeclarativeEngine> - -namespace Tpy -{ - -class TELEPATHY_QT4_YELL_MODELS_EXPORT AvatarImageProvider : public QDeclarativeImageProvider -{ - Q_DISABLE_COPY(AvatarImageProvider) - -public: - AvatarImageProvider(const Tp::AccountManagerPtr &am); - virtual ~AvatarImageProvider(); - - static QString urlFor(const Tp::AccountPtr &account); - static void registerProvider(QDeclarativeEngine *engine, const Tp::AccountManagerPtr &am); - - virtual QImage requestImage(const QString &id, QSize *size, const QSize &requestedSize); - -private: - struct Private; - friend struct Private; - Private *mPriv; -}; - -} - -#endif // _TelepathyQt4Yell_Models_avatar_image_provider_h_HEADER_GUARD_ diff --git a/TelepathyQt4Yell/Models/contact-model-item.cpp b/TelepathyQt4Yell/Models/contact-model-item.cpp deleted file mode 100644 index 9e1986c..0000000 --- a/TelepathyQt4Yell/Models/contact-model-item.cpp +++ /dev/null @@ -1,209 +0,0 @@ -/* - * This file is part of TelepathyQt4Yell Models - * - * Copyright (C) 2010 Collabora Ltd. <http://www.collabora.co.uk/> - * - * 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.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include <TelepathyQt4Yell/Models/ContactModelItem> - -#include "TelepathyQt4Yell/Models/_gen/contact-model-item.moc.hpp" - -#include <TelepathyQt4Yell/Models/AccountsModel> -#include <TelepathyQt4Yell/CallChannel> -#include <TelepathyQt4Yell/ContactCapabilities> -#include <TelepathyQt4Yell/RequestableChannelClassSpec> - -#include <TelepathyQt4/AvatarData> -#include <TelepathyQt4/ContactManager> -#include <TelepathyQt4/ContactCapabilities> - -#include <QImage> - -namespace Tpy -{ - -struct TELEPATHY_QT4_YELL_MODELS_NO_EXPORT ContactModelItem::Private -{ - Private(const Tp::ContactPtr &contact) - : mContact(contact), - mCallContactCaps(contact->capabilities().allClassSpecs(), - contact->capabilities().isSpecificToContact()) - { - } - - Tp::ContactPtr mContact; - Tpy::ContactCapabilities mCallContactCaps; -}; - -ContactModelItem::ContactModelItem(const Tp::ContactPtr &contact) - : mPriv(new Private(contact)) -{ - - connect(contact.data(), - SIGNAL(aliasChanged(QString)), - SLOT(onChanged())); - connect(contact.data(), - SIGNAL(avatarTokenChanged(QString)), - SLOT(onChanged())); - connect(contact.data(), - SIGNAL(avatarDataChanged(Tp::AvatarData)), - SLOT(onChanged())); - connect(contact.data(), - SIGNAL(presenceChanged(Tp::Presence)), - SLOT(onChanged())); - connect(contact.data(), - SIGNAL(capabilitiesChanged(Tp::ContactCapabilities)), - SLOT(onChanged())); - connect(contact.data(), - SIGNAL(capabilitiesChanged(Tp::ContactCapabilities)), - SLOT(onCapabilitiesChanged())); - connect(contact.data(), - SIGNAL(locationUpdated(Tp::LocationInfo)), - SLOT(onChanged())); - connect(contact.data(), - SIGNAL(infoFieldsChanged(Tp::Contact::InfoFields)), - SLOT(onChanged())); - connect(contact.data(), - SIGNAL(subscriptionStateChanged(Tp::Contact::PresenceState)), - SLOT(onChanged())); - connect(contact.data(), - SIGNAL(publishStateChanged(Tp::Contact::PresenceState,QString)), - SLOT(onChanged())); - connect(contact.data(), - SIGNAL(blockStatusChanged(bool)), - SLOT(onChanged())); -} - -ContactModelItem::~ContactModelItem() -{ - delete mPriv; -} - -QVariant ContactModelItem::data(int role) const -{ - switch (role) - { - case AccountsModel::ItemRole: - return QVariant::fromValue( - const_cast<QObject *>( - static_cast<const QObject *>(this))); - case AccountsModel::IdRole: - return mPriv->mContact->id(); - case Qt::DisplayRole: - case AccountsModel::AliasRole: - return mPriv->mContact->alias(); - case AccountsModel::PresenceStatusRole: - return mPriv->mContact->presence().status(); - case AccountsModel::PresenceTypeRole: - return mPriv->mContact->presence().type(); - case AccountsModel::PresenceMessageRole: - return mPriv->mContact->presence().statusMessage(); - case AccountsModel::SubscriptionStateRole: - return mPriv->mContact->subscriptionState(); - case AccountsModel::PublishStateRole: - return mPriv->mContact->publishState(); - case AccountsModel::BlockedRole: - return mPriv->mContact->isBlocked(); - case AccountsModel::GroupsRole: - return mPriv->mContact->groups(); - case AccountsModel::AvatarRole: - return mPriv->mContact->avatarData().fileName; - case Qt::DecorationRole: - return QImage(mPriv->mContact->avatarData().fileName); - case AccountsModel::TextChatCapabilityRole: - return mPriv->mContact->capabilities().textChats(); - case AccountsModel::StreamedMediaCallCapabilityRole: - return mPriv->mContact->capabilities().streamedMediaCalls(); - case AccountsModel::StreamedMediaAudioCallCapabilityRole: - return mPriv->mContact->capabilities().streamedMediaAudioCalls(); - case AccountsModel::StreamedMediaVideoCallCapabilityRole: - return mPriv->mContact->capabilities().streamedMediaVideoCalls(); - case AccountsModel::StreamedMediaVideoCallWithAudioCapabilityRole: - return mPriv->mContact->capabilities().streamedMediaVideoCallsWithAudio(); - case AccountsModel::StreamedMediaUpgradeCallCapabilityRole: - return mPriv->mContact->capabilities().upgradingStreamedMediaCalls(); - case AccountsModel::MediaCallCapabilityRole: - return mPriv->mCallContactCaps.mediaCalls(); - case AccountsModel::AudioCallCapabilityRole: - return mPriv->mCallContactCaps.audioCalls(); - case AccountsModel::VideoCallCapabilityRole: - return mPriv->mCallContactCaps.videoCalls(); - case AccountsModel::VideoCallWithAudioCapabilityRole: - return mPriv->mCallContactCaps.videoCallsWithAudio(); - case AccountsModel::UpgradeCallCapabilityRole: - return mPriv->mCallContactCaps.upgradingCalls(); - case AccountsModel::FileTransferCapabilityRole: { - foreach (const Tp::RequestableChannelClassSpec &rccSpec, mPriv->mContact->capabilities().allClassSpecs()) { - if (rccSpec.supports(Tp::RequestableChannelClassSpec::fileTransfer())) { - return true; - } - } - return false; - } - default: - break; - } - - return QVariant(); -} - -bool ContactModelItem::setData(int role, const QVariant &value) -{ - switch (role) { - case AccountsModel::PublishStateRole: { - Tp::Contact::PresenceState state; - state = (Tp::Contact::PresenceState) value.toInt(); - switch (state) { - case Tp::Contact::PresenceStateYes: - // authorize the contact and request its presence publication - mPriv->mContact->authorizePresencePublication(); - mPriv->mContact->requestPresenceSubscription(); - return true; - case Tp::Contact::PresenceStateNo: { - // reject the presence publication and remove the contact - mPriv->mContact->removePresencePublication(); - QList<Tp::ContactPtr> contacts; - contacts << mPriv->mContact; - mPriv->mContact->manager()->removeContacts(contacts); - return true; - } - default: - return false; - } - } - default: - return false; - } -} - -void ContactModelItem::onChanged() -{ - emit changed(this); -} - -Tp::ContactPtr ContactModelItem::contact() const -{ - return mPriv->mContact; -} - -void ContactModelItem::onCapabilitiesChanged() -{ - mPriv->mCallContactCaps.updateRequestableChannelClasses(mPriv->mContact->capabilities().allClassSpecs().bareClasses()); - emit capabilitiesChanged(); -} - -} diff --git a/TelepathyQt4Yell/Models/contact-model-item.h b/TelepathyQt4Yell/Models/contact-model-item.h deleted file mode 100644 index 4dbb5b1..0000000 --- a/TelepathyQt4Yell/Models/contact-model-item.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - * This file is part of TelepathyQt4Yell Models - * - * Copyright (C) 2010 Collabora Ltd. <http://www.collabora.co.uk/> - * - * 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.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#ifndef _TelepathyQt4Yell_Models_contact_model_item_h_HEADER_GUARD_ -#define _TelepathyQt4Yell_Models_contact_model_item_h_HEADER_GUARD_ - -#ifndef IN_TELEPATHY_QT4_YELL_MODELS_HEADER -#error IN_TELEPATHY_QT4_YELL_MODELS_HEADER -#endif - -#include <TelepathyQt4Yell/Models/TreeNode> - -#include <TelepathyQt4/Types> - -namespace Tpy -{ - -class TELEPATHY_QT4_YELL_MODELS_EXPORT ContactModelItem : public TreeNode -{ - Q_OBJECT - Q_DISABLE_COPY(ContactModelItem) - -public: - ContactModelItem(const Tp::ContactPtr &contact); - virtual ~ContactModelItem(); - - Q_INVOKABLE virtual QVariant data(int role) const; - Q_INVOKABLE virtual bool setData(int role, const QVariant &value); - - Tp::ContactPtr contact() const; - -Q_SIGNALS: - void capabilitiesChanged(); - -public Q_SLOTS: - void onChanged(); - void onCapabilitiesChanged(); - -private: - struct Private; - friend struct Private; - Private *mPriv; -}; - -} - -#endif // _TelepathyQt4Yell_Models_contact_model_item_h_HEADER_GUARD_ diff --git a/TelepathyQt4Yell/Models/flat-model-proxy.cpp b/TelepathyQt4Yell/Models/flat-model-proxy.cpp deleted file mode 100644 index dae0341..0000000 --- a/TelepathyQt4Yell/Models/flat-model-proxy.cpp +++ /dev/null @@ -1,200 +0,0 @@ -/* - * This file is part of TelepathyQt4Yell Models - * - * Copyright (C) 2010 Collabora Ltd. <http://www.collabora.co.uk/> - * - * 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.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include <TelepathyQt4Yell/Models/FlatModelProxy> - -#include "TelepathyQt4Yell/Models/_gen/flat-model-proxy.moc.hpp" -#include <TelepathyQt4Yell/Models/AccountsModel> - -namespace Tpy -{ - -struct TELEPATHY_QT4_YELL_MODELS_NO_EXPORT FlatModelProxy::Private -{ - int offsetOf(const FlatModelProxy *model, int index) const; -}; - -int FlatModelProxy::Private::offsetOf(const FlatModelProxy *model, int index) const -{ - int offset = 0; - for (int i = 0; i < index; i++) { - offset += model->sourceModel()->rowCount(model->sourceModel()->index(i, 0, QModelIndex())); - } - return offset; -} - -FlatModelProxy::FlatModelProxy(QAbstractItemModel *source) - : QAbstractProxyModel(source), - mPriv(new Private()) -{ - setSourceModel(source); - - connect(source, - SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)), - SLOT(onRowsAboutToBeInserted(QModelIndex,int,int))); - connect(source, - SIGNAL(rowsInserted(QModelIndex,int,int)), - SLOT(onRowsInserted(QModelIndex,int,int))); - connect(source, - SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)), - SLOT(onRowsAboutToBeRemoved(QModelIndex,int,int))); - connect(source, - SIGNAL(rowsRemoved(QModelIndex,int,int)), - SLOT(onRowsRemoved(QModelIndex,int,int))); - connect(source, - SIGNAL(rowsInserted(QModelIndex,int,int)), - SIGNAL(rowCountChanged())); - connect(source, - SIGNAL(rowsRemoved(QModelIndex,int,int)), - SIGNAL(rowCountChanged())); - connect(source, - SIGNAL(dataChanged(QModelIndex,QModelIndex)), - SLOT(onDataChanged(QModelIndex,QModelIndex))); - - Tpy::AccountsModel *accountsModel = qobject_cast<Tpy::AccountsModel *> (source); - if (accountsModel) { - connect(accountsModel, - SIGNAL(hierarchicalDataChanged(QModelIndex,QModelIndex)), - SLOT(onHierarchicalDataChanged(QModelIndex,QModelIndex))); - } -} - -FlatModelProxy::~FlatModelProxy() -{ - delete mPriv; -} - -QModelIndex FlatModelProxy::mapFromSource(const QModelIndex &index) const -{ - if (!index.isValid()) { - return QModelIndex(); - } - - QModelIndex parent = index.parent(); - - if (!parent.isValid()) { - return QModelIndex(); - } - - return createIndex(mPriv->offsetOf(this, parent.row()) + index.row(), index.column(), parent.row()); -} - -QModelIndex FlatModelProxy::mapToSource(const QModelIndex &index) const -{ - int parentRow = index.internalId(); - QModelIndex parent = sourceModel()->index(parentRow, 0, QModelIndex()); - int row = index.row() - mPriv->offsetOf(this, parent.row()); - return sourceModel()->index(row, index.column(), parent); -} - -QModelIndex FlatModelProxy::index(int row, int column, const QModelIndex &parent) const -{ - int count = 0; - for (int i = 0; i < sourceModel()->rowCount(QModelIndex()); i++) { - QModelIndex sourceIndex = sourceModel()->index(i, 0, QModelIndex()); - count += sourceModel()->rowCount(sourceIndex); - if (row < count) { - return createIndex(row, column, i); - } - } - - return QModelIndex(); -} - -QModelIndex FlatModelProxy::parent(const QModelIndex &index) const -{ - return QModelIndex(); -} - -int FlatModelProxy::columnCount(const QModelIndex &parent) const -{ - return 1; -} - -int FlatModelProxy::rowCount() const -{ - return rowCount(QModelIndex()); -} - -int FlatModelProxy::rowCount(const QModelIndex &parent) const -{ - return mPriv->offsetOf(this, sourceModel()->rowCount(QModelIndex())); -} - -void FlatModelProxy::onRowsAboutToBeInserted(const QModelIndex &index, int first, int last) -{ - if (index.isValid()) { - int offset = mPriv->offsetOf(this, index.row()); - int firstIndex = offset + first; - int lastIndex = offset + last; - - beginInsertRows(QModelIndex(), firstIndex, lastIndex); - } -} - -void FlatModelProxy::onRowsAboutToBeRemoved(const QModelIndex &index, int first, int last) -{ - if (index.isValid()) { - int offset = mPriv->offsetOf(this, index.row()); - int firstIndex = offset + first; - int lastIndex = offset + last; - - beginRemoveRows(QModelIndex(), firstIndex, lastIndex); - } -} - -void FlatModelProxy::onRowsInserted(const QModelIndex &index, int first, int last) -{ - if (index.isValid()) { - endInsertRows(); - } -} - -void FlatModelProxy::onRowsRemoved(const QModelIndex &index, int first, int last) -{ - if (index.isValid()) { - endRemoveRows(); - } -} - -void FlatModelProxy::onDataChanged(const QModelIndex &first, const QModelIndex &last) -{ - if (first.parent().isValid() && last.parent().isValid() && first.parent() == last.parent()) { - QModelIndex firstIndex = mapFromSource(first); - QModelIndex lastIndex = mapFromSource(last); - emit dataChanged(firstIndex, lastIndex); - } -} - -void FlatModelProxy::onHierarchicalDataChanged(const QModelIndex &first, const QModelIndex &last) -{ - if (!first.parent().isValid() && !last.parent().isValid()) { - int firstOffset = mPriv->offsetOf(this, first.row()); - int lastOffset = mPriv->offsetOf(this, last.row() + 1) - 1; - QModelIndex firstIndex = createIndex(firstOffset, 0, first.row()); - QModelIndex lastIndex = createIndex(lastOffset, 0, last.row()); - emit dataChanged(firstIndex, lastIndex); - } else { - // do not do normal dataChanged, since dataChanged it was already triggered separately - //onDataChanged(first, last); - } -} - -} diff --git a/TelepathyQt4Yell/Models/flat-model-proxy.h b/TelepathyQt4Yell/Models/flat-model-proxy.h deleted file mode 100644 index e926d41..0000000 --- a/TelepathyQt4Yell/Models/flat-model-proxy.h +++ /dev/null @@ -1,73 +0,0 @@ -/* - * This file is part of TelepathyQt4Yell Models - * - * Copyright (C) 2010 Collabora Ltd. <http://www.collabora.co.uk/> - * - * 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.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#ifndef _TelepathyQt4Yell_Models_flat_model_proxy_h_HEADER_GUARD_ -#define _TelepathyQt4Yell_Models_flat_model_proxy_h_HEADER_GUARD_ - -#ifndef IN_TELEPATHY_QT4_YELL_MODELS_HEADER -#error IN_TELEPATHY_QT4_YELL_MODELS_HEADER -#endif - -#include <TelepathyQt4Yell/Models/Global> - -#include <QAbstractProxyModel> - -namespace Tpy -{ - -class TELEPATHY_QT4_YELL_MODELS_EXPORT FlatModelProxy : public QAbstractProxyModel -{ - Q_OBJECT - Q_DISABLE_COPY(FlatModelProxy) - Q_PROPERTY(int rowCount READ rowCount NOTIFY rowCountChanged) - -public: - FlatModelProxy(QAbstractItemModel *source); - virtual ~FlatModelProxy(); - - virtual QModelIndex mapFromSource(const QModelIndex &index) const; - virtual QModelIndex mapToSource(const QModelIndex &index) const; - virtual QModelIndex index(int row, int column, const QModelIndex &parent) const; - virtual QModelIndex parent(const QModelIndex &index) const; - virtual int rowCount(const QModelIndex &parent) const; - virtual int columnCount(const QModelIndex &parent) const; - - int rowCount() const; - -Q_SIGNALS: - void rowCountChanged(); - -private Q_SLOTS: - void onRowsAboutToBeInserted(const QModelIndex &index, int first, int last); - void onRowsInserted(const QModelIndex &index, int first, int last); - void onRowsAboutToBeRemoved(const QModelIndex &index, int first, int last); - void onRowsRemoved(const QModelIndex &index, int first, int last); - void onDataChanged(const QModelIndex &first, const QModelIndex &last); - void onHierarchicalDataChanged(const QModelIndex &fisrt, const QModelIndex &last); - -private: - struct Private; - friend struct Private; - Private *mPriv; -}; - -} - -#endif // _TelepathyQt4Yell_Models_flat_model_proxy_h_HEADER_GUARD_ diff --git a/TelepathyQt4Yell/Models/tree-node.cpp b/TelepathyQt4Yell/Models/tree-node.cpp deleted file mode 100644 index e805954..0000000 --- a/TelepathyQt4Yell/Models/tree-node.cpp +++ /dev/null @@ -1,127 +0,0 @@ -/* - * This file is part of TelepathyQt4Yell Models - * - * Copyright (C) 2010 Collabora Ltd. <http://www.collabora.co.uk/> - * - * 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.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include <TelepathyQt4Yell/Models/TreeNode> - -#include "TelepathyQt4Yell/Models/_gen/tree-node.moc.hpp" - -namespace Tpy -{ - -struct TELEPATHY_QT4_YELL_MODELS_NO_EXPORT TreeNode::Private -{ - Private() : - mParent(0) - { - } - - ~Private() - { - qDeleteAll(mChildren); - mChildren.clear(); - } - - QList<TreeNode *> mChildren; - TreeNode *mParent; -}; - -TreeNode::TreeNode() - : mPriv(new Private()) -{ -} - -TreeNode::~TreeNode() -{ - if (mPriv->mParent) { - mPriv->mParent->mPriv->mChildren.removeOne(this); - } - delete mPriv; -} - -TreeNode *TreeNode::childAt(int index) const -{ - return mPriv->mChildren[index]; -} - -void TreeNode::addChild(TreeNode *node) -{ - // takes ownership of node - mPriv->mChildren.append(node); - node->mPriv->mParent = this; - - // set the parent QObject so that the node doesn't get deleted if used - // from QML/QtScript - node->setParent(this); - - // chain changed and removed signals - connect(node, - SIGNAL(changed(Tpy::TreeNode*)), - SIGNAL(changed(Tpy::TreeNode*))); - connect(node, - SIGNAL(childrenAdded(Tpy::TreeNode*,QList<Tpy::TreeNode*>)), - SIGNAL(childrenAdded(Tpy::TreeNode*,QList<Tpy::TreeNode*>))); - connect(node, - SIGNAL(childrenRemoved(Tpy::TreeNode*,int,int)), - SIGNAL(childrenRemoved(Tpy::TreeNode*,int,int))); -} - -int TreeNode::indexOf(TreeNode *node) const { - return mPriv->mChildren.indexOf(node); -} - -int TreeNode::size() const { - return mPriv->mChildren.size(); -} - -TreeNode *TreeNode::parent() const -{ - return mPriv->mParent; -} - -QVariant TreeNode::data(int role) const -{ - return QVariant(); -} - -bool TreeNode::setData(int role, const QVariant &value) -{ - return false; -} - -void TreeNode::remove() -{ - if (mPriv->mParent) { - disconnect(this, - SIGNAL(changed(Tpy::TreeNode*)), - mPriv->mParent, - SIGNAL(changed(Tpy::TreeNode*))); - disconnect(this, - SIGNAL(childrenAdded(Tpy::TreeNode*,QList<Tpy::TreeNode*>)), - mPriv->mParent, - SIGNAL(childrenAdded(Tpy::TreeNode*,QList<Tpy::TreeNode*>))); - disconnect(this, - SIGNAL(childrenRemoved(Tpy::TreeNode*,int,int)), - mPriv->mParent, - SIGNAL(childrenRemoved(Tpy::TreeNode*,int,int))); - } - deleteLater(); -} - -} diff --git a/TelepathyQt4Yell/Models/tree-node.h b/TelepathyQt4Yell/Models/tree-node.h deleted file mode 100644 index 3f7d366..0000000 --- a/TelepathyQt4Yell/Models/tree-node.h +++ /dev/null @@ -1,73 +0,0 @@ -/* - * This file is part of TelepathyQt4Yell Models - * - * Copyright (C) 2010 Collabora Ltd. <http://www.collabora.co.uk/> - * - * 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.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#ifndef _TelepathyQt4Yell_Models_tree_node_h_HEADER_GUARD_ -#define _TelepathyQt4Yell_Models_tree_node_h_HEADER_GUARD_ - -#ifndef IN_TELEPATHY_QT4_YELL_MODELS_HEADER -#error IN_TELEPATHY_QT4_YELL_MODELS_HEADER -#endif - -#include <TelepathyQt4Yell/Models/Global> - -#include <QObject> -#include <QVariant> - -namespace Tpy -{ - -class TELEPATHY_QT4_YELL_MODELS_EXPORT TreeNode : public QObject -{ - Q_OBJECT - Q_DISABLE_COPY(TreeNode) - -public: - TreeNode(); - - virtual ~TreeNode(); - - TreeNode *childAt(int index) const; - - void addChild(TreeNode *node); - - int indexOf(TreeNode *node) const; - - int size() const; - - TreeNode *parent() const; - - virtual QVariant data(int role) const; - virtual bool setData(int role, const QVariant &value); - virtual void remove(); - -Q_SIGNALS: - void changed(Tpy::TreeNode *); - void childrenAdded(Tpy::TreeNode *parent, const QList<Tpy::TreeNode *> &nodes); - void childrenRemoved(Tpy::TreeNode *parent, int first, int last); - -private: - struct Private; - friend struct Private; - Private *mPriv; -}; - -} - -#endif // _TelepathyQt4Yell_Models_tree_node_h_HEADER_GUARD_ |