File indexing completed on 2024-04-21 05:51:24

0001 /*
0002     SPDX-FileCopyrightText: 2006-2008 Robert Knight <robertknight@gmail.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #ifndef MAINWINDOW_H
0008 #define MAINWINDOW_H
0009 
0010 // Qt
0011 #include <QAction>
0012 #include <QExplicitlySharedDataPointer>
0013 #include <QPointer>
0014 #include <QUrl>
0015 
0016 // KDE
0017 #include <KXmlGuiWindow>
0018 
0019 // Konsole
0020 #include "widgets/ViewSplitter.h"
0021 
0022 #include "pluginsystem/IKonsolePlugin.h"
0023 
0024 #include "konsoleapp_export.h"
0025 
0026 #include <vector>
0027 
0028 class KActionMenu;
0029 class KHamburgerMenu;
0030 class KToggleAction;
0031 
0032 namespace Konsole
0033 {
0034 class ViewManager;
0035 class ViewProperties;
0036 class Session;
0037 class SessionController;
0038 class Profile;
0039 class ProfileList;
0040 class BookmarkHandler;
0041 
0042 /**
0043  * The main window.  This contains the menus and an area which contains the terminal displays.
0044  *
0045  * The main window does not create the views or the container widgets which hold the views.
0046  * This is done by the ViewManager class.  When a MainWindow is instantiated, it creates
0047  * a new ViewManager.  The ViewManager can then be used to create new terminal displays
0048  * inside the window.
0049  *
0050  * Do not construct new main windows directly, use Application's newMainWindow() method.
0051  */
0052 class KONSOLEAPP_EXPORT MainWindow : public KXmlGuiWindow
0053 {
0054     Q_OBJECT
0055 
0056 public:
0057     /**
0058      * Constructs a new main window.  Do not create new main windows directly, use Application's
0059      * newMainWindow() method instead.
0060      */
0061     MainWindow();
0062 
0063     /**
0064      * Returns the view manager associated with this window.  The view manager can be used to
0065      * create new views on particular session objects inside this window.
0066      */
0067     ViewManager *viewManager() const;
0068 
0069     /**
0070      * Create a new session.
0071      *
0072      * @param profile The profile to use to create the new session.
0073      * @param directory Initial working directory for the new session or empty
0074      * if the default working directory associated with the profile should be used.
0075      */
0076     Session *createSession(QExplicitlySharedDataPointer<Profile> profile, const QString &directory);
0077 
0078     /**
0079      * create a new SSH session.
0080      *
0081      * @param profile The profile to use to create the new session.
0082      * @param url the URL representing the new SSH connection
0083      */
0084     Session *createSSHSession(QExplicitlySharedDataPointer<Profile> profile, const QUrl &url);
0085 
0086     /**
0087      * Helper method to make this window get input focus
0088      */
0089     void setFocus();
0090 
0091     /**
0092      * Set the initial visibility of the menubar.
0093      */
0094     void setMenuBarInitialVisibility(bool showMenuBar);
0095 
0096     /**
0097      * @brief Set the frameless state
0098      *
0099      * @param frameless If true, no titlebar or frame is displayed.
0100      */
0101     void setRemoveWindowTitleBarAndFrame(bool frameless);
0102 
0103     /**
0104      * A reference to a plugin on the system.
0105      */
0106     void addPlugin(IKonsolePlugin *plugin);
0107 
0108     /**
0109      * creates a new tab for the main window
0110      */
0111     void newTab();
0112 
0113     /**
0114      * @brief set list actions for menu "Plugins"
0115      */
0116     void setPluginsActions(const QList<QAction *> &actions);
0117 
0118 Q_SIGNALS:
0119 
0120     /**
0121      * Emitted by the main window to request the creation of a
0122      * new session in a new window.
0123      *
0124      * @param profile The profile to use to create the
0125      * first session in the new window.
0126      * @param directory Initial working directory for the new window or empty
0127      * if the default working directory associated with the profile should
0128      * be used.
0129      */
0130     void newWindowRequest(const QExplicitlySharedDataPointer<Profile> &profile, const QString &directory);
0131 
0132     /**
0133      * Emitted when a view for one session is detached from this window
0134      */
0135     void terminalsDetached(ViewSplitter *splitter, QHash<TerminalDisplay *, Session *> sessionsMap);
0136 
0137 protected:
0138     // Reimplemented for internal reasons.
0139     void showEvent(QShowEvent *event) override;
0140     bool eventFilter(QObject *obj, QEvent *event) override;
0141 
0142     // reimplemented from KMainWindow
0143     bool queryClose() override;
0144     void saveProperties(KConfigGroup &group) override;
0145     void readProperties(const KConfigGroup &group) override;
0146     void saveGlobalProperties(KConfig *config) override;
0147     void readGlobalProperties(KConfig *config) override;
0148 
0149     // reimplemented from QWidget
0150     bool focusNextPrevChild(bool next) override;
0151 
0152 protected Q_SLOTS:
0153     void saveNewToolbarConfig() override;
0154 
0155 private Q_SLOTS:
0156     void cloneTab();
0157     void newWindow();
0158     void showManageProfilesDialog();
0159     void activateMenuBar();
0160     void showSettingsDialog(bool showProfilePage = false);
0161     void showShortcutsDialog();
0162     void newFromProfile(const QExplicitlySharedDataPointer<Profile> &profile);
0163     void activeViewChanged(SessionController *controller);
0164     void disconnectController(SessionController *controller);
0165     void activeViewTitleChanged(ViewProperties *);
0166 
0167     void profileListChanged(const QList<QAction *> &sessionActions);
0168     void configureNotifications();
0169     void setBlur(bool blur);
0170 
0171     void updateWindowIcon();
0172     void updateWindowCaption();
0173     void openUrls(const QList<QUrl> &urls);
0174 
0175     // Sets the list of profiles to be displayed under the "New Tab" action
0176     void setProfileList(ProfileList *list);
0177 
0178     void applyKonsoleSettings();
0179 
0180     // Ask the window manager to show this application window
0181     void activationRequest(const QString &xdgActivationToken);
0182 
0183     void updateUseTransparency();
0184 
0185 public Q_SLOTS:
0186     void viewFullScreen(bool fullScreen);
0187 
0188 private:
0189     void applyMainWindowSettings(const KConfigGroup &config) override;
0190 
0191     /**
0192      * Returns true if the window geometry was previously saved to the
0193      * config file, false otherwise.
0194      */
0195     bool wasWindowGeometrySaved() const;
0196 
0197     void correctStandardShortcuts();
0198     void rememberMenuAccelerators();
0199     void removeMenuAccelerators();
0200     void restoreMenuAccelerators();
0201     void setupActions();
0202     QString activeSessionDir() const;
0203     void triggerAction(const QString &name) const;
0204 
0205     /**
0206      * Returns the bookmark handler associated with this window.
0207      */
0208     BookmarkHandler *bookmarkHandler() const;
0209 
0210     // sets the active shortcuts of actions in 'dest' to the shortcuts of actions
0211     // with the same name in 'source' (see QAction::ActiveShortcut)
0212     static void syncActiveShortcuts(KActionCollection *dest, const KActionCollection *source);
0213     void updateHamburgerMenu();
0214 
0215 private:
0216     ViewManager *_viewManager;
0217     BookmarkHandler *_bookmarkHandler;
0218     KToggleAction *_toggleMenuBarAction;
0219     KActionMenu *_newTabMenuAction;
0220     KHamburgerMenu *_hamburgerMenu;
0221 
0222     QPointer<SessionController> _pluggedController;
0223     std::vector<IKonsolePlugin *> _plugins;
0224     QList<QAction *> _pluginsActions;
0225     bool _blurEnabled = false;
0226     bool _firstShowEvent = true;
0227 
0228     struct {
0229         bool enabled = false; // indicates that we got a command line argument for menubar
0230         bool showMenuBar = true;
0231     } _windowArgsMenuBarVisible;
0232 };
0233 }
0234 
0235 #endif // MAINWINDOW_H