2 Copyright © 2002-2006, The AROS Development Team. All rights reserved.
6 #define MUIMASTER_YES_INLINE_STDARG
8 #include <exec/memory.h>
10 #include <dos/datetime.h>
11 #include <clib/alib_protos.h>
12 #include <proto/exec.h>
13 #include <proto/dos.h>
14 #include <proto/intuition.h>
15 #include <proto/utility.h>
16 #include <proto/muimaster.h>
22 #include "muimaster_intern.h"
24 #include "support_classes.h"
25 #include "dirlist_private.h"
27 extern struct Library
*MUIMasterBase
;
29 AROS_UFH3S(APTR
, construct_func
,
30 AROS_UFHA(struct Hook
*, hook
, A0
),
31 AROS_UFHA(APTR
, pool
, A2
),
32 AROS_UFHA(struct Dirlist_Entry
*, entry
, A1
))
36 struct Dirlist_Entry
*new;
38 if ((new = AllocPooled(pool
, sizeof(*new))))
48 AROS_UFH3S(void, destruct_func
,
49 AROS_UFHA(struct Hook
*, hook
, A0
),
50 AROS_UFHA(APTR
, pool
, A2
),
51 AROS_UFHA(struct Dirlist_Entry
*, entry
, A1
))
55 FreePooled(pool
, entry
, sizeof(struct Dirlist_Entry
));
60 AROS_UFH3S(LONG
, display_func
,
61 AROS_UFHA(struct Hook
*, hook
, A0
),
62 AROS_UFHA(char **, array
, A2
),
63 AROS_UFHA(struct Dirlist_Entry
*, entry
, A1
))
67 struct Dirlist_DATA
*data
= hook
->h_Data
;
70 /* MUI: name | size | Date | Time | Protection | Comment */
73 *array
++ = entry
->fib
.fib_FileName
;
75 if (entry
->fib
.fib_DirEntryType
> 0)
77 *array
++ = "\33I[6:22]";
81 snprintf(data
->size_string
, sizeof(data
->size_string
), "%ld",
82 (long)entry
->fib
.fib_Size
);
83 *array
++ = data
->size_string
;
86 dt
.dat_Stamp
= entry
->fib
.fib_Date
;
87 dt
.dat_Format
= FORMAT_DOS
;
90 dt
.dat_StrDate
= data
->date_string
;
91 dt
.dat_StrTime
= data
->time_string
;
95 *array
++ = data
->date_string
;
96 *array
++ = data
->time_string
;
98 data
->prot_string
[0] =
99 (entry
->fib
.fib_Protection
& FIBF_SCRIPT
) ? 's' : '-';
100 data
->prot_string
[1] =
101 (entry
->fib
.fib_Protection
& FIBF_PURE
) ? 'p' : '-';
102 data
->prot_string
[2] =
103 (entry
->fib
.fib_Protection
& FIBF_ARCHIVE
) ? 'a' : '-';
104 data
->prot_string
[3] =
105 (entry
->fib
.fib_Protection
& FIBF_READ
) ? '-' : 'r';
106 data
->prot_string
[4] =
107 (entry
->fib
.fib_Protection
& FIBF_WRITE
) ? '-' : 'w';
108 data
->prot_string
[5] =
109 (entry
->fib
.fib_Protection
& FIBF_EXECUTE
) ? '-' : 'e';
110 data
->prot_string
[6] =
111 (entry
->fib
.fib_Protection
& FIBF_DELETE
) ? '-' : 'd';
112 data
->prot_string
[7] = '\0';
114 *array
++ = data
->prot_string
;
115 *array
= entry
->fib
.fib_Comment
;
132 IPTR
Dirlist__OM_SET(struct IClass
*cl
, Object
*obj
, struct opSet
*msg
);
134 IPTR
Dirlist__OM_NEW(struct IClass
*cl
, Object
*obj
, struct opSet
*msg
)
137 (STRPTR
) GetTagData(MUIA_List_Format
, 0, msg
->ops_AttrList
);
139 obj
= (Object
*) DoSuperNewTags
141 format
? TAG_IGNORE
: MUIA_List_Format
, (IPTR
) ",P=\33r,,,,",
142 TAG_MORE
, (IPTR
) msg
->ops_AttrList
);
146 struct Dirlist_DATA
*data
= INST_DATA(cl
, obj
);
148 data
->status
= MUIV_Dirlist_Status_Invalid
;
150 data
->construct_hook
.h_Entry
= (HOOKFUNC
) construct_func
;
151 data
->destruct_hook
.h_Entry
= (HOOKFUNC
) destruct_func
;
152 data
->display_hook
.h_Entry
= (HOOKFUNC
) display_func
;
153 data
->display_hook
.h_Data
= data
;
155 SetAttrs(obj
, MUIA_List_ConstructHook
,
156 (IPTR
) & data
->construct_hook
, MUIA_List_DestructHook
,
157 (IPTR
) & data
->destruct_hook
, MUIA_List_DisplayHook
,
158 (IPTR
) & data
->display_hook
, TAG_DONE
);
160 Dirlist__OM_SET(cl
, obj
, msg
);
166 IPTR
Dirlist__OM_DISPOSE(struct IClass
*cl
, Object
*obj
, Msg msg
)
168 struct Dirlist_DATA
*data
= INST_DATA(cl
, obj
);
172 return DoSuperMethodA(cl
, obj
, msg
);
175 static void ReadDirectory(Object
*obj
, struct Dirlist_DATA
*data
)
177 struct FileInfoBlock
*fib
;
180 if ((fib
= AllocDosObject(DOS_FIB
, NULL
)))
182 if ((lock
= Lock(data
->directory
, SHARED_LOCK
)))
186 success
= Examine(lock
, fib
);
188 if (success
&& (fib
->fib_DirEntryType
> 0))
194 success
= ExNext(lock
, fib
);
198 if (IoErr() == ERROR_NO_MORE_ENTRIES
)
204 isdir
= (fib
->fib_DirEntryType
> 0);
206 if (data
->filterhook
)
208 struct ExAllData ead
= { 0 };
210 ead
.ed_Name
= fib
->fib_FileName
;
211 ead
.ed_Type
= fib
->fib_DirEntryType
;
212 ead
.ed_Size
= fib
->fib_Size
;
213 ead
.ed_Prot
= fib
->fib_Protection
;
214 ead
.ed_Days
= fib
->fib_Date
.ds_Days
;
215 ead
.ed_Mins
= fib
->fib_Date
.ds_Minute
;
216 ead
.ed_Ticks
= fib
->fib_Date
.ds_Tick
;
217 ead
.ed_Comment
= fib
->fib_Comment
;
219 if (!CallHookPkt(data
->filterhook
, obj
, &ead
))
224 if (isdir
&& data
->filesonly
)
226 if (!isdir
&& data
->drawersonly
)
229 if (data
->rejecticons
)
231 WORD len
= strlen(fib
->fib_FileName
);
235 if (stricmp(fib
->fib_FileName
+ len
- 5,
241 if (!isdir
|| data
->filterdrawers
)
243 if (data
->acceptpattern
)
245 if (!MatchPatternNoCase(data
->acceptpattern
,
250 if (data
->rejectpattern
)
252 if (MatchPatternNoCase(data
->rejectpattern
,
260 set(obj
, MUIA_Dirlist_NumDrawers
,
265 set(obj
, MUIA_Dirlist_NumFiles
,
267 set(obj
, MUIA_Dirlist_NumBytes
,
268 data
->numbytes
+ fib
->fib_Size
);
271 DoMethod(obj
, MUIM_List_InsertSingle
, (IPTR
) fib
,
272 MUIV_List_Insert_Bottom
);
274 } /* no filterhook */
278 set(obj
, MUIA_Dirlist_Status
, MUIV_Dirlist_Status_Valid
);
285 FreeDosObject(DOS_FIB
, fib
);
289 IPTR
Dirlist__OM_SET(struct IClass
*cl
, Object
*obj
, struct opSet
*msg
)
291 struct Dirlist_DATA
*data
= INST_DATA(cl
, obj
);
292 struct TagItem
*tag
, *tags
;
293 BOOL directory_changed
= FALSE
;
295 for (tags
= msg
->ops_AttrList
; (tag
= NextTagItem(&tags
));)
297 IPTR tidata
= tag
->ti_Data
;
302 case MUIA_Dirlist_AcceptPattern
:
303 data
->acceptpattern
= (STRPTR
) tidata
;
306 case MUIA_Dirlist_Directory
:
307 data
->directory
= (STRPTR
) tidata
;
308 directory_changed
= TRUE
;
311 case MUIA_Dirlist_DrawersOnly
:
312 data
->drawersonly
= tidata
? TRUE
: FALSE
;
315 case MUIA_Dirlist_FilesOnly
:
316 data
->filesonly
= tidata
? TRUE
: FALSE
;
319 case MUIA_Dirlist_FilterDrawers
:
320 data
->filterdrawers
= tidata
? TRUE
: FALSE
;
323 case MUIA_Dirlist_FilterHook
:
324 data
->filterhook
= (struct Hook
*)tidata
;
327 case MUIA_Dirlist_MultiSelDirs
:
328 data
->multiseldirs
= tidata
? TRUE
: FALSE
;
331 case MUIA_Dirlist_RejectIcons
:
332 data
->rejecticons
= tidata
? TRUE
: FALSE
;
335 case MUIA_Dirlist_RejectPattern
:
336 data
->rejectpattern
= (STRPTR
) tidata
;
339 case MUIA_Dirlist_SortDirs
:
340 data
->sortdirs
= tidata
? TRUE
: FALSE
;
343 case MUIA_Dirlist_SortHighLow
:
344 data
->sorthighlow
= tidata
? TRUE
: FALSE
;
347 case MUIA_Dirlist_SortType
:
348 data
->sorttype
= tidata
;
351 case MUIA_Dirlist_Status
:
352 data
->status
= tidata
;
358 if (directory_changed
)
360 if (data
->status
== MUIV_Dirlist_Status_Valid
)
362 DoMethod(obj
, MUIM_List_Clear
);
364 SetAttrs(obj
, MUIA_Dirlist_Status
, MUIV_Dirlist_Status_Invalid
,
365 MUIA_Dirlist_NumBytes
, 0,
366 MUIA_Dirlist_NumFiles
, 0,
367 MUIA_Dirlist_NumDrawers
, 0, TAG_DONE
);
373 ReadDirectory(obj
, data
);
378 return (msg
->MethodID
== OM_SET
) ? DoSuperMethodA(cl
, obj
,
383 IPTR
Dirlist__OM_GET(struct IClass
*cl
, Object
*obj
, struct opGet
*msg
)
385 struct Dirlist_DATA
*data
= INST_DATA(cl
, obj
);
387 #define STORE *(msg->opg_Storage)
389 switch (msg
->opg_AttrID
)
391 case MUIA_Dirlist_AcceptPattern
:
392 STORE
= (IPTR
) data
->acceptpattern
;
395 case MUIA_Dirlist_Directory
:
396 STORE
= (IPTR
) data
->directory
;
399 case MUIA_Dirlist_DrawersOnly
:
400 STORE
= data
->drawersonly
;
403 case MUIA_Dirlist_FilesOnly
:
404 STORE
= data
->filesonly
;
407 case MUIA_Dirlist_FilterDrawers
:
408 STORE
= data
->filterdrawers
;
411 case MUIA_Dirlist_FilterHook
:
412 STORE
= (IPTR
) data
->filterhook
;
415 case MUIA_Dirlist_MultiSelDirs
:
416 STORE
= data
->multiseldirs
;
419 case MUIA_Dirlist_NumBytes
:
420 STORE
= data
->numbytes
;
423 case MUIA_Dirlist_NumFiles
:
424 STORE
= data
->numfiles
;
427 case MUIA_Dirlist_NumDrawers
:
428 STORE
= data
->numdrawers
;
431 case MUIA_Dirlist_Path
:
440 if (data
->status
== MUIV_Dirlist_Status_Valid
)
442 struct FileInfoBlock
*fib
;
444 DoMethod(obj
, MUIM_List_GetEntry
, MUIV_List_GetEntry_Active
,
450 strlen(fib
->fib_FileName
) + strlen(data
->directory
) + 3;
452 data
->path
= AllocVec(len
, MEMF_ANY
);
455 strcpy(data
->path
, data
->directory
);
456 if (AddPart(data
->path
, fib
->fib_FileName
, len
))
458 STORE
= (IPTR
) data
->path
;
465 case MUIA_Dirlist_RejectIcons
:
466 STORE
= data
->rejecticons
;
469 case MUIA_Dirlist_RejectPattern
:
470 STORE
= (IPTR
) data
->rejectpattern
;
473 case MUIA_Dirlist_SortDirs
:
474 STORE
= data
->sortdirs
;
477 case MUIA_Dirlist_SortHighLow
:
478 STORE
= data
->sorthighlow
;
481 case MUIA_Dirlist_SortType
:
482 STORE
= data
->sorttype
;
485 case MUIA_Dirlist_Status
:
486 STORE
= data
->status
;
490 return DoSuperMethodA(cl
, obj
, (Msg
) msg
);
494 IPTR
Dirlist__MUIM_Dirlist_ReRead(struct IClass
*cl
, Object
*obj
,
495 struct MUIP_Dirlist_ReRead
*msg
)
497 struct Dirlist_DATA
*data
= INST_DATA(cl
, obj
);
499 set(obj
, MUIA_List_Quiet
, TRUE
);
500 if (data
->status
== MUIV_Dirlist_Status_Valid
)
502 DoMethod(obj
, MUIM_List_Clear
);
504 SetAttrs(obj
, MUIA_Dirlist_Status
, MUIV_Dirlist_Status_Invalid
,
505 MUIA_Dirlist_NumBytes
, 0,
506 MUIA_Dirlist_NumFiles
, 0,
507 MUIA_Dirlist_NumDrawers
, 0, TAG_DONE
);
512 ReadDirectory(obj
, data
);
514 set(obj
, MUIA_List_Quiet
, FALSE
);
520 #if ZUNE_BUILTIN_DIRLIST
521 BOOPSI_DISPATCHER(IPTR
, Dirlist_Dispatcher
, cl
, obj
, msg
)
523 switch (msg
->MethodID
)
526 return Dirlist__OM_NEW(cl
, obj
, (struct opSet
*)msg
);
528 return Dirlist__OM_DISPOSE(cl
, obj
, msg
);
530 return Dirlist__OM_SET(cl
, obj
, (struct opSet
*)msg
);
532 return Dirlist__OM_GET(cl
, obj
, (struct opGet
*)msg
);
533 case MUIM_Dirlist_ReRead
:
534 return Dirlist__MUIM_Dirlist_ReRead(cl
, obj
, (struct opGet
*)msg
);
536 return DoSuperMethodA(cl
, obj
, msg
);
539 BOOPSI_DISPATCHER_END
541 const struct __MUIBuiltinClass _MUI_Dirlist_desc
=
545 sizeof(struct Dirlist_DATA
),
546 (void *) Dirlist_Dispatcher
548 #endif /* ZUNE_BUILTIN_DIRLIST */