2 * Telepathy initializer initializes telepathy and is inspired by
3 * TelepathyQt4Yell project
5 * Copyright (C) 2011 Vojta Kulicka <vojtechkulicka@gmail.com>
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 #include <TelepathyQt4/Types>
23 #include <TelepathyQt4/Global>
24 #include <TelepathyQt4/Constants>
25 #include <TelepathyQt4/AccountManager>
26 #include <TelepathyQt4/Account>
27 #include <TelepathyQt4/ContactManager>
28 #include <TelepathyQt4/PendingOperation>
29 #include <TelepathyQt4/PendingReady>
30 #include <TelepathyQt4/TextChannel>
31 #include <TelepathyQt4/StreamedMediaChannel>
32 #include <TelepathyQt4/FileTransferChannel>
33 #include <TelepathyQt4/ChannelClassSpecList>
35 #include "telepathy-client.h"
36 #include "telepathy-initializer.h"
37 #include "accounts-model.h"
38 #include <TelepathyQt4/IncomingFileTransferChannel>
39 #include <TelepathyQt4/OutgoingFileTransferChannel>
41 namespace MaknetoBackend
{
43 TelepathyInitializer::TelepathyInitializer(QObject
*parent
)
48 Tp::enableDebug(false);
49 Tp::enableWarnings(true);
52 void TelepathyInitializer::createClient(QString name
) {
56 // check QDBus connection
57 if (!QDBusConnection::sessionBus().isConnected())
58 qWarning() << "TelepathyInitializer: session bus is not connected!" << QDBusConnection::sessionBus().lastError();
60 //create AccountManager
61 Tp::Features connFeatures
;
62 Tp::Features accountFeatures
;
65 Tp::AccountFactoryPtr accountFactory
= Tp::AccountFactory::create(QDBusConnection::sessionBus(),
67 << Tp::Account::FeatureCore
68 << Tp::Account::FeatureAvatar
69 << Tp::Account::FeatureCapabilities
73 Tp::ConnectionFactoryPtr connectionFactory
= Tp::ConnectionFactory::create(
74 QDBusConnection::sessionBus(),
75 Tp::Features() << Tp::Connection::FeatureSelfContact
76 << Tp::Connection::FeatureCore
77 << Tp::Connection::FeatureSimplePresence
78 << Tp::Connection::FeatureRoster
79 << Tp::Connection::FeatureRosterGroups
83 Tp::ChannelFactoryPtr channelFactory
= Tp::ChannelFactory::create(QDBusConnection::sessionBus());
85 Tp::Features textFeatures
= Tp::Features() << Tp::TextChannel::FeatureCore
86 << Tp::TextChannel::FeatureMessageQueue
87 << Tp::TextChannel::FeatureMessageSentSignal
88 << Tp::TextChannel::FeatureChatState
89 << Tp::TextChannel::FeatureMessageCapabilities
;
91 Tp::Features callFeatures
= Tp::Features() << Tp::StreamedMediaChannel::FeatureCore
92 << Tp::StreamedMediaChannel::FeatureStreams
;
94 Tp::Features incomingFileTransferFeatures
= Tp::Features() << Tp::IncomingFileTransferChannel::FeatureCore
;
95 Tp::Features outgoingFileTransferFeatures
= Tp::Features() << Tp::OutgoingFileTransferChannel::FeatureCore
;
97 channelFactory
->addFeaturesForTextChats(textFeatures
);
98 channelFactory
->addFeaturesForTextChatrooms(textFeatures
);
99 channelFactory
->addFeaturesForStreamedMediaCalls(callFeatures
);
100 channelFactory
->addFeaturesForIncomingFileTransfers(incomingFileTransferFeatures
);
101 channelFactory
->addFeaturesForOutgoingFileTransfers(outgoingFileTransferFeatures
);
104 Tp::ContactFactoryPtr contactFactory
= Tp::ContactFactory::create(
105 Tp::Features() << Tp::Contact::FeatureAlias
106 << Tp::Contact::FeatureAvatarData
107 << Tp::Contact::FeatureCapabilities
108 << Tp::Contact::FeatureSimplePresence
);
110 m_accountManager
= Tp::AccountManager::create(QDBusConnection::sessionBus(),
116 connect(m_accountManager
->becomeReady(),
117 SIGNAL(finished(Tp::PendingOperation
*)),
118 SLOT(onAccountManagerReady(Tp::PendingOperation
*)));
121 void TelepathyInitializer::onAccountManagerReady(Tp::PendingOperation
*op
) {
123 qWarning() << "TelepathyInitializer: Error occured making AccountManager ready" << op
->errorName() << op
->errorMessage();
127 foreach(Tp::AccountPtr account
, m_accountManager
->allAccounts()) {
129 if (!account
->isEnabled())
132 connect(account
->becomeReady(),
133 SIGNAL(finished(Tp::PendingOperation
*)),
134 SLOT(onAccountReady(Tp::PendingOperation
*)));
141 void TelepathyInitializer::onAccountReady(Tp::PendingOperation
*op
) {
143 qWarning() << "TelepathyInitializer: Error occured making Account ready";
147 Tp::PendingReady
*pr
= qobject_cast
<Tp::PendingReady
*>(op
);
148 Tp::AccountPtr account
= Tp::AccountPtr::dynamicCast(pr
->object());
150 if (!account
->connection().isNull()) {
152 connect(account
->connection()->becomeReady(),
153 SIGNAL(finished(Tp::PendingOperation
*)),
154 SLOT(onConnectionReady(Tp::PendingOperation
*)));
159 qDebug() << "TelepathyInitializer: Account ready: " << account
->uniqueIdentifier();
162 void TelepathyInitializer::onConnectionReady(Tp::PendingOperation
*op
) {
164 qWarning() << "TelepathyInitializer: Error occured making Connection ready";
168 Tp::PendingReady
*pr
= qobject_cast
<Tp::PendingReady
*>(op
);
169 Tp::ConnectionPtr connection
= Tp::ConnectionPtr::dynamicCast(pr
->object());
171 Q_ASSERT(connection
);
177 void TelepathyInitializer::checkFinished() {
178 qDebug() << "TelepathyInitializer: Connections ready: " << m_connections
;
179 if (m_connections
> 0)
182 //create accounts model
183 AccountsModel
*accountsModel
= new AccountsModel(m_accountManager
);
186 //ChannelClassSpec says what channel is the client interested in and is looked at by channel dispatcher
187 TelepathyClient
*client
= TelepathyClient::Instance(Tp::ChannelClassSpecList()
188 << Tp::ChannelClassSpec::textChat()
189 << Tp::ChannelClassSpec::unnamedTextChat()
190 << Tp::ChannelClassSpec::textChatroom()
191 << Tp::ChannelClassSpec::streamedMediaCall()
192 << Tp::ChannelClassSpec::streamedMediaAudioCall()
193 << Tp::ChannelClassSpec::incomingFileTransfer()
194 << Tp::ChannelClassSpec::outgoingFileTransfer()
195 << Tp::ChannelClassSpec::streamedMediaVideoCall()
196 << Tp::ChannelClassSpec::streamedMediaVideoCallWithAudio(),
204 m_cr
= Tp::ClientRegistrar::create(m_accountManager
);
205 Tp::AbstractClientPtr
handler(client
);
206 m_cr
->registerClient(handler
, m_clientName
);
208 //create account model and set it to the client
209 qDebug() << "TelepathyInitializer: Finished";
210 emit
finished(client
);
214 #include "telepathy-initializer.moc"