Kaydet (Commit) 4774eff2 authored tarafından Jan Holesovsky's avatar Jan Holesovsky

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
üst f1fee2a6
...@@ -11,12 +11,16 @@ ...@@ -11,12 +11,16 @@
#include <comphelper/processfactory.hxx> #include <comphelper/processfactory.hxx>
#include <officecfg/Office/Common.hxx> #include <officecfg/Office/Common.hxx>
#include <osl/file.hxx>
#include <rtl/bootstrap.hxx>
#include <tools/urlobj.hxx>
#include <vcl/edit.hxx> #include <vcl/edit.hxx>
#include <vcl/msgbox.hxx> #include <vcl/msgbox.hxx>
#include <com/sun/star/lang/XMultiServiceFactory.hpp> #include <com/sun/star/lang/XMultiServiceFactory.hpp>
#include <com/sun/star/system/SystemShellExecute.hpp> #include <com/sun/star/system/SystemShellExecute.hpp>
#include <com/sun/star/system/SystemShellExecuteFlags.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/ExecutableDialogResults.hpp>
#include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp> #include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
#include <com/sun/star/ui/dialogs/XFilePicker.hpp> #include <com/sun/star/ui/dialogs/XFilePicker.hpp>
...@@ -61,8 +65,11 @@ OUString SelectPersonaDialog::GetPersonaURL() const ...@@ -61,8 +65,11 @@ OUString SelectPersonaDialog::GetPersonaURL() const
{ {
OUString aText( m_pEdit->GetText() ); 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 OUString();
}
return aText; return aText;
} }
...@@ -128,7 +135,8 @@ sal_Bool SvxPersonalizationTabPage::FillItemSet( SfxItemSet & ) ...@@ -128,7 +135,8 @@ sal_Bool SvxPersonalizationTabPage::FillItemSet( SfxItemSet & )
if ( xContext.is() && if ( xContext.is() &&
( aBackground != officecfg::Office::Common::Misc::BackgroundImage::get( xContext ) || ( aBackground != officecfg::Office::Common::Misc::BackgroundImage::get( xContext ) ||
m_aBackgroundURL != officecfg::Office::Common::Misc::BackgroundImageURL::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; bModified = true;
} }
...@@ -139,6 +147,7 @@ sal_Bool SvxPersonalizationTabPage::FillItemSet( SfxItemSet & ) ...@@ -139,6 +147,7 @@ sal_Bool SvxPersonalizationTabPage::FillItemSet( SfxItemSet & )
officecfg::Office::Common::Misc::BackgroundImage::set( aBackground, batch ); officecfg::Office::Common::Misc::BackgroundImage::set( aBackground, batch );
officecfg::Office::Common::Misc::BackgroundImageURL::set( m_aBackgroundURL, batch ); officecfg::Office::Common::Misc::BackgroundImageURL::set( m_aBackgroundURL, batch );
officecfg::Office::Common::Misc::Persona::set( aPersona, batch ); officecfg::Office::Common::Misc::Persona::set( aPersona, batch );
officecfg::Office::Common::Misc::PersonaSettings::set( m_aPersonaSettings, batch );
batch->commit(); batch->commit();
...@@ -167,7 +176,10 @@ void SvxPersonalizationTabPage::Reset( const SfxItemSet & ) ...@@ -167,7 +176,10 @@ void SvxPersonalizationTabPage::Reset( const SfxItemSet & )
// persona // persona
OUString aPersona( "default" ); OUString aPersona( "default" );
if ( xContext.is() ) if ( xContext.is() )
{
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 );
}
if ( aPersona == "no" ) if ( aPersona == "no" )
m_pNoPersona->Check(); m_pNoPersona->Check();
...@@ -223,8 +235,8 @@ IMPL_LINK( SvxPersonalizationTabPage, SelectPersona, PushButton*, /*pButton*/ ) ...@@ -223,8 +235,8 @@ IMPL_LINK( SvxPersonalizationTabPage, SelectPersona, PushButton*, /*pButton*/ )
OUString aURL( aDialog.GetPersonaURL() ); OUString aURL( aDialog.GetPersonaURL() );
if ( aURL != "" ) if ( aURL != "" )
{ {
// TODO parse the results if ( CopyPersonaToGallery( aURL ) )
m_pOwnPersona->Check(); m_pOwnPersona->Check();
break; break;
} }
// else TODO msgbox that the URL did not match // else TODO msgbox that the URL did not match
...@@ -233,4 +245,107 @@ IMPL_LINK( SvxPersonalizationTabPage, SelectPersona, PushButton*, /*pButton*/ ) ...@@ -233,4 +245,107 @@ IMPL_LINK( SvxPersonalizationTabPage, SelectPersona, PushButton*, /*pButton*/ )
return 0; 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( "&quot;", 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, "&quot;headerURL&quot;:&quot;" );
if ( pHeaderURL->isEmpty() )
return false;
*pFooterURL = searchValue( rBuffer, persona, "&quot;footerURL&quot;:&quot;" );
if ( pFooterURL->isEmpty() )
return false;
*pTextColor = searchValue( rBuffer, persona, "&quot;textcolor&quot;:&quot;" );
if ( pTextColor->isEmpty() )
return false;
*pAccentColor = searchValue( rBuffer, persona, "&quot;accentcolor&quot;:&quot;" );
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: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -7,8 +7,8 @@ ...@@ -7,8 +7,8 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/ */
#ifndef SVX_PERSONALIZATION_HXX #ifndef CUI_PERSONALIZATION_HXX
#define SVX_PERSONALIZATION_HXX #define CUI_PERSONALIZATION_HXX
#include <sfx2/tabdlg.hxx> #include <sfx2/tabdlg.hxx>
...@@ -29,6 +29,7 @@ private: ...@@ -29,6 +29,7 @@ private:
RadioButton *m_pDefaultPersona; ///< Use the built-in bitmap RadioButton *m_pDefaultPersona; ///< Use the built-in bitmap
RadioButton *m_pOwnPersona; ///< Use the user-defined bitmap RadioButton *m_pOwnPersona; ///< Use the user-defined bitmap
PushButton *m_pSelectPersona; ///< Let the user select in the 'own' case 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: public:
SvxPersonalizationTabPage( Window *pParent, const SfxItemSet &rSet ); SvxPersonalizationTabPage( Window *pParent, const SfxItemSet &rSet );
...@@ -48,8 +49,11 @@ private: ...@@ -48,8 +49,11 @@ private:
/// Handle the Persona selection /// Handle the Persona selection
DECL_LINK( SelectPersona, PushButton* ); 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: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -6734,6 +6734,16 @@ ...@@ -6734,6 +6734,16 @@
</constraints> </constraints>
<value>default</value> <value>default</value>
</prop> </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"> <prop oor:name="ToolboxStyle" oor:type="xs:short" oor:nillable="false">
<!-- UIHints: Tools Options General View --> <!-- UIHints: Tools Options General View -->
<info> <info>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment