2 * Copyright 2005, Waldemar Kornewald <wkornew@gmx.net>
3 * Distributed under the terms of the MIT License.
6 #include "PPPStatusView.h"
10 #include <StringView.h>
16 #include <PPPManager.h>
20 static const uint32 kMsgDisconnect
= 'DISC';
23 static const char *kLabelDisconnect
= "Disconnect";
24 static const char *kLabelConnectedSince
= "Connected since: ";
25 static const char *kLabelReceived
= "Received";
26 static const char *kLabelSent
= "Sent";
29 static const char *kTextBytes
= "Bytes";
30 static const char *kTextPackets
= "Packets";
33 PPPStatusView::PPPStatusView(BRect rect
, ppp_interface_id id
)
34 : BView(rect
, "PPPStatusView", B_FOLLOW_NONE
, B_PULSE_NEEDED
),
37 SetViewUIColor(B_PANEL_BACKGROUND_COLOR
);
41 rect
.left
= rect
.right
- 80;
42 rect
.bottom
= rect
.top
+ 25;
43 fButton
= new BButton(rect
, "DisconnectButton", kLabelDisconnect
,
44 new BMessage(kMsgDisconnect
));
46 rect
.right
= rect
.left
- 10;
47 rect
.left
= rect
.right
- 80;
49 rect
.bottom
= rect
.top
+ 15;
50 fTime
= new BStringView(rect
, "Time", "");
51 fTime
->SetAlignment(B_ALIGN_RIGHT
);
52 fTime
->SetFont(be_fixed_font
);
53 rect
.right
= rect
.left
- 10;
55 BStringView
*connectedSince
= new BStringView(rect
, "ConnectedSince",
56 kLabelConnectedSince
);
57 connectedSince
->SetFont(be_fixed_font
);
62 rect
.right
= rect
.left
+ (rect
.Width() - 5) / 2;
63 BBox
*received
= new BBox(rect
, "Received");
64 received
->SetLabel(kLabelReceived
);
65 rect
= received
->Bounds();
67 rect
.bottom
= rect
.top
+ 15;
68 fBytesReceived
= new BStringView(rect
, "BytesReceived", "");
69 fBytesReceived
->SetAlignment(B_ALIGN_RIGHT
);
70 fBytesReceived
->SetFont(be_fixed_font
);
71 rect
.top
= rect
.bottom
+ 5;
72 rect
.bottom
= rect
.top
+ 15;
73 fPacketsReceived
= new BStringView(rect
, "PacketsReceived", "");
74 fPacketsReceived
->SetAlignment(B_ALIGN_RIGHT
);
75 fPacketsReceived
->SetFont(be_fixed_font
);
77 rect
= received
->Frame();
78 rect
.OffsetBy(rect
.Width() + 5, 0);
79 BBox
*sent
= new BBox(rect
, "sent");
80 sent
->SetLabel(kLabelSent
);
81 rect
= received
->Bounds();
83 rect
.bottom
= rect
.top
+ 15;
84 fBytesSent
= new BStringView(rect
, "BytesSent", "");
85 fBytesSent
->SetAlignment(B_ALIGN_RIGHT
);
86 fBytesSent
->SetFont(be_fixed_font
);
87 rect
.top
= rect
.bottom
+ 5;
88 rect
.bottom
= rect
.top
+ 15;
89 fPacketsSent
= new BStringView(rect
, "PacketsSent", "");
90 fPacketsSent
->SetAlignment(B_ALIGN_RIGHT
);
91 fPacketsSent
->SetFont(be_fixed_font
);
93 received
->AddChild(fBytesReceived
);
94 received
->AddChild(fPacketsReceived
);
95 sent
->AddChild(fBytesSent
);
96 sent
->AddChild(fPacketsSent
);
100 AddChild(connectedSince
);
104 ppp_interface_info_t info
;
105 fInterface
.GetInterfaceInfo(&info
);
106 fConnectedSince
= info
.info
.connectedSince
;
111 PPPStatusView::AttachedToWindow()
113 fButton
->SetTarget(this);
114 Window()->SetTitle(fInterface
.Name());
119 PPPStatusView::MessageReceived(BMessage
*message
)
121 switch(message
->what
) {
128 BView::MessageReceived(message
);
134 PPPStatusView::Pulse()
137 ppp_statistics statistics
;
138 if(!fInterface
.GetStatistics(&statistics
)) {
139 fBytesReceived
->SetText("");
140 fPacketsReceived
->SetText("");
141 fBytesSent
->SetText("");
142 fPacketsSent
->SetText("");
147 bigtime_t time
= system_time() - fConnectedSince
;
149 int32 seconds
= time
% 60;
151 int32 minutes
= time
% 60;
152 int32 hours
= time
/ 60;
155 sprintf(minsec
, ":%02" B_PRId32
":%02" B_PRId32
, minutes
, seconds
);
156 text
<< hours
<< minsec
;
158 sprintf(minsec
, "%" B_PRId32
":%02" B_PRId32
, minutes
, seconds
);
162 fTime
->SetText(text
.String());
165 text
<< statistics
.bytesReceived
<< ' ' << kTextBytes
;
166 fBytesReceived
->SetText(text
.String());
168 text
<< statistics
.packetsReceived
<< ' ' << kTextPackets
;
169 fPacketsReceived
->SetText(text
.String());
171 text
<< statistics
.bytesSent
<< ' ' << kTextBytes
;
172 fBytesSent
->SetText(text
.String());
174 text
<< statistics
.packetsSent
<< ' ' << kTextPackets
;
175 fPacketsSent
->SetText(text
.String());