Ticket #9426: 0001-Changed-enable-notification-button-to-a-checkb.patch

File 0001-Changed-enable-notification-button-to-a-checkb.patch, 4.5 KB (added by Secris, 7 years ago)

Final patch? Fixes a potential issue with launching the Notification Server twice.

  • src/preferences/notifications/GeneralView.cpp

    From 28f5ea8f6cb510a2ccd11ad8b5e31c07d3931233 Mon Sep 17 00:00:00 2001
    From: Sean Thames <secris1@gmail.com>
    Date: Wed, 5 Mar 2014 16:20:31 -0500
    Subject: [PATCH] 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.
    
    ---
     src/preferences/notifications/GeneralView.cpp | 49 +++++++--------------------
     src/preferences/notifications/GeneralView.h   |  4 +--
     2 files changed, 13 insertions(+), 40 deletions(-)
    
    diff --git a/src/preferences/notifications/GeneralView.cpp b/src/preferences/notifications/GeneralView.cpp
    index db6e9ce..f0aed14 100644
    a b  
    3939
    4040#undef B_TRANSLATION_CONTEXT
    4141#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 
     42const int32 kToggleNotifications = '_TSR';
    4943
    5044GeneralView::GeneralView(SettingsHost* host)
    5145    :
    5246    SettingsPane("general", host)
    5347{
    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));
    7252
    7353    // Autostart
    7454    fAutoStart = new BCheckBox("autostart",
    GeneralView::GeneralView(SettingsHost* host)  
    9373    SetLayout(new BGroupLayout(B_VERTICAL));
    9474    AddChild(BGroupLayoutBuilder(B_VERTICAL, inset)
    9575        .AddGroup(B_HORIZONTAL, inset)
    96             .Add(fServerButton)
    97             .Add(fStatusLabel)
     76            .Add(fNotificationBox)
    9877            .AddGlue()
    9978        .End()
    10079
    GeneralView::GeneralView(SettingsHost* host)  
    11695void
    11796GeneralView::AttachedToWindow()
    11897{
    119     fServerButton->SetTarget(this);
     98    fNotificationBox->SetTarget(this);
    12099    fAutoStart->SetTarget(this);
    121100    fTimeout->SetTarget(this);
    122101}
    void  
    126105GeneralView::MessageReceived(BMessage* msg)
    127106{
    128107    switch (msg->what) {
    129         case kServer: {
     108        case kToggleNotifications: {
    130109                entry_ref ref;
    131110
    132111                // Check if server is available
    GeneralView::MessageReceived(BMessage* msg)  
    141120                    return;
    142121                }
    143122
    144                 if (_IsServerRunning()) {
     123                if (fNotificationBox->Value() == B_CONTROL_OFF) {
    145124                    // Server team
    146125                    team_id team = be_roster->TeamFor(kNotificationServerSignature);
    147126
    GeneralView::MessageReceived(BMessage* msg)  
    170149                        (void)alert->Go();
    171150                        return;
    172151                    }
    173 
    174                     fServerButton->SetLabel(kStartServer);
    175                     fStatusLabel->SetText(kStopped);
    176                 } else {
     152                } else if(!_IsServerRunning()){
    177153                    // Start server
    178154                    status_t err = be_roster->Launch(kNotificationServerSignature);
    179155                    if (err != B_OK) {
    GeneralView::MessageReceived(BMessage* msg)  
    188164                        (void)alert->Go();
    189165                        return;
    190166                    }
    191 
    192                     fServerButton->SetLabel(kStopServer);
    193                     fStatusLabel->SetText(kStarted);
    194167                }
    195168            } break;
    196169        case kSettingChanged:
    GeneralView::Load()  
    231204
    232205    char buffer[255];
    233206
     207    fNotificationBox->SetValue(_IsServerRunning() ? B_CONTROL_ON : B_CONTROL_OFF);
     208
    234209    bool autoStart;
    235210    if (settings.FindBool(kAutoStartName, &autoStart) != B_OK)
    236211        autoStart = kDefaultAutoStart;
  • src/preferences/notifications/GeneralView.h

    diff --git a/src/preferences/notifications/GeneralView.h b/src/preferences/notifications/GeneralView.h
    index 12c5f40..0464d1c 100644
    a b  
    99#include "SettingsPane.h"
    1010
    1111class BCheckBox;
    12 class BButton;
    1312class BStringView;
    1413class BTextControl;
    1514
    public:  
    2625            status_t        Revert();
    2726
    2827private:
    29         BButton*            fServerButton;
    30         BStringView*        fStatusLabel;
     28        BCheckBox*          fNotificationBox;
    3129        BCheckBox*          fAutoStart;
    3230        BTextControl*       fTimeout;
    3331        BCheckBox*          fHideAll;