mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-20 02:36:34 +01:00
ClosedWindowsManager: Save closed windows into session file
This commit is contained in:
parent
0b6c555c62
commit
3f60c554ee
@ -442,6 +442,8 @@ void MainApplication::openSession(BrowserWindow* window, RestoreData &restoreDat
|
||||
window->restoreWindow(data);
|
||||
}
|
||||
|
||||
m_closedWindowsManager->restoreState(restoreData.closedWindows);
|
||||
|
||||
restoreOverrideCursor();
|
||||
}
|
||||
|
||||
@ -741,6 +743,8 @@ QByteArray MainApplication::saveState() const
|
||||
stream << m_restoreManager->restoreData();
|
||||
}
|
||||
|
||||
restoreData.closedWindows = m_closedWindowsManager->saveState();
|
||||
|
||||
QByteArray data;
|
||||
QDataStream stream(&data, QIODevice::WriteOnly);
|
||||
|
||||
|
@ -22,7 +22,7 @@
|
||||
|
||||
#include <QFile>
|
||||
|
||||
static const int restoreDataVersion = 1;
|
||||
static const int restoreDataVersion = 2;
|
||||
|
||||
bool RestoreData::isValid() const
|
||||
{
|
||||
@ -43,6 +43,7 @@ QDataStream &operator<<(QDataStream &stream, const RestoreData &data)
|
||||
|
||||
stream << restoreDataVersion;
|
||||
stream << data.crashedSession;
|
||||
stream << data.closedWindows;
|
||||
|
||||
return stream;
|
||||
}
|
||||
@ -66,6 +67,10 @@ QDataStream &operator>>(QDataStream &stream, RestoreData &data)
|
||||
stream >> data.crashedSession;
|
||||
}
|
||||
|
||||
if (version >= 2) {
|
||||
stream >> data.closedWindows;
|
||||
}
|
||||
|
||||
return stream;
|
||||
}
|
||||
|
||||
|
@ -29,6 +29,7 @@ struct QUPZILLA_EXPORT RestoreData
|
||||
{
|
||||
QVector<BrowserWindow::SavedWindow> windows;
|
||||
QByteArray crashedSession;
|
||||
QByteArray closedWindows;
|
||||
|
||||
bool isValid() const;
|
||||
void clear();
|
||||
|
@ -39,7 +39,7 @@ QVector<ClosedWindowsManager::Window> ClosedWindowsManager::closedWindows() cons
|
||||
|
||||
void ClosedWindowsManager::saveWindow(BrowserWindow *window)
|
||||
{
|
||||
if (mApp->isPrivate() || !window->weView()) {
|
||||
if (mApp->isPrivate() || mApp->windowCount() == 1 || !window->weView()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -97,3 +97,49 @@ void ClosedWindowsManager::clearClosedWindows()
|
||||
{
|
||||
m_closedWindows.clear();
|
||||
}
|
||||
|
||||
static const int closedWindowsVersion = 1;
|
||||
|
||||
QByteArray ClosedWindowsManager::saveState() const
|
||||
{
|
||||
QByteArray data;
|
||||
QDataStream stream(&data, QIODevice::WriteOnly);
|
||||
|
||||
stream << closedWindowsVersion;
|
||||
stream << m_closedWindows.count();
|
||||
|
||||
for (const Window &window : qAsConst(m_closedWindows)) {
|
||||
stream << window.windowState;
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
void ClosedWindowsManager::restoreState(const QByteArray &state)
|
||||
{
|
||||
QDataStream stream(state);
|
||||
|
||||
int version;
|
||||
stream >> version;
|
||||
|
||||
if (version < 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_closedWindows.clear();
|
||||
|
||||
int windowCount;
|
||||
stream >> windowCount;
|
||||
m_closedWindows.reserve(windowCount);
|
||||
|
||||
for (int i = 0; i < windowCount; ++i) {
|
||||
Window window;
|
||||
stream >> window.windowState;
|
||||
if (!window.isValid()) {
|
||||
continue;
|
||||
}
|
||||
window.icon = window.windowState.tabs.at(0).icon;
|
||||
window.title = window.windowState.tabs.at(0).title;
|
||||
m_closedWindows.append(window);
|
||||
}
|
||||
}
|
||||
|
@ -50,6 +50,9 @@ public:
|
||||
// Takes window at given index
|
||||
Window takeClosedWindowAt(int index);
|
||||
|
||||
QByteArray saveState() const;
|
||||
void restoreState(const QByteArray &state);
|
||||
|
||||
public slots:
|
||||
void restoreClosedWindow();
|
||||
void restoreAllClosedWindows();
|
||||
|
Loading…
Reference in New Issue
Block a user