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 
21 #include "pppoptimizerdialog.hxx"
22 #include "optimizerdialog.hxx"
23 #include <sal/log.hxx>
24 
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;
30 
31 #define SERVICE_NAME "com.sun.star.comp.PresentationMinimizer"
33 
35  mxContext( xContext ),
36  mpOptimizerDialog( nullptr )
37 {
38 }
39 
41 {
42 }
43 
44 void SAL_CALL PPPOptimizerDialog::initialize( const Sequence< Any >& aArguments )
45 {
46  if( aArguments.getLength() != 1 )
47  throw IllegalArgumentException();
48 
49  aArguments[ 0 ] >>= mxFrame;
50  if ( mxFrame.is() )
51  mxController = mxFrame->getController();
52 }
53 
55 {
57 }
58 
59 sal_Bool SAL_CALL PPPOptimizerDialog::supportsService( const OUString& ServiceName )
60 {
61  return cppu::supportsService(this, ServiceName);
62 }
63 
65 {
67 }
68 
69 Reference< css::frame::XDispatch > SAL_CALL PPPOptimizerDialog::queryDispatch(
70  const URL& aURL, const OUString& /* aTargetFrameName */, sal_Int32 /* nSearchFlags */ )
71 {
72  Reference < XDispatch > xRet;
73  if ( aURL.Protocol.equalsIgnoreAsciiCase( "vnd.com.sun.star.comp.PresentationMinimizer:" ) )
74  xRet = this;
75 
76  return xRet;
77 }
78 
79 Sequence< Reference< css::frame::XDispatch > > SAL_CALL PPPOptimizerDialog::queryDispatches(
80  const Sequence< css::frame::DispatchDescriptor >& aDescripts )
81 {
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;
87 }
88 
89 void SAL_CALL PPPOptimizerDialog::dispatch( const URL& rURL,
90  const Sequence< PropertyValue >& rArguments )
91 {
92 
93  if ( !(mxController.is() && rURL.Protocol.equalsIgnoreAsciiCase( "vnd.com.sun.star.comp.PresentationMinimizer:" )) )
94  return;
95 
96  if ( rURL.Path == "execute" )
97  {
98  try
99  {
100  sal_Int64 nFileSizeSource = 0;
101  sal_Int64 nFileSizeDest = 0;
104 
106  if ( pVal )
107  *pVal >>= nFileSizeSource;
109  if ( pVal )
110  *pVal >>= nFileSizeDest;
111 
112  if ( nFileSizeSource && nFileSizeDest )
113  {
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 );
120  }
121  }
122  catch( ... )
123  {
124  }
125  delete mpOptimizerDialog;
126  mpOptimizerDialog = nullptr;
127  }
128  else if ( rURL.Path == "statusupdate" )
129  {
130  if ( mpOptimizerDialog )
131  mpOptimizerDialog->UpdateStatus( rArguments );
132  }
133 }
134 
135 void SAL_CALL PPPOptimizerDialog::addStatusListener( const Reference< XStatusListener >&, const URL& )
136 {
137  // TODO
138  // OSL_FAIL( "PPPOptimizerDialog::addStatusListener()\nNot implemented yet!" );
139 }
140 
141 void SAL_CALL PPPOptimizerDialog::removeStatusListener( const Reference< XStatusListener >&, const URL& )
142 {
143  // TODO
144  // OSL_FAIL( "PPPOptimizerDialog::removeStatusListener()\nNot implemented yet!" );
145 }
146 
148 {
149  return "com.sun.star.comp.PresentationMinimizerImp";
150 }
151 
153 {
155  return aRet;
156 }
157 
159 {
160  return static_cast<cppu::OWeakObject*>(new PPPOptimizerDialog( rSMgr ));
161 }
162 
163 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const css::uno::Any * GetStatusValue(const PPPOptimizerTokenEnum eStat) const
virtual void SAL_CALL dispatch(const css::util::URL &aURL, const css::uno::Sequence< css::beans::PropertyValue > &lArguments) override
virtual ~PPPOptimizerDialog() override
virtual void SAL_CALL addStatusListener(const css::uno::Reference< css::frame::XStatusListener > &xListener, const css::util::URL &aURL) override
virtual OUString SAL_CALL getImplementationName() override
uno::Reference< 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
virtual void SAL_CALL removeStatusListener(const css::uno::Reference< css::frame::XStatusListener > &xListener, const css::util::URL &aURL) override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
void SAL_CALL initialize(const css::uno::Sequence< css::uno::Any > &aArguments) override
css::uno::Reference< css::uno::XComponentContext > mxContext
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
virtual css::uno::Sequence< css::uno::Reference< css::frame::XDispatch > > SAL_CALL queryDispatches(const css::uno::Sequence< css::frame::DispatchDescriptor > &aDescripts) override
PPPOptimizerDialog(const css::uno::Reference< css::uno::XComponentContext > &xContext)
OUString PPPOptimizerDialog_getImplementationName()
css::uno::Reference< css::frame::XFrame > mxFrame
void UpdateStatus(const css::uno::Sequence< css::beans::PropertyValue > &rStatus)
unsigned char sal_Bool
OptimizerDialog * mpOptimizerDialog
#define SERVICE_NAME
Sequence< OUString > PPPOptimizerDialog_getSupportedServiceNames()
virtual sal_Bool SAL_CALL supportsService(const OUString &sServiceName) override
#define SAL_INFO(area, stream)
css::uno::Reference< css::frame::XController > mxController
OptimizationStats maStats
Reference< XInterface > PPPOptimizerDialog_createInstance(const Reference< XComponentContext > &rSMgr)