Kaydet (Commit) e372d28c authored tarafından Rachit Gupta's avatar Rachit Gupta Kaydeden (comit) Jan Holesovsky

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
üst 95771f49
...@@ -112,7 +112,10 @@ OUString SelectPersonaDialog::GetSelectedPersona() const ...@@ -112,7 +112,10 @@ OUString SelectPersonaDialog::GetSelectedPersona() const
IMPL_LINK( SelectPersonaDialog, SearchPersonas, PushButton*, pButton ) IMPL_LINK( SelectPersonaDialog, SearchPersonas, PushButton*, pButton )
{ {
OUString searchTerm; OUString searchTerm;
if( pButton == m_pSearchButton) if( m_rSearchThread.is() )
m_rSearchThread->StopExecution();
if( pButton == m_pSearchButton )
searchTerm = m_pEdit->GetText(); searchTerm = m_pEdit->GetText();
else else
{ {
...@@ -146,14 +149,17 @@ IMPL_LINK( SelectPersonaDialog, ActionOK, PushButton*, /* pButton */ ) ...@@ -146,14 +149,17 @@ IMPL_LINK( SelectPersonaDialog, ActionOK, PushButton*, /* pButton */ )
} }
else else
{
if( m_rSearchThread.is() )
m_rSearchThread->StopExecution();
EndDialog( RET_OK ); EndDialog( RET_OK );
}
return 0; return 0;
} }
IMPL_LINK( SelectPersonaDialog, ActionCancel, PushButton*, /* pButton */ ) IMPL_LINK( SelectPersonaDialog, ActionCancel, PushButton*, /* pButton */ )
{ {
if( m_rSearchThread.is() ) m_rSearchThread->StopExecution();
m_rSearchThread->terminate();
EndDialog( RET_CANCEL ); EndDialog( RET_CANCEL );
return 0; return 0;
...@@ -161,6 +167,9 @@ IMPL_LINK( SelectPersonaDialog, ActionCancel, PushButton*, /* pButton */ ) ...@@ -161,6 +167,9 @@ IMPL_LINK( SelectPersonaDialog, ActionCancel, PushButton*, /* pButton */ )
IMPL_LINK( SelectPersonaDialog, SelectPersona, PushButton*, pButton ) IMPL_LINK( SelectPersonaDialog, SelectPersona, PushButton*, pButton )
{ {
if( m_rSearchThread.is() )
m_rSearchThread->StopExecution();
for( sal_Int32 index = 0; index < 9; index++ ) for( sal_Int32 index = 0; index < 9; index++ )
{ {
if( pButton == m_vResultList[index] ) if( pButton == m_vResultList[index] )
...@@ -526,7 +535,8 @@ SearchAndParseThread::SearchAndParseThread( SelectPersonaDialog* pDialog, ...@@ -526,7 +535,8 @@ SearchAndParseThread::SearchAndParseThread( SelectPersonaDialog* pDialog,
const OUString& rURL ) : const OUString& rURL ) :
Thread( "cuiPersonasSearchThread" ), Thread( "cuiPersonasSearchThread" ),
m_pPersonaDialog( pDialog ), m_pPersonaDialog( pDialog ),
m_aURL( rURL ) m_aURL( rURL ),
m_bExecute( true )
{ {
} }
...@@ -587,6 +597,9 @@ void SearchAndParseThread::execute() ...@@ -587,6 +597,9 @@ void SearchAndParseThread::execute()
aFilter.ImportGraphic( aGraphic, aURLObj ); aFilter.ImportGraphic( aGraphic, aURLObj );
Bitmap aBmp = aGraphic.GetBitmap(); Bitmap aBmp = aGraphic.GetBitmap();
if( !m_bExecute )
return;
// for VCL to be able to do visual changes in the thread // for VCL to be able to do visual changes in the thread
SolarMutexGuard aGuard; SolarMutexGuard aGuard;
m_pPersonaDialog->SetImages( Image( aBmp ), nIndex++ ); m_pPersonaDialog->SetImages( Image( aBmp ), nIndex++ );
...@@ -594,8 +607,10 @@ void SearchAndParseThread::execute() ...@@ -594,8 +607,10 @@ void SearchAndParseThread::execute()
m_pPersonaDialog->AddPersonaSetting( aPersonaSetting ); m_pPersonaDialog->AddPersonaSetting( aPersonaSetting );
} }
SolarMutexGuard aGuard; if( !m_bExecute )
return;
SolarMutexGuard aGuard;
sProgress = ""; sProgress = "";
m_pPersonaDialog->SetProgress( sProgress ); m_pPersonaDialog->SetProgress( sProgress );
m_pPersonaDialog->setOptimalLayoutSize(); m_pPersonaDialog->setOptimalLayoutSize();
...@@ -657,6 +672,9 @@ void SearchAndParseThread::execute() ...@@ -657,6 +672,9 @@ void SearchAndParseThread::execute()
return; return;
} }
if( !m_bExecute )
return;
SolarMutexGuard aGuard; SolarMutexGuard aGuard;
aPersonaSetting = aHeaderFile + ";" + aFooterFile + ";" + aTextColor + ";" + aAccentColor; aPersonaSetting = aHeaderFile + ";" + aFooterFile + ";" + aTextColor + ";" + aAccentColor;
......
...@@ -116,6 +116,7 @@ private: ...@@ -116,6 +116,7 @@ private:
SelectPersonaDialog *m_pPersonaDialog; SelectPersonaDialog *m_pPersonaDialog;
OUString m_aURL; OUString m_aURL;
bool m_bExecute;
virtual ~SearchAndParseThread(); virtual ~SearchAndParseThread();
virtual void execute() SAL_OVERRIDE; virtual void execute() SAL_OVERRIDE;
...@@ -125,6 +126,8 @@ public: ...@@ -125,6 +126,8 @@ public:
SearchAndParseThread( SelectPersonaDialog* pDialog, SearchAndParseThread( SelectPersonaDialog* pDialog,
const OUString& rURL ); const OUString& rURL );
void StopExecution() { m_bExecute = false; }
}; };
#endif // INCLUDED_CUI_SOURCE_OPTIONS_PERSONALIZATION_HXX #endif // INCLUDED_CUI_SOURCE_OPTIONS_PERSONALIZATION_HXX
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment