Added ppp_up. Still in need of nice icons for the replicant.

Untested.
This also fixes makehdimage.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@14360 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Waldemar Kornewald 2005-10-12 10:07:22 +00:00
parent a89ad654b0
commit 1dd511e38b
15 changed files with 1083 additions and 0 deletions

View File

@ -141,6 +141,7 @@ SubInclude OBOS_TOP src bin rcs ;
SubInclude OBOS_TOP src bin arp ;
SubInclude OBOS_TOP src bin ifconfig ;
SubInclude OBOS_TOP src bin pppconfig ;
SubInclude OBOS_TOP src bin ppp_up ;
SubInclude OBOS_TOP src bin ping ;
SubInclude OBOS_TOP src bin route ;
SubInclude OBOS_TOP src bin traceroute ;

View File

@ -0,0 +1,373 @@
/*
* Copyright 2005, Waldemar Kornewald <wkornew@gmx.net>
* Distributed under the terms of the MIT License.
*/
#include "ConnectionView.h"
#include "PPPDeskbarReplicant.h"
#include <MessageDriverSettingsUtils.h>
#include <Application.h>
#include <Box.h>
#include <Button.h>
#include <Deskbar.h>
#include <Entry.h>
#include <File.h>
#include <String.h>
#include <StringView.h>
#include <TextControl.h>
#include <Window.h>
#include <PPPInterface.h>
#include <settings_tools.h>
#include <stl_algobase.h>
// for max()
// GUI constants
static const uint32 kDefaultButtonWidth = 80;
// message constants
static const uint32 kMsgCancel = 'CANC';
static const uint32 kMsgConnect = 'CONN';
static const uint32 kMsgUpdate = 'MUPD';
// labels
static const char *kLabelSavePassword = "Save Password";
static const char *kLabelName = "Username: ";
static const char *kLabelPassword = "Password: ";
static const char *kLabelConnect = "Connect";
static const char *kLabelCancel = "Cancel";
static const char *kLabelAuthentication = "Authentication";
// connection status strings
static const char *kTextConnecting = "Connecting...";
static const char *kTextConnectionEstablished = "Connection established.";
static const char *kTextNotConnected = "Not connected.";
static const char *kTextDeviceUpFailed = "Failed to connect.";
static const char *kTextAuthenticating = "Authenticating...";
static const char *kTextAuthenticationFailed = "Authentication failed!";
static const char *kTextConnectionLost = "Connection lost!";
ConnectionView::ConnectionView(BRect rect, const BString& interfaceName)
: BView(rect, "ConnectionView", B_FOLLOW_NONE, 0),
fListener(this),
fInterfaceName(interfaceName),
fKeepLabel(false)
{
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
rect = Bounds();
rect.InsetBy(5, 5);
rect.bottom = rect.top
+ 25 // space for topmost control
+ 3 * 20 // size of controls
+ 3 * 5; // space beween controls and bottom of box
BBox *authenticationBox = new BBox(rect, "Authentication");
authenticationBox->SetLabel(kLabelAuthentication);
rect = authenticationBox->Bounds();
rect.InsetBy(10, 20);
rect.bottom = rect.top + 20;
fUsername = new BTextControl(rect, "username", kLabelName, NULL, NULL);
rect.top = rect.bottom + 5;
rect.bottom = rect.top + 20;
fPassword = new BTextControl(rect, "password", kLabelPassword, NULL, NULL);
fPassword->TextView()->HideTyping(true);
// set dividers
float width = max(StringWidth(fUsername->Label()),
StringWidth(fPassword->Label()));
fUsername->SetDivider(width + 5);
fPassword->SetDivider(width + 5);
rect.top = rect.bottom + 5;
rect.bottom = rect.top + 20;
fSavePassword = new BCheckBox(rect, "SavePassword", kLabelSavePassword, NULL);
authenticationBox->AddChild(fUsername);
authenticationBox->AddChild(fPassword);
authenticationBox->AddChild(fSavePassword);
AddChild(authenticationBox);
rect = authenticationBox->Frame();
rect.top = rect.bottom + 10;
rect.bottom = rect.top + 15;
fAttemptView = new BStringView(rect, "AttemptView", "");
AddChild(fAttemptView);
// add status view
rect.top = rect.bottom + 5;
rect.bottom = rect.top + 15;
fStatusView = new BStringView(rect, "StatusView", "");
AddChild(fStatusView);
// add "Connect" and "Cancel" buttons
rect.top = rect.bottom + 10;
rect.bottom = rect.top + 25;
rect.right = rect.left + kDefaultButtonWidth;
fConnectButton = new BButton(rect, "ConnectButton", kLabelConnect,
new BMessage(kMsgConnect));
Window()->SetDefaultButton(fConnectButton);
rect.left = rect.right + 10;
rect.right = rect.left + kDefaultButtonWidth;
fCancelButton = new BButton(rect, "CancelButton", kLabelCancel,
new BMessage(kMsgCancel));
AddChild(fConnectButton);
AddChild(fCancelButton);
}
void
ConnectionView::AttachedToWindow()
{
Reload();
fListener.WatchManager();
WatchInterface(fListener.Manager().InterfaceWithName(fInterfaceName.String()));
fConnectButton->SetTarget(this);
fCancelButton->SetTarget(this);
}
void
ConnectionView::MessageReceived(BMessage *message)
{
switch(message->what) {
case PPP_REPORT_MESSAGE:
HandleReportMessage(message);
break;
case kMsgConnect:
Connect();
break;
case kMsgCancel:
Cancel();
break;
default:
BView::MessageReceived(message);
}
}
// update authentication UI
void
ConnectionView::Reload()
{
// load username and password
BString path("ptpnet/");
path << fInterfaceName;
fSettings.MakeEmpty();
ReadMessageDriverSettings(path.String(), &fSettings);
fHasUsername = fHasPassword = false;
BString username, password;
BMessage parameter;
int32 parameterIndex = 0;
if(FindMessageParameter(PPP_USERNAME_KEY, fSettings, &parameter, &parameterIndex)
&& parameter.FindString(MDSU_VALUES, &username) == B_OK)
fHasUsername = true;
parameterIndex = 0;
if(FindMessageParameter(PPP_PASSWORD_KEY, fSettings, &parameter, &parameterIndex)
&& parameter.FindString(MDSU_VALUES, &password) == B_OK)
fHasPassword = true;
fUsername->SetText(username.String());
fPassword->SetText(password.String());
fSavePassword->SetValue(fHasPassword);
fUsername->SetEnabled(fHasUsername);
fPassword->SetEnabled(fHasUsername);
fSavePassword->SetEnabled(fHasUsername);
}
void
ConnectionView::Connect()
{
PPPInterface interface(PPPManager().CreateInterfaceWithName(
fInterfaceName.String()));
interface.SetUsername(Username());
interface.SetPassword(Password());
interface.SetAskBeforeConnecting(false);
interface.Up();
// save settings
if(fHasUsername) {
BMessage parameter;
int32 index = 0;
if(FindMessageParameter(PPP_USERNAME_KEY, fSettings, &parameter, &index))
fSettings.RemoveData(MDSU_PARAMETERS, index);
parameter.MakeEmpty();
parameter.AddString(MDSU_NAME, PPP_USERNAME_KEY);
parameter.AddString(MDSU_VALUES, Username());
fSettings.AddMessage(MDSU_PARAMETERS, &parameter);
index = 0;
if(FindMessageParameter(PPP_PASSWORD_KEY, fSettings, &parameter, &index))
fSettings.RemoveData(MDSU_PARAMETERS, index);
if(DoesSavePassword()) {
parameter.MakeEmpty();
parameter.AddString(MDSU_NAME, PPP_PASSWORD_KEY);
parameter.AddString(MDSU_VALUES, Password());
fSettings.AddMessage(MDSU_PARAMETERS, &parameter);
}
BEntry entry;
if(interface.GetSettingsEntry(&entry) == B_OK) {
BFile file(&entry, B_WRITE_ONLY);
WriteMessageDriverSettings(file, fSettings);
}
}
Reload();
}
void
ConnectionView::Cancel()
{
PPPInterface interface(fListener.Interface());
bool quit = false;
ppp_interface_info_t info;
if(interface.GetInterfaceInfo(&info) && info.info.phase < PPP_ESTABLISHMENT_PHASE)
quit = true;
interface.Down();
if(quit)
Window()->Quit();
}
// Clean up before our window quits (called by ConnectionWindow).
void
ConnectionView::CleanUp()
{
fListener.StopWatchingInterface();
fListener.StopWatchingManager();
}
BString
ConnectionView::AttemptString() const
{
PPPInterface interface(fListener.Interface());
ppp_interface_info_t info;
if(!interface.GetInterfaceInfo(&info))
return BString("");
BString attempt;
attempt << "Attempt " << info.info.connectAttempt << " of " <<
info.info.connectRetriesLimit + 1;
return attempt;
}
void
ConnectionView::HandleReportMessage(BMessage *message)
{
ppp_interface_id id;
if(message->FindInt32("interface", reinterpret_cast<int32*>(&id)) != B_OK
|| (fListener.Interface() != PPP_UNDEFINED_INTERFACE_ID
&& id != fListener.Interface()))
return;
int32 type, code;
message->FindInt32("type", &type);
message->FindInt32("code", &code);
if(type == PPP_MANAGER_REPORT && code == PPP_REPORT_INTERFACE_CREATED) {
PPPInterface interface(id);
if(interface.InitCheck() != B_OK || fInterfaceName != interface.Name())
return;
WatchInterface(id);
if(((fHasUsername && !fHasPassword) || fAskBeforeConnecting)
&& Window()->IsHidden())
Window()->Show();
} else if(type == PPP_CONNECTION_REPORT)
UpdateStatus(code);
else if(type == PPP_DESTRUCTION_REPORT)
fListener.StopWatchingInterface();
}
void
ConnectionView::UpdateStatus(int32 code)
{
BString attemptString = AttemptString();
fAttemptView->SetText(attemptString.String());
if(code == PPP_REPORT_UP_SUCCESSFUL) {
fStatusView->SetText(kTextConnectionEstablished);
PPPDeskbarReplicant *item = new PPPDeskbarReplicant(fListener.Interface());
BDeskbar().AddItem(item);
delete item;
Window()->Quit();
return;
}
// maybe the status string must not be changed (codes that set fKeepLabel to false
// should still be handled)
if(fKeepLabel && code != PPP_REPORT_GOING_UP && code != PPP_REPORT_UP_SUCCESSFUL)
return;
if(fListener.InitCheck() != B_OK) {
fStatusView->SetText(kTextConnectionLost);
return;
}
// only errors should set fKeepLabel to true
switch(code) {
case PPP_REPORT_GOING_UP:
fKeepLabel = false;
fStatusView->SetText(kTextConnecting);
break;
case PPP_REPORT_DOWN_SUCCESSFUL:
fStatusView->SetText(kTextNotConnected);
break;
case PPP_REPORT_DEVICE_UP_FAILED:
fKeepLabel = true;
fStatusView->SetText(kTextDeviceUpFailed);
break;
case PPP_REPORT_AUTHENTICATION_REQUESTED:
fStatusView->SetText(kTextAuthenticating);
break;
case PPP_REPORT_AUTHENTICATION_FAILED:
fKeepLabel = true;
fStatusView->SetText(kTextAuthenticationFailed);
break;
case PPP_REPORT_CONNECTION_LOST:
fKeepLabel = true;
fStatusView->SetText(kTextConnectionLost);
break;
}
}
void
ConnectionView::WatchInterface(ppp_interface_id ID)
{
fListener.WatchInterface(ID);
// update status
Reload();
PPPInterface interface(fListener.Interface());
ppp_interface_info_t info;
if(!interface.GetInterfaceInfo(&info)) {
UpdateStatus(PPP_REPORT_DOWN_SUCCESSFUL);
fAskBeforeConnecting = false;
} else
fAskBeforeConnecting = info.info.askBeforeConnecting;
}

