diff options
author | Rachit Gupta <rachitgupta1792@gmail.com> | 2014-05-21 11:38:21 +0530 |
---|---|---|
committer | Rachit Gupta <rachitgupta1792@gmail.com> | 2014-08-04 20:27:44 +0530 |
commit | 83122eee143caf8518a4b76864aa6ac808458bee (patch) | |
tree | 5aa8893b5d460a0db6630795c7584043aa1142c9 | |
parent | 7d872cee67833a082432c33657a50e00f69971d4 (diff) |
Added SearchAndParseThread.
The search results data is retrieved and parsed in a separate
thread so that the UI doesn't hang awkwardly.
Change-Id: I51437edd4cfbd45f5fb7e487ad2baf5dba6618a4
-rw-r--r-- | cui/source/options/personalization.cxx | 62 | ||||
-rw-r--r-- | cui/source/options/personalization.hxx | 21 |
2 files changed, 61 insertions, 22 deletions
diff --git a/cui/source/options/personalization.cxx b/cui/source/options/personalization.cxx index 3e23c33a3108..0d00ecf837f0 100644 --- a/cui/source/options/personalization.cxx +++ b/cui/source/options/personalization.cxx @@ -35,7 +35,6 @@ using namespace ::com::sun::star::ucb; SelectPersonaDialog::SelectPersonaDialog( Window *pParent ) : ModalDialog( pParent, "SelectPersonaDialog", "cui/ui/select_persona_dialog.ui" ) { - PushButton *pButton; get( pButton, "search_personas" ); pButton->SetClickHdl( LINK( this, SelectPersonaDialog, VisitPersonas ) ); @@ -55,29 +54,10 @@ OUString SelectPersonaDialog::GetPersonaURL() const IMPL_LINK( SelectPersonaDialog, VisitPersonas, PushButton*, /*pButton*/ ) { - 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 ); - OUString searchTerm = m_pEdit->GetText(); OUString rURL = "https://addons.allizom.org/en-US/firefox/api/1.5/search/" + searchTerm + "/9/"; - if ( !xFileAccess.is() ) - return false; - - try { - xStream = xFileAccess->openFileRead( rURL ); - } - catch (...) - { - return false; - } - xml::sax::InputSource aParserInput; - aParserInput.aInputStream = xStream; - xParser->parseStream( aParserInput ); + m_aSearchThread = new SearchAndParseThread( this, rURL ); + m_aSearchThread->launch(); return 0; } @@ -297,4 +277,42 @@ bool SvxPersonalizationTabPage::CopyPersonaToGallery( const OUString &rURL ) return true; } + +SearchAndParseThread::SearchAndParseThread( SelectPersonaDialog* pDialog, + const OUString& rURL ) : + Thread( "cuiPersonasSearchThread" ), + m_pPersonaDialog( pDialog ), + m_aURL( rURL ) +{ +} + +SearchAndParseThread::~SearchAndParseThread() +{ +} + +void SearchAndParseThread::execute() +{ + 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 false; + + try { + xStream = xFileAccess->openFileRead( m_aURL ); + } + catch (...) + { + // return false; + } + xml::sax::InputSource aParserInput; + aParserInput.aInputStream = xStream; + xParser->parseStream( aParserInput ); +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/cui/source/options/personalization.hxx b/cui/source/options/personalization.hxx index 870053dae965..7c2fc3c24ac8 100644 --- a/cui/source/options/personalization.hxx +++ b/cui/source/options/personalization.hxx @@ -11,8 +11,12 @@ #define INCLUDED_CUI_SOURCE_OPTIONS_PERSONALIZATION_HXX #include <sfx2/tabdlg.hxx> +#include <salhelper/thread.hxx> +#include <rtl/ref.hxx> +#include <vcl/prgsbar.hxx> class FixedText; +class SearchAndParseThread; class SvxPersonalizationTabPage : public SfxTabPage { @@ -57,9 +61,12 @@ class SelectPersonaDialog : public ModalDialog { private: Edit *m_pEdit; ///< The input line for the Persona URL + PushButton *pButton; + public: SelectPersonaDialog( Window *pParent ); + ::rtl::Reference< SearchAndParseThread > m_aSearchThread; /// Get the URL from the Edit field. OUString GetPersonaURL() const; @@ -69,7 +76,21 @@ private: DECL_LINK( VisitPersonas, PushButton* ); }; +class SearchAndParseThread: public salhelper::Thread +{ +private: + + SelectPersonaDialog *m_pPersonaDialog; + OUString m_aURL; + virtual ~SearchAndParseThread(); + virtual void execute() SAL_OVERRIDE; + +public: + + SearchAndParseThread( SelectPersonaDialog* pDialog, + const OUString& rURL ); +}; #endif // INCLUDED_CUI_SOURCE_OPTIONS_PERSONALIZATION_HXX |