[Libreoffice-commits] core.git: 2 commits - sc/source ucbhelper/source

Noel Grandin noel.grandin at collabora.co.uk
Fri Jun 29 06:27:05 UTC 2018


 sc/source/ui/inc/tphfedit.hxx            |    6 +-
 sc/source/ui/pagedlg/tphfedit.cxx        |   12 ++---
 ucbhelper/source/client/proxydecider.cxx |   63 +++++++++++++++++++++++++------
 3 files changed, 60 insertions(+), 21 deletions(-)

New commits:
commit a440837ee2be3759559325e3e31d90d358587727
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date:   Thu Jun 28 09:30:24 2018 +0200

    loplugin:useuniqueptr in ScEditWindow
    
    Change-Id: I0398045030b8c2dcc8cd8e47112271c80d194616
    Reviewed-on: https://gerrit.libreoffice.org/56617
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/sc/source/ui/inc/tphfedit.hxx b/sc/source/ui/inc/tphfedit.hxx
index 741f432d95bc..606053ef4920 100644
--- a/sc/source/ui/inc/tphfedit.hxx
+++ b/sc/source/ui/inc/tphfedit.hxx
@@ -68,7 +68,7 @@ public:
 
     virtual css::uno::Reference< css::accessibility::XAccessible > CreateAccessible() override;
 
-    ScHeaderEditEngine*  GetEditEngine() const { return pEdEngine; }
+    ScHeaderEditEngine*  GetEditEngine() const { return pEdEngine.get(); }
     void SetObjectSelectHdl( const Link<ScEditWindow&,void>& aLink) { aObjectSelectLink = aLink; }
     void SetGetFocusHdl(const std::function<void (ScEditWindow&)>& rLink) { m_GetFocusLink = rLink; }
 
@@ -85,8 +85,8 @@ protected:
     virtual void    Resize() override;
 
 private:
-    ScHeaderEditEngine* pEdEngine;
-    EditView*           pEdView;
+    std::unique_ptr<ScHeaderEditEngine> pEdEngine;
+    std::unique_ptr<EditView>           pEdView;
     ScEditWindowLocation eLocation;
     bool mbRTL;
 
diff --git a/sc/source/ui/pagedlg/tphfedit.cxx b/sc/source/ui/pagedlg/tphfedit.cxx
index 7ddb851ff18f..ba8582e5db87 100644
--- a/sc/source/ui/pagedlg/tphfedit.cxx
+++ b/sc/source/ui/pagedlg/tphfedit.cxx
@@ -80,7 +80,7 @@ ScEditWindow::ScEditWindow( vcl::Window* pParent, WinBits nBits, ScEditWindowLoc
     Size aSize( GetOutputSize() );
     aSize.setHeight( aSize.Height() * 4 );
 
-    pEdEngine = new ScHeaderEditEngine( EditEngine::CreatePool() );
+    pEdEngine.reset( new ScHeaderEditEngine( EditEngine::CreatePool() ) );
     pEdEngine->SetPaperSize( aSize );
     pEdEngine->SetRefDevice( this );
 
@@ -94,11 +94,11 @@ ScEditWindow::ScEditWindow( vcl::Window* pParent, WinBits nBits, ScEditWindowLoc
     if (mbRTL)
         pEdEngine->SetDefaultHorizontalTextDirection(EEHorizontalTextDirection::R2L);
 
-    pEdView = new EditView( pEdEngine, this );
+    pEdView.reset( new EditView( pEdEngine.get(), this ) );
     pEdView->SetOutputArea( tools::Rectangle( Point(0,0), GetOutputSize() ) );
 
     pEdView->SetBackgroundColor( aBgColor );
-    pEdEngine->InsertView( pEdView );
+    pEdEngine->InsertView( pEdView.get() );
 }
 
 void ScEditWindow::Resize()
@@ -125,8 +125,8 @@ void ScEditWindow::dispose()
         if (xTemp.is())
             pAcc->dispose();
     }
-    delete pEdEngine;
-    delete pEdView;
+    pEdEngine.reset();
+    pEdView.reset();
     Control::dispose();
 }
 
@@ -326,7 +326,7 @@ css::uno::Reference< css::accessibility::XAccessible > ScEditWindow::CreateAcces
         }
         break;
     }
