2 Copyright © 2002-2011, The AROS Development Team. All rights reserved.
6 #define MUIMASTER_YES_INLINE_STDARG
8 #include <exec/memory.h>
9 #include <clib/alib_protos.h>
10 #include <proto/exec.h>
11 #include <proto/dos.h>
12 #include <proto/intuition.h>
13 #include <proto/utility.h>
14 #include <proto/muimaster.h>
20 #include "muimaster_intern.h"
22 #include "support_classes.h"
23 #include "volumelist_private.h"
25 extern struct Library
*MUIMasterBase
;
28 static void printSize(STRPTR string
, size_t bufsize
, UQUAD size
)
32 if (size
>= 9999999999ULL)
37 else if (size
>= 9999999UL)
48 snprintf(string
, bufsize
, "%u%c", (unsigned int)size
, unit
);
49 string
[bufsize
- 1] = '\0';
52 AROS_UFH3S(APTR
, construct_func
,
53 AROS_UFHA(struct Hook
*, hook
, A0
),
54 AROS_UFHA(APTR
, pool
, A2
),
55 AROS_UFHA(struct Volumelist_Entry
*, entry
, A1
))
59 struct Volumelist_Entry
*new;
61 if ((new = AllocPooled(pool
, sizeof(*new))))
70 AROS_UFH3S(void, destruct_func
,
71 AROS_UFHA(struct Hook
*, hook
, A0
),
72 AROS_UFHA(APTR
, pool
, A2
),
73 AROS_UFHA(struct Volumelist_Entry
*, entry
, A1
))
77 FreePooled(pool
, entry
, sizeof(struct Volumelist_Entry
));
82 AROS_UFH3S(LONG
, display_func
,
83 AROS_UFHA(struct Hook
*, hook
, A0
),
84 AROS_UFHA(char **, array
, A2
),
85 AROS_UFHA(struct Volumelist_Entry
*, entry
, A1
))
89 /* MUI: logo | devicename | %-used | bytes free | bytes used */
93 if (entry
->type
== DLT_DEVICE
)
95 *array
++ = "\33I[6:24]";
97 else if (entry
->type
== DLT_VOLUME
)
99 *array
++ = "\33I[6:26]";
103 *array
++ = "\33I[6:29]";
106 *array
++ = entry
->name
;
107 *array
++ = entry
->full
;
108 *array
++ = entry
->free
;
109 *array
= entry
->used
;
126 IPTR
Volumelist__OM_NEW(struct IClass
*cl
, Object
*obj
,
129 struct DosList
*dl
, *actdl
;
132 (STRPTR
) GetTagData(MUIA_List_Format
, 0, msg
->ops_AttrList
);
134 obj
= (Object
*)DoSuperNewTags
137 format
? TAG_IGNORE
: MUIA_List_Format
, (IPTR
)",,P=\33r,P=\33r,P=\33r",
138 TAG_MORE
, (IPTR
) msg
->ops_AttrList
143 struct Volumelist_DATA
*data
= INST_DATA(cl
, obj
);
145 data
->construct_hook
.h_Entry
= (HOOKFUNC
) construct_func
;
146 data
->destruct_hook
.h_Entry
= (HOOKFUNC
) destruct_func
;
147 data
->display_hook
.h_Entry
= (HOOKFUNC
) display_func
;
149 SetAttrs(obj
, MUIA_List_ConstructHook
,
150 (IPTR
) & data
->construct_hook
, MUIA_List_DestructHook
,
151 (IPTR
) & data
->destruct_hook
, MUIA_List_DisplayHook
,
152 (IPTR
) & data
->display_hook
, TAG_DONE
);
154 dl
= LockDosList(LDF_READ
| LDF_VOLUMES
| LDF_ASSIGNS
|
158 while ((actdl
= NextDosEntry(actdl
, LDF_DEVICES
)))
160 struct Volumelist_Entry entry
;
162 entry
.full
[0] = '\0';
163 entry
.free
[0] = '\0';
164 entry
.used
[0] = '\0';
166 entry
.type
= DLT_DEVICE
;
168 strncpy(entry
.name
, AROS_BSTR_ADDR(actdl
->dol_Name
),
170 entry
.name
[sizeof(entry
.name
) - 2] = '\0';
171 strcat(entry
.name
, ":");
173 DoMethod(obj
, MUIM_List_InsertSingle
, (IPTR
) & entry
,
174 MUIV_List_Insert_Bottom
);
178 while ((actdl
= NextDosEntry(actdl
, LDF_VOLUMES
)))
180 struct Volumelist_Entry entry
;
181 struct InfoData diskinfo
;
186 entry
.full
[0] = '\0';
187 entry
.free
[0] = '\0';
188 entry
.used
[0] = '\0';
190 entry
.type
= DLT_VOLUME
;
192 strncpy(entry
.name
, AROS_BSTR_ADDR(actdl
->dol_Name
),
194 entry
.name
[sizeof(entry
.name
) - 2] = '\0';
195 strcat(entry
.name
, ":");
197 if ((lock
= Lock(entry
.name
, SHARED_LOCK
)) != BNULL
)
199 if (Info(lock
, &diskinfo
) != DOSFALSE
)
205 (long)(100 * diskinfo
.id_NumBlocksUsed
/
206 diskinfo
.id_NumBlocks
));
207 entry
.full
[sizeof(entry
.full
) - 1] = '\0';
210 (UQUAD
) diskinfo
.id_NumBlocksUsed
*
211 diskinfo
.id_BytesPerBlock
;
213 (UQUAD
) diskinfo
.id_NumBlocks
*
214 diskinfo
.id_BytesPerBlock
- used
;
215 printSize(entry
.free
, sizeof entry
.free
, free
);
216 printSize(entry
.used
, sizeof entry
.used
, used
);
221 DoMethod(obj
, MUIM_List_InsertSingle
, (IPTR
) & entry
,
222 MUIV_List_Insert_Bottom
);
226 while ((actdl
= NextDosEntry(actdl
, LDF_ASSIGNS
)))
228 struct Volumelist_Entry entry
;
230 entry
.full
[0] = '\0';
231 entry
.free
[0] = '\0';
232 entry
.used
[0] = '\0';
234 entry
.type
= DLT_DIRECTORY
;
236 strncpy(entry
.name
, AROS_BSTR_ADDR(actdl
->dol_Name
),
238 entry
.name
[sizeof(entry
.name
) - 2] = '\0';
239 strcat(entry
.name
, ":");
241 DoMethod(obj
, MUIM_List_InsertSingle
, (IPTR
) & entry
,
242 MUIV_List_Insert_Bottom
);
245 UnLockDosList(LDF_READ
| LDF_VOLUMES
| LDF_ASSIGNS
| LDF_DEVICES
);
252 #if ZUNE_BUILTIN_VOLUMELIST
253 BOOPSI_DISPATCHER(IPTR
, Volumelist_Dispatcher
, cl
, obj
, msg
)
255 switch (msg
->MethodID
)
258 return Volumelist__OM_NEW(cl
, obj
, (struct opSet
*)msg
);
261 return DoSuperMethodA(cl
, obj
, msg
);
264 BOOPSI_DISPATCHER_END
266 const struct __MUIBuiltinClass _MUI_Volumelist_desc
=
270 sizeof(struct Volumelist_DATA
),
271 (void *) Volumelist_Dispatcher
273 #endif /* ZUNE_BUILTIN_VOLUMELIST */