File indexing completed on 2024-05-05 05:57:01

0001 /*
0002   SPDX-FileCopyrightText: 2008-2014 Eike Hein <hein@kde.org>
0003 
0004   SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0005 */
0006 
0007 #ifndef TERMINAL_H
0008 #define TERMINAL_H
0009 
0010 #include <KParts/Part>
0011 
0012 #include <QPointer>
0013 
0014 class QKeyEvent;
0015 
0016 // Requires V2 to access profileProperty().
0017 class TerminalInterface;
0018 
0019 class Terminal : public QObject
0020 {
0021     Q_OBJECT
0022 
0023 public:
0024     explicit Terminal(const QString &workingDir, QWidget *parent = nullptr);
0025     ~Terminal();
0026 
0027     bool eventFilter(QObject *watched, QEvent *event) override;
0028 
0029     int id()
0030     {
0031         return m_terminalId;
0032     }
0033     const QString title()
0034     {
0035         return m_title;
0036     }
0037 
0038     QWidget *partWidget()
0039     {
0040         return m_partWidget;
0041     }
0042     QWidget *terminalWidget()
0043     {
0044         return m_terminalWidget;
0045     }
0046 
0047     QWidget *splitter()
0048     {
0049         return m_parentSplitter;
0050     }
0051     void setSplitter(QWidget *splitter)
0052     {
0053         m_parentSplitter = splitter;
0054     }
0055 
0056     void runCommand(const QString &command);
0057 
0058     void manageProfiles();
0059     void editProfile();
0060 
0061     bool keyboardInputEnabled()
0062     {
0063         return m_keyboardInputEnabled;
0064     }
0065     void setKeyboardInputEnabled(bool enabled)
0066     {
0067         m_keyboardInputEnabled = enabled;
0068     }
0069 
0070     bool monitorActivityEnabled()
0071     {
0072         return m_monitorActivityEnabled;
0073     }
0074     void setMonitorActivityEnabled(bool enabled);
0075 
0076     bool monitorSilenceEnabled()
0077     {
0078         return m_monitorSilenceEnabled;
0079     }
0080     void setMonitorSilenceEnabled(bool enabled);
0081 
0082     QString currentWorkingDirectory() const;
0083 
0084     void deletePart();
0085 
0086     KActionCollection *actionCollection();
0087 
0088     bool wantsBlur() const
0089     {
0090         return m_wantsBlur;
0091     }
0092 
0093 Q_SIGNALS:
0094     void titleChanged(int terminalId, const QString &title);
0095     void activated(int terminalId);
0096     void manuallyActivated(Terminal *terminal);
0097     void keyboardInputBlocked(Terminal *terminal);
0098     void activityDetected(Terminal *terminal);
0099     void silenceDetected(Terminal *terminal);
0100     void destroyed(int terminalId);
0101     void closeRequested(int terminalId);
0102 
0103 private Q_SLOTS:
0104     void setTitle(const QString &title);
0105     void overrideShortcut(QKeyEvent *event, bool &override);
0106     void silenceDetected();
0107     void activityDetected();
0108 
0109 private:
0110     void disableOffendingPartActions();
0111 
0112     void displayKPartLoadError();
0113 
0114     static int m_availableTerminalId;
0115     int m_terminalId;
0116 
0117     KParts::Part *m_part = nullptr;
0118     TerminalInterface *m_terminalInterface = nullptr;
0119     QWidget *m_partWidget = nullptr;
0120     QPointer<QWidget> m_terminalWidget = nullptr;
0121     QWidget *m_parentSplitter;
0122 
0123     QString m_title;
0124 
0125     bool m_keyboardInputEnabled = true;
0126 
0127     bool m_monitorActivityEnabled = false;
0128     bool m_monitorSilenceEnabled = false;
0129     bool m_wantsBlur = false;
0130 
0131     bool m_destroying = false;
0132 };
0133 
0134 #endif