Ticket #8929: 0001-Add-optional-username-password-fields-to-Web-proxy-s.patch

File 0001-Add-optional-username-password-fields-to-Web-proxy-s.patch, 8.7 KB (added by jessicah, 12 years ago)
  • src/apps/webpositive/SettingsKeys.cpp

    From 0e5fd7f6440292dfba03a78b739b7ab5e7abf607 Mon Sep 17 00:00:00 2001
    From: Jessica Hamilton <jessica.l.hamilton@gmail.com>
    Date: Mon, 3 Sep 2012 19:04:45 +1200
    Subject: [PATCH] Add optional username/password fields to Web+ proxy settings.
    
    ---
     src/apps/webpositive/SettingsKeys.cpp   |    3 +
     src/apps/webpositive/SettingsKeys.h     |    5 ++-
     src/apps/webpositive/SettingsWindow.cpp |   87 +++++++++++++++++++++++++++----
     src/apps/webpositive/SettingsWindow.h   |    5 ++-
     4 files changed, 88 insertions(+), 12 deletions(-)
     mode change 100644 => 100755 src/apps/webpositive/SettingsKeys.cpp
     mode change 100644 => 100755 src/apps/webpositive/SettingsKeys.h
     mode change 100644 => 100755 src/apps/webpositive/SettingsWindow.cpp
     mode change 100644 => 100755 src/apps/webpositive/SettingsWindow.h
    
    diff --git a/src/apps/webpositive/SettingsKeys.cpp b/src/apps/webpositive/SettingsKeys.cpp
    old mode 100644
    new mode 100755
    index b72166c..4e2cf57
    a b const char* kDefaultSearchPageURL = "http://www.google.com";  
    4949const char* kSettingsKeyUseProxy = "use http proxy";
    5050const char* kSettingsKeyProxyAddress = "http proxy address";
    5151const char* kSettingsKeyProxyPort = "http proxy port";
     52const char* kSettingsKeyUseProxyAuth = "use http proxy authentication";
     53const char* kSettingsKeyProxyUsername = "http proxy username";
     54const char* kSettingsKeyProxyPassword = "http proxy password";
  • src/apps/webpositive/SettingsKeys.h

    diff --git a/src/apps/webpositive/SettingsKeys.h b/src/apps/webpositive/SettingsKeys.h
    old mode 100644
    new mode 100755
    index 1a95bbf..b3034b0
    a b extern const char* kDefaultSearchPageURL;  
    4747
    4848extern const char* kSettingsKeyUseProxy;
    4949extern const char* kSettingsKeyProxyAddress;
    50 extern const char* kSettingsKeyProxyPort;
     50extern const char* kSettingsKeyProxyPort;
     51extern const char* kSettingsKeyUseProxyAuth;
     52extern const char* kSettingsKeyProxyUsername;
     53extern const char* kSettingsKeyProxyPassword;
    5154
    5255#endif  // SETTINGS_KEYS_H
  • src/apps/webpositive/SettingsWindow.cpp

    diff --git a/src/apps/webpositive/SettingsWindow.cpp b/src/apps/webpositive/SettingsWindow.cpp
    old mode 100644
    new mode 100755
    index 39fa27a..552a3b8
    a b enum {  
    8585
    8686    MSG_USE_PROXY_CHANGED                       = 'upsc',
    8787    MSG_PROXY_ADDRESS_CHANGED                   = 'psac',
    88     MSG_PROXY_PORT_CHANGED                      = 'pspc',
     88    MSG_PROXY_PORT_CHANGED                      = 'pspc',
     89    MSG_USE_PROXY_AUTH_CHANGED                  = 'upsa',
     90    MSG_PROXY_USERNAME_CHANGED                  = 'psuc',
     91    MSG_PROXY_PASSWORD_CHANGED                  = 'pswc',
    8992};
    9093
    9194static const int32 kDefaultFontSize = 14;
    SettingsWindow::MessageReceived(BMessage* message)  
    211214        case MSG_FIXED_FONT_CHANGED:
    212215        case MSG_USE_PROXY_CHANGED:
    213216        case MSG_PROXY_ADDRESS_CHANGED:
    214         case MSG_PROXY_PORT_CHANGED:
     217        case MSG_PROXY_PORT_CHANGED:
     218        case MSG_USE_PROXY_AUTH_CHANGED:
     219        case MSG_PROXY_USERNAME_CHANGED:
     220        case MSG_PROXY_PASSWORD_CHANGED:
    215221            // TODO: Some settings could change live, some others not?
    216222            _ValidateControlsEnabledStatus();
    217223            break;
    SettingsWindow::_CreateProxyPage(float spacing)  
    463469    fProxyPortControl->SetModificationMessage(
    464470        new BMessage(MSG_PROXY_PORT_CHANGED));
    465471    fProxyPortControl->SetText(
    466         fSettings->GetValue(kSettingsKeyProxyAddress, ""));
     472        fSettings->GetValue(kSettingsKeyProxyAddress, ""));
     473
     474    fUseProxyAuthCheckBox = new BCheckBox("use authentication",
     475        B_TRANSLATE("Proxy server requires authentication"),
     476        new BMessage(MSG_USE_PROXY_AUTH_CHANGED));
     477    fUseProxyAuthCheckBox->SetValue(B_CONTROL_ON);
     478
     479    fProxyUsernameControl = new BTextControl("proxy username",
     480        B_TRANSLATE("Proxy username:"), "",
     481        new BMessage(MSG_PROXY_USERNAME_CHANGED));
     482    fProxyUsernameControl->SetModificationMessage(
     483        new BMessage(MSG_PROXY_USERNAME_CHANGED));
     484    fProxyUsernameControl->SetText(
     485        fSettings->GetValue(kSettingsKeyProxyUsername, ""));
     486
     487    fProxyPasswordControl = new BTextControl("proxy password",
     488        B_TRANSLATE("Proxy password:"), "",
     489        new BMessage(MSG_PROXY_PASSWORD_CHANGED));
     490    fProxyPasswordControl->SetModificationMessage(
     491        new BMessage(MSG_PROXY_PASSWORD_CHANGED));
     492    fProxyPasswordControl->TextView()->HideTyping(true);
     493    fProxyPasswordControl->SetText(
     494        fSettings->GetValue(kSettingsKeyProxyPassword, ""));
    467495
    468496    BView* view = BGroupLayoutBuilder(B_VERTICAL, spacing / 2)
    469497        .Add(fUseProxyCheckBox)
    SettingsWindow::_CreateProxyPage(float spacing)  
    473501
    474502            .Add(fProxyPortControl->CreateLabelLayoutItem(), 0, 1)
    475503            .Add(fProxyPortControl->CreateTextViewLayoutItem(), 1, 1)
     504        )
     505        .Add(fUseProxyAuthCheckBox)
     506        .Add(BGridLayoutBuilder(spacing / 2, spacing / 2)
     507            .Add(fProxyUsernameControl->CreateLabelLayoutItem(), 0, 0)
     508            .Add(fProxyUsernameControl->CreateTextViewLayoutItem(), 1, 0)
     509
     510            .Add(fProxyPasswordControl->CreateLabelLayoutItem(), 0, 1)
     511            .Add(fProxyPasswordControl->CreateTextViewLayoutItem(), 1, 1)
    476512        )
    477513        .Add(BSpaceLayoutItem::CreateGlue())
    478514
    SettingsWindow::_CanApplySettings() const  
    599635        fSettings->GetValue(kSettingsKeyProxyAddress, "")) != 0);
    600636
    601637    canApply = canApply || (_ProxyPort()
    602         != fSettings->GetValue(kSettingsKeyProxyPort, (uint32)0));
     638        != fSettings->GetValue(kSettingsKeyProxyPort, (uint32)0));
     639
     640    canApply = canApply || ((fUseProxyAuthCheckBox->Value() == B_CONTROL_ON)
     641        != fSettings->GetValue(kSettingsKeyUseProxyAuth, false));
     642
     643    canApply = canApply || (strcmp(fProxyUsernameControl->Text(),
     644        fSettings->GetValue(kSettingsKeyProxyUsername, "")) != 0);
     645
     646    canApply = canApply || (strcmp(fProxyPasswordControl->Text(),
     647        fSettings->GetValue(kSettingsKeyProxyPassword, "")) != 0);
    603648
    604649    return canApply;
    605650}
    SettingsWindow::_ApplySettings()  
    648693    fSettings->SetValue(kSettingsKeyProxyAddress,
    649694        fProxyAddressControl->Text());
    650695    uint32 proxyPort = _ProxyPort();
    651     fSettings->SetValue(kSettingsKeyProxyPort, proxyPort);
     696    fSettings->SetValue(kSettingsKeyProxyPort, proxyPort);
     697    fSettings->SetValue(kSettingsKeyUseProxyAuth,
     698        fUseProxyAuthCheckBox->Value() == B_CONTROL_ON);
     699    fSettings->SetValue(kSettingsKeyProxyUsername,
     700        fProxyUsernameControl->Text());
     701    fSettings->SetValue(kSettingsKeyProxyPassword,
     702        fProxyPasswordControl->Text());
    652703
    653704    fSettings->Save();
    654705
    SettingsWindow::_ApplySettings()  
    660711    BWebSettings::Default()->SetDefaultStandardFontSize(standardFontSize);
    661712    BWebSettings::Default()->SetDefaultFixedFontSize(fixedFontSize);
    662713
    663     if (fUseProxyCheckBox->Value() == B_CONTROL_ON) {
    664         BWebSettings::Default()->SetProxyInfo(fProxyAddressControl->Text(),
    665             proxyPort, B_PROXY_TYPE_HTTP, "", "");
     714    if (fUseProxyCheckBox->Value() == B_CONTROL_ON) {
     715        if (fUseProxyAuthCheckBox->Value() == B_CONTROL_ON) {
     716            BWebSettings::Default()->SetProxyInfo(fProxyAddressControl->Text(),
     717                proxyPort, B_PROXY_TYPE_HTTP, fProxyUsernameControl->Text(),
     718                fProxyPasswordControl->Text());
     719        } else {
     720            BWebSettings::Default()->SetProxyInfo(fProxyAddressControl->Text(),
     721                proxyPort, B_PROXY_TYPE_HTTP, "", "");
     722        }
    666723    } else
    667724        BWebSettings::Default()->SetProxyInfo();
    668725
    SettingsWindow::_RevertSettings()  
    760817        ""));
    761818    text = "";
    762819    text << fSettings->GetValue(kSettingsKeyProxyPort, (uint32)0);
    763     fProxyPortControl->SetText(text.String());
     820    fProxyPortControl->SetText(text.String());
     821    fUseProxyAuthCheckBox->SetValue(fSettings->GetValue(kSettingsKeyUseProxyAuth,
     822        false));
     823    fProxyUsernameControl->SetText(fSettings->GetValue(kSettingsKeyProxyUsername,
     824        ""));
     825    fProxyPasswordControl->SetText(fSettings->GetValue(kSettingsKeyProxyPassword,
     826        ""));
    764827
    765828    _ValidateControlsEnabledStatus();
    766829}
    SettingsWindow::_ValidateControlsEnabledStatus()  
    778841
    779842    bool useProxy = fUseProxyCheckBox->Value() == B_CONTROL_ON;
    780843    fProxyAddressControl->SetEnabled(useProxy);
    781     fProxyPortControl->SetEnabled(useProxy);
     844    fProxyPortControl->SetEnabled(useProxy);
     845    fUseProxyAuthCheckBox->SetEnabled(useProxy);
     846    bool useProxyAuth = useProxy && fUseProxyAuthCheckBox->Value() == B_CONTROL_ON;
     847    fProxyUsernameControl->SetEnabled(useProxyAuth);
     848    fProxyPasswordControl->SetEnabled(useProxyAuth);
    782849}
    783850
    784851
  • src/apps/webpositive/SettingsWindow.h

    diff --git a/src/apps/webpositive/SettingsWindow.h b/src/apps/webpositive/SettingsWindow.h
    old mode 100644
    new mode 100755
    index 251d844..0de4a5b
    a b private:  
    107107
    108108            BCheckBox*          fUseProxyCheckBox;
    109109            BTextControl*       fProxyAddressControl;
    110             BTextControl*       fProxyPortControl;
     110            BTextControl*       fProxyPortControl;
     111            BCheckBox*          fUseProxyAuthCheckBox;
     112            BTextControl*       fProxyUsernameControl;
     113            BTextControl*       fProxyPasswordControl;
    111114
    112115            BButton*            fApplyButton;
    113116            BButton*            fCancelButton;