cui/source/options/personalization.cxx | 138 ++++++++++++- cui/source/options/personalization.hxx | 13 - officecfg/registry/schema/org/openoffice/Office/Common.xcs | 10 3 files changed, 153 insertions(+), 8 deletions(-)
New commits: commit 93fce951784cd561f308c5019aa0b3a178116a92 Author: Jan Holesovsky <[email protected]> Date: Thu Dec 6 08:29:02 2012 +0100 Personas: Force selection when the 'own' clicked, but nothing chosen yet. Change-Id: Iaf5a82a7f12ed7112f86bfa1c5f243ab00ca4285 diff --git a/cui/source/options/personalization.cxx b/cui/source/options/personalization.cxx index 33fb11d..562b7b4 100644 --- a/cui/source/options/personalization.cxx +++ b/cui/source/options/personalization.cxx @@ -90,7 +90,9 @@ SvxPersonalizationTabPage::SvxPersonalizationTabPage( Window *pParent, const Sfx // background image get( m_pNoBackground, "no_background" ); get( m_pDefaultBackground, "default_background" ); + get( m_pOwnBackground, "own_background" ); + m_pOwnBackground->SetClickHdl( LINK( this, SvxPersonalizationTabPage, ForceSelect ) ); get( m_pSelectBackground, "select_background" ); m_pSelectBackground->SetClickHdl( LINK( this, SvxPersonalizationTabPage, SelectBackground ) ); @@ -98,10 +100,11 @@ SvxPersonalizationTabPage::SvxPersonalizationTabPage( Window *pParent, const Sfx // persona get( m_pNoPersona, "no_persona" ); get( m_pDefaultPersona, "default_persona" ); + get( m_pOwnPersona, "own_persona" ); + m_pOwnPersona->SetClickHdl( LINK( this, SvxPersonalizationTabPage, ForceSelect ) ); get( m_pSelectPersona, "select_persona" ); - LINK( this, SvxPersonalizationTabPage, SelectPersona ); m_pSelectPersona->SetClickHdl( LINK( this, SvxPersonalizationTabPage, SelectPersona ) ); } @@ -245,6 +248,16 @@ IMPL_LINK( SvxPersonalizationTabPage, SelectPersona, PushButton*, /*pButton*/ ) return 0; } +IMPL_LINK( SvxPersonalizationTabPage, ForceSelect, RadioButton*, pButton ) +{ + if ( pButton == m_pOwnBackground && m_aBackgroundURL.isEmpty() ) + SelectBackground( m_pSelectBackground ); + else if ( pButton == m_pOwnPersona && m_aPersonaSettings.isEmpty() ) + SelectPersona( m_pSelectPersona ); + + return 0; +} + /// Find the value on the Persona page, and convert it to a usable form. static OUString searchValue( const OString &rBuffer, sal_Int32 from, const OString &rIdentifier ) { diff --git a/cui/source/options/personalization.hxx b/cui/source/options/personalization.hxx index 499a0a0..c3ff06e 100644 --- a/cui/source/options/personalization.hxx +++ b/cui/source/options/personalization.hxx @@ -50,6 +50,9 @@ private: /// Handle the Persona selection DECL_LINK( SelectPersona, PushButton* ); + /// When 'own' is chosen, but the background image or Persona is not chosen yet. + DECL_LINK( ForceSelect, RadioButton* ); + /// Download the bitmaps + color settings, and copy them to user's profile. bool CopyPersonaToGallery( const OUString &rURL ); }; commit 4774eff21caa200fff6ffc03c9f7304d49c1d6e7 Author: Jan Holesovsky <[email protected]> Date: Thu Dec 6 08:04:48 2012 +0100 Personas: Read the info from the Persona page, and store it. Copies the bitmaps to user/gallery/personas/ in user's profile too. Change-Id: Ibb673320042633850df8bb7a6a849be2c3fc13b8 diff --git a/cui/source/options/personalization.cxx b/cui/source/options/personalization.cxx index c0d788c..33fb11d 100644 --- a/cui/source/options/personalization.cxx +++ b/cui/source/options/personalization.cxx @@ -11,12 +11,16 @@ #include <comphelper/processfactory.hxx> #include <officecfg/Office/Common.hxx> +#include <osl/file.hxx> +#include <rtl/bootstrap.hxx> +#include <tools/urlobj.hxx> #include <vcl/edit.hxx> #include <vcl/msgbox.hxx> #include <com/sun/star/lang/XMultiServiceFactory.hpp> #include <com/sun/star/system/SystemShellExecute.hpp> #include <com/sun/star/system/SystemShellExecuteFlags.hpp> +#include <com/sun/star/ucb/SimpleFileAccess.hpp> #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp> #include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp> #include <com/sun/star/ui/dialogs/XFilePicker.hpp> @@ -61,8 +65,11 @@ OUString SelectPersonaDialog::GetPersonaURL() const { OUString aText( m_pEdit->GetText() ); - if ( !aText.startsWith( "http://www.getpersonas.com/" ) ) + if ( !aText.startsWith( "http://www.getpersonas.com/" ) && + !aText.startsWith( "https://www.getpersonas.com/" ) ) + { return OUString(); + } return aText; } @@ -128,7 +135,8 @@ sal_Bool SvxPersonalizationTabPage::FillItemSet( SfxItemSet & ) if ( xContext.is() && ( aBackground != officecfg::Office::Common::Misc::BackgroundImage::get( xContext ) || m_aBackgroundURL != officecfg::Office::Common::Misc::BackgroundImageURL::get( xContext ) || - aPersona != officecfg::Office::Common::Misc::Persona::get( xContext ) ) ) + aPersona != officecfg::Office::Common::Misc::Persona::get( xContext ) || + m_aPersonaSettings != officecfg::Office::Common::Misc::PersonaSettings::get( xContext ) ) ) { bModified = true; } @@ -139,6 +147,7 @@ sal_Bool SvxPersonalizationTabPage::FillItemSet( SfxItemSet & ) officecfg::Office::Common::Misc::BackgroundImage::set( aBackground, batch ); officecfg::Office::Common::Misc::BackgroundImageURL::set( m_aBackgroundURL, batch ); officecfg::Office::Common::Misc::Persona::set( aPersona, batch ); + officecfg::Office::Common::Misc::PersonaSettings::set( m_aPersonaSettings, batch ); batch->commit(); @@ -167,7 +176,10 @@ void SvxPersonalizationTabPage::Reset( const SfxItemSet & ) // persona OUString aPersona( "default" ); if ( xContext.is() ) + { aPersona = officecfg::Office::Common::Misc::Persona::get( xContext ); + m_aPersonaSettings = officecfg::Office::Common::Misc::PersonaSettings::get( xContext ); + } if ( aPersona == "no" ) m_pNoPersona->Check(); @@ -223,8 +235,8 @@ IMPL_LINK( SvxPersonalizationTabPage, SelectPersona, PushButton*, /*pButton*/ ) OUString aURL( aDialog.GetPersonaURL() ); if ( aURL != "" ) { - // TODO parse the results - m_pOwnPersona->Check(); + if ( CopyPersonaToGallery( aURL ) ) + m_pOwnPersona->Check(); break; } // else TODO msgbox that the URL did not match @@ -233,4 +245,107 @@ IMPL_LINK( SvxPersonalizationTabPage, SelectPersona, PushButton*, /*pButton*/ ) return 0; } +/// Find the value on the Persona page, and convert it to a usable form. +static OUString searchValue( const OString &rBuffer, sal_Int32 from, const OString &rIdentifier ) +{ + sal_Int32 where = rBuffer.indexOf( rIdentifier, from ); + if ( where < 0 ) + return OUString(); + + where += rIdentifier.getLength(); + + sal_Int32 end = rBuffer.indexOf( """, where ); + if ( end < 0 ) + return OUString(); + + OString aOString( rBuffer.copy( where, end - where ) ); + OUString aString( aOString.getStr(), aOString.getLength(), RTL_TEXTENCODING_UTF8, OSTRING_TO_OUSTRING_CVTFLAGS ); + + return aString.replaceAll( "\\/", "/" ); +} + +/// Parse the Persona web page, and find where to get the bitmaps + the color values. +static bool parsePersonaInfo( const OString &rBuffer, OUString *pHeaderURL, OUString *pFooterURL, OUString *pTextColor, OUString *pAccentColor ) +{ + // it is the first attribute that contains "persona=" + sal_Int32 persona = rBuffer.indexOf( "persona=\"{" ); + if ( persona < 0 ) + return false; + + // now search inside + *pHeaderURL = searchValue( rBuffer, persona, ""headerURL":"" ); + if ( pHeaderURL->isEmpty() ) + return false; + + *pFooterURL = searchValue( rBuffer, persona, ""footerURL":"" ); + if ( pFooterURL->isEmpty() ) + return false; + + *pTextColor = searchValue( rBuffer, persona, ""textcolor":"" ); + if ( pTextColor->isEmpty() ) + return false; + + *pAccentColor = searchValue( rBuffer, persona, ""accentcolor":"" ); + if ( pAccentColor->isEmpty() ) + return false; + + return true; +} + +bool SvxPersonalizationTabPage::CopyPersonaToGallery( const OUString &rURL ) +{ + // init the input stream + uno::Reference< ucb::XSimpleFileAccess3 > xFileAccess( ucb::SimpleFileAccess::create( comphelper::getProcessComponentContext() ), uno::UNO_QUERY ); + if ( !xFileAccess.is() ) + return false; + + uno::Reference< io::XInputStream > xStream( xFileAccess->openFileRead( rURL ), uno::UNO_QUERY ); + if ( !xStream.is() ) + 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; + + if ( !parsePersonaInfo( aBuffer.makeStringAndClear(), &aHeaderURL, &aFooterURL, &aTextColor, &aAccentColor ) ) + return false; + + // copy the images to the user's gallery + OUString gallery = "${$BRAND_BASE_DIR/program/" SAL_CONFIGFILE( "bootstrap") "::UserInstallation}"; + rtl::Bootstrap::expandMacros( gallery ); + gallery += "/user/gallery/personas/"; + osl::Directory::createPath( gallery ); + + OUString aHeaderFile( INetURLObject( aHeaderURL ).getName() ); + OUString aFooterFile( INetURLObject( aFooterURL ).getName() ); + + try { + xFileAccess->copy( aHeaderURL, gallery + aHeaderFile ); + xFileAccess->copy( aFooterURL, gallery + aFooterFile ); + } + catch ( const uno::Exception & ) + { + return false; + } + + m_aPersonaSettings = aHeaderFile + ";" + aFooterFile + ";" + 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 bb70b33..499a0a0 100644 --- a/cui/source/options/personalization.hxx +++ b/cui/source/options/personalization.hxx @@ -7,8 +7,8 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#ifndef SVX_PERSONALIZATION_HXX -#define SVX_PERSONALIZATION_HXX +#ifndef CUI_PERSONALIZATION_HXX +#define CUI_PERSONALIZATION_HXX #include <sfx2/tabdlg.hxx> @@ -29,6 +29,7 @@ private: RadioButton *m_pDefaultPersona; ///< Use the built-in bitmap RadioButton *m_pOwnPersona; ///< Use the user-defined bitmap PushButton *m_pSelectPersona; ///< Let the user select in the 'own' case + OUString m_aPersonaSettings; ///< Header and footer images + color to be set in the settings. public: SvxPersonalizationTabPage( Window *pParent, const SfxItemSet &rSet ); @@ -48,8 +49,11 @@ private: /// Handle the Persona selection DECL_LINK( SelectPersona, PushButton* ); + + /// Download the bitmaps + color settings, and copy them to user's profile. + bool CopyPersonaToGallery( const OUString &rURL ); }; -#endif // SVX_PERSONALIZATION_HXX +#endif // CUI_PERSONALIZATION_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/officecfg/registry/schema/org/openoffice/Office/Common.xcs b/officecfg/registry/schema/org/openoffice/Office/Common.xcs index 3910287..df1f534 100644 --- a/officecfg/registry/schema/org/openoffice/Office/Common.xcs +++ b/officecfg/registry/schema/org/openoffice/Office/Common.xcs @@ -6734,6 +6734,16 @@ </constraints> <value>default</value> </prop> + <prop oor:name="PersonaSettings" oor:type="xs:string" oor:nillable="false"> + <!-- UIHints: Tools Options General Personalization --> + <info> + <author>kendy</author> + <desc>Names of the header and footer images, and colors for text and + accent. When set, the value has form + "header.jpg;footer.jpg;#RGBTXT;#RGBACC".</desc> + </info> + <value></value> + </prop> <prop oor:name="ToolboxStyle" oor:type="xs:short" oor:nillable="false"> <!-- UIHints: Tools Options General View --> <info> _______________________________________________ Libreoffice-commits mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
