• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.8.3 API Reference
  • 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 
00099     bool isApplication() const;
00100 
00106 #ifndef KDE_NO_DEPRECATED
00107     KDE_DEPRECATED QString type() const;
00108 #endif
00109 
00115     QString exec() const;
00121     QString library() const;
00122 
00128     QString icon() const;
00133     bool terminal() const;
00134 
00143     QString terminalOptions() const;
00149     bool substituteUid() const;
00157     QString username() const;
00158 
00173 #ifndef KDE_NO_DEPRECATED
00174     KDE_DEPRECATED QString desktopEntryPath() const;
00175 #endif
00176 
00183     QString desktopEntryName() const;
00184 
00190     QString menuId() const;
00191 
00198     QString storageId() const;
00199 
00212     enum DBusStartupType { DBusNone = 0, DBusUnique, DBusMulti, DBusWait };
00213 
00218     DBusStartupType dbusStartupType() const;
00219 
00225     QString path() const;
00226 
00232     QString comment() const;
00233 
00240     QString genericName() const;
00241 
00249     QString untranslatedGenericName() const;
00250 
00255     QStringList keywords() const;
00256 
00261     QStringList categories() const;
00262 
00269     QStringList mimeTypes() const;
00270 
00277     QStringList serviceTypes() const;
00278 
00286     bool hasServiceType( const QString& serviceTypePtr ) const;
00287 
00306 #ifndef KDE_NO_DEPRECATED
00307     KDE_DEPRECATED bool hasMimeType( const KServiceType* mimeTypePtr ) const;
00308 #endif
00309 
00316     bool hasMimeType( const QString& mimeType ) const;
00317 
00328     bool allowAsDefault() const;
00329 
00333     QList<KServiceAction> actions() const;
00334 
00341     bool allowMultipleFiles() const;
00342 
00349     int initialPreference() const;
00350 
00358     bool noDisplay() const;
00359 
00370     bool showInKDE() const;
00371 
00377     QString parentApp() const;
00378 
00384     QString pluginKeyword() const;
00385 
00391     QString docPath() const;
00392 
00401     QVariant property( const QString& _name, QVariant::Type t ) const;
00402 
00403     using KSycocaEntry::property;
00404 
00410     QString locateLocal() const;
00411 
00416     void setMenuId(const QString &menuId);
00421     void setTerminal(bool b);
00426     void setTerminalOptions(const QString &options);
00427 
00438 #ifndef KDE_NO_DEPRECATED
00439     static Ptr serviceByName( const QString& _name ); // KDE5: remove
00440 #endif
00441 
00451     static Ptr serviceByDesktopPath( const QString& _path );
00452 
00467     static Ptr serviceByDesktopName( const QString& _name );
00468 
00477     static Ptr serviceByMenuId( const QString& _menuId );
00478 
00488     static Ptr serviceByStorageId( const QString& _storageId );
00489 
00499     static List allServices();
00500 
00516     static QString newServicePath(bool showInMenu, const QString &suggestedName,
00517                                   QString *menuId = 0,
00518                                   const QStringList *reservedMenuIds = 0);
00519 
00532     template <class T>
00533     T *createInstance(QObject *parent = 0,
00534             const QVariantList &args = QVariantList(), QString *error = 0) const
00535     {
00536         return createInstance<T>(0, parent, args, error);
00537     }
00538 
00552     template <class T>
00553     T *createInstance(QWidget *parentWidget, QObject *parent,
00554             const QVariantList &args = QVariantList(), QString *error = 0) const
00555     {
00556         KPluginLoader pluginLoader(*this);
00557         KPluginFactory *factory = pluginLoader.factory();
00558         if (factory) {
00559             T *o = factory->template create<T>(parentWidget, parent, pluginKeyword(), args);
00560             if (!o && error)
00561                 *error = i18n("The service '%1' does not provide an interface '%2' with keyword '%3'",
00562                               name(), QString::fromLatin1(T::staticMetaObject.className()), pluginKeyword());
00563             return o;
00564         }
00565         else if (error) {
00566             *error = pluginLoader.errorString();
00567             pluginLoader.unload();
00568         }
00569         return 0;
00570     }
00571 
00575 #ifndef KDE_NO_DEPRECATED
00576     template <class T>
00577     static KDE_DEPRECATED T *createInstance(const KService::Ptr &service, QObject *parent = 0,
00578             const QVariantList &args = QVariantList(), QString *error = 0)
00579     {
00580         return service->createInstance<T>(parent, args, error);
00581     }
00582 #endif
00583 
00588 #ifndef KDE_NO_DEPRECATED
00589     template <class T>
00590     static KDE_DEPRECATED T *createInstance( const KService::Ptr &service,
00591                               QObject *parent,
00592                               const QStringList &args,
00593                               int *error = 0 )
00594     {
00595         const QString library = service->library();
00596         if ( library.isEmpty() ) {
00597             if ( error )
00598                 *error = KLibLoader::ErrServiceProvidesNoLibrary;
00599             return 0;
00600         }
00601 
00602         return KLibLoader::createInstance<T>( library, parent, args, error );
00603     }
00604 #endif
00605 
00621 #ifndef KDE_NO_DEPRECATED
00622     template <class T, class ServiceIterator>
00623     static KDE_DEPRECATED T *createInstance(ServiceIterator begin, ServiceIterator end, QObject *parent = 0,
00624             const QVariantList &args = QVariantList(), QString *error = 0)
00625     {
00626         for (; begin != end; ++begin) {
00627             KService::Ptr service = *begin;
00628             if (error) {
00629                 error->clear();
00630             }
00631 
00632             T *component = createInstance<T>(service, parent, args, error);
00633             if (component) {
00634                 return component;
00635             }
00636         }
00637         if (error) {
00638             *error = KLibLoader::errorString(KLibLoader::ErrNoServiceFound);
00639         }
00640         return 0;
00641     }
00642 #endif
00643 
00644 #ifndef KDE_NO_DEPRECATED
00645     template <class T, class ServiceIterator>
00646     static KDE_DEPRECATED T *createInstance( ServiceIterator begin, ServiceIterator end,
00647                               QObject *parent,
00648                               const QStringList &args,
00649                               int *error = 0 )
00650     {
00651         for (; begin != end; ++begin ) {
00652             KService::Ptr service = *begin;
00653             if ( error )
00654                 *error = 0;
00655 
00656             T *component = createInstance<T>( service, parent, args, error );
00657             if ( component )
00658                 return component;
00659         }
00660         if ( error )
00661             *error = KLibLoader::ErrNoServiceFound;
00662         return 0;
00663     }
00664 #endif
00665 
00666 protected:
00667     friend class KMimeAssociations;
00668     friend class KBuildServiceFactory;
00669 
00671     struct ServiceTypeAndPreference
00672     {
00673         ServiceTypeAndPreference()
00674             : preference(-1), serviceType() {}
00675         ServiceTypeAndPreference(int pref, const QString& servType)
00676             : preference(pref), serviceType(servType) {}
00677         int preference;
00678         QString serviceType; // or mimetype
00679     };
00681     QVector<ServiceTypeAndPreference>& _k_accessServiceTypes();
00682 
00683     friend QDataStream& operator>>( QDataStream&, ServiceTypeAndPreference& );
00684     friend QDataStream& operator<<( QDataStream&, const ServiceTypeAndPreference& );
00685 private:
00686     Q_DECLARE_PRIVATE(KService)
00687 };
00688 #endif
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Thu May 10 2012 20:49:32 by doxygen 1.8.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

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-4.8.3 API Reference

Skip menu "kdelibs-4.8.3 API Reference"
  • 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
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal