• Skip to content
  • Skip to link menu
KDE 4.1 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 
00355     QVariant property( const QString& _name, QVariant::Type t ) const;
00356 
00357     using KSycocaEntry::property;
00358 
00364     QString locateLocal() const;
00365 
00370     void setMenuId(const QString &menuId);
00375     void setTerminal(bool b);
00380     void setTerminalOptions(const QString &options);
00381 
00392     static Ptr serviceByName( const QString& _name );
00393 
00403     static Ptr serviceByDesktopPath( const QString& _path );
00404 
00419     static Ptr serviceByDesktopName( const QString& _name );
00420 
00429     static Ptr serviceByMenuId( const QString& _menuId );
00430 
00440     static Ptr serviceByStorageId( const QString& _storageId );
00441 
00451     static List allServices();
00452 
00468     static QString newServicePath(bool showInMenu, const QString &suggestedName,
00469                                   QString *menuId = 0,
00470                                   const QStringList *reservedMenuIds = 0);
00471 
00484     template <class T>
00485     T *createInstance(QObject *parent = 0,
00486             const QVariantList &args = QVariantList(), QString *error = 0) const
00487     {
00488         return createInstance<T>(0, parent, args, error);
00489     }
00490 
00504     template <class T>
00505     T *createInstance(QWidget *parentWidget, QObject *parent,
00506             const QVariantList &args = QVariantList(), QString *error = 0) const
00507     {
00508         KPluginLoader pluginLoader(*this);
00509         KPluginFactory *factory = pluginLoader.factory();
00510         if (factory) {
00511             T *o = factory->template create<T>(parentWidget, parent, pluginKeyword(), args);
00512             if (!o && error)
00513                 *error = i18n("The service '%1' does not provide an interface '%2' with keyword '%3'",
00514                               name(), QString::fromLatin1(T::staticMetaObject.className()), pluginKeyword());
00515             return o;
00516         }
00517         else if (error) {
00518             *error = pluginLoader.errorString();
00519             pluginLoader.unload();
00520         }
00521         return 0;
00522     }
00523 
00524     template <class T>
00525     static KDE_DEPRECATED T *createInstance(const KService::Ptr &service, QObject *parent = 0,
00526             const QVariantList &args = QVariantList(), QString *error = 0)
00527     {
00528         return service->createInstance<T>(parent, args, error);
00529     }
00530 
00531     template <class T>
00532     static KDE_DEPRECATED T *createInstance( const KService::Ptr &service,
00533                               QObject *parent,
00534                               const QStringList &args,
00535                               int *error = 0 )
00536     {
00537         const QString library = service->library();
00538         if ( library.isEmpty() ) {
00539             if ( error )
00540                 *error = KLibLoader::ErrServiceProvidesNoLibrary;
00541             return 0;
00542         }
00543 
00544         return KLibLoader::createInstance<T>( library, parent, args, error );
00545     }
00546 
00562     template <class T, class ServiceIterator>
00563     static KDE_DEPRECATED T *createInstance(ServiceIterator begin, ServiceIterator end, QObject *parent = 0,
00564             const QVariantList &args = QVariantList(), QString *error = 0)
00565     {
00566         for (; begin != end; ++begin) {
00567             KService::Ptr service = *begin;
00568             if (error) {
00569                 *error = QString();
00570             }
00571 
00572             T *component = createInstance<T>(service, parent, args, error);
00573             if (component) {
00574                 return component;
00575             }
00576         }
00577         if (error) {
00578             *error = KLibLoader::errorString(KLibLoader::ErrNoServiceFound);
00579         }
00580         return 0;
00581     }
00582 
00583     template <class T, class ServiceIterator>
00584     static KDE_DEPRECATED T *createInstance( ServiceIterator begin, ServiceIterator end,
00585                               QObject *parent,
00586                               const QStringList &args,
00587                               int *error = 0 )
00588     {
00589         for (; begin != end; ++begin ) {
00590             KService::Ptr service = *begin;
00591             if ( error )
00592                 *error = 0;
00593 
00594             T *component = createInstance<T>( service, parent, args, error );
00595             if ( component )
00596                 return component;
00597         }
00598         if ( error )
00599             *error = KLibLoader::ErrNoServiceFound;
00600         return 0;
00601     }
00602 
00603 protected:
00604     friend class KMimeAssociations;
00605     friend class KBuildServiceFactory;
00606 
00608     struct ServiceTypeAndPreference
00609     {
00610         ServiceTypeAndPreference()
00611             : preference(-1), serviceType() {}
00612         ServiceTypeAndPreference(int pref, const QString& servType)
00613             : preference(pref), serviceType(servType) {}
00614         int preference;
00615         QString serviceType; // or mimetype
00616     };
00618     QVector<ServiceTypeAndPreference>& _k_accessServiceTypes();
00619 
00620     friend QDataStream& operator>>( QDataStream&, ServiceTypeAndPreference& );
00621     friend QDataStream& operator<<( QDataStream&, const ServiceTypeAndPreference& );
00622 private:
00623     Q_DECLARE_PRIVATE(KService)
00624 };
00625 #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
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.4
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