minor tidy up
[AROS.git] / workbench / system / Snoopy / gui.c
blob197fa0018263a1d81f40c5c32e2dcedd18175353
1 /*
2 Copyright © 2006-2015, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #define MUIMASTER_YES_INLINE_STDARG
8 #include <aros/config.h>
9 #include <aros/debug.h>
11 #include <libraries/mui.h>
13 #include <proto/alib.h>
14 #include <proto/muimaster.h>
15 #include <proto/intuition.h>
17 #include "main.h"
18 #include "gui.h"
19 #include "setup.h"
20 #include "patches.h"
21 #include "locale.h"
23 #define VERSION "$VER: Snoopy 0.13 (04.05.2015) © 2006-2015 The AROS Dev Team"
25 static Object *app, *window, *saveBtn, *openBtn, *useBtn, *undoBtn, *resetBtn, *cancelBtn;
26 static Object *failCM, *cliCM, *pathCM, *devCM, *ignoreCM, *breakPointCM, *patternStr;
27 static Object *nameNum, *actionNum, *targetNum, *optionNum;
28 static Object *changeDirCM, *deleteCM, *executeCM, *getVarCM, *loadSegCM, *lockCM, *makeDirCM, *makeLinkCM;
29 static Object *openCM, *renameCM, *runCommandCM, *setVarCM, *systemCM, *findPortCM, *findResidentCM, *findSemaphoreCM;
30 static Object *findTaskCM, *lockScreenCM, *openDeviceCM, *openFontCM, *openLibraryCM, *openResourceCM, *readToolTypesCM;
32 static struct Hook save_hook, open_hook, use_hook, undo_hook, reset_hook, cancel_hook;
34 AROS_UFH3S(void, save_function,
35 AROS_UFHA(struct Hook *, h, A0),
36 AROS_UFHA(Object *, object, A2),
37 AROS_UFHA(APTR, msg, A1))
39 AROS_USERFUNC_INIT
41 oldsetup = setup;
42 gui_get();
43 patches_set();
44 if ( ! setup_save())
46 MUI_Request ( app, window, 0, MSG(MSG_TITLE), MSG(MSG_OK), MSG(MSG_ERROR_SAVE), PREFFILE);
49 AROS_USERFUNC_EXIT
52 AROS_UFH3S(void, open_function,
53 AROS_UFHA(struct Hook *, h, A0),
54 AROS_UFHA(Object *, object, A2),
55 AROS_UFHA(APTR, msg, A1))
57 AROS_USERFUNC_INIT
59 if ( ! setup_open() )
61 MUI_Request ( app, window, 0, MSG(MSG_TITLE), MSG(MSG_OK), MSG(MSG_ERROR_LOAD), PREFFILE);
63 gui_set();
64 patches_set();
66 AROS_USERFUNC_EXIT
69 AROS_UFH3S(void, reset_function,
70 AROS_UFHA(struct Hook *, h, A0),
71 AROS_UFHA(Object *, object, A2),
72 AROS_UFHA(APTR, msg, A1))
74 AROS_USERFUNC_INIT
76 oldsetup = setup;
77 setup_reset();
78 gui_set();
79 patches_set();
81 AROS_USERFUNC_EXIT
84 AROS_UFH3S(void, use_function,
85 AROS_UFHA(struct Hook *, h, A0),
86 AROS_UFHA(Object *, object, A2),
87 AROS_UFHA(APTR, msg, A1))
89 AROS_USERFUNC_INIT
91 oldsetup = setup;
92 gui_get();
93 patches_set();
95 AROS_USERFUNC_EXIT
98 AROS_UFH3S(void, undo_function,
99 AROS_UFHA(struct Hook *, h, A0),
100 AROS_UFHA(Object *, object, A2),
101 AROS_UFHA(APTR, msg, A1))
103 AROS_USERFUNC_INIT
105 setup = oldsetup;
106 gui_set();
107 patches_set();
109 AROS_USERFUNC_EXIT
112 AROS_UFH3S(void, cancel_function,
113 AROS_UFHA(struct Hook *, h, A0),
114 AROS_UFHA(Object *, object, A2),
115 AROS_UFHA(APTR, msg, A1))
117 AROS_USERFUNC_INIT
119 // FIXME: original SnoopDos has a separate task for the patches. When cancelling SnoopDos the GUI
120 // is removed and the patchtask stays in RAM. We can't do that because we have no separate task.
121 // The cancelling function of Snoopy is more for debugging.
122 if (MUI_Request ( app, window, 0, MSG(MSG_TITLE), MSG(MSG_RESET_PATCHES), MSG(MSG_ASK_RESET)))
124 set(saveBtn, MUIA_Disabled, TRUE);
125 set(openBtn, MUIA_Disabled, TRUE);
126 set(useBtn, MUIA_Disabled, TRUE);
127 set(undoBtn, MUIA_Disabled, TRUE);
128 set(resetBtn, MUIA_Disabled, TRUE);
129 set(cancelBtn, MUIA_Disabled, TRUE);
130 patches_reset();
131 if (MUI_Request ( app, window, 0, MSG(MSG_TITLE), MSG(MSG_REMOVE_SNOOP), MSG(MSG_ASK_REMOVE)))
133 DoMethod(app, MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit);
136 AROS_USERFUNC_EXIT
139 void gui_init(void)
141 save_hook.h_Entry = (APTR)save_function;
142 open_hook.h_Entry = (APTR)open_function;
143 use_hook.h_Entry = (APTR)use_function;
144 undo_hook.h_Entry = (APTR)undo_function;
145 reset_hook.h_Entry = (APTR)reset_function;
146 cancel_hook.h_Entry = (APTR)cancel_function;
148 app = (Object *)ApplicationObject,
149 MUIA_Application_Title, (IPTR) MSG(MSG_TITLE),
150 MUIA_Application_Version, (IPTR) VERSION,
151 MUIA_Application_Copyright, (IPTR) MSG(MSG_COPYRIGHT),
152 MUIA_Application_Author, (IPTR) MSG(MSG_AUTHOR),
153 MUIA_Application_Description, (IPTR) MSG(MSG_DESCRIPTION),
154 MUIA_Application_Base, (IPTR) MSG(MSG_PORTNAME),
155 MUIA_Application_SingleTask, TRUE,
157 SubWindow, (IPTR)(window = (Object *)WindowObject,
158 MUIA_Window_Title, (IPTR)MSG(MSG_TITLE),
159 MUIA_Window_CloseGadget, FALSE,
160 WindowContents, (IPTR)(VGroup,
161 Child, (IPTR)(HGroup,
162 Child, (IPTR)(VGroup,
163 Child, (IPTR)(ColGroup(2),
164 GroupFrameT(MSG(MSG_SETTINGS)),
165 Child, (IPTR)Label(MSG(MSG_SHOW_FAILS)),
166 Child, (IPTR)(failCM = MUI_MakeObject(MUIO_Checkmark, "")),
167 Child, (IPTR)Label(MSG(MSG_CLI_NUMBER)),
168 Child, (IPTR)(cliCM = MUI_MakeObject(MUIO_Checkmark, "")),
169 Child, (IPTR)Label(MSG(MSG_FULL_PATH)),
170 Child, (IPTR)(pathCM = MUI_MakeObject(MUIO_Checkmark, "")),
171 Child, (IPTR)Label(MSG(MSG_DEVICE)),
172 Child, (IPTR)(devCM = MUI_MakeObject(MUIO_Checkmark, "")),
173 Child, (IPTR)Label(MSG(MSG_IGNORE_WB)),
174 Child, (IPTR)(ignoreCM = MUI_MakeObject(MUIO_Checkmark, "")),
175 Child, (IPTR)Label(MSG(MSG_BREAKPOINT)),
176 Child, (IPTR)(breakPointCM = MUI_MakeObject(MUIO_Checkmark, "")),
177 Child, (IPTR)HVSpace,
178 Child, (IPTR)HVSpace,
179 End),
180 Child, (IPTR)(ColGroup(2),
181 Child, (IPTR)Label(MSG(MSG_MATCH)),
182 Child, (IPTR)(patternStr = (Object *)StringObject,
183 StringFrame,
184 MUIA_String_MaxLen, PATTERNLEN,
185 End),
186 End),
187 Child, (IPTR)(ColGroup(2),
188 GroupFrameT(MSG(MSG_OUTPUT_FIELD)),
189 Child, (IPTR)Label(MSG(MSG_NAME)),
190 Child, (IPTR)(nameNum = (Object *)SliderObject,
191 MUIA_Numeric_Min, 10,
192 MUIA_Numeric_Max, 50,
193 End),
194 Child, (IPTR)Label(MSG(MSG_ACTION)),
195 Child, (IPTR)(actionNum = (Object *)SliderObject,
196 MUIA_Numeric_Min, 10,
197 MUIA_Numeric_Max, 50,
198 End),
199 Child, (IPTR)Label(MSG(MSG_TARGET)),
200 Child, (IPTR)(targetNum = (Object *)SliderObject,
201 MUIA_Numeric_Min, 10,
202 MUIA_Numeric_Max, 50,
203 End),
204 Child, (IPTR)Label(MSG(MSG_OPTION)),
205 Child, (IPTR)(optionNum = (Object *)SliderObject,
206 MUIA_Numeric_Min, 10,
207 MUIA_Numeric_Max, 50,
208 End),
209 End),
210 End),
211 Child, (IPTR)(VGroup,
212 Child, (IPTR)(ColGroup(2),
213 GroupFrameT(MSG(MSG_SYSTEM_FUNC)),
214 Child, (IPTR)Label("FindPort"),
215 Child, (IPTR)(findPortCM = MUI_MakeObject(MUIO_Checkmark, "")),
216 Child, (IPTR)Label("FindResident"),
217 Child, (IPTR)(findResidentCM = MUI_MakeObject(MUIO_Checkmark, "")),
218 Child, (IPTR)Label("FindSemaphore"),
219 Child, (IPTR)(findSemaphoreCM = MUI_MakeObject(MUIO_Checkmark, "")),
220 Child, (IPTR)Label("FindTask"),
221 Child, (IPTR)(findTaskCM = MUI_MakeObject(MUIO_Checkmark, "")),
222 Child, (IPTR)Label("LockScreen"),
223 Child, (IPTR)(lockScreenCM = MUI_MakeObject(MUIO_Checkmark, "")),
224 Child, (IPTR)Label("OpenDevice"),
225 Child, (IPTR)(openDeviceCM = MUI_MakeObject(MUIO_Checkmark, "")),
226 Child, (IPTR)Label("OpenFont"),
227 Child, (IPTR)(openFontCM = MUI_MakeObject(MUIO_Checkmark, "")),
228 Child, (IPTR)Label("OpenLibrary"),
229 Child, (IPTR)(openLibraryCM = MUI_MakeObject(MUIO_Checkmark, "")),
230 Child, (IPTR)Label("OpenResource"),
231 Child, (IPTR)(openResourceCM = MUI_MakeObject(MUIO_Checkmark, "")),
232 Child, (IPTR)Label("ReadToolTypes"),
233 Child, (IPTR)(readToolTypesCM = MUI_MakeObject(MUIO_Checkmark, "")),
234 Child, (IPTR)HVSpace,
235 Child, (IPTR)HVSpace,
236 End),
237 End),
238 Child, (IPTR)(VGroup,
239 Child, (IPTR)(ColGroup(2),
240 GroupFrameT(MSG(MSG_DOS_FUNC)),
241 Child, (IPTR)Label("ChangeDir"),
242 Child, (IPTR)(changeDirCM = MUI_MakeObject(MUIO_Checkmark, "")),
243 Child, (IPTR)Label("Delete"),
244 Child, (IPTR)(deleteCM = MUI_MakeObject(MUIO_Checkmark, "")),
245 Child, (IPTR)Label("Execute"),
246 Child, (IPTR)(executeCM = MUI_MakeObject(MUIO_Checkmark, "")),
247 Child, (IPTR)Label("GetVar"),
248 Child, (IPTR)(getVarCM = MUI_MakeObject(MUIO_Checkmark, "")),
249 Child, (IPTR)Label("LoadSeg"),
250 Child, (IPTR)(loadSegCM = MUI_MakeObject(MUIO_Checkmark, "")),
251 Child, (IPTR)Label("Lock"),
252 Child, (IPTR)(lockCM = MUI_MakeObject(MUIO_Checkmark, "")),
253 Child, (IPTR)Label("MakeDir"),
254 Child, (IPTR)(makeDirCM = MUI_MakeObject(MUIO_Checkmark, "")),
255 Child, (IPTR)Label("MakeLink"),
256 Child, (IPTR)(makeLinkCM = MUI_MakeObject(MUIO_Checkmark, "")),
257 Child, (IPTR)Label("Open"),
258 Child, (IPTR)(openCM = MUI_MakeObject(MUIO_Checkmark, "")),
259 Child, (IPTR)Label("Rename"),
260 Child, (IPTR)(renameCM = MUI_MakeObject(MUIO_Checkmark, "")),
261 Child, (IPTR)Label("RunCommand"),
262 Child, (IPTR)(runCommandCM = MUI_MakeObject(MUIO_Checkmark, "")),
263 Child, (IPTR)Label("SetVar"),
264 Child, (IPTR)(setVarCM = MUI_MakeObject(MUIO_Checkmark, "")),
265 Child, (IPTR)Label("System"),
266 Child, (IPTR)(systemCM = MUI_MakeObject(MUIO_Checkmark, "")),
267 Child, (IPTR)HVSpace,
268 Child, (IPTR)HVSpace,
269 End),
270 End),
271 End),
272 Child, (IPTR) (RectangleObject,
273 MUIA_Rectangle_HBar, TRUE,
274 MUIA_FixHeight, 2,
275 End),
276 Child, (IPTR)(HGroup,
277 Child, (IPTR)(saveBtn = SimpleButton(MSG(MSG_SAVE))),
278 Child, (IPTR)(openBtn = SimpleButton(MSG(MSG_OPEN))),
279 Child, (IPTR)HVSpace,
280 Child, (IPTR)(useBtn = SimpleButton(MSG(MSG_USE))),
281 Child, (IPTR)(undoBtn = SimpleButton(MSG(MSG_UNDO))),
282 Child, (IPTR)(resetBtn = SimpleButton(MSG(MSG_RESET))),
283 Child, (IPTR)HVSpace,
284 Child, (IPTR)(cancelBtn = SimpleButton(MSG(MSG_CANCEL))),
285 End),
286 End), // WindowContents
287 End), // WindowObject
288 End; // ApplicationObject
290 if ( ! app)
292 clean_exit("Can't create application\n");
295 // disable unavailable functions
296 //set(pathCM, MUIA_Disabled, TRUE);
297 //set(devCM, MUIA_Disabled, TRUE);
298 // breakpoint option only available on hosted
299 #if !(AROS_FLAVOUR & AROS_FLAVOUR_EMULATION)
300 set(breakPointCM, MUIA_Disabled, TRUE);
301 #endif
303 gui_set();
304 set(window, MUIA_Window_Open, TRUE);
306 DoMethod(saveBtn, MUIM_Notify, MUIA_Pressed, FALSE,
307 (IPTR)app, 2, MUIM_CallHook, (IPTR)&save_hook);
309 DoMethod(openBtn, MUIM_Notify, MUIA_Pressed, FALSE,
310 (IPTR)app, 2, MUIM_CallHook, (IPTR)&open_hook);
312 DoMethod(useBtn, MUIM_Notify, MUIA_Pressed, FALSE,
313 (IPTR)app, 2, MUIM_CallHook, (IPTR)&use_hook);
315 DoMethod(undoBtn, MUIM_Notify, MUIA_Pressed, FALSE,
316 (IPTR)app, 2, MUIM_CallHook, (IPTR)&undo_hook);
318 DoMethod(resetBtn, MUIM_Notify, MUIA_Pressed, FALSE,
319 (IPTR)app, 2, MUIM_CallHook, (IPTR)&reset_hook);
321 DoMethod(cancelBtn, MUIM_Notify, MUIA_Pressed, FALSE,
322 (IPTR)app, 2, MUIM_CallHook, (IPTR)&cancel_hook);
325 void gui_handleevents(void)
327 DoMethod(app, MUIM_Application_Execute);
330 void gui_cleanup(void)
332 MUI_DisposeObject(app);
335 void gui_set(void)
337 set(failCM, MUIA_Selected, setup.onlyShowFails);
338 set(cliCM, MUIA_Selected, setup.showCliNr);
339 set(pathCM, MUIA_Selected, setup.showPaths);
340 set(devCM, MUIA_Selected, setup.useDevNames);
341 set(ignoreCM, MUIA_Selected, setup.ignoreWB);
342 set(breakPointCM, MUIA_Selected, setup.breakPoint);
344 set(patternStr, MUIA_String_Contents, setup.pattern);
345 main_parsepattern();
347 set(changeDirCM, MUIA_Selected, setup.enableChangeDir);
348 set(deleteCM, MUIA_Selected, setup.enableDelete);
349 set(executeCM, MUIA_Selected, setup.enableExecute);
350 set(getVarCM, MUIA_Selected, setup.enableGetVar);
351 set(loadSegCM, MUIA_Selected, setup.enableLoadSeg);
352 set(lockCM, MUIA_Selected, setup.enableLock);
353 set(makeDirCM, MUIA_Selected, setup.enableMakeDir);
354 set(makeLinkCM, MUIA_Selected, setup.enableMakeLink);
355 set(openCM, MUIA_Selected, setup.enableOpen);
356 set(renameCM, MUIA_Selected, setup.enableRename);
357 set(runCommandCM, MUIA_Selected, setup.enableRunCommand);
358 set(setVarCM, MUIA_Selected, setup.enableSetVar);
359 set(systemCM, MUIA_Selected, setup.enableSystem);
361 set(findPortCM, MUIA_Selected, setup.enableFindPort);
362 set(findResidentCM, MUIA_Selected, setup.enableFindResident);
363 set(findSemaphoreCM, MUIA_Selected, setup.enableFindSemaphore);
364 set(findTaskCM, MUIA_Selected, setup.enableFindTask);
365 set(lockScreenCM, MUIA_Selected, setup.enableLockScreen);
366 set(openDeviceCM, MUIA_Selected, setup.enableOpenDevice);
367 set(openFontCM, MUIA_Selected, setup.enableOpenFont);
368 set(openLibraryCM, MUIA_Selected, setup.enableOpenLibrary);
369 set(openResourceCM, MUIA_Selected, setup.enableOpenResource);
370 set(readToolTypesCM, MUIA_Selected, setup.enableReadToolTypes);
372 set(nameNum, MUIA_Numeric_Value, setup.nameLen);
373 set(actionNum, MUIA_Numeric_Value, setup.actionLen);
374 set(targetNum, MUIA_Numeric_Value, setup.targetLen);
375 set(optionNum, MUIA_Numeric_Value, setup.optionLen);
378 void gui_get(void)
380 setup.onlyShowFails = XGET(failCM, MUIA_Selected);
381 setup.showCliNr = XGET(cliCM, MUIA_Selected);
382 setup.showPaths = XGET(pathCM, MUIA_Selected);
383 setup.useDevNames = XGET(devCM, MUIA_Selected);
384 setup.ignoreWB = XGET(ignoreCM, MUIA_Selected);
385 setup.breakPoint = XGET(breakPointCM, MUIA_Selected);
387 setup.pattern = (STRPTR)XGET(patternStr, MUIA_String_Contents);
388 main_parsepattern();
390 setup.enableChangeDir = XGET(changeDirCM, MUIA_Selected);
391 setup.enableDelete = XGET(deleteCM, MUIA_Selected);
392 setup.enableExecute = XGET(executeCM, MUIA_Selected);
393 setup.enableGetVar = XGET(getVarCM, MUIA_Selected);
394 setup.enableLoadSeg = XGET(loadSegCM, MUIA_Selected);
395 setup.enableLock = XGET(lockCM, MUIA_Selected);
396 setup.enableMakeDir = XGET(makeDirCM, MUIA_Selected);
397 setup.enableMakeLink = XGET(makeLinkCM, MUIA_Selected);
398 setup.enableOpen = XGET(openCM, MUIA_Selected);
399 setup.enableRename = XGET(renameCM, MUIA_Selected);
400 setup.enableRunCommand = XGET(runCommandCM, MUIA_Selected);
401 setup.enableSetVar = XGET(setVarCM, MUIA_Selected);
402 setup.enableSystem = XGET(systemCM, MUIA_Selected);
404 setup.enableFindPort = XGET(findPortCM, MUIA_Selected);
405 setup.enableFindResident = XGET(findResidentCM, MUIA_Selected);
406 setup.enableFindSemaphore = XGET(findSemaphoreCM, MUIA_Selected);
407 setup.enableFindTask = XGET(findTaskCM, MUIA_Selected);
408 setup.enableLockScreen = XGET(lockScreenCM, MUIA_Selected);
409 setup.enableOpenDevice = XGET(openDeviceCM, MUIA_Selected);
410 setup.enableOpenFont = XGET(openFontCM, MUIA_Selected);
411 setup.enableOpenLibrary = XGET(openLibraryCM, MUIA_Selected);
412 setup.enableOpenResource = XGET(openResourceCM, MUIA_Selected);
413 setup.enableReadToolTypes = XGET(readToolTypesCM, MUIA_Selected);
415 setup.nameLen = XGET(nameNum, MUIA_Numeric_Value);
416 setup.actionLen = XGET(actionNum, MUIA_Numeric_Value);
417 setup.targetLen = XGET(targetNum, MUIA_Numeric_Value);
418 setup.optionLen = XGET(optionNum, MUIA_Numeric_Value);