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

0001 /*
0002     This file is part of the KDE project
0003     SPDX-FileCopyrightText: 2001 Carsten Pfeiffer <pfeiffer@kde.org>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007 
0008 #ifndef KHISTORYPROVIDER_H
0009 #define KHISTORYPROVIDER_H
0010 
0011 #include <libkonq_export.h>
0012 
0013 #include <QObject>
0014 
0015 class HistoryProviderPrivate;
0016 
0017 /**
0018  * @short Basic class to manage a history of "items". This class is only meant
0019  * for fast lookup, if an item is in the history or not.
0020  *
0021  * May be subclassed to implement a persistent history for example.
0022  * For usage with khtml, just create your provider and call the
0023  * HistoryProvider constructor _before_ you do any khtml stuff. That way,
0024  * khtml, using the self()-method, will use your subclassed provider.
0025  *
0026  * @author Carsten Pfeiffer <pfeiffer@kde.org>
0027  */
0028 class LIBKONQ_EXPORT HistoryProvider : public QObject
0029 {
0030     Q_OBJECT
0031     friend class ::HistoryProviderPrivate;
0032 
0033 public:
0034     static HistoryProvider *self();
0035 
0036     /**
0037      * @returns true if a provider has already been created.
0038      * @since 4.4
0039      */
0040     static bool exists();
0041 
0042     /**
0043      * @returns true if @p item is present in the history.
0044      */
0045     virtual bool contains(const QString &item) const;
0046 
0047     /**
0048      * Inserts @p item into the history.
0049      */
0050     virtual void insert(const QString &item);
0051 
0052     /**
0053      * Removes @p item from the history.
0054      */
0055     virtual void remove(const QString &item);
0056 
0057     /**
0058      * Clears the history. The cleared() signal is emitted after clearing.
0059      */
0060     virtual void clear();
0061 
0062 Q_SIGNALS:
0063     /**
0064      * Emitted after the history has been cleared.
0065      */
0066     void cleared();
0067 
0068     /**
0069      * This signal is never emitted from this class, it is only meant as an
0070      * interface for subclasses. Emit this signal to notify others that the
0071      * history has changed. Put those items that were added or removed from the
0072      * history into @p items.
0073      */
0074     void updated(const QStringList &items);
0075 
0076     /**
0077      * Emitted after the item has been inserted
0078      */
0079     void inserted(const QString &item);
0080 
0081 protected:
0082     /**
0083      * Creates a KHistoryProvider with an optional parent and name
0084      */
0085     HistoryProvider(QObject *parent = nullptr);
0086 
0087     /**
0088      * Destroys the provider.
0089      */
0090     ~HistoryProvider() override;
0091 
0092 private:
0093     HistoryProviderPrivate *const d;
0094 };
0095 
0096 #endif // KHISTORYPROVIDER_H