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

akonadi

control.cpp

00001 /*
00002     Copyright (c) 2007 Volker Krause <vkrause@kde.org>
00003 
00004     This library is free software; you can redistribute it and/or modify it
00005     under the terms of the GNU Library General Public License as published by
00006     the Free Software Foundation; either version 2 of the License, or (at your
00007     option) any later version.
00008 
00009     This library is distributed in the hope that it will be useful, but WITHOUT
00010     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00011     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00012     License for more details.
00013 
00014     You should have received a copy of the GNU Library General Public License
00015     along with this library; see the file COPYING.LIB.  If not, write to the
00016     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00017     02110-1301, USA.
00018 */
00019 
00020 #include "control.h"
00021 
00022 #include <kdebug.h>
00023 #include <kglobal.h>
00024 
00025 #include <QtCore/QEventLoop>
00026 #include <QtCore/QProcess>
00027 #include <QtCore/QTimer>
00028 #include <QtDBus/QDBusConnection>
00029 #include <QtDBus/QDBusConnectionInterface>
00030 
00031 #define AKONADI_CONTROL_SERVICE QLatin1String("org.freedesktop.Akonadi.Control")
00032 #define AKONADI_SERVER_SERVICE QLatin1String("org.freedesktop.Akonadi")
00033 
00034 using namespace Akonadi;
00035 
00039 class Control::Private
00040 {
00041   public:
00042     Private( Control *parent )
00043       : mParent( parent ), mEventLoop( 0 ), mSuccess( false )
00044     {
00045     }
00046 
00047     bool startInternal();
00048     void serviceOwnerChanged( const QString&, const QString&, const QString& );
00049 
00050     Control *mParent;
00051     QEventLoop *mEventLoop;
00052     bool mSuccess;
00053 };
00054 
00055 class StaticControl : public Control
00056 {
00057   public:
00058     StaticControl() : Control() {}
00059 };
00060 
00061 K_GLOBAL_STATIC( StaticControl, s_instance )
00062 
00063 
00064 bool Control::Private::startInternal()
00065 {
00066   if ( QDBusConnection::sessionBus().interface()->isServiceRegistered( AKONADI_CONTROL_SERVICE ) || mEventLoop )
00067     return true;
00068 
00069   QDBusReply<void> reply = QDBusConnection::sessionBus().interface()->startService( AKONADI_CONTROL_SERVICE );
00070   if ( !reply.isValid() ) {
00071     kWarning( 5250 ) << "Unable to start Akonadi control process: "
00072                      << reply.error().message();
00073 
00074     // start via D-Bus .service file didn't work, let's try starting the process manually
00075     if ( reply.error().type() == QDBusError::ServiceUnknown ) {
00076       const bool ok = QProcess::startDetached( QLatin1String("akonadi_control") );
00077       if ( !ok ) {
00078         kWarning( 5250 ) << "Error: unable to execute binary akonadi_control";
00079         return false;
00080       }
00081     } else {
00082       return false;
00083     }
00084   }
00085 
00086   mEventLoop = new QEventLoop( mParent );
00087   // safety timeout
00088   QTimer::singleShot( 10000, mEventLoop, SLOT(quit()) );
00089   mEventLoop->exec();
00090   mEventLoop->deleteLater();
00091   mEventLoop = 0;
00092 
00093   if ( !mSuccess )
00094     kWarning( 5250 ) << "Could not start Akonadi!";
00095   return mSuccess;
00096 }
00097 
00098 void Control::Private::serviceOwnerChanged( const QString & name, const QString & oldOwner, const QString & newOwner )
00099 {
00100   Q_UNUSED( oldOwner );
00101   if ( name == AKONADI_SERVER_SERVICE && !newOwner.isEmpty() && mEventLoop && mEventLoop->isRunning() ) {
00102     mEventLoop->quit();
00103     mSuccess = true;
00104   }
00105 }
00106 
00107 
00108 Control::Control()
00109   : d( new Private( this ) )
00110 {
00111   connect( QDBusConnection::sessionBus().interface(), SIGNAL( serviceOwnerChanged( QString, QString, QString ) ),
00112            SLOT( serviceOwnerChanged( QString, QString, QString ) ) );
00113 }
00114 
00115 Control::~Control()
00116 {
00117   delete d;
00118 }
00119 
00120 bool Control::start()
00121 {
00122   return s_instance->d->startInternal();
00123 }
00124 
00125 #include "control.moc"

akonadi

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

KDE-PIM Libraries

Skip menu "KDE-PIM Libraries"
  • akonadi
  • kabc
  • kblog
  • kcal
  • kimap
  • kioslave
  •   imap4
  •   mbox
  • kldap
  • kmime
  • kpimidentities
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Generated for KDE-PIM Libraries by doxygen 1.5.4
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