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

Nepomuk-Core

  • KTp
persistent-contact.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2013 David Edmundson <davidedmundson@kde.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 "persistent-contact.h"
20 
21 #include <TelepathyQt/Account>
22 #include <TelepathyQt/AccountManager>
23 #include <TelepathyQt/PendingContacts>
24 #include <TelepathyQt/ContactManager>
25 
26 #include <KDebug>
27 
28 namespace KTp
29 {
30 class PersistentContact::Private
31 {
32 public:
33  QString contactId;
34  QString accountId;
35  KTp::ContactPtr contact;
36  Tp::AccountPtr account;
37 };
38 }
39 
40 KTp::PersistentContactPtr KTp::PersistentContact::create(const QString &accountId, const QString &contactId)
41 {
42  return KTp::PersistentContactPtr(new KTp::PersistentContact(accountId, contactId));
43 }
44 
45 KTp::PersistentContact::PersistentContact(const QString &accountId, const QString &contactId)
46  : QObject(),
47  d(new PersistentContact::Private())
48 {
49  d->contactId = contactId;
50  d->accountId = accountId;
51 }
52 
53 KTp::PersistentContact::~PersistentContact()
54 {
55  delete d;
56 }
57 
58 QString KTp::PersistentContact::contactId() const
59 {
60  return d->contactId;
61 }
62 
63 QString KTp::PersistentContact::accountId() const
64 {
65  return d->accountId;
66 }
67 
68 void KTp::PersistentContact::setAccountManager(const Tp::AccountManagerPtr &accountManager)
69 {
70  Q_FOREACH(const Tp::AccountPtr &account, accountManager->allAccounts()) {
71  if (account->uniqueIdentifier() == d->accountId) {
72  d->account = account;
73  connect(account.data(), SIGNAL(connectionChanged(Tp::ConnectionPtr)), SLOT(onAccountConnectionChanged(Tp::ConnectionPtr)));
74  onAccountConnectionChanged(account->connection());
75  return;
76  }
77  }
78  kWarning() << "Could not find account " << d->accountId;
79 }
80 
81 KTp::ContactPtr KTp::PersistentContact::contact() const
82 {
83  return d->contact;
84 }
85 
86 Tp::AccountPtr KTp::PersistentContact::account() const
87 {
88  return d->account;
89 }
90 
91 void KTp::PersistentContact::onAccountConnectionChanged(const Tp::ConnectionPtr &connection)
92 {
93  if (connection) {
94  Tp::ContactManagerPtr manager = connection->contactManager();
95  connect(manager->contactsForIdentifiers(QStringList() << d->contactId), SIGNAL(finished(Tp::PendingOperation*)), SLOT(onPendingContactsFinished(Tp::PendingOperation*)));
96  }
97 }
98 
99 void KTp::PersistentContact::onPendingContactsFinished(Tp::PendingOperation *op)
100 {
101  Tp::PendingContacts *pendingContactsOp = qobject_cast<Tp::PendingContacts*>(op);
102  Q_ASSERT(pendingContactsOp);
103 
104  if (pendingContactsOp->contacts().size() == 1) {
105  d->contact = KTp::ContactPtr::qObjectCast(pendingContactsOp->contacts()[0]);
106  Q_EMIT contactChanged(d->contact);
107  connect(d->contact.data(), SIGNAL(invalidated()), SLOT(onContactInvalid()));
108  }
109 }
110 
111 void KTp::PersistentContact::onContactInvalid()
112 {
113  d->contact = KTp::ContactPtr();
114  Q_EMIT contactChanged(d->contact);
115 }
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