KToolInvocation

Search for usage in LXR

#include <KToolInvocation>

Inheritance diagram for KToolInvocation:

Signals

void kapplication_hook (QStringList &env, QByteArray &startup_id)
 

Public Slots

static void invokeBrowser (const QString &url, const QByteArray &startup_id=QByteArray())
 
static void invokeMailer (const QString &address, const QString &subject, const QByteArray &startup_id=QByteArray())
 
static void invokeMailer (const QUrl &mailtoURL, const QByteArray &startup_id=QByteArray(), bool allowAttachments=false)
 
static void invokeMailer (const QString &to, const QString &cc, const QString &bcc, const QString &subject, const QString &body, const QString &messageFile=QString(), const QStringList &attachURLs=QStringList(), const QByteArray &startup_id=QByteArray())
 
static void invokeTerminal (const QString &command, const QStringList &envs, const QString &workdir=QString(), const QByteArray &startup_id="")
 
static void invokeTerminal (const QString &command, const QString &workdir=QString(), const QByteArray &startup_id="")
 
static KServicePtr terminalApplication (const QString &command=QString(), const QString &workingDir=QString())
 

Static Public Member Functions

static void ensureKdeinitRunning ()
 
static int kdeinitExec (const QString &name, const QStringList &args=QStringList(), QString *error=nullptr, int *pid=nullptr, const QByteArray &startup_id=QByteArray())
 
static int kdeinitExecWait (const QString &name, const QStringList &args=QStringList(), QString *error=nullptr, int *pid=nullptr, const QByteArray &startup_id=QByteArray())
 
static KToolInvocationself ()
 
static int startServiceByDesktopName (const QString &_name, const QString &URL, QString *error=nullptr, QString *serviceName=nullptr, int *pid=nullptr, const QByteArray &startup_id=QByteArray(), bool noWait=false)
 
static int startServiceByDesktopName (const QString &_name, const QStringList &URLs=QStringList(), QString *error=nullptr, QString *serviceName=nullptr, int *pid=nullptr, const QByteArray &startup_id=QByteArray(), bool noWait=false)
 
static int startServiceByDesktopPath (const QString &_name, const QString &URL, QString *error=nullptr, QString *serviceName=nullptr, int *pid=nullptr, const QByteArray &startup_id=QByteArray(), bool noWait=false)
 
static int startServiceByDesktopPath (const QString &_name, const QStringList &URLs=QStringList(), QString *error=nullptr, QString *serviceName=nullptr, int *pid=nullptr, const QByteArray &startup_id=QByteArray(), bool noWait=false)
 
static int startServiceByName (const QString &_name, const QString &URL, QString *error=nullptr, QString *serviceName=nullptr, int *pid=nullptr, const QByteArray &startup_id=QByteArray(), bool noWait=false)
 
static int startServiceByName (const QString &_name, const QStringList &URLs=QStringList(), QString *error=nullptr, QString *serviceName=nullptr, int *pid=nullptr, const QByteArray &startup_id=QByteArray(), bool noWait=false)
 
- Static Public Member Functions inherited from QObject
QMetaObject::Connection connect (const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, Functor functor)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, const QObject *context, Functor functor, Qt::ConnectionType type)
 
bool disconnect (const QMetaObject::Connection &connection)
 
bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *method)
 
bool disconnect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method)
 
bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method)
 
QString tr (const char *sourceText, const char *disambiguation, int n)
 
QString trUtf8 (const char *sourceText, const char *disambiguation, int n)
 

Additional Inherited Members

- Properties inherited from QObject
 objectName
 
- Public Member Functions inherited from QObject
 QObject (QObject *parent)
 
bool blockSignals (bool block)
 
const QObjectListchildren () const const
 
QMetaObject::Connection connect (const QObject *sender, const char *signal, const char *method, Qt::ConnectionType type) const const
 
void deleteLater ()
 
void destroyed (QObject *obj)
 
bool disconnect (const char *signal, const QObject *receiver, const char *method) const const
 
bool disconnect (const QObject *receiver, const char *method) const const
 
void dumpObjectInfo ()
 
void dumpObjectInfo () const const
 
void dumpObjectTree ()
 
void dumpObjectTree () const const
 
QList< QByteArraydynamicPropertyNames () const const
 
virtual bool event (QEvent *e)
 
virtual bool eventFilter (QObject *watched, QEvent *event)
 
findChild (const QString &name, Qt::FindChildOptions options) const const
 
QList< T > findChildren (const QString &name, Qt::FindChildOptions options) const const
 
