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:
Axel Dörfler
2015-03-27 13:24:08 +01:00
parent d26777c4e4
commit d45b018021
2 changed files with 46 additions and 16 deletions
@@ -12,13 +12,15 @@
#include <Button.h>
#include <Catalog.h>
#include <LayoutBuilder.h>
#include <MessageRunner.h>
#include <StringView.h>
#include <TextView.h>
#include <NetServer.h>
static const uint32 kMsgToggleService = 'tgls';
static const uint32 kMsgEnableToggleButton = 'entg';
static const bigtime_t kDisableDuration = 500000;
#undef B_TRANSLATION_CONTEXT
@@ -54,6 +56,8 @@ ServiceView::ServiceView(const char* name, const char* executable,
SetExplicitMinSize(BSize(200, B_SIZE_UNSET));
_UpdateEnableButton();
fWasEnabled = IsEnabled();
}
@@ -62,6 +66,21 @@ ServiceView::~ServiceView()
}
bool
ServiceView::IsRevertable()
{
return IsEnabled() != fWasEnabled;
}
void
ServiceView::Revert()
{
if (IsRevertable())
_Toggle();
}
void
ServiceView::SettingsUpdated(uint32 which)
{
@@ -82,13 +101,14 @@ ServiceView::MessageReceived(BMessage* message)
{
switch (message->what) {
case kMsgToggleService:
if (IsEnabled())
Disable();
else
Enable();
_Toggle();
break;
case kMsgEnableToggleButton:
fEnableButton->SetEnabled(true);
_UpdateEnableButton();
break;
default:
BView::MessageReceived(message);
break;
@@ -99,16 +119,7 @@ ServiceView::MessageReceived(BMessage* message)
bool
ServiceView::IsEnabled() const
{
BMessage request(kMsgIsServiceRunning);
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;
return fSettings.Service(fName).IsRunning();
}
@@ -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
ServiceView::_UpdateEnableButton()
{
@@ -26,6 +26,9 @@ public:
BNetworkSettings& settings);
virtual ~ServiceView();
bool IsRevertable();
void Revert();
void SettingsUpdated(uint32 which);
virtual void AttachedToWindow();
@@ -37,6 +40,7 @@ protected:
virtual void Disable();
private:
void _Toggle();
void _UpdateEnableButton();
protected:
@@ -44,6 +48,7 @@ protected:
const char* fExecutable;
BNetworkSettings& fSettings;
BButton* fEnableButton;
bool fWasEnabled;
};