Updated PCI IDs to latest snapshot.
[tangerine.git] / workbench / libs / desktop / diskiconobserver.c
blob7c378bb0e3208d670c216a446f72ce6dc3dccf81
1 /*
2 Copyright © 1995-2003, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #define MUIMASTER_YES_INLINE_STDARG
8 #define DEBUG 1
9 #include <aros/debug.h>
11 #include <exec/types.h>
12 #include <exec/memory.h>
13 #include <intuition/classes.h>
14 #include <intuition/classusr.h>
15 #include <libraries/desktop.h>
16 #include <libraries/mui.h>
18 #include "support.h"
19 #include "worker.h"
20 #include "desktop_intern.h"
22 #include <proto/desktop.h>
23 #include <proto/dos.h>
24 #include <proto/intuition.h>
25 #include <proto/utility.h>
27 #include "presentation.h"
28 #include "iconobserver.h"
29 #include "diskiconobserver.h"
31 #include "desktop_intern_protos.h"
33 #include <string.h>
37 enum Unit { U_GIGABYTE, U_MEGABYTE, U_KILOBYTE, U_BYTE; };
39 UBYTE* formatDiskUsageString(Object *obj) {
41 This function will return a string in the form of: "1Mb in use, 2Mb free,
42 33% full" "1kb in use, 2kb free, 33% full" "1b in use, 2b free, 33% full
43 (validating)"
45 struct InfoData *info BOOL success; BPTR lock; UBYTE retval=NULL; struct
46 InfoData info; UQUAD usedBytes=0, totalBytes=0, usagePercent=0; Unit used,
47 total; LONG length=0;
49 lock=Lock(_name(obj)); if(lock) { success=Info(lock, &info); if(success) {
50 totalBytes=id.id_NumBlocks*id.id_BlocksPerByte;
51 usedBytes=id.id_NumBlocksUsed*id.id_BlocksPerByte;
52 usagePercent=(usedBytes/freeBytes);
54 if(usedBytes > 1024*1024*1024) { usedBytes/=(1024*1024*1024);
55 used=U_GIGABYTE; length+=(2+(int)log10(number)+1)); } else if(usedBytes >
56 1024*1024) { usedBytes/=(1024*1024); used=U_MEGABYTE;
57 length+=(2+(int)log10(number)+1); } else if(usedBytes > 1024) {
58 usedBytes/=(1024); used=U_KILOBYTE; length+=(2+(int)log10(number)+1); }
59 else { used=U_BYTE; length+=(1+(int)log10(number)+1); }
61 length+=strlen(" in use, ");
63 if(totalBytes > 1024*1024*1024) { totalBytes/=(1024*1024*1024);
64 total=U_GIGABYTE; length+=(2+(int)log10(number)+1); } else if(totalBytes >
65 1024*1024) { totalBytes/=(1024*1024); total=U_MEGABYTE;
66 length+=(2+(int)log10(number)+1); } else if(totalBytes > 1024) {
67 totalBytes/=(1024); total=U_KILOBYTE; length+=(2+(int)log10(number)+1); }
68 else { total=U_BYTE; length+=(1+(int)log10(number)+1); }
70 length+=strlen(" free"); }
72 length+=((int)log10(usagePercent)+1+strlen("%");
74 if(id.id_DiskState==ID_VALIDATING) length+=strlen(" (Validating)");
76 length+=1;
78 retval=AllocMem(length, MEMF_ANY);
80 sprintf("1763Mb in use, 2Mb free, 33% full"); strcpy(retval, );
83 Unlock(lock); }
85 return retval; }
87 IPTR diskIconObserverNew(Class * cl, Object * obj, struct opSet * msg)
89 IPTR retval = 0;
90 struct DiskIconObserverClassData *data;
91 //struct TagItem *tag;
93 retval = DoSuperMethodA(cl, obj, (Msg) msg);
94 if (retval)
96 obj = (Object *) retval;
97 data = INST_DATA(cl, obj);
100 return retval;
103 IPTR diskIconObserverSet(Class * cl, Object * obj, struct opSet * msg)
105 struct DiskIconObserverClassData *data;
106 IPTR retval = 1;
107 struct TagItem *tag,
108 *tstate = msg->ops_AttrList;
110 data = (struct DiskIconObserverClassData *) INST_DATA(cl, obj);
112 while ((tag = NextTagItem(&tstate)))
114 switch (tag->ti_Tag)
116 default:
117 break;
121 retval = DoSuperMethodA(cl, obj, (Msg) msg);
123 return retval;
126 IPTR diskIconObserverGet(Class * cl, Object * obj, struct opGet * msg)
128 IPTR retval = 1;
129 struct DiskIconObserverClassData *data;
131 data = (struct DiskIconObserverClassData *) INST_DATA(cl, obj);
133 switch (msg->opg_AttrID)
135 default:
136 retval = DoSuperMethodA(cl, obj, (Msg) msg);
137 break;
140 return retval;
143 IPTR diskIconObserverDispose(Class * cl, Object * obj, Msg msg)
145 IPTR retval;
147 retval = DoSuperMethodA(cl, obj, msg);
149 return retval;
152 BOOPSI_DISPATCHER(IPTR, diskIconObserverDispatcher, cl, obj, msg)
154 ULONG retval = 0;
156 switch (msg->MethodID)
158 case OM_NEW:
159 retval = diskIconObserverNew(cl, obj, (struct opSet *) msg);
160 break;
161 case OM_SET:
162 retval = diskIconObserverSet(cl, obj, (struct opSet *) msg);
163 break;
164 case OM_GET:
165 retval = diskIconObserverGet(cl, obj, (struct opGet *) msg);
166 break;
167 case OM_DISPOSE:
168 retval = diskIconObserverDispose(cl, obj, msg);
169 break;
170 default:
171 retval = DoSuperMethodA(cl, obj, msg);
172 break;
175 return retval;
177 BOOPSI_DISPATCHER_END