xref: /trunk/main/sdext/source/minimizer/pppoptimizerdialog.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1  /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sdext.hxx"
30 
31 #include "pppoptimizerdialog.hxx"
32 #include "optimizerdialog.hxx"
33 
34 using namespace ::rtl;
35 using namespace ::com::sun::star::uno;
36 using namespace ::com::sun::star::util;
37 using namespace ::com::sun::star::lang;
38 using namespace ::com::sun::star::frame;
39 using namespace ::com::sun::star::beans;
40 
41 #define SERVICE_NAME "com.sun.star.comp.SunPresentationMinimizer"
42 #include <rtl/ustrbuf.hxx>
43 
44 // ----------------------
45 // - PPPOptimizerDialog -
46 // ----------------------
47 
48 PPPOptimizerDialog::PPPOptimizerDialog( const Reference< XComponentContext > &rxMSF ) :
49     mxMSF( rxMSF ),
50     mpOptimizerDialog( NULL )
51 {
52 }
53 
54 // -----------------------------------------------------------------------------
55 
56 PPPOptimizerDialog::~PPPOptimizerDialog()
57 {
58 }
59 
60 // -----------------------------------------------------------------------------
61 // XInitialization
62 // -----------------------------------------------------------------------------
63 
64 void SAL_CALL PPPOptimizerDialog::initialize( const Sequence< Any >& aArguments )
65     throw ( Exception, RuntimeException )
66 {
67     if( aArguments.getLength() != 1 )
68         throw IllegalArgumentException();
69 
70     aArguments[ 0 ] >>= mxFrame;
71     if ( mxFrame.is() )
72         mxController = mxFrame->getController();
73 }
74 
75 // -----------------------------------------------------------------------------
76 // XServiceInfo
77 // -----------------------------------------------------------------------------
78 
79 OUString SAL_CALL PPPOptimizerDialog::getImplementationName()
80     throw (RuntimeException)
81 {
82     return PPPOptimizerDialog_getImplementationName();
83 }
84 
85 sal_Bool SAL_CALL PPPOptimizerDialog::supportsService( const OUString& ServiceName )
86     throw ( RuntimeException )
87 {
88     return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( SERVICE_NAME ) );
89 }
90 
91 Sequence< OUString > SAL_CALL PPPOptimizerDialog::getSupportedServiceNames()
92     throw (RuntimeException)
93 {
94     return PPPOptimizerDialog_getSupportedServiceNames();
95 }
96 
97 // -----------------------------------------------------------------------------
98 // XDispatchProvider
99 // -----------------------------------------------------------------------------
100 
101 Reference< com::sun::star::frame::XDispatch > SAL_CALL PPPOptimizerDialog::queryDispatch(
102     const URL& aURL, const ::rtl::OUString& /* aTargetFrameName */, sal_Int32 /* nSearchFlags */ ) throw( RuntimeException )
103 {
104     Reference < XDispatch > xRet;
105     if ( aURL.Protocol.compareToAscii( "vnd.com.sun.star.comp.SunPresentationMinimizer:" ) == 0 )
106         xRet = this;
107 
108     return xRet;
109 }
110 
111 //------------------------------------------------------------------------------
112 
113 Sequence< Reference< com::sun::star::frame::XDispatch > > SAL_CALL PPPOptimizerDialog::queryDispatches(
114     const Sequence< com::sun::star::frame::DispatchDescriptor >& aDescripts ) throw( RuntimeException )
115 {
116     Sequence< Reference< com::sun::star::frame::XDispatch> > aReturn( aDescripts.getLength() );
117     Reference< com::sun::star::frame::XDispatch>* pReturn = aReturn.getArray();
118     const com::sun::star::frame::DispatchDescriptor* pDescripts = aDescripts.getConstArray();
119     for (sal_Int16 i = 0; i < aDescripts.getLength(); ++i, ++pReturn, ++pDescripts )
120     {
121         *pReturn = queryDispatch( pDescripts->FeatureURL, pDescripts->FrameName, pDescripts->SearchFlags );
122     }
123     return aReturn;
124 }
125 
126 // -----------------------------------------------------------------------------
127 // XDispatch
128 // -----------------------------------------------------------------------------
129 
130 void SAL_CALL PPPOptimizerDialog::dispatch( const URL& rURL,
131                                             const Sequence< PropertyValue >& rArguments )
132     throw( RuntimeException )
133 {
134     sal_Int64 nFileSizeSource = 0;
135     sal_Int64 nFileSizeDest = 0;
136 
137     if ( mxController.is() && ( rURL.Protocol.compareToAscii( "vnd.com.sun.star.comp.SunPresentationMinimizer:" ) == 0 ) )
138     {
139         if ( rURL.Path.compareToAscii( "execute" ) == 0 )
140         {
141             sal_Bool bDialogExecuted = sal_False;
142 
143             try
144             {
145                 mpOptimizerDialog = new OptimizerDialog( mxMSF, mxFrame, this );
146                 bDialogExecuted = mpOptimizerDialog->execute();
147 
148                 const Any* pVal( mpOptimizerDialog->maStats.GetStatusValue( TK_FileSizeSource ) );
149                 if ( pVal )
150                     *pVal >>= nFileSizeSource;
151                 pVal = mpOptimizerDialog->maStats.GetStatusValue( TK_FileSizeDestination );
152                 if ( pVal )
153                     *pVal >>= nFileSizeDest;
154 
155                 if ( nFileSizeSource && nFileSizeDest )
156                 {
157                     rtl::OUStringBuffer sBuf( rtl::OUString::createFromAscii( "Your Presentation has been minimized from:" ) );
158                     sBuf.append( rtl::OUString::valueOf( nFileSizeSource >> 10 ) );
159                     sBuf.append( rtl::OUString::createFromAscii( "KB to " ) );
160                     sBuf.append( rtl::OUString::valueOf( nFileSizeDest >> 10 ) );
161                     sBuf.append( rtl::OUString::createFromAscii( "KB." ) );
162                     OUString sResult( sBuf.makeStringAndClear() );
163 //                  mpOptimizerDialog->showMessageBox( sResult, sResult, sal_False );
164                 }
165                 delete mpOptimizerDialog, mpOptimizerDialog = NULL;
166             }
167             catch( ... )
168             {
169 
170             }
171         }
172         else if ( rURL.Path.compareToAscii( "statusupdate" ) == 0 )
173         {
174             if ( mpOptimizerDialog )
175                 mpOptimizerDialog->UpdateStatus( rArguments );
176         }
177     }
178 }
179 
180 //===============================================
181 void SAL_CALL PPPOptimizerDialog::addStatusListener( const Reference< XStatusListener >&, const URL& )
182     throw( RuntimeException )
183 {
184     // TODO
185     // OSL_ENSURE( sal_False, "PPPOptimizerDialog::addStatusListener()\nNot implemented yet!" );
186 }
187 
188 //===============================================
189 void SAL_CALL PPPOptimizerDialog::removeStatusListener( const Reference< XStatusListener >&, const URL& )
190     throw( RuntimeException )
191 {
192     // TODO
193     // OSL_ENSURE( sal_False, "PPPOptimizerDialog::removeStatusListener()\nNot implemented yet!" );
194 }
195 
196 // -----------------------------------------------------------------------------
197 
198 OUString PPPOptimizerDialog_getImplementationName()
199 {
200     return OUString ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.comp.SunPresentationMinimizerImp" ) );
201 }
202 
203 Sequence< OUString > PPPOptimizerDialog_getSupportedServiceNames()
204 {
205     Sequence < OUString > aRet(1);
206     OUString* pArray = aRet.getArray();
207     pArray[0] =  OUString ( RTL_CONSTASCII_USTRINGPARAM( SERVICE_NAME ) );
208     return aRet;
209 }
210 
211 Reference< XInterface > PPPOptimizerDialog_createInstance( const Reference< XComponentContext > & rSMgr)
212     throw( Exception )
213 {
214     return (cppu::OWeakObject*) new PPPOptimizerDialog( rSMgr );
215 }
216 
217 // -----------------------------------------------------------------------------
218