add more spacing
[personal-kdebase.git] / apps / keditbookmarks / bookmarkiterator.cpp
bloba06fab7842125d78b57b65420aee6cf8e31797f1
1 // -*- indent-tabs-mode:nil -*-
2 // vim: set ts=4 sts=4 sw=4 et:
3 /* This file is part of the KDE project
4 Copyright (C) 2000 David Faure <faure@kde.org>
5 Copyright (C) 2002-2003 Alexander Kellett <lypanov@kde.org>
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public
9 License version 2 or at your option version 3 as published by
10 the Free Software Foundation.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA.
23 #include "bookmarkiterator.h"
25 #include "toplevel.h"
27 #include <kdebug.h>
28 #include <QtCore/QTimer>
29 #include <assert.h>
31 BookmarkIterator::BookmarkIterator(QList<KBookmark> bks) : m_bklist(bks) {
32 connect(this, SIGNAL( deleteSelf(BookmarkIterator *) ),
33 SLOT( slotCancelTest(BookmarkIterator *) ));
34 delayedEmitNextOne();
37 BookmarkIterator::~BookmarkIterator() {
41 void BookmarkIterator::delayedEmitNextOne() {
42 QTimer::singleShot(1, this, SLOT( nextOne() ));
45 void BookmarkIterator::slotCancelTest(BookmarkIterator *test) {
46 holder()->removeItr(test);
49 const KBookmark BookmarkIterator::curBk() const {
50 return m_bk;
53 void BookmarkIterator::nextOne() {
54 // kDebug() << "BookmarkIterator::nextOne";
56 if (m_bklist.isEmpty()) {
57 emit deleteSelf(this);
58 return;
61 QList<KBookmark>::iterator head = m_bklist.begin();
62 KBookmark bk = (*head);
64 bool viable = bk.hasParent() && isApplicable(bk);
66 if (viable) {
67 m_bk = bk;
68 doAction();
71 m_bklist.erase(head);
73 if (!viable)
74 delayedEmitNextOne();
77 /* --------------------------- */
79 BookmarkIteratorHolder::BookmarkIteratorHolder()
83 void BookmarkIteratorHolder::insertItr(BookmarkIterator *itr) {
84 m_itrs.prepend(itr);
85 doItrListChanged();
88 void BookmarkIteratorHolder::removeItr(BookmarkIterator *itr) {
89 m_itrs.removeAll(itr);
90 delete itr;
91 doItrListChanged();
94 void BookmarkIteratorHolder::cancelAllItrs()
96 qDeleteAll(m_itrs);
97 m_itrs.clear();
98 doItrListChanged();
101 #include "bookmarkiterator.moc"