Replaced Popscren with a custom pop-up list for selecting public screen. Now it conta...
[tangerine.git] / workbench / prefs / Zune / zune.c
blob1e99ec55c762265b460b6348de1fea976fff84c1
1 /*
2 Copyright 2002-2006, 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 /************************************************************************/
41 #ifndef MAXFILENAMELENGTH
42 #define MAXFILENAMELENGTH 255
43 #endif
45 /************************************************************************/
47 #ifdef __AROS__
48 #define MCC_Query(x) AROS_LVO_CALL1(struct MUI_CustomClass *, \
49 AROS_LCA(LONG, (x), D0), \
50 struct Library *, mcclib, 5, lib)
51 #else
53 #ifdef __amigaos4__
54 #else
55 struct MUI_CustomClass *MCC_Query(ULONG d0);
56 #pragma libcall mcclib MCC_Query 01e 001
57 #endif
58 #endif
60 #define ZUNEVERSION "$VER: Zune 0.2 (22.02.2006) AROS Dev Team"
62 APTR *appaddr;
64 struct TagItem prefstags[] =
66 { ASLFR_DoPatterns, (IPTR)TRUE },
67 { ASLFR_InitialPattern, (IPTR)"#?.prefs" },
68 { TAG_DONE, 0 },
71 /************************************************************************/
73 void load_prefs(CONST_STRPTR name);
74 void save_prefs(CONST_STRPTR name, BOOL envarc);
75 void test_prefs(void);
76 void main_open_menu(void);
77 void main_saveas_menu(void);
78 void restore_prefs(CONST_STRPTR name);
80 /************************************************************************/
82 #ifdef __amigaos4__
83 struct Library *ZuneMasterBase;
84 struct ZuneMasterIFace *IZuneMaster;
85 #endif
88 /************************************************************************/
90 /****************************************************************
91 Open needed libraries
92 *****************************************************************/
93 int open_libs(void)
95 #ifdef __amigaos4__
96 if (!(ZuneMasterBase = OpenLibrary("zunemaster.library",0)))
98 printf("Unable to open zunemaster.library\n");
99 return 0;
102 if (!(IZuneMaster = (struct ZuneMasterIFace*)GetInterface(ZuneMasterBase,"main",1,NULL)))
104 printf("Unable to get main interface of zunemaster.library\n");
105 CloseLibrary(ZuneMasterBase); ZuneMasterBase = NULL;
106 return 0;
108 #endif
109 return 1;
112 /****************************************************************
113 Close opened libraries
114 *****************************************************************/
115 void close_libs(void)
117 #ifdef __amigaos4__
118 DropInterface((struct Interface*)IZuneMaster);
119 CloseLibrary(ZuneMasterBase);
120 #endif
123 struct Hook hook_standard;
125 static Object *app;
126 static Object *open_menuitem;
127 static Object *append_menuitem;
128 static Object *saveas_menuitem;
129 static Object *aboutzune_menuitem;
130 static Object *quit_menuitem;
131 static Object *LastSavedConfigdata = NULL;
132 static STRPTR appname = NULL;
134 static Object *main_wnd;
135 static Object *main_page_list;
136 static Object *main_page_group; /* contains the selelected group */
137 static Object *main_page_group_displayed; /* The current displayed group */
138 static Object *main_page_space; /* a space object */
140 void close_classes(void)
144 int open_classes(void)
146 if (1)
148 return 1;
150 else
152 close_classes();
153 return 0;
158 struct page_entry
160 char *name;
161 struct MUI_CustomClass *cl; /* The class pointer, maybe NULL */
162 Object *group; /* The group which should be is displayed, maybe NULL */
163 const struct __MUIBuiltinClass *desc;
164 struct Library *mcp_library;
165 UBYTE mcp_namebuffer[MAXFILENAMELENGTH + 1];
168 #define MAX_PAGE_ENTRIES 100
170 /* the name field is set in init_gui() */
171 struct page_entry main_page_entries[MAX_PAGE_ENTRIES + 1] =
173 /* {"Info",NULL,NULL,NULL}, */
174 { "", NULL, NULL, &_MUIP_System_desc },
175 { "", NULL, NULL, &_MUIP_Windows_desc },
176 { "", NULL, NULL, &_MUIP_Groups_desc },
177 { "", NULL, NULL, &_MUIP_Buttons_desc },
178 { "", NULL, NULL, &_MUIP_Cycles_desc },
179 { "", NULL, NULL, &_MUIP_Sliders_desc },
180 { "", NULL, NULL, &_MUIP_Scrollbars_desc },
181 { "", NULL, NULL, &_MUIP_Listviews_desc },
182 { "", NULL, NULL, &_MUIP_Strings_desc },
183 { "", NULL, NULL, &_MUIP_Navigation_desc },
184 { "", NULL, NULL, &_MUIP_Special_desc },
185 { "", NULL, NULL, &_MUIP_Frames_desc },
186 { NULL, NULL, NULL, NULL },
189 struct MUI_CustomClass *create_class(const struct __MUIBuiltinClass *desc)
191 return MUI_CreateCustomClass(NULL,MUIC_Settingsgroup,NULL,desc->datasize,desc->dispatcher);
194 /****************************************************************
195 Our standard hook function, for easy call backs
196 *****************************************************************/
197 static void hook_func_standard(struct Hook *h, void *dummy, ULONG * funcptr)
199 void (*func) (ULONG *) = (void (*)(ULONG *)) (*funcptr);
200 if (func) func(funcptr + 1);
203 /****************************************************************
204 The display function for the page listview
205 *****************************************************************/
206 static void main_page_list_display(struct Hook *h, char **strings, struct page_entry *entry)
208 if (entry)
210 strings[0] = entry->name;
215 /****************************************************************
216 A new entry has been selected
217 *****************************************************************/
218 void main_page_active(void)
220 int new_active = XGET(main_page_list,MUIA_List_Active);
221 Object *new_group;
223 if (new_active == -1)
224 new_group = main_page_space;
225 else
227 new_group = main_page_entries[new_active].group;
228 if (!new_group)
229 new_group = main_page_space;
232 if (new_group == main_page_group_displayed)
233 return;
235 DoMethod(main_page_group, MUIM_Group_InitChange);
236 DoMethod(main_page_group, OM_REMMEMBER, (IPTR)main_page_group_displayed);
237 DoMethod(main_page_group, OM_ADDMEMBER, (IPTR)new_group);
238 DoMethod(main_page_group, MUIM_Group_ExitChange);
239 main_page_group_displayed = new_group;
242 /****************************************************************
243 Save pressed
244 *****************************************************************/
245 void main_save_pressed(void)
247 save_prefs(appname, TRUE);
248 DoMethod(app, MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit);
251 /****************************************************************
252 Use pressed
253 *****************************************************************/
254 void main_use_pressed(void)
256 save_prefs(appname, FALSE);
257 DoMethod(app, MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit);
260 /****************************************************************
261 Test pressed
262 *****************************************************************/
263 void main_test_pressed(void)
265 test_prefs();
268 /****************************************************************
269 Cancel pressed
270 *****************************************************************/
271 void main_cancel_pressed(void)
273 restore_prefs(appname);
274 DoMethod(app, MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit);
277 /****************************************************************
278 Look for MCPs
280 TODO: Write for AmigaOS4
281 *****************************************************************/
282 void find_mcps(void)
284 #ifndef __amigaos4__
285 static CONST_STRPTR const searchpaths[] =
287 "Zune/#?.(mcp|mcc)",
288 "Classes/Zune/#?.(mcp|mcc)",
289 "MUI/#?.(mcp|mcc)",
290 NULL,
292 CONST_STRPTR const *pathptr;
293 struct DevProc *dp = NULL;
294 struct page_entry *pe;
295 WORD num_page_entries = 0;
296 BPTR olddir;
298 for(pe = main_page_entries; pe->name; pe++)
300 num_page_entries++;
303 olddir = CurrentDir(NULL);
305 while((dp = GetDeviceProc("LIBS:", dp)))
307 CurrentDir(dp->dvp_Lock);
309 for(pathptr = searchpaths; *pathptr; pathptr++)
311 struct AnchorPath *ap;
312 LONG match;
314 ap = (struct AnchorPath *)AllocVec(sizeof(struct AnchorPath) + 256, MEMF_CLEAR);
315 if (ap)
317 ap->ap_Strlen = 256;
319 for(match = MatchFirst((STRPTR)*pathptr, ap);
320 match == 0;
321 match = MatchNext(ap))
323 struct Library *mcclib;
325 if (num_page_entries < MAX_PAGE_ENTRIES)
327 if ((mcclib = OpenLibrary(ap->ap_Buf, 0)))
329 struct MUI_CustomClass *mcp;
331 if ((mcp = MCC_Query(1)))
333 char *sp;
335 pe->cl = mcp;
336 pe->mcp_library = mcclib;
337 mcclib = NULL;
339 pe->mcp_namebuffer[0] = 27;
340 pe->mcp_namebuffer[1] = '3';
341 strncpy(pe->mcp_namebuffer + 2, mcp->mcc_Class->cl_ID, sizeof(pe->mcp_namebuffer) - 3);
343 if ((sp = strrchr(pe->mcp_namebuffer, '.')))
344 *sp = '\0';
346 pe->name = pe->mcp_namebuffer;
348 pe++;
349 num_page_entries++;
351 } /* if ((mcp = MCC_Query(1))) */
353 if (mcclib) CloseLibrary(mcclib);
355 } /* if ((mcclib = OpenLibrary(ap->ap_Buf, 0))) */
357 } /* if (num_page_entries < MAX_PAGE_ENTRIES) */
359 } /* for(match = ... */
361 MatchEnd(ap);
363 FreeVec(ap);
365 } /* if (ap) */
367 } /* for(pathptr = searchpaths; *pathptr; pathptr++) */
369 if (!dp->dvp_Flags & DVPF_ASSIGN) break;
371 } /* while((dp = GetDeviceProc("LIBS:", dp))) */
373 FreeDeviceProc(dp);
375 CurrentDir(olddir);
376 #endif
379 /****************************************************************
380 Deallocates all gui resources
381 *****************************************************************/
382 void deinit_gui(void)
384 int i;
386 if (app)
387 MUI_DisposeObject(app);
389 for (i = 0; main_page_entries[i].name; i++)
391 if ((main_page_entries[i].group != NULL) &&
392 (main_page_entries[i].group != main_page_group_displayed))
394 DisposeObject(main_page_entries[i].group);
397 if (main_page_entries[i].mcp_library)
399 main_page_entries[i].cl = NULL; /* Prevent MUI_DeleteCustomClass call below */
401 if ((main_page_entries[i].group == NULL) ||
402 (main_page_entries[i].group != main_page_group_displayed))
404 /* Only close library if main_page_group_displayed is not this page,
405 because in that case the object got automatically killed through
406 MUI_DisposeObject(app) which also does the CloseLibrary()!! */
408 CloseLibrary(main_page_entries[i].mcp_library);
409 main_page_entries[i].mcp_library = NULL;
413 main_page_entries[i].group = NULL;
415 if (main_page_entries[i].cl != NULL)
417 MUI_DeleteCustomClass(main_page_entries[i].cl);
418 main_page_entries[i].cl = NULL;
422 if (main_page_group_displayed != main_page_space)
423 MUI_DisposeObject(main_page_space);
426 /****************************************************************
427 Allocate resources for gui
428 *****************************************************************/
429 int init_gui(void)
431 Object *save_button;
432 Object *use_button;
433 Object *test_button;
434 Object *cancel_button;
435 STRPTR wintitle;
436 char titlebuf[255];
438 main_page_entries[ 0].name = (char *)_(MSG_DSC_SYSTEM);
439 main_page_entries[ 1].name = (char *)_(MSG_DSC_WINDOWS);
440 main_page_entries[ 2].name = (char *)_(MSG_DSC_GROUPS);
441 main_page_entries[ 3].name = (char *)_(MSG_DSC_BUTTONS);
442 main_page_entries[ 4].name = (char *)_(MSG_DSC_CYCLES);
443 main_page_entries[ 5].name = (char *)_(MSG_DSC_SLIDERS);
444 main_page_entries[ 6].name = (char *)_(MSG_DSC_SCROLLBARS);
445 main_page_entries[ 7].name = (char *)_(MSG_DSC_LISTVIEWS);
446 main_page_entries[ 8].name = (char *)_(MSG_DSC_STRINGS);
447 main_page_entries[ 9].name = (char *)_(MSG_DSC_NAVIGATION);
448 main_page_entries[10].name = (char *)_(MSG_DSC_SPECIAL);
449 main_page_entries[11].name = (char *)_(MSG_DSC_FRAMES);
451 static struct Hook page_display_hook;
453 #ifdef __amigaos4__
454 hook_standard.h_Entry = (HOOKFUNC)hook_func_standard;
455 page_display_hook.h_Entry = (HOOKFUNC)main_page_list_display;
456 #else
457 hook_standard.h_Entry = HookEntry;
458 hook_standard.h_SubEntry = (APTR)hook_func_standard;
459 page_display_hook.h_Entry = HookEntry;
460 page_display_hook.h_SubEntry = (APTR)main_page_list_display;
461 #endif
463 if (!strcmp(appname, "global"))
464 wintitle = (STRPTR) _(MSG_WINTITLE1);
465 else
467 snprintf(titlebuf, 255, _(MSG_WINTITLE2), appname);
468 wintitle = titlebuf;
471 app = ApplicationObject,
472 MUIA_Application_Title, (IPTR) "Zune",
473 MUIA_Application_Version, (IPTR) ZUNEVERSION,
474 MUIA_Application_Copyright, (IPTR) " 2006, The AROS Development Team",
475 MUIA_Application_Description, wintitle,
476 MUIA_Application_Base, "ZUNEPREF",
477 MUIA_Application_Menustrip, MenuitemObject,
478 MUIA_Family_Child, MenuitemObject,
479 MUIA_Menuitem_Title, _(MSG_MEN_PROJECT),
480 MUIA_Family_Child, open_menuitem = MenuitemObject,
481 MUIA_Menuitem_Title, _(MSG_MEN_OPEN), MUIA_Menuitem_Shortcut, _(MSG_MEN_OPEN_SC),
482 End,
483 MUIA_Family_Child, append_menuitem = MenuitemObject, MUIA_Menuitem_Title, _(MSG_MEN_APPEND), End,
484 MUIA_Family_Child, saveas_menuitem = MenuitemObject,
485 MUIA_Menuitem_Title, _(MSG_MEN_SAVEAS), MUIA_Menuitem_Shortcut, _(MSG_MEN_SAVEAS_SC),
486 End,
487 MUIA_Family_Child, MenuitemObject, MUIA_Menuitem_Title, NM_BARLABEL, End,
488 MUIA_Family_Child, aboutzune_menuitem = MenuitemObject,
489 MUIA_Menuitem_Title, _(MSG_MEN_ABOUT), MUIA_Menuitem_Shortcut, _(MSG_MEN_ABOUT_SC),
490 End,
491 MUIA_Family_Child, MenuitemObject, MUIA_Menuitem_Title, NM_BARLABEL, End,
492 MUIA_Family_Child, quit_menuitem = MenuitemObject,
493 MUIA_Menuitem_Title, _(MSG_MEN_QUIT), MUIA_Menuitem_Shortcut, _(MSG_MEN_QUIT_SC),
494 End,
495 End,
496 End,
497 SubWindow, main_wnd = WindowObject,
498 MUIA_Window_Title, (IPTR)wintitle,
499 MUIA_Window_Activate, TRUE,
500 MUIA_Window_CloseGadget, FALSE,
501 MUIA_Window_ID, MAKE_ID('Z','W','I','N'),
503 WindowContents, VGroup,
504 MUIA_Group_VertSpacing, 10,
505 Child, HGroup,
506 Child, VGroup,
507 Child, ListviewObject,
508 MUIA_CycleChain, 1,
509 MUIA_Listview_List, main_page_list = ListObject,
510 InputListFrame,
511 MUIA_List_AdjustWidth, TRUE,
512 MUIA_List_DisplayHook, &page_display_hook,
513 End,
514 End,
515 Child, HGroup,
516 Child, MUI_NewObject(MUIC_Popframe,
517 MUIA_FixHeight, 20,
518 MUIA_Window_Title, (IPTR) _(MSG_FRAME_CLIPBOARD),
519 TAG_DONE),
520 Child, MUI_NewObject(MUIC_Popimage,
521 MUIA_FixHeight, 20,
522 MUIA_Imageadjust_Type, MUIV_Imageadjust_Type_All,
523 MUIA_Window_Title, (IPTR) _(MSG_IMAGE_CLIPBOARD),
524 TAG_DONE),
525 End, /* HGroup */
526 End,
527 Child, VGroup,
528 TextFrame,
529 InnerSpacing(6,6),
530 MUIA_Background, MUII_PageBack,
531 Child, main_page_group = VGroup,
532 Child, main_page_group_displayed = main_page_space = HVSpace,
533 End,
534 End,
535 End,
536 Child, HGroup,
537 Child, test_button = MakeButton(_(MSG_GAD_TEST)),
538 Child, HVSpace,
539 Child, save_button = MakeButton(_(MSG_GAD_SAVE)),
540 Child, use_button = MakeButton(_(MSG_GAD_USE)),
541 Child, cancel_button = MakeButton(_(MSG_GAD_CANCEL)),
542 End,
543 End,
544 End,
545 End;
547 if (app)
549 int i;
551 DoMethod(main_wnd, MUIM_Notify, MUIA_Window_CloseRequest, TRUE,
552 (IPTR)app, 3, MUIM_CallHook, (IPTR)&hook_standard,
553 (IPTR)main_cancel_pressed);
554 DoMethod(cancel_button, MUIM_Notify, MUIA_Pressed, FALSE, (IPTR)app, 3,
555 MUIM_CallHook, (IPTR)&hook_standard, (IPTR)main_cancel_pressed);
556 DoMethod(save_button, MUIM_Notify, MUIA_Pressed, FALSE, (IPTR)app, 3,
557 MUIM_CallHook, (IPTR)&hook_standard, (IPTR)main_save_pressed);
558 DoMethod(use_button, MUIM_Notify, MUIA_Pressed, FALSE, (IPTR)app, 3,
559 MUIM_CallHook, (IPTR)&hook_standard, (IPTR)main_use_pressed);
560 DoMethod(test_button, MUIM_Notify, MUIA_Pressed, FALSE, (IPTR)app, 6,
561 MUIM_Application_PushMethod, (IPTR)app, 3, MUIM_CallHook,
562 (IPTR)&hook_standard, (IPTR)main_test_pressed);
563 DoMethod(quit_menuitem, MUIM_Notify, MUIA_Menuitem_Trigger,
564 MUIV_EveryTime, (IPTR)app, 3, MUIM_CallHook,
565 (IPTR)&hook_standard, (IPTR)main_cancel_pressed);
566 DoMethod(open_menuitem, MUIM_Notify, MUIA_Menuitem_Trigger,
567 MUIV_EveryTime, (IPTR)app, 3, MUIM_CallHook,
568 (IPTR)&hook_standard, (IPTR)main_open_menu);
569 DoMethod(saveas_menuitem, MUIM_Notify, MUIA_Menuitem_Trigger,
570 MUIV_EveryTime, (IPTR)app, 3, MUIM_CallHook,
571 (IPTR)&hook_standard, (IPTR)main_saveas_menu);
572 DoMethod(aboutzune_menuitem, MUIM_Notify, MUIA_Menuitem_Trigger,
573 MUIV_EveryTime, (IPTR)app, 2, MUIM_Application_AboutMUI,
574 (IPTR)main_wnd);
576 for (i = 0; main_page_entries[i].name != NULL; i++)
578 struct page_entry *p = &main_page_entries[i];
580 if (!p->cl) p->cl = create_class(p->desc);
582 if (!(p->cl && (p->group = NewObject(p->cl->mcc_Class, NULL, TAG_DONE))))
584 deinit_gui();
585 return 0;
588 DoMethod(main_page_list, MUIM_List_InsertSingle, (IPTR)p,
589 MUIV_List_Insert_Bottom);
592 DoMethod(main_page_list, MUIM_Notify, MUIA_List_Active, MUIV_EveryTime,
593 (IPTR)app, 3, MUIM_CallHook, (IPTR)&hook_standard,
594 (IPTR)main_page_active);
596 /* Activate first entry */
597 set(main_page_list,MUIA_List_Active,0);
599 return 1;
601 return 0;
604 /****************************************************************
605 Load the given prefs
606 *****************************************************************/
607 void load_prefs(CONST_STRPTR name)
609 Object *configdata;
611 configdata = MUI_NewObject(MUIC_Configdata,
612 MUIA_Configdata_ApplicationBase, (IPTR)name,
613 TAG_DONE);
614 if (configdata != NULL)
616 int i;
618 /* D(bug("zune::load_prefs: created configdata %p\n", configdata)); */
619 LastSavedConfigdata = configdata;
621 /* Call MUIM_Settingsgroup_ConfigToGadgets for every group */
622 for (i=0;main_page_entries[i].name;i++)
624 struct page_entry *p = &main_page_entries[i];
625 if (p->group)
626 DoMethod(p->group, MUIM_Settingsgroup_ConfigToGadgets,
627 (IPTR)configdata);
630 /* D(bug("zune::save_prefs: disposed configdata %p\n", configdata)); */
634 /* write prefs to env: */
635 void test_prefs(void)
637 Object *cfg;
639 save_prefs(appname, FALSE);
640 /* load_prefs(); */
641 cfg = MUI_NewObject(MUIC_Configdata, MUIA_Configdata_Application, (IPTR)app, TAG_DONE);
642 set(app, MUIA_Application_Configdata, (IPTR)cfg);
645 void restore_prefs(CONST_STRPTR name)
647 char buf[255];
649 snprintf(buf, 255, "ENV:zune/%s.prefs", name);
650 DoMethod(LastSavedConfigdata, MUIM_Configdata_Save, (IPTR)buf);
654 /****************************************************************
655 open given prefs file from menue
656 *****************************************************************/
658 void main_open_menu(void)
660 static char dirpart[500]="ENVARC:Zune",filepart[500],filename[1000];
662 if (aslfilerequest ("Load a Zune Prefs File", (char *)&dirpart, (char *)&filepart, (char *)&filename, prefstags));
664 Object *configdata;
666 configdata = MUI_NewObject(MUIC_Configdata,
667 MUIA_Configdata_ApplicationBase,appname,
668 TAG_DONE);
670 if (configdata != NULL)
672 int i;
674 /* D(bug("zune::load_prefs: created configdata %p\n", configdata)); */
675 //LastSavedConfigdata = configdata;
676 DoMethod(configdata, MUIM_Configdata_Load,filename);
678 /* Call MUIM_Settingsgroup_ConfigToGadgets for every group */
679 for (i=0;main_page_entries[i].name;i++)
681 struct page_entry *p = &main_page_entries[i];
683 if (p->group) DoMethod(p->group, MUIM_Settingsgroup_ConfigToGadgets, (IPTR)configdata);
686 /* activate prefs in test mode */
687 test_prefs();
689 /* D(bug("zune::save_prefs: disposed configdata %p\n", configdata)); */
695 /****************************************************************
696 Saves the done prefs
697 *****************************************************************/
698 void save_prefs(CONST_STRPTR name, BOOL envarc)
700 Object *configdata;
702 configdata = MUI_NewObject(MUIC_Configdata,
703 //MUIA_Configdata_ApplicationBase, name,
704 MUIA_Configdata_Application,appaddr,
705 TAG_DONE);
706 if (configdata != NULL)
708 int i;
709 char buf[255];
711 /* D(bug("zune::save_prefs: created configdata %p\n", configdata)); */
713 /* Call MUIM_Settingsgroup_GadgetsToConfig for every group */
714 for (i=0;main_page_entries[i].name;i++)
716 struct page_entry *p = &main_page_entries[i];
717 if (p->group)
718 DoMethod(p->group, MUIM_Settingsgroup_GadgetsToConfig,
719 (IPTR)configdata);
722 if (envarc)
724 snprintf(buf, 255, "ENVARC:zune/%s.prefs", name);
725 DoMethod(configdata, MUIM_Configdata_Save, (IPTR)buf);
727 snprintf(buf, 255, "ENV:zune/%s.prefs", name);
728 DoMethod(configdata, MUIM_Configdata_Save, (IPTR)buf);
730 MUI_DisposeObject(configdata);
731 /* D(bug("zune::save_prefs: disposed configdata %p\n", configdata)); */
736 /****************************************************************
737 SaveAS the done prefs from menue
738 *****************************************************************/
740 void main_saveas_menu(void)
742 static char dirpart[500]="ENVARC:Zune",filepart[500],filename[1000];
744 if (aslfilerequest("Save a Zune Prefs File", (char *)&dirpart, (char *)&filepart, (char *)&filename, prefstags));
746 Object *configdata;
748 configdata = MUI_NewObject(MUIC_Configdata,
749 MUIA_Configdata_ApplicationBase, "dummyfile",
750 TAG_DONE);
752 /* check for ".prefs" suffix in filename, add if not existing */
753 if ( !strstr( filename, ".prefs") ) strcat(filename, ".prefs");
755 if (configdata != NULL)
757 int i;
759 /* D(bug("zune::save_prefs: created configdata %p\n", configdata)); */
761 /* Call MUIM_Settingsgroup_GadgetsToConfig for every group */
762 for (i=0;main_page_entries[i].name;i++)
764 struct page_entry *p = &main_page_entries[i];
766 if (p->group) DoMethod(p->group, MUIM_Settingsgroup_GadgetsToConfig, (IPTR)configdata);
769 DoMethod(configdata, MUIM_Configdata_Save, filename);
771 MUI_DisposeObject(configdata);
772 /* D(bug("zune::save_prefs: disposed configdata %p\n", configdata)); */
780 /****************************************************************
781 The message loop
782 *****************************************************************/
783 void loop(void)
785 ULONG sigs = 0;
787 while((LONG) DoMethod(app, MUIM_Application_NewInput, (IPTR)&sigs)
788 != MUIV_Application_ReturnID_Quit)
790 if (sigs)
792 sigs = Wait(sigs | SIGBREAKF_CTRL_C | SIGBREAKF_CTRL_D);
793 if (sigs & SIGBREAKF_CTRL_C) break;
794 if (sigs & SIGBREAKF_CTRL_D) break;
799 /****************************************************************
800 The main entry point
801 *****************************************************************/
803 int main(void)
805 BPTR OldDir, NewDir;
806 int retval = RETURN_OK;
807 struct RDArgs *rda = NULL;
808 // APTR *proc=0;
809 IPTR args[] = { 0,0 };
810 enum { ARG_APPNAME = 0,ARG_APPADDR=1 };
812 Locale_Initialize();
814 if (Cli())
816 rda = ReadArgs("/A,/N", args, NULL);
817 appname=(STRPTR)args[ARG_APPNAME];
818 appaddr=(APTR)args[ARG_APPADDR];
819 if (appaddr)appaddr=*(appaddr);
821 else
823 appname = 0;
827 if (retval == RETURN_OK)
829 if (!appname)
830 appname = "global";
832 if (open_libs())
834 if (open_classes())
836 find_mcps();
837 NewDir = Lock("RAM:", SHARED_LOCK);
838 if (NewDir)
839 OldDir = CurrentDir(NewDir);
840 if (init_gui())
842 load_prefs((STRPTR)args[ARG_APPNAME]);
843 set(main_wnd, MUIA_Window_Open, TRUE);
844 if (XGET(main_wnd,MUIA_Window_Open))
846 loop();
848 if (LastSavedConfigdata)
849 MUI_DisposeObject(LastSavedConfigdata);
850 deinit_gui();
852 if (NewDir) {
853 CurrentDir(OldDir);
854 UnLock(NewDir);
856 close_classes();
858 close_libs();
862 if (rda) FreeArgs(rda);
864 Locale_Deinitialize();
865 return retval;