Commit 9a11564b authored by Eduardo Robles Elvira's avatar Eduardo Robles Elvira

Adding improving the closed window items support after having discussed the patch with David Faure.

    - Shared closed window items over D-Bus
    - Persistent closed window items by storing them in a config file or sharing them by D-Bus when there are other konqueror instances running

CCMAIL:kfm-devel@kde.org
CCMAIL:faure@kde.org



svn path=/trunk/KDE/kdebase/apps/; revision=794867
parent cc911f6b
......@@ -69,6 +69,9 @@ kde4_add_ui_files(konqueror_KDEINIT_SRCS konqprofiledlg_base.ui)
qt4_add_dbus_interface(konqueror_KDEINIT_SRCS org.kde.Konqueror.Main.xml konqueror_interface)
qt4_add_dbus_interface(konqueror_KDEINIT_SRCS ${KDE4_DBUS_INTERFACES_DIR}/org.kde.kded.xml kded_interface)
qt4_add_dbus_adaptor(konqueror_KDEINIT_SRCS org.kde.Konqueror.UndoManager.xml konqundomanager.h KonqClosedWindowsManager konqundomanageradaptor KonqClosedWindowsManagerAdaptor)
qt4_add_dbus_interface(konqueror_KDEINIT_SRCS org.kde.Konqueror.UndoManager.xml konqundomanager_interface)
kde4_add_kdeinit_executable(konqueror ${konqueror_KDEINIT_SRCS} konqmain.cpp)
kde4_add_app_icon(konqueror_KDEINIT_SRCS "${KDE4_ICON_INSTALL_DIR}/oxygen/*/apps/konqueror.png")
......
......@@ -19,6 +19,7 @@
*/
#include "konqcloseditem.h"
#include "konqundomanager.h"
#include <QFile>
#include <QFont>
#include <QFontMetrics>
......@@ -34,27 +35,6 @@
#include <kstandarddirs.h>
#include <unistd.h>
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;
};
class KonqIcon {
public:
KonqIcon()
......@@ -66,11 +46,10 @@ public:
QImage image;
};
K_GLOBAL_STATIC(KConfigNew, s_config)
K_GLOBAL_STATIC(KonqIcon, s_lightIconImage)
KonqClosedItem::KonqClosedItem(const QString& title, const QString& group, quint64 serialNumber)
: m_title(title), m_configGroup(s_config->config, group), m_serialNumber(serialNumber)
: m_title(title), m_configGroup(KonqClosedWindowsManager::self()->config(), group), m_serialNumber(serialNumber)
{
}
......@@ -92,7 +71,7 @@ KonqClosedTabItem::~KonqClosedTabItem()
kDebug(1202) << "deleted group" << m_configGroup.name();
}
QPixmap KonqClosedTabItem::icon() {
QPixmap KonqClosedTabItem::icon() const {
return KonqPixmapProvider::self()->pixmapFor(m_url);
}
......@@ -104,11 +83,12 @@ KonqClosedWindowItem::KonqClosedWindowItem(const QString& title, quint64 serialN
KonqClosedWindowItem::~KonqClosedWindowItem()
{
m_configGroup.deleteGroup();
kDebug(1202) << "deleted group" << m_configGroup.name();
// Do this manually when needed:
// m_configGroup.deleteGroup();
}
QPixmap KonqClosedWindowItem::icon() {
QPixmap KonqClosedWindowItem::icon() const
{
QImage overlayImg = s_lightIconImage->image.copy();
int oldWidth = overlayImg.width();
QString countStr = QString::number( m_numTabs );
......@@ -134,3 +114,56 @@ QPixmap KonqClosedWindowItem::icon() {
return QPixmap::fromImage(overlayImg);
}
int KonqClosedWindowItem::numTabs() const
{
return m_numTabs;
}
KonqClosedRemoteWindowItem::KonqClosedRemoteWindowItem(const QString& title,
const QString& groupName, const QString& configFileName, quint64 serialNumber,
int numTabs, const QString& dbusService)
: KonqClosedWindowItem(title, serialNumber, numTabs),
m_remoteGroupName(groupName), m_remoteConfigFileName(configFileName),
m_dbusService(dbusService), m_remoteConfigGroup(0L), m_remoteConfig(0L)
{
kDebug();
}
KonqClosedRemoteWindowItem::~KonqClosedRemoteWindowItem()
{
delete m_remoteConfigGroup;
delete m_remoteConfig;
}
void KonqClosedRemoteWindowItem::readConfig() const
{
// only do this once
if(m_remoteConfig || m_remoteConfigGroup)
return;
m_remoteConfig = new KConfig(
KStandardDirs::locateLocal("appdata", m_remoteConfigFileName),
KConfig::SimpleConfig, "appdata");
m_remoteConfigGroup = new KConfigGroup(m_remoteConfig, m_remoteGroupName);
kDebug();
}
const KConfigGroup& KonqClosedRemoteWindowItem::configGroup() const
{
readConfig();
return *m_remoteConfigGroup;
}
KConfigGroup& KonqClosedRemoteWindowItem::configGroup()
{
readConfig();
return *m_remoteConfigGroup;
}
bool KonqClosedRemoteWindowItem::equalsTo(const QString& groupName,
const QString& configFileName) const
{
return (m_remoteGroupName == groupName &&
m_remoteConfigFileName == configFileName);
}
......@@ -23,17 +23,20 @@
#include "konqprivate_export.h"
#include <kconfiggroup.h>
#include <QtDBus/QtDBus>
#include <QString>
#include <QImage>
class KConfig;
class KONQ_TESTS_EXPORT KonqClosedItem : public QObject {
public:
virtual ~KonqClosedItem();
const KConfigGroup& configGroup() const { return m_configGroup; }
KConfigGroup& configGroup() { return m_configGroup; }
virtual KConfigGroup& configGroup() { return m_configGroup; }
virtual const KConfigGroup& configGroup() const { return m_configGroup; }
quint64 serialNumber() const { return m_serialNumber; }
QString title() const { return m_title; }
virtual QPixmap icon() = 0;
virtual QPixmap icon() const = 0;
protected:
KonqClosedItem(const QString& title, const QString& group, quint64 serialNumber);
......@@ -50,7 +53,7 @@ class KONQ_TESTS_EXPORT KonqClosedTabItem : public KonqClosedItem {
public:
KonqClosedTabItem(const QString& url, const QString& title, int index, quint64 serialNumber);
virtual ~KonqClosedTabItem();
virtual QPixmap icon();
virtual QPixmap icon() const;
QString url() const { return m_url; }
/// The position inside the tabbar that the tab had when it was closed
int pos() const { return m_pos; }
......@@ -68,11 +71,37 @@ class KONQ_TESTS_EXPORT KonqClosedWindowItem : public KonqClosedItem {
public:
KonqClosedWindowItem(const QString& title, quint64 serialNumber, int numTabs);
virtual ~KonqClosedWindowItem();
virtual QPixmap icon();
virtual QPixmap icon() const;
int numTabs() const;
protected:
int m_numTabs;
};
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);
virtual ~KonqClosedRemoteWindowItem();
virtual KConfigGroup& configGroup();
virtual const KConfigGroup& configGroup() const;
bool equalsTo(const QString& groupName, const QString& configFileName) const;
QString dbusService() const { return m_dbusService; }
const QString& remoteGroupName() const { return m_remoteGroupName; }
const QString& remoteConfigFileName() const { return m_remoteConfigFileName; }
protected:
/**
* Actually reads the config file. Call to this function before calling to
* configGroup(). This function is const so that it can be called by
* configGroup() const. It's used to get delayed initialization so that
* we don't load the config file unless it's needed.
*/
void readConfig() const;
QString m_remoteGroupName;
QString m_remoteConfigFileName;
QString m_dbusService;
mutable KConfigGroup* m_remoteConfigGroup;
mutable KConfig* m_remoteConfig;
};
#endif /* KONQCLOSEDITEM_H */
......@@ -2895,7 +2895,7 @@ void KonqMainWindow::slotClosedItemsListAboutToShow()
QMenu* popup = m_paClosedItems->menu();
// Clear the menu and fill it with a maximum of s_closedTabsListLength number of urls
popup->clear();
QAction* clearAction = popup->addAction( i18n("Empty Closed Tabs History") );
QAction* clearAction = popup->addAction( i18n("Empty Closed Items History") );
connect(clearAction, SIGNAL(triggered()), m_undoManager, SLOT(clearClosedItemsList()));
popup->insertSeparator((QAction*)0);
......@@ -4994,10 +4994,7 @@ void KonqMainWindow::closeEvent( QCloseEvent *e )
// save size to have something to restore if the profile does not contain size
saveWindowSize();
// Save the window tabs so that we can restore it later, but only if there
// are other windows opened
if(s_konqMainWindowInstancesCount > 1)
addClosedWindowToUndoList();
addClosedWindowToUndoList();
hide();
qApp->flush();
......@@ -5040,7 +5037,11 @@ void KonqMainWindow::addClosedWindowToUndoList()
closedWindowItem->configGroup().writeEntry( "Height", height() );
closedWindowItem->configGroup().writeEntry( "FullScreen", fullScreenMode() );
tabContainer->saveConfig( closedWindowItem->configGroup(), prefix, flags, 0L, 0, 1);
// Save window settings
KConfigGroup cfg( &closedWindowItem->configGroup(), "Main Window Settings" );
saveMainWindowSettings( cfg );
closedWindowItem->configGroup().sync();
// 3. Finally add the KonqClosedWindowItem to the undo list
m_paClosedItems->setEnabled(true);
m_undoManager->addClosedWindowItem( closedWindowItem );
......
This diff is collapsed.
......@@ -21,12 +21,16 @@
#ifndef KONQUNDOMANAGER_H
#define KONQUNDOMANAGER_H
#include "konqprivate_export.h"
#include <QObject>
#include <QString>
#include <QList>
#include <kconfig.h>
#include "konqcloseditem.h"
#include "konqundomanager_interface.h"
class QAction;
class KonqUndoManagerCommunicatorPrivate;
class KonqClosedWindowsManagerPrivate;
class QDBusMessage;
/**
* Note that there is one KonqUndoManager per mainwindow.
* It integrates KonqFileUndoManager (undoing file operations)
......@@ -54,7 +58,7 @@ public:
public Q_SLOTS:
void undo();
void clearClosedItemsList();
void clearClosedItemsList(bool onlyInthisWindow = false);
void undoLastClosedItem();
/**
* Opens in a new tab/window the item the user selected from the closed tabs
......@@ -102,31 +106,157 @@ private:
/**
* Provides a shared singleton for all Konq window instances.
* This class is a singleton, use self() to access its only instance.
*
* - it synchronizes the closed window list with other
* Konqueror instances via DBUS.
*
* - When a konqueror instance is closed, the closed window list is written
* to disk so that the undo closed windows list can be retrieved even when
* no other konqueror instance is running.
*/
class KONQ_TESTS_EXPORT KonqUndoManagerCommunicator : public QObject
class KONQ_TESTS_EXPORT KonqClosedWindowsManager : public QObject
{
Q_OBJECT
public:
friend class KonqUndoManagerCommunicatorPrivate;
static KonqUndoManagerCommunicator *self();
friend class KonqClosedWindowsManagerPrivate;
static KonqClosedWindowsManager *self();
const QList<KonqClosedWindowItem *>& closedWindowItemList();
void addClosedWindowItem(KonqUndoManager *real_sender, KonqClosedWindowItem
*closedWindowItem);
*closedWindowItem, bool propagate = true);
void removeClosedWindowItem(KonqUndoManager *real_sender, const
KonqClosedWindowItem *closedWindowItem);
KonqClosedWindowItem *closedWindowItem, bool propagate = true);
void applySettings();
int maxNumClosedItems();
void setMaxNumClosedItems(int max);
KConfig* config();
public Q_SLOTS:
void readSettings();
/**
* Reads the list of closed window from the configuration file if it couldn't
* be retrieved from running konqueror windows
*/
void readConfig();
Q_SIGNALS:
/**
* Notifies the addition the closed window list in all the konqueror windows of
* this konqueror instance.
*/
void addWindowInOtherInstances(KonqUndoManager *real_sender,
KonqClosedWindowItem *closedWindowItem);
/**
* Notifies the removal the closed window list in all the konqueror windows of
* this konqueror instance.
*/
void removeWindowInOtherInstances(KonqUndoManager *real_sender, const
KonqClosedWindowItem *closedWindowItem);
KonqClosedWindowItem *closedWindowItem);
private:
KonqClosedWindowsManager();
virtual ~KonqClosedWindowsManager();
/**
* Called by readSettings(), which is called by a singleShot timer inside
* the constructor. Fills the closed window list with items from other
* konqueror instances, being the list retrieved via DBUS using the method
* localClosedWindowItems();
*
* It also sets a timer so that if no other konqueror instance pings back in
* X miliseconds, then the closed window list is read from disk.
*/
void populate();
/**
* Called by the destructor. Saves the closed windows list to disk inside a
* config file
*/
void saveConfig();
KonqClosedRemoteWindowItem* findClosedRemoteWindowItem(const QString& configFileName,
const QString& configGroup);
KonqClosedWindowItem* findClosedLocalWindowItem(const QString& configFileName,
const QString& configGroup);
/**
* This function removes all the files in appdata/closeditem/. Thus, it's
* used to clean the config files inside that directory.
*/
void removeClosedItemsConfigFiles();
private:
QList<KonqClosedWindowItem *> m_closedWindowItemList;
KConfig *m_konqClosedItemsConfig;
int m_maxNumClosedItems;
bool m_amIalone;
Q_SIGNALS: // DBUS signals
/**
* Every konqueror instance broadcasts new closed windows to other
* konqueror instances.
*/
void notifyClosedWindowItem( const QString& title, const int& numTabs,
const QString& configFileName, const QString& configGroup );
/**
* Every konqueror instance broadcasts removed closed windows to other
* konqueror instances.
*/
void notifyRemove( const QString& configFileName,
const QString& configGroup );
/**
* Ask over D-BUS to all running konqueror instances to return their list
* of local closed window items.
*/
void requestLocalClosedWindowItems();
public Q_SLOTS: // DBUS methods
/**
* This is the answer call when a konqueror instance receives a call from
* requestLocalClosedWindowItems().
*/
void localClosedWindowItems(const QList<QVariant>& windowItems,
const QString& dbusService);
/**
* This signal is received from other konqueror instances in order to let
* us know that there are other konqueror instances from which we can
* retrieve the list of closed window items, so that we don't need to read
* them from disk.
*/
void pong();
private Q_SLOTS:// connected to DBUS signals
void slotNotifyClosedWindowItem( const QString& title, const int& numTabs,
const QString& configFileName, const QString& configGroup,
const QString& service );
void slotNotifyClosedWindowItem( const QString& title, const int& numTabs,
const QString& configFileName, const QString& configGroup,
const QDBusMessage& msg );
void slotNotifyRemove( const QString& configFileName,
const QString& configGroup, const QDBusMessage& msg );
void slotRequestLocalClosedWindowItems( const QDBusMessage& msg );
private:
KonqUndoManagerCommunicator();
virtual ~KonqUndoManagerCommunicator();
void emitNotifyClosedWindowItem(const KonqClosedWindowItem *closedWindowItem);
void emitNotifyRemove(const KonqClosedWindowItem *closedWindowItem);
void emitPong(const QString & service);
};
#endif /* KONQUNDOMANAGER_H */
......
......@@ -358,9 +358,11 @@ void KonqViewManager::openClosedWindow(const KonqClosedWindowItem& closedWindowI
}
mainWindow->viewManager()->loadRootItem( closedWindowItem.configGroup(), mainWindow->viewManager()->tabContainer(), KUrl(), true, KUrl() );
// read window settings
mainWindow->applyMainWindowSettings( KConfigGroup( KGlobal::config(), "KonqMainWindow" ), true );
mainWindow->applyMainWindowSettings( KConfigGroup( & closedWindowItem.configGroup(), "Main Window Settings" ), true );
mainWindow->activateChild();
mainWindow->show();
kDebug(1202) << "done";
}
......
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node>
<interface name="org.kde.Konqueror.UndoManager">
<signal name="notifyClosedWindowItem">
<arg name="title" type="s" direction="out"/>
<arg name="numTabs" type="i" direction="out"/>
<arg name="configFileName" type="s" direction="out"/>
<arg name="configGroup" type="s" direction="out"/>
</signal>
<signal name="notifyRemove">
<arg name="configFileName" type="s" direction="out"/>
<arg name="configGroup" type="s" direction="out"/>
</signal>
<signal name="requestLocalClosedWindowItems">
</signal>
<method name="localClosedWindowItems">
<arg name="windowItems" type="av" direction="in"/>
<arg name="service" type="s" direction="in"/>
</method>
<method name="pong">
</method>
</interface>
</node>
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