~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to khotkeys/libkhotkeysprivate/action_data/action_data.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
 
 
3
 KHotKeys
 
4
 
 
5
 Copyright (C) 1999-2001 Lubos Lunak <l.lunak@kde.org>
 
6
 
 
7
 Distributed under the terms of the GNU General Public License version 2.
 
8
 
 
9
****************************************************************************/
 
10
 
 
11
#include "action_data/action_data.h"
 
12
 
 
13
#include "action_data/action_data_visitor.h"
 
14
#include "actions/actions.h"
 
15
#include "triggers/triggers.h"
 
16
 
 
17
#include <kconfiggroup.h>
 
18
#include <kdebug.h>
 
19
 
 
20
 
 
21
namespace KHotKeys
 
22
{
 
23
 
 
24
 
 
25
ActionData::ActionData(
 
26
        ActionDataGroup* parent_P,
 
27
        const QString& name_P,
 
28
        const QString& comment_P,
 
29
        Trigger_list* triggers_P,
 
30
        Condition_list* conditions_P,
 
31
        ActionList* actions_P)
 
32
    :   ActionDataBase( parent_P, name_P, comment_P, conditions_P),
 
33
        _triggers( triggers_P ),
 
34
        _actions( actions_P )
 
35
    {
 
36
    if (!_triggers)
 
37
        _triggers = new Trigger_list;
 
38
 
 
39
    if (!_actions)
 
40
        _actions = new ActionList;
 
41
    }
 
42
 
 
43
 
 
44
void ActionData::accept(ActionDataConstVisitor *visitor) const
 
45
    {
 
46
    visitor->visitActionData(this);
 
47
    }
 
48
 
 
49
 
 
50
ActionData::~ActionData()
 
51
    {
 
52
    delete _triggers; _triggers = NULL;
 
53
    delete _actions; _actions = NULL;
 
54
    }
 
55
 
 
56
 
 
57
void ActionData::accept(ActionDataVisitor *visitor)
 
58
    {
 
59
    visitor->visitActionData(this);
 
60
    }
 
61
 
 
62
void ActionData::doDisable()
 
63
    {
 
64
    triggers()->disable();
 
65
    update_triggers();
 
66
    }
 
67
 
 
68
void ActionData::doEnable()
 
69
    {
 
70
    triggers()->enable();
 
71
    update_triggers();
 
72
    }
 
73
 
 
74
 
 
75
Trigger_list* ActionData::triggers()
 
76
    {
 
77
    return _triggers;
 
78
    }
 
79
 
 
80
 
 
81
const Trigger_list* ActionData::triggers() const
 
82
    {
 
83
    return _triggers;
 
84
    }
 
85
 
 
86
 
 
87
void ActionData::aboutToBeErased()
 
88
    {
 
89
    _triggers->aboutToBeErased();
 
90
    _actions->aboutToBeErased();
 
91
    }
 
92
 
 
93
const ActionList* ActionData::actions() const
 
94
    {
 
95
    return _actions;
 
96
    }
 
97
 
 
98
 
 
99
ActionList* ActionData::actions()
 
100
    {
 
101
    return _actions;
 
102
    }
 
103
 
 
104
 
 
105
void ActionData::execute()
 
106
    {
 
107
    for( ActionList::Iterator it = _actions->begin();
 
108
         it != _actions->end();
 
109
         ++it )
 
110
        (*it)->execute();
 
111
    }
 
112
 
 
113
 
 
114
void ActionData::add_trigger( Trigger* trigger_P )
 
115
    {
 
116
    _triggers->append( trigger_P );
 
117
    }
 
118
 
 
119
 
 
120
void ActionData::add_triggers( Trigger_list* triggers_P )
 
121
    {
 
122
    while (!triggers_P->isEmpty())
 
123
        {
 
124
        _triggers->append( triggers_P->takeFirst() );
 
125
        }
 
126
    Q_ASSERT( triggers_P->isEmpty());
 
127
    delete triggers_P;
 
128
    }
 
129
 
 
130
 
 
131
void ActionData::set_triggers( Trigger_list* triggers_P )
 
132
    {
 
133
    if (_triggers) delete _triggers;
 
134
 
 
135
    _triggers = triggers_P;
 
136
    }
 
137
 
 
138
 
 
139
void ActionData::add_action(Action* action, Action* after)
 
140
    {
 
141
    if (after)
 
142
        {
 
143
        int index = _actions->indexOf(after);
 
144
        _actions->insert(
 
145
                index != -1
 
146
                    ? index +1
 
147
                    : _actions->count(),
 
148
                action);
 
149
        }
 
150
    else
 
151
        {
 
152
        _actions->append(action);
 
153
        }
 
154
    }
 
155
 
 
156
 
 
157
void ActionData::add_actions( ActionList* actions_P, Action* after_P )
 
158
    {
 
159
    int index = 0;
 
160
    for( ActionList::Iterator it = _actions->begin();
 
161
         it != _actions->end();
 
162
         ++it )
 
163
        {
 
164
        ++index;
 
165
        if( *it == after_P )
 
166
            break;
 
167
        }
 
168
 
 
169
    while (!actions_P->empty())
 
170
        {
 
171
        // Insert the actions to _actions after removing them from actions_P
 
172
        // to prevent their deletion upon delete actions_P below.
 
173
        _actions->insert( ++index, actions_P->takeFirst() );
 
174
        }
 
175
    Q_ASSERT( actions_P->isEmpty());
 
176
    delete actions_P;
 
177
    }
 
178
 
 
179
 
 
180
void ActionData::set_actions( ActionList* actions_P )
 
181
    {
 
182
    if (_actions) delete _actions;
 
183
    _actions = actions_P;
 
184
    }
 
185
 
 
186
 
 
187
void ActionData::update_triggers()
 
188
    {
 
189
    if (!_triggers) return;
 
190
 
 
191
    bool activate = false;
 
192
    // Activate the triggers if the actions is enabled and the conditions
 
193
    // match.
 
194
    if (isEnabled() && conditions_match())
 
195
        {
 
196
        activate = true;
 
197
        }
 
198
 
 
199
    for( Trigger_list::Iterator it = _triggers->begin();
 
200
         it != _triggers->end();
 
201
         ++it )
 
202
        {
 
203
        (*it)->activate(activate);
 
204
        }
 
205
    }
 
206
 
 
207
 
 
208
} // namespace KHotKeys