1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: pppoptimizerdialog.cxx,v $
13 * This file is part of OpenOffice.org.
15 * OpenOffice.org is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU Lesser General Public License version 3
17 * only, as published by the Free Software Foundation.
19 * OpenOffice.org is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Lesser General Public License version 3 for more details
23 * (a copy is included in the LICENSE file that accompanied this code).
25 * You should have received a copy of the GNU Lesser General Public License
26 * version 3 along with OpenOffice.org. If not, see
27 * <http://www.openoffice.org/license.html>
28 * for a copy of the LGPLv3 License.
30 ************************************************************************/
32 // MARKER(update_precomp.py): autogen include statement, do not remove
33 #include "precompiled_sdext.hxx"
35 #include "pppoptimizerdialog.hxx"
36 #include "optimizerdialog.hxx"
37 #include "aboutdialog.hxx"
39 using namespace ::rtl
;
40 using namespace ::com::sun::star::uno
;
41 using namespace ::com::sun::star::util
;
42 using namespace ::com::sun::star::lang
;
43 using namespace ::com::sun::star::frame
;
44 using namespace ::com::sun::star::beans
;
46 #define SERVICE_NAME "com.sun.star.comp.SunPresentationMinimizer"
47 #include <rtl/ustrbuf.hxx>
49 // ----------------------
50 // - PPPOptimizerDialog -
51 // ----------------------
53 PPPOptimizerDialog::PPPOptimizerDialog( const Reference
< XComponentContext
> &rxMSF
) :
55 mpOptimizerDialog( NULL
)
59 // -----------------------------------------------------------------------------
61 PPPOptimizerDialog::~PPPOptimizerDialog()
65 // -----------------------------------------------------------------------------
67 // -----------------------------------------------------------------------------
69 void SAL_CALL
PPPOptimizerDialog::initialize( const Sequence
< Any
>& aArguments
)
70 throw ( Exception
, RuntimeException
)
72 if( aArguments
.getLength() != 1 )
73 throw IllegalArgumentException();
75 aArguments
[ 0 ] >>= mxFrame
;
77 mxController
= mxFrame
->getController();
80 // -----------------------------------------------------------------------------
82 // -----------------------------------------------------------------------------
84 OUString SAL_CALL
PPPOptimizerDialog::getImplementationName()
85 throw (RuntimeException
)
87 return PPPOptimizerDialog_getImplementationName();
90 sal_Bool SAL_CALL
PPPOptimizerDialog::supportsService( const OUString
& ServiceName
)
91 throw ( RuntimeException
)
93 return ServiceName
.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( SERVICE_NAME
) );
96 Sequence
< OUString
> SAL_CALL
PPPOptimizerDialog::getSupportedServiceNames()
97 throw (RuntimeException
)
99 return PPPOptimizerDialog_getSupportedServiceNames();
102 // -----------------------------------------------------------------------------
104 // -----------------------------------------------------------------------------
106 Reference
< com::sun::star::frame::XDispatch
> SAL_CALL
PPPOptimizerDialog::queryDispatch(
107 const URL
& aURL
, const ::rtl::OUString
& /* aTargetFrameName */, sal_Int32
/* nSearchFlags */ ) throw( RuntimeException
)
109 Reference
< XDispatch
> xRet
;
110 if ( aURL
.Protocol
.compareToAscii( "vnd.com.sun.star.comp.SunPresentationMinimizer:" ) == 0 )
116 //------------------------------------------------------------------------------
118 Sequence
< Reference
< com::sun::star::frame::XDispatch
> > SAL_CALL
PPPOptimizerDialog::queryDispatches(
119 const Sequence
< com::sun::star::frame::DispatchDescriptor
>& aDescripts
) throw( RuntimeException
)
121 Sequence
< Reference
< com::sun::star::frame::XDispatch
> > aReturn( aDescripts
.getLength() );
122 Reference
< com::sun::star::frame::XDispatch
>* pReturn
= aReturn
.getArray();
123 const com::sun::star::frame::DispatchDescriptor
* pDescripts
= aDescripts
.getConstArray();
124 for (sal_Int16 i
= 0; i
< aDescripts
.getLength(); ++i
, ++pReturn
, ++pDescripts
)
126 *pReturn
= queryDispatch( pDescripts
->FeatureURL
, pDescripts
->FrameName
, pDescripts
->SearchFlags
);
131 // -----------------------------------------------------------------------------
133 // -----------------------------------------------------------------------------
135 void SAL_CALL
PPPOptimizerDialog::dispatch( const URL
& rURL
,
136 const Sequence
< PropertyValue
>& rArguments
)
137 throw( RuntimeException
)
139 sal_Int64 nFileSizeSource
= 0;
140 sal_Int64 nFileSizeDest
= 0;
142 if ( mxController
.is() && ( rURL
.Protocol
.compareToAscii( "vnd.com.sun.star.comp.SunPresentationMinimizer:" ) == 0 ) )
144 if ( rURL
.Path
.compareToAscii( "execute" ) == 0 )
146 sal_Bool bDialogExecuted
= sal_False
;
150 mpOptimizerDialog
= new OptimizerDialog( mxMSF
, mxFrame
, this );
151 bDialogExecuted
= mpOptimizerDialog
->execute();
153 const Any
* pVal( mpOptimizerDialog
->maStats
.GetStatusValue( TK_FileSizeSource
) );
155 *pVal
>>= nFileSizeSource
;
156 pVal
= mpOptimizerDialog
->maStats
.GetStatusValue( TK_FileSizeDestination
);
158 *pVal
>>= nFileSizeDest
;
160 if ( nFileSizeSource
&& nFileSizeDest
)
162 rtl::OUStringBuffer
sBuf( rtl::OUString::createFromAscii( "Your Presentation has been minimized from:" ) );
163 sBuf
.append( rtl::OUString::valueOf( nFileSizeSource
>> 10 ) );
164 sBuf
.append( rtl::OUString::createFromAscii( "KB to " ) );
165 sBuf
.append( rtl::OUString::valueOf( nFileSizeDest
>> 10 ) );
166 sBuf
.append( rtl::OUString::createFromAscii( "KB." ) );
167 OUString
sResult( sBuf
.makeStringAndClear() );
168 // mpOptimizerDialog->showMessageBox( sResult, sResult, sal_False );
170 delete mpOptimizerDialog
, mpOptimizerDialog
= NULL
;
177 else if ( rURL
.Path
.compareToAscii( "statusupdate" ) == 0 )
179 if ( mpOptimizerDialog
)
180 mpOptimizerDialog
->UpdateStatus( rArguments
);
182 else if ( rURL
.Path
.compareToAscii( "about" ) == 0 )
184 AboutDialog
aAboutDialog( mxMSF
, mxFrame
);
185 aAboutDialog
.execute();
190 //===============================================
191 void SAL_CALL
PPPOptimizerDialog::addStatusListener( const Reference
< XStatusListener
>&, const URL
& )
192 throw( RuntimeException
)
195 // OSL_ENSURE( sal_False, "PPPOptimizerDialog::addStatusListener()\nNot implemented yet!" );
198 //===============================================
199 void SAL_CALL
PPPOptimizerDialog::removeStatusListener( const Reference
< XStatusListener
>&, const URL
& )
200 throw( RuntimeException
)
203 // OSL_ENSURE( sal_False, "PPPOptimizerDialog::removeStatusListener()\nNot implemented yet!" );
206 // -----------------------------------------------------------------------------
208 OUString
PPPOptimizerDialog_getImplementationName()
210 return OUString ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.comp.SunPresentationMinimizerImp" ) );
213 Sequence
< OUString
> PPPOptimizerDialog_getSupportedServiceNames()
215 Sequence
< OUString
> aRet(1);
216 OUString
* pArray
= aRet
.getArray();
217 pArray
[0] = OUString ( RTL_CONSTASCII_USTRINGPARAM( SERVICE_NAME
) );
221 Reference
< XInterface
> PPPOptimizerDialog_createInstance( const Reference
< XComponentContext
> & rSMgr
)
224 return (cppu::OWeakObject
*) new PPPOptimizerDialog( rSMgr
);
227 // -----------------------------------------------------------------------------