1 /*
2     Copyright (C) 2013 David Edmundson <davidedmundson@kde.org>
3     Copyright (C) 2013 Aleix Pol <aleixpol@kde.org>
4 
5     This library is free software; you can redistribute it and/or
6     modify it under the terms of the GNU Lesser General Public
7     License as published by the Free Software Foundation; either
8     version 2.1 of the License, or (at your option) any later version.
9 
10     This library is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13     Lesser General Public License for more details.
14 
15     You should have received a copy of the GNU Lesser General Public
16     License along with this library; if not, write to the Free Software
17     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
18 */
19 
20 #ifndef TELEPATHYMANAGER_H
21 #define TELEPATHYMANAGER_H
22 
23 #include <QObject>
24 #include <TelepathyQt/Types>
25 
26 #include <KTp/contact.h>
27 #include <KTp/contact-factory.h>
28 
29 #include <KTp/types.h>
30 
31 namespace Tp {
32 class PendingChannelRequest;
33 }
34 
35 
36 class TelepathyManager : public QObject
37 {
38     Q_OBJECT
39     Q_PROPERTY(Tp::AccountManagerPtr accountManager READ accountManager CONSTANT)
40 
41     /** @returns whether there's a ktp-dialout-ui executable */
42     Q_PROPERTY(bool canDial READ canDial)
43 
44     /** @returns whether there's a ktp-send-file executable */
45     Q_PROPERTY(bool canSendFiles READ canSendFiles)
46 
47     Q_PROPERTY(bool ready READ isReady NOTIFY ready)
48 
49 public:
50     TelepathyManager(QObject *parent=nullptr);
51     ~TelepathyManager() override;
52 
53     /** Returns the account manager*/
54     Tp::AccountManagerPtr accountManager();
55 
56     /** Add features to ObjectFactories that allow for all TextChannel features
57      * This must be called before becomeReady()
58      */
59     Q_INVOKABLE void addTextChatFeatures();
60 
61     /** Add features to ObjectFactories that allow for all features needed for a contact list
62      * This must be called before becomeReady()
63      */
64     Q_INVOKABLE void addContactListFeatures();
65 
66     /** Add all useful ObjectFactory features
67      * This must be called before becomeReady()
68      */
69     Q_INVOKABLE void addAllFeatures();
70 
71     /** Call Tp::AccountManager::becomeReady
72      */
73     Q_INVOKABLE void becomeReady();
74 
75     /** Register an abstractClient to clientRegistrar
76      * @arg client. Clients must subclass AbstractClient and QObject in their implementation to be used in QML
77      *
78      * @arg clientName
79      * 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.
80      *
81      * See ClientRegistrar::registerClient for details
82      *
83      * @return whether registration was successful
84      *
85      */
86     Q_INVOKABLE bool registerClient(QObject *client, const QString &clientName);
87 
88     Q_INVOKABLE bool unregisterClient(QObject* client);
89 
90     bool canDial() const;
91     bool canSendFiles() const;
92     bool isReady() const;
93 
94     /** Opens UI to start an audio call */
95     Q_INVOKABLE void openDialUi() const;
96 
97     /** Opens UI to send a file */
98     Q_INVOKABLE void openSendFileUi() const;
99 
100     /** Opens UI to add a new contact */
101     Q_INVOKABLE void addContact();
102 
103     /** Opens UI to join a chat room */
104     Q_INVOKABLE void joinChatRoom();
105 
106     /** Opens UI to show the KDE Telepathy settings module */
107     Q_INVOKABLE void showSettingsKCM();
108 
109     /** Toggles the visibility of the ktp-contact-list program */
110     Q_INVOKABLE void toggleContactList();
111 
112 public Q_SLOTS:
113     /** Start a text chat using the default KTp text application
114         @arg account the account to start the channel from
115         @arg contact the contact to start the channel with
116         @arg delegateToPreferredHandler whether any existing handlers should release handling the channel and pass control to the requested handler
117      */
118     Tp::PendingChannelRequest* startChat(const Tp::AccountPtr &account,
119                                          const KTp::ContactPtr &contact,
120                                          bool delegateToPreferredHandler = true);
121 
122     /** Start a text chat using the preffered client
123         @arg account the account to start the channel from
124         @arg contact the contact to start the channel with
125         @arg preferredHandler the preferred client
126     */
127     Tp::PendingChannelRequest* startChat(const Tp::AccountPtr &account,
128                                          const KTp::ContactPtr &contact,
129                                          const QString &preferredHandler);
130 
131     /** Start an audio call using the default KTp call application
132         @arg account the account to start the channel from
133         @arg contact the contact to start the channel with
134     */
135     Tp::PendingChannelRequest* startAudioCall(const Tp::AccountPtr &account,
136                                               const KTp::ContactPtr &contact);
137 
138     /** Start an audio call using the default KTp call application
139         @arg account the account to start the channel from
140         @arg contact the contact to start the channel with
141     */
142     Tp::PendingChannelRequest* startAudioVideoCall(const Tp::AccountPtr &account,
143                                                    const KTp::ContactPtr &contact);
144 
145     /** Start a file transfer using the default KTp file transfer application
146         @arg account the account to start the channel from
147         @arg contact the contact to start the channel with
148     */
149     Tp::PendingOperation* startFileTransfer(const Tp::AccountPtr &account,
150                                             const KTp::ContactPtr &contact,
151                                             const QUrl& url);
152 
153     /** Open logs using the default KTp log application
154         @arg account the account to start the channel from
155         @arg contact the contact to start the channel with
156     */
157     void openLogViewer(const Tp::AccountPtr &account, const KTp::ContactPtr &contact);
158 
159 private Q_SLOTS:
160     void contactlistDBusAccessed(QDBusPendingCallWatcher*);
161 
162 Q_SIGNALS:
163     void ready();
164 
165 private:
166     Tp::AccountManagerPtr m_accountManager;
167     Tp::ClientRegistrarPtr m_clientRegistrar;
168 
169     Tp::AccountFactoryPtr m_accountFactory;
170     Tp::ContactFactoryPtr m_contactFactory;
171     Tp::ConnectionFactoryPtr m_connectionFactory;
172     Tp::ChannelFactoryPtr m_channelFactory;
173 
174     bool m_isReady;
175 
176 };
177 
178 #endif // DECLARATIVEKTPACTIONS_H
179