not quite so much needs to be delayed to the init() function
[personal-kdebase.git] / workspace / khotkeys / libkhotkeysprivate / actions / actions.h
blobd9af49343432b7cd16ea2789cc5ff0d0a5ddb48e
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 #ifndef _ACTIONS_H_
12 #define _ACTIONS_H_
15 #include <QtCore/QList>
16 #include <QtCore/QTimer>
18 #include <kservice.h>
20 class KConfig;
22 #include "khotkeysglobal.h"
24 namespace KHotKeys
27 class ActionData;
28 class Windowdef_list;
30 // this one is a base for all "real" resulting actions, e.g. running a command,
31 // ActionData instances usually contain at least one Action
32 class KDE_EXPORT Action
34 Q_DISABLE_COPY( Action )
36 public:
38 /**
39 * A enum for all possible action types.
41 * @see type()
43 enum ActionType
45 ActivateWindowActionType = 0x01, //!< @see ActivateWindowAction
46 CommandUrlActionType = 0x02, //!< @see CommandUrlAction
47 DBusActionType = 0x04, //!< @see DBusAction
48 KeyboardInputActionType = 0x08, //!< @see KeyboardInputAction
49 MenuEntryActionType = 0x10, //!< @see MenuEntryAction
50 ActionListType = 0x11, //!< @see ActionList
51 AllTypes = 0xEF //!< All types. For convenience
54 Q_DECLARE_FLAGS(ActionTypes, ActionType)
56 /**
57 * Create a action
59 Action( ActionData* data_P );
60 Action( KConfigGroup& cfg_P, ActionData* data_P );
62 virtual ~Action();
64 /**
65 * Execute the action.
67 virtual void execute() = 0;
69 /**
70 * Have a look what's inside.
72 * @return the type of the action.
74 virtual ActionType type() = 0;
76 /**
77 * Returns a short descriptions of the action.
79 * The description is generated and can't be set.
81 * @return a description for this action
83 virtual const QString description() const = 0;
85 /**
86 * Write the actions configuration to @p cfg_P.
88 virtual void cfg_write( KConfigGroup& cfg_P ) const;
90 /**
91 * Read the configuration from @p cfg_P and create a new action.
93 * It's is the responsibility of the caller to make sure that @p cfg_P
94 * really holds the configuration for a action. But the code still
95 * tries to be as smart as possible when interpreting that stuff.
97 * The new actions will have @p parent_P as the parent.
99 * @param cfg_P the configuration object to read from
100 * @param data_P parent for the new object
102 * @returns the new action object.
104 static Action* create_cfg_read( KConfigGroup& cfg_P, ActionData* data_P );
107 * Return a copy of the action.
109 * This is a real deep copy.
111 virtual Action* copy( ActionData* data_P ) const = 0;
114 * The action is about to be erased permanently
116 virtual void aboutToBeErased();
118 protected:
121 * The action data corresponding to this action.
123 ActionData* const data;
126 Q_DECLARE_OPERATORS_FOR_FLAGS(Action::ActionTypes)
129 class KDE_EXPORT ActionList
130 : public QList< Action* >
132 Q_DISABLE_COPY( ActionList )
133 public:
134 ActionList( const QString& comment_P ); // CHECKME nebo i data ?
135 ActionList( KConfigGroup& cfg_P, ActionData* data_P );
136 ~ActionList();
137 void cfg_write( KConfigGroup& cfg_P ) const;
138 //! Some convenience typedef
139 typedef QList<Action*>::Iterator Iterator;
140 typedef QList<Action*>::ConstIterator ConstIterator;
141 const QString& comment() const;
144 * @reimp
146 void aboutToBeErased();
148 private:
149 QString _comment;
152 class KDE_EXPORT CommandUrlAction
153 : public Action
155 typedef Action base;
156 public:
157 CommandUrlAction( ActionData* data_P, const QString& command_url_P = QString() );
158 CommandUrlAction( KConfigGroup& cfg_P, ActionData* data_P );
159 virtual void cfg_write( KConfigGroup& cfg_P ) const;
160 virtual void execute();
161 virtual const QString description() const;
163 //! The command url to trigger
164 void set_command_url( const QString &command_url );
165 QString command_url() const;
167 virtual ActionType type() { return CommandUrlActionType; }
168 virtual Action* copy( ActionData* data_P ) const;
169 protected:
170 QTimer timeout;
171 private:
172 QString _command_url;
175 class KDE_EXPORT MenuEntryAction
176 : public CommandUrlAction
178 typedef CommandUrlAction base;
179 public:
180 MenuEntryAction( ActionData* data_P, const QString& menuentry_P = QString() );
181 MenuEntryAction( KConfigGroup& cfg_P, ActionData* data_P );
182 virtual void cfg_write( KConfigGroup& cfg_P ) const;
183 virtual void execute();
185 // The service we trigger
186 KService::Ptr service() const;
187 void set_service( KService::Ptr );
189 virtual const QString description() const;
190 virtual Action* copy( ActionData* data_P ) const;
191 virtual ActionType type() { return Action::MenuEntryActionType; }
192 private:
193 KService::Ptr _service;
196 class KDE_EXPORT DBusAction
197 : public Action
199 typedef Action base;
200 public:
201 DBusAction(
202 ActionData* data_P,
203 const QString& app_P = QString(),
204 const QString& obj_P = QString(),
205 const QString& call_P= QString(),
206 const QString& args_P= QString() );
208 DBusAction( KConfigGroup& cfg_P, ActionData* data_P );
209 virtual void cfg_write( KConfigGroup& cfg_P ) const;
210 virtual void execute();
211 const QString remote_application() const;
212 const QString remote_object() const;
213 const QString called_function() const;
214 const QString arguments() const;
216 void set_remote_application( const QString &application );
217 void set_remote_object( const QString &object );
218 void set_called_function( const QString &function );
219 void set_arguments( const QString &args );
221 virtual const QString description() const;
222 virtual Action* copy( ActionData* data_P ) const;
223 virtual ActionType type() { return DBusActionType; }
224 private:
225 QString _application; // CHECKME QCString ?
226 QString _object;
227 QString _function;
228 QString _arguments;
231 class KDE_EXPORT KeyboardInputAction
232 : public Action
234 typedef Action base;
235 public:
236 KeyboardInputAction( ActionData* data_P, const QString& input_P,
237 const Windowdef_list* dest_window_P, bool active_window_P );
238 KeyboardInputAction( KConfigGroup& cfg_P, ActionData* data_P );
239 virtual ~KeyboardInputAction();
240 virtual void cfg_write( KConfigGroup& cfg_P ) const;
241 virtual void execute();
242 const QString& input() const;
243 // send to specific window: dest_window != NULL
244 // send to active window: dest_window == NULL && activeWindow() == true
245 // send to action window: dest_window == NULL && activeWindow() == false
246 const Windowdef_list* dest_window() const;
247 bool activeWindow() const;
248 virtual const QString description() const;
249 virtual Action* copy( ActionData* data_P ) const;
250 virtual ActionType type() { return KeyboardInputActionType; }
251 private:
252 QString _input;
253 const Windowdef_list* _dest_window;
254 bool _active_window;
257 class KDE_EXPORT ActivateWindowAction
258 : public Action
260 typedef Action base;
261 public:
262 ActivateWindowAction( ActionData* data_P, const Windowdef_list* window_P );
263 ActivateWindowAction( KConfigGroup& cfg_P, ActionData* data_P );
264 virtual ~ActivateWindowAction();
265 virtual void cfg_write( KConfigGroup& cfg_P ) const;
266 virtual void execute();
267 const Windowdef_list* window() const;
268 virtual const QString description() const;
269 virtual Action* copy( ActionData* data_P ) const;
270 virtual ActionType type() { return ActivateWindowActionType; }
271 private:
272 const Windowdef_list* _window;
275 } // namespace KHotKeys
277 #endif