2 Copyright 2004-2009, 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 "Classes/iconlist_attributes.h"
62 #include "iconwindow_attributes.h"
68 #include <prefs/prefhdr.h>
69 #include <prefs/wanderer.h>
71 #include <prefs_AROS/prefhdr.h>
72 #include <prefs_AROS/wanderer.h>
80 #define D(x) if (DEBUG) x
82 #define bug DebugPrintF
91 static CONST_STRPTR wandererPrefs_PrefsFile
= "ENV:SYS/Wanderer/global.prefs";
92 static Object
*wandererPrefs_PrefsObject
;
93 struct Wanderer_FSHandler
*wandererPrefs_PrefsNotifyHandler
= NULL
;
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
;
116 struct WandererPrefs_ViewSettingsNode
118 struct Node wpbn_Node
;
120 IPTR wpbn_Background
;
121 struct TagItem32
*wpbn_Options
;
122 Object
*wpbn_NotifyObject
;
125 /*** Macros *****************************************************************/
126 #define SETUP_INST_DATA struct WandererPrefs_DATA *data = INST_DATA(CLASS, self)
128 /*** Utility Functions ******************************************************/
130 BOOL
SetString(STRPTR
*dst
, STRPTR src
)
134 if ((*dst
== NULL
) || (strcmp(src
, *dst
) != 0))
136 STRPTR tmp
=(STRPTR
) StrDup(src
);
153 static unsigned char strtochar(STRPTR st
)
158 /******** code from workbench/c/Info.c **************************************/
160 static void fmtlarge(UBYTE
*buf
, ULONG num
)
174 if (num
>= 1073741824)
177 array
.val
= num
>> 30;
178 d
= ((UQUAD
)num
* 10 + 536870912) / 1073741824;
180 ch
= strtochar((STRPTR
)_(MSG_MEM_G
));
182 else if (num
>= 1048576)
185 array
.val
= num
>> 20;
186 d
= ((UQUAD
)num
* 10 + 524288) / 1048576;
188 ch
= strtochar((STRPTR
)_(MSG_MEM_M
));
190 else if (num
>= 1024)
193 array
.val
= num
>> 10;
194 d
= (num
* 10 + 512) / 1024;
196 ch
= strtochar((STRPTR
)_(MSG_MEM_K
));
204 ch
= strtochar((STRPTR
)_(MSG_MEM_B
));
207 if (!array
.dec
&& (d
> array
.val
* 10))
212 RawDoFmt(array
.dec
? "%lu.%lu" : "%lu", &array
, NULL
, buf
);
225 /* Case-insensitive FindName()
226 * code from workbench/c/Version.c
229 struct Node
*findname(struct List
*list
, CONST_STRPTR name
)
233 ForeachNode(list
, node
)
235 Foreach_Node(list
, node
);
238 if (!Stricmp(node
->ln_Name
, (STRPTR
) name
))
248 ///ProcessUserScreenTitle()
249 /*pattern matching of user screentitle...;*/
250 STRPTR
ProcessUserScreenTitle(STRPTR screentitle_Template
)
252 /* Work in progress :-) */
253 int screentitle_TemplateLen
;
254 STATIC
char title
[256];
255 char temp
[256], buffer
[256];
257 int screentitle_curChar
;
259 if (screentitle_Template
== NULL
)
261 D(bug("[Wanderer:Prefs] ProcessUserScreenTitle(),EXTERN screentitle = NULL\n"));
262 return screentitle_Template
;
266 D(bug("[Wanderer:Prefs] ProcessUserScreenTitle('%s')\n", screentitle_Template
));
269 screentitle_TemplateLen
= strlen(screentitle_Template
);
271 if (screentitle_TemplateLen
< 1)
273 D(bug("[Wanderer:Prefs] ProcessUserScreenTitle: EXTERN screentitle_TemplateLen = %d\n", screentitle_TemplateLen
));
274 return (STRPTR
) screentitle_TemplateLen
;
277 strcpy(temp
, screentitle_Template
);
279 for (screentitle_curChar
= 0; screentitle_curChar
< screentitle_TemplateLen
; screentitle_curChar
++)
281 if (temp
[screentitle_curChar
]=='%')
283 if (screentitle_TemplateLen
>= 3)
287 if (strncmp(temp
+ screentitle_curChar
, "%wv", 3) == 0)
289 struct Library
*MyLibrary
= NULL
;
292 MyLibrary
= (struct Library
*)findname(&SysBase
->LibList
, "workbench.library");
293 //workbench.library is just opened, what is the sense of this istruction?
295 MyLibrary
= WorkbenchBase
;
298 sprintf(infostr
, "%ld.%ld",(long int) MyLibrary
->lib_Version
,(long int) MyLibrary
->lib_Revision
);
302 if (strncmp(temp
+ screentitle_curChar
, "%ov", 3) == 0)
304 struct Library
*AROSBase
= OpenLibrary(AROSLIBNAME
, AROSLIBVERSION
);
313 AI_ArosVersion
, (IPTR
)&ver
,
316 sprintf(infostr
, "%d", ver
);
317 CloseLibrary(AROSBase
);
322 if (strncmp(temp
+ screentitle_curChar
, "%os", 3) == 0)
324 struct Library
*AROSBase
= OpenLibrary(AROSLIBNAME
, AROSLIBVERSION
);
326 if (AROSBase
!= NULL
)
333 AI_ArosReleaseMajor
, (IPTR
)&ver
,
334 AI_ArosReleaseMinor
, (IPTR
)&rev
,
337 sprintf(infostr
, "%ld.%ld", ver
, rev
);
338 CloseLibrary(AROSBase
);
343 if (strncmp(temp
+ screentitle_curChar
, "%wb", 3) == 0)
345 struct Library
*AROSBase
= OpenLibrary(AROSLIBNAME
, AROSLIBVERSION
);
347 if (AROSBase
!= NULL
)
354 AI_ArosReleaseMajor
, (IPTR
)&ver
,
355 AI_ArosReleaseMinor
, (IPTR
)&rev
,
358 sprintf(infostr
, "%d.%d", WANDERERVERS
, WANDERERREV
);
359 CloseLibrary(AROSBase
);
364 if (strncmp(temp
+ screentitle_curChar
, "%pc", 3) == 0)
366 fmtlarge(infostr
, AvailMem(MEMF_CHIP
));
370 if (strncmp(temp
+ screentitle_curChar
, "%pf", 3) == 0)
372 fmtlarge(infostr
, AvailMem(MEMF_FAST
));
376 if (strncmp(temp
+ screentitle_curChar
, "%pt", 3) == 0)
378 fmtlarge(infostr
, AvailMem(MEMF_ANY
));
382 if (strncmp(temp
+ screentitle_curChar
, "%PC", 3) == 0)
384 fmtlarge(infostr
, AvailMem(MEMF_CHIP
|MEMF_TOTAL
));
388 if (strncmp(temp
+ screentitle_curChar
, "%PF", 3) == 0)
390 fmtlarge(infostr
, AvailMem(MEMF_FAST
|MEMF_TOTAL
));
394 if (strncmp(temp
+ screentitle_curChar
, "%PT", 3) == 0)
396 fmtlarge(infostr
, AvailMem(MEMF_ANY
|MEMF_TOTAL
));
402 temp
[screentitle_curChar
+ 1] = 's';
403 temp
[screentitle_curChar
+ 2] = ' ';
405 sprintf(title
, temp
, infostr
);
407 screentitle_curChar
= screentitle_curChar
+ strlen(infostr
);
408 strncpy(buffer
, title
, screentitle_curChar
);
409 strcpy(&buffer
[screentitle_curChar
], &temp
[(screentitle_curChar
+ 3) - strlen(infostr
)]);
410 strcpy(temp
, buffer
);
412 screentitle_TemplateLen
= screentitle_TemplateLen
+ strlen(infostr
);
416 temp
[screentitle_curChar
] = '?';
417 temp
[screentitle_curChar
+ 1] = '?';
418 temp
[screentitle_curChar
+ 2] = '?';
419 sprintf(title
, temp
);
424 switch (screentitle_TemplateLen
)
427 temp
[screentitle_curChar
]= '?';
428 temp
[screentitle_curChar
+ 1]= '?';
431 temp
[screentitle_curChar
] = '?';
433 sprintf(title
, temp
);
437 sprintf(title
, temp
);
444 /* Expand a passed in env: string to its full location */
445 /* Wanderer doesnt free this mem at the moment but should
446 incase it is every closed */
447 static STRPTR
ExpandEnvName(STRPTR env_path
)
450 char tmp_envbuff
[1024];
451 STRPTR fullpath
= NULL
;
452 BPTR env_lock
= (BPTR
) NULL
;
454 env_lock
= Lock("ENV:", SHARED_LOCK
);
457 if (NameFromLock(env_lock
, tmp_envbuff
, 256)) ok
= TRUE
;
463 if ((fullpath
= AllocVec(strlen(tmp_envbuff
) + strlen(env_path
) + 1 + 1 - 4, MEMF_CLEAR
| MEMF_PUBLIC
)) != NULL
)
465 strcpy(fullpath
, tmp_envbuff
);
466 AddPart(fullpath
, env_path
+ 4, 1019);
471 //We couldnt expand it so just use as is ..
477 IPTR
WandererPrefs__HandleFSUpdate()
479 DoMethod(wandererPrefs_PrefsObject
, MUIM_WandererPrefs_Reload
);
483 /*** Methods ****************************************************************/
486 Object
*WandererPrefs__OM_NEW(Class
*CLASS
, Object
*self
, struct opSet
*message
)
488 IPTR _wandererPrefs__FSNotifyPort
= 0;
489 struct List
*_wandererPrefs__FSNotifyList
= NULL
;
490 D(bug("[Wanderer:Prefs]:New()\n"));
492 _wandererPrefs__FSNotifyPort
= GetTagData(MUIA_Wanderer_FileSysNotifyPort
, (IPTR
) NULL
, message
->ops_AttrList
);
493 _wandererPrefs__FSNotifyList
= GetTagData(MUIA_Wanderer_FileSysNotifyList
, (IPTR
) NULL
, message
->ops_AttrList
);
495 self
= (Object
*) DoSuperMethodA(CLASS
, self
, (Msg
) message
);
501 wandererPrefs_PrefsObject
= self
;
503 /* Setup notification on prefs file --------------------------------*/
504 if (_wandererPrefs__FSNotifyList
&& ((wandererPrefs_PrefsNotifyHandler
= AllocMem(sizeof(struct Wanderer_FSHandler
), MEMF_CLEAR
)) != NULL
))
506 wandererPrefs_PrefsNotifyHandler
->fshn_Node
.ln_Name
= ExpandEnvName(wandererPrefs_PrefsFile
);
507 data
->wpd_PrefsNotifyRequest
.nr_Name
= wandererPrefs_PrefsNotifyHandler
->fshn_Node
.ln_Name
;
508 data
->wpd_PrefsNotifyRequest
.nr_Flags
= NRF_SEND_MESSAGE
;
509 data
->wpd_PrefsNotifyRequest
.nr_stuff
.nr_Msg
.nr_Port
= _wandererPrefs__FSNotifyPort
;
510 wandererPrefs_PrefsNotifyHandler
->HandleFSUpdate
= WandererPrefs__HandleFSUpdate
;
512 if (StartNotify(&data
->wpd_PrefsNotifyRequest
))
514 D(bug("[Wanderer:Prefs] Wanderer__OM_NEW: Prefs-notification setup on '%s'\n", data
->wpd_PrefsNotifyRequest
.nr_Name
));
518 D(bug("[Wanderer:Prefs] Wanderer__OM_NEW: FAILED to setup Prefs-notification!\n"));
520 AddTail(_wandererPrefs__FSNotifyList
, &wandererPrefs_PrefsNotifyHandler
->fshn_Node
);
522 D(bug("[Wanderer:Prefs]:New - reloading\n"));
524 NewList(&data
->wpd_ViewSettings
);
526 data
->wpd_PROCESSING
= FALSE
;
528 DoMethod(self
, MUIM_WandererPrefs_Reload
);
530 D(bug("[Wanderer:Prefs] obj = %ld\n", self
));
536 IPTR
WandererPrefs__OM_DISPOSE(Class
*CLASS
, Object
*self
, Msg message
)
539 EndNotify(&data
->wpd_PrefsNotifyRequest
);
540 return DoSuperMethodA(CLASS
, self
, (Msg
)message
);
545 IPTR
WandererPrefs__OM_SET(Class
*CLASS
, Object
*self
, struct opSet
*message
)
548 const struct TagItem
*tstate
= message
->ops_AttrList
;
551 while ((tag
= NextTagItem((TAGITEM
)&tstate
)) != NULL
)
555 case MUIA_WandererPrefs_Processing
:
556 data
->wpd_PROCESSING
= (BOOL
)tag
->ti_Data
;
558 case MUIA_IconWindowExt_NetworkBrowser_Show
:
559 data
->wpd_ShowNetwork
= (LONG
)tag
->ti_Data
;
562 case MUIA_IconWindowExt_UserFiles_ShowFilesFolder
:
563 data
->wpd_ShowUserFiles
= (LONG
)tag
->ti_Data
;
566 case MUIA_IconWindowExt_ScreenTitle_String
:
567 strcpy((STRPTR
)data
->wpd_ScreenTitleString
, (STRPTR
)tag
->ti_Data
);
568 //data->wpd_ScreenTitleString = (LONG)tag->ti_Data;
571 case MUIA_IconWindow_WindowNavigationMethod
:
572 data
->wpd_NavigationMethod
= (LONG
)tag
->ti_Data
;
577 return DoSuperMethodA(CLASS
, self
, (Msg
)message
);
582 IPTR
WandererPrefs__OM_GET(Class
*CLASS
, Object
*self
, struct opGet
*message
)
585 IPTR
*store
= message
->opg_Storage
;
588 switch (message
->opg_AttrID
)
590 case MUIA_WandererPrefs_Processing
:
591 *store
= (IPTR
)data
->wpd_PROCESSING
;
594 case MUIA_IconWindowExt_NetworkBrowser_Show
:
595 *store
= (IPTR
)data
->wpd_ShowNetwork
;
598 case MUIA_IconWindowExt_UserFiles_ShowFilesFolder
:
599 *store
= (IPTR
)data
->wpd_ShowUserFiles
;
602 case MUIA_IconWindowExt_ScreenTitle_String
:
603 *store
= (IPTR
)data
->wpd_ScreenTitleString
;
604 D(bug("[Wanderer:Prefs] WandererPrefs__GET: MUIA_IconWindowExt_ScreenTitle_String '%s'\n", data
->wpd_ScreenTitleString
));
607 case MUIA_IconWindow_WindowNavigationMethod
:
608 *store
= (IPTR
)data
->wpd_NavigationMethod
;
612 rv
= DoSuperMethodA(CLASS
, self
, (Msg
)message
);
619 ///ProcessGlobalChunk()
620 BOOL
WandererPrefs_ProccessGlobalChunk(Class
*CLASS
, Object
*self
, struct TagItem32
*global_chunk
, IPTR chunk_size
)
624 int i
= 0, tag_count
= (chunk_size
/ sizeof(struct TagItem32
));
627 D(bug("[Wanderer:Prefs] WandererPrefs_ProccessGlobalChunk()\n"));
628 #warning "TODO: fix problems with endian-ness?"
630 for (i
= 0; i
< tag_count
; i
++)
634 /* prefs file is stored in little endian */
635 if (AROS_LE2LONG(global_chunk
[i
].ti_Tag
) == TAG_DONE
)
639 else if (AROS_LE2LONG(global_chunk
[i
].ti_Tag
) == MUIA_WandererPrefs_DefaultStack
)
641 #warning "TODO: We should have an option to set the DefaultStackSize in wanderers prefs, and push it onto workbench.library"
642 struct TagItem wbca_Tags
[] =
644 { WBCTRLA_SetDefaultStackSize
, (IPTR
)AROS_LE2LONG(global_chunk
[i
].ti_Data
) },
647 #warning "TODO: What should we use for the name arg in WorkbenchControlA"
648 WorkbenchControlA("", wbca_Tags
);
652 SET(self
, AROS_LE2LONG(global_chunk
[i
].ti_Tag
), AROS_LE2LONG(global_chunk
[i
].ti_Data
));
661 ///WPEditor_ProccessNetworkChunk()
662 BOOL
WPEditor_ProccessNetworkChunk(Class
*CLASS
, Object
*self
, UBYTE
*_viewSettings_Chunk
)
666 struct TagItem
*network_tags
= (struct TagItem
*)_viewSettings_Chunk
;
667 SET(self
, AROS_LE2LONG(network_tags
[0].ti_Tag
), AROS_LE2LONG(network_tags
[0].ti_Data
));
673 ///WPEditor_ProccessScreenTitleChunk()
674 BOOL
WPEditor_ProccessScreenTitleChunk(Class
*CLASS
, Object
*self
, UBYTE
*_ScreenTitle_Chunk
)
677 char *displayed_screentitle
= _ScreenTitle_Chunk
;
678 char *userscreentitle
= NULL
;
680 D(bug("[Wanderer:Prefs] WandererPrefs__ProccessScreenTitleChunk@@@@@@@@@: ScreenTitle Template = '%s'\n", _ScreenTitle_Chunk
));
682 if ((userscreentitle
= ProcessUserScreenTitle(_ScreenTitle_Chunk
)) != NULL
)
684 D(bug("[Wanderer:Prefs] WandererPrefs__ProccessScreenTitleChunk@@@@@@@@@: ProcessUserScreenTitle returns '%s'\n", userscreentitle
));
685 displayed_screentitle
= userscreentitle
;
688 SET(self
, MUIA_IconWindowExt_ScreenTitle_String
, displayed_screentitle
);
689 D(bug("[Wanderer:Prefs] WandererPrefs__ProccessScreenTitleChunk@@@@@@@@@: SCREENTITLE set\n"));
695 ///WandererPrefs_FindViewSettingsNode()
696 struct WandererPrefs_ViewSettingsNode
*WandererPrefs_FindViewSettingsNode(struct WandererPrefs_DATA
*data
, char *node_Name
)
698 struct WandererPrefs_ViewSettingsNode
*current_Node
= NULL
;
701 ForeachNode(&data
->wpd_ViewSettings
, current_Node
)
703 Foreach_Node(&data
->wpd_ViewSettings
, current_Node
);
706 if ((strcmp(current_Node
->wpbn_Name
, node_Name
)) == 0) return current_Node
;
712 ///WandererPrefs_ProccessViewSettingsChunk()
713 BOOL
WandererPrefs_ProccessViewSettingsChunk(Class
*CLASS
, Object
*self
, char *_viewSettings_ViewName
, UBYTE
*_viewSettings_Chunk
, IPTR chunk_size
)
717 struct WandererPrefs_ViewSettingsNode
*_viewSettings_Node
= NULL
;
719 D(bug("[Wanderer:Prefs] WandererPrefs_ProccessViewSettingsChunk()\n"));
721 _viewSettings_Node
= WandererPrefs_FindViewSettingsNode(data
, _viewSettings_ViewName
);
723 if (_viewSettings_Node
)
725 D(bug("[Wanderer:Prefs] WandererPrefs_ProccessViewSettingsChunk: Updating Existing node @ 0x%p\n", _viewSettings_Node
));
726 if (_viewSettings_Node
->wpbn_Background
)
727 FreeVec((APTR
)_viewSettings_Node
->wpbn_Background
);
728 #warning "TODO: Free any Cached backgrounds here .."
732 D(bug("[Wanderer:Prefs] WandererPrefs_ProccessViewSettingsChunk: Creating new node for '%s'\n", _viewSettings_ViewName
));
733 _viewSettings_Node
= AllocMem(sizeof(struct WandererPrefs_ViewSettingsNode
), MEMF_CLEAR
|MEMF_PUBLIC
);
735 _viewSettings_Node
->wpbn_Name
= AllocVec(strlen(_viewSettings_ViewName
) + 1, MEMF_CLEAR
|MEMF_PUBLIC
);
736 strcpy(_viewSettings_Node
->wpbn_Name
, _viewSettings_ViewName
);
738 _viewSettings_Node
->wpbn_NotifyObject
= (Object
*)NotifyObject
, End
;
740 _viewSettings_Node
->wpbn_NotifyObject
= MUI_NewObject(MUIC_Notify
, TAG_DONE
);
743 AddTail(&data
->wpd_ViewSettings
, &_viewSettings_Node
->wpbn_Node
);
746 _viewSettings_Node
->wpbn_Background
=(IPTR
) AllocVec(strlen(_viewSettings_Chunk
) + 1, MEMF_CLEAR
|MEMF_PUBLIC
);
747 strcpy((char *)_viewSettings_Node
->wpbn_Background
, _viewSettings_Chunk
);
748 D(bug("[Wanderer:Prefs] WandererPrefs_ProccessViewSettingsChunk: NAME BACKGROUND= %s\n",_viewSettings_Chunk
));
749 SET(_viewSettings_Node
->wpbn_NotifyObject
, MUIA_Background
, _viewSettings_Chunk
);
751 #warning "TODO: Cache backgrounds here .."
753 if (chunk_size
> (strlen(_viewSettings_Chunk
) + 1))
755 UBYTE _viewSettings_TagOffset
= ((strlen(_viewSettings_Chunk
) + 1)/4);
756 IPTR _viewSettings_TagCount
;
758 D(bug("[Wanderer:Prefs] WandererPrefs_ProccessViewSettingsChunk: Chunk has options Tag data ..\n"));
760 if ((_viewSettings_TagOffset
* 4) != (strlen(_viewSettings_Chunk
) + 1))
762 _viewSettings_TagOffset
= (_viewSettings_TagOffset
+ 1) * 4;
763 D(bug("[WPEditor] WPEditor_ProccessBackgroundChunk: String length unalined - rounding up (length %d, rounded %d) \n", strlen(_viewSettings_Chunk
) + 1, _viewSettings_TagOffset
));
767 _viewSettings_TagOffset
= _viewSettings_TagOffset
* 4;
768 D(bug("[WPEditor] WPEditor_ProccessBackgroundChunk: String length doesnt need aligned (length %d) \n", strlen(_viewSettings_Chunk
) + 1));
771 _viewSettings_TagCount
= ((chunk_size
- _viewSettings_TagOffset
)/sizeof(struct TagItem32
));
773 D(bug("[Wanderer:Prefs] WandererPrefs_ProccessViewSettingsChunk: %d Tags at offset %d ..\n", _viewSettings_TagCount
, _viewSettings_TagOffset
));
775 if (_viewSettings_Node
->wpbn_Options
!= NULL
)
777 D(bug("[Wanderer:Prefs] WandererPrefs_ProccessViewSettingsChunk: Freeing old background tag's @ 0x%p\n", _viewSettings_Node
->wpbn_Options
));
778 FreeVec(_viewSettings_Node
->wpbn_Options
);
779 _viewSettings_Node
->wpbn_Options
= NULL
;
782 _viewSettings_Node
->wpbn_Options
= AllocVec((_viewSettings_TagCount
+ 1) * sizeof(struct TagItem32
), MEMF_CLEAR
|MEMF_PUBLIC
);
783 D(bug("[Wanderer:Prefs] WandererPrefs_ProccessViewSettingsChunk: New tag storage @ 0x%p\n", _viewSettings_Node
->wpbn_Options
));
785 CopyMem(_viewSettings_Chunk
+ _viewSettings_TagOffset
, _viewSettings_Node
->wpbn_Options
, (_viewSettings_TagCount
) * sizeof(struct TagItem32
));
786 D(bug("[Wanderer:Prefs] WandererPrefs_ProccessViewSettingsChunk: Tags copied to storage \n"));
788 _viewSettings_Node
->wpbn_Options
[_viewSettings_TagCount
].ti_Tag
= TAG_DONE
;
792 for (i
= 0; i
< _viewSettings_TagCount
; i
++)
795 _viewSettings_Node
->wpbn_Options
[i
].ti_Tag
= AROS_LE2LONG(_viewSettings_Node
->wpbn_Options
[i
].ti_Tag
);
796 _viewSettings_Node
->wpbn_Options
[i
].ti_Data
= AROS_LE2LONG(_viewSettings_Node
->wpbn_Options
[i
].ti_Data
);
798 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
));
799 SET(_viewSettings_Node
->wpbn_NotifyObject
, _viewSettings_Node
->wpbn_Options
[i
].ti_Tag
, _viewSettings_Node
->wpbn_Options
[i
].ti_Data
);
807 ///WandererPrefs__MUIM_WandererPrefs_Reload()
808 IPTR WandererPrefs__MUIM_WandererPrefs_Reload
810 Class
*CLASS
, Object
*self
, Msg message
813 struct ContextNode
*context
;
814 struct IFFHandle
*handle
;
817 IPTR iff_parse_mode
= IFFPARSE_SCAN
;
818 UBYTE chunk_buffer
[IFF_CHUNK_BUFFER_SIZE
];
820 D(bug("[Wanderer:Prefs] WandererPrefs__MUIM_WandererPrefs_Reload()\n"));
822 if (!(handle
= AllocIFF()))
825 handle
->iff_Stream
= (IPTR
)Open(wandererPrefs_PrefsFile
, MODE_OLDFILE
);
827 if (!handle
->iff_Stream
)
830 InitIFFasDOS(handle
);
832 if ((error
= OpenIFF(handle
, IFFF_READ
)) == 0)
834 if ((error
= StopChunk(handle
, ID_PREF
, ID_WANDR
)) == 0)
836 SET(self
, MUIA_WandererPrefs_Processing
, TRUE
);
839 if ((error
= ParseIFF(handle
, iff_parse_mode
)) == 0)
841 context
= CurrentChunk(handle
);
842 iff_parse_mode
= IFFPARSE_STEP
;
844 D(bug("[Wanderer:Prefs] WandererPrefs__MUIM_WandererPrefs_Reload: Context 0x%p\n", context
));
846 if ((error
=ReadChunkBytes(handle
, chunk_buffer
, IFF_CHUNK_BUFFER_SIZE
)))
848 struct WandererPrefsIFFChunkHeader
*this_header
=(struct WandererPrefsIFFChunkHeader
*) chunk_buffer
;
849 char *this_chunk_name
= NULL
;
850 IPTR this_chunk_size
= AROS_LE2LONG(this_header
->wpIFFch_ChunkSize
);
852 D(bug("[Wanderer:Prefs] WandererPrefs__MUIM_WandererPrefs_Reload: ReadChunkBytes() Chunk matches Prefs Header size ..\n"));
854 if ((this_chunk_name
= AllocVec(strlen(this_header
->wpIFFch_ChunkType
) +1,MEMF_ANY
|MEMF_CLEAR
)))
856 strcpy(this_chunk_name
, this_header
->wpIFFch_ChunkType
);
857 D(bug("[Wanderer:Prefs] WandererPrefs__MUIM_WandererPrefs_Reload: Prefs Header for '%s' data size %d bytes\n", this_chunk_name
, this_chunk_size
));
859 if ((error
= ParseIFF(handle
, IFFPARSE_STEP
)) == IFFERR_EOC
)
861 D(bug("[Wanderer:Prefs] WandererPrefs__MUIM_WandererPrefs_Reload: End of header chunk ..\n"));
863 if ((error
= ParseIFF(handle
, IFFPARSE_STEP
)) == 0)
865 context
= CurrentChunk(handle
);
867 D(bug("[Wanderer:Prefs] WandererPrefs__MUIM_WandererPrefs_Reload: Context 0x%p\n", context
));
869 error
= ReadChunkBytes
876 if (error
== this_chunk_size
)
878 D(bug("[Wanderer:Prefs] WandererPrefs__MUIM_WandererPrefs_Reload: ReadChunkBytes() Chunk matches Prefs Data size .. (%d)\n", error
));
879 if ((strcmp(this_chunk_name
, "wanderer:global")) == 0)
881 D(bug("[Wanderer:Prefs] WandererPrefs__MUIM_WandererPrefs_Reload: Process data for wanderer global chunk ..\n"));
882 WandererPrefs_ProccessGlobalChunk(CLASS
, self
,(struct TagItem32
*) chunk_buffer
, this_chunk_size
);
884 else if ((strcmp(this_chunk_name
, "wanderer:network")) == 0)
886 D(bug("[WPEditor] WPEditor__MUIM_PrefsEditor_ImportFH: Process data for wanderer network config chunk ..\n"));
887 WPEditor_ProccessNetworkChunk(CLASS
, self
, chunk_buffer
);
889 else if ((strcmp(this_chunk_name
, "wanderer:screentitle")) == 0)
891 D(bug("[WPEditor] WPEditor__MUIM_PrefsEditor_ImportFH: Process data for wanderer screentitle config chunk ..size=%d\n", error
));
892 D(bug("[WPEditor] WPEditor__MUIM_PrefsEditor_ImportFH: Process data for wanderer screentitle STRING= %s\n", chunk_buffer
));
893 WPEditor_ProccessScreenTitleChunk(CLASS
, self
, chunk_buffer
);
896 else if ((strncmp(this_chunk_name
, "wanderer:viewsettings", strlen("wanderer:viewsettings"))) == 0)
898 char *view_name
= this_chunk_name
+ strlen("wanderer:viewsettings") + 1;
899 D(bug("[Wanderer:Prefs] WandererPrefs__MUIM_WandererPrefs_Reload: Process data for wanderer background chunk '%s'..\n", view_name
));
900 WandererPrefs_ProccessViewSettingsChunk(CLASS
, self
, view_name
, chunk_buffer
, this_chunk_size
);
902 }//END if (error == this_chunk_size)
903 if ((error
= ParseIFF(handle
, IFFPARSE_STEP
)) == IFFERR_EOC
)
905 D(bug("[Wanderer:Prefs] WandererPrefs__MUIM_WandererPrefs_Reload: TAG_DONE) of Data chunk ..\n"));
907 }//END if ((error = ParseIFF(handle, IFFPARSE_STEP)) == 0)
908 }//END if ((error = ParseIFF(handle, IFFPARSE_STEP)) == IFFERR_EOC)
909 }//END if ((this_chunk_name = AllocVec(strlen(this_header->wpIFFch_ChunkType) +1,MEMF_ANY|MEMF_CLEAR)))
910 }//END if ((error=ReadChunkBytes(handle, chunk_buffer, IFF_CHUNK_BUFFER_SIZE)))
914 D(bug("[Wanderer:Prefs] ParseIFF() failed, returncode %ld!\n", error
));
916 }//END if ((error = ParseIFF(handle, iff_parse_mode)) == 0)
918 } while (error
!= IFFERR_EOF
);
919 SET(self
, MUIA_WandererPrefs_Processing
, FALSE
);
923 D(bug("[Wanderer:Prefs] StopChunk() failed, returncode %ld!\n", error
));
931 D(bug("[Wanderer:Prefs] Failed to open stream!, returncode %ld!\n", error
));
932 //ShowError(_(MSG_CANT_OPEN_STREAM));
934 }//END if ((error = StopChunk(handle, ID_PREF, ID_WANDR)) == 0)
936 Close((BPTR
)handle
->iff_Stream
);
944 ///WandererPrefs__MUIM_WandererPrefs_ViewSettings_GetNotifyObject()
945 IPTR WandererPrefs__MUIM_WandererPrefs_ViewSettings_GetNotifyObject
947 Class
*CLASS
, Object
*self
, struct MUIP_WandererPrefs_ViewSettings_GetNotifyObject
*message
951 struct WandererPrefs_ViewSettingsNode
*current_Node
= NULL
;
953 D(bug("[Wanderer:Prefs] WandererPrefs__MUIM_WandererPrefs_ViewSettings_GetNotifyObject()\n"));
955 if ((current_Node
= WandererPrefs_FindViewSettingsNode(data
, message
->Background_Name
)))
957 D(bug("[Wanderer:Prefs] WandererPrefs__MUIM_WandererPrefs_ViewSettings_GetNotifyObject: Returning Object for existing record\n"));
958 return (IPTR
) current_Node
->wpbn_NotifyObject
;
961 current_Node
= AllocMem(sizeof(struct WandererPrefs_ViewSettingsNode
), MEMF_CLEAR
|MEMF_PUBLIC
);
962 D(bug("[Wanderer:Prefs] WandererPrefs__MUIM_WandererPrefs_ViewSettings_GetNotifyObject: Created new node ..\n"));
964 current_Node
->wpbn_Name
= AllocVec(strlen(message
->Background_Name
) + 1, MEMF_CLEAR
|MEMF_PUBLIC
);
965 strcpy(current_Node
->wpbn_Name
, message
->Background_Name
);
967 current_Node
->wpbn_NotifyObject
= (Object
*)NotifyObject
, End
;
969 current_Node
->wpbn_NotifyObject
= MUI_NewObject(MUIC_Notify
, TAG_DONE
);
971 AddTail(&data
->wpd_ViewSettings
, ¤t_Node
->wpbn_Node
);
973 D(bug("[Wanderer:Prefs] WandererPrefs__MUIM_WandererPrefs_ViewSettings_GetNotifyObject: Notify Object @ 0x%p\n", current_Node
->wpbn_NotifyObject
));
975 return (IPTR
) current_Node
->wpbn_NotifyObject
;
980 #warning "TODO: Replace with propper 64bit check"
981 /* 32bit replacements for utility.library tag funcs */
982 struct TagItem32
* NextTag32Item(struct TagItem32
** tagListPtr
)
984 if(!(*tagListPtr
)) return NULL
;
988 switch ((*tagListPtr
)->ti_Tag
)
994 (*tagListPtr
) = NULL
;
998 (*tagListPtr
) += (*tagListPtr
)->ti_Data
+ 1;
1002 /* Use post-increment (return will return the current value and
1003 then tagListPtr will be incremented) */
1004 return (struct TagItem32
*)(*tagListPtr
)++;
1013 struct TagItem32
* FindTag32Item(ULONG tagValue
, struct TagItem32
*tagList
)
1015 struct TagItem32
*tag
;
1016 const struct TagItem32
*tagptr
= tagList
;
1018 while ((tag
= NextTag32Item((struct TagItem32
**)&tagptr
)))
1020 if (tag
->ti_Tag
== tagValue
) return tag
;
1029 ULONG
GetTag32Data(ULONG tagValue
, ULONG defaultVal
, struct TagItem32
*tagList
)
1031 struct TagItem32
*ti
= NULL
;
1033 if ((tagList
!= NULL
) && (ti
= FindTag32Item(tagValue
, tagList
)))
1040 ///WandererPrefs__MUIM_WandererPrefs_ViewSettings_GetAttribute()
1041 IPTR WandererPrefs__MUIM_WandererPrefs_ViewSettings_GetAttribute
1043 Class
*CLASS
, Object
*self
, struct MUIP_WandererPrefs_ViewSettings_GetAttribute
*message
1047 struct WandererPrefs_ViewSettingsNode
*current_Node
= NULL
;
1049 D(bug("[Wanderer:Prefs] WandererPrefs__MUIM_WandererPrefs_ViewSettings_GetAttribute()\n"));
1051 if ((current_Node
= WandererPrefs_FindViewSettingsNode(data
, message
->Background_Name
)) != NULL
)
1053 D(bug("[Wanderer:Prefs] WandererPrefs__MUIM_WandererPrefs_ViewSettings_GetAttribute: Found Background Record ..\n"));
1054 if (message
->AttributeID
== MUIA_Background
)
1056 if (current_Node
->wpbn_Background
) return current_Node
->wpbn_Background
;
1058 else if (current_Node
->wpbn_Options
)
1060 if (sizeof(IPTR
) > 4)
1062 ULONG retVal
= GetTag32Data(message
->AttributeID
, (ULONG
)-1,(struct TagItem32
*) current_Node
->wpbn_Options
);
1064 D(bug("[Wanderer:Prefs] WandererPrefs__MUIM_WandererPrefs_ViewSettings_GetAttribute: Using internal GetTag32Data()\n"));
1066 if (retVal
!= (ULONG
)-1)
1067 return (IPTR
)retVal
;
1071 D(bug("[Wanderer:Prefs] WandererPrefs__MUIM_WandererPrefs_ViewSettings_GetAttribute: Using utility.library->GetTagData()\n"));
1072 return (IPTR
)GetTagData(message
->AttributeID
, (IPTR
)-1, (struct TagItem
*) current_Node
->wpbn_Options
);
1079 /*** Setup ******************************************************************/
1082 WandererPrefs
, NULL
, MUIC_Notify
, NULL
,
1083 OM_NEW
, struct opSet
*,
1085 OM_SET
, struct opSet
*,
1086 OM_GET
, struct opGet
*,
1087 MUIM_WandererPrefs_Reload
, Msg
,
1088 MUIM_WandererPrefs_ViewSettings_GetNotifyObject
, struct MUIP_WandererPrefs_ViewSettings_GetNotifyObject
*,
1089 MUIM_WandererPrefs_ViewSettings_GetAttribute
, struct MUIP_WandererPrefs_ViewSettings_GetAttribute
*