From c0914b38908ef5a676be578467c97cc4c165cbf3 Mon Sep 17 00:00:00 2001 From: Nodir Temirkhodjaev Date: Thu, 1 Feb 2024 12:51:23 +0300 Subject: [PATCH] UI: Options: Add "Auto-Show Alert Window for New Programs" & "Alert Window is Always on top" flags --- src/ui/form/opt/pages/optionspage.cpp | 19 +++++++++++++++++-- src/ui/form/opt/pages/optionspage.h | 2 ++ src/ui/form/prog/programalertwindow.cpp | 5 ++++- src/ui/form/tray/trayicon.cpp | 10 +++++++--- src/ui/user/iniuser.h | 9 +++++++++ 5 files changed, 39 insertions(+), 6 deletions(-) diff --git a/src/ui/form/opt/pages/optionspage.cpp b/src/ui/form/opt/pages/optionspage.cpp index ed3bb7f0..32559352 100644 --- a/src/ui/form/opt/pages/optionspage.cpp +++ b/src/ui/form/opt/pages/optionspage.cpp @@ -169,6 +169,8 @@ void OptionsPage::onRetranslateUi() m_cbLogBlocked->setText(tr("Collect New Programs")); m_cbAppNotifyMessage->setText(tr("Use System Notifications for New Programs")); + m_cbAppAlertAutoShow->setText(tr("Auto-Show Alert Window for New Programs")); + m_cbAppAlertAlwaysOnTop->setText(tr("Alert Window is Always on top")); m_cbPurgeOnStart->setText(tr("Purge Obsolete on startup")); m_cbPurgeOnMounted->setText(tr("Purge Obsolete only on mounted drives")); @@ -525,6 +527,18 @@ void OptionsPage::setupProgBox() ctrl()->setIniUserEdited(); }); + m_cbAppAlertAutoShow = + ControlUtil::createCheckBox(iniUser()->progAlertWindowAutoShow(), [&](bool checked) { + iniUser()->setProgAlertWindowAutoShow(checked); + ctrl()->setIniUserEdited(); + }); + + m_cbAppAlertAlwaysOnTop = + ControlUtil::createCheckBox(iniUser()->progAlertWindowAlwaysOnTop(), [&](bool checked) { + iniUser()->setProgAlertWindowAlwaysOnTop(checked); + ctrl()->setIniUserEdited(); + }); + m_cbPurgeOnStart = ControlUtil::createCheckBox(ini()->progPurgeOnStart(), [&](bool checked) { if (ini()->progPurgeOnStart() != checked) { ini()->setProgPurgeOnStart(checked); @@ -541,8 +555,9 @@ void OptionsPage::setupProgBox() }); // Layout - auto layout = ControlUtil::createVLayoutByWidgets({ m_cbLogBlocked, m_cbAppNotifyMessage, - ControlUtil::createSeparator(), m_cbPurgeOnStart, m_cbPurgeOnMounted }); + auto layout = ControlUtil::createVLayoutByWidgets( + { m_cbLogBlocked, m_cbAppNotifyMessage, m_cbAppAlertAutoShow, m_cbAppAlertAlwaysOnTop, + ControlUtil::createSeparator(), m_cbPurgeOnStart, m_cbPurgeOnMounted }); m_gbProg = new QGroupBox(); m_gbProg->setLayout(layout); diff --git a/src/ui/form/opt/pages/optionspage.h b/src/ui/form/opt/pages/optionspage.h index 15e5161b..b01a8a67 100644 --- a/src/ui/form/opt/pages/optionspage.h +++ b/src/ui/form/opt/pages/optionspage.h @@ -99,6 +99,8 @@ private: QToolButton *m_btPasswordLock = nullptr; QCheckBox *m_cbLogBlocked = nullptr; QCheckBox *m_cbAppNotifyMessage = nullptr; + QCheckBox *m_cbAppAlertAutoShow = nullptr; + QCheckBox *m_cbAppAlertAlwaysOnTop = nullptr; QCheckBox *m_cbPurgeOnStart = nullptr; QCheckBox *m_cbPurgeOnMounted = nullptr; diff --git a/src/ui/form/prog/programalertwindow.cpp b/src/ui/form/prog/programalertwindow.cpp index 3bf36392..043e3ea7 100644 --- a/src/ui/form/prog/programalertwindow.cpp +++ b/src/ui/form/prog/programalertwindow.cpp @@ -9,7 +9,7 @@ #include "programscontroller.h" ProgramAlertWindow::ProgramAlertWindow(QWidget *parent) : - ProgramEditDialog(new ProgramsController(/*this*/), parent, Qt::Window), + ProgramEditDialog(new ProgramsController(/*this*/), parent), m_stateWatcher(new WidgetWindowStateWatcher(this)) { setupUi(); @@ -71,6 +71,9 @@ void ProgramAlertWindow::setupUi() // Modality this->setWindowModality(Qt::NonModal); + // Top Window + this->setWindowFlag(Qt::WindowStaysOnTopHint, iniUser()->progAlertWindowAlwaysOnTop()); + // Icon this->setWindowIcon(GuiUtil::overlayIcon(":/icons/fort.png", ":/icons/error.png")); } diff --git a/src/ui/form/tray/trayicon.cpp b/src/ui/form/tray/trayicon.cpp index 6e16ce06..78c47a99 100644 --- a/src/ui/form/tray/trayicon.cpp +++ b/src/ui/form/tray/trayicon.cpp @@ -555,10 +555,14 @@ void TrayIcon::updateAppGroupActions() void TrayIcon::sendAlertMessage() { - if (!iniUser()->progNotifyMessage()) - return; + if (iniUser()->progNotifyMessage()) { + windowManager()->showTrayMessage( + tr("New program detected!"), WindowManager::TrayMessageAlert); + } - windowManager()->showTrayMessage(tr("New program detected!"), WindowManager::TrayMessageAlert); + if (iniUser()->progAlertWindowAutoShow()) { + windowManager()->showProgramAlertWindow(); + } } void TrayIcon::updateAlertTimer() diff --git a/src/ui/user/iniuser.h b/src/ui/user/iniuser.h index 1ee7a086..def0e5c4 100644 --- a/src/ui/user/iniuser.h +++ b/src/ui/user/iniuser.h @@ -101,6 +101,15 @@ public: bool progAlertWindowMaximized() const { return valueBool("progAlertWindow/maximized"); } void setProgAlertWindowMaximized(bool on) { setValue("progAlertWindow/maximized", on); } + bool progAlertWindowAutoShow() const { return valueBool("progAlertWindow/autoShow", true); } + void setProgAlertWindowAutoShow(bool on) { setValue("progAlertWindow/autoShow", on); } + + bool progAlertWindowAlwaysOnTop() const + { + return valueBool("progAlertWindow/alwaysOnTop", true); + } + void setProgAlertWindowAlwaysOnTop(bool on) { setValue("progAlertWindow/alwaysOnTop", on); } + QRect optWindowGeometry() const { return value("optWindow/geometry").toRect(); } void setOptWindowGeometry(const QRect &v) { setValue("optWindow/geometry", v); }