1 /*
2     SPDX-FileCopyrightText: 2002 Frerich Raabe <raabe@kde.org>
3 
4     SPDX-License-Identifier: GPL-2.0-or-later
5 */
6 
7 #ifndef KHC_HISTORY_H
8 #define KHC_HISTORY_H
9 
10 #include <QUrl>
11 #include <QObject>
12 #include <QList>
13 
14 class KActionCollection;
15 class KXmlGuiWindow;
16 class KToolBarPopupAction;
17 class QMenu;
18 class QAction;
19 
20 namespace KHC {
21 
22 class View;
23 
24 class History : public QObject
25 {
26     Q_OBJECT
27   public:
28     friend class foo; // to make gcc shut up
29     struct Entry
30     {
EntryEntry31       Entry() {}
32 
33       View *view = nullptr;
34       QUrl url;
35       QString title;
36       QByteArray buffer;
37       bool search = false;
38     };
39 
40     static History &self();
41 
42     void setupActions( KActionCollection *coll );
43     void updateActions();
44 
45     void installMenuBarHook( KXmlGuiWindow *mainWindow );
46 
47     void createEntry();
48     void updateCurrentEntry( KHC::View *view );
49 
50   Q_SIGNALS:
51     void goInternalUrl( const QUrl & );
52     void goUrl( const QUrl & );
53 
54   private Q_SLOTS:
55     void backActivated( QAction *action );
56     void fillBackMenu();
57     void forwardActivated( QAction *action );
58     void fillForwardMenu();
59     void goMenuActivated( QAction* action );
60     void fillGoMenu();
61     void back();
62     void forward();
63     void goHistoryActivated( int steps );
64     void goHistory( int steps );
65     void goHistoryDelayed();
66 
67   private:
68     History();
69     History( const History &rhs );
70     History &operator=( const History &rhs );
71     ~History();
72 
73     typedef QList<Entry*> EntryList;
74 
75     bool canGoBack() const;
76     bool canGoForward() const;
77     void fillHistoryPopup( QMenu *, bool, bool, bool, uint = 0 );
78 
79     /**
80      *  dumps the history with a kDebug and mark wihch one is the current one
81      *  This is a debugging function.
82      */
83     void dumpHistory() const;
84 
85     static History *m_instance;
86 
87     EntryList m_entries;
88     EntryList::Iterator m_entries_current;
89 
90 
91     int m_goBuffer;
92     int m_goMenuIndex;
93     int m_goMenuHistoryStartPos;
94     int m_goMenuHistoryCurrentPos;
95   public:
96     KToolBarPopupAction *m_backAction = nullptr;
97     KToolBarPopupAction *m_forwardAction = nullptr;
98 };
99 
100 }
101 
102 #endif // KHC_HISTORY_H
103 // vim:ts=2:sw=2:et
104