2 Copyright © 2012, The AROS Development Team. All rights reserved.
7 #include <aros/debug.h>
9 #include <libraries/mui.h>
10 #include <libraries/asl.h>
12 #include <proto/muimaster.h>
13 #include <proto/intuition.h>
14 #include <proto/exec.h>
15 #include <proto/alib.h>
16 #include <proto/asl.h>
17 #include <proto/dos.h>
24 Object
*application
, *window
;
25 struct Hook execute_btn_hook
, pop_single_btn_hook
, pop_multi_btn_hook
;
26 struct FileRequester
*request
;
28 AROS_UFH3S(void, execute_btn_func
,
29 AROS_UFHA(struct Hook
*, h
, A0
),
30 AROS_UFHA(Object
*, object
, A2
),
31 AROS_UFHA(struct Req
**, msg
, A1
))
35 D(bug("[R/execute_btn_func] msg %p *msg %p\n", msg
, *msg
));
36 (*msg
)->do_execute
= TRUE
;
37 DoMethod(application
, MUIM_Application_ReturnID
, MUIV_Application_ReturnID_Quit
);
43 AROS_UFH3S(void, pop_single_btn_func
,
44 AROS_UFHA(struct Hook
*, h
, A0
),
45 AROS_UFHA(Object
*, object
, A2
),
46 AROS_UFHA(Object
**, str_object
, A1
))
50 D(bug("[R/pop_single_btn_func] msg %p *msg %p\n", str_object
, *str_object
));
57 ASLFR_DoMultiSelect
, FALSE
,
58 ASLFR_InitialFile
, "",
59 ASLFR_InitialDrawer
, "",
64 ULONG buflen
= strlen(request
->fr_Drawer
) + strlen(request
->fr_File
) + 10;
65 TEXT
*buffer
= AllocPooled(poolmem
, buflen
);
68 strcpy(buffer
, request
->fr_Drawer
);
69 AddPart(buffer
, request
->fr_File
, buflen
);
70 SET(*str_object
, MUIA_String_Contents
, buffer
);
71 FreePooled(poolmem
, buffer
, buflen
);
79 AROS_UFH3S(void, pop_multi_btn_func
,
80 AROS_UFHA(struct Hook
*, h
, A0
),
81 AROS_UFHA(Object
*, object
, A2
),
82 AROS_UFHA(Object
**, str_object
, A1
))
86 D(bug("[R/pop_multi_btn_func] msg %p *msg %p\n", str_object
, *str_object
));
93 ASLFR_DoMultiSelect
, TRUE
,
94 ASLFR_InitialFile
, "",
95 ASLFR_InitialDrawer
, "",
102 for (i
= 0; i
< request
->fr_NumArgs
; i
++)
104 buflen
+= strlen(request
->fr_Drawer
) + strlen(request
->fr_ArgList
[i
].wa_Name
) + 5;
107 TEXT
*buffer
= AllocPooled(poolmem
, buflen
);
112 for (i
= 0; i
< request
->fr_NumArgs
; i
++)
115 strcpy(ptr
, request
->fr_Drawer
);
116 AddPart(ptr
, request
->fr_ArgList
[i
].wa_Name
, buffer
+ buflen
- ptr
- 2);
117 ptr
= buffer
+ strlen(buffer
);
121 SET(*str_object
, MUIA_String_Contents
, buffer
);
122 FreePooled(poolmem
, buffer
, buflen
);
130 BOOL
create_gui(struct Req
*req
)
132 Object
*ok_btn
, *cancel_btn
, *str_group
, *chk_group
;
133 struct TagItem str_group_tags
[50];
134 struct TagItem chk_group_tags
[50];
136 LONG i
, str_cnt
, chk_cnt
;
138 request
= AllocAslRequest(ASL_FileRequest
, NULL
);
142 execute_btn_hook
.h_Entry
= (HOOKFUNC
)execute_btn_func
;
143 pop_single_btn_hook
.h_Entry
= (HOOKFUNC
)pop_single_btn_func
;
144 pop_multi_btn_hook
.h_Entry
= (HOOKFUNC
)pop_multi_btn_func
;
148 bug(" i Name A F K M N S T\n");
149 for (i
= 0; i
< req
->arg_cnt
; i
++)
153 "%2d %25s %c %c %c %c %c %c\n",
154 i
, req
->cargs
[i
].argname
,
155 req
->cargs
[i
].a_flag
? 'X' : '-',
156 req
->cargs
[i
].f_flag
? 'X' : '-',
157 req
->cargs
[i
].k_flag
? 'X' : '-',
158 req
->cargs
[i
].m_flag
? 'X' : '-',
159 req
->cargs
[i
].n_flag
? 'X' : '-',
160 req
->cargs
[i
].s_flag
? 'X' : '-',
161 req
->cargs
[i
].t_flag
? 'X' : '-'
168 i
= 0, str_cnt
= 0, chk_cnt
= 0;
169 i
< req
->arg_cnt
&& str_cnt
< 40 && chk_cnt
< 40;
173 Object
*new_obj
= NULL
;
174 Object
*new_arg_obj
= NULL
; // the object with the argument's value
176 if (req
->cargs
[i
].s_flag
|| req
->cargs
[i
].t_flag
) // Switch
178 new_obj
= Label1(req
->cargs
[i
].argname
);
181 chk_group_tags
[chk_cnt
].ti_Tag
= Child
;
182 chk_group_tags
[chk_cnt
].ti_Data
= (IPTR
)new_obj
;
185 new_arg_obj
= MUI_MakeObject(MUIO_Checkmark
, NULL
);
188 chk_group_tags
[chk_cnt
].ti_Tag
= Child
;
189 chk_group_tags
[chk_cnt
].ti_Data
= (IPTR
)new_arg_obj
;
190 req
->cargs
[i
].object
= new_arg_obj
;
194 else if (req
->cargs
[i
].n_flag
) // Numeric
196 new_obj
= Label2(req
->cargs
[i
].argname
);
199 str_group_tags
[str_cnt
].ti_Tag
= Child
;
200 str_group_tags
[str_cnt
].ti_Data
= (IPTR
)new_obj
;
203 new_arg_obj
= StringObject
,
206 MUIA_String_Accept
, "+-0123456879",
210 str_group_tags
[str_cnt
].ti_Tag
= Child
;
211 str_group_tags
[str_cnt
].ti_Data
= (IPTR
)new_arg_obj
;
212 req
->cargs
[i
].object
= new_arg_obj
;
216 else if (req
->cargs
[i
].m_flag
) // Multiple
219 new_obj
= Label2(req
->cargs
[i
].argname
);
222 str_group_tags
[str_cnt
].ti_Tag
= Child
;
223 str_group_tags
[str_cnt
].ti_Data
= (IPTR
)new_obj
;
227 Child
, new_arg_obj
= StringObject
,
231 Child
, pop_btn
= PopButton(MUII_PopFile
),
235 D(bug("[R] pop %p string %p\n", pop_btn
, new_arg_obj
));
238 pop_btn
, MUIM_Notify
, MUIA_Pressed
, FALSE
,
239 (IPTR
)pop_btn
, 3, MUIM_CallHook
, &pop_multi_btn_hook
, new_arg_obj
241 str_group_tags
[str_cnt
].ti_Tag
= Child
;
242 str_group_tags
[str_cnt
].ti_Data
= (IPTR
)new_obj
;
243 req
->cargs
[i
].object
= new_arg_obj
;
250 new_obj
= Label2(req
->cargs
[i
].argname
);
253 str_group_tags
[str_cnt
].ti_Tag
= Child
;
254 str_group_tags
[str_cnt
].ti_Data
= (IPTR
)new_obj
;
258 Child
, new_arg_obj
= StringObject
,
262 Child
, pop_btn
= PopButton(MUII_PopFile
),
266 D(bug("[R] pop %p string %p\n", pop_btn
, new_arg_obj
));
269 pop_btn
, MUIM_Notify
, MUIA_Pressed
, FALSE
,
270 (IPTR
)pop_btn
, 3, MUIM_CallHook
, &pop_single_btn_hook
, new_arg_obj
272 str_group_tags
[str_cnt
].ti_Tag
= Child
;
273 str_group_tags
[str_cnt
].ti_Data
= (IPTR
)new_obj
;
274 req
->cargs
[i
].object
= new_arg_obj
;
280 // create string group
281 str_group_tags
[str_cnt
].ti_Tag
= MUIA_Group_Columns
;
282 str_group_tags
[str_cnt
].ti_Data
= 2;
284 str_group_tags
[str_cnt
].ti_Tag
= TAG_DONE
;
285 str_group
= MUI_NewObjectA(MUIC_Group
, str_group_tags
);
287 // fill empty check slots
288 for (i
= 0; i
< chk_cnt
% 8; i
++)
290 chk_group_tags
[chk_cnt
].ti_Tag
= Child
;
291 chk_group_tags
[chk_cnt
].ti_Data
= (IPTR
)HVSpace
;
295 // create check group
296 chk_group_tags
[chk_cnt
].ti_Tag
= MUIA_Group_Columns
;
297 chk_group_tags
[chk_cnt
].ti_Data
= 8;
299 chk_group_tags
[chk_cnt
].ti_Tag
= TAG_DONE
;
300 chk_group
= MUI_NewObjectA(MUIC_Group
, chk_group_tags
);
302 sprintf(filename
, _(MSG_WIN_TITLE
), req
->filename
);
303 application
= (Object
*)ApplicationObject
,
304 MUIA_Application_Title
, __(MSG_APP_TITLE
),
305 MUIA_Application_Version
, (IPTR
) VERSION
,
306 MUIA_Application_Description
, __(MSG_APP_DESCRIPTION
),
307 MUIA_Application_Base
, (IPTR
) "REQUEST",
308 MUIA_Application_UseCommodities
, FALSE
,
309 SubWindow
, (IPTR
)(window
= (Object
*)WindowObject
,
310 MUIA_Window_Title
, (IPTR
) filename
,
311 MUIA_Window_ID
, MAKE_ID('R','E','Q','U'),
312 WindowContents
, VGroup
,
319 Child
, (IPTR
) (RectangleObject
,
320 MUIA_Rectangle_HBar
, TRUE
,
324 MUIA_Group_SameWidth
, TRUE
,
325 Child
, ok_btn
= SimpleButton(_(MSG_OK
)),
327 Child
, cancel_btn
= SimpleButton(_(MSG_CANCEL
)),
338 MUIM_Notify
, MUIA_Window_CloseRequest
, TRUE
,
339 (IPTR
)application
, 2,
340 MUIM_Application_ReturnID
, MUIV_Application_ReturnID_Quit
346 MUIM_Notify
, MUIA_Pressed
, FALSE
,
347 (IPTR
)application
, 2,
348 MUIM_Application_ReturnID
, MUIV_Application_ReturnID_Quit
354 MUIM_Notify
, MUIA_Pressed
, FALSE
,
355 (IPTR
)application
, 3,
356 MUIM_CallHook
, &execute_btn_hook
, req
359 SET(window
, MUIA_Window_Open
, TRUE
);
367 BOOL
handle_gui(struct Req
*req
)
369 DoMethod(application
, MUIM_Application_Execute
);
370 SET(window
, MUIA_Window_Open
, FALSE
);
371 return req
->do_execute
;
374 // combine string array to a single string with quoted entries
375 static STRPTR
build_quoted_string(STRPTR
*strings
)
381 for (i
= 0; strings
[i
]; i
++)
383 size
+= strlen(strings
[i
]) + 3;
385 str
= AllocPooled(poolmem
, size
);
391 for (i
= 0; strings
[i
]; i
++)
394 strcat(str
, strings
[i
]);
397 // string will be '\0' terminated because AllocPooled has MEMF_CLEAR
402 // fill the gadgets with the values which were given by the
403 // command line argument ARGUMENTS
404 BOOL
set_defaults(struct Req
*req
)
409 BOOL success
= FALSE
;
411 if (req
->arguments
== NULL
|| req
->arguments
[0] == '\0')
413 // we're done if shell parameter 'argument' wasn't given
417 array
= AllocPooled(poolmem
, sizeof (IPTR
) * req
->arg_cnt
);
420 rda
= AllocDosObject(DOS_RDARGS
, NULL
);
423 rda
->RDA_Source
.CS_Buffer
= req
->arguments
;
424 rda
->RDA_Source
.CS_Length
= strlen(req
->arguments
);
425 rda
->RDA_Source
.CS_CurChr
= 0;
426 if (ReadArgs(req
->cmd_template
, array
, rda
))
428 for (i
= 0; i
< req
->arg_cnt
; i
++)
430 if (req
->cargs
[i
].s_flag
|| req
->cargs
[i
].t_flag
)
432 SET(req
->cargs
[i
].object
, MUIA_Selected
, array
[i
] ? TRUE
: FALSE
);
434 else if (req
->cargs
[i
].n_flag
&& array
[i
])
436 SET(req
->cargs
[i
].object
, MUIA_String_Integer
, *(LONG
*)array
[i
]);
438 else if (req
->cargs
[i
].m_flag
&& array
[i
])
440 SET(req
->cargs
[i
].object
, MUIA_String_Contents
, build_quoted_string((STRPTR
*)array
[i
]));
444 SET(req
->cargs
[i
].object
, MUIA_String_Contents
, array
[i
]);
450 FreeDosObject(DOS_RDARGS
, rda
);
452 FreePooled(poolmem
, array
, sizeof (IPTR
) * req
->arg_cnt
);
458 BOOL
get_gui_bool(struct CArg
*carg
)
460 return XGET(carg
->object
, MUIA_Selected
);
464 CONST_STRPTR
get_gui_string(struct CArg
*carg
)
466 return (CONST_STRPTR
)XGET(carg
->object
, MUIA_String_Contents
);
470 void cleanup_gui(void)
472 if (application
) MUI_DisposeObject(application
);
473 if (request
) FreeAslRequest(request
);