Finished the UI stuff. Not tested, though. If everything works as expected (I doubt it ;) you should see a little window prompting your login before connecting. It also allows canceling a connection attempt. After you establish a connection you should see an ugly Deskbar replicant. Click on it to see connection statistics and to disconnect.
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@10692 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -33,6 +33,7 @@ static const char *kLabelName = "Username: ";
|
|||||||
static const char *kLabelPassword = "Password: ";
|
static const char *kLabelPassword = "Password: ";
|
||||||
static const char *kLabelConnect = "Connect";
|
static const char *kLabelConnect = "Connect";
|
||||||
static const char *kLabelCancel = "Cancel";
|
static const char *kLabelCancel = "Cancel";
|
||||||
|
static const char *kLabelAuthentication = "Authentication";
|
||||||
|
|
||||||
// connection status strings
|
// connection status strings
|
||||||
static const char *kTextConnecting = "Connecting...";
|
static const char *kTextConnecting = "Connecting...";
|
||||||
@@ -78,20 +79,16 @@ ConnectionView::ConnectionView(BRect rect, const char *name, ppp_interface_id id
|
|||||||
{
|
{
|
||||||
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
||||||
|
|
||||||
BRect rect = Bounds();
|
rect = Bounds();
|
||||||
rect.InsetBy(5, 5);
|
rect.InsetBy(5, 5);
|
||||||
rect.bottom = rect.top
|
rect.bottom = rect.top
|
||||||
+ 25 // space for topmost control
|
+ 25 // space for topmost control
|
||||||
+ 3 * 20 // size of controls
|
+ 3 * 20 // size of controls
|
||||||
+ 3 * 5; // space beween controls and bottom of box
|
+ 3 * 5; // space beween controls and bottom of box
|
||||||
BBox *authenticationBox = new BBox(rect, "Authentication");
|
BBox *authenticationBox = new BBox(rect, "Authentication");
|
||||||
|
authenticationBox->SetLabel(kLabelAuthentication);
|
||||||
rect = authenticationBox->Bounds();
|
rect = authenticationBox->Bounds();
|
||||||
rect.InsetBy(10, 5);
|
rect.InsetBy(10, 20);
|
||||||
rect.top = 25;
|
|
||||||
BView *authenticationView = new BView(rect, "authenticationView",
|
|
||||||
B_FOLLOW_NONE, 0);
|
|
||||||
authenticationView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
|
||||||
rect = authenticationView->Bounds();
|
|
||||||
rect.bottom = rect.top + 20;
|
rect.bottom = rect.top + 20;
|
||||||
fUsername = new BTextControl(rect, "username", kLabelName, NULL, NULL);
|
fUsername = new BTextControl(rect, "username", kLabelName, NULL, NULL);
|
||||||
rect.top = rect.bottom + 5;
|
rect.top = rect.bottom + 5;
|
||||||
@@ -109,10 +106,9 @@ ConnectionView::ConnectionView(BRect rect, const char *name, ppp_interface_id id
|
|||||||
rect.bottom = rect.top + 20;
|
rect.bottom = rect.top + 20;
|
||||||
fSavePassword = new BCheckBox(rect, "SavePassword", kLabelSavePassword, NULL);
|
fSavePassword = new BCheckBox(rect, "SavePassword", kLabelSavePassword, NULL);
|
||||||
|
|
||||||
authenticationView->AddChild(fUsername);
|
authenticationBox->AddChild(fUsername);
|
||||||
authenticationView->AddChild(fPassword);
|
authenticationBox->AddChild(fPassword);
|
||||||
authenticationView->AddChild(fSavePassword);
|
authenticationBox->AddChild(fSavePassword);
|
||||||
authenticationBox->AddChild(authenticationView);
|
|
||||||
AddChild(authenticationBox);
|
AddChild(authenticationBox);
|
||||||
|
|
||||||
rect = authenticationBox->Frame();
|
rect = authenticationBox->Frame();
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2004, Waldemar Kornewald <[email protected]>
|
* Copyright 2004-2005, Waldemar Kornewald <[email protected]>
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -11,8 +11,8 @@
|
|||||||
|
|
||||||
ConnectionWindow::ConnectionWindow(BRect frame, const char *name, ppp_interface_id id,
|
ConnectionWindow::ConnectionWindow(BRect frame, const char *name, ppp_interface_id id,
|
||||||
thread_id replyThread)
|
thread_id replyThread)
|
||||||
: BWindow(frame, "", B_MODAL_WINDOW,
|
: BWindow(frame, "", B_TITLED_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE,
|
||||||
B_NOT_RESIZABLE | B_NOT_ZOOMABLE)
|
B_ALL_WORKSPACES)
|
||||||
{
|
{
|
||||||
BString title("Connecting to ");
|
BString title("Connecting to ");
|
||||||
title << "\"" << name << "\"...";
|
title << "\"" << name << "\"...";
|
||||||
|
|||||||
@@ -10,8 +10,11 @@ AddResources ppp_up : ppp_up.rdef ;
|
|||||||
BinCommand ppp_up :
|
BinCommand ppp_up :
|
||||||
ConnectionView.cpp
|
ConnectionView.cpp
|
||||||
ConnectionWindow.cpp
|
ConnectionWindow.cpp
|
||||||
|
PPPDeskbarReplicant.cpp
|
||||||
PPPUpAddon.cpp
|
PPPUpAddon.cpp
|
||||||
PPPUpApplication.cpp
|
PPPUpApplication.cpp
|
||||||
|
StatusView.cpp
|
||||||
|
StatusWindow.cpp
|
||||||
;
|
;
|
||||||
|
|
||||||
LinkSharedOSLibs ppp_up : libptpnet.a libppp.a be ;
|
LinkSharedOSLibs ppp_up : libptpnet.a libppp.a be ;
|
||||||
|
|||||||
@@ -1,17 +1,138 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2004, Waldemar Kornewald <[email protected]>
|
* Copyright 2004-2005, Waldemar Kornewald <[email protected]>
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "PPPDeskbarReplicant.h"
|
#include "PPPDeskbarReplicant.h"
|
||||||
#include "ConnectionWindow.h"
|
|
||||||
|
#include "PPPUpApplication.h"
|
||||||
|
#include "StatusWindow.h"
|
||||||
|
#include <PPPInterface.h>
|
||||||
|
#include <InterfaceUtils.h>
|
||||||
|
|
||||||
|
#include <Message.h>
|
||||||
|
#include <Deskbar.h>
|
||||||
|
|
||||||
|
|
||||||
PPPDeskbarReplicant::PPPDeskbarReplicant()
|
// TODO: remove this
|
||||||
|
/*extern "C" _EXPORT BView *instantiate_deskbar_item();
|
||||||
|
|
||||||
|
BView*
|
||||||
|
instantiate_deskbar_item()
|
||||||
|
{
|
||||||
|
return new PPPDeskbarReplicant();
|
||||||
|
}*/
|
||||||
|
|
||||||
|
|
||||||
|
static
|
||||||
|
status_t
|
||||||
|
destruction_thread(void *data)
|
||||||
|
{
|
||||||
|
thread_id sender;
|
||||||
|
ppp_report_packet report;
|
||||||
|
int32 reportCode;
|
||||||
|
while(true) {
|
||||||
|
reportCode = receive_data(&sender, &report, sizeof(report));
|
||||||
|
if(reportCode != PPP_REPORT_CODE)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if(report.type != PPP_DESTRUCTION_REPORT)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// our interface has been destroyed, remove the corresponding replicant
|
||||||
|
// XXX: We do not know which ID the replicant has and there might exist
|
||||||
|
// multiple connections (replicants)!
|
||||||
|
BDeskbar().RemoveItem("PPPDeskbarReplicant");
|
||||||
|
}
|
||||||
|
|
||||||
|
return B_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
PPPDeskbarReplicant::PPPDeskbarReplicant(ppp_interface_id id)
|
||||||
|
: BView(BRect(0, 0, 15, 15), "PPPDeskbarReplicant", B_FOLLOW_NONE, 0),
|
||||||
|
fID(id)
|
||||||
|
{
|
||||||
|
Init();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
PPPDeskbarReplicant::PPPDeskbarReplicant(BMessage *message)
|
||||||
: BView(BRect(0, 0, 15, 15), "PPPDeskbarReplicant", B_FOLLOW_NONE, 0)
|
: BView(BRect(0, 0, 15, 15), "PPPDeskbarReplicant", B_FOLLOW_NONE, 0)
|
||||||
{
|
{
|
||||||
BRect rect(0, 0, 300, 250);
|
message->FindInt32("interface", reinterpret_cast<int32*>(&fID));
|
||||||
fWindow = new ConnectionWindow(rect, id, sender);
|
Init();
|
||||||
fWindow->MoveTo(center_on_screen(rect, fWindow));
|
}
|
||||||
fWindow->Show();
|
|
||||||
|
|
||||||
|
PPPDeskbarReplicant::~PPPDeskbarReplicant()
|
||||||
|
{
|
||||||
|
fWindow->LockLooper();
|
||||||
|
fWindow->Quit();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
PPPDeskbarReplicant*
|
||||||
|
PPPDeskbarReplicant::Instantiate(BMessage *data)
|
||||||
|
{
|
||||||
|
if(!validate_instantiation(data, "PPPDeskbarReplicant"))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
return new PPPDeskbarReplicant(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
PPPDeskbarReplicant::Archive(BMessage *data, bool deep = true) const
|
||||||
|
{
|
||||||
|
BView::Archive(data, deep);
|
||||||
|
|
||||||
|
data->AddString("add_on", APP_SIGNATURE);
|
||||||
|
data->AddInt32("interface", fID);
|
||||||
|
return B_NO_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
PPPDeskbarReplicant::MouseDown(BPoint point)
|
||||||
|
{
|
||||||
|
Looper()->CurrentMessage()->FindInt32("buttons", &fLastButtons);
|
||||||
|
|
||||||
|
// TODO: on secondary mouse button we want to show a pop-up menu
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
PPPDeskbarReplicant::MouseUp(BPoint point)
|
||||||
|
{
|
||||||
|
if(fLastButtons & B_PRIMARY_MOUSE_BUTTON) {
|
||||||
|
fWindow->MoveTo(center_on_screen(fWindow->Frame(), fWindow));
|
||||||
|
fWindow->Show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
PPPDeskbarReplicant::Draw(BRect updateRect)
|
||||||
|
{
|
||||||
|
// TODO: I want a nice blinking icon!
|
||||||
|
MovePenTo(4, 12);
|
||||||
|
DrawString("P");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
PPPDeskbarReplicant::Init()
|
||||||
|
{
|
||||||
|
BRect rect(50,50,380,150);
|
||||||
|
fWindow = new StatusWindow(rect, fID);
|
||||||
|
|
||||||
|
// watch interface destruction
|
||||||
|
PPPInterface interface(fID);
|
||||||
|
if(interface.InitCheck() != B_OK)
|
||||||
|
return;
|
||||||
|
|
||||||
|
thread_id destructionThread = spawn_thread(destruction_thread,
|
||||||
|
"destruction_thread", B_NORMAL_PRIORITY, NULL);
|
||||||
|
interface.EnableReports(PPP_DESTRUCTION_REPORT, destructionThread);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2004, Waldemar Kornewald <[email protected]>
|
* Copyright 2004-2005, Waldemar Kornewald <[email protected]>
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -7,11 +7,32 @@
|
|||||||
#define PPP_DESKBAR_REPLICANT__H
|
#define PPP_DESKBAR_REPLICANT__H
|
||||||
|
|
||||||
#include <View.h>
|
#include <View.h>
|
||||||
|
#include <PPPDefs.h>
|
||||||
|
|
||||||
|
class StatusWindow;
|
||||||
|
|
||||||
|
|
||||||
class PPPDeskbarReplicant : public BView {
|
class PPPDeskbarReplicant : public BView {
|
||||||
public:
|
public:
|
||||||
PPPDeskbarReplicant();
|
PPPDeskbarReplicant(ppp_interface_id id);
|
||||||
|
PPPDeskbarReplicant(BMessage *message);
|
||||||
|
virtual ~PPPDeskbarReplicant();
|
||||||
|
|
||||||
|
static PPPDeskbarReplicant *Instantiate(BMessage *data);
|
||||||
|
virtual status_t Archive(BMessage *data, bool deep = true) const;
|
||||||
|
|
||||||
|
virtual void MouseDown(BPoint point);
|
||||||
|
virtual void MouseUp(BPoint point);
|
||||||
|
|
||||||
|
virtual void Draw(BRect updateRect);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void Init();
|
||||||
|
|
||||||
|
private:
|
||||||
|
StatusWindow *fWindow;
|
||||||
|
ppp_interface_id fID;
|
||||||
|
int32 fLastButtons;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2004, Waldemar Kornewald <[email protected]>
|
* Copyright 2004-2005, Waldemar Kornewald <[email protected]>
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <Application.h>
|
#include "PPPUpApplication.h"
|
||||||
|
|
||||||
#include <Window.h>
|
#include <Window.h>
|
||||||
|
|
||||||
#include "DialUpView.h"
|
#include "DialUpView.h"
|
||||||
@@ -11,40 +12,8 @@
|
|||||||
#include <KPPPUtils.h>
|
#include <KPPPUtils.h>
|
||||||
#include <PPPReportDefs.h>
|
#include <PPPReportDefs.h>
|
||||||
|
|
||||||
|
#include <Deskbar.h>
|
||||||
static const char *kSignature = "application/x-vnd.haiku.ppp_up";
|
#include "PPPDeskbarReplicant.h"
|
||||||
|
|
||||||
extern "C" _EXPORT BView *instantiate_deskbar_item();
|
|
||||||
|
|
||||||
|
|
||||||
class PPPUpApplication : public BApplication {
|
|
||||||
public:
|
|
||||||
PPPUpApplication(const char *name, ppp_interface_id id,
|
|
||||||
thread_id replyThread);
|
|
||||||
|
|
||||||
virtual void ReadyToRun();
|
|
||||||
|
|
||||||
const char *Name() const
|
|
||||||
{ return fName; }
|
|
||||||
ppp_interface_id ID() const
|
|
||||||
{ return fID; }
|
|
||||||
thread_id ReplyThread() const
|
|
||||||
{ return fReplyThread; }
|
|
||||||
|
|
||||||
private:
|
|
||||||
const char *fName;
|
|
||||||
ppp_interface_id fID;
|
|
||||||
thread_id fReplyThread;
|
|
||||||
ConnectionWindow *fWindow;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
BView*
|
|
||||||
instantiate_deskbar_item()
|
|
||||||
{
|
|
||||||
// TODO: implement me!
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static
|
static
|
||||||
@@ -95,7 +64,6 @@ report_thread(void *data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(report.code == PPP_REPORT_GOING_UP) {
|
if(report.code == PPP_REPORT_GOING_UP) {
|
||||||
// TODO:
|
|
||||||
// create connection window (it will send the reply for us) (DONE?)
|
// create connection window (it will send the reply for us) (DONE?)
|
||||||
BRect rect(150, 50, 450, 435);
|
BRect rect(150, 50, 450, 435);
|
||||||
if(!window) {
|
if(!window) {
|
||||||
@@ -107,12 +75,13 @@ report_thread(void *data)
|
|||||||
// wait for reply from window and forward it to the kernel
|
// wait for reply from window and forward it to the kernel
|
||||||
thread_id tmp;
|
thread_id tmp;
|
||||||
PPP_REPLY(sender, receive_data(&tmp, NULL, 0));
|
PPP_REPLY(sender, receive_data(&tmp, NULL, 0));
|
||||||
|
|
||||||
// PPP_REPLY(sender, B_OK);
|
|
||||||
// TODO: remove this when finished with above
|
|
||||||
} else {
|
} else {
|
||||||
if(report.code == PPP_REPORT_UP_SUCCESSFUL)
|
if(report.code == PPP_REPORT_UP_SUCCESSFUL) {
|
||||||
; // TODO: add deskbar replicant
|
// add deskbar replicant (DONE?)
|
||||||
|
PPPDeskbarReplicant *replicant = new PPPDeskbarReplicant(id);
|
||||||
|
BDeskbar().AddItem(replicant);
|
||||||
|
delete replicant;
|
||||||
|
}
|
||||||
|
|
||||||
PPP_REPLY(sender, PPP_OK_DISABLE_REPORTS);
|
PPP_REPLY(sender, PPP_OK_DISABLE_REPORTS);
|
||||||
}
|
}
|
||||||
@@ -144,7 +113,7 @@ main(int argc, const char *argv[])
|
|||||||
|
|
||||||
PPPUpApplication::PPPUpApplication(const char *name, ppp_interface_id id,
|
PPPUpApplication::PPPUpApplication(const char *name, ppp_interface_id id,
|
||||||
thread_id replyThread)
|
thread_id replyThread)
|
||||||
: BApplication(kSignature),
|
: BApplication(APP_SIGNATURE),
|
||||||
fName(name),
|
fName(name),
|
||||||
fID(id),
|
fID(id),
|
||||||
fReplyThread(replyThread)
|
fReplyThread(replyThread)
|
||||||
|
|||||||
@@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2005, Waldemar Kornewald <[email protected]>
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef PPP_UP_APPLICATION__H
|
||||||
|
#define PPP_UP_APPLICATION__H
|
||||||
|
|
||||||
|
#include <Application.h>
|
||||||
|
#include <PPPDefs.h>
|
||||||
|
|
||||||
|
class ConnectionWindow;
|
||||||
|
|
||||||
|
#define APP_SIGNATURE "application/x-vnd.haiku.ppp_up"
|
||||||
|
|
||||||
|
|
||||||
|
class PPPUpApplication : public BApplication {
|
||||||
|
public:
|
||||||
|
PPPUpApplication(const char *name, ppp_interface_id id,
|
||||||
|
thread_id replyThread);
|
||||||
|
|
||||||
|
virtual void ReadyToRun();
|
||||||
|
|
||||||
|
const char *Name() const
|
||||||
|
{ return fName; }
|
||||||
|
ppp_interface_id ID() const
|
||||||
|
{ return fID; }
|
||||||
|
thread_id ReplyThread() const
|
||||||
|
{ return fReplyThread; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
const char *fName;
|
||||||
|
ppp_interface_id fID;
|
||||||
|
thread_id fReplyThread;
|
||||||
|
ConnectionWindow *fWindow;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,176 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2005, Waldemar Kornewald <[email protected]>
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "StatusView.h"
|
||||||
|
|
||||||
|
#include <Box.h>
|
||||||
|
#include <Button.h>
|
||||||
|
#include <StringView.h>
|
||||||
|
#include <Window.h>
|
||||||
|
|
||||||
|
#include <cstdio>
|
||||||
|
#include <String.h>
|
||||||
|
|
||||||
|
#include <PPPManager.h>
|
||||||
|
|
||||||
|
|
||||||
|
// message constants
|
||||||
|
static const uint32 kMsgDisconnect = 'DISC';
|
||||||
|
|
||||||
|
// labels
|
||||||
|
static const char *kLabelDisconnect = "Disconnect";
|
||||||
|
static const char *kLabelConnectedSince = "Connected Since: ";
|
||||||
|
static const char *kLabelReceived = "Received";
|
||||||
|
static const char *kLabelSent = "Sent";
|
||||||
|
|
||||||
|
// strings
|
||||||
|
static const char *kTextBytes = "Bytes";
|
||||||
|
static const char *kTextPackets = "Packets";
|
||||||
|
|
||||||
|
|
||||||
|
StatusView::StatusView(BRect rect, ppp_interface_id id)
|
||||||
|
: BView(rect, "StatusView", B_FOLLOW_NONE, B_PULSE_NEEDED),
|
||||||
|
fInterface(id)
|
||||||
|
{
|
||||||
|
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
||||||
|
|
||||||
|
rect = Bounds();
|
||||||
|
rect.InsetBy(5, 5);
|
||||||
|
rect.left = rect.right - 80;
|
||||||
|
rect.bottom = rect.top + 25;
|
||||||
|
fButton = new BButton(rect, "DisconnectButton", kLabelDisconnect,
|
||||||
|
new BMessage(kMsgDisconnect));
|
||||||
|
|
||||||
|
rect.right = rect.left - 10;
|
||||||
|
rect.left = rect.right - 80;
|
||||||
|
rect.top += 5;
|
||||||
|
rect.bottom = rect.top + 15;
|
||||||
|
fTime = new BStringView(rect, "Time", "");
|
||||||
|
fTime->SetAlignment(B_ALIGN_RIGHT);
|
||||||
|
fTime->SetFont(be_fixed_font);
|
||||||
|
rect.right = rect.left - 10;
|
||||||
|
rect.left = 5;
|
||||||
|
BStringView *connectedSince = new BStringView(rect, "ConnectedSince",
|
||||||
|
kLabelConnectedSince);
|
||||||
|
connectedSince->SetFont(be_fixed_font);
|
||||||
|
|
||||||
|
rect = Bounds();
|
||||||
|
rect.InsetBy(5, 5);
|
||||||
|
rect.top += 35;
|
||||||
|
rect.right = rect.left + (rect.Width() - 5) / 2;
|
||||||
|
BBox *received = new BBox(rect, "Received");
|
||||||
|
received->SetLabel(kLabelReceived);
|
||||||
|
rect = received->Bounds();
|
||||||
|
rect.InsetBy(10, 15);
|
||||||
|
rect.bottom = rect.top + 15;
|
||||||
|
fBytesReceived = new BStringView(rect, "BytesReceived", "");
|
||||||
|
fBytesReceived->SetAlignment(B_ALIGN_RIGHT);
|
||||||
|
fBytesReceived->SetFont(be_fixed_font);
|
||||||
|
rect.top = rect.bottom + 5;
|
||||||
|
rect.bottom = rect.top + 15;
|
||||||
|
fPacketsReceived = new BStringView(rect, "PacketsReceived", "");
|
||||||
|
fPacketsReceived->SetAlignment(B_ALIGN_RIGHT);
|
||||||
|
fPacketsReceived->SetFont(be_fixed_font);
|
||||||
|
|
||||||
|
rect = received->Frame();
|
||||||
|
rect.OffsetBy(rect.Width() + 5, 0);
|
||||||
|
BBox *sent = new BBox(rect, "sent");
|
||||||
|
sent->SetLabel(kLabelSent);
|
||||||
|
rect = received->Bounds();
|
||||||
|
rect.InsetBy(10, 15);
|
||||||
|
rect.bottom = rect.top + 15;
|
||||||
|
fBytesSent = new BStringView(rect, "BytesSent", "");
|
||||||
|
fBytesSent->SetAlignment(B_ALIGN_RIGHT);
|
||||||
|
fBytesSent->SetFont(be_fixed_font);
|
||||||
|
rect.top = rect.bottom + 5;
|
||||||
|
rect.bottom = rect.top + 15;
|
||||||
|
fPacketsSent = new BStringView(rect, "PacketsSent", "");
|
||||||
|
fPacketsSent->SetAlignment(B_ALIGN_RIGHT);
|
||||||
|
fPacketsSent->SetFont(be_fixed_font);
|
||||||
|
|
||||||
|
received->AddChild(fBytesReceived);
|
||||||
|
received->AddChild(fPacketsReceived);
|
||||||
|
sent->AddChild(fBytesSent);
|
||||||
|
sent->AddChild(fPacketsSent);
|
||||||
|
|
||||||
|
AddChild(fButton);
|
||||||
|
AddChild(fTime);
|
||||||
|
AddChild(connectedSince);
|
||||||
|
AddChild(received);
|
||||||
|
AddChild(sent);
|
||||||
|
|
||||||
|
ppp_interface_info_t info;
|
||||||
|
fInterface.GetInterfaceInfo(&info);
|
||||||
|
fConnectedSince = info.info.connectedSince;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
StatusView::AttachedToWindow()
|
||||||
|
{
|
||||||
|
fButton->SetTarget(this);
|
||||||
|
Window()->SetTitle(fInterface.Name());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
StatusView::MessageReceived(BMessage *message)
|
||||||
|
{
|
||||||
|
switch(message->what) {
|
||||||
|
case kMsgDisconnect:
|
||||||
|
fInterface.Down();
|
||||||
|
Window()->Hide();
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
BView::MessageReceived(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
StatusView::Pulse()
|
||||||
|
{
|
||||||
|
// update status
|
||||||
|
ppp_statistics statistics;
|
||||||
|
if(!fInterface.GetStatistics(&statistics)) {
|
||||||
|
fBytesReceived->SetText("");
|
||||||
|
fPacketsReceived->SetText("");
|
||||||
|
fBytesSent->SetText("");
|
||||||
|
fPacketsSent->SetText("");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
BString text;
|
||||||
|
bigtime_t time = system_time() - fConnectedSince;
|
||||||
|
time /= 1000000;
|
||||||
|
int32 seconds = time % 60;
|
||||||
|
time /= 60;
|
||||||
|
int32 minutes = time % 60;
|
||||||
|
int32 hours = time / 60;
|
||||||
|
char minsec[7];
|
||||||
|
if(hours) {
|
||||||
|
sprintf(minsec, ":%02ld:%02ld", minutes, seconds);
|
||||||
|
text << hours << minsec;
|
||||||
|
} else if(minutes) {
|
||||||
|
sprintf(minsec, "%ld:%02ld", minutes, seconds);
|
||||||
|
text << minsec;
|
||||||
|
} else
|
||||||
|
text << seconds;
|
||||||
|
fTime->SetText(text.String());
|
||||||
|
|
||||||
|
text = "";
|
||||||
|
text << statistics.bytesReceived << ' ' << kTextBytes;
|
||||||
|
fBytesReceived->SetText(text.String());
|
||||||
|
text = "";
|
||||||
|
text << statistics.packetsReceived << ' ' << kTextPackets;
|
||||||
|
fPacketsReceived->SetText(text.String());
|
||||||
|
text = "";
|
||||||
|
text << statistics.bytesSent << ' ' << kTextBytes;
|
||||||
|
fBytesSent->SetText(text.String());
|
||||||
|
text = "";
|
||||||
|
text << statistics.packetsSent << ' ' << kTextPackets;
|
||||||
|
fPacketsSent->SetText(text.String());
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2005, Waldemar Kornewald <[email protected]>
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef STATUS_VIEW__H
|
||||||
|
#define STATUS_VIEW__H
|
||||||
|
|
||||||
|
#include <View.h>
|
||||||
|
#include <PPPInterface.h>
|
||||||
|
|
||||||
|
|
||||||
|
class StatusView : public BView {
|
||||||
|
public:
|
||||||
|
StatusView(BRect rect, ppp_interface_id id);
|
||||||
|
|
||||||
|
virtual void AttachedToWindow();
|
||||||
|
virtual void MessageReceived(BMessage *message);
|
||||||
|
virtual void Pulse();
|
||||||
|
|
||||||
|
private:
|
||||||
|
BButton *fButton;
|
||||||
|
BStringView *fTime;
|
||||||
|
BStringView *fBytesReceived, *fBytesSent, *fPacketsReceived, *fPacketsSent;
|
||||||
|
bigtime_t fConnectedSince;
|
||||||
|
PPPInterface fInterface;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2005, Waldemar Kornewald <[email protected]>
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "StatusWindow.h"
|
||||||
|
#include "StatusView.h"
|
||||||
|
|
||||||
|
|
||||||
|
StatusWindow::StatusWindow(BRect frame, ppp_interface_id id)
|
||||||
|
: BWindow(frame, "", B_TITLED_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE,
|
||||||
|
B_ALL_WORKSPACES)
|
||||||
|
{
|
||||||
|
SetPulseRate(1000000);
|
||||||
|
|
||||||
|
StatusView *view = new StatusView(Bounds(), id);
|
||||||
|
AddChild(view);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
StatusWindow::QuitRequested()
|
||||||
|
{
|
||||||
|
// only the replicant may delete this window!
|
||||||
|
Hide();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2005, Waldemar Kornewald <[email protected]>
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef STATUS_WINDOW__H
|
||||||
|
#define STATUS_WINDOW__H
|
||||||
|
|
||||||
|
#include <Window.h>
|
||||||
|
#include <PPPDefs.h>
|
||||||
|
|
||||||
|
|
||||||
|
class StatusWindow : public BWindow {
|
||||||
|
public:
|
||||||
|
StatusWindow(BRect frame, ppp_interface_id id);
|
||||||
|
|
||||||
|
virtual bool QuitRequested();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
Reference in New Issue
Block a user