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

akonadi/contact

  • akonadi
  • contact
  • actions
qskypedialer.cpp
1/*
2 This file is part of Akonadi Contact.
3
4 Copyright (c) 2009 Tobias Koenig <tokoe@kde.org>
5
6 This library is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Library General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or (at your
9 option) any later version.
10
11 This library is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
14 License for more details.
15
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301, USA.
20*/
21
22#include "qskypedialer.h"
23
24#include "../dbusconnectionpool.h"
25
26#include <QtCore/QProcess>
27#include <QtDBus/QDBusConnection>
28#include <QtDBus/QDBusConnectionInterface>
29#include <QtDBus/QDBusInterface>
30#include <QtDBus/QDBusReply>
31#include <klocalizedstring.h>
32
33#include <unistd.h>
34
35static bool isSkypeServiceRegistered()
36{
37 const QLatin1String service("com.Skype.API");
38
39 QDBusConnectionInterface *interface = QDBusConnection::sessionBus().interface();
40 if (interface->isServiceRegistered(service)) {
41 return true;
42 }
43
44 interface = Akonadi::DBusConnectionPool::threadConnection().interface();
45 if (interface->isServiceRegistered(service)) {
46 return true;
47 }
48
49 return false;
50}
51
52static QDBusInterface *searchSkypeDBusInterface()
53{
54 const QLatin1String service("com.Skype.API");
55 const QLatin1String path("/com/Skype");
56
57 QDBusInterface *interface = new QDBusInterface(service, path, QString(), QDBusConnection::sessionBus());
58 if (!interface->isValid()) {
59 delete interface;
60 interface = new QDBusInterface(service, path, QString(), Akonadi::DBusConnectionPool::threadConnection());
61 }
62
63 return interface;
64}
65
66QSkypeDialer::QSkypeDialer(const QString &applicationName)
67 : QDialer(applicationName), mInterface(0)
68{
69}
70
71QSkypeDialer::~QSkypeDialer()
72{
73 delete mInterface;
74}
75
76bool QSkypeDialer::initializeSkype()
77{
78 if (mInterface && mInterface->isValid()) {
79 return true;
80 }
81
82 // first check whether dbus interface is available yet
83 if (!isSkypeServiceRegistered()) {
84
85 // it could be skype is not running yet, so start it now
86 if (!QProcess::startDetached(QLatin1String("skype"), QStringList())) {
87 mErrorMessage = i18n("Unable to start skype process, check that skype executable is in your PATH variable.");
88 return false;
89 }
90
91 const int runs = 100;
92 for (int i = 0; i < runs; ++i) {
93 if (!isSkypeServiceRegistered()) {
94 ::sleep(2);
95 } else {
96 break;
97 }
98 }
99 }
100
101 // check again for the dbus interface
102 mInterface = searchSkypeDBusInterface();
103
104 if (!mInterface->isValid()) {
105 delete mInterface;
106 mInterface = 0;
107
108 mErrorMessage = i18n("Skype Public API (D-Bus) seems to be disabled.");
109 return false;
110 }
111
112 QDBusReply<QString> reply = mInterface->call(QLatin1String("Invoke"), QString::fromLatin1("NAME %1").arg(mApplicationName));
113 if (reply.value() != QLatin1String("OK")) {
114 delete mInterface;
115 mInterface = 0;
116
117 mErrorMessage = i18n("Skype registration failed.");
118 return false;
119 }
120
121 reply = mInterface->call(QLatin1String("Invoke"), QLatin1String("PROTOCOL 1"));
122 if (reply.value() != QLatin1String("PROTOCOL 1")) {
123 delete mInterface;
124 mInterface = 0;
125
126 mErrorMessage = i18n("Protocol mismatch.");
127 return false;
128 }
129
130 return true;
131}
132
133bool QSkypeDialer::dialNumber(const QString &number)
134{
135 if (!initializeSkype()) {
136 return false;
137 }
138
139 QDBusReply<QString> reply = mInterface->call(QLatin1String("Invoke"), QString::fromLatin1("CALL %1").arg(number));
140
141 return true;
142}
143
144bool QSkypeDialer::sendSms(const QString &number, const QString &text)
145{
146 if (!initializeSkype()) {
147 return false;
148 }
149
150 // First we create a new SMS object that gets an ID. We need that ID later...
151 QDBusReply<QString> reply = mInterface->call(QLatin1String("Invoke"), QString::fromLatin1("CREATE SMS OUTGOING %1").arg(number));
152 const QString messageId = reply.value().section(QLatin1String(" "), 1, 1);
153
154 // Set the SMS text
155 reply = mInterface->call(QLatin1String("Invoke"), QString::fromLatin1("SET SMS %1 BODY %2").arg(messageId, text));
156
157 // Send the SMS
158 reply = mInterface->call(QLatin1String("Invoke"), QString::fromLatin1("ALTER SMS %1 SEND").arg(messageId));
159 if (reply.value().contains(QLatin1String("ERROR"))) {
160 mErrorMessage = reply.value();
161 // As sending the message failed (not enough Skype credit), lets delete the message
162 reply = mInterface->call(QLatin1String("Invoke"), QString::fromLatin1("DELETE SMS %1").arg(messageId));
163 return false;
164 }
165
166 return true;
167}
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Thu Jul 21 2022 00:00:00 by doxygen 1.9.5 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

akonadi/contact

Skip menu "akonadi/contact"
  • Main Page
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • Related Pages

kdepimlibs-4.14.10 API Reference

Skip menu "kdepimlibs-4.14.10 API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
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