1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sdext.hxx"
26 
27 #include "pppoptimizerdialog.hxx"
28 #include "optimizerdialog.hxx"
29 
30 using namespace ::rtl;
31 using namespace ::com::sun::star::uno;
32 using namespace ::com::sun::star::util;
33 using namespace ::com::sun::star::lang;
34 using namespace ::com::sun::star::frame;
35 using namespace ::com::sun::star::beans;
36 
37 #define SERVICE_NAME "com.sun.star.comp.SunPresentationMinimizer"
38 #include <rtl/ustrbuf.hxx>
39 
40 // ----------------------
41 // - PPPOptimizerDialog -
42 // ----------------------
43 
44 PPPOptimizerDialog::PPPOptimizerDialog( const Reference< XComponentContext > &rxMSF ) :
45     mxMSF( rxMSF ),
46 	mpOptimizerDialog( NULL )
47 {
48 }
49 
50 // -----------------------------------------------------------------------------
51 
52 PPPOptimizerDialog::~PPPOptimizerDialog()
53 {
54 }
55 
56 // -----------------------------------------------------------------------------
57 // XInitialization
58 // -----------------------------------------------------------------------------
59 
60 void SAL_CALL PPPOptimizerDialog::initialize( const Sequence< Any >& aArguments )
61 	throw ( Exception, RuntimeException )
62 {
63 	if( aArguments.getLength() != 1 )
64 		throw IllegalArgumentException();
65 
66 	aArguments[ 0 ] >>= mxFrame;
67 	if ( mxFrame.is() )
68 		mxController = mxFrame->getController();
69 }
70 
71 // -----------------------------------------------------------------------------
72 // XServiceInfo
73 // -----------------------------------------------------------------------------
74 
75 OUString SAL_CALL PPPOptimizerDialog::getImplementationName()
76 	throw (RuntimeException)
77 {
78 	return PPPOptimizerDialog_getImplementationName();
79 }
80 
81 sal_Bool SAL_CALL PPPOptimizerDialog::supportsService( const OUString& ServiceName )
82 	throw ( RuntimeException )
83 {
84     return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( SERVICE_NAME ) );
85 }
86 
87 Sequence< OUString > SAL_CALL PPPOptimizerDialog::getSupportedServiceNames()
88     throw (RuntimeException)
89 {
90 	return PPPOptimizerDialog_getSupportedServiceNames();
91 }
92 
93 // -----------------------------------------------------------------------------
94 // XDispatchProvider
95 // -----------------------------------------------------------------------------
96 
97 Reference< com::sun::star::frame::XDispatch > SAL_CALL PPPOptimizerDialog::queryDispatch(
98 	const URL& aURL, const ::rtl::OUString& /* aTargetFrameName */, sal_Int32 /* nSearchFlags */ ) throw( RuntimeException )
99 {
100 	Reference < XDispatch > xRet;
101     if ( aURL.Protocol.compareToAscii( "vnd.com.sun.star.comp.SunPresentationMinimizer:" ) == 0 )
102 		xRet = this;
103 
104 	return xRet;
105 }
106 
107 //------------------------------------------------------------------------------
108 
109 Sequence< Reference< com::sun::star::frame::XDispatch > > SAL_CALL PPPOptimizerDialog::queryDispatches(
110 	const Sequence< com::sun::star::frame::DispatchDescriptor >& aDescripts ) throw( RuntimeException )
111 {
112 	Sequence< Reference< com::sun::star::frame::XDispatch> > aReturn( aDescripts.getLength() );
113 	Reference< com::sun::star::frame::XDispatch>* pReturn = aReturn.getArray();
114 	const com::sun::star::frame::DispatchDescriptor* pDescripts = aDescripts.getConstArray();
115 	for (sal_Int16 i = 0; i < aDescripts.getLength(); ++i, ++pReturn, ++pDescripts )
116 	{
117 		*pReturn = queryDispatch( pDescripts->FeatureURL, pDescripts->FrameName, pDescripts->SearchFlags );
118 	}
119 	return aReturn;
120 }
121 
122 // -----------------------------------------------------------------------------
123 // XDispatch
124 // -----------------------------------------------------------------------------
125 
126 void SAL_CALL PPPOptimizerDialog::dispatch( const URL& rURL,
127 											const Sequence< PropertyValue >& rArguments )
128     throw( RuntimeException )
129 {
130 	sal_Int64 nFileSizeSource = 0;
131 	sal_Int64 nFileSizeDest = 0;
132 
133 	if ( mxController.is() && ( rURL.Protocol.compareToAscii( "vnd.com.sun.star.comp.SunPresentationMinimizer:" ) == 0 ) )
134 	{
135 		if ( rURL.Path.compareToAscii( "execute" ) == 0 )
136 		{
137 			sal_Bool bDialogExecuted = sal_False;
138 
139 			try
140 			{
141 				mpOptimizerDialog = new OptimizerDialog( mxMSF, mxFrame, this );
142 				bDialogExecuted = mpOptimizerDialog->execute();
143 
144 				const Any* pVal( mpOptimizerDialog->maStats.GetStatusValue( TK_FileSizeSource ) );
145 				if ( pVal )
146 					*pVal >>= nFileSizeSource;
147 				pVal = mpOptimizerDialog->maStats.GetStatusValue( TK_FileSizeDestination );
148 				if ( pVal )
149 					*pVal >>= nFileSizeDest;
150 
151 				if ( nFileSizeSource && nFileSizeDest )
152 				{
153 					rtl::OUStringBuffer sBuf( rtl::OUString::createFromAscii( "Your Presentation has been minimized from:" ) );
154 					sBuf.append( rtl::OUString::valueOf( nFileSizeSource >> 10 ) );
155 					sBuf.append( rtl::OUString::createFromAscii( "KB to " ) );
156 					sBuf.append( rtl::OUString::valueOf( nFileSizeDest >> 10 ) );
157 					sBuf.append( rtl::OUString::createFromAscii( "KB." ) );
158 					OUString sResult( sBuf.makeStringAndClear() );
159 //					mpOptimizerDialog->showMessageBox( sResult, sResult, sal_False );
160 				}
161 				delete mpOptimizerDialog, mpOptimizerDialog = NULL;
162 			}
163 			catch( ... )
164 			{
165 
166 			}
167 		}
168 		else if ( rURL.Path.compareToAscii( "statusupdate" ) == 0 )
169 		{
170 			if ( mpOptimizerDialog )
171 				mpOptimizerDialog->UpdateStatus( rArguments );
172 		}
173 	}
174 }
175 
176 //===============================================
177 void SAL_CALL PPPOptimizerDialog::addStatusListener( const Reference< XStatusListener >&, const URL& )
178 	throw( RuntimeException )
179 {
180     // TODO
181 	// OSL_ENSURE( sal_False, "PPPOptimizerDialog::addStatusListener()\nNot implemented yet!" );
182 }
183 
184 //===============================================
185 void SAL_CALL PPPOptimizerDialog::removeStatusListener( const Reference< XStatusListener >&, const URL& )
186     throw( RuntimeException )
187 {
188     // TODO
189     // OSL_ENSURE( sal_False, "PPPOptimizerDialog::removeStatusListener()\nNot implemented yet!" );
190 }
191 
192 // -----------------------------------------------------------------------------
193 
194 OUString PPPOptimizerDialog_getImplementationName()
195 {
196 	return OUString ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.comp.SunPresentationMinimizerImp" ) );
197 }
198 
199 Sequence< OUString > PPPOptimizerDialog_getSupportedServiceNames()
200 {
201 	Sequence < OUString > aRet(1);
202     OUString* pArray = aRet.getArray();
203     pArray[0] =  OUString ( RTL_CONSTASCII_USTRINGPARAM( SERVICE_NAME ) );
204     return aRet;
205 }
206 
207 Reference< XInterface > PPPOptimizerDialog_createInstance( const Reference< XComponentContext > & rSMgr)
208     throw( Exception )
209 {
210 	return (cppu::OWeakObject*) new PPPOptimizerDialog( rSMgr );
211 }
212 
213 // -----------------------------------------------------------------------------
214