Check for SYS/GL during library init. Reason is that
[AROS.git] / workbench / system / Wanderer / wandererprefs.c
blob05298cf5fc90ee7efacfbcddb6cddd8442702e76
1 /*
2 Copyright 2004-2013, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #define ZCC_QUIET
8 #include "portable_macros.h"
9 #ifdef __AROS__
10 #define DEBUG 0
11 #include <aros/debug.h>
13 #define MUIMASTER_YES_INLINE_STDARG
14 #endif
16 #define IFF_CHUNK_BUFFER_SIZE 1024
18 #include <exec/types.h>
19 #include <libraries/mui.h>
21 #ifdef __AROS__
22 #include <zune/customclasses.h>
23 #else
24 #include <zune_AROS/customclasses.h>
25 #endif
27 #include <proto/workbench.h>
29 #include <proto/utility.h>
31 #include <proto/dos.h>
33 #ifdef __AROS__
34 #include <proto/alib.h>
35 #endif
37 #include <proto/iffparse.h>
39 #ifdef __AROS__
40 #include <proto/aros.h>
41 #endif
43 #include <aros/arosbase.h>
44 #include <aros/inquire.h>
46 #include <string.h>
47 #include <stdio.h>
50 #if defined(__AMIGA__) && !defined(__PPC__)
51 #define NO_INLINE_STDARG
52 #endif
53 #ifndef _PROTO_INTUITION_H
54 #include <proto/intuition.h>
55 #endif
57 #include <proto/muimaster.h>
59 #include "wanderer.h"
60 #include "wandererprefs.h"
61 #include "wandererprefsfont.h"
62 #include "Classes/iconlist_attributes.h"
63 #include "iconwindow_attributes.h"
64 #include "support.h"
65 #include "locale.h"
66 #include "version.h"
68 #ifdef __AROS__
69 #include <prefs/prefhdr.h>
70 #include <prefs/wanderer.h>
71 #else
72 #include <prefs_AROS/prefhdr.h>
73 #include <prefs_AROS/wanderer.h>
74 #endif
77 #ifndef __AROS__
78 #define DEBUG 1
80 #ifdef DEBUG
81 #define D(x) if (DEBUG) x
82 #ifdef __amigaos4__
83 #define bug DebugPrintF
84 #else
85 #define bug kprintf
86 #endif
87 #else
88 #define D(...)
89 #endif
90 #endif
92 static CONST_STRPTR wandererPrefs_PrefsFile = "ENV:SYS/Wanderer/global.prefs";
93 static CONST_STRPTR wandererPrefs_FontsPrefsFile = "ENV:SYS/Font.prefs";
95 struct TagItem32 {
96 ULONG ti_Tag;
97 ULONG ti_Data;
100 /*** Instance Data **********************************************************/
101 struct WandererPrefs_DATA
103 ULONG wpd_NavigationMethod;
104 ULONG wpd_ToolbarEnabled;
105 ULONG wpd_ShowNetwork;
106 ULONG wpd_ShowUserFiles;
107 ULONG wpd_ScreenTitleString[IFF_CHUNK_BUFFER_SIZE];
109 struct List wpd_ViewSettings;
111 struct NotifyRequest wpd_PrefsNotifyRequest;
112 struct Wanderer_FSHandler wpd_PrefsFSHandler;
114 struct NotifyRequest wpd_FontPrefsNotifyRequest;
115 struct Wanderer_FSHandler wpd_FontPrefsFSHandler;
117 BOOL wpd_PROCESSING;
119 struct WandererFontPrefsData wfpd;
122 struct WandererPrefs_ViewSettingsNode
124 struct Node wpbn_Node;
125 char *wpbn_Name;
126 IPTR wpbn_Background;
127 struct TagItem32 *wpbn_Options;
128 Object *wpbn_NotifyObject;
131 /*** Macros *****************************************************************/
132 #define SETUP_INST_DATA struct WandererPrefs_DATA *data = INST_DATA(CLASS, self)
134 /*** Utility Functions ******************************************************/
135 ///SetString()
136 BOOL SetString(STRPTR *dst, STRPTR src)
138 if (src != NULL)
140 if ((*dst == NULL) || (strcmp(src, *dst) != 0))
142 STRPTR tmp =(STRPTR) StrDup(src);
144 if (tmp != NULL)
146 FreeVec(*dst);
147 *dst = tmp;
149 return TRUE;
154 return FALSE;
158 ///strtochar()
159 static unsigned char strtochar(STRPTR st)
161 return *st++;
164 /******** code from workbench/c/Info.c **************************************/
165 ///fmtlarge()
166 static void fmtlarge(UBYTE *buf, ULONG num)
168 UQUAD d;
169 UBYTE ch;
170 struct
172 ULONG val;
173 ULONG dec;
174 } array =
176 num,
180 if (num >= 1073741824)
182 //Gigabytes
183 array.val = num >> 30;
184 d = ((UQUAD)num * 10 + 536870912) / 1073741824;
185 array.dec = d % 10;
186 ch = strtochar((STRPTR)_(MSG_MEM_G));
188 else if (num >= 1048576)
190 //Megabytes
191 array.val = num >> 20;
192 d = ((UQUAD)num * 10 + 524288) / 1048576;
193 array.dec = d % 10;
194 ch = strtochar((STRPTR)_(MSG_MEM_M));
196 else if (num >= 1024)
198 //Kilobytes
199 array.val = num >> 10;
200 d = (num * 10 + 512) / 1024;
201 array.dec = d % 10;
202 ch = strtochar((STRPTR)_(MSG_MEM_K));
204 else
206 //Bytes
207 array.val = num;
208 array.dec = 0;
209 d = 0;
210 ch = strtochar((STRPTR)_(MSG_MEM_B));
213 if (!array.dec && (d > array.val * 10))
215 array.val++;
218 RawDoFmt(array.dec ? "%lu.%lu" : "%lu", (RAWARG)&array, NULL, buf);
220 while (*buf)
222 buf++;
225 *buf++ = ch;
226 *buf = '\0';
230 ///findname()
231 /* Case-insensitive FindName()
232 * code from workbench/c/Version.c
234 static
235 struct Node *findname(struct List *list, CONST_STRPTR name)
237 struct Node *node;
238 #ifdef __AROS__
239 ForeachNode(list, node)
240 #else
241 Foreach_Node(list, node);
242 #endif
244 if (!Stricmp(node->ln_Name, (STRPTR) name))
246 return node;
250 return NULL;
254 ///ProcessUserScreenTitle()
255 /*pattern matching of user screentitle...;*/
256 STRPTR ProcessUserScreenTitle(STRPTR screentitle_Template)
258 /* Work in progress :-) */
259 int screentitle_TemplateLen;
260 STATIC char title[256];
261 char temp[256], buffer[256];
262 char infostr[10];
263 int screentitle_curChar;
265 if (screentitle_Template == NULL)
267 D(bug("[Wanderer:Prefs] ProcessUserScreenTitle(),EXTERN screentitle = NULL\n"));
268 return screentitle_Template;
270 else
272 D(bug("[Wanderer:Prefs] ProcessUserScreenTitle('%s')\n", screentitle_Template));
275 screentitle_TemplateLen = strlen(screentitle_Template);
277 if (screentitle_TemplateLen > sizeof(temp)-1)
279 D(bug("[Wanderer:Prefs] ProcessUserScreenTitle: EXTERN screentitle_TemplateLen = %d\n", screentitle_TemplateLen));
280 return (STRPTR)NULL;
283 strcpy(temp, screentitle_Template);
285 for (screentitle_curChar = 0; screentitle_curChar < screentitle_TemplateLen; screentitle_curChar++)
287 if (temp[screentitle_curChar]=='%')
289 if (screentitle_TemplateLen >= 3)
291 BOOL found = FALSE;
293 if (strncmp(temp + screentitle_curChar, "%wv", 3) == 0)
295 struct Library *MyLibrary = NULL;
297 #ifdef __AROS__
298 MyLibrary = (struct Library *)findname(&SysBase->LibList, "workbench.library");
299 //workbench.library is just opened, what is the sense of this istruction?
300 #else
301 MyLibrary = WorkbenchBase;
302 #endif
304 sprintf(infostr, "%ld.%ld",(long int) MyLibrary->lib_Version,(long int) MyLibrary->lib_Revision);
305 found = TRUE;
308 if (strncmp(temp + screentitle_curChar, "%ov", 3) == 0)
310 struct Library *AROSBase = OpenLibrary(AROSLIBNAME, AROSLIBVERSION);
312 if (AROSBase!=NULL)
314 UWORD ver = 0;
315 //UWORD kickrev = 0;
317 ArosInquire
319 AI_ArosVersion, (IPTR)&ver,
320 TAG_DONE
322 sprintf(infostr, "%d", ver);
323 CloseLibrary(AROSBase);
324 found = TRUE;
328 if (strncmp(temp + screentitle_curChar, "%os", 3) == 0)
330 struct Library *AROSBase = OpenLibrary(AROSLIBNAME, AROSLIBVERSION);
332 if (AROSBase != NULL)
334 ULONG ver = 0,
335 rev = 0;
337 ArosInquire
339 AI_ArosReleaseMajor, (IPTR)&ver,
340 AI_ArosReleaseMinor, (IPTR)&rev,
341 TAG_DONE
343 sprintf(infostr, "%d.%d", (int)ver, (int)rev);
344 CloseLibrary(AROSBase);
345 found = TRUE;
349 if (strncmp(temp + screentitle_curChar, "%wb", 3) == 0)
351 struct Library *AROSBase = OpenLibrary(AROSLIBNAME, AROSLIBVERSION);
353 if (AROSBase != NULL)
355 ULONG ver = 0;
356 ULONG rev = 0;
358 ArosInquire
360 AI_ArosReleaseMajor, (IPTR)&ver,
361 AI_ArosReleaseMinor, (IPTR)&rev,
362 TAG_DONE
364 sprintf(infostr, "%d.%d", WANDERERVERS, WANDERERREV);
365 CloseLibrary(AROSBase);
366 found = TRUE;
370 if (strncmp(temp + screentitle_curChar, "%pc", 3) == 0)
372 fmtlarge(infostr, AvailMem(MEMF_CHIP));
373 found = TRUE;
376 if (strncmp(temp + screentitle_curChar, "%pf", 3) == 0)
378 fmtlarge(infostr, AvailMem(MEMF_FAST));
379 found = TRUE;
382 if (strncmp(temp + screentitle_curChar, "%pt", 3) == 0)
384 fmtlarge(infostr, AvailMem(MEMF_ANY));
385 found = TRUE;
388 if (strncmp(temp + screentitle_curChar, "%PC", 3) == 0)
390 fmtlarge(infostr, AvailMem(MEMF_CHIP|MEMF_TOTAL));
391 found = TRUE;
394 if (strncmp(temp + screentitle_curChar, "%PF", 3) == 0)
396 fmtlarge(infostr, AvailMem(MEMF_FAST|MEMF_TOTAL));
397 found = TRUE;
400 if (strncmp(temp + screentitle_curChar, "%PT", 3) == 0)
402 fmtlarge(infostr, AvailMem(MEMF_ANY|MEMF_TOTAL));
403 found = TRUE;
406 if (found)
408 temp[screentitle_curChar + 1] = 's';
409 temp[screentitle_curChar + 2] = ' ';
411 sprintf(title, temp, infostr);
413 screentitle_curChar = screentitle_curChar + strlen(infostr);
414 strncpy(buffer, title, screentitle_curChar);
415 strcpy(&buffer[screentitle_curChar], &temp[(screentitle_curChar + 3) - strlen(infostr)]);
416 strcpy(temp, buffer);
418 screentitle_TemplateLen = screentitle_TemplateLen + strlen(infostr);
420 else
422 temp[screentitle_curChar] = '?';
423 temp[screentitle_curChar + 1] = '?';
424 temp[screentitle_curChar + 2] = '?';
425 strcpy(title, temp);
428 else
430 switch (screentitle_TemplateLen)
432 case 2:
433 temp[screentitle_curChar]= '?';
434 temp[screentitle_curChar + 1]= '?';
435 break;
436 case 1:
437 temp[screentitle_curChar] = '?';
439 strcpy(title, temp);
443 strcpy(title, temp);
445 return title;
449 ///ExpandEnvName()
450 /* Expand a passed in env: string to its full location */
451 /* Wanderer doesnt free this mem at the moment but should
452 incase it is every closed */
453 static CONST_STRPTR ExpandEnvName(CONST_STRPTR env_path)
455 BOOL ok = FALSE;
456 char tmp_envbuff[1024];
457 STRPTR fullpath = NULL;
458 BPTR env_lock = (BPTR) NULL;
460 env_lock = Lock("ENV:", SHARED_LOCK);
461 if (env_lock)
463 if (NameFromLock(env_lock, tmp_envbuff, 256)) ok = TRUE;
464 UnLock(env_lock);
467 if (ok)
469 if ((fullpath = AllocVec(strlen(tmp_envbuff) + strlen(env_path) + 1 + 1 - 4, MEMF_CLEAR | MEMF_PUBLIC)) != NULL)
471 strcpy(fullpath, tmp_envbuff);
472 AddPart(fullpath, env_path + 4, 1019);
473 return fullpath;
477 //We couldnt expand it so just use as is ..
478 return env_path;
483 IPTR WandererPrefs__HandleFSUpdate(Object *prefs, struct NotifyMessage *msg)
485 DoMethod(prefs, MUIM_WandererPrefs_Reload);
486 return 0;
489 IPTR WandererPrefs__HandleFontPrefsFSUpdate(Object *prefs, struct NotifyMessage *msg)
491 DoMethod(prefs, MUIM_WandererPrefs_ReloadFontPrefs);
492 return 0;
495 /*** Methods ****************************************************************/
497 ///OM_NEW()
498 Object *WandererPrefs__OM_NEW(Class *CLASS, Object *self, struct opSet *message)
500 IPTR _wandererPrefs__FSNotifyPort = 0;
501 D(bug("[Wanderer:Prefs]:New()\n"));
503 _wandererPrefs__FSNotifyPort = GetTagData(MUIA_Wanderer_FileSysNotifyPort, (IPTR) NULL, message->ops_AttrList);
505 self = (Object *) DoSuperMethodA(CLASS, self, (Msg) message);
507 if (self != NULL)
509 SETUP_INST_DATA;
511 /* Setup notification on prefs file --------------------------------*/
512 if (_wandererPrefs__FSNotifyPort != 0)
514 data->wpd_PrefsFSHandler.target = self;
515 data->wpd_PrefsFSHandler.fshn_Node.ln_Name = (STRPTR)ExpandEnvName(wandererPrefs_PrefsFile);
516 data->wpd_PrefsFSHandler.HandleFSUpdate = WandererPrefs__HandleFSUpdate;
517 data->wpd_PrefsNotifyRequest.nr_Name = data->wpd_PrefsFSHandler.fshn_Node.ln_Name;
518 data->wpd_PrefsNotifyRequest.nr_Flags = NRF_SEND_MESSAGE;
519 data->wpd_PrefsNotifyRequest.nr_stuff.nr_Msg.nr_Port = (struct MsgPort *)_wandererPrefs__FSNotifyPort;
520 data->wpd_PrefsNotifyRequest.nr_UserData = (IPTR)&data->wpd_PrefsFSHandler;
522 if (StartNotify(&data->wpd_PrefsNotifyRequest))
524 D(bug("[Wanderer:Prefs] Wanderer__OM_NEW: Prefs-notification setup on '%s'\n", data->wpd_PrefsNotifyRequest.nr_Name));
526 else
528 D(bug("[Wanderer:Prefs] Wanderer__OM_NEW: FAILED to setup Prefs-notification!\n"));
529 data->wpd_PrefsFSHandler.fshn_Node.ln_Name = NULL;
530 data->wpd_PrefsNotifyRequest.nr_Name = NULL;
534 /* Setup notification on font prefs file --------------------------------*/
535 if (_wandererPrefs__FSNotifyPort != 0)
537 data->wpd_FontPrefsFSHandler.target = self;
538 data->wpd_FontPrefsFSHandler.fshn_Node.ln_Name = (STRPTR)ExpandEnvName(wandererPrefs_FontsPrefsFile);
539 data->wpd_FontPrefsFSHandler.HandleFSUpdate = WandererPrefs__HandleFontPrefsFSUpdate;
540 data->wpd_FontPrefsNotifyRequest.nr_Name = data->wpd_FontPrefsFSHandler.fshn_Node.ln_Name;
541 data->wpd_FontPrefsNotifyRequest.nr_Flags = NRF_SEND_MESSAGE;
542 data->wpd_FontPrefsNotifyRequest.nr_stuff.nr_Msg.nr_Port = (struct MsgPort *)_wandererPrefs__FSNotifyPort;
543 data->wpd_FontPrefsNotifyRequest.nr_UserData = (IPTR)&data->wpd_FontPrefsFSHandler;
546 if (StartNotify(&data->wpd_FontPrefsNotifyRequest))
548 D(bug("[Wanderer:Prefs] Wanderer__OM_NEW: Prefs-notification setup on '%s'\n", data->wpd_FontPrefsNotifyRequest.nr_Name));
550 else
552 D(bug("[Wanderer:Prefs] Wanderer__OM_NEW: FAILED to setup Prefs-notification!\n"));
553 data->wpd_FontPrefsFSHandler.fshn_Node.ln_Name = NULL;
554 data->wpd_FontPrefsNotifyRequest.nr_Name = NULL;
558 D(bug("[Wanderer:Prefs]:New - reloading\n"));
560 NewList(&data->wpd_ViewSettings);
562 data->wpd_PROCESSING = FALSE;
564 DoMethod(self, MUIM_WandererPrefs_Reload);
565 DoMethod(self, MUIM_WandererPrefs_ReloadFontPrefs);
568 D(bug("[Wanderer:Prefs] obj = %ld\n", self));
569 return self;
573 ///OM_DISPOSE()
574 IPTR WandererPrefs__OM_DISPOSE(Class *CLASS, Object *self, Msg message)
576 SETUP_INST_DATA;
577 EndNotify(&data->wpd_PrefsNotifyRequest);
578 EndNotify(&data->wpd_FontPrefsNotifyRequest);
579 return DoSuperMethodA(CLASS, self, (Msg)message);
583 ///OM_SET()
584 IPTR WandererPrefs__OM_SET(Class *CLASS, Object *self, struct opSet *message)
586 SETUP_INST_DATA;
587 struct TagItem *tstate = message->ops_AttrList;
588 struct TagItem *tag;
590 while ((tag = NextTagItem((TAGITEM)&tstate)) != NULL)
592 switch (tag->ti_Tag)
594 case MUIA_WandererPrefs_Processing:
595 data->wpd_PROCESSING = (BOOL)tag->ti_Data;
596 break;
597 case MUIA_IconWindowExt_NetworkBrowser_Show:
598 data->wpd_ShowNetwork = (LONG)tag->ti_Data;
599 break;
601 case MUIA_IconWindowExt_UserFiles_ShowFilesFolder:
602 data->wpd_ShowUserFiles = (LONG)tag->ti_Data;
603 break;
605 case MUIA_IconWindowExt_ScreenTitle_String:
606 strcpy((STRPTR)data->wpd_ScreenTitleString, (STRPTR)tag->ti_Data);
607 //data->wpd_ScreenTitleString = (LONG)tag->ti_Data;
608 break;
610 case MUIA_IconWindow_WindowNavigationMethod:
611 data->wpd_NavigationMethod = (LONG)tag->ti_Data;
612 break;
616 return DoSuperMethodA(CLASS, self, (Msg)message);
620 ///OM_GET()
621 IPTR WandererPrefs__OM_GET(Class *CLASS, Object *self, struct opGet *message)
623 SETUP_INST_DATA;
624 IPTR *store = message->opg_Storage;
625 IPTR rv = TRUE;
627 switch (message->opg_AttrID)
629 case MUIA_WandererPrefs_Processing:
630 *store = (IPTR)data->wpd_PROCESSING;
631 break;
633 case MUIA_IconWindowExt_NetworkBrowser_Show:
634 *store = (IPTR)data->wpd_ShowNetwork;
635 break;
637 case MUIA_IconWindowExt_UserFiles_ShowFilesFolder:
638 *store = (IPTR)data->wpd_ShowUserFiles;
639 break;
641 case MUIA_IconWindowExt_ScreenTitle_String:
642 *store = (IPTR)data->wpd_ScreenTitleString;
643 D(bug("[Wanderer:Prefs] WandererPrefs__GET: MUIA_IconWindowExt_ScreenTitle_String '%s'\n", data->wpd_ScreenTitleString));
644 break;
646 case MUIA_IconWindow_WindowNavigationMethod:
647 *store = (IPTR)data->wpd_NavigationMethod;
648 break;
650 default:
651 rv = DoSuperMethodA(CLASS, self, (Msg)message);
654 return rv;
658 ///ProcessGlobalChunk()
659 BOOL WandererPrefs_ProccessGlobalChunk(Class *CLASS, Object *self, struct TagItem32 *global_chunk, IPTR chunk_size)
661 //SETUP_INST_DATA;
663 int i = 0, tag_count = (chunk_size / sizeof(struct TagItem32));
664 BOOL cont = TRUE;
666 D(bug("[Wanderer:Prefs] WandererPrefs_ProccessGlobalChunk()\n"));
667 /* TODO: fix problems with endian-ness? */
669 for (i = 0; i < tag_count; i++)
671 if (cont)
673 /* prefs file is stored in little endian */
674 if (AROS_LE2LONG(global_chunk[i].ti_Tag) == TAG_DONE)
676 cont = FALSE;
678 else if (AROS_LE2LONG(global_chunk[i].ti_Tag) == MUIA_WandererPrefs_DefaultStack)
680 /* TODO: We should have an option to set the DefaultStackSize in wanderers prefs, and push it onto workbench.library */
681 struct TagItem wbca_Tags[] =
683 { WBCTRLA_SetDefaultStackSize, (IPTR)AROS_LE2LONG(global_chunk[i].ti_Data) },
684 { TAG_DONE, 0 }
686 /* TODO: What should we use for the name arg in WorkbenchControlA */
687 WorkbenchControlA("", wbca_Tags);
689 else
691 SET(self, AROS_LE2LONG(global_chunk[i].ti_Tag), AROS_LE2LONG(global_chunk[i].ti_Data));
696 return TRUE;
700 ///WPEditor_ProccessNetworkChunk()
701 BOOL WPEditor_ProccessNetworkChunk(Class *CLASS, Object *self, UBYTE *_viewSettings_Chunk)
703 //SETUP_INST_DATA;
705 struct TagItem *network_tags = (struct TagItem *)_viewSettings_Chunk;
706 SET(self, AROS_LE2LONG(network_tags[0].ti_Tag), AROS_LE2LONG(network_tags[0].ti_Data));
708 return TRUE;
712 ///WPEditor_ProccessScreenTitleChunk()
713 BOOL WPEditor_ProccessScreenTitleChunk(Class *CLASS, Object *self, UBYTE *_ScreenTitle_Chunk)
715 //SETUP_INST_DATA;
716 char *displayed_screentitle = _ScreenTitle_Chunk;
717 char *userscreentitle = NULL;
719 D(bug("[Wanderer:Prefs] WandererPrefs__ProccessScreenTitleChunk@@@@@@@@@: ScreenTitle Template = '%s'\n", _ScreenTitle_Chunk));
721 if ((userscreentitle = ProcessUserScreenTitle(_ScreenTitle_Chunk)) != NULL)
723 D(bug("[Wanderer:Prefs] WandererPrefs__ProccessScreenTitleChunk@@@@@@@@@: ProcessUserScreenTitle returns '%s'\n", userscreentitle));
724 displayed_screentitle = userscreentitle;
727 SET(self, MUIA_IconWindowExt_ScreenTitle_String, displayed_screentitle);
728 D(bug("[Wanderer:Prefs] WandererPrefs__ProccessScreenTitleChunk@@@@@@@@@: SCREENTITLE set\n"));
730 return TRUE;
734 ///WandererPrefs_FindViewSettingsNode()
735 struct WandererPrefs_ViewSettingsNode *WandererPrefs_FindViewSettingsNode(struct WandererPrefs_DATA *data, char *node_Name)
737 struct WandererPrefs_ViewSettingsNode *current_Node = NULL;
739 #ifdef __AROS__
740 ForeachNode(&data->wpd_ViewSettings, current_Node)
741 #else
742 Foreach_Node(&data->wpd_ViewSettings, current_Node);
743 #endif
745 if ((strcmp(current_Node->wpbn_Name, node_Name)) == 0) return current_Node;
747 return NULL;
751 ///WandererPrefs_ProccessViewSettingsChunk()
752 BOOL WandererPrefs_ProccessViewSettingsChunk(Class *CLASS, Object *self, char *_viewSettings_ViewName, UBYTE *_viewSettings_Chunk, IPTR chunk_size)
754 SETUP_INST_DATA;
756 struct WandererPrefs_ViewSettingsNode *_viewSettings_Node = NULL;
758 D(bug("[Wanderer:Prefs] WandererPrefs_ProccessViewSettingsChunk()\n"));
760 _viewSettings_Node = WandererPrefs_FindViewSettingsNode(data, _viewSettings_ViewName);
762 if (_viewSettings_Node)
764 D(bug("[Wanderer:Prefs] WandererPrefs_ProccessViewSettingsChunk: Updating Existing node @ 0x%p\n", _viewSettings_Node));
765 FreeVec((APTR)_viewSettings_Node->wpbn_Background);
766 /* TODO: Free any Cached backgrounds here .. */
768 else
770 D(bug("[Wanderer:Prefs] WandererPrefs_ProccessViewSettingsChunk: Creating new node for '%s'\n", _viewSettings_ViewName));
771 _viewSettings_Node = AllocMem(sizeof(struct WandererPrefs_ViewSettingsNode), MEMF_CLEAR|MEMF_PUBLIC);
773 _viewSettings_Node->wpbn_Name = AllocVec(strlen(_viewSettings_ViewName) + 1, MEMF_CLEAR|MEMF_PUBLIC);
774 strcpy(_viewSettings_Node->wpbn_Name, _viewSettings_ViewName);
775 #ifdef __AROS__
776 _viewSettings_Node->wpbn_NotifyObject = (Object *)NotifyObject, End;
777 #else
778 _viewSettings_Node->wpbn_NotifyObject = MUI_NewObject(MUIC_Notify, TAG_DONE);
779 #endif
781 AddTail(&data->wpd_ViewSettings, &_viewSettings_Node->wpbn_Node);
784 _viewSettings_Node->wpbn_Background =(IPTR) AllocVec(strlen(_viewSettings_Chunk) + 1, MEMF_CLEAR|MEMF_PUBLIC);
785 strcpy((char *)_viewSettings_Node->wpbn_Background, _viewSettings_Chunk);
786 D(bug("[Wanderer:Prefs] WandererPrefs_ProccessViewSettingsChunk: NAME BACKGROUND= %s\n",_viewSettings_Chunk));
787 SET(_viewSettings_Node->wpbn_NotifyObject, MUIA_Background, _viewSettings_Chunk);
789 /* TODO: Cache backgrounds here .. */
791 if (chunk_size > (strlen(_viewSettings_Chunk) + 1))
793 UBYTE _viewSettings_TagOffset = ((strlen(_viewSettings_Chunk) + 1)/4);
794 IPTR _viewSettings_TagCount;
796 D(bug("[Wanderer:Prefs] WandererPrefs_ProccessViewSettingsChunk: Chunk has options Tag data ..\n"));
798 if ((_viewSettings_TagOffset * 4) != (strlen(_viewSettings_Chunk) + 1))
800 _viewSettings_TagOffset = (_viewSettings_TagOffset + 1) * 4;
801 D(bug("[WPEditor] WPEditor_ProccessBackgroundChunk: String length unalined - rounding up (length %d, rounded %d) \n", strlen(_viewSettings_Chunk) + 1, _viewSettings_TagOffset ));
803 else
805 _viewSettings_TagOffset = _viewSettings_TagOffset * 4;
806 D(bug("[WPEditor] WPEditor_ProccessBackgroundChunk: String length doesnt need aligned (length %d) \n", strlen(_viewSettings_Chunk) + 1));
809 _viewSettings_TagCount = ((chunk_size - _viewSettings_TagOffset)/sizeof(struct TagItem32));
811 D(bug("[Wanderer:Prefs] WandererPrefs_ProccessViewSettingsChunk: %d Tags at offset %d ..\n", _viewSettings_TagCount, _viewSettings_TagOffset));
813 if (_viewSettings_Node->wpbn_Options != NULL)
815 D(bug("[Wanderer:Prefs] WandererPrefs_ProccessViewSettingsChunk: Freeing old background tag's @ 0x%p\n", _viewSettings_Node->wpbn_Options));
816 FreeVec(_viewSettings_Node->wpbn_Options);
817 _viewSettings_Node->wpbn_Options = NULL;
820 _viewSettings_Node->wpbn_Options = AllocVec((_viewSettings_TagCount + 1) * sizeof(struct TagItem32), MEMF_CLEAR|MEMF_PUBLIC);
821 D(bug("[Wanderer:Prefs] WandererPrefs_ProccessViewSettingsChunk: New tag storage @ 0x%p\n", _viewSettings_Node->wpbn_Options));
823 CopyMem(_viewSettings_Chunk + _viewSettings_TagOffset, _viewSettings_Node->wpbn_Options, (_viewSettings_TagCount) * sizeof(struct TagItem32));
824 D(bug("[Wanderer:Prefs] WandererPrefs_ProccessViewSettingsChunk: Tags copied to storage \n"));
826 _viewSettings_Node->wpbn_Options[_viewSettings_TagCount].ti_Tag = TAG_DONE;
829 int i = 0;
830 for (i = 0; i < _viewSettings_TagCount; i++)
832 #if AROS_BIG_ENDIAN
833 _viewSettings_Node->wpbn_Options[i].ti_Tag = AROS_LE2LONG(_viewSettings_Node->wpbn_Options[i].ti_Tag);
834 _viewSettings_Node->wpbn_Options[i].ti_Data = AROS_LE2LONG(_viewSettings_Node->wpbn_Options[i].ti_Data);
835 #endif
836 D(bug("[Wanderer:Prefs] WandererPrefs_ProccessViewSettingsChunk: Setting Tag 0x%p Value %d\n", _viewSettings_Node->wpbn_Options[i].ti_Tag, _viewSettings_Node->wpbn_Options[i].ti_Data));
837 SET(_viewSettings_Node->wpbn_NotifyObject, _viewSettings_Node->wpbn_Options[i].ti_Tag, _viewSettings_Node->wpbn_Options[i].ti_Data);
841 return TRUE;
845 ///WandererPrefs__MUIM_WandererPrefs_Reload()
846 IPTR WandererPrefs__MUIM_WandererPrefs_Reload
848 Class *CLASS, Object *self, Msg message
851 D(struct ContextNode *context);
852 struct IFFHandle *handle;
853 BOOL success = TRUE;
854 LONG error;
855 IPTR iff_parse_mode = IFFPARSE_SCAN;
856 UBYTE chunk_buffer[IFF_CHUNK_BUFFER_SIZE];
858 D(bug("[Wanderer:Prefs] WandererPrefs__MUIM_WandererPrefs_Reload()\n"));
860 if (!(handle = AllocIFF()))
861 return FALSE;
863 handle->iff_Stream = (IPTR)Open(wandererPrefs_PrefsFile, MODE_OLDFILE);
865 if (!handle->iff_Stream)
866 return FALSE;
868 InitIFFasDOS(handle);
870 if ((error = OpenIFF(handle, IFFF_READ)) == 0)
872 if ((error = StopChunk(handle, ID_PREF, ID_WANDR)) == 0)
874 SET(self, MUIA_WandererPrefs_Processing, TRUE);
877 if ((error = ParseIFF(handle, iff_parse_mode)) == 0)
879 D(context = CurrentChunk(handle));
880 iff_parse_mode = IFFPARSE_STEP;
882 D(bug("[Wanderer:Prefs] WandererPrefs__MUIM_WandererPrefs_Reload: Context 0x%p\n", context));
884 if ((error=ReadChunkBytes(handle, chunk_buffer, IFF_CHUNK_BUFFER_SIZE)))
886 struct WandererPrefsIFFChunkHeader *this_header =(struct WandererPrefsIFFChunkHeader *) chunk_buffer;
887 char *this_chunk_name = NULL;
888 IPTR this_chunk_size = AROS_LE2LONG(this_header->wpIFFch_ChunkSize);
890 D(bug("[Wanderer:Prefs] WandererPrefs__MUIM_WandererPrefs_Reload: ReadChunkBytes() Chunk matches Prefs Header size ..\n"));
892 if ((this_chunk_name = AllocVec(strlen(this_header->wpIFFch_ChunkType) +1,MEMF_ANY|MEMF_CLEAR)))
894 strcpy(this_chunk_name, this_header->wpIFFch_ChunkType);
895 D(bug("[Wanderer:Prefs] WandererPrefs__MUIM_WandererPrefs_Reload: Prefs Header for '%s' data size %d bytes\n", this_chunk_name, this_chunk_size));
897 if ((error = ParseIFF(handle, IFFPARSE_STEP)) == IFFERR_EOC)
899 D(bug("[Wanderer:Prefs] WandererPrefs__MUIM_WandererPrefs_Reload: End of header chunk ..\n"));
901 if ((error = ParseIFF(handle, IFFPARSE_STEP)) == 0)
903 D(context = CurrentChunk(handle));
905 D(bug("[Wanderer:Prefs] WandererPrefs__MUIM_WandererPrefs_Reload: Context 0x%p\n", context));
907 error = ReadChunkBytes
909 handle,
910 chunk_buffer,
911 this_chunk_size
914 if (error == this_chunk_size)
916 D(bug("[Wanderer:Prefs] WandererPrefs__MUIM_WandererPrefs_Reload: ReadChunkBytes() Chunk matches Prefs Data size .. (%d)\n", error));
917 if ((strcmp(this_chunk_name, "wanderer:global")) == 0)
919 D(bug("[Wanderer:Prefs] WandererPrefs__MUIM_WandererPrefs_Reload: Process data for wanderer global chunk ..\n"));
920 WandererPrefs_ProccessGlobalChunk(CLASS, self,(struct TagItem32 *) chunk_buffer, this_chunk_size);
922 else if ((strcmp(this_chunk_name, "wanderer:network")) == 0)
924 D(bug("[WPEditor] WPEditor__MUIM_PrefsEditor_ImportFH: Process data for wanderer network config chunk ..\n"));
925 WPEditor_ProccessNetworkChunk(CLASS, self, chunk_buffer);
927 else if ((strcmp(this_chunk_name, "wanderer:screentitle")) == 0)
929 D(bug("[WPEditor] WPEditor__MUIM_PrefsEditor_ImportFH: Process data for wanderer screentitle config chunk ..size=%d\n", error));
930 D(bug("[WPEditor] WPEditor__MUIM_PrefsEditor_ImportFH: Process data for wanderer screentitle STRING= %s\n", chunk_buffer));
931 WPEditor_ProccessScreenTitleChunk(CLASS, self, chunk_buffer);
934 else if ((strncmp(this_chunk_name, "wanderer:viewsettings", strlen("wanderer:viewsettings"))) == 0)
936 char *view_name = this_chunk_name + strlen("wanderer:viewsettings") + 1;
937 D(bug("[Wanderer:Prefs] WandererPrefs__MUIM_WandererPrefs_Reload: Process data for wanderer background chunk '%s'..\n", view_name));
938 WandererPrefs_ProccessViewSettingsChunk(CLASS, self, view_name, chunk_buffer, this_chunk_size);
940 }//END if (error == this_chunk_size)
941 if ((error = ParseIFF(handle, IFFPARSE_STEP)) == IFFERR_EOC)
943 D(bug("[Wanderer:Prefs] WandererPrefs__MUIM_WandererPrefs_Reload: TAG_DONE) of Data chunk ..\n"));
945 }//END if ((error = ParseIFF(handle, IFFPARSE_STEP)) == 0)
946 }//END if ((error = ParseIFF(handle, IFFPARSE_STEP)) == IFFERR_EOC)
947 }//END if ((this_chunk_name = AllocVec(strlen(this_header->wpIFFch_ChunkType) +1,MEMF_ANY|MEMF_CLEAR)))
948 }//END if ((error=ReadChunkBytes(handle, chunk_buffer, IFF_CHUNK_BUFFER_SIZE)))
950 else
952 D(bug("[Wanderer:Prefs] ParseIFF() failed, returncode %ld!\n", error));
953 //success = FALSE;
954 }//END if ((error = ParseIFF(handle, iff_parse_mode)) == 0)
956 } while (error != IFFERR_EOF);
957 SET(self, MUIA_WandererPrefs_Processing, FALSE);
959 else
961 D(bug("[Wanderer:Prefs] StopChunk() failed, returncode %ld!\n", error));
962 //success = FALSE;
965 CloseIFF(handle);
967 else
969 D(bug("[Wanderer:Prefs] Failed to open stream!, returncode %ld!\n", error));
970 //ShowError(_(MSG_CANT_OPEN_STREAM));
971 success = FALSE;
972 }//END if ((error = StopChunk(handle, ID_PREF, ID_WANDR)) == 0)
974 Close((BPTR)handle->iff_Stream);
976 FreeIFF(handle);
978 return success;
982 ///WandererPrefs__MUIM_WandererPrefs_ReloadFontPrefs()
983 IPTR WandererPrefs__MUIM_WandererPrefs_ReloadFontPrefs
985 Class *CLASS, Object *self, Msg message
988 struct WandererPrefs_ViewSettingsNode * current_Node = NULL;
990 SETUP_INST_DATA;
992 SET(self, MUIA_WandererPrefs_Processing, TRUE);
994 WandererPrefs_ReloadFontPrefs(wandererPrefs_FontsPrefsFile, &data->wfpd);
996 ForeachNode(&data->wpd_ViewSettings, current_Node)
997 SET(current_Node->wpbn_NotifyObject, MUIA_IconWindow_Font, data->wfpd.wfpd_IconFont);
999 SET(self, MUIA_WandererPrefs_Processing, FALSE);
1001 WandererPrefs_CloseOldIconFont(&data->wfpd);
1003 return TRUE;
1007 ///WandererPrefs__MUIM_WandererPrefs_ViewSettings_GetNotifyObject()
1008 IPTR WandererPrefs__MUIM_WandererPrefs_ViewSettings_GetNotifyObject
1010 Class *CLASS, Object *self, struct MUIP_WandererPrefs_ViewSettings_GetNotifyObject *message
1013 SETUP_INST_DATA;
1014 struct WandererPrefs_ViewSettingsNode *current_Node = NULL;
1016 D(bug("[Wanderer:Prefs] WandererPrefs__MUIM_WandererPrefs_ViewSettings_GetNotifyObject()\n"));
1018 if ((current_Node = WandererPrefs_FindViewSettingsNode(data, message->Background_Name)))
1020 D(bug("[Wanderer:Prefs] WandererPrefs__MUIM_WandererPrefs_ViewSettings_GetNotifyObject: Returning Object for existing record\n"));
1021 return (IPTR) current_Node->wpbn_NotifyObject;
1024 current_Node = AllocMem(sizeof(struct WandererPrefs_ViewSettingsNode), MEMF_CLEAR|MEMF_PUBLIC);
1025 D(bug("[Wanderer:Prefs] WandererPrefs__MUIM_WandererPrefs_ViewSettings_GetNotifyObject: Created new node ..\n"));
1027 current_Node->wpbn_Name = AllocVec(strlen(message->Background_Name) + 1, MEMF_CLEAR|MEMF_PUBLIC);
1028 strcpy(current_Node->wpbn_Name, message->Background_Name);
1029 #ifdef __AROS__
1030 current_Node->wpbn_NotifyObject = (Object *)NotifyObject, End;
1031 #else
1032 current_Node->wpbn_NotifyObject = MUI_NewObject(MUIC_Notify, TAG_DONE);
1033 #endif
1034 AddTail(&data->wpd_ViewSettings, &current_Node->wpbn_Node);
1036 D(bug("[Wanderer:Prefs] WandererPrefs__MUIM_WandererPrefs_ViewSettings_GetNotifyObject: Notify Object @ 0x%p\n", current_Node->wpbn_NotifyObject));
1038 return (IPTR) current_Node->wpbn_NotifyObject;
1042 ///NextTag32Item()
1043 /* TODO: Replace with propper 64bit check */
1044 /* 32bit replacements for utility.library tag funcs */
1045 struct TagItem32 * NextTag32Item(struct TagItem32 ** tagListPtr)
1047 if(!(*tagListPtr)) return NULL;
1049 while (TRUE)
1051 switch ((*tagListPtr)->ti_Tag)
1053 case TAG_IGNORE:
1054 break;
1056 case TAG_END:
1057 (*tagListPtr) = NULL;
1058 return NULL;
1060 case TAG_SKIP:
1061 (*tagListPtr) += (*tagListPtr)->ti_Data + 1;
1062 continue;
1064 default:
1065 /* Use post-increment (return will return the current value and
1066 then tagListPtr will be incremented) */
1067 return (struct TagItem32 *)(*tagListPtr)++;
1070 (*tagListPtr) ++;
1075 ///FindTag32Item()
1076 struct TagItem32 * FindTag32Item(ULONG tagValue, struct TagItem32 *tagList)
1078 struct TagItem32 *tag;
1079 const struct TagItem32 *tagptr = tagList;
1081 while ((tag = NextTag32Item((struct TagItem32 **)&tagptr)))
1083 if (tag->ti_Tag == tagValue) return tag;
1086 return NULL;
1091 ///GetTag32Data()
1092 ULONG GetTag32Data(ULONG tagValue, ULONG defaultVal, struct TagItem32 *tagList)
1094 struct TagItem32 *ti = NULL;
1096 if ((tagList != NULL) && (ti = FindTag32Item(tagValue, tagList)))
1097 return ti->ti_Data;
1099 return defaultVal;
1103 ///WandererPrefs__MUIM_WandererPrefs_ViewSettings_GetAttribute()
1104 IPTR WandererPrefs__MUIM_WandererPrefs_ViewSettings_GetAttribute
1106 Class *CLASS, Object *self, struct MUIP_WandererPrefs_ViewSettings_GetAttribute *message
1109 SETUP_INST_DATA;
1110 struct WandererPrefs_ViewSettingsNode *current_Node = NULL;
1112 D(bug("[Wanderer:Prefs] WandererPrefs__MUIM_WandererPrefs_ViewSettings_GetAttribute()\n"));
1114 if ((current_Node = WandererPrefs_FindViewSettingsNode(data, message->Background_Name)) != NULL)
1116 D(bug("[Wanderer:Prefs] WandererPrefs__MUIM_WandererPrefs_ViewSettings_GetAttribute: Found Background Record ..\n"));
1117 if (message->AttributeID == MUIA_Background)
1119 if (current_Node->wpbn_Background) return current_Node->wpbn_Background;
1121 else if (message->AttributeID == MUIA_IconWindow_Font)
1123 return (IPTR)data->wfpd.wfpd_IconFont;
1125 else if (current_Node->wpbn_Options)
1127 if (sizeof(IPTR) > 4)
1129 ULONG retVal = GetTag32Data(message->AttributeID, (ULONG)-1,(struct TagItem32 *) current_Node->wpbn_Options);
1131 D(bug("[Wanderer:Prefs] WandererPrefs__MUIM_WandererPrefs_ViewSettings_GetAttribute: Using internal GetTag32Data()\n"));
1133 if (retVal != (ULONG)-1)
1134 return (IPTR)retVal;
1136 else
1138 D(bug("[Wanderer:Prefs] WandererPrefs__MUIM_WandererPrefs_ViewSettings_GetAttribute: Using utility.library->GetTagData()\n"));
1139 return (IPTR)GetTagData(message->AttributeID, (IPTR)-1, (struct TagItem *) current_Node->wpbn_Options);
1143 return (IPTR)-1;
1146 /*** Setup ******************************************************************/
1147 ZUNE_CUSTOMCLASS_8
1149 WandererPrefs, NULL, MUIC_Notify, NULL,
1150 OM_NEW, struct opSet *,
1151 OM_DISPOSE, Msg,
1152 OM_SET, struct opSet *,
1153 OM_GET, struct opGet *,
1154 MUIM_WandererPrefs_Reload, Msg,
1155 MUIM_WandererPrefs_ReloadFontPrefs, Msg,
1156 MUIM_WandererPrefs_ViewSettings_GetNotifyObject, struct MUIP_WandererPrefs_ViewSettings_GetNotifyObject *,
1157 MUIM_WandererPrefs_ViewSettings_GetAttribute, struct MUIP_WandererPrefs_ViewSettings_GetAttribute *