QList< T > findChildren (const QRegExp &regExp, Qt::FindChildOptions options) const const
 
QList< T > findChildren (const QRegularExpression &re, Qt::FindChildOptions options) const const
 
bool inherits (const char *className) const const
 
void installEventFilter (QObject *filterObj)
 
bool isWidgetType () const const
 
bool isWindowType () const const
 
void killTimer (int id)
 
virtual const QMetaObjectmetaObject () const const
 
void moveToThread (QThread *targetThread)
 
QString objectName () const const
 
void objectNameChanged (const QString &objectName)
 
QObjectparent () const const
 
QVariant property (const char *name) const const
 
 Q_CLASSINFO (Name, Value)
 
 Q_DISABLE_COPY (Class)
 
 Q_DISABLE_COPY_MOVE (Class)
 
 Q_DISABLE_MOVE (Class)
 
 Q_EMIT Q_EMIT
 
 Q_ENUM (...)
 
 Q_ENUM_NS (...)
 
 Q_ENUMS (...)
 
 Q_FLAG (...)
 
 Q_FLAG_NS (...)
 
 Q_FLAGS (...)
 
 Q_GADGET Q_GADGET
 
 Q_INTERFACES (...)
 
 Q_INVOKABLE Q_INVOKABLE
 
 Q_NAMESPACE Q_NAMESPACE
 
 Q_NAMESPACE_EXPORT (EXPORT_MACRO)
 
 Q_OBJECT Q_OBJECT
 
 Q_PROPERTY (...)
 
 Q_REVISION Q_REVISION
 
 Q_SET_OBJECT_NAME (Object)
 
 Q_SIGNAL Q_SIGNAL
 
 Q_SIGNALS Q_SIGNALS
 
 Q_SLOT Q_SLOT
 
 Q_SLOTS Q_SLOTS
 
qFindChild (const QObject *obj, const QString &name)
 
QList< T > qFindChildren (const QObject *obj, const QRegExp &regExp)
 
QList< T > qFindChildren (const QObject *obj, const QString &name)
 
qobject_cast (QObject *object)
 
qobject_cast (const QObject *object)
 
 QT_NO_NARROWING_CONVERSIONS_IN_CONNECT QT_NO_NARROWING_CONVERSIONS_IN_CONNECT
 
void removeEventFilter (QObject *obj)
 
void setObjectName (const QString &name)
 
void setParent (QObject *parent)
 
bool setProperty (const char *name, const QVariant &value)
 
bool signalsBlocked () const const
 
int startTimer (int interval, Qt::TimerType timerType)
 
int startTimer (std::chrono::milliseconds time, Qt::TimerType timerType)
 
QThreadthread () const const
 
- Public Attributes inherited from QObject
typedef QObjectList
 
- Protected Member Functions inherited from QObject
virtual void childEvent (QChildEvent *event)
 
virtual void connectNotify (const QMetaMethod &signal)
 
virtual void customEvent (QEvent *event)
 
virtual void disconnectNotify (const QMetaMethod &signal)
 
bool isSignalConnected (const QMetaMethod &signal) const const
 
int receivers (const char *signal) const const
 
QObjectsender () const const
 
int senderSignalIndex () const const
 
virtual void timerEvent (QTimerEvent *event)
 

Detailed Description

KToolInvocation: for starting other programs.

Desktop files for startServiceBy

The way a service gets started depends on the 'X-DBUS-StartupType' entry in the desktop file of the service:

There are three possibilities:

  • X-DBUS-StartupType=None (default) Always start a new service, don't wait till the service registers with D-Bus.
  • X-DBUS-StartupType=Multi Always start a new service, wait until the service has registered with D-Bus.
  • X-DBUS-StartupType=Unique Only start the service if it isn't already running, wait until the service has registered with D-Bus. The .desktop file can specify the name that the application will use when registering using X-DBUS-ServiceName=org.domain.mykapp. Otherwise org.kde.binaryname is assumed.

Multi-threading

The static members (apart from self()), have to be called from the QApplication main thread. Calls to members are only allowed if there is a Q(Core)Application object created If you call the members with signal/slot connections across threads, you can't use the return values If a function is called from the wrong thread and it has a return value -1 is returned Investigate if this is really needed or if D-Bus is threadsafe anyway

For more details see techbase.

Definition at line 63 of file ktoolinvocation.h.

Member Function Documentation

void KToolInvocation::ensureKdeinitRunning ( )
static

Ensures that kdeinit5 and klauncher are running.

Definition at line 305 of file ktoolinvocation.cpp.

