xref: /trunk/main/sdext/source/minimizer/pppoptimizer.cxx (revision 45c5a00162811bd03b87fcb4fe9996782f2b59ec)
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 
48 PPPOptimizer::PPPOptimizer( const Reference< XComponentContext > &rxContext ) :
49     mxContext( rxContext )
50 {
51     OSL_TRACE("PPPOptimizer::PPPOptimizer");
52 }
53 
54 // -----------------------------------------------------------------------------
55 
56 PPPOptimizer::~PPPOptimizer()
57 {
58     OSL_TRACE("PPPOptimizer::~PPPOptimizer");
59 }
60 
61 // -----------------------------------------------------------------------------
62 // XInitialization
63 // -----------------------------------------------------------------------------
64 
65 void SAL_CALL PPPOptimizer::initialize( const Sequence< Any >& aArguments )
66 {
67     OSL_TRACE("PPPOptimizer::initialize");
68     if( aArguments.getLength() != 1 )
69         throw IllegalArgumentException();
70 
71     Reference< XFrame > xFrame;
72     aArguments[ 0 ] >>= xFrame;
73     if ( xFrame.is() )
74         mxController = xFrame->getController();
75 }
76 
77 // -----------------------------------------------------------------------------
78 // XServiceInfo
79 // -----------------------------------------------------------------------------
80 
81 OUString SAL_CALL PPPOptimizer::getImplementationName()
82 {
83     return PPPOptimizer_getImplementationName();
84 }
85 
86 sal_Bool SAL_CALL PPPOptimizer::supportsService( const OUString& rServiceName )
87 {
88     return rServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( SERVICE_NAME ) );
89 }
90 
91 Sequence< OUString > SAL_CALL PPPOptimizer::getSupportedServiceNames()
92 {
93     return PPPOptimizer_getSupportedServiceNames();
94 }
95 
96 // -----------------------------------------------------------------------------
97 // XDispatchProvider
98 // -----------------------------------------------------------------------------
99 
100 Reference< com::sun::star::frame::XDispatch > SAL_CALL PPPOptimizer::queryDispatch(
101     const URL& aURL, const ::rtl::OUString& /* aTargetFrameName */, sal_Int32 /* nSearchFlags */ )
102 {
103     Reference < XDispatch > xRet;
104     if ( aURL.Protocol.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(
105         "vnd.com.sun.star.presentation.PresentationOptimizer:" ) ) )
106     {
107 //      if ( aURL.Path.compareToAscii( "Function1" ) == 0 )
108         xRet = this;
109     }
110     return xRet;
111 }
112 
113 //------------------------------------------------------------------------------
114 
115 Sequence< Reference< com::sun::star::frame::XDispatch > > SAL_CALL PPPOptimizer::queryDispatches(
116     const Sequence< com::sun::star::frame::DispatchDescriptor >& aDescripts )
117 {
118     Sequence< Reference< com::sun::star::frame::XDispatch> > aReturn( aDescripts.getLength() );
119     Reference< com::sun::star::frame::XDispatch>* pReturn = aReturn.getArray();
120     const com::sun::star::frame::DispatchDescriptor* pDescripts = aDescripts.getConstArray();
121     for (sal_Int16 i = 0; i < aDescripts.getLength(); ++i, ++pReturn, ++pDescripts )
122     {
123         *pReturn = queryDispatch( pDescripts->FeatureURL, pDescripts->FrameName, pDescripts->SearchFlags );
124     }
125     return aReturn;
126 }
127 
128 // -----------------------------------------------------------------------------
129 // XDispatch
130 // -----------------------------------------------------------------------------
131 
132 void SAL_CALL PPPOptimizer::dispatch( const URL& rURL, const Sequence< PropertyValue >& lArguments )
133 {
134     OSL_TRACE("PPPOptimizer::dispatch");
135     if ( mxController.is() && rURL.Protocol.equalsAsciiL(
136         RTL_CONSTASCII_STRINGPARAM(
137             "vnd.com.sun.star.presentation.PresentationOptimizer:" )))
138     {
139         if ( rURL.Path.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("optimize") ) )
140         {
141             Reference< XModel > xModel( mxController->getModel() );
142             if ( xModel.is() )
143             {
144                 try
145                 {
146                     ImpOptimizer aOptimizer( mxContext, xModel );
147                     aOptimizer.Optimize( lArguments );
148                 }
149                 catch( Exception& )
150                 {
151                 }
152             }
153         }
154     }
155 }
156 
157 //===============================================
158 void SAL_CALL PPPOptimizer::addStatusListener( const Reference< XStatusListener >&, const URL& )
159 {
160     // TODO
161     OSL_ENSURE( sal_False, "PPPOptimizer::addStatusListener()\nNot implemented yet!" );
162 }
163 
164 //===============================================
165 void SAL_CALL PPPOptimizer::removeStatusListener( const Reference< XStatusListener >&, const URL& )
166 {
167     // TODO
168     OSL_ENSURE( sal_False, "PPPOptimizer::removeStatusListener()\nNot implemented yet!" );
169 }
170 
171 // -----------------------------------------------------------------------------
172 // returning filesize, on error zero is returned
173 sal_Int64 PPPOptimizer::GetFileSize( const rtl::OUString& rURL )
174 {
175     sal_Int64 nFileSize = 0;
176     osl::DirectoryItem aItem;
177     if ( osl::DirectoryItem::get( rURL, aItem ) == osl::FileBase::E_None )
178     {
179         osl::FileStatus aStatus( osl_FileStatus_Mask_FileSize );
180         if ( aItem.getFileStatus( aStatus ) == osl::FileBase::E_None )
181         {
182             nFileSize = aStatus.getFileSize();
183         }
184     }
185     return nFileSize;
186 }
187 
188 // -----------------------------------------------------------------------------
189 
190 OUString PPPOptimizer_getImplementationName()
191 {
192     return OUString ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.comp.presentation.PresentationOptimizer" ) );
193 }
194 
195 Sequence< OUString > PPPOptimizer_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 
203 Reference< XInterface > PPPOptimizer_createInstance( const Reference< XComponentContext > & rSMgr )
204 {
205     return (cppu::OWeakObject*) new PPPOptimizer( rSMgr );
206 }
207