Akonadi Contacts

dialphonenumberaction.cpp
1 /*
2  This file is part of Akonadi Contact.
3 
4  SPDX-FileCopyrightText: 2009 Tobias Koenig <[email protected]>
5 
6  SPDX-License-Identifier: LGPL-2.0-or-later
7 */
8 
9 #include "dialphonenumberaction.h"
10 
11 #include "contactactionssettings.h"
12 #include "qdialer.h"
13 #include "qekigadialer.h"
14 #include "qsflphonedialer.h"
15 #include "qskypedialer.h"
16 
17 #include <KContacts/PhoneNumber>
18 #include <KDialogJobUiDelegate>
19 #include <KIO/CommandLauncherJob>
20 #include <KLocalizedString>
21 #include <KMessageBox>
22 
23 #include <QDesktopServices>
24 
25 using namespace Akonadi;
26 
27 void DialPhoneNumberAction::dialNumber(const KContacts::PhoneNumber &number)
28 {
29  // synchronize
30  ContactActionsSettings::self()->load();
31 
32  QDialer *dialer = nullptr;
33  // we handle skype separated
34  if (ContactActionsSettings::self()->dialPhoneNumberAction() == ContactActionsSettings::UseSkype) {
35  dialer = new QSkypeDialer(QStringLiteral("AkonadiContacts"));
36  } else if (ContactActionsSettings::self()->dialPhoneNumberAction() == ContactActionsSettings::UseSflPhone) {
37  dialer = new QSflPhoneDialer(QStringLiteral("AkonadiContacts"));
38  } else if (ContactActionsSettings::self()->dialPhoneNumberAction() == ContactActionsSettings::UseEkiga) {
39  dialer = new QEkigaDialer(QStringLiteral("AkonadiContacts"));
40  }
41  if (dialer) {
42  if (!dialer->dialNumber(number.normalizedNumber())) {
43  KMessageBox::error(nullptr, dialer->errorMessage());
44  }
45  delete dialer;
46  return;
47  }
48 
49  if (ContactActionsSettings::self()->dialPhoneNumberAction() == ContactActionsSettings::UseSystemDefault) {
50  QUrl url;
51  url.setScheme(QStringLiteral("tel"));
52  url.setPath(number.normalizedNumber());
54  return;
55  }
56 
57  QString command = ContactActionsSettings::self()->phoneCommand();
58  if (command.isEmpty()) {
59  KMessageBox::error(nullptr, i18n("There is no application set which could be executed.\nPlease go to the settings dialog and configure one."));
60  return;
61  }
62 
63  /*
64  * %N the raw number
65  * %n the number with all additional non-number characters removed
66  */
67  command.replace(QLatin1String("%N"), number.number());
68  command.replace(QLatin1String("%n"), number.normalizedNumber());
69 
70  auto job = new KIO::CommandLauncherJob(command);
71  job->setUiDelegate(new KDialogJobUiDelegate(KJobUiDelegate::AutoHandlingEnabled, nullptr));
72  job->start();
73 }
QString number(int n, int base)
bool openUrl(const QUrl &url)
void setScheme(const QString &scheme)
QString i18n(const char *text, const TYPE &arg...)
bool isEmpty() const const
void error(QWidget *parent, const QString &text, const QString &title, const KGuiItem &buttonOk, Options options=Notify)
QString & replace(int position, int n, QChar after)
void setPath(const QString &path, QUrl::ParsingMode mode)
KIOCORE_EXPORT QString number(KIO::filesize_t size)
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Sat Apr 1 2023 04:09:04 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.