View File

@ -0,0 +1,61 @@
/*
* Copyright 2005, Waldemar Kornewald <wkornew@gmx.net>
* Distributed under the terms of the MIT License.
*/
#ifndef CONNECTION_VIEW__H
#define CONNECTION_VIEW__H
#include <CheckBox.h>
#include <Message.h>
#include <TextControl.h>
#include <PPPInterfaceListener.h>
class BButton;
class BStringView;
class ConnectionView : public BView {
friend class ConnectionWindow;
public:
ConnectionView(BRect rect, const BString& interfaceName);
virtual void AttachedToWindow();
virtual void MessageReceived(BMessage *message);
const char *Username() const
{ return fUsername->Text(); }
const char *Password() const
{ return fPassword->Text(); }
bool DoesSavePassword() const
{ return fSavePassword->Value(); }
private:
void Reload();
void Connect();
void Cancel();
void CleanUp();
BString AttemptString() const;
void HandleReportMessage(BMessage *message);
void UpdateStatus(int32 code);
void WatchInterface(ppp_interface_id ID);
private:
PPPInterfaceListener fListener;
BString fInterfaceName;
BTextControl *fUsername, *fPassword;
BCheckBox *fSavePassword;
BStringView *fAttemptView, *fStatusView;
BButton *fConnectButton, *fCancelButton;
BMessage fSettings;
bool fKeepLabel, fHasUsername, fHasPassword, fAskBeforeConnecting;
};
#endif

