Make a branch to make krunner Good Enough For Aaron™.
[kdebase/uwolfer.git] / apps / keditbookmarks / testlink.cpp
bloba8b8a4fa802aad5ec3a97683a757faaff4562865
1 /* This file is part of the KDE project
2 Copyright (C) 2000 David Faure <faure@kde.org>
3 Copyright (C) 2002-2003 Alexander Kellett <lypanov@kde.org>
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public
7 License version 2 or at your option version 3 as published by
8 the Free Software Foundation.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; see the file COPYING. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
21 // Own
22 #include "testlink.h"
24 // Qt
25 #include <QtCore/QTimer>
26 #include <QtGui/QPainter>
28 // KDE
29 #include <kdebug.h>
31 #include <kdatetime.h>
32 #include <kcharsets.h>
33 #include <kbookmarkmanager.h>
35 #include <kaction.h>
36 #include <klocale.h>
38 // Local
39 #include "toplevel.h"
40 #include "commands.h"
41 #include "bookmarkiterator.h"
42 #include "bookmarkmodel.h"
44 TestLinkItrHolder *TestLinkItrHolder::s_self = 0;
46 TestLinkItrHolder::TestLinkItrHolder()
47 : BookmarkIteratorHolder() {
48 // do stuff
51 void TestLinkItrHolder::doItrListChanged() {
52 KEBApp::self()->setCancelTestsEnabled(count() > 0);
53 if(count() == 0)
55 kDebug()<<"Notifing managers "<<m_affectedBookmark;
56 CurrentMgr::self()->notifyManagers(CurrentMgr::bookmarkAt(m_affectedBookmark).toGroup());
57 m_affectedBookmark.clear();
61 void TestLinkItrHolder::addAffectedBookmark( const QString & address )
63 kDebug()<<"addAffectedBookmark "<<address;
64 if(m_affectedBookmark.isNull())
65 m_affectedBookmark = address;
66 else
67 m_affectedBookmark = KBookmark::commonParent(m_affectedBookmark, address);
68 kDebug()<<" m_affectedBookmark is now "<<m_affectedBookmark;
71 /* -------------------------- */
73 TestLinkItr::TestLinkItr(QList<KBookmark> bks)
74 : BookmarkIterator(bks) {
75 m_job = 0;
78 TestLinkItr::~TestLinkItr() {
79 //FIXME setStatus(m_oldStatus); if we didn't finish
80 if (m_job) {
81 // kDebug() << "JOB kill\n";
82 m_job->disconnect();
83 m_job->kill();
87 void TestLinkItr::setStatus(const QString & text)
89 EditCommand::setNodeText(curBk(), QStringList()<< "info" << "metadata" << "linkstate", text);
90 CurrentMgr::self()->model()->emitDataChanged(curBk());
93 bool TestLinkItr::isApplicable(const KBookmark &bk) const {
94 return (!bk.isGroup() && !bk.isSeparator());
97 void TestLinkItr::doAction() {
98 kDebug()<<"TestLinkItr::doAction() "<<endl;
99 m_job = KIO::get(curBk().url(), KIO::Reload, KIO::HideProgressInfo);
100 m_job->addMetaData( QString("cookies"), QString("none") );
101 m_job->addMetaData( QString("errorPage"), QString("false") );
103 connect(m_job, SIGNAL( result( KJob *)),
104 this, SLOT( slotJobResult(KJob *)));
106 m_oldStatus = EditCommand::getNodeText(curBk(), QStringList()<< "info" << "metadata" << "linkstate");
107 setStatus(i18n("Checking..."));
110 void TestLinkItr::slotJobResult(KJob *job) {
111 kDebug()<<"TestLinkItr::slotJobResult()"<<endl;
112 m_job = 0;
114 KIO::TransferJob *transfer = (KIO::TransferJob *)job;
115 QString modDate = transfer->queryMetaData("modified");
117 if (transfer->error() || transfer->isErrorPage())
119 kDebug()<<"***********"<<transfer->error()<<" "<<transfer->isErrorPage()<<endl;
120 // can we assume that errorString will contain no entities?
121 QString err = transfer->errorString();
122 err.replace("\n", " ");
123 setStatus(err);
125 else
127 if (!modDate.isEmpty())
128 setStatus(modDate);
129 else
130 setStatus(i18n("OK"));
133 holder()->addAffectedBookmark(KBookmark::parentAddress(curBk().address()));
134 delayedEmitNextOne();
135 //FIXME check that we don't need to call kill()
137 #include "testlink.moc"