22#include "sendsmsaction.h"
24#include "contactactionssettings.h"
25#include "qskypedialer.h"
28#include <kabc/phonenumber.h>
29#include <klocalizedstring.h>
30#include <kmessagebox.h>
35static QString strippedSmsNumber(
const QString &number)
39 for (
int i = 0; i < number.length(); ++i) {
40 const QChar character = number.at(i);
41 if (character.isDigit() || (character == QLatin1Char(
'+') && i == 0)) {
49void SendSmsAction::sendSms(
const KABC::PhoneNumber &phoneNumber)
51 const QString number = phoneNumber.number().trimmed();
54 ContactActionsSettings::self()->readConfig();
56 QString command = ContactActionsSettings::self()->smsCommand();
58 if (command.isEmpty()) {
59 KMessageBox::sorry(0, i18n(
"There is no application set which could be executed.\nPlease go to the settings dialog and configure one."));
63 QPointer<SmsDialog> dlg(
new SmsDialog(number));
64 if (dlg->exec() != QDialog::Accepted) {
68 const QString message = (dlg != 0 ? dlg->message() : QString());
72 if (ContactActionsSettings::self()->sendSmsAction() == ContactActionsSettings::UseSkypeSms) {
73 QSkypeDialer dialer(QLatin1String(
"AkonadiContacts"));
74 if (dialer.sendSms(number, message)) {
78 KMessageBox::sorry(0, dialer.errorMessage());
88 command = command.replace(QLatin1String(
"%N"), phoneNumber.number());
89 command = command.replace(QLatin1String(
"%n"), strippedSmsNumber(number));
90 command = command.replace(QLatin1String(
"%t"), message);
92 command = command.replace(QLatin1String(
"%F"), message);
93 KRun::runCommand(command, 0);