File indexing completed on 2023-10-01 08:41:44
0001 /* 0002 * static methods on the KTp namespace 0003 * 0004 * Copyright (C) 2013 David Edmundson <kde@davidedmundson.co.uk> 0005 * 0006 * This library is free software; you can redistribute it and/or 0007 * modify it under the terms of the GNU Lesser General Public 0008 * License as published by the Free Software Foundation; either 0009 * version 2.1 of the License, or (at your option) any later version. 0010 * 0011 * This library is distributed in the hope that it will be useful, 0012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0014 * Lesser General Public License for more details. 0015 * 0016 * You should have received a copy of the GNU Lesser General Public 0017 * License along with this library; if not, write to the Free Software 0018 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 0019 */ 0020 0021 #include "core.h" 0022 0023 #ifdef HAVE_KPEOPLE 0024 #include <QDBusMessage> 0025 #include <QDBusReply> 0026 #endif 0027 0028 #include <QtGlobal> 0029 #include <TelepathyQt/AccountManager> 0030 #include <KTp/global-contact-manager.h> 0031 #include "contact-factory.h" 0032 #include "account-factory_p.h" 0033 0034 class CorePrivate 0035 { 0036 public: 0037 CorePrivate(); 0038 bool m_kPeopleEnabled; 0039 Tp::AccountFactoryPtr m_accountFactory; 0040 Tp::ConnectionFactoryPtr m_connectionFactory; 0041 Tp::ContactFactoryPtr m_contactFactory; 0042 Tp::ChannelFactoryPtr m_channelFactory ; 0043 0044 Tp::AccountManagerPtr m_accountManager; 0045 KTp::GlobalContactManager *m_contactManager; 0046 }; 0047 0048 CorePrivate::CorePrivate() 0049 : m_kPeopleEnabled(false), 0050 m_contactManager(nullptr) 0051 { 0052 //if built with kpeople support, enable it 0053 #ifdef HAVE_KPEOPLE 0054 m_kPeopleEnabled = true; 0055 #endif 0056 0057 m_accountFactory = KTp::AccountFactory::create(QDBusConnection::sessionBus(), 0058 Tp::Features() << Tp::Account::FeatureCore 0059 << Tp::Account::FeatureCapabilities 0060 << Tp::Account::FeatureProfile); 0061 0062 m_connectionFactory = Tp::ConnectionFactory::create(QDBusConnection::sessionBus(), 0063 Tp::Features() << Tp::Connection::FeatureCore 0064 << Tp::Connection::FeatureConnected 0065 << Tp::Connection::FeatureSelfContact); 0066 0067 m_contactFactory = KTp::ContactFactory::create(Tp::Features() << Tp::Contact::FeatureAlias 0068 << Tp::Contact::FeatureSimplePresence 0069 << Tp::Contact::FeatureCapabilities 0070 << Tp::Contact::FeatureClientTypes 0071 << Tp::Contact::FeatureAvatarData); 0072 0073 m_channelFactory = Tp::ChannelFactory::create(QDBusConnection::sessionBus()); 0074 } 0075 0076 Q_GLOBAL_STATIC(CorePrivate, s_instance) 0077 0078 bool KTp::kpeopleEnabled() 0079 { 0080 return s_instance->m_kPeopleEnabled; 0081 } 0082 0083 Tp::AccountFactoryConstPtr KTp::accountFactory() 0084 { 0085 return s_instance->m_accountFactory; 0086 } 0087 0088 Tp::ConnectionFactoryConstPtr KTp::connectionFactory() 0089 { 0090 return s_instance->m_connectionFactory; 0091 } 0092 0093 Tp::ChannelFactoryConstPtr KTp::channelFactory() 0094 { 0095 return s_instance->m_channelFactory; 0096 } 0097 0098 Tp::ContactFactoryConstPtr KTp::contactFactory() 0099 { 0100 return s_instance->m_contactFactory; 0101 } 0102 0103 Tp::AccountManagerPtr KTp::accountManager() 0104 { 0105 if (!s_instance->m_accountManager) { 0106 s_instance->m_accountManager = Tp::AccountManager::create(QDBusConnection::sessionBus(), 0107 KTp::accountFactory(), 0108 KTp::connectionFactory(), 0109 KTp::channelFactory(), 0110 KTp::contactFactory()); 0111 } 0112 return s_instance->m_accountManager; 0113 } 0114 0115 KTp::GlobalContactManager* KTp::contactManager() 0116 { 0117 if (!s_instance->m_contactManager) { 0118 s_instance->m_contactManager = new KTp::GlobalContactManager(KTp::accountManager(), nullptr); 0119 } 0120 0121 return s_instance->m_contactManager; 0122 }