2 * Contacts model item, represents a contact in the contactlist tree
3 * This file is based on TelepathyQt4Yell Models
5 * Copyright (C) 2010 Collabora Ltd. <http://www.collabora.co.uk/>
6 * Copyright (C) 2011 Martin Klapetek <martin dot klapetek at gmail dot com>
7 * Copyright (C) 2011 Vojta Kulicka <vojtechkulicka@gmail.com>
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26 #include <TelepathyQt4/AvatarData>
27 #include <TelepathyQt4/ContactCapabilities>
28 #include <TelepathyQt4/ContactManager>
29 #include <TelepathyQt4/RequestableChannelClassSpec>
30 #include <TelepathyQt4/Account>
32 #include "accounts-model.h"
33 #include "contact-model-item.h"
36 namespace MaknetoBackend
{
38 struct ContactModelItem::Private
40 Private(const Tp::ContactPtr
&contact
, const Tp::AccountPtr
&account
)
41 : mContact(contact
), mAccount(account
)
45 Tp::ContactPtr mContact
;
46 Tp::AccountPtr mAccount
;
49 ContactModelItem::ContactModelItem(const Tp::ContactPtr
&contact
, const Tp::AccountPtr
&account
)
50 : mPriv(new Private(contact
, account
))
53 connect(contact
.data(),
54 SIGNAL(aliasChanged(QString
)),
56 connect(contact
.data(),
57 SIGNAL(avatarTokenChanged(QString
)),
59 connect(contact
.data(),
60 SIGNAL(avatarDataChanged(Tp::AvatarData
)),
62 connect(contact
.data(),
63 SIGNAL(presenceChanged(Tp::Presence
)),
65 connect(contact
.data(),
66 SIGNAL(capabilitiesChanged(Tp::ContactCapabilities
)),
68 connect(contact
.data(),
69 SIGNAL(locationUpdated(Tp::LocationInfo
)),
71 connect(contact
.data(),
72 SIGNAL(infoFieldsChanged(Tp::Contact::InfoFields
)),
74 connect(contact
.data(),
75 SIGNAL(subscriptionStateChanged(Tp::Contact::PresenceState
)),
77 connect(contact
.data(),
78 SIGNAL(publishStateChanged(Tp::Contact::PresenceState
,QString
)),
80 connect(contact
.data(),
81 SIGNAL(blockStatusChanged(bool)),
85 ContactModelItem::~ContactModelItem()
90 QVariant
ContactModelItem::data(int role
) const
92 QString aliasAndStatus
;
96 case AccountsModel::ItemRole
:
97 return QVariant::fromValue((ContactModelItem
*)this);
98 case AccountsModel::IdRole
:
99 return mPriv
->mContact
->id();
100 case Qt::DisplayRole
:
101 case AccountsModel::AliasRole
:
102 aliasAndStatus
.append(mPriv
->mContact
->alias());
103 aliasAndStatus
.append(" (");
104 aliasAndStatus
.append(mPriv
->mContact
->presence().status());
105 aliasAndStatus
.append(")");
106 return aliasAndStatus
;
107 //return mPriv->mContact->alias();
108 case AccountsModel::ManagerIdRole
:
109 return mPriv
->mAccount
->uniqueIdentifier();
110 case AccountsModel::PresenceStatusRole
:
111 return mPriv
->mContact
->presence().status();
112 case AccountsModel::PresenceTypeRole
:
113 return mPriv
->mContact
->presence().type();
114 case AccountsModel::PresenceMessageRole
:
115 return mPriv
->mContact
->presence().statusMessage();
116 case AccountsModel::SubscriptionStateRole
:
117 return mPriv
->mContact
->subscriptionState();
118 case AccountsModel::PublishStateRole
:
119 return mPriv
->mContact
->publishState();
120 case AccountsModel::BlockedRole
:
121 return mPriv
->mContact
->isBlocked();
122 case AccountsModel::GroupsRole
:
123 return mPriv
->mContact
->groups();
124 case AccountsModel::AvatarRole
:
125 return mPriv
->mContact
->avatarData().fileName
;
126 case Qt::DecorationRole
:
127 avatar
= QImage(mPriv
->mContact
->avatarData().fileName
);
128 if( avatar
!= QImage())
129 avatar
= avatar
.scaled(24,24);
131 case AccountsModel::TextChatCapabilityRole
:
132 return mPriv
->mContact
->capabilities().textChats();
133 case AccountsModel::MediaCallCapabilityRole
:
134 return mPriv
->mContact
->capabilities().streamedMediaCalls();
135 case AccountsModel::AudioCallCapabilityRole
:
136 return mPriv
->mContact
->capabilities().streamedMediaAudioCalls();
137 case AccountsModel::VideoCallCapabilityRole
:
138 return mPriv
->mContact
->capabilities().streamedMediaVideoCalls();
139 case AccountsModel::UpgradeCallCapabilityRole
:
140 return mPriv
->mContact
->capabilities().upgradingStreamedMediaCalls();
141 case AccountsModel::FileTransferCapabilityRole
: {
142 foreach(const Tp::RequestableChannelClassSpec
& rccSpec
, mPriv
->mContact
->capabilities().allClassSpecs()) {
143 if (rccSpec
.supports(Tp::RequestableChannelClassSpec::fileTransfer())) {
156 bool ContactModelItem::setData(int role
, const QVariant
&value
)
159 case AccountsModel::PublishStateRole
: {
160 Tp::Contact::PresenceState state
;
161 state
= (Tp::Contact::PresenceState
) value
.toInt();
163 case Tp::Contact::PresenceStateYes
:
164 // authorize the contact and request its presence publication
165 mPriv
->mContact
->authorizePresencePublication();
166 mPriv
->mContact
->requestPresenceSubscription();
168 case Tp::Contact::PresenceStateNo
: {
169 // reject the presence publication and remove the contact
170 mPriv
->mContact
->removePresencePublication();
171 QList
<Tp::ContactPtr
> contacts
;
172 contacts
<< mPriv
->mContact
;
173 mPriv
->mContact
->manager()->removeContacts(contacts
);
185 void ContactModelItem::onChanged()
190 Tp::ContactPtr
ContactModelItem::contact() const
192 return mPriv
->mContact
;
197 #include "contact-model-item.moc"