void KToolInvocation::invokeBrowser ( const QString url,
const QByteArray startup_id = QByteArray() 
)
staticslot

Invokes the user's preferred browser.

Note that you should only do this when you know for sure that the browser can handle the URL (i.e. its MIME type). In doubt, if the URL can point to an image or anything else than HTML, prefer to use new KRun( url ).

See also <a href="http://techbase.kde.org/Development/Architecture/KDE4/Starting_Other_Programs#KToolInvocation::invokeBrowser>techbase for a discussion of invokeBrowser vs KRun.

Parameters
urlThe destination address
startup_idfor app startup notification, "0" for none, "" ( empty string ) is the default
Deprecated:
since 5.0, use QDesktopServices::openUrl(url)

Definition at line 29 of file ktoolinvocation_win.cpp.

void KToolInvocation::invokeMailer ( const QString address,
const QString subject,
const QByteArray startup_id = QByteArray() 
)
staticslot

Convenience method; invokes the standard email application.

Parameters
addressThe destination address
subjectSubject string. Can be QString().
startup_idfor app startup notification, "0" for none, "" ( empty string ) is the default
Deprecated:
since 5.0, use QDesktopServices::openUrl(mailtoURL), using QUrl::setPath(address) and a query item of "subject" for the subject.

Definition at line 255 of file ktoolinvocation.cpp.

void KToolInvocation::invokeMailer ( const QUrl mailtoURL,
const QByteArray startup_id = QByteArray(),
bool  allowAttachments = false 
)
staticslot

Invokes the standard email application.

Parameters
mailtoURLA mailto URL.
startup_idfor app startup notification, "0" for none, "" ( empty string ) is the default
allowAttachmentswhether attachments specified in mailtoURL should be honoured. The default is false; do not honor requests for attachments.
Deprecated:
since 5.0, use QDesktopServices::openUrl(mailtoURL)

Definition at line 266 of file ktoolinvocation.cpp.

void KToolInvocation::invokeMailer ( const QString to,
const QString cc,
const QString bcc,
const QString subject,
const QString body,
const QString messageFile = QString(),
const QStringList attachURLs = QStringList(),
const QByteArray startup_id = QByteArray() 
)
staticslot

Convenience method; invokes the standard email application.

All parameters are optional.

Parameters
toThe destination address.
ccThe Cc field
bccThe Bcc field
subjectSubject string
bodyA string containing the body of the mail (exclusive with messageFile)
messageFileA file (URL) containing the body of the mail (exclusive with body) - currently unsupported
attachURLsList of URLs to be attached to the mail.
startup_idfor app startup notification, "0" for none, "" ( empty string ) is the default

Definition at line 47 of file ktoolinvocation_win.cpp.

void KToolInvocation::invokeTerminal ( const QString command,
const QStringList envs,
const QString workdir = QString(),
const QByteArray startup_id = "" 
)
staticslot

Invokes the standard terminal application.

Parameters
commandthe command to execute, can be empty.
envsENV variables for the invoked terminal command
workdirthe initial working directory, can be empty.
startup_idfor app startup notification, "0" for none, "" ( empty string ) is the default
Since
5.73

Definition at line 82 of file ktoolinvocation_win.cpp.

void KToolInvocation::invokeTerminal ( const QString command,
const QString workdir = QString(),
const QByteArray startup_id = "" 
)
staticslot

Invokes the standard terminal application.

Parameters
commandthe command to execute, can be empty.
workdirthe initial working directory, can be empty.
startup_idfor app startup notification, "0" for none, "" ( empty string ) is the default
Since
4.1
Deprecated:
since 5,79, use invokeTerminal(const QString &command, const QStringList &envs, const QString &workdir, const QByteArray &startup_id) instead

Definition at line 127 of file ktoolinvocation_win.cpp.

void KToolInvocation::kapplication_hook ( QStringList env,
QByteArray startup_id 
)
signal

Hook for KApplication in kdeui.

int KToolInvocation::kdeinitExec ( const QString name,
const QStringList args = QStringList(),
QString error = nullptr,
int *  pid = nullptr,
const QByteArray startup_id = QByteArray() 
)
static

Starts a program via kdeinit.

program name and arguments are converted to according to the local encoding and passed as is to kdeinit.

Parameters
nameName of the program to start
argsArguments to pass to the program
errorOn failure, error contains a description of the error that occurred. If the pointer is 0, the argument will be ignored
pidOn success, the process id of the new service will be written here. If the pointer is 0, the argument will be ignored.
startup_idfor app startup notification, "0" for none, "" ( empty string ) is the default
Returns
an error code indicating success (== 0) or failure (> 0).

Definition at line 236 of file ktoolinvocation.cpp.

int KToolInvocation::kdeinitExecWait ( const QString name,
const QStringList args = QStringList(),
QString error = nullptr,
int *  pid = nullptr,
const QByteArray startup_id = QByteArray() 
)
static

Starts a program via kdeinit and wait for it to finish.

Like kdeinitExec(), but it waits till the program is finished. As such it behaves similar to the system(...) function.

Parameters
nameName of the program to start
argsArguments to pass to the program
errorOn failure, error contains a description of the error that occurred. If the pointer is 0, the argument will be ignored
pidOn success, the process id of the new service will be written here. If the pointer is 0, the argument will be ignored.
startup_idfor app startup notification, "0" for none, "" ( empty string ) is the default
Returns
an error code indicating success (== 0) or failure (> 0).

Definition at line 245 of file ktoolinvocation.cpp.

int KToolInvocation::startServiceByDesktopName ( const QString _name,
const QString URL,
QString error = nullptr,
QString serviceName = nullptr,
int *  pid = nullptr,
const QByteArray startup_id = QByteArray(),
bool  noWait = false 
)
static

Starts a service based on the desktop name of the service.

E.g. "konqueror"

Parameters
_namethe desktop name of the service
URLif not empty this URL is passed to the service
errorOn failure, error contains a description of the error that occurred. If the pointer is 0, the argument will be ignored
serviceNameOn success, serviceName contains the D-Bus service name under which this service is available. If empty, the service does not provide D-Bus services. If the pointer is 0 the argument will be ignored
pidOn success, the process id of the new service will be written here. If the pointer is 0, the argument will be ignored.
startup_idfor app startup notification, "0" for none, "" ( empty string ) is the default
noWaitif set, the function does not wait till the service is running.
Returns
an error code indicating success (== 0) or failure (> 0).
Deprecated:
since 5.0 use QDBusConnectionInterface::startService("org.kde.serviceName"), to start a unique application in order to make D-Bus calls to it (after ensuring that it installs a D-Bus org.kde.serviceName.service file). Otherwise just use QProcess or KRun.

Definition at line 202 of file ktoolinvocation.cpp.

int KToolInvocation::startServiceByDesktopName ( const QString _name,
const QStringList URLs = QStringList(),
QString error = nullptr,
QString serviceName = nullptr,
int *  pid = nullptr,
const QByteArray startup_id = QByteArray(),
bool  noWait = false 
)
static

Starts a service based on the desktop name of the service.

E.g. "konqueror"

Parameters
_namethe desktop name of the service
URLsif not empty these URLs will be passed to the service
errorOn failure, error contains a description of the error that occurred. If the pointer is 0, the argument will be ignored
serviceNameOn success, serviceName contains the D-Bus service name under which this service is available. If empty, the service does not provide D-Bus services. If the pointer is 0 the argument will be ignored
pidOn success, the process id of the new service will be written here. If the pointer is 0, the argument will be ignored.
startup_idfor app startup notification, "0" for none, "" ( empty string ) is the default
noWaitif set, the function does not wait till the service is running.
Returns
an error code indicating success (== 0) or failure (> 0).
Deprecated:
since 5.0 use QDBusConnectionInterface::startService("org.kde.serviceName"), to start a unique application in order to make D-Bus calls to it (after ensuring that it installs a D-Bus org.kde.serviceName.service file). Otherwise just use QProcess or KRun.

Definition at line 221 of file ktoolinvocation.cpp.

int KToolInvocation::startServiceByDesktopPath ( const QString _name,
const QString URL,
QString error = nullptr,
QString serviceName = nullptr,
int *  pid = nullptr,
const QByteArray startup_id = QByteArray(),
bool  noWait = false 
)
static

Starts a service based on the desktop path of the service.

E.g. "Applications/konqueror.desktop" or "/home/user/bla/myfile.desktop"

Parameters
_namethe path of the desktop file
URLif not empty this URL is passed to the service
errorOn failure, error contains a description of the error that occurred. If the pointer is 0, the argument will be ignored
serviceNameOn success, serviceName contains the D-Bus name under which this service is available. If empty, the service does not provide D-Bus services. If the pointer is 0 the argument will be ignored
pidOn success, the process id of the new service will be written here. If the pointer is 0, the argument will be ignored.
startup_idfor app startup notification, "0" for none, "" ( empty string ) is the default
noWaitif set, the function does not wait till the service is running.
Returns
an error code indicating success (== 0) or failure (> 0).
Deprecated:
since 5.0 use QDBusConnectionInterface::startService("org.kde.serviceName"), to start a unique application in order to make D-Bus calls to it (after ensuring that it installs a D-Bus org.kde.serviceName.service file). Otherwise just use QProcess or KRun.

Definition at line 168 of file ktoolinvocation.cpp.

int KToolInvocation::startServiceByDesktopPath ( const QString _name,
const QStringList URLs = QStringList(),
QString error = nullptr,
QString serviceName = nullptr,
int *  pid = nullptr,
const QByteArray startup_id = QByteArray(),
bool  noWait = false 
)
static

Starts a service based on the desktop path of the service.

E.g. "Applications/konqueror.desktop" or "/home/user/bla/myfile.desktop"

Parameters
_namethe path of the desktop file
URLsif not empty these URLs will be passed to the service
errorOn failure, error contains a description of the error that occurred. If the pointer is 0, the argument will be ignored *
serviceNameOn success, serviceName contains the D-Bus name under which this service is available. If empty, the service does not provide D-Bus services. If the pointer is 0 the argument will be ignored
pidOn success, the process id of the new service will be written here. If the pointer is 0, the argument will be ignored.
startup_idfor app startup notification, "0" for none, "" ( empty string ) is the default
noWaitif set, the function does not wait till the service is running.
Returns
an error code indicating success (== 0) or failure (> 0).
Deprecated:
since 5.0 use QDBusConnectionInterface::startService("org.kde.serviceName"), to start a unique application in order to make D-Bus calls to it (after ensuring that it installs a D-Bus org.kde.serviceName.service file). Otherwise just use QProcess or KRun.

Definition at line 187 of file ktoolinvocation.cpp.

int KToolInvocation::startServiceByName ( const QString _name,
const QString URL,
QString error = nullptr,
QString serviceName = nullptr,
int *  pid = nullptr,
const QByteArray startup_id = QByteArray(),
bool  noWait = false 
)
static

Starts a service based on the (translated) name of the service.

E.g. "Web Browser"

Parameters
_namethe name of the service
URLif not empty this URL is passed to the service
errorOn failure, error contains a description of the error that occurred. If the pointer is 0, the argument will be ignored
serviceNameOn success, serviceName contains the D-Bus name under which this service is available. If empty, the service does not provide D-Bus services. If the pointer is 0 the argument will be ignored
pidOn success, the process id of the new service will be written here. If the pointer is 0, the argument will be ignored.
startup_idfor app startup notification, "0" for none, "" ( empty string ) is the default
noWaitif set, the function does not wait till the service is running.
Returns
an error code indicating success (== 0) or failure (> 0).
Deprecated:
Since 5.0, use startServiceByDesktopName or startServiceByDesktopPath

Definition at line 131 of file ktoolinvocation.cpp.

int KToolInvocation::startServiceByName ( const QString _name,
const QStringList URLs = QStringList(),
QString error = nullptr,
QString serviceName = nullptr,
int *  pid = nullptr,
const QByteArray startup_id = QByteArray(),
bool  noWait = false 
)
static

Starts a service based on the (translated) name of the service.

E.g. "Web Browser"

Parameters
_namethe name of the service
URLsif not empty these URLs will be passed to the service
errorOn failure, error contains a description of the error that occurred. If the pointer is 0, the argument will be ignored
serviceNameOn success, serviceName contains the D-Bus name under which this service is available. If empty, the service does not provide D-Bus services. If the pointer is 0 the argument will be ignored
pidOn success, the process id of the new service will be written here. If the pointer is 0, the argument will be ignored.
startup_idfor app startup notification, "0" for none, "" ( empty string ) is the default
noWaitif set, the function does not wait till the service is running.
Returns
an error code indicating success (== 0) or failure (> 0).
Deprecated:
Since 5.0, use startServiceByDesktopName or startServiceByDesktopPath

Definition at line 152 of file ktoolinvocation.cpp.

KServicePtr KToolInvocation::terminalApplication ( const QString command = QString(),
const QString workingDir = QString() 
)
staticslot

Returns the configured default terminal application.

This is compatible with the old config format from the KCM in Plasma < 5.21.

Parameters
commandCommand that should be executed in the terminal app
workingDirWorking directory for the terminal app.
Returns
KServicePtr of terminal application.
Since
5.78

Definition at line 133 of file ktoolinvocation_win.cpp.


The documentation for this class was generated from the following files:
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Fri Apr 16 2021 22:47:36 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.