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 <KDialogJobUiDelegate>
18 #include <KIO/CommandLauncherJob>
19 #include <KLocalizedString>
20 #include <KMessageBox>
21 #include <kcontacts/phonenumber.h>
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::sorry(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::sorry(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 normalizedNumber() const
void setPath(const QString &path, QUrl::ParsingMode mode)
QString number() const
bool isEmpty() const const
void setScheme(const QString &scheme)
QString i18n(const char *text, const TYPE &arg...)
QString & replace(int position, int n, QChar after)
bool openUrl(const QUrl &url)
void sorry(QWidget *parent, const QString &text, const QString &caption=QString(), Options options=Notify)
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Wed Jun 23 2021 23:09:24 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.