LibreOffice Module sdext (master) 1
optimizerdialogcontrols.cxx
Go to the documentation of this file.
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 "optimizerdialog.hxx"
22
23
24#include "pppoptimizer.hxx"
25#include "graphiccollector.hxx"
26#include "pagecollector.hxx"
27#include <com/sun/star/awt/PushButtonType.hpp>
28#include <com/sun/star/awt/XSpinField.hpp>
29#include <com/sun/star/awt/XTextComponent.hpp>
30#include <com/sun/star/presentation/XCustomPresentationSupplier.hpp>
31#include <com/sun/star/drawing/XMasterPagesSupplier.hpp>
32#include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
33#include <com/sun/star/awt/FontDescriptor.hpp>
34#include <com/sun/star/awt/FontWeight.hpp>
35#include <com/sun/star/frame/XStorable.hpp>
36#include <rtl/ustrbuf.hxx>
37#include <sal/macros.h>
38#include <o3tl/string_view.hxx>
39
40using namespace ::com::sun::star::awt;
41using namespace ::com::sun::star::uno;
42using namespace ::com::sun::star::util;
43using namespace ::com::sun::star::lang;
44using namespace ::com::sun::star::frame;
45using namespace ::com::sun::star::beans;
46using namespace ::com::sun::star::drawing;
47using namespace ::com::sun::star::container;
48using namespace ::com::sun::star::presentation;
49
51{
52 m_xHelp->hide();
53}
54
56{
57 int nSelectedItem = -1;
58 std::vector<OUString> aItemList;
59 const std::vector< OptimizerSettings >& rList( GetOptimizerSettings() );
60 if ( rList.size() > 1 ) // the first session in the list is the actual one -> skipping first one
61 {
62 for ( std::vector<OptimizerSettings>::size_type i = 1; i < rList.size(); i++ )
63 {
64 aItemList.push_back(rList[i].maName);
65 if ( nSelectedItem < 0 )
66 {
67 if ( rList[ i ] == rList[ 0 ] )
68 nSelectedItem = static_cast< short >( i - 1 );
69 }
70 }
71 }
72 bool bRemoveButtonEnabled = false;
73 if ( nSelectedItem >= 0 )
74 {
75 if ( nSelectedItem > 2 ) // only allowing to delete custom themes, the first can|t be deleted
76 bRemoveButtonEnabled = true;
77 }
78 mpPage0->UpdateControlStates(aItemList, nSelectedItem, bRemoveButtonEnabled);
79}
80
82{
84}
85
87{
88 bool bDeleteUnusedMasterPages( GetConfigProperty( TK_DeleteUnusedMasterPages, false ) );
89 bool bDeleteHiddenSlides( GetConfigProperty( TK_DeleteHiddenSlides, false ) );
90 bool bDeleteNotesPages( GetConfigProperty( TK_DeleteNotesPages, false ) );
91 mpPage1->UpdateControlStates(bDeleteUnusedMasterPages, bDeleteHiddenSlides, bDeleteNotesPages);
92}
93
95{
96 Sequence< OUString > aCustomShowList;
97 Reference< XModel > xModel( mxController->getModel() );
98 if ( xModel.is() )
99 {
100 Reference< XCustomPresentationSupplier > aXCPSup( xModel, UNO_QUERY_THROW );
101 Reference< XNameContainer > aXCont( aXCPSup->getCustomPresentations() );
102 if ( aXCont.is() )
103 aCustomShowList = aXCont->getElementNames();
104 }
105 mpPage1->Init(aCustomShowList);
106
108}
109
111{
112 bool bJPEGCompression( GetConfigProperty( TK_JPEGCompression, false ) );
113 bool bRemoveCropArea( GetConfigProperty( TK_RemoveCropArea, false ) );
114 bool bEmbedLinkedGraphics( GetConfigProperty( TK_EmbedLinkedGraphics, true ) );
115 sal_Int32 nJPEGQuality( GetConfigProperty( TK_JPEGQuality, sal_Int32(90) ) );
116 sal_Int32 nImageResolution( GetConfigProperty( TK_ImageResolution, sal_Int32(0) ) );
117
118 mpPage2->UpdateControlStates(bJPEGCompression, nJPEGQuality, bRemoveCropArea, nImageResolution, bEmbedLinkedGraphics);
119}
120
122{
124}
125
127{
128 bool bConvertOLEObjects( GetConfigProperty( TK_OLEOptimization, false ) );
129 sal_Int16 nOLEOptimizationType( GetConfigProperty( TK_OLEOptimizationType, sal_Int16(0) ) );
130
131 mpPage3->UpdateControlStates(bConvertOLEObjects, nOLEOptimizationType);
132}
133
135{
136 int nOLECount = 0;
137 Reference< XModel > xModel( mxController->getModel() );
138 Reference< XDrawPagesSupplier > xDrawPagesSupplier( xModel, UNO_QUERY_THROW );
139 Reference< XDrawPages > xDrawPages( xDrawPagesSupplier->getDrawPages(), UNO_SET_THROW );
140 for ( sal_Int32 i = 0; i < xDrawPages->getCount(); i++ )
141 {
142 Reference< XShapes > xShapes( xDrawPages->getByIndex( i ), UNO_QUERY_THROW );
143 for ( sal_Int32 j = 0; j < xShapes->getCount(); j++ )
144 {
145 Reference< XShape > xShape( xShapes->getByIndex( j ), UNO_QUERY_THROW );
146 if ( xShape->getShapeType() == "com.sun.star.drawing.OLE2Shape" )
147 nOLECount++;
148 }
149 }
150
152
154}
155
156static OUString ImpValueOfInMB( sal_Int64 rVal, sal_Unicode nSeparator )
157{
158 double fVal( static_cast<double>( rVal ) );
159 fVal /= ( 1 << 20 );
160 fVal += 0.05;
161 OUStringBuffer aVal( OUString::number( fVal ) );
162 sal_Int32 nX( aVal.indexOf( '.' ) );
163 if ( nX >= 0 )
164 {
165 aVal.setLength( nX + 2 );
166 aVal[nX] = nSeparator;
167 }
168 aVal.append( " MB" );
169 return aVal.makeStringAndClear();
170}
171
173{
174 bool bSaveAs( GetConfigProperty( TK_SaveAs, true ) );
175 if ( mbIsReadonly )
176 bSaveAs = true;
177
178 std::vector<OUString> aItemList;
179 const std::vector< OptimizerSettings >& rList( GetOptimizerSettings() );
180 if ( rList.size() > 1 ) // the first session in the list is the actual one -> skipping first one
181 {
182 for ( std::vector<OptimizerSettings>::size_type w = 1; w < rList.size(); w++ )
183 aItemList.push_back(rList[ w ].maName);
184 }
185
186 // now check if it is sensible to enable the combo box
187 bool bSaveSettingsEnabled = true;
188 if ( rList.size() > 1 ) // the first session in the list is the actual one -> skipping first one
189 {
190 for ( std::vector<OptimizerSettings>::size_type w = 1; w < rList.size(); w++ )
191 {
192 if ( rList[ w ] == rList[ 0 ] )
193 {
194 bSaveSettingsEnabled = false;
195 break;
196 }
197 }
198 }
199
200 std::vector< OUString > aSummaryStrings;
201
202 // taking care of deleted slides
203 sal_Int32 nDeletedSlides = 0;
204 OUString sTKCustomShowName(mpPage1->Get_TK_CustomShowName());
205 if (!sTKCustomShowName.isEmpty())
206 SetConfigProperty(TK_CustomShowName, Any(sTKCustomShowName));
208 {
209 Reference< XDrawPagesSupplier > xDrawPagesSupplier( mxController->getModel(), UNO_QUERY_THROW );
210 Reference< XDrawPages > xDrawPages( xDrawPagesSupplier->getDrawPages(), UNO_SET_THROW );
211 for( sal_Int32 i = 0; i < xDrawPages->getCount(); i++ )
212 {
213 Reference< XDrawPage > xDrawPage( xDrawPages->getByIndex( i ), UNO_QUERY_THROW );
214 Reference< XPropertySet > xPropSet( xDrawPage, UNO_QUERY_THROW );
215
216 bool bVisible = true;
217 if ( xPropSet->getPropertyValue( "Visible" ) >>= bVisible )
218 {
219 if (!bVisible )
220 nDeletedSlides++;
221 }
222 }
223 }
225 {
226 std::vector< PageCollector::MasterPageEntity > aMasterPageList;
227 PageCollector::CollectMasterPages( mxController->getModel(), aMasterPageList );
228 Reference< XMasterPagesSupplier > xMasterPagesSupplier( mxController->getModel(), UNO_QUERY_THROW );
229 Reference< XDrawPages > xMasterPages( xMasterPagesSupplier->getMasterPages(), UNO_SET_THROW );
230 nDeletedSlides += std::count_if(aMasterPageList.begin(), aMasterPageList.end(),
231 [](const PageCollector::MasterPageEntity& rEntity) { return !rEntity.bUsed; });
232 }
233 if ( nDeletedSlides > 1 )
234 {
235 OUString aStr( getString( STR_DELETE_SLIDES ) );
236 OUString aPlaceholder( "%SLIDES" );
237 sal_Int32 i = aStr.indexOf( aPlaceholder );
238 if ( i >= 0 )
239 aStr = aStr.replaceAt( i, aPlaceholder.getLength(), OUString::number( nDeletedSlides ) );
240 aSummaryStrings.push_back( aStr );
241 }
242
243// generating graphic compression info
244 sal_Int32 nGraphics = 0;
245 bool bJPEGCompression( GetConfigProperty( TK_JPEGCompression, false ) );
246 sal_Int32 nJPEGQuality( GetConfigProperty( TK_JPEGQuality, sal_Int32(90) ) );
247 sal_Int32 nImageResolution( GetConfigProperty( TK_ImageResolution, sal_Int32(0) ) );
248 GraphicSettings aGraphicSettings( bJPEGCompression, nJPEGQuality, GetConfigProperty( TK_RemoveCropArea, false ),
249 nImageResolution, GetConfigProperty( TK_EmbedLinkedGraphics, true ) );
250 GraphicCollector::CountGraphics( mxContext, mxController->getModel(), aGraphicSettings, nGraphics );
251 if ( nGraphics > 1 )
252 {
253 OUString aStr( getString( STR_OPTIMIZE_IMAGES ) );
254 OUString aImagePlaceholder( "%IMAGES" );
255 OUString aQualityPlaceholder( "%QUALITY" );
256 OUString aResolutionPlaceholder( "%RESOLUTION" );
257 sal_Int32 i = aStr.indexOf( aImagePlaceholder );
258 if ( i >= 0 )
259 aStr = aStr.replaceAt( i, aImagePlaceholder.getLength(), OUString::number( nGraphics ) );
260
261 sal_Int32 j = aStr.indexOf( aQualityPlaceholder );
262 if ( j >= 0 )
263 aStr = aStr.replaceAt( j, aQualityPlaceholder.getLength(), OUString::number( nJPEGQuality ) );
264
265 sal_Int32 k = aStr.indexOf( aResolutionPlaceholder );
266 if ( k >= 0 )
267 aStr = aStr.replaceAt( k, aResolutionPlaceholder.getLength(), OUString::number( nImageResolution ) );
268
269 aSummaryStrings.push_back( aStr );
270 }
271
273 {
274 sal_Int32 nOLEReplacements = 0;
275 Reference< XDrawPagesSupplier > xDrawPagesSupplier( mxController->getModel(), UNO_QUERY_THROW );
276 Reference< XDrawPages > xDrawPages( xDrawPagesSupplier->getDrawPages(), UNO_SET_THROW );
277 for ( sal_Int32 i = 0; i < xDrawPages->getCount(); i++ )
278 {
279 Reference< XShapes > xShapes( xDrawPages->getByIndex( i ), UNO_QUERY_THROW );
280 for ( sal_Int32 j = 0; j < xShapes->getCount(); j++ )
281 {
282 Reference< XShape > xShape( xShapes->getByIndex( j ), UNO_QUERY_THROW );
283 if ( xShape->getShapeType() == "com.sun.star.drawing.OLE2Shape" )
284 nOLEReplacements++;
285 }
286 }
287 if ( nOLEReplacements > 1 )
288 {
290 OUString aPlaceholder( "%OLE" );
291 sal_Int32 i = aStr.indexOf( aPlaceholder );
292 if ( i >= 0 )
293 aStr = aStr.replaceAt( i, aPlaceholder.getLength(), OUString::number( nOLEReplacements ) );
294 aSummaryStrings.push_back( aStr );
295 }
296 }
297 while( aSummaryStrings.size() < 3 )
298 aSummaryStrings.emplace_back( );
299
300 sal_Int64 nCurrentFileSize = 0;
301 sal_Int64 nEstimatedFileSize = 0;
302 Reference< XStorable > xStorable( mxController->getModel(), UNO_QUERY );
303 if ( xStorable.is() && xStorable->hasLocation() )
304 nCurrentFileSize = PPPOptimizer::GetFileSize( xStorable->getLocation() );
305
306 if ( nCurrentFileSize )
307 {
308 double fE = static_cast< double >( nCurrentFileSize );
309 if ( nImageResolution )
310 {
311 double v = ( static_cast< double >( nImageResolution ) + 75.0 ) / 300.0;
312 if ( v < 1.0 )
313 fE *= v;
314 }
315 if ( bJPEGCompression )
316 {
317 double v = 0.75 - ( ( 100.0 - static_cast< double >( nJPEGQuality ) ) / 400.0 ) ;
318 fE *= v;
319 }
320 nEstimatedFileSize = static_cast< sal_Int64 >( fE );
321 }
322 sal_Unicode nSeparator = '.';
323 OUString aStr( getString( STR_FILESIZESEPARATOR ) );
324 if ( !aStr.isEmpty() )
325 nSeparator = aStr[ 0 ];
326 mpPage4->UpdateControlStates(bSaveAs, bSaveSettingsEnabled, aItemList,
327 aSummaryStrings,
328 ImpValueOfInMB(nCurrentFileSize, nSeparator),
329 ImpValueOfInMB(nEstimatedFileSize, nSeparator));
330 SetConfigProperty( TK_EstimatedFileSize, Any( nEstimatedFileSize ) );
331}
332
334{
335 // creating a default session name that hasn't been used yet
336 OUString aSettingsName;
337 OUString aDefault( getString( STR_MY_SETTINGS ) );
338 sal_Int32 nSession = 1;
339 std::vector<OptimizerSettings>::size_type i;
340 const std::vector< OptimizerSettings >& rList( GetOptimizerSettings() );
341 do
342 {
343 OUString aTemp = aDefault + OUString::number( nSession++ );
344 for ( i = 1; i < rList.size(); i++ )
345 {
346 if ( rList[ i ].maName == aTemp )
347 break;
348 }
349 if ( i == rList.size() )
350 aSettingsName = aTemp;
351 }
352 while( aSettingsName.isEmpty() );
353
354 mpPage4->Init(aSettingsName, mbIsReadonly);
355
357}
358
359/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
OUString maName
std::vector< OptimizerSettings > & GetOptimizerSettings()
OUString getString(const PPPOptimizerTokenEnum) const
void SetConfigProperty(const PPPOptimizerTokenEnum, const css::uno::Any &aValue)
css::uno::Any GetConfigProperty(const PPPOptimizerTokenEnum) const
css::uno::Reference< css::uno::XComponentContext > mxContext
static void CountGraphics(const css::uno::Reference< css::uno::XComponentContext > &rxMSF, const css::uno::Reference< css::frame::XModel > &rxModel, const GraphicSettings &rGraphicSettings, sal_Int32 &rGraphics)
void UpdateControlStates(bool bJPEGCompression, int nJPEGQuality, bool bRemoveCropArea, int nResolution, bool bEmbedLinkedGraphics)
void UpdateControlStates(const std::vector< OUString > &rItemList, int nSelectedItem, bool bRemoveButtonEnabled)
void Init(const OUString &rDesc)
void UpdateControlStates(bool bConvertOLEObjects, int nOLEOptimizationType)
SummaryPage * mpPage4
css::uno::Reference< css::frame::XController > mxController
SlidesPage * mpPage1
ObjectsPage * mpPage3
ImagesPage * mpPage2
static void CollectMasterPages(const css::uno::Reference< css::frame::XModel > &, std::vector< MasterPageEntity > &)
void Init(const css::uno::Sequence< OUString > &rCustomShowList)
OUString Get_TK_CustomShowName() const
void UpdateControlStates(bool bDeleteUnusedMasterPages, bool bDeleteHiddenSlides, bool bDeleteNotesPages)
void Init(const OUString &rSettingsName, bool bIsReadonly)
void UpdateControlStates(bool bSaveAs, bool bSaveSettingsEnabled, const std::vector< OUString > &rItemList, const std::vector< OUString > &rSummaryStrings, const OUString &rCurrentFileSize, const OUString &rEstimatedFileSize)
std::unique_ptr< weld::Button > m_xHelp
float v
aStr
int i
sal_Int32 w
static OUString ImpValueOfInMB(sal_Int64 rVal, sal_Unicode nSeparator)
@ TK_EstimatedFileSize
@ TK_ImageResolution
@ STR_OPTIMIZE_IMAGES
@ STR_OLE_OBJECTS_DESC
@ STR_DELETE_SLIDES
@ TK_JPEGCompression
@ STR_FILESIZESEPARATOR
@ STR_CREATE_REPLACEMENT
@ TK_DeleteUnusedMasterPages
@ TK_DeleteHiddenSlides
@ TK_RemoveCropArea
@ STR_MY_SETTINGS
@ TK_JPEGQuality
@ TK_DeleteNotesPages
@ TK_OLEOptimization
@ STR_NO_OLE_OBJECTS_DESC
@ TK_EmbedLinkedGraphics
@ TK_OLEOptimizationType
@ TK_SaveAs
@ TK_CustomShowName
static sal_Int64 GetFileSize(const OUString &rURL)
Reference< XModel > xModel
bool bVisible
sal_uInt16 sal_Unicode