File indexing completed on 2024-04-28 04:58:11

0001 /* This file is part of the KDE project
0002     SPDX-FileCopyrightText: 2000, 2001 Carsten Pfeiffer <pfeiffer@kde.org>
0003     SPDX-FileCopyrightText: 2007-2009 David Faure <faure@kde.org>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0006 */
0007 
0008 #ifndef KONQ_HISTORYPROVIDER_H
0009 #define KONQ_HISTORYPROVIDER_H
0010 
0011 #include <historyprovider.h>
0012 #include <QUrl>
0013 #include "libkonq_export.h"
0014 #include "konq_historyentry.h"
0015 
0016 class KonqHistoryEntry;
0017 class KonqHistoryList;
0018 class KonqHistoryProviderPrivate;
0019 
0020 /**
0021  * This class maintains and manages a history of all URLs visited by Konqueror.
0022  * It synchronizes the history with other KonqHistoryProvider instances in
0023  * other processes (konqueror, history list, krunner etc.) via D-Bus to keep
0024  * one global and persistent history.
0025  */
0026 class LIBKONQ_EXPORT KonqHistoryProvider : public HistoryProvider
0027 {
0028     Q_OBJECT
0029 
0030 public:
0031     /**
0032      * Returns the KonqHistoryProvider instance. This relies on a KonqHistoryProvider
0033      * instance being created first!
0034      * This is a bit like "qApp": you can access the instance anywhere, but you need to
0035      * create it first.
0036      */
0037     static KonqHistoryProvider *self()
0038     {
0039         return static_cast<KonqHistoryProvider *>(HistoryProvider::self());
0040     }
0041 
0042     explicit KonqHistoryProvider(QObject *parent = nullptr);
0043     ~KonqHistoryProvider() override;
0044 
0045     /**
0046      * @returns the list of all history entries, sorted by date
0047      * (oldest entries first)
0048      */
0049     const KonqHistoryList &entries() const;
0050 
0051     /**
0052      * @returns the current maximum number of history entries.
0053      */
0054     int maxCount() const;
0055 
0056     /**
0057      * @returns the current maximum age (in days) of history entries.
0058      */
0059     int maxAge() const;
0060 
0061     /**
0062      * Sets a new maximum size of history and truncates the current history
0063      * if necessary. Notifies all other Konqueror instances via D-Bus
0064      * to do the same.
0065      *
0066      * The history is saved after receiving the D-Bus call.
0067      */
0068     void emitSetMaxCount(int count);
0069 
0070     /**
0071      * Sets a new maximum age of history entries and removes all entries that
0072      * are older than @p days. Notifies all other Konqueror instances via D-Bus
0073      * to do the same.
0074      *
0075      * An age of 0 means no expiry based on the age.
0076      *
0077      * The history is saved after receiving the D-Bus call.
0078      */
0079     void emitSetMaxAge(int days);
0080 
0081     /**
0082      * Removes the history entry for @p url, if existent. Tells all other
0083      * Konqueror instances via D-Bus to do the same.
0084      *
0085      * The history is saved after receiving the D-Bus call.
0086      */
0087     void emitRemoveFromHistory(const QUrl &url);
0088 
0089     /**
0090      * Removes the history entries for the given list of @p urls. Tells all
0091      * other Konqueror instances via D-Bus to do the same.
0092      *
0093      * The history is saved after receiving the D-Bus call.
0094      */
0095     void emitRemoveListFromHistory(const QList<QUrl> &urls);
0096 
0097     /**
0098      * Clears the history and tells all other Konqueror instances via D-Bus
0099      * to do the same.
0100      * The history is saved afterwards, if necessary.
0101      */
0102     void emitClear();
0103 
0104     /**
0105      * Load the whole history from disk. Call this exactly once.
0106      */
0107     bool loadHistory();
0108 
0109 Q_SIGNALS:
0110     /**
0111      * Emitted after a new entry was added
0112      */
0113     void entryAdded(const KonqHistoryEntry &entry);
0114 
0115     /**
0116      * Emitted after an entry was removed from the history
0117      * Note, that this entry will be deleted immediately after you got
0118      * that signal.
0119      */
0120     void entryRemoved(const KonqHistoryEntry &entry);
0121 
0122 protected: // only to be used by konqueror's KonqHistoryManager
0123 
0124     virtual void finishAddingEntry(const KonqHistoryEntry &entry, bool isSender);
0125     virtual void removeEntry(KonqHistoryList::iterator it);
0126 
0127     /**
0128      * a little optimization for KonqHistoryList::findEntry(),
0129      * checking the dict of KParts::HistoryProvider before traversing the list.
0130      * Can't be used everywhere, because it always returns end() for "pending"
0131      * entries, as those are not added to the dict, currently.
0132      */
0133     KonqHistoryList::iterator findEntry(const QUrl &url);
0134     KonqHistoryList::const_iterator constFindEntry(const QUrl &url) const;
0135 
0136     /**
0137      * Notifies all running instances about a new HistoryEntry via D-Bus.
0138      */
0139     void emitAddToHistory(const KonqHistoryEntry &entry);
0140 
0141 private:
0142     KonqHistoryProviderPrivate *const d;
0143     friend class KonqHistoryProviderPrivate;
0144 };
0145 
0146 #endif /* KONQ_HISTORYPROVIDER_H */