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 "qdialer.h"
00026 #include "qskypedialer.h"
00027 #ifdef Q_OS_WINCE
00028 #include "qwincedialer.h"
00029 #endif // Q_OS_WINCE
00030
00031 #include <kabc/phonenumber.h>
00032 #include <kconfig.h>
00033 #include <kconfiggroup.h>
00034 #include <klocale.h>
00035 #include <kmessagebox.h>
00036 #include <krun.h>
00037
00038 using namespace Akonadi;
00039
00040 static QString strippedDialNumber( const QString &number )
00041 {
00042 QString result;
00043
00044 for ( int i = 0; i < number.length(); ++i ) {
00045 const QChar character = number.at( i );
00046 if ( character.isDigit() || (character == QLatin1Char( '+' ) && i == 0) )
00047 result += character;
00048 }
00049
00050 return result;
00051 }
00052
00053 void DialPhoneNumberAction::dialNumber( const KABC::PhoneNumber &number )
00054 {
00055
00056 ContactActionsSettings::self()->readConfig();
00057
00058 QDialer *dialer = NULL;
00059
00060 if ( ContactActionsSettings::self()->dialPhoneNumberAction() == ContactActionsSettings::UseSkype ) {
00061 dialer = new QSkypeDialer( QLatin1String( "AkonadiContacts" ) );
00062 }
00063 #ifdef Q_OS_WINCE
00064 else if ( ContactActionsSettings::self()->dialPhoneNumberAction() == ContactActionsSettings::UseWinCE ) {
00065 dialer = new QWinCEDialer( QLatin1String( "AkonadiContacts" ) );
00066 }
00067 #endif // Q_OS_WINCE
00068 if ( dialer ) {
00069 if ( !dialer->dialNumber( strippedDialNumber( number.number().trimmed() ) ) ) {
00070 KMessageBox::sorry( 0, dialer->errorMessage() );
00071 }
00072 delete dialer;
00073 return;
00074 }
00075
00076 QString command = ContactActionsSettings::self()->phoneCommand();
00077
00078 if ( command.isEmpty() ) {
00079 KMessageBox::sorry( 0, i18n( "There is no application set which could be executed. Please go to the settings dialog and configure one." ) );
00080 return;
00081 }
00082
00083
00084
00085
00086
00087 command = command.replace( QLatin1String( "%N" ), number.number() );
00088 command = command.replace( QLatin1String( "%n" ), strippedDialNumber( number.number().trimmed() ) );
00089
00090 KRun::runCommand( command, 0 );
00091 }