File indexing completed on 2024-03-24 05:53:12
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/model.h" 0024 0025 #include <KLocalizedString> 0026 0027 FavIconsItrHolder::FavIconsItrHolder(QObject *parent, KBookmarkModel *model) 0028 : BookmarkIteratorHolder(parent, model) 0029 { 0030 } 0031 0032 /* -------------------------- */ 0033 0034 FavIconsItr::FavIconsItr(BookmarkIteratorHolder *holder, const QList<KBookmark> &bks) 0035 : BookmarkIterator(holder, bks) 0036 , m_updater(nullptr) 0037 { 0038 } 0039 0040 FavIconsItr::~FavIconsItr() 0041 { 0042 delete m_updater; 0043 } 0044 0045 void FavIconsItr::setStatus(const QString &status) 0046 { 0047 currentBookmark().setMetaDataItem(QStringLiteral("favstate"), status); 0048 model()->emitDataChanged(currentBookmark()); 0049 } 0050 0051 void FavIconsItr::slotDone(bool succeeded, const QString &errorString) 0052 { 0053 // //qCDebug(KEDITBOOKMARKS_LOG) << "FavIconsItr::slotDone()"; 0054 setStatus(succeeded ? i18n("OK") : errorString); 0055 holder()->addAffectedBookmark(KBookmark::parentAddress(currentBookmark().address())); 0056 delayedEmitNextOne(); 0057 } 0058 0059 bool FavIconsItr::isApplicable(const KBookmark &bk) const 0060 { 0061 if (bk.isGroup() || bk.isSeparator()) 0062 return false; 0063 return bk.url().scheme().startsWith(QLatin1String("http")); 0064 } 0065 0066 void FavIconsItr::doAction() 0067 { 0068 // //qCDebug(KEDITBOOKMARKS_LOG) << "FavIconsItr::doAction()"; 0069 m_oldStatus = currentBookmark().metaDataItem(QStringLiteral("favstate")); 0070 setStatus(i18n("Updating favicon...")); 0071 if (!m_updater) { 0072 m_updater = new FavIconUpdater(this); 0073 connect(m_updater, &FavIconUpdater::done, this, &FavIconsItr::slotDone); 0074 } 0075 m_updater->downloadIcon(currentBookmark()); 0076 } 0077 0078 void FavIconsItr::cancel() 0079 { 0080 setStatus(m_oldStatus); 0081 } 0082 0083 #include "moc_favicons.cpp"