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 using namespace ::com::sun::star::uno
;
26 using namespace ::com::sun::star::util
;
27 using namespace ::com::sun::star::lang
;
28 using namespace ::com::sun::star::frame
;
29 using namespace ::com::sun::star::beans
;
35 PPPOptimizer::PPPOptimizer(
36 css::uno::Reference
<css::uno::XComponentContext
> const & xContext
,
37 css::uno::Reference
< css::frame::XFrame
> const & xFrame
):
38 mxContext( xContext
),
39 mxController( xFrame
->getController() )
45 PPPOptimizer::~PPPOptimizer()
53 Reference
< com::sun::star::frame::XDispatch
> SAL_CALL
PPPOptimizer::queryDispatch(
54 const URL
& aURL
, const OUString
& /* aTargetFrameName */, sal_Int32
/* nSearchFlags */ ) throw( RuntimeException
, std::exception
)
56 Reference
< XDispatch
> xRet
;
57 if ( aURL
.Protocol
.equalsIgnoreAsciiCase( "vnd.com.sun.star.comp.PPPOptimizer:" ) )
59 // if ( aURL.Path.equalsAscii( "Function1" ) )
67 Sequence
< Reference
< com::sun::star::frame::XDispatch
> > SAL_CALL
PPPOptimizer::queryDispatches(
68 const Sequence
< com::sun::star::frame::DispatchDescriptor
>& aDescripts
) throw( RuntimeException
, std::exception
)
70 Sequence
< Reference
< com::sun::star::frame::XDispatch
> > aReturn( aDescripts
.getLength() );
71 Reference
< com::sun::star::frame::XDispatch
>* pReturn
= aReturn
.getArray();
72 const com::sun::star::frame::DispatchDescriptor
* pDescripts
= aDescripts
.getConstArray();
73 for (sal_Int16 i
= 0; i
< aDescripts
.getLength(); ++i
, ++pReturn
, ++pDescripts
)
75 *pReturn
= queryDispatch( pDescripts
->FeatureURL
, pDescripts
->FrameName
, pDescripts
->SearchFlags
);
84 void SAL_CALL
PPPOptimizer::dispatch( const URL
& rURL
, const Sequence
< PropertyValue
>& lArguments
)
85 throw( RuntimeException
, std::exception
)
87 if ( mxController
.is() && rURL
.Protocol
.equalsIgnoreAsciiCase( "vnd.com.sun.star.comp.PPPOptimizer:" ) )
89 if ( rURL
.Path
== "optimize" )
91 Reference
< XModel
> xModel( mxController
->getModel() );
96 ImpOptimizer
aOptimizer( mxContext
, xModel
);
97 aOptimizer
.Optimize( lArguments
);
108 void SAL_CALL
PPPOptimizer::addStatusListener( const Reference
< XStatusListener
>&, const URL
& )
109 throw( RuntimeException
, std::exception
)
112 OSL_FAIL( "PPPOptimizer::addStatusListener()\nNot implemented yet!" );
116 void SAL_CALL
PPPOptimizer::removeStatusListener( const Reference
< XStatusListener
>&, const URL
& )
117 throw( RuntimeException
, std::exception
)
120 OSL_FAIL( "PPPOptimizer::removeStatusListener()\nNot implemented yet!" );
124 // returning filesize, on error zero is returned
125 sal_Int64
PPPOptimizer::GetFileSize( const OUString
& rURL
)
127 sal_Int64 nFileSize
= 0;
128 osl::DirectoryItem aItem
;
129 if ( osl::DirectoryItem::get( rURL
, aItem
) == osl::FileBase::E_None
)
131 osl::FileStatus
aStatus( osl_FileStatus_Mask_FileSize
);
132 if ( aItem
.getFileStatus( aStatus
) == osl::FileBase::E_None
)
134 nFileSize
= aStatus
.getFileSize();
140 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */