[Libreoffice-commits] core.git: cui/source

Stephan Bergmann sbergman at redhat.com
Wed May 4 20:33:23 UTC 2016


 cui/source/options/personalization.cxx |  136 ++++++++++++++++-----------------
 cui/source/options/personalization.hxx |    1 
 2 files changed, 70 insertions(+), 67 deletions(-)

New commits:
commit 75ac19149d21f5164e7bb3ea1b114670e1d7859e
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Wed May 4 22:32:55 2016 +0200

    loplugin:staticmethods
    
    Change-Id: I679fd93c409035ce87101f7fe150822c2214765e

diff --git a/cui/source/options/personalization.cxx b/cui/source/options/personalization.cxx
index 70a2f8d..1b668b6 100644
--- a/cui/source/options/personalization.cxx
+++ b/cui/source/options/personalization.cxx
@@ -599,6 +599,76 @@ SearchAndParseThread::~SearchAndParseThread()
 {
 }
 
+namespace {
+
+bool getPreviewFile( const OUString& rURL, OUString *pPreviewFile, OUString *pPersonaSetting )
+{
+    uno::Reference< ucb::XSimpleFileAccess3 > xFileAccess( ucb::SimpleFileAccess::create( comphelper::getProcessComponentContext() ), uno::UNO_QUERY );
+    if ( !xFileAccess.is() )
+        return false;
+
+    Reference<XComponentContext> xContext( ::comphelper::getProcessComponentContext() );
+    uno::Reference< io::XInputStream > xStream;
+    try {
+        css:: uno::Reference< task::XInteractionHandler > xIH(
+            css::task::InteractionHandler::createWithParent( xContext, nullptr ) );
+
+        xFileAccess->setInteractionHandler( new comphelper::SimpleFileAccessInteraction( xIH ) );
+        xStream = xFileAccess->openFileRead( rURL );
+
+        if( !xStream.is() )
+            return false;
+    }
+    catch (...)
+    {
+        return false;
+    }
+
+    // read the persona specification
+    // NOTE: Parsing for real is an overkill here; and worse - I tried, and
+    // the HTML the site provides is not 100% valid ;-)
+    const sal_Int32 BUF_LEN = 8000;
+    uno::Sequence< sal_Int8 > buffer( BUF_LEN );
+    OStringBuffer aBuffer( 64000 );
+
+    sal_Int32 nRead = 0;
+    while ( ( nRead = xStream->readBytes( buffer, BUF_LEN ) ) == BUF_LEN )
+        aBuffer.append( reinterpret_cast< const char* >( buffer.getConstArray() ), nRead );
+
+    if ( nRead > 0 )
+        aBuffer.append( reinterpret_cast< const char* >( buffer.getConstArray() ), nRead );
+
+    xStream->closeInput();
+
+    // get the important bits of info
+    OUString aHeaderURL, aFooterURL, aTextColor, aAccentColor, aPreviewURL, aName;
+
+    if ( !parsePersonaInfo( aBuffer.makeStringAndClear(), &aHeaderURL, &aFooterURL, &aTextColor, &aAccentColor, &aPreviewURL, &aName ) )
+        return false;
+
+    // copy the images to the user's gallery
+    OUString gallery = "${$BRAND_BASE_DIR/" LIBO_ETC_FOLDER "/" SAL_CONFIGFILE( "bootstrap") "::UserInstallation}";
+    rtl::Bootstrap::expandMacros( gallery );
+    gallery += "/user/gallery/personas/";
+    gallery += aName + "/";
+    osl::Directory::createPath( gallery );
+
+    OUString aPreviewFile( INetURLObject( aPreviewURL ).getName() );
+
+    try {
+        xFileAccess->copy( aPreviewURL, gallery + aPreviewFile );
+    }
+    catch ( const uno::Exception & )
+    {
+        return false;
+    }
+    *pPreviewFile = gallery + aPreviewFile;
+    *pPersonaSetting = aName + ";" + aHeaderURL + ";" + aFooterURL + ";" + aTextColor + ";" + aAccentColor;
+    return true;
+}
+
+}
+
 void SearchAndParseThread::execute()
 {
     if( m_aURL.startsWith( "https://" ) )
@@ -777,70 +847,4 @@ void SearchAndParseThread::execute()
     }
 }
 
