From befc88871a4487909fe59055e82ab53b69375461 Mon Sep 17 00:00:00 2001 From: Adam Honse Date: Tue, 23 Nov 2021 00:30:37 -0600 Subject: [PATCH] Add Do Not Show Again box to LOG_DIALOG, using std::hash to hash the dialog string --- qt/OpenRGBDialog2.cpp | 58 ++++++++++++++++++++++++++++++++++++++++++- qt/OpenRGBDialog2.h | 2 ++ 2 files changed, 59 insertions(+), 1 deletion(-) diff --git a/qt/OpenRGBDialog2.cpp b/qt/OpenRGBDialog2.cpp index cbe6728af..a81b2192e 100644 --- a/qt/OpenRGBDialog2.cpp +++ b/qt/OpenRGBDialog2.cpp @@ -1,3 +1,4 @@ +#include #include "OpenRGBDialog2.h" #include "LogManager.h" #include "PluginManager.h" @@ -1433,6 +1434,34 @@ void OpenRGBDialog2::on_ShowHide() void OpenRGBDialog2::onShowDialogMessage() { + std::size_t hash = std::hash{}(dialog_message.toStdString()); + + /*-----------------------------------------------------*\ + | Load the LogManager settings and check if the hash of | + | this message is in the no-show list | + \*-----------------------------------------------------*/ + SettingsManager* settings_manager = ResourceManager::get()->GetSettingsManager(); + std::string log_manager_string = "LogManager"; + json log_manager_settings; + + log_manager_settings = settings_manager->GetSettings(log_manager_string); + + /*-----------------------------------------------------*\ + | If in the no-show list, clear the message string and | + | return without displaying message box | + \*-----------------------------------------------------*/ + if(log_manager_settings.contains("dialog_no_show_hashes")) + { + for(unsigned int list_idx = 0; list_idx < log_manager_settings["dialog_no_show_hashes"].size(); list_idx++) + { + if(log_manager_settings["dialog_no_show_hashes"][list_idx] == hash) + { + dialog_message.clear(); + return; + } + } + } + QMessageBox box; if(IsDarkTheme()) @@ -1447,11 +1476,38 @@ void OpenRGBDialog2::onShowDialogMessage() box.setInformativeText(dialog_message); - box.exec(); + QCheckBox* CheckBox_DontShowAgain = new QCheckBox("Don't show this message again"); + DontShowAgain = false; + + QObject::connect(CheckBox_DontShowAgain, &QCheckBox::stateChanged, [this](int state) + { + if(static_cast(state) == Qt::CheckState::Checked) + { + this->DontShowAgain = true; + } + }); + + box.setCheckBox(CheckBox_DontShowAgain); box.setTextFormat(Qt::RichText); box.setTextInteractionFlags(Qt::TextSelectableByMouse|Qt::TextBrowserInteraction); + box.exec(); + + if(DontShowAgain) + { + /*-----------------------------------------------------*\ + | Add hash of dialog text to no-show list in LogManager | + | settings | + \*-----------------------------------------------------*/ + log_manager_settings["dialog_no_show_hashes"].push_back(hash); + + settings_manager->SetSettings(log_manager_string, log_manager_settings); + settings_manager->SaveSettings(); + } + + DontShowAgain = false; + dialog_message.clear(); } diff --git a/qt/OpenRGBDialog2.h b/qt/OpenRGBDialog2.h index fb5e20e62..bbb3a43f8 100644 --- a/qt/OpenRGBDialog2.h +++ b/qt/OpenRGBDialog2.h @@ -59,6 +59,8 @@ public: void SetDialogMessage(PLogMessage msg); + bool DontShowAgain; + private: /*-------------------------------------*\ | Page pointers |