bump product version to 5.0.4.1
[LibreOffice.git] / sdext / source / minimizer / pppoptimizerdialog.cxx
blob49064f1812f116e8d3a3c39025c221cd13490a81
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"
24 using namespace ::com::sun::star::uno;
25 using namespace ::com::sun::star::util;
26 using namespace ::com::sun::star::lang;
27 using namespace ::com::sun::star::frame;
28 using namespace ::com::sun::star::beans;
30 #define SERVICE_NAME "com.sun.star.comp.PresentationMinimizer"
31 #include <cppuhelper/supportsservice.hxx>
32 #include <rtl/ustrbuf.hxx>
34 PPPOptimizerDialog::PPPOptimizerDialog( const Reference< XComponentContext > &xContext ) :
35 mxContext( xContext ),
36 mpOptimizerDialog( NULL )
40 PPPOptimizerDialog::~PPPOptimizerDialog()
44 void SAL_CALL PPPOptimizerDialog::initialize( const Sequence< Any >& aArguments )
45 throw ( Exception, RuntimeException, std::exception )
47 if( aArguments.getLength() != 1 )
48 throw IllegalArgumentException();
50 aArguments[ 0 ] >>= mxFrame;
51 if ( mxFrame.is() )
52 mxController = mxFrame->getController();
55 OUString SAL_CALL PPPOptimizerDialog::getImplementationName()
56 throw (RuntimeException, std::exception)
58 return PPPOptimizerDialog_getImplementationName();
61 sal_Bool SAL_CALL PPPOptimizerDialog::supportsService( const OUString& ServiceName )
62 throw ( RuntimeException, std::exception )
64 return cppu::supportsService(this, ServiceName);
67 Sequence< OUString > SAL_CALL PPPOptimizerDialog::getSupportedServiceNames()
68 throw (RuntimeException, std::exception)
70 return PPPOptimizerDialog_getSupportedServiceNames();
73 Reference< com::sun::star::frame::XDispatch > SAL_CALL PPPOptimizerDialog::queryDispatch(
74 const URL& aURL, const OUString& /* aTargetFrameName */, sal_Int32 /* nSearchFlags */ ) throw( RuntimeException, std::exception )
76 Reference < XDispatch > xRet;
77 if ( aURL.Protocol.equalsIgnoreAsciiCase( "vnd.com.sun.star.comp.PresentationMinimizer:" ) )
78 xRet = this;
80 return xRet;
83 Sequence< Reference< com::sun::star::frame::XDispatch > > SAL_CALL PPPOptimizerDialog::queryDispatches(
84 const Sequence< com::sun::star::frame::DispatchDescriptor >& aDescripts ) throw( RuntimeException, std::exception )
86 Sequence< Reference< com::sun::star::frame::XDispatch> > aReturn( aDescripts.getLength() );
87 Reference< com::sun::star::frame::XDispatch>* pReturn = aReturn.getArray();
88 const com::sun::star::frame::DispatchDescriptor* pDescripts = aDescripts.getConstArray();
89 for (sal_Int16 i = 0; i < aDescripts.getLength(); ++i, ++pReturn, ++pDescripts )
91 *pReturn = queryDispatch( pDescripts->FeatureURL, pDescripts->FrameName, pDescripts->SearchFlags );
93 return aReturn;
96 void SAL_CALL PPPOptimizerDialog::dispatch( const URL& rURL,
97 const Sequence< PropertyValue >& rArguments )
98 throw( RuntimeException, std::exception )
101 if ( mxController.is() && rURL.Protocol.equalsIgnoreAsciiCase( "vnd.com.sun.star.comp.PresentationMinimizer:" ) )
103 if ( rURL.Path == "execute" )
107 sal_Int64 nFileSizeSource = 0;
108 sal_Int64 nFileSizeDest = 0;
109 mpOptimizerDialog = new OptimizerDialog( mxContext, mxFrame, this );
110 mpOptimizerDialog->execute();
112 const Any* pVal( mpOptimizerDialog->maStats.GetStatusValue( TK_FileSizeSource ) );
113 if ( pVal )
114 *pVal >>= nFileSizeSource;
115 pVal = mpOptimizerDialog->maStats.GetStatusValue( TK_FileSizeDestination );
116 if ( pVal )
117 *pVal >>= nFileSizeDest;
119 if ( nFileSizeSource && nFileSizeDest )
121 OUStringBuffer sBuf( "Your Presentation has been minimized from:" );
122 sBuf.append( OUString::number( nFileSizeSource >> 10 ) );
123 sBuf.append( "KB to " );
124 sBuf.append( OUString::number( nFileSizeDest >> 10 ) );
125 sBuf.append( "KB." );
126 OUString sResult( sBuf.makeStringAndClear() );
127 SAL_INFO("sdext.minimizer", sResult );
129 delete mpOptimizerDialog, mpOptimizerDialog = NULL;
131 catch( ... )
136 else if ( rURL.Path == "statusupdate" )
138 if ( mpOptimizerDialog )
139 mpOptimizerDialog->UpdateStatus( rArguments );
144 void SAL_CALL PPPOptimizerDialog::addStatusListener( const Reference< XStatusListener >&, const URL& )
145 throw( RuntimeException, std::exception )
147 // TODO
148 // OSL_FAIL( "PPPOptimizerDialog::addStatusListener()\nNot implemented yet!" );
151 void SAL_CALL PPPOptimizerDialog::removeStatusListener( const Reference< XStatusListener >&, const URL& )
152 throw( RuntimeException, std::exception )
154 // TODO
155 // OSL_FAIL( "PPPOptimizerDialog::removeStatusListener()\nNot implemented yet!" );
158 OUString PPPOptimizerDialog_getImplementationName()
160 return OUString( "com.sun.star.comp.PresentationMinimizerImp" );
163 Sequence< OUString > PPPOptimizerDialog_getSupportedServiceNames()
165 Sequence < OUString > aRet(1);
166 OUString* pArray = aRet.getArray();
167 pArray[0] = SERVICE_NAME;
168 return aRet;
171 Reference< XInterface > PPPOptimizerDialog_createInstance( const Reference< XComponentContext > & rSMgr)
172 throw( Exception )
174 return (cppu::OWeakObject*) new PPPOptimizerDialog( rSMgr );
177 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */