Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 :
21 : #include "pppoptimizer.hxx"
22 : #include "impoptimizer.hxx"
23 : #include <osl/file.hxx>
24 :
25 : #include <com/sun/star/lang/IllegalArgumentException.hpp>
26 :
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;
33 :
34 : #define SERVICE_NAME "com.sun.star.comp.PPPOptimizer"
35 :
36 : // ----------------
37 : // - PPPOptimizer -
38 : // ----------------
39 :
40 0 : PPPOptimizer::PPPOptimizer( const Reference< XComponentContext > &rxMSF ) :
41 0 : mxMSF( rxMSF )
42 : {
43 0 : }
44 :
45 : // -----------------------------------------------------------------------------
46 :
47 0 : PPPOptimizer::~PPPOptimizer()
48 : {
49 0 : }
50 :
51 : // -----------------------------------------------------------------------------
52 : // XInitialization
53 : // -----------------------------------------------------------------------------
54 :
55 0 : void SAL_CALL PPPOptimizer::initialize( const Sequence< Any >& aArguments )
56 : throw ( Exception, RuntimeException )
57 : {
58 0 : if( aArguments.getLength() != 1 )
59 0 : throw IllegalArgumentException();
60 :
61 0 : Reference< XFrame > xFrame;
62 0 : aArguments[ 0 ] >>= xFrame;
63 0 : if ( xFrame.is() )
64 0 : mxController = xFrame->getController();
65 0 : }
66 :
67 : // -----------------------------------------------------------------------------
68 : // XServiceInfo
69 : // -----------------------------------------------------------------------------
70 :
71 0 : OUString SAL_CALL PPPOptimizer::getImplementationName()
72 : throw ( RuntimeException )
73 : {
74 0 : return PPPOptimizer_getImplementationName();
75 : }
76 :
77 0 : sal_Bool SAL_CALL PPPOptimizer::supportsService( const OUString& rServiceName )
78 : throw ( RuntimeException )
79 : {
80 0 : return rServiceName == SERVICE_NAME;
81 : }
82 :
83 0 : Sequence< OUString > SAL_CALL PPPOptimizer::getSupportedServiceNames()
84 : throw ( RuntimeException )
85 : {
86 0 : return PPPOptimizer_getSupportedServiceNames();
87 : }
88 :
89 : // -----------------------------------------------------------------------------
90 : // XDispatchProvider
91 : // -----------------------------------------------------------------------------
92 :
93 0 : Reference< com::sun::star::frame::XDispatch > SAL_CALL PPPOptimizer::queryDispatch(
94 : const URL& aURL, const ::rtl::OUString& /* aTargetFrameName */, sal_Int32 /* nSearchFlags */ ) throw( RuntimeException )
95 : {
96 0 : Reference < XDispatch > xRet;
97 0 : if ( aURL.Protocol.compareToAscii( "vnd.com.sun.star.comp.PPPOptimizer:" ) == 0 )
98 : {
99 : // if ( aURL.Path.compareToAscii( "Function1" ) == 0 )
100 0 : xRet = this;
101 : }
102 0 : return xRet;
103 : }
104 :
105 : //------------------------------------------------------------------------------
106 :
107 0 : Sequence< Reference< com::sun::star::frame::XDispatch > > SAL_CALL PPPOptimizer::queryDispatches(
108 : const Sequence< com::sun::star::frame::DispatchDescriptor >& aDescripts ) throw( RuntimeException )
109 : {
110 0 : Sequence< Reference< com::sun::star::frame::XDispatch> > aReturn( aDescripts.getLength() );
111 0 : Reference< com::sun::star::frame::XDispatch>* pReturn = aReturn.getArray();
112 0 : const com::sun::star::frame::DispatchDescriptor* pDescripts = aDescripts.getConstArray();
113 0 : for (sal_Int16 i = 0; i < aDescripts.getLength(); ++i, ++pReturn, ++pDescripts )
114 : {
115 0 : *pReturn = queryDispatch( pDescripts->FeatureURL, pDescripts->FrameName, pDescripts->SearchFlags );
116 : }
117 0 : return aReturn;
118 : }
119 :
120 : // -----------------------------------------------------------------------------
121 : // XDispatch
122 : // -----------------------------------------------------------------------------
123 :
124 0 : void SAL_CALL PPPOptimizer::dispatch( const URL& rURL, const Sequence< PropertyValue >& lArguments )
125 : throw( RuntimeException )
126 : {
127 0 : if ( mxController.is() && ( rURL.Protocol.compareToAscii( "vnd.com.sun.star.comp.PPPOptimizer:" ) == 0 ) )
128 : {
129 0 : if ( rURL.Path.compareToAscii( "optimize" ) == 0 )
130 : {
131 0 : Reference< XModel > xModel( mxController->getModel() );
132 0 : if ( xModel.is() )
133 : {
134 : try
135 : {
136 0 : ImpOptimizer aOptimizer( mxMSF, xModel );
137 0 : aOptimizer.Optimize( lArguments );
138 : }
139 0 : catch( Exception& )
140 : {
141 : }
142 0 : }
143 : }
144 : }
145 0 : }
146 :
147 : //===============================================
148 0 : void SAL_CALL PPPOptimizer::addStatusListener( const Reference< XStatusListener >&, const URL& )
149 : throw( RuntimeException )
150 : {
151 : // TODO
152 : OSL_FAIL( "PPPOptimizer::addStatusListener()\nNot implemented yet!" );
153 0 : }
154 :
155 : //===============================================
156 0 : void SAL_CALL PPPOptimizer::removeStatusListener( const Reference< XStatusListener >&, const URL& )
157 : throw( RuntimeException )
158 : {
159 : // TODO
160 : OSL_FAIL( "PPPOptimizer::removeStatusListener()\nNot implemented yet!" );
161 0 : }
162 :
163 : // -----------------------------------------------------------------------------
164 : // returning filesize, on error zero is returned
165 0 : sal_Int64 PPPOptimizer::GetFileSize( const rtl::OUString& rURL )
166 : {
167 0 : sal_Int64 nFileSize = 0;
168 0 : osl::DirectoryItem aItem;
169 0 : if ( osl::DirectoryItem::get( rURL, aItem ) == osl::FileBase::E_None )
170 : {
171 0 : osl::FileStatus aStatus( osl_FileStatus_Mask_FileSize );
172 0 : if ( aItem.getFileStatus( aStatus ) == osl::FileBase::E_None )
173 : {
174 0 : nFileSize = aStatus.getFileSize();
175 0 : }
176 : }
177 0 : return nFileSize;
178 : }
179 :
180 : // -----------------------------------------------------------------------------
181 :
182 0 : OUString PPPOptimizer_getImplementationName()
183 : {
184 0 : return OUString ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.comp.PPPOptimizerImp" ) );
185 : }
186 :
187 0 : Sequence< OUString > PPPOptimizer_getSupportedServiceNames()
188 : {
189 0 : Sequence < OUString > aRet(1);
190 0 : OUString* pArray = aRet.getArray();
191 0 : pArray[0] = OUString ( RTL_CONSTASCII_USTRINGPARAM( SERVICE_NAME ) );
192 0 : return aRet;
193 : }
194 :
195 0 : Reference< XInterface > PPPOptimizer_createInstance( const Reference< XComponentContext > & rSMgr )
196 : throw( Exception )
197 : {
198 0 : return (cppu::OWeakObject*) new PPPOptimizer( rSMgr );
199 : }
200 :
201 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|