3 #include <proto/intuition.h>
4 #include <proto/muimaster.h>
5 #include <proto/utility.h>
7 #include <libraries/mui.h>
8 #include <libraries/gadtools.h>
10 #include "muimiamipanel_intern.h"
11 #include "muimiamipanel_locale.h"
12 #include "muimiamipanel_misc.h"
13 #include "muimiamipanel_commands.h"
15 #include <mui/Busy_mcc.h>
17 /***********************************************************************/
19 struct MiamiPanelIfClass_DATA
52 FLG_UseBusyBar
= 1<<0,
53 FLG_BusyBarInUse
= 1<<1,
56 /***********************************************************************/
58 #define SHOW_ALL (MIAMIPANELV_Init_Flags_ShowStatusButton|MIAMIPANELV_Init_Flags_ShowSpeed|MIAMIPANELV_Init_Flags_ShowDataTransferRate|MIAMIPANELV_Init_Flags_ShowUpTime|MIAMIPANELV_Init_Flags_ShowTotal)
60 static struct MiamiPanelBase_intern
*MiamiPanelBaseIntern
;
63 MUIPC_If__OM_NEW(struct IClass
*CLASS
,Object
*self
,struct opSet
*message
)
65 struct MiamiPanelIfClass_DATA temp
;
66 struct TagItem
*attrs
= message
->ops_AttrList
, *tag
;
67 struct MPS_Prefs
*prefs
= (struct MPS_Prefs
*)GetTagData(MPA_Prefs
,NULL
,attrs
);
68 ULONG show
, lbutton
, ontime
, traffic
, rate
, speed
, some
;
71 memset(&temp
,0,sizeof(temp
));
73 name
= (UBYTE
*)GetTagData(MPA_If_Name
,NULL
,attrs
);
74 temp
.unitv
= GetTagData(MPA_If_Unit
,-1,attrs
);
76 show
= (tag
= FindTagItem(MPA_Show
,attrs
)) ? tag
->ti_Data
: SHOW_ALL
;
77 lbutton
= show
& MIAMIPANELV_Init_Flags_ShowStatusButton
;
78 ontime
= show
& MIAMIPANELV_Init_Flags_ShowUpTime
;
79 traffic
= show
& MIAMIPANELV_Init_Flags_ShowTotal
;
80 rate
= show
& MIAMIPANELV_Init_Flags_ShowDataTransferRate
;
81 speed
= show
& MIAMIPANELV_Init_Flags_ShowSpeed
;
82 some
= ontime
|| traffic
|| rate
|| speed
;
84 if (self
= (Object
*)DoSuperNewTags
88 Child
, temp
.g
= HGroup
,
90 Child
, temp
.name
= TextObject
,
91 MUIA_Text_PreParse
, MUIX_B MUIX_U MUIX_C
,
92 MUIA_Font
, MUIV_Font_Big
,
93 MUIA_FixWidthTxt
, "XXXXXXXX",
96 //Child, temp.slabel = olabel1(MSG_IF_Title_State, MiamiPanelBaseIntern),
98 Child
, temp
.state
= TextObject
,
99 //MUIA_Frame, MUIV_Frame_Text,
100 //MUIA_Background, MUII_TextBack,
103 lbutton
? Child
: TAG_IGNORE
, lbutton
? (temp
.lbutton
= NewObject(MiamiPanelBaseIntern
->mpb_lbuttonClass
->mcc_Class
, NULL
, TAG_DONE
)) : NULL
,
106 /*some ? Child : TAG_IGNORE, some ? HGroup,
108 Child, RectangleObject, MUIA_Weight, 10, End,
109 Child, RectangleObject, MUIA_Rectangle_HBar, TRUE, End,
110 Child, RectangleObject, MUIA_Weight, 10, End,
113 some
? Child
: TAG_IGNORE
, some
? VSpace(4) : 0,
115 some
? Child
: TAG_IGNORE
, some
? ColGroup(2),
116 ontime
? Child
: TAG_IGNORE
, ontime
? olabel(MSG_IF_Title_OnTime
, MiamiPanelBaseIntern
) : NULL
,
117 ontime
? Child
: TAG_IGNORE
, ontime
? (temp
.ontime
= NewObject(MiamiPanelBaseIntern
->mpb_timeTextClass
->mcc_Class
, NULL
, TAG_DONE
)) : NULL
,
119 traffic
? Child
: TAG_IGNORE
, traffic
? olabel(MSG_IF_Title_Traffic
, MiamiPanelBaseIntern
) : NULL
,
120 traffic
? Child
: TAG_IGNORE
, traffic
? (temp
.traffic
= NewObject(MiamiPanelBaseIntern
->mpb_trafficClass
->mcc_Class
, NULL
, MPA_Prefs
, prefs
, TAG_DONE
)) : NULL
,
122 rate
? Child
: TAG_IGNORE
, rate
? olabel(MSG_IF_Title_Rate
, MiamiPanelBaseIntern
) : NULL
,
123 rate
? Child
: TAG_IGNORE
, rate
? (temp
.rate
= NewObject(MiamiPanelBaseIntern
->mpb_rateClass
->mcc_Class
, NULL
, MPA_Prefs
, prefs
, TAG_DONE
)) : NULL
,
125 speed
? Child
: TAG_IGNORE
, speed
? olabel(MSG_IF_Title_Speed
, MiamiPanelBaseIntern
) : NULL
,
126 speed
? Child
: TAG_IGNORE
, speed
? (temp
.speed
= TextObject
, End
) : NULL
,
131 struct MiamiPanelIfClass_DATA
*data
= INST_DATA(CLASS
,self
);
133 CopyMem(&temp
,data
,sizeof(struct MiamiPanelIfClass_DATA
));
135 data
->busy
= BusyObject
,
137 MUIA_Busy_ShowHideIH
, TRUE
,
138 MUIA_Busy_Speed
, MUIV_Busy_Speed_User
,
141 if (data
->cmenu
= (APTR
)GetTagData(MUIA_ContextMenu
,NULL
,attrs
))
143 data
->cmtitle
= (APTR
)DoMethod(data
->cmenu
,MUIM_FindUData
,MSG_Menu_Project
);
144 data
->cmonline
= (APTR
)DoMethod(data
->cmenu
,MUIM_FindUData
,MSG_IFGroup_CItem_Online
);
145 data
->cmoffline
= (APTR
)DoMethod(data
->cmenu
,MUIM_FindUData
,MSG_IFGroup_CItem_Offline
);
149 DoMethod(data
->lbutton
,MUIM_Notify
,MUIA_Pressed
,0,(ULONG
)self
,1,MPM_If_Switch
);
153 struct ifnode
*ifnode
;
155 if (ifnode
= findIFNode(prefs
,name
)) data
->scale
= ifnode
->scale
;
156 else data
->scale
= DEF_Scale
;
158 set(data
->rate
,MUIA_Gauge_Max
,data
->scale
);
163 message
->MethodID
= OM_SET
;
164 DoMethodA(self
,(Msg
)message
);
165 message
->MethodID
= OM_NEW
;
171 /***********************************************************************/
174 showBar(Object
*self
,struct MiamiPanelIfClass_DATA
*data
,ULONG show
)
180 get(self
,MUIA_Parent
,&parent
);
181 if (parent
) DoMethod(parent
,MUIM_Group_InitChange
);
182 DoMethod(data
->g
,MUIM_Group_InitChange
);
186 DoMethod(data
->g
,OM_ADDMEMBER
,(ULONG
)data
->busy
);
187 DoMethod(data
->g
,MUIM_Group_Sort
,(ULONG
)data
->name
,/*(ULONG)data->slabel,*/(ULONG
)data
->state
,(ULONG
)data
->busy
,(ULONG
)data
->lbutton
,NULL
);
189 else DoMethod(data
->g
,OM_REMMEMBER
,(ULONG
)data
->busy
);
191 DoMethod(data
->g
,MUIM_Group_ExitChange
);
192 if (parent
) DoMethod(parent
,MUIM_Group_ExitChange
);
196 /***********************************************************************/
199 changeState(Object
*self
,struct MiamiPanelIfClass_DATA
*data
,ULONG state
)
203 if (state
& MIAMIPANELV_AddInterface_State_GoingOnline
) state
= MIAMIPANELV_AddInterface_State_GoingOnline
, sstring
= MSG_IF_Status_GoingOnline
, busy
= TRUE
;
204 else if (state
& MIAMIPANELV_AddInterface_State_GoingOffline
) state
= MIAMIPANELV_AddInterface_State_GoingOffline
, sstring
= MSG_IF_Status_GoingOffline
, busy
= TRUE
;
205 else if (state
& MIAMIPANELV_AddInterface_State_Suspending
) state
= MIAMIPANELV_AddInterface_State_Suspending
, sstring
= MSG_IF_Status_Suspending
, busy
= TRUE
;
206 else if (state
& MIAMIPANELV_AddInterface_State_Offline
) state
= MIAMIPANELV_AddInterface_State_Offline
, sstring
= MSG_IF_Status_Offline
, busy
= FALSE
;
207 else if (state
& MIAMIPANELV_AddInterface_State_Online
) state
= MIAMIPANELV_AddInterface_State_Online
, sstring
= MSG_IF_Status_Online
, busy
= FALSE
;
208 else if (state
& MIAMIPANELV_AddInterface_State_Suspended
) state
= MIAMIPANELV_AddInterface_State_Suspended
, sstring
= MSG_IF_Status_Suspended
, busy
= FALSE
;
209 else state
= MIAMIPANELV_AddInterface_State_Offline
, sstring
= MSG_IF_Status_Offline
, busy
= FALSE
;
211 data
->statev
= state
;
213 if (data
->lbutton
) set(data
->lbutton
,MPA_LButton_State
,state
);
214 set(data
->state
,MUIA_Text_Contents
, __(sstring
));
216 if ((data
->flags
& FLG_UseBusyBar
) && !BOOLSAME(data
->flags
& FLG_BusyBarInUse
,busy
))
217 showBar(self
,data
,busy
);
219 if (busy
) data
->flags
|= FLG_BusyBarInUse
;
220 else data
->flags
&= ~FLG_BusyBarInUse
;
225 /***********************************************************************/
228 MUIPC_If__OM_SET(struct IClass
*CLASS
,Object
*self
,struct opSet
*message
)
230 struct MiamiPanelIfClass_DATA
*data
= INST_DATA(CLASS
,self
);
232 struct TagItem
*tstate
;
234 for (tstate
= message
->ops_AttrList
; tag
= NextTagItem(&tstate
); )
236 ULONG tidata
= tag
->ti_Data
;
241 stccpy(data
->namev
,(UBYTE
*)tidata
,sizeof(data
->namev
));
242 set(data
->name
,MUIA_Text_Contents
,tidata
);
246 changeState(self
,data
,tidata
);
250 data
->ontimev
= tidata
;
254 if (data
->ontime
) set(data
->ontime
,MPA_Value
,tidata
-data
->ontimev
);
258 if (data
->traffic
) set(data
->traffic
,MPA_Value
,tidata
);
262 if (data
->rate
) set(data
->rate
,MPA_Value
,tidata
);
266 if (data
->speed
) set(data
->speed
,MUIA_Text_Contents
,tidata
);
270 if (!BOOLSAME(data
->flags
& FLG_UseBusyBar
,PREFS(tidata
)->flags
& MPV_Flags_UseBusyBar
))
272 if (PREFS(tidata
)->flags
& MPV_Flags_UseBusyBar
) data
->flags
|= FLG_UseBusyBar
;
273 else data
->flags
&= ~FLG_UseBusyBar
;
275 if (data
->flags
& FLG_BusyBarInUse
)
276 showBar(self
,data
,data
->flags
& FLG_UseBusyBar
);
281 struct ifnode
*ifnode
;
283 if (ifnode
= findIFNode(PREFS(tidata
),data
->namev
))
284 set(data
->rate
, MUIA_Gauge_Max
, (data
->scale
= ifnode
->scale
));
290 return DoSuperMethodA(CLASS
,self
,(Msg
)message
);
293 /***********************************************************************/
296 MUIPC_If__OM_GET(struct IClass
*CLASS
,Object
*self
,struct opGet
*message
)
298 struct MiamiPanelIfClass_DATA
*data
= INST_DATA(CLASS
,self
);
300 switch(message
->opg_AttrID
)
302 case MPA_If_Unit
: *message
->opg_Storage
= data
->unitv
; return TRUE
;
303 case MPA_If_State
: *message
->opg_Storage
= data
->statev
; return TRUE
;
304 case MPA_If_Name
: *message
->opg_Storage
= (ULONG
)data
->namev
; return TRUE
;
305 case MPA_If_Scale
: *message
->opg_Storage
= data
->scale
; return TRUE
;
306 default: return DoSuperMethodA(CLASS
,self
,(Msg
)message
);
310 /***********************************************************************/
313 MUIPC_If__MPM_If_Switch(struct IClass
*CLASS
,Object
*self
,Msg message
)
315 struct MiamiPanelIfClass_DATA
*data
= INST_DATA(CLASS
,self
);
317 switch (data
->statev
)
319 case MIAMIPANELV_AddInterface_State_GoingOnline
:
320 case MIAMIPANELV_AddInterface_State_Online
:
321 MiamiPanelFun(MIAMIPANELV_CallBack_Code_UnitOffline
,data
->unitv
);
324 case MIAMIPANELV_AddInterface_State_Suspending
:
325 case MIAMIPANELV_AddInterface_State_Suspended
:
329 MiamiPanelFun(MIAMIPANELV_CallBack_Code_UnitOnline
,data
->unitv
);
336 /***********************************************************************/
339 MUIPC_If__MUIM_ContextMenuBuild(struct IClass
*CLASS
,Object
*self
,struct MUIP_ContextMenuBuild
*message
)
341 struct MiamiPanelIfClass_DATA
*data
= INST_DATA(CLASS
,self
);
347 switch (data
->statev
)
349 case MIAMIPANELV_AddInterface_State_GoingOnline
:
350 case MIAMIPANELV_AddInterface_State_Online
:
355 case MIAMIPANELV_AddInterface_State_Suspending
:
356 case MIAMIPANELV_AddInterface_State_Suspended
:
366 set(data
->cmtitle
,MUIA_Menu_Title
, data
->namev
);
367 set(data
->cmonline
,MUIA_Menuitem_Enabled
,on
);
368 set(data
->cmoffline
,MUIA_Menuitem_Enabled
,off
);
371 set((Object
*)DoMethod(data
->cmenu
,MUIM_FindUData
,valueToID(data
->scale
)),MUIA_Menuitem_Checked
,TRUE
);
373 return (ULONG
)data
->cmenu
;
376 return DoSuperMethodA(CLASS
,self
,(Msg
)message
);
379 /***********************************************************************/
382 MUIPC_If__MUIM_ContextMenuChoice(struct IClass
*CLASS
,Object
*self
,struct MUIP_ContextMenuChoice
*message
)
384 struct MiamiPanelIfClass_DATA
*data
= INST_DATA(CLASS
,self
);
385 ULONG item
= muiUserData(message
->item
);
389 case MSG_IFGroup_CItem_Online
:
390 case MSG_IFGroup_CItem_Offline
:
391 DoMethod(data
->this,MPM_If_Switch
);
394 case TAG_SCALE_1
: case TAG_SCALE_2
: case TAG_SCALE_3
:
395 case TAG_SCALE_4
: case TAG_SCALE_5
: case TAG_SCALE_6
:
396 case TAG_SCALE_7
: case TAG_SCALE_8
:
399 data
->scale
= IDToValue((ULONG
)item
, MiamiPanelBaseIntern
);
400 set(data
->rate
,MUIA_Gauge_Max
,data
->scale
);
408 /***********************************************************************/
410 BOOPSI_DISPATCHER(IPTR
, MUIPC_If_Dispatcher
, CLASS
, self
, message
)
412 switch (message
->MethodID
)
414 case OM_NEW
: return MUIPC_If__OM_NEW(CLASS
,self
,(APTR
)message
);
415 case OM_SET
: return MUIPC_If__OM_SET(CLASS
,self
,(APTR
)message
);
416 case OM_GET
: return MUIPC_If__OM_GET(CLASS
,self
,(APTR
)message
);
417 case MUIM_ContextMenuChoice
: return MUIPC_If__MUIM_ContextMenuChoice(CLASS
,self
,(APTR
)message
);
418 case MUIM_ContextMenuBuild
: return MUIPC_If__MUIM_ContextMenuBuild(CLASS
,self
,(APTR
)message
);
419 case MPM_If_Switch
: return MUIPC_If__MPM_If_Switch(CLASS
,self
,(APTR
)message
);
420 default: return DoSuperMethodA(CLASS
,self
,message
);
424 BOOPSI_DISPATCHER_END
426 /***********************************************************************/
429 MUIPC_If_ClassInit(struct MiamiPanelBase_intern
*MiamiPanelBase
)
431 MiamiPanelBaseIntern
= MiamiPanelBase
;
432 return (ULONG
)(MiamiPanelBaseIntern
->mpb_ifClass
= MUI_CreateCustomClass(NULL
, MUIC_Group
, NULL
, sizeof(struct MiamiPanelIfClass_DATA
), MUIPC_If_Dispatcher
));
435 /***********************************************************************/