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