Keyset Memory Management Bugfix
[pierogi] / macros / pirmacrocommanditem.h
1 #ifndef PIRMACROCOMMANDITEM_H
2 #define PIRMACROCOMMANDITEM_H
3
4 #include <QListWidgetItem>
5 #include <QObject>
6 #include <QString>
7
8 #include "pirkeynames.h"
9
10 class QTimer;
11 class QSettings;
12 class MainWindow;
13
14 // For convenience:
15 enum CommandItemType{
16   NoCommand_Type,
17   KeysetCommand_Type,
18   KeyCommand_Type,
19   PauseCommand_Type
20 };
21
22 class PIRMacroCommandItem: public QObject
23 {
24   Q_OBJECT
25
26 public:
27   PIRMacroCommandItem();
28
29   PIRMacroCommandItem(
30     QString displayName);
31
32   virtual void executeCommand() = 0;
33
34   virtual void storeSettings(
35     QSettings &settings,
36     int index) = 0;
37
38   virtual QString getTypeString() const = 0;
39
40   QString getName() const;
41
42   void setName(
43     QString name);
44
45 signals:
46   void commandCompleted();
47
48 private:
49   QString name;
50 };
51
52
53 class PIRKeyCommandItem: public PIRMacroCommandItem
54 {
55   Q_OBJECT
56
57 public:
58   PIRKeyCommandItem(
59     PIRKeyName keyToExecute,
60     MainWindow *mw);
61
62   ~PIRKeyCommandItem();
63
64   virtual void executeCommand();
65
66   virtual void storeSettings(
67     QSettings &settings,
68     int index);
69
70   virtual QString getTypeString() const;
71
72 private slots:
73   void startRunningCommand();
74   void stopRunningCommand();
75
76 private:
77   PIRKeyName key;
78   QTimer *advanceTimer;
79   MainWindow *mainWindow;
80 };
81
82
83 class PIRKeysetCommandItem: public PIRMacroCommandItem
84 {
85   Q_OBJECT
86
87 public:
88   PIRKeysetCommandItem(
89     QString displayName,
90     unsigned int keysetToChoose,
91     MainWindow *mw);
92
93   PIRKeysetCommandItem(
94     unsigned int keysetToChoose,
95     MainWindow *mw);
96
97   virtual void executeCommand();
98
99   virtual void storeSettings(
100     QSettings &settings,
101     int index);
102
103   virtual QString getTypeString() const;
104
105 private:
106   unsigned int id;
107   MainWindow *mainWindow;
108 };
109
110
111 class PIRPauseCommandItem: public PIRMacroCommandItem
112 {
113   Q_OBJECT
114
115 public:
116   PIRPauseCommandItem(
117     unsigned int timeToWait);
118
119   ~PIRPauseCommandItem();
120
121   virtual void executeCommand();
122
123   virtual void storeSettings(
124     QSettings &settings,
125     int index);
126
127   virtual QString getTypeString() const;
128
129 private slots:
130   void finishedWaiting();
131
132 private:
133   unsigned int timeInSeconds;
134   QTimer *advanceTimer;
135 };
136
137
138 #endif // PIRMACROCOMMANDITEM_H