File indexing completed on 2024-04-28 05:45:13

0001 /*
0002  * SPDX-FileCopyrightText: 2007-2010 Peter Penz <peter.penz19@gmail.com>
0003  *
0004  * SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 
0007 #ifndef TERMINALPANEL_H
0008 #define TERMINALPANEL_H
0009 
0010 #include "kiofuse_interface.h"
0011 #include "panels/panel.h"
0012 
0013 #include <QQueue>
0014 
0015 class TerminalInterface;
0016 class KActionCollection;
0017 class KMessageWidget;
0018 class QVBoxLayout;
0019 class QWidget;
0020 
0021 namespace KIO
0022 {
0023 class StatJob;
0024 }
0025 
0026 namespace KParts
0027 {
0028 class ReadOnlyPart;
0029 }
0030 class KJob;
0031 /**
0032  * @brief Shows the terminal which is synchronized with the URL of the
0033  *        active view.
0034  */
0035 class TerminalPanel : public Panel
0036 {
0037     Q_OBJECT
0038 
0039 public:
0040     explicit TerminalPanel(QWidget *parent = nullptr);
0041     ~TerminalPanel() override;
0042 
0043     /**
0044      * @brief This function is used to set the terminal panels's cwd to
0045      *        home when an unmounting request is received.
0046      */
0047     void goHome();
0048     bool currentWorkingDirectoryIsChildOf(const QString &path) const;
0049     bool isHiddenInVisibleWindow() const;
0050     bool terminalHasFocus() const;
0051     bool hasProgramRunning() const;
0052     QString runningProgramName() const;
0053     KActionCollection *actionCollection();
0054 
0055 public Q_SLOTS:
0056     void terminalExited();
0057     void dockVisibilityChanged();
0058 
0059 Q_SIGNALS:
0060     void hideTerminalPanel();
0061 
0062     /**
0063      * Is emitted if the an URL change is requested.
0064      */
0065     void changeUrl(const QUrl &url);
0066 
0067 protected:
0068     bool urlChanged() override;
0069 
0070     void showEvent(QShowEvent *event) override;
0071 
0072 private Q_SLOTS:
0073     void slotMostLocalUrlResult(KJob *job);
0074     void slotKonsolePartCurrentDirectoryChanged(const QString &dir);
0075 
0076 private:
0077     enum class HistoryPolicy { AddToHistory, SkipHistory };
0078 
0079     void changeDir(const QUrl &url);
0080     void sendCdToTerminal(const QString &path, HistoryPolicy addToHistory = HistoryPolicy::AddToHistory);
0081     void sendCdToTerminalKIOFuse(const QUrl &url);
0082 
0083 private:
0084     bool m_clearTerminal;
0085     KIO::StatJob *m_mostLocalUrlJob;
0086 
0087     QVBoxLayout *m_layout;
0088     TerminalInterface *m_terminal;
0089     QWidget *m_terminalWidget;
0090     KMessageWidget *m_konsolePartMissingMessage;
0091     KParts::ReadOnlyPart *m_konsolePart;
0092     QString m_konsolePartCurrentDirectory;
0093     QQueue<QString> m_sendCdToTerminalHistory;
0094     org::kde::KIOFuse::VFS m_kiofuseInterface;
0095 };
0096 
0097 #endif // TERMINALPANEL_H