1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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"
40 PPPOptimizer::PPPOptimizer( const Reference
< XComponentContext
> &rxMSF
) :
45 // -----------------------------------------------------------------------------
47 PPPOptimizer::~PPPOptimizer()
51 // -----------------------------------------------------------------------------
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
;
64 mxController
= xFrame
->getController();
67 // -----------------------------------------------------------------------------
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 // -----------------------------------------------------------------------------
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 )
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
);
120 // -----------------------------------------------------------------------------
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() );
136 ImpOptimizer
aOptimizer( mxMSF
, xModel
);
137 aOptimizer
.Optimize( lArguments
);
147 //===============================================
148 void SAL_CALL
PPPOptimizer::addStatusListener( const Reference
< XStatusListener
>&, const URL
& )
149 throw( RuntimeException
)
152 OSL_FAIL( "PPPOptimizer::addStatusListener()\nNot implemented yet!" );
155 //===============================================
156 void SAL_CALL
PPPOptimizer::removeStatusListener( const Reference
< XStatusListener
>&, const URL
& )
157 throw( RuntimeException
)
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();
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
);
195 Reference
< XInterface
> PPPOptimizer_createInstance( const Reference
< XComponentContext
> & rSMgr
)
198 return (cppu::OWeakObject
*) new PPPOptimizer( rSMgr
);
201 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */