2 Copyright © 2003-2011, The AROS Development Team. All rights reserved.
7 #include <zune/customclasses.h>
8 #include <zune/prefseditor.h>
10 #include <proto/alib.h>
11 #include <proto/intuition.h>
12 #include <proto/muimaster.h>
13 #include <proto/asl.h>
14 #include <proto/dos.h>
18 #include <aros/debug.h>
21 #include "bibeditor.h"
24 /*** Instance Data **********************************************************/
28 Object
*dock_lst
, *add_dock_btn
, *del_dock_btn
;
29 Object
*dock_name_str
;
30 Object
*program_lst
, *add_program_btn
, *del_program_btn
;
31 struct Hook add_dock_hook
, del_dock_hook
, change_dock_hook
;
32 struct Hook add_program_hook
, del_program_hook
, change_program_hook
;
35 STATIC VOID
BibPrefs2Gadgets(struct BibEditor_DATA
*data
);
36 STATIC VOID
Gadgets2BibPrefs(struct BibEditor_DATA
*data
);
37 STATIC CONST_STRPTR
AllocExpandPath(CONST_STRPTR path
, CONST_STRPTR file
);
39 /*** Macros *****************************************************************/
40 #define SETUP_INST_DATA struct BibEditor_DATA *data = INST_DATA(CLASS, self)
42 /*** Hook Functions *********************************************************/
44 AROS_UFH3S(void, add_dock_func
,
45 AROS_UFHA(struct Hook
*, h
, A0
),
46 AROS_UFHA(Object
*, obj
, A2
),
47 AROS_UFHA(APTR
, msg
, A1
))
51 D(bug("[add_dock_func] called\n"));
53 struct BibEditor_DATA
*data
= h
->h_Data
;
56 STRPTR newentry
= (STRPTR
)XGET(data
->dock_name_str
, MUIA_String_Contents
);
57 LONG dock_count
= XGET(data
->dock_lst
, MUIA_List_Entries
);
59 if (dock_count
< BIB_MAX_DOCKS
- 1 && newentry
[0] != '\0')
64 MUIM_List_InsertSingle
, newentry
, MUIV_List_Insert_Bottom
66 strcpy(bibprefs
.docks
[dock_count
].name
, newentry
);
67 for (i
= 0; i
< BIB_MAX_PROGRAMS
; i
++)
69 bibprefs
.docks
[dock_count
].programs
[i
][0] = '\0';
71 SET(data
->dock_lst
, MUIA_List_Active
, MUIV_List_Active_Bottom
);
72 SET(obj
, MUIA_PrefsEditor_Changed
, TRUE
);
78 AROS_UFH3S(void, del_dock_func
,
79 AROS_UFHA(struct Hook
*, h
, A0
),
80 AROS_UFHA(Object
*, obj
, A2
),
81 AROS_UFHA(APTR
, msg
, A1
))
85 D(bug("[del_dock_func] called\n"));
87 struct BibEditor_DATA
*data
= h
->h_Data
;
89 LONG current_dock
= XGET(data
->dock_lst
, MUIA_List_Active
);
90 LONG dock_count
= XGET(data
->dock_lst
, MUIA_List_Entries
);
92 if( current_dock
!= MUIV_List_Active_Off
)
96 for (i
= current_dock
; i
< dock_count
; i
++ )
98 if (bibprefs
.docks
[i
+ 1].name
[0] != '\0')
100 memcpy(&bibprefs
.docks
[i
], &bibprefs
.docks
[i
+ 1], sizeof(struct Dock
));
104 bibprefs
.docks
[i
].name
[0] = 0;
108 for (i
= 0; i
< BIB_MAX_PROGRAMS
; i
++ )
110 if (bibprefs
.docks
[dock_count
].programs
[i
][0] != '\0')
112 bibprefs
.docks
[dock_count
].programs
[i
][0] = '\0';
115 DoMethod(data
->dock_lst
, MUIM_List_Remove
, current_dock
);
116 SET(obj
, MUIA_PrefsEditor_Changed
, TRUE
);
122 AROS_UFH3S(void, change_dock_func
,
123 AROS_UFHA(struct Hook
*, h
, A0
),
124 AROS_UFHA(Object
*, obj
, A2
),
125 AROS_UFHA(APTR
, msg
, A1
))
129 struct BibEditor_DATA
*data
= h
->h_Data
;
132 LONG current_dock
= XGET(data
->dock_lst
, MUIA_List_Active
);
134 D(bug("[change_dock_func] current_dock %d\n", current_dock
));
136 SET(data
->program_lst
, MUIA_List_Quiet
, TRUE
);
137 DoMethod(data
->program_lst
, MUIM_List_Clear
);
139 if (current_dock
!= MUIV_List_Active_Off
)
144 i
< BIB_MAX_PROGRAMS
&& bibprefs
.docks
[current_dock
].programs
[i
][0] != '\0';
151 MUIM_List_InsertSingle
, bibprefs
.docks
[current_dock
].programs
[i
],
152 MUIV_List_Insert_Bottom
155 SET(data
->del_dock_btn
, MUIA_Disabled
, FALSE
);
156 SET(data
->add_program_btn
, MUIA_Disabled
, FALSE
);
160 SET(data
->del_dock_btn
, MUIA_Disabled
, TRUE
);
161 SET(data
->add_program_btn
, MUIA_Disabled
, TRUE
);
163 SET(data
->program_lst
, MUIA_List_Quiet
, FALSE
);
168 AROS_UFH3S(void, add_program_func
,
169 AROS_UFHA(struct Hook
*, h
, A0
),
170 AROS_UFHA(Object
*, obj
, A2
),
171 AROS_UFHA(APTR
, msg
, A1
))
175 D(bug("[add_program_func] called\n"));
177 struct BibEditor_DATA
*data
= h
->h_Data
;
179 struct FileRequester
*freq
;
180 CONST_STRPTR name
= NULL
;
182 LONG current_dock
= XGET(data
->dock_lst
, MUIA_List_Active
);
183 LONG program_count
= XGET(data
->program_lst
, MUIA_List_Entries
);
185 if (current_dock
== MUIV_List_Active_Off
)
187 D(bug("[IconBarPrefs] Dock not selected, cannot add program!\n"));
191 if (program_count
>= BIB_MAX_PROGRAMS
)
193 D(bug("[IconBarPrefs] Too many programs in dock!\n"));
197 if ((freq
= AllocAslRequestTags(ASL_FileRequest
, TAG_END
)) != NULL
)
204 ASLFR_TitleText
, _(MSG_ADD_P
),
205 ASLFR_DoPatterns
, TRUE
,
206 ASLFR_RejectIcons
, TRUE
,
207 ASLFR_InitialDrawer
, "SYS:",
212 if ((name
= AllocExpandPath(freq
->fr_Drawer
, freq
->fr_File
)) != NULL
)
214 DoMethod(data
->program_lst
, MUIM_List_InsertSingle
, name
, MUIV_List_Insert_Bottom
);
215 strcpy(bibprefs
.docks
[current_dock
].programs
[program_count
], name
);
216 SET(obj
, MUIA_PrefsEditor_Changed
, TRUE
);
220 FreeAslRequest(freq
);
226 AROS_UFH3S(void, del_program_func
,
227 AROS_UFHA(struct Hook
*, h
, A0
),
228 AROS_UFHA(Object
*, obj
, A2
),
229 AROS_UFHA(APTR
, msg
, A1
))
233 D(bug("[del_program_func] called\n"));
235 struct BibEditor_DATA
*data
= h
->h_Data
;
237 LONG current_dock
= XGET(data
->dock_lst
, MUIA_List_Active
);
238 LONG delete_program
= XGET(data
->program_lst
, MUIA_List_Active
);
239 LONG program_count
= XGET(data
->program_lst
, MUIA_List_Entries
);
241 if ((current_dock
!= MUIV_List_Active_Off
) && (delete_program
!= MUIV_List_Active_Off
))
245 for (i
= delete_program
; i
< program_count
; i
++ )
247 if (bibprefs
.docks
[current_dock
].programs
[i
+ 1][0] != '\0')
251 bibprefs
.docks
[current_dock
].programs
[i
],
252 bibprefs
.docks
[current_dock
].programs
[i
+ 1]
257 bibprefs
.docks
[current_dock
].programs
[i
][0] = '\0';
260 DoMethod(data
->program_lst
, MUIM_List_Remove
, MUIV_List_Remove_Selected
);
261 SET(obj
, MUIA_PrefsEditor_Changed
, TRUE
);
267 AROS_UFH3S(void, change_program_func
,
268 AROS_UFHA(struct Hook
*, h
, A0
),
269 AROS_UFHA(Object
*, obj
, A2
),
270 AROS_UFHA(APTR
, msg
, A1
))
274 struct BibEditor_DATA
*data
= h
->h_Data
;
276 LONG current_program
= XGET(data
->program_lst
, MUIA_List_Active
);
278 D(bug("[change_dock_func] current_program %d\n", current_program
));
280 if (current_program
!= MUIV_List_Active_Off
)
282 SET(data
->del_program_btn
, MUIA_Disabled
, FALSE
);
286 SET(data
->del_program_btn
, MUIA_Disabled
, TRUE
);
292 /*** Methods ****************************************************************/
293 Object
*BibEditor__OM_NEW(Class
*CLASS
, Object
*self
, struct opSet
*message
)
295 D(bug("[bibedit class] BibEdit Class New\n"));
297 Object
*dock_lst
, *add_dock_btn
, *del_dock_btn
, *dock_name_str
;
298 Object
*program_lst
, *add_program_btn
, *del_program_btn
;
300 self
= (Object
*) DoSuperNewTags
303 MUIA_PrefsEditor_Name
, _(MSG_TITLE
),
304 MUIA_PrefsEditor_Path
, (IPTR
) "Iconbar.prefs",
305 MUIA_PrefsEditor_IconTool
, (IPTR
) "SYS:Prefs/BoingIconBar",
306 //MUIA_Group_Horiz, TRUE,
307 MUIA_Group_Columns
, 2,
310 MUIA_Text_Contents
, _(MSG_DOCK
),
312 Child
, dock_lst
= ListviewObject
,
313 MUIA_Listview_List
, ListObject
,
314 MUIA_Frame
, MUIV_Frame_InputList
,
315 MUIA_List_ConstructHook
, MUIV_List_ConstructHook_String
,
316 MUIA_List_DestructHook
, MUIV_List_DestructHook_String
,
322 MUIA_Text_Contents
, _(MSG_PROGRAMS
),
324 Child
, program_lst
= ListviewObject
,
325 MUIA_Listview_List
, ListObject
,
326 MUIA_Frame
, MUIV_Frame_InputList
,
327 MUIA_List_ConstructHook
, MUIV_List_ConstructHook_String
,
328 MUIA_List_DestructHook
, MUIV_List_DestructHook_String
,
333 Child
, dock_name_str
= StringObject
,
334 MUIA_String_AdvanceOnCR
, TRUE
,
338 Child
, add_dock_btn
= SimpleButton(_(MSG_ADD_DOCK
)),
339 Child
, del_dock_btn
= SimpleButton(_(MSG_DEL_DOCK
)),
345 Child
, add_program_btn
= SimpleButton(_(MSG_ADD_P
)),
346 Child
, del_program_btn
= SimpleButton(_(MSG_DEL_P
)),
356 data
->dock_lst
= dock_lst
;
357 data
->add_dock_btn
= add_dock_btn
;
358 data
->del_dock_btn
= del_dock_btn
;
359 data
->dock_name_str
= dock_name_str
;
360 data
->program_lst
= program_lst
;
361 data
->add_program_btn
= add_program_btn
;
362 data
->del_program_btn
= del_program_btn
;
363 data
->dock_name_str
= dock_name_str
;
365 data
->add_dock_hook
.h_Entry
= (HOOKFUNC
)add_dock_func
;
366 data
->add_dock_hook
.h_Data
= data
;
367 data
->del_dock_hook
.h_Entry
= (HOOKFUNC
)del_dock_func
;
368 data
->del_dock_hook
.h_Data
= data
;
369 data
->change_dock_hook
.h_Entry
= (HOOKFUNC
)change_dock_func
;
370 data
->change_dock_hook
.h_Data
= data
;
371 data
->add_program_hook
.h_Entry
= (HOOKFUNC
)add_program_func
;
372 data
->add_program_hook
.h_Data
= data
;
373 data
->del_program_hook
.h_Entry
= (HOOKFUNC
)del_program_func
;
374 data
->del_program_hook
.h_Data
= data
;
375 data
->change_program_hook
.h_Entry
= (HOOKFUNC
)change_program_func
;
376 data
->change_program_hook
.h_Data
= data
;
378 SET(data
->del_dock_btn
, MUIA_Disabled
, TRUE
);
379 SET(data
->add_program_btn
, MUIA_Disabled
, TRUE
);
380 SET(data
->del_program_btn
, MUIA_Disabled
, TRUE
);
384 data
->add_dock_btn
, MUIM_Notify
, MUIA_Pressed
, FALSE
,
385 self
, 2, MUIM_CallHook
, &data
->add_dock_hook
390 data
->del_dock_btn
, MUIM_Notify
, MUIA_Pressed
, FALSE
,
391 self
, 2, MUIM_CallHook
, &data
->del_dock_hook
396 data
->dock_lst
, MUIM_Notify
, MUIA_List_Active
, MUIV_EveryTime
,
397 self
, 2, MUIM_CallHook
, &data
->change_dock_hook
402 data
->add_program_btn
, MUIM_Notify
, MUIA_Pressed
, FALSE
,
403 self
, 2, MUIM_CallHook
, &data
->add_program_hook
408 data
->del_program_btn
, MUIM_Notify
, MUIA_Pressed
, FALSE
,
409 self
, 2, MUIM_CallHook
, &data
->del_program_hook
414 data
->program_lst
, MUIM_Notify
, MUIA_List_Active
, MUIV_EveryTime
,
415 self
, 2, MUIM_CallHook
, &data
->change_program_hook
418 BibPrefs2Gadgets(data
);
425 * update struct bibprefs with actual data selected in gadgets
427 STATIC VOID
Gadgets2BibPrefs (struct BibEditor_DATA
*data
)
429 D(bug("Gadgets2BibPrefs\n"));
431 // no-op because we are immediately changing bibprefs
435 * update gadgets with values of struct bibprefs
437 STATIC VOID
BibPrefs2Gadgets(struct BibEditor_DATA
*data
)
441 DoMethod(data
->dock_lst
, MUIM_List_Clear
);
442 DoMethod(data
->program_lst
, MUIM_List_Clear
);
444 for (dock
= 0; bibprefs
.docks
[dock
].name
[0] != '\0'; dock
++)
449 MUIM_List_InsertSingle
, bibprefs
.docks
[dock
].name
, MUIV_List_Insert_Bottom
452 SET(data
->dock_lst
, MUIA_List_Active
, 0);
456 * combine path and file and expand it to an absolute path if necessary
458 STATIC CONST_STRPTR
AllocExpandPath(CONST_STRPTR path
, CONST_STRPTR file
)
460 STRPTR result
= NULL
;
463 if ((result
= AllocVec(BIB_MAX_PATH
, MEMF_ANY
| MEMF_CLEAR
)) != NULL
)
465 strlcpy(result
, path
, BIB_MAX_PATH
);
466 if (file
&& (*file
!= '\0'))
468 AddPart(result
, file
, BIB_MAX_PATH
);
470 if (strchr(result
, ':') == NULL
) // relative path
472 if ((lock
= Lock(result
, ACCESS_READ
)) != BNULL
)
474 NameFromLock(lock
, result
, BIB_MAX_PATH
);
482 IPTR
BibEditor__MUIM_PrefsEditor_ImportFH (
483 Class
*CLASS
, Object
*self
,
484 struct MUIP_PrefsEditor_ImportFH
*message
490 D(bug("[bibedit class] BibEdit Class Import\n"));
492 success
= Prefs_ImportFH(message
->fh
);
493 if (success
) BibPrefs2Gadgets(data
);
498 IPTR BibEditor__MUIM_PrefsEditor_ExportFH
500 Class
*CLASS
, Object
*self
,
501 struct MUIP_PrefsEditor_ExportFH
*message
507 D(bug("[bibedit class] BibEdit Class Export\n"));
509 Gadgets2BibPrefs(data
);
510 success
= Prefs_ExportFH(message
->fh
);
515 IPTR BibEditor__MUIM_PrefsEditor_SetDefaults
517 Class
*CLASS
, Object
*self
, Msg message
523 D(bug("[bibedit class] BibEdit Class SetDefaults\n"));
525 success
= Prefs_Default();
526 if (success
) BibPrefs2Gadgets(data
);
531 /*** Setup ******************************************************************/
534 BibEditor
, NULL
, MUIC_PrefsEditor
, NULL
,
535 OM_NEW
, struct opSet
*,
536 MUIM_PrefsEditor_ImportFH
, struct MUIP_PrefsEditor_ImportFH
*,
537 MUIM_PrefsEditor_ExportFH
, struct MUIP_PrefsEditor_ExportFH
*,
538 MUIM_PrefsEditor_SetDefaults
, Msg