• Skip to content
  • Skip to link menu
KDE 4.2 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 
00057 class KDECORE_EXPORT KService : public KSycocaEntry
00058 {
00059 public:
00060     typedef KSharedPtr<KService> Ptr;
00061     typedef QList<Ptr> List;
00062 
00069     KService(const QString & name, const QString &exec, const QString &icon);
00070 
00076     explicit KService( const QString & fullpath );
00077 
00082     explicit KService( const KDesktopFile *config );
00083 
00089     KService( QDataStream& str, int offset );
00090 
00091     virtual ~KService();
00092 
00098     bool isApplication() const;
00099 
00105     KDE_DEPRECATED QString type() const;
00106 
00112     QString exec() const;
00118     QString library() const;
00119 
00125     QString icon() const;
00130     bool terminal() const;
00131 
00140     QString terminalOptions() const;
00146     bool substituteUid() const;
00154     QString username() const;
00155 
00170     KDE_DEPRECATED QString desktopEntryPath() const;
00171 
00178     QString desktopEntryName() const;
00179 
00185     QString menuId() const;
00186 
00193     QString storageId() const;
00194 
00207     enum DBusStartupType { DBusNone = 0, DBusUnique, DBusMulti, DBusWait };
00208 
00213     DBusStartupType dbusStartupType() const;
00214 
00220     QString path() const;
00221 
00227     QString comment() const;
00228 
00235     QString genericName() const;
00236 
00244     QString untranslatedGenericName() const;
00245 
00250     QStringList keywords() const;
00251 
00256     QStringList categories() const;
00257 
00264     QStringList serviceTypes() const;
00265 
00273     bool hasServiceType( const QString& serviceTypePtr ) const;
00274 
00292     bool hasMimeType( const KServiceType* mimeTypePtr ) const;
00293 
00304     bool allowAsDefault() const;
00305 
00309     QList<KServiceAction> actions() const;
00310 
00317     bool allowMultipleFiles() const;
00318 
00325     int initialPreference() const;
00326 
00331     bool noDisplay() const;
00332 
00338     QString parentApp() const;
00339 
00345     QString pluginKeyword() const;
00346 
00352     QString docPath() const;
00353 
00362     QVariant property( const QString& _name, QVariant::Type t ) const;
00363 
00364     using KSycocaEntry::property;
00365 
00371     QString locateLocal() const;
00372 
00377     void setMenuId(const QString &menuId);
00382     void setTerminal(bool b);
00387     void setTerminalOptions(const QString &options);
00388 
00399     static Ptr serviceByName( const QString& _name );
00400 
00410     static Ptr serviceByDesktopPath( const QString& _path );
00411 
00426     static Ptr serviceByDesktopName( const QString& _name );
00427 
00436     static Ptr serviceByMenuId( const QString& _menuId );
00437 
00447     static Ptr serviceByStorageId( const QString& _storageId );
00448 
00458     static List allServices();
00459 
00475     static QString newServicePath(bool showInMenu, const QString &suggestedName,
00476                                   QString *menuId = 0,
00477                                   const QStringList *reservedMenuIds = 0);
00478 
00491     template <class T>
00492     T *createInstance(QObject *parent = 0,
00493             const QVariantList &args = QVariantList(), QString *error = 0) const
00494     {
00495         return createInstance<T>(0, parent, args, error);
00496     }
00497 
00511     template <class T>
00512     T *createInstance(QWidget *parentWidget, QObject *parent,
00513             const QVariantList &args = QVariantList(), QString *error = 0) const
00514     {
00515         KPluginLoader pluginLoader(*this);
00516         KPluginFactory *factory = pluginLoader.factory();
00517         if (factory) {
00518             T *o = factory->template create<T>(parentWidget, parent, pluginKeyword(), args);
00519             if (!o && error)
00520                 *error = i18n("The service '%1' does not provide an interface '%2' with keyword '%3'",
00521                               name(), QString::fromLatin1(T::staticMetaObject.className()), pluginKeyword());
00522             return o;
00523         }
00524         else if (error) {
00525             *error = pluginLoader.errorString();
00526             pluginLoader.unload();
00527         }
00528         return 0;
00529     }
00530 
00531     template <class T>
00532     static KDE_DEPRECATED T *createInstance(const KService::Ptr &service, QObject *parent = 0,
00533             const QVariantList &args = QVariantList(), QString *error = 0)
00534     {
00535         return service->createInstance<T>(parent, args, error);
00536     }
00537 
00538     template <class T>
00539     static KDE_DEPRECATED T *createInstance( const KService::Ptr &service,
00540                               QObject *parent,
00541                               const QStringList &args,
00542                               int *error = 0 )
00543     {
00544         const QString library = service->library();
00545         if ( library.isEmpty() ) {
00546             if ( error )
00547                 *error = KLibLoader::ErrServiceProvidesNoLibrary;
00548             return 0;
00549         }
00550 
00551         return KLibLoader::createInstance<T>( library, parent, args, error );
00552     }
00553 
00569     template <class T, class ServiceIterator>
00570     static KDE_DEPRECATED T *createInstance(ServiceIterator begin, ServiceIterator end, QObject *parent = 0,
00571             const QVariantList &args = QVariantList(), QString *error = 0)
00572     {
00573         for (; begin != end; ++begin) {
00574             KService::Ptr service = *begin;
00575             if (error) {
00576                 error->clear();
00577             }
00578 
00579             T *component = createInstance<T>(service, parent, args, error);
00580             if (component) {
00581                 return component;
00582             }
00583         }
00584         if (error) {
00585             *error = KLibLoader::errorString(KLibLoader::ErrNoServiceFound);
00586         }
00587         return 0;
00588     }
00589 
00590     template <class T, class ServiceIterator>
00591     static KDE_DEPRECATED T *createInstance( ServiceIterator begin, ServiceIterator end,
00592                               QObject *parent,
00593                               const QStringList &args,
00594                               int *error = 0 )
00595     {
00596         for (; begin != end; ++begin ) {
00597             KService::Ptr service = *begin;
00598             if ( error )
00599                 *error = 0;
00600 
00601             T *component = createInstance<T>( service, parent, args, error );
00602             if ( component )
00603                 return component;
00604         }
00605         if ( error )
00606             *error = KLibLoader::ErrNoServiceFound;
00607         return 0;
00608     }
00609 
00610 protected:
00611     friend class KMimeAssociations;
00612     friend class KBuildServiceFactory;
00613 
00615     struct ServiceTypeAndPreference
00616     {
00617         ServiceTypeAndPreference()
00618             : preference(-1), serviceType() {}
00619         ServiceTypeAndPreference(int pref, const QString& servType)
00620             : preference(pref), serviceType(servType) {}
00621         int preference;
00622         QString serviceType; // or mimetype
00623     };
00625     QVector<ServiceTypeAndPreference>& _k_accessServiceTypes();
00626 
00627     friend QDataStream& operator>>( QDataStream&, ServiceTypeAndPreference& );
00628     friend QDataStream& operator<<( QDataStream&, const ServiceTypeAndPreference& );
00629 private:
00630     Q_DECLARE_PRIVATE(KService)
00631 };
00632 #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
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.7
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