• Skip to content
  • Skip to link menu
KDE 4.4 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

KDECore

kservice.h

Go to the documentation of this file.
00001 /* This file is part of the KDE project
00002    Copyright (C) 1998, 1999 Torben Weis <weis@kde.org>
00003    Copyright     1999-2006  David Faure <faure@kde.org>
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License as published by the Free Software Foundation; either
00008    version 2 of the License, or (at your option) any later version.
00009 
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public License
00016    along with this library; see the file COPYING.LIB.  If not, write to
00017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018    Boston, MA 02110-1301, USA.
00019 */
00020 
00021 #ifndef KSERVICE_H
00022 #define KSERVICE_H
00023 
00024 #include "kserviceaction.h"
00025 #include <QtCore/QStringList>
00026 #include <QtCore/QVariant>
00027 #include <klibloader.h>
00028 #include <kpluginfactory.h>
00029 #include <kpluginloader.h>
00030 #include <ksycocaentry.h>
00031 #include <klocale.h>
00032 
00033 class KServiceType;
00034 class QDataStream;
00035 class KDesktopFile;
00036 class QWidget;
00037 
00038 class KServicePrivate;
00039 
00056 class KDECORE_EXPORT KService : public KSycocaEntry
00057 {
00058 public:
00059     typedef KSharedPtr<KService> Ptr;
00060     typedef QList<Ptr> List;
00061 
00068     KService(const QString & name, const QString &exec, const QString &icon);
00069 
00075     explicit KService( const QString & fullpath );
00076 
00081     explicit KService( const KDesktopFile *config );
00082 
00088     KService( QDataStream& str, int offset );
00089 
00090     virtual ~KService();
00091 
00097     bool isApplication() const;
00098 
00104     KDE_DEPRECATED QString type() const;
00105 
00111     QString exec() const;
00117     QString library() const;
00118 
00124     QString icon() const;
00129     bool terminal() const;
00130 
00139     QString terminalOptions() const;
00145     bool substituteUid() const;
00153     QString username() const;
00154 
00169     KDE_DEPRECATED QString desktopEntryPath() const;
00170 
00177     QString desktopEntryName() const;
00178 
00184     QString menuId() const;
00185 
00192     QString storageId() const;
00193 
00206     enum DBusStartupType { DBusNone = 0, DBusUnique, DBusMulti, DBusWait };
00207 
00212     DBusStartupType dbusStartupType() const;
00213 
00219     QString path() const;
00220 
00226     QString comment() const;
00227 
00234     QString genericName() const;
00235 
00243     QString untranslatedGenericName() const;
00244 
00249     QStringList keywords() const;
00250 
00255     QStringList categories() const;
00256 
00263     QStringList serviceTypes() const;
00264 
00272     bool hasServiceType( const QString& serviceTypePtr ) const;
00273 
00291     bool hasMimeType( const KServiceType* mimeTypePtr ) const;
00292 
00303     bool allowAsDefault() const;
00304 
00308     QList<KServiceAction> actions() const;
00309 
00316     bool allowMultipleFiles() const;
00317 
00324     int initialPreference() const;
00325 
00330     bool noDisplay() const;
00331 
00337     QString parentApp() const;
00338 
00344     QString pluginKeyword() const;
00345 
00351     QString docPath() const;
00352 
00361     QVariant property( const QString& _name, QVariant::Type t ) const;
00362 
00363     using KSycocaEntry::property;
00364 
00370     QString locateLocal() const;
00371 
00376     void setMenuId(const QString &menuId);
00381     void setTerminal(bool b);
00386     void setTerminalOptions(const QString &options);
00387 
00398     static Ptr serviceByName( const QString& _name ); // KDE5: remove
00399 
00409     static Ptr serviceByDesktopPath( const QString& _path );
00410 
00425     static Ptr serviceByDesktopName( const QString& _name );
00426 
00435     static Ptr serviceByMenuId( const QString& _menuId );
00436 
00446     static Ptr serviceByStorageId( const QString& _storageId );
00447 
00457     static List allServices();
00458 
00474     static QString newServicePath(bool showInMenu, const QString &suggestedName,
00475                                   QString *menuId = 0,
00476                                   const QStringList *reservedMenuIds = 0);
00477 
00490     template <class T>
00491     T *createInstance(QObject *parent = 0,
00492             const QVariantList &args = QVariantList(), QString *error = 0) const
00493     {
00494         return createInstance<T>(0, parent, args, error);
00495     }
00496 
00510     template <class T>
00511     T *createInstance(QWidget *parentWidget, QObject *parent,
00512             const QVariantList &args = QVariantList(), QString *error = 0) const
00513     {
00514         KPluginLoader pluginLoader(*this);
00515         KPluginFactory *factory = pluginLoader.factory();
00516         if (factory) {
00517             T *o = factory->template create<T>(parentWidget, parent, pluginKeyword(), args);
00518             if (!o && error)
00519                 *error = i18n("The service '%1' does not provide an interface '%2' with keyword '%3'",
00520                               name(), QString::fromLatin1(T::staticMetaObject.className()), pluginKeyword());
00521             return o;
00522         }
00523         else if (error) {
00524             *error = pluginLoader.errorString();
00525             pluginLoader.unload();
00526         }
00527         return 0;
00528     }
00529 
00533     template <class T>
00534     static KDE_DEPRECATED T *createInstance(const KService::Ptr &service, QObject *parent = 0,
00535             const QVariantList &args = QVariantList(), QString *error = 0)
00536     {
00537         return service->createInstance<T>(parent, args, error);
00538     }
00539 
00544     template <class T>
00545     static KDE_DEPRECATED T *createInstance( const KService::Ptr &service,
00546                               QObject *parent,
00547                               const QStringList &args,
00548                               int *error = 0 )
00549     {
00550         const QString library = service->library();
00551         if ( library.isEmpty() ) {
00552             if ( error )
00553                 *error = KLibLoader::ErrServiceProvidesNoLibrary;
00554             return 0;
00555         }
00556 
00557         return KLibLoader::createInstance<T>( library, parent, args, error );
00558     }
00559 
00575     template <class T, class ServiceIterator>
00576     static KDE_DEPRECATED T *createInstance(ServiceIterator begin, ServiceIterator end, QObject *parent = 0,
00577             const QVariantList &args = QVariantList(), QString *error = 0)
00578     {
00579         for (; begin != end; ++begin) {
00580             KService::Ptr service = *begin;
00581             if (error) {
00582                 error->clear();
00583             }
00584 
00585             T *component = createInstance<T>(service, parent, args, error);
00586             if (component) {
00587                 return component;
00588             }
00589         }
00590         if (error) {
00591             *error = KLibLoader::errorString(KLibLoader::ErrNoServiceFound);
00592         }
00593         return 0;
00594     }
00595 
00596     template <class T, class ServiceIterator>
00597     static KDE_DEPRECATED T *createInstance( ServiceIterator begin, ServiceIterator end,
00598                               QObject *parent,
00599                               const QStringList &args,
00600                               int *error = 0 )
00601     {
00602         for (; begin != end; ++begin ) {
00603             KService::Ptr service = *begin;
00604             if ( error )
00605                 *error = 0;
00606 
00607             T *component = createInstance<T>( service, parent, args, error );
00608             if ( component )
00609                 return component;
00610         }
00611         if ( error )
00612             *error = KLibLoader::ErrNoServiceFound;
00613         return 0;
00614     }
00615 
00616 protected:
00617     friend class KMimeAssociations;
00618     friend class KBuildServiceFactory;
00619 
00621     struct ServiceTypeAndPreference
00622     {
00623         ServiceTypeAndPreference()
00624             : preference(-1), serviceType() {}
00625         ServiceTypeAndPreference(int pref, const QString& servType)
00626             : preference(pref), serviceType(servType) {}
00627         int preference;
00628         QString serviceType; // or mimetype
00629     };
00631     QVector<ServiceTypeAndPreference>& _k_accessServiceTypes();
00632 
00633     friend QDataStream& operator>>( QDataStream&, ServiceTypeAndPreference& );
00634     friend QDataStream& operator<<( QDataStream&, const ServiceTypeAndPreference& );
00635 private:
00636     Q_DECLARE_PRIVATE(KService)
00637 };
00638 #endif

KDECore

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

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  •     Sodep
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.9-20090814
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal