From ab10faa2ad952cc4f728549efaf336917e27a67b Mon Sep 17 00:00:00 2001
From: Sean Thames <secris1@gmail.com>
Date: Wed, 5 Mar 2014 15:48:18 -0500
Subject: [PATCH] Changed notification button to a checkbox. Changed to more
appropriate variable names. Fixed a potential issue with fNotificationBox
getting out of sync
---
src/preferences/notifications/GeneralView.cpp | 47 +++++++--------------------
src/preferences/notifications/GeneralView.h | 4 +--
2 files changed, 12 insertions(+), 39 deletions(-)
diff --git a/src/preferences/notifications/GeneralView.cpp b/src/preferences/notifications/GeneralView.cpp
index db6e9ce..e9fc6c0 100644
a
|
b
|
|
39 | 39 | |
40 | 40 | #undef B_TRANSLATION_CONTEXT |
41 | 41 | #define B_TRANSLATION_CONTEXT "GeneralView" |
42 | | const int32 kServer = '_TSR'; |
43 | | |
44 | | const char* kStartServer = B_TRANSLATE("Enable notifications"); |
45 | | const char* kStopServer = B_TRANSLATE("Disable notifications"); |
46 | | const char* kStarted = B_TRANSLATE("Events are notified"); |
47 | | const char* kStopped = B_TRANSLATE("Events are not notified"); |
48 | | |
| 42 | const int32 kToggleNotifications = '_TSR'; |
49 | 43 | |
50 | 44 | GeneralView::GeneralView(SettingsHost* host) |
51 | 45 | : |
52 | 46 | SettingsPane("general", host) |
53 | 47 | { |
54 | | BFont statusFont; |
55 | | |
56 | | // Set a smaller font for the status label |
57 | | statusFont.SetSize(be_plain_font->Size() * 0.8); |
58 | | |
59 | | // Status button and label |
60 | | fServerButton = new BButton("server", kStartServer, new BMessage(kServer)); |
61 | | fStatusLabel = new BStringView("status", kStopped); |
62 | | fStatusLabel->SetFont(&statusFont); |
63 | | |
64 | | // Update status label and server button |
65 | | if (_IsServerRunning()) { |
66 | | fServerButton->SetLabel(kStopServer); |
67 | | fStatusLabel->SetText(kStarted); |
68 | | } else { |
69 | | fServerButton->SetLabel(kStartServer); |
70 | | fStatusLabel->SetText(kStopped); |
71 | | } |
| 48 | // Notifications |
| 49 | fNotificationBox = new BCheckBox("server", |
| 50 | B_TRANSLATE("Enable notifications"), |
| 51 | new BMessage(kToggleNotifications)); |
72 | 52 | |
73 | 53 | // Autostart |
74 | 54 | fAutoStart = new BCheckBox("autostart", |
… |
… |
GeneralView::GeneralView(SettingsHost* host)
|
93 | 73 | SetLayout(new BGroupLayout(B_VERTICAL)); |
94 | 74 | AddChild(BGroupLayoutBuilder(B_VERTICAL, inset) |
95 | 75 | .AddGroup(B_HORIZONTAL, inset) |
96 | | .Add(fServerButton) |
97 | | .Add(fStatusLabel) |
| 76 | .Add(fNotificationBox) |
98 | 77 | .AddGlue() |
99 | 78 | .End() |
100 | 79 | |
… |
… |
GeneralView::GeneralView(SettingsHost* host)
|
116 | 95 | void |
117 | 96 | GeneralView::AttachedToWindow() |
118 | 97 | { |
119 | | fServerButton->SetTarget(this); |
| 98 | fNotificationBox->SetTarget(this); |
120 | 99 | fAutoStart->SetTarget(this); |
121 | 100 | fTimeout->SetTarget(this); |
122 | 101 | } |
… |
… |
void
|
126 | 105 | GeneralView::MessageReceived(BMessage* msg) |
127 | 106 | { |
128 | 107 | switch (msg->what) { |
129 | | case kServer: { |
| 108 | case kToggleNotifications: { |
130 | 109 | entry_ref ref; |
131 | 110 | |
132 | 111 | // Check if server is available |
… |
… |
GeneralView::MessageReceived(BMessage* msg)
|
141 | 120 | return; |
142 | 121 | } |
143 | 122 | |
144 | | if (_IsServerRunning()) { |
| 123 | if (fNotificationBox->Value() == B_CONTROL_OFF) { |
145 | 124 | // Server team |
146 | 125 | team_id team = be_roster->TeamFor(kNotificationServerSignature); |
147 | 126 | |
… |
… |
GeneralView::MessageReceived(BMessage* msg)
|
170 | 149 | (void)alert->Go(); |
171 | 150 | return; |
172 | 151 | } |
173 | | |
174 | | fServerButton->SetLabel(kStartServer); |
175 | | fStatusLabel->SetText(kStopped); |
176 | 152 | } else { |
177 | 153 | // Start server |
178 | 154 | status_t err = be_roster->Launch(kNotificationServerSignature); |
… |
… |
GeneralView::MessageReceived(BMessage* msg)
|
188 | 164 | (void)alert->Go(); |
189 | 165 | return; |
190 | 166 | } |
191 | | |
192 | | fServerButton->SetLabel(kStopServer); |
193 | | fStatusLabel->SetText(kStarted); |
194 | 167 | } |
195 | 168 | } break; |
196 | 169 | case kSettingChanged: |
… |
… |
GeneralView::Load()
|
231 | 204 | |
232 | 205 | char buffer[255]; |
233 | 206 | |
| 207 | fNotificationBox->SetValue(_IsServerRunning() ? B_CONTROL_ON : B_CONTROL_OFF); |
| 208 | |
234 | 209 | bool autoStart; |
235 | 210 | if (settings.FindBool(kAutoStartName, &autoStart) != B_OK) |
236 | 211 | autoStart = kDefaultAutoStart; |
diff --git a/src/preferences/notifications/GeneralView.h b/src/preferences/notifications/GeneralView.h
index 12c5f40..0464d1c 100644
a
|
b
|
|
9 | 9 | #include "SettingsPane.h" |
10 | 10 | |
11 | 11 | class BCheckBox; |
12 | | class BButton; |
13 | 12 | class BStringView; |
14 | 13 | class BTextControl; |
15 | 14 | |
… |
… |
public:
|
26 | 25 | status_t Revert(); |
27 | 26 | |
28 | 27 | private: |
29 | | BButton* fServerButton; |
30 | | BStringView* fStatusLabel; |
| 28 | BCheckBox* fNotificationBox; |
31 | 29 | BCheckBox* fAutoStart; |
32 | 30 | BTextControl* fTimeout; |
33 | 31 | BCheckBox* fHideAll; |