add casts to zune macros to silence some warnings
[tangerine.git] / workbench / system / Wanderer / wandererprefs.c
blob2979864fa9f5fffb7623098ae87ebed2c05c28fb
1 /*
2 Copyright 2004-2007, The AROS Development Team. All rights reserved.
3 $Id$
4 */
5 #define DEBUG 0
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>
24 #include <string.h>
26 #include "wandererprefs.h"
27 #include "../../libs/muimaster/classes/iconlist_attributes.h"
28 #include "iconwindow_attributes.h"
29 #include "support.h"
30 #include "locale.h"
31 #include "version.h"
33 #include <prefs/prefhdr.h>
34 #include <prefs/wanderer.h>
36 struct TagItem32 {
37 ULONG ti_Tag;
38 ULONG ti_Data;
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 ULONG wpd_IconListMode;
51 ULONG wpd_IconTextMode;
52 ULONG wpd_IconTextMaxLen;
54 ULONG wpd_MultiLine;
55 ULONG wpd_MultiLineOnFocus;
57 struct List wpd_ViewSettings;
60 struct WandererPrefs_ViewSettingsNode
62 struct Node wpbn_Node;
63 char *wpbn_Name;
64 IPTR wpbn_Background;
65 struct TagItem32 *wpbn_Options;
66 Object *wpbn_NotifyObject;
69 /*** Macros *****************************************************************/
70 #define SETUP_INST_DATA struct WandererPrefs_DATA *data = INST_DATA(CLASS, self)
72 /*** Utility Functions ******************************************************/
73 BOOL SetString(STRPTR *dst, STRPTR src)
75 if (src != NULL)
77 if ( (*dst == NULL) || (strcmp(src, *dst) != 0) )
79 STRPTR tmp = StrDup(src);
81 if (tmp != NULL)
83 FreeVec(*dst);
84 *dst = tmp;
86 return TRUE;
91 return FALSE;
93 static unsigned char strtochar(STRPTR st)
95 return *st++;
98 /******** code from workbench/c/Info.c *******************/
99 static void fmtlarge(UBYTE *buf, ULONG num)
101 UQUAD d;
102 UBYTE ch;
103 struct
105 ULONG val;
106 LONG dec;
107 } array =
109 num,
113 if (num >= 1073741824)
115 array.val = num >> 30;
116 d = ((UQUAD)num * 10 + 536870912) / 1073741824;
117 array.dec = d % 10;
118 //ch = 'G';
119 ch = strtochar((STRPTR)_(MSG_MEM_G));
121 else if (num >= 1048576)
123 array.val = num >> 20;
124 d = ((UQUAD)num * 10 + 524288) / 1048576;
125 array.dec = d % 10;
126 //ch = 'M';
127 ch = strtochar((STRPTR)_(MSG_MEM_M));
129 else if (num >= 1024)
131 array.val = num >> 10;
132 d = (num * 10 + 512) / 1024;
133 array.dec = d % 10;
134 //ch = 'K';
135 ch = strtochar((STRPTR)_(MSG_MEM_K));
137 else
139 array.val = num;
140 array.dec = 0;
141 d = 0;
142 //ch = 'B';
143 ch = strtochar((STRPTR)_(MSG_MEM_B));
146 if (!array.dec && (d > array.val * 10))
148 array.val++;
151 RawDoFmt(array.dec ? "%lu.%lu" : "%lu", &array, NULL, buf);
152 while (*buf) { buf++; }
153 *buf++ = ch;
154 *buf = '\0';
157 /* Case-insensitive FindName()
158 * code from workbench/c/Version.c
160 static
161 struct Node *findname(struct List *list, CONST_STRPTR name)
163 struct Node *node;
165 ForeachNode(list, node)
167 if (!Stricmp(node->ln_Name, (STRPTR) name))
169 return node;
173 return NULL;
176 /*ProcessUserScreenTitle(): pattern matching of user screentitle...;*/
177 STRPTR ProcessUserScreenTitle(STRPTR screentitlestr)
179 /*Work in progress :-)
182 D(bug("[Wanderer] ProcessUserScreenTitle(),EXTERN screentitlestr=%s\n", screentitlestr));
184 if (screentitlestr==NULL)
186 D(bug("[Wanderer] ProcessUserScreenTitle(),EXTERN screentitle=NULL\n"));
187 return screentitlestr;
190 int screentitleleng = strlen(screentitlestr);
192 if (screentitleleng<1)
194 D(bug("[Wanderer] ProcessUserScreenTitle(),EXTERN screentitleleng=%d\n", screentitleleng));
195 return screentitleleng;
198 STATIC char title[256];
199 char temp[256], buffer[256];
200 char infostr[10];
202 strcpy(temp,screentitlestr);
205 int i;
206 for (i=0; i<screentitleleng; i++)
208 if (temp[i]=='%')
211 if (screentitleleng>=3)
213 BOOL found=FALSE;
215 if (strncmp(temp+i,"%wv",3)==0)
217 struct Library *MyLibrary;
218 MyLibrary = (struct Library *) findname(&SysBase->LibList, "workbench.library");
220 sprintf(infostr,"%ld",MyLibrary->lib_Version);
221 sprintf(infostr+strlen(infostr),".");
222 sprintf(infostr+strlen(infostr),"%ld",MyLibrary->lib_Revision);
223 found=TRUE;
226 if (strncmp(temp+i,"%ov",3)==0)
228 struct Library *AROSBase=OpenLibrary(AROSLIBNAME, AROSLIBVERSION);
229 if (AROSBase!=NULL)
231 UWORD ver, kickrev;
232 ArosInquire(AI_ArosVersion, (IPTR) &ver,
233 TAG_DONE
235 sprintf(infostr,"%d", ver);
236 CloseLibrary(AROSBase);
237 found=TRUE;
242 if (strncmp(temp+i,"%os",3)==0)
244 struct Library *AROSBase=OpenLibrary(AROSLIBNAME, AROSLIBVERSION);
245 if (AROSBase!=NULL)
247 ULONG ver, rev;
248 ArosInquire(AI_ArosReleaseMajor, (IPTR) &ver,
249 AI_ArosReleaseMinor,(IPTR) &rev,
250 TAG_DONE
252 sprintf(infostr,"%ld", ver);
253 sprintf(infostr+strlen(infostr),".");
254 sprintf(infostr+strlen(infostr),"%ld",rev);
255 CloseLibrary(AROSBase);
256 found=TRUE;
260 if (strncmp(temp+i,"%wb",3)==0)
262 struct Library *AROSBase=OpenLibrary(AROSLIBNAME, AROSLIBVERSION);
263 if (AROSBase!=NULL)
265 ULONG ver, rev;
266 ArosInquire(AI_ArosReleaseMajor, (IPTR) &ver,
267 AI_ArosReleaseMinor,(IPTR) &rev,
268 TAG_DONE
270 sprintf(infostr,"%d", WANDERERVERS);
271 sprintf(infostr+strlen(infostr),".");
272 sprintf(infostr+strlen(infostr),"%d",WANDERERREV);
273 CloseLibrary(AROSBase);
274 found=TRUE;
279 if (strncmp(temp+i,"%pc",3)==0)
281 fmtlarge(infostr,AvailMem(MEMF_CHIP));
282 found=TRUE;
286 if (strncmp(temp+i,"%pf",3)==0)
288 fmtlarge(infostr,AvailMem(MEMF_FAST));
289 found=TRUE;
292 if (strncmp(temp+i,"%pt",3)==0)
294 fmtlarge(infostr,AvailMem(MEMF_ANY));
295 found=TRUE;
298 if (strncmp(temp+i,"%PC",3)==0)
300 fmtlarge(infostr,AvailMem(MEMF_CHIP|MEMF_TOTAL));
301 found=TRUE;
305 if (strncmp(temp+i,"%PF",3)==0)
307 fmtlarge(infostr,AvailMem(MEMF_FAST|MEMF_TOTAL));
308 found=TRUE;
311 if (strncmp(temp+i,"%PT",3)==0)
313 fmtlarge(infostr,AvailMem(MEMF_ANY|MEMF_TOTAL));
314 found=TRUE;
317 if (found)
320 temp[i+1]='s';
321 temp[i+2]=' ';
323 sprintf(title,temp, infostr);
325 i=i+strlen(infostr);
326 strncpy(buffer, title, i);
327 strcpy(&buffer[i],&temp[(i+3)-strlen(infostr)]);
328 strcpy(temp, buffer);
330 screentitleleng=screentitleleng+strlen(infostr);
332 else
334 temp[i]='?';
335 temp[i+1]='?';
336 temp[i+2]='?';
337 sprintf(title,temp);
340 else
342 switch (screentitleleng)
344 case 2:
345 temp[i]='?';
346 temp[i+1]='?';
347 break;
348 case 1:
349 temp[i]='?';
351 sprintf(title,temp);
356 sprintf(title,temp);
358 return title;
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"));
369 if (self != NULL)
371 SETUP_INST_DATA;
373 D(bug("WandererPrefs::New - reloading\n"));
375 NewList(&data->wpd_ViewSettings);
376 DoMethod(self, MUIM_WandererPrefs_Reload);
379 return self;
382 IPTR WandererPrefs__OM_DISPOSE(Class *CLASS, Object *self, Msg message)
384 //SETUP_INST_DATA;
386 return DoSuperMethodA(CLASS, self, (Msg)message);
389 IPTR WandererPrefs__OM_SET(Class *CLASS, Object *self, struct opSet *message)
391 SETUP_INST_DATA;
392 const struct TagItem *tstate = message->ops_AttrList;
393 struct TagItem *tag;
395 while ((tag = NextTagItem(&tstate)) != NULL)
397 switch (tag->ti_Tag)
399 case MUIA_IconWindowExt_NetworkBrowser_Show:
400 data->wpd_ShowNetwork = (LONG)tag->ti_Data;
401 break;
403 case MUIA_IconWindowExt_UserFiles_ShowFilesFolder:
404 data->wpd_ShowUserFiles = (LONG)tag->ti_Data;
405 break;
407 case MUIA_IconWindowExt_ScreenTitle_String:
408 strcpy(data->wpd_ScreenTitleString,tag->ti_Data);
409 //data->wpd_ScreenTitleString = (LONG)tag->ti_Data;
410 break;
412 case MUIA_IconWindowExt_Toolbar_Enabled:
413 data->wpd_ToolbarEnabled = (LONG)tag->ti_Data;
414 break;
416 case MUIA_IconWindowExt_Toolbar_NavigationMethod:
417 data->wpd_NavigationMethod = (LONG)tag->ti_Data;
418 break;
420 /* The Following attributes will be moved to the ViewSettings Specific Chunks */
422 case MUIA_IconList_IconListMode:
423 data->wpd_IconListMode = (LONG)tag->ti_Data;
424 break;
426 case MUIA_IconList_LabelText_Mode:
427 data->wpd_IconTextMode = (ULONG)tag->ti_Data;
428 break;
430 case MUIA_IconList_LabelText_MaxLineLen:
431 data->wpd_IconTextMaxLen = (ULONG)tag->ti_Data;
432 break;
434 case MUIA_IconList_LabelText_MultiLine:
435 data->wpd_MultiLine = (ULONG)tag->ti_Data;
436 break;
438 case MUIA_IconList_LabelText_MultiLineOnFocus:
439 data->wpd_MultiLineOnFocus = (ULONG)tag->ti_Data;
440 break;
444 return DoSuperMethodA(CLASS, self, (Msg)message);
447 IPTR WandererPrefs__OM_GET(Class *CLASS, Object *self, struct opGet *message)
449 SETUP_INST_DATA;
450 IPTR *store = message->opg_Storage;
451 IPTR rv = TRUE;
454 switch (message->opg_AttrID)
456 case MUIA_IconWindowExt_NetworkBrowser_Show:
457 *store = (IPTR)data->wpd_ShowNetwork;
458 break;
460 case MUIA_IconWindowExt_UserFiles_ShowFilesFolder:
461 *store = (IPTR)data->wpd_ShowUserFiles;
462 break;
464 case MUIA_IconWindowExt_ScreenTitle_String:
465 *store = (IPTR)data->wpd_ScreenTitleString;
466 D(bug("[WANDERER.PREFS] WandererPrefs__GET@@@@@@@@@: SCREENTITLE= %s\n", data->wpd_ScreenTitleString));
467 break;
469 case MUIA_IconWindowExt_Toolbar_NavigationMethod:
470 *store = (IPTR)data->wpd_NavigationMethod;
471 break;
473 case MUIA_IconWindowExt_Toolbar_Enabled:
474 *store = (IPTR)data->wpd_ToolbarEnabled;
475 break;
477 case MUIA_IconList_IconListMode:
478 *store = (IPTR)data->wpd_IconListMode;
479 break;
481 case MUIA_IconList_LabelText_Mode:
482 *store = (IPTR)data->wpd_IconTextMode;
483 break;
485 case MUIA_IconList_LabelText_MaxLineLen:
486 *store = (IPTR)data->wpd_IconTextMaxLen;
487 break;
489 case MUIA_IconList_LabelText_MultiLine:
490 *store = (IPTR)data->wpd_MultiLine;
491 break;
493 case MUIA_IconList_LabelText_MultiLineOnFocus:
494 *store = (IPTR)data->wpd_MultiLineOnFocus;
495 break;
497 default:
498 rv = DoSuperMethodA(CLASS, self, (Msg)message);
501 return rv;
504 BOOL WandererPrefs_ProccessGlobalChunk(Class *CLASS, Object *self, struct TagItem32 *global_chunk)
506 //SETUP_INST_DATA;
508 int i = 0;
509 BOOL cont = TRUE;
511 D(bug("[WANDERER.PREFS] WandererPrefs_ProccessGlobalChunk()\n"));
512 #warning "TODO: fix problems with endian-ness?"
514 for (i =0; i < WP_GLOBALTAGCOUNT; i++)
516 if (cont)
518 /* prefs file is stored in little endian */
519 if (AROS_LE2LONG(global_chunk[i].ti_Tag) == TAG_DONE) cont = FALSE;
520 else SET(self, AROS_LE2LONG(global_chunk[i].ti_Tag), AROS_LE2LONG(global_chunk[i].ti_Data));
524 return TRUE;
527 BOOL WPEditor_ProccessNetworkChunk(Class *CLASS, Object *self, UBYTE *_viewSettings_Chunk)
529 //SETUP_INST_DATA;
531 struct TagItem *network_tags =(struct TagItem32 *) _viewSettings_Chunk;
532 SET(self, AROS_LE2LONG(network_tags[0].ti_Tag), AROS_LE2LONG(network_tags[0].ti_Data));
534 return TRUE;
537 BOOL WPEditor_ProccessScreenTitleChunk(Class *CLASS, Object *self, UBYTE *_ScreenTitle_Chunk)
539 //SETUP_INST_DATA;
542 D(bug("[WANDERER.PREFS] WandererPrefs__ProccessScreenTitleChunk@@@@@@@@@: SCREENTITLE to write= %s\n", _ScreenTitle_Chunk));
544 char *userscreentitle= ProcessUserScreenTitle(_ScreenTitle_Chunk);
545 D(bug("[WANDERER.PREFS] WandererPrefs__ProccessScreenTitleChunk@@@@@@@@@: SCREENTITLE returned= %s\n", userscreentitle));
547 if (userscreentitle==NULL)
548 SET(self, MUIA_IconWindowExt_ScreenTitle_String,_ScreenTitle_Chunk);
549 else
550 SET(self, MUIA_IconWindowExt_ScreenTitle_String,userscreentitle);
551 D(bug("[WANDERER.PREFS] WandererPrefs__ProccessScreenTitleChunk@@@@@@@@@: SCREENTITLE setted\n"));
553 return TRUE;
556 struct WandererPrefs_ViewSettingsNode *WandererPrefs_FindViewSettingsNode(struct WandererPrefs_DATA *data, char *node_Name)
558 struct WandererPrefs_ViewSettingsNode *current_Node = NULL;
560 ForeachNode(&data->wpd_ViewSettings, current_Node)
562 if ((strcmp(current_Node->wpbn_Name, node_Name)) == 0) return current_Node;
564 return NULL;
567 BOOL WandererPrefs_ProccessViewSettingsChunk(Class *CLASS, Object *self, char *_viewSettings_ViewName, UBYTE *_viewSettings_Chunk, IPTR chunk_size)
569 SETUP_INST_DATA;
571 D(bug("[WANDERER.PREFS] WandererPrefs_ProccessViewSettingsChunk()\n"));
572 BOOL background_node_found = FALSE;
573 struct WandererPrefs_ViewSettingsNode *_viewSettings_Node = NULL;
575 _viewSettings_Node = WandererPrefs_FindViewSettingsNode(data, _viewSettings_ViewName);
577 if (_viewSettings_Node)
579 D(bug("[WANDERER.PREFS] WandererPrefs_ProccessViewSettingsChunk: Updating Existing node @ %x\n", _viewSettings_Node));
580 if (_viewSettings_Node->wpbn_Background) FreeVec(_viewSettings_Node->wpbn_Background);
582 else
584 D(bug("[WANDERER.PREFS] WandererPrefs_ProccessViewSettingsChunk: Creating new node for '%s'\n", _viewSettings_ViewName));
585 _viewSettings_Node = AllocMem(sizeof(struct WandererPrefs_ViewSettingsNode), MEMF_CLEAR|MEMF_PUBLIC);
587 _viewSettings_Node->wpbn_Name = AllocVec(strlen(_viewSettings_ViewName) + 1, MEMF_CLEAR|MEMF_PUBLIC);
588 strcpy(_viewSettings_Node->wpbn_Name, _viewSettings_ViewName);
590 _viewSettings_Node->wpbn_NotifyObject = NotifyObject, End;
592 AddTail(&data->wpd_ViewSettings, &_viewSettings_Node->wpbn_Node);
595 _viewSettings_Node->wpbn_Background =(IPTR) AllocVec(strlen(_viewSettings_Chunk) + 1, MEMF_CLEAR|MEMF_PUBLIC);
596 strcpy((char *)_viewSettings_Node->wpbn_Background, _viewSettings_Chunk);
597 D(bug("[WANDERER.PREFS] WandererPrefs_ProccessViewSettingsChunk: NAME BACKGROUND= %s\n",_viewSettings_Chunk));
598 SET(_viewSettings_Node->wpbn_NotifyObject, MUIA_Background, _viewSettings_Chunk);
600 if (chunk_size > (strlen(_viewSettings_Chunk) + 1))
602 D(bug("[WANDERER.PREFS] WandererPrefs_ProccessViewSettingsChunk: Chunk has options Tag data ..\n"));
603 UBYTE _viewSettings_TagOffset = ((strlen(_viewSettings_Chunk) + 1)/4);
605 if ((_viewSettings_TagOffset * 4) != (strlen(_viewSettings_Chunk) + 1))
607 _viewSettings_TagOffset = (_viewSettings_TagOffset + 1) * 4;
608 D(bug("[WPEditor] WPEditor_ProccessBackgroundChunk: String length unalined - rounding up (length %d, rounded %d) \n", strlen(_viewSettings_Chunk) + 1, _viewSettings_TagOffset ));
610 else
612 _viewSettings_TagOffset = _viewSettings_TagOffset * 4;
613 D(bug("[WPEditor] WPEditor_ProccessBackgroundChunk: String length doesnt need aligned (length %d) \n", strlen(_viewSettings_Chunk) + 1));
616 IPTR _viewSettings_TagCount = ((chunk_size - _viewSettings_TagOffset)/sizeof(struct TagItem32));
618 D(bug("[WANDERER.PREFS] WandererPrefs_ProccessViewSettingsChunk: %d Tags at offset %d ..\n", _viewSettings_TagCount, _viewSettings_TagOffset));
620 if (_viewSettings_Node->wpbn_Options != NULL)
622 D(bug("[WANDERER.PREFS] WandererPrefs_ProccessViewSettingsChunk: Freeing old background tag's @ %x\n", _viewSettings_Node->wpbn_Options));
623 FreeVec(_viewSettings_Node->wpbn_Options);
624 _viewSettings_Node->wpbn_Options = NULL;
627 _viewSettings_Node->wpbn_Options = AllocVec((_viewSettings_TagCount + 1) * sizeof(struct TagItem32), MEMF_CLEAR|MEMF_PUBLIC);
628 D(bug("[WANDERER.PREFS] WandererPrefs_ProccessViewSettingsChunk: New tag storage @ %x\n", _viewSettings_Node->wpbn_Options));
630 CopyMem(_viewSettings_Chunk + _viewSettings_TagOffset, _viewSettings_Node->wpbn_Options, (_viewSettings_TagCount) * sizeof(struct TagItem32));
631 D(bug("[WANDERER.PREFS] WandererPrefs_ProccessViewSettingsChunk: Tags copied to storage \n"));
633 _viewSettings_Node->wpbn_Options[_viewSettings_TagCount].ti_Tag = TAG_DONE;
635 int i = 0;
636 for (i = 0; i < _viewSettings_TagCount; i++)
638 D(bug("[WANDERER.PREFS] WandererPrefs_ProccessViewSettingsChunk: Setting Tag %x Value %d\n", AROS_LE2LONG(_viewSettings_Node->wpbn_Options[i].ti_Tag), AROS_LE2LONG(_viewSettings_Node->wpbn_Options[i].ti_Data)));
639 SET(_viewSettings_Node->wpbn_NotifyObject, AROS_LE2LONG(_viewSettings_Node->wpbn_Options[i].ti_Tag), AROS_LE2LONG(_viewSettings_Node->wpbn_Options[i].ti_Data));
642 return TRUE;
645 IPTR WandererPrefs__MUIM_WandererPrefs_Reload
647 Class *CLASS, Object *self, Msg message
650 struct ContextNode *context;
651 struct IFFHandle *handle;
652 BOOL success = TRUE;
653 LONG error;
654 IPTR iff_parse_mode = IFFPARSE_SCAN;
655 UBYTE chunk_buffer[IFF_CHUNK_BUFFER_SIZE];
657 D(bug("WandererPrefs::Reload\n"));
659 if (!(handle = AllocIFF()))
660 return FALSE;
662 handle->iff_Stream = (IPTR) Open("ENV:SYS/Wanderer.prefs", MODE_OLDFILE);
664 if (!handle->iff_Stream) return FALSE;
666 InitIFFasDOS(handle);
668 if ((error = OpenIFF(handle, IFFF_READ)) == 0)
670 if ((error = StopChunk(handle, ID_PREF, ID_WANDR)) == 0)
672 SET(self, MUIA_WandererPrefs_Processing, TRUE);
675 if ((error = ParseIFF(handle, iff_parse_mode)) == 0)
677 context = CurrentChunk(handle);
678 iff_parse_mode = IFFPARSE_STEP;
680 D(bug("[WANDERER.PREFS] WandererPrefs__MUIM_WandererPrefs_Reload: Context %x\n", context));
682 if ((error=ReadChunkBytes(handle, chunk_buffer, IFF_CHUNK_BUFFER_SIZE)))
684 D(bug("[WANDERER.PREFS] WandererPrefs__MUIM_WandererPrefs_Reload: ReadChunkBytes() Chunk matches Prefs Header size ..\n"));
685 struct WandererPrefsIFFChunkHeader *this_header =(struct WandererPrefsIFFChunkHeader *) chunk_buffer;
686 char *this_chunk_name = NULL;
687 IPTR this_chunk_size = AROS_LE2LONG(this_header->wpIFFch_ChunkSize);
690 if ((this_chunk_name = AllocVec(strlen(this_header->wpIFFch_ChunkType) +1,MEMF_ANY|MEMF_CLEAR)))
692 strcpy(this_chunk_name, this_header->wpIFFch_ChunkType);
693 D(bug("[WANDERER.PREFS] WandererPrefs__MUIM_WandererPrefs_Reload: Prefs Header for '%s' data size %d bytes\n", this_chunk_name, this_chunk_size));
695 if ((error = ParseIFF(handle, IFFPARSE_STEP)) == IFFERR_EOC)
697 D(bug("[WANDERER.PREFS] WandererPrefs__MUIM_WandererPrefs_Reload: End of header chunk ..\n"));
699 if ((error = ParseIFF(handle, IFFPARSE_STEP)) == 0)
701 context = CurrentChunk(handle);
703 D(bug("[WANDERER.PREFS] WandererPrefs__MUIM_WandererPrefs_Reload: Context %x\n", context));
705 error = ReadChunkBytes(
706 handle,
707 chunk_buffer,
708 this_chunk_size
711 if (error == this_chunk_size)
713 D(bug("[WANDERER.PREFS] WandererPrefs__MUIM_WandererPrefs_Reload: ReadChunkBytes() Chunk matches Prefs Data size .. (%d)\n", error));
714 if ((strcmp(this_chunk_name, "wanderer:global")) == 0)
716 D(bug("[WANDERER.PREFS] WandererPrefs__MUIM_WandererPrefs_Reload: Process data for wanderer global chunk ..\n"));
717 WandererPrefs_ProccessGlobalChunk(CLASS, self,(struct TagItem32 *) chunk_buffer);
719 else if ((strcmp(this_chunk_name, "wanderer:network")) == 0)
721 D(bug("[WPEditor] WPEditor__MUIM_PrefsEditor_ImportFH: Process data for wanderer network config chunk ..\n"));
722 WPEditor_ProccessNetworkChunk(CLASS, self, chunk_buffer);
724 else if ((strcmp(this_chunk_name, "wanderer:screentitle")) == 0)
726 D(bug("[WPEditor] WPEditor__MUIM_PrefsEditor_ImportFH: Process data for wanderer screentitle config chunk ..size=%d\n", error));
727 D(bug("[WPEditor] WPEditor__MUIM_PrefsEditor_ImportFH: Process data for wanderer screentitle STRING= %s\n", chunk_buffer));
728 WPEditor_ProccessScreenTitleChunk(CLASS, self, chunk_buffer);
731 else if ((strncmp(this_chunk_name, "wanderer:viewsettings", strlen("wanderer:viewsettings"))) == 0)
733 char *view_name = this_chunk_name + strlen("wanderer:viewsettings") + 1;
734 D(bug("[WANDERER.PREFS] WandererPrefs__MUIM_WandererPrefs_Reload: Process data for wanderer background chunk '%s'..\n", view_name));
735 WandererPrefs_ProccessViewSettingsChunk(CLASS, self, view_name, chunk_buffer, this_chunk_size);
737 }//END if (error == this_chunk_size)
738 if ((error = ParseIFF(handle, IFFPARSE_STEP)) == IFFERR_EOC)
740 D(bug("[WANDERER.PREFS] WandererPrefs__MUIM_WandererPrefs_Reload: End of Data chunk ..\n"));
742 }//END if ((error = ParseIFF(handle, IFFPARSE_STEP)) == 0)
743 }//END if ((error = ParseIFF(handle, IFFPARSE_STEP)) == IFFERR_EOC)
744 }//END if ((this_chunk_name = AllocVec(strlen(this_header->wpIFFch_ChunkType) +1,MEMF_ANY|MEMF_CLEAR)))
745 }//END if ((error=ReadChunkBytes(handle, chunk_buffer, IFF_CHUNK_BUFFER_SIZE)))
747 else
749 D(bug("[WANDERER.PREFS] ParseIFF() failed, returncode %ld!\n", error));
750 //success = FALSE;
751 }//END if ((error = ParseIFF(handle, iff_parse_mode)) == 0)
753 } while (error != IFFERR_EOF);
754 SET(self, MUIA_WandererPrefs_Processing, FALSE);
756 else
758 D(bug("[WANDERER.PREFS] StopChunk() failed, returncode %ld!\n", error));
759 //success = FALSE;
762 CloseIFF(handle);
764 else
766 D(bug("[WANDERER.PREFS] Failed to open stream!, returncode %ld!\n", error));
767 //ShowError(_(MSG_CANT_OPEN_STREAM));
768 success = FALSE;
769 }//END if ((error = StopChunk(handle, ID_PREF, ID_WANDR)) == 0)
771 Close((APTR)handle->iff_Stream);
773 FreeIFF(handle);
775 return success;
779 IPTR WandererPrefs__MUIM_WandererPrefs_ViewSettings_GetNotifyObject
781 Class *CLASS, Object *self, struct MUIP_WandererPrefs_ViewSettings_GetNotifyObject *message
784 SETUP_INST_DATA;
785 struct WandererPrefs_ViewSettingsNode *current_Node = NULL;
787 D(bug("[WANDERER.PREFS] WandererPrefs__MUIM_WandererPrefs_ViewSettings_GetNotifyObject()\n"));
789 if ((current_Node = WandererPrefs_FindViewSettingsNode(data, message->Background_Name)))
791 D(bug("[WANDERER.PREFS] WandererPrefs__MUIM_WandererPrefs_ViewSettings_GetNotifyObject: Returning Object for existing record\n"));
792 return (IPTR) current_Node->wpbn_NotifyObject;
795 current_Node = AllocMem(sizeof(struct WandererPrefs_ViewSettingsNode), MEMF_CLEAR|MEMF_PUBLIC);
796 D(bug("[WANDERER.PREFS] WandererPrefs__MUIM_WandererPrefs_ViewSettings_GetNotifyObject: Created new node ..\n"));
798 current_Node->wpbn_Name = AllocVec(strlen(message->Background_Name) + 1, MEMF_CLEAR|MEMF_PUBLIC);
799 strcpy(current_Node->wpbn_Name, message->Background_Name);
801 current_Node->wpbn_NotifyObject = NotifyObject, End;
803 AddTail(&data->wpd_ViewSettings, &current_Node->wpbn_Node);
805 D(bug("[WANDERER.PREFS] WandererPrefs__MUIM_WandererPrefs_ViewSettings_GetNotifyObject: Notify Object @ %x\n", current_Node->wpbn_NotifyObject));
807 return (IPTR) current_Node->wpbn_NotifyObject;
810 #warning "TODO: Replace with propper 64bit check"
811 /* 32bit replacements for utility.library tag funcs */
812 struct TagItem32 * NextTag32Item(struct TagItem32 ** tagListPtr)
814 if(!(*tagListPtr)) return NULL;
816 while (TRUE)
818 switch ((*tagListPtr)->ti_Tag)
820 case TAG_IGNORE:
821 break;
823 case TAG_END:
824 (*tagListPtr) = NULL;
825 return NULL;
827 case TAG_SKIP:
828 (*tagListPtr) += (*tagListPtr)->ti_Data + 1;
829 continue;
831 default:
832 /* Use post-increment (return will return the current value and
833 then tagListPtr will be incremented) */
834 return (struct TagItem32 *)(*tagListPtr)++;
837 (*tagListPtr) ++;
841 struct TagItem32 * FindTag32Item(ULONG tagValue, struct TagItem32 *tagList)
843 struct TagItem32 *tag;
844 const struct TagItem32 *tagptr = tagList;
846 while( (tag = NextTag32Item(&tagptr)) )
848 if(tag->ti_Tag == tagValue) return tag;
851 return NULL;
855 IPTR GetTag32Data(ULONG tagValue, ULONG defaultVal, struct TagItem32 *tagList)
857 struct TagItem32 *ti = NULL;
859 if ((tagList != NULL) && (ti = FindTag32Item(tagValue, tagList)))
860 return ti->ti_Data;
862 return defaultVal;
865 IPTR WandererPrefs__MUIM_WandererPrefs_ViewSettings_GetAttribute
867 Class *CLASS, Object *self, struct MUIP_WandererPrefs_ViewSettings_GetAttribute *message
870 SETUP_INST_DATA;
871 struct WandererPrefs_ViewSettingsNode *current_Node = NULL;
873 D(bug("[WANDERER.PREFS] WandererPrefs__MUIM_WandererPrefs_ViewSettings_GetAttribute()\n"));
875 if ((current_Node = WandererPrefs_FindViewSettingsNode(data, message->Background_Name)))
877 D(bug("[WANDERER.PREFS] WandererPrefs__MUIM_WandererPrefs_ViewSettings_GetAttribute: Found Background Record ..\n"));
878 if (message->AttributeID == MUIA_Background)
880 if (current_Node->wpbn_Background) return current_Node->wpbn_Background;
882 else if (current_Node->wpbn_Options)
884 if (sizeof(IPTR) > 4)
886 D(bug("[WANDERER.PREFS] WandererPrefs__MUIM_WandererPrefs_ViewSettings_GetAttribute: Using internal GetTag32Data()\n"));
887 return GetTag32Data(message->AttributeID, (IPTR)-1, current_Node->wpbn_Options);
889 else
891 D(bug("[WANDERER.PREFS] WandererPrefs__MUIM_WandererPrefs_ViewSettings_GetAttribute: Using utility.library->GetTagData()\n"));
892 return GetTagData(message->AttributeID, (IPTR)-1, current_Node->wpbn_Options);
896 return -1;
899 /*** Setup ******************************************************************/
900 ZUNE_CUSTOMCLASS_7
902 WandererPrefs, NULL, MUIC_Notify, NULL,
903 OM_NEW, struct opSet *,
904 OM_DISPOSE, Msg,
905 OM_SET, struct opSet *,
906 OM_GET, struct opGet *,
907 MUIM_WandererPrefs_Reload, Msg,
908 MUIM_WandererPrefs_ViewSettings_GetNotifyObject, struct MUIP_WandererPrefs_ViewSettings_GetNotifyObject *,
909 MUIM_WandererPrefs_ViewSettings_GetAttribute, struct MUIP_WandererPrefs_ViewSettings_GetAttribute *