2
Copyright (C) 1999-2001 Lubos Lunak <l.lunak@kde.org>
3
Copyright (C) 2008 Michael Jansen <kde@michael-jansen.biz>
5
This library is free software; you can redistribute it and/or
6
modify it under the terms of the GNU Library General Public
7
License version 2 as published by the Free Software Foundation.
9
This library is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
Library General Public License for more details.
14
You should have received a copy of the GNU Library General Public License
15
along with this library; see the file COPYING.LIB. If not, write to
16
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17
Boston, MA 02110-1301, USA.
20
#include "triggers/triggers.h"
21
#include "action_data/action_data.h"
22
#include "windows_handler.h"
24
#include <KDE/KAction>
25
#include <KDE/KConfigGroup>
28
#include "shortcuts_handler.h"
32
ShortcutTriggerVisitor::~ShortcutTriggerVisitor()
36
ShortcutTrigger::ShortcutTrigger(
38
const KShortcut& shortcut,
48
ShortcutTrigger::~ShortcutTrigger()
50
keyboard_handler->removeAction( _uuid );
54
void ShortcutTrigger::accept(TriggerVisitor& visitor)
56
if (ShortcutTriggerVisitor *v = dynamic_cast<ShortcutTriggerVisitor*>(&visitor))
62
kDebug() << "Visitor error";
67
void ShortcutTrigger::aboutToBeErased()
73
void ShortcutTrigger::activate( bool newState )
76
kDebug() << "new:" << newState << "old:" << _active;
78
// If there is no change in state just return.
79
if (newState == _active)
90
// FIXME: The following workaround tries to prevent having two actions with
91
// the same uuid. That happens wile exporting/importing actions. The uuid
93
KAction *act = keyboard_handler->addAction( _uuid, name, _shortcut );
94
// addAction can change the uuid. That's why we store the uuid from the
96
_uuid = act->objectName();
99
act, SIGNAL(triggered(bool)),
100
this, SLOT(trigger()) );
103
act, SIGNAL(globalShortcutChanged(const QKeySequence&)),
104
this, SIGNAL(globalShortcutChanged(const QKeySequence&)));
108
// Disable the trigger. Delete the action.
109
KAction *action = qobject_cast<KAction*>(keyboard_handler->getAction( _uuid ));
112
// In case the shortcut was changed from the kcm.
113
_shortcut = action->globalShortcut();
114
keyboard_handler->removeAction(_uuid);
120
void ShortcutTrigger::cfg_write( KConfigGroup& cfg_P ) const
122
base::cfg_write( cfg_P );
123
cfg_P.writeEntry( "Key", shortcut().toString());
124
cfg_P.writeEntry( "Type", "SHORTCUT" ); // overwrites value set in base::cfg_write()
125
cfg_P.writeEntry( "Uuid", _uuid.toString() );
129
ShortcutTrigger* ShortcutTrigger::copy( ActionData* data_P ) const
131
return new ShortcutTrigger( data_P ? data_P : data, shortcut(), QUuid::createUuid());
135
const QString ShortcutTrigger::description() const
137
return i18n( "Shortcut trigger: " ) + shortcut().toString();
141
void ShortcutTrigger::disable()
145
// Unregister the shortcut with kglobalaccel
146
KAction *action = qobject_cast<KAction*>(keyboard_handler->getAction( _uuid ));
149
// In case the shortcut was changed from the kcm.
150
_shortcut = action->globalShortcut();
153
// Unregister the global shortcut.
154
action->forgetGlobalShortcut();
155
keyboard_handler->removeAction(_uuid);
160
void ShortcutTrigger::enable()
162
// To enable the shortcut we have to just register it once with
163
// kglobalaccel and deactivate it immediately
169
void ShortcutTrigger::set_key_sequence( const QKeySequence &seq )
171
// Get the action from the keyboard handler
172
KAction *action = qobject_cast<KAction*>(keyboard_handler->getAction( _uuid ));
175
_shortcut.setPrimary(seq);
179
action->setGlobalShortcut(
181
KAction::ActiveShortcut,
182
KAction::NoAutoloading );
187
KShortcut ShortcutTrigger::shortcut() const
189
// Get the action from the keyboard handler
190
KAction *action = qobject_cast<KAction*>(keyboard_handler->getAction( _uuid ));
197
return action->globalShortcut();
201
void ShortcutTrigger::trigger()
203
if (khotkeys_active())
205
windows_handler->set_action_window( 0 ); // use active window
211
} // namespace KHotKeys