File indexing completed on 2024-10-06 06:38:57

0001 /*
0002     This file is part of the KDE libraries
0003     SPDX-FileCopyrightText: 2000, 2006 David Faure <faure@kde.org>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-only
0006 */
0007 #ifndef KBOOKMARK_OWNER_H
0008 #define KBOOKMARK_OWNER_H
0009 
0010 #include "kbookmark.h"
0011 
0012 #include <QSharedDataPointer>
0013 #include <QString>
0014 
0015 class QWidget;
0016 
0017 class KBookmarkGroup;
0018 
0019 /**
0020  * @class KBookmarkOwner kbookmarkowner.h KBookmarkOwner
0021  *
0022  * The KBookmarkMenu and KBookmarkBar classes gives the user
0023  * the ability to either edit bookmarks or add their own.  In the
0024  * first case, the app may want to open the bookmark in a special way.
0025  * In the second case, the app @em must supply the name and the
0026  * URL for the bookmark.
0027  *
0028  * This class gives the app this callback-like ability.
0029  *
0030  * If your app does not give the user the ability to add bookmarks and
0031  * you don't mind using the default bookmark editor to edit your
0032  * bookmarks, then you don't need to overload this class at all.
0033  * Rather, just use something like:
0034  *
0035  * @code
0036  * bookmarks = new KBookmarkMenu(manager, nullptr, menu);
0037  * @endcode
0038  *
0039  * If you wish to use your own editor or allow the user to add
0040  * bookmarks, you must overload this class.
0041  */
0042 class KBOOKMARKS_EXPORT KBookmarkOwner
0043 {
0044 public:
0045     KBookmarkOwner();
0046     virtual ~KBookmarkOwner();
0047 
0048     /**
0049      * This function is called whenever the user wants to add the
0050      * current page to the bookmarks list.  The title will become the
0051      * "name" of the bookmark.  You must overload this function if you
0052      * wish to give your users the ability to add bookmarks.
0053      * The default returns an empty string.
0054      *
0055      * @return the title of the current page.
0056      */
0057     virtual QString currentTitle() const
0058     {
0059         return QString();
0060     }
0061 
0062     /**
0063      * This function is called whenever the user wants to add the
0064      * current page to the bookmarks list.  The URL will become the URL
0065      * of the bookmark.  You must overload this function if you wish to
0066      * give your users the ability to add bookmarks.
0067      * The default returns an empty string.
0068      *
0069      * @return the URL of the current page.
0070      * Since 5.0 this method returns a QUrl. While porting it, remember to implement currentIcon too.
0071      */
0072     virtual QUrl currentUrl() const
0073     {
0074         return QUrl();
0075     }
0076 
0077     /**
0078      * This function is called whenever the user wants to add the
0079      * current page to the bookmarks list.  The icon will become the icon
0080      * of the bookmark.  You must overload this function if you wish to
0081      * give your users the ability to add bookmarks.
0082      * The default returns an empty string.
0083      *
0084      * A very common implementation for this method is
0085      * return KIO::iconNameForUrl(currentUrl());
0086      *
0087      * @return the icon name of the current page.
0088      * @since 5.0
0089      */
0090     virtual QString currentIcon() const
0091     {
0092         return QString();
0093     }
0094 
0095     /**
0096      * This function returns whether the owner supports tabs.
0097      * The default returns @c false.
0098      */
0099     virtual bool supportsTabs() const
0100     {
0101         return false;
0102     }
0103 
0104     class FutureBookmarkPrivate;
0105     /**
0106      * Represents the data for a bookmark that will be added.
0107      * @since 5.0
0108      */
0109     class KBOOKMARKS_EXPORT FutureBookmark
0110     {
0111     public:
0112         FutureBookmark(const QString &title, const QUrl &url, const QString &icon);
0113         ~FutureBookmark();
0114         FutureBookmark(const FutureBookmark &other);
0115         FutureBookmark &operator=(const FutureBookmark &other);
0116 
0117         QString title() const;
0118         QUrl url() const;
0119         QString icon() const;
0120 
0121     private:
0122         QSharedDataPointer<FutureBookmarkPrivate> d;
0123     };
0124 
0125     /**
0126      * Returns a list of bookmark data for the open tabs.
0127      * The default returns an empty list.
0128      */
0129     virtual QList<FutureBookmark> currentBookmarkList() const
0130     {
0131         return QList<FutureBookmark>();
0132     }
0133 
0134     enum BookmarkOption { ShowAddBookmark, ShowEditBookmark };
0135 
0136     /** Returns true if \p action should be shown in the menu
0137      *  The default is to show both a add and editBookmark Entry
0138      *  //TODO ContextMenuAction? to disable the contextMenu?
0139      *         Delete and Properties to disable those in the
0140      *         context menu?
0141      */
0142     virtual bool enableOption(BookmarkOption option) const;
0143 
0144     /**
0145      * Called if a bookmark is selected. You need to override this.
0146      */
0147     virtual void openBookmark(const KBookmark &bm, Qt::MouseButtons mb, Qt::KeyboardModifiers km) = 0;
0148 
0149     /**
0150      * Called if the user wants to open every bookmark in this folder in a new tab.
0151      * The default implementation does nothing.
0152      * This is only called if supportsTabs() returns true
0153      */
0154     virtual void openFolderinTabs(const KBookmarkGroup &bm);
0155 
0156     /**
0157      * Called when a bookmark should be opened in a new tab.
0158      * The default implementation calls openBookmark.
0159      * @since 5.0
0160      */
0161     virtual void openInNewTab(const KBookmark &bm);
0162 
0163     /**
0164      * Called when a bookmark should be opened in a new window.
0165      * The default implementation calls openBookmark.
0166      * @since 5.0
0167      */
0168     virtual void openInNewWindow(const KBookmark &bm);
0169 
0170 private:
0171     class KBookmarkOwnerPrivate;
0172     KBookmarkOwnerPrivate *d;
0173 };
0174 
0175 #endif