[Libreoffice-commits] core.git: Branch 'feature/gsoc14-personas' - cui/source

Rachit Gupta rachitgupta1792 at gmail.com
Thu Jul 10 10:59:13 PDT 2014


 cui/source/options/personalization.cxx |   28 +++++++++++++++++++++++-----
 cui/source/options/personalization.hxx |    3 +++
 2 files changed, 26 insertions(+), 5 deletions(-)

New commits:
commit bba5ba8a7e02e8f35d1a5f9e65723a19fdc57d28
Author: Rachit Gupta <rachitgupta1792 at gmail.com>
Date:   Thu Jul 10 23:23:12 2014 +0530

    Fixed thread related issues.
    
    Added a data member m_bExecute which defaults to true but is set to
    false when StopExecution is called. During execution, the member's value
    is checked at various positions, if it is false, the execution is stopped
    by returning from the execute method.
    
    Following issues have been resolved:
    
    * Multiple searches can be performed. The previous search is halted.
    * Cancel button can be pressed in between any search or application of
      the persona.
    * A theme can be selected and applied by clicking on OK while the search
      is being done.
    
    Change-Id: Ic76c224ca0d317a6e1a44b3e8933a3ba50b371cb

diff --git a/cui/source/options/personalization.cxx b/cui/source/options/personalization.cxx
index e67318a..d69076e 100644
--- a/cui/source/options/personalization.cxx
+++ b/cui/source/options/personalization.cxx
@@ -112,7 +112,10 @@ OUString SelectPersonaDialog::GetSelectedPersona() const
 IMPL_LINK( SelectPersonaDialog, SearchPersonas, PushButton*, pButton )
 {
     OUString searchTerm;
-    if( pButton ==  m_pSearchButton)
+    if( m_rSearchThread.is() )
+        m_rSearchThread->StopExecution();
+
+    if( pButton ==  m_pSearchButton )
         searchTerm = m_pEdit->GetText();
     else
     {
@@ -146,14 +149,17 @@ IMPL_LINK( SelectPersonaDialog, ActionOK, PushButton*, /* pButton */ )
     }
 
     else
+    {
+        if( m_rSearchThread.is() )
+            m_rSearchThread->StopExecution();
         EndDialog( RET_OK );
+    }
     return 0;
 }
 
 IMPL_LINK( SelectPersonaDialog, ActionCancel, PushButton*, /* pButton */ )
 {
-    if( m_rSearchThread.is() )
-        m_rSearchThread->terminate();
+    m_rSearchThread->StopExecution();
 
     EndDialog( RET_CANCEL );
     return 0;
@@ -161,6 +167,9 @@ IMPL_LINK( SelectPersonaDialog, ActionCancel, PushButton*, /* pButton */ )
 
 IMPL_LINK( SelectPersonaDialog, SelectPersona, PushButton*, pButton )
 {
+    if( m_rSearchThread.is() )
+        m_rSearchThread->StopExecution();
+
     for( sal_Int32 index = 0; index < 9; index++ )
     {
         if( pButton == m_vResultList[index] )
@@ -526,7 +535,8 @@ SearchAndParseThread::SearchAndParseThread( SelectPersonaDialog* pDialog,
                           const OUString& rURL ) :
             Thread( "cuiPersonasSearchThread" ),
             m_pPersonaDialog( pDialog ),
-            m_aURL( rURL )
+            m_aURL( rURL ),
+            m_bExecute( true )
 {
 }
 
@@ -587,6 +597,9 @@ void SearchAndParseThread::execute()
             aFilter.ImportGraphic( aGraphic, aURLObj );
             Bitmap aBmp = aGraphic.GetBitmap();
 
+            if( !m_bExecute )
+                return;
+
             // for VCL to be able to do visual changes in the thread
             SolarMutexGuard aGuard;
             m_pPersonaDialog->SetImages( Image( aBmp ), nIndex++ );
@@ -594,8 +607,10 @@ void SearchAndParseThread::execute()
             m_pPersonaDialog->AddPersonaSetting( aPersonaSetting );
         }
 
-        SolarMutexGuard aGuard;
+        if( !m_bExecute )
+            return;
 
+        SolarMutexGuard aGuard;
         sProgress = "";
         m_pPersonaDialog->SetProgress( sProgress );
         m_pPersonaDialog->setOptimalLayoutSize();
@@ -657,6 +672,9 @@ void SearchAndParseThread::execute()
             return;
         }
 
+        if( !m_bExecute )
+            return;
+
         SolarMutexGuard aGuard;
 
         aPersonaSetting = aHeaderFile + ";" + aFooterFile + ";" + aTextColor + ";" + aAccentColor;
diff --git a/cui/source/options/personalization.hxx b/cui/source/options/personalization.hxx
index a09226e..92ce3de 100644
--- a/cui/source/options/personalization.hxx
+++ b/cui/source/options/personalization.hxx
@@ -116,6 +116,7 @@ private:
 
     SelectPersonaDialog *m_pPersonaDialog;
     OUString m_aURL;
+    bool m_bExecute;
 
     virtual ~SearchAndParseThread();
     virtual void execute() SAL_OVERRIDE;
@@ -125,6 +126,8 @@ public:
 
     SearchAndParseThread( SelectPersonaDialog* pDialog,
                           const OUString& rURL );
+
+    void StopExecution() { m_bExecute = false; }
 };
 
 #endif // INCLUDED_CUI_SOURCE_OPTIONS_PERSONALIZATION_HXX


More information about the Libreoffice-commits mailing list