• Skip to content
  • Skip to link menu
KDE 4.8 API Reference
  • KDE API Reference
  • kdelibs
  • KDE Home
  • 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 #ifndef KDE_NO_DEPRECATED
00028 #include <klibloader.h>
00029 #endif
00030 #include <kpluginfactory.h>
00031 #include <kpluginloader.h>
00032 #include <ksycocaentry.h>
00033 #include <klocale.h>
00034 
00035 class KServiceType;
00036 class QDataStream;
00037 class KDesktopFile;
00038 class QWidget;
00039 
00040 class KServicePrivate;
00041 
00058 class KDECORE_EXPORT KService : public KSycocaEntry // TODO KDE5: inherit kshared, but move KSycocaEntry to Private
00059 {
00060 public:
00061     typedef KSharedPtr<KService> Ptr;
00062     typedef QList<Ptr> List;
00063 
00070     KService(const QString & name, const QString &exec, const QString &icon);
00071 
00077     explicit KService( const QString & fullpath );
00078 
00083     explicit KService( const KDesktopFile *config );
00084 
00090     KService( QDataStream& str, int offset );
00091 
00092     virtual ~KService();
00093 
00094     // TODO KDE5: add mimeTypes() accessor
00095 
00101     bool isApplication() const;
00102 
00108 #ifndef KDE_NO_DEPRECATED
00109     KDE_DEPRECATED QString type() const;
00110 #endif
00111 
00117     QString exec() const;
00123     QString library() const;
00124 
00130     QString icon() const;
00135     bool terminal() const;
00136 
00145     QString terminalOptions() const;
00151     bool substituteUid() const;
00159     QString username() const;
00160 
00175 #ifndef KDE_NO_DEPRECATED
00176     KDE_DEPRECATED QString desktopEntryPath() const;
00177 #endif
00178 
00185     QString desktopEntryName() const;
00186 
00192     QString menuId() const;
00193 
00200     QString storageId() const;
00201 
00214     enum DBusStartupType { DBusNone = 0, DBusUnique, DBusMulti, DBusWait };
00215 
00220     DBusStartupType dbusStartupType() const;
00221 
00227     QString path() const;
00228 
00234     QString comment() const;
00235 
00242     QString genericName() const;
00243 
00251     QString untranslatedGenericName() const;
00252 
00257     QStringList keywords() const;
00258 
00263     QStringList categories() const;
00264 
00271     QStringList serviceTypes() const;
00272 
00280     bool hasServiceType( const QString& serviceTypePtr ) const;
00281 
00300 #ifndef KDE_NO_DEPRECATED
00301     KDE_DEPRECATED bool hasMimeType( const KServiceType* mimeTypePtr ) const;
00302 #endif
00303 
00310     bool hasMimeType( const QString& mimeType ) const;
00311 
00322     bool allowAsDefault() const;
00323 
00327     QList<KServiceAction> actions() const;
00328 
00335     bool allowMultipleFiles() const;
00336 
00343     int initialPreference() const;
00344 
00352     bool noDisplay() const;
00353 
00364     bool showInKDE() const;
00365 
00371     QString parentApp() const;
00372 
00378     QString pluginKeyword() const;
00379 
00385     QString docPath() const;
00386 
00395     QVariant property( const QString& _name, QVariant::Type t ) const;
00396 
00397     using KSycocaEntry::property;
00398 
00404     QString locateLocal() const;
00405 
00410     void setMenuId(const QString &menuId);
00415     void setTerminal(bool b);
00420     void setTerminalOptions(const QString &options);
00421 
00432 #ifndef KDE_NO_DEPRECATED
00433     static Ptr serviceByName( const QString& _name ); // KDE5: remove
00434 #endif
00435 
00445     static Ptr serviceByDesktopPath( const QString& _path );
00446 
00461     static Ptr serviceByDesktopName( const QString& _name );
00462 
00471     static Ptr serviceByMenuId( const QString& _menuId );
00472 
00482     static Ptr serviceByStorageId( const QString& _storageId );
00483 
00493     static List allServices();
00494 
00510     static QString newServicePath(bool showInMenu, const QString &suggestedName,
00511                                   QString *menuId = 0,
00512                                   const QStringList *reservedMenuIds = 0);
00513 
00526     template <class T>
00527     T *createInstance(QObject *parent = 0,
00528             const QVariantList &args = QVariantList(), QString *error = 0) const
00529     {
00530         return createInstance<T>(0, parent, args, error);
00531     }
00532 
00546     template <class T>
00547     T *createInstance(QWidget *parentWidget, QObject *parent,
00548             const QVariantList &args = QVariantList(), QString *error = 0) const
00549     {
00550         KPluginLoader pluginLoader(*this);
00551         KPluginFactory *factory = pluginLoader.factory();
00552         if (factory) {
00553             T *o = factory->template create<T>(parentWidget, parent, pluginKeyword(), args);
00554             if (!o && error)
00555                 *error = i18n("The service '%1' does not provide an interface '%2' with keyword '%3'",
00556                               name(), QString::fromLatin1(T::staticMetaObject.className()), pluginKeyword());
00557             return o;
00558         }
00559         else if (error) {
00560             *error = pluginLoader.errorString();
00561             pluginLoader.unload();
00562         }
00563         return 0;
00564     }
00565 
00569 #ifndef KDE_NO_DEPRECATED
00570     template <class T>
00571     static KDE_DEPRECATED T *createInstance(const KService::Ptr &service, QObject *parent = 0,
00572             const QVariantList &args = QVariantList(), QString *error = 0)
00573     {
00574         return service->createInstance<T>(parent, args, error);
00575     }
00576 #endif
00577 
00582 #ifndef KDE_NO_DEPRECATED
00583     template <class T>
00584     static KDE_DEPRECATED T *createInstance( const KService::Ptr &service,
00585                               QObject *parent,
00586                               const QStringList &args,
00587                               int *error = 0 )
00588     {
00589         const QString library = service->library();
00590         if ( library.isEmpty() ) {
00591             if ( error )
00592                 *error = KLibLoader::ErrServiceProvidesNoLibrary;
00593             return 0;
00594         }
00595 
00596         return KLibLoader::createInstance<T>( library, parent, args, error );
00597     }
00598 #endif
00599 
00615 #ifndef KDE_NO_DEPRECATED
00616     template <class T, class ServiceIterator>
00617     static KDE_DEPRECATED T *createInstance(ServiceIterator begin, ServiceIterator end, QObject *parent = 0,
00618             const QVariantList &args = QVariantList(), QString *error = 0)
00619     {
00620         for (; begin != end; ++begin) {
00621             KService::Ptr service = *begin;
00622             if (error) {
00623                 error->clear();
00624             }
00625 
00626             T *component = createInstance<T>(service, parent, args, error);
00627             if (component) {
00628                 return component;
00629             }
00630         }
00631         if (error) {
00632             *error = KLibLoader::errorString(KLibLoader::ErrNoServiceFound);
00633         }
00634         return 0;
00635     }
00636 #endif
00637 
00638 #ifndef KDE_NO_DEPRECATED
00639     template <class T, class ServiceIterator>
00640     static KDE_DEPRECATED T *createInstance( ServiceIterator begin, ServiceIterator end,
00641                               QObject *parent,
00642                               const QStringList &args,
00643                               int *error = 0 )
00644     {
00645         for (; begin != end; ++begin ) {
00646             KService::Ptr service = *begin;
00647             if ( error )
00648                 *error = 0;
00649 
00650             T *component = createInstance<T>( service, parent, args, error );
00651             if ( component )
00652                 return component;
00653         }
00654         if ( error )
00655             *error = KLibLoader::ErrNoServiceFound;
00656         return 0;
00657     }
00658 #endif
00659 
00660 protected:
00661     friend class KMimeAssociations;
00662     friend class KBuildServiceFactory;
00663 
00665     struct ServiceTypeAndPreference
00666     {
00667         ServiceTypeAndPreference()
00668             : preference(-1), serviceType() {}
00669         ServiceTypeAndPreference(int pref, const QString& servType)
00670             : preference(pref), serviceType(servType) {}
00671         int preference;
00672         QString serviceType; // or mimetype
00673     };
00675     QVector<ServiceTypeAndPreference>& _k_accessServiceTypes();
00676 
00677     friend QDataStream& operator>>( QDataStream&, ServiceTypeAndPreference& );
00678     friend QDataStream& operator<<( QDataStream&, const ServiceTypeAndPreference& );
00679 private:
00680     Q_DECLARE_PRIVATE(KService)
00681 };
00682 #endif

KDECore

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

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • 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
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.7.6.1
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