View File

@ -0,0 +1,31 @@
/*
* Copyright 2005, Waldemar Kornewald <wkornew@gmx.net>
* Distributed under the terms of the MIT License.
*/
#include "ConnectionWindow.h"
#include <Application.h>
#include <String.h>
ConnectionWindow::ConnectionWindow(BRect frame, const BString& interfaceName)
: BWindow(frame, "", B_TITLED_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE,
B_ALL_WORKSPACES)
{
BString title("Connecting to ");
title << "\"" << interfaceName << "\"...";
SetTitle(title.String());
fConnectionView = new ConnectionView(Bounds(), interfaceName);
AddChild(fConnectionView);
}
bool
ConnectionWindow::QuitRequested()
{
fConnectionView->CleanUp();
be_app->PostMessage(B_QUIT_REQUESTED);
return true;
}

View File

@ -0,0 +1,24 @@
/*
* Copyright 2005, Waldemar Kornewald <wkornew@gmx.net>
* Distributed under the terms of the MIT License.
*/
#ifndef CONNECTION_WINDOW__H
#define CONNECTION_WINDOW__H
#include <Window.h>
#include "ConnectionView.h"
class ConnectionWindow : public BWindow {
public:
ConnectionWindow(BRect frame, const BString& interfaceName);
virtual bool QuitRequested();
private:
ConnectionView *fConnectionView;
};
#endif

