Network: service enable now waits a bit, revertable.
* When you press the enable/disable button, it now stays disabled for half a second before it is updated, and reenabled again. * This is done so that the net_server has time to update its internal state, so that it should look correct right from the start, even if the server does not immediately react to the changes. * Now uses the BNetworkServiceSettings::IsRunning() method. * Added IsRevertable(), and Revert(), methods.
This commit is contained in:
@@ -12,13 +12,15 @@
|
|||||||
#include <Button.h>
|
#include <Button.h>
|
||||||
#include <Catalog.h>
|
#include <Catalog.h>
|
||||||
#include <LayoutBuilder.h>
|
#include <LayoutBuilder.h>
|
||||||
|
#include <MessageRunner.h>
|
||||||
#include <StringView.h>
|
#include <StringView.h>
|
||||||
#include <TextView.h>
|
#include <TextView.h>
|
||||||
|
|
||||||
#include <NetServer.h>
|
|
||||||
|
|
||||||
|
|
||||||
static const uint32 kMsgToggleService = 'tgls';
|
static const uint32 kMsgToggleService = 'tgls';
|
||||||
|
static const uint32 kMsgEnableToggleButton = 'entg';
|
||||||
|
|
||||||
|
static const bigtime_t kDisableDuration = 500000;
|
||||||
|
|
||||||
|
|
||||||
#undef B_TRANSLATION_CONTEXT
|
#undef B_TRANSLATION_CONTEXT
|
||||||
@@ -54,6 +56,8 @@ ServiceView::ServiceView(const char* name, const char* executable,
|
|||||||
|
|
||||||
SetExplicitMinSize(BSize(200, B_SIZE_UNSET));
|
SetExplicitMinSize(BSize(200, B_SIZE_UNSET));
|
||||||
_UpdateEnableButton();
|
_UpdateEnableButton();
|
||||||
|
|
||||||
|
fWasEnabled = IsEnabled();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -62,6 +66,21 @@ ServiceView::~ServiceView()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
ServiceView::IsRevertable()
|
||||||
|
{
|
||||||
|
return IsEnabled() != fWasEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
ServiceView::Revert()
|
||||||
|
{
|
||||||
|
if (IsRevertable())
|
||||||
|
_Toggle();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ServiceView::SettingsUpdated(uint32 which)
|
ServiceView::SettingsUpdated(uint32 which)
|
||||||
{
|
{
|
||||||
@@ -82,13 +101,14 @@ ServiceView::MessageReceived(BMessage* message)
|
|||||||
{
|
{
|
||||||
switch (message->what) {
|
switch (message->what) {
|
||||||
case kMsgToggleService:
|
case kMsgToggleService:
|
||||||
if (IsEnabled())
|
_Toggle();
|
||||||
Disable();
|
break;
|
||||||
else
|
|
||||||
Enable();
|
|
||||||
|
|
||||||
|
case kMsgEnableToggleButton:
|
||||||
|
fEnableButton->SetEnabled(true);
|
||||||
_UpdateEnableButton();
|
_UpdateEnableButton();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
BView::MessageReceived(message);
|
BView::MessageReceived(message);
|
||||||
break;
|
break;
|
||||||
@@ -99,16 +119,7 @@ ServiceView::MessageReceived(BMessage* message)
|
|||||||
bool
|
bool
|
||||||
ServiceView::IsEnabled() const
|
ServiceView::IsEnabled() const
|
||||||
{
|
{
|
||||||
BMessage request(kMsgIsServiceRunning);
|
return fSettings.Service(fName).IsRunning();
|
||||||
request.AddString("name", fName);
|
|
||||||
|
|
||||||
BMessenger networkServer(kNetServerSignature);
|
|
||||||
BMessage reply;
|
|
||||||
status_t status = networkServer.SendMessage(&request, &reply);
|
|
||||||
if (status == B_OK)
|
|
||||||
return reply.GetBool("running");
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -132,6 +143,20 @@ ServiceView::Disable()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
ServiceView::_Toggle()
|
||||||
|
{
|
||||||
|
if (IsEnabled())
|
||||||
|
Disable();
|
||||||
|
else
|
||||||
|
Enable();
|
||||||
|
|
||||||
|
fEnableButton->SetEnabled(false);
|
||||||
|
BMessage reenable(kMsgEnableToggleButton);
|
||||||
|
BMessageRunner::StartSending(this, &reenable, kDisableDuration, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ServiceView::_UpdateEnableButton()
|
ServiceView::_UpdateEnableButton()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -26,6 +26,9 @@ public:
|
|||||||
BNetworkSettings& settings);
|
BNetworkSettings& settings);
|
||||||
virtual ~ServiceView();
|
virtual ~ServiceView();
|
||||||
|
|
||||||
|
bool IsRevertable();
|
||||||
|
void Revert();
|
||||||
|
|
||||||
void SettingsUpdated(uint32 which);
|
void SettingsUpdated(uint32 which);
|
||||||
|
|
||||||
virtual void AttachedToWindow();
|
virtual void AttachedToWindow();
|
||||||
@@ -37,6 +40,7 @@ protected:
|
|||||||
virtual void Disable();
|
virtual void Disable();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void _Toggle();
|
||||||
void _UpdateEnableButton();
|
void _UpdateEnableButton();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@@ -44,6 +48,7 @@ protected:
|
|||||||
const char* fExecutable;
|
const char* fExecutable;
|
||||||
BNetworkSettings& fSettings;
|
BNetworkSettings& fSettings;
|
||||||
BButton* fEnableButton;
|
BButton* fEnableButton;
|
||||||
|
bool fWasEnabled;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user