-bool SearchAndParseThread::getPreviewFile( const OUString& rURL, OUString *pPreviewFile, OUString *pPersonaSetting )
-{
-    uno::Reference< ucb::XSimpleFileAccess3 > xFileAccess( ucb::SimpleFileAccess::create( comphelper::getProcessComponentContext() ), uno::UNO_QUERY );
-    if ( !xFileAccess.is() )
-        return false;
-
-    Reference<XComponentContext> xContext( ::comphelper::getProcessComponentContext() );
-    uno::Reference< io::XInputStream > xStream;
-    try {
-        css:: uno::Reference< task::XInteractionHandler > xIH(
-            css::task::InteractionHandler::createWithParent( xContext, nullptr ) );
-
-        xFileAccess->setInteractionHandler( new comphelper::SimpleFileAccessInteraction( xIH ) );
-        xStream = xFileAccess->openFileRead( rURL );
-
-        if( !xStream.is() )
-            return false;
-    }
-    catch (...)
-    {
-        return false;
-    }
-
-    // read the persona specification
-    // NOTE: Parsing for real is an overkill here; and worse - I tried, and
-    // the HTML the site provides is not 100% valid ;-)
-    const sal_Int32 BUF_LEN = 8000;
-    uno::Sequence< sal_Int8 > buffer( BUF_LEN );
-    OStringBuffer aBuffer( 64000 );
-
-    sal_Int32 nRead = 0;
-    while ( ( nRead = xStream->readBytes( buffer, BUF_LEN ) ) == BUF_LEN )
-        aBuffer.append( reinterpret_cast< const char* >( buffer.getConstArray() ), nRead );
-
-    if ( nRead > 0 )
-        aBuffer.append( reinterpret_cast< const char* >( buffer.getConstArray() ), nRead );
-
-    xStream->closeInput();
-
-    // get the important bits of info
-    OUString aHeaderURL, aFooterURL, aTextColor, aAccentColor, aPreviewURL, aName;
-
-    if ( !parsePersonaInfo( aBuffer.makeStringAndClear(), &aHeaderURL, &aFooterURL, &aTextColor, &aAccentColor, &aPreviewURL, &aName ) )
-        return false;
-
-    // copy the images to the user's gallery
-    OUString gallery = "${$BRAND_BASE_DIR/" LIBO_ETC_FOLDER "/" SAL_CONFIGFILE( "bootstrap") "::UserInstallation}";
-    rtl::Bootstrap::expandMacros( gallery );
-    gallery += "/user/gallery/personas/";
-    gallery += aName + "/";
-    osl::Directory::createPath( gallery );
-
-    OUString aPreviewFile( INetURLObject( aPreviewURL ).getName() );
-
-    try {
-        xFileAccess->copy( aPreviewURL, gallery + aPreviewFile );
-    }
-    catch ( const uno::Exception & )
-    {
-        return false;
-    }
-    *pPreviewFile = gallery + aPreviewFile;
-    *pPersonaSetting = aName + ";" + aHeaderURL + ";" + aFooterURL + ";" + aTextColor + ";" + aAccentColor;
-    return true;
-}
-
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/cui/source/options/personalization.hxx b/cui/source/options/personalization.hxx
index d801a56..f607cf3 100644
--- a/cui/source/options/personalization.hxx
+++ b/cui/source/options/personalization.hxx
@@ -125,7 +125,6 @@ private:
 
     virtual ~SearchAndParseThread();
     virtual void execute() override;
-    bool getPreviewFile( const OUString&, OUString *, OUString * );
 
 public:
 


More information about the Libreoffice-commits mailing list