diff --git a/KTp/Declarative/telepathy-manager.cpp b/KTp/Declarative/telepathy-manager.cpp index 57b1150..b2ed151 100644 --- a/KTp/Declarative/telepathy-manager.cpp +++ b/KTp/Declarative/telepathy-manager.cpp @@ -1,227 +1,245 @@ /* Copyright (C) 2013 David Edmundson Copyright (C) 2013 Aleix Pol This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "telepathy-manager.h" #include #include #include #include #include #include #include #include #include #include #include +#include #include TelepathyManager::TelepathyManager(QObject *parent) : QObject(parent) { Tp::registerTypes(); + m_isReady = false; + m_accountFactory = Tp::AccountFactory::create(QDBusConnection::sessionBus(), Tp::Features() << Tp::Account::FeatureCore << Tp::Account::FeatureProfile << Tp::Account::FeatureCapabilities); m_connectionFactory = Tp::ConnectionFactory::create(QDBusConnection::sessionBus(), Tp::Features() << Tp::Connection::FeatureCore); m_contactFactory = KTp::ContactFactory::create(Tp::Features() << Tp::Contact::FeatureAlias << Tp::Contact::FeatureSimplePresence << Tp::Contact::FeatureCapabilities); m_channelFactory = Tp::ChannelFactory::create(QDBusConnection::sessionBus()); m_accountManager = Tp::AccountManager::create(m_accountFactory, m_connectionFactory, m_channelFactory, m_contactFactory); + connect(m_accountManager->becomeReady(), &Tp::PendingReady::finished, [=](Tp::PendingOperation *op) { + if (op->isError()) { + qWarning() << "AccountManager failed to become ready!" << op->errorMessage(); + return; + } + + m_isReady = true; + + Q_EMIT ready(); + }); } TelepathyManager::~TelepathyManager() { } Tp::AccountManagerPtr TelepathyManager::accountManager() { return m_accountManager; } void TelepathyManager::becomeReady() { m_accountManager->becomeReady(); } bool TelepathyManager::registerClient(QObject *client, const QString &name) { Tp::AbstractClient* abstractClient = dynamic_cast(client); if (!abstractClient) { return false; } if (! m_clientRegistrar) { m_clientRegistrar = Tp::ClientRegistrar::create(m_accountManager); } //the client registrar will delete the handler when the registrar is deleted. QQmlEngine::setObjectOwnership(client, QQmlEngine::CppOwnership); return m_clientRegistrar->registerClient(Tp::AbstractClientPtr(abstractClient), name); } bool TelepathyManager::unregisterClient(QObject* client) { Tp::AbstractClient* abstractClient = dynamic_cast(client); return abstractClient && m_clientRegistrar && m_clientRegistrar->unregisterClient(Tp::AbstractClientPtr(abstractClient)); } void TelepathyManager::addTextChatFeatures() { m_connectionFactory->addFeatures(Tp::Features() << Tp::Connection::FeatureSelfContact); Tp::Features textFeatures = Tp::Features() << Tp::TextChannel::FeatureMessageQueue << Tp::TextChannel::FeatureMessageSentSignal << Tp::TextChannel::FeatureChatState << Tp::TextChannel::FeatureMessageCapabilities; m_contactFactory->addFeatures(Tp::Features() << Tp::Contact::FeatureAlias << Tp::Contact::FeatureSimplePresence << Tp::Contact::FeatureCapabilities << Tp::Contact::FeatureAvatarData); m_channelFactory->addFeaturesForTextChats(textFeatures); m_channelFactory->addFeaturesForTextChatrooms(textFeatures); } void TelepathyManager::addContactListFeatures() { m_connectionFactory->addFeatures(Tp::Features() << Tp::Connection::FeatureRosterGroups << Tp::Connection::FeatureRoster << Tp::Connection::FeatureSelfContact); m_contactFactory->addFeatures(Tp::Features() << Tp::Contact::FeatureAlias << Tp::Contact::FeatureSimplePresence << Tp::Contact::FeatureCapabilities << Tp::Contact::FeatureAvatarData); //used for optionally keeping track of unread message count/icon in contact list Tp::Features textFeatures = Tp::Features() << Tp::TextChannel::FeatureMessageQueue; m_channelFactory->addFeaturesForTextChats(textFeatures); } void TelepathyManager::addAllFeatures() { addTextChatFeatures(); addContactListFeatures(); } void TelepathyManager::openLogViewer(const Tp::AccountPtr &account, const KTp::ContactPtr &contact) { KTp::Actions::openLogViewer(account, contact); } Tp::PendingChannelRequest* TelepathyManager::startAudioCall(const Tp::AccountPtr &account, const KTp::ContactPtr &contact) { return KTp::Actions::startAudioCall(account, contact); } Tp::PendingChannelRequest* TelepathyManager::startAudioVideoCall(const Tp::AccountPtr &account, const KTp::ContactPtr &contact) { return KTp::Actions::startAudioVideoCall(account, contact); } Tp::PendingChannelRequest* TelepathyManager::startChat(const Tp::AccountPtr &account, const KTp::ContactPtr &contact, bool delegateToPreferredHandler) { return KTp::Actions::startChat(account, contact, delegateToPreferredHandler); } Tp::PendingChannelRequest *TelepathyManager::startChat(const Tp::AccountPtr &account, const KTp::ContactPtr &contact, const QString &preferredHandler) { return account->ensureTextChat(contact, QDateTime::currentDateTime(), preferredHandler); } Tp::PendingOperation* TelepathyManager::startFileTransfer(const Tp::AccountPtr &account, const KTp::ContactPtr &contact, const QUrl &url) { return KTp::Actions::startFileTransfer(account, contact, url); } bool TelepathyManager::canDial() const { return !QStandardPaths::findExecutable(QLatin1String("ktp-dialout-ui")).isEmpty(); } bool TelepathyManager::canSendFiles() const { return !QStandardPaths::findExecutable(QLatin1String("ktp-send-file")).isEmpty(); } +bool TelepathyManager::isReady() const +{ + return m_isReady; +} + void TelepathyManager::openDialUi() const { KToolInvocation::kdeinitExec(QLatin1String("ktp-dialout-ui")); } void TelepathyManager::openSendFileUi() const { KToolInvocation::kdeinitExec(QLatin1String("ktp-send-file")); } void TelepathyManager::addContact() { KTp::AddContactDialog *dialog = new KTp::AddContactDialog(m_accountManager); dialog->setAttribute(Qt::WA_DeleteOnClose); dialog->show(); } void TelepathyManager::joinChatRoom() { KTp::JoinChatRoomDialog *dialog = new KTp::JoinChatRoomDialog(m_accountManager); dialog->setAttribute(Qt::WA_DeleteOnClose); dialog->show(); } void TelepathyManager::toggleContactList() { //contact list is registered, call toggleWindowVisibility in contact list QDBusMessage methodCall = QDBusMessage::createMethodCall(QLatin1String("org.kde.ktpcontactlist"), QLatin1String("/ktpcontactlist/MainWindow"), QLatin1String("org.kde.KTp.ContactList"), QLatin1String("toggleWindowVisibility")); QDBusPendingCall call = QDBusConnection::sessionBus().asyncCall(methodCall); QDBusPendingCallWatcher *watch = new QDBusPendingCallWatcher(call, this); connect(watch, SIGNAL(finished(QDBusPendingCallWatcher*)), SLOT(contactlistDBusAccessed(QDBusPendingCallWatcher*))); connect(watch, SIGNAL(finished(QDBusPendingCallWatcher*)), watch, SLOT(deleteLater())); } void TelepathyManager::contactlistDBusAccessed(QDBusPendingCallWatcher *w) { if (w->isError()) { // if toggleWindowVisibility failed, try starting the application via dbus QDBusConnection::sessionBus().interface()->startService(QStringLiteral("org.kde.ktpcontactlist")); } } void TelepathyManager::showSettingsKCM() { KTp::SettingsKcmDialog *dialog = new KTp::SettingsKcmDialog(); dialog->addGeneralSettingsModule(); dialog->addNotificationsModule(); dialog->show(); } diff --git a/KTp/Declarative/telepathy-manager.h b/KTp/Declarative/telepathy-manager.h index d9ad24a..97c71b0 100644 --- a/KTp/Declarative/telepathy-manager.h +++ b/KTp/Declarative/telepathy-manager.h @@ -1,170 +1,178 @@ /* Copyright (C) 2013 David Edmundson Copyright (C) 2013 Aleix Pol This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #ifndef TELEPATHYMANAGER_H #define TELEPATHYMANAGER_H #include #include #include #include #include namespace Tp { class PendingChannelRequest; } class TelepathyManager : public QObject { Q_OBJECT Q_PROPERTY(Tp::AccountManagerPtr accountManager READ accountManager CONSTANT) /** @returns whether there's a ktp-dialout-ui executable */ Q_PROPERTY(bool canDial READ canDial) /** @returns whether there's a ktp-send-file executable */ Q_PROPERTY(bool canSendFiles READ canSendFiles) + Q_PROPERTY(bool ready READ isReady NOTIFY ready) + public: TelepathyManager(QObject *parent=0); virtual ~TelepathyManager(); /** Returns the account manager*/ Tp::AccountManagerPtr accountManager(); /** Add features to ObjectFactories that allow for all TextChannel features * This must be called before becomeReady() */ Q_INVOKABLE void addTextChatFeatures(); /** Add features to ObjectFactories that allow for all features needed for a contact list * This must be called before becomeReady() */ Q_INVOKABLE void addContactListFeatures(); /** Add all useful ObjectFactory features * This must be called before becomeReady() */ Q_INVOKABLE void addAllFeatures(); /** Call Tp::AccountManager::becomeReady */ Q_INVOKABLE void becomeReady(); /** Register an abstractClient to clientRegistrar * @arg client. Clients must subclass AbstractClient and QObject in their implementation to be used in QML * * @arg clientName * The client name MUST be a non-empty string of ASCII digits, letters, dots and/or underscores, starting with a letter, and without sets of two consecutive dots or a dot followed by a digit. * * See ClientRegistrar::registerClient for details * * @return whether registration was successful * */ Q_INVOKABLE bool registerClient(QObject *client, const QString &clientName); Q_INVOKABLE bool unregisterClient(QObject* client); bool canDial() const; bool canSendFiles() const; + bool isReady() const; /** Opens UI to start an audio call */ Q_INVOKABLE void openDialUi() const; /** Opens UI to send a file */ Q_INVOKABLE void openSendFileUi() const; /** Opens UI to add a new contact */ Q_INVOKABLE void addContact(); /** Opens UI to join a chat room */ Q_INVOKABLE void joinChatRoom(); /** Opens UI to show the KDE Telepathy settings module */ Q_INVOKABLE void showSettingsKCM(); /** Toggles the visibility of the ktp-contact-list program */ Q_INVOKABLE void toggleContactList(); public Q_SLOTS: /** Start a text chat using the default KTp text application @arg account the account to start the channel from @arg contact the contact to start the channel with @arg delegateToPreferredHandler whether any existing handlers should release handling the channel and pass control to the requested handler */ Tp::PendingChannelRequest* startChat(const Tp::AccountPtr &account, const KTp::ContactPtr &contact, bool delegateToPreferredHandler = true); /** Start a text chat using the preffered client @arg account the account to start the channel from @arg contact the contact to start the channel with @arg preferredHandler the preferred client */ Tp::PendingChannelRequest* startChat(const Tp::AccountPtr &account, const KTp::ContactPtr &contact, const QString &preferredHandler); /** Start an audio call using the default KTp call application @arg account the account to start the channel from @arg contact the contact to start the channel with */ Tp::PendingChannelRequest* startAudioCall(const Tp::AccountPtr &account, const KTp::ContactPtr &contact); /** Start an audio call using the default KTp call application @arg account the account to start the channel from @arg contact the contact to start the channel with */ Tp::PendingChannelRequest* startAudioVideoCall(const Tp::AccountPtr &account, const KTp::ContactPtr &contact); /** Start a file transfer using the default KTp file transfer application @arg account the account to start the channel from @arg contact the contact to start the channel with */ Tp::PendingOperation* startFileTransfer(const Tp::AccountPtr &account, const KTp::ContactPtr &contact, const QUrl& url); /** Open logs using the default KTp log application @arg account the account to start the channel from @arg contact the contact to start the channel with */ void openLogViewer(const Tp::AccountPtr &account, const KTp::ContactPtr &contact); private Q_SLOTS: void contactlistDBusAccessed(QDBusPendingCallWatcher*); +Q_SIGNALS: + void ready(); + private: Tp::AccountManagerPtr m_accountManager; Tp::ClientRegistrarPtr m_clientRegistrar; Tp::AccountFactoryPtr m_accountFactory; Tp::ContactFactoryPtr m_contactFactory; Tp::ConnectionFactoryPtr m_connectionFactory; Tp::ChannelFactoryPtr m_channelFactory; + bool m_isReady; + }; #endif // DECLARATIVEKTPACTIONS_H