27
src/bin/ppp_up/Jamfile Normal file
View File

@ -0,0 +1,27 @@
SubDir OBOS_TOP src bin ppp_up ;
UsePrivateHeaders net ;
UseHeaders [ FDirName $(OBOS_TOP) src add-ons kernel network ppp shared libppp headers ] ;
UseHeaders [ FDirName $(OBOS_TOP) src add-ons kernel network ppp shared libkernelppp headers ] ;
AddResources ppp_up : ppp_up.rdef ;
BinCommand ppp_up :
ConnectionView.cpp
ConnectionWindow.cpp
PPPDeskbarReplicant.cpp
PPPStatusView.cpp
PPPStatusWindow.cpp
PPPUpApplication.cpp
;
LinkSharedOSLibs ppp_up : libppp.a be ;
# Installation
OBOSInstall install-networking
: /boot/beos/bin
: ppp_up ;
Package haiku-networkingkit-cvs :
ppp_up :
boot beos bin ;

View File

@ -0,0 +1,155 @@
/*
* Copyright 2005, Waldemar Kornewald <wkornew@gmx.net>
* Distributed under the terms of the MIT License.
*/
#include "PPPDeskbarReplicant.h"
#include "PPPUpApplication.h"
#include "PPPStatusWindow.h"
#include <PPPInterface.h>
#include <Deskbar.h>
#include <MenuItem.h>
#include <Message.h>
#include <PopUpMenu.h>
// message constants
static const uint32 kMsgDisconnect = 'DISC';
static const uint32 kMsgStatus = 'STAT';
// labels
static const char *kLabelDisconnect = "Disconnect";
static const char *kLabelStatus = "Status";
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)
{
message->FindInt32("interface", reinterpret_cast<int32*>(&fID));
Init();
}
PPPDeskbarReplicant::~PPPDeskbarReplicant()
{
delete fContextMenu;
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::AttachedToWindow()
{
BMenuItem *item = new BMenuItem(kLabelDisconnect, new BMessage(kMsgDisconnect));
item->SetTarget(fWindow->StatusView());
fContextMenu->AddItem(item);
fContextMenu->AddSeparatorItem();
item = new BMenuItem(kLabelStatus, new BMessage(kMsgStatus));
item->SetTarget(this);
fContextMenu->AddItem(item);
}
void
PPPDeskbarReplicant::MessageReceived(BMessage *message)
{
switch(message->what) {
case PPP_REPORT_MESSAGE: {
int32 type;
message->FindInt32("type", &type);
if(type == PPP_DESTRUCTION_REPORT)
BDeskbar().RemoveItem(Name());
} break;
case kMsgStatus:
fWindow->Show();
break;
default:
BView::MessageReceived(message);
}
}
void
PPPDeskbarReplicant::MouseDown(BPoint point)
{
Looper()->CurrentMessage()->FindInt32("buttons", &fLastButtons);
if(fLastButtons & B_SECONDARY_MOUSE_BUTTON) {
ConvertToScreen(&point);
fContextMenu->Go(point, true, true, true);
}
}
void
PPPDeskbarReplicant::MouseUp(BPoint point)
{
if(fLastButtons & B_PRIMARY_MOUSE_BUTTON) {
// TODO: center on screen
// 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()
{
BString name("PPPDeskbarReplicant");
name << fID;
SetName(name.String());
BRect rect(50,50,380,150);
fWindow = new PPPStatusWindow(rect, fID);
fContextMenu = new BPopUpMenu("PPPContextMenu", false);
// watch interface destruction
PPPInterface interface(fID);
if(interface.InitCheck() != B_OK)
return;
}

View File

@ -0,0 +1,44 @@
/*
* Copyright 2005, Waldemar Kornewald <wkornew@gmx.net>
* Distributed under the terms of the MIT License.
*/
#ifndef PPP_DESKBAR_REPLICANT__H
#define PPP_DESKBAR_REPLICANT__H
#include <View.h>
#include <PPPDefs.h>
class BPopUpMenu;
class PPPStatusWindow;
class PPPDeskbarReplicant : public BView {
public:
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 AttachedToWindow();
virtual void MessageReceived(BMessage *message);
virtual void MouseDown(BPoint point);
virtual void MouseUp(BPoint point);
virtual void Draw(BRect updateRect);
private:
void Init();
private:
PPPStatusWindow *fWindow;
BPopUpMenu *fContextMenu;
ppp_interface_id fID;
int32 fLastButtons;
};
#endif

View File

@ -0,0 +1,176 @@
/*
* Copyright 2005, Waldemar Kornewald <wkornew@gmx.net>
* Distributed under the terms of the MIT License.
*/
#include "PPPStatusView.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";
PPPStatusView::PPPStatusView(BRect rect, ppp_interface_id id)
: BView(rect, "PPPStatusView", 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
PPPStatusView::AttachedToWindow()
{
fButton->SetTarget(this);
Window()->SetTitle(fInterface.Name());
}
void
PPPStatusView::MessageReceived(BMessage *message)
{
switch(message->what) {
case kMsgDisconnect:
fInterface.Down();
Window()->Hide();
break;
default:
BView::MessageReceived(message);
}
}
void
PPPStatusView::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());
}

View File

@ -0,0 +1,30 @@
/*
* Copyright 2005, Waldemar Kornewald <wkornew@gmx.net>
* Distributed under the terms of the MIT License.
*/
#ifndef STATUS_VIEW__H
#define STATUS_VIEW__H
#include <View.h>
#include <PPPInterface.h>
class PPPStatusView : public BView {
public:
PPPStatusView(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

View File

@ -0,0 +1,26 @@
/*
* Copyright 2005, Waldemar Kornewald <wkornew@gmx.net>
* Distributed under the terms of the MIT License.
*/
#include "PPPStatusWindow.h"
PPPStatusWindow::PPPStatusWindow(BRect frame, ppp_interface_id id)
: BWindow(frame, "", B_TITLED_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE,
B_ALL_WORKSPACES)
{
SetPulseRate(1000000);
fStatusView = new PPPStatusView(Bounds(), id);
AddChild(fStatusView);
}
bool
PPPStatusWindow::QuitRequested()
{
// only the replicant may delete this window!
Hide();
return false;
}

View File

@ -0,0 +1,27 @@
/*
* Copyright 2005, Waldemar Kornewald <wkornew@gmx.net>
* Distributed under the terms of the MIT License.
*/
#ifndef STATUS_WINDOW__H
#define STATUS_WINDOW__H
#include <Window.h>
#include "PPPStatusView.h"
class PPPStatusWindow : public BWindow {
public:
PPPStatusWindow(BRect frame, ppp_interface_id id);
PPPStatusView *StatusView()
{ return fStatusView; }
virtual bool QuitRequested();
private:
PPPStatusView *fStatusView;
};
#endif

View File

@ -0,0 +1,42 @@
/*
* Copyright 2005, Waldemar Kornewald <wkornew@gmx.net>
* Distributed under the terms of the MIT License.
*/
#include "PPPUpApplication.h"
#include "ConnectionWindow.h"
#include <KPPPUtils.h>
#include <PPPReportDefs.h>
int
main(int argc, const char *argv[])
{
if(argc != 2)
return -1;
const char *interfaceName = argv[1];
new PPPUpApplication(interfaceName);
be_app->Run();
delete be_app;
return 0;
}
PPPUpApplication::PPPUpApplication(const char *interfaceName)
: BApplication(APP_SIGNATURE),
fInterfaceName(interfaceName)
{
}
void
PPPUpApplication::ReadyToRun()
{
BRect rect(150, 50, 450, 435);
// TODO: center rect on screen
(new ConnectionWindow(rect, fInterfaceName))->Run();
}

View File

@ -0,0 +1,29 @@
/*
* Copyright 2005, Waldemar Kornewald <wkornew@gmx.net>
* Distributed under the terms of the MIT License.
*/
#ifndef PPP_UP_APPLICATION__H
#define PPP_UP_APPLICATION__H
#include <Application.h>
#include <String.h>
#include <PPPInterfaceListener.h>
class ConnectionWindow;
#define APP_SIGNATURE "application/x-vnd.haiku.ppp_up"
class PPPUpApplication : public BApplication {
public:
PPPUpApplication(const char *interfaceName);
virtual void ReadyToRun();
private:
BString fInterfaceName;
};
#endif

View File

@ -0,0 +1,37 @@
/*
ppp_up.rdef
*/
resource app_signature "application/x-vnd.haiku.ppp_up";
/* BEOS:APP_FLAGS :
00000000 = SINGLE LAUNCH
00000001 = MULTIPLE LAUNCH
00000002 = EXCLUSIVE LAUNCH
00000004 = BACKGROUND APP + SINGLE LAUNCH
00000005 = BACKGROUND APP + MULTIPLE LAUNCH
00000006 = BACKGROUND APP + EXCLUSIVE LAUNCH
00000008 = ARGV_ONLY + SINGLE LAUNCH
00000009 = ARGV_ONLY + MULTIPLE LAUNCH
0000000A = ARGV_ONLY + EXCLUSIVE LAUNCH
0000000C = ARGV_ONLY + BACKGROUND APP + SINGLE LAUNCH
0000000D = ARGV_ONLY + BACKGROUND APP + MULTIPLE LAUNCH
0000000E = ARGV_ONLY + BACKGROUND APP + EXCLUSIVE LAUNCH
*/
resource app_flags 0x00000005;
resource app_version {
major = 0,
middle = 1,
minor = 0,
/* 0 = development 1 = alpha 2 = beta
3 = gamma 4 = golden master 5 = final */
variety = 0,
internal = 0,
short_info = "ppp_up",
long_info = "PPP interface GUI initialization app."
};