File indexing completed on 2023-09-24 06:06:11
0001 /* This file is part of the KDE project 0002 Copyright (C) 2000, 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 GNU 0013 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; see the file COPYING. If not, write to 0017 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0018 Boston, MA 02110-1301, USA. 0019 */ 0020 0021 // Own 0022 #include "testlink.h" 0023 0024 // KDE 0025 #include <KLocalizedString> 0026 0027 // Local 0028 #include "kbookmarkmodel/model.h" 0029 0030 TestLinkItrHolder::TestLinkItrHolder(QObject *parent, KBookmarkModel *model) 0031 : BookmarkIteratorHolder(parent, model) 0032 { 0033 } 0034 0035 /* -------------------------- */ 0036 0037 TestLinkItr::TestLinkItr(BookmarkIteratorHolder *holder, const QList<KBookmark> &bks) 0038 : BookmarkIterator(holder, bks) 0039 , m_job(nullptr) 0040 { 0041 } 0042 0043 TestLinkItr::~TestLinkItr() 0044 { 0045 if (m_job) { 0046 // //qCDebug(KEDITBOOKMARKS_LOG) << "JOB kill\n"; 0047 m_job->disconnect(this); 0048 m_job->kill(); 0049 } 0050 } 0051 0052 void TestLinkItr::setStatus(const QString &text) 0053 { 0054 currentBookmark().setMetaDataItem(QStringLiteral("linkstate"), text); 0055 model()->emitDataChanged(currentBookmark()); 0056 } 0057 0058 bool TestLinkItr::isApplicable(const KBookmark &bk) const 0059 { 0060 return !bk.isGroup() && !bk.isSeparator(); 0061 } 0062 0063 void TestLinkItr::doAction() 0064 { 0065 // qCDebug(KEDITBOOKMARKS_LOG); 0066 m_job = KIO::get(currentBookmark().url(), KIO::Reload, KIO::HideProgressInfo); 0067 m_job->addMetaData(QStringLiteral("cookies"), QStringLiteral("none")); 0068 m_job->addMetaData(QStringLiteral("errorPage"), QStringLiteral("false")); 0069 0070 connect(m_job, &KIO::TransferJob::result, this, &TestLinkItr::slotJobResult); 0071 0072 m_oldStatus = currentBookmark().metaDataItem(QStringLiteral("linkstate")); 0073 setStatus(i18n("Checking...")); 0074 } 0075 0076 void TestLinkItr::slotJobResult(KJob *job) 0077 { 0078 // qCDebug(KEDITBOOKMARKS_LOG); 0079 m_job = nullptr; 0080 0081 KIO::TransferJob *transfer = static_cast<KIO::TransferJob *>(job); 0082 const QString modDate = transfer->queryMetaData(QStringLiteral("modified")); 0083 0084 if (transfer->error() || transfer->isErrorPage()) { 0085 // qCDebug(KEDITBOOKMARKS_LOG)<<"***********"<<transfer->error()<<" "<<transfer->isErrorPage(); 0086 // can we assume that errorString will contain no entities? 0087 QString err = transfer->errorString(); 0088 err.replace(QLatin1String("\n"), QLatin1String(" ")); 0089 setStatus(err); 0090 } else { 0091 if (!modDate.isEmpty()) 0092 setStatus(modDate); 0093 else 0094 setStatus(i18n("OK")); 0095 } 0096 0097 holder()->addAffectedBookmark(KBookmark::parentAddress(currentBookmark().address())); 0098 delayedEmitNextOne(); 0099 } 0100 0101 void TestLinkItr::cancel() 0102 { 0103 setStatus(m_oldStatus); 0104 } 0105 0106 #include "moc_testlink.cpp"