kmail

korghelper.cpp

Go to the documentation of this file.
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 "korghelper.h"
00021 
00022 #include <dcopclient.h>
00023 #include <dcopref.h>
00024 #include <kapplication.h>
00025 #include <kdebug.h>
00026 #include <kdcopservicestarter.h>
00027 
00028 void KMail::KorgHelper::ensureRunning()
00029 {
00030   QString error;
00031   QCString dcopService;
00032   int result = KDCOPServiceStarter::self()->findServiceFor( "DCOP/Organizer", QString::null, QString::null, &error, &dcopService );
00033   if ( result == 0 ) {
00034     // OK, so korganizer (or kontact) is running. Now ensure the object we want is available
00035     // [that's not the case when kontact was already running, but korganizer not loaded into it...]
00036     static const char* const dcopObjectId = "KOrganizerIface";
00037     QCString dummy;
00038     if ( !kapp->dcopClient()->findObject( dcopService, dcopObjectId, "", QByteArray(), dummy, dummy ) ) {
00039       DCOPRef ref( dcopService, dcopService ); // talk to the KUniqueApplication or its kontact wrapper
00040       DCOPReply reply = ref.call( "load()" );
00041       if ( reply.isValid() && (bool)reply ) {
00042         kdDebug() << "Loaded " << dcopService << " successfully" << endl;
00043         Q_ASSERT( kapp->dcopClient()->findObject( dcopService, dcopObjectId, "", QByteArray(), dummy, dummy ) );
00044       } else
00045         kdWarning() << "Error loading " << dcopService << endl;
00046     }
00047 
00048     // We don't do anything with it, we just need it to be running so that it handles
00049     // the incoming directory.
00050   }
00051   else
00052     kdWarning() << "Couldn't start DCOP/Organizer: " << dcopService << " " << error << endl;
00053 }