• Skip to content
  • Skip to link menu
KDE 4.0 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 
00467     static QString newServicePath(bool showInMenu, const QString &suggestedName,
00468                                   QString *menuId = 0,
00469                                   const QStringList *reservedMenuIds = 0);
00470 
00483     template <class T>
00484     T *createInstance(QObject *parent = 0,
00485             const QVariantList &args = QVariantList(), QString *error = 0) const
00486     {
00487         return createInstance<T>(0, parent, args, error);
00488     }
00489 
00503     template <class T>
00504     T *createInstance(QWidget *parentWidget, QObject *parent,
00505             const QVariantList &args = QVariantList(), QString *error = 0) const
00506     {
00507         KPluginLoader pluginLoader(*this);
00508         KPluginFactory *factory = pluginLoader.factory();
00509         if (factory) {
00510             T *o = factory->template create<T>(parentWidget, parent, pluginKeyword(), args);
00511             if (!o && error)
00512                 *error = i18n("The service '%1' does not provide an interface '%2' with keyword '%3'",
00513                               name(), QString::fromLatin1(T::staticMetaObject.className()), pluginKeyword());
00514             return o;
00515         }
00516         else if (error) {
00517             *error = pluginLoader.errorString();
00518             pluginLoader.unload();
00519         }
00520         return 0;
00521     }
00522 
00523     template <class T>
00524     static KDE_DEPRECATED T *createInstance(const KService::Ptr &service, QObject *parent = 0,
00525             const QVariantList &args = QVariantList(), QString *error = 0)
00526     {
00527         return service->createInstance<T>(parent, args, error);
00528     }
00529 
00530     template <class T>
00531     static KDE_DEPRECATED T *createInstance( const KService::Ptr &service,
00532                               QObject *parent,
00533                               const QStringList &args,
00534                               int *error = 0 )
00535     {
00536         const QString library = service->library();
00537         if ( library.isEmpty() ) {
00538             if ( error )
00539                 *error = KLibLoader::ErrServiceProvidesNoLibrary;
00540             return 0;
00541         }
00542 
00543         return KLibLoader::createInstance<T>( library, parent, args, error );
00544     }
00545 
00561     template <class T, class ServiceIterator>
00562     static KDE_DEPRECATED T *createInstance(ServiceIterator begin, ServiceIterator end, QObject *parent = 0,
00563             const QVariantList &args = QVariantList(), QString *error = 0)
00564     {
00565         for (; begin != end; ++begin) {
00566             KService::Ptr service = *begin;
00567             if (error) {
00568                 *error = QString();
00569             }
00570 
00571             T *component = createInstance<T>(service, parent, args, error);
00572             if (component) {
00573                 return component;
00574             }
00575         }
00576         if (error) {
00577             *error = KLibLoader::errorString(KLibLoader::ErrNoServiceFound);
00578         }
00579         return 0;
00580     }
00581 
00582     template <class T, class ServiceIterator>
00583     static KDE_DEPRECATED T *createInstance( ServiceIterator begin, ServiceIterator end,
00584                               QObject *parent,
00585                               const QStringList &args,
00586                               int *error = 0 )
00587     {
00588         for (; begin != end; ++begin ) {
00589             KService::Ptr service = *begin;
00590             if ( error )
00591                 *error = 0;
00592 
00593             T *component = createInstance<T>( service, parent, args, error );
00594             if ( component )
00595                 return component;
00596         }
00597         if ( error )
00598             *error = KLibLoader::ErrNoServiceFound;
00599         return 0;
00600     }
00601 
00602 protected:
00603     friend class KMimeAssociations;
00604     friend class KBuildServiceFactory;
00605 
00607     struct ServiceTypeAndPreference
00608     {
00609         ServiceTypeAndPreference()
00610             : preference(-1), serviceType() {}
00611         ServiceTypeAndPreference(int pref, const QString& servType)
00612             : preference(pref), serviceType(servType) {}
00613         int preference;
00614         QString serviceType; // or mimetype
00615     };
00617     QVector<ServiceTypeAndPreference>& _k_accessServiceTypes();
00618 
00619     friend QDataStream& operator>>( QDataStream&, ServiceTypeAndPreference& );
00620     friend QDataStream& operator<<( QDataStream&, const ServiceTypeAndPreference& );
00621 private:
00622     Q_DECLARE_PRIVATE(KService)
00623 };
00624 #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
  •   WTF
  • KJSEmbed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  •   core
  • Phonon
  •   Backend
  • 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