kmail

korghelper.cpp
1 /*
2  Copyright (c) 2007 Volker Krause <vkrause@kde.org>
3 
4  This library is free software; you can redistribute it and/or modify it
5  under the terms of the GNU Library General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or (at your
7  option) any later version.
8 
9  This library is distributed in the hope that it will be useful, but WITHOUT
10  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12  License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to the
16  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  02110-1301, USA.
18 */
19 
20 #include "korghelper.h"
21 
22 #include <dcopclient.h>
23 #include <dcopref.h>
24 #include <tdeapplication.h>
25 #include <kdebug.h>
26 #include <kdcopservicestarter.h>
27 
28 void KMail::KorgHelper::ensureRunning()
29 {
30  TQString error;
31  TQCString dcopService;
32  int result = KDCOPServiceStarter::self()->findServiceFor( "DCOP/Organizer", TQString(), TQString(), &error, &dcopService );
33  if ( result == 0 ) {
34  // OK, so korganizer (or kontact) is running. Now ensure the object we want is available
35  // [that's not the case when kontact was already running, but korganizer not loaded into it...]
36  static const char* const dcopObjectId = "KOrganizerIface";
37  TQCString dummy;
38  if ( !kapp->dcopClient()->findObject( dcopService, dcopObjectId, "", TQByteArray(), dummy, dummy ) ) {
39  DCOPRef ref( dcopService, dcopService ); // talk to the TDEUniqueApplication or its kontact wrapper
40  DCOPReply reply = ref.call( "load()" );
41  if ( reply.isValid() && (bool)reply ) {
42  kdDebug() << "Loaded " << dcopService << " successfully" << endl;
43  Q_ASSERT( kapp->dcopClient()->findObject( dcopService, dcopObjectId, "", TQByteArray(), dummy, dummy ) );
44  } else
45  kdWarning() << "Error loading " << dcopService << endl;
46  }
47 
48  // We don't do anything with it, we just need it to be running so that it handles
49  // the incoming directory.
50  }
51  else
52  kdWarning() << "Couldn't start DCOP/Organizer: " << dcopService << " " << error << endl;
53 }