]> cloud.milkyroute.net Git - dolphin.git/blob - src/panels/terminal/terminalpanel.h
Merge branch 'release/21.12'
[dolphin.git] / src / panels / terminal / terminalpanel.h
1 /*
2 * SPDX-FileCopyrightText: 2007-2010 Peter Penz <peter.penz19@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
7 #ifndef TERMINALPANEL_H
8 #define TERMINALPANEL_H
9
10 #include "kiofuse_interface.h"
11 #include "panels/panel.h"
12
13 #include <QQueue>
14
15 class TerminalInterface;
16 class KActionCollection;
17 class KMessageWidget;
18 class QVBoxLayout;
19 class QWidget;
20
21 namespace KIO {
22 class StatJob;
23 }
24
25 namespace KParts {
26 class ReadOnlyPart;
27 }
28 class KJob;
29 /**
30 * @brief Shows the terminal which is synchronized with the URL of the
31 * active view.
32 */
33 class TerminalPanel : public Panel
34 {
35 Q_OBJECT
36
37 public:
38 explicit TerminalPanel(QWidget* parent = nullptr);
39 ~TerminalPanel() override;
40
41 /**
42 * @brief This function is used to set the terminal panels's cwd to
43 * home when an unmounting request is received.
44 */
45 void goHome();
46 QString currentWorkingDirectory();
47 bool isHiddenInVisibleWindow() const;
48 bool terminalHasFocus() const;
49 bool hasProgramRunning() const;
50 QString runningProgramName() const;
51 KActionCollection *actionCollection();
52
53 public Q_SLOTS:
54 void terminalExited();
55 void dockVisibilityChanged();
56
57 Q_SIGNALS:
58 void hideTerminalPanel();
59
60 /**
61 * Is emitted if the an URL change is requested.
62 */
63 void changeUrl(const QUrl& url);
64
65 protected:
66 bool urlChanged() override;
67
68 void showEvent(QShowEvent* event) override;
69
70 private Q_SLOTS:
71 void slotMostLocalUrlResult(KJob* job);
72 void slotKonsolePartCurrentDirectoryChanged(const QString& dir);
73
74 private:
75 enum class HistoryPolicy {
76 AddToHistory,
77 SkipHistory
78 };
79
80 void changeDir(const QUrl& url);
81 void sendCdToTerminal(const QString& path, HistoryPolicy addToHistory = HistoryPolicy::AddToHistory);
82 void sendCdToTerminalKIOFuse(const QUrl &url);
83 private:
84 bool m_clearTerminal;
85 KIO::StatJob* m_mostLocalUrlJob;
86
87 QVBoxLayout* m_layout;
88 TerminalInterface* m_terminal;
89 QWidget* m_terminalWidget;
90 KMessageWidget* m_konsolePartMissingMessage;
91 KParts::ReadOnlyPart* m_konsolePart;
92 QString m_konsolePartCurrentDirectory;
93 QQueue<QString> m_sendCdToTerminalHistory;
94 org::kde::KIOFuse::VFS m_kiofuseInterface;
95 };
96
97 #endif // TERMINALPANEL_H