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/.
|
|
|
|
*/
|
|
|
|
|
2013-08-16 11:08:32 +03:00
|
|
|
#include <config_folders.h>
|
|
|
|
|
2012-11-29 13:05:39 +01:00
|
|
|
#include "personalization.hxx"
|
2014-04-29 19:48:48 +05:30
|
|
|
#include "personasdochandler.hxx"
|
2012-11-29 13:05:39 +01:00
|
|
|
|
2012-12-03 14:43:43 +01:00
|
|
|
#include <comphelper/processfactory.hxx>
|
|
|
|
#include <officecfg/Office/Common.hxx>
|
2012-12-06 08:04:48 +01:00
|
|
|
#include <osl/file.hxx>
|
|
|
|
#include <rtl/bootstrap.hxx>
|
|
|
|
#include <tools/urlobj.hxx>
|
2012-12-04 08:49:50 +01:00
|
|
|
#include <vcl/edit.hxx>
|
2012-12-03 14:43:43 +01:00
|
|
|
#include <vcl/msgbox.hxx>
|
2013-01-04 23:43:42 +01:00
|
|
|
#include <vcl/svapp.hxx>
|
2014-01-02 23:52:37 +01:00
|
|
|
#include <vcl/settings.hxx>
|
2014-05-19 19:56:44 +05:30
|
|
|
#include <vcl/graphicfilter.hxx>
|
2012-12-03 14:43:43 +01:00
|
|
|
|
2012-12-06 08:04:48 +01:00
|
|
|
#include <com/sun/star/ucb/SimpleFileAccess.hpp>
|
2014-04-29 19:48:48 +05:30
|
|
|
#include <com/sun/star/xml/sax/XParser.hpp>
|
|
|
|
#include <com/sun/star/xml/sax/Parser.hpp>
|
|
|
|
#include "ucbhelper/content.hxx"
|
2012-12-04 00:16:18 +01:00
|
|
|
|
2012-12-03 14:43:43 +01:00
|
|
|
using namespace com::sun::star;
|
2014-04-29 19:48:48 +05:30
|
|
|
using namespace ::com::sun::star::uno;
|
|
|
|
using namespace ::com::sun::star::ucb;
|
|
|
|
|
2012-11-30 10:37:34 +01:00
|
|
|
SelectPersonaDialog::SelectPersonaDialog( Window *pParent )
|
|
|
|
: ModalDialog( pParent, "SelectPersonaDialog", "cui/ui/select_persona_dialog.ui" )
|
|
|
|
{
|
2014-06-07 13:01:29 +05:30
|
|
|
get( m_pSearchButton, "search_personas" );
|
|
|
|
m_pSearchButton->SetClickHdl( LINK( this, SelectPersonaDialog, SearchPersonas ) );
|
2012-12-04 08:49:50 +01:00
|
|
|
|
2014-05-01 23:55:41 +05:30
|
|
|
get( m_pEdit, "search_term" );
|
|
|
|
m_pEdit->SetPlaceholderText( "Search term..." );
|
2014-05-22 20:48:34 +05:30
|
|
|
|
|
|
|
get( m_pProgressLabel, "progress_label" );
|
|
|
|
|
2014-06-02 23:26:11 +05:30
|
|
|
get(m_vResultList[0], "result1");
|
2014-06-08 20:33:50 +05:30
|
|
|
m_vResultList[0]->SetClickHdl( LINK( this, SelectPersonaDialog, SelectPersona ) );
|
|
|
|
|
2014-06-02 23:26:11 +05:30
|
|
|
get(m_vResultList[1], "result2");
|
2014-06-08 20:33:50 +05:30
|
|
|
m_vResultList[1]->SetClickHdl( LINK( this, SelectPersonaDialog, SelectPersona ) );
|
|
|
|
|
2014-06-02 23:26:11 +05:30
|
|
|
get(m_vResultList[2], "result3");
|
2014-06-08 20:33:50 +05:30
|
|
|
m_vResultList[2]->SetClickHdl( LINK( this, SelectPersonaDialog, SelectPersona ) );
|
|
|
|
|
2014-06-02 23:26:11 +05:30
|
|
|
get(m_vResultList[3], "result4");
|
2014-06-08 20:33:50 +05:30
|
|
|
m_vResultList[3]->SetClickHdl( LINK( this, SelectPersonaDialog, SelectPersona ) );
|
|
|
|
|
2014-06-02 23:26:11 +05:30
|
|
|
get(m_vResultList[4], "result5");
|
2014-06-08 20:33:50 +05:30
|
|
|
m_vResultList[4]->SetClickHdl( LINK( this, SelectPersonaDialog, SelectPersona ) );
|
|
|
|
|
2014-06-02 23:26:11 +05:30
|
|
|
get(m_vResultList[5], "result6");
|
2014-06-08 20:33:50 +05:30
|
|
|
m_vResultList[5]->SetClickHdl( LINK( this, SelectPersonaDialog, SelectPersona ) );
|
|
|
|
|
2014-06-02 23:26:11 +05:30
|
|
|
get(m_vResultList[6], "result7");
|
2014-06-08 20:33:50 +05:30
|
|
|
m_vResultList[6]->SetClickHdl( LINK( this, SelectPersonaDialog, SelectPersona ) );
|
|
|
|
|
2014-06-02 23:26:11 +05:30
|
|
|
get(m_vResultList[7], "result8");
|
2014-06-08 20:33:50 +05:30
|
|
|
m_vResultList[7]->SetClickHdl( LINK( this, SelectPersonaDialog, SelectPersona ) );
|
|
|
|
|
2014-06-02 23:26:11 +05:30
|
|
|
get(m_vResultList[8], "result9");
|
2014-06-08 20:33:50 +05:30
|
|
|
m_vResultList[8]->SetClickHdl( LINK( this, SelectPersonaDialog, SelectPersona ) );
|
2012-12-04 08:49:50 +01:00
|
|
|
}
|
|
|
|
|
2014-06-08 20:33:50 +05:30
|
|
|
OUString SelectPersonaDialog::GetSelectedPersona() const
|
2012-12-04 08:49:50 +01:00
|
|
|
{
|
2014-06-08 20:33:50 +05:30
|
|
|
if( !m_aSelectedPersona.isEmpty( ) )
|
|
|
|
return m_aSelectedPersona;
|
2013-01-04 23:09:18 +01:00
|
|
|
|
2013-04-19 15:56:38 +02:00
|
|
|
return OUString();
|
2012-12-04 00:33:12 +01:00
|
|
|
}
|
|
|
|
|
2014-06-07 13:01:29 +05:30
|
|
|
IMPL_LINK( SelectPersonaDialog, SearchPersonas, PushButton*, /*pButton*/ )
|
2012-12-04 00:33:12 +01:00
|
|
|
{
|
2014-05-01 23:55:41 +05:30
|
|
|
OUString searchTerm = m_pEdit->GetText();
|
2014-06-08 20:33:50 +05:30
|
|
|
if( searchTerm.isEmpty( ) )
|
|
|
|
return 0;
|
|
|
|
|
2014-06-12 17:13:33 +05:30
|
|
|
OUString rSearchURL = "https://addons.allizom.org/en-US/firefox/api/1.5/search/" + searchTerm + "/9/1";
|
|
|
|
m_rSearchThread = new SearchAndParseThread( this, rSearchURL );
|
|
|
|
m_rSearchThread->launch();
|
2012-12-04 00:33:12 +01:00
|
|
|
return 0;
|
2012-11-30 10:37:34 +01:00
|
|
|
}
|
2012-11-29 13:05:39 +01:00
|
|
|
|
2014-06-08 20:33:50 +05:30
|
|
|
IMPL_LINK( SelectPersonaDialog, SelectPersona, PushButton*, pButton )
|
|
|
|
{
|
|
|
|
if( pButton == m_vResultList[0] )
|
|
|
|
{
|
|
|
|
if( !m_vPersonaSettings[0].isEmpty() )
|
|
|
|
m_aSelectedPersona = m_vPersonaSettings[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
else if( pButton == m_vResultList[1] )
|
|
|
|
{
|
|
|
|
if( !m_vPersonaSettings[1].isEmpty() )
|
|
|
|
m_aSelectedPersona = m_vPersonaSettings[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
else if( pButton == m_vResultList[2] )
|
|
|
|
{
|
|
|
|
if( !m_vPersonaSettings[2].isEmpty() )
|
|
|
|
m_aSelectedPersona = m_vPersonaSettings[2];
|
|
|
|
}
|
|
|
|
|
|
|
|
else if( pButton == m_vResultList[3] )
|
|
|
|
{
|
|
|
|
if( !m_vPersonaSettings[3].isEmpty() )
|
|
|
|
m_aSelectedPersona = m_vPersonaSettings[3];
|
|
|
|
}
|
|
|
|
|
|
|
|
else if( pButton == m_vResultList[4] )
|
|
|
|
{
|
|
|
|
if( !m_vPersonaSettings[4].isEmpty() )
|
|
|
|
m_aSelectedPersona = m_vPersonaSettings[4];
|
|
|
|
}
|
|
|
|
|
|
|
|
else if( pButton == m_vResultList[5] )
|
|
|
|
{
|
|
|
|
if( !m_vPersonaSettings[5].isEmpty() )
|
|
|
|
m_aSelectedPersona = m_vPersonaSettings[5];
|
|
|
|
}
|
|
|
|
|
|
|
|
else if( pButton == m_vResultList[6] )
|
|
|
|
{
|
|
|
|
if( !m_vPersonaSettings[6].isEmpty() )
|
|
|
|
m_aSelectedPersona = m_vPersonaSettings[6];
|
|
|
|
}
|
|
|
|
|
|
|
|
else if( pButton == m_vResultList[7] )
|
|
|
|
{
|
|
|
|
if( !m_vPersonaSettings[7].isEmpty() )
|
|
|
|
m_aSelectedPersona = m_vPersonaSettings[7];
|
|
|
|
}
|
|
|
|
|
|
|
|
else if( pButton == m_vResultList[8] )
|
|
|
|
{
|
|
|
|
if( !m_vPersonaSettings[8].isEmpty() )
|
|
|
|
m_aSelectedPersona = m_vPersonaSettings[8];
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-05-22 20:48:34 +05:30
|
|
|
void SelectPersonaDialog::SetProgress( OUString& rProgress )
|
|
|
|
{
|
|
|
|
if(rProgress.isEmpty())
|
|
|
|
m_pProgressLabel->Hide();
|
|
|
|
else
|
2014-06-13 11:34:59 +05:30
|
|
|
{
|
|
|
|
SolarMutexGuard aGuard;
|
|
|
|
m_pProgressLabel->Show();
|
2014-05-22 20:48:34 +05:30
|
|
|
m_pProgressLabel->SetText( rProgress );
|
2014-06-13 11:34:59 +05:30
|
|
|
setOptimalLayoutSize();
|
|
|
|
}
|
2014-05-22 20:48:34 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
void SelectPersonaDialog::SetImages( std::vector<Image> &rImageList )
|
|
|
|
{
|
|
|
|
sal_Int32 nCount = 0;
|
|
|
|
for( std::vector<Image>::iterator it=rImageList.begin(); it!=rImageList.end(); ++it )
|
|
|
|
{
|
2014-06-02 23:26:11 +05:30
|
|
|
m_vResultList[nCount]->Show();
|
|
|
|
m_vResultList[nCount]->SetModeImage( *it );
|
|
|
|
nCount++;
|
2014-05-22 20:48:34 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-08 20:33:50 +05:30
|
|
|
void SelectPersonaDialog::AddPersonaSetting( OUString& rPersonaSetting )
|
|
|
|
{
|
|
|
|
m_vPersonaSettings.push_back( rPersonaSetting );
|
|
|
|
}
|
|
|
|
|
2014-06-13 13:42:25 +05:30
|
|
|
void SelectPersonaDialog::ClearSearchResults()
|
|
|
|
{
|
|
|
|
m_vPersonaSettings.clear();
|
|
|
|
m_aSelectedPersona = "";
|
|
|
|
}
|
|
|
|
|
2012-11-29 13:05:39 +01:00
|
|
|
SvxPersonalizationTabPage::SvxPersonalizationTabPage( Window *pParent, const SfxItemSet &rSet )
|
2014-06-11 14:34:46 +02:00
|
|
|
: SfxTabPage( pParent, "PersonalizationTabPage", "cui/ui/personalization_tab.ui", &rSet )
|
2012-11-29 13:05:39 +01:00
|
|
|
{
|
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" );
|
2012-12-06 08:29:02 +01:00
|
|
|
|
2012-11-30 09:44:17 +01:00
|
|
|
get( m_pOwnPersona, "own_persona" );
|
2012-12-06 08:29:02 +01:00
|
|
|
m_pOwnPersona->SetClickHdl( LINK( this, SvxPersonalizationTabPage, ForceSelect ) );
|
2012-11-30 09:44:17 +01:00
|
|
|
|
|
|
|
get( m_pSelectPersona, "select_persona" );
|
|
|
|
m_pSelectPersona->SetClickHdl( LINK( this, SvxPersonalizationTabPage, SelectPersona ) );
|
2012-11-29 13:05:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
SvxPersonalizationTabPage::~SvxPersonalizationTabPage()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-06-11 14:34:46 +02:00
|
|
|
SfxTabPage* SvxPersonalizationTabPage::Create( Window *pParent, const SfxItemSet *rSet )
|
2012-11-29 13:05:39 +01:00
|
|
|
{
|
2014-06-11 14:34:46 +02:00
|
|
|
return new SvxPersonalizationTabPage( pParent, *rSet );
|
2012-11-29 13:05:39 +01:00
|
|
|
}
|
|
|
|
|
2014-06-10 17:23:12 +02:00
|
|
|
bool SvxPersonalizationTabPage::FillItemSet( SfxItemSet * )
|
2012-11-30 09:44:17 +01:00
|
|
|
{
|
2012-12-03 14:43:43 +01:00
|
|
|
// persona
|
|
|
|
OUString aPersona( "default" );
|
|
|
|
if ( m_pNoPersona->IsChecked() )
|
|
|
|
aPersona = "no";
|
|
|
|
else if ( m_pOwnPersona->IsChecked() )
|
|
|
|
aPersona = "own";
|
|
|
|
|
|
|
|
bool bModified = false;
|
2013-01-01 22:30:18 +01:00
|
|
|
uno::Reference< uno::XComponentContext > xContext( comphelper::getProcessComponentContext() );
|
2012-12-03 14:43:43 +01:00
|
|
|
if ( xContext.is() &&
|
2013-05-10 10:47:53 +02:00
|
|
|
( aPersona != officecfg::Office::Common::Misc::Persona::get( xContext ) ||
|
2012-12-06 08:04:48 +01:00
|
|
|
m_aPersonaSettings != officecfg::Office::Common::Misc::PersonaSettings::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::Persona::set( aPersona, batch );
|
2012-12-06 08:04:48 +01:00
|
|
|
officecfg::Office::Common::Misc::PersonaSettings::set( m_aPersonaSettings, batch );
|
2012-12-03 14:43:43 +01:00
|
|
|
batch->commit();
|
|
|
|
|
2013-01-04 23:43:42 +01:00
|
|
|
if ( bModified )
|
|
|
|
{
|
|
|
|
// broadcast the change
|
|
|
|
DataChangedEvent aDataChanged( DATACHANGED_SETTINGS, NULL, SETTINGS_STYLE );
|
|
|
|
Application::NotifyAllWindows( aDataChanged );
|
|
|
|
}
|
|
|
|
|
2012-12-03 14:43:43 +01:00
|
|
|
return bModified;
|
|
|
|
}
|
|
|
|
|
2014-06-11 10:35:24 +02:00
|
|
|
void SvxPersonalizationTabPage::Reset( const SfxItemSet * )
|
2012-12-03 14:43:43 +01:00
|
|
|
{
|
2013-01-01 22:30:18 +01:00
|
|
|
uno::Reference< uno::XComponentContext > xContext( comphelper::getProcessComponentContext() );
|
2012-12-03 14:43:43 +01:00
|
|
|
|
|
|
|
// persona
|
|
|
|
OUString aPersona( "default" );
|
|
|
|
if ( xContext.is() )
|
2012-12-06 08:04:48 +01:00
|
|
|
{
|
2012-12-03 14:43:43 +01:00
|
|
|
aPersona = officecfg::Office::Common::Misc::Persona::get( xContext );
|
2012-12-06 08:04:48 +01:00
|
|
|
m_aPersonaSettings = officecfg::Office::Common::Misc::PersonaSettings::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, SelectPersona, PushButton*, /*pButton*/ )
|
|
|
|
{
|
2012-11-30 10:37:34 +01:00
|
|
|
SelectPersonaDialog aDialog( NULL );
|
2012-12-03 14:43:43 +01:00
|
|
|
|
2012-12-04 08:49:50 +01:00
|
|
|
while ( aDialog.Execute() == RET_OK )
|
2012-12-03 14:43:43 +01:00
|
|
|
{
|
2014-06-08 20:33:50 +05:30
|
|
|
OUString aURL( aDialog.GetSelectedPersona() );
|
2013-01-04 23:09:18 +01:00
|
|
|
if ( !aURL.isEmpty() )
|
2012-12-04 08:49:50 +01:00
|
|
|
{
|
2014-06-12 17:13:33 +05:30
|
|
|
CopyPersonaToGallery( aURL );
|
2012-12-04 08:49:50 +01:00
|
|
|
break;
|
|
|
|
}
|
2012-12-03 14:43:43 +01:00
|
|
|
}
|
2012-11-30 10:37:34 +01:00
|
|
|
|
2012-11-30 09:44:17 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-12-06 08:29:02 +01:00
|
|
|
IMPL_LINK( SvxPersonalizationTabPage, ForceSelect, RadioButton*, pButton )
|
|
|
|
{
|
2013-05-10 10:47:53 +02:00
|
|
|
if ( pButton == m_pOwnPersona && m_aPersonaSettings.isEmpty() )
|
2012-12-06 08:29:02 +01:00
|
|
|
SelectPersona( m_pSelectPersona );
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-12-06 08:04:48 +01:00
|
|
|
/// 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();
|
|
|
|
|
2013-04-19 15:56:38 +02:00
|
|
|
sal_Int32 end = rBuffer.indexOf( """, where );
|
2012-12-06 08:04:48 +01:00
|
|
|
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.
|
2014-05-22 20:48:34 +05:30
|
|
|
static bool parsePersonaInfo( const OString &rBuffer, OUString *pHeaderURL, OUString *pFooterURL,
|
|
|
|
OUString *pTextColor, OUString *pAccentColor, OUString *pPreviewURL,
|
|
|
|
OUString *pName )
|
2012-12-06 08:04:48 +01:00
|
|
|
{
|
|
|
|
// it is the first attribute that contains "persona="
|
2013-04-19 15:56:38 +02:00
|
|
|
sal_Int32 persona = rBuffer.indexOf( "data-browsertheme=\"{" );
|
2012-12-06 08:04:48 +01:00
|
|
|
if ( persona < 0 )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// now search inside
|
2013-04-19 15:56:38 +02:00
|
|
|
*pHeaderURL = searchValue( rBuffer, persona, ""headerURL":"" );
|
2012-12-06 08:04:48 +01:00
|
|
|
if ( pHeaderURL->isEmpty() )
|
|
|
|
return false;
|
|
|
|
|
2013-04-19 15:56:38 +02:00
|
|
|
*pFooterURL = searchValue( rBuffer, persona, ""footerURL":"" );
|
2012-12-06 08:04:48 +01:00
|
|
|
if ( pFooterURL->isEmpty() )
|
|
|
|
return false;
|
|
|
|
|
2013-04-19 15:56:38 +02:00
|
|
|
*pTextColor = searchValue( rBuffer, persona, ""textcolor":"" );
|
2012-12-06 08:04:48 +01:00
|
|
|
if ( pTextColor->isEmpty() )
|
|
|
|
return false;
|
|
|
|
|
2013-04-19 15:56:38 +02:00
|
|
|
*pAccentColor = searchValue( rBuffer, persona, ""accentcolor":"" );
|
2012-12-06 08:04:48 +01:00
|
|
|
if ( pAccentColor->isEmpty() )
|
|
|
|
return false;
|
|
|
|
|
2014-05-22 20:48:34 +05:30
|
|
|
*pPreviewURL = searchValue( rBuffer, persona, ""previewURL":"" );
|
2014-06-08 20:33:50 +05:30
|
|
|
if ( pPreviewURL->isEmpty() )
|
2014-05-22 20:48:34 +05:30
|
|
|
return false;
|
|
|
|
|
|
|
|
*pName = searchValue( rBuffer, persona, ""name":"" );
|
2014-06-08 20:33:50 +05:30
|
|
|
if ( pName->isEmpty() )
|
2014-05-22 20:48:34 +05:30
|
|
|
return false;
|
|
|
|
|
2012-12-06 08:04:48 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-06-12 17:13:33 +05:30
|
|
|
void SvxPersonalizationTabPage::CopyPersonaToGallery( const OUString &rURL )
|
2012-12-06 08:04:48 +01:00
|
|
|
{
|
2014-06-12 17:13:33 +05:30
|
|
|
m_rApplyThread = new SearchAndParseThread( this, rURL );
|
|
|
|
m_rApplyThread->launch();
|
2012-12-06 08:04:48 +01:00
|
|
|
}
|
|
|
|
|
2014-06-12 17:13:33 +05:30
|
|
|
void SvxPersonalizationTabPage::setPersonaSettings( const OUString aPersonaSettings )
|
|
|
|
{
|
|
|
|
m_aPersonaSettings = aPersonaSettings;
|
|
|
|
m_pOwnPersona->Check();
|
|
|
|
}
|
2014-05-21 11:38:21 +05:30
|
|
|
|
|
|
|
SearchAndParseThread::SearchAndParseThread( SelectPersonaDialog* pDialog,
|
|
|
|
const OUString& rURL ) :
|
|
|
|
Thread( "cuiPersonasSearchThread" ),
|
|
|
|
m_pPersonaDialog( pDialog ),
|
2014-06-12 17:13:33 +05:30
|
|
|
m_pPersonalizationTabPage( NULL ),
|
|
|
|
m_aURL( rURL )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
SearchAndParseThread::SearchAndParseThread( SvxPersonalizationTabPage* pDialog,
|
|
|
|
const OUString& rURL ) :
|
|
|
|
Thread( "cuiPersonasSearchThread" ),
|
|
|
|
m_pPersonaDialog( NULL ),
|
|
|
|
m_pPersonalizationTabPage( pDialog ),
|
2014-05-21 11:38:21 +05:30
|
|
|
m_aURL( rURL )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
SearchAndParseThread::~SearchAndParseThread()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void SearchAndParseThread::execute()
|
|
|
|
{
|
2014-06-12 17:13:33 +05:30
|
|
|
if(m_pPersonaDialog)
|
|
|
|
{
|
2014-06-13 13:42:25 +05:30
|
|
|
m_pPersonaDialog->ClearSearchResults();
|
2014-06-12 17:13:33 +05:30
|
|
|
OUString sProgress( "Searching.. Please Wait.." );
|
|
|
|
m_pPersonaDialog->SetProgress( sProgress );
|
|
|
|
Reference<XComponentContext> xContext( ::comphelper::getProcessComponentContext() );
|
|
|
|
Reference< xml::sax::XParser > xParser = xml::sax::Parser::create(xContext);
|
|
|
|
PersonasDocHandler* pHandler = new PersonasDocHandler();
|
|
|
|
Reference< xml::sax::XDocumentHandler > xDocHandler = pHandler;
|
|
|
|
uno::Reference< ucb::XSimpleFileAccess3 > xFileAccess( ucb::SimpleFileAccess::create( comphelper::getProcessComponentContext() ), uno::UNO_QUERY );
|
|
|
|
uno::Reference< io::XInputStream > xStream;
|
|
|
|
xParser->setDocumentHandler( xDocHandler );
|
|
|
|
|
|
|
|
if ( !xFileAccess.is() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
try {
|
|
|
|
xStream = xFileAccess->openFileRead( m_aURL );
|
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
2014-06-13 11:34:59 +05:30
|
|
|
return;
|
2014-06-12 17:13:33 +05:30
|
|
|
}
|
2014-05-21 11:38:21 +05:30
|
|
|
|
2014-06-12 17:13:33 +05:30
|
|
|
xml::sax::InputSource aParserInput;
|
|
|
|
aParserInput.aInputStream = xStream;
|
|
|
|
xParser->parseStream( aParserInput );
|
2014-05-21 11:38:21 +05:30
|
|
|
|
2014-06-12 17:13:33 +05:30
|
|
|
std::vector<OUString> vLearnmoreURLs = pHandler->getLearnmoreURLs();
|
|
|
|
std::vector<OUString>::iterator it;
|
|
|
|
std::vector<Image> vResultList;
|
|
|
|
GraphicFilter aFilter;
|
|
|
|
Graphic aGraphic;
|
|
|
|
|
|
|
|
for( it = vLearnmoreURLs.begin(); it!=vLearnmoreURLs.end(); ++it )
|
|
|
|
{
|
|
|
|
OUString sHeaderFile, aPersonaSetting;
|
|
|
|
getPreviewFile( *it, &sHeaderFile, &aPersonaSetting );
|
|
|
|
INetURLObject aURLObj( sHeaderFile );
|
|
|
|
aFilter.ImportGraphic( aGraphic, aURLObj );
|
|
|
|
Bitmap aBmp = aGraphic.GetBitmap();
|
|
|
|
vResultList.push_back( Image( aBmp ) );
|
|
|
|
m_pPersonaDialog->AddPersonaSetting(aPersonaSetting);
|
|
|
|
}
|
|
|
|
|
|
|
|
// for VCL to be able to do visual changes in the thread
|
|
|
|
SolarMutexGuard aGuard;
|
|
|
|
|
|
|
|
m_pPersonaDialog->SetImages( vResultList );
|
|
|
|
sProgress = "";
|
|
|
|
m_pPersonaDialog->SetProgress( sProgress );
|
|
|
|
m_pPersonaDialog->setOptimalLayoutSize();
|
2014-05-21 11:38:21 +05:30
|
|
|
}
|
2014-06-12 17:13:33 +05:30
|
|
|
|
|
|
|
else
|
2014-05-21 11:38:21 +05:30
|
|
|
{
|
2014-06-12 17:13:33 +05:30
|
|
|
uno::Reference< ucb::XSimpleFileAccess3 > xFileAccess( ucb::SimpleFileAccess::create( comphelper::getProcessComponentContext() ), uno::UNO_QUERY );
|
|
|
|
if ( !xFileAccess.is() )
|
|
|
|
return;
|
2014-05-22 20:48:34 +05:30
|
|
|
|
2014-06-12 17:13:33 +05:30
|
|
|
OUString aName, aHeaderURL, aFooterURL, aTextColor, aAccentColor;
|
|
|
|
OUString m_aPersonaSettings;
|
2014-05-22 20:48:34 +05:30
|
|
|
|
2014-06-12 17:13:33 +05:30
|
|
|
// get the required fields from m_aURL
|
|
|
|
sal_Int32 nOldIndex = 0;
|
|
|
|
sal_Int32 nNewIndex = m_aURL.indexOf( ';', nOldIndex );
|
|
|
|
aName = m_aURL.copy( nOldIndex, ( nNewIndex - nOldIndex ) );
|
|
|
|
|
|
|
|
nOldIndex = nNewIndex + 1;
|
|
|
|
nNewIndex = m_aURL.indexOf( ';', nOldIndex );
|
|
|
|
aHeaderURL = m_aURL.copy(nOldIndex , ( nNewIndex - nOldIndex ) );
|
|
|
|
|
|
|
|
nOldIndex = nNewIndex + 1;
|
|
|
|
nNewIndex = m_aURL.indexOf( ';', nOldIndex );
|
|
|
|
aFooterURL = m_aURL.copy( nOldIndex, ( nNewIndex - nOldIndex ) );
|
|
|
|
|
|
|
|
nOldIndex = nNewIndex + 1;
|
|
|
|
nNewIndex = m_aURL.indexOf( ';', nOldIndex );
|
|
|
|
aTextColor = m_aURL.copy( nOldIndex, ( nNewIndex - nOldIndex ) );
|
|
|
|
|
|
|
|
nOldIndex = nNewIndex + 1;
|
|
|
|
nNewIndex = m_aURL.getLength();
|
|
|
|
aAccentColor = m_aURL.copy( nOldIndex, ( nNewIndex - nOldIndex ) );
|
2014-06-01 13:15:02 +02:00
|
|
|
|
2014-06-12 17:13:33 +05:30
|
|
|
// 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/";
|
|
|
|
osl::Directory::createPath( gallery );
|
2014-06-01 13:15:02 +02:00
|
|
|
|
2014-06-12 17:13:33 +05:30
|
|
|
OUString aHeaderFile( INetURLObject( aHeaderURL ).getName() );
|
|
|
|
OUString aFooterFile( INetURLObject( aFooterURL ).getName() );
|
|
|
|
|
|
|
|
aHeaderFile = aName + "/" + aHeaderFile;
|
|
|
|
aFooterFile = aName + "/" + aFooterFile;
|
|
|
|
|
|
|
|
try {
|
|
|
|
xFileAccess->copy( aHeaderURL, gallery + aHeaderFile );
|
|
|
|
xFileAccess->copy( aFooterURL, gallery + aFooterFile );
|
|
|
|
}
|
|
|
|
catch ( const uno::Exception & )
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_aPersonaSettings = aHeaderFile + ";" + aFooterFile + ";" + aTextColor + ";" + aAccentColor;
|
|
|
|
m_pPersonalizationTabPage->setPersonaSettings( m_aPersonaSettings );
|
|
|
|
}
|
2014-05-21 11:38:21 +05:30
|
|
|
}
|
|
|
|
|
2014-06-08 20:33:50 +05:30
|
|
|
void SearchAndParseThread::getPreviewFile( const OUString& rURL, OUString *pHeaderFile, OUString *pPersonaSetting )
|
2014-05-22 20:48:34 +05:30
|
|
|
{
|
|
|
|
uno::Reference< ucb::XSimpleFileAccess3 > xFileAccess( ucb::SimpleFileAccess::create( comphelper::getProcessComponentContext() ), uno::UNO_QUERY );
|
|
|
|
if ( !xFileAccess.is() )
|
2014-06-08 20:33:50 +05:30
|
|
|
return;
|
2014-05-22 20:48:34 +05:30
|
|
|
|
|
|
|
uno::Reference< io::XInputStream > xStream;
|
|
|
|
try {
|
|
|
|
xStream = xFileAccess->openFileRead( rURL );
|
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
2014-06-08 20:33:50 +05:30
|
|
|
return;
|
2014-05-22 20:48:34 +05:30
|
|
|
}
|
|
|
|
if ( !xStream.is() )
|
2014-06-08 20:33:50 +05:30
|
|
|
return;
|
2014-05-22 20:48:34 +05:30
|
|
|
|
|
|
|
// 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 ) )
|
2014-06-08 20:33:50 +05:30
|
|
|
return;
|
2014-05-22 20:48:34 +05:30
|
|
|
|
|
|
|
// 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 & )
|
|
|
|
{
|
2014-06-08 20:33:50 +05:30
|
|
|
return;
|
2014-05-22 20:48:34 +05:30
|
|
|
}
|
2014-06-08 20:33:50 +05:30
|
|
|
*pHeaderFile = gallery + aPreviewFile;
|
|
|
|
*pPersonaSetting = aName + ";" + aHeaderURL + ";" + aFooterURL + ";" + aTextColor + ";" + aAccentColor;
|
2014-05-22 20:48:34 +05:30
|
|
|
}
|
2014-06-12 17:13:33 +05:30
|
|
|
|
2012-11-29 13:05:39 +01:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|