2 Copyright 2004-2007, The AROS Development Team. All rights reserved.
6 #include <aros/debug.h>
8 #define MUIMASTER_YES_INLINE_STDARG
9 #define IFF_CHUNK_BUFFER_SIZE 1024
11 #include <exec/types.h>
12 #include <libraries/mui.h>
13 #include <zune/customclasses.h>
14 #include <proto/utility.h>
15 #include <proto/intuition.h>
16 #include <proto/muimaster.h>
17 #include <proto/dos.h>
18 #include <proto/alib.h>
19 #include <proto/iffparse.h>
20 #include <proto/aros.h>
21 #include <aros/arosbase.h>
22 #include <aros/inquire.h>
26 #include "wandererprefs.h"
27 #include "../../libs/muimaster/classes/iconlist_attributes.h"
28 #include "iconwindow_attributes.h"
33 #include <prefs/prefhdr.h>
34 #include <prefs/wanderer.h>
41 /*** Instance Data **********************************************************/
42 struct WandererPrefs_DATA
44 ULONG wpd_NavigationMethod
;
45 ULONG wpd_ToolbarEnabled
;
46 ULONG wpd_ShowNetwork
;
47 ULONG wpd_ShowUserFiles
;
48 ULONG wpd_ScreenTitleString
[IFF_CHUNK_BUFFER_SIZE
];
50 struct List wpd_ViewSettings
;
55 struct WandererPrefs_ViewSettingsNode
57 struct Node wpbn_Node
;
60 struct TagItem32
*wpbn_Options
;
61 Object
*wpbn_NotifyObject
;
64 /*** Macros *****************************************************************/
65 #define SETUP_INST_DATA struct WandererPrefs_DATA *data = INST_DATA(CLASS, self)
67 /*** Utility Functions ******************************************************/
68 BOOL
SetString(STRPTR
*dst
, STRPTR src
)
72 if ((*dst
== NULL
) || (strcmp(src
, *dst
) != 0))
74 STRPTR tmp
= StrDup(src
);
88 static unsigned char strtochar(STRPTR st
)
93 /******** code from workbench/c/Info.c *******************/
94 static void fmtlarge(UBYTE
*buf
, ULONG num
)
108 if (num
>= 1073741824)
111 array
.val
= num
>> 30;
112 d
= ((UQUAD
)num
* 10 + 536870912) / 1073741824;
114 ch
= strtochar((STRPTR
)_(MSG_MEM_G
));
116 else if (num
>= 1048576)
119 array
.val
= num
>> 20;
120 d
= ((UQUAD
)num
* 10 + 524288) / 1048576;
122 ch
= strtochar((STRPTR
)_(MSG_MEM_M
));
124 else if (num
>= 1024)
127 array
.val
= num
>> 10;
128 d
= (num
* 10 + 512) / 1024;
130 ch
= strtochar((STRPTR
)_(MSG_MEM_K
));
138 ch
= strtochar((STRPTR
)_(MSG_MEM_B
));
141 if (!array
.dec
&& (d
> array
.val
* 10))
146 RawDoFmt(array
.dec
? "%lu.%lu" : "%lu", &array
, NULL
, buf
);
157 /* Case-insensitive FindName()
158 * code from workbench/c/Version.c
161 struct Node
*findname(struct List
*list
, CONST_STRPTR name
)
165 ForeachNode(list
, node
)
167 if (!Stricmp(node
->ln_Name
, (STRPTR
) name
))
176 /*ProcessUserScreenTitle(): pattern matching of user screentitle...;*/
177 STRPTR
ProcessUserScreenTitle(STRPTR screentitle_Template
)
179 /* Work in progress :-) */
181 D(bug("[Wanderer] ProcessUserScreenTitle(),EXTERN screentitle_Template = %s\n", screentitle_Template
));
183 if (screentitle_Template
== NULL
)
185 D(bug("[Wanderer] ProcessUserScreenTitle(),EXTERN screentitle = NULL\n"));
186 return screentitle_Template
;
189 int screentitle_TemplateLen
= strlen(screentitle_Template
);
191 if (screentitle_TemplateLen
< 1)
193 D(bug("[Wanderer] ProcessUserScreenTitle(),EXTERN screentitle_TemplateLen = %d\n", screentitle_TemplateLen
));
194 return screentitle_TemplateLen
;
197 STATIC
char title
[256];
198 char temp
[256], buffer
[256];
201 strcpy(temp
, screentitle_Template
);
203 int screentitle_curChar
;
204 for (screentitle_curChar
= 0; screentitle_curChar
< screentitle_TemplateLen
; screentitle_curChar
++)
206 if (temp
[screentitle_curChar
]=='%')
208 if (screentitle_TemplateLen
>= 3)
212 if (strncmp(temp
+ screentitle_curChar
, "%wv", 3) == 0)
214 struct Library
*MyLibrary
= NULL
;
216 MyLibrary
= (struct Library
*)findname(&SysBase
->LibList
, "workbench.library");
218 sprintf(infostr
, "%ld.%ld", MyLibrary
->lib_Version
, MyLibrary
->lib_Revision
);
222 if (strncmp(temp
+ screentitle_curChar
, "%ov", 3) == 0)
224 struct Library
*AROSBase
= OpenLibrary(AROSLIBNAME
, AROSLIBVERSION
);
233 AI_ArosVersion
, (IPTR
)&ver
,
236 sprintf(infostr
, "%d", ver
);
237 CloseLibrary(AROSBase
);
242 if (strncmp(temp
+ screentitle_curChar
, "%os", 3) == 0)
244 struct Library
*AROSBase
= OpenLibrary(AROSLIBNAME
, AROSLIBVERSION
);
246 if (AROSBase
!= NULL
)
253 AI_ArosReleaseMajor
, (IPTR
)&ver
,
254 AI_ArosReleaseMinor
, (IPTR
)&rev
,
257 sprintf(infostr
, "%ld.%ld", ver
, rev
);
258 CloseLibrary(AROSBase
);
263 if (strncmp(temp
+ screentitle_curChar
, "%wb", 3) == 0)
265 struct Library
*AROSBase
= OpenLibrary(AROSLIBNAME
, AROSLIBVERSION
);
267 if (AROSBase
!= NULL
)
274 AI_ArosReleaseMajor
, (IPTR
)&ver
,
275 AI_ArosReleaseMinor
, (IPTR
)&rev
,
278 sprintf(infostr
, "%d.%d", WANDERERVERS
, WANDERERREV
);
279 CloseLibrary(AROSBase
);
284 if (strncmp(temp
+ screentitle_curChar
, "%pc", 3) == 0)
286 fmtlarge(infostr
, AvailMem(MEMF_CHIP
));
290 if (strncmp(temp
+ screentitle_curChar
, "%pf", 3) == 0)
292 fmtlarge(infostr
, AvailMem(MEMF_FAST
));
296 if (strncmp(temp
+ screentitle_curChar
, "%pt", 3) == 0)
298 fmtlarge(infostr
, AvailMem(MEMF_ANY
));
302 if (strncmp(temp
+ screentitle_curChar
, "%PC", 3) == 0)
304 fmtlarge(infostr
, AvailMem(MEMF_CHIP
|MEMF_TOTAL
));
308 if (strncmp(temp
+ screentitle_curChar
, "%PF", 3) == 0)
310 fmtlarge(infostr
, AvailMem(MEMF_FAST
|MEMF_TOTAL
));
314 if (strncmp(temp
+ screentitle_curChar
, "%PT", 3) == 0)
316 fmtlarge(infostr
, AvailMem(MEMF_ANY
|MEMF_TOTAL
));
322 temp
[screentitle_curChar
+ 1] = 's';
323 temp
[screentitle_curChar
+ 2] = ' ';
325 sprintf(title
, temp
, infostr
);
327 screentitle_curChar
= screentitle_curChar
+ strlen(infostr
);
328 strncpy(buffer
, title
, screentitle_curChar
);
329 strcpy(&buffer
[screentitle_curChar
], &temp
[(screentitle_curChar
+ 3) - strlen(infostr
)]);
330 strcpy(temp
, buffer
);
332 screentitle_TemplateLen
= screentitle_TemplateLen
+ strlen(infostr
);
336 temp
[screentitle_curChar
] = '?';
337 temp
[screentitle_curChar
+ 1] = '?';
338 temp
[screentitle_curChar
+ 2] = '?';
339 sprintf(title
, temp
);
344 switch (screentitle_TemplateLen
)
347 temp
[screentitle_curChar
]= '?';
348 temp
[screentitle_curChar
+ 1]= '?';
351 temp
[screentitle_curChar
] = '?';
353 sprintf(title
, temp
);
357 sprintf(title
, temp
);
362 /*** Methods ****************************************************************/
363 Object
*WandererPrefs__OM_NEW(Class
*CLASS
, Object
*self
, struct opSet
*message
)
365 self
= (Object
*) DoSuperMethodA(CLASS
, self
, (Msg
) message
);
367 D(bug("WandererPrefs::New()\n"));
373 D(bug("WandererPrefs::New - reloading\n"));
375 NewList(&data
->wpd_ViewSettings
);
377 data
->wpd_PROCESSING
= FALSE
;
379 DoMethod(self
, MUIM_WandererPrefs_Reload
);
385 IPTR
WandererPrefs__OM_DISPOSE(Class
*CLASS
, Object
*self
, Msg message
)
389 return DoSuperMethodA(CLASS
, self
, (Msg
)message
);
392 IPTR
WandererPrefs__OM_SET(Class
*CLASS
, Object
*self
, struct opSet
*message
)
395 const struct TagItem
*tstate
= message
->ops_AttrList
;
398 while ((tag
= NextTagItem(&tstate
)) != NULL
)
402 case MUIA_WandererPrefs_Processing
:
403 data
->wpd_PROCESSING
= (BOOL
)tag
->ti_Data
;
405 case MUIA_IconWindowExt_NetworkBrowser_Show
:
406 data
->wpd_ShowNetwork
= (LONG
)tag
->ti_Data
;
409 case MUIA_IconWindowExt_UserFiles_ShowFilesFolder
:
410 data
->wpd_ShowUserFiles
= (LONG
)tag
->ti_Data
;
413 case MUIA_IconWindowExt_ScreenTitle_String
:
414 strcpy(data
->wpd_ScreenTitleString
,tag
->ti_Data
);
415 //data->wpd_ScreenTitleString = (LONG)tag->ti_Data;
418 case MUIA_IconWindowExt_Toolbar_Enabled
:
419 data
->wpd_ToolbarEnabled
= (LONG
)tag
->ti_Data
;
422 case MUIA_IconWindowExt_Toolbar_NavigationMethod
:
423 data
->wpd_NavigationMethod
= (LONG
)tag
->ti_Data
;
428 return DoSuperMethodA(CLASS
, self
, (Msg
)message
);
431 IPTR
WandererPrefs__OM_GET(Class
*CLASS
, Object
*self
, struct opGet
*message
)
434 IPTR
*store
= message
->opg_Storage
;
437 switch (message
->opg_AttrID
)
439 case MUIA_WandererPrefs_Processing
:
440 *store
= (IPTR
)data
->wpd_PROCESSING
;
443 case MUIA_IconWindowExt_NetworkBrowser_Show
:
444 *store
= (IPTR
)data
->wpd_ShowNetwork
;
447 case MUIA_IconWindowExt_UserFiles_ShowFilesFolder
:
448 *store
= (IPTR
)data
->wpd_ShowUserFiles
;
451 case MUIA_IconWindowExt_ScreenTitle_String
:
452 *store
= (IPTR
)data
->wpd_ScreenTitleString
;
453 D(bug("[WANDERER.PREFS] WandererPrefs__GET@@@@@@@@@: SCREENTITLE= %s\n", data
->wpd_ScreenTitleString
));
456 case MUIA_IconWindowExt_Toolbar_NavigationMethod
:
457 *store
= (IPTR
)data
->wpd_NavigationMethod
;
460 case MUIA_IconWindowExt_Toolbar_Enabled
:
461 *store
= (IPTR
)data
->wpd_ToolbarEnabled
;
465 rv
= DoSuperMethodA(CLASS
, self
, (Msg
)message
);
471 BOOL
WandererPrefs_ProccessGlobalChunk(Class
*CLASS
, Object
*self
, struct TagItem32
*global_chunk
, IPTR chunk_size
)
475 int i
= 0, tag_count
= (chunk_size
/ sizeof(struct TagItem32
));
478 D(bug("[WANDERER.PREFS] WandererPrefs_ProccessGlobalChunk()\n"));
479 #warning "TODO: fix problems with endian-ness?"
481 for (i
= 0; i
< tag_count
; i
++)
485 /* prefs file is stored in little endian */
486 if (AROS_LE2LONG(global_chunk
[i
].ti_Tag
) == TAG_DONE
) cont
= FALSE
;
487 else SET(self
, AROS_LE2LONG(global_chunk
[i
].ti_Tag
), AROS_LE2LONG(global_chunk
[i
].ti_Data
));
494 BOOL
WPEditor_ProccessNetworkChunk(Class
*CLASS
, Object
*self
, UBYTE
*_viewSettings_Chunk
)
498 struct TagItem
*network_tags
=(struct TagItem32
*) _viewSettings_Chunk
;
499 SET(self
, AROS_LE2LONG(network_tags
[0].ti_Tag
), AROS_LE2LONG(network_tags
[0].ti_Data
));
504 BOOL
WPEditor_ProccessScreenTitleChunk(Class
*CLASS
, Object
*self
, UBYTE
*_ScreenTitle_Chunk
)
507 D(bug("[WANDERER.PREFS] WandererPrefs__ProccessScreenTitleChunk@@@@@@@@@: ScreenTitle Template = '%s'\n", _ScreenTitle_Chunk
));
508 char *displayed_screentitle
= _ScreenTitle_Chunk
;
509 char *userscreentitle
= NULL
;
511 if ((userscreentitle
= ProcessUserScreenTitle(_ScreenTitle_Chunk
)) != NULL
)
513 D(bug("[WANDERER.PREFS] WandererPrefs__ProccessScreenTitleChunk@@@@@@@@@: ProcessUserScreenTitle returns '%s'\n", userscreentitle
));
514 displayed_screentitle
= userscreentitle
;
517 SET(self
, MUIA_IconWindowExt_ScreenTitle_String
, displayed_screentitle
);
518 D(bug("[WANDERER.PREFS] WandererPrefs__ProccessScreenTitleChunk@@@@@@@@@: SCREENTITLE set\n"));
523 struct WandererPrefs_ViewSettingsNode
*WandererPrefs_FindViewSettingsNode(struct WandererPrefs_DATA
*data
, char *node_Name
)
525 struct WandererPrefs_ViewSettingsNode
*current_Node
= NULL
;
527 ForeachNode(&data
->wpd_ViewSettings
, current_Node
)
529 if ((strcmp(current_Node
->wpbn_Name
, node_Name
)) == 0) return current_Node
;
534 BOOL
WandererPrefs_ProccessViewSettingsChunk(Class
*CLASS
, Object
*self
, char *_viewSettings_ViewName
, UBYTE
*_viewSettings_Chunk
, IPTR chunk_size
)
538 D(bug("[WANDERER.PREFS] WandererPrefs_ProccessViewSettingsChunk()\n"));
539 BOOL background_node_found
= FALSE
;
540 struct WandererPrefs_ViewSettingsNode
*_viewSettings_Node
= NULL
;
542 _viewSettings_Node
= WandererPrefs_FindViewSettingsNode(data
, _viewSettings_ViewName
);
544 if (_viewSettings_Node
)
546 D(bug("[WANDERER.PREFS] WandererPrefs_ProccessViewSettingsChunk: Updating Existing node @ 0x%p\n", _viewSettings_Node
));
547 if (_viewSettings_Node
->wpbn_Background
) FreeVec(_viewSettings_Node
->wpbn_Background
);
551 D(bug("[WANDERER.PREFS] WandererPrefs_ProccessViewSettingsChunk: Creating new node for '%s'\n", _viewSettings_ViewName
));
552 _viewSettings_Node
= AllocMem(sizeof(struct WandererPrefs_ViewSettingsNode
), MEMF_CLEAR
|MEMF_PUBLIC
);
554 _viewSettings_Node
->wpbn_Name
= AllocVec(strlen(_viewSettings_ViewName
) + 1, MEMF_CLEAR
|MEMF_PUBLIC
);
555 strcpy(_viewSettings_Node
->wpbn_Name
, _viewSettings_ViewName
);
557 _viewSettings_Node
->wpbn_NotifyObject
= NotifyObject
, End
;
559 AddTail(&data
->wpd_ViewSettings
, &_viewSettings_Node
->wpbn_Node
);
562 _viewSettings_Node
->wpbn_Background
=(IPTR
) AllocVec(strlen(_viewSettings_Chunk
) + 1, MEMF_CLEAR
|MEMF_PUBLIC
);
563 strcpy((char *)_viewSettings_Node
->wpbn_Background
, _viewSettings_Chunk
);
564 D(bug("[WANDERER.PREFS] WandererPrefs_ProccessViewSettingsChunk: NAME BACKGROUND= %s\n",_viewSettings_Chunk
));
565 SET(_viewSettings_Node
->wpbn_NotifyObject
, MUIA_Background
, _viewSettings_Chunk
);
567 if (chunk_size
> (strlen(_viewSettings_Chunk
) + 1))
569 D(bug("[WANDERER.PREFS] WandererPrefs_ProccessViewSettingsChunk: Chunk has options Tag data ..\n"));
570 UBYTE _viewSettings_TagOffset
= ((strlen(_viewSettings_Chunk
) + 1)/4);
572 if ((_viewSettings_TagOffset
* 4) != (strlen(_viewSettings_Chunk
) + 1))
574 _viewSettings_TagOffset
= (_viewSettings_TagOffset
+ 1) * 4;
575 D(bug("[WPEditor] WPEditor_ProccessBackgroundChunk: String length unalined - rounding up (length %d, rounded %d) \n", strlen(_viewSettings_Chunk
) + 1, _viewSettings_TagOffset
));
579 _viewSettings_TagOffset
= _viewSettings_TagOffset
* 4;
580 D(bug("[WPEditor] WPEditor_ProccessBackgroundChunk: String length doesnt need aligned (length %d) \n", strlen(_viewSettings_Chunk
) + 1));
583 IPTR _viewSettings_TagCount
= ((chunk_size
- _viewSettings_TagOffset
)/sizeof(struct TagItem32
));
585 D(bug("[WANDERER.PREFS] WandererPrefs_ProccessViewSettingsChunk: %d Tags at offset %d ..\n", _viewSettings_TagCount
, _viewSettings_TagOffset
));
587 if (_viewSettings_Node
->wpbn_Options
!= NULL
)
589 D(bug("[WANDERER.PREFS] WandererPrefs_ProccessViewSettingsChunk: Freeing old background tag's @ 0x%p\n", _viewSettings_Node
->wpbn_Options
));
590 FreeVec(_viewSettings_Node
->wpbn_Options
);
591 _viewSettings_Node
->wpbn_Options
= NULL
;
594 _viewSettings_Node
->wpbn_Options
= AllocVec((_viewSettings_TagCount
+ 1) * sizeof(struct TagItem32
), MEMF_CLEAR
|MEMF_PUBLIC
);
595 D(bug("[WANDERER.PREFS] WandererPrefs_ProccessViewSettingsChunk: New tag storage @ 0x%p\n", _viewSettings_Node
->wpbn_Options
));
597 CopyMem(_viewSettings_Chunk
+ _viewSettings_TagOffset
, _viewSettings_Node
->wpbn_Options
, (_viewSettings_TagCount
) * sizeof(struct TagItem32
));
598 D(bug("[WANDERER.PREFS] WandererPrefs_ProccessViewSettingsChunk: Tags copied to storage \n"));
600 _viewSettings_Node
->wpbn_Options
[_viewSettings_TagCount
].ti_Tag
= TAG_DONE
;
603 for (i
= 0; i
< _viewSettings_TagCount
; i
++)
605 D(bug("[WANDERER.PREFS] WandererPrefs_ProccessViewSettingsChunk: Setting Tag 0x%p Value %d\n", AROS_LE2LONG(_viewSettings_Node
->wpbn_Options
[i
].ti_Tag
), AROS_LE2LONG(_viewSettings_Node
->wpbn_Options
[i
].ti_Data
)));
606 SET(_viewSettings_Node
->wpbn_NotifyObject
, AROS_LE2LONG(_viewSettings_Node
->wpbn_Options
[i
].ti_Tag
), AROS_LE2LONG(_viewSettings_Node
->wpbn_Options
[i
].ti_Data
));
612 IPTR WandererPrefs__MUIM_WandererPrefs_Reload
614 Class
*CLASS
, Object
*self
, Msg message
617 struct ContextNode
*context
;
618 struct IFFHandle
*handle
;
621 IPTR iff_parse_mode
= IFFPARSE_SCAN
;
622 UBYTE chunk_buffer
[IFF_CHUNK_BUFFER_SIZE
];
624 D(bug("[WANDERER.PREFS] WandererPrefs__MUIM_WandererPrefs_Reload()\n"));
626 if (!(handle
= AllocIFF()))
629 handle
->iff_Stream
= (IPTR
)Open("ENV:SYS/Wanderer.prefs", MODE_OLDFILE
);
631 if (!handle
->iff_Stream
)
634 InitIFFasDOS(handle
);
636 if ((error
= OpenIFF(handle
, IFFF_READ
)) == 0)
638 if ((error
= StopChunk(handle
, ID_PREF
, ID_WANDR
)) == 0)
640 SET(self
, MUIA_WandererPrefs_Processing
, TRUE
);
643 if ((error
= ParseIFF(handle
, iff_parse_mode
)) == 0)
645 context
= CurrentChunk(handle
);
646 iff_parse_mode
= IFFPARSE_STEP
;
648 D(bug("[WANDERER.PREFS] WandererPrefs__MUIM_WandererPrefs_Reload: Context 0x%p\n", context
));
650 if ((error
=ReadChunkBytes(handle
, chunk_buffer
, IFF_CHUNK_BUFFER_SIZE
)))
652 D(bug("[WANDERER.PREFS] WandererPrefs__MUIM_WandererPrefs_Reload: ReadChunkBytes() Chunk matches Prefs Header size ..\n"));
653 struct WandererPrefsIFFChunkHeader
*this_header
=(struct WandererPrefsIFFChunkHeader
*) chunk_buffer
;
654 char *this_chunk_name
= NULL
;
655 IPTR this_chunk_size
= AROS_LE2LONG(this_header
->wpIFFch_ChunkSize
);
657 if ((this_chunk_name
= AllocVec(strlen(this_header
->wpIFFch_ChunkType
) +1,MEMF_ANY
|MEMF_CLEAR
)))
659 strcpy(this_chunk_name
, this_header
->wpIFFch_ChunkType
);
660 D(bug("[WANDERER.PREFS] WandererPrefs__MUIM_WandererPrefs_Reload: Prefs Header for '%s' data size %d bytes\n", this_chunk_name
, this_chunk_size
));
662 if ((error
= ParseIFF(handle
, IFFPARSE_STEP
)) == IFFERR_EOC
)
664 D(bug("[WANDERER.PREFS] WandererPrefs__MUIM_WandererPrefs_Reload: End of header chunk ..\n"));
666 if ((error
= ParseIFF(handle
, IFFPARSE_STEP
)) == 0)
668 context
= CurrentChunk(handle
);
670 D(bug("[WANDERER.PREFS] WandererPrefs__MUIM_WandererPrefs_Reload: Context 0x%p\n", context
));
672 error
= ReadChunkBytes
679 if (error
== this_chunk_size
)
681 D(bug("[WANDERER.PREFS] WandererPrefs__MUIM_WandererPrefs_Reload: ReadChunkBytes() Chunk matches Prefs Data size .. (%d)\n", error
));
682 if ((strcmp(this_chunk_name
, "wanderer:global")) == 0)
684 D(bug("[WANDERER.PREFS] WandererPrefs__MUIM_WandererPrefs_Reload: Process data for wanderer global chunk ..\n"));
685 WandererPrefs_ProccessGlobalChunk(CLASS
, self
,(struct TagItem32
*) chunk_buffer
, this_chunk_size
);
687 else if ((strcmp(this_chunk_name
, "wanderer:network")) == 0)
689 D(bug("[WPEditor] WPEditor__MUIM_PrefsEditor_ImportFH: Process data for wanderer network config chunk ..\n"));
690 WPEditor_ProccessNetworkChunk(CLASS
, self
, chunk_buffer
);
692 else if ((strcmp(this_chunk_name
, "wanderer:screentitle")) == 0)
694 D(bug("[WPEditor] WPEditor__MUIM_PrefsEditor_ImportFH: Process data for wanderer screentitle config chunk ..size=%d\n", error
));
695 D(bug("[WPEditor] WPEditor__MUIM_PrefsEditor_ImportFH: Process data for wanderer screentitle STRING= %s\n", chunk_buffer
));
696 WPEditor_ProccessScreenTitleChunk(CLASS
, self
, chunk_buffer
);
699 else if ((strncmp(this_chunk_name
, "wanderer:viewsettings", strlen("wanderer:viewsettings"))) == 0)
701 char *view_name
= this_chunk_name
+ strlen("wanderer:viewsettings") + 1;
702 D(bug("[WANDERER.PREFS] WandererPrefs__MUIM_WandererPrefs_Reload: Process data for wanderer background chunk '%s'..\n", view_name
));
703 WandererPrefs_ProccessViewSettingsChunk(CLASS
, self
, view_name
, chunk_buffer
, this_chunk_size
);
705 }//END if (error == this_chunk_size)
706 if ((error
= ParseIFF(handle
, IFFPARSE_STEP
)) == IFFERR_EOC
)
708 D(bug("[WANDERER.PREFS] WandererPrefs__MUIM_WandererPrefs_Reload: End of Data chunk ..\n"));
710 }//END if ((error = ParseIFF(handle, IFFPARSE_STEP)) == 0)
711 }//END if ((error = ParseIFF(handle, IFFPARSE_STEP)) == IFFERR_EOC)
712 }//END if ((this_chunk_name = AllocVec(strlen(this_header->wpIFFch_ChunkType) +1,MEMF_ANY|MEMF_CLEAR)))
713 }//END if ((error=ReadChunkBytes(handle, chunk_buffer, IFF_CHUNK_BUFFER_SIZE)))
717 D(bug("[WANDERER.PREFS] ParseIFF() failed, returncode %ld!\n", error
));
719 }//END if ((error = ParseIFF(handle, iff_parse_mode)) == 0)
721 } while (error
!= IFFERR_EOF
);
722 SET(self
, MUIA_WandererPrefs_Processing
, FALSE
);
726 D(bug("[WANDERER.PREFS] StopChunk() failed, returncode %ld!\n", error
));
734 D(bug("[WANDERER.PREFS] Failed to open stream!, returncode %ld!\n", error
));
735 //ShowError(_(MSG_CANT_OPEN_STREAM));
737 }//END if ((error = StopChunk(handle, ID_PREF, ID_WANDR)) == 0)
739 Close((APTR
)handle
->iff_Stream
);
747 IPTR WandererPrefs__MUIM_WandererPrefs_ViewSettings_GetNotifyObject
749 Class
*CLASS
, Object
*self
, struct MUIP_WandererPrefs_ViewSettings_GetNotifyObject
*message
753 struct WandererPrefs_ViewSettingsNode
*current_Node
= NULL
;
755 D(bug("[WANDERER.PREFS] WandererPrefs__MUIM_WandererPrefs_ViewSettings_GetNotifyObject()\n"));
757 if ((current_Node
= WandererPrefs_FindViewSettingsNode(data
, message
->Background_Name
)))
759 D(bug("[WANDERER.PREFS] WandererPrefs__MUIM_WandererPrefs_ViewSettings_GetNotifyObject: Returning Object for existing record\n"));
760 return (IPTR
) current_Node
->wpbn_NotifyObject
;
763 current_Node
= AllocMem(sizeof(struct WandererPrefs_ViewSettingsNode
), MEMF_CLEAR
|MEMF_PUBLIC
);
764 D(bug("[WANDERER.PREFS] WandererPrefs__MUIM_WandererPrefs_ViewSettings_GetNotifyObject: Created new node ..\n"));
766 current_Node
->wpbn_Name
= AllocVec(strlen(message
->Background_Name
) + 1, MEMF_CLEAR
|MEMF_PUBLIC
);
767 strcpy(current_Node
->wpbn_Name
, message
->Background_Name
);
769 current_Node
->wpbn_NotifyObject
= NotifyObject
, End
;
771 AddTail(&data
->wpd_ViewSettings
, ¤t_Node
->wpbn_Node
);
773 D(bug("[WANDERER.PREFS] WandererPrefs__MUIM_WandererPrefs_ViewSettings_GetNotifyObject: Notify Object @ 0x%p\n", current_Node
->wpbn_NotifyObject
));
775 return (IPTR
) current_Node
->wpbn_NotifyObject
;
778 #warning "TODO: Replace with propper 64bit check"
779 /* 32bit replacements for utility.library tag funcs */
780 struct TagItem32
* NextTag32Item(struct TagItem32
** tagListPtr
)
782 if(!(*tagListPtr
)) return NULL
;
786 switch ((*tagListPtr
)->ti_Tag
)
792 (*tagListPtr
) = NULL
;
796 (*tagListPtr
) += (*tagListPtr
)->ti_Data
+ 1;
800 /* Use post-increment (return will return the current value and
801 then tagListPtr will be incremented) */
802 return (struct TagItem32
*)(*tagListPtr
)++;
809 struct TagItem32
* FindTag32Item(ULONG tagValue
, struct TagItem32
*tagList
)
811 struct TagItem32
*tag
;
812 const struct TagItem32
*tagptr
= tagList
;
814 while ((tag
= NextTag32Item(&tagptr
)))
816 if (tag
->ti_Tag
== tagValue
) return tag
;
823 ULONG
GetTag32Data(ULONG tagValue
, ULONG defaultVal
, struct TagItem32
*tagList
)
825 struct TagItem32
*ti
= NULL
;
827 if ((tagList
!= NULL
) && (ti
= FindTag32Item(tagValue
, tagList
)))
833 IPTR WandererPrefs__MUIM_WandererPrefs_ViewSettings_GetAttribute
835 Class
*CLASS
, Object
*self
, struct MUIP_WandererPrefs_ViewSettings_GetAttribute
*message
839 struct WandererPrefs_ViewSettingsNode
*current_Node
= NULL
;
841 D(bug("[WANDERER.PREFS] WandererPrefs__MUIM_WandererPrefs_ViewSettings_GetAttribute()\n"));
843 if ((current_Node
= WandererPrefs_FindViewSettingsNode(data
, message
->Background_Name
)) != NULL
)
845 D(bug("[WANDERER.PREFS] WandererPrefs__MUIM_WandererPrefs_ViewSettings_GetAttribute: Found Background Record ..\n"));
846 if (message
->AttributeID
== MUIA_Background
)
848 if (current_Node
->wpbn_Background
) return current_Node
->wpbn_Background
;
850 else if (current_Node
->wpbn_Options
)
852 if (sizeof(IPTR
) > 4)
854 D(bug("[WANDERER.PREFS] WandererPrefs__MUIM_WandererPrefs_ViewSettings_GetAttribute: Using internal GetTag32Data()\n"));
855 ULONG retVal
= GetTag32Data(message
->AttributeID
, (ULONG
)-1, current_Node
->wpbn_Options
);
856 if (retVal
!= (ULONG
)-1)
861 D(bug("[WANDERER.PREFS] WandererPrefs__MUIM_WandererPrefs_ViewSettings_GetAttribute: Using utility.library->GetTagData()\n"));
862 return (IPTR
)GetTagData(message
->AttributeID
, (IPTR
)-1, current_Node
->wpbn_Options
);
869 /*** Setup ******************************************************************/
872 WandererPrefs
, NULL
, MUIC_Notify
, NULL
,
873 OM_NEW
, struct opSet
*,
875 OM_SET
, struct opSet
*,
876 OM_GET
, struct opGet
*,
877 MUIM_WandererPrefs_Reload
, Msg
,
878 MUIM_WandererPrefs_ViewSettings_GetNotifyObject
, struct MUIP_WandererPrefs_ViewSettings_GetNotifyObject
*,
879 MUIM_WandererPrefs_ViewSettings_GetAttribute
, struct MUIP_WandererPrefs_ViewSettings_GetAttribute
*