File indexing completed on 2024-04-28 17:05:53

0001 /*
0002     SPDX-FileCopyrightText: 2002 Shie Erlich <erlich@users.sourceforge.net>
0003     SPDX-FileCopyrightText: 2002 Rafi Yanai <yanai@users.sourceforge.net>
0004     SPDX-FileCopyrightText: 2004-2022 Krusader Krew <https://krusader.org>
0005 
0006     SPDX-License-Identifier: GPL-2.0-or-later
0007 */
0008 
0009 #ifndef KRBOOKMARKHANDLER_H
0010 #define KRBOOKMARKHANDLER_H
0011 
0012 // QtCore
0013 #include <QEvent>
0014 #include <QMap>
0015 #include <QObject>
0016 #include <QPointer>
0017 #include <QUrl>
0018 // QtXml
0019 #include <QDomEntity>
0020 // QtWidgets
0021 #include <QLineEdit>
0022 #include <QMenu>
0023 #include <QWidgetAction>
0024 
0025 #include "krbookmark.h"
0026 
0027 class KActionCollection;
0028 class KBookmarkManager;
0029 class KrMainWindow;
0030 
0031 class KrBookmarkHandler : public QObject
0032 {
0033     Q_OBJECT
0034     friend class KrAddBookmarkDlg;
0035     enum Actions { BookmarkCurrent = 0, ManageBookmarks };
0036 
0037 public:
0038     explicit KrBookmarkHandler(KrMainWindow *mainWindow);
0039     ~KrBookmarkHandler() override;
0040     void populate(QMenu *menu);
0041     void addBookmark(KrBookmark *bm, KrBookmark *parent = nullptr);
0042     void bookmarkCurrent(QUrl url);
0043 
0044 protected:
0045     void deleteBookmark(KrBookmark *bm);
0046     void importFromFile();
0047     bool importFromFileBookmark(QDomElement &e, KrBookmark *parent, const QString &path, QString *errorMsg);
0048     bool importFromFileFolder(QDomNode &first, KrBookmark *parent, const QString &path, QString *errorMsg);
0049     void exportToFile();
0050     void exportToFileFolder(QDomDocument &doc, QDomElement &parent, KrBookmark *folder);
0051     void exportToFileBookmark(QDomDocument &doc, QDomElement &where, KrBookmark *bm);
0052     void clearBookmarks(KrBookmark *root, bool removeBookmarks = true);
0053     void buildMenu(KrBookmark *parent, QMenu *menu, int depth = 0);
0054 
0055     bool eventFilter(QObject *obj, QEvent *ev) override;
0056     void rightClicked(QMenu *menu, KrBookmark *bm);
0057     void rightClickOnSpecialBookmark();
0058 
0059     void removeReferences(KrBookmark *root, KrBookmark *bmToRemove);
0060 
0061 protected slots:
0062     void bookmarksChanged(const QString &, const QString &);
0063     void slotActivated(const QUrl &url);
0064 
0065 private:
0066     KrMainWindow *_mainWindow;
0067     KActionCollection *_collection, *_privateCollection;
0068     KrBookmark *_root;
0069     // the whole KBookmarkManager is an ugly hack. use it until we have our own
0070     KBookmarkManager *manager;
0071     bool _middleClick; // if true, the user clicked the middle button to open the bookmark
0072 
0073     QPointer<QMenu> _mainBookmarkPopup; // main bookmark popup menu
0074     QList<QAction *> _specialBookmarks; // the action list of the special bookmarks
0075 
0076     QWidgetAction *_quickSearchAction; ///< Search bar container action
0077     QLineEdit *_quickSearchBar; ///< Search bar containing current query
0078     QMenu *_quickSearchMenu; ///< The menu where the search is performed
0079     QHash<QAction *, QString> _quickSearchOriginalActionTitles; ///< Saved original action text values to restore after search
0080 
0081     void _setQuickSearchText(const QString &text);
0082     QString _quickSearchText() const;
0083     static void _highlightAction(QAction *action, bool isMatched = true);
0084     void _resetActionTextAndHighlighting();
0085 };
0086 
0087 Q_DECLARE_METATYPE(KrBookmark *)
0088 
0089 #endif // KRBOOKMARK_HANDLER_H