2 Copyright © 1995-2003, The AROS Development Team. All rights reserved.
6 #define MUIMASTER_YES_INLINE_STDARG
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>
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"
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
45 struct InfoData *info BOOL success; BPTR lock; UBYTE retval=NULL; struct
46 InfoData info; UQUAD usedBytes=0, totalBytes=0, usagePercent=0; Unit used,
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)");
78 retval=AllocMem(length, MEMF_ANY);
80 sprintf("1763Mb in use, 2Mb free, 33% full"); strcpy(retval, );
87 IPTR
diskIconObserverNew(Class
* cl
, Object
* obj
, struct opSet
* msg
)
90 struct DiskIconObserverClassData
*data
;
91 //struct TagItem *tag;
93 retval
= DoSuperMethodA(cl
, obj
, (Msg
) msg
);
96 obj
= (Object
*) retval
;
97 data
= INST_DATA(cl
, obj
);
103 IPTR
diskIconObserverSet(Class
* cl
, Object
* obj
, struct opSet
* msg
)
105 struct DiskIconObserverClassData
*data
;
108 *tstate
= msg
->ops_AttrList
;
110 data
= (struct DiskIconObserverClassData
*) INST_DATA(cl
, obj
);
112 while ((tag
= NextTagItem(&tstate
)))
121 retval
= DoSuperMethodA(cl
, obj
, (Msg
) msg
);
126 IPTR
diskIconObserverGet(Class
* cl
, Object
* obj
, struct opGet
* msg
)
129 struct DiskIconObserverClassData
*data
;
131 data
= (struct DiskIconObserverClassData
*) INST_DATA(cl
, obj
);
133 switch (msg
->opg_AttrID
)
136 retval
= DoSuperMethodA(cl
, obj
, (Msg
) msg
);
143 IPTR
diskIconObserverDispose(Class
* cl
, Object
* obj
, Msg msg
)
147 retval
= DoSuperMethodA(cl
, obj
, msg
);
152 BOOPSI_DISPATCHER(IPTR
, diskIconObserverDispatcher
, cl
, obj
, msg
)
156 switch (msg
->MethodID
)
159 retval
= diskIconObserverNew(cl
, obj
, (struct opSet
*) msg
);
162 retval
= diskIconObserverSet(cl
, obj
, (struct opSet
*) msg
);
165 retval
= diskIconObserverGet(cl
, obj
, (struct opGet
*) msg
);
168 retval
= diskIconObserverDispose(cl
, obj
, msg
);
171 retval
= DoSuperMethodA(cl
, obj
, msg
);
177 BOOPSI_DISPATCHER_END