From d519a1253e2064321e33a9d4d4071559c69b4e47 Mon Sep 17 00:00:00 2001 From: nowrep Date: Fri, 6 Dec 2013 21:26:07 +0100 Subject: [PATCH] [Sessions] Last 2 sessions are now backuped in profile directory. Closes #1100 --- CHANGELOG | 1 + src/lib/app/mainapplication.cpp | 24 ++++++++++++++++++++++++ src/lib/app/mainapplication.h | 1 + 3 files changed, 26 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index 75a4c7c4f..0cdef48ee 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -17,6 +17,7 @@ Version 1.5.0 * cancel upload when trying to upload non-readable files * select previous / next engines with ctrl+up/down in websearchbar * ask user first before closing all but the current tab from tabbar + * last 2 sessions are now backuped in profile directory * GreaseMonkey: added icon in statusbar * GreaseMonkey: added support for GM_Settings * GreaseMonkey: fixed userscripts when first loading plugin diff --git a/src/lib/app/mainapplication.cpp b/src/lib/app/mainapplication.cpp index 2692f988e..74be5074b 100644 --- a/src/lib/app/mainapplication.cpp +++ b/src/lib/app/mainapplication.cpp @@ -289,6 +289,9 @@ MainApplication::MainApplication(int &argc, char** argv) if (checkUpdates) { new Updater(qupzilla); } + + backupSavedSessions(); + if (m_startingAfterCrash || afterLaunch == 3) { m_restoreManager = new RestoreManager(m_activeProfil + "session.dat"); if (!m_restoreManager->isValid()) { @@ -763,6 +766,27 @@ void MainApplication::translateApp() installTranslator(sys); } +void MainApplication::backupSavedSessions() +{ + // session.dat - current + // session.dat.old - first backup + // session.dat.old1 - second backup + + const QString sessionFile = m_activeProfil + "session.dat"; + + if (!QFile::exists(sessionFile)) { + return; + } + + if (QFile::exists(sessionFile + ".old")) { + QFile::remove(sessionFile + ".old1"); + QFile::copy(sessionFile + ".old", sessionFile + ".old1"); + } + + QFile::remove(sessionFile + ".old"); + QFile::copy(sessionFile, sessionFile + ".old"); +} + void MainApplication::quitApplication() { if (m_downloadManager && !m_downloadManager->canClose()) { diff --git a/src/lib/app/mainapplication.h b/src/lib/app/mainapplication.h index 34ec03a2d..c15037772 100644 --- a/src/lib/app/mainapplication.h +++ b/src/lib/app/mainapplication.h @@ -163,6 +163,7 @@ private: void loadTheme(const QString &name); void translateApp(); void restoreOtherWindows(); + void backupSavedSessions(); QUrl userStyleSheet(const QString &filePath) const;