Changed enable notification button to a checkb Changed variable names to more appropriate names. Fixed a potential issue with fNotificationBox getting out of sync. Fixed a potential issue of starting the Notification Server more than once.

Signed-off-by: Adrien Destugues <pulkomandy@pulkomandy.tk>
This commit is contained in:
Sean Thames 2014-03-05 16:20:31 -05:00 committed by Adrien Destugues
parent 01be25aefe
commit 54e1893c41
2 changed files with 13 additions and 40 deletions

View File

@ -39,36 +39,16 @@
#undef B_TRANSLATION_CONTEXT
#define B_TRANSLATION_CONTEXT "GeneralView"
const int32 kServer = '_TSR';
const char* kStartServer = B_TRANSLATE("Enable notifications");
const char* kStopServer = B_TRANSLATE("Disable notifications");
const char* kStarted = B_TRANSLATE("Events are notified");
const char* kStopped = B_TRANSLATE("Events are not notified");
const int32 kToggleNotifications = '_TSR';
GeneralView::GeneralView(SettingsHost* host)
:
SettingsPane("general", host)
{
BFont statusFont;
// Set a smaller font for the status label
statusFont.SetSize(be_plain_font->Size() * 0.8);
// Status button and label
fServerButton = new BButton("server", kStartServer, new BMessage(kServer));
fStatusLabel = new BStringView("status", kStopped);
fStatusLabel->SetFont(&statusFont);
// Update status label and server button
if (_IsServerRunning()) {
fServerButton->SetLabel(kStopServer);
fStatusLabel->SetText(kStarted);
} else {
fServerButton->SetLabel(kStartServer);
fStatusLabel->SetText(kStopped);
}
// Notifications
fNotificationBox = new BCheckBox("server",
B_TRANSLATE("Enable notifications"),
new BMessage(kToggleNotifications));
// Autostart
fAutoStart = new BCheckBox("autostart",
@ -93,8 +73,7 @@ GeneralView::GeneralView(SettingsHost* host)
SetLayout(new BGroupLayout(B_VERTICAL));
AddChild(BGroupLayoutBuilder(B_VERTICAL, inset)
.AddGroup(B_HORIZONTAL, inset)
.Add(fServerButton)
.Add(fStatusLabel)
.Add(fNotificationBox)
.AddGlue()
.End()
@ -116,7 +95,7 @@ GeneralView::GeneralView(SettingsHost* host)
void
GeneralView::AttachedToWindow()
{
fServerButton->SetTarget(this);
fNotificationBox->SetTarget(this);
fAutoStart->SetTarget(this);
fTimeout->SetTarget(this);
}
@ -126,7 +105,7 @@ void
GeneralView::MessageReceived(BMessage* msg)
{
switch (msg->what) {
case kServer: {
case kToggleNotifications: {
entry_ref ref;
// Check if server is available
@ -141,7 +120,7 @@ GeneralView::MessageReceived(BMessage* msg)
return;
}
if (_IsServerRunning()) {
if (fNotificationBox->Value() == B_CONTROL_OFF) {
// Server team
team_id team = be_roster->TeamFor(kNotificationServerSignature);
@ -170,10 +149,7 @@ GeneralView::MessageReceived(BMessage* msg)
(void)alert->Go();
return;
}
fServerButton->SetLabel(kStartServer);
fStatusLabel->SetText(kStopped);
} else {
} else if(!_IsServerRunning()){
// Start server
status_t err = be_roster->Launch(kNotificationServerSignature);
if (err != B_OK) {
@ -188,9 +164,6 @@ GeneralView::MessageReceived(BMessage* msg)
(void)alert->Go();
return;
}
fServerButton->SetLabel(kStopServer);
fStatusLabel->SetText(kStarted);
}
} break;
case kSettingChanged:
@ -231,6 +204,8 @@ GeneralView::Load()
char buffer[255];
fNotificationBox->SetValue(_IsServerRunning() ? B_CONTROL_ON : B_CONTROL_OFF);
bool autoStart;
if (settings.FindBool(kAutoStartName, &autoStart) != B_OK)
autoStart = kDefaultAutoStart;

View File

@ -9,7 +9,6 @@
#include "SettingsPane.h"
class BCheckBox;
class BButton;
class BStringView;
class BTextControl;
@ -26,8 +25,7 @@ public:
status_t Revert();
private:
BButton* fServerButton;
BStringView* fStatusLabel;
BCheckBox* fNotificationBox;
BCheckBox* fAutoStart;
BTextControl* fTimeout;
BCheckBox* fHideAll;