• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • kio/kio
 

kio/kio

  • kio
  • kio
kdcopservicestarter.cpp
1 /* This file is part of the KDE libraries
2  Copyright (C) 2003 David Faure <faure@kde.org>
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Library General Public
6  License version 2 as published by the Free Software Foundation.
7 
8  This library is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  Library General Public License for more details.
12 
13  You should have received a copy of the GNU Library General Public License
14  along with this library; see the file COPYING.LIB. If not, write to
15  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16  Boston, MA 02110-1301, USA.
17 */
18 
19 #include "kdcopservicestarter.h"
20 #include "ktrader.h"
21 #include <kapplication.h>
22 #include "kservice.h"
23 #include <kstaticdeleter.h>
24 #include <kdebug.h>
25 #include <klocale.h>
26 #include <dcopclient.h>
27 
28 static KStaticDeleter<KDCOPServiceStarter> dss_sd;
29 KDCOPServiceStarter* KDCOPServiceStarter::s_self;
30 
31 KDCOPServiceStarter* KDCOPServiceStarter::self()
32 {
33  if ( !s_self )
34  dss_sd.setObject( s_self, new KDCOPServiceStarter );
35  return s_self;
36 }
37 
38 KDCOPServiceStarter::KDCOPServiceStarter()
39 {
40  // Set the singleton instance - useful when a derived KDCOPServiceStarter
41  // was created (before self() was called)
42  s_self = this;
43 }
44 
45 KDCOPServiceStarter::~KDCOPServiceStarter()
46 {
47 }
48 
49 int KDCOPServiceStarter::findServiceFor( const TQString& serviceType,
50  const TQString& _constraint,
51  const TQString& preferences,
52  TQString *error, TQCString* pDcopService,
53  int flags )
54 {
55  // Ask the trader which service is preferred for this servicetype
56  // We want one that provides a DCOP interface
57  TQString constraint = _constraint;
58  if ( !constraint.isEmpty() )
59  constraint += " and ";
60  constraint += "exist [X-DCOP-ServiceName]";
61  KTrader::OfferList offers = KTrader::self()->query(serviceType, "Application", constraint, preferences);
62  if ( offers.isEmpty() ) {
63  if ( error )
64  *error = i18n("No service implementing %1").arg( serviceType );
65  kdWarning() << "KDCOPServiceStarter: No service implementing " << serviceType << endl;
66  return -1;
67  }
68  KService::Ptr ptr = offers.first();
69  TQCString dcopService = ptr->property("X-DCOP-ServiceName").toString().latin1();
70 
71  if ( !kapp->dcopClient()->isApplicationRegistered( dcopService ) )
72  {
73  TQString error;
74  if ( startServiceFor( serviceType, constraint, preferences, &error, &dcopService, flags ) != 0 )
75  {
76  kdDebug() << "KDCOPServiceStarter: Couldn't start service: " << error << endl;
77  return -2;
78  }
79  }
80  kdDebug() << "KDCOPServiceStarter: DCOP service is available now, as " << dcopService << endl;
81  if ( pDcopService )
82  *pDcopService = dcopService;
83  return 0;
84 }
85 
86 int KDCOPServiceStarter::startServiceFor( const TQString& serviceType,
87  const TQString& constraint,
88  const TQString& preferences,
89  TQString *error, TQCString* dcopService, int /*flags*/ )
90 {
91  KTrader::OfferList offers = KTrader::self()->query(serviceType, "Application", constraint, preferences);
92  if ( offers.isEmpty() )
93  return -1;
94  KService::Ptr ptr = offers.first();
95  kdDebug() << "KDCOPServiceStarter: starting " << ptr->desktopEntryPath() << endl;
96  return kapp->startServiceByDesktopPath( ptr->desktopEntryPath(), TQStringList(), error, dcopService );
97 }
KDCOPServiceStarter
A generic DCOP service starter, using KTrader.
Definition: kdcopservicestarter.h:34
KTrader::query
virtual OfferList query(const TQString &servicetype, const TQString &constraint=TQString::null, const TQString &preferences=TQString::null) const
The main function in the KTrader class.
Definition: ktrader.cpp:106
KTrader::OfferList
TQValueList< KService::Ptr > OfferList
A list of services.
Definition: ktrader.h:92
KTrader::self
static KTrader * self()
This is a static pointer to a KTrader instance.
Definition: ktrader.cpp:90
KDCOPServiceStarter::startServiceFor
virtual int startServiceFor(const TQString &serviceType, const TQString &constraint=TQString::null, const TQString &preferences=TQString::null, TQString *error=0, TQCString *dcopService=0, int flags=0)
Find an implementation of the given serviceType, and start it, to use its DCOP interface.
Definition: kdcopservicestarter.cpp:86
KDCOPServiceStarter::findServiceFor
int findServiceFor(const TQString &serviceType, const TQString &constraint=TQString::null, const TQString &preferences=TQString::null, TQString *error=0, TQCString *dcopService=0, int flags=0)
Check if a given DCOP interface is available - from the serviceType it&#39;s supposed to implement...
Definition: kdcopservicestarter.cpp:49

kio/kio

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

kio/kio

Skip menu "kio/kio"
  • arts
  • dcop
  • dnssd
  • interfaces
  •     interface
  •     library
  •   kspeech
  •   ktexteditor
  • kabc
  • kate
  • kcmshell
  • kdecore
  • kded
  • kdefx
  • kdeprint
  • kdesu
  • kdeui
  • kdoctools
  • khtml
  • kimgio
  • kinit
  • kio
  •   bookmarks
  •   httpfilter
  •   kfile
  •   kio
  •   kioexec
  •   kpasswdserver
  •   kssl
  • kioslave
  •   http
  • kjs
  • kmdi
  •   kmdi
  • knewstuff
  • kparts
  • krandr
  • kresources
  • kspell2
  • kunittest
  • kutils
  • kwallet
  • libkmid
  • libkscreensaver
Generated for kio/kio by doxygen 1.8.13
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |