Updated PCI IDs to latest snapshot.
[tangerine.git] / workbench / system / Wanderer / wandererprefs.c
blobd94304737c8092e174dc148cac22760aca41577f
1 /*
2 Copyright 2004-2009, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #define ZCC_QUIET
8 #include "portable_macros.h"
9 #ifdef __AROS__
10 #define DEBUG 0
11 #include <aros/debug.h>
13 #define MUIMASTER_YES_INLINE_STDARG
14 #endif
16 #define IFF_CHUNK_BUFFER_SIZE 1024
18 #include <exec/types.h>
19 #include <libraries/mui.h>
21 #ifdef __AROS__
22 #include <zune/customclasses.h>
23 #else
24 #include <zune_AROS/customclasses.h>
25 #endif
27 #include <proto/workbench.h>
29 #include <proto/utility.h>
31 #include <proto/dos.h>
33 #ifdef __AROS__
34 #include <proto/alib.h>
35 #endif
37 #include <proto/iffparse.h>
39 #ifdef __AROS__
40 #include <proto/aros.h>
41 #endif
43 #include <aros/arosbase.h>
44 #include <aros/inquire.h>
46 #include <string.h>
47 #include <stdio.h>
50 #if defined(__AMIGA__) && !defined(__PPC__)
51 #define NO_INLINE_STDARG
52 #endif
53 #ifndef _PROTO_INTUITION_H
54 #include <proto/intuition.h>
55 #endif
57 #include <proto/muimaster.h>
59 #include "wanderer.h"
60 #include "wandererprefs.h"
61 #include "Classes/iconlist_attributes.h"
62 #include "iconwindow_attributes.h"
63 #include "support.h"
64 #include "locale.h"
65 #include "version.h"
67 #ifdef __AROS__
68 #include <prefs/prefhdr.h>
69 #include <prefs/wanderer.h>
70 #else
71 #include <prefs_AROS/prefhdr.h>
72 #include <prefs_AROS/wanderer.h>
73 #endif
76 #ifndef __AROS__
77 #define DEBUG 1
79 #ifdef DEBUG
80 #define D(x) if (DEBUG) x
81 #ifdef __amigaos4__
82 #define bug DebugPrintF
83 #else
84 #define bug kprintf
85 #endif
86 #else
87 #define D(...)
88 #endif
89 #endif
91 static CONST_STRPTR wandererPrefs_PrefsFile = "ENV:SYS/Wanderer/global.prefs";
92 static Object *wandererPrefs_PrefsObject;
93 struct Wanderer_FSHandler *wandererPrefs_PrefsNotifyHandler = NULL;
95 struct TagItem32 {
96 ULONG ti_Tag;
97 ULONG ti_Data;
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;
113 BOOL wpd_PROCESSING;
116 struct WandererPrefs_ViewSettingsNode
118 struct Node wpbn_Node;
119 char *wpbn_Name;
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 ******************************************************/
129 ///SetString()
130 BOOL SetString(STRPTR *dst, STRPTR src)
132 if (src != NULL)
134 if ((*dst == NULL) || (strcmp(src, *dst) != 0))
136 STRPTR tmp =(STRPTR) StrDup(src);
138 if (tmp != NULL)
140 FreeVec(*dst);
141 *dst = tmp;
143 return TRUE;
148 return FALSE;
152 ///strtochar()
153 static unsigned char strtochar(STRPTR st)
155 return *st++;
158 /******** code from workbench/c/Info.c **************************************/
159 ///fmtlarge()
160 static void fmtlarge(UBYTE *buf, ULONG num)
162 UQUAD d;
163 UBYTE ch;
164 struct
166 IPTR val;
167 IPTR dec;
168 } array =
170 num,
174 if (num >= 1073741824)
176 //Gigabytes
177 array.val = num >> 30;
178 d = ((UQUAD)num * 10 + 536870912) / 1073741824;
179 array.dec = d % 10;
180 ch = strtochar((STRPTR)_(MSG_MEM_G));
182 else if (num >= 1048576)
184 //Megabytes
185 array.val = num >> 20;
186 d = ((UQUAD)num * 10 + 524288) / 1048576;
187 array.dec = d % 10;
188 ch = strtochar((STRPTR)_(MSG_MEM_M));
190 else if (num >= 1024)
192 //Kilobytes
193 array.val = num >> 10;
194 d = (num * 10 + 512) / 1024;
195 array.dec = d % 10;
196 ch = strtochar((STRPTR)_(MSG_MEM_K));
198 else
200 //Bytes
201 array.val = num;
202 array.dec = 0;
203 d = 0;
204 ch = strtochar((STRPTR)_(MSG_MEM_B));
207 if (!array.dec && (d > array.val * 10))
209 array.val++;
212 RawDoFmt(array.dec ? "%lu.%lu" : "%lu", &array, NULL, buf);
214 while (*buf)
216 buf++;
219 *buf++ = ch;
220 *buf = '\0';
224 ///findname()
225 /* Case-insensitive FindName()
226 * code from workbench/c/Version.c
228 static
229 struct Node *findname(struct List *list, CONST_STRPTR name)
231 struct Node *node;
232 #ifdef __AROS__
233 ForeachNode(list, node)
234 #else
235 Foreach_Node(list, node);
236 #endif
238 if (!Stricmp(node->ln_Name, (STRPTR) name))
240 return node;
244 return NULL;
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];
256 char infostr[10];
257 int screentitle_curChar;
259 if (screentitle_Template == NULL)
261 D(bug("[Wanderer:Prefs] ProcessUserScreenTitle(),EXTERN screentitle = NULL\n"));
262 return screentitle_Template;
264 else
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)
285 BOOL found = FALSE;
287 if (strncmp(temp + screentitle_curChar, "%wv", 3) == 0)
289 struct Library *MyLibrary = NULL;
291 #ifdef __AROS__
292 MyLibrary = (struct Library *)findname(&SysBase->LibList, "workbench.library");
293 //workbench.library is just opened, what is the sense of this istruction?
294 #else
295 MyLibrary = WorkbenchBase;
296 #endif
298 sprintf(infostr, "%ld.%ld",(long int) MyLibrary->lib_Version,(long int) MyLibrary->lib_Revision);
299 found = TRUE;
302 if (strncmp(temp + screentitle_curChar, "%ov", 3) == 0)
304 struct Library *AROSBase = OpenLibrary(AROSLIBNAME, AROSLIBVERSION);
306 if (AROSBase!=NULL)
308 UWORD ver = 0;
309 //UWORD kickrev = 0;
311 ArosInquire
313 AI_ArosVersion, (IPTR)&ver,
314 TAG_DONE
316 sprintf(infostr, "%d", ver);
317 CloseLibrary(AROSBase);
318 found = TRUE;
322 if (strncmp(temp + screentitle_curChar, "%os", 3) == 0)
324 struct Library *AROSBase = OpenLibrary(AROSLIBNAME, AROSLIBVERSION);
326 if (AROSBase != NULL)
328 ULONG ver = 0,
329 rev = 0;
331 ArosInquire
333 AI_ArosReleaseMajor, (IPTR)&ver,
334 AI_ArosReleaseMinor, (IPTR)&rev,
335 TAG_DONE
337 sprintf(infostr, "%ld.%ld", ver, rev);
338 CloseLibrary(AROSBase);
339 found = TRUE;
343 if (strncmp(temp + screentitle_curChar, "%wb", 3) == 0)
345 struct Library *AROSBase = OpenLibrary(AROSLIBNAME, AROSLIBVERSION);
347 if (AROSBase != NULL)
349 ULONG ver = 0;
350 ULONG rev = 0;
352 ArosInquire
354 AI_ArosReleaseMajor, (IPTR)&ver,
355 AI_ArosReleaseMinor, (IPTR)&rev,
356 TAG_DONE
358 sprintf(infostr, "%d.%d", WANDERERVERS, WANDERERREV);
359 CloseLibrary(AROSBase);
360 found = TRUE;
364 if (strncmp(temp + screentitle_curChar, "%pc", 3) == 0)
366 fmtlarge(infostr, AvailMem(MEMF_CHIP));
367 found = TRUE;
370 if (strncmp(temp + screentitle_curChar, "%pf", 3) == 0)
372 fmtlarge(infostr, AvailMem(MEMF_FAST));
373 found = TRUE;
376 if (strncmp(temp + screentitle_curChar, "%pt", 3) == 0)
378 fmtlarge(infostr, AvailMem(MEMF_ANY));
379 found = TRUE;
382 if (strncmp(temp + screentitle_curChar, "%PC", 3) == 0)
384 fmtlarge(infostr, AvailMem(MEMF_CHIP|MEMF_TOTAL));
385 found = TRUE;
388 if (strncmp(temp + screentitle_curChar, "%PF", 3) == 0)
390 fmtlarge(infostr, AvailMem(MEMF_FAST|MEMF_TOTAL));
391 found = TRUE;
394 if (strncmp(temp + screentitle_curChar, "%PT", 3) == 0)
396 fmtlarge(infostr, AvailMem(MEMF_ANY|MEMF_TOTAL));
397 found = TRUE;
400 if (found)
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);
414 else
416 temp[screentitle_curChar] = '?';
417 temp[screentitle_curChar + 1] = '?';
418 temp[screentitle_curChar + 2] = '?';
419 sprintf(title, temp);
422 else
424 switch (screentitle_TemplateLen)
426 case 2:
427 temp[screentitle_curChar]= '?';
428 temp[screentitle_curChar + 1]= '?';
429 break;
430 case 1:
431 temp[screentitle_curChar] = '?';
433 sprintf(title, temp);
437 sprintf(title, temp);
439 return title;
443 ///ExpandEnvName()
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)
449 BOOL ok = FALSE;
450 char tmp_envbuff[1024];
451 STRPTR fullpath = NULL;
452 BPTR env_lock = (BPTR) NULL;
454 env_lock = Lock("ENV:", SHARED_LOCK);
455 if (env_lock)
457 if (NameFromLock(env_lock, tmp_envbuff, 256)) ok = TRUE;
458 UnLock(env_lock);
461 if (ok)
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);
467 return fullpath;
471 //We couldnt expand it so just use as is ..
472 return env_path;
477 IPTR WandererPrefs__HandleFSUpdate()
479 DoMethod(wandererPrefs_PrefsObject, MUIM_WandererPrefs_Reload);
480 return NULL;
483 /*** Methods ****************************************************************/
485 ///OM_NEW()
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);
497 if (self != NULL)
499 SETUP_INST_DATA;
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));
516 else
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));
531 return self;
535 ///OM_DISPOSE()
536 IPTR WandererPrefs__OM_DISPOSE(Class *CLASS, Object *self, Msg message)
538 SETUP_INST_DATA;
539 EndNotify(&data->wpd_PrefsNotifyRequest);
540 return DoSuperMethodA(CLASS, self, (Msg)message);
544 ///OM_SET()
545 IPTR WandererPrefs__OM_SET(Class *CLASS, Object *self, struct opSet *message)
547 SETUP_INST_DATA;
548 const struct TagItem *tstate = message->ops_AttrList;
549 struct TagItem *tag;
551 while ((tag = NextTagItem((TAGITEM)&tstate)) != NULL)
553 switch (tag->ti_Tag)
555 case MUIA_WandererPrefs_Processing:
556 data->wpd_PROCESSING = (BOOL)tag->ti_Data;
557 break;
558 case MUIA_IconWindowExt_NetworkBrowser_Show:
559 data->wpd_ShowNetwork = (LONG)tag->ti_Data;
560 break;
562 case MUIA_IconWindowExt_UserFiles_ShowFilesFolder:
563 data->wpd_ShowUserFiles = (LONG)tag->ti_Data;
564 break;
566 case MUIA_IconWindowExt_ScreenTitle_String:
567 strcpy((STRPTR)data->wpd_ScreenTitleString, (STRPTR)tag->ti_Data);
568 //data->wpd_ScreenTitleString = (LONG)tag->ti_Data;
569 break;
571 case MUIA_IconWindow_WindowNavigationMethod:
572 data->wpd_NavigationMethod = (LONG)tag->ti_Data;
573 break;
577 return DoSuperMethodA(CLASS, self, (Msg)message);
581 ///OM_GET()
582 IPTR WandererPrefs__OM_GET(Class *CLASS, Object *self, struct opGet *message)
584 SETUP_INST_DATA;
585 IPTR *store = message->opg_Storage;
586 IPTR rv = TRUE;
588 switch (message->opg_AttrID)
590 case MUIA_WandererPrefs_Processing:
591 *store = (IPTR)data->wpd_PROCESSING;
592 break;
594 case MUIA_IconWindowExt_NetworkBrowser_Show:
595 *store = (IPTR)data->wpd_ShowNetwork;
596 break;
598 case MUIA_IconWindowExt_UserFiles_ShowFilesFolder:
599 *store = (IPTR)data->wpd_ShowUserFiles;
600 break;
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));
605 break;
607 case MUIA_IconWindow_WindowNavigationMethod:
608 *store = (IPTR)data->wpd_NavigationMethod;
609 break;
611 default:
612 rv = DoSuperMethodA(CLASS, self, (Msg)message);
615 return rv;
619 ///ProcessGlobalChunk()
620 BOOL WandererPrefs_ProccessGlobalChunk(Class *CLASS, Object *self, struct TagItem32 *global_chunk, IPTR chunk_size)
622 //SETUP_INST_DATA;
624 int i = 0, tag_count = (chunk_size / sizeof(struct TagItem32));
625 BOOL cont = TRUE;
627 D(bug("[Wanderer:Prefs] WandererPrefs_ProccessGlobalChunk()\n"));
628 #warning "TODO: fix problems with endian-ness?"
630 for (i = 0; i < tag_count; i++)
632 if (cont)
634 /* prefs file is stored in little endian */
635 if (AROS_LE2LONG(global_chunk[i].ti_Tag) == TAG_DONE)
637 cont = FALSE;
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) },
645 { TAG_DONE, 0 }
647 #warning "TODO: What should we use for the name arg in WorkbenchControlA"
648 WorkbenchControlA("", wbca_Tags);
650 else
652 SET(self, AROS_LE2LONG(global_chunk[i].ti_Tag), AROS_LE2LONG(global_chunk[i].ti_Data));
657 return TRUE;
661 ///WPEditor_ProccessNetworkChunk()
662 BOOL WPEditor_ProccessNetworkChunk(Class *CLASS, Object *self, UBYTE *_viewSettings_Chunk)
664 //SETUP_INST_DATA;
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));
669 return TRUE;
673 ///WPEditor_ProccessScreenTitleChunk()
674 BOOL WPEditor_ProccessScreenTitleChunk(Class *CLASS, Object *self, UBYTE *_ScreenTitle_Chunk)
676 //SETUP_INST_DATA;
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"));
691 return TRUE;
695 ///WandererPrefs_FindViewSettingsNode()
696 struct WandererPrefs_ViewSettingsNode *WandererPrefs_FindViewSettingsNode(struct WandererPrefs_DATA *data, char *node_Name)
698 struct WandererPrefs_ViewSettingsNode *current_Node = NULL;
700 #ifdef __AROS__
701 ForeachNode(&data->wpd_ViewSettings, current_Node)
702 #else
703 Foreach_Node(&data->wpd_ViewSettings, current_Node);
704 #endif
706 if ((strcmp(current_Node->wpbn_Name, node_Name)) == 0) return current_Node;
708 return NULL;
712 ///WandererPrefs_ProccessViewSettingsChunk()
713 BOOL WandererPrefs_ProccessViewSettingsChunk(Class *CLASS, Object *self, char *_viewSettings_ViewName, UBYTE *_viewSettings_Chunk, IPTR chunk_size)
715 SETUP_INST_DATA;
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 .."
730 else
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);
737 #ifdef __AROS__
738 _viewSettings_Node->wpbn_NotifyObject = (Object *)NotifyObject, End;
739 #else
740 _viewSettings_Node->wpbn_NotifyObject = MUI_NewObject(MUIC_Notify, TAG_DONE);
741 #endif
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 ));
765 else
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;
791 int i = 0;
792 for (i = 0; i < _viewSettings_TagCount; i++)
794 #if AROS_BIG_ENDIAN
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);
797 #endif
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);
803 return TRUE;
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;
815 BOOL success = TRUE;
816 LONG error;
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()))
823 return FALSE;
825 handle->iff_Stream = (IPTR)Open(wandererPrefs_PrefsFile, MODE_OLDFILE);
827 if (!handle->iff_Stream)
828 return FALSE;
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
871 handle,
872 chunk_buffer,
873 this_chunk_size
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)))
912 else
914 D(bug("[Wanderer:Prefs] ParseIFF() failed, returncode %ld!\n", error));
915 //success = FALSE;
916 }//END if ((error = ParseIFF(handle, iff_parse_mode)) == 0)
918 } while (error != IFFERR_EOF);
919 SET(self, MUIA_WandererPrefs_Processing, FALSE);
921 else
923 D(bug("[Wanderer:Prefs] StopChunk() failed, returncode %ld!\n", error));
924 //success = FALSE;
927 CloseIFF(handle);
929 else
931 D(bug("[Wanderer:Prefs] Failed to open stream!, returncode %ld!\n", error));
932 //ShowError(_(MSG_CANT_OPEN_STREAM));
933 success = FALSE;
934 }//END if ((error = StopChunk(handle, ID_PREF, ID_WANDR)) == 0)
936 Close((BPTR)handle->iff_Stream);
938 FreeIFF(handle);
940 return success;
944 ///WandererPrefs__MUIM_WandererPrefs_ViewSettings_GetNotifyObject()
945 IPTR WandererPrefs__MUIM_WandererPrefs_ViewSettings_GetNotifyObject
947 Class *CLASS, Object *self, struct MUIP_WandererPrefs_ViewSettings_GetNotifyObject *message
950 SETUP_INST_DATA;
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);
966 #ifdef __AROS__
967 current_Node->wpbn_NotifyObject = (Object *)NotifyObject, End;
968 #else
969 current_Node->wpbn_NotifyObject = MUI_NewObject(MUIC_Notify, TAG_DONE);
970 #endif
971 AddTail(&data->wpd_ViewSettings, &current_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;
979 ///NextTag32Item()
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;
986 while (TRUE)
988 switch ((*tagListPtr)->ti_Tag)
990 case TAG_IGNORE:
991 break;
993 case TAG_END:
994 (*tagListPtr) = NULL;
995 return NULL;
997 case TAG_SKIP:
998 (*tagListPtr) += (*tagListPtr)->ti_Data + 1;
999 continue;
1001 default:
1002 /* Use post-increment (return will return the current value and
1003 then tagListPtr will be incremented) */
1004 return (struct TagItem32 *)(*tagListPtr)++;
1007 (*tagListPtr) ++;
1012 ///FindTag32Item()
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;
1023 return NULL;
1028 ///GetTag32Data()
1029 ULONG GetTag32Data(ULONG tagValue, ULONG defaultVal, struct TagItem32 *tagList)
1031 struct TagItem32 *ti = NULL;
1033 if ((tagList != NULL) && (ti = FindTag32Item(tagValue, tagList)))
1034 return ti->ti_Data;
1036 return defaultVal;
1040 ///WandererPrefs__MUIM_WandererPrefs_ViewSettings_GetAttribute()
1041 IPTR WandererPrefs__MUIM_WandererPrefs_ViewSettings_GetAttribute
1043 Class *CLASS, Object *self, struct MUIP_WandererPrefs_ViewSettings_GetAttribute *message
1046 SETUP_INST_DATA;
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;
1069 else
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);
1076 return (IPTR)-1;
1079 /*** Setup ******************************************************************/
1080 ZUNE_CUSTOMCLASS_7
1082 WandererPrefs, NULL, MUIC_Notify, NULL,
1083 OM_NEW, struct opSet *,
1084 OM_DISPOSE, Msg,
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 *