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

tdeio/tdeio

  • tdeio
  • tdeio
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 <tdeapplication.h>
22#include "kservice.h"
23#include <kstaticdeleter.h>
24#include <kdebug.h>
25#include <tdelocale.h>
26#include <dcopclient.h>
27
28static KStaticDeleter<KDCOPServiceStarter> dss_sd;
29KDCOPServiceStarter* KDCOPServiceStarter::s_self;
30
31KDCOPServiceStarter* KDCOPServiceStarter::self()
32{
33 if ( !s_self )
34 dss_sd.setObject( s_self, new KDCOPServiceStarter );
35 return s_self;
36}
37
38KDCOPServiceStarter::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
45KDCOPServiceStarter::~KDCOPServiceStarter()
46{
47}
48
49int 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 TDETrader::OfferList offers = TDETrader::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 ( !tdeApp->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
86int KDCOPServiceStarter::startServiceFor( const TQString& serviceType,
87 const TQString& constraint,
88 const TQString& preferences,
89 TQString *error, TQCString* dcopService, int /*flags*/ )
90{
91 TDETrader::OfferList offers = TDETrader::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 tdeApp->startServiceByDesktopPath( ptr->desktopEntryPath(), TQStringList(), error, dcopService );
97}
KDCOPServiceStarter
A generic DCOP service starter, using TDETrader.
Definition: kdcopservicestarter.h:34
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's supposed to implement.
Definition: kdcopservicestarter.cpp:49
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
TDETrader::query
virtual OfferList query(const TQString &servicetype, const TQString &constraint=TQString::null, const TQString &preferences=TQString::null) const
The main function in the TDETrader class.
Definition: ktrader.cpp:106
TDETrader::self
static TDETrader * self()
This is a static pointer to a TDETrader instance.
Definition: ktrader.cpp:90
TDETrader::OfferList
TQValueList< KService::Ptr > OfferList
A list of services.
Definition: ktrader.h:92

tdeio/tdeio

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

tdeio/tdeio

Skip menu "tdeio/tdeio"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeio/tdeio by doxygen 1.9.4
This website is maintained by Timothy Pearson.