Warning, file /utilities/keditbookmarks/src/testlink.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) 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 "keditbookmarks_debug.h"
0026 #include <KLocalizedString>
0027 
0028 // Local
0029 #include "kbookmarkmodel/commands.h"
0030 #include "kbookmarkmodel/model.h"
0031 
0032 TestLinkItrHolder::TestLinkItrHolder(QObject *parent, KBookmarkModel *model)
0033     : BookmarkIteratorHolder(parent, model)
0034 {
0035 }
0036 
0037 /* -------------------------- */
0038 
0039 TestLinkItr::TestLinkItr(BookmarkIteratorHolder *holder, const QList<KBookmark> &bks)
0040     : BookmarkIterator(holder, bks)
0041     , m_job(nullptr)
0042 {
0043 }
0044 
0045 TestLinkItr::~TestLinkItr()
0046 {
0047     if (m_job) {
0048         // //qCDebug(KEDITBOOKMARKS_LOG) << "JOB kill\n";
0049         m_job->disconnect(this);
0050         m_job->kill();
0051     }
0052 }
0053 
0054 void TestLinkItr::setStatus(const QString &text)
0055 {
0056     currentBookmark().setMetaDataItem(QStringLiteral("linkstate"), text);
0057     model()->emitDataChanged(currentBookmark());
0058 }
0059 
0060 bool TestLinkItr::isApplicable(const KBookmark &bk) const
0061 {
0062     return !bk.isGroup() && !bk.isSeparator();
0063 }
0064 
0065 void TestLinkItr::doAction()
0066 {
0067     // qCDebug(KEDITBOOKMARKS_LOG);
0068     m_job = KIO::get(currentBookmark().url(), KIO::Reload, KIO::HideProgressInfo);
0069     m_job->addMetaData(QStringLiteral("cookies"), QStringLiteral("none"));
0070     m_job->addMetaData(QStringLiteral("errorPage"), QStringLiteral("false"));
0071 
0072     connect(m_job, &KIO::TransferJob::result, this, &TestLinkItr::slotJobResult);
0073 
0074     m_oldStatus = currentBookmark().metaDataItem(QStringLiteral("linkstate"));
0075     setStatus(i18n("Checking..."));
0076 }
0077 
0078 void TestLinkItr::slotJobResult(KJob *job)
0079 {
0080     // qCDebug(KEDITBOOKMARKS_LOG);
0081     m_job = nullptr;
0082 
0083     KIO::TransferJob *transfer = static_cast<KIO::TransferJob *>(job);
0084     const QString modDate = transfer->queryMetaData(QStringLiteral("modified"));
0085 
0086     if (transfer->error() || transfer->isErrorPage()) {
0087         // qCDebug(KEDITBOOKMARKS_LOG)<<"***********"<<transfer->error()<<"  "<<transfer->isErrorPage();
0088         // can we assume that errorString will contain no entities?
0089         QString err = transfer->errorString();
0090         err.replace(QLatin1String("\n"), QLatin1String(" "));
0091         setStatus(err);
0092     } else {
0093         if (!modDate.isEmpty())
0094             setStatus(modDate);
0095         else
0096             setStatus(i18n("OK"));
0097     }
0098 
0099     holder()->addAffectedBookmark(KBookmark::parentAddress(currentBookmark().address()));
0100     delayedEmitNextOne();
0101 }
0102 
0103 void TestLinkItr::cancel()
0104 {
0105     setStatus(m_oldStatus);
0106 }