summaryrefslogtreecommitdiff
path: root/cui
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2016-05-04 22:32:55 +0200
committerStephan Bergmann <sbergman@redhat.com>2016-05-04 22:32:55 +0200
commit75ac19149d21f5164e7bb3ea1b114670e1d7859e (patch)
treecf3e0a29c1188dea0608c1cafe54c6f60ee03c6f /cui
parent7a8331eb7f4e782cd9febc9923b99d4c02cd2945 (diff)
loplugin:staticmethods
Change-Id: I679fd93c409035ce87101f7fe150822c2214765e
Diffstat (limited to 'cui')
-rw-r--r--cui/source/options/personalization.cxx136
-rw-r--r--cui/source/options/personalization.hxx1
2 files changed, 70 insertions, 67 deletions
diff --git a/cui/source/options/personalization.cxx b/cui/source/options/personalization.cxx
index 70a2f8d57f4f..1b668b6d9bc5 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 d801a56f9e5d..f607cf39c70e 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: