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

View File

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