Changeset View
Changeset View
Standalone View
Standalone View
kcms/keyboard/daemon/bindings.cpp
- This file was moved from kcms/keyboard/bindings.cpp.
Show All 21 Lines | |||||
22 | #include <klocalizedstring.h> | 22 | #include <klocalizedstring.h> | ||
23 | #include <kglobalaccel.h> | 23 | #include <kglobalaccel.h> | ||
24 | #include <kaboutdata.h> | 24 | #include <kaboutdata.h> | ||
25 | 25 | | |||
26 | #include <QList> | 26 | #include <QList> | ||
27 | #include <QAction> | 27 | #include <QAction> | ||
28 | 28 | | |||
29 | #include "x11_helper.h" | 29 | #include "x11_helper.h" | ||
30 | #include "flags.h" | | |||
31 | 30 | | |||
32 | 31 | | |||
33 | static const char actionName[] = I18N_NOOP("Switch to Next Keyboard Layout"); | 32 | static const char actionName[] = I18N_NOOP("Switch to Next Keyboard Layout"); | ||
34 | static const char COMPONENT_NAME[] = I18N_NOOP("KDE Keyboard Layout Switcher"); | 33 | static const char COMPONENT_NAME[] = I18N_NOOP("KDE Keyboard Layout Switcher"); | ||
35 | 34 | | |||
36 | 35 | | |||
37 | KeyboardLayoutActionCollection::KeyboardLayoutActionCollection(QObject* parent, bool configAction_): | 36 | KeyboardLayoutActionCollection::KeyboardLayoutActionCollection(QObject* parent, bool configAction_): | ||
38 | KActionCollection(parent, COMPONENT_NAME), | 37 | KActionCollection(parent, COMPONENT_NAME), | ||
Show All 13 Lines | |||||
52 | { | 51 | { | ||
53 | clear(); | 52 | clear(); | ||
54 | } | 53 | } | ||
55 | 54 | | |||
56 | QAction* KeyboardLayoutActionCollection::getToggleAction() | 55 | QAction* KeyboardLayoutActionCollection::getToggleAction() | ||
57 | { | 56 | { | ||
58 | return action(0); | 57 | return action(0); | ||
59 | } | 58 | } | ||
60 | 59 | /* | |||
61 | QAction* KeyboardLayoutActionCollection::createLayoutShortcutActon(const LayoutUnit& layoutUnit, const Rules* rules, bool autoload) | 60 | QAction* KeyboardLayoutActionCollection::createLayoutShortcutActon(const LayoutUnit& layoutUnit, const XkbRules* rules, bool autoload) | ||
62 | { | 61 | { | ||
63 | QString longLayoutName = Flags::getLongText( layoutUnit, rules ); | 62 | QString longLayoutName = getLongText(layoutUnit, rules); | ||
64 | QString actionName = QStringLiteral("Switch keyboard layout to "); | 63 | QString actionName = QStringLiteral("Switch keyboard layout to "); | ||
65 | actionName += longLayoutName; | 64 | actionName += longLayoutName; | ||
66 | QAction* action = addAction( actionName ); | 65 | QAction* action = addAction( actionName ); | ||
67 | action->setText( i18n("Switch keyboard layout to %1", longLayoutName) ); | 66 | action->setText( i18n("Switch keyboard layout to %1", longLayoutName) ); | ||
68 | KGlobalAccel::GlobalShortcutLoading loading = autoload ? KGlobalAccel::Autoloading : KGlobalAccel::NoAutoloading; | 67 | KGlobalAccel::GlobalShortcutLoading loading = autoload ? KGlobalAccel::Autoloading : KGlobalAccel::NoAutoloading; | ||
69 | QList<QKeySequence> shortcuts; | 68 | QList<QKeySequence> shortcuts; | ||
70 | if (!autoload) { | 69 | if (!autoload) { | ||
71 | shortcuts << layoutUnit.getShortcut(); | 70 | shortcuts << layoutUnit.getShortcut(); | ||
72 | } | 71 | } | ||
73 | KGlobalAccel::self()->setShortcut(action, shortcuts, loading); | 72 | KGlobalAccel::self()->setShortcut(action, shortcuts, loading); | ||
74 | action->setData(layoutUnit.toString()); | 73 | action->setData(layoutUnit.toString()); | ||
75 | if( configAction ) { | 74 | if( configAction ) { | ||
76 | action->setProperty("isConfigurationAction", true); | 75 | action->setProperty("isConfigurationAction", true); | ||
77 | } | 76 | } | ||
78 | return action; | 77 | return action; | ||
79 | } | 78 | } | ||
80 | 79 | */ | |||
81 | void KeyboardLayoutActionCollection::setToggleShortcut(const QKeySequence& keySequence) | 80 | void KeyboardLayoutActionCollection::setToggleShortcut(const QKeySequence& keySequence) | ||
82 | { | 81 | { | ||
83 | KGlobalAccel::self()->setShortcut(getToggleAction(), QList<QKeySequence>() << keySequence, KGlobalAccel::NoAutoloading); | 82 | KGlobalAccel::self()->setShortcut(getToggleAction(), QList<QKeySequence>() << keySequence, KGlobalAccel::NoAutoloading); | ||
84 | } | 83 | } | ||
85 | 84 | | |||
86 | //KAction* KeyboardLayoutActionCollection::setShortcut(LayoutUnit& layoutUnit, const QKeySequence& keySequence, const Rules* rules) | 85 | //KAction* KeyboardLayoutActionCollection::setShortcut(LayoutUnit& layoutUnit, const QKeySequence& keySequence, const Rules* rules) | ||
87 | //{ | 86 | //{ | ||
88 | // KAction* action = getAction(layoutUnit); | 87 | // KAction* action = getAction(layoutUnit); | ||
89 | // if( action == NULL && ! keySequence.isEmpty() ) { | 88 | // if( action == NULL && ! keySequence.isEmpty() ) { | ||
90 | // action = createLayoutShortcutActon(layoutUnit, rules, false); | 89 | // action = createLayoutShortcutActon(layoutUnit, rules, false); | ||
91 | // } | 90 | // } | ||
92 | // else if( action != NULL && keySequence.isEmpty() ){ | 91 | // else if( action != NULL && keySequence.isEmpty() ){ | ||
93 | //// action->setGlobalShortcut(KShortcut(keySequence), KAction::ActiveShortcut, KAction::NoAutoloading); // do we need this? | 92 | //// action->setGlobalShortcut(KShortcut(keySequence), KAction::ActiveShortcut, KAction::NoAutoloading); // do we need this? | ||
94 | // removeAction(action); | 93 | // removeAction(action); | ||
95 | // action = NULL; | 94 | // action = NULL; | ||
96 | // } | 95 | // } | ||
97 | //// if( configAction ) { | 96 | //// if( configAction ) { | ||
98 | //// layoutUnit.setShortcut(keySequence); // shortcut was restored | 97 | //// layoutUnit.setShortcut(keySequence); // shortcut was restored | ||
99 | //// } | 98 | //// } | ||
100 | // return action; | 99 | // return action; | ||
101 | //} | 100 | //} | ||
102 | 101 | /* | |||
103 | void KeyboardLayoutActionCollection::setLayoutShortcuts(QList<LayoutUnit>& layoutUnits, const Rules* rules) | 102 | void KeyboardLayoutActionCollection::setLayoutShortcuts(QList<LayoutUnit>& layoutUnits, const XkbRules* rules) | ||
104 | { | 103 | { | ||
105 | for (QList<LayoutUnit>::iterator i = layoutUnits.begin(); i != layoutUnits.end(); ++i) { | 104 | for (QList<LayoutUnit>::iterator i = layoutUnits.begin(); i != layoutUnits.end(); ++i) { | ||
106 | LayoutUnit& layoutUnit = *i; | 105 | LayoutUnit& layoutUnit = *i; | ||
107 | if( ! layoutUnit.getShortcut().isEmpty() ) { | 106 | if( ! layoutUnit.getShortcut().isEmpty() ) { | ||
108 | createLayoutShortcutActon(layoutUnit, rules, false); | 107 | createLayoutShortcutActon(layoutUnit, rules, false); | ||
109 | } | 108 | } | ||
110 | } | 109 | } | ||
111 | qCDebug(KCM_KEYBOARD) << "Cleaning component shortcuts on save" << KGlobalAccel::cleanComponent(COMPONENT_NAME); | 110 | qCDebug(KCM_KEYBOARD) << "Cleaning component shortcuts on save" << KGlobalAccel::cleanComponent(COMPONENT_NAME); | ||
112 | } | 111 | } | ||
113 | 112 | */ | |||
114 | void KeyboardLayoutActionCollection::loadLayoutShortcuts(QList<LayoutUnit>& layoutUnits, const Rules* rules) | 113 | /* | ||
114 | void KeyboardLayoutActionCollection::loadLayoutShortcuts(QList<LayoutUnit>& layoutUnits, const XkbRules* rules) | ||||
115 | { | 115 | { | ||
116 | for (QList<LayoutUnit>::iterator i = layoutUnits.begin(); i != layoutUnits.end(); ++i) { | 116 | for (QList<LayoutUnit>::iterator i = layoutUnits.begin(); i != layoutUnits.end(); ++i) { | ||
117 | LayoutUnit& layoutUnit = *i; | 117 | LayoutUnit& layoutUnit = *i; | ||
118 | QAction* action = createLayoutShortcutActon(layoutUnit, rules, true); | 118 | QAction* action = createLayoutShortcutActon(layoutUnit, rules, true); | ||
119 | const auto shortcut = KGlobalAccel::self()->shortcut(action); | 119 | const auto shortcut = KGlobalAccel::self()->shortcut(action); | ||
120 | if( ! shortcut.isEmpty() ) { | 120 | if( ! shortcut.isEmpty() ) { | ||
121 | qCDebug(KCM_KEYBOARD, ) << "Restored shortcut for" << layoutUnit.toString() << shortcut.first(); | 121 | qCDebug(KCM_KEYBOARD, ) << "Restored shortcut for" << layoutUnit.toString() << shortcut.first(); | ||
122 | layoutUnit.setShortcut(shortcut.first()); | 122 | layoutUnit.setShortcut(shortcut.first()); | ||
123 | } | 123 | } | ||
124 | else { | 124 | else { | ||
125 | qCDebug(KCM_KEYBOARD, ) << "Skipping empty shortcut for" << layoutUnit.toString(); | 125 | qCDebug(KCM_KEYBOARD, ) << "Skipping empty shortcut for" << layoutUnit.toString(); | ||
126 | removeAction(action); | 126 | removeAction(action); | ||
127 | } | 127 | } | ||
128 | } | 128 | } | ||
129 | qCDebug(KCM_KEYBOARD) << "Cleaning component shortcuts on load" << KGlobalAccel::cleanComponent(COMPONENT_NAME); | 129 | qCDebug(KCM_KEYBOARD) << "Cleaning component shortcuts on load" << KGlobalAccel::cleanComponent(COMPONENT_NAME); | ||
130 | } | 130 | } | ||
131 | 131 | */ | |||
132 | //KAction* KeyboardLayoutActionCollection::getAction(const LayoutUnit& layoutUnit) | 132 | //KAction* KeyboardLayoutActionCollection::getAction(const LayoutUnit& layoutUnit) | ||
133 | //{ | 133 | //{ | ||
134 | // for(int i=1; i<actions().size(); i++) { | 134 | // for(int i=1; i<actions().size(); i++) { | ||
135 | // if( action(i)->data() == layoutUnit.toString() ) | 135 | // if( action(i)->data() == layoutUnit.toString() ) | ||
136 | // return static_cast<KAction*>(action(i)); | 136 | // return static_cast<KAction*>(action(i)); | ||
137 | // } | 137 | // } | ||
138 | // return NULL; | 138 | // return NULL; | ||
139 | //} | 139 | //} | ||
140 | 140 | | |||
141 | void KeyboardLayoutActionCollection::resetLayoutShortcuts() | 141 | void KeyboardLayoutActionCollection::resetLayoutShortcuts() | ||
142 | { | 142 | { | ||
143 | for(int i=1; i<actions().size(); i++) { | 143 | for(int i=1; i<actions().size(); i++) { | ||
144 | KGlobalAccel::self()->setShortcut(action(i), QList<QKeySequence>(), KGlobalAccel::NoAutoloading); | 144 | KGlobalAccel::self()->setShortcut(action(i), QList<QKeySequence>(), KGlobalAccel::NoAutoloading); | ||
145 | KGlobalAccel::self()->setDefaultShortcut(action(i), QList<QKeySequence>(), KGlobalAccel::NoAutoloading); | 145 | KGlobalAccel::self()->setDefaultShortcut(action(i), QList<QKeySequence>(), KGlobalAccel::NoAutoloading); | ||
146 | } | 146 | } | ||
147 | } | 147 | } |