File indexing completed on 2024-04-21 05:50:21

0001 /* This file is part of the KDE project
0002    Copyright (C) 2010 David Faure <faure@kde.org>
0003    Copyright (C) 2002-2003 Alexander Kellett <lypanov@kde.org>
0004 
0005    This program is free software; you can redistribute it and/or
0006    modify it under the terms of the GNU General Public
0007    License version 2 or at your option version 3 as published by
0008    the Free Software Foundation.
0009 
0010    This program is distributed in the hope that it will be useful,
0011    but WITHOUT ANY WARRANTY; without even the implied warranty of
0012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0013    GNU General Public License for more details.
0014 
0015    You should have received a copy of the GNU General Public License
0016    along with this program.  If not, see <http://www.gnu.org/licenses/>
0017 */
0018 
0019 #ifndef __bookmarkiterator_h
0020 #define __bookmarkiterator_h
0021 
0022 #include <KBookmark>
0023 #include <QList>
0024 #include <QObject>
0025 
0026 class KBookmarkModel;
0027 class BookmarkIteratorHolder;
0028 
0029 /**
0030  * A bookmark iterator goes through every bookmark and performs an asynchronous
0031  * action (e.g. downloading the favicon or testing whether the url exists).
0032  */
0033 class BookmarkIterator : public QObject
0034 {
0035     Q_OBJECT
0036 
0037 public:
0038     BookmarkIterator(BookmarkIteratorHolder *holder, const QList<KBookmark> &bks);
0039     ~BookmarkIterator() override;
0040     BookmarkIteratorHolder *holder() const
0041     {
0042         return m_holder;
0043     }
0044     KBookmarkModel *model();
0045     void delayedEmitNextOne();
0046     virtual void cancel() = 0;
0047 
0048 public Q_SLOTS:
0049     void nextOne();
0050 
0051 protected:
0052     virtual void doAction() = 0;
0053     virtual bool isApplicable(const KBookmark &bk) const = 0;
0054     KBookmark currentBookmark();
0055 
0056 private:
0057     KBookmark m_bk;
0058     QList<KBookmark> m_bookmarkList;
0059     BookmarkIteratorHolder *m_holder;
0060 };
0061 
0062 /**
0063  * The "bookmark iterator holder" handles all concurrent iterators for a given
0064  * functionality: e.g. all favicon iterators.
0065  *
0066  * BookmarkIteratorHolder is the base class for the favicon and testlink holders.
0067  */
0068 class BookmarkIteratorHolder : public QObject
0069 {
0070     Q_OBJECT
0071 public:
0072     void cancelAllItrs();
0073     void removeIterator(BookmarkIterator *);
0074     void insertIterator(BookmarkIterator *);
0075     void addAffectedBookmark(const QString &address);
0076     KBookmarkModel *model()
0077     {
0078         return m_model;
0079     }
0080 
0081 Q_SIGNALS:
0082     void setCancelEnabled(bool canCancel);
0083 
0084 protected:
0085     BookmarkIteratorHolder(QObject *parent, KBookmarkModel *model);
0086     ~BookmarkIteratorHolder() override
0087     {
0088     }
0089     void doIteratorListChanged();
0090     int count() const
0091     {
0092         return m_iterators.count();
0093     }
0094     KBookmarkModel *m_model;
0095 
0096 private:
0097     QString m_affectedBookmark;
0098     QList<BookmarkIterator *> m_iterators;
0099 };
0100 
0101 #endif