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

tdeio/tdeio

kdcopservicestarter.cpp

00001 /* This file is part of the KDE libraries
00002    Copyright (C) 2003 David Faure <faure@kde.org>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License version 2 as published by the Free Software Foundation.
00007 
00008    This library is distributed in the hope that it will be useful,
00009    but WITHOUT ANY WARRANTY; without even the implied warranty of
00010    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011    Library General Public License for more details.
00012 
00013    You should have received a copy of the GNU Library General Public License
00014    along with this library; see the file COPYING.LIB.  If not, write to
00015    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00016    Boston, MA 02110-1301, USA.
00017 */
00018 
00019 #include "kdcopservicestarter.h"
00020 #include "ktrader.h"
00021 #include <tdeapplication.h>
00022 #include "kservice.h"
00023 #include <kstaticdeleter.h>
00024 #include <kdebug.h>
00025 #include <tdelocale.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     // Set the singleton instance - useful when a derived KDCOPServiceStarter
00041     // was created (before self() was called)
00042     s_self = this;
00043 }
00044 
00045 KDCOPServiceStarter::~KDCOPServiceStarter()
00046 {
00047 }
00048 
00049 int KDCOPServiceStarter::findServiceFor( const TQString& serviceType,
00050                                          const TQString& _constraint,
00051                                          const TQString& preferences,
00052                                          TQString *error, TQCString* pDcopService,
00053                                          int flags )
00054 {
00055     // Ask the trader which service is preferred for this servicetype
00056     // We want one that provides a DCOP interface
00057     TQString constraint = _constraint;
00058     if ( !constraint.isEmpty() )
00059         constraint += " and ";
00060     constraint += "exist [X-DCOP-ServiceName]";
00061     TDETrader::OfferList offers = TDETrader::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     TQCString dcopService = ptr->property("X-DCOP-ServiceName").toString().latin1();
00070 
00071     if ( !kapp->dcopClient()->isApplicationRegistered( dcopService ) )
00072     {
00073         TQString 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 TQString& serviceType,
00087                                           const TQString& constraint,
00088                                           const TQString& preferences,
00089                                           TQString *error, TQCString* dcopService, int /*flags*/ )
00090 {
00091     TDETrader::OfferList offers = TDETrader::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(), TQStringList(), error, dcopService );
00097 }

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.6.3
This website is maintained by Timothy Pearson.