Fixes to typos in comments etc.
[AROS.git] / workbench / prefs / Zune / zune.c
blob2629a65f06e3f05b2bc8230aaffb36ed16453f7e
1 /*
2 Copyright 2002-2014, The AROS Development Team.
3 All rights reserved.
5 $Id$
6 */
8 #include <string.h>
9 #include <stdio.h>
11 #include <exec/memory.h>
13 #include <libraries/asl.h>
14 #include <libraries/mui.h>
15 #include <prefs/prefhdr.h>
17 #include <clib/alib_protos.h>
18 #include <proto/exec.h>
19 #include <proto/dos.h>
20 #include <proto/intuition.h>
21 #include <proto/utility.h>
22 #include <proto/iffparse.h>
23 #include <proto/muimaster.h>
25 #include "systemp.h"
26 #include "buttonsp.h"
27 #include "groupsp.h"
28 #include "windowp.h"
29 #include "cyclesp.h"
30 #include "slidersp.h"
31 #include "scrollbarsp.h"
32 #include "listviewsp.h"
33 #include "stringsp.h"
34 #include "specialp.h"
35 #include "navigationp.h"
36 #include "framesp.h"
37 #include "zunestuff.h"
39 #define DEBUG 0
40 #include <aros/debug.h>
42 /************************************************************************/
44 #ifndef MAXFILENAMELENGTH
45 #define MAXFILENAMELENGTH 255
46 #endif
48 /************************************************************************/
50 #define MCC_Query(x) AROS_LVO_CALL1(struct MUI_CustomClass *, \
51 AROS_LCA(LONG, (x), D0), \
52 struct Library *, mcclib, 5, lib)
55 #define ZUNEVERSION "$VER: Zune 0.2 (22.02.2006) AROS Dev Team"
57 APTR *appaddr;
59 struct TagItem prefstags[] =
61 { ASLFR_DoPatterns, (IPTR)TRUE },
62 { ASLFR_InitialPattern, (IPTR)"#?.prefs" },
63 { TAG_DONE, 0 },
66 /************************************************************************/
68 void load_prefs(CONST_STRPTR name);
69 void save_prefs(CONST_STRPTR name, BOOL envarc);
70 void test_prefs(void);
71 void main_open_menu(void);
72 void main_saveas_menu(void);
73 void restore_prefs(CONST_STRPTR name);
75 /************************************************************************/
78 static struct Hook main_cancel_pressed_hook;
79 static struct Hook main_save_pressed_hook;
80 static struct Hook main_use_pressed_hook;
81 static struct Hook main_test_pressed_hook;
82 static struct Hook main_open_menu_hook;
83 static struct Hook main_saveas_menu_hook;
84 static struct Hook main_page_active_hook;
85 static struct Hook page_display_hook;
87 static Object *app;
88 static Object *open_menuitem;
89 static Object *append_menuitem;
90 static Object *saveas_menuitem;
91 static Object *aboutzune_menuitem;
92 static Object *quit_menuitem;
93 static Object *LastSavedConfigdata = NULL;
94 static STRPTR appname = NULL;
96 static Object *main_wnd;
97 static Object *main_page_list;
98 static Object *main_page_group; /* contains the selelected group */
99 static Object *main_page_group_displayed; /* The current displayed group */
100 static Object *main_page_space; /* a space object */
102 void close_classes(void)
104 delete_listview_class();
107 int open_classes(void)
109 if ((ClassListview_CLASS = create_listview_class()) != NULL)
111 return 1;
113 else
115 close_classes();
116 return 0;
121 #define MAX_PAGE_ENTRIES 100
123 /* the name field is set in init_gui() */
124 struct page_entry main_page_entries[MAX_PAGE_ENTRIES + 1] =
126 /* {"Info", NULL, NULL, NULL, NULL, NULL}, */
127 { "", NULL, NULL, NULL, NULL, &_MUIP_System_desc },
128 { "", NULL, NULL, NULL, NULL, &_MUIP_Windows_desc },
129 { "", NULL, NULL, NULL, NULL, &_MUIP_Groups_desc },
130 { "", NULL, NULL, NULL, NULL, &_MUIP_Buttons_desc },
131 { "", NULL, NULL, NULL, NULL, &_MUIP_Cycles_desc },
132 { "", NULL, NULL, NULL, NULL, &_MUIP_Sliders_desc },
133 { "", NULL, NULL, NULL, NULL, &_MUIP_Scrollbars_desc },
134 { "", NULL, NULL, NULL, NULL, &_MUIP_Listviews_desc },
135 { "", NULL, NULL, NULL, NULL, &_MUIP_Strings_desc },
136 { "", NULL, NULL, NULL, NULL, &_MUIP_Navigation_desc },
137 { "", NULL, NULL, NULL, NULL, &_MUIP_Special_desc },
138 { "", NULL, NULL, NULL, NULL, &_MUIP_Frames_desc },
139 { NULL, NULL, NULL, NULL, NULL, NULL },
142 struct MUI_CustomClass *create_class(const struct __MUIBuiltinClass *desc)
144 return MUI_CreateCustomClass(NULL,MUIC_Settingsgroup,NULL,desc->datasize,desc->dispatcher);
148 /****************************************************************
149 The display function for the page listview
150 *****************************************************************/
151 static void main_page_list_display(struct Hook *h, char **strings, struct page_entry *entry)
153 if (entry)
155 sprintf(entry->mcp_imagespec, "\33O[%08lx]", (long unsigned)entry->mcp_listimage);
156 *strings++ = entry->mcp_imagespec;
157 *strings = entry->name;
162 /****************************************************************
163 A new entry has been selected
164 *****************************************************************/
165 void main_page_active(void)
167 int new_active = XGET(main_page_list,MUIA_List_Active);
168 Object *new_group;
170 if (new_active == -1)
171 new_group = main_page_space;
172 else
174 new_group = main_page_entries[new_active].group;
175 if (!new_group)
176 new_group = main_page_space;
179 if (new_group == main_page_group_displayed)
180 return;
182 DoMethod(main_page_group, MUIM_Group_InitChange);
183 DoMethod(main_page_group, OM_REMMEMBER, (IPTR)main_page_group_displayed);
184 DoMethod(main_page_group, OM_ADDMEMBER, (IPTR)new_group);
185 DoMethod(main_page_group, MUIM_Group_ExitChange);
186 main_page_group_displayed = new_group;
189 /****************************************************************
190 Save pressed
191 *****************************************************************/
192 void main_save_pressed(void)
194 save_prefs(appname, TRUE);
195 DoMethod(app, MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit);
198 /****************************************************************
199 Use pressed
200 *****************************************************************/
201 void main_use_pressed(void)
203 save_prefs(appname, FALSE);
204 DoMethod(app, MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit);
207 /****************************************************************
208 Test pressed
209 *****************************************************************/
210 void main_test_pressed(void)
212 test_prefs();
215 /****************************************************************
216 Cancel pressed
217 *****************************************************************/
218 void main_cancel_pressed(void)
220 restore_prefs(appname);
221 DoMethod(app, MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit);
224 /****************************************************************
225 Look for MCPs
226 *****************************************************************/
227 void find_mcps(void)
229 static CONST_STRPTR const searchpaths[] =
231 "Zune/#?.(mcp|mcc)",
232 "Classes/Zune/#?.(mcp|mcc)",
233 "MUI/#?.(mcp|mcc)",
234 NULL,
236 CONST_STRPTR const *pathptr;
237 struct DevProc *dp = NULL;
238 struct page_entry *pe;
239 WORD num_page_entries = 0;
240 BPTR olddir;
242 for(pe = main_page_entries; pe->name; pe++)
244 num_page_entries++;
247 olddir = CurrentDir(BNULL);
249 while((dp = GetDeviceProc("LIBS:", dp)))
251 CurrentDir(dp->dvp_Lock);
253 for(pathptr = searchpaths; *pathptr; pathptr++)
255 struct AnchorPath *ap;
256 LONG match;
258 ap = (struct AnchorPath *)AllocVec(sizeof(struct AnchorPath) + 256, MEMF_CLEAR);
259 if (ap)
261 ap->ap_Strlen = 256;
263 for(match = MatchFirst((STRPTR)*pathptr, ap);
264 match == 0;
265 match = MatchNext(ap))
267 struct Library *mcclib;
269 if (num_page_entries < MAX_PAGE_ENTRIES)
271 if ((mcclib = OpenLibrary(ap->ap_Buf, 0)))
273 struct MUI_CustomClass *mcp;
275 if ((mcp = MCC_Query(1)))
277 char *sp;
279 pe->cl = mcp;
280 pe->mcp_library = mcclib;
281 pe->mcp_image = (Object *)MCC_Query(2); /* Get MCP image */
282 D(bug("[Zune Prefs/find_mcps] image %p\n", pe->mcp_image));
284 mcclib = NULL;
286 pe->mcp_namebuffer[0] = 27;
287 pe->mcp_namebuffer[1] = '3';
288 strncpy(pe->mcp_namebuffer + 2, mcp->mcc_Class->cl_ID, sizeof(pe->mcp_namebuffer) - 3);
290 if ((sp = strrchr(pe->mcp_namebuffer, '.')))
291 *sp = '\0';
293 pe->name = pe->mcp_namebuffer;
295 pe++;
296 num_page_entries++;
298 } /* if ((mcp = MCC_Query(1))) */
300 if (mcclib) CloseLibrary(mcclib);
302 } /* if ((mcclib = OpenLibrary(ap->ap_Buf, 0))) */
304 } /* if (num_page_entries < MAX_PAGE_ENTRIES) */
306 } /* for(match = ... */
308 MatchEnd(ap);
310 FreeVec(ap);
312 } /* if (ap) */
314 } /* for(pathptr = searchpaths; *pathptr; pathptr++) */
316 if (!(dp->dvp_Flags & DVPF_ASSIGN)) break;
318 } /* while((dp = GetDeviceProc("LIBS:", dp))) */
320 FreeDeviceProc(dp);
322 CurrentDir(olddir);
325 /****************************************************************
326 Deallocates all gui resources
327 *****************************************************************/
328 void deinit_gui(void)
330 int i;
332 if (app)
333 MUI_DisposeObject(app);
335 for (i = 0; main_page_entries[i].name; i++)
337 if ((main_page_entries[i].group != NULL) &&
338 (main_page_entries[i].group != main_page_group_displayed))
340 DisposeObject(main_page_entries[i].group);
343 if (main_page_entries[i].mcp_library)
345 main_page_entries[i].cl = NULL; /* Prevent MUI_DeleteCustomClass call below */
347 if ((main_page_entries[i].group == NULL) ||
348 (main_page_entries[i].group != main_page_group_displayed))
350 /* Only close library if main_page_group_displayed is not this page,
351 because in that case the object got automatically killed through
352 MUI_DisposeObject(app) which also does the CloseLibrary()!! */
354 CloseLibrary(main_page_entries[i].mcp_library);
355 main_page_entries[i].mcp_library = NULL;
359 main_page_entries[i].group = NULL;
361 if (main_page_entries[i].cl != NULL)
363 MUI_DeleteCustomClass(main_page_entries[i].cl);
364 main_page_entries[i].cl = NULL;
368 if (main_page_group_displayed != main_page_space)
369 MUI_DisposeObject(main_page_space);
372 /****************************************************************
373 Allocate resources for gui
374 *****************************************************************/
375 int init_gui(void)
377 Object *save_button;
378 Object *use_button;
379 Object *test_button;
380 Object *cancel_button;
381 STRPTR wintitle;
382 char titlebuf[255];
384 main_page_entries[ 0].name = (char *)_(MSG_DSC_SYSTEM);
385 main_page_entries[ 1].name = (char *)_(MSG_DSC_WINDOWS);
386 main_page_entries[ 2].name = (char *)_(MSG_DSC_GROUPS);
387 main_page_entries[ 3].name = (char *)_(MSG_DSC_BUTTONS);
388 main_page_entries[ 4].name = (char *)_(MSG_DSC_CYCLES);
389 main_page_entries[ 5].name = (char *)_(MSG_DSC_SLIDERS);
390 main_page_entries[ 6].name = (char *)_(MSG_DSC_SCROLLBARS);
391 main_page_entries[ 7].name = (char *)_(MSG_DSC_LISTVIEWS);
392 main_page_entries[ 8].name = (char *)_(MSG_DSC_STRINGS);
393 main_page_entries[ 9].name = (char *)_(MSG_DSC_NAVIGATION);
394 main_page_entries[10].name = (char *)_(MSG_DSC_SPECIAL);
395 main_page_entries[11].name = (char *)_(MSG_DSC_FRAMES);
397 main_cancel_pressed_hook.h_Entry = HookEntry;
398 main_cancel_pressed_hook.h_SubEntry = (HOOKFUNC)main_cancel_pressed;
400 main_save_pressed_hook.h_Entry = HookEntry;
401 main_save_pressed_hook.h_SubEntry = (HOOKFUNC)main_save_pressed;
403 main_use_pressed_hook.h_Entry = HookEntry;
404 main_use_pressed_hook.h_SubEntry = (HOOKFUNC)main_use_pressed;
406 main_test_pressed_hook.h_Entry = HookEntry;
407 main_test_pressed_hook.h_SubEntry = (HOOKFUNC)main_test_pressed;
409 main_open_menu_hook.h_Entry = HookEntry;
410 main_open_menu_hook.h_SubEntry = (HOOKFUNC)main_open_menu;
412 main_saveas_menu_hook.h_Entry = HookEntry;
413 main_saveas_menu_hook.h_SubEntry = (HOOKFUNC)main_saveas_menu;
415 main_page_active_hook.h_Entry = HookEntry;
416 main_page_active_hook.h_SubEntry = (HOOKFUNC)main_page_active;
418 page_display_hook.h_Entry = HookEntry;
419 page_display_hook.h_SubEntry = (APTR)main_page_list_display;
421 if (!strcmp(appname, "global"))
422 wintitle = (STRPTR) _(MSG_WINTITLE1);
423 else
425 snprintf(titlebuf, 255, _(MSG_WINTITLE2), appname);
426 wintitle = titlebuf;
429 app = ApplicationObject,
430 MUIA_Application_Title, (IPTR) "Zune",
431 MUIA_Application_Version, (IPTR) ZUNEVERSION,
432 MUIA_Application_Copyright, (IPTR) " 2006, The AROS Development Team",
433 MUIA_Application_Description, wintitle,
434 MUIA_Application_Base, "ZUNEPREF",
435 MUIA_Application_Menustrip, MenuitemObject,
436 MUIA_Family_Child, MenuitemObject,
437 MUIA_Menuitem_Title, _(MSG_MEN_PROJECT),
438 MUIA_Family_Child, open_menuitem = MenuitemObject,
439 MUIA_Menuitem_Title, _(MSG_MEN_OPEN), MUIA_Menuitem_Shortcut, _(MSG_MEN_OPEN_SC),
440 End,
441 MUIA_Family_Child, append_menuitem = MenuitemObject, MUIA_Menuitem_Title, _(MSG_MEN_APPEND), End,
442 MUIA_Family_Child, saveas_menuitem = MenuitemObject,
443 MUIA_Menuitem_Title, _(MSG_MEN_SAVEAS), MUIA_Menuitem_Shortcut, _(MSG_MEN_SAVEAS_SC),
444 End,
445 MUIA_Family_Child, MenuitemObject, MUIA_Menuitem_Title, NM_BARLABEL, End,
446 MUIA_Family_Child, aboutzune_menuitem = MenuitemObject,
447 MUIA_Menuitem_Title, _(MSG_MEN_ABOUT), MUIA_Menuitem_Shortcut, _(MSG_MEN_ABOUT_SC),
448 End,
449 MUIA_Family_Child, MenuitemObject, MUIA_Menuitem_Title, NM_BARLABEL, End,
450 MUIA_Family_Child, quit_menuitem = MenuitemObject,
451 MUIA_Menuitem_Title, _(MSG_MEN_QUIT), MUIA_Menuitem_Shortcut, _(MSG_MEN_QUIT_SC),
452 End,
453 End,
454 End,
455 SubWindow, main_wnd = WindowObject,
456 MUIA_Window_Title, (IPTR)wintitle,
457 MUIA_Window_Activate, TRUE,
458 MUIA_Window_CloseGadget, FALSE,
459 MUIA_Window_ID, MAKE_ID('Z','W','I','N'),
461 WindowContents, VGroup,
462 MUIA_Group_VertSpacing, 10,
463 Child, HGroup,
464 Child, VGroup,
465 Child, (NewObject(ClassListview_CLASS->mcc_Class, NULL,
466 MUIA_CycleChain, 1,
467 MUIA_Listview_List, main_page_list = ListObject,
468 InputListFrame,
469 MUIA_List_AdjustWidth, TRUE,
470 MUIA_List_Format, ",",
471 MUIA_List_DisplayHook, &page_display_hook,
472 End,
473 TAG_DONE)),
474 Child, HGroup,
475 Child, MUI_NewObject(MUIC_Popframe,
476 MUIA_FixHeight, 20,
477 MUIA_Window_Title, (IPTR) _(MSG_FRAME_CLIPBOARD),
478 TAG_DONE),
479 Child, MUI_NewObject(MUIC_Popimage,
480 MUIA_FixHeight, 20,
481 MUIA_Imageadjust_Type, MUIV_Imageadjust_Type_All,
482 MUIA_Window_Title, (IPTR) _(MSG_IMAGE_CLIPBOARD),
483 TAG_DONE),
484 End, /* HGroup */
485 End,
486 Child, VGroup,
487 TextFrame,
488 InnerSpacing(6,6),
489 MUIA_Background, MUII_PageBack,
490 Child, main_page_group = VGroup,
491 Child, main_page_group_displayed = main_page_space = HVSpace,
492 End,
493 End,
494 End,
495 Child, HGroup,
496 Child, test_button = ImageButton(_(MSG_GAD_TEST), "THEME:Images/Gadgets/Prefs/Test"),
497 Child, HVSpace,
498 Child, save_button = ImageButton(_(MSG_GAD_SAVE), "THEME:Images/Gadgets/Prefs/Save"),
499 Child, use_button = ImageButton(_(MSG_GAD_USE), "THEME:Images/Gadgets/Prefs/Use"),
500 Child, cancel_button = ImageButton(_(MSG_GAD_CANCEL), "THEME:Images/Gadgets/Prefs/Cancel"),
501 End,
502 End,
503 End,
504 End;
506 if (app)
508 int i;
510 DoMethod(main_wnd, MUIM_Notify, MUIA_Window_CloseRequest, TRUE,
511 (IPTR)app, 2, MUIM_CallHook, (IPTR)&main_cancel_pressed_hook);
512 DoMethod(cancel_button, MUIM_Notify, MUIA_Pressed, FALSE, (IPTR)app, 2,
513 MUIM_CallHook, (IPTR)&main_cancel_pressed_hook);
514 DoMethod(save_button, MUIM_Notify, MUIA_Pressed, FALSE, (IPTR)app, 2,
515 MUIM_CallHook, (IPTR)&main_save_pressed_hook);
516 DoMethod(use_button, MUIM_Notify, MUIA_Pressed, FALSE, (IPTR)app, 2,
517 MUIM_CallHook, (IPTR)&main_use_pressed_hook);
518 DoMethod(test_button, MUIM_Notify, MUIA_Pressed, FALSE, (IPTR)app, 5,
519 MUIM_Application_PushMethod, (IPTR)app, 2, MUIM_CallHook,
520 (IPTR)&main_test_pressed_hook);
521 DoMethod(quit_menuitem, MUIM_Notify, MUIA_Menuitem_Trigger,
522 MUIV_EveryTime, (IPTR)app, 2, MUIM_CallHook,
523 (IPTR)&main_cancel_pressed_hook);
524 DoMethod(open_menuitem, MUIM_Notify, MUIA_Menuitem_Trigger,
525 MUIV_EveryTime, (IPTR)app, 2, MUIM_CallHook,
526 (IPTR)&main_open_menu_hook);
527 DoMethod(saveas_menuitem, MUIM_Notify, MUIA_Menuitem_Trigger,
528 MUIV_EveryTime, (IPTR)app, 2, MUIM_CallHook,
529 (IPTR)&main_saveas_menu_hook);
530 DoMethod(aboutzune_menuitem, MUIM_Notify, MUIA_Menuitem_Trigger,
531 MUIV_EveryTime, (IPTR)app, 2, MUIM_Application_AboutMUI,
532 (IPTR)main_wnd);
534 for (i = 0; main_page_entries[i].name != NULL; i++)
536 struct page_entry *p = &main_page_entries[i];
538 if (!p->cl) p->cl = create_class(p->desc);
540 if (!(p->cl && (p->group = NewObject(p->cl->mcc_Class, NULL, TAG_DONE))))
542 deinit_gui();
543 return 0;
546 DoMethod(main_page_list, MUIM_List_InsertSingle, (IPTR)p,
547 MUIV_List_Insert_Bottom);
550 DoMethod(main_page_list, MUIM_Notify, MUIA_List_Active, MUIV_EveryTime,
551 (IPTR)app, 3, MUIM_CallHook, (IPTR)&main_page_active_hook);
553 /* Activate first entry */
554 set(main_page_list,MUIA_List_Active,0);
556 return 1;
558 return 0;
561 /****************************************************************
562 Load the given prefs
563 *****************************************************************/
564 void load_prefs(CONST_STRPTR name)
566 Object *configdata;
568 configdata = MUI_NewObject(MUIC_Configdata,
569 MUIA_Configdata_ApplicationBase, (IPTR)name,
570 TAG_DONE);
571 if (configdata != NULL)
573 int i;
575 /* D(bug("zune::load_prefs: created configdata %p\n", configdata)); */
576 LastSavedConfigdata = configdata;
578 /* Call MUIM_Settingsgroup_ConfigToGadgets for every group */
579 for (i=0;main_page_entries[i].name;i++)
581 struct page_entry *p = &main_page_entries[i];
582 if (p->group)
583 DoMethod(p->group, MUIM_Settingsgroup_ConfigToGadgets,
584 (IPTR)configdata);
587 /* D(bug("zune::save_prefs: disposed configdata %p\n", configdata)); */
591 /* write prefs to env: */
592 void test_prefs(void)
594 Object *cfg;
596 save_prefs(appname, FALSE);
597 /* load_prefs(); */
598 cfg = MUI_NewObject(MUIC_Configdata, MUIA_Configdata_Application, (IPTR)app, TAG_DONE);
599 set(app, MUIA_Application_Configdata, (IPTR)cfg);
602 void restore_prefs(CONST_STRPTR name)
604 char buf[255];
606 snprintf(buf, 255, "ENV:zune/%s.prefs", name);
607 DoMethod(LastSavedConfigdata, MUIM_Configdata_Save, (IPTR)buf);
611 /****************************************************************
612 open given prefs file from menue
613 *****************************************************************/
615 void main_open_menu(void)
617 static char dirpart[500]="ENVARC:Zune",filepart[500],filename[1000];
619 if (aslfilerequest ("Load a Zune Prefs File", (char *)&dirpart, (char *)&filepart, (char *)&filename, prefstags));
621 Object *configdata;
623 configdata = MUI_NewObject(MUIC_Configdata,
624 MUIA_Configdata_ApplicationBase,appname,
625 TAG_DONE);
627 if (configdata != NULL)
629 int i;
631 /* D(bug("zune::load_prefs: created configdata %p\n", configdata)); */
632 //LastSavedConfigdata = configdata;
633 DoMethod(configdata, MUIM_Configdata_Load,filename);
635 /* Call MUIM_Settingsgroup_ConfigToGadgets for every group */
636 for (i=0;main_page_entries[i].name;i++)
638 struct page_entry *p = &main_page_entries[i];
640 if (p->group) DoMethod(p->group, MUIM_Settingsgroup_ConfigToGadgets, (IPTR)configdata);
643 /* activate prefs in test mode */
644 test_prefs();
646 /* D(bug("zune::save_prefs: disposed configdata %p\n", configdata)); */
652 /****************************************************************
653 Saves the done prefs
654 *****************************************************************/
655 void save_prefs(CONST_STRPTR name, BOOL envarc)
657 Object *configdata;
659 configdata = MUI_NewObject(MUIC_Configdata,
660 //MUIA_Configdata_ApplicationBase, name,
661 MUIA_Configdata_Application,appaddr,
662 TAG_DONE);
663 if (configdata != NULL)
665 int i;
666 char buf[255];
668 /* D(bug("zune::save_prefs: created configdata %p\n", configdata)); */
670 /* Call MUIM_Settingsgroup_GadgetsToConfig for every group */
671 for (i=0;main_page_entries[i].name;i++)
673 struct page_entry *p = &main_page_entries[i];
674 if (p->group)
675 DoMethod(p->group, MUIM_Settingsgroup_GadgetsToConfig,
676 (IPTR)configdata);
679 if (envarc)
681 snprintf(buf, 255, "ENVARC:zune/%s.prefs", name);
682 DoMethod(configdata, MUIM_Configdata_Save, (IPTR)buf);
684 snprintf(buf, 255, "ENV:zune/%s.prefs", name);
685 DoMethod(configdata, MUIM_Configdata_Save, (IPTR)buf);
687 MUI_DisposeObject(configdata);
688 /* D(bug("zune::save_prefs: disposed configdata %p\n", configdata)); */
693 /****************************************************************
694 SaveAS the done prefs from menu
695 *****************************************************************/
697 void main_saveas_menu(void)
699 static char dirpart[500]="ENVARC:Zune",filepart[500],filename[1000];
701 if (aslfilerequest("Save a Zune Prefs File", (char *)&dirpart, (char *)&filepart, (char *)&filename, prefstags));
703 Object *configdata;
705 configdata = MUI_NewObject(MUIC_Configdata,
706 MUIA_Configdata_ApplicationBase, "dummyfile",
707 TAG_DONE);
709 /* check for ".prefs" suffix in filename, add if not existing */
710 if ( !strstr( filename, ".prefs") ) strcat(filename, ".prefs");
712 if (configdata != NULL)
714 int i;
716 /* D(bug("zune::save_prefs: created configdata %p\n", configdata)); */
718 /* Call MUIM_Settingsgroup_GadgetsToConfig for every group */
719 for (i=0;main_page_entries[i].name;i++)
721 struct page_entry *p = &main_page_entries[i];
723 if (p->group) DoMethod(p->group, MUIM_Settingsgroup_GadgetsToConfig, (IPTR)configdata);
726 DoMethod(configdata, MUIM_Configdata_Save, filename);
728 MUI_DisposeObject(configdata);
729 /* D(bug("zune::save_prefs: disposed configdata %p\n", configdata)); */
737 /****************************************************************
738 The message loop
739 *****************************************************************/
740 void loop(void)
742 ULONG sigs = 0;
744 while((LONG) DoMethod(app, MUIM_Application_NewInput, (IPTR)&sigs)
745 != MUIV_Application_ReturnID_Quit)
747 if (sigs)
749 sigs = Wait(sigs | SIGBREAKF_CTRL_C | SIGBREAKF_CTRL_D);
750 if (sigs & SIGBREAKF_CTRL_C) break;
751 if (sigs & SIGBREAKF_CTRL_D) break;
756 /****************************************************************
757 The main entry point
758 *****************************************************************/
760 int main(void)
762 BPTR OldDir = BNULL, NewDir;
763 int retval = RETURN_OK;
764 struct RDArgs *rda = NULL;
765 // APTR *proc=0;
766 IPTR args[] = { 0,0 };
767 enum { ARG_APPNAME = 0,ARG_APPADDR=1 };
769 Locale_Initialize();
771 if (Cli())
773 rda = ReadArgs("/A,/N", args, NULL);
774 appname=(STRPTR)args[ARG_APPNAME];
775 appaddr=(APTR)args[ARG_APPADDR];
776 if (appaddr)appaddr=*(appaddr);
778 else
780 appname = 0;
783 if (retval == RETURN_OK)
785 if (!appname)
786 appname = "global";
788 if (open_classes())
790 find_mcps();
791 NewDir = Lock("RAM:", SHARED_LOCK);
792 if (NewDir)
793 OldDir = CurrentDir(NewDir);
794 if (init_gui())
796 load_prefs((STRPTR)args[ARG_APPNAME]);
797 set(main_wnd, MUIA_Window_Open, TRUE);
798 if (XGET(main_wnd,MUIA_Window_Open))
800 loop();
802 if (LastSavedConfigdata)
803 MUI_DisposeObject(LastSavedConfigdata);
804 deinit_gui();
806 if (NewDir) {
807 CurrentDir(OldDir);
808 UnLock(NewDir);
810 close_classes();
814 if (rda) FreeArgs(rda);
816 Locale_Deinitialize();
817 return retval;