MainWindow.h 6.3 KB
Newer Older
1
/*
2
    Copyright 2006-2008 by Robert Knight <robertknight@gmail.com>
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301  USA.
*/

20 21
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
22

23
// Qt
24 25
#include <QPointer>
#include <QUrl>
26
#include <QExplicitlySharedDataPointer>
27 28

// KDE
29
#include <KXmlGuiWindow>
30

Jekyll Wu's avatar
Jekyll Wu committed
31
// Konsole
32
#include "widgets/ViewSplitter.h"
33

Laurent Montel's avatar
Laurent Montel committed
34
class QAction;
35
class KActionMenu;
36
class KToggleAction;
37

Kurt Hindenburg's avatar
Kurt Hindenburg committed
38
namespace Konsole {
39
class ViewManager;
40
class ViewProperties;
41
class Session;
42
class SessionController;
43
class Profile;
44
class ProfileList;
45
class BookmarkHandler;
46

47 48 49 50
/**
 * The main window.  This contains the menus and an area which contains the terminal displays.
 *
 * The main window does not create the views or the container widgets which hold the views.
51
 * This is done by the ViewManager class.  When a MainWindow is instantiated, it creates
52 53 54
 * a new ViewManager.  The ViewManager can then be used to create new terminal displays
 * inside the window.
 *
55
 * Do not construct new main windows directly, use Application's newMainWindow() method.
56
 */
57
class MainWindow : public KXmlGuiWindow
58
{
59 60
    Q_OBJECT

Kurt Hindenburg's avatar
Kurt Hindenburg committed
61 62 63 64 65 66 67 68 69 70 71
public:
    /**
     * Constructs a new main window.  Do not create new main windows directly, use Application's
     * newMainWindow() method instead.
     */
    MainWindow();

    /**
     * Returns the view manager associated with this window.  The view manager can be used to
     * create new views on particular session objects inside this window.
     */
Kurt Hindenburg's avatar
Kurt Hindenburg committed
72
    ViewManager *viewManager() const;
Kurt Hindenburg's avatar
Kurt Hindenburg committed
73 74

    /**
75
     * Create a new session.
Kurt Hindenburg's avatar
Kurt Hindenburg committed
76 77 78 79 80
     *
     * @param profile The profile to use to create the new session.
     * @param directory Initial working directory for the new session or empty
     * if the default working directory associated with the profile should be used.
     */
81
    Session *createSession(QExplicitlySharedDataPointer<Profile> profile, const QString &directory);
Kurt Hindenburg's avatar
Kurt Hindenburg committed
82 83

    /**
84
     * create a new SSH session.
Kurt Hindenburg's avatar
Kurt Hindenburg committed
85 86
     *
     * @param profile The profile to use to create the new session.
87
     * @param url the URL representing the new SSH connection
Kurt Hindenburg's avatar
Kurt Hindenburg committed
88
     */
89
    Session *createSSHSession(QExplicitlySharedDataPointer<Profile> profile , const QUrl &url);
90

91 92 93 94 95
    /**
     * Helper method to make this window get input focus
     */
    void setFocus();

96 97 98 99 100
    /**
     * Set the initial visibility of the menubar.
     */
    void setMenuBarInitialVisibility(bool visible);

101 102

    /**
103
     * @brief Set the frameless state
104
     *
Kurt Hindenburg's avatar
Kurt Hindenburg committed
105
     * @param frameless If true, no titlebar or frame is displayed.
106 107 108
     */
    void setRemoveWindowTitleBarAndFrame(bool frameless);

109
Q_SIGNALS:
Kurt Hindenburg's avatar
Kurt Hindenburg committed
110 111 112 113 114 115 116 117 118 119 120

    /**
     * Emitted by the main window to request the creation of a
     * new session in a new window.
     *
     * @param profile The profile to use to create the
     * first session in the new window.
     * @param directory Initial working directory for the new window or empty
     * if the default working directory associated with the profile should
     * be used.
     */
121
    void newWindowRequest(const QExplicitlySharedDataPointer<Profile> &profile, const QString &directory);
Kurt Hindenburg's avatar
Kurt Hindenburg committed
122

123 124 125
    /**
     * Emitted when a view for one session is detached from this window
     */
Tomaz  Canabrava's avatar
Tomaz Canabrava committed
126
    void terminalsDetached(ViewSplitter *splitter, QHash<TerminalDisplay*, Session*> sessionsMap);
127

Kurt Hindenburg's avatar
Kurt Hindenburg committed
128 129
protected:
    // Reimplemented for internal reasons.
130 131
    void showEvent(QShowEvent *event) override;
    bool eventFilter(QObject *obj, QEvent *event) override;
Kurt Hindenburg's avatar
Kurt Hindenburg committed
132 133

    // reimplemented from KMainWindow
134 135 136 137 138
    bool queryClose() override;
    void saveProperties(KConfigGroup &group) override;
    void readProperties(const KConfigGroup &group) override;
    void saveGlobalProperties(KConfig *config) override;
    void readGlobalProperties(KConfig *config) override;
Kurt Hindenburg's avatar
Kurt Hindenburg committed
139 140

    // reimplemented from QWidget
141
    bool focusNextPrevChild(bool next) override;
Kurt Hindenburg's avatar
Kurt Hindenburg committed
142

143
private Q_SLOTS:
Tomaz  Canabrava's avatar
Tomaz Canabrava committed
144
    void newTab();
145
    void cloneTab();
Kurt Hindenburg's avatar
Kurt Hindenburg committed
146 147 148
    void newWindow();
    void showManageProfilesDialog();
    void activateMenuBar();
149
    void showSettingsDialog(bool showProfilePage = false);
Kurt Hindenburg's avatar
Kurt Hindenburg committed
150
    void showShortcutsDialog();
151
    void newFromProfile(const QExplicitlySharedDataPointer<Profile> &profile);
Kurt Hindenburg's avatar
Kurt Hindenburg committed
152 153 154
    void activeViewChanged(SessionController *controller);
    void disconnectController(SessionController *controller);
    void activeViewTitleChanged(ViewProperties *);
Kurt Hindenburg's avatar
Kurt Hindenburg committed
155

156
    void profileListChanged(const QList<QAction *> &sessionActions);
Kurt Hindenburg's avatar
Kurt Hindenburg committed
157
    void configureNotifications();
158
    void setBlur(bool blur);
Kurt Hindenburg's avatar
Kurt Hindenburg committed
159 160

    void updateWindowIcon();
161
    void updateWindowCaption();
Kurt Hindenburg's avatar
Kurt Hindenburg committed
162
    void openUrls(const QList<QUrl> &urls);
Kurt Hindenburg's avatar
Kurt Hindenburg committed
163

164
    // Sets the list of profiles to be displayed under the "New Tab" action
Kurt Hindenburg's avatar
Kurt Hindenburg committed
165
    void setProfileList(ProfileList *list);
166

Jekyll Wu's avatar
Jekyll Wu committed
167
    void applyKonsoleSettings();
168

Eike Hein's avatar
Eike Hein committed
169 170
    void updateUseTransparency();

171
public Q_SLOTS:
172 173
    void viewFullScreen(bool fullScreen);

Kurt Hindenburg's avatar
Kurt Hindenburg committed
174
private:
Jekyll Wu's avatar
Jekyll Wu committed
175
    void correctStandardShortcuts();
176
    void rememberMenuAccelerators();
Kurt Hindenburg's avatar
Kurt Hindenburg committed
177
    void removeMenuAccelerators();
Jekyll Wu's avatar
Jekyll Wu committed
178
    void restoreMenuAccelerators();
Kurt Hindenburg's avatar
Kurt Hindenburg committed
179 180
    void setupActions();
    QString activeSessionDir() const;
181
    void triggerAction(const QString &name) const;
Kurt Hindenburg's avatar
Kurt Hindenburg committed
182

183 184 185
    /**
     * Returns the bookmark handler associated with this window.
     */
Kurt Hindenburg's avatar
Kurt Hindenburg committed
186
    BookmarkHandler *bookmarkHandler() const;
187

Kurt Hindenburg's avatar
Kurt Hindenburg committed
188
    // sets the active shortcuts of actions in 'dest' to the shortcuts of actions
Laurent Montel's avatar
Laurent Montel committed
189
    // with the same name in 'source' (see QAction::ActiveShortcut)
Kurt Hindenburg's avatar
Kurt Hindenburg committed
190
    static void syncActiveShortcuts(KActionCollection *dest, const KActionCollection *source);
Kurt Hindenburg's avatar
Kurt Hindenburg committed
191 192

private:
Kurt Hindenburg's avatar
Kurt Hindenburg committed
193 194 195 196
    ViewManager *_viewManager;
    BookmarkHandler *_bookmarkHandler;
    KToggleAction *_toggleMenuBarAction;
    KActionMenu *_newTabMenuAction;
Kurt Hindenburg's avatar
Kurt Hindenburg committed
197 198 199

    QPointer<SessionController> _pluggedController;

200
    bool _menuBarInitialVisibility;
Kurt Hindenburg's avatar
Kurt Hindenburg committed
201
    bool _menuBarInitialVisibilityApplied;
202
    bool _blurEnabled = false;
203
};
Stephan Binner's avatar
Stephan Binner committed
204
}
205

206
#endif // MAINWINDOW_H