1 /****************************************************************************
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 #include "action_data_base.h"
13 #include "generic_action_data.h"
14 #include "command_url_shortcut_action_data.h"
15 #include "menuentry_shortcut_action_data.h"
16 #include "keyboard_input_gesture_action_data.h"
18 #include "triggers/triggers.h"
19 #include "conditions/conditions.h"
22 #include <kconfiggroup.h>
29 ActionDataBase::ActionDataBase(
30 ActionDataGroup
* parent_P
31 ,const QString
& name_P
32 ,const QString
& comment_P
33 ,Condition_list
* conditions_P
36 ,_conditions(conditions_P
)
42 parent()->add_child( this );
43 if( _conditions
!= 0 )
44 _conditions
->set_data( this );
48 ActionDataBase::ActionDataBase(
50 ,ActionDataGroup
* parent_P
)
54 _name
= cfg_P
.readEntry( "Name" );
55 _comment
= cfg_P
.readEntry( "Comment" );
56 _enabled
= cfg_P
.readEntry( "Enabled", true);
57 KConfigGroup
conditionsConfig( cfg_P
.config(), cfg_P
.name() + "Conditions" );
59 // Load the conditions if they exist
60 if ( conditionsConfig
.exists() )
62 kDebug() << "Reading conditions";
63 _conditions
= new Condition_list( conditionsConfig
, this );
67 parent()->add_child( this );
71 ActionDataBase::~ActionDataBase()
74 parent()->remove_child( this );
79 bool ActionDataBase::cfg_is_enabled( KConfigGroup
& cfg_P
)
81 return cfg_P
.readEntry( "Enabled", true);
85 void ActionDataBase::cfg_write( KConfigGroup
& cfg_P
) const
87 kDebug() << cfg_P
.keyList();
89 cfg_P
.writeEntry( "Type", "ERROR" ); // derived classes should call with their type
90 cfg_P
.writeEntry( "Name", name());
91 cfg_P
.writeEntry( "Comment", comment());
92 cfg_P
.writeEntry( "Enabled", enabled( true ));
94 if ( conditions() != 0 )
96 kDebug() << "writing conditions";
97 KConfigGroup
conditionsConfig( cfg_P
.config(), cfg_P
.name() + "Conditions" );
98 conditions()->cfg_write( conditionsConfig
);
103 QString
ActionDataBase::comment() const
109 const Condition_list
* ActionDataBase::conditions() const
115 bool ActionDataBase::conditions_match() const
117 return ( conditions() ? conditions()->match() : true )
118 && ( parent() ? parent()->conditions_match() : true );
122 ActionDataBase
* ActionDataBase::create_cfg_read( KConfigGroup
& cfg_P
, ActionDataGroup
* parent_P
)
124 QString type
= cfg_P
.readEntry( "Type" );
125 if( type
== "ACTION_DATA_GROUP" )
127 if( cfg_P
.readEntry( "AllowMerge", false ))
129 Q_FOREACH(ActionDataBase
*child
,parent_P
->children())
131 if( ActionDataGroup
* existing
= dynamic_cast< ActionDataGroup
* >(child
))
133 if( cfg_P
.readEntry( "Name" ) == existing
->name())
138 return new ActionDataGroup( cfg_P
, parent_P
);
140 if( type
== "GENERIC_ACTION_DATA" )
141 return new Generic_action_data( cfg_P
, parent_P
);
142 else if( type
== "KEYBOARD_INPUT_GESTURE_ACTION_DATA" )
143 return new Keyboard_input_gesture_action_data( cfg_P
, parent_P
);
144 else if( type
== "SIMPLE_ACTION_DATA"
145 || type
== "DCOP_SHORTCUT_ACTION_DATA" || type
== "DBUS_SHORTCUT_ACTION_DATA"
146 || type
== "MENUENTRY_SHORTCUT_ACTION_DATA"
147 || type
== "COMMAND_URL_SHORTCUT_ACTION_DATA"
148 || type
== "KEYBOARD_INPUT_SHORTCUT_ACTION_DATA"
149 || type
== "ACTIVATE_WINDOW_SHORTCUT_ACTION_DATA" )
150 return new SimpleActionData( cfg_P
, parent_P
);
151 kWarning() << "Unknown ActionDataBase type read from cfg file\n";
156 bool ActionDataBase::enabled( bool ignore_group_P
) const
161 return _enabled
&& ( parent() == 0 || parent()->enabled( false ));
165 QString
ActionDataBase::name() const
171 ActionDataGroup
* ActionDataBase::parent() const
177 void ActionDataBase::set_comment( const QString
&comment
)
183 void ActionDataBase::set_enabled( bool enabled
)
189 void ActionDataBase::set_name( const QString
& name_P
)
195 void ActionDataBase::reparent( ActionDataGroup
* new_parent_P
)
197 if( parent() == new_parent_P
)
201 parent()->remove_child( this );
202 _parent
= new_parent_P
;
204 parent()->add_child( this );
208 void ActionDataBase::set_conditions( Condition_list
* conditions_P
)
210 Q_ASSERT( _conditions
== 0 );
211 _conditions
= conditions_P
;
215 } // namespace KHotKeys