pppoptimizerdialog.cxx (880c69c6) | pppoptimizerdialog.cxx (597a4c59) |
---|---|
1/************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance --- 13 unchanged lines hidden (view full) --- 22 23 24// MARKER(update_precomp.py): autogen include statement, do not remove 25#include "precompiled_sdext.hxx" 26 27#include "pppoptimizerdialog.hxx" 28#include "optimizerdialog.hxx" 29 | 1/************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance --- 13 unchanged lines hidden (view full) --- 22 23 24// MARKER(update_precomp.py): autogen include statement, do not remove 25#include "precompiled_sdext.hxx" 26 27#include "pppoptimizerdialog.hxx" 28#include "optimizerdialog.hxx" 29 |
30using namespace ::rtl; | 30#include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp> 31#include <rtl/strbuf.hxx> 32#include <rtl/ref.hxx> 33 34#define SERVICE_NAME "com.sun.star.ui.dialogs.PresentationMinimizerDialog" 35#define IMPLEMENTATION_NAME "com.sun.star.comp.ui.dialogs.PresentationMinimizerDialog" 36 |
31using namespace ::com::sun::star::uno; 32using namespace ::com::sun::star::util; 33using namespace ::com::sun::star::lang; 34using namespace ::com::sun::star::frame; 35using namespace ::com::sun::star::beans; 36 | 37using namespace ::com::sun::star::uno; 38using namespace ::com::sun::star::util; 39using namespace ::com::sun::star::lang; 40using namespace ::com::sun::star::frame; 41using namespace ::com::sun::star::beans; 42 |
37#define SERVICE_NAME "com.sun.star.comp.SunPresentationMinimizer" 38#include <rtl/ustrbuf.hxx> | 43using ::rtl::OUString; 44using ::com::sun::star::awt::XWindow; 45using ::com::sun::star::awt::XWindowPeer; |
39 40// ---------------------- 41// - PPPOptimizerDialog - 42// ---------------------- 43 | 46 47// ---------------------- 48// - PPPOptimizerDialog - 49// ---------------------- 50 |
44PPPOptimizerDialog::PPPOptimizerDialog( const Reference< XComponentContext > &rxMSF ) : 45 mxMSF( rxMSF ), 46 mpOptimizerDialog( NULL ) | 51PPPOptimizerDialog::PPPOptimizerDialog( 52 const Reference< XComponentContext > &rxContext ) 53 : m_xContext( rxContext ) 54 , mbInitialized( false ) |
47{ | 55{ |
56 OSL_TRACE("PPPOptimizerDialog::PPPOptimizerDialog"); |
|
48} 49 50// ----------------------------------------------------------------------------- 51 52PPPOptimizerDialog::~PPPOptimizerDialog() 53{ | 57} 58 59// ----------------------------------------------------------------------------- 60 61PPPOptimizerDialog::~PPPOptimizerDialog() 62{ |
63 OSL_TRACE("PPPOptimizerDialog::~PPPOptimizerDialog"); |
|
54} 55 56// ----------------------------------------------------------------------------- 57// XInitialization 58// ----------------------------------------------------------------------------- 59 60void SAL_CALL PPPOptimizerDialog::initialize( const Sequence< Any >& aArguments ) 61 throw ( Exception, RuntimeException ) 62{ | 64} 65 66// ----------------------------------------------------------------------------- 67// XInitialization 68// ----------------------------------------------------------------------------- 69 70void SAL_CALL PPPOptimizerDialog::initialize( const Sequence< Any >& aArguments ) 71 throw ( Exception, RuntimeException ) 72{ |
63 if( aArguments.getLength() != 1 ) 64 throw IllegalArgumentException(); | 73 OSL_TRACE("PPPOptimizerDialog::initialize"); 74 osl::ResettableMutexGuard aGuard( m_aMutex ); 75 if ( mbInitialized ) 76 throw RuntimeException( 77 OUString( RTL_CONSTASCII_USTRINGPARAM( 78 "PPPOptimizerDialog has already been initialized!") ), 79 Reference< XInterface >() ); 80 aGuard.clear(); |
65 | 81 |
66 aArguments[ 0 ] >>= mxFrame; 67 if ( mxFrame.is() ) 68 mxController = mxFrame->getController(); | 82 Reference< XFrame > xFrame; 83 Reference< XController > xController; 84 Reference< XModel > xModel; 85 Reference< XWindow > xWindow; 86 87 const Any *pAny = aArguments.getConstArray(); 88 const Any *pEnd = pAny + aArguments.getLength(); 89 for ( ; pAny != pEnd && !xFrame.is() && !xWindow.is(); pAny++ ) 90 { 91 if ( ( *pAny >>= xFrame ) && xFrame.is() ) 92 { 93 xWindow = xFrame->getContainerWindow(); 94 } 95 else if ( ( *pAny >>= xController ) && xController.is() ) 96 { 97 xFrame = xController->getFrame(); 98 if ( xFrame.is() ) 99 xWindow = xFrame->getContainerWindow(); 100 } 101 else if ( ( *pAny >>= xModel ) && xModel.is() ) 102 { 103 xController = xModel->getCurrentController(); 104 if ( xController.is() ) 105 { 106 xFrame = xController->getFrame(); 107 if ( xFrame.is() ) 108 xWindow = xFrame->getContainerWindow(); 109 } 110 } 111 else 112 *pAny >>= xWindow; 113 } 114 115 if ( !xFrame.is() ) 116 throw IllegalArgumentException( 117 OUString( RTL_CONSTASCII_USTRINGPARAM( 118 "PPPOptimizerDialog must be initialized with an " 119 "XFrame, XController or XModel!") ), 120 Reference< XInterface >(), 0 ); 121 122 aGuard.reset(); 123 mxFrame = xFrame; 124 mxParentWindow.set( xWindow, UNO_QUERY ); 125 mbInitialized = true; 126 aGuard.clear(); |
69} 70 71// ----------------------------------------------------------------------------- 72// XServiceInfo 73// ----------------------------------------------------------------------------- 74 75OUString SAL_CALL PPPOptimizerDialog::getImplementationName() 76 throw (RuntimeException) --- 8 unchanged lines hidden (view full) --- 85} 86 87Sequence< OUString > SAL_CALL PPPOptimizerDialog::getSupportedServiceNames() 88 throw (RuntimeException) 89{ 90 return PPPOptimizerDialog_getSupportedServiceNames(); 91} 92 | 127} 128 129// ----------------------------------------------------------------------------- 130// XServiceInfo 131// ----------------------------------------------------------------------------- 132 133OUString SAL_CALL PPPOptimizerDialog::getImplementationName() 134 throw (RuntimeException) --- 8 unchanged lines hidden (view full) --- 143} 144 145Sequence< OUString > SAL_CALL PPPOptimizerDialog::getSupportedServiceNames() 146 throw (RuntimeException) 147{ 148 return PPPOptimizerDialog_getSupportedServiceNames(); 149} 150 |
93// ----------------------------------------------------------------------------- 94// XDispatchProvider 95// ----------------------------------------------------------------------------- | |
96 | 151 |
97Reference< com::sun::star::frame::XDispatch > SAL_CALL PPPOptimizerDialog::queryDispatch( 98 const URL& aURL, const ::rtl::OUString& /* aTargetFrameName */, sal_Int32 /* nSearchFlags */ ) throw( RuntimeException ) | 152void SAL_CALL PPPOptimizerDialog::setTitle( const ::rtl::OUString& aTitle ) 153throw (::com::sun::star::uno::RuntimeException) |
99{ | 154{ |
100 Reference < XDispatch > xRet; 101 if ( aURL.Protocol.compareToAscii( "vnd.com.sun.star.comp.SunPresentationMinimizer:" ) == 0 ) 102 xRet = this; 103 104 return xRet; | 155 osl::MutexGuard aGuard( m_aMutex ); 156 msTitle = aTitle; |
105} 106 | 157} 158 |
107//------------------------------------------------------------------------------ 108 109Sequence< Reference< com::sun::star::frame::XDispatch > > SAL_CALL PPPOptimizerDialog::queryDispatches( 110 const Sequence< com::sun::star::frame::DispatchDescriptor >& aDescripts ) throw( RuntimeException ) | 159::sal_Int16 SAL_CALL PPPOptimizerDialog::execute( ) 160throw (::com::sun::star::uno::RuntimeException) |
111{ | 161{ |
112 Sequence< Reference< com::sun::star::frame::XDispatch> > aReturn( aDescripts.getLength() ); 113 Reference< com::sun::star::frame::XDispatch>* pReturn = aReturn.getArray(); 114 const com::sun::star::frame::DispatchDescriptor* pDescripts = aDescripts.getConstArray(); 115 for (sal_Int16 i = 0; i < aDescripts.getLength(); ++i, ++pReturn, ++pDescripts ) 116 { 117 *pReturn = queryDispatch( pDescripts->FeatureURL, pDescripts->FrameName, pDescripts->SearchFlags ); 118 } 119 return aReturn; 120} | 162 OSL_TRACE("PPPOptimizerDialog::execute"); 163 sal_Int16 aRet = ::com::sun::star::ui::dialogs::ExecutableDialogResults::CANCEL; |
121 | 164 |
122// ----------------------------------------------------------------------------- 123// XDispatch 124// ----------------------------------------------------------------------------- | 165 osl::ClearableMutexGuard aGuard( m_aMutex ); 166 bool bInit( mbInitialized ); 167 Reference< XFrame > xFrame( mxFrame ); 168 Reference< XWindowPeer > xParent( mxParentWindow ); 169 aGuard.clear(); |
125 | 170 |
126void SAL_CALL PPPOptimizerDialog::dispatch( const URL& rURL, 127 const Sequence< PropertyValue >& rArguments ) 128 throw( RuntimeException ) 129{ 130 sal_Int64 nFileSizeSource = 0; 131 sal_Int64 nFileSizeDest = 0; | 171 if ( !bInit || !xFrame.is() || !xParent.is() ) 172 throw RuntimeException(); 173 try 174 { 175 OptimizerDialog *pDialog( 176 new OptimizerDialog( m_xContext, xFrame, xParent ) ); 177 pDialog->setTitle( msTitle ); 178 aRet = pDialog->execute(); 179 delete pDialog; 180 } 181 catch( ... ) 182 { 183 } |
132 | 184 |
133 if ( mxController.is() && ( rURL.Protocol.compareToAscii( "vnd.com.sun.star.comp.SunPresentationMinimizer:" ) == 0 ) ) 134 { 135 if ( rURL.Path.compareToAscii( "execute" ) == 0 ) 136 { 137 sal_Bool bDialogExecuted = sal_False; 138 139 try 140 { 141 mpOptimizerDialog = new OptimizerDialog( mxMSF, mxFrame, this ); 142 bDialogExecuted = mpOptimizerDialog->execute(); 143 144 const Any* pVal( mpOptimizerDialog->maStats.GetStatusValue( TK_FileSizeSource ) ); 145 if ( pVal ) 146 *pVal >>= nFileSizeSource; 147 pVal = mpOptimizerDialog->maStats.GetStatusValue( TK_FileSizeDestination ); 148 if ( pVal ) 149 *pVal >>= nFileSizeDest; 150 151 if ( nFileSizeSource && nFileSizeDest ) 152 { 153 rtl::OUStringBuffer sBuf( rtl::OUString::createFromAscii( "Your Presentation has been minimized from:" ) ); 154 sBuf.append( rtl::OUString::valueOf( nFileSizeSource >> 10 ) ); 155 sBuf.append( rtl::OUString::createFromAscii( "KB to " ) ); 156 sBuf.append( rtl::OUString::valueOf( nFileSizeDest >> 10 ) ); 157 sBuf.append( rtl::OUString::createFromAscii( "KB." ) ); 158 OUString sResult( sBuf.makeStringAndClear() ); 159// mpOptimizerDialog->showMessageBox( sResult, sResult, sal_False ); 160 } 161 delete mpOptimizerDialog, mpOptimizerDialog = NULL; 162 } 163 catch( ... ) 164 { 165 166 } 167 } 168 else if ( rURL.Path.compareToAscii( "statusupdate" ) == 0 ) 169 { 170 if ( mpOptimizerDialog ) 171 mpOptimizerDialog->UpdateStatus( rArguments ); 172 } 173 } | 185 return aRet; |
174} 175 | 186} 187 |
176//=============================================== 177void SAL_CALL PPPOptimizerDialog::addStatusListener( const Reference< XStatusListener >&, const URL& ) 178 throw( RuntimeException ) 179{ 180 // TODO 181 // OSL_ENSURE( sal_False, "PPPOptimizerDialog::addStatusListener()\nNot implemented yet!" ); 182} 183 184//=============================================== 185void SAL_CALL PPPOptimizerDialog::removeStatusListener( const Reference< XStatusListener >&, const URL& ) 186 throw( RuntimeException ) 187{ 188 // TODO 189 // OSL_ENSURE( sal_False, "PPPOptimizerDialog::removeStatusListener()\nNot implemented yet!" ); 190} 191 | |
192// ----------------------------------------------------------------------------- 193 194OUString PPPOptimizerDialog_getImplementationName() 195{ | 188// ----------------------------------------------------------------------------- 189 190OUString PPPOptimizerDialog_getImplementationName() 191{ |
196 return OUString ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.comp.SunPresentationMinimizerImp" ) ); | 192 return OUString ( RTL_CONSTASCII_USTRINGPARAM ( IMPLEMENTATION_NAME ) ); |
197} 198 199Sequence< OUString > PPPOptimizerDialog_getSupportedServiceNames() 200{ 201 Sequence < OUString > aRet(1); 202 OUString* pArray = aRet.getArray(); 203 pArray[0] = OUString ( RTL_CONSTASCII_USTRINGPARAM( SERVICE_NAME ) ); 204 return aRet; 205} 206 207Reference< XInterface > PPPOptimizerDialog_createInstance( const Reference< XComponentContext > & rSMgr) 208 throw( Exception ) 209{ 210 return (cppu::OWeakObject*) new PPPOptimizerDialog( rSMgr ); 211} 212 213// ----------------------------------------------------------------------------- | 193} 194 195Sequence< OUString > PPPOptimizerDialog_getSupportedServiceNames() 196{ 197 Sequence < OUString > aRet(1); 198 OUString* pArray = aRet.getArray(); 199 pArray[0] = OUString ( RTL_CONSTASCII_USTRINGPARAM( SERVICE_NAME ) ); 200 return aRet; 201} 202 203Reference< XInterface > PPPOptimizerDialog_createInstance( const Reference< XComponentContext > & rSMgr) 204 throw( Exception ) 205{ 206 return (cppu::OWeakObject*) new PPPOptimizerDialog( rSMgr ); 207} 208 209// ----------------------------------------------------------------------------- |