LCOV - code coverage report
Current view: top level - libreoffice/sdext/source/minimizer - informationdialog.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 149 0.0 %
Date: 2012-12-17 Functions: 0 12 0.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10