2005-05-12 12:15:44 +00:00
|
|
|
// -*- indent-tabs-mode:nil -*-
|
2003-10-06 18:31:25 +00:00
|
|
|
// vim: set ts=4 sts=4 sw=4 et:
|
2003-01-21 16:16:53 +00:00
|
|
|
/* This file is part of the KDE project
|
|
|
|
Copyright (C) 2000 David Faure <faure@kde.org>
|
|
|
|
Copyright (C) 2002-2003 Alexander Kellett <lypanov@kde.org>
|
|
|
|
|
|
|
|
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.
|
2003-01-21 16:16:53 +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.
|
2003-01-21 16:16:53 +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.
|
2003-01-21 16:16:53 +00:00
|
|
|
*/
|
|
|
|
|
2003-09-14 18:07:31 +00:00
|
|
|
#include "bookmarkiterator.h"
|
2003-01-21 16:16:53 +00:00
|
|
|
|
|
|
|
#include "toplevel.h"
|
2003-09-14 18:07:31 +00:00
|
|
|
|
|
|
|
#include <kdebug.h>
|
2007-05-09 22:23:52 +00:00
|
|
|
#include <QtCore/QTimer>
|
2005-08-13 20:13:21 +00:00
|
|
|
#include <assert.h>
|
2003-01-21 16:16:53 +00:00
|
|
|
|
2010-04-17 08:10:35 +00:00
|
|
|
BookmarkIterator::BookmarkIterator(BookmarkIteratorHolder* holder, const QList<KBookmark>& bks)
|
|
|
|
: m_bklist(bks), m_holder(holder)
|
2010-04-08 12:16:33 +00:00
|
|
|
{
|
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
|
|
|
BookmarkIterator::~BookmarkIterator()
|
|
|
|
{
|
2003-01-21 16:16:53 +00:00
|
|
|
}
|
|
|
|
|
2010-04-08 12:16:33 +00:00
|
|
|
void BookmarkIterator::delayedEmitNextOne()
|
|
|
|
{
|
|
|
|
QTimer::singleShot(1, this, SLOT(nextOne()));
|
2003-01-21 16:16:53 +00:00
|
|
|
}
|
|
|
|
|
2010-04-08 12:50:34 +00:00
|
|
|
KBookmark BookmarkIterator::curBk()
|
2010-04-08 12:16:33 +00:00
|
|
|
{
|
2003-10-11 13:39:50 +00:00
|
|
|
return m_bk;
|
2003-01-21 16:16:53 +00:00
|
|
|
}
|
|
|
|
|
2010-04-08 12:16:33 +00:00
|
|
|
void BookmarkIterator::nextOne()
|
|
|
|
{
|
2007-08-03 06:40:12 +00:00
|
|
|
// kDebug() << "BookmarkIterator::nextOne";
|
2003-01-21 16:16:53 +00:00
|
|
|
|
2003-10-11 13:39:50 +00:00
|
|
|
if (m_bklist.isEmpty()) {
|
2010-04-08 12:16:33 +00:00
|
|
|
holder()->removeItr(this); // deletes "this"
|
2003-10-11 13:39:50 +00:00
|
|
|
return;
|
|
|
|
}
|
2003-01-21 16:16:53 +00:00
|
|
|
|
2005-09-28 16:16:52 +00:00
|
|
|
QList<KBookmark>::iterator head = m_bklist.begin();
|
2003-10-11 13:39:50 +00:00
|
|
|
KBookmark bk = (*head);
|
2003-01-21 16:16:53 +00:00
|
|
|
|
2003-10-11 13:39:50 +00:00
|
|
|
bool viable = bk.hasParent() && isApplicable(bk);
|
2003-03-22 00:43:39 +00:00
|
|
|
|
2003-10-11 13:39:50 +00:00
|
|
|
if (viable) {
|
|
|
|
m_bk = bk;
|
|
|
|
doAction();
|
|
|
|
}
|
2003-03-22 00:43:39 +00:00
|
|
|
|
2005-08-13 20:13:21 +00:00
|
|
|
m_bklist.erase(head);
|
2003-03-22 00:43:39 +00:00
|
|
|
|
2003-10-19 16:23:37 +00:00
|
|
|
if (!viable)
|
|
|
|
delayedEmitNextOne();
|
2003-01-21 16:16:53 +00:00
|
|
|
}
|
|
|
|
|
2003-03-22 00:43:39 +00:00
|
|
|
/* --------------------------- */
|
2003-02-16 00:05:39 +00:00
|
|
|
|
2010-04-17 16:01:46 +00:00
|
|
|
BookmarkIteratorHolder::BookmarkIteratorHolder(KBookmarkModel* model)
|
|
|
|
: m_model(model)
|
2005-09-28 16:16:52 +00:00
|
|
|
{
|
2010-04-17 16:01:46 +00:00
|
|
|
Q_ASSERT(m_model);
|
2003-01-21 16:16:53 +00:00
|
|
|
}
|
|
|
|
|
2010-04-08 12:16:33 +00:00
|
|
|
void BookmarkIteratorHolder::insertItr(BookmarkIterator *itr)
|
|
|
|
{
|
2005-09-28 16:16:52 +00:00
|
|
|
m_itrs.prepend(itr);
|
2003-10-11 13:39:50 +00:00
|
|
|
doItrListChanged();
|
2003-01-21 16:16:53 +00:00
|
|
|
}
|
|
|
|
|
2010-04-08 12:16:33 +00:00
|
|
|
void BookmarkIteratorHolder::removeItr(BookmarkIterator *itr)
|
|
|
|
{
|
2006-04-04 18:12:34 +00:00
|
|
|
m_itrs.removeAll(itr);
|
2010-04-08 12:16:33 +00:00
|
|
|
itr->deleteLater();
|
2003-10-11 13:39:50 +00:00
|
|
|
doItrListChanged();
|
2003-01-21 16:16:53 +00:00
|
|
|
}
|
|
|
|
|
2010-04-08 12:16:33 +00:00
|
|
|
void BookmarkIteratorHolder::cancelAllItrs()
|
2005-09-28 16:16:52 +00:00
|
|
|
{
|
|
|
|
qDeleteAll(m_itrs);
|
2005-06-10 01:08:43 +00:00
|
|
|
m_itrs.clear();
|
|
|
|
doItrListChanged();
|
2003-01-21 16:16:53 +00:00
|
|
|
}
|
|
|
|
|
2010-04-17 16:01:46 +00:00
|
|
|
KBookmarkModel* BookmarkIterator::model()
|
|
|
|
{
|
|
|
|
return m_holder->model();
|
|
|
|
}
|
|
|
|
|
2003-01-21 16:16:53 +00:00
|
|
|
#include "bookmarkiterator.moc"
|