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