• Skip to content
  • Skip to link menu
  • KDE API Reference
  • KDE Home
  • Contact Us
 

Nepomuk-Core

  • KTp
  • Declarative
conversation-target.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2011 Lasath Fernando <kde@lasath.org>
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Lesser General Public
6  License as published by the Free Software Foundation; either
7  version 2.1 of the License, or (at your option) any later version.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Lesser General Public License for more details.
13 
14  You should have received a copy of the GNU Lesser General Public
15  License along with this library; if not, write to the Free Software
16  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18 
19 #include "conversation-target.h"
20 #include <TelepathyQt/AvatarData>
21 #include <TelepathyQt/Contact>
22 #include <KDebug>
23 #include <KTp/presence.h>
24 
25 class ConversationTarget::ConversationTargetPrivate
26 {
27  public:
28  KTp::ContactPtr contact;
29  KIcon avatar;
30  Tp::AccountPtr account;
31 };
32 
33 ConversationTarget::ConversationTarget(const Tp::AccountPtr &account, const KTp::ContactPtr &contact, QObject *parent) :
34  QObject(parent),
35  d(new ConversationTargetPrivate)
36 {
37  kDebug();
38 
39  if (contact) {
40  setupContactSignals(contact);
41  }
42 
43  d->contact = contact;
44  d->account = account;
45  updateAvatar();
46 }
47 
48 void ConversationTarget::setupContactSignals(KTp::ContactPtr contact)
49 {
50  connect(contact.constData(), SIGNAL(aliasChanged(QString)), SIGNAL(nickChanged(QString)));
51  connect(contact.constData(), SIGNAL(avatarDataChanged(Tp::AvatarData)), SLOT(onAvatarDataChanged()));
52  connect(contact.constData(), SIGNAL(presenceChanged(Tp::Presence)), SLOT(onPresenceChanged()));
53 }
54 
55 QIcon ConversationTarget::avatar() const
56 {
57  if (d->contact) {
58  return d->avatar;
59  } else {
60  return QIcon();
61  }
62 }
63 
64 QString ConversationTarget::id() const
65 {
66  if (d->contact) {
67  return d->contact->id();
68  } else {
69  return QString();
70  }
71 }
72 
73 QString ConversationTarget::nick() const
74 {
75  if (d->contact) {
76  return d->contact->alias();
77  } else {
78  return QString();
79  }
80 }
81 
82 QIcon ConversationTarget::presenceIcon() const
83 {
84  if (d->contact) {
85  return KTp::Presence(d->contact->presence()).icon();
86  } else {
87  return QIcon();
88  }
89 }
90 
91 QString ConversationTarget::presenceIconName() const
92 {
93  if (d->contact) {
94  return KTp::Presence(d->contact->presence()).iconName();
95  } else {
96  return QString();
97  }
98 }
99 
100 void ConversationTarget::onPresenceChanged()
101 {
102  Q_EMIT presenceIconChanged(presenceIcon());
103  Q_EMIT presenceIconNameChanged(presenceIconName());
104 }
105 
106 void ConversationTarget::onAvatarDataChanged()
107 {
108  updateAvatar();
109  Q_EMIT avatarChanged(avatar());
110 }
111 
112 void ConversationTarget::updateAvatar()
113 {
114  QString path;
115  if (d->contact) {
116  path = d->contact->avatarData().fileName;
117  }
118 
119  if (path.isEmpty()) {
120  path = QLatin1String("im-user");
121  }
122 
123  d->avatar = KIcon(path);
124 }
125 
126 KTp::ContactPtr ConversationTarget::contact() const
127 {
128  return d->contact;
129 }
130 
131 Tp::AccountPtr ConversationTarget::account() const
132 {
133  return d->account;
134 }
135 
136 ConversationTarget::~ConversationTarget()
137 {
138  delete d;
139 }
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Fri Mar 22 2013 10:58:52 by doxygen 1.8.1.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

ktp-common-internals API Reference

Skip menu "ktp-common-internals API Reference"
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal