vcl: allow for overriding the default PDF rendering resolution
[LibreOffice.git] / sdext / source / minimizer / pppoptimizerdialog.cxx
blob168a4bbc26ebc2f55468aa8c4b55c3247cf76d3b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 "pppoptimizerdialog.hxx"
22 #include "optimizerdialog.hxx"
23 #include <sal/log.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;
31 #define SERVICE_NAME "com.sun.star.comp.PresentationMinimizer"
32 #include <cppuhelper/supportsservice.hxx>
34 PPPOptimizerDialog::PPPOptimizerDialog( const Reference< XComponentContext > &xContext ) :
35 mxContext( xContext ),
36 mpOptimizerDialog( nullptr )
40 PPPOptimizerDialog::~PPPOptimizerDialog()
44 void SAL_CALL PPPOptimizerDialog::initialize( const Sequence< Any >& aArguments )
46 if( aArguments.getLength() != 1 )
47 throw IllegalArgumentException();
49 aArguments[ 0 ] >>= mxFrame;
50 if ( mxFrame.is() )
51 mxController = mxFrame->getController();
54 OUString SAL_CALL PPPOptimizerDialog::getImplementationName()
56 return PPPOptimizerDialog_getImplementationName();
59 sal_Bool SAL_CALL PPPOptimizerDialog::supportsService( const OUString& ServiceName )
61 return cppu::supportsService(this, ServiceName);
64 Sequence< OUString > SAL_CALL PPPOptimizerDialog::getSupportedServiceNames()
66 return PPPOptimizerDialog_getSupportedServiceNames();
69 Reference< css::frame::XDispatch > SAL_CALL PPPOptimizerDialog::queryDispatch(
70 const URL& aURL, const OUString& /* aTargetFrameName */, sal_Int32 /* nSearchFlags */ )
72 Reference < XDispatch > xRet;
73 if ( aURL.Protocol.equalsIgnoreAsciiCase( "vnd.com.sun.star.comp.PresentationMinimizer:" ) )
74 xRet = this;
76 return xRet;
79 Sequence< Reference< css::frame::XDispatch > > SAL_CALL PPPOptimizerDialog::queryDispatches(
80 const Sequence< css::frame::DispatchDescriptor >& aDescripts )
82 Sequence< Reference< css::frame::XDispatch> > aReturn( aDescripts.getLength() );
83 std::transform(aDescripts.begin(), aDescripts.end(), aReturn.begin(),
84 [this](const css::frame::DispatchDescriptor& rDescr) -> Reference<css::frame::XDispatch> {
85 return queryDispatch(rDescr.FeatureURL, rDescr.FrameName, rDescr.SearchFlags); });
86 return aReturn;
89 void SAL_CALL PPPOptimizerDialog::dispatch( const URL& rURL,
90 const Sequence< PropertyValue >& rArguments )
93 if ( !(mxController.is() && rURL.Protocol.equalsIgnoreAsciiCase( "vnd.com.sun.star.comp.PresentationMinimizer:" )) )
94 return;
96 if ( rURL.Path == "execute" )
98 try
100 sal_Int64 nFileSizeSource = 0;
101 sal_Int64 nFileSizeDest = 0;
102 mpOptimizerDialog = new OptimizerDialog( mxContext, mxFrame, this );
103 mpOptimizerDialog->execute();
105 const Any* pVal( mpOptimizerDialog->maStats.GetStatusValue( TK_FileSizeSource ) );
106 if ( pVal )
107 *pVal >>= nFileSizeSource;
108 pVal = mpOptimizerDialog->maStats.GetStatusValue( TK_FileSizeDestination );
109 if ( pVal )
110 *pVal >>= nFileSizeDest;
112 if ( nFileSizeSource && nFileSizeDest )
114 OUString sResult = "Your Presentation has been minimized from:" +
115 OUString::number( nFileSizeSource >> 10 ) +
116 "KB to " +
117 OUString::number( nFileSizeDest >> 10 ) +
118 "KB.";
119 SAL_INFO("sdext.minimizer", sResult );
122 catch( ... )
125 delete mpOptimizerDialog;
126 mpOptimizerDialog = nullptr;
128 else if ( rURL.Path == "statusupdate" )
130 if ( mpOptimizerDialog )
131 mpOptimizerDialog->UpdateStatus( rArguments );
135 void SAL_CALL PPPOptimizerDialog::addStatusListener( const Reference< XStatusListener >&, const URL& )
137 // TODO
138 // OSL_FAIL( "PPPOptimizerDialog::addStatusListener()\nNot implemented yet!" );
141 void SAL_CALL PPPOptimizerDialog::removeStatusListener( const Reference< XStatusListener >&, const URL& )
143 // TODO
144 // OSL_FAIL( "PPPOptimizerDialog::removeStatusListener()\nNot implemented yet!" );
147 OUString PPPOptimizerDialog_getImplementationName()
149 return "com.sun.star.comp.PresentationMinimizerImp";
152 Sequence< OUString > PPPOptimizerDialog_getSupportedServiceNames()
154 Sequence<OUString> aRet { SERVICE_NAME };
155 return aRet;
158 Reference< XInterface > PPPOptimizerDialog_createInstance( const Reference< XComponentContext > & rSMgr)
160 return static_cast<cppu::OWeakObject*>(new PPPOptimizerDialog( rSMgr ));
163 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */