KIO

kterminallauncherjob.h
1/*
2 This file is part of the KDE libraries
3 SPDX-FileCopyrightText: 2021 David Faure <faure@kde.org>
4
5 SPDX-License-Identifier: LGPL-2.0-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
6*/
7
8#ifndef KTERMINALLAUNCHERJOB_H
9#define KTERMINALLAUNCHERJOB_H
10
11#include <KIO/CommandLauncherJob>
12#include <memory>
13
14class KTerminalLauncherJobPrivate;
15
16/**
17 * @class KTerminalLauncherJob kterminallauncherjob.h <KTerminalLauncherJob>
18 *
19 * @brief KTerminalLauncherJob starts a terminal application,
20 * either for the user to use interactively, or to execute a command.
21 *
22 * It creates a startup notification and finishes it on success or on error (for the taskbar).
23 * It also emits an error message if necessary (e.g. "program not found").
24 *
25 * The job finishes when the application is successfully started.
26 * For error handling, either connect to the result() signal, or for a simple messagebox on error,
27 * you can do
28 * @code
29 * job->setUiDelegate(new KDialogJobUiDelegate(KJobUiDelegate::AutoHandlingEnabled, this));
30 * @endcode
31 *
32 * @since 5.83
33 */
34class KIOGUI_EXPORT KTerminalLauncherJob : public KJob
35{
36 Q_OBJECT
37public:
38 /**
39 * Creates a KTerminalLauncherJob.
40 * @param command the command to execute in a terminal, can be empty.
41 * @param parent the parent QObject
42 */
43 explicit KTerminalLauncherJob(const QString &command, QObject *parent = nullptr);
44
45 /**
46 * Destructor
47 *
48 * Note that jobs auto-delete themselves after emitting result
49 */
51
52 /**
53 * Sets the working directory from which to run the command.
54 * @param workingDirectory path of a local directory
55 */
56 void setWorkingDirectory(const QString &workingDirectory);
57
58 /**
59 * Sets the platform-specific startup id of the command launch.
60 * @param startupId startup id, if any (otherwise "").
61 * For X11, this would be the id for the Startup Notification protocol.
62 * For Wayland, this would be the token for the XDG Activation protocol.
63 */
64 void setStartupId(const QByteArray &startupId);
65
66 /**
67 * Can be used to pass environment variables to the child process.
68 * @param environment set of environment variables to pass to the child process
69 * @see QProcessEnvironment
70 */
71 void setProcessEnvironment(const QProcessEnvironment &environment);
72
73 /**
74 * Starts the job.
75 * You must call this, after having called all the necessary setters.
76 */
77 void start() override;
78
79private:
80 friend class KTerminalLauncherJobTest;
81 void determineFullCommand(bool fallbackToKonsoleService = true); // for the unittest
82 QString fullCommand() const; // for the unittest
83
84 KIOGUI_NO_EXPORT void emitDelayedResult();
85
86 friend class KTerminalLauncherJobPrivate;
87 std::unique_ptr<KTerminalLauncherJobPrivate> d;
88};
89
90#endif // KTERMINALLAUNCHERJOB_H
virtual Q_SCRIPTABLE void start()=0
KTerminalLauncherJob starts a terminal application, either for the user to use interactively,...
~KTerminalLauncherJob() override
Destructor.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sun Feb 25 2024 18:45:23 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.