action.h (1734B)
1 // Copyright (c) 2003 - 2009 Anselm R Garbe <anselm@garbe.us> 2 // See LICENSE for license details. 3 4 #ifndef __ACTION_H 5 #define __ACTION_H 6 7 extern "C" { 8 #include <X11/Xlib.h> 9 } 10 11 #include <list> 12 #include <string> 13 #include "wmi.h" 14 15 class Action; 16 class Actions; 17 class Prompt; 18 class Shortcut; 19 class Validators; 20 21 // Method pointer type for actions 22 typedef void (Actions::*ToPerform)(Action *, const char *); 23 typedef bool (Validators::*IsValid)(); 24 25 typedef list<Prompt *> LPrompt; 26 27 /** Interface for all actions which will be performed by WMI. */ 28 class Action 29 { 30 31 public: 32 33 enum Type {INTERN, EXTERN, SEQUENCE, UNKNOWN}; 34 35 Action(string id, ToPerform toPerform, 36 IsValid isValid, Type type = INTERN, char *argument = 0); 37 38 ~Action(); 39 40 string id() const; 41 42 unsigned int promptsCount() const; 43 44 /** Performs the action. */ 45 void perform(); 46 47 /** Returns <code>true</code> if the actions is possible. */ 48 bool isValid(); 49 50 /** Returns the is possible method pointer. */ 51 IsValid getIsValid() const; 52 53 void setShortcut(Shortcut *shortcut); 54 55 Shortcut *shortcut() const; 56 57 void setArgument(char *argument); 58 59 char *argument() const; 60 61 Type type() const; 62 63 void setType(Type type); 64 65 /** Returns prompt for argument at position 'index'. */ 66 Prompt *prompt(unsigned int index); 67 68 LPrompt *prompts(); 69 70 ToPerform getToPerform() const; 71 72 void setListenOn(Shortcut *listenOn); 73 74 Shortcut *listenOn() const; 75 76 private: 77 78 string id_; 79 ToPerform toPerform_; 80 IsValid isValid_; 81 82 // for keyboard bindings 83 Shortcut *shortcut_; 84 Shortcut *listenOn_; 85 86 // for special stuff 87 char *argument_; 88 Type type_; 89 LPrompt prompts_; 90 91 }; 92 93 #endif // __ACTION_H