MainWindow.h 6.01 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
22
#ifndef KONSOLEMAINWINDOW_H
#define KONSOLEMAINWINDOW_H

23
// Qt
Dirk Mueller's avatar
Dirk Mueller committed
24
#include <QtCore/QPointer>
25
26

// KDE
27
#include <KXmlGuiWindow>
28
#include <KUrl>
29

Jekyll Wu's avatar
Jekyll Wu committed
30
// Konsole
31
32
#include "Profile.h"

33
34
class KAction;
class KActionMenu;
35
class KToggleAction;
36

37
38
39
namespace Konsole
{

40
class IncrementalSearchBar;
41
class ViewManager;
42
43
class ViewProperties;
class SessionController;
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
72
73
74
75
76
77
78
79
80
81
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.
     */
    ViewManager* viewManager() const;

    /**
     * Returns the search bar.
     *
     * This is a convenience method. The search bar is actually owned by
     * ViewManager, or more precisely, by ViewContainer.
     */
    IncrementalSearchBar* searchBar() const;

Jekyll Wu's avatar
Jekyll Wu committed
82
83
    /** Sets the list of profiles to be displayed in the File menu */
    void setProfileList(ProfileList* list);
Kurt Hindenburg's avatar
Kurt Hindenburg committed
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150

    /**
     * Returns the bookmark handler associated with this window.
     */
    BookmarkHandler* bookmarkHandler() const;

signals:
    /**
     * Emitted by the main window to request the creation of a new session.
     *
     * @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.
     * @param view The view manager owned by this main window
     */
    void newSessionRequest(Profile::Ptr profile,
                           const QString& directory,
                           ViewManager* view);

    /**
     * Emitted by the main window to request the creation of a new SSH session.
     *
     * @param profile The profile to use to create the new session.
     * @param url URL for the new session
     * @param view The view manager owned by this main window
     */
    void newSSHSessionRequest(Profile::Ptr profile,
                              const KUrl& url,
                              ViewManager* view);

    /**
     * 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.
     */
    void newWindowRequest(Profile::Ptr profile,
                          const QString& directory);

    /**
     * Emitted by the main window to request the current session to close.
     */
    void closeActiveSessionRequest();

protected:
    // Reimplemented for internal reasons.
    virtual void showEvent(QShowEvent* event);

    // reimplemented from KMainWindow
    virtual bool queryClose();
    virtual void saveProperties(KConfigGroup& group);
    virtual void readProperties(const KConfigGroup& group);
    virtual void saveGlobalProperties(KConfig* config);
    virtual void readGlobalProperties(KConfig* config);

    // reimplemented from QWidget
    virtual bool focusNextPrevChild(bool next);

private slots:
    void newTab();
    void newWindow();
    void showManageProfilesDialog();
    void activateMenuBar();
Jekyll Wu's avatar
Jekyll Wu committed
151
        void showSettingsDialog();
Kurt Hindenburg's avatar
Kurt Hindenburg committed
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
    void showShortcutsDialog();
    void newFromProfile(Profile::Ptr profile);
    void activeViewChanged(SessionController* controller);
    void disconnectController(SessionController* controller);
    void activeViewTitleChanged(ViewProperties*);

    void sessionListChanged(const QList<QAction*>& actions);
    void viewFullScreen(bool fullScreen);
    void configureNotifications();

    void setSaveGeometryOnExit(bool visible);

    void updateWindowIcon();

    void openUrls(const QList<KUrl>& urls);

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

Kurt Hindenburg's avatar
Kurt Hindenburg committed
170
171
private:
    void correctShortcuts();
172
    void rememberMenuAccelerators();
Kurt Hindenburg's avatar
Kurt Hindenburg committed
173
    void removeMenuAccelerators();
174
    void recoverMenuAccelerators();
Kurt Hindenburg's avatar
Kurt Hindenburg committed
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
    void setupActions();
    void setupWidgets();
    QString activeSessionDir() const;

    // sets the active shortcuts of actions in 'dest' to the shortcuts of actions
    // with the same name in 'source' (see KAction::ActiveShortcut)
    static void syncActiveShortcuts(KActionCollection* dest, const KActionCollection* source);

private:
    ViewManager*  _viewManager;
    BookmarkHandler* _bookmarkHandler;
    KToggleAction* _toggleMenuBarAction;
    KActionMenu* _newTabMenuAction;

    QPointer<SessionController> _pluggedController;

    bool _menuBarInitialVisibilityApplied;
192
};
193

Stephan Binner's avatar
Stephan Binner committed
194
}
195

196
#endif // KONSOLEMAINWINDOW_H