status_t GeneralView::Load(BMessage& settings) { char buffer[255]; fNotificationBox->SetValue(_IsServerRunning() ? B_CONTROL_ON : B_CONTROL_OFF); bool autoStart; if (settings.FindBool(kAutoStartName, &autoStart) != B_OK) autoStart = kDefaultAutoStart; fAutoStart->SetValue(autoStart ? B_CONTROL_ON : B_CONTROL_OFF); int32 timeout; if (settings.FindInt32(kTimeoutName, &timeout) != B_OK) timeout = kDefaultTimeout; (void)sprintf(buffer, "%" B_PRId32, timeout); fTimeout->SetText(buffer); return B_OK; }
void GeneralView::MessageReceived(BMessage* msg) { switch (msg->what) { case kToggleNotifications: { entry_ref ref; // Check if server is available if (!_CanFindServer(&ref)) { BAlert* alert = new BAlert(B_TRANSLATE("Notifications"), B_TRANSLATE("The notifications server cannot be" " found, this means your InfoPopper installation was" " not successfully completed."), B_TRANSLATE("OK"), NULL, NULL, B_WIDTH_AS_USUAL, B_STOP_ALERT); alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE); (void)alert->Go(); return; } if (fNotificationBox->Value() == B_CONTROL_OFF) { // Server team team_id team = be_roster->TeamFor(kNotificationServerSignature); // Establish a connection to infopopper_server status_t ret = B_ERROR; BMessenger messenger(kNotificationServerSignature, team, &ret); if (ret != B_OK) { BAlert* alert = new BAlert(B_TRANSLATE( "Notifications"), B_TRANSLATE("Notifications " "cannot be stopped, because the server can't be" " reached."), B_TRANSLATE("OK"), NULL, NULL, B_WIDTH_AS_USUAL, B_STOP_ALERT); alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE); (void)alert->Go(); return; } // Send quit message if (messenger.SendMessage(B_QUIT_REQUESTED) != B_OK) { BAlert* alert = new BAlert(B_TRANSLATE( "Notifications"), B_TRANSLATE("Cannot disable" " notifications because the server can't be " "reached."), B_TRANSLATE("OK"), NULL, NULL, B_WIDTH_AS_USUAL, B_STOP_ALERT); alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE); (void)alert->Go(); return; } } else if (!_IsServerRunning()) { // Start server status_t err = be_roster->Launch(kNotificationServerSignature); if (err != B_OK) { BAlert* alert = new BAlert(B_TRANSLATE( "Notifications"), B_TRANSLATE("Cannot enable" " notifications because the server cannot be " "found.\nThis means your InfoPopper installation" " was not successfully completed."), B_TRANSLATE("OK"), NULL, NULL, B_WIDTH_AS_USUAL, B_STOP_ALERT); alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE); (void)alert->Go(); return; } } break; } case kSettingChanged: SettingsPane::MessageReceived(msg); break; default: BView::MessageReceived(msg); break; } }
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); } // Autostart fAutoStart = new BCheckBox("autostart", B_TRANSLATE("Enable notifications at startup"), new BMessage(kSettingChanged)); // Display time fTimeout = new BTextControl(B_TRANSLATE("Hide notifications from screen" " after"), NULL, new BMessage(kSettingChanged)); BStringView* displayTimeLabel = new BStringView("dt_label", B_TRANSLATE("seconds of inactivity")); // Default position // TODO: Here will come a screen representation with the four corners clickable // Load settings Load(); // Calculate inset float inset = ceilf(be_plain_font->Size() * 0.7f); SetLayout(new BGroupLayout(B_VERTICAL)); AddChild(BGroupLayoutBuilder(B_VERTICAL, inset) .AddGroup(B_HORIZONTAL, inset) .Add(fServerButton) .Add(fStatusLabel) .AddGlue() .End() .AddGroup(B_VERTICAL, inset) .Add(fAutoStart) .AddGroup(B_HORIZONTAL) .AddGroup(B_HORIZONTAL, 2) .Add(fTimeout) .Add(displayTimeLabel) .End() .End() .End() .AddGlue() ); }