not quite so much needs to be delayed to the init() function
[personal-kdebase.git] / workspace / khotkeys / libkhotkeysprivate / action_data / simple_action_data.h
blob3c96b031291a40912463964cea426320fb91c972
1 /****************************************************************************
3 KHotKeys
5 Copyright (C) 1999-2001 Lubos Lunak <l.lunak@kde.org>
7 Distributed under the terms of the GNU General Public License version 2.
9 ****************************************************************************/
11 #ifndef SIMPLE_ACTION_DATA_H
12 #define SIMPLE_ACTION_DATA_H
14 #include "action_data/action_data.h"
16 #include "actions/actions.h"
17 #include "triggers/triggers.h"
19 namespace KHotKeys {
22 class KDE_EXPORT SimpleActionData : public ActionData
24 typedef ActionData base;
26 public:
28 SimpleActionData(
29 ActionDataGroup* parent_P,
30 const QString& name_P,
31 const QString& comment_P,
32 bool enabled_P = true );
34 SimpleActionData(
35 KConfigGroup& cfg_P,
36 ActionDataGroup* parent_P );
38 //! The action associated with this hotkey
39 virtual const Action* action() const;
40 virtual Action* action();
42 //! The trigger for this hotkey
43 virtual const Trigger* trigger() const;
44 virtual Trigger* trigger();
46 void set_action( Action* action_P );
47 void set_trigger( Trigger* trigger_P );
49 virtual void cfg_write( KConfigGroup& cfg_P ) const;
50 }; // class SimpleActionData
53 /**
54 * A template adding convenience methods to SimpleActionData.
56 template< typename T, typename A >
57 class KDE_EXPORT Simple_action_data
58 : public SimpleActionData
60 typedef SimpleActionData base;
62 public:
64 Simple_action_data(
65 ActionDataGroup* parent_P,
66 const QString& name_P,
67 const QString& comment_P,
68 bool enabled_P = true )
69 : base( parent_P, name_P, comment_P, enabled_P )
72 Simple_action_data(
73 KConfigGroup& cfg_P,
74 ActionDataGroup* parent_P )
75 : base( cfg_P, parent_P )
78 //! The action associated with this hotkey
79 const A* action() const;
80 A* action();
82 //! The trigger for this hotkey
83 const T* trigger() const;
84 T* trigger();
86 void set_action( Action *action_P );
87 void set_trigger( Trigger *trigger_P );
89 virtual void cfg_write( KConfigGroup& cfg_P ) const;
92 // ==========================================================================
93 // TYPEDEFS
95 //! A keyboard shortcut to dbus call action
96 typedef Simple_action_data< ShortcutTrigger, DBusAction > Dbus_shortcut_action_data;
98 //! A keyboard shortcut to keyboard input action
99 typedef Simple_action_data< ShortcutTrigger, KeyboardInputAction >
100 Keyboard_input_shortcut_action_data;
102 //! A keyboard shortcut to activate window action
103 typedef Simple_action_data< ShortcutTrigger, ActivateWindowAction >
104 Activate_window_shortcut_action_data;
107 // ==========================================================================
108 // TEMPLATE METHOD DEFINITIONS
111 template< typename T, typename A >
112 void Simple_action_data< T, A >::set_action( Action* action_P )
114 Q_ASSERT( dynamic_cast<A*>( action_P ) );
115 base::set_action(action_P);
118 template< typename T, typename A >
119 void Simple_action_data< T, A >::set_trigger( Trigger* trigger_P )
121 Q_ASSERT( dynamic_cast<T*>( trigger_P ) );
122 base::set_trigger(trigger_P);
125 template< typename T, typename A >
126 const A* Simple_action_data< T, A >::action() const
128 if( actions() == 0 || actions()->isEmpty() )
129 return 0;
130 return dynamic_cast< const A* >( actions()->first());
133 template< typename T, typename A >
134 A* Simple_action_data< T, A >::action()
136 if( actions() == 0 || actions()->isEmpty() )
137 return 0;
138 return dynamic_cast< A* >(actions()->first());
141 template< typename T, typename A >
142 const T* Simple_action_data< T, A >::trigger() const
144 if( triggers() == 0 || triggers()->isEmpty() )
145 return 0;
146 return dynamic_cast< const T* >( triggers()->first());
149 template< typename T, typename A >
150 T* Simple_action_data< T, A >::trigger()
152 if( triggers() == 0 || triggers()->isEmpty() )
153 return 0;
154 return dynamic_cast< T* >( triggers()->first());
157 } // namespace KHotKeys
159 #endif