Akonadi Contacts

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

KDE's Doxygen guidelines are available online.