Kaydet (Commit) e2cb51bf authored tarafından Jan-Marek Glogowski's avatar Jan-Marek Glogowski

Refactor a bit of the presentation minimizer

This was originally just about getting rid of the resource leak.
Turned out to include a little refactoring to hide most of the
UnoDialog member variables.

* use cppu::component_getFactoryHelper
* free leaked createPeer resources in destructor

Change-Id: I45449c49e32af4935908b801ed9bd9732af944d3
Reviewed-on: https://gerrit.libreoffice.org/73565
Tested-by: Jenkins
Reviewed-by: 's avatarJan-Marek Glogowski <glogow@fbihome.de>
üst 7140da91
......@@ -232,7 +232,7 @@ void InformationDialog::InitDialog()
Sequence< OUString > aNames( pNames, nCount );
Sequence< Any > aValues( pValues, nCount );
mxDialogModelMultiPropertySet->setPropertyValues( aNames, aValues );
setPropertyValues(aNames, aValues);
sal_Int64 nSource = mnSourceSize;
sal_Int64 nDest = mnDestSize;
......@@ -315,11 +315,6 @@ InformationDialog::InformationDialog( const Reference< XComponentContext > &rxCo
mrbOpenNewDocument( rbOpenNewDocument ),
maSaveAsURL( rSaveAsURL )
{
Reference< XFrame > xFrame( mxController->getFrame() );
Reference< XWindow > xContainerWindow( xFrame->getContainerWindow() );
Reference< XWindowPeer > xWindowPeer( xContainerWindow, UNO_QUERY_THROW );
createWindowPeer( xWindowPeer );
InitDialog();
}
......
......@@ -77,7 +77,7 @@ void OptimizerDialog::InitDialog()
Sequence< OUString > aNames( pNames, nCount );
Sequence< Any > aValues( pValues, nCount );
mxDialogModelMultiPropertySet->setPropertyValues( aNames, aValues );
setPropertyValues(aNames, aValues);
}
......@@ -111,7 +111,7 @@ void OptimizerDialog::InitRoadmap()
Reference< XPropertySet > xPropertySet( mxRoadmapControlModel, UNO_QUERY_THROW );
xPropertySet->setPropertyValue( "Name", Any( OUString("rdmNavi") ) );
mxRoadmapControl = mxDialog->getControl( "rdmNavi" );
mxRoadmapControl = getControl( "rdmNavi" );
InsertRoadmapItem( 0, getString( STR_INTRODUCTION ), ITEM_ID_INTRODUCTION );
InsertRoadmapItem( 1, getString( STR_SLIDES ), ITEM_ID_SLIDES );
InsertRoadmapItem( 2, getString( STR_IMAGE_OPTIMIZATION ), ITEM_ID_GRAPHIC_OPTIMIZATION );
......@@ -234,7 +234,7 @@ OptimizerDialog::OptimizerDialog( const Reference< XComponentContext > &rxContex
OptimizerDialog::~OptimizerDialog()
{
// not saving configuration if the dialog has been finished via cancel or close window
if ( mbStatus )
if ( endStatus() )
SaveConfiguration();
}
......@@ -317,9 +317,6 @@ OUString OptimizerDialog::GetSelectedString( OUString const & token )
void OptimizerDialog::UpdateStatus( const css::uno::Sequence< css::beans::PropertyValue >& rStatus )
{
if ( !mxReschedule.is() )
return;
maStats.InitializeStatusValues( rStatus );
const Any* pVal( maStats.GetStatusValue( TK_Status ) );
if ( pVal )
......@@ -342,7 +339,7 @@ void OptimizerDialog::UpdateStatus( const css::uno::Sequence< css::beans::Proper
if ( pVal )
SetConfigProperty( TK_OpenNewDocument, *pVal );
mxReschedule->reschedule();
reschedule();
}
......@@ -507,7 +504,7 @@ void ActionListener::actionPerformed( const ActionEvent& rEvent )
// generating default file name
OUString aName;
Reference< XStorable > xStorable( mrOptimizerDialog.mxController->getModel(), UNO_QUERY );
Reference< XStorable > xStorable( mrOptimizerDialog.controller()->getModel(), UNO_QUERY );
if ( xStorable.is() && xStorable->hasLocation() )
{
INetURLObject aURLObj( xStorable->getLocation() );
......@@ -547,17 +544,14 @@ void ActionListener::actionPerformed( const ActionEvent& rEvent )
}
// waiting for 500ms
if ( mrOptimizerDialog.mxReschedule.is() )
{
mrOptimizerDialog.mxReschedule->reschedule();
for ( sal_uInt32 i = osl_getGlobalTimer(); ( i + 500 ) > ( osl_getGlobalTimer() ); )
mrOptimizerDialog.mxReschedule->reschedule();
}
mrOptimizerDialog.reschedule();
for ( sal_uInt32 i = osl_getGlobalTimer(); ( i + 500 ) > ( osl_getGlobalTimer() ); )
mrOptimizerDialog.reschedule();
}
else
{
// Apply changes to current presentation
Reference<XModifiable> xModifiable(mrOptimizerDialog.mxController->getModel(),
Reference<XModifiable> xModifiable(mrOptimizerDialog.controller()->getModel(),
UNO_QUERY_THROW );
if ( xModifiable->isModified() )
{
......
......@@ -123,13 +123,12 @@ void SAL_CALL PPPOptimizerDialog::dispatch( const URL& rURL,
OUString sResult( sBuf.makeStringAndClear() );
SAL_INFO("sdext.minimizer", sResult );
}
delete mpOptimizerDialog;
mpOptimizerDialog = nullptr;
}
catch( ... )
{
}
delete mpOptimizerDialog;
mpOptimizerDialog = nullptr;
}
else if ( rURL.Path == "statusupdate" )
{
......
......@@ -17,44 +17,27 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include <osl/thread.h>
#include <cppuhelper/factory.hxx>
#include <com/sun/star/lang/XSingleComponentFactory.hpp>
#include <cppuhelper/implementationentry.hxx>
#include "pppoptimizerdialog.hxx"
using namespace ::cppu;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::lang;
using namespace ::com::sun::star::registry;
extern "C"
namespace
{
SAL_DLLPUBLIC_EXPORT void* pptminimizer_component_getFactory(
const sal_Char * pImplName, void * pServiceManager,
SAL_UNUSED_PARAMETER void * /*pRegistryKey*/ )
{
OUString aImplName( OUString::createFromAscii( pImplName ) );
void* pRet = nullptr;
if( pServiceManager )
{
Reference< XSingleComponentFactory > xFactory;
if( aImplName == PPPOptimizerDialog_getImplementationName() )
{
xFactory = createSingleComponentFactory(
PPPOptimizerDialog_createInstance,
OUString::createFromAscii( pImplName ),
PPPOptimizerDialog_getSupportedServiceNames() );
}
if( xFactory.is() )
{
xFactory->acquire();
pRet = xFactory.get();
}
}
return pRet;
}
static cppu::ImplementationEntry const services[] = {
{ &PPPOptimizerDialog_createInstance,
&PPPOptimizerDialog_getImplementationName,
&PPPOptimizerDialog_getSupportedServiceNames,
&cppu::createSingleComponentFactory, nullptr, 0 },
{ nullptr, nullptr, nullptr, nullptr, nullptr, 0 } };
}
extern "C" SAL_DLLPUBLIC_EXPORT void * pptminimizer_component_getFactory(
char const * pImplName, void * pServiceManager, void * pRegistryKey)
{
return cppu::component_getFactoryHelper(
pImplName, pServiceManager, pRegistryKey, services);
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -19,6 +19,7 @@
#include "unodialog.hxx"
#include <com/sun/star/awt/MessageBoxButtons.hpp>
#include <com/sun/star/awt/Toolkit.hpp>
#include <com/sun/star/awt/UnoControlDialog.hpp>
......@@ -56,17 +57,24 @@ UnoDialog::UnoDialog( const Reference< XComponentContext > &rxContext, Reference
Reference< XFrame > xFrame( mxController->getFrame() );
Reference< XWindow > xContainerWindow( xFrame->getContainerWindow() );
mxWindowPeer.set( xContainerWindow, UNO_QUERY_THROW );
createWindowPeer( mxWindowPeer );
}
Reference< XWindowPeer > xWindowPeer( xContainerWindow, UNO_QUERY_THROW );
// set the main loop handle to update GUI while busy
Reference< XToolkit > xToolkit( Toolkit::create( mxContext ), UNO_QUERY_THROW );
mxReschedule.set( xToolkit, UNO_QUERY );
// allocate the real window resources
mxDialog->createPeer(xToolkit,
xWindowPeer.is() ? xWindowPeer : xToolkit->getDesktopWindow());
}
UnoDialog::~UnoDialog()
{
// free the resources
Reference<XComponent> xDialogComponent(mxDialog, UNO_QUERY_THROW);
xDialogComponent->dispose();
}
void UnoDialog::execute()
{
mxDialog->setEnable( true );
......@@ -80,20 +88,6 @@ void UnoDialog::endExecute( bool bStatus )
mxDialog->endExecute();
}
Reference< XWindowPeer > UnoDialog::createWindowPeer( Reference< XWindowPeer > const & xParentPeer )
{
mxDialog->setVisible( false );
Reference< XToolkit > xToolkit( Toolkit::create( mxContext ), UNO_QUERY_THROW );
mxReschedule.set( xToolkit, UNO_QUERY );
mxDialog->createPeer(
xToolkit,
xParentPeer.is() ? xParentPeer : xToolkit->getDesktopWindow());
// xWindowPeer = xControl.getPeer();
return mxDialog->getPeer();
}
Reference< XInterface > UnoDialog::insertControlModel( const OUString& rServiceName, const OUString& rName,
const Sequence< OUString >& rPropertyNames, const Sequence< Any >& rPropertyValues )
{
......
......@@ -59,9 +59,6 @@ public:
void execute();
void endExecute( bool bStatus );
/// @throws css::uno::Exception
css::uno::Reference< css::awt::XWindowPeer > createWindowPeer( css::uno::Reference< css::awt::XWindowPeer > const & xParentPeer );
css::uno::Reference< css::uno::XInterface > insertControlModel( const OUString& rServiceName, const OUString& rName,
const css::uno::Sequence< OUString >& rPropertyNames, const css::uno::Sequence< css::uno::Any >& rPropertyValues );
......@@ -98,10 +95,19 @@ public:
void enableControl( const OUString& rControlName );
void disableControl( const OUString& rControlName );
void reschedule() const { mxReschedule->reschedule(); }
bool endStatus() const { return mbStatus; }
css::uno::Reference<css::awt::XControl> getControl(const OUString& rControlName) const { return mxDialog->getControl(rControlName); }
css::uno::Reference<css::frame::XController> controller() const { return mxController; }
void setPropertyValues(const css::uno::Sequence<OUString>& rNameSeq, const css::uno::Sequence<css::uno::Any>& rValueSeq)
{ mxDialogModelMultiPropertySet->setPropertyValues(rNameSeq, rValueSeq); }
protected:
css::uno::Reference< css::uno::XComponentContext > mxContext;
css::uno::Reference< css::frame::XController > mxController;
css::uno::Reference< css::awt::XReschedule > mxReschedule;
private:
css::uno::Reference< css::awt::XReschedule > mxReschedule;
css::uno::Reference< css::uno::XInterface > mxDialogModel;
css::uno::Reference< css::beans::XMultiPropertySet > mxDialogModelMultiPropertySet;
css::uno::Reference< css::lang::XMultiServiceFactory > mxDialogModelMSF;
......@@ -112,8 +118,6 @@ public:
css::uno::Reference< css::awt::XUnoControlDialog > mxDialog;
css::uno::Reference< css::awt::XControl > mxControl;
css::uno::Reference< css::awt::XWindowPeer > mxWindowPeer;
bool mbStatus;
};
......
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