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/action_data.h"
13 #include "actions/actions.h"
14 #include "triggers/triggers.h"
16 #include <kconfiggroup.h>
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;
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 );
59 void ActionData::aboutToBeErased()
61 _triggers
->aboutToBeErased();
62 _actions
->aboutToBeErased();
65 const ActionList
* ActionData::actions() const
67 // Q_ASSERT( _actions != 0 );
72 void ActionData::cfg_write( KConfigGroup
& cfg_P
) const
74 ActionDataBase::cfg_write( cfg_P
);
76 // Write triggers if available
79 KConfigGroup
triggersGroup( cfg_P
.config(), cfg_P
.name() + "Triggers" );
80 triggers()->cfg_write( triggersGroup
);
82 // Write actions if available
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();
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());
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
)
128 for( ActionList::Iterator it
= _actions
->begin();
129 it
!= _actions
->end();
136 _actions
->insert( index
, action_P
);
140 void ActionData::add_actions( ActionList
* actions_P
, Action
* after_P
)
143 for( ActionList::Iterator it
= _actions
->begin();
144 it
!= _actions
->end();
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());
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();
178 // kDebug() << "Going over the triggers";
179 (*it
)->activate( activate
);
184 } // namespace KHotKeys