Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include "pppoptimizer.hxx"
31 : : #include "impoptimizer.hxx"
32 : : #include <osl/file.hxx>
33 : :
34 : : #include <com/sun/star/lang/IllegalArgumentException.hpp>
35 : :
36 : : using namespace ::rtl;
37 : : using namespace ::com::sun::star::uno;
38 : : using namespace ::com::sun::star::util;
39 : : using namespace ::com::sun::star::lang;
40 : : using namespace ::com::sun::star::frame;
41 : : using namespace ::com::sun::star::beans;
42 : :
43 : : #define SERVICE_NAME "com.sun.star.comp.PPPOptimizer"
44 : :
45 : : // ----------------
46 : : // - PPPOptimizer -
47 : : // ----------------
48 : :
49 : 0 : PPPOptimizer::PPPOptimizer( const Reference< XComponentContext > &rxMSF ) :
50 : 0 : mxMSF( rxMSF )
51 : : {
52 : 0 : }
53 : :
54 : : // -----------------------------------------------------------------------------
55 : :
56 : 0 : PPPOptimizer::~PPPOptimizer()
57 : : {
58 : 0 : }
59 : :
60 : : // -----------------------------------------------------------------------------
61 : : // XInitialization
62 : : // -----------------------------------------------------------------------------
63 : :
64 : 0 : void SAL_CALL PPPOptimizer::initialize( const Sequence< Any >& aArguments )
65 : : throw ( Exception, RuntimeException )
66 : : {
67 : 0 : if( aArguments.getLength() != 1 )
68 : 0 : throw IllegalArgumentException();
69 : :
70 : 0 : Reference< XFrame > xFrame;
71 : 0 : aArguments[ 0 ] >>= xFrame;
72 : 0 : if ( xFrame.is() )
73 : 0 : mxController = xFrame->getController();
74 : 0 : }
75 : :
76 : : // -----------------------------------------------------------------------------
77 : : // XServiceInfo
78 : : // -----------------------------------------------------------------------------
79 : :
80 : 0 : OUString SAL_CALL PPPOptimizer::getImplementationName()
81 : : throw ( RuntimeException )
82 : : {
83 : 0 : return PPPOptimizer_getImplementationName();
84 : : }
85 : :
86 : 0 : sal_Bool SAL_CALL PPPOptimizer::supportsService( const OUString& rServiceName )
87 : : throw ( RuntimeException )
88 : : {
89 : 0 : return rServiceName == SERVICE_NAME;
90 : : }
91 : :
92 : 0 : Sequence< OUString > SAL_CALL PPPOptimizer::getSupportedServiceNames()
93 : : throw ( RuntimeException )
94 : : {
95 : 0 : return PPPOptimizer_getSupportedServiceNames();
96 : : }
97 : :
98 : : // -----------------------------------------------------------------------------
99 : : // XDispatchProvider
100 : : // -----------------------------------------------------------------------------
101 : :
102 : 0 : Reference< com::sun::star::frame::XDispatch > SAL_CALL PPPOptimizer::queryDispatch(
103 : : const URL& aURL, const ::rtl::OUString& /* aTargetFrameName */, sal_Int32 /* nSearchFlags */ ) throw( RuntimeException )
104 : : {
105 : 0 : Reference < XDispatch > xRet;
106 : 0 : if ( aURL.Protocol.compareToAscii( "vnd.com.sun.star.comp.PPPOptimizer:" ) == 0 )
107 : : {
108 : : // if ( aURL.Path.compareToAscii( "Function1" ) == 0 )
109 : 0 : xRet = this;
110 : : }
111 : 0 : return xRet;
112 : : }
113 : :
114 : : //------------------------------------------------------------------------------
115 : :
116 : 0 : Sequence< Reference< com::sun::star::frame::XDispatch > > SAL_CALL PPPOptimizer::queryDispatches(
117 : : const Sequence< com::sun::star::frame::DispatchDescriptor >& aDescripts ) throw( RuntimeException )
118 : : {
119 : 0 : Sequence< Reference< com::sun::star::frame::XDispatch> > aReturn( aDescripts.getLength() );
120 : 0 : Reference< com::sun::star::frame::XDispatch>* pReturn = aReturn.getArray();
121 : 0 : const com::sun::star::frame::DispatchDescriptor* pDescripts = aDescripts.getConstArray();
122 : 0 : for (sal_Int16 i = 0; i < aDescripts.getLength(); ++i, ++pReturn, ++pDescripts )
123 : : {
124 : 0 : *pReturn = queryDispatch( pDescripts->FeatureURL, pDescripts->FrameName, pDescripts->SearchFlags );
125 : : }
126 : 0 : return aReturn;
127 : : }
128 : :
129 : : // -----------------------------------------------------------------------------
130 : : // XDispatch
131 : : // -----------------------------------------------------------------------------
132 : :
133 : 0 : void SAL_CALL PPPOptimizer::dispatch( const URL& rURL, const Sequence< PropertyValue >& lArguments )
134 : : throw( RuntimeException )
135 : : {
136 : 0 : if ( mxController.is() && ( rURL.Protocol.compareToAscii( "vnd.com.sun.star.comp.PPPOptimizer:" ) == 0 ) )
137 : : {
138 : 0 : if ( rURL.Path.compareToAscii( "optimize" ) == 0 )
139 : : {
140 : 0 : Reference< XModel > xModel( mxController->getModel() );
141 : 0 : if ( xModel.is() )
142 : : {
143 : : try
144 : : {
145 : 0 : ImpOptimizer aOptimizer( mxMSF, xModel );
146 : 0 : aOptimizer.Optimize( lArguments );
147 : : }
148 : 0 : catch( Exception& )
149 : : {
150 : : }
151 : 0 : }
152 : : }
153 : : }
154 : 0 : }
155 : :
156 : : //===============================================
157 : 0 : void SAL_CALL PPPOptimizer::addStatusListener( const Reference< XStatusListener >&, const URL& )
158 : : throw( RuntimeException )
159 : : {
160 : : // TODO
161 : : OSL_FAIL( "PPPOptimizer::addStatusListener()\nNot implemented yet!" );
162 : 0 : }
163 : :
164 : : //===============================================
165 : 0 : void SAL_CALL PPPOptimizer::removeStatusListener( const Reference< XStatusListener >&, const URL& )
166 : : throw( RuntimeException )
167 : : {
168 : : // TODO
169 : : OSL_FAIL( "PPPOptimizer::removeStatusListener()\nNot implemented yet!" );
170 : 0 : }
171 : :
172 : : // -----------------------------------------------------------------------------
173 : : // returning filesize, on error zero is returned
174 : 0 : sal_Int64 PPPOptimizer::GetFileSize( const rtl::OUString& rURL )
175 : : {
176 : 0 : sal_Int64 nFileSize = 0;
177 : 0 : osl::DirectoryItem aItem;
178 : 0 : if ( osl::DirectoryItem::get( rURL, aItem ) == osl::FileBase::E_None )
179 : : {
180 : 0 : osl::FileStatus aStatus( osl_FileStatus_Mask_FileSize );
181 : 0 : if ( aItem.getFileStatus( aStatus ) == osl::FileBase::E_None )
182 : : {
183 : 0 : nFileSize = aStatus.getFileSize();
184 : 0 : }
185 : : }
186 : 0 : return nFileSize;
187 : : }
188 : :
189 : : // -----------------------------------------------------------------------------
190 : :
191 : 0 : OUString PPPOptimizer_getImplementationName()
192 : : {
193 : 0 : return OUString ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.comp.PPPOptimizerImp" ) );
194 : : }
195 : :
196 : 0 : Sequence< OUString > PPPOptimizer_getSupportedServiceNames()
197 : : {
198 : 0 : Sequence < OUString > aRet(1);
199 : 0 : OUString* pArray = aRet.getArray();
200 : 0 : pArray[0] = OUString ( RTL_CONSTASCII_USTRINGPARAM( SERVICE_NAME ) );
201 : 0 : return aRet;
202 : : }
203 : :
204 : 0 : Reference< XInterface > PPPOptimizer_createInstance( const Reference< XComponentContext > & rSMgr )
205 : : throw( Exception )
206 : : {
207 : 0 : return (cppu::OWeakObject*) new PPPOptimizer( rSMgr );
208 : : }
209 : :
210 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|