File indexing completed on 2024-04-14 04:53:06

0001 /* This file is part of the KDE project
0002     SPDX-FileCopyrightText: 1998, 1999 Torben Weis <weis@kde.org>
0003     SPDX-FileCopyrightText: 2006 Daniel Teske <teske@squorn.de>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007 
0008 #ifndef __konqbookmarkmenu_h__
0009 #define __konqbookmarkmenu_h__
0010 
0011 #include "kbookmarkmenu.h"
0012 #include "kbookmarkactionmenu.h"
0013 #include "kbookmarkcontextmenu.h"
0014 
0015 #include <KActionCollection>
0016 #include <kbookmarks_version.h>
0017 
0018 namespace Konqueror { // to avoid clashing with KF5::Bookmarks which had a KonqBookmarkMenu class. Remove once using KF6.
0019 
0020 class KonqBookmarkMenu : public KBookmarkMenu
0021 {
0022     //friend class KBookmarkBar;
0023     Q_OBJECT
0024 public:
0025     /**
0026      * Fills a bookmark menu with konquerors bookmarks
0027      * (one instance of KonqBookmarkMenu is created for the toplevel menu,
0028      *  but also one per submenu).
0029      *
0030      * @param mgr The bookmark manager to use (i.e. for reading and writing)
0031      * @param owner implementation of the KBookmarkOwner callback interface.
0032      * Note: If you pass a null KBookmarkOwner to the constructor, the
0033      * URLs are openend by QDesktopServices::openUrl and "Add Bookmark" is disabled.
0034      * @param parentMenu menu to be filled
0035      * @param collec parent collection for the KActions.
0036      */
0037     KonqBookmarkMenu(KBookmarkManager *mgr, KBookmarkOwner *owner, KBookmarkActionMenu *parentMenu, KActionCollection *collec)
0038         : KBookmarkMenu(mgr, owner, parentMenu->menu())
0039     {
0040         m_actionCollection = collec;
0041 #if QT_VERSION_MAJOR >= 6
0042         setBrowserMode(true);
0043 #endif
0044     }
0045     ~KonqBookmarkMenu() override
0046     {}
0047 
0048     /**
0049      * Creates a bookmark submenu.
0050      * Only used internally and for bookmark toolbar.
0051      */
0052     KonqBookmarkMenu(KBookmarkManager *mgr, KBookmarkOwner *owner, KBookmarkActionMenu *parentMenu, QString parentAddress, KActionCollection *collec)
0053 #if QT_VERSION_MAJOR < 6
0054         : KBookmarkMenu(mgr, owner, parentMenu->menu(), parentAddress)
0055 #else
0056         : KBookmarkMenu(mgr, owner, parentMenu->menu(), parentAddress), m_actionCollection(collec)
0057 #endif
0058     {
0059     }
0060 
0061 protected:
0062     void refill() override;
0063     QAction *actionForBookmark(const KBookmark &bm) override;
0064     QMenu *contextMenu(QAction *action) override;
0065 #if QT_VERSION_MAJOR > 5
0066         KActionCollection *m_actionCollection = nullptr;
0067 #endif
0068 };
0069 
0070 class KonqBookmarkContextMenu : public KBookmarkContextMenu
0071 {
0072     Q_OBJECT
0073 public:
0074     KonqBookmarkContextMenu(const KBookmark &bm, KBookmarkManager *mgr, KBookmarkOwner *owner);
0075     ~KonqBookmarkContextMenu() override;
0076     void addActions() override;
0077 
0078 public Q_SLOTS:
0079     void openInNewTab();
0080     void openInNewWindow();
0081     void toggleShowInToolbar();
0082 };
0083 
0084 }
0085 
0086 #endif