BookmarkHandler.h 3.87 KB
Newer Older
1
/* This file was part of the KDE libraries
2

3
4
    Copyright 2002 Carsten Pfeiffer <pfeiffer@kde.org>
    Copyright 2007-2008 Robert Knight <robertknight@gmail.com>
Stephan Binner's avatar
Stephan Binner committed
5
6
7

    library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
Jekyll Wu's avatar
Jekyll Wu committed
8
    License as published by the Free Software Foundation, version 2
9
    or (at your option) any later version.
Stephan Binner's avatar
Stephan Binner committed
10
11
12
13
14
15
16
17

    This library 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
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to
Dirk Mueller's avatar
Dirk Mueller committed
18
    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Dirk Mueller's avatar
Dirk Mueller committed
19
    Boston, MA 02110-1301, USA.
Stephan Binner's avatar
Stephan Binner committed
20
21
*/

22
23
// Born as kdelibs/kio/kfile/kfilebookmarkhandler.h

24
25
#ifndef BOOKMARKHANDLER_H
#define BOOKMARKHANDLER_H
26

27
// KDE
28
#include <KBookmarkManager>
Kurt Hindenburg's avatar
Kurt Hindenburg committed
29

30
#include <QUrl>
31

32
// Konsole
Laurent Montel's avatar
Laurent Montel committed
33
#include "konsoleprivate_export.h"
34

Alex Richardson's avatar
Alex Richardson committed
35
class QMenu;
36
class KActionCollection;
37

Kurt Hindenburg's avatar
Kurt Hindenburg committed
38
namespace Konsole {
39
class ViewProperties;
40

41
42
43
44
45
/**
 * This class handles the communication between the bookmark menu and the active session,
 * providing a suggested title and URL when the user clicks the "Add Bookmark" item in
 * the bookmarks menu.
 *
Jekyll Wu's avatar
Jekyll Wu committed
46
 * The bookmark handler is associated with a session controller, which is used to
47
48
49
50
51
 * determine the working URL of the current session.  When the user changes the active
 * view, the bookmark handler's controller should be changed using setController()
 *
 * When the user selects a bookmark, the openUrl() signal is emitted.
 */
52
class KONSOLEPRIVATE_EXPORT BookmarkHandler : public QObject, public KBookmarkOwner
53
54
55
56
{
    Q_OBJECT

public:
57
58
59
    /**
     * Constructs a new bookmark handler for Konsole bookmarks.
     *
Jekyll Wu's avatar
Jekyll Wu committed
60
     * @param collection The collection which the bookmark menu's actions should be added to
61
62
     * @param menu The menu which the bookmark actions should be added to
     * @param toplevel TODO: Document me
63
     * @param parent The parent object
64
     */
Kurt Hindenburg's avatar
Kurt Hindenburg committed
65
    BookmarkHandler(KActionCollection *collection, QMenu *menu, bool toplevel, QObject *parent);
66
    ~BookmarkHandler() Q_DECL_OVERRIDE;
67

68
69
70
71
    QUrl currentUrl() const Q_DECL_OVERRIDE;
    QString currentTitle() const Q_DECL_OVERRIDE;
    QString currentIcon() const Q_DECL_OVERRIDE;
    bool enableOption(BookmarkOption option) const Q_DECL_OVERRIDE;
Kurt Hindenburg's avatar
Kurt Hindenburg committed
72
    void openFolderinTabs(const KBookmarkGroup &group) Q_DECL_OVERRIDE;
73

Jekyll Wu's avatar
Jekyll Wu committed
74
    /**
75
76
     * Returns the menu which this bookmark handler inserts its actions into.
     */
Kurt Hindenburg's avatar
Kurt Hindenburg committed
77
78
    QMenu *menu() const
    {
Kurt Hindenburg's avatar
Kurt Hindenburg committed
79
80
        return _menu;
    }
81

Kurt Hindenburg's avatar
Kurt Hindenburg committed
82
83
    QList<ViewProperties *> views() const;
    ViewProperties *activeView() const;
84

85
public Q_SLOTS:
86
    /**
87
     *
88
     */
Kurt Hindenburg's avatar
Kurt Hindenburg committed
89
    void setViews(const QList<ViewProperties *> &views);
90

Kurt Hindenburg's avatar
Kurt Hindenburg committed
91
    void setActiveView(ViewProperties *view);
92

93
Q_SIGNALS:
94
95
96
97
98
    /**
     * Emitted when the user selects a bookmark from the bookmark menu.
     *
     * @param url The url of the bookmark which was selected by the user.
     */
Kurt Hindenburg's avatar
Kurt Hindenburg committed
99
    void openUrl(const QUrl &url);
100

101
    /**
Jekyll Wu's avatar
Jekyll Wu committed
102
     * Emitted when the user selects 'Open Folder in Tabs'
103
104
     * from the bookmark menu.
     *
Jekyll Wu's avatar
Jekyll Wu committed
105
     * @param urls The urls of the bookmarks in the folder whose
106
107
     * 'Open Folder in Tabs' action was triggered
     */
Kurt Hindenburg's avatar
Kurt Hindenburg committed
108
    void openUrls(const QList<QUrl> &urls);
109

110
private Q_SLOTS:
Kurt Hindenburg's avatar
Kurt Hindenburg committed
111
    void openBookmark(const KBookmark &bm, Qt::MouseButtons, Qt::KeyboardModifiers) Q_DECL_OVERRIDE;
112
113

private:
114
115
    Q_DISABLE_COPY(BookmarkHandler)

Kurt Hindenburg's avatar
Kurt Hindenburg committed
116
117
118
    QString titleForView(ViewProperties *view) const;
    QUrl urlForView(ViewProperties *view) const;
    QString iconForView(ViewProperties *view) const;
119

Kurt Hindenburg's avatar
Kurt Hindenburg committed
120
    QMenu *_menu;
121
122
    QString _file;
    bool _toplevel;
Kurt Hindenburg's avatar
Kurt Hindenburg committed
123
124
    ViewProperties *_activeView;
    QList<ViewProperties *> _views;
125
};
Stephan Binner's avatar
Stephan Binner committed
126
}
127

128
#endif // BOOKMARKHANDLER_H