Various cleanup to global shortcuts code
This commit is contained in:
@@ -42,9 +42,6 @@
|
||||
#include "core/iconloader.h"
|
||||
#include "core/logging.h"
|
||||
#include "core/utilities.h"
|
||||
#ifdef Q_OS_MACOS
|
||||
# include "core/mac_utilities.h"
|
||||
#endif
|
||||
#include "globalshortcuts/globalshortcutgrabber.h"
|
||||
#include "globalshortcuts/globalshortcutsmanager.h"
|
||||
#include "settingspage.h"
|
||||
@@ -71,41 +68,32 @@ GlobalShortcutsSettingsPage::GlobalShortcutsSettingsPage(SettingsDialog *dialog,
|
||||
QObject::connect(ui_->radio_custom, &QRadioButton::clicked, this, &GlobalShortcutsSettingsPage::ChangeClicked);
|
||||
QObject::connect(ui_->button_change, &QPushButton::clicked, this, &GlobalShortcutsSettingsPage::ChangeClicked);
|
||||
|
||||
#if defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)
|
||||
# ifdef HAVE_DBUS
|
||||
#if defined(Q_OS_UNIX) && !defined(Q_OS_MACOS) && defined(HAVE_DBUS)
|
||||
QObject::connect(ui_->checkbox_kde, &QCheckBox::toggled, this, &GlobalShortcutsSettingsPage::ShortcutOptionsChanged);
|
||||
QObject::connect(ui_->checkbox_gnome, &QCheckBox::toggled, this, &GlobalShortcutsSettingsPage::ShortcutOptionsChanged);
|
||||
QObject::connect(ui_->checkbox_mate, &QCheckBox::toggled, this, &GlobalShortcutsSettingsPage::ShortcutOptionsChanged);
|
||||
QObject::connect(ui_->button_gnome_open, &QPushButton::clicked, this, &GlobalShortcutsSettingsPage::OpenGnomeKeybindingProperties);
|
||||
QObject::connect(ui_->button_mate_open, &QPushButton::clicked, this, &GlobalShortcutsSettingsPage::OpenMateKeybindingProperties);
|
||||
# endif
|
||||
# ifdef HAVE_X11_GLOBALSHORTCUTS
|
||||
QObject::connect(ui_->checkbox_x11, &QCheckBox::toggled, this, &GlobalShortcutsSettingsPage::ShortcutOptionsChanged);
|
||||
# endif
|
||||
#else
|
||||
ui_->widget_kde->hide();
|
||||
ui_->widget_gnome->hide();
|
||||
ui_->widget_mate->hide();
|
||||
#endif // defined(Q_OS_UNIX) && !defined(Q_OS_MACOS) && defined(HAVE_DBUS)
|
||||
|
||||
#ifdef HAVE_X11_GLOBALSHORTCUTS
|
||||
QObject::connect(ui_->checkbox_x11, &QCheckBox::toggled, this, &GlobalShortcutsSettingsPage::ShortcutOptionsChanged);
|
||||
#else
|
||||
ui_->widget_x11->hide();
|
||||
#endif // defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)
|
||||
#endif // HAVE_X11_GLOBALSHORTCUTS
|
||||
|
||||
#ifndef Q_OS_MACOS
|
||||
ui_->widget_macos_access->hide();
|
||||
#endif // Q_OS_MACOS
|
||||
|
||||
}
|
||||
|
||||
GlobalShortcutsSettingsPage::~GlobalShortcutsSettingsPage() { delete ui_; }
|
||||
|
||||
bool GlobalShortcutsSettingsPage::IsEnabled() const {
|
||||
|
||||
#ifdef Q_OS_MACOS
|
||||
qLog(Debug) << Utilities::GetMacOsVersion();
|
||||
if (Utilities::GetMacOsVersion() < 6) { // Leopard and earlier.
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
void GlobalShortcutsSettingsPage::Load() {
|
||||
|
||||
QSettings s;
|
||||
@@ -119,10 +107,13 @@ void GlobalShortcutsSettingsPage::Load() {
|
||||
de_ = Utilities::DesktopEnvironment();
|
||||
ui_->widget_warning->hide();
|
||||
|
||||
QObject::connect(ui_->button_macos_open, &QPushButton::clicked, manager, &GlobalShortcutsManager::ShowMacAccessibilityDialog);
|
||||
#ifdef Q_OS_MACOS
|
||||
QObject::connect(ui_->button_macos_preferences, &QPushButton::clicked, manager, &GlobalShortcutsManager::ShowMacAccessibilityDialog);
|
||||
#endif
|
||||
|
||||
#if defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)
|
||||
if (manager->IsKdeAvailable()) {
|
||||
#if defined(Q_OS_UNIX) && !defined(Q_OS_MACOS) && defined(HAVE_DBUS)
|
||||
|
||||
if (GlobalShortcutsManager::IsKdeAvailable()) {
|
||||
qLog(Debug) << "KDE (KGlobalAccel) backend is available.";
|
||||
ui_->widget_kde->show();
|
||||
}
|
||||
@@ -131,7 +122,7 @@ void GlobalShortcutsSettingsPage::Load() {
|
||||
ui_->widget_kde->hide();
|
||||
}
|
||||
|
||||
if (manager->IsGnomeAvailable()) {
|
||||
if (GlobalShortcutsManager::IsGnomeAvailable()) {
|
||||
qLog(Debug) << "Gnome (GSD) backend is available.";
|
||||
ui_->widget_gnome->show();
|
||||
}
|
||||
@@ -140,7 +131,7 @@ void GlobalShortcutsSettingsPage::Load() {
|
||||
ui_->widget_gnome->hide();
|
||||
}
|
||||
|
||||
if (manager->IsMateAvailable()) {
|
||||
if (GlobalShortcutsManager::IsMateAvailable()) {
|
||||
qLog(Debug) << "MATE backend is available.";
|
||||
ui_->widget_mate->show();
|
||||
}
|
||||
@@ -149,7 +140,10 @@ void GlobalShortcutsSettingsPage::Load() {
|
||||
ui_->widget_mate->hide();
|
||||
}
|
||||
|
||||
if (manager->IsX11Available()) {
|
||||
#endif // defined(Q_OS_UNIX) && !defined(Q_OS_MACOS) && defined(HAVE_DBUS)
|
||||
|
||||
#ifdef HAVE_X11_GLOBALSHORTCUTS
|
||||
if (GlobalShortcutsManager::IsX11Available()) {
|
||||
qLog(Debug) << "X11 backend is available.";
|
||||
ui_->widget_x11->show();
|
||||
}
|
||||
@@ -157,7 +151,7 @@ void GlobalShortcutsSettingsPage::Load() {
|
||||
qLog(Debug) << "X11 backend is unavailable.";
|
||||
ui_->widget_x11->hide();
|
||||
}
|
||||
#endif
|
||||
#endif // HAVE_X11_GLOBALSHORTCUTS
|
||||
|
||||
QList<GlobalShortcutsManager::Shortcut> shortcuts = manager->shortcuts().values();
|
||||
for (const GlobalShortcutsManager::Shortcut &i : shortcuts) {
|
||||
@@ -178,7 +172,7 @@ void GlobalShortcutsSettingsPage::Load() {
|
||||
SetShortcut(shortcut.s.id, shortcut.s.action->shortcut());
|
||||
}
|
||||
|
||||
#if defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)
|
||||
#if defined(Q_OS_UNIX) && !defined(Q_OS_MACOS) && defined(HAVE_DBUS)
|
||||
|
||||
if (ui_->widget_kde->isVisibleTo(this)) {
|
||||
ui_->checkbox_kde->setChecked(s.value("use_kde", true).toBool());
|
||||
@@ -192,20 +186,20 @@ void GlobalShortcutsSettingsPage::Load() {
|
||||
ui_->checkbox_mate->setChecked(s.value("use_mate", true).toBool());
|
||||
}
|
||||
|
||||
#endif // defined(Q_OS_UNIX) && !defined(Q_OS_MACOS) && defined(HAVE_DBUS)
|
||||
|
||||
#ifdef HAVE_X11_GLOBALSHORTCUTS
|
||||
if (ui_->widget_x11->isVisibleTo(this)) {
|
||||
ui_->checkbox_x11->setChecked(s.value("use_x11", false).toBool());
|
||||
}
|
||||
#endif
|
||||
#endif // HAVE_X11_GLOBALSHORTCUTS
|
||||
|
||||
#if defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)
|
||||
#if defined(Q_OS_UNIX) && !defined(Q_OS_MACOS) && (defined(HAVE_DBUS) || defined(HAVE_X11_GLOBALSHORTCUTS))
|
||||
ShortcutOptionsChanged();
|
||||
#endif
|
||||
|
||||
ui_->widget_macos->setVisible(!manager->IsMacAccessibilityEnabled());
|
||||
#ifdef Q_OS_MACOS
|
||||
qint32 macos_version = Utilities::GetMacOsVersion();
|
||||
ui_->label_macos->setVisible(macos_version < 9);
|
||||
ui_->label_macos_mavericks->setVisible(macos_version >= 9);
|
||||
ui_->widget_macos_access->setVisible(!GlobalShortcutsManager::IsMacAccessibilityEnabled());
|
||||
#endif // Q_OS_MACOS
|
||||
|
||||
s.endGroup();
|
||||
@@ -228,12 +222,15 @@ void GlobalShortcutsSettingsPage::Save() {
|
||||
s.setValue(shortcut.s.id, shortcut.key.toString());
|
||||
}
|
||||
|
||||
#if defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)
|
||||
#if defined(Q_OS_UNIX) && !defined(Q_OS_MACOS) && defined(HAVE_DBUS)
|
||||
s.setValue("use_kde", ui_->checkbox_kde->isChecked());
|
||||
s.setValue("use_gnome", ui_->checkbox_gnome->isChecked());
|
||||
s.setValue("use_mate", ui_->checkbox_mate->isChecked());
|
||||
#endif // defined(Q_OS_UNIX) && !defined(Q_OS_MACOS) && defined(HAVE_DBUS)
|
||||
|
||||
#ifdef HAVE_X11_GLOBALSHORTCUTS
|
||||
s.setValue("use_x11", ui_->checkbox_x11->isChecked());
|
||||
#endif
|
||||
#endif // HAVE_X11_GLOBALSHORTCUTS
|
||||
|
||||
s.endGroup();
|
||||
|
||||
|
||||
@@ -49,8 +49,6 @@ class GlobalShortcutsSettingsPage : public SettingsPage {
|
||||
|
||||
static const char *kSettingsGroup;
|
||||
|
||||
bool IsEnabled() const override;
|
||||
|
||||
void Load() override;
|
||||
void Save() override;
|
||||
|
||||
|
||||
@@ -156,6 +156,18 @@
|
||||
<item>
|
||||
<widget class="QWidget" name="widget_warning" native="true">
|
||||
<layout class="QHBoxLayout" name="layout_warning">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_warn_icon">
|
||||
<property name="sizePolicy">
|
||||
@@ -210,11 +222,8 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QWidget" name="widget_macos" native="true">
|
||||
<widget class="QWidget" name="widget_macos_access" native="true">
|
||||
<layout class="QHBoxLayout" name="layout_macos">
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
@@ -228,23 +237,41 @@
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_macos">
|
||||
<widget class="QLabel" name="label_macos_access_icon">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>You need to launch System Preferences and turn on "<span style=" font-style:italic;">Enable access for assistive devices</span>" to use global shortcuts in Strawberry.</string>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>48</width>
|
||||
<height>48</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>48</width>
|
||||
<height>48</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="baseSize">
|
||||
<size>
|
||||
<width>64</width>
|
||||
<height>64</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="pixmap">
|
||||
<pixmap resource="../../data/icons.qrc">:/icons/48x48/dialog-warning.png</pixmap>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_macos_mavericks">
|
||||
<widget class="QLabel" name="label_macos_access">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
@@ -260,7 +287,7 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="button_macos_open">
|
||||
<widget class="QPushButton" name="button_macos_preferences">
|
||||
<property name="text">
|
||||
<string>Open...</string>
|
||||
</property>
|
||||
@@ -360,7 +387,7 @@
|
||||
<tabstop>checkbox_gnome</tabstop>
|
||||
<tabstop>button_gnome_open</tabstop>
|
||||
<tabstop>checkbox_x11</tabstop>
|
||||
<tabstop>button_macos_open</tabstop>
|
||||
<tabstop>button_macos_preferences</tabstop>
|
||||
<tabstop>list</tabstop>
|
||||
<tabstop>radio_none</tabstop>
|
||||
<tabstop>radio_default</tabstop>
|
||||
|
||||
Reference in New Issue
Block a user