Changeset View
Changeset View
Standalone View
Standalone View
kcms/activities/SwitchingTab.cpp
Show All 13 Lines | |||||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
15 | * GNU General Public License for more details. | 15 | * GNU General Public License for more details. | ||
16 | * | 16 | * | ||
17 | * You should have received a copy of the GNU General Public License | 17 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
19 | */ | 19 | */ | ||
20 | 20 | | |||
21 | #include "SwitchingTab.h" | 21 | #include "SwitchingTab.h" | ||
22 | #include "kactivitymanagerd_settings.h" | ||||
22 | 23 | | |||
23 | #include <KActionCollection> | 24 | #include <KActionCollection> | ||
24 | #include <KConfigGroup> | 25 | #include <KConfigGroup> | ||
25 | #include <KGlobalAccel> | 26 | #include <KGlobalAccel> | ||
26 | #include <KSharedConfig> | 27 | #include <KSharedConfig> | ||
27 | 28 | | |||
28 | #include "ui_SwitchingTabBase.h" | 29 | #include "ui_SwitchingTabBase.h" | ||
29 | 30 | | |||
30 | #include <utils/d_ptr_implementation.h> | 31 | #include <utils/d_ptr_implementation.h> | ||
31 | #include <KActivities/Consumer> | 32 | #include <KActivities/Consumer> | ||
32 | 33 | | |||
33 | class SwitchingTab::Private : public Ui::SwitchingTabBase { | 34 | class SwitchingTab::Private : public Ui::SwitchingTabBase { | ||
34 | public: | 35 | public: | ||
35 | KSharedConfig::Ptr mainConfig; | 36 | KActivityManagerdSettings mainConfig; | ||
36 | 37 | | |||
37 | KActionCollection *mainActionCollection; | 38 | KActionCollection *mainActionCollection; | ||
38 | KActivities::Consumer activities; | 39 | KActivities::Consumer activities; | ||
39 | 40 | | |||
40 | void createAction(const QString &actionName, const QString &actionText, | 41 | void createAction(const QString &actionName, const QString &actionText, | ||
41 | const QList<QKeySequence> &sequence) | 42 | const QList<QKeySequence> &defaultSequence) | ||
42 | { | 43 | { | ||
43 | auto action = mainActionCollection->addAction(actionName); | 44 | auto action = mainActionCollection->addAction(actionName); | ||
44 | action->setProperty("isConfigurationAction", true); | 45 | action->setProperty("isConfigurationAction", true); | ||
45 | action->setText(actionText); | 46 | action->setText(actionText); | ||
46 | KGlobalAccel::self()->setShortcut(action, sequence); | 47 | KGlobalAccel::self()->setShortcut(action, defaultSequence); | ||
48 | KGlobalAccel::self()->setDefaultShortcut(action, defaultSequence); | ||||
47 | } | 49 | } | ||
48 | 50 | | |||
49 | Private() | 51 | Private() | ||
50 | : mainActionCollection(nullptr) | 52 | : mainActionCollection(nullptr) | ||
51 | { | 53 | { | ||
52 | } | 54 | } | ||
53 | }; | 55 | }; | ||
54 | 56 | | |||
55 | SwitchingTab::SwitchingTab(QWidget *parent) | 57 | SwitchingTab::SwitchingTab(QWidget *parent) | ||
56 | : QWidget(parent) | 58 | : QWidget(parent) | ||
57 | , d() | 59 | , d() | ||
58 | { | 60 | { | ||
59 | d->setupUi(this); | 61 | d->setupUi(this); | ||
60 | 62 | | |||
61 | d->mainConfig = KSharedConfig::openConfig(QStringLiteral("kactivitymanagerdrc")); | | |||
62 | | ||||
63 | // Shortcut config. The shortcut belongs to the component "plasmashell"! | 63 | // Shortcut config. The shortcut belongs to the component "plasmashell"! | ||
64 | d->mainActionCollection = new KActionCollection(this, QStringLiteral("plasmashell")); | 64 | d->mainActionCollection = new KActionCollection(this, QStringLiteral("plasmashell")); | ||
65 | d->mainActionCollection->setComponentDisplayName(i18n("Activity switching")); | 65 | d->mainActionCollection->setComponentDisplayName(i18n("Activity switching")); | ||
66 | d->mainActionCollection->setConfigGlobal(true); | 66 | d->mainActionCollection->setConfigGlobal(true); | ||
67 | 67 | | |||
68 | d->createAction(QStringLiteral("next activity"), | 68 | d->createAction(QStringLiteral("next activity"), | ||
69 | i18nc("@action", "Walk through activities"), | 69 | i18nc("@action", "Walk through activities"), | ||
70 | { Qt::META + Qt::Key_Tab }); | 70 | { Qt::META + Qt::Key_Tab }); | ||
Show All 11 Lines | |||||
82 | 82 | | |||
83 | defaults(); | 83 | defaults(); | ||
84 | } | 84 | } | ||
85 | 85 | | |||
86 | SwitchingTab::~SwitchingTab() | 86 | SwitchingTab::~SwitchingTab() | ||
87 | { | 87 | { | ||
88 | } | 88 | } | ||
89 | 89 | | |||
90 | bool SwitchingTab::isDefault() | ||||
91 | { | ||||
92 | return !d->checkRememberVirtualDesktop->isChecked(); | ||||
93 | } | ||||
94 | | ||||
90 | void SwitchingTab::shortcutChanged(const QKeySequence &sequence) | 95 | void SwitchingTab::shortcutChanged(const QKeySequence &sequence) | ||
91 | { | 96 | { | ||
92 | QString actionName = sender() | 97 | QString actionName = sender() | ||
93 | ? sender()->property("shortcutAction").toString() | 98 | ? sender()->property("shortcutAction").toString() | ||
94 | : QString(); | 99 | : QString(); | ||
95 | 100 | | |||
96 | if (actionName.isEmpty()) return; | 101 | if (actionName.isEmpty()) return; | ||
97 | 102 | | |||
98 | auto action = d->mainActionCollection->action(actionName); | 103 | auto action = d->mainActionCollection->action(actionName); | ||
99 | 104 | | |||
100 | KGlobalAccel::self()->setShortcut(action, { sequence }, | 105 | KGlobalAccel::self()->setShortcut(action, { sequence }, | ||
101 | KGlobalAccel::NoAutoloading); | 106 | KGlobalAccel::NoAutoloading); | ||
102 | d->mainActionCollection->writeSettings(); | 107 | d->mainActionCollection->writeSettings(); | ||
103 | 108 | | |||
104 | emit changed(); | 109 | emit changed(); | ||
105 | } | 110 | } | ||
106 | 111 | | |||
107 | void SwitchingTab::defaults() | 112 | void SwitchingTab::defaults() | ||
108 | { | 113 | { | ||
109 | d->checkRememberVirtualDesktop->setChecked(false); | 114 | d->checkRememberVirtualDesktop->setChecked(false); | ||
110 | } | 115 | } | ||
111 | 116 | | |||
112 | void SwitchingTab::load() | 117 | void SwitchingTab::load() | ||
113 | { | 118 | { | ||
114 | auto pluginListConfig = d->mainConfig->group("Plugins"); | | |||
115 | 119 | | |||
116 | d->checkRememberVirtualDesktop->setChecked(pluginListConfig.readEntry( | 120 | d->checkRememberVirtualDesktop->setChecked(d->mainConfig.virtualDesktopSwitchEnabled()); | ||
117 | "org.kde.ActivityManager.VirtualDesktopSwitchEnabled", false)); | | |||
118 | } | 121 | } | ||
119 | 122 | | |||
120 | void SwitchingTab::save() | 123 | void SwitchingTab::save() | ||
121 | { | 124 | { | ||
122 | auto pluginListConfig = d->mainConfig->group("Plugins"); | 125 | d->mainConfig.setVirtualDesktopSwitchEnabled(d->checkRememberVirtualDesktop->isChecked()); | ||
123 | 126 | d->mainConfig.save(); | |||
124 | pluginListConfig.writeEntry( | | |||
125 | "org.kde.ActivityManager.VirtualDesktopSwitchEnabled", | | |||
126 | d->checkRememberVirtualDesktop->isChecked()); | | |||
127 | | ||||
128 | pluginListConfig.sync(); | | |||
129 | } | 127 | } |