From eb629f8fa6f7edd3ba9f3e76146d71f62dafff57 Mon Sep 17 00:00:00 2001 From: Nathan Reiner Date: Sun, 3 Mar 2024 22:56:04 +0100 Subject: refractor and add permission manager without save --- src/tray.cpp | 136 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 136 insertions(+) create mode 100644 src/tray.cpp (limited to 'src/tray.cpp') diff --git a/src/tray.cpp b/src/tray.cpp new file mode 100644 index 0000000..c6e48a8 --- /dev/null +++ b/src/tray.cpp @@ -0,0 +1,136 @@ +#include "tray.hpp" + +Tray::Tray() +{ + this->app_toggle = this->menu.addAction(""); + this->menu.addSeparator(); + this->menu.addMenu(&this->settings)->setText("Settings"); + this->menu.addSeparator(); + this->quit = this->menu.addAction("Quit"); + + this->permissions.camera = this->settings.addAction("Allow Camera"); + this->permissions.microphone = this->settings.addAction("Allow Microphone"); + this->permissions.screenshare = this->settings.addAction("Allow Screenshare"); + this->permissions.system_audio = + this->settings.addAction("Allow System Audio Record"); + this->permissions.notifications = + this->settings.addAction("Allow Notifications"); + this->permissions.location = this->settings.addAction("Allow Location"); + this->permissions.lock_mouse = this->settings.addAction("Allow Lock Mouse"); + this->settings.addSeparator(); + this->reset_storage = this->settings.addAction("Reset Storage"); + + this->permissions.camera->setCheckable(true); + this->permissions.microphone->setCheckable(true); + this->permissions.screenshare->setCheckable(true); + this->permissions.system_audio->setCheckable(true); + this->permissions.notifications->setCheckable(true); + this->permissions.location->setCheckable(true); + this->permissions.lock_mouse->setCheckable(true); + + this->connect(this, + &QSystemTrayIcon::activated, + [&](QSystemTrayIcon::ActivationReason reason) { + if (reason == QSystemTrayIcon::ActivationReason::Trigger) { + this->toggle_signal(); + } + }); + + this->menu.connect(&this->menu, &QMenu::triggered, [&](QAction *action) { + if (action == this->app_toggle) { + this->toggle_signal(); + } else if (action == quit) { + this->quit_signal(); + } + }); + + this->settings.connect( + &this->settings, &QMenu::triggered, [&](QAction *action) { + if (action == this->reset_storage) { + this->reset_cookies_signal(); + + } else if (action == this->permissions.camera) { + this->permission_changed_signal( + QWebEnginePage::Feature::MediaVideoCapture, + this->permissions.camera->isChecked()); + + } else if (action == this->permissions.microphone) { + this->permission_changed_signal( + QWebEnginePage::Feature::MediaAudioCapture, + this->permissions.microphone->isChecked()); + + } else if (action == this->permissions.system_audio) { + this->permission_changed_signal( + QWebEnginePage::Feature::DesktopAudioVideoCapture, + this->permissions.system_audio->isChecked()); + + } else if (action == this->permissions.screenshare) { + this->permission_changed_signal( + QWebEnginePage::Feature::DesktopVideoCapture, + this->permissions.screenshare->isChecked()); + + } else if (action == this->permissions.notifications) { + this->permission_changed_signal( + QWebEnginePage::Feature::Notifications, + this->permissions.notifications->isChecked()); + + } else if (action == this->permissions.location) { + this->permission_changed_signal( + QWebEnginePage::Feature::Geolocation, + this->permissions.location->isChecked()); + + } else if (action == this->permissions.lock_mouse) { + this->permission_changed_signal( + QWebEnginePage::Feature::MouseLock, + this->permissions.lock_mouse->isChecked()); + } + }); + + this->setContextMenu(&this->menu); +} + +void +Tray::connect_toggle(std::function fn) +{ + this->toggle_signal = fn; +} + +void +Tray::connect_quit(std::function fn) +{ + this->quit_signal = fn; +} + +void +Tray::connect_reset_cookies(std::function fn) +{ + this->reset_cookies_signal = fn; +} + +void +Tray::connect_permission_changed( + std::function fn) +{ + this->permission_changed_signal = fn; +} + +void +Tray::set_title(const QString &title) +{ + this->setToolTip(title); + this->app_toggle->setText(title); +} + +void +Tray::send_notification(std::unique_ptr notification) +{ + this->showMessage(notification->title(), + notification->message(), + QSystemTrayIcon::MessageIcon::Information, + 2000); +} + +void +Tray::set_permission(QWebEnginePage::Feature feature, bool value) +{ +} -- cgit v1.2.3-70-g09d2