-    pAcc = new ScAccessibleEditObject(GetAccessibleParentWindow()->GetAccessible(), pEdView, this,
+    pAcc = new ScAccessibleEditObject(GetAccessibleParentWindow()->GetAccessible(), pEdView.get(), this,
         sName, sDescription, ScAccessibleEditObject::EditControl);
     css::uno::Reference< css::accessibility::XAccessible > xAccessible = pAcc;
     xAcc = xAccessible;
commit 0e375686e2f2c6c626f50c06c5323c0982d7f602
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date:   Thu Jun 28 16:19:51 2018 +0200

    tdf#114227 Add support for OS proxy to ucbhelper::InternetProxyDecider on Unix
    
    Also make m_nProxyType a scoped enum so the code is a little easier to
    follow.
    
    Change-Id: Ic2862a1de8fe1005c4fb25147b3effc49b95140c
    Reviewed-on: https://gerrit.libreoffice.org/56599
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/ucbhelper/source/client/proxydecider.cxx b/ucbhelper/source/client/proxydecider.cxx
index fdf4506add26..080e176863ab 100644
--- a/ucbhelper/source/client/proxydecider.cxx
+++ b/ucbhelper/source/client/proxydecider.cxx
@@ -118,12 +118,14 @@ public:
 class InternetProxyDecider_Impl :
     public cppu::WeakImplHelper< util::XChangesListener >
 {
+    // see officecfg/registry/schema/org/openoffice/Inet.xcs for the definition of these values
+    enum class ProxyType { NoProxy, Automatic, Manual };
     mutable osl::Mutex                       m_aMutex;
     InternetProxyServer                      m_aHttpProxy;
     InternetProxyServer                      m_aHttpsProxy;
     InternetProxyServer                      m_aFtpProxy;
     const InternetProxyServer                m_aEmptyProxy;
-    sal_Int32                                m_nProxyType;
+    ProxyType                                m_nProxyType;
     uno::Reference< util::XChangesNotifier > m_xNotifier;
     std::vector< NoProxyListEntry >          m_aNoProxyList;
     mutable HostnameCache                    m_aHostnames;
@@ -284,7 +286,7 @@ bool getConfigInt32Value(
 
 InternetProxyDecider_Impl::InternetProxyDecider_Impl(
     const uno::Reference< uno::XComponentContext >& rxContext )
-    : m_nProxyType( 0 ),
+    : m_nProxyType( ProxyType::NoProxy ),
       m_aHostnames()
 {
     try
@@ -317,8 +319,10 @@ InternetProxyDecider_Impl::InternetProxyDecider_Impl(
             if ( xNameAccess.is() )
             {
                 // *** Proxy type ***
+                sal_Int32 tmp = 0;
                 getConfigInt32Value(
-                    xNameAccess, PROXY_TYPE_KEY, m_nProxyType );
+                    xNameAccess, PROXY_TYPE_KEY, tmp );
+                m_nProxyType = static_cast<ProxyType>(tmp);
 
                 // *** No proxy list ***
                 OUString aNoProxyList;
@@ -435,9 +439,9 @@ bool InternetProxyDecider_Impl::shouldUseProxy( const OUString & rHost,
     return true;
 }
 
-#ifdef _WIN32
 namespace
 {
+#ifdef _WIN32
 struct GetPACProxyData
 {
     const OUString& m_rProtocol;
@@ -563,8 +567,40 @@ InternetProxyServer GetPACProxy(const OUString& rProtocol, const OUString& rHost
     }
     return aData.m_ProxyServer;
 }
+
+#else // .. _WIN32
+
+// Read the settings from the OS which are stored in env vars
+//
+InternetProxyServer GetUnixSystemProxy(const OUString & rProtocol,
+                                            const OUString & /*rHost*/,
+                                            sal_Int32 /*nPort*/)
+{
+    // TODO this could be improved to read the "no_proxy" env variable
+    InternetProxyServer aProxy;
+    OUString protocolLower = rProtocol.toAsciiLowerCase() + "_proxy";
+    OString protocolLowerStr = OUStringToOString( protocolLower, RTL_TEXTENCODING_ASCII_US );
+    const char* pEnvProxy = getenv(protocolLowerStr.getStr());
+    if (!pEnvProxy)
+        return aProxy;
+    // expecting something like "https://example.ct:80"
+    OUString tmp = OUString::createFromAscii(pEnvProxy);
+    if (tmp.getLength() < (rProtocol.getLength() + 3))
+        return aProxy;
+    tmp = tmp.copy(rProtocol.getLength() + 3);
+    sal_Int32 x = tmp.indexOf(':');
+    if (x == -1)
+        return aProxy;
+    int nPort = tmp.copy(x + 1).toInt32();
+    if (nPort == 0)
+        return aProxy;
+    aProxy.aName = tmp.copy(0, x);
+    aProxy.nPort = nPort;
+    return aProxy;
+}
+
+#endif // else .. _WIN32
 }
-#endif // _WIN32
 
 InternetProxyServer InternetProxyDecider_Impl::getProxy(
                                             const OUString & rProtocol,
@@ -573,22 +609,23 @@ InternetProxyServer InternetProxyDecider_Impl::getProxy(
 {
     osl::Guard< osl::Mutex > aGuard( m_aMutex );
 
-    if ( m_nProxyType == 0 )
+    if ( m_nProxyType == ProxyType::NoProxy )
     {
         // Never use proxy.
         return m_aEmptyProxy;
     }
 
-#ifdef _WIN32
     // If get from system
-    if (m_nProxyType == 1 && !rHost.isEmpty())
+    if (m_nProxyType == ProxyType::Automatic && !rHost.isEmpty())
     {
+#ifdef _WIN32
         InternetProxyServer aProxy(GetPACProxy(rProtocol, rHost, nPort));
+#else
+        InternetProxyServer aProxy(GetUnixSystemProxy(rProtocol, rHost, nPort));
+#endif // _WIN32
         if (!aProxy.aName.isEmpty())
             return aProxy;
     }
-#endif // _WIN32
-
 
     if ( !rHost.isEmpty() && !m_aNoProxyList.empty() )
     {
@@ -667,7 +704,6 @@ InternetProxyServer InternetProxyDecider_Impl::getProxy(
     return m_aEmptyProxy;
 }
 
-
 // virtual
 void SAL_CALL InternetProxyDecider_Impl::changesOccurred(
                                         const util::ChangesEvent& Event )
@@ -687,11 +723,14 @@ void SAL_CALL InternetProxyDecider_Impl::changesOccurred(
             {
                 if ( aKey == PROXY_TYPE_KEY )
                 {
-                    if ( !( rElem.Element >>= m_nProxyType ) )
+                    sal_Int32 tmp;
+                    if ( !( rElem.Element >>= tmp ) )
                     {
                         OSL_FAIL( "InternetProxyDecider - changesOccurred - "
                                     "Error getting config item value!" );
                     }
+                    else
+                        m_nProxyType = static_cast<ProxyType>(tmp);
                 }
                 else if ( aKey == NO_PROXY_LIST_KEY )
                 {


More information about the Libreoffice-commits mailing list