Changeset View
Changeset View
Standalone View
Standalone View
src/akonadi-contacts/actions/dialphonenumberaction.cpp
Show All 30 Lines | |||||
31 | #include <KLocalizedString> | 31 | #include <KLocalizedString> | ||
32 | #include <KMessageBox> | 32 | #include <KMessageBox> | ||
33 | #include <krun.h> | 33 | #include <krun.h> | ||
34 | 34 | | |||
35 | #include <QDesktopServices> | 35 | #include <QDesktopServices> | ||
36 | 36 | | |||
37 | using namespace Akonadi; | 37 | using namespace Akonadi; | ||
38 | 38 | | |||
39 | static QString strippedDialNumber(const QString &number) | | |||
40 | { | | |||
41 | QString result; | | |||
42 | | ||||
43 | const int numberLength(number.length()); | | |||
44 | for (int i = 0; i < numberLength; ++i) { | | |||
45 | const QChar character = number.at(i); | | |||
46 | if (character.isDigit() || (character == QLatin1Char('+') && i == 0)) { | | |||
47 | result += character; | | |||
48 | } | | |||
49 | } | | |||
50 | | ||||
51 | return result; | | |||
52 | } | | |||
53 | | ||||
54 | void DialPhoneNumberAction::dialNumber(const KContacts::PhoneNumber &number) | 39 | void DialPhoneNumberAction::dialNumber(const KContacts::PhoneNumber &number) | ||
55 | { | 40 | { | ||
56 | // synchronize | 41 | // synchronize | ||
57 | ContactActionsSettings::self()->load(); | 42 | ContactActionsSettings::self()->load(); | ||
58 | 43 | | |||
59 | QDialer *dialer = nullptr; | 44 | QDialer *dialer = nullptr; | ||
60 | // we handle skype separated | 45 | // we handle skype separated | ||
61 | if (ContactActionsSettings::self()->dialPhoneNumberAction() == ContactActionsSettings::UseSkype) { | 46 | if (ContactActionsSettings::self()->dialPhoneNumberAction() == ContactActionsSettings::UseSkype) { | ||
62 | dialer = new QSkypeDialer(QStringLiteral("AkonadiContacts")); | 47 | dialer = new QSkypeDialer(QStringLiteral("AkonadiContacts")); | ||
63 | } else if (ContactActionsSettings::self()->dialPhoneNumberAction() == ContactActionsSettings::UseSflPhone) { | 48 | } else if (ContactActionsSettings::self()->dialPhoneNumberAction() == ContactActionsSettings::UseSflPhone) { | ||
64 | dialer = new QSflPhoneDialer(QStringLiteral("AkonadiContacts")); | 49 | dialer = new QSflPhoneDialer(QStringLiteral("AkonadiContacts")); | ||
65 | } else if (ContactActionsSettings::self()->dialPhoneNumberAction() == ContactActionsSettings::UseEkiga) { | 50 | } else if (ContactActionsSettings::self()->dialPhoneNumberAction() == ContactActionsSettings::UseEkiga) { | ||
66 | dialer = new QEkigaDialer(QStringLiteral("AkonadiContacts")); | 51 | dialer = new QEkigaDialer(QStringLiteral("AkonadiContacts")); | ||
67 | } | 52 | } | ||
68 | if (dialer) { | 53 | if (dialer) { | ||
69 | if (!dialer->dialNumber(strippedDialNumber(number.number().trimmed()))) { | 54 | if (!dialer->dialNumber(number.normalizedNumber())) { | ||
70 | KMessageBox::sorry(nullptr, dialer->errorMessage()); | 55 | KMessageBox::sorry(nullptr, dialer->errorMessage()); | ||
71 | } | 56 | } | ||
72 | delete dialer; | 57 | delete dialer; | ||
73 | return; | 58 | return; | ||
74 | } | 59 | } | ||
75 | 60 | | |||
76 | if (ContactActionsSettings::self()->dialPhoneNumberAction() == ContactActionsSettings::UseSystemDefault) { | 61 | if (ContactActionsSettings::self()->dialPhoneNumberAction() == ContactActionsSettings::UseSystemDefault) { | ||
77 | QUrl url; | 62 | QUrl url; | ||
78 | url.setScheme(QStringLiteral("tel")); | 63 | url.setScheme(QStringLiteral("tel")); | ||
79 | url.setPath(strippedDialNumber(number.number())); | 64 | url.setPath(number.normalizedNumber()); | ||
80 | QDesktopServices::openUrl(url); | 65 | QDesktopServices::openUrl(url); | ||
81 | return; | 66 | return; | ||
82 | } | 67 | } | ||
83 | 68 | | |||
84 | QString command = ContactActionsSettings::self()->phoneCommand(); | 69 | QString command = ContactActionsSettings::self()->phoneCommand(); | ||
85 | if (command.isEmpty()) { | 70 | if (command.isEmpty()) { | ||
86 | KMessageBox::sorry(nullptr, i18n("There is no application set which could be executed.\nPlease go to the settings dialog and configure one.")); | 71 | KMessageBox::sorry(nullptr, i18n("There is no application set which could be executed.\nPlease go to the settings dialog and configure one.")); | ||
87 | return; | 72 | return; | ||
88 | } | 73 | } | ||
89 | 74 | | |||
90 | /* | 75 | /* | ||
91 | * %N the raw number | 76 | * %N the raw number | ||
92 | * %n the number with all additional non-number characters removed | 77 | * %n the number with all additional non-number characters removed | ||
93 | */ | 78 | */ | ||
94 | command = command.replace(QLatin1String("%N"), number.number()); | 79 | command = command.replace(QLatin1String("%N"), number.number()); | ||
95 | command = command.replace(QLatin1String("%n"), strippedDialNumber(number.number().trimmed())); | 80 | command = command.replace(QLatin1String("%n"), number.normalizedNumber()); | ||
96 | 81 | | |||
97 | KRun::runCommand(command, nullptr); | 82 | KRun::runCommand(command, nullptr); | ||
98 | } | 83 | } |