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
21 #include "pppoptimizerdialog.hxx"
22 #include "optimizerdialog.hxx"
23 #include <sal/log.hxx>
24 #include <cppuhelper/supportsservice.hxx>
25
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;
31
PPPOptimizerDialog(const Reference<XComponentContext> & xContext)32 PPPOptimizerDialog::PPPOptimizerDialog( const Reference< XComponentContext > &xContext ) :
33 mxContext( xContext ),
34 mpOptimizerDialog( nullptr )
35 {
36 }
37
~PPPOptimizerDialog()38 PPPOptimizerDialog::~PPPOptimizerDialog()
39 {
40 }
41
initialize(const Sequence<Any> & aArguments)42 void 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
getImplementationName()52 OUString SAL_CALL PPPOptimizerDialog::getImplementationName()
53 {
54 return "com.sun.star.comp.PresentationMinimizerImp";
55 }
56
supportsService(const OUString & ServiceName)57 sal_Bool SAL_CALL PPPOptimizerDialog::supportsService( const OUString& ServiceName )
58 {
59 return cppu::supportsService(this, ServiceName);
60 }
61
getSupportedServiceNames()62 Sequence< OUString > SAL_CALL PPPOptimizerDialog::getSupportedServiceNames()
63 {
64 return { "com.sun.star.comp.PresentationMinimizer" };
65 }
66
queryDispatch(const URL & aURL,const OUString &,sal_Int32)67 Reference< 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
queryDispatches(const Sequence<css::frame::DispatchDescriptor> & aDescripts)77 Sequence< 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.begin(),
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
dispatch(const URL & rURL,const Sequence<PropertyValue> & rArguments)87 void 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;
100 mpOptimizerDialog = new OptimizerDialog( mxContext, mxFrame, this );
101 mpOptimizerDialog->execute();
102
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;
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
addStatusListener(const Reference<XStatusListener> &,const URL &)133 void SAL_CALL PPPOptimizerDialog::addStatusListener( const Reference< XStatusListener >&, const URL& )
134 {
135 // TODO
136 // OSL_FAIL( "PPPOptimizerDialog::addStatusListener()\nNot implemented yet!" );
137 }
138
removeStatusListener(const Reference<XStatusListener> &,const URL &)139 void SAL_CALL PPPOptimizerDialog::removeStatusListener( const Reference< XStatusListener >&, const URL& )
140 {
141 // TODO
142 // OSL_FAIL( "PPPOptimizerDialog::removeStatusListener()\nNot implemented yet!" );
143 }
144
145
146 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
sdext_PPPOptimizerDialog_get_implementation(css::uno::XComponentContext * context,css::uno::Sequence<css::uno::Any> const &)147 sdext_PPPOptimizerDialog_get_implementation(
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: */
154