From a1ff0c0dc49f5832a20be21d3bd225b207c4bb9b Mon Sep 17 00:00:00 2001 From: nowrep Date: Fri, 20 Apr 2012 15:29:04 +0200 Subject: [PATCH] Saving state of Clear Private Data dialog --- src/lib/other/clearprivatedata.cpp | 83 ++++++++++++++++++++++++++++++ src/lib/other/clearprivatedata.h | 5 ++ 2 files changed, 88 insertions(+) diff --git a/src/lib/other/clearprivatedata.cpp b/src/lib/other/clearprivatedata.cpp index 6145ae06d..160575947 100644 --- a/src/lib/other/clearprivatedata.cpp +++ b/src/lib/other/clearprivatedata.cpp @@ -19,6 +19,7 @@ #include "qupzilla.h" #include "tabwidget.h" #include "cookiejar.h" +#include "settings.h" #include "mainapplication.h" #include "networkmanager.h" #include "clickablelabel.h" @@ -31,6 +32,7 @@ #include #include #include +#include ClearPrivateData::ClearPrivateData(QupZilla* mainClass, QWidget* parent) : QDialog(parent) @@ -45,6 +47,11 @@ ClearPrivateData::ClearPrivateData(QupZilla* mainClass, QWidget* parent) //Resizing +2 of sizeHint to get visible underlined link resize(sizeHint().width(), sizeHint().height() + 2); + + Settings settings; + settings.beginGroup("ClearPrivateData"); + restoreState(settings.value("state", QByteArray()).toByteArray()); + settings.endGroup(); } void ClearPrivateData::historyClicked(bool state) @@ -86,6 +93,16 @@ void ClearPrivateData::clearFlash() p_QupZilla->tabWidget()->addView(QUrl("http://www.macromedia.com/support/documentation/en/flashplayer/help/settings_manager07.html")); } +void ClearPrivateData::closeEvent(QCloseEvent* e) +{ + Settings settings; + settings.beginGroup("ClearPrivateData"); + settings.setValue("state", saveState()); + settings.endGroup(); + + e->accept(); +} + void ClearPrivateData::dialogAccepted() { QApplication::setOverrideCursor(Qt::WaitCursor); @@ -140,3 +157,69 @@ void ClearPrivateData::dialogAccepted() close(); } + +static const int stateDataVersion = 0x0001; + +void ClearPrivateData::restoreState(const QByteArray &state) +{ + QDataStream stream(state); + if (stream.atEnd()) { + return; + } + + int version = -1; + int historyIndex = -1; + bool databases = false; + bool localStorage = false; + bool cache = false; + bool cookies = false; + bool icons = false; + + stream >> version; + if (version != stateDataVersion) { + return; + } + + stream >> historyIndex; + stream >> databases; + stream >> localStorage; + stream >> cache; + stream >> cookies; + stream >> icons; + + if (historyIndex != -1) { + ui->history->setChecked(true); + ui->historyLength->setEnabled(true); + ui->historyLength->setCurrentIndex(historyIndex); + } + + ui->databases->setChecked(databases); + ui->localStorage->setChecked(localStorage); + ui->cache->setChecked(cache); + ui->cookies->setChecked(cookies); + ui->icons->setChecked(icons); +} + +QByteArray ClearPrivateData::saveState() +{ + // history - web database - local storage - cache - cookies - icons + QByteArray data; + QDataStream stream(&data, QIODevice::WriteOnly); + + stream << stateDataVersion; + + if (!ui->history->isChecked()) { + stream << -1; + } + else { + stream << ui->historyLength->currentIndex(); + } + + stream << ui->databases->isChecked(); + stream << ui->localStorage->isChecked(); + stream << ui->cache->isChecked(); + stream << ui->cookies->isChecked(); + stream << ui->icons->isChecked(); + + return data; +} diff --git a/src/lib/other/clearprivatedata.h b/src/lib/other/clearprivatedata.h index f7bc855de..1f94614d4 100644 --- a/src/lib/other/clearprivatedata.h +++ b/src/lib/other/clearprivatedata.h @@ -45,6 +45,11 @@ private slots: void clearFlash(); private: + void closeEvent(QCloseEvent* e); + + void restoreState(const QByteArray &state); + QByteArray saveState(); + QupZilla* p_QupZilla; Ui::ClearPrivateData* ui;