2 Copyright 2004-2010, The AROS Development Team. All rights reserved.
6 #include "portable_macros.h"
8 #define MUIMASTER_YES_INLINE_STDARG
13 #include <aros/debug.h>
16 #include <exec/types.h>
17 #include <libraries/mui.h>
20 #include <zune/customclasses.h>
22 #include <zune_AROS/customclasses.h>
25 #include <proto/utility.h>
27 #include <proto/graphics.h>
29 #include <proto/exec.h>
30 #include <proto/datatypes.h>
33 #include <proto/dos.h>
35 #include <proto/icon.h>
40 #include <intuition/screens.h>
41 #include <datatypes/pictureclass.h>
42 #include <clib/macros.h>
45 #include <clib/alib_protos.h>
47 #include <prefs/wanderer.h>
49 #include <prefs_AROS/wanderer.h>
52 #if defined(__AMIGA__) && !defined(__PPC__)
53 #define NO_INLINE_STDARG
55 #ifndef _PROTO_INTUITION_H
56 #include <proto/intuition.h>
58 #include <proto/muimaster.h>
60 #include "Classes/iconlist.h"
61 #include "Classes/iconlistview.h"
62 #include "Classes/iconlist_attributes.h"
63 #include "Classes/icon_attributes.h"
65 #include "wandererprefs.h"
67 #include "iconwindow.h"
68 #include "iconwindow_attributes.h"
70 extern struct List iconwindow_Extensions
;
72 /*** Private Data *********************************************************/
74 static CONST_STRPTR extension_Name
= "IconWindow StatusBar Extension";
75 static CONST_STRPTR extension_PrefsFile
= "ENV:SYS/Wanderer/statusbar.prefs";
76 static STRPTR extension_PrefsData
;
77 static struct iconWindow_Extension panelStatusBar__Extension
;
78 static struct List panelStatusBar__StatusBars
;
79 static struct NotifyRequest panelStatusBar__PrefsNotifyRequest
;
80 static Object
*panelStatusBar__PrefsNotificationObject
;
82 struct panel_StatusBar_DATA
86 Object
*iwp_StatusBar_StatusBarObj
;
87 Object
*iwp_StatusBar_StatusTextObj
;
89 struct Hook iwp_StatusBar_updateHook
;
91 struct Hook
*iwp_StatusBar_updateHook
;
95 /// From panel_toolbar
96 STRPTR
ExpandEnvName(CONST_STRPTR env_path
);
99 const UBYTE MSG_MEM_G
[] = "GB";
100 const UBYTE MSG_MEM_M
[] = "MB";
101 const UBYTE MSG_MEM_K
[] = "KB";
102 const UBYTE MSG_MEM_B
[] = "Bytes";
105 static void FmtSizeToString(UBYTE
*buf
, ULONG num
)
119 if (num
>= 1073741824)
122 array
.val
= num
>> 30;
123 d
= ((UQUAD
)num
* 10 + 536870912) / 1073741824;
127 else if (num
>= 1048576)
130 array
.val
= num
>> 20;
131 d
= ((UQUAD
)num
* 10 + 524288) / 1048576;
135 else if (num
>= 1024)
138 array
.val
= num
>> 10;
139 d
= (num
* 10 + 512) / 1024;
152 if (!array
.dec
&& (d
> array
.val
* 10))
157 RawDoFmt(array
.dec
? "%lu.%lu" : "%lu", &array
, NULL
, buf
);
164 sprintf(buf
, " %s", ch
);
168 /*** Hook functions *********************************************************/
170 ///panelStatusBar__HookFunc_UpdateStatusFunc()
173 void, panelStatusBar__HookFunc_UpdateStatusFunc
,
174 AROS_UFHA(struct Hook
*, hook
, A0
),
175 AROS_UFHA(APTR
*, obj
, A2
),
176 AROS_UFHA(APTR
, param
, A1
)
180 HOOKPROTO(panelStatusBar__HookFunc_UpdateStatusFunc
, void, APTR
*obj
, APTR param
)
186 Object
*self
= ( Object
*)obj
;
187 Class
*CLASS
= *( Class
**)param
;
188 struct panel_StatusBar_DATA
*panelStatusBarPrivate
= NULL
;
190 SETUP_ICONWINDOW_INST_DATA
;
192 D(bug("[IW.statusbar]: %s()\n", __PRETTY_FUNCTION__
));
194 /* Only change dir if it is a valid directory/volume */
195 if ((panelStatusBarPrivate
= (struct panel_StatusBar_DATA
*)data
->iwd_BottomPanel
.iwp_PanelPrivate
) != NULL
)
197 if (panelStatusBarPrivate
->iwp_Node
.ln_Name
!= (char *)extension_Name
)
200 struct List
*iconList
= NULL
;
201 struct IconEntry
*icon
= NULL
;
202 UBYTE status_str
[1024];
205 int files
= 0, dirs
= 0, hidden
= 0;
208 GET(data
->iwd_IconListObj
, MUIA_Family_List
, &iconList
);
211 ForeachNode(iconList
, icon
)
213 if (icon
->ie_Flags
& ICONENTRY_FLAG_VISIBLE
)
215 if (icon
->ie_IconListEntry
.type
== ST_USERDIR
)
222 if (icon
->ie_FileInfoBlock
)
224 size
+= icon
->ie_FileInfoBlock
->fib_Size
;
225 D(bug("[IW.statusbar] %s: '%s' FIB Size = %d bytes\n", __PRETTY_FUNCTION__
, icon
->ie_IconNode
.ln_Name
, icon
->ie_FileInfoBlock
->fib_Size
));
238 FmtSizeToString(size_str
, size
);
239 sprintf(status_str
, " %s in %d files", size_str
, files
);
240 previous
= strlen(status_str
);
244 sprintf(status_str
+ previous
, "%s%d drawers", (previous
> 0) ? ", " : " " , dirs
);
245 previous
= strlen(status_str
);
249 sprintf(status_str
+ previous
, " (%d hidden)", hidden
);
250 previous
= strlen(status_str
);
255 SET(panelStatusBarPrivate
->iwp_StatusBar_StatusTextObj
, MUIA_Text_Contents
, (IPTR
)status_str
);
259 SET(panelStatusBarPrivate
->iwp_StatusBar_StatusTextObj
, MUIA_Text_Contents
, (IPTR
)"");
266 MakeStaticHook(StatusBar_updateHook
, panelStatusBar__HookFunc_UpdateStatusFunc
);
269 /*** Main Functions ****************************************************************/
271 #define STATUSBAR_PREFSSIZE 1024
272 static IPTR
panelStatusBar__HandleFSUpdate(Object
*WandererObj
, struct NotifyMessage
*msg
)
274 if (GetVar(extension_PrefsFile
, extension_PrefsData
, STATUSBAR_PREFSSIZE
, GVF_GLOBAL_ONLY
) != -1)
276 D(bug("[IW.statusbar] %s: Prefs contain '%s'\n", __PRETTY_FUNCTION__
, extension_PrefsData
));
277 if ((strcasecmp(extension_PrefsData
, "True")) == 0)
279 SET(panelStatusBar__PrefsNotificationObject
, MUIA_ShowMe
, TRUE
);
283 SET(panelStatusBar__PrefsNotificationObject
, MUIA_ShowMe
, FALSE
);
289 ///panelStatusBar__PrefsSetup()
290 static IPTR
panelStatusBar__PrefsSetup(Class
*CLASS
, Object
*self
, struct opSet
*message
)
292 IPTR panelStatusBarFSNotifyPort
= 0;
293 struct panel_StatusBar_DATA
*panelStatusBarPrivate
= NULL
;
294 struct List
*panelStatusBarFSNotifyList
= NULL
;
296 SETUP_ICONWINDOW_INST_DATA
;
298 panelStatusBarFSNotifyPort
= GetTagData(MUIA_Wanderer_FileSysNotifyPort
, (IPTR
) NULL
, message
->ops_AttrList
);
299 panelStatusBarFSNotifyList
= (APTR
)GetTagData(MUIA_Wanderer_FileSysNotifyList
, (IPTR
) NULL
, message
->ops_AttrList
);
301 D(bug("[IW.statusbar]: %s()\n", __PRETTY_FUNCTION__
));
303 if ((panelStatusBarPrivate
= (struct panel_StatusBar_DATA
*)data
->iwd_BottomPanel
.iwp_PanelPrivate
) != NULL
)
305 if (panelStatusBarPrivate
->iwp_Node
.ln_Name
!= (char *)extension_Name
)
308 extension_PrefsData
= AllocVec(STATUSBAR_PREFSSIZE
, MEMF_CLEAR
);
310 /* Setup notification on prefs file --------------------------------*/
311 struct Wanderer_FSHandler
*_prefsNotifyHandler
= NULL
;
313 if ((_prefsNotifyHandler
= AllocMem(sizeof(struct Wanderer_FSHandler
), MEMF_CLEAR
)) != NULL
)
315 _prefsNotifyHandler
->fshn_Node
.ln_Name
= ExpandEnvName(extension_PrefsFile
);
316 panelStatusBar__PrefsNotifyRequest
.nr_Name
= _prefsNotifyHandler
->fshn_Node
.ln_Name
;
317 panelStatusBar__PrefsNotifyRequest
.nr_Flags
= NRF_SEND_MESSAGE
;
318 panelStatusBar__PrefsNotifyRequest
.nr_stuff
.nr_Msg
.nr_Port
= (struct MsgPort
*)panelStatusBarFSNotifyPort
;
319 _prefsNotifyHandler
->HandleFSUpdate
= panelStatusBar__HandleFSUpdate
;
321 if (StartNotify(&panelStatusBar__PrefsNotifyRequest
))
323 D(bug("[IW.statusbar]%s: Prefs-notification setup on '%s'\n", __PRETTY_FUNCTION__
, panelStatusBar__PrefsNotifyRequest
.nr_Name
));
327 D(bug("[IW.statusbar] %s: FAILED to setup Prefs-notification!\n", __PRETTY_FUNCTION__
));
329 AddTail(panelStatusBarFSNotifyList
, &_prefsNotifyHandler
->fshn_Node
);
332 panelStatusBar__PrefsNotificationObject
= (Object
*)NotifyObject
, End
;
334 panelStatusBar__PrefsNotificationObject
= MUI_NewObject(MUIC_Notify
, TAG_DONE
);
336 if (GetVar(extension_PrefsFile
, extension_PrefsData
, STATUSBAR_PREFSSIZE
, GVF_GLOBAL_ONLY
) != -1)
338 D(bug("[IW.statusbar] %s: Prefs contain '%s'\n", __PRETTY_FUNCTION__
, extension_PrefsData
));
345 ///panelStatusBar__Setup()
346 static IPTR
panelStatusBar__Setup(Class
*CLASS
, Object
*self
, struct opSet
*message
)
348 SETUP_ICONWINDOW_INST_DATA
;
350 Object
*panel_StatusBar
= NULL
,
351 *panelStatusBar_TextStatus
= NULL
;
353 struct panel_StatusBar_DATA
*panelStatusBarPrivate
= NULL
;
355 if (!(!(data
->iwd_Flags
& IWDFLAG_ISROOT
) && data
->iwd_BottomPanel
.iwp_PanelContainerObj
))
358 D(bug("[IW.statusbar]: %s()\n", __PRETTY_FUNCTION__
));
360 if (data
->iwd_BottomPanel
.iwp_PanelPrivate
== 0)
362 if ((data
->iwd_BottomPanel
.iwp_PanelPrivate
= (IPTR
)AllocVec(sizeof(struct panel_StatusBar_DATA
), MEMF_CLEAR
)) == (IPTR
)NULL
)
365 panelStatusBarPrivate
= (struct panel_StatusBar_DATA
*)data
->iwd_BottomPanel
.iwp_PanelPrivate
;
366 panelStatusBarPrivate
->iwp_Node
.ln_Name
= (char *)extension_Name
;
368 /* Create the "StatusBar" panel object .. */
369 panel_StatusBar
= MUI_NewObject(MUIC_Group
,
373 MUIA_InnerBottom
,(0),
374 MUIA_Frame
, MUIV_Frame_None
,
375 Child
, (IPTR
)MUI_NewObject(MUIC_Group
, MUIA_Group_Horiz
, TRUE
,
379 MUIA_InnerBottom
,(0),
380 MUIA_Group_Spacing
, 0,
382 MUIA_Frame
, MUIV_Frame_None
,
383 MUIA_Background
, MUII_SHADOW
,
384 Child
, (IPTR
)MUI_NewObject(MUIC_Rectangle
,
385 MUIA_Frame
, MUIV_Frame_None
,
388 Child
, (IPTR
)MUI_NewObject(MUIC_Group
, MUIA_Group_Horiz
, TRUE
,
392 MUIA_InnerBottom
,(4),
393 MUIA_Frame
, MUIV_Frame_None
,
395 Child
, (IPTR
)MUI_NewObject(MUIC_Group
, MUIA_Group_Horiz
, TRUE
,
399 MUIA_InnerBottom
,(0),
401 Child
, (IPTR
)( panelStatusBar_TextStatus
= MUI_NewObject(MUIC_Text
,
402 MUIA_Font
, MUIV_Font_Tiny
,
403 MUIA_Text_Contents
, (IPTR
)"",
409 /* Got a StatusBarPanel? setup notifies and other values are
410 copied to the data of the object */
411 if ( panel_StatusBar
!= NULL
)
413 D(bug("[IW.statusbar] %s: StatusBar Obj @ 0x%p\n", __PRETTY_FUNCTION__
, panel_StatusBar
));
415 panelStatusBarPrivate
->iwp_StatusBar_StatusTextObj
= panelStatusBar_TextStatus
;
416 panelStatusBarPrivate
->iwp_StatusBar_StatusBarObj
= panel_StatusBar
;
418 if (DoMethod(data
->iwd_BottomPanel
.iwp_PanelGroupObj
, MUIM_Group_InitChange
))
420 DoMethod(data
->iwd_BottomPanel
.iwp_PanelGroupObj
, OM_ADDMEMBER
, (IPTR
)panel_StatusBar
);
421 if (data
->iwd_BottomPanel
.iwp_PanelGroupSpacerObj
)
423 DoMethod(data
->iwd_BottomPanel
.iwp_PanelGroupObj
, OM_REMMEMBER
, (IPTR
)data
->iwd_BottomPanel
.iwp_PanelGroupSpacerObj
);
424 data
->iwd_BottomPanel
.iwp_PanelGroupSpacerObj
= NULL
;
427 DoMethod(data
->iwd_BottomPanel
.iwp_PanelGroupObj
, MUIM_Group_ExitChange
);
430 if (panelStatusBarPrivate
->iwp_StatusBar_StatusBarObj
)
433 panelStatusBarPrivate
->iwp_StatusBar_updateHook
.h_Entry
= ( HOOKFUNC
)panelStatusBar__HookFunc_UpdateStatusFunc
;
435 panelStatusBarPrivate
->iwp_StatusBar_updateHook
= &StatusBar_updateHook
;
438 data
->iwd_IconListObj
, MUIM_Notify
, MUIA_IconList_Changed
, MUIV_EveryTime
,
439 (IPTR
)self
, 3, MUIM_CallHook
, &panelStatusBarPrivate
->iwp_StatusBar_updateHook
, (IPTR
)CLASS
442 if (!(panelStatusBar__PrefsNotificationObject
))
443 panelStatusBar__PrefsSetup(CLASS
, self
, message
);
447 panelStatusBar__PrefsNotificationObject
, MUIM_Notify
, MUIA_ShowMe
, MUIV_EveryTime
,
448 (IPTR
)data
->iwd_BottomPanel
.iwp_PanelContainerObj
, 3, MUIM_Set
, MUIA_ShowMe
, MUIV_TriggerValue
451 if ((strcasecmp(extension_PrefsData
, "True")) == 0)
453 SET(data
->iwd_BottomPanel
.iwp_PanelContainerObj
, MUIA_ShowMe
, TRUE
);
456 AddTail(&panelStatusBar__StatusBars
, &panelStatusBarPrivate
->iwp_Node
);
461 panelStatusBarPrivate
->iwp_StatusBar_StatusBarObj
= NULL
;
468 ///panelStatusBar__Cleanup()
469 static IPTR
panelStatusBar__Cleanup(Class
*CLASS
, Object
*self
, Msg msg
)
471 SETUP_ICONWINDOW_INST_DATA
;
472 struct panel_StatusBar_DATA
*panelStatusBarPrivate
;
474 D(bug("[IW.statusbar]: %s()\n", __PRETTY_FUNCTION__
));
476 if ((panelStatusBarPrivate
= (struct panel_StatusBar_DATA
*)data
->iwd_TopPanel
.iwp_PanelPrivate
) != NULL
)
478 if (panelStatusBarPrivate
->iwp_Node
.ln_Name
!= (char *)extension_Name
)
481 if (panelStatusBar__PrefsNotificationObject
)
485 panelStatusBar__PrefsNotificationObject
, MUIM_KillNotifyObj
, MUIA_ShowMe
,
486 (IPTR
)data
->iwd_BottomPanel
.iwp_PanelContainerObj
494 ///panelStatusBar__OM_GET()
495 static IPTR
panelStatusBar__OM_GET(Class
*CLASS
, Object
*self
, struct opGet
*message
)
497 SETUP_ICONWINDOW_INST_DATA
;
499 struct panel_StatusBar_DATA
*panelStatusBarPrivate
= NULL
;
500 // IPTR *store = message->opg_Storage;
503 D(bug("[IW.statusbar]: %s()\n", __PRETTY_FUNCTION__
));
505 if ((panelStatusBarPrivate
= (struct panel_StatusBar_DATA
*)data
->iwd_BottomPanel
.iwp_PanelPrivate
) != NULL
)
507 if (panelStatusBarPrivate
->iwp_Node
.ln_Name
!= (char *)extension_Name
)
510 switch (message
->opg_AttrID
)
519 static IPTR
panelStatusBar__OM_SET(Class
*CLASS
, Object
*self
, struct opSet
*message
)
521 SETUP_ICONWINDOW_INST_DATA
;
523 struct panel_StatusBar_DATA
*panelStatusBarPrivate
= NULL
;
524 struct TagItem
*tstate
= message
->ops_AttrList
, *tag
;
525 // BOOL UpdateIconlist = FALSE;
526 // IPTR focusicon = (IPTR) NULL;
529 D(bug("[IW.statusbar]: %s()\n", __PRETTY_FUNCTION__
));
531 if ((panelStatusBarPrivate
= (struct panel_StatusBar_DATA
*)data
->iwd_BottomPanel
.iwp_PanelPrivate
) != NULL
)
533 if (panelStatusBarPrivate
->iwp_Node
.ln_Name
!= (char *)extension_Name
)
536 while ((tag
= NextTagItem((TAGITEM
)&tstate
)) != NULL
)
540 /*case MUIA_IconWindowExt_ToolBar_Enabled:
541 if ((!(data->iwd_Flags & IWDFLAG_ISROOT)) && (data->iwd_BottomPanel.iwp_PanelContainerObj))
544 if (!(( BOOL )tag->ti_Data))
546 if (panelStatusBarPrivate->iwp_StatusBar_StatusBarObj != NULL)
548 data->iwd_BottomPanel.iwp_PanelGroupSpacerObj = HSpace(0);
550 SET(data->iwd_BottomPanel.iwp_PanelContainerObj, MUIA_Frame, MUIV_Frame_None);
551 SET(data->iwd_BottomPanel.iwp_PanelContainerObj, MUIA_Group_Spacing, 0);
553 if ((data->iwd_BottomPanel.iwp_PanelGroupSpacerObj) && (DoMethod(data->iwd_BottomPanel.iwp_PanelGroupObj, MUIM_Group_InitChange)))
555 DoMethod(data->iwd_BottomPanel.iwp_PanelGroupObj, OM_REMMEMBER, (IPTR)panelStatusBarPrivate->iwp_StatusBar_StatusBarObj);
556 DoMethod(data->iwd_BottomPanel.iwp_PanelGroupObj, OM_ADDMEMBER, (IPTR)data->iwd_BottomPanel.iwp_PanelGroupSpacerObj);
557 DoMethod(data->iwd_BottomPanel.iwp_PanelGroupObj, MUIM_Group_ExitChange);
558 panelStatusBarPrivate->iwp_StatusBar_StatusBarObj = NULL;
565 if (panelStatusBarPrivate->iwp_StatusBar_StatusBarObj == NULL)
567 Object *prefs = NULL;
568 GET(_app(self), MUIA_Wanderer_Prefs, &prefs);
569 panelStatusBar__Setup(CLASS, self, prefs);
580 #define PANELSTATUSBAR_PRIORITY 10
582 IPTR
panelStatusBar__Init()
584 D(bug("[IW.statusbar]: %s()\n", __PRETTY_FUNCTION__
));
586 panelStatusBar__Extension
.iwe_Node
.ln_Pri
= PANELSTATUSBAR_PRIORITY
;
587 panelStatusBar__Extension
.iwe_Node
.ln_Name
= (char *)extension_Name
;
588 panelStatusBar__Extension
.iwe_Setup
= panelStatusBar__Setup
;
589 panelStatusBar__Extension
.iwe_Cleanup
= panelStatusBar__Cleanup
;
590 panelStatusBar__Extension
.iwe_Set
= panelStatusBar__OM_SET
;
591 panelStatusBar__Extension
.iwe_Get
= panelStatusBar__OM_GET
;
593 NewList(&panelStatusBar__StatusBars
);
595 Enqueue(&iconwindow_Extensions
, (struct Node
*)&panelStatusBar__Extension
);
597 D(bug("[IconWindow] %s: Added Extension '%s' @ %p to list @ %p\n", __PRETTY_FUNCTION__
, panelStatusBar__Extension
.iwe_Node
.ln_Name
, &panelStatusBar__Extension
.iwe_Node
, &iconwindow_Extensions
));
602 ADD2INIT(panelStatusBar__Init
, PANELSTATUSBAR_PRIORITY
);