Warning, file /utilities/keditbookmarks/src/favicons.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /* This file is part of the KDE project
0002    Copyright (C) 2002-2003 Alexander Kellett <lypanov@kde.org>
0003 
0004    This program is free software; you can redistribute it and/or
0005    modify it under the terms of the GNU General Public
0006    License version 2 or at your option version 3 as published by
0007    the Free Software Foundation.
0008 
0009    This program is distributed in the hope that it will be useful,
0010    but WITHOUT ANY WARRANTY; without even the implied warranty of
0011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0012    General Public License for more details.
0013 
0014    You should have received a copy of the GNU General Public License
0015    along with this program; see the file COPYING.  If not, write to
0016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0017    Boston, MA 02110-1301, USA.
0018 */
0019 
0020 #include "favicons.h"
0021 
0022 #include "faviconupdater.h"
0023 #include "kbookmarkmodel/commands.h"
0024 #include "kbookmarkmodel/model.h"
0025 
0026 #include "keditbookmarks_debug.h"
0027 #include <KLocalizedString>
0028 
0029 FavIconsItrHolder::FavIconsItrHolder(QObject *parent, KBookmarkModel *model)
0030     : BookmarkIteratorHolder(parent, model)
0031 {
0032 }
0033 
0034 /* -------------------------- */
0035 
0036 FavIconsItr::FavIconsItr(BookmarkIteratorHolder *holder, const QList<KBookmark> &bks)
0037     : BookmarkIterator(holder, bks)
0038     , m_updater(nullptr)
0039 {
0040 }
0041 
0042 FavIconsItr::~FavIconsItr()
0043 {
0044     delete m_updater;
0045 }
0046 
0047 void FavIconsItr::setStatus(const QString &status)
0048 {
0049     currentBookmark().setMetaDataItem(QStringLiteral("favstate"), status);
0050     model()->emitDataChanged(currentBookmark());
0051 }
0052 
0053 void FavIconsItr::slotDone(bool succeeded, const QString &errorString)
0054 {
0055     // //qCDebug(KEDITBOOKMARKS_LOG) << "FavIconsItr::slotDone()";
0056     setStatus(succeeded ? i18n("OK") : errorString);
0057     holder()->addAffectedBookmark(KBookmark::parentAddress(currentBookmark().address()));
0058     delayedEmitNextOne();
0059 }
0060 
0061 bool FavIconsItr::isApplicable(const KBookmark &bk) const
0062 {
0063     if (bk.isGroup() || bk.isSeparator())
0064         return false;
0065     return bk.url().scheme().startsWith(QLatin1String("http"));
0066 }
0067 
0068 void FavIconsItr::doAction()
0069 {
0070     // //qCDebug(KEDITBOOKMARKS_LOG) << "FavIconsItr::doAction()";
0071     m_oldStatus = currentBookmark().metaDataItem(QStringLiteral("favstate"));
0072     setStatus(i18n("Updating favicon..."));
0073     if (!m_updater) {
0074         m_updater = new FavIconUpdater(this);
0075         connect(m_updater, &FavIconUpdater::done, this, &FavIconsItr::slotDone);
0076     }
0077     m_updater->downloadIcon(currentBookmark());
0078 }
0079 
0080 void FavIconsItr::cancel()
0081 {
0082     setStatus(m_oldStatus);
0083 }