LibreOffice Module sdext (master) 1
pppoptimizerdialog.cxx
Go to the documentation of this file.
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
22#include "optimizerdialog.hxx"
23#include <sal/log.hxx>
25
26using namespace ::com::sun::star::uno;
27using namespace ::com::sun::star::util;
28using namespace ::com::sun::star::lang;
29using namespace ::com::sun::star::frame;
30using namespace ::com::sun::star::beans;
31
32PPPOptimizerDialog::PPPOptimizerDialog( const Reference< XComponentContext > &xContext ) :
33 mxContext( xContext ),
34 mpOptimizerDialog( nullptr )
35{
36}
37
39{
40}
41
42void SAL_CALL PPPOptimizerDialog::initialize( const Sequence< Any >& aArguments )
43{
44 if( aArguments.getLength() != 1 )
45 throw IllegalArgumentException();
46
47 aArguments[ 0 ] >>= mxFrame;
48 if ( mxFrame.is() )
49 mxController = mxFrame->getController();
50}
51
53{
54 return "com.sun.star.comp.PresentationMinimizerImp";
55}
56
57sal_Bool SAL_CALL PPPOptimizerDialog::supportsService( const OUString& ServiceName )
58{
60}
61
62Sequence< OUString > SAL_CALL PPPOptimizerDialog::getSupportedServiceNames()
63{
64 return { "com.sun.star.comp.PresentationMinimizer" };
65}
66
67Reference< css::frame::XDispatch > SAL_CALL PPPOptimizerDialog::queryDispatch(
68 const URL& aURL, const OUString& /* aTargetFrameName */, sal_Int32 /* nSearchFlags */ )
69{
70 Reference < XDispatch > xRet;
71 if ( aURL.Protocol.equalsIgnoreAsciiCase( "vnd.com.sun.star.comp.PresentationMinimizer:" ) )
72 xRet = this;
73
74 return xRet;
75}
76
77Sequence< Reference< css::frame::XDispatch > > SAL_CALL PPPOptimizerDialog::queryDispatches(
78 const Sequence< css::frame::DispatchDescriptor >& aDescripts )
79{
80 Sequence< Reference< css::frame::XDispatch> > aReturn( aDescripts.getLength() );
81 std::transform(aDescripts.begin(), aDescripts.end(), aReturn.getArray(),
82 [this](const css::frame::DispatchDescriptor& rDescr) -> Reference<css::frame::XDispatch> {
83 return queryDispatch(rDescr.FeatureURL, rDescr.FrameName, rDescr.SearchFlags); });
84 return aReturn;
85}
86
87void SAL_CALL PPPOptimizerDialog::dispatch( const URL& rURL,
88 const Sequence< PropertyValue >& rArguments )
89{
90
91 if ( !(mxController.is() && rURL.Protocol.equalsIgnoreAsciiCase( "vnd.com.sun.star.comp.PresentationMinimizer:" )) )
92 return;
93
94 if ( rURL.Path == "execute" )
95 {
96 try
97 {
98 sal_Int64 nFileSizeSource = 0;
99 sal_Int64 nFileSizeDest = 0;
102
104 if ( pVal )
105 *pVal >>= nFileSizeSource;
107 if ( pVal )
108 *pVal >>= nFileSizeDest;
109
110 if ( nFileSizeSource && nFileSizeDest )
111 {
112 OUString sResult = "Your Presentation has been minimized from:" +
113 OUString::number( nFileSizeSource >> 10 ) +
114 "KB to " +
115 OUString::number( nFileSizeDest >> 10 ) +
116 "KB.";
117 SAL_INFO("sdext.minimizer", sResult );
118 }
119 }
120 catch( ... )
121 {
122 }
123 delete mpOptimizerDialog;
124 mpOptimizerDialog = nullptr;
125 }
126 else if ( rURL.Path == "statusupdate" )
127 {
128 if ( mpOptimizerDialog )
129 mpOptimizerDialog->UpdateStatus( rArguments );
130 }
131}
132
133void SAL_CALL PPPOptimizerDialog::addStatusListener( const Reference< XStatusListener >&, const URL& )
134{
135 // TODO
136 // OSL_FAIL( "PPPOptimizerDialog::addStatusListener()\nNot implemented yet!" );
137}
138
139void SAL_CALL PPPOptimizerDialog::removeStatusListener( const Reference< XStatusListener >&, const URL& )
140{
141 // TODO
142 // OSL_FAIL( "PPPOptimizerDialog::removeStatusListener()\nNot implemented yet!" );
143}
144
145
146extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
148 css::uno::XComponentContext* context , css::uno::Sequence<css::uno::Any> const&)
149{
150 return cppu::acquire(new PPPOptimizerDialog(context));
151}
152
153/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const css::uno::Any * GetStatusValue(const PPPOptimizerTokenEnum eStat) const
OptimizationStats maStats
void UpdateStatus(const css::uno::Sequence< css::beans::PropertyValue > &rStatus)
virtual OUString SAL_CALL getImplementationName() override
css::uno::Reference< css::frame::XFrame > mxFrame
css::uno::Reference< css::uno::XComponentContext > mxContext
virtual css::uno::Reference< css::frame::XDispatch > SAL_CALL queryDispatch(const css::util::URL &aURL, const OUString &aTargetFrameName, sal_Int32 nSearchFlags) override
void SAL_CALL initialize(const css::uno::Sequence< css::uno::Any > &aArguments) override
virtual void SAL_CALL addStatusListener(const css::uno::Reference< css::frame::XStatusListener > &xListener, const css::util::URL &aURL) override
virtual sal_Bool SAL_CALL supportsService(const OUString &sServiceName) override
PPPOptimizerDialog(const css::uno::Reference< css::uno::XComponentContext > &xContext)
virtual void SAL_CALL removeStatusListener(const css::uno::Reference< css::frame::XStatusListener > &xListener, const css::util::URL &aURL) override
virtual css::uno::Sequence< css::uno::Reference< css::frame::XDispatch > > SAL_CALL queryDispatches(const css::uno::Sequence< css::frame::DispatchDescriptor > &aDescripts) override
virtual ~PPPOptimizerDialog() override
OptimizerDialog * mpOptimizerDialog
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual void SAL_CALL dispatch(const css::util::URL &aURL, const css::uno::Sequence< css::beans::PropertyValue > &lArguments) override
css::uno::Reference< css::frame::XController > mxController
URL aURL
uno::Reference< uno::XComponentContext > mxContext
Sequence< PropertyValue > aArguments
#define SAL_INFO(area, stream)
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * sdext_PPPOptimizerDialog_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
@ TK_FileSizeDestination
@ TK_FileSizeSource
unsigned char sal_Bool