File indexing completed on 2024-04-28 17:06:05

0001 /*
0002     SPDX-FileCopyrightText: 2008 Václav Juza <vaclavjuza@gmail.com>
0003     SPDX-FileCopyrightText: 2008-2022 Krusader Krew <https://krusader.org>
0004 
0005     SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 
0008 #ifndef TERMINALDOCK_H
0009 #define TERMINALDOCK_H
0010 
0011 // QtCore
0012 #include <QEvent>
0013 #include <QObject>
0014 #include <QString>
0015 // QtWidgets
0016 #include <QHBoxLayout>
0017 #include <QWidget>
0018 
0019 #include <KParts/ReadOnlyPart>
0020 #include <kde_terminal_interface.h>
0021 
0022 class KrMainWindow;
0023 
0024 /**
0025  * This is a class to make the work with the embedded terminal emulator easier.
0026  * It takes care of loading the library and initialising when necessary.
0027  * A big advantage is that the code which uses this class does not need to
0028  * check if the part was loaded successfully.
0029  *
0030  */
0031 class TerminalDock : public QWidget
0032 {
0033     Q_OBJECT
0034 public:
0035     TerminalDock(QWidget *parent, KrMainWindow *mainWindow);
0036     ~TerminalDock() override;
0037     void sendInput(const QString &input, bool clearCommand = true);
0038     void sendCd(const QString &path);
0039     bool eventFilter(QObject *watched, QEvent *e) override;
0040     bool isTerminalVisible() const;
0041     bool isInitialised() const;
0042     bool initialise();
0043     void hideEvent(QHideEvent *e) override;
0044     void showEvent(QShowEvent *e) override;
0045     void onTerminalFocusChanged(bool focused);
0046     inline KParts::Part *part()
0047     {
0048         return konsole_part;
0049     }
0050 
0051 private slots:
0052     void killTerminalEmulator();
0053     void currentDirChanged(const QString &terminalPath);
0054 
0055 private:
0056     KrMainWindow *_mainWindow;
0057     QString lastPath; // path of the last sendCd
0058     QHBoxLayout *terminal_hbox; // hbox for terminal_dock
0059     KParts::ReadOnlyPart *konsole_part; // the actual part pointer
0060     TerminalInterface *t; // TerminalInterface of the konsole part
0061     bool initialised;
0062     bool firstInput;
0063     bool applyShortcuts(QKeyEvent *ke);
0064 };
0065 
0066 #endif /* TERMINALDOCK_H */