summaryrefslogtreecommitdiffstats
path: root/khotkeys/shared/actions.h
blob: d2e63db85078b2837ee19a68fa33bb30898573ab (plain)
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
/****************************************************************************

 KHotKeys
 
 Copyright (C) 1999-2001 Lubos Lunak <l.lunak@kde.org>

 Distributed under the terms of the GNU General Public License version 2.
 
****************************************************************************/

#ifndef _ACTIONS_H_
#define _ACTIONS_H_


#include <tqstring.h>
#include <tqptrlist.h>
#include <tqtimer.h>

#include <kservice.h>

class TDEConfig;

#include "khotkeysglobal.h"

namespace KHotKeys
{

class Action_data;
class Windowdef_list;

// this one is a base for all "real" resulting actions, e.g. running a command,
// Action_data instances usually contain at least one Action
class TDE_EXPORT Action
    {
    public:
        Action( Action_data* data_P );
        Action( TDEConfig& cfg_P, Action_data* data_P );
        virtual ~Action();
        virtual void execute() = 0;
        virtual TQString description() const = 0;
        virtual void cfg_write( TDEConfig& cfg_P ) const;
        virtual Action* copy( Action_data* data_P ) const = 0;
        static Action* create_cfg_read( TDEConfig& cfg_P, Action_data* data_P );
    protected:
        Action_data* const data;
    KHOTKEYS_DISABLE_COPY( Action );
    };

class TDE_EXPORT Action_list
    : public TQPtrList< Action >
    {
    public:
        Action_list( const TQString& comment_P );
        Action_list( TDEConfig& cfg_P, Action_data* data_P );
        void cfg_write( TDEConfig& cfg_P ) const;
        typedef TQPtrListIterator< Action > Iterator;
        const TQString& comment() const;
    private:
        TQString _comment;
    KHOTKEYS_DISABLE_COPY( Action_list );
    };

class TDE_EXPORT Command_url_action
    : public Action
    {
    typedef Action base;
    public:
        Command_url_action( Action_data* data_P, const TQString& command_url_P );
        Command_url_action( TDEConfig& cfg_P, Action_data* data_P );
        virtual void cfg_write( TDEConfig& cfg_P ) const;
        virtual void execute();
        virtual TQString description() const;
        const TQString& command_url() const;
        virtual Action* copy( Action_data* data_P ) const;
    protected:
        TQTimer timeout;
    private:
        TQString _command_url;
    };
    
class TDE_EXPORT Menuentry_action
    : public Command_url_action
    {
    typedef Command_url_action base;
    public:
        Menuentry_action( Action_data* data_P, const TQString& menuentry_P );
        Menuentry_action( TDEConfig& cfg_P, Action_data* data_P );
        virtual void cfg_write( TDEConfig& cfg_P ) const;
        virtual void execute();
        virtual TQString description() const;
        virtual Action* copy( Action_data* data_P ) const;
        KService::Ptr service() const;
    private:
        KService::Ptr _service;
    };
    
class TDE_EXPORT Dcop_action
    : public Action
    {
    typedef Action base;
    public:
        Dcop_action( Action_data* data_P, const TQString& app_P, const TQString& obj_P,
            const TQString& call_P, const TQString& args_P );
        Dcop_action( TDEConfig& cfg_P, Action_data* data_P );
        virtual void cfg_write( TDEConfig& cfg_P ) const;
        virtual void execute();
        const TQString& remote_application() const;
        const TQString& remote_object() const;
        const TQString& called_function() const;
        const TQString& arguments() const;
        virtual TQString description() const;
        virtual Action* copy( Action_data* data_P ) const;
    private:
        TQString app;
        TQString obj;
        TQString call;
        TQString args;
    };
        
class TDE_EXPORT Keyboard_input_action
    : public Action
    {
    typedef Action base;
    public:
        Keyboard_input_action( Action_data* data_P, const TQString& input_P, 
            const Windowdef_list* dest_window_P, bool active_window_P );
        Keyboard_input_action( TDEConfig& cfg_P, Action_data* data_P );
        virtual ~Keyboard_input_action();
        virtual void cfg_write( TDEConfig& cfg_P ) const;
        virtual void execute();
        const TQString& input() const;
        // send to specific window: dest_window != NULL
        // send to active window: dest_window == NULL && activeWindow() == true
        // send to action window: dest_window == NULL && activeWindow() == false
        const Windowdef_list* dest_window() const;
        bool activeWindow() const;
        virtual TQString description() const;
        virtual Action* copy( Action_data* data_P ) const;
    private:
        TQString _input;
        const Windowdef_list* _dest_window;
        bool _active_window;
    };

class TDE_EXPORT Activate_window_action
    : public Action
    {
    typedef Action base;
    public:
        Activate_window_action( Action_data* data_P, const Windowdef_list* window_P );
        Activate_window_action( TDEConfig& cfg_P, Action_data* data_P );
        virtual ~Activate_window_action();
        virtual void cfg_write( TDEConfig& cfg_P ) const;
        virtual void execute();
        const Windowdef_list* window() const;
        virtual TQString description() const;
        virtual Action* copy( Action_data* data_P ) const;
    private:
        const Windowdef_list* _window;
    };
        
class TDE_EXPORT Waiting_action
    : public Action
    {
    typedef Action base;
    public:
        Waiting_action( Action_data* data_P, const int waiting_time );
        Waiting_action( TDEConfig& cfg_P, Action_data* data_P );
        virtual void cfg_write( TDEConfig& cfg_P ) const;
        virtual void execute();
        virtual TQString description() const;
        virtual Action* copy( Action_data* data_P ) const;

        int _waiting_time;
    };

//***************************************************************************
// Inline
//***************************************************************************

// Action
    
inline
Action::Action( Action_data* data_P )
    : data( data_P )
    {
    }
    
inline
Action::Action( TDEConfig&, Action_data* data_P )
    : data( data_P )
    {
    }
    
inline
Action::~Action()
    {
    }

// Action_list
        
inline
Action_list::Action_list( const TQString& comment_P )
    : TQPtrList< Action >(), _comment( comment_P )
    {
    setAutoDelete( true );
    }

inline
const TQString& Action_list::comment() const
    {
    return _comment;
    }

// Command_url_action
    
inline
Command_url_action::Command_url_action( Action_data* data_P, const TQString& command_url_P )
    : Action( data_P ), _command_url( command_url_P )
    {
    }

inline
const TQString& Command_url_action::command_url() const
    {
    return _command_url;
    }
    
// Menuentry_action

inline
Menuentry_action::Menuentry_action( Action_data* data_P, const TQString& menuentry_P )
    : Command_url_action( data_P, menuentry_P )
    {
    }
    
inline
Menuentry_action::Menuentry_action( TDEConfig& cfg_P, Action_data* data_P )
    : Command_url_action( cfg_P, data_P )
    {
    }

// DCOP_action

inline
Dcop_action::Dcop_action( Action_data* data_P, const TQString& app_P, const TQString& obj_P,
    const TQString& call_P, const TQString& args_P )
    : Action( data_P ), app( app_P ), obj( obj_P ), call( call_P ), args( args_P )
    {
    }

inline
const TQString& Dcop_action::remote_application() const
    {
    return app;
    }
    
inline
const TQString& Dcop_action::remote_object() const
    {
    return obj;
    }
    
inline
const TQString& Dcop_action::called_function() const
    {
    return call;
    }
    
inline
const TQString& Dcop_action::arguments() const
    {
    return args;
    }

// Keyboard_input_action

inline
Keyboard_input_action::Keyboard_input_action( Action_data* data_P, const TQString& input_P,
    const Windowdef_list* dest_window_P, bool active_window_P )
    : Action( data_P ), _input( input_P ), _dest_window( dest_window_P ), _active_window( active_window_P )
    {
    }
    
inline
const TQString& Keyboard_input_action::input() const
    {
    return _input;
    }
    
inline
const Windowdef_list* Keyboard_input_action::dest_window() const
    {
    return _dest_window;
    }

inline
bool Keyboard_input_action::activeWindow() const
    {
    return _active_window;
    }

// Activate_window_action

inline
Activate_window_action::Activate_window_action( Action_data* data_P,
    const Windowdef_list* window_P )
    : Action( data_P ), _window( window_P )
    {
    }
    
inline
const Windowdef_list* Activate_window_action::window() const
    {
    return _window;
    }

// Waiting_action

inline
Waiting_action::Waiting_action( Action_data* data_P, const int waiting_time)
    : Action( data_P ), _waiting_time(waiting_time)
    {
    }

} // namespace KHotKeys

#endif