akonadi/contact
sendsmsaction.cpp
00001 /* 00002 This file is part of Akonadi Contact. 00003 00004 Copyright (c) 2010 Felix Mauch (felix_mauch@web.de) 00005 00006 This library is free software; you can redistribute it and/or modify it 00007 under the terms of the GNU Library General Public License as published by 00008 the Free Software Foundation; either version 2 of the License, or (at your 00009 option) any later version. 00010 00011 This library is distributed in the hope that it will be useful, but WITHOUT 00012 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00013 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 00014 License for more details. 00015 00016 You should have received a copy of the GNU Library General Public License 00017 along with this library; see the file COPYING.LIB. If not, write to the 00018 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 00019 02110-1301, USA. 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() ) // the cancel button has been clicked 00052 return; 00053 00054 // synchronize 00055 ContactActionsSettings::self()->readConfig(); 00056 00057 // we handle skype separated 00058 if ( ContactActionsSettings::self()->sendSmsAction() == ContactActionsSettings::UseSkypeSms ) { 00059 QSkypeDialer dialer( QLatin1String( "AkonadiContacts" ) ); 00060 if ( dialer.sendSms( number, dlg.message() ) ) { 00061 // I'm not sure whether here should be a notification. 00062 // Skype can do a notification itself if whished. 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 * %N the raw number 00079 * %n the number with all additional non-number characters removed 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 //Bug: 293232 In KDE3 We used %F to replace text 00085 command = command.replace( QLatin1String( "%F" ), dlg.message() ); 00086 KRun::runCommand( command, 0 ); 00087 }
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Thu Aug 2 2012 15:25:43 by doxygen 1.7.5 written by Dimitri van Heesch, © 1997-2006
Documentation copyright © 1996-2012 The KDE developers.
Generated on Thu Aug 2 2012 15:25:43 by doxygen 1.7.5 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.