1 /*
2 
3                           Firewall Builder
4 
5                  Copyright (C) 2009 NetCitadel, LLC
6 
7   Author:  Vadim Kurland     vadim@fwbuilder.org
8 
9   $Id$
10 
11   This program is free software which we release under the GNU General Public
12   License. You may redistribute and/or modify this program under the terms
13   of that license as published by the Free Software Foundation; either
14   version 2 of the License, or (at your option) any later version.
15 
16   This program is distributed in the hope that it will be useful,
17   but WITHOUT ANY WARRANTY; without even the implied warranty of
18   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19   GNU General Public License for more details.
20 
21   To get a copy of the GNU General Public License, write to the Free Software
22   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23 
24 */
25 
26 #ifndef FWBUILDER_EVENTS_HH
27 #define FWBUILDER_EVENTS_HH
28 
29 #include "global.h"
30 #include "ObjectEditor.h"
31 #include "ColDesc.h"
32 
33 #include <QEvent>
34 #include <QString>
35 
36 /* Custom event types.  QEvent::registerEventType is only available
37    starting QT 4.4 but we have to support QT 4.3 for Ubuntu Hardy so
38    need to allocate types manually for now. Event types are defined as
39    increments above QEvent::User
40 */
41 
42 enum EVENT_CODES {
43     DATA_MODIFIED_EVENT  ,
44     UPDATE_OBJECT_IN_TREE_EVENT  ,
45     UPDATE_OBJECT_AND_SUBTREE_IN_TREE_EVENT  ,
46     UPDATE_OBJECT_AND_SUBTREE_IMMEDIATELY_EVENT  ,
47     UPDATE_OBJECT_EVERYWHERE_EVENT  ,
48     UPDATE_LAST_COMPILED_TIMESTAMP_EVENT ,
49     UPDATE_LAST_INSTALLED_TIMESTAMP_EVENT ,
50     SHOW_OBJECT_IN_TREE_EVENT ,
51     SHOW_OBJECT_IN_RULESET_EVENT ,
52     SELECT_RULE_ELEMENT_EVENT,
53     INSERT_OBJECT_IN_TREE_EVENT,
54     REMOVE_OBJECT_FROM_TREE_EVENT,
55     ADD_TREE_PAGE_EVENT,
56     REMOVE_TREE_PAGE_EVENT,
57     RELOAD_OBJECT_TREE_EVENT ,
58     RELOAD_OBJECT_TREE_IMMEDIATELY_EVENT ,
59     OPEN_RULESET_EVENT ,
60     OPEN_RULESET_IMMEDIATELY_EVENT ,
61     RELOAD_RULESET_EVENT ,
62     RELOAD_RULESET_IMMEDIATELY_EVENT ,
63     MAKE_CURRENT_RULE_VISIBLE_IN_RULESET_EVENT,
64     OPEN_OBJECT_IN_EDITOR_EVENT ,
65     OPEN_OPT_OBJECT_IN_EDITOR_EVENT ,
66     CLOSE_OBJECT_EVENT ,
67     OBJECT_NAME_CHANGED_EVENT,
68     OPEN_LIBRARY_FOR_OBJECT_EVENT,
69     UPDATE_SUBWINDOW_TITLES_EVENT,
70     UPDATE_GUI_STATE_EVENT,
71     EXPAND_OBJECT_IN_TREE,
72     CLOSE_EDITOR_PANEL_EVENT ,
73     CLEAR_EDITOR_PANEL_EVENT ,
74     ADD_USER_FOLDER_EVENT,
75     REMOVE_USER_FOLDER_EVENT,
76     MOVE_TOFROM_USER_FOLDER_EVENT,
77 };
78 
79 
80 class fwbUpdateEvent : public QEvent {
81     QString data_file_name;
82     int object_id;
83     QString event_name;
84 public:
fwbUpdateEvent(const QString & file_name,int obj_id,QEvent::Type event_type,const QString & ev_name)85     fwbUpdateEvent(const QString &file_name, int obj_id, QEvent::Type event_type,
86                    const QString &ev_name) : QEvent(event_type), event_name(ev_name)
87     {
88         data_file_name = file_name;
89         object_id = obj_id;
90     }
getEventName()91     QString getEventName() { return event_name; }
getFileName()92     QString getFileName() { return data_file_name; }
getObjectId()93     int getObjectId() { return object_id; }
94 };
95 
96 
97 class dataModifiedEvent : public fwbUpdateEvent {
98 public:
dataModifiedEvent(const QString & file_name,int obj_id)99     dataModifiedEvent(const QString &file_name, int obj_id) :
100       fwbUpdateEvent(file_name, obj_id,
101                      QEvent::Type(QEvent::User + DATA_MODIFIED_EVENT),
102                      "dataModifiedEvent")
103       {}
104 };
105 
106 
107 class updateObjectInTreeEvent : public fwbUpdateEvent {
108 public:
updateObjectInTreeEvent(const QString & file_name,int obj_id)109     updateObjectInTreeEvent(const QString &file_name, int obj_id) :
110       fwbUpdateEvent(file_name, obj_id,
111                      QEvent::Type(QEvent::User + UPDATE_OBJECT_IN_TREE_EVENT),
112                      "updateObjectInTreeEvent")
113       {}
114 };
115 
116 
117 class updateObjectAndSubtreeInTreeEvent : public fwbUpdateEvent {
118 public:
updateObjectAndSubtreeInTreeEvent(const QString & file_name,int obj_id)119     updateObjectAndSubtreeInTreeEvent(const QString &file_name, int obj_id) :
120       fwbUpdateEvent(file_name, obj_id,
121                      QEvent::Type(QEvent::User + UPDATE_OBJECT_AND_SUBTREE_IN_TREE_EVENT),
122                      "updateObjectAndSubtreeInTreeEvent")
123       {}
124 };
125 
126 
127 class updateObjectAndSubtreeImmediatelyEvent : public fwbUpdateEvent {
128 public:
updateObjectAndSubtreeImmediatelyEvent(const QString & file_name,int obj_id)129     updateObjectAndSubtreeImmediatelyEvent(const QString &file_name, int obj_id) :
130       fwbUpdateEvent(file_name, obj_id,
131                      QEvent::Type(QEvent::User + UPDATE_OBJECT_AND_SUBTREE_IMMEDIATELY_EVENT),
132                      "updateObjectAndSubtreeImmediatelyEvent")
133       {}
134 };
135 
136 
137 class updateObjectEverywhereEvent : public fwbUpdateEvent {
138 public:
updateObjectEverywhereEvent(const QString & file_name,int obj_id)139     updateObjectEverywhereEvent(const QString &file_name, int obj_id) :
140       fwbUpdateEvent(file_name, obj_id,
141                      QEvent::Type(QEvent::User + UPDATE_OBJECT_EVERYWHERE_EVENT),
142                      "updateObjectEverywhereEvent")
143       {}
144 };
145 
146 
147 class updateLastCompiledTimestampEvent : public fwbUpdateEvent {
148 public:
updateLastCompiledTimestampEvent(const QString & file_name,int obj_id)149     updateLastCompiledTimestampEvent(const QString &file_name, int obj_id) :
150       fwbUpdateEvent(file_name, obj_id,
151                      QEvent::Type(QEvent::User + UPDATE_LAST_COMPILED_TIMESTAMP_EVENT),
152                      "updateLastCompiledTimestampEvent")
153       {}
154 };
155 
156 
157 class updateLastInstalledTimestampEvent : public fwbUpdateEvent {
158 public:
updateLastInstalledTimestampEvent(const QString & file_name,int obj_id)159     updateLastInstalledTimestampEvent(const QString &file_name, int obj_id) :
160       fwbUpdateEvent(file_name, obj_id,
161                      QEvent::Type(QEvent::User + UPDATE_LAST_INSTALLED_TIMESTAMP_EVENT),
162                      "updateLastInstalledTimestampEvent")
163       {}
164 };
165 
166 
167 class showObjectInTreeEvent : public fwbUpdateEvent {
168 public:
showObjectInTreeEvent(const QString & file_name,int obj_id)169     showObjectInTreeEvent(const QString &file_name, int obj_id) :
170     fwbUpdateEvent(file_name, obj_id,
171                    QEvent::Type(QEvent::User + SHOW_OBJECT_IN_TREE_EVENT),
172                    "showObjectInTreeEvent")
173     {}
174 };
175 
176 
177 class showObjectInRulesetEvent : public fwbUpdateEvent {
178 public:
showObjectInRulesetEvent(const QString & file_name,int obj_id)179     showObjectInRulesetEvent(const QString &file_name, int obj_id) :
180       fwbUpdateEvent(file_name, obj_id,
181                      QEvent::Type(QEvent::User + SHOW_OBJECT_IN_RULESET_EVENT),
182                      "showObjectInRulesetEvent")
183       {}
184 };
185 
186 
187 class selectRuleElementEvent : public fwbUpdateEvent {
188 public:
189     ColDesc::ColumnType column_type;
selectRuleElementEvent(const QString & file_name,int obj_id,ColDesc::ColumnType ct)190     selectRuleElementEvent(const QString &file_name, int obj_id, ColDesc::ColumnType ct) :
191     fwbUpdateEvent(file_name, obj_id,
192                      QEvent::Type(QEvent::User + SELECT_RULE_ELEMENT_EVENT),
193                      "selectRuleElementEvent")
194     { column_type = ct; }
195 };
196 
197 
198 class insertObjectInTreeEvent : public fwbUpdateEvent {
199 public:
200     int parent_id;
insertObjectInTreeEvent(const QString & file_name,int p_id,int obj_id)201     insertObjectInTreeEvent(const QString &file_name, int p_id, int obj_id) :
202     fwbUpdateEvent(file_name, obj_id,
203                    QEvent::Type(QEvent::User + INSERT_OBJECT_IN_TREE_EVENT),
204                    "insertObjectInTreeEvent")
205     { parent_id = p_id; }
206 };
207 
208 
209 class removeObjectFromTreeEvent : public fwbUpdateEvent {
210 public:
removeObjectFromTreeEvent(const QString & file_name,int obj_id)211     removeObjectFromTreeEvent(const QString &file_name, int obj_id) :
212     fwbUpdateEvent(file_name, obj_id,
213                    QEvent::Type(QEvent::User + REMOVE_OBJECT_FROM_TREE_EVENT),
214                    "removeObjectFromTreeEvent")
215     {}
216 };
217 
218 
219 class addTreePageEvent : public fwbUpdateEvent {
220 public:
addTreePageEvent(const QString & file_name,int obj_id)221     addTreePageEvent(const QString &file_name, int obj_id) :
222     fwbUpdateEvent(file_name, obj_id,
223                    QEvent::Type(QEvent::User + ADD_TREE_PAGE_EVENT),
224                    "addTreePageEvent")
225     {}
226 };
227 
228 
229 class removeTreePageEvent : public fwbUpdateEvent {
230 public:
removeTreePageEvent(const QString & file_name,int obj_id)231     removeTreePageEvent(const QString &file_name, int obj_id) :
232     fwbUpdateEvent(file_name, obj_id,
233                    QEvent::Type(QEvent::User + REMOVE_TREE_PAGE_EVENT),
234                    "removeTreePageEvent")
235     {}
236 };
237 
238 
239 class reloadObjectTreeEvent : public fwbUpdateEvent {
240 public:
reloadObjectTreeEvent(const QString & file_name)241     reloadObjectTreeEvent(const QString &file_name) :
242     fwbUpdateEvent(file_name, -1,
243                    QEvent::Type(QEvent::User + RELOAD_OBJECT_TREE_EVENT),
244                    "reloadObjectTreeEvent")
245     {}
246 };
247 
248 
249 class reloadObjectTreeImmediatelyEvent : public fwbUpdateEvent {
250 public:
reloadObjectTreeImmediatelyEvent(const QString & file_name)251     reloadObjectTreeImmediatelyEvent(const QString &file_name) :
252     fwbUpdateEvent(file_name, -1,
253                    QEvent::Type(QEvent::User + RELOAD_OBJECT_TREE_IMMEDIATELY_EVENT),
254                    "reloadObjectTreeImmediatelyEvent")
255     {}
256 };
257 
258 
259 class reloadRulesetEvent : public fwbUpdateEvent {
260 public:
reloadRulesetEvent(const QString & file_name)261     reloadRulesetEvent(const QString &file_name) :
262     fwbUpdateEvent(file_name, -1,
263                    QEvent::Type(QEvent::User + RELOAD_RULESET_EVENT),
264                    "reloadRulesetEvent")
265     {}
266 };
267 
268 
269 class reloadRulesetImmediatelyEvent : public fwbUpdateEvent {
270 public:
reloadRulesetImmediatelyEvent(const QString & file_name)271     reloadRulesetImmediatelyEvent(const QString &file_name) :
272     fwbUpdateEvent(file_name, -1,
273                    QEvent::Type(QEvent::User + RELOAD_RULESET_IMMEDIATELY_EVENT),
274                    "reloadRulesetImmediatelyEvent")
275     {}
276 };
277 
278 class makeCurrentRuleVisibleInRulesetEvent : public fwbUpdateEvent {
279 public:
makeCurrentRuleVisibleInRulesetEvent(const QString & file_name)280     makeCurrentRuleVisibleInRulesetEvent(const QString &file_name) :
281     fwbUpdateEvent(file_name, -1,
282                    QEvent::Type(QEvent::User + MAKE_CURRENT_RULE_VISIBLE_IN_RULESET_EVENT),
283                    "makeCurrentRuleVisibleInRulesetEvent")
284     {}
285 };
286 
287 
288 
289 class openRulesetEvent : public fwbUpdateEvent {
290 public:
openRulesetEvent(const QString & file_name,int obj_id)291     openRulesetEvent(const QString &file_name, int obj_id) :
292     fwbUpdateEvent(file_name, obj_id,
293                    QEvent::Type(QEvent::User + OPEN_RULESET_EVENT),
294                    "openRulesetEvent")
295     {}
296 };
297 
298 
299 class openRulesetImmediatelyEvent : public fwbUpdateEvent {
300 public:
openRulesetImmediatelyEvent(const QString & file_name,int obj_id)301     openRulesetImmediatelyEvent(const QString &file_name, int obj_id) :
302     fwbUpdateEvent(file_name, obj_id,
303                    QEvent::Type(QEvent::User + OPEN_RULESET_IMMEDIATELY_EVENT),
304                    "openRulesetImmediatelyEvent")
305     {}
306 };
307 
308 
309 class openObjectInEditorEvent : public fwbUpdateEvent {
310 public:
openObjectInEditorEvent(const QString & file_name,int obj_id)311     openObjectInEditorEvent(const QString &file_name, int obj_id) :
312     fwbUpdateEvent(file_name, obj_id,
313                    QEvent::Type(QEvent::User + OPEN_OBJECT_IN_EDITOR_EVENT),
314                    "openObjectInEditorEvent")
315     {}
316 };
317 
318 
319 class openOptObjectInEditorEvent : public fwbUpdateEvent {
320 public:
321     ObjectEditor::OptType opt_code;
openOptObjectInEditorEvent(const QString & file_name,int obj_id,ObjectEditor::OptType opt)322     openOptObjectInEditorEvent(const QString &file_name, int obj_id, ObjectEditor::OptType opt) :
323     fwbUpdateEvent(file_name, obj_id,
324                    QEvent::Type(QEvent::User + OPEN_OPT_OBJECT_IN_EDITOR_EVENT),
325                    "openOptObjectInEditorEvent")
326     { opt_code = opt; }
327 };
328 
329 
330 class closeObjectEvent : public fwbUpdateEvent {
331 public:
closeObjectEvent(const QString & file_name,int obj_id)332     closeObjectEvent(const QString &file_name, int obj_id) :
333     fwbUpdateEvent(file_name, obj_id,
334                    QEvent::Type(QEvent::User + CLOSE_OBJECT_EVENT),
335                    "closeObjectEvent")
336     {}
337 };
338 
339 
340 class objectNameChangedEvent : public fwbUpdateEvent {
341 public:
342     QString old_name;
343     QString new_name;
344     bool rename_children;
objectNameChangedEvent(const QString & file_name,int obj_id,const QString & _old_name,const QString & _new_name,bool _rename_children)345     objectNameChangedEvent(const QString &file_name, int obj_id,
346                            const QString &_old_name, const QString &_new_name,
347                            bool _rename_children) :
348     fwbUpdateEvent(file_name, obj_id,
349                    QEvent::Type(QEvent::User + OBJECT_NAME_CHANGED_EVENT),
350                    "objectNameChangedEvent")
351     { old_name = _old_name; new_name = _new_name; rename_children = _rename_children; }
352 };
353 
354 
355 class openLibraryForObjectEvent : public fwbUpdateEvent {
356 public:
357     QString old_name;
358     QString new_name;
openLibraryForObjectEvent(const QString & file_name,int obj_id)359     openLibraryForObjectEvent(const QString &file_name, int obj_id) :
360     fwbUpdateEvent(file_name, obj_id,
361                    QEvent::Type(QEvent::User + OPEN_LIBRARY_FOR_OBJECT_EVENT),
362                    "openLibraryForObjectEvent")
363     {}
364 };
365 
366 /*
367  * This event is processed by FWWindow class and updates titles of all
368  * ProjectPanel windows.
369  */
370 class updateSubWindowTitlesEvent : public fwbUpdateEvent {
371 public:
updateSubWindowTitlesEvent()372     updateSubWindowTitlesEvent() :
373     fwbUpdateEvent("", -1,
374                    QEvent::Type(QEvent::User + UPDATE_SUBWINDOW_TITLES_EVENT),
375                    "updateSubWindowTitlesEvent")
376     {}
377 };
378 
379 /*
380  * This event is processed by FWWindow class and updates all menus and
381  * toolbar buttins
382  */
383 class updateGUIStateEvent : public fwbUpdateEvent {
384 public:
updateGUIStateEvent()385     updateGUIStateEvent() :
386     fwbUpdateEvent("", -1,
387                    QEvent::Type(QEvent::User + UPDATE_GUI_STATE_EVENT),
388                    "updateGUIStateEvent")
389     {}
390 };
391 
392 class expandObjectInTreeEvent : public fwbUpdateEvent {
393 public:
394     int parent_id;
expandObjectInTreeEvent(const QString & file_name,int obj_id)395     expandObjectInTreeEvent(const QString &file_name, int obj_id) :
396     fwbUpdateEvent(file_name, obj_id,
397                    QEvent::Type(QEvent::User + EXPAND_OBJECT_IN_TREE),
398                    "expandObjectInTreeEvent")
399     {}
400 };
401 
402 class closeEditorPanelEvent : public fwbUpdateEvent {
403 public:
closeEditorPanelEvent()404     closeEditorPanelEvent() :
405     fwbUpdateEvent("", -1,
406                    QEvent::Type(QEvent::User + CLOSE_EDITOR_PANEL_EVENT),
407                    "closeEditorPanelEvent")
408     {}
409 };
410 
411 class clearEditorPanelEvent : public fwbUpdateEvent {
412 public:
clearEditorPanelEvent()413     clearEditorPanelEvent() :
414     fwbUpdateEvent("", -1,
415                    QEvent::Type(QEvent::User + CLEAR_EDITOR_PANEL_EVENT),
416                    "clearEditorPanelEvent")
417     {}
418 };
419 
420 
421 class addUserFolderEvent : public fwbUpdateEvent {
422 public:
423     QString m_userFolder;
addUserFolderEvent(const QString & fileName,int objId,const QString & userFolder)424     addUserFolderEvent(const QString &fileName, int objId,
425                        const QString &userFolder) :
426         fwbUpdateEvent(fileName, objId,
427                        QEvent::Type(QEvent::User + ADD_USER_FOLDER_EVENT),
428                        "addUserFolderEvent")
429     { m_userFolder = userFolder; }
430 };
431 
432 class removeUserFolderEvent : public fwbUpdateEvent {
433 public:
434     QString m_userFolder;
removeUserFolderEvent(const QString & fileName,int objId,const QString & userFolder)435     removeUserFolderEvent(const QString &fileName, int objId,
436                           const QString &userFolder) :
437         fwbUpdateEvent(fileName, objId,
438                        QEvent::Type(QEvent::User + REMOVE_USER_FOLDER_EVENT),
439                        "removeUserFolderEvent")
440     { m_userFolder = userFolder; }
441 };
442 
443 class moveToFromUserFolderEvent : public fwbUpdateEvent {
444 public:
445     int m_objIdToMove;
446     QString m_oldFolder;
447     QString m_newFolder;
moveToFromUserFolderEvent(const QString & fileName,int objId,int objIdToMove,const QString & oldFolder,const QString & newFolder)448     moveToFromUserFolderEvent(const QString &fileName, int objId,
449                               int objIdToMove, const QString &oldFolder,
450                               const QString &newFolder) :
451         fwbUpdateEvent(fileName, objId,
452                        QEvent::Type(QEvent::User+MOVE_TOFROM_USER_FOLDER_EVENT),
453                        "removeUserFolderEvent"),
454         m_objIdToMove(objIdToMove),
455         m_oldFolder(oldFolder),
456         m_newFolder(newFolder)
457     {}
458 };
459 
460 #endif
461