some refactorings, tray icon test
This commit is contained in:
parent
1fc0337211
commit
44ee50ab76
@ -30,7 +30,7 @@
|
|||||||
<url type="donation">https://martinrotter.github.io/donate/</url>
|
<url type="donation">https://martinrotter.github.io/donate/</url>
|
||||||
<content_rating type="oars-1.1" />
|
<content_rating type="oars-1.1" />
|
||||||
<releases>
|
<releases>
|
||||||
<release version="3.9.2" date="2021-04-28"/>
|
<release version="3.9.0" date="2021-02-25"/>
|
||||||
</releases>
|
</releases>
|
||||||
<content_rating type="oars-1.0">
|
<content_rating type="oars-1.0">
|
||||||
<content_attribute id="violence-cartoon">none</content_attribute>
|
<content_attribute id="violence-cartoon">none</content_attribute>
|
||||||
|
@ -204,7 +204,7 @@ QList<QAction*> FormMain::allActions() const {
|
|||||||
|
|
||||||
void FormMain::prepareMenus() {
|
void FormMain::prepareMenus() {
|
||||||
// Setup menu for tray icon.
|
// Setup menu for tray icon.
|
||||||
if (SystemTrayIcon::isSystemTrayAvailable()) {
|
if (SystemTrayIcon::isSystemTrayAreaAvailable()) {
|
||||||
#if defined(Q_OS_WIN)
|
#if defined(Q_OS_WIN)
|
||||||
m_trayMenu = new TrayIconMenu(APP_NAME, this);
|
m_trayMenu = new TrayIconMenu(APP_NAME, this);
|
||||||
#else
|
#else
|
||||||
@ -449,7 +449,7 @@ void FormMain::updateFeedButtonsAvailability() {
|
|||||||
|
|
||||||
void FormMain::switchVisibility(bool force_hide) {
|
void FormMain::switchVisibility(bool force_hide) {
|
||||||
if (force_hide || isVisible()) {
|
if (force_hide || isVisible()) {
|
||||||
if (SystemTrayIcon::isSystemTrayActivated()) {
|
if (SystemTrayIcon::isSystemTrayDesired() && SystemTrayIcon::isSystemTrayAreaAvailable()) {
|
||||||
hide();
|
hide();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -813,7 +813,8 @@ void FormMain::changeEvent(QEvent* event) {
|
|||||||
switch (event->type()) {
|
switch (event->type()) {
|
||||||
case QEvent::WindowStateChange: {
|
case QEvent::WindowStateChange: {
|
||||||
if ((windowState() & Qt::WindowState::WindowMinimized) == Qt::WindowState::WindowMinimized &&
|
if ((windowState() & Qt::WindowState::WindowMinimized) == Qt::WindowState::WindowMinimized &&
|
||||||
SystemTrayIcon::isSystemTrayActivated() &&
|
SystemTrayIcon::isSystemTrayDesired() &&
|
||||||
|
SystemTrayIcon::isSystemTrayAreaAvailable() &&
|
||||||
qApp->settings()->value(GROUP(GUI), SETTING(GUI::HideMainWindowWhenMinimized)).toBool()) {
|
qApp->settings()->value(GROUP(GUI), SETTING(GUI::HideMainWindowWhenMinimized)).toBool()) {
|
||||||
event->ignore();
|
event->ignore();
|
||||||
QTimer::singleShot(CHANGE_EVENT_DELAY, this, [this]() {
|
QTimer::singleShot(CHANGE_EVENT_DELAY, this, [this]() {
|
||||||
|
@ -84,14 +84,11 @@ void SettingsGui::loadSettings() {
|
|||||||
onBeginLoadSettings();
|
onBeginLoadSettings();
|
||||||
|
|
||||||
// Load settings of tray icon.
|
// Load settings of tray icon.
|
||||||
if (SystemTrayIcon::isSystemTrayAvailable()) {
|
|
||||||
m_ui->m_grpTray->setChecked(settings()->value(GROUP(GUI), SETTING(GUI::UseTrayIcon)).toBool());
|
m_ui->m_grpTray->setChecked(settings()->value(GROUP(GUI), SETTING(GUI::UseTrayIcon)).toBool());
|
||||||
}
|
|
||||||
|
|
||||||
// Tray icon is not supported on this machine.
|
if (!SystemTrayIcon::isSystemTrayAreaAvailable()) {
|
||||||
else {
|
m_ui->m_grpTray->setTitle(m_ui->m_grpTray->title() + QL1C(' ') + tr("(Your OS does not support tray icons at the moment.)"));
|
||||||
m_ui->m_grpTray->setTitle(m_ui->m_grpTray->title() + QL1C(' ') + tr("(Tray icon is not available.)"));
|
m_ui->m_grpTray->setEnabled(false);
|
||||||
m_ui->m_grpTray->setChecked(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
m_ui->m_checkHidden->setChecked(settings()->value(GROUP(GUI), SETTING(GUI::MainWindowStartsHidden)).toBool());
|
m_ui->m_checkHidden->setChecked(settings()->value(GROUP(GUI), SETTING(GUI::MainWindowStartsHidden)).toBool());
|
||||||
@ -200,7 +197,7 @@ void SettingsGui::saveSettings() {
|
|||||||
m_ui->m_cmbToolbarButtonStyle->itemData(m_ui->m_cmbToolbarButtonStyle->currentIndex()));
|
m_ui->m_cmbToolbarButtonStyle->itemData(m_ui->m_cmbToolbarButtonStyle->currentIndex()));
|
||||||
|
|
||||||
// Save tray icon.
|
// Save tray icon.
|
||||||
if (SystemTrayIcon::isSystemTrayAvailable()) {
|
if (SystemTrayIcon::isSystemTrayAreaAvailable()) {
|
||||||
settings()->setValue(GROUP(GUI), GUI::UseTrayIcon, m_ui->m_grpTray->isChecked());
|
settings()->setValue(GROUP(GUI), GUI::UseTrayIcon, m_ui->m_grpTray->isChecked());
|
||||||
|
|
||||||
if (m_ui->m_grpTray->isChecked()) {
|
if (m_ui->m_grpTray->isChecked()) {
|
||||||
|
@ -60,12 +60,12 @@ void SystemTrayIcon::onActivated(QSystemTrayIcon::ActivationReason reason) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SystemTrayIcon::isSystemTrayAvailable() {
|
bool SystemTrayIcon::isSystemTrayAreaAvailable() {
|
||||||
return QSystemTrayIcon::isSystemTrayAvailable() && QSystemTrayIcon::supportsMessages();
|
return QSystemTrayIcon::isSystemTrayAvailable() && QSystemTrayIcon::supportsMessages();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SystemTrayIcon::isSystemTrayActivated() {
|
bool SystemTrayIcon::isSystemTrayDesired() {
|
||||||
return SystemTrayIcon::isSystemTrayAvailable() && qApp->settings()->value(GROUP(GUI), SETTING(GUI::UseTrayIcon)).toBool();
|
return qApp->settings()->value(GROUP(GUI), SETTING(GUI::UseTrayIcon)).toBool();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SystemTrayIcon::areNotificationsEnabled() {
|
bool SystemTrayIcon::areNotificationsEnabled() {
|
||||||
@ -92,8 +92,8 @@ void SystemTrayIcon::show() {
|
|||||||
showPrivate();
|
showPrivate();
|
||||||
#else
|
#else
|
||||||
// Delay avoids race conditions and tray icon is properly displayed.
|
// Delay avoids race conditions and tray icon is properly displayed.
|
||||||
qDebugNN << LOGSEC_GUI << "Showing tray icon with 1000 ms delay.";
|
qDebugNN << LOGSEC_GUI << "Showing tray icon with 3000 ms delay.";
|
||||||
QTimer::singleShot(1000, this, &SystemTrayIcon::showPrivate);
|
QTimer::singleShot(3000, this, &SystemTrayIcon::showPrivate);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,12 +46,11 @@ class SystemTrayIcon : public QSystemTrayIcon {
|
|||||||
void showMessage(const QString& title, const QString& message, MessageIcon icon = Information,
|
void showMessage(const QString& title, const QString& message, MessageIcon icon = Information,
|
||||||
int milliseconds_timeout_hint = TRAY_ICON_BUBBLE_TIMEOUT, std::function<void()> functor = nullptr);
|
int milliseconds_timeout_hint = TRAY_ICON_BUBBLE_TIMEOUT, std::function<void()> functor = nullptr);
|
||||||
|
|
||||||
// Returns true if tray icon CAN be constructed on this machine.
|
// Returns true if tray area is available and icon can be displayed.
|
||||||
static bool isSystemTrayAvailable();
|
static bool isSystemTrayAreaAvailable();
|
||||||
|
|
||||||
// Returns true if tray icon CAN be costructed and IS enabled in
|
// Returns true if user wants to have tray icon displayed.
|
||||||
// application settings.
|
static bool isSystemTrayDesired();
|
||||||
static bool isSystemTrayActivated();
|
|
||||||
|
|
||||||
// Determines whether balloon tips are enabled or not on tray icons.
|
// Determines whether balloon tips are enabled or not on tray icons.
|
||||||
static bool areNotificationsEnabled();
|
static bool areNotificationsEnabled();
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
|
|
||||||
#include <QProcess>
|
#include <QProcess>
|
||||||
#include <QSessionManager>
|
#include <QSessionManager>
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
#if defined(USE_WEBENGINE)
|
#if defined(USE_WEBENGINE)
|
||||||
#include "network-web/adblock/adblockicon.h"
|
#include "network-web/adblock/adblockicon.h"
|
||||||
@ -122,7 +123,9 @@ void Application::reactOnForeignNotifications() {
|
|||||||
|
|
||||||
void Application::hideOrShowMainForm() {
|
void Application::hideOrShowMainForm() {
|
||||||
// Display main window.
|
// Display main window.
|
||||||
if (qApp->settings()->value(GROUP(GUI), SETTING(GUI::MainWindowStartsHidden)).toBool() && SystemTrayIcon::isSystemTrayActivated()) {
|
if (qApp->settings()->value(GROUP(GUI), SETTING(GUI::MainWindowStartsHidden)).toBool() &&
|
||||||
|
SystemTrayIcon::isSystemTrayDesired() &&
|
||||||
|
SystemTrayIcon::isSystemTrayAreaAvailable()) {
|
||||||
qDebugNN << LOGSEC_CORE << "Hiding the main window when the application is starting.";
|
qDebugNN << LOGSEC_CORE << "Hiding the main window when the application is starting.";
|
||||||
mainForm()->switchVisibility(true);
|
mainForm()->switchVisibility(true);
|
||||||
}
|
}
|
||||||
@ -412,8 +415,15 @@ QIcon Application::desktopAwareIcon() const {
|
|||||||
|
|
||||||
void Application::showTrayIcon() {
|
void Application::showTrayIcon() {
|
||||||
// Display tray icon if it is enabled and available.
|
// Display tray icon if it is enabled and available.
|
||||||
if (SystemTrayIcon::isSystemTrayActivated()) {
|
if (SystemTrayIcon::isSystemTrayDesired()) {
|
||||||
qDebugNN << LOGSEC_CORE << "Showing tray icon.";
|
#if !defined(Q_OS_LINUX)
|
||||||
|
if (!SystemTrayIcon::isSystemTrayAreaAvailable()) {
|
||||||
|
qWarningNN << LOGSEC_GUI << "Tray icon area is not available.";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
qDebugNN << LOGSEC_GUI << "Showing tray icon.";
|
||||||
trayIcon()->show();
|
trayIcon()->show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -433,7 +443,9 @@ void Application::deleteTrayIcon() {
|
|||||||
void Application::showGuiMessage(const QString& title, const QString& message,
|
void Application::showGuiMessage(const QString& title, const QString& message,
|
||||||
QSystemTrayIcon::MessageIcon message_type, QWidget* parent,
|
QSystemTrayIcon::MessageIcon message_type, QWidget* parent,
|
||||||
bool show_at_least_msgbox, std::function<void()> functor) {
|
bool show_at_least_msgbox, std::function<void()> functor) {
|
||||||
if (SystemTrayIcon::areNotificationsEnabled() && SystemTrayIcon::isSystemTrayActivated()) {
|
if (SystemTrayIcon::areNotificationsEnabled() &&
|
||||||
|
SystemTrayIcon::isSystemTrayDesired() &&
|
||||||
|
SystemTrayIcon::isSystemTrayAreaAvailable()) {
|
||||||
trayIcon()->showMessage(title, message, message_type, TRAY_ICON_BUBBLE_TIMEOUT, std::move(functor));
|
trayIcon()->showMessage(title, message, message_type, TRAY_ICON_BUBBLE_TIMEOUT, std::move(functor));
|
||||||
}
|
}
|
||||||
else if (show_at_least_msgbox) {
|
else if (show_at_least_msgbox) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user