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

Nepomuk-Core

  • KTp
  • Declarative
contact-list.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2011 David Edmundson <kde@davidedmundson.co.uk>
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 "contact-list.h"
20 
21 #include <TelepathyQt/AccountFactory>
22 #include <TelepathyQt/ConnectionFactory>
23 #include <TelepathyQt/AccountManager>
24 #include <TelepathyQt/PendingReady>
25 #include <TelepathyQt/PendingChannelRequest>
26 
27 #include <KDebug>
28 
29 #include <KTp/contact-factory.h>
30 
31 #include <KTp/actions.h>
32 
33 ContactList::ContactList(QObject *parent)
34  : QObject(parent),
35  m_contactsModel(new KTp::ContactsListModel(this)),
36  m_filterModel(new KTp::ContactsFilterModel(this))
37 {
38  m_filterModel->setSourceModel(m_contactsModel);
39  //flat model takes the source as a constructor parameter, the other's don't.
40  //due to a bug somewhere creating the flat model proxy with the filter model as a source before the filter model has a source means the rolenames do not get propgated up
41 
42  Tp::registerTypes();
43 
44  // Start setting up the Telepathy AccountManager.
45  Tp::AccountFactoryPtr accountFactory = Tp::AccountFactory::create(QDBusConnection::sessionBus(),
46  Tp::Features() << Tp::Account::FeatureCore
47  << Tp::Account::FeatureAvatar
48  << Tp::Account::FeatureCapabilities
49  << Tp::Account::FeatureProtocolInfo
50  << Tp::Account::FeatureProfile);
51 
52  Tp::ConnectionFactoryPtr connectionFactory = Tp::ConnectionFactory::create(QDBusConnection::sessionBus(),
53  Tp::Features() << Tp::Connection::FeatureCore
54  << Tp::Connection::FeatureRosterGroups
55  << Tp::Connection::FeatureRoster
56  << Tp::Connection::FeatureSelfContact);
57 
58  Tp::ContactFactoryPtr contactFactory = KTp::ContactFactory::create(Tp::Features() << Tp::Contact::FeatureAlias
59  << Tp::Contact::FeatureAvatarData
60  << Tp::Contact::FeatureSimplePresence
61  << Tp::Contact::FeatureCapabilities);
62 
63 
64 
65  Tp::ChannelFactoryPtr channelFactory = Tp::ChannelFactory::create(QDBusConnection::sessionBus());
66 
67  m_accountManager = Tp::AccountManager::create(QDBusConnection::sessionBus(),
68  accountFactory,
69  connectionFactory,
70  channelFactory,
71  contactFactory);
72 
73  connect(m_accountManager->becomeReady(),
74  SIGNAL(finished(Tp::PendingOperation*)),
75  SLOT(onAccountManagerReady(Tp::PendingOperation*)));
76 }
77 
78 
79 void ContactList::onAccountManagerReady(Tp::PendingOperation *op)
80 {
81  Q_UNUSED(op);
82  m_contactsModel->setAccountManager(m_accountManager);
83 }
84 
85 KTp::ContactsFilterModel* ContactList::filterModel() const
86 {
87  return m_filterModel;
88 }
89 
90 void ContactList::startChat(const Tp::AccountPtr &account, const KTp::ContactPtr &contact)
91 {
92  kDebug() << "Requesting chat for contact" << contact->alias();
93  kDebug() << "account is" << account->normalizedName();
94 
95  Tp::PendingOperation *op = KTp::Actions::startChat(account, contact, false);
96  connect(op, SIGNAL(finished(Tp::PendingOperation*)), SLOT(onGenericOperationFinished(Tp::PendingOperation*)));
97 }
98 
99 void ContactList::onGenericOperationFinished(Tp::PendingOperation *op)
100 {
101  if (op->isError()) {
102  kDebug() << op->errorName();
103  kDebug() << op->errorMessage();
104  }
105 }
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