Network: SSH list item now indicates a running server.
* This will be moved into the network preferences, so that it can be used from other add-ons, as well.
This commit is contained in:
@@ -5,6 +5,7 @@ UsePrivateHeaders app libroot kernel net shared ;
|
|||||||
|
|
||||||
Addon SSHService :
|
Addon SSHService :
|
||||||
SSHServiceAddOn.cpp
|
SSHServiceAddOn.cpp
|
||||||
|
ServiceListItem.cpp
|
||||||
ServiceView.cpp
|
ServiceView.cpp
|
||||||
|
|
||||||
: be bnetapi libshared.a <nogrist>Network [ TargetLibsupc++ ]
|
: be bnetapi libshared.a <nogrist>Network [ TargetLibsupc++ ]
|
||||||
@@ -13,5 +14,6 @@ Addon SSHService :
|
|||||||
|
|
||||||
DoCatalogs SSHService : x-vnd.Haiku-SSHService :
|
DoCatalogs SSHService : x-vnd.Haiku-SSHService :
|
||||||
SSHServiceAddOn.cpp
|
SSHServiceAddOn.cpp
|
||||||
|
ServiceListItem.cpp
|
||||||
ServiceView.cpp
|
ServiceView.cpp
|
||||||
;
|
;
|
||||||
|
|||||||
@@ -15,7 +15,6 @@
|
|||||||
#include <LayoutBuilder.h>
|
#include <LayoutBuilder.h>
|
||||||
#include <NetworkSettings.h>
|
#include <NetworkSettings.h>
|
||||||
#include <NetworkSettingsAddOn.h>
|
#include <NetworkSettingsAddOn.h>
|
||||||
#include <StringItem.h>
|
|
||||||
#include <StringView.h>
|
#include <StringView.h>
|
||||||
#include <TextView.h>
|
#include <TextView.h>
|
||||||
|
|
||||||
@@ -24,6 +23,7 @@
|
|||||||
#include <user_group.h>
|
#include <user_group.h>
|
||||||
#include <util/KMessage.h>
|
#include <util/KMessage.h>
|
||||||
|
|
||||||
|
#include "ServiceListItem.h"
|
||||||
#include "ServiceView.h"
|
#include "ServiceView.h"
|
||||||
|
|
||||||
|
|
||||||
@@ -76,7 +76,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
BNetworkSettings& fSettings;
|
BNetworkSettings& fSettings;
|
||||||
BStringItem* fItem;
|
BListItem* fItem;
|
||||||
ServiceView* fView;
|
ServiceView* fView;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -171,7 +171,7 @@ SSHServiceView::Enable()
|
|||||||
SSHServiceItem::SSHServiceItem(BNetworkSettings& settings)
|
SSHServiceItem::SSHServiceItem(BNetworkSettings& settings)
|
||||||
:
|
:
|
||||||
fSettings(settings),
|
fSettings(settings),
|
||||||
fItem(new BStringItem(B_TRANSLATE("SSH server"))),
|
fItem(new ServiceListItem("ssh", B_TRANSLATE("SSH server"), settings)),
|
||||||
fView(NULL)
|
fView(NULL)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,126 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2015 Haiku, Inc. All rights reserved.
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Axel Dörfler, <[email protected]>
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "ServiceListItem.h"
|
||||||
|
|
||||||
|
#include <Catalog.h>
|
||||||
|
#include <ControlLook.h>
|
||||||
|
|
||||||
|
|
||||||
|
static const char* kEnabledState = "on";
|
||||||
|
static const char* kDisabledState = "off";
|
||||||
|
|
||||||
|
|
||||||
|
#undef B_TRANSLATION_CONTEXT
|
||||||
|
#define B_TRANSLATION_CONTEXT "ServiceListItem"
|
||||||
|
|
||||||
|
|
||||||
|
ServiceListItem::ServiceListItem(const char* name, const char* label,
|
||||||
|
const BNetworkSettings& settings)
|
||||||
|
:
|
||||||
|
fName(name),
|
||||||
|
fLabel(label),
|
||||||
|
fSettings(settings),
|
||||||
|
fEnabled(false)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ServiceListItem::~ServiceListItem()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
ServiceListItem::DrawItem(BView* owner, BRect bounds, bool complete)
|
||||||
|
{
|
||||||
|
owner->PushState();
|
||||||
|
|
||||||
|
rgb_color lowColor = owner->LowColor();
|
||||||
|
|
||||||
|
if (IsSelected() || complete) {
|
||||||
|
if (IsSelected()) {
|
||||||
|
owner->SetHighColor(ui_color(B_LIST_SELECTED_BACKGROUND_COLOR));
|
||||||
|
owner->SetLowColor(owner->HighColor());
|
||||||
|
} else
|
||||||
|
owner->SetHighColor(lowColor);
|
||||||
|
|
||||||
|
owner->FillRect(bounds);
|
||||||
|
}
|
||||||
|
|
||||||
|
const char* stateText = fEnabled ? B_TRANSLATE(kEnabledState)
|
||||||
|
: B_TRANSLATE(kDisabledState);
|
||||||
|
|
||||||
|
// Set the initial bounds of item contents
|
||||||
|
BPoint statePoint = bounds.RightTop() + BPoint(0, fLineOffset)
|
||||||
|
- BPoint(be_plain_font->StringWidth(stateText)
|
||||||
|
+ be_control_look->DefaultLabelSpacing(), 0);
|
||||||
|
BPoint namePoint = bounds.LeftTop()
|
||||||
|
+ BPoint(be_control_look->DefaultLabelSpacing(), fLineOffset);
|
||||||
|
|
||||||
|
owner->SetDrawingMode(B_OP_OVER);
|
||||||
|
|
||||||
|
rgb_color textColor;
|
||||||
|
if (IsSelected())
|
||||||
|
textColor = ui_color(B_LIST_SELECTED_ITEM_TEXT_COLOR);
|
||||||
|
else
|
||||||
|
textColor = ui_color(B_LIST_ITEM_TEXT_COLOR);
|
||||||
|
|
||||||
|
owner->SetHighColor(textColor);
|
||||||
|
owner->DrawString(fLabel, namePoint);
|
||||||
|
|
||||||
|
if (!fEnabled) {
|
||||||
|
if (textColor.red + textColor.green + textColor.blue > 128 * 3)
|
||||||
|
owner->SetHighColor(tint_color(textColor, B_DARKEN_1_TINT));
|
||||||
|
else
|
||||||
|
owner->SetHighColor(tint_color(textColor, B_LIGHTEN_1_TINT));
|
||||||
|
}
|
||||||
|
owner->DrawString(stateText, statePoint);
|
||||||
|
|
||||||
|
owner->PopState();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
ServiceListItem::Update(BView* owner, const BFont* font)
|
||||||
|
{
|
||||||
|
fOwner = owner;
|
||||||
|
fEnabled = IsEnabled();
|
||||||
|
|
||||||
|
BListItem::Update(owner, font);
|
||||||
|
font_height height;
|
||||||
|
font->GetHeight(&height);
|
||||||
|
|
||||||
|
fLineOffset = 2 + ceilf(height.ascent + height.leading / 2);
|
||||||
|
|
||||||
|
float maxStateWidth = std::max(font->StringWidth(B_TRANSLATE(kEnabledState)),
|
||||||
|
font->StringWidth(B_TRANSLATE(kDisabledState)));
|
||||||
|
SetWidth(font->StringWidth(fLabel)
|
||||||
|
+ 3 * be_control_look->DefaultLabelSpacing() + maxStateWidth);
|
||||||
|
SetHeight(4 + ceilf(height.ascent + height.leading + height.descent));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
ServiceListItem::SettingsUpdated(uint32 type)
|
||||||
|
{
|
||||||
|
if (type == BNetworkSettings::kMsgServiceSettingsUpdated) {
|
||||||
|
bool wasEnabled = fEnabled;
|
||||||
|
fEnabled = IsEnabled();
|
||||||
|
if (wasEnabled != fEnabled)
|
||||||
|
fOwner->Invalidate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
ServiceListItem::IsEnabled()
|
||||||
|
{
|
||||||
|
return fSettings.Service(fName).IsRunning();
|
||||||
|
}
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2015 Haiku, Inc. All rights reserved.
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Axel Dörfler, <[email protected]>
|
||||||
|
*/
|
||||||
|
#ifndef SERVICE_LIST_ITEM_H
|
||||||
|
#define SERVICE_LIST_ITEM_H
|
||||||
|
|
||||||
|
|
||||||
|
#include <ListItem.h>
|
||||||
|
#include <NetworkSettings.h>
|
||||||
|
#include <NetworkSettingsAddOn.h>
|
||||||
|
|
||||||
|
|
||||||
|
using namespace BNetworkKit;
|
||||||
|
|
||||||
|
|
||||||
|
class ServiceListItem : public BListItem,
|
||||||
|
public BNetworkKit::BNetworkSettingsListener {
|
||||||
|
public:
|
||||||
|
ServiceListItem(const char* name,
|
||||||
|
const char* label,
|
||||||
|
const BNetworkSettings& settings);
|
||||||
|
virtual ~ServiceListItem();
|
||||||
|
|
||||||
|
virtual void DrawItem(BView* owner,
|
||||||
|
BRect bounds, bool complete);
|
||||||
|
virtual void Update(BView* owner, const BFont* font);
|
||||||
|
|
||||||
|
inline const char* Name() const { return fName; }
|
||||||
|
|
||||||
|
virtual void SettingsUpdated(uint32 type);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual bool IsEnabled();
|
||||||
|
|
||||||
|
private:
|
||||||
|
const char* fName;
|
||||||
|
const char* fLabel;
|
||||||
|
const BNetworkSettings&
|
||||||
|
fSettings;
|
||||||
|
|
||||||
|
BView* fOwner;
|
||||||
|
float fLineOffset;
|
||||||
|
bool fEnabled;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif // SERVICE_LIST_ITEM_H
|
||||||
Reference in New Issue
Block a user