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

Multiple bugfixes in konqueror undo closed window feature:

 * Now it works again with multiple processes *sight*. Stopped working when we moved to memory storage, so basically we go back and use again file storage for closed windows. Rename the config file var again from "memoryStorage" to "Storage".
 * Now we only remove the temporary files storing closed windows of each process when we are the only process left and we're exiting. Otherwise, another process might try later on to reopen a window of a now inexistant process and find that the file has been erased.
 * Everytime we change the closed windows list, like when we clean it or reopen a window, save it to disk or otherwise if a new konqueror process is launched it will read an outdated list of closed windows and that's not what we want.
 * Read correctly the remote closed windows, we were trying to open an incorrect filename in "appdata" but it's in "tmp". Have you got a dir called "tmp" in $KDEHOME/share/apps/konqueror ? My fault :P.


svn path=/trunk/KDE/kdebase/apps/; revision=985413
parent 9b2be265
......@@ -142,9 +142,7 @@ void KonqClosedRemoteWindowItem::readConfig() const
if(m_remoteConfig || m_remoteConfigGroup)
return;
m_remoteConfig = new KConfig(
KStandardDirs::locateLocal("appdata", m_remoteConfigFileName),
KConfig::SimpleConfig, "appdata");
m_remoteConfig = new KConfig( m_remoteConfigFileName, KConfig::SimpleConfig, "tmp");
m_remoteConfigGroup = new KConfigGroup(m_remoteConfig, m_remoteGroupName);
kDebug();
}
......
......@@ -47,8 +47,6 @@ K_GLOBAL_STATIC(KonqClosedWindowsManagerPrivate, myKonqClosedWindowsManagerPriva
KonqClosedWindowsManager::KonqClosedWindowsManager()
{
//qDBusRegisterMetaType<QList<QVariant> >();
new KonqClosedWindowsManagerAdaptor ( this );
const QString dbusPath = "/KonqUndoManager";
......@@ -68,7 +66,7 @@ KonqClosedWindowsManager::KonqClosedWindowsManager()
m_konqClosedItemsConfig = 0L;
m_blockClosedItems = false;
m_konqClosedItemsMemoryStore = new KConfig(QString(), KConfig::SimpleConfig);
m_konqClosedItemsStore = new KConfig(filename, KConfig::SimpleConfig, "tmp");
}
KonqClosedWindowsManager::~KonqClosedWindowsManager()
......@@ -77,12 +75,12 @@ KonqClosedWindowsManager::~KonqClosedWindowsManager()
removeClosedItemsConfigFiles();
delete m_konqClosedItemsConfig;
delete m_konqClosedItemsMemoryStore;
delete m_konqClosedItemsStore;
}
KConfig* KonqClosedWindowsManager::memoryStore()
{
return m_konqClosedItemsMemoryStore;
return m_konqClosedItemsStore;
}
KonqClosedWindowsManager *KonqClosedWindowsManager::self()
......@@ -126,7 +124,7 @@ void KonqClosedWindowsManager::addClosedWindowItem(KonqUndoManager
// we need to call to saveConfig() to keep updated the kconfig file, so
// that new konqueror instances can read it correctly updated.
saveConfig();
// Once saved, tell to other konqi processes
emitNotifyClosedWindowItem(closedWindowItem);
}
......@@ -182,11 +180,15 @@ bool isSenderOfSignal( const QString& service )
}
void KonqClosedWindowsManager::emitNotifyClosedWindowItem(
const KonqClosedWindowItem *closedWindowItem)
const KonqClosedWindowItem *closedWindowItem)
{
QString filename = "closeditems/" + KonqMisc::encodeFilename(QDBusConnection::sessionBus().baseService());
QString file = KStandardDirs::locateLocal("tmp", filename);
emit notifyClosedWindowItem( closedWindowItem->title(),
closedWindowItem->numTabs(),
closedWindowItem->configGroup().config()->name(),
m_konqClosedItemsStore->name(),
closedWindowItem->configGroup().name() );
}
......@@ -297,8 +299,41 @@ KonqClosedWindowItem* KonqClosedWindowsManager::findClosedLocalWindowItem(
return closedWindowItem;
}
/**
* @returns the number of konqueror processes by counting the number of
* org.kde.konqueror services in dbus.
*
* If dbus fails it returns -1.
*/
static int numberOfKonquerorProcesses()
{
QDBusConnection dbus = QDBusConnection::sessionBus();
QDBusReply<QStringList> reply = dbus.interface()->registeredServiceNames();
if ( !reply.isValid() )
return -1;
const QStringList allServices = reply;
int count = 0; // count the number of running konqueror processes. Should be at least one, us.
for ( QStringList::const_iterator it = allServices.begin(), end = allServices.end() ; it != end ; ++it ) {
const QString service = *it;
if ( service.startsWith( "org.kde.konqueror" ) ) {
count++;
}
}
return count;
}
void KonqClosedWindowsManager::removeClosedItemsConfigFiles()
{
// We'll only remove closed items config files if we are the only process
// left or if dbus fails (just in case there is any other konqi process
// but we couldn't see it).
int count = numberOfKonquerorProcesses();
if(count > 1 || count == -1)
return;
// We are the only instance of konqueror left and thus we can safely remove
// all those temporary files.
QString dir = KStandardDirs::locateLocal("tmp", "closeditems/");
QDBusConnectionInterface *idbus = QDBusConnection::sessionBus().interface();
QDirIterator it(dir, QDir::Writable|QDir::Files);
......@@ -311,7 +346,6 @@ void KonqClosedWindowsManager::removeClosedItemsConfigFiles()
}
}
void KonqClosedWindowsManager::saveConfig()
{
readConfig();
......@@ -339,6 +373,10 @@ void KonqClosedWindowsManager::saveConfig()
KConfigGroup configGroup(KGlobal::config(), "Undo");
configGroup.writeEntry("Number of Closed Windows", m_closedWindowItemList.size());
configGroup.sync();
// Finally the most important thing, which is to save the store config
// so that other konqi processes can reopen windows closed in this process.
m_konqClosedItemsStore->sync();
delete config;
}
......
......@@ -113,13 +113,15 @@ private:
const QString& configGroup);
/**
* This function removes all the closed items temporary files.
* This function removes all the closed items temporary files. Only done if
* there's no other konqueror process running than us, otherwise that process
* might want to use that temporary file.
*/
void removeClosedItemsConfigFiles();
private:
QList<KonqClosedWindowItem *> m_closedWindowItemList;
int m_numUndoClosedItems;
KConfig *m_konqClosedItemsConfig, *m_konqClosedItemsMemoryStore;
KConfig *m_konqClosedItemsConfig, *m_konqClosedItemsStore;
int m_maxNumClosedItems;
/**
* This bool var is used internally to allow delayed initialization of the
......
......@@ -215,6 +215,9 @@ void KonqUndoManager::undoClosedItem(int index)
emit openClosedWindow(*closedWindowItem);
KonqClosedWindowsManager::self()->removeClosedWindowItem(this, closedWindowItem);
closedWindowItem->configGroup().deleteGroup();
// Save config so that this window won't appear in new konqueror processes
KonqClosedWindowsManager::self()->saveConfig();
}
delete closedItem;
emit undoAvailable(this->undoAvailable());
......@@ -273,8 +276,6 @@ void KonqUndoManager::updateSupportsFileUndo(bool enable)
void KonqUndoManager::clearClosedItemsList(bool onlyInthisWindow)
{
populate();
// 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)
{
......@@ -292,8 +293,12 @@ void KonqUndoManager::clearClosedItemsList(bool onlyInthisWindow)
delete closedWindowItem;
}
}
emit closedItemsListChanged();
emit undoAvailable(this->undoAvailable());
// Save config so that this window won't appear in new konqueror processes
KonqClosedWindowsManager::self()->saveConfig();
}
void KonqUndoManager::undoLastClosedItem()
......
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