From 2437cf972a9dbf7ab11e18e7fd8b43ef5f6a63e0 Mon Sep 17 00:00:00 2001 From: Jan Holesovsky Date: Mon, 3 Dec 2012 14:43:43 +0100 Subject: Personas: Configuration entries for Personas and BacgroundImage. Change-Id: I47b1a5bacaeb5bd54f11630e5d3f2652be2bdfb4 --- cui/source/options/personalization.cxx | 109 ++++++++++++++++++++++++--------- cui/source/options/personalization.hxx | 10 ++- 2 files changed, 86 insertions(+), 33 deletions(-) (limited to 'cui/source') diff --git a/cui/source/options/personalization.cxx b/cui/source/options/personalization.cxx index e6d6a395ceb3..1bfe549c2be8 100644 --- a/cui/source/options/personalization.cxx +++ b/cui/source/options/personalization.cxx @@ -9,6 +9,12 @@ #include "personalization.hxx" +#include +#include +#include + +using namespace com::sun::star; + /** Dialog that will allow the user to choose a Persona to use. So far there is no better possibility than just to paste the URL from @@ -26,24 +32,21 @@ SelectPersonaDialog::SelectPersonaDialog( Window *pParent ) } SvxPersonalizationTabPage::SvxPersonalizationTabPage( Window *pParent, const SfxItemSet &rSet ) - : SfxTabPage( pParent, "PersonalizationTabPage", "cui/ui/personalization_tab.ui", rSet ) + : SfxTabPage( pParent, "PersonalizationTabPage", "cui/ui/personalization_tab.ui", rSet ), + m_aBackgroundURL() { + // background image get( m_pNoBackground, "no_background" ); get( m_pDefaultBackground, "default_background" ); get( m_pOwnBackground, "own_background" ); - m_pNoBackground->SetClickHdl( LINK( this, SvxPersonalizationTabPage, EnableDisableSelectionButtons ) ); - m_pDefaultBackground->SetClickHdl( LINK( this, SvxPersonalizationTabPage, EnableDisableSelectionButtons ) ); - m_pOwnBackground->SetClickHdl( LINK( this, SvxPersonalizationTabPage, EnableDisableSelectionButtons ) ); get( m_pSelectBackground, "select_background" ); m_pSelectBackground->SetClickHdl( LINK( this, SvxPersonalizationTabPage, SelectBackground ) ); + // persona get( m_pNoPersona, "no_persona" ); get( m_pDefaultPersona, "default_persona" ); get( m_pOwnPersona, "own_persona" ); - m_pNoPersona->SetClickHdl( LINK( this, SvxPersonalizationTabPage, EnableDisableSelectionButtons ) ); - m_pDefaultPersona->SetClickHdl( LINK( this, SvxPersonalizationTabPage, EnableDisableSelectionButtons ) ); - m_pOwnPersona->SetClickHdl( LINK( this, SvxPersonalizationTabPage, EnableDisableSelectionButtons ) ); get( m_pSelectPersona, "select_persona" ); LINK( this, SvxPersonalizationTabPage, SelectPersona ); @@ -59,47 +62,93 @@ SfxTabPage* SvxPersonalizationTabPage::Create( Window *pParent, const SfxItemSet return new SvxPersonalizationTabPage( pParent, rSet ); } -IMPL_LINK( SvxPersonalizationTabPage, EnableDisableSelectionButtons, RadioButton*, pButton ) +sal_Bool SvxPersonalizationTabPage::FillItemSet( SfxItemSet & ) { - PushButton *pPushButton = NULL; - RadioButton *pRadioButton = NULL; - - if ( pButton == m_pNoBackground || pButton == m_pDefaultBackground || pButton == m_pOwnBackground ) + // background image + OUString aBackground( "default" ); + if ( m_pNoBackground->IsChecked() ) + aBackground = "no"; + else if ( m_pOwnBackground->IsChecked() ) + aBackground = "own"; + + // persona + OUString aPersona( "default" ); + if ( m_pNoPersona->IsChecked() ) + aPersona = "no"; + else if ( m_pOwnPersona->IsChecked() ) + aPersona = "own"; + + bool bModified = false; + uno::Reference< uno::XComponentContext > xContext = comphelper::getProcessComponentContext(); + 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 ) ) ) { - pPushButton = m_pSelectBackground; - pRadioButton = m_pOwnBackground; + bModified = true; } - else if ( pButton == m_pNoPersona || pButton == m_pDefaultPersona || pButton == m_pOwnPersona ) + + // write + boost::shared_ptr< comphelper::ConfigurationChanges > batch( comphelper::ConfigurationChanges::create() ); + + 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 ); + + batch->commit(); + + return bModified; +} + +void SvxPersonalizationTabPage::Reset( const SfxItemSet & ) +{ + uno::Reference< uno::XComponentContext > xContext = comphelper::getProcessComponentContext(); + + // background image + OUString aBackground( "default" ); + if ( xContext.is() ) { - pPushButton = m_pSelectPersona; - pRadioButton = m_pOwnPersona; + aBackground = officecfg::Office::Common::Misc::BackgroundImage::get( xContext ); + m_aBackgroundURL = officecfg::Office::Common::Misc::BackgroundImageURL::get( xContext ); } + + if ( aBackground == "no" ) + m_pNoBackground->Check(); + else if ( aBackground == "own" ) + m_pOwnBackground->Check(); else - return 0; + m_pDefaultBackground->Check(); - if ( pRadioButton->IsChecked() && !pPushButton->IsEnabled() ) - { - pPushButton->Enable(); - pPushButton->Invalidate(); - } - else if ( !pRadioButton->IsChecked() && pPushButton->IsEnabled() ) - { - pPushButton->Disable(); - pPushButton->Invalidate(); - } + // persona + OUString aPersona( "default" ); + if ( xContext.is() ) + aPersona = officecfg::Office::Common::Misc::Persona::get( xContext ); - return 0; + if ( aPersona == "no" ) + m_pNoPersona->Check(); + else if ( aPersona == "own" ) + m_pOwnPersona->Check(); + else + m_pDefaultPersona->Check(); } IMPL_LINK( SvxPersonalizationTabPage, SelectBackground, PushButton*, /*pButton*/ ) { + // TODO m_pOwnBackground->Check(); if something selected + // TODO parse the results + return 0; } IMPL_LINK( SvxPersonalizationTabPage, SelectPersona, PushButton*, /*pButton*/ ) { SelectPersonaDialog aDialog( NULL ); - /* TODO handle the ret val sal_Int16 nReturn =*/ aDialog.Execute(); + + if ( aDialog.Execute() == RET_OK ) + { + m_pOwnPersona->Check(); + // TODO parse the results + } return 0; } diff --git a/cui/source/options/personalization.hxx b/cui/source/options/personalization.hxx index 89fc3fde28a0..bb70b33e1bb4 100644 --- a/cui/source/options/personalization.hxx +++ b/cui/source/options/personalization.hxx @@ -23,6 +23,7 @@ private: RadioButton *m_pDefaultBackground; ///< Use the built-in bitmap for Writer background RadioButton *m_pOwnBackground; ///< Use the user-defined bitmap PushButton *m_pSelectBackground; ///< Let the user select in the 'own' case + OUString m_aBackgroundURL; ///< URL of the the background image in the 'own' case RadioButton *m_pNoPersona; ///< Just the default look, without any bitmap RadioButton *m_pDefaultPersona; ///< Use the built-in bitmap @@ -35,10 +36,13 @@ public: static SfxTabPage* Create( Window *pParent, const SfxItemSet &rSet ); -private: - /// Maintain sane behavior of the m_pSelect(Background|Persona) buttons - DECL_LINK( EnableDisableSelectionButtons, RadioButton* ); + /// Apply the settings ([OK] button). + virtual sal_Bool FillItemSet( SfxItemSet &rSet ); + + /// Reset to default settings ([Revert] button). + virtual void Reset( const SfxItemSet &rSet ); +private: /// Handle the bacground selection DECL_LINK( SelectBackground, PushButton* ); -- cgit v1.2.3