2012-11-29 13:05:39 +01:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "personalization.hxx"
|
|
|
|
|
2012-12-03 14:43:43 +01:00
|
|
|
#include <comphelper/processfactory.hxx>
|
|
|
|
#include <officecfg/Office/Common.hxx>
|
|
|
|
#include <vcl/msgbox.hxx>
|
|
|
|
|
2012-12-04 00:16:18 +01:00
|
|
|
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
|
2012-12-04 00:33:12 +01:00
|
|
|
#include <com/sun/star/system/SystemShellExecute.hpp>
|
|
|
|
#include <com/sun/star/system/SystemShellExecuteFlags.hpp>
|
2012-12-04 00:16:18 +01:00
|
|
|
#include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
|
|
|
|
#include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
|
|
|
|
#include <com/sun/star/ui/dialogs/XFilePicker.hpp>
|
|
|
|
#include <com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp>
|
|
|
|
#include <com/sun/star/ui/dialogs/XFilterManager.hpp>
|
|
|
|
|
2012-12-03 14:43:43 +01:00
|
|
|
using namespace com::sun::star;
|
|
|
|
|
2012-11-30 10:37:34 +01:00
|
|
|
/** 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
|
|
|
|
http://www.getpersona.com ...
|
|
|
|
*/
|
|
|
|
class SelectPersonaDialog : public ModalDialog
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
SelectPersonaDialog( Window *pParent );
|
2012-12-04 00:33:12 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
/// Handle the [Visit Firefox Personas] button
|
|
|
|
DECL_LINK( VisitPersonas, PushButton* );
|
2012-11-30 10:37:34 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
SelectPersonaDialog::SelectPersonaDialog( Window *pParent )
|
|
|
|
: ModalDialog( pParent, "SelectPersonaDialog", "cui/ui/select_persona_dialog.ui" )
|
|
|
|
{
|
2012-12-04 00:33:12 +01:00
|
|
|
PushButton *pButton;
|
|
|
|
get( pButton, "visit_personas" );
|
|
|
|
pButton->SetClickHdl( LINK( this, SelectPersonaDialog, VisitPersonas ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
IMPL_LINK( SelectPersonaDialog, VisitPersonas, PushButton*, /*pButton*/ )
|
|
|
|
{
|
|
|
|
uno::Reference< system::XSystemShellExecute > xSystemShell( system::SystemShellExecute::create( ::comphelper::getProcessComponentContext() ) );
|
|
|
|
|
|
|
|
xSystemShell->execute( "http://www.getpersonas.com", OUString(), system::SystemShellExecuteFlags::URIS_ONLY );
|
|
|
|
|
|
|
|
return 0;
|
2012-11-30 10:37:34 +01:00
|
|
|
}
|
2012-11-29 13:05:39 +01:00
|
|
|
|
|
|
|
SvxPersonalizationTabPage::SvxPersonalizationTabPage( Window *pParent, const SfxItemSet &rSet )
|
2012-12-03 14:43:43 +01:00
|
|
|
: SfxTabPage( pParent, "PersonalizationTabPage", "cui/ui/personalization_tab.ui", rSet ),
|
|
|
|
m_aBackgroundURL()
|
2012-11-29 13:05:39 +01:00
|
|
|
{
|
2012-12-03 14:43:43 +01:00
|
|
|
// background image
|
2012-11-30 09:44:17 +01:00
|
|
|
get( m_pNoBackground, "no_background" );
|
|
|
|
get( m_pDefaultBackground, "default_background" );
|
|
|
|
get( m_pOwnBackground, "own_background" );
|
|
|
|
|
|
|
|
get( m_pSelectBackground, "select_background" );
|
|
|
|
m_pSelectBackground->SetClickHdl( LINK( this, SvxPersonalizationTabPage, SelectBackground ) );
|
|
|
|
|
2012-12-03 14:43:43 +01:00
|
|
|
// persona
|
2012-11-29 13:05:39 +01:00
|
|
|
get( m_pNoPersona, "no_persona" );
|
2012-11-30 09:44:17 +01:00
|
|
|
get( m_pDefaultPersona, "default_persona" );
|
|
|
|
get( m_pOwnPersona, "own_persona" );
|
|
|
|
|
|
|
|
get( m_pSelectPersona, "select_persona" );
|
|
|
|
LINK( this, SvxPersonalizationTabPage, SelectPersona );
|
|
|
|
m_pSelectPersona->SetClickHdl( LINK( this, SvxPersonalizationTabPage, SelectPersona ) );
|
2012-11-29 13:05:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
SvxPersonalizationTabPage::~SvxPersonalizationTabPage()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
SfxTabPage* SvxPersonalizationTabPage::Create( Window *pParent, const SfxItemSet &rSet )
|
|
|
|
{
|
|
|
|
return new SvxPersonalizationTabPage( pParent, rSet );
|
|
|
|
}
|
|
|
|
|
2012-12-03 14:43:43 +01:00
|
|
|
sal_Bool SvxPersonalizationTabPage::FillItemSet( SfxItemSet & )
|
2012-11-30 09:44:17 +01:00
|
|
|
{
|
2012-12-03 14:43:43 +01:00
|
|
|
// 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 ) ) )
|
2012-11-30 09:44:17 +01:00
|
|
|
{
|
2012-12-03 14:43:43 +01:00
|
|
|
bModified = true;
|
2012-11-30 09:44:17 +01:00
|
|
|
}
|
2012-12-03 14:43:43 +01:00
|
|
|
|
|
|
|
// 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() )
|
2012-11-30 09:44:17 +01:00
|
|
|
{
|
2012-12-03 14:43:43 +01:00
|
|
|
aBackground = officecfg::Office::Common::Misc::BackgroundImage::get( xContext );
|
|
|
|
m_aBackgroundURL = officecfg::Office::Common::Misc::BackgroundImageURL::get( xContext );
|
2012-11-30 09:44:17 +01:00
|
|
|
}
|
2012-12-03 14:43:43 +01:00
|
|
|
|
|
|
|
if ( aBackground == "no" )
|
|
|
|
m_pNoBackground->Check();
|
|
|
|
else if ( aBackground == "own" )
|
|
|
|
m_pOwnBackground->Check();
|
2012-11-30 09:44:17 +01:00
|
|
|
else
|
2012-12-03 14:43:43 +01:00
|
|
|
m_pDefaultBackground->Check();
|
2012-11-30 09:44:17 +01:00
|
|
|
|
2012-12-03 14:43:43 +01:00
|
|
|
// persona
|
|
|
|
OUString aPersona( "default" );
|
|
|
|
if ( xContext.is() )
|
|
|
|
aPersona = officecfg::Office::Common::Misc::Persona::get( xContext );
|
2012-11-30 09:44:17 +01:00
|
|
|
|
2012-12-03 14:43:43 +01:00
|
|
|
if ( aPersona == "no" )
|
|
|
|
m_pNoPersona->Check();
|
|
|
|
else if ( aPersona == "own" )
|
|
|
|
m_pOwnPersona->Check();
|
|
|
|
else
|
|
|
|
m_pDefaultPersona->Check();
|
2012-11-30 09:44:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
IMPL_LINK( SvxPersonalizationTabPage, SelectBackground, PushButton*, /*pButton*/ )
|
|
|
|
{
|
2012-12-04 00:16:18 +01:00
|
|
|
uno::Reference< lang::XMultiServiceFactory > xFactory( ::comphelper::getProcessServiceFactory() );
|
|
|
|
if ( !xFactory.is() )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
uno::Reference< ui::dialogs::XFilePicker > xFilePicker( xFactory->createInstance( "com.sun.star.ui.dialogs.FilePicker" ), uno::UNO_QUERY );
|
|
|
|
if ( !xFilePicker.is() )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
xFilePicker->setMultiSelectionMode( false );
|
|
|
|
|
|
|
|
uno::Reference< ui::dialogs::XFilePickerControlAccess > xController( xFilePicker, uno::UNO_QUERY );
|
|
|
|
if ( xController.is() )
|
|
|
|
xController->setValue( ui::dialogs::ExtendedFilePickerElementIds::CHECKBOX_PREVIEW, 0, uno::makeAny( sal_True ) );
|
|
|
|
|
|
|
|
uno::Reference< ui::dialogs::XFilterManager > xFilterMgr( xFilePicker, uno::UNO_QUERY );
|
|
|
|
if ( xFilterMgr.is() )
|
|
|
|
xFilterMgr->appendFilter( "Background images (*.jpg;*.png)", "*.jpg;*.png" ); // TODO localize
|
|
|
|
|
|
|
|
while ( xFilePicker->execute() == ui::dialogs::ExecutableDialogResults::OK )
|
|
|
|
{
|
|
|
|
OUString aFile( xFilePicker->getFiles()[0] );
|
|
|
|
|
|
|
|
if ( aFile.startsWith( "file:///" ) && ( aFile.endsWith( ".png" ) || aFile.endsWith( ".jpg" ) ) )
|
|
|
|
{
|
|
|
|
m_aBackgroundURL = aFile;
|
|
|
|
m_pOwnBackground->Check();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO display what is wrong (not a file:// or not .png / .jpg)
|
|
|
|
}
|
2012-12-03 14:43:43 +01:00
|
|
|
|
2012-11-30 09:44:17 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
IMPL_LINK( SvxPersonalizationTabPage, SelectPersona, PushButton*, /*pButton*/ )
|
|
|
|
{
|
2012-11-30 10:37:34 +01:00
|
|
|
SelectPersonaDialog aDialog( NULL );
|
2012-12-03 14:43:43 +01:00
|
|
|
|
|
|
|
if ( aDialog.Execute() == RET_OK )
|
|
|
|
{
|
|
|
|
m_pOwnPersona->Check();
|
|
|
|
// TODO parse the results
|
|
|
|
}
|
2012-11-30 10:37:34 +01:00
|
|
|
|
2012-11-30 09:44:17 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-11-29 13:05:39 +01:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|