00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
#include "kdcopservicestarter.h"
00020
#include "ktrader.h"
00021
#include <kapplication.h>
00022
#include "kservice.h"
00023
#include <kstaticdeleter.h>
00024
#include <kdebug.h>
00025
#include <klocale.h>
00026
#include <dcopclient.h>
00027
00028
static KStaticDeleter<KDCOPServiceStarter> dss_sd;
00029
KDCOPServiceStarter* KDCOPServiceStarter::s_self;
00030
00031
KDCOPServiceStarter* KDCOPServiceStarter::self()
00032 {
00033
if ( !s_self )
00034 dss_sd.setObject( s_self,
new KDCOPServiceStarter );
00035
return s_self;
00036 }
00037
00038 KDCOPServiceStarter::KDCOPServiceStarter()
00039 {
00040
00041
00042 s_self =
this;
00043 }
00044
00045 KDCOPServiceStarter::~KDCOPServiceStarter()
00046 {
00047 }
00048
00049 int KDCOPServiceStarter::findServiceFor(
const QString& serviceType,
00050
const QString& _constraint,
00051
const QString& preferences,
00052
QString *error,
QCString* pDcopService,
00053
int flags )
00054 {
00055
00056
00057
QString constraint = _constraint;
00058
if ( !constraint.
isEmpty() )
00059 constraint +=
" and ";
00060 constraint +=
"exist [X-DCOP-ServiceName]";
00061
KTrader::OfferList offers = KTrader::self()->query(serviceType,
"Application", constraint, preferences);
00062
if ( offers.
isEmpty() ) {
00063
if ( error )
00064 *error = i18n(
"No service implementing %1").
arg( serviceType );
00065
kdWarning() <<
"KDCOPServiceStarter: No service implementing " << serviceType <<
endl;
00066
return -1;
00067 }
00068
KService::Ptr ptr = offers.
first();
00069
QCString dcopService = ptr->property(
"X-DCOP-ServiceName").toString().latin1();
00070
00071
if ( !kapp->dcopClient()->isApplicationRegistered( dcopService ) )
00072 {
00073
QString error;
00074
if (
startServiceFor( serviceType, constraint, preferences, &error, &dcopService, flags ) != 0 )
00075 {
00076
kdDebug() <<
"KDCOPServiceStarter: Couldn't start service: " << error <<
endl;
00077
return -2;
00078 }
00079 }
00080
kdDebug() <<
"KDCOPServiceStarter: DCOP service is available now, as " << dcopService <<
endl;
00081
if ( pDcopService )
00082 *pDcopService = dcopService;
00083
return 0;
00084 }
00085
00086 int KDCOPServiceStarter::startServiceFor(
const QString& serviceType,
00087
const QString& constraint,
00088
const QString& preferences,
00089
QString *error,
QCString* dcopService,
int )
00090 {
00091
KTrader::OfferList offers = KTrader::self()->query(serviceType,
"Application", constraint, preferences);
00092
if ( offers.
isEmpty() )
00093
return -1;
00094
KService::Ptr ptr = offers.
first();
00095
kdDebug() <<
"KDCOPServiceStarter: starting " << ptr->desktopEntryPath() <<
endl;
00096
return kapp->startServiceByDesktopPath( ptr->desktopEntryPath(),
QStringList(), error, dcopService );
00097 }