added concrete implementations of putc(), getc(), getchar() and gets()
[tangerine.git] / workbench / system / Wanderer / wandererprefs.c
blob78e343b217b54a9dffc0c40808d67c96231ab3b3
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 struct List wpd_ViewSettings;
52 BOOL wpd_PROCESSING;
55 struct WandererPrefs_ViewSettingsNode
57 struct Node wpbn_Node;
58 char *wpbn_Name;
59 IPTR wpbn_Background;
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)
70 if (src != NULL)
72 if ((*dst == NULL) || (strcmp(src, *dst) != 0))
74 STRPTR tmp = StrDup(src);
76 if (tmp != NULL)
78 FreeVec(*dst);
79 *dst = tmp;
81 return TRUE;
86 return FALSE;
88 static unsigned char strtochar(STRPTR st)
90 return *st++;
93 /******** code from workbench/c/Info.c *******************/
94 static void fmtlarge(UBYTE *buf, ULONG num)
96 UQUAD d;
97 UBYTE ch;
98 struct
100 ULONG val;
101 LONG dec;
102 } array =
104 num,
108 if (num >= 1073741824)
110 //Gigabytes
111 array.val = num >> 30;
112 d = ((UQUAD)num * 10 + 536870912) / 1073741824;
113 array.dec = d % 10;
114 ch = strtochar((STRPTR)_(MSG_MEM_G));
116 else if (num >= 1048576)
118 //Megabytes
119 array.val = num >> 20;
120 d = ((UQUAD)num * 10 + 524288) / 1048576;
121 array.dec = d % 10;
122 ch = strtochar((STRPTR)_(MSG_MEM_M));
124 else if (num >= 1024)
126 //Kilobytes
127 array.val = num >> 10;
128 d = (num * 10 + 512) / 1024;
129 array.dec = d % 10;
130 ch = strtochar((STRPTR)_(MSG_MEM_K));
132 else
134 //Bytes
135 array.val = num;
136 array.dec = 0;
137 d = 0;
138 ch = strtochar((STRPTR)_(MSG_MEM_B));
141 if (!array.dec && (d > array.val * 10))
143 array.val++;
146 RawDoFmt(array.dec ? "%lu.%lu" : "%lu", &array, NULL, buf);
148 while (*buf)
150 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 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];
199 char infostr[10];
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)
210 BOOL found = FALSE;
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);
219 found = TRUE;
222 if (strncmp(temp + screentitle_curChar, "%ov", 3) == 0)
224 struct Library *AROSBase = OpenLibrary(AROSLIBNAME, AROSLIBVERSION);
226 if (AROSBase!=NULL)
228 UWORD ver = 0,
229 kickrev = 0;
231 ArosInquire
233 AI_ArosVersion, (IPTR)&ver,
234 TAG_DONE
236 sprintf(infostr, "%d", ver);
237 CloseLibrary(AROSBase);
238 found = TRUE;
242 if (strncmp(temp + screentitle_curChar, "%os", 3) == 0)
244 struct Library *AROSBase = OpenLibrary(AROSLIBNAME, AROSLIBVERSION);
246 if (AROSBase != NULL)
248 ULONG ver = 0,
249 rev = 0;
251 ArosInquire
253 AI_ArosReleaseMajor, (IPTR)&ver,
254 AI_ArosReleaseMinor, (IPTR)&rev,
255 TAG_DONE
257 sprintf(infostr, "%ld.%ld", ver, rev);
258 CloseLibrary(AROSBase);
259 found = TRUE;
263 if (strncmp(temp + screentitle_curChar, "%wb", 3) == 0)
265 struct Library *AROSBase = OpenLibrary(AROSLIBNAME, AROSLIBVERSION);
267 if (AROSBase != NULL)
269 ULONG ver = 0,
270 rev = 0;
272 ArosInquire
274 AI_ArosReleaseMajor, (IPTR)&ver,
275 AI_ArosReleaseMinor, (IPTR)&rev,
276 TAG_DONE
278 sprintf(infostr, "%d.%d", WANDERERVERS, WANDERERREV);
279 CloseLibrary(AROSBase);
280 found = TRUE;
284 if (strncmp(temp + screentitle_curChar, "%pc", 3) == 0)
286 fmtlarge(infostr, AvailMem(MEMF_CHIP));
287 found = TRUE;
290 if (strncmp(temp + screentitle_curChar, "%pf", 3) == 0)
292 fmtlarge(infostr, AvailMem(MEMF_FAST));
293 found = TRUE;
296 if (strncmp(temp + screentitle_curChar, "%pt", 3) == 0)
298 fmtlarge(infostr, AvailMem(MEMF_ANY));
299 found = TRUE;
302 if (strncmp(temp + screentitle_curChar, "%PC", 3) == 0)
304 fmtlarge(infostr, AvailMem(MEMF_CHIP|MEMF_TOTAL));
305 found = TRUE;
308 if (strncmp(temp + screentitle_curChar, "%PF", 3) == 0)
310 fmtlarge(infostr, AvailMem(MEMF_FAST|MEMF_TOTAL));
311 found = TRUE;
314 if (strncmp(temp + screentitle_curChar, "%PT", 3) == 0)
316 fmtlarge(infostr, AvailMem(MEMF_ANY|MEMF_TOTAL));
317 found = TRUE;
320 if (found)
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);
334 else
336 temp[screentitle_curChar] = '?';
337 temp[screentitle_curChar + 1] = '?';
338 temp[screentitle_curChar + 2] = '?';
339 sprintf(title, temp);
342 else
344 switch (screentitle_TemplateLen)
346 case 2:
347 temp[screentitle_curChar]= '?';
348 temp[screentitle_curChar + 1]= '?';
349 break;
350 case 1:
351 temp[screentitle_curChar] = '?';
353 sprintf(title, temp);
357 sprintf(title, temp);
359 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);
377 data->wpd_PROCESSING = FALSE;
379 DoMethod(self, MUIM_WandererPrefs_Reload);
382 return self;
385 IPTR WandererPrefs__OM_DISPOSE(Class *CLASS, Object *self, Msg message)
387 //SETUP_INST_DATA;
389 return DoSuperMethodA(CLASS, self, (Msg)message);
392 IPTR WandererPrefs__OM_SET(Class *CLASS, Object *self, struct opSet *message)
394 SETUP_INST_DATA;
395 const struct TagItem *tstate = message->ops_AttrList;
396 struct TagItem *tag;
398 while ((tag = NextTagItem(&tstate)) != NULL)
400 switch (tag->ti_Tag)
402 case MUIA_WandererPrefs_Processing:
403 data->wpd_PROCESSING = (BOOL)tag->ti_Data;
404 break;
405 case MUIA_IconWindowExt_NetworkBrowser_Show:
406 data->wpd_ShowNetwork = (LONG)tag->ti_Data;
407 break;
409 case MUIA_IconWindowExt_UserFiles_ShowFilesFolder:
410 data->wpd_ShowUserFiles = (LONG)tag->ti_Data;
411 break;
413 case MUIA_IconWindowExt_ScreenTitle_String:
414 strcpy(data->wpd_ScreenTitleString,tag->ti_Data);
415 //data->wpd_ScreenTitleString = (LONG)tag->ti_Data;
416 break;
418 case MUIA_IconWindowExt_Toolbar_Enabled:
419 data->wpd_ToolbarEnabled = (LONG)tag->ti_Data;
420 break;
422 case MUIA_IconWindowExt_Toolbar_NavigationMethod:
423 data->wpd_NavigationMethod = (LONG)tag->ti_Data;
424 break;
428 return DoSuperMethodA(CLASS, self, (Msg)message);
431 IPTR WandererPrefs__OM_GET(Class *CLASS, Object *self, struct opGet *message)
433 SETUP_INST_DATA;
434 IPTR *store = message->opg_Storage;
435 IPTR rv = TRUE;
437 switch (message->opg_AttrID)
439 case MUIA_WandererPrefs_Processing:
440 *store = (IPTR)data->wpd_PROCESSING;
441 break;
443 case MUIA_IconWindowExt_NetworkBrowser_Show:
444 *store = (IPTR)data->wpd_ShowNetwork;
445 break;
447 case MUIA_IconWindowExt_UserFiles_ShowFilesFolder:
448 *store = (IPTR)data->wpd_ShowUserFiles;
449 break;
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));
454 break;
456 case MUIA_IconWindowExt_Toolbar_NavigationMethod:
457 *store = (IPTR)data->wpd_NavigationMethod;
458 break;
460 case MUIA_IconWindowExt_Toolbar_Enabled:
461 *store = (IPTR)data->wpd_ToolbarEnabled;
462 break;
464 default:
465 rv = DoSuperMethodA(CLASS, self, (Msg)message);
468 return rv;
471 BOOL WandererPrefs_ProccessGlobalChunk(Class *CLASS, Object *self, struct TagItem32 *global_chunk, IPTR chunk_size)
473 //SETUP_INST_DATA;
475 int i = 0, tag_count = (chunk_size / sizeof(struct TagItem32));
476 BOOL cont = TRUE;
478 D(bug("[WANDERER.PREFS] WandererPrefs_ProccessGlobalChunk()\n"));
479 #warning "TODO: fix problems with endian-ness?"
481 for (i = 0; i < tag_count; i++)
483 if (cont)
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));
491 return TRUE;
494 BOOL WPEditor_ProccessNetworkChunk(Class *CLASS, Object *self, UBYTE *_viewSettings_Chunk)
496 //SETUP_INST_DATA;
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));
501 return TRUE;
504 BOOL WPEditor_ProccessScreenTitleChunk(Class *CLASS, Object *self, UBYTE *_ScreenTitle_Chunk)
506 //SETUP_INST_DATA;
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"));
520 return TRUE;
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;
531 return NULL;
534 BOOL WandererPrefs_ProccessViewSettingsChunk(Class *CLASS, Object *self, char *_viewSettings_ViewName, UBYTE *_viewSettings_Chunk, IPTR chunk_size)
536 SETUP_INST_DATA;
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);
549 else
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 ));
577 else
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;
602 int i = 0;
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));
609 return TRUE;
612 IPTR WandererPrefs__MUIM_WandererPrefs_Reload
614 Class *CLASS, Object *self, Msg message
617 struct ContextNode *context;
618 struct IFFHandle *handle;
619 BOOL success = TRUE;
620 LONG error;
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()))
627 return FALSE;
629 handle->iff_Stream = (IPTR)Open("ENV:SYS/Wanderer.prefs", MODE_OLDFILE);
631 if (!handle->iff_Stream)
632 return FALSE;
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
674 handle,
675 chunk_buffer,
676 this_chunk_size
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)))
715 else
717 D(bug("[WANDERER.PREFS] ParseIFF() failed, returncode %ld!\n", error));
718 //success = FALSE;
719 }//END if ((error = ParseIFF(handle, iff_parse_mode)) == 0)
721 } while (error != IFFERR_EOF);
722 SET(self, MUIA_WandererPrefs_Processing, FALSE);
724 else
726 D(bug("[WANDERER.PREFS] StopChunk() failed, returncode %ld!\n", error));
727 //success = FALSE;
730 CloseIFF(handle);
732 else
734 D(bug("[WANDERER.PREFS] Failed to open stream!, returncode %ld!\n", error));
735 //ShowError(_(MSG_CANT_OPEN_STREAM));
736 success = FALSE;
737 }//END if ((error = StopChunk(handle, ID_PREF, ID_WANDR)) == 0)
739 Close((APTR)handle->iff_Stream);
741 FreeIFF(handle);
743 return success;
747 IPTR WandererPrefs__MUIM_WandererPrefs_ViewSettings_GetNotifyObject
749 Class *CLASS, Object *self, struct MUIP_WandererPrefs_ViewSettings_GetNotifyObject *message
752 SETUP_INST_DATA;
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, &current_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;
784 while (TRUE)
786 switch ((*tagListPtr)->ti_Tag)
788 case TAG_IGNORE:
789 break;
791 case TAG_END:
792 (*tagListPtr) = NULL;
793 return NULL;
795 case TAG_SKIP:
796 (*tagListPtr) += (*tagListPtr)->ti_Data + 1;
797 continue;
799 default:
800 /* Use post-increment (return will return the current value and
801 then tagListPtr will be incremented) */
802 return (struct TagItem32 *)(*tagListPtr)++;
805 (*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;
819 return NULL;
823 ULONG GetTag32Data(ULONG tagValue, ULONG defaultVal, struct TagItem32 *tagList)
825 struct TagItem32 *ti = NULL;
827 if ((tagList != NULL) && (ti = FindTag32Item(tagValue, tagList)))
828 return ti->ti_Data;
830 return defaultVal;
833 IPTR WandererPrefs__MUIM_WandererPrefs_ViewSettings_GetAttribute
835 Class *CLASS, Object *self, struct MUIP_WandererPrefs_ViewSettings_GetAttribute *message
838 SETUP_INST_DATA;
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)
857 return (IPTR)retVal;
859 else
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);
866 return (IPTR)-1;
869 /*** Setup ******************************************************************/
870 ZUNE_CUSTOMCLASS_7
872 WandererPrefs, NULL, MUIC_Notify, NULL,
873 OM_NEW, struct opSet *,
874 OM_DISPOSE, Msg,
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 *