added concrete implementations of putc(), getc(), getchar() and gets()
[tangerine.git] / workbench / prefs / Zune / zune.c
blobc698d630cb877b252ac20c2e5b47c644ee1d97f6
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 "buttonsp.h"
26 #include "groupsp.h"
27 #include "windowp.h"
28 #include "cyclesp.h"
29 #include "slidersp.h"
30 #include "scrollbarsp.h"
31 #include "listviewsp.h"
32 #include "stringsp.h"
33 #include "specialp.h"
34 #include "navigationp.h"
35 #include "framesp.h"
36 #include "zunestuff.h"
38 /************************************************************************/
40 #ifndef MAXFILENAMELENGTH
41 #define MAXFILENAMELENGTH 255
42 #endif
44 /************************************************************************/
46 #ifdef __AROS__
47 #define MCC_Query(x) AROS_LVO_CALL1(struct MUI_CustomClass *, \
48 AROS_LCA(LONG, (x), D0), \
49 struct Library *, mcclib, 5, lib)
50 #else
52 #ifdef __amigaos4__
53 #else
54 struct MUI_CustomClass *MCC_Query(ULONG d0);
55 #pragma libcall mcclib MCC_Query 01e 001
56 #endif
57 #endif
59 #define ZUNEVERSION "$VER: Zune 0.2 (22.02.2006) AROS Dev Team"
61 APTR *appaddr;
63 struct TagItem prefstags[] =
65 { ASLFR_DoPatterns, (IPTR)TRUE },
66 { ASLFR_InitialPattern, (IPTR)"#?.prefs" },
67 { TAG_DONE, 0 },
70 /************************************************************************/
72 void load_prefs(CONST_STRPTR name);
73 void save_prefs(CONST_STRPTR name, BOOL envarc);
74 void test_prefs(void);
75 void main_open_menu(void);
76 void main_saveas_menu(void);
77 void restore_prefs(CONST_STRPTR name);
79 /************************************************************************/
81 #ifdef __amigaos4__
82 struct Library *ZuneMasterBase;
83 struct ZuneMasterIFace *IZuneMaster;
84 #endif
87 /************************************************************************/
89 /****************************************************************
90 Open needed libraries
91 *****************************************************************/
92 int open_libs(void)
94 #ifdef __amigaos4__
95 if (!(ZuneMasterBase = OpenLibrary("zunemaster.library",0)))
97 printf("Unable to open zunemaster.library\n");
98 return 0;
101 if (!(IZuneMaster = (struct ZuneMasterIFace*)GetInterface(ZuneMasterBase,"main",1,NULL)))
103 printf("Unable to get main interface of zunemaster.library\n");
104 CloseLibrary(ZuneMasterBase); ZuneMasterBase = NULL;
105 return 0;
107 #endif
108 return 1;
111 /****************************************************************
112 Close opened libraries
113 *****************************************************************/
114 void close_libs(void)
116 #ifdef __amigaos4__
117 DropInterface((struct Interface*)IZuneMaster);
118 CloseLibrary(ZuneMasterBase);
119 #endif
122 struct Hook hook_standard;
124 static Object *app;
125 static Object *open_menuitem;
126 static Object *append_menuitem;
127 static Object *saveas_menuitem;
128 static Object *aboutzune_menuitem;
129 static Object *quit_menuitem;
130 static Object *LastSavedConfigdata = NULL;
131 static STRPTR appname = NULL;
133 static Object *main_wnd;
134 static Object *main_page_list;
135 static Object *main_page_group; /* contains the selelected group */
136 static Object *main_page_group_displayed; /* The current displayed group */
137 static Object *main_page_space; /* a space object */
139 void close_classes(void)
143 int open_classes(void)
145 if (1)
147 return 1;
149 else
151 close_classes();
152 return 0;
157 struct page_entry
159 char *name;
160 struct MUI_CustomClass *cl; /* The class pointer, maybe NULL */
161 Object *group; /* The group which should be is displayed, maybe NULL */
162 const struct __MUIBuiltinClass *desc;
163 struct Library *mcp_library;
164 UBYTE mcp_namebuffer[MAXFILENAMELENGTH + 1];
167 #define MAX_PAGE_ENTRIES 100
169 /* the name field is set in init_gui() */
170 struct page_entry main_page_entries[MAX_PAGE_ENTRIES + 1] =
172 /* {"Info",NULL,NULL,NULL}, */
173 /* {"System",NULL,NULL,NULL}, */
174 { "", NULL, NULL, &_MUIP_Windows_desc },
175 { "", NULL, NULL, &_MUIP_Groups_desc },
176 { "", NULL, NULL, &_MUIP_Buttons_desc },
177 { "", NULL, NULL, &_MUIP_Cycles_desc },
178 { "", NULL, NULL, &_MUIP_Sliders_desc },
179 { "", NULL, NULL, &_MUIP_Scrollbars_desc },
180 { "", NULL, NULL, &_MUIP_Listviews_desc },
181 { "", NULL, NULL, &_MUIP_Strings_desc },
182 { "", NULL, NULL, &_MUIP_Navigation_desc },
183 { "", NULL, NULL, &_MUIP_Special_desc },
184 { "", NULL, NULL, &_MUIP_Frames_desc },
185 { NULL, NULL, NULL, NULL },
188 struct MUI_CustomClass *create_class(const struct __MUIBuiltinClass *desc)
190 return MUI_CreateCustomClass(NULL,MUIC_Settingsgroup,NULL,desc->datasize,desc->dispatcher);
193 /****************************************************************
194 Our standard hook function, for easy call backs
195 *****************************************************************/
196 static void hook_func_standard(struct Hook *h, void *dummy, ULONG * funcptr)
198 void (*func) (ULONG *) = (void (*)(ULONG *)) (*funcptr);
199 if (func) func(funcptr + 1);
202 /****************************************************************
203 The display function for the page listview
204 *****************************************************************/
205 static void main_page_list_display(struct Hook *h, char **strings, struct page_entry *entry)
207 if (entry)
209 strings[0] = entry->name;
214 /****************************************************************
215 A new entry has been selected
216 *****************************************************************/
217 void main_page_active(void)
219 int new_active = XGET(main_page_list,MUIA_List_Active);
220 Object *new_group;
222 if (new_active == -1)
223 new_group = main_page_space;
224 else
226 new_group = main_page_entries[new_active].group;
227 if (!new_group)
228 new_group = main_page_space;
231 if (new_group == main_page_group_displayed)
232 return;
234 DoMethod(main_page_group, MUIM_Group_InitChange);
235 DoMethod(main_page_group, OM_REMMEMBER, (IPTR)main_page_group_displayed);
236 DoMethod(main_page_group, OM_ADDMEMBER, (IPTR)new_group);
237 DoMethod(main_page_group, MUIM_Group_ExitChange);
238 main_page_group_displayed = new_group;
241 /****************************************************************
242 Save pressed
243 *****************************************************************/
244 void main_save_pressed(void)
246 save_prefs(appname, TRUE);
247 DoMethod(app, MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit);
250 /****************************************************************
251 Use pressed
252 *****************************************************************/
253 void main_use_pressed(void)
255 save_prefs(appname, FALSE);
256 DoMethod(app, MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit);
259 /****************************************************************
260 Test pressed
261 *****************************************************************/
262 void main_test_pressed(void)
264 test_prefs();
267 /****************************************************************
268 Cancel pressed
269 *****************************************************************/
270 void main_cancel_pressed(void)
272 restore_prefs(appname);
273 DoMethod(app, MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit);
276 /****************************************************************
277 Look for MCPs
279 TODO: Write for AmigaOS4
280 *****************************************************************/
281 void find_mcps(void)
283 #ifndef __amigaos4__
284 static CONST_STRPTR const searchpaths[] =
286 "Zune/#?.(mcp|mcc)",
287 "Classes/Zune/#?.(mcp|mcc)",
288 "MUI/#?.(mcp|mcc)",
289 NULL,
291 CONST_STRPTR const *pathptr;
292 struct DevProc *dp = NULL;
293 struct page_entry *pe;
294 WORD num_page_entries = 0;
295 BPTR olddir;
297 for(pe = main_page_entries; pe->name; pe++)
299 num_page_entries++;
302 olddir = CurrentDir(NULL);
304 while((dp = GetDeviceProc("LIBS:", dp)))
306 CurrentDir(dp->dvp_Lock);
308 for(pathptr = searchpaths; *pathptr; pathptr++)
310 struct AnchorPath *ap;
311 LONG match;
313 ap = (struct AnchorPath *)AllocVec(sizeof(struct AnchorPath) + 256, MEMF_CLEAR);
314 if (ap)
316 ap->ap_Strlen = 256;
318 for(match = MatchFirst((STRPTR)*pathptr, ap);
319 match == 0;
320 match = MatchNext(ap))
322 struct Library *mcclib;
324 if (num_page_entries < MAX_PAGE_ENTRIES)
326 if ((mcclib = OpenLibrary(ap->ap_Buf, 0)))
328 struct MUI_CustomClass *mcp;
330 if ((mcp = MCC_Query(1)))
332 char *sp;
334 pe->cl = mcp;
335 pe->mcp_library = mcclib;
336 mcclib = NULL;
338 pe->mcp_namebuffer[0] = 27;
339 pe->mcp_namebuffer[1] = '3';
340 strncpy(pe->mcp_namebuffer + 2, mcp->mcc_Class->cl_ID, sizeof(pe->mcp_namebuffer) - 3);
342 if ((sp = strrchr(pe->mcp_namebuffer, '.')))
343 *sp = '\0';
345 pe->name = pe->mcp_namebuffer;
347 pe++;
348 num_page_entries++;
350 } /* if ((mcp = MCC_Query(1))) */
352 if (mcclib) CloseLibrary(mcclib);
354 } /* if ((mcclib = OpenLibrary(ap->ap_Buf, 0))) */
356 } /* if (num_page_entries < MAX_PAGE_ENTRIES) */
358 } /* for(match = ... */
360 MatchEnd(ap);
362 FreeVec(ap);
364 } /* if (ap) */
366 } /* for(pathptr = searchpaths; *pathptr; pathptr++) */
368 if (!dp->dvp_Flags & DVPF_ASSIGN) break;
370 } /* while((dp = GetDeviceProc("LIBS:", dp))) */
372 FreeDeviceProc(dp);
374 CurrentDir(olddir);
375 #endif
378 /****************************************************************
379 Deallocates all gui resources
380 *****************************************************************/
381 void deinit_gui(void)
383 int i;
385 if (app)
386 MUI_DisposeObject(app);
388 for (i = 0; main_page_entries[i].name; i++)
390 if ((main_page_entries[i].group != NULL) &&
391 (main_page_entries[i].group != main_page_group_displayed))
393 DisposeObject(main_page_entries[i].group);
396 if (main_page_entries[i].mcp_library)
398 main_page_entries[i].cl = NULL; /* Prevent MUI_DeleteCustomClass call below */
400 if ((main_page_entries[i].group == NULL) ||
401 (main_page_entries[i].group != main_page_group_displayed))
403 /* Only close library if main_page_group_displayed is not this page,
404 because in that case the object got automatically killed through
405 MUI_DisposeObject(app) which also does the CloseLibrary()!! */
407 CloseLibrary(main_page_entries[i].mcp_library);
408 main_page_entries[i].mcp_library = NULL;
412 main_page_entries[i].group = NULL;
414 if (main_page_entries[i].cl != NULL)
416 MUI_DeleteCustomClass(main_page_entries[i].cl);
417 main_page_entries[i].cl = NULL;
421 if (main_page_group_displayed != main_page_space)
422 MUI_DisposeObject(main_page_space);
425 /****************************************************************
426 Allocate resources for gui
427 *****************************************************************/
428 int init_gui(void)
430 Object *save_button;
431 Object *use_button;
432 Object *test_button;
433 Object *cancel_button;
434 STRPTR wintitle;
435 char titlebuf[255];
437 main_page_entries[ 0].name = (char *)_(MSG_DSC_WINDOWS);
438 main_page_entries[ 1].name = (char *)_(MSG_DSC_GROUPS);
439 main_page_entries[ 2].name = (char *)_(MSG_DSC_BUTTONS);
440 main_page_entries[ 3].name = (char *)_(MSG_DSC_CYCLES);
441 main_page_entries[ 4].name = (char *)_(MSG_DSC_SLIDERS);
442 main_page_entries[ 5].name = (char *)_(MSG_DSC_SCROLLBARS);
443 main_page_entries[ 6].name = (char *)_(MSG_DSC_LISTVIEWS);
444 main_page_entries[ 7].name = (char *)_(MSG_DSC_STRINGS);
445 main_page_entries[ 8].name = (char *)_(MSG_DSC_NAVIGATION);
446 main_page_entries[ 9].name = (char *)_(MSG_DSC_SPECIAL);
447 main_page_entries[10].name = (char *)_(MSG_DSC_FRAMES);
449 static struct Hook page_display_hook;
451 #ifdef __amigaos4__
452 hook_standard.h_Entry = (HOOKFUNC)hook_func_standard;
453 page_display_hook.h_Entry = (HOOKFUNC)main_page_list_display;
454 #else
455 hook_standard.h_Entry = HookEntry;
456 hook_standard.h_SubEntry = (APTR)hook_func_standard;
457 page_display_hook.h_Entry = HookEntry;
458 page_display_hook.h_SubEntry = (APTR)main_page_list_display;
459 #endif
461 if (!strcmp(appname, "global"))
462 wintitle = (STRPTR) _(MSG_WINTITLE1);
463 else
465 snprintf(titlebuf, 255, _(MSG_WINTITLE2), appname);
466 wintitle = titlebuf;
469 app = ApplicationObject,
470 MUIA_Application_Title, (IPTR) "Zune",
471 MUIA_Application_Version, (IPTR) ZUNEVERSION,
472 MUIA_Application_Copyright, (IPTR) " 2006, The AROS Development Team",
473 MUIA_Application_Description, wintitle,
474 MUIA_Application_Base, "ZUNEPREF",
475 MUIA_Application_Menustrip, MenuitemObject,
476 MUIA_Family_Child, MenuitemObject,
477 MUIA_Menuitem_Title, _(MSG_MEN_PROJECT),
478 MUIA_Family_Child, open_menuitem = MenuitemObject,
479 MUIA_Menuitem_Title, _(MSG_MEN_OPEN), MUIA_Menuitem_Shortcut, _(MSG_MEN_OPEN_SC),
480 End,
481 MUIA_Family_Child, append_menuitem = MenuitemObject, MUIA_Menuitem_Title, _(MSG_MEN_APPEND), End,
482 MUIA_Family_Child, saveas_menuitem = MenuitemObject,
483 MUIA_Menuitem_Title, _(MSG_MEN_SAVEAS), MUIA_Menuitem_Shortcut, _(MSG_MEN_SAVEAS_SC),
484 End,
485 MUIA_Family_Child, MenuitemObject, MUIA_Menuitem_Title, ~0, End,
486 MUIA_Family_Child, aboutzune_menuitem = MenuitemObject,
487 MUIA_Menuitem_Title, _(MSG_MEN_ABOUT), MUIA_Menuitem_Shortcut, _(MSG_MEN_ABOUT_SC),
488 End,
489 MUIA_Family_Child, MenuitemObject, MUIA_Menuitem_Title, ~0, End,
490 MUIA_Family_Child, quit_menuitem = MenuitemObject,
491 MUIA_Menuitem_Title, _(MSG_MEN_QUIT), MUIA_Menuitem_Shortcut, _(MSG_MEN_QUIT_SC),
492 End,
493 End,
494 End,
495 SubWindow, main_wnd = WindowObject,
496 MUIA_Window_Title, (IPTR)wintitle,
497 MUIA_Window_Activate, TRUE,
498 MUIA_Window_CloseGadget, FALSE,
499 MUIA_Window_ID, MAKE_ID('Z','W','I','N'),
501 WindowContents, VGroup,
502 MUIA_Group_VertSpacing, 10,
503 Child, HGroup,
504 Child, VGroup,
505 Child, ListviewObject,
506 MUIA_CycleChain, 1,
507 MUIA_Listview_List, main_page_list = ListObject,
508 InputListFrame,
509 MUIA_List_AdjustWidth, TRUE,
510 MUIA_List_DisplayHook, &page_display_hook,
511 End,
512 End,
513 Child, HGroup,
514 Child, MUI_NewObject(MUIC_Popframe,
515 MUIA_FixHeight, 20,
516 MUIA_Window_Title, (IPTR) _(MSG_FRAME_CLIPBOARD),
517 TAG_DONE),
518 Child, MUI_NewObject(MUIC_Popimage,
519 MUIA_FixHeight, 20,
520 MUIA_Imageadjust_Type, MUIV_Imageadjust_Type_All,
521 MUIA_Window_Title, (IPTR) _(MSG_IMAGE_CLIPBOARD),
522 TAG_DONE),
523 End, /* HGroup */
524 End,
525 Child, VGroup,
526 TextFrame,
527 InnerSpacing(6,6),
528 MUIA_Background, MUII_PageBack,
529 Child, main_page_group = VGroup,
530 Child, main_page_group_displayed = main_page_space = HVSpace,
531 End,
532 End,
533 End,
534 Child, HGroup,
535 Child, test_button = MakeButton(_(MSG_GAD_TEST)),
536 Child, HVSpace,
537 Child, save_button = MakeButton(_(MSG_GAD_SAVE)),
538 Child, use_button = MakeButton(_(MSG_GAD_USE)),
539 Child, cancel_button = MakeButton(_(MSG_GAD_CANCEL)),
540 End,
541 End,
542 End,
543 End;
545 if (app)
547 int i;
549 DoMethod(main_wnd, MUIM_Notify, MUIA_Window_CloseRequest, TRUE,
550 (IPTR)app, 3, MUIM_CallHook, (IPTR)&hook_standard,
551 (IPTR)main_cancel_pressed);
552 DoMethod(cancel_button, MUIM_Notify, MUIA_Pressed, FALSE, (IPTR)app, 3,
553 MUIM_CallHook, (IPTR)&hook_standard, (IPTR)main_cancel_pressed);
554 DoMethod(save_button, MUIM_Notify, MUIA_Pressed, FALSE, (IPTR)app, 3,
555 MUIM_CallHook, (IPTR)&hook_standard, (IPTR)main_save_pressed);
556 DoMethod(use_button, MUIM_Notify, MUIA_Pressed, FALSE, (IPTR)app, 3,
557 MUIM_CallHook, (IPTR)&hook_standard, (IPTR)main_use_pressed);
558 DoMethod(test_button, MUIM_Notify, MUIA_Pressed, FALSE, (IPTR)app, 6,
559 MUIM_Application_PushMethod, (IPTR)app, 3, MUIM_CallHook,
560 (IPTR)&hook_standard, (IPTR)main_test_pressed);
561 DoMethod(quit_menuitem, MUIM_Notify, MUIA_Menuitem_Trigger,
562 MUIV_EveryTime, (IPTR)app, 3, MUIM_CallHook,
563 (IPTR)&hook_standard, (IPTR)main_cancel_pressed);
564 DoMethod(open_menuitem, MUIM_Notify, MUIA_Menuitem_Trigger,
565 MUIV_EveryTime, (IPTR)app, 3, MUIM_CallHook,
566 (IPTR)&hook_standard, (IPTR)main_open_menu);
567 DoMethod(saveas_menuitem, MUIM_Notify, MUIA_Menuitem_Trigger,
568 MUIV_EveryTime, (IPTR)app, 3, MUIM_CallHook,
569 (IPTR)&hook_standard, (IPTR)main_saveas_menu);
570 DoMethod(aboutzune_menuitem, MUIM_Notify, MUIA_Menuitem_Trigger,
571 MUIV_EveryTime, (IPTR)app, 2, MUIM_Application_AboutMUI,
572 (IPTR)main_wnd);
574 for (i = 0; main_page_entries[i].name != NULL; i++)
576 struct page_entry *p = &main_page_entries[i];
578 if (!p->cl) p->cl = create_class(p->desc);
580 if (!(p->cl && (p->group = NewObject(p->cl->mcc_Class, NULL, TAG_DONE))))
582 deinit_gui();
583 return 0;
586 DoMethod(main_page_list, MUIM_List_InsertSingle, (IPTR)p,
587 MUIV_List_Insert_Bottom);
590 DoMethod(main_page_list, MUIM_Notify, MUIA_List_Active, MUIV_EveryTime,
591 (IPTR)app, 3, MUIM_CallHook, (IPTR)&hook_standard,
592 (IPTR)main_page_active);
594 /* Activate first entry */
595 set(main_page_list,MUIA_List_Active,0);
597 return 1;
599 return 0;
602 /****************************************************************
603 Load the given prefs
604 *****************************************************************/
605 void load_prefs(CONST_STRPTR name)
607 Object *configdata;
609 configdata = MUI_NewObject(MUIC_Configdata,
610 MUIA_Configdata_ApplicationBase, (IPTR)name,
611 TAG_DONE);
612 if (configdata != NULL)
614 int i;
616 /* D(bug("zune::load_prefs: created configdata %p\n", configdata)); */
617 LastSavedConfigdata = configdata;
619 /* Call MUIM_Settingsgroup_ConfigToGadgets for every group */
620 for (i=0;main_page_entries[i].name;i++)
622 struct page_entry *p = &main_page_entries[i];
623 if (p->group)
624 DoMethod(p->group, MUIM_Settingsgroup_ConfigToGadgets,
625 (IPTR)configdata);
628 /* D(bug("zune::save_prefs: disposed configdata %p\n", configdata)); */
632 /* write prefs to env: */
633 void test_prefs(void)
635 Object *cfg;
637 save_prefs(appname, FALSE);
638 /* load_prefs(); */
639 cfg = MUI_NewObject(MUIC_Configdata, MUIA_Configdata_Application, (IPTR)app, TAG_DONE);
640 set(app, MUIA_Application_Configdata, (IPTR)cfg);
643 void restore_prefs(CONST_STRPTR name)
645 char buf[255];
647 snprintf(buf, 255, "ENV:zune/%s.prefs", name);
648 DoMethod(LastSavedConfigdata, MUIM_Configdata_Save, (IPTR)buf);
652 /****************************************************************
653 open given prefs file from menue
654 *****************************************************************/
656 void main_open_menu(void)
658 static char dirpart[500]="ENVARC:Zune",filepart[500],filename[1000];
660 if (aslfilerequest ("Load a Zune Prefs File", (char *)&dirpart, (char *)&filepart, (char *)&filename, prefstags));
662 Object *configdata;
664 configdata = MUI_NewObject(MUIC_Configdata,
665 MUIA_Configdata_ApplicationBase,appname,
666 TAG_DONE);
668 if (configdata != NULL)
670 int i;
672 /* D(bug("zune::load_prefs: created configdata %p\n", configdata)); */
673 //LastSavedConfigdata = configdata;
674 DoMethod(configdata, MUIM_Configdata_Load,filename);
676 /* Call MUIM_Settingsgroup_ConfigToGadgets for every group */
677 for (i=0;main_page_entries[i].name;i++)
679 struct page_entry *p = &main_page_entries[i];
681 if (p->group) DoMethod(p->group, MUIM_Settingsgroup_ConfigToGadgets, (IPTR)configdata);
684 /* activate prefs in test mode */
685 test_prefs();
687 /* D(bug("zune::save_prefs: disposed configdata %p\n", configdata)); */
693 /****************************************************************
694 Saves the done prefs
695 *****************************************************************/
696 void save_prefs(CONST_STRPTR name, BOOL envarc)
698 Object *configdata;
700 configdata = MUI_NewObject(MUIC_Configdata,
701 //MUIA_Configdata_ApplicationBase, name,
702 MUIA_Configdata_Application,appaddr,
703 TAG_DONE);
704 if (configdata != NULL)
706 int i;
707 char buf[255];
709 /* D(bug("zune::save_prefs: created configdata %p\n", configdata)); */
711 /* Call MUIM_Settingsgroup_GadgetsToConfig for every group */
712 for (i=0;main_page_entries[i].name;i++)
714 struct page_entry *p = &main_page_entries[i];
715 if (p->group)
716 DoMethod(p->group, MUIM_Settingsgroup_GadgetsToConfig,
717 (IPTR)configdata);
720 if (envarc)
722 snprintf(buf, 255, "ENVARC:zune/%s.prefs", name);
723 DoMethod(configdata, MUIM_Configdata_Save, (IPTR)buf);
725 snprintf(buf, 255, "ENV:zune/%s.prefs", name);
726 DoMethod(configdata, MUIM_Configdata_Save, (IPTR)buf);
728 MUI_DisposeObject(configdata);
729 /* D(bug("zune::save_prefs: disposed configdata %p\n", configdata)); */
734 /****************************************************************
735 SaveAS the done prefs from menue
736 *****************************************************************/
738 void main_saveas_menu(void)
740 static char dirpart[500]="ENVARC:Zune",filepart[500],filename[1000];
742 if (aslfilerequest("Save a Zune Prefs File", (char *)&dirpart, (char *)&filepart, (char *)&filename, prefstags));
744 Object *configdata;
746 configdata = MUI_NewObject(MUIC_Configdata,
747 MUIA_Configdata_ApplicationBase, "dummyfile",
748 TAG_DONE);
750 /* check for ".prefs" suffix in filename, add if not existing */
751 if ( !strstr( filename, ".prefs") ) strcat(filename, ".prefs");
753 if (configdata != NULL)
755 int i;
757 /* D(bug("zune::save_prefs: created configdata %p\n", configdata)); */
759 /* Call MUIM_Settingsgroup_GadgetsToConfig for every group */
760 for (i=0;main_page_entries[i].name;i++)
762 struct page_entry *p = &main_page_entries[i];
764 if (p->group) DoMethod(p->group, MUIM_Settingsgroup_GadgetsToConfig, (IPTR)configdata);
767 DoMethod(configdata, MUIM_Configdata_Save, filename);
769 MUI_DisposeObject(configdata);
770 /* D(bug("zune::save_prefs: disposed configdata %p\n", configdata)); */
778 /****************************************************************
779 The message loop
780 *****************************************************************/
781 void loop(void)
783 ULONG sigs = 0;
785 while((LONG) DoMethod(app, MUIM_Application_NewInput, (IPTR)&sigs)
786 != MUIV_Application_ReturnID_Quit)
788 if (sigs)
790 sigs = Wait(sigs | SIGBREAKF_CTRL_C | SIGBREAKF_CTRL_D);
791 if (sigs & SIGBREAKF_CTRL_C) break;
792 if (sigs & SIGBREAKF_CTRL_D) break;
797 /****************************************************************
798 The main entry point
799 *****************************************************************/
801 int main(void)
803 BPTR OldDir, NewDir;
804 int retval = RETURN_OK;
805 struct RDArgs *rda = NULL;
806 // APTR *proc=0;
807 IPTR args[] = { 0,0 };
808 enum { ARG_APPNAME = 0,ARG_APPADDR=1 };
810 Locale_Initialize();
812 if (Cli())
814 rda = ReadArgs("/A,/N", args, NULL);
815 appname=(STRPTR)args[ARG_APPNAME];
816 appaddr=(APTR)args[ARG_APPADDR];
817 if (appaddr)appaddr=*(appaddr);
819 else
821 appname = 0;
825 if (retval == RETURN_OK)
827 if (!appname)
828 appname = "global";
830 if (open_libs())
832 if (open_classes())
834 find_mcps();
835 NewDir = Lock("RAM:", SHARED_LOCK);
836 if (NewDir)
837 OldDir = CurrentDir(NewDir);
838 if (init_gui())
840 load_prefs((STRPTR)args[ARG_APPNAME]);
841 set(main_wnd, MUIA_Window_Open, TRUE);
842 if (XGET(main_wnd,MUIA_Window_Open))
844 loop();
846 if (LastSavedConfigdata)
847 MUI_DisposeObject(LastSavedConfigdata);
848 deinit_gui();
850 if (NewDir) {
851 CurrentDir(OldDir);
852 UnLock(NewDir);
854 close_classes();
856 close_libs();
860 if (rda) FreeArgs(rda);
862 Locale_Deinitialize();
863 return retval;