KParts

kde_terminal_interface.h
1/*
2 interface.h
3 SPDX-FileCopyrightText: 2002 Dominique Devriese <devriese@kde.org>
4
5 SPDX-License-Identifier: LGPL-2.1-or-later
6*/
7
8#ifndef KDELIBS_KDE_TERMINAL_INTERFACE_H
9#define KDELIBS_KDE_TERMINAL_INTERFACE_H
10
11#include <QObject>
12#include <QStringList>
13
14/**
15 * TerminalInterface is an interface implemented by KonsolePart to
16 * allow developers access to the KonsolePart in ways that are not
17 * possible through the normal KPart interface.
18 *
19 * Note that besides the functions below here, KonsolePart also has
20 * some signals you can connect to. They aren't in this class cause
21 * we can't have signals without having a QObject, which
22 * TerminalInterface is not.
23 *
24 * These are some signals you can connect to:
25 * void currentDirectoryChanged(const QString& dir);
26 *
27 * See the example code below for how to connect to these.
28 *
29 * Use it like this:
30 * \code
31 * // Query the .desktop file to get service information about konsolepart
32 * KService::Ptr service = KService::serviceByDesktopName("konsolepart");
33 *
34 * if (!service) {
35 * QMessageBox::critical(this, tr("Konsole not installed"), tr("Please install the kde konsole and try again!"), QMessageBox::Ok);
36 * return ;
37 * }
38 *
39 * // Create one instance of konsolepart
40 * KParts::ReadOnlyPart *part = service->createInstance<KParts::ReadOnlyPart>(parent, parentWidget, QVariantList());
41 *
42 * if (!part) {
43 * return;
44 * }
45 *
46 * // Cast the konsolepart to the TerminalInterface..
47 * TerminalInterface *terminalIface = qobject_cast<TerminalInterface *>(part);
48 *
49 * if (!terminalIface) {
50 * return;
51 * }
52 *
53 * // Now use the interface in all sorts of ways, e.g.
54 * // terminalIface->showShellInDir(QDir::home().path());
55 * // Or:
56 * // QStringList list;
57 * // list.append("python");
58 * // terminalIface->startProgram( QString::fromUtf8( "/usr/bin/python" ), list);
59 * // Or connect to one of the signals. Connect to the Part object,
60 * // not to the TerminalInterface, since the latter is not a QObject,
61 * // and as such does not have signals..:
62 * connect(part, &KParts::ReadOnlyPart::currentDirectoryChanged, this, [this](const QString &dirPath) {
63 * currentDirectoryChanged(dirPath);
64 * });
65 * // etc.
66 *
67 * \endcode
68 *
69 * @author Dominique Devriese <devriese@kde.org>
70 */
72{
73public:
74 virtual ~TerminalInterface()
75 {
76 }
77 /**
78 * This starts @p program, with arguments @p args
79 */
80 virtual void startProgram(const QString &program, const QStringList &args) = 0;
81 /**
82 * If no shell is running, this starts a shell with the
83 * @dir as the starting directory.
84 * If a shell is already running, nothing is done.
85 */
86 virtual void showShellInDir(const QString &dir) = 0;
87
88 /**
89 * This sends @param text as input to the currently running
90 * program..
91 */
92 virtual void sendInput(const QString &text) = 0;
93
94 /**
95 * Return terminal PID. If no process is currently running, returns 0.
96 */
97 virtual int terminalProcessId() = 0;
98
99 /**
100 * Return foregound PID, If there is no foreground process running, returns -1
101 */
102 virtual int foregroundProcessId() = 0;
103
104 /**
105 * Returns sub process name. If there is no sub process running, returns empty QString
106 */
108
109 /**
110 * Returns the current working directory
111 */
112 virtual QString currentWorkingDirectory() const = 0;
113
114 /**
115 * Returns the names of available profiles.
116 */
117 virtual QStringList availableProfiles() const = 0;
118
119 /**
120 * Returns the name of the currently active profile.
121 */
122 virtual QString currentProfileName() const = 0;
123
124 /**
125 * Changes the currently active profile to @p profileName.
126 * @returns Returns true if setting the profile was successful
127 */
128 virtual bool setCurrentProfile(const QString &profileName) = 0;
129
130 /**
131 * Returns the property @p profileProperty of the currently active profile.
132 */
134};
135
136Q_DECLARE_INTERFACE(TerminalInterface, "org.kde.TerminalInterface")
137
138#endif
TerminalInterface is an interface implemented by KonsolePart to allow developers access to the Konsol...
virtual QString currentProfileName() const =0
Returns the name of the currently active profile.
virtual void startProgram(const QString &program, const QStringList &args)=0
This starts program, with arguments args.
virtual QString currentWorkingDirectory() const =0
Returns the current working directory.
virtual QStringList availableProfiles() const =0
Returns the names of available profiles.
virtual QString foregroundProcessName()=0
Returns sub process name.
virtual int terminalProcessId()=0
Return terminal PID.
virtual void sendInput(const QString &text)=0
This sends.
virtual bool setCurrentProfile(const QString &profileName)=0
Changes the currently active profile to profileName.
virtual QVariant profileProperty(const QString &profileProperty) const =0
Returns the property profileProperty of the currently active profile.
virtual int foregroundProcessId()=0
Return foregound PID, If there is no foreground process running, returns -1.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Dec 20 2024 12:00:53 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.