File indexing completed on 2024-04-21 05:51:24
0001 /* 0002 SPDX-FileCopyrightText: 2007-2008 Robert Knight <robertknight@gmail.com> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef PART_H 0008 #define PART_H 0009 0010 // KDE 0011 #include <KParts/ReadOnlyPart> 0012 #include <kde_terminal_interface.h> 0013 0014 // Qt 0015 #include <QVariantList> 0016 0017 // Konsole 0018 #include "config-konsole.h" 0019 #include "session/Session.h" 0020 0021 class QKeyEvent; 0022 0023 namespace Konsole 0024 { 0025 class Session; 0026 class SessionController; 0027 class ViewManager; 0028 class ViewProperties; 0029 0030 /** 0031 * A re-usable terminal emulator component using the KParts framework which can 0032 * be used to embed terminal emulators into other applications. 0033 */ 0034 class Part : public KParts::ReadOnlyPart, public TerminalInterface 0035 { 0036 Q_OBJECT 0037 Q_INTERFACES(TerminalInterface) 0038 public: 0039 /** Constructs a new Konsole part with the specified parent. */ 0040 explicit Part(QObject *parent, const QVariantList &); 0041 ~Part() override; 0042 0043 /** Reimplemented from TerminalInterface. */ 0044 void startProgram(const QString &program, const QStringList &arguments) override; 0045 /** Reimplemented from TerminalInterface. */ 0046 void showShellInDir(const QString &dir) override; 0047 /** Reimplemented from TerminalInterface. */ 0048 void sendInput(const QString &text) override; 0049 0050 /** Reimplemented from TerminalInterface. */ 0051 int terminalProcessId() override; 0052 0053 /** Reimplemented from TerminalInterface. */ 0054 int foregroundProcessId() override; 0055 0056 /** Reimplemented from TerminalInterface. */ 0057 QString foregroundProcessName() override; 0058 0059 /** Reimplemented from TerminalInterface. */ 0060 QString currentWorkingDirectory() const override; 0061 0062 /** Reimplemented from TerminalInterfaceV2 */ 0063 QStringList availableProfiles() const override; 0064 0065 /** Reimplemented from TerminalInterfaceV2 */ 0066 QString currentProfileName() const override; 0067 0068 /** Reimplemented from TerminalInterfaceV2 */ 0069 bool setCurrentProfile(const QString &profileName) override; 0070 0071 /** Reimplemented from TerminalInterfaceV2 */ 0072 QVariant profileProperty(const QString &profileProperty) const override; 0073 0074 public Q_SLOTS: 0075 /** 0076 * creates and run a session using the specified profile and directory 0077 * 0078 * @param profileName Specifies the name of the profile to create session 0079 * @param directory specifies The initial working directory of the created session 0080 * 0081 * This is highly experimental. Do not use it at the moment 0082 */ 0083 void createSession(const QString &profileName = QString(), const QString &directory = QString()); 0084 0085 void showManageProfilesDialog(QWidget *parent); 0086 0087 /** 0088 * Shows the dialog used to edit the profile used by the active session. The 0089 * dialog will be non-modal and will delete itself when it is closed. 0090 * 0091 * This is experimental API and not guaranteed to be present in later KDE 4 0092 * releases. 0093 * 0094 * @param parent The parent widget of the new dialog. 0095 */ 0096 void showEditCurrentProfileDialog(QWidget *parent); 0097 /** 0098 * Sends a profile change command to the active session. This is equivalent to using 0099 * the konsoleprofile tool within the session to change its settings. The @p text string 0100 * is a semi-colon separated list of property=value pairs, eg. "colors=Linux Colors" 0101 * 0102 * See the documentation for konsoleprofile for information on the format of @p text 0103 * 0104 * This is experimental API and not guaranteed to be present in later KDE 4 releases. 0105 */ 0106 void changeSessionSettings(const QString &text); 0107 0108 /** 0109 * Connects to an existing pseudo-teletype. See Session::openTeletype(). 0110 * This must be called before the session is started by startProgram(), 0111 * or showShellInDir() 0112 * 0113 * @param ptyMasterFd The file descriptor of the pseudo-teletype (pty) master 0114 * @param runShell When true (default, legacy), runs the teletype in a shell 0115 * session environment. When false, the session is not run, so that the 0116 * KPtyProcess can be standalone, which may be useful for interactive programs. 0117 */ 0118 void openTeletype(int ptyMasterFd, bool runShell = true); 0119 0120 /** 0121 * Toggles monitoring for silence in the active session. If silence is detected, 0122 * the silenceDetected() signal is emitted. 0123 * 0124 * @param enabled Whether to enable or disable monitoring for silence. 0125 * */ 0126 void setMonitorSilenceEnabled(bool enabled); 0127 0128 /** 0129 * Toggles monitoring for activity in the active session. If activity is detected, 0130 * the activityDetected() signal is emitted. 0131 * 0132 * @param enabled Whether to enable or disable monitoring for activity. 0133 * */ 0134 void setMonitorActivityEnabled(bool enabled); 0135 0136 /** 0137 * Returns the status of the blur of the current profile. 0138 * 0139 * @return True if blur is enabled for the current active Konsole color profile. 0140 * */ 0141 bool isBlurEnabled(); 0142 0143 Q_SIGNALS: 0144 /** 0145 * Emitted when the key sequence for a shortcut, which is also a valid terminal key sequence, 0146 * is pressed while the terminal has focus. By responding to this signal, the 0147 * controlling application can choose whether to execute the action associated with 0148 * the shortcut or ignore the shortcut and send the key 0149 * sequence to the terminal application. 0150 * 0151 * In the embedded terminal, shortcuts are overridden and sent to the terminal by default. 0152 * Set @p override to false to prevent this happening and allow the shortcut to be triggered 0153 * normally. 0154 * 0155 * overrideShortcut() is not called for shortcuts which are not valid terminal key sequences, 0156 * eg. shortcuts with two or more modifiers. 0157 * 0158 * @param event Describes the keys that were pressed. 0159 * @param override Set this to false to prevent the terminal display from overriding the shortcut 0160 */ 0161 void overrideShortcut(QKeyEvent *event, bool &override); 0162 0163 /** 0164 * Emitted when silence has been detected in the active session. Monitoring 0165 * for silence has to be enabled first using setMonitorSilenceEnabled(). 0166 */ 0167 void silenceDetected(); 0168 0169 /** 0170 * Emitted when activity has been detected in the active session. Monitoring 0171 * for activity has to be enabled first using setMonitorActivityEnabled(). 0172 */ 0173 void activityDetected(); 0174 0175 /** 0176 * Emitted when the current working directory of the active session has changed. 0177 */ 0178 void currentDirectoryChanged(const QString &dir); 0179 0180 protected: 0181 /** Reimplemented from KParts::PartBase. */ 0182 bool openFile() override; 0183 bool openUrl(const QUrl &url) override; 0184 0185 private Q_SLOTS: 0186 void activeViewChanged(SessionController *controller); 0187 void activeViewTitleChanged(ViewProperties *properties); 0188 void terminalExited(); 0189 void newTab(); 0190 void overrideTerminalShortcut(QKeyEvent *, bool &override); 0191 void notificationChanged(Session::Notification notification, bool enabled); 0192 0193 private: 0194 Session *activeSession() const; 0195 0196 private: 0197 ViewManager *_viewManager; 0198 SessionController *_pluggedController; 0199 }; 0200 } 0201 0202 #endif // PART_H