• Skip to content
  • Skip to link menu
KDE 4.3 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 
00530     template <class T>
00531     static KDE_DEPRECATED T *createInstance(const KService::Ptr &service, QObject *parent = 0,
00532             const QVariantList &args = QVariantList(), QString *error = 0)
00533     {
00534         return service->createInstance<T>(parent, args, error);
00535     }
00536 
00537     template <class T>
00538     static KDE_DEPRECATED T *createInstance( const KService::Ptr &service,
00539                               QObject *parent,
00540                               const QStringList &args,
00541                               int *error = 0 )
00542     {
00543         const QString library = service->library();
00544         if ( library.isEmpty() ) {
00545             if ( error )
00546                 *error = KLibLoader::ErrServiceProvidesNoLibrary;
00547             return 0;
00548         }
00549 
00550         return KLibLoader::createInstance<T>( library, parent, args, error );
00551     }
00552 
00568     template <class T, class ServiceIterator>
00569     static KDE_DEPRECATED T *createInstance(ServiceIterator begin, ServiceIterator end, QObject *parent = 0,
00570             const QVariantList &args = QVariantList(), QString *error = 0)
00571     {
00572         for (; begin != end; ++begin) {
00573             KService::Ptr service = *begin;
00574             if (error) {
00575                 error->clear();
00576             }
00577 
00578             T *component = createInstance<T>(service, parent, args, error);
00579             if (component) {
00580                 return component;
00581             }
00582         }
00583         if (error) {
00584             *error = KLibLoader::errorString(KLibLoader::ErrNoServiceFound);
00585         }
00586         return 0;
00587     }
00588 
00589     template <class T, class ServiceIterator>
00590     static KDE_DEPRECATED T *createInstance( ServiceIterator begin, ServiceIterator end,
00591                               QObject *parent,
00592                               const QStringList &args,
00593                               int *error = 0 )
00594     {
00595         for (; begin != end; ++begin ) {
00596             KService::Ptr service = *begin;
00597             if ( error )
00598                 *error = 0;
00599 
00600             T *component = createInstance<T>( service, parent, args, error );
00601             if ( component )
00602                 return component;
00603         }
00604         if ( error )
00605             *error = KLibLoader::ErrNoServiceFound;
00606         return 0;
00607     }
00608 
00609 protected:
00610     friend class KMimeAssociations;
00611     friend class KBuildServiceFactory;
00612 
00614     struct ServiceTypeAndPreference
00615     {
00616         ServiceTypeAndPreference()
00617             : preference(-1), serviceType() {}
00618         ServiceTypeAndPreference(int pref, const QString& servType)
00619             : preference(pref), serviceType(servType) {}
00620         int preference;
00621         QString serviceType; // or mimetype
00622     };
00624     QVector<ServiceTypeAndPreference>& _k_accessServiceTypes();
00625 
00626     friend QDataStream& operator>>( QDataStream&, ServiceTypeAndPreference& );
00627     friend QDataStream& operator<<( QDataStream&, const ServiceTypeAndPreference& );
00628 private:
00629     Q_DECLARE_PRIVATE(KService)
00630 };
00631 #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
  • KPty
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.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