tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / sdext / source / minimizer / pppoptimizerdialog.cxx
blob889bf3a851900df4b544faa13aa286dca6995f3e
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>
24 #include <cppuhelper/supportsservice.hxx>
26 using namespace ::com::sun::star::uno;
27 using namespace ::com::sun::star::util;
28 using namespace ::com::sun::star::lang;
29 using namespace ::com::sun::star::frame;
30 using namespace ::com::sun::star::beans;
32 PPPOptimizerDialog::PPPOptimizerDialog( const Reference< XComponentContext > &xContext ) :
33 mxContext( xContext ),
34 mpOptimizerDialog( nullptr )
38 PPPOptimizerDialog::~PPPOptimizerDialog()
42 void SAL_CALL PPPOptimizerDialog::initialize( const Sequence< Any >& aArguments )
44 if( aArguments.getLength() != 1 )
45 throw IllegalArgumentException();
47 aArguments[ 0 ] >>= mxFrame;
48 if ( mxFrame.is() )
49 mxController = mxFrame->getController();
52 OUString SAL_CALL PPPOptimizerDialog::getImplementationName()
54 return u"com.sun.star.comp.PresentationMinimizerImp"_ustr;
57 sal_Bool SAL_CALL PPPOptimizerDialog::supportsService( const OUString& ServiceName )
59 return cppu::supportsService(this, ServiceName);
62 Sequence< OUString > SAL_CALL PPPOptimizerDialog::getSupportedServiceNames()
64 return { u"com.sun.star.comp.PresentationMinimizer"_ustr };
67 Reference< css::frame::XDispatch > SAL_CALL PPPOptimizerDialog::queryDispatch(
68 const URL& aURL, const OUString& /* aTargetFrameName */, sal_Int32 /* nSearchFlags */ )
70 Reference < XDispatch > xRet;
71 if ( aURL.Protocol.equalsIgnoreAsciiCase( "vnd.com.sun.star.comp.PresentationMinimizer:" ) )
72 xRet = this;
74 return xRet;
77 Sequence< Reference< css::frame::XDispatch > > SAL_CALL PPPOptimizerDialog::queryDispatches(
78 const Sequence< css::frame::DispatchDescriptor >& aDescripts )
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;
87 void SAL_CALL PPPOptimizerDialog::dispatch( const URL& rURL,
88 const Sequence< PropertyValue >& rArguments )
91 if ( !(mxController.is() && rURL.Protocol.equalsIgnoreAsciiCase( "vnd.com.sun.star.comp.PresentationMinimizer:" )) )
92 return;
94 if ( rURL.Path == "execute" )
96 try
98 sal_Int64 nFileSizeSource = 0;
99 sal_Int64 nFileSizeDest = 0;
100 mpOptimizerDialog = new OptimizerDialog( mxContext, mxFrame, this );
101 mpOptimizerDialog->execute();
103 const Any* pVal( mpOptimizerDialog->maStats.GetStatusValue( TK_FileSizeSource ) );
104 if ( pVal )
105 *pVal >>= nFileSizeSource;
106 pVal = mpOptimizerDialog->maStats.GetStatusValue( TK_FileSizeDestination );
107 if ( pVal )
108 *pVal >>= nFileSizeDest;
110 if ( nFileSizeSource && nFileSizeDest )
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 );
120 catch( ... )
123 delete mpOptimizerDialog;
124 mpOptimizerDialog = nullptr;
126 else if ( rURL.Path == "statusupdate" )
128 if ( mpOptimizerDialog )
129 mpOptimizerDialog->UpdateStatus( rArguments );
133 void SAL_CALL PPPOptimizerDialog::addStatusListener( const Reference< XStatusListener >&, const URL& )
135 // TODO
136 // OSL_FAIL( "PPPOptimizerDialog::addStatusListener()\nNot implemented yet!" );
139 void SAL_CALL PPPOptimizerDialog::removeStatusListener( const Reference< XStatusListener >&, const URL& )
141 // TODO
142 // OSL_FAIL( "PPPOptimizerDialog::removeStatusListener()\nNot implemented yet!" );
146 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
147 sdext_PPPOptimizerDialog_get_implementation(
148 css::uno::XComponentContext* context , css::uno::Sequence<css::uno::Any> const&)
150 return cppu::acquire(new PPPOptimizerDialog(context));
153 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */