Commit dbe3d396 authored by Eduardo Robles Elvira's avatar Eduardo Robles Elvira

* Adding a limit to the number of closed items

* Now closed windows don't get removed innecesarily, thus a preloaded konqueror instance can restore them
* Changing the s_config to be SimpleConfig and deleting it everytime, using it as temporal, and moving it to appdata
* minor cosmetic adjustements in a header

CCMAIL:kfm-devel@kde.org


svn path=/trunk/KDE/kdebase/apps/; revision=788586
parent d58582de
......@@ -19,15 +19,39 @@
*/
#include "konqcloseditem.h"
#include <QFile>
#include <kconfig.h>
#include <kdebug.h>
#include <kglobal.h>
#include <konqpixmapprovider.h>
#include <kstandarddirs.h>
#include <unistd.h>
K_GLOBAL_STATIC_WITH_ARGS(KConfig, s_config, ("konqueror_closeditems", KConfig::NoGlobals) )
class KConfigNew
{
public:
KConfigNew()
{
filename = "closeditems/closeditems_" + QString::number(getpid());
QString file = KStandardDirs::locateLocal("appdata", filename);
if(QFile::exists(file))
QFile::remove(file);
config = new KConfig(filename, KConfig::SimpleConfig, "appdata");
kDebug();
}
~KConfigNew() {
QFile::remove(KStandardDirs::locateLocal("appdata", filename));
delete config;
}
KConfig *config;
QString filename;
};
K_GLOBAL_STATIC(KConfigNew, s_config)
KonqClosedItem::KonqClosedItem(const QString& title, const QString& group, quint64 serialNumber)
: m_title(title), m_configGroup(s_config, group), m_serialNumber(serialNumber)
: m_title(title), m_configGroup(s_config->config, group), m_serialNumber(serialNumber)
{
}
......
......@@ -20,6 +20,7 @@
#include "konqundomanager.h"
#include <QAction>
#include <QTimer>
#include <konq_fileundomanager.h>
#include <kconfig.h>
#include <kdebug.h>
......@@ -30,6 +31,7 @@ class KonqUndoManagerCommunicatorPrivate {
public:
KonqUndoManagerCommunicator instance;
QList<KonqClosedWindowItem *> m_closedWindowItemList;
int m_maxNumClosedItems;
};
K_GLOBAL_STATIC(KonqUndoManagerCommunicatorPrivate, myKonqUndoManagerCommunicatorPrivate)
......@@ -146,7 +148,19 @@ void KonqUndoManager::slotAddClosedWindowItem(KonqUndoManager *real_sender, Konq
{
if(real_sender == this)
return;
if(m_closedItemList.size() >= KonqUndoManagerCommunicator::self()->maxNumClosedItems())
{
const KonqClosedItem* last = m_closedItemList.last();
const KonqClosedTabItem* lastTab =
dynamic_cast<const KonqClosedTabItem *>(last);
m_closedItemList.removeLast();
// Delete only if it's a tab
if(lastTab)
delete lastTab;
}
kDebug();
m_closedItemList.prepend(closedWindowItem);
emit undoTextChanged(i18n("Und&o: Closed Window"));
......@@ -221,6 +235,18 @@ quint64 KonqUndoManager::newCommandSerialNumber()
void KonqUndoManager::addClosedTabItem(KonqClosedTabItem* closedTabItem)
{
if(m_closedItemList.size() >= KonqUndoManagerCommunicator::self()->maxNumClosedItems())
{
const KonqClosedItem* last = m_closedItemList.last();
const KonqClosedTabItem* lastTab =
dynamic_cast<const KonqClosedTabItem *>(last);
m_closedItemList.removeLast();
// Delete only if it's a tab
if(lastTab)
delete lastTab;
}
m_closedItemList.prepend(closedTabItem);
emit undoTextChanged(i18n("Und&o: Closed Tab"));
emit undoAvailable(true);
......@@ -234,7 +260,7 @@ void KonqUndoManager::updateSupportsFileUndo(bool enable)
void KonqUndoManager::clearClosedItemsList()
{
// normally we only DELETE tab items! So we can't do this anymore:
// we only DELETE tab items! So we can't do this anymore:
// qDeleteAll(m_closedItemList);
QList<KonqClosedItem *>::iterator it = m_closedItemList.begin();
for (; it != m_closedItemList.end(); ++it)
......@@ -242,8 +268,8 @@ void KonqUndoManager::clearClosedItemsList()
KonqClosedItem *closedItem = *it;
const KonqClosedTabItem* closedTabItem =
dynamic_cast<const KonqClosedTabItem *>(closedItem);
const KonqClosedWindowItem* closedWindowItem =
dynamic_cast<const KonqClosedWindowItem *>(closedItem);
// const KonqClosedWindowItem* closedWindowItem =
// dynamic_cast<const KonqClosedWindowItem *>(closedItem);
m_closedItemList.erase(it);
if(closedTabItem)
......@@ -261,6 +287,7 @@ void KonqUndoManager::undoLastClosedItem()
KonqUndoManagerCommunicator::KonqUndoManagerCommunicator()
{
QTimer::singleShot(0, this, SLOT(readSettings()));
}
KonqUndoManagerCommunicator::~KonqUndoManagerCommunicator()
......@@ -275,6 +302,18 @@ KonqUndoManagerCommunicator *KonqUndoManagerCommunicator::self()
void KonqUndoManagerCommunicator::addClosedWindowItem(KonqUndoManager
*real_sender, KonqClosedWindowItem *closedWindowItem)
{
// If we are off the limit, remove the last closed window item
if(myKonqUndoManagerCommunicatorPrivate->m_closedWindowItemList.size() >=
maxNumClosedItems())
{
QList<KonqClosedWindowItem *> &closedWindowItemList =
myKonqUndoManagerCommunicatorPrivate->m_closedWindowItemList;
KonqClosedWindowItem* last = closedWindowItemList.last();
emit removeWindowInOtherInstances(0L, last);
closedWindowItemList.removeLast();
delete last;
}
myKonqUndoManagerCommunicatorPrivate->m_closedWindowItemList.prepend(closedWindowItem);
emit addWindowInOtherInstances(real_sender, closedWindowItem);
}
......@@ -298,3 +337,34 @@ const QList<KonqClosedWindowItem *>& KonqUndoManagerCommunicator::closedWindowIt
{
return myKonqUndoManagerCommunicatorPrivate->m_closedWindowItemList;
}
int KonqUndoManagerCommunicator::maxNumClosedItems()
{
return myKonqUndoManagerCommunicatorPrivate->m_maxNumClosedItems;
}
void KonqUndoManagerCommunicator::setMaxNumClosedItems(int max)
{
myKonqUndoManagerCommunicatorPrivate->m_maxNumClosedItems = qMax(1, max);
}
void KonqUndoManagerCommunicator::readSettings(bool global)
{
KSharedConfigPtr config;
if (global)
config = KGlobal::config();
else
config = KSharedConfig::openConfig("konquerorrc");
KConfigGroup configGroup( config, "UndoManagerSettings");
myKonqUndoManagerCommunicatorPrivate->m_maxNumClosedItems = configGroup.readEntry("Maximum number of Closed Items", 20 );
myKonqUndoManagerCommunicatorPrivate->m_maxNumClosedItems = qMax(1, myKonqUndoManagerCommunicatorPrivate->m_maxNumClosedItems);
}
void KonqUndoManagerCommunicator::applySettings()
{
KConfigGroup configGroup(KSharedConfig::openConfig("konquerorrc"), "UndoManagerSettings");
configGroup.writeEntry("Value youngerThan", myKonqUndoManagerCommunicatorPrivate->m_maxNumClosedItems );
}
......@@ -61,7 +61,8 @@ public Q_SLOTS:
* menu (by emitting openClosedTab/Window), and takes it from the list.
*/
void slotClosedItemsActivated(QAction* action);
void slotAddClosedWindowItem(KonqUndoManager *real_sender, KonqClosedWindowItem *closedWindowItem);
void slotAddClosedWindowItem(KonqUndoManager *real_sender,
KonqClosedWindowItem *closedWindowItem);
Q_SIGNALS:
void undoAvailable(bool canUndo);
......@@ -76,9 +77,10 @@ Q_SIGNALS:
/// Emitted to be received in other window instances, uing the singleton
/// communicator
void removeWindowInOtherInstances(KonqUndoManager *real_sender, const KonqClosedWindowItem
*closedWindowItem);
void addWindowInOtherInstances(KonqUndoManager *real_sender, KonqClosedWindowItem *closedWindowItem);
void removeWindowInOtherInstances(KonqUndoManager *real_sender, const
KonqClosedWindowItem *closedWindowItem);
void addWindowInOtherInstances(KonqUndoManager *real_sender,
KonqClosedWindowItem *closedWindowItem);
private Q_SLOTS:
void slotFileUndoAvailable(bool);
void slotFileUndoTextChanged(const QString& text);
......@@ -87,7 +89,8 @@ private Q_SLOTS:
* Received from other window instances, removes/adds a reference of a
* window from m_closedItemList.
*/
void slotRemoveClosedWindowItem(KonqUndoManager *real_sender, const KonqClosedWindowItem *closedWindowItem);
void slotRemoveClosedWindowItem(KonqUndoManager *real_sender, const
KonqClosedWindowItem *closedWindowItem);
private:
/// Fill the m_closedItemList with closed windows
void populate();
......@@ -107,13 +110,20 @@ public:
friend class KonqUndoManagerCommunicatorPrivate;
static KonqUndoManagerCommunicator *self();
const QList<KonqClosedWindowItem *>& closedWindowItemList();
void addClosedWindowItem(KonqUndoManager *real_sender, KonqClosedWindowItem *closedWindowItem);
void removeClosedWindowItem(KonqUndoManager *real_sender, const KonqClosedWindowItem
*closedWindowItem);
void addClosedWindowItem(KonqUndoManager *real_sender, KonqClosedWindowItem
*closedWindowItem);
void removeClosedWindowItem(KonqUndoManager *real_sender, const
KonqClosedWindowItem *closedWindowItem);
void applySettings();
int maxNumClosedItems();
void setMaxNumClosedItems(int max);
public Q_SLOTS:
void readSettings(bool global = false);
Q_SIGNALS:
void addWindowInOtherInstances(KonqUndoManager *real_sender, KonqClosedWindowItem *closedWindowItem);
void removeWindowInOtherInstances(KonqUndoManager *real_sender, const KonqClosedWindowItem
*closedWindowItem);
void addWindowInOtherInstances(KonqUndoManager *real_sender,
KonqClosedWindowItem *closedWindowItem);
void removeWindowInOtherInstances(KonqUndoManager *real_sender, const
KonqClosedWindowItem *closedWindowItem);
private:
KonqUndoManagerCommunicator();
virtual ~KonqUndoManagerCommunicator();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment