22 #include "sendsmsaction.h"
24 #include "contactactionssettings.h"
25 #include "qskypedialer.h"
26 #include "smsdialog.h"
28 #include <kabc/phonenumber.h>
29 #include <klocalizedstring.h>
30 #include <kmessagebox.h>
35 static 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 ) ) {
49 void 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. Please 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() );
73 if ( ContactActionsSettings::self()->sendSmsAction() == ContactActionsSettings::UseSkypeSms ) {
74 QSkypeDialer dialer( QLatin1String(
"AkonadiContacts" ) );
75 if ( dialer.sendSms( number, message ) ) {
79 KMessageBox::sorry( 0, dialer.errorMessage() );
89 command = command.replace( QLatin1String(
"%N" ), phoneNumber.number() );
90 command = command.replace( QLatin1String(
"%n" ), strippedSmsNumber( number ) );
91 command = command.replace( QLatin1String(
"%t" ), message );
93 command = command.replace( QLatin1String(
"%F" ), message );
94 KRun::runCommand( command, 0 );