• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.10.5 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 
35 class KServiceType;
36 class QDataStream;
37 class KDesktopFile;
38 class QWidget;
39 
40 class KServicePrivate;
41 
58 class KDECORE_EXPORT KService : public KSycocaEntry // TODO KDE5: inherit kshared, but move KSycocaEntry to Private
59 {
60 public:
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 
438 #ifndef KDE_NO_DEPRECATED
439  static Ptr serviceByName( const QString& _name ); // KDE5: remove
440 #endif
441 
451  static Ptr serviceByDesktopPath( const QString& _path );
452 
467  static Ptr serviceByDesktopName( const QString& _name );
468 
477  static Ptr serviceByMenuId( const QString& _menuId );
478 
488  static Ptr serviceByStorageId( const QString& _storageId );
489 
499  static List allServices();
500 
516  static QString newServicePath(bool showInMenu, const QString &suggestedName,
517  QString *menuId = 0,
518  const QStringList *reservedMenuIds = 0);
519 
532  template <class T>
533  T *createInstance(QObject *parent = 0,
534  const QVariantList &args = QVariantList(), QString *error = 0) const
535  {
536  return createInstance<T>(0, parent, args, error);
537  }
538 
552  template <class T>
553  T *createInstance(QWidget *parentWidget, QObject *parent,
554  const QVariantList &args = QVariantList(), QString *error = 0) const
555  {
556  KPluginLoader pluginLoader(*this);
557  KPluginFactory *factory = pluginLoader.factory();
558  if (factory) {
559  T *o = factory->template create<T>(parentWidget, parent, pluginKeyword(), args);
560  if (!o && error)
561  *error = i18n("The service '%1' does not provide an interface '%2' with keyword '%3'",
562  name(), QString::fromLatin1(T::staticMetaObject.className()), pluginKeyword());
563  return o;
564  }
565  else if (error) {
566  *error = pluginLoader.errorString();
567  pluginLoader.unload();
568  }
569  return 0;
570  }
571 
575 #ifndef KDE_NO_DEPRECATED
576  template <class T>
577  static KDE_DEPRECATED T *createInstance(const KService::Ptr &service, QObject *parent = 0,
578  const QVariantList &args = QVariantList(), QString *error = 0)
579  {
580  return service->createInstance<T>(parent, args, error);
581  }
582 #endif
583 
588 #ifndef KDE_NO_DEPRECATED
589  template <class T>
590  static KDE_DEPRECATED T *createInstance( const KService::Ptr &service,
591  QObject *parent,
592  const QStringList &args,
593  int *error = 0 )
594  {
595  const QString library = service->library();
596  if ( library.isEmpty() ) {
597  if ( error )
598  *error = KLibLoader::ErrServiceProvidesNoLibrary;
599  return 0;
600  }
601 
602  return KLibLoader::createInstance<T>( library, parent, args, error );
603  }
604 #endif
605 
621 #ifndef KDE_NO_DEPRECATED
622  template <class T, class ServiceIterator>
623  static KDE_DEPRECATED T *createInstance(ServiceIterator begin, ServiceIterator end, QObject *parent = 0,
624  const QVariantList &args = QVariantList(), QString *error = 0)
625  {
626  for (; begin != end; ++begin) {
627  KService::Ptr service = *begin;
628  if (error) {
629  error->clear();
630  }
631 
632  T *component = createInstance<T>(service, parent, args, error);
633  if (component) {
634  return component;
635  }
636  }
637  if (error) {
638  *error = KLibLoader::errorString(KLibLoader::ErrNoServiceFound);
639  }
640  return 0;
641  }
642 #endif
643 
644 #ifndef KDE_NO_DEPRECATED
645  template <class T, class ServiceIterator>
646  static KDE_DEPRECATED T *createInstance( ServiceIterator begin, ServiceIterator end,
647  QObject *parent,
648  const QStringList &args,
649  int *error = 0 )
650  {
651  for (; begin != end; ++begin ) {
652  KService::Ptr service = *begin;
653  if ( error )
654  *error = 0;
655 
656  T *component = createInstance<T>( service, parent, args, error );
657  if ( component )
658  return component;
659  }
660  if ( error )
661  *error = KLibLoader::ErrNoServiceFound;
662  return 0;
663  }
664 #endif
665 
666 protected:
667  friend class KMimeAssociations;
668  friend class KBuildServiceFactory;
669 
671  struct ServiceTypeAndPreference
672  {
673  ServiceTypeAndPreference()
674  : preference(-1), serviceType() {}
675  ServiceTypeAndPreference(int pref, const QString& servType)
676  : preference(pref), serviceType(servType) {}
677  int preference;
678  QString serviceType; // or mimetype
679  };
681  QVector<ServiceTypeAndPreference>& _k_accessServiceTypes();
682 
683  friend QDataStream& operator>>( QDataStream&, ServiceTypeAndPreference& );
684  friend QDataStream& operator<<( QDataStream&, const ServiceTypeAndPreference& );
685 private:
686  Q_DECLARE_PRIVATE(KService)
687 };
688 #endif
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Tue Jul 23 2013 21:56:51 by doxygen 1.8.1.1 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.10.5 API Reference

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