Akonadi Contacts

qekigadialer.cpp
1 /*
2  SPDX-FileCopyrightText: 2013-2021 Laurent Montel <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 
6 */
7 
8 #include "qekigadialer.h"
9 
10 #include <KLocalizedString>
11 
12 #include <QDBusConnection>
13 #include <QDBusConnectionInterface>
14 #include <QDBusInterface>
15 #include <QDBusReply>
16 #include <QProcess>
17 
18 #if !defined(Q_OS_WIN)
19 #include <unistd.h>
20 #else
21 #include <windows.h>
22 #endif
23 
24 static bool isEkigaServiceRegistered()
25 {
26  const QString service(QStringLiteral("org.ekiga.Ekiga"));
27 
29  if (interface->isServiceRegistered(service)) {
30  return true;
31  }
32 
33  interface = QDBusConnection::sessionBus().interface();
34  if (interface->isServiceRegistered(service)) {
35  return true;
36  }
37  return false;
38 }
39 
40 static QDBusInterface *searchEkigaDBusInterface()
41 {
42  const QString service(QStringLiteral("org.ekiga.Ekiga"));
43  const QString path(QStringLiteral("/org/ekiga/Ekiga"));
44 
45  auto interface = new QDBusInterface(service, path, QString(), QDBusConnection::sessionBus());
46  if (!interface->isValid()) {
47  delete interface;
48  interface = new QDBusInterface(service, path, QString(), QDBusConnection::sessionBus());
49  }
50 
51  return interface;
52 }
53 
54 QEkigaDialer::QEkigaDialer(const QString &applicationName)
55  : QDialer(applicationName)
56 {
57 }
58 
59 QEkigaDialer::~QEkigaDialer()
60 {
61  delete mInterface;
62 }
63 
64 bool QEkigaDialer::initializeEkiga()
65 {
66  // first check whether dbus interface is available yet
67  if (!isEkigaServiceRegistered()) {
68  // it could be ekiga is not running yet, so start it now
69  if (!QProcess::startDetached(QStringLiteral("ekiga"), QStringList())) {
70  mErrorMessage = i18n("Unable to start ekiga process, check that ekiga executable is in your PATH variable.");
71  return false;
72  }
73 
74  const int runs = 100;
75  for (int i = 0; i < runs; ++i) {
76  if (!isEkigaServiceRegistered()) {
77 #if !defined(Q_OS_WIN)
78  ::sleep(2);
79 #else
80  Sleep(2000);
81 #endif
82  } else {
83  break;
84  }
85  }
86  }
87 
88  // check again for the dbus interface
89  mInterface = searchEkigaDBusInterface();
90 
91  if (!mInterface->isValid()) {
92  delete mInterface;
93  mInterface = nullptr;
94 
95  mErrorMessage = i18n("Ekiga Public API (D-Bus) seems to be disabled.");
96  return false;
97  }
98 
99  return true;
100 }
101 
102 bool QEkigaDialer::dialNumber(const QString &number)
103 {
104  if (!initializeEkiga()) {
105  return false;
106  }
107  QDBusReply<void> reply = mInterface->call(QStringLiteral("Call"), number);
108  return true;
109 }
110 
111 bool QEkigaDialer::sendSms(const QString &number, const QString &text)
112 {
113  Q_UNUSED(number)
114  Q_UNUSED(text)
115  mErrorMessage = i18n("Sending an SMS is currently not supported on Ekiga.");
116  return false;
117 }
QDBusConnectionInterface * interface() const const
bool startDetached(qint64 *pid)
QDBusConnection sessionBus()
QDBusReply< bool > isServiceRegistered(const QString &serviceName) const const
QString i18n(const char *text, const TYPE &arg...)
if(recurs()&&!first)
bool isValid(QStringView ifopt)
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Wed Jun 23 2021 23:09:25 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.