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"
24 #include <KDE/KAction>
25 #include <KDE/KConfigGroup>
28 #include "shortcuts_handler.h"
32 ShortcutTrigger::ShortcutTrigger(
34 const KShortcut
& shortcut
,
36 : Trigger( data_P
), _uuid(uuid
)
41 name
= data_P
->name();
47 KAction
*act
= keyboard_handler
->addAction( _uuid
, name
, shortcut
);
49 act
, SIGNAL(triggered(bool)),
50 this, SLOT(trigger()) );
53 act
, SIGNAL(globalShortcutChanged(const QKeySequence
&)),
54 this, SIGNAL(globalShortcutChanged(const QKeySequence
&)));
58 ShortcutTrigger::ShortcutTrigger(
61 : Trigger( cfg_P
, data_P
)
62 ,_uuid( cfg_P
.readEntry( "Uuid", QUuid::createUuid().toString()))
64 QString shortcutString
= cfg_P
.readEntry( "Key" );
66 // TODO: Check if this is still necessary
67 shortcutString
.replace("Win+", "Meta+"); // Qt4 doesn't parse Win+, avoid a shortcut without modifier
69 KAction
*act
= keyboard_handler
->addAction(
72 KShortcut(shortcutString
));
75 act
, SIGNAL(triggered(bool)),
76 this, SLOT(trigger()) );
79 act
, SIGNAL(globalShortcutChanged(const QKeySequence
&)),
80 this, SIGNAL(globalShortcutChanged(const QKeySequence
&)));
84 ShortcutTrigger::~ShortcutTrigger()
86 keyboard_handler
->removeAction( _uuid
);
90 void ShortcutTrigger::aboutToBeErased()
93 KAction
*action
= qobject_cast
<KAction
*>(keyboard_handler
->getAction( _uuid
));
96 kDebug() << "removing the global shortcut";
97 action
->forgetGlobalShortcut();
102 void ShortcutTrigger::activate( bool activate_P
)
104 kDebug() << activate_P
<< " and " << khotkeys_active();
105 if( activate_P
&& khotkeys_active())
107 kDebug() << "TODO implement activate";
111 kDebug() << "TODO implement activate";
116 void ShortcutTrigger::cfg_write( KConfigGroup
& cfg_P
) const
118 base::cfg_write( cfg_P
);
119 cfg_P
.writeEntry( "Key", shortcut().toString());
120 cfg_P
.writeEntry( "Type", "SHORTCUT" ); // overwrites value set in base::cfg_write()
121 cfg_P
.writeEntry( "Uuid", _uuid
.toString() );
125 ShortcutTrigger
* ShortcutTrigger::copy( ActionData
* data_P
) const
127 kDebug() << "Shortcut_trigger::copy()";
128 return new ShortcutTrigger( data_P
? data_P
: data
, shortcut(), QUuid::createUuid());
132 const QString
ShortcutTrigger::description() const
135 return i18n( "Shortcut trigger: " ) + shortcut().toString();
136 // CHECKME i18n pro toString() ?
140 void ShortcutTrigger::set_key_sequence( const QKeySequence
&seq
)
142 // Get the action from the keyboard handler
143 KAction
*action
= qobject_cast
<KAction
*>(keyboard_handler
->getAction( _uuid
));
147 // Set our key sequence
148 action
->setGlobalShortcut(
150 KAction::ActiveShortcut
,
151 KAction::NoAutoloading
);
155 KShortcut
ShortcutTrigger::shortcut() const
157 // Get the action from the keyboard handler
158 KAction
*action
= qobject_cast
<KAction
*>(keyboard_handler
->getAction( _uuid
));
163 return action
->globalShortcut();
167 void ShortcutTrigger::trigger()
169 kDebug() << data
->name() << " was triggered";
170 windows_handler
->set_action_window( 0 ); // use active window
175 } // namespace KHotKeys