Changeset View
Changeset View
Standalone View
Standalone View
src/akonadi-contacts/actions/sendsmsaction.cpp
Show All 32 Lines | |||||
33 | 33 | | |||
34 | #include <QDesktopServices> | 34 | #include <QDesktopServices> | ||
35 | #include <QPointer> | 35 | #include <QPointer> | ||
36 | #include <QUrl> | 36 | #include <QUrl> | ||
37 | #include <QUrlQuery> | 37 | #include <QUrlQuery> | ||
38 | 38 | | |||
39 | #include <memory> | 39 | #include <memory> | ||
40 | 40 | | |||
41 | static QString strippedSmsNumber(const QString &number) | | |||
42 | { | | |||
43 | QString result; | | |||
44 | | ||||
45 | const int numberLenght(number.length()); | | |||
46 | for (int i = 0; i < numberLenght; ++i) { | | |||
47 | const QChar character = number.at(i); | | |||
48 | if (character.isDigit() || (character == QLatin1Char('+') && i == 0)) { | | |||
49 | result += character; | | |||
50 | } | | |||
51 | } | | |||
52 | | ||||
53 | return result; | | |||
54 | } | | |||
55 | | ||||
56 | void SendSmsAction::sendSms(const KContacts::PhoneNumber &phoneNumber) | 41 | void SendSmsAction::sendSms(const KContacts::PhoneNumber &phoneNumber) | ||
57 | { | 42 | { | ||
58 | const QString number = phoneNumber.number().trimmed(); | 43 | const QString number = phoneNumber.number().trimmed(); | ||
59 | 44 | | |||
60 | // synchronize | 45 | // synchronize | ||
61 | ContactActionsSettings::self()->load(); | 46 | ContactActionsSettings::self()->load(); | ||
62 | 47 | | |||
63 | // check for valid config first, so the user doesn't type the message without a way to actually send it | 48 | // check for valid config first, so the user doesn't type the message without a way to actually send it | ||
Show All 25 Lines | 70 | if (dialer) { | |||
89 | } else { | 74 | } else { | ||
90 | KMessageBox::sorry(nullptr, dialer->errorMessage()); | 75 | KMessageBox::sorry(nullptr, dialer->errorMessage()); | ||
91 | } | 76 | } | ||
92 | } | 77 | } | ||
93 | 78 | | |||
94 | if (ContactActionsSettings::self()->sendSmsAction() == ContactActionsSettings::UseSystemDefaultSms) { | 79 | if (ContactActionsSettings::self()->sendSmsAction() == ContactActionsSettings::UseSystemDefaultSms) { | ||
95 | QUrl url; | 80 | QUrl url; | ||
96 | url.setScheme(QStringLiteral("sms")); | 81 | url.setScheme(QStringLiteral("sms")); | ||
97 | url.setPath(strippedSmsNumber(phoneNumber.number())); | 82 | url.setPath(phoneNumber.normalizedNumber()); | ||
98 | QUrlQuery query; | 83 | QUrlQuery query; | ||
99 | query.addQueryItem(QStringLiteral("body"), message); | 84 | query.addQueryItem(QStringLiteral("body"), message); | ||
100 | url.setQuery(query); | 85 | url.setQuery(query); | ||
101 | QDesktopServices::openUrl(url); | 86 | QDesktopServices::openUrl(url); | ||
102 | return; | 87 | return; | ||
103 | } | 88 | } | ||
104 | 89 | | |||
105 | /* | 90 | /* | ||
106 | * %N the raw number | 91 | * %N the raw number | ||
107 | * %n the number with all additional non-number characters removed | 92 | * %n the number with all additional non-number characters removed | ||
108 | */ | 93 | */ | ||
109 | command = command.replace(QLatin1String("%N"), QStringLiteral("\"%1\"").arg(phoneNumber.number())); | 94 | command = command.replace(QLatin1String("%N"), QStringLiteral("\"%1\"").arg(phoneNumber.number())); | ||
110 | command = command.replace(QLatin1String("%n"), QStringLiteral("\"%1\"").arg(strippedSmsNumber(number))); | 95 | command = command.replace(QLatin1String("%n"), QStringLiteral("\"%1\"").arg(phoneNumber.normalizedNumber())); | ||
111 | command = command.replace(QLatin1String("%t"), QStringLiteral("\"%1\"").arg(message)); | 96 | command = command.replace(QLatin1String("%t"), QStringLiteral("\"%1\"").arg(message)); | ||
112 | //Bug: 293232 In KDE3 We used %F to replace text | 97 | //Bug: 293232 In KDE3 We used %F to replace text | ||
113 | command = command.replace(QLatin1String("%F"), message); | 98 | command = command.replace(QLatin1String("%F"), message); | ||
114 | KRun::runCommand(command, nullptr); | 99 | KRun::runCommand(command, nullptr); | ||
115 | } | 100 | } |