• Skip to content
  • Skip to link menu
KDE 4.7 API Reference
  • KDE API Reference
  • KDE-PIM Libraries
  • KDE Home
  • Contact Us
 

akonadi

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 
00085   KRun::runCommand( command, 0 );
00086 }

akonadi

Skip menu "akonadi"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • Modules
  • Related Pages

KDE-PIM Libraries

Skip menu "KDE-PIM Libraries"
  • akonadi
  •   contact
  •   kmime
  • kabc
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  •   richtextbuilders
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Generated for KDE-PIM Libraries by doxygen 1.7.5
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal