Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include "informationdialog.hxx"
31 : : #include "optimizationstats.hxx"
32 : : #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
33 : : #include <com/sun/star/graphic/GraphicProvider.hpp>
34 : : #include <com/sun/star/graphic/XGraphicProvider.hpp>
35 : : #include <com/sun/star/graphic/XGraphic.hpp>
36 : : #include <rtl/ustrbuf.hxx>
37 : : #include <sal/macros.h>
38 : : #include "com/sun/star/util/URL.hpp"
39 : : #include "com/sun/star/util/URLTransformer.hpp"
40 : : #include "com/sun/star/util/XURLTransformer.hpp"
41 : :
42 : : #define DIALOG_WIDTH 240
43 : : #define DIALOG_HEIGHT 80
44 : : #define PAGE_POS_X 35
45 : : #define PAGE_WIDTH ( DIALOG_WIDTH - PAGE_POS_X ) - 6
46 : :
47 : :
48 : : // ---------------------
49 : : // - INFORMATIONDIALOG -
50 : : // ---------------------
51 : :
52 : : using namespace ::rtl;
53 : : using namespace ::com::sun::star;
54 : : using namespace ::com::sun::star::io;
55 : : using namespace ::com::sun::star::ui;
56 : : using namespace ::com::sun::star::awt;
57 : : using namespace ::com::sun::star::uno;
58 : : using namespace ::com::sun::star::util;
59 : : using namespace ::com::sun::star::lang;
60 : : using namespace ::com::sun::star::frame;
61 : : using namespace ::com::sun::star::beans;
62 : : using namespace ::com::sun::star::script;
63 : : using namespace ::com::sun::star::container;
64 : :
65 : :
66 : :
67 : : // -----------------------------------------------------------------------------
68 : :
69 : 0 : rtl::OUString InsertFixedText( InformationDialog& rInformationDialog, const rtl::OUString& rControlName, const OUString& rLabel,
70 : : sal_Int32 nXPos, sal_Int32 nYPos, sal_Int32 nWidth, sal_Int32 nHeight, sal_Bool bMultiLine, sal_Int16 nTabIndex )
71 : : {
72 : : OUString pNames[] = {
73 : : TKGet( TK_Height ),
74 : : TKGet( TK_Label ),
75 : : TKGet( TK_MultiLine ),
76 : : TKGet( TK_PositionX ),
77 : : TKGet( TK_PositionY ),
78 : : TKGet( TK_Step ),
79 : : TKGet( TK_TabIndex ),
80 : 0 : TKGet( TK_Width ) };
81 : :
82 : : Any pValues[] = {
83 : : Any( nHeight ),
84 : : Any( rLabel ),
85 : : Any( bMultiLine ),
86 : : Any( nXPos ),
87 : : Any( nYPos ),
88 : : Any( (sal_Int16)0 ),
89 : : Any( nTabIndex ),
90 : 0 : Any( nWidth ) };
91 : :
92 : 0 : sal_Int32 nCount = SAL_N_ELEMENTS( pNames );
93 : :
94 : 0 : Sequence< rtl::OUString > aNames( pNames, nCount );
95 : 0 : Sequence< Any > aValues( pValues, nCount );
96 : :
97 : 0 : rInformationDialog.insertFixedText( rControlName, aNames, aValues );
98 : 0 : return rControlName;
99 : : }
100 : :
101 : 0 : rtl::OUString InsertImage( InformationDialog& rInformationDialog, const OUString& rControlName, const OUString& rURL,
102 : : sal_Int32 nPosX, sal_Int32 nPosY, sal_Int32 nWidth, sal_Int32 nHeight )
103 : : {
104 : : OUString pNames[] = {
105 : : TKGet( TK_Border ),
106 : : TKGet( TK_Height ),
107 : : TKGet( TK_ImageURL ),
108 : : TKGet( TK_PositionX ),
109 : : TKGet( TK_PositionY ),
110 : : TKGet( TK_ScaleImage ),
111 : 0 : TKGet( TK_Width ) };
112 : :
113 : : Any pValues[] = {
114 : : Any( sal_Int16( 0 ) ),
115 : : Any( nHeight ),
116 : : Any( rURL ),
117 : : Any( nPosX ),
118 : : Any( nPosY ),
119 : : Any( sal_True ),
120 : 0 : Any( nWidth ) };
121 : 0 : sal_Int32 nCount = SAL_N_ELEMENTS( pNames );
122 : :
123 : 0 : Sequence< rtl::OUString > aNames( pNames, nCount );
124 : 0 : Sequence< Any > aValues( pValues, nCount );
125 : :
126 : 0 : rInformationDialog.insertImage( rControlName, aNames, aValues );
127 : 0 : return rControlName;
128 : : }
129 : :
130 : 0 : rtl::OUString InsertCheckBox( InformationDialog& rInformationDialog, const OUString& rControlName,
131 : : const Reference< XItemListener > xItemListener, const OUString& rLabel,
132 : : sal_Int32 nXPos, sal_Int32 nYPos, sal_Int32 nWidth, sal_Int32 nHeight, sal_Int16 nTabIndex )
133 : : {
134 : : OUString pNames[] = {
135 : : TKGet( TK_Enabled ),
136 : : TKGet( TK_Height ),
137 : : TKGet( TK_Label ),
138 : : TKGet( TK_PositionX ),
139 : : TKGet( TK_PositionY ),
140 : : TKGet( TK_Step ),
141 : : TKGet( TK_TabIndex ),
142 : 0 : TKGet( TK_Width ) };
143 : :
144 : : Any pValues[] = {
145 : : Any( sal_True ),
146 : : Any( nHeight ),
147 : : Any( rLabel ),
148 : : Any( nXPos ),
149 : : Any( nYPos ),
150 : : Any( (sal_Int16)0 ),
151 : : Any( nTabIndex ),
152 : 0 : Any( nWidth ) };
153 : :
154 : 0 : sal_Int32 nCount = SAL_N_ELEMENTS( pNames );
155 : :
156 : 0 : Sequence< rtl::OUString > aNames( pNames, nCount );
157 : 0 : Sequence< Any > aValues( pValues, nCount );
158 : :
159 : 0 : Reference< XCheckBox > xCheckBox( rInformationDialog.insertCheckBox( rControlName, aNames, aValues ) );
160 : 0 : if ( xItemListener.is() )
161 : 0 : xCheckBox->addItemListener( xItemListener );
162 : 0 : return rControlName;
163 : : }
164 : :
165 : 0 : rtl::OUString InsertButton( InformationDialog& rInformationDialog, const OUString& rControlName, Reference< XActionListener >& xActionListener,
166 : : sal_Int32 nXPos, sal_Int32 nYPos, sal_Int32 nWidth, sal_Int32 nHeight, sal_Int16 nTabIndex, PPPOptimizerTokenEnum nResID )
167 : : {
168 : : OUString pNames[] = {
169 : : TKGet( TK_Enabled ),
170 : : TKGet( TK_Height ),
171 : : TKGet( TK_Label ),
172 : : TKGet( TK_PositionX ),
173 : : TKGet( TK_PositionY ),
174 : : TKGet( TK_PushButtonType ),
175 : : TKGet( TK_Step ),
176 : : TKGet( TK_TabIndex ),
177 : 0 : TKGet( TK_Width ) };
178 : :
179 : : Any pValues[] = {
180 : : Any( sal_True ),
181 : : Any( nHeight ),
182 : : Any( rInformationDialog.getString( nResID ) ),
183 : : Any( nXPos ),
184 : : Any( nYPos ),
185 : : Any( static_cast< sal_Int16 >( PushButtonType_OK ) ),
186 : : Any( (sal_Int16)0 ),
187 : : Any( nTabIndex ),
188 : 0 : Any( nWidth ) };
189 : :
190 : :
191 : 0 : sal_Int32 nCount = SAL_N_ELEMENTS( pNames );
192 : :
193 : 0 : Sequence< rtl::OUString > aNames( pNames, nCount );
194 : 0 : Sequence< Any > aValues( pValues, nCount );
195 : :
196 : 0 : rInformationDialog.insertButton( rControlName, xActionListener, aNames, aValues );
197 : 0 : return rControlName;
198 : : }
199 : :
200 : :
201 : 0 : static OUString ImpValueOfInMB( const sal_Int64& rVal )
202 : : {
203 : 0 : double fVal( static_cast<double>( rVal ) );
204 : 0 : fVal /= ( 1 << 20 );
205 : 0 : fVal += 0.05;
206 : 0 : rtl::OUStringBuffer aVal( OUString::valueOf( fVal ) );
207 : 0 : sal_Int32 nX( OUString( aVal.getStr() ).indexOf( '.', 0 ) );
208 : 0 : if ( nX > 0 )
209 : 0 : aVal.setLength( nX + 2 );
210 : 0 : return aVal.makeStringAndClear();
211 : : }
212 : :
213 : 0 : OUString InformationDialog::ImpGetStandardImage( const OUString& sPrivateURL )
214 : : {
215 : 0 : rtl::OUString sURL;
216 : : try
217 : : {
218 : 0 : mxTempFile = Reference< XStream >( mxMSF->getServiceManager()->createInstanceWithContext( OUString("com.sun.star.io.TempFile"), mxMSF ), UNO_QUERY_THROW );
219 : 0 : Reference< XPropertySet > xPropSet( mxTempFile, UNO_QUERY );
220 : 0 : Reference< XOutputStream > xOutputStream( mxTempFile->getOutputStream() );
221 : 0 : if ( xOutputStream.is() && xPropSet.is() )
222 : : {
223 : 0 : Reference< graphic::XGraphicProvider > xGraphicProvider( graphic::GraphicProvider::create( mxMSF ) );
224 : 0 : Sequence< PropertyValue > aArgs( 1 );
225 : 0 : aArgs[ 0 ].Name = OUString("URL");
226 : 0 : aArgs[ 0 ].Value <<= sPrivateURL;
227 : 0 : Reference< graphic::XGraphic > xGraphic( xGraphicProvider->queryGraphic( aArgs ) );
228 : 0 : if ( xGraphic.is() )
229 : : {
230 : 0 : OUString aDestMimeType( "image/png" );
231 : 0 : Sequence< PropertyValue > aArgs2( 2 );
232 : 0 : aArgs2[ 0 ].Name = TKGet( TK_MimeType ); // the GraphicProvider is using "MimeType", the GraphicExporter "MediaType"...
233 : 0 : aArgs2[ 0 ].Value <<= aDestMimeType;
234 : 0 : aArgs2[ 1 ].Name = TKGet( TK_OutputStream );
235 : 0 : aArgs2[ 1 ].Value <<= xOutputStream;
236 : 0 : xGraphicProvider->storeGraphic( xGraphic, aArgs2 );
237 : : }
238 : 0 : xPropSet->getPropertyValue( OUString("Uri") ) >>= sURL;
239 : 0 : }
240 : : }
241 : 0 : catch( Exception& )
242 : : {
243 : : }
244 : 0 : return sURL;
245 : : }
246 : :
247 : 0 : void InformationDialog::InitDialog()
248 : : {
249 : 0 : sal_Int32 nDialogHeight = DIALOG_HEIGHT;
250 : 0 : if ( maSaveAsURL.isEmpty() )
251 : 0 : nDialogHeight -= 22;
252 : :
253 : : // setting the dialog properties
254 : : OUString pNames[] = {
255 : : TKGet( TK_Closeable ),
256 : : TKGet( TK_Height ),
257 : : TKGet( TK_Moveable ),
258 : : TKGet( TK_PositionX ),
259 : : TKGet( TK_PositionY ),
260 : : TKGet( TK_Title ),
261 : 0 : TKGet( TK_Width ) };
262 : :
263 : : Any pValues[] = {
264 : : Any( sal_True ),
265 : : Any( nDialogHeight ),
266 : : Any( sal_True ),
267 : : Any( sal_Int32( 245 ) ),
268 : : Any( sal_Int32( 115 ) ),
269 : : Any( getString( STR_SUN_OPTIMIZATION_WIZARD2 ) ),
270 : 0 : Any( sal_Int32( DIALOG_WIDTH ) ) };
271 : :
272 : 0 : sal_Int32 nCount = SAL_N_ELEMENTS( pNames );
273 : :
274 : 0 : Sequence< rtl::OUString > aNames( pNames, nCount );
275 : 0 : Sequence< Any > aValues( pValues, nCount );
276 : :
277 : 0 : mxDialogModelMultiPropertySet->setPropertyValues( aNames, aValues );
278 : :
279 : 0 : sal_Int64 nSource = mnSourceSize;
280 : 0 : sal_Int64 nDest = mnDestSize;
281 : :
282 : 0 : PPPOptimizerTokenEnum eInfoString( STR_INFO_1 );
283 : 0 : if ( mnSourceSize )
284 : : {
285 : 0 : if ( mnDestSize )
286 : 0 : eInfoString = STR_INFO_1;
287 : : else
288 : : {
289 : 0 : eInfoString = STR_INFO_2;
290 : 0 : nDest = mnApproxSize;
291 : : }
292 : : }
293 : 0 : else if ( mnDestSize )
294 : 0 : eInfoString = STR_INFO_3;
295 : : else
296 : : {
297 : 0 : eInfoString = STR_INFO_4;
298 : 0 : nDest = mnApproxSize;
299 : : }
300 : :
301 : 0 : rtl::OUString aTitle;
302 : 0 : if ( !maSaveAsURL.isEmpty() )
303 : : {
304 : 0 : Reference< XURLTransformer > xURLTransformer( URLTransformer::create(mxMSF) );
305 : 0 : util::URL aURL, aPresentationURL;
306 : 0 : aURL.Complete = maSaveAsURL;
307 : 0 : xURLTransformer->parseSmart( aURL, rtl::OUString() );
308 : :
309 : 0 : const OUString sFileProtocol( "file:///" );
310 : 0 : aPresentationURL.Complete = sFileProtocol.concat( aURL.Name );
311 : 0 : aTitle = xURLTransformer->getPresentation( aPresentationURL, sal_False );
312 : :
313 : 0 : if ( aTitle.match( sFileProtocol, 0 ) )
314 : 0 : aTitle = aTitle.replaceAt( 0, sFileProtocol.getLength(), rtl::OUString() );
315 : : }
316 : :
317 : 0 : OUString aInfoString( getString( eInfoString ) );
318 : 0 : const OUString aOldSizePlaceholder( "%OLDFILESIZE" );
319 : 0 : const OUString aNewSizePlaceholder( "%NEWFILESIZE" );
320 : 0 : const OUString aTitlePlaceholder( !aTitle.isEmpty() ? OUString("%TITLE" )
321 : 0 : : OUString("'%TITLE'") );
322 : :
323 : 0 : sal_Int32 i = aInfoString.indexOf( aOldSizePlaceholder, 0 );
324 : 0 : if ( i >= 0 )
325 : 0 : aInfoString = aInfoString.replaceAt( i, aOldSizePlaceholder.getLength(), ImpValueOfInMB( nSource ) );
326 : :
327 : 0 : sal_Int32 j = aInfoString.indexOf( aNewSizePlaceholder, 0 );
328 : 0 : if ( j >= 0 )
329 : 0 : aInfoString = aInfoString.replaceAt( j, aNewSizePlaceholder.getLength(), ImpValueOfInMB( nDest ) );
330 : :
331 : 0 : sal_Int32 k = aInfoString.indexOf( aTitlePlaceholder, 0 );
332 : 0 : if ( k >= 0 )
333 : 0 : aInfoString = aInfoString.replaceAt( k, aTitlePlaceholder.getLength(), aTitle );
334 : :
335 : 0 : com::sun::star::uno::Reference< com::sun::star::awt::XItemListener > xItemListener;
336 : 0 : InsertImage( *this, rtl::OUString("aboutimage"), ImpGetStandardImage( rtl::OUString("private:standardimage/query") ), 5, 5, 25, 25 );
337 : 0 : InsertFixedText( *this, rtl::OUString("fixedtext"), aInfoString, PAGE_POS_X, 6, PAGE_WIDTH, 24, sal_True, 0 );
338 : 0 : if ( !maSaveAsURL.isEmpty() )
339 : 0 : InsertCheckBox( *this, TKGet( TK_OpenNewDocument ), xItemListener, getString( STR_AUTOMATICALLY_OPEN ), PAGE_POS_X, 42, PAGE_WIDTH, 8, 1 );
340 : 0 : InsertButton( *this, rtl::OUString("button"), mxActionListener, DIALOG_WIDTH / 2 - 25, nDialogHeight - 20, 50, 14, 2, STR_OK );
341 : :
342 : 0 : sal_Bool bOpenNewDocument = mrbOpenNewDocument;
343 : 0 : setControlProperty( TKGet( TK_OpenNewDocument ), TKGet( TK_State ), Any( (sal_Int16)bOpenNewDocument ) );
344 : 0 : }
345 : :
346 : : // -----------------------------------------------------------------------------
347 : :
348 : 0 : InformationDialog::InformationDialog( const Reference< XComponentContext > &rxMSF, Reference< XFrame >& rxFrame, const rtl::OUString& rSaveAsURL, sal_Bool& rbOpenNewDocument, const sal_Int64& rSourceSize, const sal_Int64& rDestSize, const sal_Int64& rApproxSize ) :
349 : : UnoDialog( rxMSF, rxFrame ),
350 : : ConfigurationAccess( rxMSF, NULL ),
351 : : mxMSF( rxMSF ),
352 : : mxFrame( rxFrame ),
353 : 0 : mxActionListener( new OKActionListener( *this ) ),
354 : : mnSourceSize( rSourceSize ),
355 : : mnDestSize( rDestSize ),
356 : : mnApproxSize( rApproxSize ),
357 : : mrbOpenNewDocument( rbOpenNewDocument ),
358 : 0 : maSaveAsURL( rSaveAsURL )
359 : : {
360 : 0 : Reference< XFrame > xFrame( mxController->getFrame() );
361 : 0 : Reference< XWindow > xContainerWindow( xFrame->getContainerWindow() );
362 : 0 : Reference< XWindowPeer > xWindowPeer( xContainerWindow, UNO_QUERY_THROW );
363 : 0 : createWindowPeer( xWindowPeer );
364 : :
365 : 0 : InitDialog();
366 : 0 : }
367 : :
368 : : // -----------------------------------------------------------------------------
369 : :
370 : 0 : InformationDialog::~InformationDialog()
371 : : {
372 : 0 : }
373 : :
374 : : // -----------------------------------------------------------------------------
375 : :
376 : 0 : sal_Bool InformationDialog::execute()
377 : : {
378 : 0 : UnoDialog::execute();
379 : :
380 : 0 : if ( !maSaveAsURL.isEmpty() )
381 : : {
382 : 0 : sal_Int16 nInt16 = 0;
383 : 0 : Any aAny( getControlProperty( TKGet( TK_OpenNewDocument ), TKGet( TK_State ) ) );
384 : 0 : if ( aAny >>= nInt16 )
385 : : {
386 : 0 : sal_Bool bOpenNewDocument = static_cast< sal_Bool >( nInt16 );
387 : 0 : mrbOpenNewDocument = bOpenNewDocument;
388 : 0 : }
389 : : }
390 : 0 : return mbStatus;
391 : : }
392 : :
393 : : // -----------------------------------------------------------------------------
394 : :
395 : 0 : void OKActionListener::actionPerformed( const ActionEvent& rEvent )
396 : : throw ( com::sun::star::uno::RuntimeException )
397 : : {
398 : 0 : if ( rEvent.ActionCommand == "button" )
399 : : {
400 : 0 : mrInformationDialog.endExecute( sal_True );
401 : : }
402 : 0 : }
403 : 0 : void OKActionListener::disposing( const ::com::sun::star::lang::EventObject& /* Source */ )
404 : : throw ( com::sun::star::uno::RuntimeException )
405 : : {
406 : 0 : }
407 : :
408 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|