Make a branch to make krunner Good Enough For Aaron™.
[kdebase/uwolfer.git] / apps / konqueror / src / konqundomanager.cpp
blobff1233b0781c44775147be2f74a1c6f977e94ee5
1 /* This file is part of the KDE project
2 Copyright 2007 David Faure <faure@kde.org>
3 Copyright 2007 Eduardo Robles Elvira <edulix@gmail.com>
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 as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
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 #include "konqundomanager.h"
22 #include <QAction>
23 #include "konqclosedtabitem.h"
24 #include <konq_fileundomanager.h>
25 #include <kconfig.h>
26 #include <kdebug.h>
27 #include <klocale.h>
29 KonqUndoManager::KonqUndoManager(QObject* parent)
30 : QObject(parent)
32 KonqFileUndoManager::incRef();
33 connect( KonqFileUndoManager::self(), SIGNAL(undoAvailable(bool)),
34 this, SLOT(slotFileUndoAvailable(bool)) );
35 connect( KonqFileUndoManager::self(), SIGNAL(undoTextChanged(QString)),
36 this, SLOT(slotFileUndoTextChanged(QString)) );
39 KonqUndoManager::~KonqUndoManager()
41 clearClosedTabsList();
42 KonqFileUndoManager::decRef();
45 void KonqUndoManager::slotFileUndoAvailable(bool)
47 emit undoAvailable(this->undoAvailable());
50 bool KonqUndoManager::undoAvailable() const
52 if (!m_closedTabsList.isEmpty())
53 return true;
54 else
55 return (m_supportsFileUndo && KonqFileUndoManager::self()->undoAvailable());
58 QString KonqUndoManager::undoText() const
60 if (!m_closedTabsList.isEmpty()) {
61 const KonqClosedTabItem* closedTabItem = m_closedTabsList.first();
62 if (closedTabItem->serialNumber() > KonqFileUndoManager::self()->currentCommandSerialNumber()) {
63 return i18n("Und&o: Closed Tab");
66 return KonqFileUndoManager::self()->undoText();
69 void KonqUndoManager::undo()
71 if (!m_closedTabsList.isEmpty()) {
72 const KonqClosedTabItem* closedTabItem = m_closedTabsList.first();
74 // Check what to undo
75 kDebug() << "closedTabItem->serialNumber:" << closedTabItem->serialNumber()
76 << ", KonqFileUndoManager currentCommandSerialNumber(): " << KonqFileUndoManager::self()->currentCommandSerialNumber();
78 if (closedTabItem->serialNumber() > KonqFileUndoManager::self()->currentCommandSerialNumber()) {
79 m_closedTabsList.removeFirst();
80 emit openClosedTab(*closedTabItem);
81 delete closedTabItem;
82 emit undoAvailable(this->undoAvailable());
83 emit closedTabsListChanged();
84 } else {
85 KonqFileUndoManager::self()->undo();
87 } else {
88 KonqFileUndoManager::self()->undo();
92 const QList<KonqClosedTabItem *>& KonqUndoManager::closedTabsList() const
94 return m_closedTabsList;
97 void KonqUndoManager::undoClosedTab(int index)
99 Q_ASSERT(!m_closedTabsList.isEmpty());
100 KonqClosedTabItem* closedTabItem = m_closedTabsList.at( index );
101 m_closedTabsList.removeAt(index);
102 emit openClosedTab(*closedTabItem);
103 delete closedTabItem;
104 emit undoAvailable(this->undoAvailable());
105 emit undoTextChanged(this->undoText());
106 emit closedTabsListChanged();
109 void KonqUndoManager::slotClosedTabsActivated(QAction* action)
111 // Open a closed tab
112 const int index = action->data().toInt();
113 undoClosedTab(index);
116 void KonqUndoManager::slotFileUndoTextChanged(const QString& text)
118 // I guess we can always just forward that one?
119 emit undoTextChanged(text);
122 quint64 KonqUndoManager::newCommandSerialNumber()
124 return KonqFileUndoManager::self()->newCommandSerialNumber();
127 void KonqUndoManager::addClosedTabItem(KonqClosedTabItem* closedTabItem)
129 m_closedTabsList.prepend(closedTabItem);
130 emit undoTextChanged(i18n("Und&o: Closed Tab"));
131 emit undoAvailable(true);
134 void KonqUndoManager::updateSupportsFileUndo(bool enable)
136 m_supportsFileUndo = enable;
137 emit undoAvailable(this->undoAvailable());
140 void KonqUndoManager::clearClosedTabsList()
142 qDeleteAll(m_closedTabsList);
143 m_closedTabsList.clear();
144 emit closedTabsListChanged();
145 emit undoAvailable(this->undoAvailable());
148 void KonqUndoManager::undoLastClosedTab()
150 undoClosedTab(0);