Akonadi Contacts

qsflphonedialer.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 "qsflphonedialer.h"
9 
10 #include <KLocalizedString>
11 
12 #include <QDBusConnection>
13 #include <QDBusConnectionInterface>
14 #include <QProcess>
15 
16 #if !defined(Q_OS_WIN)
17 #include <unistd.h>
18 #else
19 #include <windows.h>
20 #endif
21 
22 static bool isSflPhoneServiceRegistered()
23 {
24  const QString service(QStringLiteral("org.sflphone.SFLphone"));
25 
27  if (interface->isServiceRegistered(service)) {
28  return true;
29  }
30 
31  interface = QDBusConnection::sessionBus().interface();
32  if (interface->isServiceRegistered(service)) {
33  return true;
34  }
35  return false;
36 }
37 
38 QSflPhoneDialer::QSflPhoneDialer(const QString &applicationName)
39  : QDialer(applicationName)
40 {
41 }
42 
43 QSflPhoneDialer::~QSflPhoneDialer()
44 {
45 }
46 
47 bool QSflPhoneDialer::initializeSflPhone()
48 {
49  // first check whether dbus interface is available yet
50  if (!isSflPhoneServiceRegistered()) {
51  // it could be skype is not running yet, so start it now
52  if (!QProcess::startDetached(QStringLiteral("sflphone-client-kde"), QStringList())) {
53  mErrorMessage = i18n("Unable to start sflphone-client-kde process, check that sflphone-client-kde executable is in your PATH variable.");
54  return false;
55  }
56 
57  const int runs = 100;
58  for (int i = 0; i < runs; ++i) {
59  if (!isSflPhoneServiceRegistered()) {
60 #if !defined(Q_OS_WIN)
61  ::sleep(2);
62 #else
63  Sleep(2000);
64 #endif
65  } else {
66  return true;
67  }
68  }
69  }
70  return true;
71 }
72 
73 bool QSflPhoneDialer::dialNumber(const QString &number)
74 {
75  if (!initializeSflPhone()) {
76  return false;
77  }
78 
79  QStringList arguments;
80  arguments << QStringLiteral("--place-call");
81  arguments << number;
82  if (!QProcess::startDetached(QStringLiteral("sflphone-client-kde"), arguments)) {
83  return false;
84  }
85 
86  return true;
87 }
88 
89 bool QSflPhoneDialer::sendSms(const QString &number, const QString &text)
90 {
91  if (!initializeSflPhone()) {
92  return false;
93  }
94 
95  QStringList arguments;
96  arguments << QStringLiteral("--send-text");
97  arguments << number;
98  arguments << QStringLiteral("--message");
99  arguments << text;
100  if (!QProcess::startDetached(QStringLiteral("sflphone-client-kde"), arguments)) {
101  return false;
102  }
103  return true;
104 }
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...)
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.