Updated core
[LibreOffice.git] / sdext / source / minimizer / pppoptimizer.cxx
blob3d7994e097e99cf943346062e6656e3aa0168aa5
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include "pppoptimizer.hxx"
22 #include "impoptimizer.hxx"
23 #include <osl/file.hxx>
25 #include <com/sun/star/lang/IllegalArgumentException.hpp>
27 using namespace ::rtl;
28 using namespace ::com::sun::star::uno;
29 using namespace ::com::sun::star::util;
30 using namespace ::com::sun::star::lang;
31 using namespace ::com::sun::star::frame;
32 using namespace ::com::sun::star::beans;
34 #define SERVICE_NAME "com.sun.star.comp.PPPOptimizer"
36 // ----------------
37 // - PPPOptimizer -
38 // ----------------
40 PPPOptimizer::PPPOptimizer( const Reference< XComponentContext > &rxMSF ) :
41 mxMSF( rxMSF )
45 // -----------------------------------------------------------------------------
47 PPPOptimizer::~PPPOptimizer()
51 // -----------------------------------------------------------------------------
52 // XInitialization
53 // -----------------------------------------------------------------------------
55 void SAL_CALL PPPOptimizer::initialize( const Sequence< Any >& aArguments )
56 throw ( Exception, RuntimeException )
58 if( aArguments.getLength() != 1 )
59 throw IllegalArgumentException();
61 Reference< XFrame > xFrame;
62 aArguments[ 0 ] >>= xFrame;
63 if ( xFrame.is() )
64 mxController = xFrame->getController();
67 // -----------------------------------------------------------------------------
68 // XServiceInfo
69 // -----------------------------------------------------------------------------
71 OUString SAL_CALL PPPOptimizer::getImplementationName()
72 throw ( RuntimeException )
74 return PPPOptimizer_getImplementationName();
77 sal_Bool SAL_CALL PPPOptimizer::supportsService( const OUString& rServiceName )
78 throw ( RuntimeException )
80 return rServiceName == SERVICE_NAME;
83 Sequence< OUString > SAL_CALL PPPOptimizer::getSupportedServiceNames()
84 throw ( RuntimeException )
86 return PPPOptimizer_getSupportedServiceNames();
89 // -----------------------------------------------------------------------------
90 // XDispatchProvider
91 // -----------------------------------------------------------------------------
93 Reference< com::sun::star::frame::XDispatch > SAL_CALL PPPOptimizer::queryDispatch(
94 const URL& aURL, const OUString& /* aTargetFrameName */, sal_Int32 /* nSearchFlags */ ) throw( RuntimeException )
96 Reference < XDispatch > xRet;
97 if ( aURL.Protocol.compareToAscii( "vnd.com.sun.star.comp.PPPOptimizer:" ) == 0 )
99 // if ( aURL.Path.compareToAscii( "Function1" ) == 0 )
100 xRet = this;
102 return xRet;
105 //------------------------------------------------------------------------------
107 Sequence< Reference< com::sun::star::frame::XDispatch > > SAL_CALL PPPOptimizer::queryDispatches(
108 const Sequence< com::sun::star::frame::DispatchDescriptor >& aDescripts ) throw( RuntimeException )
110 Sequence< Reference< com::sun::star::frame::XDispatch> > aReturn( aDescripts.getLength() );
111 Reference< com::sun::star::frame::XDispatch>* pReturn = aReturn.getArray();
112 const com::sun::star::frame::DispatchDescriptor* pDescripts = aDescripts.getConstArray();
113 for (sal_Int16 i = 0; i < aDescripts.getLength(); ++i, ++pReturn, ++pDescripts )
115 *pReturn = queryDispatch( pDescripts->FeatureURL, pDescripts->FrameName, pDescripts->SearchFlags );
117 return aReturn;
120 // -----------------------------------------------------------------------------
121 // XDispatch
122 // -----------------------------------------------------------------------------
124 void SAL_CALL PPPOptimizer::dispatch( const URL& rURL, const Sequence< PropertyValue >& lArguments )
125 throw( RuntimeException )
127 if ( mxController.is() && ( rURL.Protocol.compareToAscii( "vnd.com.sun.star.comp.PPPOptimizer:" ) == 0 ) )
129 if ( rURL.Path.compareToAscii( "optimize" ) == 0 )
131 Reference< XModel > xModel( mxController->getModel() );
132 if ( xModel.is() )
136 ImpOptimizer aOptimizer( mxMSF, xModel );
137 aOptimizer.Optimize( lArguments );
139 catch( Exception& )
147 //===============================================
148 void SAL_CALL PPPOptimizer::addStatusListener( const Reference< XStatusListener >&, const URL& )
149 throw( RuntimeException )
151 // TODO
152 OSL_FAIL( "PPPOptimizer::addStatusListener()\nNot implemented yet!" );
155 //===============================================
156 void SAL_CALL PPPOptimizer::removeStatusListener( const Reference< XStatusListener >&, const URL& )
157 throw( RuntimeException )
159 // TODO
160 OSL_FAIL( "PPPOptimizer::removeStatusListener()\nNot implemented yet!" );
163 // -----------------------------------------------------------------------------
164 // returning filesize, on error zero is returned
165 sal_Int64 PPPOptimizer::GetFileSize( const OUString& rURL )
167 sal_Int64 nFileSize = 0;
168 osl::DirectoryItem aItem;
169 if ( osl::DirectoryItem::get( rURL, aItem ) == osl::FileBase::E_None )
171 osl::FileStatus aStatus( osl_FileStatus_Mask_FileSize );
172 if ( aItem.getFileStatus( aStatus ) == osl::FileBase::E_None )
174 nFileSize = aStatus.getFileSize();
177 return nFileSize;
180 // -----------------------------------------------------------------------------
182 OUString PPPOptimizer_getImplementationName()
184 return OUString( "com.sun.star.comp.PPPOptimizerImp" );
187 Sequence< OUString > PPPOptimizer_getSupportedServiceNames()
189 Sequence < OUString > aRet(1);
190 OUString* pArray = aRet.getArray();
191 pArray[0] = OUString ( SERVICE_NAME );
192 return aRet;
195 Reference< XInterface > PPPOptimizer_createInstance( const Reference< XComponentContext > & rSMgr )
196 throw( Exception )
198 return (cppu::OWeakObject*) new PPPOptimizer( rSMgr );
201 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */