From f60dac9d7ebb5b989aad67d67d5ab3ccef7d278c Mon Sep 17 00:00:00 2001 From: "Felix (xq) Queißner" Date: Mon, 15 Mar 2021 12:57:36 +0100 Subject: Adds option to have old or new session behaviour. Closes #187 --- src/dialogs/settingsdialog.cpp | 18 ++++++ src/dialogs/settingsdialog.hpp | 2 + src/dialogs/settingsdialog.ui | 130 ++++++++++++++++++++++------------------- src/kristall.hpp | 7 +++ src/main.cpp | 7 ++- 5 files changed, 102 insertions(+), 62 deletions(-) (limited to 'src') diff --git a/src/dialogs/settingsdialog.cpp b/src/dialogs/settingsdialog.cpp index f6d4728..ea30d4f 100644 --- a/src/dialogs/settingsdialog.cpp +++ b/src/dialogs/settingsdialog.cpp @@ -54,6 +54,10 @@ SettingsDialog::SettingsDialog(QWidget *parent) : this->ui->list_symbol->addItem(tr("Circle"), QVariant::fromValue(int(QTextListFormat::Style::ListCircle))); this->ui->list_symbol->addItem(tr("Square"), QVariant::fromValue(int(QTextListFormat::Style::ListSquare))); + this->ui->session_restore_behaviour->clear(); + this->ui->session_restore_behaviour->addItem(tr("Start Page"), QVariant::fromValue(GenericSettings::NoSessionRestore)); + this->ui->session_restore_behaviour->addItem(tr("Restore Last Session"), QVariant::fromValue(GenericSettings::RestoreLastSession)); + setGeminiStyle(DocumentStyle { }); this->predefined_styles.clear(); @@ -372,6 +376,15 @@ void SettingsDialog::setOptions(const GenericSettings &options) this->ui->cache_life->setValue(this->current_options.cache_life); this->ui->enable_unlimited_cache_life->setChecked(this->current_options.cache_unlimited_life); this->ui->cache_life->setEnabled(!this->current_options.cache_unlimited_life); + + this->ui->session_restore_behaviour->setCurrentIndex(0); + for(int i = 0; i < this->ui->session_restore_behaviour->count(); ++i) + { + if(this->ui->session_restore_behaviour->itemData(i).toInt() == int(options.session_restore_behaviour)) { + this->ui->session_restore_behaviour->setCurrentIndex(i); + break; + } + } } GenericSettings SettingsDialog::options() const @@ -970,3 +983,8 @@ void SettingsDialog::on_strip_nav_off_clicked() { this->current_options.strip_nav = false; } + +void SettingsDialog::on_session_restore_behaviour_currentIndexChanged(int index) +{ + this->current_options.session_restore_behaviour = GenericSettings::SessionRestoreBehaviour(this->ui->session_restore_behaviour->itemData(index).toInt()); +} diff --git a/src/dialogs/settingsdialog.hpp b/src/dialogs/settingsdialog.hpp index 9f996b1..97b1549 100644 --- a/src/dialogs/settingsdialog.hpp +++ b/src/dialogs/settingsdialog.hpp @@ -176,6 +176,8 @@ private slots: void on_strip_nav_off_clicked(); + void on_session_restore_behaviour_currentIndexChanged(int index); + private: void reloadStylePreview(); diff --git a/src/dialogs/settingsdialog.ui b/src/dialogs/settingsdialog.ui index e33ec43..97121c3 100644 --- a/src/dialogs/settingsdialog.ui +++ b/src/dialogs/settingsdialog.ui @@ -60,44 +60,93 @@ + + + + Additional toolbar buttons + + + + + + + + + Home + + + + + + + New tab + + + + + + + Root (/) + + + + + + + Parent (..) + + + + + + + + Startup Behaviour + + + + + + + UI Theme - + - + Icon Theme - + - + UI Density - + - + Enabled Protocols - + @@ -142,14 +191,14 @@ - + Unknown Scheme - + @@ -173,38 +222,38 @@ - + Max. Number of Redirections - + 5 - + Redirection Handling - + - + Network Timeout - + ms @@ -217,45 +266,6 @@ - - - - Additional toolbar buttons - - - - - - - - - Home - - - - - - - New tab - - - - - - - Root (/) - - - - - - - Parent (..) - - - - - @@ -1663,14 +1673,14 @@ + + + - + + - - - - - + diff --git a/src/kristall.hpp b/src/kristall.hpp index 73ed9e4..66de0e1 100644 --- a/src/kristall.hpp +++ b/src/kristall.hpp @@ -64,6 +64,11 @@ struct GenericSettings WarnAlways = -1, }; + enum SessionRestoreBehaviour { + NoSessionRestore = 0, + RestoreLastSession = 1, + }; + QString start_page = "about:favourites"; QString search_engine = "gemini://geminispace.info/search?%1"; Theme theme = Theme::light; @@ -102,6 +107,8 @@ struct GenericSettings int cache_life = 60; bool cache_unlimited_life = true; + SessionRestoreBehaviour session_restore_behaviour = RestoreLastSession; + void load(QSettings & settings); void save(QSettings & settings) const; }; diff --git a/src/main.cpp b/src/main.cpp index cd8e5ef..c881ee8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -682,13 +682,12 @@ int main(int argc, char *argv[]) // Stores the first window from the restored session (if any) MainWindow * root_window = nullptr; - if(session_store != nullptr) + if((session_store != nullptr) and (kristall::globals().options.session_restore_behaviour == GenericSettings::RestoreLastSession)) { auto & settings = *session_store; int window_count = settings.beginReadArray("windows"); - for(int index = 0; index < window_count; index += 1) { settings.setArrayIndex(index); @@ -822,6 +821,8 @@ void GenericSettings::load(QSettings &settings) cache_threshold = settings.value("cache_threshold", 125).toInt(); cache_life = settings.value("cache_life", 15).toInt(); cache_unlimited_life = settings.value("cache_unlimited_life", true).toBool(); + + session_restore_behaviour = SessionRestoreBehaviour(settings.value("session_restore_behaviour", int(session_restore_behaviour)).toInt()); } void GenericSettings::save(QSettings &settings) const @@ -886,6 +887,8 @@ void GenericSettings::save(QSettings &settings) const // with emoji support, they get it out of the box. settings.setValue("emojis_enabled", emojis_enabled); } + + settings.setValue("session_restore_behaviour", int(session_restore_behaviour)); } void kristall::applySettings() -- cgit v1.2.3