1c142477cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3c142477cSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4c142477cSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5c142477cSAndrew Rist  * distributed with this work for additional information
6c142477cSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7c142477cSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8c142477cSAndrew Rist  * "License"); you may not use this file except in compliance
9c142477cSAndrew Rist  * with the License.  You may obtain a copy of the License at
10c142477cSAndrew Rist  *
11c142477cSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12c142477cSAndrew Rist  *
13c142477cSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14c142477cSAndrew Rist  * software distributed under the License is distributed on an
15c142477cSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16c142477cSAndrew Rist  * KIND, either express or implied.  See the License for the
17c142477cSAndrew Rist  * specific language governing permissions and limitations
18c142477cSAndrew Rist  * under the License.
19c142477cSAndrew Rist  *
20c142477cSAndrew Rist  *************************************************************/
21c142477cSAndrew Rist 
22c142477cSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sdext.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "pppoptimizer.hxx"
28cdf0e10cSrcweir #include "impoptimizer.hxx"
29cdf0e10cSrcweir #include <osl/file.hxx>
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #include <com/sun/star/lang/IllegalArgumentException.hpp>
32cdf0e10cSrcweir 
33*8c5bb9c6SAriel Constenla-Haile #define SERVICE_NAME "com.sun.star.presentation.PresentationOptimizer"
34597a4c59SAriel Constenla-Haile 
35597a4c59SAriel Constenla-Haile 
36cdf0e10cSrcweir using namespace ::com::sun::star::uno;
37cdf0e10cSrcweir using namespace ::com::sun::star::util;
38cdf0e10cSrcweir using namespace ::com::sun::star::lang;
39cdf0e10cSrcweir using namespace ::com::sun::star::frame;
40cdf0e10cSrcweir using namespace ::com::sun::star::beans;
41cdf0e10cSrcweir 
42597a4c59SAriel Constenla-Haile using ::rtl::OUString;
43cdf0e10cSrcweir 
44cdf0e10cSrcweir // ----------------
45cdf0e10cSrcweir // - PPPOptimizer -
46cdf0e10cSrcweir // ----------------
47cdf0e10cSrcweir 
PPPOptimizer(const Reference<XComponentContext> & rxContext)48597a4c59SAriel Constenla-Haile PPPOptimizer::PPPOptimizer( const Reference< XComponentContext > &rxContext ) :
49597a4c59SAriel Constenla-Haile     mxContext( rxContext )
50cdf0e10cSrcweir {
51597a4c59SAriel Constenla-Haile     OSL_TRACE("PPPOptimizer::PPPOptimizer");
52cdf0e10cSrcweir }
53cdf0e10cSrcweir 
54cdf0e10cSrcweir // -----------------------------------------------------------------------------
55cdf0e10cSrcweir 
~PPPOptimizer()56cdf0e10cSrcweir PPPOptimizer::~PPPOptimizer()
57cdf0e10cSrcweir {
58597a4c59SAriel Constenla-Haile     OSL_TRACE("PPPOptimizer::~PPPOptimizer");
59cdf0e10cSrcweir }
60cdf0e10cSrcweir 
61cdf0e10cSrcweir // -----------------------------------------------------------------------------
62cdf0e10cSrcweir // XInitialization
63cdf0e10cSrcweir // -----------------------------------------------------------------------------
64cdf0e10cSrcweir 
initialize(const Sequence<Any> & aArguments)65cdf0e10cSrcweir void SAL_CALL PPPOptimizer::initialize( const Sequence< Any >& aArguments )
66cdf0e10cSrcweir 	throw ( Exception, RuntimeException )
67cdf0e10cSrcweir {
68597a4c59SAriel Constenla-Haile     OSL_TRACE("PPPOptimizer::initialize");
69cdf0e10cSrcweir 	if( aArguments.getLength() != 1 )
70cdf0e10cSrcweir 		throw IllegalArgumentException();
71cdf0e10cSrcweir 
72cdf0e10cSrcweir 	Reference< XFrame > xFrame;
73cdf0e10cSrcweir 	aArguments[ 0 ] >>= xFrame;
74cdf0e10cSrcweir 	if ( xFrame.is() )
75cdf0e10cSrcweir 		mxController = xFrame->getController();
76cdf0e10cSrcweir }
77cdf0e10cSrcweir 
78cdf0e10cSrcweir // -----------------------------------------------------------------------------
79cdf0e10cSrcweir // XServiceInfo
80cdf0e10cSrcweir // -----------------------------------------------------------------------------
81cdf0e10cSrcweir 
getImplementationName()82cdf0e10cSrcweir OUString SAL_CALL PPPOptimizer::getImplementationName()
83cdf0e10cSrcweir 	throw ( RuntimeException )
84cdf0e10cSrcweir {
85cdf0e10cSrcweir 	return PPPOptimizer_getImplementationName();
86cdf0e10cSrcweir }
87cdf0e10cSrcweir 
supportsService(const OUString & rServiceName)88cdf0e10cSrcweir sal_Bool SAL_CALL PPPOptimizer::supportsService( const OUString& rServiceName )
89cdf0e10cSrcweir 	throw ( RuntimeException )
90cdf0e10cSrcweir {
91cdf0e10cSrcweir     return rServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( SERVICE_NAME ) );
92cdf0e10cSrcweir }
93cdf0e10cSrcweir 
getSupportedServiceNames()94cdf0e10cSrcweir Sequence< OUString > SAL_CALL PPPOptimizer::getSupportedServiceNames()
95cdf0e10cSrcweir 	throw ( RuntimeException )
96cdf0e10cSrcweir {
97cdf0e10cSrcweir     return PPPOptimizer_getSupportedServiceNames();
98cdf0e10cSrcweir }
99cdf0e10cSrcweir 
100cdf0e10cSrcweir // -----------------------------------------------------------------------------
101cdf0e10cSrcweir // XDispatchProvider
102cdf0e10cSrcweir // -----------------------------------------------------------------------------
103cdf0e10cSrcweir 
queryDispatch(const URL & aURL,const::rtl::OUString &,sal_Int32)104cdf0e10cSrcweir Reference< com::sun::star::frame::XDispatch > SAL_CALL PPPOptimizer::queryDispatch(
105cdf0e10cSrcweir 	const URL& aURL, const ::rtl::OUString& /* aTargetFrameName */, sal_Int32 /* nSearchFlags */ ) throw( RuntimeException )
106cdf0e10cSrcweir {
107cdf0e10cSrcweir 	Reference < XDispatch > xRet;
108*8c5bb9c6SAriel Constenla-Haile     if ( aURL.Protocol.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(
109*8c5bb9c6SAriel Constenla-Haile         "vnd.com.sun.star.presentation.PresentationOptimizer:" ) ) )
110cdf0e10cSrcweir     {
111cdf0e10cSrcweir //		if ( aURL.Path.compareToAscii( "Function1" ) == 0 )
112cdf0e10cSrcweir 		xRet = this;
113cdf0e10cSrcweir     }
114cdf0e10cSrcweir 	return xRet;
115cdf0e10cSrcweir }
116cdf0e10cSrcweir 
117cdf0e10cSrcweir //------------------------------------------------------------------------------
118cdf0e10cSrcweir 
queryDispatches(const Sequence<com::sun::star::frame::DispatchDescriptor> & aDescripts)119cdf0e10cSrcweir Sequence< Reference< com::sun::star::frame::XDispatch > > SAL_CALL PPPOptimizer::queryDispatches(
120cdf0e10cSrcweir 	const Sequence< com::sun::star::frame::DispatchDescriptor >& aDescripts ) throw( RuntimeException )
121cdf0e10cSrcweir {
122cdf0e10cSrcweir 	Sequence< Reference< com::sun::star::frame::XDispatch> > aReturn( aDescripts.getLength() );
123cdf0e10cSrcweir 	Reference< com::sun::star::frame::XDispatch>* pReturn = aReturn.getArray();
124cdf0e10cSrcweir 	const com::sun::star::frame::DispatchDescriptor* pDescripts = aDescripts.getConstArray();
125cdf0e10cSrcweir 	for (sal_Int16 i = 0; i < aDescripts.getLength(); ++i, ++pReturn, ++pDescripts )
126cdf0e10cSrcweir 	{
127cdf0e10cSrcweir 		*pReturn = queryDispatch( pDescripts->FeatureURL, pDescripts->FrameName, pDescripts->SearchFlags );
128cdf0e10cSrcweir 	}
129cdf0e10cSrcweir 	return aReturn;
130cdf0e10cSrcweir }
131cdf0e10cSrcweir 
132cdf0e10cSrcweir // -----------------------------------------------------------------------------
133cdf0e10cSrcweir // XDispatch
134cdf0e10cSrcweir // -----------------------------------------------------------------------------
135cdf0e10cSrcweir 
dispatch(const URL & rURL,const Sequence<PropertyValue> & lArguments)136cdf0e10cSrcweir void SAL_CALL PPPOptimizer::dispatch( const URL& rURL, const Sequence< PropertyValue >& lArguments )
137cdf0e10cSrcweir     throw( RuntimeException )
138cdf0e10cSrcweir {
139597a4c59SAriel Constenla-Haile     OSL_TRACE("PPPOptimizer::dispatch");
140*8c5bb9c6SAriel Constenla-Haile 	if ( mxController.is() && rURL.Protocol.equalsAsciiL(
141*8c5bb9c6SAriel Constenla-Haile         RTL_CONSTASCII_STRINGPARAM(
142*8c5bb9c6SAriel Constenla-Haile             "vnd.com.sun.star.presentation.PresentationOptimizer:" )))
143cdf0e10cSrcweir 	{
144*8c5bb9c6SAriel Constenla-Haile 		if ( rURL.Path.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("optimize") ) )
145cdf0e10cSrcweir 		{
146cdf0e10cSrcweir 			Reference< XModel > xModel( mxController->getModel() );
147cdf0e10cSrcweir 			if ( xModel.is() )
148cdf0e10cSrcweir 			{
149cdf0e10cSrcweir 				try
150cdf0e10cSrcweir 				{
151597a4c59SAriel Constenla-Haile 					ImpOptimizer aOptimizer( mxContext, xModel );
152cdf0e10cSrcweir 					aOptimizer.Optimize( lArguments );
153cdf0e10cSrcweir 				}
154cdf0e10cSrcweir 				catch( Exception& )
155cdf0e10cSrcweir 				{
156cdf0e10cSrcweir 				}
157cdf0e10cSrcweir 			}
158cdf0e10cSrcweir 		}
159cdf0e10cSrcweir 	}
160cdf0e10cSrcweir }
161cdf0e10cSrcweir 
162cdf0e10cSrcweir //===============================================
addStatusListener(const Reference<XStatusListener> &,const URL &)163cdf0e10cSrcweir void SAL_CALL PPPOptimizer::addStatusListener( const Reference< XStatusListener >&, const URL& )
164cdf0e10cSrcweir 	throw( RuntimeException )
165cdf0e10cSrcweir {
166cdf0e10cSrcweir     // TODO
167cdf0e10cSrcweir     OSL_ENSURE( sal_False, "PPPOptimizer::addStatusListener()\nNot implemented yet!" );
168cdf0e10cSrcweir }
169cdf0e10cSrcweir 
170cdf0e10cSrcweir //===============================================
removeStatusListener(const Reference<XStatusListener> &,const URL &)171cdf0e10cSrcweir void SAL_CALL PPPOptimizer::removeStatusListener( const Reference< XStatusListener >&, const URL& )
172cdf0e10cSrcweir     throw( RuntimeException )
173cdf0e10cSrcweir {
174cdf0e10cSrcweir     // TODO
175cdf0e10cSrcweir     OSL_ENSURE( sal_False, "PPPOptimizer::removeStatusListener()\nNot implemented yet!" );
176cdf0e10cSrcweir }
177cdf0e10cSrcweir 
178cdf0e10cSrcweir // -----------------------------------------------------------------------------
179cdf0e10cSrcweir // returning filesize, on error zero is returned
GetFileSize(const rtl::OUString & rURL)180cdf0e10cSrcweir sal_Int64 PPPOptimizer::GetFileSize( const rtl::OUString& rURL )
181cdf0e10cSrcweir {
182cdf0e10cSrcweir 	sal_Int64 nFileSize = 0;
183cdf0e10cSrcweir 	osl::DirectoryItem aItem;
184cdf0e10cSrcweir 	if ( osl::DirectoryItem::get( rURL, aItem ) == osl::FileBase::E_None )
185cdf0e10cSrcweir 	{
186cdf0e10cSrcweir 		osl::FileStatus aStatus( osl_FileStatus_Mask_FileSize );
187cdf0e10cSrcweir 		if ( aItem.getFileStatus( aStatus ) == osl::FileBase::E_None )
188cdf0e10cSrcweir 		{
189cdf0e10cSrcweir 			nFileSize = aStatus.getFileSize();
190cdf0e10cSrcweir 		}
191cdf0e10cSrcweir 	}
192cdf0e10cSrcweir 	return nFileSize;
193cdf0e10cSrcweir }
194cdf0e10cSrcweir 
195cdf0e10cSrcweir // -----------------------------------------------------------------------------
196cdf0e10cSrcweir 
PPPOptimizer_getImplementationName()197cdf0e10cSrcweir OUString PPPOptimizer_getImplementationName()
198cdf0e10cSrcweir {
199*8c5bb9c6SAriel Constenla-Haile 	return OUString ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.comp.presentation.PresentationOptimizer" ) );
200cdf0e10cSrcweir }
201cdf0e10cSrcweir 
PPPOptimizer_getSupportedServiceNames()202cdf0e10cSrcweir Sequence< OUString > PPPOptimizer_getSupportedServiceNames()
203cdf0e10cSrcweir {
204cdf0e10cSrcweir 	Sequence < OUString > aRet(1);
205cdf0e10cSrcweir     OUString* pArray = aRet.getArray();
206cdf0e10cSrcweir     pArray[0] =  OUString ( RTL_CONSTASCII_USTRINGPARAM( SERVICE_NAME ) );
207cdf0e10cSrcweir     return aRet;
208cdf0e10cSrcweir }
209cdf0e10cSrcweir 
PPPOptimizer_createInstance(const Reference<XComponentContext> & rSMgr)210cdf0e10cSrcweir Reference< XInterface > PPPOptimizer_createInstance( const Reference< XComponentContext > & rSMgr )
211cdf0e10cSrcweir 	throw( Exception )
212cdf0e10cSrcweir {
213cdf0e10cSrcweir 	return (cppu::OWeakObject*) new PPPOptimizer( rSMgr );
214cdf0e10cSrcweir }
215