not quite so much needs to be delayed to the init() function
[personal-kdebase.git] / workspace / khotkeys / libkhotkeysprivate / action_data / action_data.cpp
blobdc0e37d39ab9a276cfa5be666d2a6f19b0fca92b
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 #include "action_data/action_data.h"
13 #include "actions/actions.h"
14 #include "triggers/triggers.h"
16 #include <kconfiggroup.h>
17 #include <kdebug.h>
20 namespace KHotKeys
24 ActionData::ActionData( KConfigGroup& cfg_P, ActionDataGroup* parent_P )
25 : ActionDataBase( cfg_P, parent_P )
27 KConfigGroup triggersGroup( cfg_P.config(), cfg_P.name() + "Triggers" );
28 _triggers = new Trigger_list( triggersGroup, this );
29 KConfigGroup actionsGroup( cfg_P.config(), cfg_P.name() + "Actions" );
30 _actions = new ActionList( actionsGroup, this );
34 ActionData::~ActionData()
36 // kDebug() << "~ActionData" << this;
37 delete _triggers;
38 delete _actions;
39 // CHECKME jeste remove z parenta ?
43 ActionData::ActionData( ActionDataGroup* parent_P, const QString& name_P,
44 const QString& comment_P, Trigger_list* triggers_P, Condition_list* conditions_P,
45 ActionList* actions_P, bool enabled_P )
46 : ActionDataBase( parent_P, name_P, comment_P, conditions_P, enabled_P ),
47 _triggers( triggers_P ), _actions( actions_P )
52 const Trigger_list* ActionData::triggers() const
54 // Q_ASSERT( _triggers != 0 );
55 return _triggers;
59 void ActionData::aboutToBeErased()
61 _triggers->aboutToBeErased();
62 _actions->aboutToBeErased();
65 const ActionList* ActionData::actions() const
67 // Q_ASSERT( _actions != 0 );
68 return _actions;
72 void ActionData::cfg_write( KConfigGroup& cfg_P ) const
74 ActionDataBase::cfg_write( cfg_P );
76 // Write triggers if available
77 if (triggers())
79 KConfigGroup triggersGroup( cfg_P.config(), cfg_P.name() + "Triggers" );
80 triggers()->cfg_write( triggersGroup );
82 // Write actions if available
83 if (actions())
85 KConfigGroup actionsGroup( cfg_P.config(), cfg_P.name() + "Actions" );
86 actions()->cfg_write( actionsGroup );
91 void ActionData::execute()
93 for( ActionList::Iterator it = _actions->begin();
94 it != _actions->end();
95 ++it )
96 (*it)->execute();
97 // CHECKME nebo nejak zpozdeni ?
101 void ActionData::add_trigger( Trigger* trigger_P )
103 _triggers->append( trigger_P );
107 void ActionData::add_triggers( Trigger_list* triggers_P )
109 while (!triggers_P->isEmpty())
111 _triggers->append( triggers_P->takeFirst() );
113 Q_ASSERT( triggers_P->isEmpty());
114 delete triggers_P;
118 void ActionData::set_triggers( Trigger_list* triggers_P )
120 Q_ASSERT( _triggers == 0 );
121 _triggers = triggers_P;
125 void ActionData::add_action( Action* action_P, Action* after_P )
127 int index = 0;
128 for( ActionList::Iterator it = _actions->begin();
129 it != _actions->end();
130 ++it )
132 ++index;
133 if( *it == after_P )
134 break;
136 _actions->insert( index, action_P );
140 void ActionData::add_actions( ActionList* actions_P, Action* after_P )
142 int index = 0;
143 for( ActionList::Iterator it = _actions->begin();
144 it != _actions->end();
145 ++it )
147 ++index;
148 if( *it == after_P )
149 break;
152 while (!actions_P->empty())
154 // Insert the actions to _actions after removing them from actions_P
155 // to prevent their deletion upon delete actions_P below.
156 _actions->insert( ++index, actions_P->takeFirst() );
158 Q_ASSERT( actions_P->isEmpty());
159 delete actions_P;
163 void ActionData::set_actions( ActionList* actions_P )
165 Q_ASSERT( _actions == 0 );
166 _actions = actions_P;
170 void ActionData::update_triggers()
172 bool activate = conditions_match() && enabled( false );
173 kDebug() << "### Update triggers: " << name() << ":" << activate;
174 for( Trigger_list::Iterator it = _triggers->begin();
175 it != _triggers->end();
176 ++it )
178 // kDebug() << "Going over the triggers";
179 (*it)->activate( activate );
184 } // namespace KHotKeys