From 46c87a5e8a52afd0060a399f71e8814cc120852c Mon Sep 17 00:00:00 2001 From: Susobhan Ghosh Date: Mon, 21 Mar 2016 03:25:27 +0530 Subject: tdf#88502 Firefox Theme URL in custom theme search Persona Dialog modified. Search supports Firefox Theme URL. Added display of installed theme on personalization dialog. Fixed category buttons. Added SOLID as category. Removed invalid/duplicate results. Change-Id: I603c0c292fe5c3e380553b9a2eaab6f4bc0683e1 Reviewed-on: https://gerrit.libreoffice.org/23385 Reviewed-by: Katarina Behrens Tested-by: Jenkins --- cui/source/inc/cuires.hrc | 1 + cui/source/options/personalization.cxx | 168 +++++++---- cui/source/options/personalization.hxx | 11 +- cui/source/options/personalization.src | 5 + cui/uiconfig/ui/personalization_tab.ui | 15 +- cui/uiconfig/ui/select_persona_dialog.ui | 470 +++++++++++++++++-------------- 6 files changed, 392 insertions(+), 278 deletions(-) (limited to 'cui') diff --git a/cui/source/inc/cuires.hrc b/cui/source/inc/cuires.hrc index 98cbb8dc7e23..f0a8ccd33223 100644 --- a/cui/source/inc/cuires.hrc +++ b/cui/source/inc/cuires.hrc @@ -443,6 +443,7 @@ #define RID_SVXSTR_PERSONA_COLOR (RID_SVX_START + 1287) #define RID_SVXSTR_PERSONA_MUSIC (RID_SVX_START + 1288) #define RID_SVXSTR_PERSONA_NATURE (RID_SVX_START + 1289) +#define RID_SVXSTR_PERSONA_SOLID (RID_SVX_START + 1290) #define RID_SVXPAGE_OPENCL (RID_SVX_START + 254) diff --git a/cui/source/options/personalization.cxx b/cui/source/options/personalization.cxx index d7816883cfa1..70a2f8d57f4f 100644 --- a/cui/source/options/personalization.cxx +++ b/cui/source/options/personalization.cxx @@ -26,6 +26,7 @@ #include #include #include +#include #include #include "cuires.hrc" @@ -36,6 +37,8 @@ #include "ucbhelper/content.hxx" #include +#define MAX_RESULTS 9 + using namespace com::sun::star; using namespace ::com::sun::star::uno; using namespace ::com::sun::star::ucb; @@ -67,8 +70,11 @@ SelectPersonaDialog::SelectPersonaDialog( vcl::Window *pParent ) m_vSearchSuggestions[4]->SetText( CUI_RES( RID_SVXSTR_PERSONA_NATURE ) ); m_vSearchSuggestions[4]->SetClickHdl( LINK( this, SelectPersonaDialog, SearchPersonas ) ); + get( m_vSearchSuggestions[5], "suggestion6" ); + m_vSearchSuggestions[5]->SetText( CUI_RES( RID_SVXSTR_PERSONA_SOLID ) ); + m_vSearchSuggestions[5]->SetClickHdl( LINK( this, SelectPersonaDialog, SearchPersonas ) ); + get( m_pEdit, "search_term" ); - m_pEdit->SetPlaceholderText( CUI_RES( RID_SVXSTR_SEARCHTERM ) ); get( m_pProgressLabel, "progress_label" ); @@ -131,11 +137,12 @@ IMPL_LINK_TYPED( SelectPersonaDialog, SearchPersonas, Button*, pButton, void ) searchTerm = m_pEdit->GetText(); else { - for(VclPtr & i : m_vSearchSuggestions) + for( VclPtr & i : m_vSearchSuggestions ) { if( pButton == i ) { - searchTerm = i->GetDisplayText(); + // GetDisplayText() is returning a blank string, thus removing mnemonics explicitly. + searchTerm = MnemonicGenerator::EraseAllMnemonicChars(i->GetText()); break; } } @@ -144,8 +151,14 @@ IMPL_LINK_TYPED( SelectPersonaDialog, SearchPersonas, Button*, pButton, void ) if( searchTerm.isEmpty( ) ) return; - OUString rSearchURL = "https://services.addons.mozilla.org/en-US/firefox/api/1.5/search/" + searchTerm + "/9/9"; - m_rSearchThread = new SearchAndParseThread( this, rSearchURL ); + // 15 results so that invalid and duplicate search results whose names can't be retreived can be skipped + OUString rSearchURL = "https://services.addons.allizom.org/en-US/firefox/api/1.5/search/" + searchTerm + "/9/15"; + + if ( searchTerm.startsWith( "https://addons.mozilla.org/en-US/firefox/addon" ) ) + m_rSearchThread = new SearchAndParseThread( this, searchTerm, true ); + else + m_rSearchThread = new SearchAndParseThread( this, rSearchURL, false ); + m_rSearchThread->launch(); } @@ -155,7 +168,7 @@ IMPL_LINK_NOARG_TYPED( SelectPersonaDialog, ActionOK, Button*, void ) if( !aSelectedPersona.isEmpty() ) { - m_rSearchThread = new SearchAndParseThread( this, aSelectedPersona ); + m_rSearchThread = new SearchAndParseThread( this, aSelectedPersona, false ); m_rSearchThread->launch(); } @@ -250,6 +263,7 @@ SvxPersonalizationTabPage::SvxPersonalizationTabPage( vcl::Window *pParent, cons // persona get( m_pNoPersona, "no_persona" ); get( m_pDefaultPersona, "default_persona" ); + get( m_pAppliedThemeLabel, "applied_theme" ); get( m_pOwnPersona, "own_persona" ); m_pOwnPersona->SetClickHdl( LINK( this, SvxPersonalizationTabPage, ForceSelect ) ); @@ -273,6 +287,7 @@ SvxPersonalizationTabPage::SvxPersonalizationTabPage( vcl::Window *pParent, cons get ( m_pExtensionLabel, "extensions_label" ); + CheckAppliedTheme(); LoadDefaultImages(); LoadExtensionThemes(); } @@ -361,9 +376,31 @@ void SvxPersonalizationTabPage::Reset( const SfxItemSet * ) void SvxPersonalizationTabPage::SetPersonaSettings( const OUString& aPersonaSettings ) { m_aPersonaSettings = aPersonaSettings; + ShowAppliedThemeLabel( m_aPersonaSettings ); m_pOwnPersona->Check(); } +void SvxPersonalizationTabPage::CheckAppliedTheme() +{ + uno::Reference< uno::XComponentContext > xContext( comphelper::getProcessComponentContext() ); + OUString aPersona( "default" ), aPersonaSetting; + if ( xContext.is()) + { + aPersona = officecfg::Office::Common::Misc::Persona::get( xContext ); + aPersonaSetting = officecfg::Office::Common::Misc::PersonaSettings::get( xContext ); + } + if(aPersona == "own") + ShowAppliedThemeLabel(aPersonaSetting); +} + +void SvxPersonalizationTabPage::ShowAppliedThemeLabel(const OUString& aPersonaSetting) +{ + sal_Int32 nNameIndex = aPersonaSetting.indexOf( '/' ); + OUString aName = "(" + aPersonaSetting.copy( 0, nNameIndex ) +")"; + m_pAppliedThemeLabel->Show(); + m_pAppliedThemeLabel->SetText( aName ); +} + void SvxPersonalizationTabPage::LoadDefaultImages() { // Load the pre saved personas @@ -545,16 +582,16 @@ static bool parsePersonaInfo( const OString &rBuffer, OUString *pHeaderURL, OUSt *pName = searchValue( rBuffer, persona, ""name":"" ); if ( pName->isEmpty() ) return false; - return true; } SearchAndParseThread::SearchAndParseThread( SelectPersonaDialog* pDialog, - const OUString& rURL ) : + const OUString& rURL, bool bDirectURL ) : Thread( "cuiPersonasSearchThread" ), m_pPersonaDialog( pDialog ), m_aURL( rURL ), - m_bExecute( true ) + m_bExecute( true ), + m_bDirectURL( bDirectURL ) { } @@ -569,65 +606,86 @@ void SearchAndParseThread::execute() m_pPersonaDialog->ClearSearchResults(); OUString sProgress( CUI_RES( RID_SVXSTR_SEARCHING ) ); m_pPersonaDialog->SetProgress( sProgress ); + + PersonasDocHandler* pHandler = new PersonasDocHandler(); Reference 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 { - css:: uno::Reference< task::XInteractionHandler > xIH( - css::task::InteractionHandler::createWithParent( xContext, nullptr ) ); - - xFileAccess->setInteractionHandler( new comphelper::SimpleFileAccessInteraction( xIH ) ); + if( !m_bDirectURL ) + { + if ( !xFileAccess.is() ) + return; - xStream = xFileAccess->openFileRead( m_aURL ); - if( !xStream.is() ) + try { + css:: uno::Reference< task::XInteractionHandler > xIH( + css::task::InteractionHandler::createWithParent( xContext, nullptr ) ); + + xFileAccess->setInteractionHandler( new comphelper::SimpleFileAccessInteraction( xIH ) ); + + xStream = xFileAccess->openFileRead( m_aURL ); + if( !xStream.is() ) + { + // in case of a returned CommandFailedException + // SimpleFileAccess serves it, returning an empty stream + sProgress = CUI_RES(RID_SVXSTR_SEARCHERROR); + sProgress = sProgress.replaceAll("%1", m_aURL); + m_pPersonaDialog->SetProgress(sProgress); + return; + } + } + catch (...) { - // in case of a returned CommandFailedException - // SimpleFileAccess serves it, returning an empty stream + // a catch all clause, in case the exception is not + // served elsewhere sProgress = CUI_RES(RID_SVXSTR_SEARCHERROR); sProgress = sProgress.replaceAll("%1", m_aURL); m_pPersonaDialog->SetProgress(sProgress); return; } - } - catch (...) - { - // a catch all clause, in case the exception is not - // served elsewhere - sProgress = CUI_RES(RID_SVXSTR_SEARCHERROR); - sProgress = sProgress.replaceAll("%1", m_aURL); - m_pPersonaDialog->SetProgress(sProgress); - return; - } - xml::sax::InputSource aParserInput; - aParserInput.aInputStream = xStream; - xParser->parseStream( aParserInput ); + xml::sax::InputSource aParserInput; + aParserInput.aInputStream = xStream; + xParser->parseStream( aParserInput ); - if( !pHandler->hasResults() ) - { - sProgress = CUI_RES( RID_SVXSTR_NORESULTS ); - m_pPersonaDialog->SetProgress( sProgress ); - return; + if( !pHandler->hasResults() ) + { + sProgress = CUI_RES( RID_SVXSTR_NORESULTS ); + m_pPersonaDialog->SetProgress( sProgress ); + return; + } } - std::vector vLearnmoreURLs = pHandler->getLearnmoreURLs(); + std::vector vLearnmoreURLs; std::vector::iterator it; sal_Int32 nIndex = 0; GraphicFilter aFilter; Graphic aGraphic; - for( it = vLearnmoreURLs.begin(); it!=vLearnmoreURLs.end(); ++it ) + if( !m_bDirectURL ) + vLearnmoreURLs = pHandler->getLearnmoreURLs(); + else + vLearnmoreURLs.push_back( m_aURL ); + + for( it = vLearnmoreURLs.begin(); it!=vLearnmoreURLs.end() && nIndex < MAX_RESULTS; ++it ) { OUString sPreviewFile, aPersonaSetting; - getPreviewFile( *it, &sPreviewFile, &aPersonaSetting ); + bool bResult = getPreviewFile( *it, &sPreviewFile, &aPersonaSetting ); + // parsing is buggy at times, as HTML is not proper. Skip it. + if(aPersonaSetting.isEmpty() || !bResult) + { + if( m_bDirectURL ) + { + sProgress = CUI_RES(RID_SVXSTR_SEARCHERROR); + sProgress = sProgress.replaceAll("%1", m_aURL); + m_pPersonaDialog->SetProgress(sProgress); + return; + } + continue; + } INetURLObject aURLObj( sPreviewFile ); aFilter.ImportGraphic( aGraphic, aURLObj ); Bitmap aBmp = aGraphic.GetBitmap(); @@ -719,25 +777,28 @@ void SearchAndParseThread::execute() } } -void SearchAndParseThread::getPreviewFile( const OUString& rURL, OUString *pPreviewFile, OUString *pPersonaSetting ) +bool SearchAndParseThread::getPreviewFile( const OUString& rURL, OUString *pPreviewFile, OUString *pPersonaSetting ) { uno::Reference< ucb::XSimpleFileAccess3 > xFileAccess( ucb::SimpleFileAccess::create( comphelper::getProcessComponentContext() ), uno::UNO_QUERY ); if ( !xFileAccess.is() ) - return; + return false; + Reference xContext( ::comphelper::getProcessComponentContext() ); uno::Reference< io::XInputStream > xStream; try { + css:: uno::Reference< task::XInteractionHandler > xIH( + css::task::InteractionHandler::createWithParent( xContext, nullptr ) ); + + xFileAccess->setInteractionHandler( new comphelper::SimpleFileAccessInteraction( xIH ) ); xStream = xFileAccess->openFileRead( rURL ); + + if( !xStream.is() ) + return false; } catch (...) { - OUString sProgress( CUI_RES( RID_SVXSTR_SEARCHERROR ) ); - sProgress = sProgress.replaceAll("%1", m_aURL); - m_pPersonaDialog->SetProgress( sProgress ); - return; + return false; } - if ( !xStream.is() ) - return; // read the persona specification // NOTE: Parsing for real is an overkill here; and worse - I tried, and @@ -759,7 +820,7 @@ void SearchAndParseThread::getPreviewFile( const OUString& rURL, OUString *pPrev OUString aHeaderURL, aFooterURL, aTextColor, aAccentColor, aPreviewURL, aName; if ( !parsePersonaInfo( aBuffer.makeStringAndClear(), &aHeaderURL, &aFooterURL, &aTextColor, &aAccentColor, &aPreviewURL, &aName ) ) - return; + return false; // copy the images to the user's gallery OUString gallery = "${$BRAND_BASE_DIR/" LIBO_ETC_FOLDER "/" SAL_CONFIGFILE( "bootstrap") "::UserInstallation}"; @@ -775,10 +836,11 @@ void SearchAndParseThread::getPreviewFile( const OUString& rURL, OUString *pPrev } catch ( const uno::Exception & ) { - return; + return false; } *pPreviewFile = gallery + aPreviewFile; *pPersonaSetting = aName + ";" + aHeaderURL + ";" + aFooterURL + ";" + 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 7bef5a6c6ac1..d801a56f9e5d 100644 --- a/cui/source/options/personalization.hxx +++ b/cui/source/options/personalization.hxx @@ -34,6 +34,7 @@ private: VclPtr m_pPersonaList; ///< The ListBox to show the list of installed personas OUString m_aPersonaSettings; ///< Header and footer images + color to be set in the settings. VclPtr m_pExtensionLabel; ///< The "select persona installed via extensions" label + VclPtr m_pAppliedThemeLabel; ///< The label for showing applied custom theme std::vector m_vDefaultPersonaSettings; std::vector m_vExtensionPersonaSettings; @@ -52,6 +53,8 @@ public: virtual void Reset( const SfxItemSet *rSet ) override; void SetPersonaSettings( const OUString& ); + void CheckAppliedTheme(); + void ShowAppliedThemeLabel( const OUString& ); void LoadDefaultImages(); void LoadExtensionThemes(); @@ -82,7 +85,7 @@ private: VclPtr m_pSearchButton; ///< The search button VclPtr m_pProgressLabel; ///< The label for showing progress of search VclPtr m_vResultList[9]; ///< List of buttons to show search results - VclPtr m_vSearchSuggestions[5]; ///< List of buttons for the search suggestions + VclPtr m_vSearchSuggestions[6]; ///< List of buttons for the search suggestions VclPtr m_pOkButton; ///< The OK button VclPtr m_pCancelButton; ///< The Cancel button @@ -118,16 +121,16 @@ private: VclPtr m_pPersonaDialog; OUString m_aURL; - bool m_bExecute; + bool m_bExecute, m_bDirectURL; virtual ~SearchAndParseThread(); virtual void execute() override; - void getPreviewFile( const OUString&, OUString *, OUString * ); + bool getPreviewFile( const OUString&, OUString *, OUString * ); public: SearchAndParseThread( SelectPersonaDialog* pDialog, - const OUString& rURL ); + const OUString& rURL, bool bDirectURL ); void StopExecution() { m_bExecute = false; } }; diff --git a/cui/source/options/personalization.src b/cui/source/options/personalization.src index eba74b836d24..c98fd49674f6 100644 --- a/cui/source/options/personalization.src +++ b/cui/source/options/personalization.src @@ -69,4 +69,9 @@ String RID_SVXSTR_PERSONA_NATURE Text [ en-US ] = "Nature"; }; +String RID_SVXSTR_PERSONA_SOLID +{ + Text [ en-US ] = "Solid"; +}; + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/cui/uiconfig/ui/personalization_tab.ui b/cui/uiconfig/ui/personalization_tab.ui index bb4383c06f8a..d240a2da1934 100644 --- a/cui/uiconfig/ui/personalization_tab.ui +++ b/cui/uiconfig/ui/personalization_tab.ui @@ -1,5 +1,5 @@ - + @@ -130,6 +130,17 @@ 0 + + + True + False + + + True + True + 1 + + Select Theme @@ -140,7 +151,7 @@ False False - 1 + 2 diff --git a/cui/uiconfig/ui/select_persona_dialog.ui b/cui/uiconfig/ui/select_persona_dialog.ui index c34e5184a84a..600bd8d06414 100644 --- a/cui/uiconfig/ui/select_persona_dialog.ui +++ b/cui/uiconfig/ui/select_persona_dialog.ui @@ -1,5 +1,5 @@ - + @@ -13,80 +13,8 @@ False vertical 12 - - - True - False - end - - - gtk-ok - True - True - True - True - - - False - False - 0 - - - - - gtk-cancel - True - True - True - True - - - False - False - 1 - - - - - gtk-help - True - True - True - True - - - False - False - 2 - True - - - - - True - False - 0 - end - 45 - - - True - True - 3 - True - True - - - - - False - True - end - 3 - - - + True False 0 @@ -125,7 +53,8 @@ - _Search + _Go + 85 True True True @@ -151,10 +80,10 @@ - + True False - Custom Search + Search Term or Firefox Theme URL @@ -185,25 +114,12 @@ False vertical 6 - - - True - False - 0 - Categories: - True - - - False - True - 0 - - True False 6 + True True @@ -279,145 +195,26 @@ 4 - - - False - True - 1 - - - - - 624 - 219 - True - False - 6 - 6 - True - True - - - True - True - True - True - True - - - 0 - 0 - - - - - True - True - True - True - True - - - 1 - 0 - - - + True True True - True - True - - - 2 - 0 - - - - - True - True - True - True - True - - - 0 - 1 - - - - - True - True - True - True - True - - - 1 - 1 - - - - - True - True - True - True - True - - - 2 - 1 - - - - - True - True - True - True - True - - - 0 - 2 - - - - - True - True - True - True - True - - - 1 - 2 - - - - - True - True - True - True - True + + + - 2 - 2 + True + True + 5 False True - 3 + 0 @@ -428,7 +225,7 @@ True False - Suggested Themes by Category + Suggested Categories @@ -441,6 +238,241 @@ 1 + + + True + False + + + False + True + 2 + + + + + 624 + 219 + True + False + 6 + 6 + True + True + + + True + True + True + True + True + + + 0 + 0 + 1 + 1 + + + + + True + True + True + True + True + + + 1 + 0 + 1 + 1 + + + + + True + True + True + True + True + + + 2 + 0 + 1 + 1 + + + + + True + True + True + True + True + + + 0 + 1 + 1 + 1 + + + + + True + True + True + True + True + + + 1 + 1 + 1 + 1 + + + + + True + True + True + True + True + + + 2 + 1 + 1 + 1 + + + + + True + True + True + True + True + + + 0 + 2 + 1 + 1 + + + + + True + True + True + True + True + + + 1 + 2 + 1 + 1 + + + + + True + True + True + True + True + + + 2 + 2 + 1 + 1 + + + + + False + True + 3 + + + + + True + False + end + + + gtk-ok + True + True + True + True + + + False + False + 0 + + + + + gtk-cancel + True + True + True + True + + + False + False + 1 + + + + + gtk-help + True + True + True + True + + + False + False + 2 + True + + + + + True + False + 0 + end + 45 + + + True + True + 3 + True + True + + + + + False + True + end + 4 + + -- cgit