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 ****************************************************************************/
15 #include <QtCore/QList>
16 #include <QtCore/QTimer>
22 #include "khotkeysglobal.h"
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
)
39 * A enum for all possible action types.
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
)
59 Action( ActionData
* data_P
);
60 Action( KConfigGroup
& cfg_P
, ActionData
* data_P
);
67 virtual void execute() = 0;
70 * Have a look what's inside.
72 * @return the type of the action.
74 virtual ActionType
type() = 0;
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;
86 * Write the actions configuration to @p cfg_P.
88 virtual void cfg_write( KConfigGroup
& cfg_P
) const;
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();
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
)
134 ActionList( const QString
& comment_P
); // CHECKME nebo i data ?
135 ActionList( KConfigGroup
& cfg_P
, ActionData
* data_P
);
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;
146 void aboutToBeErased();
152 class KDE_EXPORT CommandUrlAction
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;
172 QString _command_url
;
175 class KDE_EXPORT MenuEntryAction
176 : public CommandUrlAction
178 typedef CommandUrlAction base
;
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
; }
193 KService::Ptr _service
;
196 class KDE_EXPORT DBusAction
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
; }
225 QString _application
; // CHECKME QCString ?
231 class KDE_EXPORT KeyboardInputAction
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
; }
253 const Windowdef_list
* _dest_window
;
257 class KDE_EXPORT ActivateWindowAction
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
; }
272 const Windowdef_list
* _window
;
275 } // namespace KHotKeys