KService

kservice.h
1 /* This file is part of the KDE project
2  Copyright (C) 1998, 1999 Torben Weis <[email protected]>
3  Copyright 1999-2006 David Faure <[email protected]>
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 <QStringList>
26 #include <QVariant>
27 #include <KPluginFactory>
28 #include <KPluginLoader>
29 #include <ksycocaentry.h>
30 #include <QCoreApplication>
31 
32 class KServiceType;
33 class QDataStream;
34 class KDesktopFile;
35 class QWidget;
36 
37 class KServicePrivate;
38 
57 class KSERVICE_EXPORT KService : public KSycocaEntry
58 {
59 public:
67  typedef QList<Ptr> List;
68 
75  KService(const QString &name, const QString &exec, const QString &icon);
76 
82  explicit KService(const QString &fullpath);
83 
89  explicit KService(const KDesktopFile *config, const QString &entryPath = QString());
90 
91  KService(const KService &other);
92 
93  virtual ~KService();
94 
100  bool isApplication() const;
101 
107  QString exec() const;
113  QString library() const;
114 
120  QString icon() const;
125  bool terminal() const;
126 
135  QString terminalOptions() const;
141  bool runOnDiscreteGpu() const;
147  bool substituteUid() const;
155  QString username() const;
156 
163  QString desktopEntryName() const;
164 
170  QString menuId() const;
171 
178  QString storageId() const;
179 
190  enum DBusStartupType { DBusNone = 0, DBusUnique, DBusMulti };
191 
196  DBusStartupType dbusStartupType() const;
197 
198 #if KSERVICE_ENABLE_DEPRECATED_SINCE(5, 63)
199 
204  KSERVICE_DEPRECATED_VERSION(5, 63, "Use KService::workingDirectory()")
205  QString path() const;
206 #endif
207 
213  QString workingDirectory() const;
214 
220  QString comment() const;
221 
228  QString genericName() const;
229 
237  QString untranslatedGenericName() const;
238 
243  QStringList keywords() const;
244 
249  QStringList categories() const;
250 
257  QStringList mimeTypes() const;
258 
265  QStringList serviceTypes() const;
266 
274  bool hasServiceType(const QString &serviceTypePtr) const;
275 
282  bool hasMimeType(const QString &mimeType) const;
283 
284 #if KSERVICE_ENABLE_DEPRECATED_SINCE(5, 67)
285 
296  KSERVICE_DEPRECATED_VERSION(5, 67, "No known use case")
297  bool allowAsDefault() const;
298 #endif
299 
303  QList<KServiceAction> actions() const;
304 
311  bool allowMultipleFiles() const;
312 
319  int initialPreference() const;
320 
328  bool noDisplay() const;
329 
330 #if KSERVICE_ENABLE_DEPRECATED_SINCE(5, 0)
331 
342  KSERVICE_DEPRECATED_VERSION(5, 0, "Use KService::showInCurrentDesktop()")
343  bool showInKDE() const { return showInCurrentDesktop(); }
344 #endif
345 
356  bool showInCurrentDesktop() const;
357 
365  bool showOnCurrentPlatform() const;
366 
372  QString parentApp() const;
373 
379  QString pluginKeyword() const;
380 
386  QString docPath() const;
387 
396  QVariant property(const QString &_name, QVariant::Type t) const;
397 
399 
405  QString locateLocal() const;
406 
411  void setMenuId(const QString &menuId);
416  void setTerminal(bool b);
421  void setTerminalOptions(const QString &options);
422 
435  void setExec(const QString &exec);
436 
446  static Ptr serviceByDesktopPath(const QString &_path);
447 
462  static Ptr serviceByDesktopName(const QString &_name);
463 
472  static Ptr serviceByMenuId(const QString &_menuId);
473 
483  static Ptr serviceByStorageId(const QString &_storageId);
484 
494  static List allServices();
495 
512  static QString newServicePath(bool showInMenu, const QString &suggestedName,
513  QString *menuId = nullptr,
514  const QStringList *reservedMenuIds = nullptr);
515 
528  template <class T>
529  T *createInstance(QObject *parent = nullptr,
530  const QVariantList &args = QVariantList(), QString *error = nullptr) const
531  {
532  return createInstance<T>(nullptr, parent, args, error);
533  }
534 
548  template <class T>
549  T *createInstance(QWidget *parentWidget, QObject *parent,
550  const QVariantList &args = QVariantList(), QString *error = nullptr) const
551  {
552  KPluginLoader pluginLoader(*this);
553  KPluginFactory *factory = pluginLoader.factory();
554  if (factory) {
555  QVariantList argsWithMetaData = args;
556  argsWithMetaData << pluginLoader.metaData().toVariantMap();
557  T *o = factory->template create<T>(parentWidget, parent, pluginKeyword(), argsWithMetaData);
558  if (!o && error)
559  *error = QCoreApplication::translate("", "The service '%1' does not provide an interface '%2' with keyword '%3'")
560  .arg(name(), QString::fromLatin1(T::staticMetaObject.className()), pluginKeyword());
561  return o;
562  } else if (error) {
563  *error = pluginLoader.errorString();
564  pluginLoader.unload();
565  }
566  return nullptr;
567  }
568 
580  operator KPluginName() const;
581 
582 private:
583  friend class KBuildServiceFactory;
584 
586  struct ServiceTypeAndPreference {
587  ServiceTypeAndPreference()
588  : preference(-1), serviceType() {}
589  ServiceTypeAndPreference(int pref, const QString &servType)
590  : preference(pref), serviceType(servType) {}
591  int preference;
592  QString serviceType; // or mimetype
593  };
595  QVector<ServiceTypeAndPreference> &_k_accessServiceTypes();
596 
597  friend QDataStream &operator>>(QDataStream &, ServiceTypeAndPreference &);
598  friend QDataStream &operator<<(QDataStream &, const ServiceTypeAndPreference &);
599 
600  Q_DECLARE_PRIVATE(KService)
601 
602  friend class KServiceFactory;
603 
609  KService(QDataStream &str, int offset);
610 };
611 #endif
T * createInstance(QWidget *parentWidget, QObject *parent, const QVariantList &args=QVariantList(), QString *error=nullptr) const
This template allows to load the library for the specified service and ask the factory to create an i...
Definition: kservice.h:549
QDataStream & operator>>(QDataStream &in, KDateTime::Spec &spec)
Represent a service, like an application or plugin bound to one or several mimetypes (or servicetypes...
Definition: kservice.h:57
QVariantMap toVariantMap() const const
QString translate(const char *context, const char *sourceText, const char *disambiguation, int n)
T * createInstance(QObject *parent=nullptr, const QVariantList &args=QVariantList(), QString *error=nullptr) const
This template allows to load the library for the specified service and ask the factory to create an i...
Definition: kservice.h:529
A service type is, well, a type of service, where a service is an application or plugin.
Definition: kservicetype.h:45
QExplicitlySharedDataPointer< KService > Ptr
A shared data pointer for KService.
Definition: kservice.h:63
QString errorString() const
Base class for all Sycoca entries.
Definition: ksycocaentry.h:41
QJsonObject metaData() const
QList< Ptr > List
A list of shared data pointers for KService.
Definition: kservice.h:67
QString storageId() const
KPluginFactory * factory()
QDataStream & operator<<(QDataStream &out, const KDateTime::Spec &spec)
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
DBusStartupType
Describes the D-Bus Startup type of the service.
Definition: kservice.h:190
QString fromLatin1(const char *str, int size)
QVariant property(const QString &name) const
Returns the requested property.
QString name() const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Wed Aug 5 2020 22:45:46 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.