00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "sendsmsaction.h"
00023
00024 #include "contactactionssettings.h"
00025 #include "qskypedialer.h"
00026 #include "smsdialog.h"
00027
00028 #include <kabc/phonenumber.h>
00029 #include <klocale.h>
00030 #include <kmessagebox.h>
00031 #include <krun.h>
00032
00033 static QString strippedSmsNumber( const QString &number )
00034 {
00035 QString result;
00036
00037 for ( int i = 0; i < number.length(); ++i ) {
00038 const QChar character = number.at( i );
00039 if ( character.isDigit() || (character == QLatin1Char( '+' ) && i == 0) )
00040 result += character;
00041 }
00042
00043 return result;
00044 }
00045
00046 void SendSmsAction::sendSms( const KABC::PhoneNumber &phoneNumber )
00047 {
00048 const QString number = phoneNumber.number().trimmed();
00049
00050 SmsDialog dlg( number );
00051 if ( !dlg.exec() )
00052 return;
00053
00054
00055 ContactActionsSettings::self()->readConfig();
00056
00057
00058 if ( ContactActionsSettings::self()->sendSmsAction() == ContactActionsSettings::UseSkypeSms ) {
00059 QSkypeDialer dialer( QLatin1String( "AkonadiContacts" ) );
00060 if ( dialer.sendSms( number, dlg.message() ) ) {
00061
00062
00063 } else {
00064 KMessageBox::sorry( 0, dialer.errorMessage() );
00065 }
00066
00067 return;
00068 }
00069
00070 QString command = ContactActionsSettings::self()->smsCommand();
00071
00072 if ( command.isEmpty() ) {
00073 KMessageBox::sorry( 0, i18n( "There is no application set which could be executed. Please go to the settings dialog and configure one." ) );
00074 return;
00075 }
00076
00077
00078
00079
00080
00081 command = command.replace( QLatin1String( "%N" ), phoneNumber.number() );
00082 command = command.replace( QLatin1String( "%n" ), strippedSmsNumber( number ) );
00083 command = command.replace( QLatin1String( "%t" ), dlg.message() );
00084
00085 KRun::runCommand( command, 0 );
00086 }