• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.14.38 API Reference
  • KDE Home
  • Contact Us
 

KDECore

  • kdecore
  • services
kservice.h
Go to the documentation of this file.
1/* This file is part of the KDE project
2 Copyright (C) 1998, 1999 Torben Weis <weis@kde.org>
3 Copyright 1999-2006 David Faure <faure@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/
20
21#ifndef KSERVICE_H
22#define KSERVICE_H
23
24#include "kserviceaction.h"
25#include <QtCore/QStringList>
26#include <QtCore/QVariant>
27#ifndef KDE_NO_DEPRECATED
28#include <klibloader.h>
29#endif
30#include <kpluginfactory.h>
31#include <kpluginloader.h>
32#include <ksycocaentry.h>
33#include <klocale.h>
34
35class KServiceType;
36class QDataStream;
37class KDesktopFile;
38class QWidget;
39
40class KServicePrivate;
41
58class KDECORE_EXPORT KService : public KSycocaEntry // TODO KDE5: inherit kshared, but move KSycocaEntry to Private
59{
60public:
61 typedef KSharedPtr<KService> Ptr;
62 typedef QList<Ptr> List;
63
70 KService(const QString & name, const QString &exec, const QString &icon);
71
77 explicit KService( const QString & fullpath );
78
83 explicit KService( const KDesktopFile *config );
84
90 KService( QDataStream& str, int offset );
91
92 virtual ~KService();
93
99 bool isApplication() const;
100
106#ifndef KDE_NO_DEPRECATED
107 KDE_DEPRECATED QString type() const;
108#endif
109
115 QString exec() const;
121 QString library() const;
122
128 QString icon() const;
133 bool terminal() const;
134
143 QString terminalOptions() const;
149 bool substituteUid() const;
157 QString username() const;
158
173#ifndef KDE_NO_DEPRECATED
174 KDE_DEPRECATED QString desktopEntryPath() const;
175#endif
176
183 QString desktopEntryName() const;
184
190 QString menuId() const;
191
198 QString storageId() const;
199
212 enum DBusStartupType { DBusNone = 0, DBusUnique, DBusMulti, DBusWait };
213
218 DBusStartupType dbusStartupType() const;
219
225 QString path() const;
226
232 QString comment() const;
233
240 QString genericName() const;
241
249 QString untranslatedGenericName() const;
250
255 QStringList keywords() const;
256
261 QStringList categories() const;
262
269 QStringList mimeTypes() const;
270
277 QStringList serviceTypes() const;
278
286 bool hasServiceType( const QString& serviceTypePtr ) const;
287
306#ifndef KDE_NO_DEPRECATED
307 KDE_DEPRECATED bool hasMimeType( const KServiceType* mimeTypePtr ) const;
308#endif
309
316 bool hasMimeType( const QString& mimeType ) const;
317
328 bool allowAsDefault() const;
329
333 QList<KServiceAction> actions() const;
334
341 bool allowMultipleFiles() const;
342
349 int initialPreference() const;
350
358 bool noDisplay() const;
359
370 bool showInKDE() const;
371
377 QString parentApp() const;
378
384 QString pluginKeyword() const;
385
391 QString docPath() const;
392
401 QVariant property( const QString& _name, QVariant::Type t ) const;
402
403 using KSycocaEntry::property;
404
410 QString locateLocal() const;
411
416 void setMenuId(const QString &menuId);
421 void setTerminal(bool b);
426 void setTerminalOptions(const QString &options);
427
440 void setExec(const QString& exec);
441
452#ifndef KDE_NO_DEPRECATED
453 static Ptr serviceByName( const QString& _name ); // KDE5: remove
454#endif
455
465 static Ptr serviceByDesktopPath( const QString& _path );
466
481 static Ptr serviceByDesktopName( const QString& _name );
482
491 static Ptr serviceByMenuId( const QString& _menuId );
492
502 static Ptr serviceByStorageId( const QString& _storageId );
503
513 static List allServices();
514
530 static QString newServicePath(bool showInMenu, const QString &suggestedName,
531 QString *menuId = 0,
532 const QStringList *reservedMenuIds = 0);
533
546 template <class T>
547 T *createInstance(QObject *parent = 0,
548 const QVariantList &args = QVariantList(), QString *error = 0) const
549 {
550 return createInstance<T>(0, parent, args, error);
551 }
552
566 template <class T>
567 T *createInstance(QWidget *parentWidget, QObject *parent,
568 const QVariantList &args = QVariantList(), QString *error = 0) const
569 {
570 KPluginLoader pluginLoader(*this);
571 KPluginFactory *factory = pluginLoader.factory();
572 if (factory) {
573 T *o = factory->template create<T>(parentWidget, parent, pluginKeyword(), args);
574 if (!o && error)
575 *error = i18n("The service '%1' does not provide an interface '%2' with keyword '%3'",
576 name(), QString::fromLatin1(T::staticMetaObject.className()), pluginKeyword());
577 return o;
578 }
579 else if (error) {
580 *error = pluginLoader.errorString();
581 pluginLoader.unload();
582 }
583 return 0;
584 }
585
589#ifndef KDE_NO_DEPRECATED
590 template <class T>
591 static KDE_DEPRECATED T *createInstance(const KService::Ptr &service, QObject *parent = 0,
592 const QVariantList &args = QVariantList(), QString *error = 0)
593 {
594 return service->createInstance<T>(parent, args, error);
595 }
596#endif
597
602#ifndef KDE_NO_DEPRECATED
603 template <class T>
604 static KDE_DEPRECATED T *createInstance( const KService::Ptr &service,
605 QObject *parent,
606 const QStringList &args,
607 int *error = 0 )
608 {
609 const QString library = service->library();
610 if ( library.isEmpty() ) {
611 if ( error )
612 *error = KLibLoader::ErrServiceProvidesNoLibrary;
613 return 0;
614 }
615
616 return KLibLoader::createInstance<T>( library, parent, args, error );
617 }
618#endif
619
635#ifndef KDE_NO_DEPRECATED
636 template <class T, class ServiceIterator>
637 static KDE_DEPRECATED T *createInstance(ServiceIterator begin, ServiceIterator end, QObject *parent = 0,
638 const QVariantList &args = QVariantList(), QString *error = 0)
639 {
640 for (; begin != end; ++begin) {
641 KService::Ptr service = *begin;
642 if (error) {
643 error->clear();
644 }
645
646 T *component = createInstance<T>(service, parent, args, error);
647 if (component) {
648 return component;
649 }
650 }
651 if (error) {
652 *error = KLibLoader::errorString(KLibLoader::ErrNoServiceFound);
653 }
654 return 0;
655 }
656#endif
657
658#ifndef KDE_NO_DEPRECATED
659 template <class T, class ServiceIterator>
660 static KDE_DEPRECATED T *createInstance( ServiceIterator begin, ServiceIterator end,
661 QObject *parent,
662 const QStringList &args,
663 int *error = 0 )
664 {
665 for (; begin != end; ++begin ) {
666 KService::Ptr service = *begin;
667 if ( error )
668 *error = 0;
669
670 T *component = createInstance<T>( service, parent, args, error );
671 if ( component )
672 return component;
673 }
674 if ( error )
675 *error = KLibLoader::ErrNoServiceFound;
676 return 0;
677 }
678#endif
679
680protected:
681 friend class KMimeAssociations;
682 friend class KBuildServiceFactory;
683
685 struct ServiceTypeAndPreference
686 {
687 ServiceTypeAndPreference()
688 : preference(-1), serviceType() {}
689 ServiceTypeAndPreference(int pref, const QString& servType)
690 : preference(pref), serviceType(servType) {}
691 int preference;
692 QString serviceType; // or mimetype
693 };
695 QVector<ServiceTypeAndPreference>& _k_accessServiceTypes();
696
697 friend QDataStream& operator>>( QDataStream&, ServiceTypeAndPreference& );
698 friend QDataStream& operator<<( QDataStream&, const ServiceTypeAndPreference& );
699private:
700 Q_DECLARE_PRIVATE(KService)
701};
702#endif
KDesktopFile
KDE Desktop File Management.
Definition: kdesktopfile.h:39
KLibLoader::errorString
static QString errorString(int componentLoadingError)
Converts a numerical error code into a human-readable error message.
Definition: klibloader.cpp:142
KLibLoader::ErrServiceProvidesNoLibrary
@ ErrServiceProvidesNoLibrary
Definition: klibloader.h:169
KLibLoader::ErrNoServiceFound
@ ErrNoServiceFound
Definition: klibloader.h:170
KPluginFactory
If you develop a library that is to be loaded dynamically at runtime, then you should return a pointe...
Definition: kpluginfactory.h:233
KPluginLoader
This class can be used to dynamically load a plugin library at runtime.
Definition: kpluginloader.h:80
KPluginLoader::errorString
QString errorString() const
Queries the last error.
Definition: kpluginloader.cpp:259
KPluginLoader::factory
KPluginFactory * factory()
Used to obtain the factory object of the plugin.
Definition: kpluginloader.cpp:185
KServicePrivate
Definition: kservice_p.h:30
KServiceType
A service type is, well, a type of service, where a service is an application or plugin.
Definition: kservicetype.h:44
KService
Represent a service, like an application or plugin bound to one or several mimetypes (or servicetypes...
Definition: kservice.h:59
KService::createInstance
T * createInstance(QWidget *parentWidget, QObject *parent, const QVariantList &args=QVariantList(), QString *error=0) const
This template allows to load the library for the specified service and ask the factory to create an i...
Definition: kservice.h:567
KService::createInstance
static T * createInstance(const KService::Ptr &service, QObject *parent=0, const QVariantList &args=QVariantList(), QString *error=0)
Definition: kservice.h:591
KService::Ptr
KSharedPtr< KService > Ptr
Definition: kservice.h:61
KService::DBusStartupType
DBusStartupType
Describes the DBUS Startup type of the service.
Definition: kservice.h:212
KService::DBusMulti
@ DBusMulti
Definition: kservice.h:212
KService::createInstance
static T * createInstance(ServiceIterator begin, ServiceIterator end, QObject *parent, const QStringList &args, int *error=0)
Definition: kservice.h:660
KService::createInstance
static T * createInstance(const KService::Ptr &service, QObject *parent, const QStringList &args, int *error=0)
Definition: kservice.h:604
KService::library
QString library() const
Returns the name of the service's library.
Definition: kservice.cpp:857
KService::createInstance
T * createInstance(QObject *parent=0, const QVariantList &args=QVariantList(), QString *error=0) const
This template allows to load the library for the specified service and ask the factory to create an i...
Definition: kservice.h:547
KService::createInstance
static T * createInstance(ServiceIterator begin, ServiceIterator end, QObject *parent=0, const QVariantList &args=QVariantList(), QString *error=0)
This template allows to create a component from a list of services, usually coming from a trader quer...
Definition: kservice.h:637
KService::List
QList< Ptr > List
Definition: kservice.h:62
KSharedPtr
Can be used to control the lifetime of an object that has derived QSharedData.
Definition: ksharedptr.h:64
KSycocaEntry
Base class for all Sycoca entries.
Definition: ksycocaentry.h:42
KSycocaEntry::property
QVariant property(const QString &name) const
Returns the requested property.
Definition: ksycocaentry.cpp:169
QList
Definition: kaboutdata.h:33
QObject
QStringList
QString
QVariant
operator<<
QDebug operator<<(QDebug dbg, const KEntryKey &key)
Definition: kconfigdata.cpp:25
operator>>
QDataStream & operator>>(QDataStream &s, KDateTime::Spec &spec)
Read a KDateTime::Spec object into spec from in, in binary format.
Definition: kdatetime.cpp:274
klibloader.h
klocale.h
i18n
QString i18n(const char *text)
Returns a localized version of a string.
Definition: klocalizedstring.h:630
kpluginfactory.h
kpluginloader.h
kserviceaction.h
T
#define T
ksycocaentry.h
KService::ServiceTypeAndPreference
Definition: kservice.h:686
KService::ServiceTypeAndPreference::ServiceTypeAndPreference
ServiceTypeAndPreference(int pref, const QString &servType)
Definition: kservice.h:689
KService::ServiceTypeAndPreference::serviceType
QString serviceType
Definition: kservice.h:692
KService::ServiceTypeAndPreference::preference
int preference
Definition: kservice.h:691
KService::ServiceTypeAndPreference::ServiceTypeAndPreference
ServiceTypeAndPreference()
Definition: kservice.h:687
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 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.14.38 API Reference

Skip menu "kdelibs-4.14.38 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