2 Copyright 2004-2013, The AROS Development Team. All rights reserved.
8 #include "portable_macros.h"
11 #include <aros/debug.h>
13 #define MUIMASTER_YES_INLINE_STDARG
16 #define IFF_CHUNK_BUFFER_SIZE 1024
18 #include <exec/types.h>
19 #include <libraries/mui.h>
22 #include <zune/customclasses.h>
24 #include <zune_AROS/customclasses.h>
27 #include <proto/workbench.h>
29 #include <proto/utility.h>
31 #include <proto/dos.h>
34 #include <proto/alib.h>
37 #include <proto/iffparse.h>
40 #include <proto/aros.h>
43 #include <aros/arosbase.h>
44 #include <aros/inquire.h>
50 #if defined(__AMIGA__) && !defined(__PPC__)
51 #define NO_INLINE_STDARG
53 #ifndef _PROTO_INTUITION_H
54 #include <proto/intuition.h>
57 #include <proto/muimaster.h>
60 #include "wandererprefs.h"
61 #include "wandererprefsfont.h"
62 #include "Classes/iconlist_attributes.h"
63 #include "iconwindow_attributes.h"
69 #include <prefs/prefhdr.h>
70 #include <prefs/wanderer.h>
72 #include <prefs_AROS/prefhdr.h>
73 #include <prefs_AROS/wanderer.h>
81 #define D(x) if (DEBUG) x
83 #define bug DebugPrintF
92 static CONST_STRPTR wandererPrefs_PrefsFile
= "ENV:SYS/Wanderer/global.prefs";
93 static CONST_STRPTR wandererPrefs_FontsPrefsFile
= "ENV:SYS/Font.prefs";
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
;
119 struct WandererFontPrefsData wfpd
;
122 struct WandererPrefs_ViewSettingsNode
124 struct Node wpbn_Node
;
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 ******************************************************/
136 BOOL
SetString(STRPTR
*dst
, STRPTR src
)
140 if ((*dst
== NULL
) || (strcmp(src
, *dst
) != 0))
142 STRPTR tmp
=(STRPTR
) StrDup(src
);
159 static unsigned char strtochar(STRPTR st
)
164 /******** code from workbench/c/Info.c **************************************/
166 static void fmtlarge(UBYTE
*buf
, ULONG num
)
180 if (num
>= 1073741824)
183 array
.val
= num
>> 30;
184 d
= ((UQUAD
)num
* 10 + 536870912) / 1073741824;
186 ch
= strtochar((STRPTR
)_(MSG_MEM_G
));
188 else if (num
>= 1048576)
191 array
.val
= num
>> 20;
192 d
= ((UQUAD
)num
* 10 + 524288) / 1048576;
194 ch
= strtochar((STRPTR
)_(MSG_MEM_M
));
196 else if (num
>= 1024)
199 array
.val
= num
>> 10;
200 d
= (num
* 10 + 512) / 1024;
202 ch
= strtochar((STRPTR
)_(MSG_MEM_K
));
210 ch
= strtochar((STRPTR
)_(MSG_MEM_B
));
213 if (!array
.dec
&& (d
> array
.val
* 10))
218 RawDoFmt(array
.dec
? "%lu.%lu" : "%lu", (RAWARG
)&array
, NULL
, buf
);
231 /* Case-insensitive FindName()
232 * code from workbench/c/Version.c
235 struct Node
*findname(struct List
*list
, CONST_STRPTR name
)
239 ForeachNode(list
, node
)
241 Foreach_Node(list
, node
);
244 if (!Stricmp(node
->ln_Name
, (STRPTR
) name
))
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];
263 int screentitle_curChar
;
265 if (screentitle_Template
== NULL
)
267 D(bug("[Wanderer:Prefs] ProcessUserScreenTitle(),EXTERN screentitle = NULL\n"));
268 return screentitle_Template
;
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
));
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)
293 if (strncmp(temp
+ screentitle_curChar
, "%wv", 3) == 0)
295 struct Library
*MyLibrary
= NULL
;
298 MyLibrary
= (struct Library
*)findname(&SysBase
->LibList
, "workbench.library");
299 //workbench.library is just opened, what is the sense of this istruction?
301 MyLibrary
= WorkbenchBase
;
304 sprintf(infostr
, "%ld.%ld",(long int) MyLibrary
->lib_Version
,(long int) MyLibrary
->lib_Revision
);
308 if (strncmp(temp
+ screentitle_curChar
, "%ov", 3) == 0)
310 struct Library
*AROSBase
= OpenLibrary(AROSLIBNAME
, AROSLIBVERSION
);
319 AI_ArosVersion
, (IPTR
)&ver
,
322 sprintf(infostr
, "%d", ver
);
323 CloseLibrary(AROSBase
);
328 if (strncmp(temp
+ screentitle_curChar
, "%os", 3) == 0)
330 struct Library
*AROSBase
= OpenLibrary(AROSLIBNAME
, AROSLIBVERSION
);
332 if (AROSBase
!= NULL
)
339 AI_ArosReleaseMajor
, (IPTR
)&ver
,
340 AI_ArosReleaseMinor
, (IPTR
)&rev
,
343 sprintf(infostr
, "%d.%d", (int)ver
, (int)rev
);
344 CloseLibrary(AROSBase
);
349 if (strncmp(temp
+ screentitle_curChar
, "%wb", 3) == 0)
351 struct Library
*AROSBase
= OpenLibrary(AROSLIBNAME
, AROSLIBVERSION
);
353 if (AROSBase
!= NULL
)
360 AI_ArosReleaseMajor
, (IPTR
)&ver
,
361 AI_ArosReleaseMinor
, (IPTR
)&rev
,
364 sprintf(infostr
, "%d.%d", WANDERERVERS
, WANDERERREV
);
365 CloseLibrary(AROSBase
);
370 if (strncmp(temp
+ screentitle_curChar
, "%pc", 3) == 0)
372 fmtlarge(infostr
, AvailMem(MEMF_CHIP
));
376 if (strncmp(temp
+ screentitle_curChar
, "%pf", 3) == 0)
378 fmtlarge(infostr
, AvailMem(MEMF_FAST
));
382 if (strncmp(temp
+ screentitle_curChar
, "%pt", 3) == 0)
384 fmtlarge(infostr
, AvailMem(MEMF_ANY
));
388 if (strncmp(temp
+ screentitle_curChar
, "%PC", 3) == 0)
390 fmtlarge(infostr
, AvailMem(MEMF_CHIP
|MEMF_TOTAL
));
394 if (strncmp(temp
+ screentitle_curChar
, "%PF", 3) == 0)
396 fmtlarge(infostr
, AvailMem(MEMF_FAST
|MEMF_TOTAL
));
400 if (strncmp(temp
+ screentitle_curChar
, "%PT", 3) == 0)
402 fmtlarge(infostr
, AvailMem(MEMF_ANY
|MEMF_TOTAL
));
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
);
422 temp
[screentitle_curChar
] = '?';
423 temp
[screentitle_curChar
+ 1] = '?';
424 temp
[screentitle_curChar
+ 2] = '?';
430 switch (screentitle_TemplateLen
)
433 temp
[screentitle_curChar
]= '?';
434 temp
[screentitle_curChar
+ 1]= '?';
437 temp
[screentitle_curChar
] = '?';
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
)
456 char tmp_envbuff
[1024];
457 STRPTR fullpath
= NULL
;
458 BPTR env_lock
= (BPTR
) NULL
;
460 env_lock
= Lock("ENV:", SHARED_LOCK
);
463 if (NameFromLock(env_lock
, tmp_envbuff
, 256)) ok
= TRUE
;
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);
477 //We couldnt expand it so just use as is ..
483 IPTR
WandererPrefs__HandleFSUpdate(Object
*prefs
, struct NotifyMessage
*msg
)
485 DoMethod(prefs
, MUIM_WandererPrefs_Reload
);
489 IPTR
WandererPrefs__HandleFontPrefsFSUpdate(Object
*prefs
, struct NotifyMessage
*msg
)
491 DoMethod(prefs
, MUIM_WandererPrefs_ReloadFontPrefs
);
495 /*** Methods ****************************************************************/
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
);
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
));
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
));
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
));
574 IPTR
WandererPrefs__OM_DISPOSE(Class
*CLASS
, Object
*self
, Msg message
)
577 EndNotify(&data
->wpd_PrefsNotifyRequest
);
578 EndNotify(&data
->wpd_FontPrefsNotifyRequest
);
579 return DoSuperMethodA(CLASS
, self
, (Msg
)message
);
584 IPTR
WandererPrefs__OM_SET(Class
*CLASS
, Object
*self
, struct opSet
*message
)
587 struct TagItem
*tstate
= message
->ops_AttrList
;
590 while ((tag
= NextTagItem((TAGITEM
)&tstate
)) != NULL
)
594 case MUIA_WandererPrefs_Processing
:
595 data
->wpd_PROCESSING
= (BOOL
)tag
->ti_Data
;
597 case MUIA_IconWindowExt_NetworkBrowser_Show
:
598 data
->wpd_ShowNetwork
= (LONG
)tag
->ti_Data
;
601 case MUIA_IconWindowExt_UserFiles_ShowFilesFolder
:
602 data
->wpd_ShowUserFiles
= (LONG
)tag
->ti_Data
;
605 case MUIA_IconWindowExt_ScreenTitle_String
:
606 strcpy((STRPTR
)data
->wpd_ScreenTitleString
, (STRPTR
)tag
->ti_Data
);
607 //data->wpd_ScreenTitleString = (LONG)tag->ti_Data;
610 case MUIA_IconWindow_WindowNavigationMethod
:
611 data
->wpd_NavigationMethod
= (LONG
)tag
->ti_Data
;
616 return DoSuperMethodA(CLASS
, self
, (Msg
)message
);
621 IPTR
WandererPrefs__OM_GET(Class
*CLASS
, Object
*self
, struct opGet
*message
)
624 IPTR
*store
= message
->opg_Storage
;
627 switch (message
->opg_AttrID
)
629 case MUIA_WandererPrefs_Processing
:
630 *store
= (IPTR
)data
->wpd_PROCESSING
;
633 case MUIA_IconWindowExt_NetworkBrowser_Show
:
634 *store
= (IPTR
)data
->wpd_ShowNetwork
;
637 case MUIA_IconWindowExt_UserFiles_ShowFilesFolder
:
638 *store
= (IPTR
)data
->wpd_ShowUserFiles
;
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
));
646 case MUIA_IconWindow_WindowNavigationMethod
:
647 *store
= (IPTR
)data
->wpd_NavigationMethod
;
651 rv
= DoSuperMethodA(CLASS
, self
, (Msg
)message
);
658 ///ProcessGlobalChunk()
659 BOOL
WandererPrefs_ProccessGlobalChunk(Class
*CLASS
, Object
*self
, struct TagItem32
*global_chunk
, IPTR chunk_size
)
663 int i
= 0, tag_count
= (chunk_size
/ sizeof(struct TagItem32
));
666 D(bug("[Wanderer:Prefs] WandererPrefs_ProccessGlobalChunk()\n"));
667 /* TODO: fix problems with endian-ness? */
669 for (i
= 0; i
< tag_count
; i
++)
673 /* prefs file is stored in little endian */
674 if (AROS_LE2LONG(global_chunk
[i
].ti_Tag
) == TAG_DONE
)
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
) },
686 /* TODO: What should we use for the name arg in WorkbenchControlA */
687 WorkbenchControlA("", wbca_Tags
);
691 SET(self
, AROS_LE2LONG(global_chunk
[i
].ti_Tag
), AROS_LE2LONG(global_chunk
[i
].ti_Data
));
700 ///WPEditor_ProccessNetworkChunk()
701 BOOL
WPEditor_ProccessNetworkChunk(Class
*CLASS
, Object
*self
, UBYTE
*_viewSettings_Chunk
)
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
));
712 ///WPEditor_ProccessScreenTitleChunk()
713 BOOL
WPEditor_ProccessScreenTitleChunk(Class
*CLASS
, Object
*self
, UBYTE
*_ScreenTitle_Chunk
)
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"));
734 ///WandererPrefs_FindViewSettingsNode()
735 struct WandererPrefs_ViewSettingsNode
*WandererPrefs_FindViewSettingsNode(struct WandererPrefs_DATA
*data
, char *node_Name
)
737 struct WandererPrefs_ViewSettingsNode
*current_Node
= NULL
;
740 ForeachNode(&data
->wpd_ViewSettings
, current_Node
)
742 Foreach_Node(&data
->wpd_ViewSettings
, current_Node
);
745 if ((strcmp(current_Node
->wpbn_Name
, node_Name
)) == 0) return current_Node
;
751 ///WandererPrefs_ProccessViewSettingsChunk()
752 BOOL
WandererPrefs_ProccessViewSettingsChunk(Class
*CLASS
, Object
*self
, char *_viewSettings_ViewName
, UBYTE
*_viewSettings_Chunk
, IPTR chunk_size
)
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 .. */
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
);
776 _viewSettings_Node
->wpbn_NotifyObject
= (Object
*)NotifyObject
, End
;
778 _viewSettings_Node
->wpbn_NotifyObject
= MUI_NewObject(MUIC_Notify
, TAG_DONE
);
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
));
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
;
830 for (i
= 0; i
< _viewSettings_TagCount
; i
++)
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
);
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
);
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
;
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()))
863 handle
->iff_Stream
= (IPTR
)Open(wandererPrefs_PrefsFile
, MODE_OLDFILE
);
865 if (!handle
->iff_Stream
)
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
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)))
952 D(bug("[Wanderer:Prefs] ParseIFF() failed, returncode %ld!\n", error
));
954 }//END if ((error = ParseIFF(handle, iff_parse_mode)) == 0)
956 } while (error
!= IFFERR_EOF
);
957 SET(self
, MUIA_WandererPrefs_Processing
, FALSE
);
961 D(bug("[Wanderer:Prefs] StopChunk() failed, returncode %ld!\n", error
));
969 D(bug("[Wanderer:Prefs] Failed to open stream!, returncode %ld!\n", error
));
970 //ShowError(_(MSG_CANT_OPEN_STREAM));
972 }//END if ((error = StopChunk(handle, ID_PREF, ID_WANDR)) == 0)
974 Close((BPTR
)handle
->iff_Stream
);
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
;
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
);
1007 ///WandererPrefs__MUIM_WandererPrefs_ViewSettings_GetNotifyObject()
1008 IPTR WandererPrefs__MUIM_WandererPrefs_ViewSettings_GetNotifyObject
1010 Class
*CLASS
, Object
*self
, struct MUIP_WandererPrefs_ViewSettings_GetNotifyObject
*message
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
);
1030 current_Node
->wpbn_NotifyObject
= (Object
*)NotifyObject
, End
;
1032 current_Node
->wpbn_NotifyObject
= MUI_NewObject(MUIC_Notify
, TAG_DONE
);
1034 AddTail(&data
->wpd_ViewSettings
, ¤t_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
;
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
;
1051 switch ((*tagListPtr
)->ti_Tag
)
1057 (*tagListPtr
) = NULL
;
1061 (*tagListPtr
) += (*tagListPtr
)->ti_Data
+ 1;
1065 /* Use post-increment (return will return the current value and
1066 then tagListPtr will be incremented) */
1067 return (struct TagItem32
*)(*tagListPtr
)++;
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
;
1092 ULONG
GetTag32Data(ULONG tagValue
, ULONG defaultVal
, struct TagItem32
*tagList
)
1094 struct TagItem32
*ti
= NULL
;
1096 if ((tagList
!= NULL
) && (ti
= FindTag32Item(tagValue
, tagList
)))
1103 ///WandererPrefs__MUIM_WandererPrefs_ViewSettings_GetAttribute()
1104 IPTR WandererPrefs__MUIM_WandererPrefs_ViewSettings_GetAttribute
1106 Class
*CLASS
, Object
*self
, struct MUIP_WandererPrefs_ViewSettings_GetAttribute
*message
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
;
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
);
1146 /*** Setup ******************************************************************/
1149 WandererPrefs
, NULL
, MUIC_Notify
, NULL
,
1150 OM_NEW
, struct opSet
*,
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
*