2002-09-30 12:36:56 +00:00
|
|
|
/* This file is part of the KDE project
|
2003-01-21 16:16:53 +00:00
|
|
|
Copyright (C) 2002-2003 Alexander Kellett <lypanov@kde.org>
|
2002-09-30 12:36:56 +00:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public
|
2007-12-20 22:23:07 +00:00
|
|
|
License version 2 or at your option version 3 as published by
|
|
|
|
the Free Software Foundation.
|
2002-09-30 12:36:56 +00:00
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
2003-10-11 13:39:50 +00:00
|
|
|
General Public License for more details.
|
2002-09-30 12:36:56 +00:00
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; see the file COPYING. If not, write to
|
2005-10-05 08:44:32 +00:00
|
|
|
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
2005-07-04 19:02:09 +00:00
|
|
|
Boston, MA 02110-1301, USA.
|
2002-09-30 12:36:56 +00:00
|
|
|
*/
|
|
|
|
|
2003-09-14 18:07:31 +00:00
|
|
|
#include "favicons.h"
|
2003-01-21 16:16:53 +00:00
|
|
|
|
2003-02-10 14:37:56 +00:00
|
|
|
#include "bookmarkiterator.h"
|
2010-04-26 17:46:35 +00:00
|
|
|
#include "faviconupdater.h"
|
2010-04-24 09:06:17 +00:00
|
|
|
#include "kbookmarkmodel/commands.h"
|
|
|
|
#include "kbookmarkmodel/model.h"
|
2003-02-10 14:37:56 +00:00
|
|
|
|
2003-09-14 18:07:31 +00:00
|
|
|
#include <kdebug.h>
|
|
|
|
#include <klocale.h>
|
2003-01-21 16:16:53 +00:00
|
|
|
|
2010-04-26 17:29:02 +00:00
|
|
|
FavIconsItrHolder::FavIconsItrHolder(QObject* parent, KBookmarkModel* model)
|
|
|
|
: BookmarkIteratorHolder(parent, model)
|
2010-04-08 12:16:33 +00:00
|
|
|
{
|
2003-10-19 11:01:37 +00:00
|
|
|
}
|
2003-01-21 16:16:53 +00:00
|
|
|
|
2003-02-16 00:05:39 +00:00
|
|
|
/* -------------------------- */
|
2003-02-15 18:58:36 +00:00
|
|
|
|
2010-04-17 16:01:46 +00:00
|
|
|
FavIconsItr::FavIconsItr(BookmarkIteratorHolder* holder, const QList<KBookmark>& bks)
|
|
|
|
: BookmarkIterator(holder, bks), m_updater(0)
|
2010-04-08 12:16:33 +00:00
|
|
|
{
|
2003-10-19 11:01:37 +00:00
|
|
|
}
|
2003-01-21 16:16:53 +00:00
|
|
|
|
2010-04-08 12:16:33 +00:00
|
|
|
FavIconsItr::~FavIconsItr()
|
|
|
|
{
|
2003-10-19 16:23:37 +00:00
|
|
|
delete m_updater;
|
2003-01-21 16:16:53 +00:00
|
|
|
}
|
|
|
|
|
2007-12-16 01:47:07 +00:00
|
|
|
void FavIconsItr::setStatus(const QString & status)
|
|
|
|
{
|
2010-04-18 14:24:11 +00:00
|
|
|
currentBookmark().setMetaDataItem("favstate", status);
|
|
|
|
model()->emitDataChanged(currentBookmark());
|
2007-12-16 01:47:07 +00:00
|
|
|
}
|
|
|
|
|
2010-04-18 14:24:11 +00:00
|
|
|
void FavIconsItr::slotDone(bool succeeded, const QString& errorString)
|
2010-04-08 12:16:33 +00:00
|
|
|
{
|
2007-08-03 06:40:12 +00:00
|
|
|
// kDebug() << "FavIconsItr::slotDone()";
|
2010-04-18 14:24:11 +00:00
|
|
|
setStatus(succeeded ? i18n("OK") : errorString);
|
|
|
|
holder()->addAffectedBookmark(KBookmark::parentAddress(currentBookmark().address()));
|
2003-10-11 13:39:50 +00:00
|
|
|
delayedEmitNextOne();
|
2003-01-21 16:16:53 +00:00
|
|
|
}
|
|
|
|
|
2010-04-08 12:16:33 +00:00
|
|
|
bool FavIconsItr::isApplicable(const KBookmark &bk) const
|
|
|
|
{
|
2010-04-18 14:24:11 +00:00
|
|
|
if (bk.isGroup() || bk.isSeparator())
|
|
|
|
return false;
|
|
|
|
return bk.url().protocol().startsWith("http");
|
2003-10-19 11:01:37 +00:00
|
|
|
}
|
2003-01-21 16:16:53 +00:00
|
|
|
|
2010-04-08 12:16:33 +00:00
|
|
|
void FavIconsItr::doAction()
|
|
|
|
{
|
2007-08-03 06:40:12 +00:00
|
|
|
// kDebug() << "FavIconsItr::doAction()";
|
2010-04-18 14:24:11 +00:00
|
|
|
m_oldStatus = currentBookmark().metaDataItem("favstate");
|
2007-12-16 01:47:07 +00:00
|
|
|
setStatus(i18n("Updating favicon..."));
|
2003-10-11 13:39:50 +00:00
|
|
|
if (!m_updater) {
|
2010-04-18 14:24:11 +00:00
|
|
|
m_updater = new FavIconUpdater(this);
|
|
|
|
connect(m_updater, SIGNAL(done(bool,QString)),
|
|
|
|
this, SLOT(slotDone(bool,QString)) );
|
2003-10-19 16:23:37 +00:00
|
|
|
}
|
2010-04-18 14:24:11 +00:00
|
|
|
m_updater->downloadIcon(currentBookmark());
|
|
|
|
}
|
|
|
|
|
|
|
|
void FavIconsItr::cancel()
|
|
|
|
{
|
|
|
|
setStatus(m_oldStatus);
|
2003-01-21 16:16:53 +00:00
|
|
|
}
|
|
|
|
|
2002-10-01 13:23:34 +00:00
|
|
|
#include "favicons.moc"
|