1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
|
/****************************************************************************
KHotKeys
Copyright (C) 1999-2001 Lubos Lunak <[email protected]>
Distributed under the terms of the GNU General Public License version 2.
****************************************************************************/
#ifndef _ACTION_DATA_H_
#define _ACTION_DATA_H_
#include <assert.h>
#include <tqstring.h>
#include <tqptrlist.h>
#include <kdebug.h>
class TDEConfig;
#include "khotkeysglobal.h"
#include "windows.h"
#include "conditions.h"
#include "triggers.h"
#include "actions.h"
namespace KHotKeys
{
class Action_data_group;
class KDE_EXPORT Action_data_base
{
public:
Action_data_base( Action_data_group* parent_P, const TQString& name_P,
const TQString& comment_P, Condition_list* condition_P, bool enabled_P );
Action_data_base( TDEConfig& cfg_P, Action_data_group* parent_P );
virtual ~Action_data_base();
virtual void cfg_write( TDEConfig& cfg_P ) const = 0;
const Condition_list* conditions() const;
Action_data_group* parent() const;
void reparent( Action_data_group* new_parent_P );
virtual void update_triggers() = 0;
bool conditions_match() const;
const TQString& name() const;
void set_name( const TQString& name_P );
const TQString& comment() const;
bool enabled( bool ignore_group_P ) const;
static Action_data_base* create_cfg_read( TDEConfig& cfg_P, Action_data_group* parent_P );
static bool cfg_is_enabled( TDEConfig& cfg_P );
protected:
void set_conditions( Condition_list* conditions_P );
private:
Action_data_group* _parent;
Condition_list* _conditions;
TQString _name;
TQString _comment;
bool _enabled; // is not really important, only used in conf. module and when reading cfg. file
KHOTKEYS_DISABLE_COPY( Action_data_base );
};
class KDE_EXPORT Action_data_group
: public Action_data_base
{
public:
enum system_group_t { SYSTEM_NONE, SYSTEM_MENUENTRIES,
SYSTEM_ROOT, /* last one*/ SYSTEM_MAX }; // don't remove entries
Action_data_group( Action_data_group* parent_P, const TQString& name_P,
const TQString& comment_P, Condition_list* conditions_P, system_group_t system_group_P,
bool enabled_P );
Action_data_group( TDEConfig& cfg_P, Action_data_group* parent_P );
virtual ~Action_data_group();
virtual void update_triggers();
virtual void cfg_write( TDEConfig& cfg_P ) const;
typedef TQPtrListIterator< Action_data_base > Iterator; // CHECKME neni const :(
Iterator first_child() const;
bool is_system_group() const;
system_group_t system_group() const;
using Action_data_base::set_conditions; // make public
protected:
TQPtrList< Action_data_base > list;
system_group_t _system_group; // e.g. menuedit entries, can't be deleted or renamed
friend class Action_data_base; // CHECKME
void add_child( Action_data_base* child_P );
void remove_child( Action_data_base* child_P );
};
// this one represents a "whole" action, i.e. triggers, resulting actions, etc.
class KDE_EXPORT Action_data
: public Action_data_base
{
typedef Action_data_base base;
public:
Action_data( Action_data_group* parent_P, const TQString& name_P,
const TQString& comment_P, Trigger_list* triggers_P, Condition_list* conditions_P,
Action_list* actions_P, bool enabled_P = true );
Action_data( TDEConfig& cfg_P, Action_data_group* parent_P );
virtual ~Action_data();
virtual void update_triggers();
virtual void cfg_write( TDEConfig& cfg_P ) const = 0;
virtual void execute();
const Trigger_list* triggers() const;
const Action_list* actions() const;
protected:
virtual void add_trigger( Trigger* trigger_P );
virtual void add_triggers(
Trigger_list* triggers_P ); // Trigger_list instance will be deleted
virtual void set_triggers( Trigger_list* triggers_P );
virtual void add_action( Action* action_P, Action* after_P = NULL );
virtual void add_actions( Action_list* actions_P,
Action* after_P = NULL ); // Action_list will be deleted
virtual void set_actions( Action_list* actions_P );
private:
Trigger_list* _triggers;
Action_list* _actions;
#if 0
action_type_t _type;
static const char* const types[];
#endif
};
class KDE_EXPORT Generic_action_data
: public Action_data
{
typedef Action_data base;
public:
Generic_action_data( Action_data_group* parent_P, const TQString& name_P,
const TQString& comment_P, Trigger_list* triggers_P, Condition_list* conditions_P,
Action_list* actions_P, bool enabled_P = true );
Generic_action_data( TDEConfig& cfg_P, Action_data_group* parent_P );
virtual void cfg_write( TDEConfig& cfg_P ) const;
using Action_data_base::set_conditions; // make public
using Action_data::add_trigger; // make public
using Action_data::add_triggers; // make public
using Action_data::set_triggers; // make public
using Action_data::add_action; // make public
using Action_data::add_actions; // make public
using Action_data::set_actions; // make public
};
template< typename T, typename A >
class KDE_EXPORT Simple_action_data
: public Action_data
{
typedef Action_data base;
public:
Simple_action_data( Action_data_group* parent_P, const TQString& name_P,
const TQString& comment_P, bool enabled_P = true );
Simple_action_data( TDEConfig& cfg_P, Action_data_group* parent_P );
const A* action() const;
const T* trigger() const;
// CHECKME kontrola, ze se dava jen jedna akce ?
void set_action( A* action_P );
void set_trigger( T* trigger_P );
virtual void cfg_write( TDEConfig& cfg_P ) const;
};
class KDE_EXPORT Command_url_shortcut_action_data
: public Simple_action_data< Shortcut_trigger, Command_url_action >
{
typedef Simple_action_data< Shortcut_trigger, Command_url_action > base;
public:
Command_url_shortcut_action_data( Action_data_group* parent_P, const TQString& name_P,
const TQString& comment_P, bool enabled_P = true );
Command_url_shortcut_action_data( Action_data_group* parent_P, const TQString& name_P,
const TQString& comment_P, const KShortcut& shortcut_P, const TQString& command_url_P,
bool enabled_P = true );
Command_url_shortcut_action_data( TDEConfig& cfg_P, Action_data_group* parent_P );
};
class KDE_EXPORT Menuentry_shortcut_action_data
: public Simple_action_data< Shortcut_trigger, Menuentry_action >
{
typedef Simple_action_data< Shortcut_trigger, Menuentry_action > base;
public:
Menuentry_shortcut_action_data( Action_data_group* parent_P, const TQString& name_P,
const TQString& comment_P, bool enabled_P = true );
Menuentry_shortcut_action_data( Action_data_group* parent_P, const TQString& name_P,
const TQString& comment_P, const KShortcut& shortcut_P, const TQString& command_url_P,
bool enabled_P = true );
Menuentry_shortcut_action_data( TDEConfig& cfg_P, Action_data_group* parent_P );
};
typedef Simple_action_data< Shortcut_trigger, Dcop_action > Dcop_shortcut_action_data;
typedef Simple_action_data< Shortcut_trigger, Keyboard_input_action >
Keyboard_input_shortcut_action_data;
typedef Simple_action_data< Shortcut_trigger, Activate_window_action >
Activate_window_shortcut_action_data;
class KDE_EXPORT Keyboard_input_gesture_action_data
: public Action_data
{
typedef Action_data base;
public:
Keyboard_input_gesture_action_data( Action_data_group* parent_P, const TQString& name_P,
const TQString& comment_P, bool enabled_P = true );
Keyboard_input_gesture_action_data( TDEConfig& cfg_P, Action_data_group* parent_P );
const Keyboard_input_action* action() const;
// CHECKME kontrola, ze se dava jen jedna akce ?
void set_action( Keyboard_input_action* action_P );
enum { NUM_TRIGGERS = 3 }; // needs changing code elsewhere
using Action_data::set_triggers; // make public // CHECKME kontrola poctu?
virtual void cfg_write( TDEConfig& cfg_P ) const;
};
//***************************************************************************
// Inline
//***************************************************************************
// Action_data_base
inline
const Condition_list* Action_data_base::conditions() const
{
// assert( _conditions != NULL );
return _conditions;
}
inline
void Action_data_base::set_conditions( Condition_list* conditions_P )
{
assert( _conditions == NULL );
_conditions = conditions_P;
}
inline
Action_data_group* Action_data_base::parent() const
{
return _parent;
}
inline
void Action_data_base::set_name( const TQString& name_P )
{
_name = name_P;
}
inline
const TQString& Action_data_base::name() const
{
return _name;
}
inline
const TQString& Action_data_base::comment() const
{
return _comment;
}
// Action_data_group
inline
Action_data_group::Action_data_group( Action_data_group* parent_P, const TQString& name_P,
const TQString& comment_P, Condition_list* conditions_P, system_group_t system_group_P,
bool enabled_P )
: Action_data_base( parent_P, name_P, comment_P, conditions_P, enabled_P ),
_system_group( system_group_P )
{
}
inline
Action_data_group::~Action_data_group()
{
// kdDebug( 1217 ) << "~Action_data_group() :" << list.count() << endl;
while( list.first())
delete list.first();
}
inline
Action_data_group::Iterator Action_data_group::first_child() const
{
return Iterator( list );
}
inline
bool Action_data_group::is_system_group() const
{
return _system_group != SYSTEM_NONE;
}
inline
Action_data_group::system_group_t Action_data_group::system_group() const
{
return _system_group;
}
inline
void Action_data_group::add_child( Action_data_base* child_P )
{
list.append( child_P ); // CHECKME tohle asi znemozni je mit nejak rucne serazene
}
inline
void Action_data_group::remove_child( Action_data_base* child_P )
{
list.removeRef( child_P ); // is not auto-delete
}
// Action_data
inline
Action_data::Action_data( Action_data_group* parent_P, const TQString& name_P,
const TQString& comment_P, Trigger_list* triggers_P, Condition_list* conditions_P,
Action_list* actions_P, bool enabled_P )
: Action_data_base( parent_P, name_P, comment_P, conditions_P, enabled_P ),
_triggers( triggers_P ), _actions( actions_P )
{
}
inline
const Trigger_list* Action_data::triggers() const
{
// assert( _triggers != NULL );
return _triggers;
}
inline
const Action_list* Action_data::actions() const
{
// assert( _actions != NULL );
return _actions;
}
// Generic_action_data
inline
Generic_action_data::Generic_action_data( Action_data_group* parent_P, const TQString& name_P,
const TQString& comment_P, Trigger_list* triggers_P, Condition_list* conditions_P,
Action_list* actions_P, bool enabled_P )
: Action_data( parent_P, name_P, comment_P, triggers_P, conditions_P, actions_P, enabled_P )
{
}
inline
Generic_action_data::Generic_action_data( TDEConfig& cfg_P, Action_data_group* parent_P )
: Action_data( cfg_P, parent_P )
{ // CHECKME do nothing ?
}
// Simple_action_data
template< typename T, typename A >
inline
Simple_action_data< T, A >::Simple_action_data( Action_data_group* parent_P,
const TQString& name_P, const TQString& comment_P, bool enabled_P )
: Action_data( parent_P, name_P, comment_P, NULL,
new Condition_list( "", this ), NULL, enabled_P )
{
}
template< typename T, typename A >
inline
Simple_action_data< T, A >::Simple_action_data( TDEConfig& cfg_P, Action_data_group* parent_P )
: Action_data( cfg_P, parent_P )
{ // CHECKME nothing ?
}
template< typename T, typename A >
void Simple_action_data< T, A >::set_action( A* action_P )
{
Action_list* tmp = new Action_list( "Simple_action_data" );
tmp->append( action_P );
set_actions( tmp );
}
template< typename T, typename A >
void Simple_action_data< T, A >::set_trigger( T* trigger_P )
{
Trigger_list* tmp = new Trigger_list( "Simple_action" );
tmp->append( trigger_P );
set_triggers( tmp );
}
template< typename T, typename A >
const A* Simple_action_data< T, A >::action() const
{
if( actions() == NULL || actions()->count() == 0 ) // CHECKME tohle poradne zkontrolovat
return NULL;
return static_cast< A* >( const_cast< Action_list* >( actions())->first());
}
template< typename T, typename A >
const T* Simple_action_data< T, A >::trigger() const
{
if( triggers() == NULL || triggers()->count() == 0 ) // CHECKME tohle poradne zkontrolovat
return NULL;
return static_cast< T* >( const_cast< Trigger_list* >( triggers())->first());
}
// Command_url_action_data
inline
Command_url_shortcut_action_data::Command_url_shortcut_action_data( Action_data_group* parent_P,
const TQString& name_P, const TQString& comment_P, bool enabled_P )
: Simple_action_data< Shortcut_trigger, Command_url_action >( parent_P, name_P,
comment_P, enabled_P )
{
}
inline
Command_url_shortcut_action_data::Command_url_shortcut_action_data( TDEConfig& cfg_P,
Action_data_group* parent_P )
: Simple_action_data< Shortcut_trigger, Command_url_action >( cfg_P, parent_P )
{
}
// Menuentry_action_data
inline
Menuentry_shortcut_action_data::Menuentry_shortcut_action_data( Action_data_group* parent_P,
const TQString& name_P, const TQString& comment_P, bool enabled_P )
: Simple_action_data< Shortcut_trigger, Menuentry_action >( parent_P, name_P,
comment_P, enabled_P )
{
}
inline
Menuentry_shortcut_action_data::Menuentry_shortcut_action_data( TDEConfig& cfg_P,
Action_data_group* parent_P )
: Simple_action_data< Shortcut_trigger, Menuentry_action >( cfg_P, parent_P )
{
}
// Keyboard_input_gesture_action_data
inline
Keyboard_input_gesture_action_data::Keyboard_input_gesture_action_data(
Action_data_group* parent_P, const TQString& name_P, const TQString& comment_P, bool enabled_P )
: Action_data( parent_P, name_P, comment_P, NULL,
new Condition_list( "", this ), NULL, enabled_P )
{
}
inline
Keyboard_input_gesture_action_data::Keyboard_input_gesture_action_data( TDEConfig& cfg_P,
Action_data_group* parent_P )
: Action_data( cfg_P, parent_P )
{ // CHECKME nothing ?
}
} // namespace KHotKeys
#endif
|