Commit e23337ba authored by David Faure's avatar David Faure
Browse files

start to un-singletonize KonqClosedWindowsManager, to fix konqviewtest

parent bfbaab30
......@@ -22,6 +22,7 @@
#include <QSignalSpy>
#include <konqundomanager.h>
#include <konqsessionmanager.h>
#include <konqclosedwindowsmanager.h>
class UndoManagerTest : public QObject
{
......@@ -31,6 +32,9 @@ private Q_SLOTS:
void initTestCase();
void testAddClosedTabItem();
void testUndoLastClosedTab();
private:
KonqClosedWindowsManager m_cwManager;
};
QTEST_MAIN(UndoManagerTest)
......@@ -40,7 +44,7 @@ void UndoManagerTest::initTestCase()
// Make sure we start clean
QStandardPaths::setTestModeEnabled(true);
KonqSessionManager::self()->disableAutosave();
KonqUndoManager manager(nullptr);
KonqUndoManager manager(&m_cwManager, nullptr);
QSignalSpy spyUndoAvailable(&manager, SIGNAL(undoAvailable(bool)));
QVERIFY(spyUndoAvailable.isValid());
manager.clearClosedItemsList();
......@@ -51,9 +55,10 @@ void UndoManagerTest::initTestCase()
void UndoManagerTest::testAddClosedTabItem()
{
KonqUndoManager manager(nullptr);
KonqUndoManager manager(&m_cwManager, nullptr);
QVERIFY(!manager.undoAvailable());
KonqClosedTabItem *item = new KonqClosedTabItem(QStringLiteral("url"), QStringLiteral("title"), 0, manager.newCommandSerialNumber());
KonqClosedTabItem *item = new KonqClosedTabItem(QStringLiteral("url"), m_cwManager.memoryStore(),
QStringLiteral("title"), 0, manager.newCommandSerialNumber());
QCOMPARE(item->url(), QString("url"));
QCOMPARE(item->serialNumber(), quint64(1001));
QCOMPARE(item->pos(), 0);
......
......@@ -47,8 +47,8 @@ public:
Q_GLOBAL_STATIC(KonqIcon, s_lightIconImage)
KonqClosedItem::KonqClosedItem(const QString &title, const QString &group, quint64 serialNumber)
: m_title(title), m_configGroup(KonqClosedWindowsManager::self()->memoryStore(), group), m_serialNumber(serialNumber)
KonqClosedItem::KonqClosedItem(const QString &title, KConfig *config, const QString &group, quint64 serialNumber)
: m_title(title), m_configGroup(config, group), m_serialNumber(serialNumber)
{
}
......@@ -58,8 +58,8 @@ KonqClosedItem::~KonqClosedItem()
m_configGroup.deleteGroup();
}
KonqClosedTabItem::KonqClosedTabItem(const QString &url, const QString &title, int pos, quint64 serialNumber)
: KonqClosedItem(title, "Closed_Tab" + QString::number(reinterpret_cast<qint64>(this)), serialNumber), m_url(url), m_pos(pos)
KonqClosedTabItem::KonqClosedTabItem(const QString &url, KConfig *config, const QString &title, int pos, quint64 serialNumber)
: KonqClosedItem(title, config, "Closed_Tab" + QString::number(reinterpret_cast<qint64>(this)), serialNumber), m_url(url), m_pos(pos)
{
qCDebug(KONQUEROR_LOG) << m_configGroup.name();
}
......@@ -75,8 +75,8 @@ QPixmap KonqClosedTabItem::icon() const
return KonqPixmapProvider::self()->pixmapFor(m_url, KIconLoader::SizeSmall);
}
KonqClosedWindowItem::KonqClosedWindowItem(const QString &title, quint64 serialNumber, int numTabs)
: KonqClosedItem(title, "Closed_Window" + QString::number(reinterpret_cast<qint64>(this)), serialNumber), m_numTabs(numTabs)
KonqClosedWindowItem::KonqClosedWindowItem(const QString &title, KConfig *config, quint64 serialNumber, int numTabs)
: KonqClosedItem(title, config, "Closed_Window" + QString::number(reinterpret_cast<qint64>(this)), serialNumber), m_numTabs(numTabs)
{
qCDebug(KONQUEROR_LOG) << m_configGroup.name();
}
......@@ -117,10 +117,10 @@ int KonqClosedWindowItem::numTabs() const
return m_numTabs;
}
KonqClosedRemoteWindowItem::KonqClosedRemoteWindowItem(const QString &title,
KonqClosedRemoteWindowItem::KonqClosedRemoteWindowItem(const QString &title, KConfig *config,
const QString &groupName, const QString &configFileName, quint64 serialNumber,
int numTabs, const QString &dbusService)
: KonqClosedWindowItem(title, serialNumber, numTabs),
: KonqClosedWindowItem(title, config, serialNumber, numTabs),
m_remoteGroupName(groupName), m_remoteConfigFileName(configFileName),
m_dbusService(dbusService), m_remoteConfigGroup(nullptr), m_remoteConfig(nullptr)
{
......
......@@ -50,7 +50,7 @@ public:
virtual QPixmap icon() const = 0;
protected:
KonqClosedItem(const QString &title, const QString &group, quint64 serialNumber);
KonqClosedItem(const QString &title, KConfig *config, const QString &group, quint64 serialNumber);
QString m_title;
KConfigGroup m_configGroup;
quint64 m_serialNumber;
......@@ -63,7 +63,7 @@ protected:
class KONQ_TESTS_EXPORT KonqClosedTabItem : public KonqClosedItem
{
public:
KonqClosedTabItem(const QString &url, const QString &title, int index, quint64 serialNumber);
KonqClosedTabItem(const QString &url, KConfig *config, const QString &title, int index, quint64 serialNumber);
~KonqClosedTabItem() override;
QPixmap icon() const override;
QString url() const
......@@ -88,7 +88,7 @@ protected:
class KONQ_TESTS_EXPORT KonqClosedWindowItem : public KonqClosedItem
{
public:
KonqClosedWindowItem(const QString &title, quint64 serialNumber, int numTabs);
KonqClosedWindowItem(const QString &title, KConfig *config, quint64 serialNumber, int numTabs);
~KonqClosedWindowItem() override;
QPixmap icon() const override;
int numTabs() const;
......@@ -100,7 +100,7 @@ protected:
class KONQ_TESTS_EXPORT KonqClosedRemoteWindowItem : public KonqClosedWindowItem
{
public:
KonqClosedRemoteWindowItem(const QString &title, const QString &groupName, const QString &configFileName, quint64 serialNumber, int numTabs, const QString &dbusService);
KonqClosedRemoteWindowItem(const QString &title, KConfig *config, const QString &groupName, const QString &configFileName, quint64 serialNumber, int numTabs, const QString &dbusService);
~KonqClosedRemoteWindowItem() override;
KConfigGroup &configGroup() override;
const KConfigGroup &configGroup() const override;
......
......@@ -213,7 +213,7 @@ void KonqClosedWindowsManager::slotNotifyClosedWindowItem(
// Create a new ClosedWindowItem and add it to the list
KonqClosedWindowItem *closedWindowItem = new KonqClosedRemoteWindowItem(
title, configGroup, configFileName,
title, memoryStore(), configGroup, configFileName,
KIO::FileUndoManager::self()->newCommandSerialNumber(), numTabs,
service);
......@@ -415,7 +415,7 @@ void KonqClosedWindowsManager ::readConfig()
int numTabs = configGroup.readEntry("numTabs", 0);
KonqClosedWindowItem *closedWindowItem = new KonqClosedWindowItem(
title, i, numTabs);
title, memoryStore(), i, numTabs);
configGroup.copyTo(&closedWindowItem->configGroup());
configGroup.writeEntry("foo", 0);
......
......@@ -46,6 +46,9 @@ class KONQ_TESTS_EXPORT KonqClosedWindowsManager : public QObject
public:
friend class KonqClosedWindowsManagerPrivate;
KonqClosedWindowsManager();
~KonqClosedWindowsManager() override;
static KonqClosedWindowsManager *self();
const QList<KonqClosedWindowItem *> &closedWindowItemList();
......@@ -102,9 +105,6 @@ Q_SIGNALS:
void removeWindowInOtherInstances(KonqUndoManager *real_sender, const
KonqClosedWindowItem *closedWindowItem);
private:
KonqClosedWindowsManager();
~KonqClosedWindowsManager() override;
KonqClosedRemoteWindowItem *findClosedRemoteWindowItem(const QString &configFileName,
const QString &configGroup);
......
......@@ -255,7 +255,7 @@ KonqMainWindow::KonqMainWindow(const QUrl &initialURL)
connect(prov, SIGNAL(changed()), SLOT(slotIconsChanged()));
m_pUndoManager = new KonqUndoManager(this);
m_pUndoManager = new KonqUndoManager(KonqClosedWindowsManager::self(), this);
connect(m_pUndoManager, SIGNAL(undoAvailable(bool)),
this, SLOT(slotUndoAvailable(bool)));
......@@ -4974,7 +4974,8 @@ void KonqMainWindow::addClosedWindowToUndoList()
}
// 2. Create the KonqClosedWindowItem and save its config
KonqClosedWindowItem *closedWindowItem = new KonqClosedWindowItem(title, m_pUndoManager->newCommandSerialNumber(), numTabs);
KonqClosedWindowItem *closedWindowItem = new KonqClosedWindowItem(title, KonqClosedWindowsManager::self()->memoryStore(),
m_pUndoManager->newCommandSerialNumber(), numTabs);
saveProperties(closedWindowItem->configGroup());
// 3. Add the KonqClosedWindowItem to the undo list
......@@ -5038,7 +5039,8 @@ void KonqMainWindow::slotAddClosedUrl(KonqFrameBase *tab)
// Now we get the position of the tab
const int index = m_pViewManager->tabContainer()->childFrameList().indexOf(tab);
KonqClosedTabItem *closedTabItem = new KonqClosedTabItem(url, title, index, m_pUndoManager->newCommandSerialNumber());
KonqClosedTabItem *closedTabItem = new KonqClosedTabItem(url, KonqClosedWindowsManager::self()->memoryStore(),
title, index, m_pUndoManager->newCommandSerialNumber());
QString prefix = KonqFrameBase::frameTypeToString(tab->frameType()) + QString::number(0);
closedTabItem->configGroup().writeEntry("RootItem", prefix);
......
......@@ -27,21 +27,18 @@
#include "konqdebug.h"
#include <KLocalizedString>
KonqUndoManager::KonqUndoManager(QWidget *parent)
: QObject(parent)
KonqUndoManager::KonqUndoManager(KonqClosedWindowsManager *cwManager, QWidget *parent)
: QObject(parent), m_cwManager(cwManager)
{
connect(KIO::FileUndoManager::self(), SIGNAL(undoAvailable(bool)),
this, SLOT(slotFileUndoAvailable(bool)));
connect(KIO::FileUndoManager::self(), SIGNAL(undoTextChanged(QString)),
this, SLOT(slotFileUndoTextChanged(QString)));
connect(KonqClosedWindowsManager::self(),
SIGNAL(addWindowInOtherInstances(KonqUndoManager*,KonqClosedWindowItem*)), this,
SLOT(slotAddClosedWindowItem(KonqUndoManager*,KonqClosedWindowItem*)));
connect(KonqClosedWindowsManager::self(),
SIGNAL(removeWindowInOtherInstances(KonqUndoManager*,const KonqClosedWindowItem*)), this,
SLOT(slotRemoveClosedWindowItem(KonqUndoManager*,const KonqClosedWindowItem*)));
m_populated = false;
connect(m_cwManager, SIGNAL(addWindowInOtherInstances(KonqUndoManager*,KonqClosedWindowItem*)),
this, SLOT(slotAddClosedWindowItem(KonqUndoManager*,KonqClosedWindowItem*)));
connect(m_cwManager, SIGNAL(removeWindowInOtherInstances(KonqUndoManager*,const KonqClosedWindowItem*)),
this, SLOT(slotRemoveClosedWindowItem(KonqUndoManager*,const KonqClosedWindowItem*)));
}
KonqUndoManager::~KonqUndoManager()
......@@ -51,12 +48,10 @@ KonqUndoManager::~KonqUndoManager()
disconnect(KIO::FileUndoManager::self(), SIGNAL(undoTextChanged(QString)),
this, SLOT(slotFileUndoTextChanged(QString)));
disconnect(KonqClosedWindowsManager::self(),
SIGNAL(addWindowInOtherInstances(KonqUndoManager*,KonqClosedWindowItem*)), this,
SLOT(slotAddClosedWindowItem(KonqUndoManager*,KonqClosedWindowItem*)));
disconnect(KonqClosedWindowsManager::self(),
SIGNAL(removeWindowInOtherInstances(KonqUndoManager*,const KonqClosedWindowItem*)), this,
SLOT(slotRemoveClosedWindowItem(KonqUndoManager*,const KonqClosedWindowItem*)));
disconnect(m_cwManager, SIGNAL(addWindowInOtherInstances(KonqUndoManager*,KonqClosedWindowItem*)),
this, SLOT(slotAddClosedWindowItem(KonqUndoManager*,KonqClosedWindowItem*)));
disconnect(m_cwManager, SIGNAL(removeWindowInOtherInstances(KonqUndoManager*,const KonqClosedWindowItem*)),
this, SLOT(slotRemoveClosedWindowItem(KonqUndoManager*,const KonqClosedWindowItem*)));
// Clear the closed item lists but only remove closed windows items
// in this window
......@@ -71,7 +66,7 @@ void KonqUndoManager::populate()
m_populated = true;
const QList<KonqClosedWindowItem *> closedWindowItemList =
KonqClosedWindowsManager::self()->closedWindowItemList();
m_cwManager->closedWindowItemList();
QListIterator<KonqClosedWindowItem *> i(closedWindowItemList);
......@@ -90,7 +85,7 @@ void KonqUndoManager::slotFileUndoAvailable(bool)
bool KonqUndoManager::undoAvailable() const
{
if (!m_closedItemList.isEmpty() || KonqClosedWindowsManager::self()->undoAvailable()) {
if (!m_closedItemList.isEmpty() || m_cwManager->undoAvailable()) {
return true;
} else {
return (m_supportsFileUndo && KIO::FileUndoManager::self()->undoAvailable());
......@@ -117,7 +112,7 @@ QString KonqUndoManager::undoText() const
return KIO::FileUndoManager::self()->undoText();
}
else if (KonqClosedWindowsManager::self()->undoAvailable()) {
else if (m_cwManager->undoAvailable()) {
return i18n("Und&o: Closed Window");
} else {
return i18n("Und&o");
......@@ -170,7 +165,7 @@ void KonqUndoManager::slotAddClosedWindowItem(KonqUndoManager *real_sender, Konq
void KonqUndoManager::addClosedWindowItem(KonqClosedWindowItem *closedWindowItem)
{
populate();
KonqClosedWindowsManager::self()->addClosedWindowItem(this, closedWindowItem);
m_cwManager->addClosedWindowItem(this, closedWindowItem);
}
void KonqUndoManager::slotRemoveClosedWindowItem(KonqUndoManager *real_sender, const KonqClosedWindowItem *closedWindowItem)
......@@ -181,7 +176,7 @@ void KonqUndoManager::slotRemoveClosedWindowItem(KonqUndoManager *real_sender, c
populate();
QList<KonqClosedItem *>::iterator it = qFind(m_closedItemList.begin(), m_closedItemList.end(), closedWindowItem);
QList<KonqClosedItem *>::iterator it = std::find(m_closedItemList.begin(), m_closedItemList.end(), closedWindowItem);
// If the item was found, remove it from the list
if (it != m_closedItemList.end()) {
......@@ -213,15 +208,15 @@ void KonqUndoManager::undoClosedItem(int index)
if (closedTabItem) {
emit openClosedTab(*closedTabItem);
} else if (closedRemoteWindowItem) {
KonqClosedWindowsManager::self()->removeClosedWindowItem(this, closedRemoteWindowItem);
m_cwManager->removeClosedWindowItem(this, closedRemoteWindowItem);
emit openClosedWindow(*closedRemoteWindowItem);
} else if (closedWindowItem) {
KonqClosedWindowsManager::self()->removeClosedWindowItem(this, closedWindowItem);
m_cwManager->removeClosedWindowItem(this, closedWindowItem);
emit openClosedWindow(*closedWindowItem);
closedWindowItem->configGroup().deleteGroup();
// Save config so that this window won't appear in new konqueror processes
KonqClosedWindowsManager::self()->saveConfig();
m_cwManager->saveConfig();
}
delete closedItem;
emit undoAvailable(this->undoAvailable());
......@@ -292,7 +287,7 @@ void KonqUndoManager::clearClosedItemsList(bool onlyInthisWindow)
if (closedTabItem) {
delete closedTabItem;
} else if (closedWindowItem && !onlyInthisWindow) {
KonqClosedWindowsManager::self()->removeClosedWindowItem(this, closedWindowItem, true);
m_cwManager->removeClosedWindowItem(this, closedWindowItem, true);
delete closedWindowItem;
}
}
......@@ -301,7 +296,7 @@ void KonqUndoManager::clearClosedItemsList(bool onlyInthisWindow)
emit undoAvailable(this->undoAvailable());
// Save config so that this window won't appear in new konqueror processes
KonqClosedWindowsManager::self()->saveConfig();
m_cwManager->saveConfig();
}
void KonqUndoManager::undoLastClosedItem()
......
......@@ -28,6 +28,7 @@
class KonqClosedWindowItem;
class KonqClosedTabItem;
class KonqClosedItem;
class KonqClosedWindowsManager;
class QAction;
/**
......@@ -43,7 +44,7 @@ public:
* Constructor
* @param parent the parent QObject, also used as the parent widget for KonqFileUndoManager::UiInterface.
*/
explicit KonqUndoManager(QWidget *parent);
explicit KonqUndoManager(KonqClosedWindowsManager *cwManager, QWidget *parent);
~KonqUndoManager() override;
bool undoAvailable() const;
......@@ -108,8 +109,9 @@ private:
void populate();
QList<KonqClosedItem *> m_closedItemList;
bool m_supportsFileUndo;
bool m_populated;
KonqClosedWindowsManager *m_cwManager;
bool m_supportsFileUndo = false;
bool m_populated = false;
};
#endif /* KONQUNDOMANAGER_H */
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