2 #include <proto/intuition.h>
3 #include <proto/muimaster.h>
4 #include <proto/utility.h>
6 #include <libraries/mui.h>
7 #include <libraries/gadtools.h>
12 #include "muimiamipanel_intern.h"
13 #include "muimiamipanel_locale.h"
14 #include "muimiamipanel_misc.h"
16 /***********************************************************************/
18 static UBYTE
*Kbs
, *Mbs
;
20 struct MiamiPanelTrafficClass_DATA
29 FLG_NoGrouping
= 1<<1,
32 /***********************************************************************/
34 static struct MiamiPanelBase_intern
*MiamiPanelBaseIntern
;
37 MUIPC_Traffic__OM_NEW(struct IClass
*CLASS
,Object
*self
,struct opSet
*message
)
39 register struct TagItem
*attrs
= message
->ops_AttrList
;
41 if (self
= (Object
*)DoSuperNewTags(CLASS
, self
, NULL
, MUIA_Text_Contents
, "0", TAG_MORE
, attrs
))
43 message
->MethodID
= OM_SET
;
44 DoMethodA(self
,(Msg
)message
);
45 message
->MethodID
= OM_NEW
;
51 /***********************************************************************/
54 MUIPC_Traffic__OM_SET(struct IClass
*CLASS
,Object
*self
,struct opSet
*message
)
56 register struct MiamiPanelTrafficClass_DATA
*data
= INST_DATA(CLASS
,self
);
57 register struct TagItem
*tag
;
58 struct TagItem
*tstate
;
59 register ULONG redraw
;
61 for (redraw
= FALSE
, tstate
= message
->ops_AttrList
; tag
= NextTagItem(&tstate
); )
63 register ULONG tidata
= tag
->ti_Data
;
68 if (!BOOLSAME(PREFS(tidata
)->flags
& MPV_Flags_TrafficShort
,data
->flags
& FLG_Short
) ||
69 !BOOLSAME(PREFS(tidata
)->flags
& MPV_Flags_TrafficNoGrouping
,data
->flags
& FLG_NoGrouping
))
71 if (PREFS(tidata
)->flags
& MPV_Flags_TrafficShort
) data
->flags
|= FLG_Short
;
72 else data
->flags
&= ~FLG_Short
;
74 if (PREFS(tidata
)->flags
& MPV_Flags_TrafficNoGrouping
) data
->flags
|= FLG_NoGrouping
;
75 else data
->flags
&= ~FLG_NoGrouping
;
83 bigint
*bi
= (bigint
*)tidata
;
86 traffic
= ((UQUAD
)bi
->hi
<< 32) | bi
->lo
;
88 if (data
->traffic
!=traffic
)
90 data
->traffic
= traffic
;
100 UQUAD tot
= data
->traffic
;
102 if (data
->flags
& FLG_Short
)
104 UBYTE
*dp
= MiamiPanelBaseIntern
->mpb_decPoint
;
106 if (tot
>>32) /* big int */
108 UBYTE buf1
[64], buf2
[64];
113 sprintf(buf1
,"%Ld",q
);
114 if (!(data
->flags
& FLG_NoGrouping
)) grouping(buf1
, MiamiPanelBaseIntern
);
118 sprintf(buf1
,"%Ld",qd
);
120 sprintf(cont
,"%s%s%3.3s %s",buf1
,dp
,buf2
,Mbs
);
127 if (tot
>=1000000) /* Mb */
131 sprintf(buf
, "%u", q
);
133 if (!(data
->flags
& FLG_NoGrouping
)) grouping(buf
, MiamiPanelBaseIntern
);
134 sprintf(cont
,"%s%s%3.3lu %s",buf
,dp
,r
,Mbs
);
140 sprintf(buf
, "%u", q
);
141 if (!(data
->flags
& FLG_NoGrouping
)) grouping(buf
, MiamiPanelBaseIntern
);
142 sprintf(cont
,"%s%s%1.1lu %s",buf
,dp
,(r
<100) ? 0 : r
,Kbs
);
148 sprintf(cont
,"%Ld",tot
);
150 if (!(data
->flags
& FLG_NoGrouping
)) grouping(cont
, MiamiPanelBaseIntern
);
153 SetSuperAttrs(CLASS
, self
, MUIA_Text_Contents
, cont
, TAG_DONE
);
156 return DoSuperMethodA(CLASS
,self
,(Msg
)message
);
159 /***********************************************************************/
161 BOOPSI_DISPATCHER(IPTR
, MUIPC_Traffic_Dispatcher
, CLASS
, self
, message
)
163 switch (message
->MethodID
)
165 case OM_SET
: return MUIPC_Traffic__OM_SET(CLASS
,self
,(APTR
)message
);
166 case OM_NEW
: return MUIPC_Traffic__OM_NEW(CLASS
,self
,(APTR
)message
);
167 default: return DoSuperMethodA(CLASS
,self
,message
);
171 BOOPSI_DISPATCHER_END
173 /***********************************************************************/
176 MUIPC_Traffic_ClassInit(struct MiamiPanelBase_intern
*MiamiPanelBase
)
178 MiamiPanelBaseIntern
= MiamiPanelBase
;
179 if (MiamiPanelBaseIntern
->mpb_trafficClass
= MUI_CreateCustomClass(NULL
, MUIC_Text
, NULL
, sizeof(struct MiamiPanelTrafficClass_DATA
), MUIPC_Traffic_Dispatcher
))
181 Kbs
= __(MSG_Traffic_KB
);
182 Mbs
= __(MSG_Traffic_MB
);
190 /***********************************************************************/