• Skip to content
  • Skip to link menu
KDE 4.5 API Reference
  • KDE API Reference
  • KDE-PIM Libraries
  • Sitemap
  • Contact Us
 

akonadi/contact

qskypedialer.cpp

00001 /*
00002     This file is part of Akonadi Contact.
00003 
00004     Copyright (c) 2009 Tobias Koenig <tokoe@kde.org>
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 "qskypedialer.h"
00023 
00024 #include <QtCore/QProcess>
00025 #include <QtDBus/QDBusConnection>
00026 #include <QtDBus/QDBusConnectionInterface>
00027 #include <QtDBus/QDBusInterface>
00028 #include <QtDBus/QDBusReply>
00029 
00030 #include <klocale.h>
00031 
00032 #include <unistd.h>
00033 
00034 static bool isSkypeServiceRegistered()
00035 {
00036   const QLatin1String service( "com.Skype.API" );
00037 
00038   QDBusConnectionInterface *interface = QDBusConnection::systemBus().interface();
00039   if ( interface->isServiceRegistered( service ) )
00040     return true;
00041 
00042   interface = QDBusConnection::sessionBus().interface();
00043   if ( interface->isServiceRegistered( service ) )
00044     return true;
00045 
00046   return false;
00047 }
00048 
00049 static QDBusInterface* searchSkypeDBusInterface()
00050 {
00051   const QLatin1String service( "com.Skype.API" );
00052   const QLatin1String path( "/com/Skype" );
00053 
00054   QDBusInterface *interface = new QDBusInterface( service, path, QString(), QDBusConnection::systemBus() );
00055   if ( !interface->isValid() ) {
00056     delete interface;
00057     interface = new QDBusInterface( service, path, QString(), QDBusConnection::sessionBus() );
00058   }
00059 
00060   return interface;
00061 }
00062 
00063 QSkypeDialer::QSkypeDialer( const QString &applicationName )
00064   : mApplicationName( applicationName )
00065 {
00066 }
00067 
00068 bool QSkypeDialer::dialNumber( const QString &number )
00069 {
00070   // first check whether dbus interface is available yet
00071   if ( !isSkypeServiceRegistered() ) {
00072 
00073     // it could be skype is not running yet, so start it now
00074     if ( !QProcess::startDetached( QLatin1String( "skype" ), QStringList() ) ) {
00075       mErrorMessage = i18n( "Unable to start skype process, check that skype executable is in your PATH variable." );
00076       return false;
00077     }
00078 
00079     const int runs = 100;
00080     for ( int i = 0; i < runs; ++i ) {
00081       if ( !isSkypeServiceRegistered() )
00082         ::sleep( 2 );
00083       else
00084         break;
00085     }
00086   }
00087 
00088   // check again for the dbus interface
00089   QDBusInterface *interface = searchSkypeDBusInterface();
00090 
00091   if ( !interface->isValid() ) {
00092     delete interface;
00093 
00094     mErrorMessage = i18n( "Skype Public API (D-Bus) seems to be disabled." );
00095     return false;
00096   }
00097 
00098   QDBusReply<QString> reply = interface->call( QLatin1String( "Invoke" ), QString::fromLatin1( "NAME %1" ).arg( mApplicationName ) );
00099   if ( reply.value() != QLatin1String( "OK" ) ) {
00100     delete interface;
00101 
00102     mErrorMessage = i18n( "Skype registration failed." );
00103     return false;
00104   }
00105 
00106   reply = interface->call( QLatin1String( "Invoke" ), QLatin1String( "PROTOCOL 1" ) );
00107   if ( reply.value() != QLatin1String( "PROTOCOL 1" ) ) {
00108     delete interface;
00109 
00110     mErrorMessage = i18n( "Protocol mismatch." );
00111     return false;
00112   }
00113 
00114   reply = interface->call( QLatin1String( "Invoke" ), QString::fromLatin1( "CALL %1" ).arg( number ) );
00115 
00116   delete interface;
00117 
00118   return true;
00119 }
00120 
00121 QString QSkypeDialer::errorMessage() const
00122 {
00123   return mErrorMessage;
00124 }

akonadi/contact

Skip menu "akonadi/contact"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

KDE-PIM Libraries

Skip menu "KDE-PIM Libraries"
  • akonadi
  •   contact
  •   kmime
  • kabc
  • kblog
  • kcal
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • 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.1
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