Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sdext / source / minimizer / optimizerdialog.cxx
blob773970a41b05d046e0bd4d12e342c8181ad02f20
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include "optimizerdialog.hxx"
22 #include "impoptimizer.hxx"
23 #include "fileopendialog.hxx"
24 #include <com/sun/star/awt/XItemEventBroadcaster.hpp>
25 #include <com/sun/star/beans/XPropertySet.hpp>
26 #include <com/sun/star/container/XIndexContainer.hpp>
27 #include <com/sun/star/frame/XStorable.hpp>
28 #include <com/sun/star/frame/XTitle.hpp>
29 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
30 #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
31 #include <com/sun/star/ucb/XSimpleFileAccess.hpp>
32 #include <com/sun/star/io/IOException.hpp>
33 #include <com/sun/star/util/XModifiable.hpp>
35 #include <comphelper/propertyvalue.hxx>
36 #include <sal/macros.h>
37 #include <osl/time.h>
38 #include <vcl/errinf.hxx>
39 #include <vcl/svapp.hxx>
40 #include <vcl/weld.hxx>
41 #include <svtools/sfxecode.hxx>
42 #include <svtools/ehdl.hxx>
43 #include <tools/urlobj.hxx>
44 #include <o3tl/string_view.hxx>
45 #include <bitmaps.hlst>
47 using namespace ::com::sun::star::io;
48 using namespace ::com::sun::star::ui;
49 using namespace ::com::sun::star::awt;
50 using namespace ::com::sun::star::ucb;
51 using namespace ::com::sun::star::uno;
52 using namespace ::com::sun::star::util;
53 using namespace ::com::sun::star::lang;
54 using namespace ::com::sun::star::frame;
55 using namespace ::com::sun::star::beans;
56 using namespace ::com::sun::star::container;
58 IntroPage::IntroPage(weld::Container* pPage, OptimizerDialog& rOptimizerDialog)
59 : vcl::OWizardPage(pPage, &rOptimizerDialog, "modules/simpress/ui/pmintropage.ui", "PMIntroPage")
60 , mrOptimizerDialog(rOptimizerDialog)
61 , mxComboBox(m_xBuilder->weld_combo_box("LB_SETTINGS"))
62 , mxButton(m_xBuilder->weld_button("STR_REMOVE"))
64 rOptimizerDialog.SetIntroPage(this);
65 mxComboBox->connect_changed(LINK(this, IntroPage, ComboBoxActionPerformed));
66 mxButton->connect_clicked(LINK(this, IntroPage, ButtonActionPerformed));
69 void IntroPage::UpdateControlStates(const std::vector<OUString>& rItemList, int nSelectedItem, bool bRemoveButtonEnabled)
71 mxComboBox->clear();
72 for (const auto& a : rItemList)
73 mxComboBox->append_text(a);
74 mxComboBox->set_active(nSelectedItem);
75 mxButton->set_sensitive(bRemoveButtonEnabled);
78 SlidesPage::SlidesPage(weld::Container* pPage, OptimizerDialog& rOptimizerDialog)
79 : vcl::OWizardPage(pPage, &rOptimizerDialog, "modules/simpress/ui/pmslidespage.ui", "PMSlidesPage")
80 , mrOptimizerDialog(rOptimizerDialog)
81 , mxMasterSlides(m_xBuilder->weld_check_button("STR_DELETE_MASTER_PAGES"))
82 , mxHiddenSlides(m_xBuilder->weld_check_button("STR_DELETE_HIDDEN_SLIDES"))
83 , mxUnusedSlides(m_xBuilder->weld_check_button("STR_CUSTOM_SHOW"))
84 , mxComboBox(m_xBuilder->weld_combo_box("LB_SLIDES"))
85 , mxClearNodes(m_xBuilder->weld_check_button("STR_DELETE_NOTES_PAGES"))
87 rOptimizerDialog.SetSlidesPage(this);
88 mxMasterSlides->connect_toggled(LINK(this, SlidesPage, UnusedMasterPagesActionPerformed));
89 mxHiddenSlides->connect_toggled(LINK(this, SlidesPage, UnusedHiddenSlidesActionPerformed));
90 mxUnusedSlides->connect_toggled(LINK(this, SlidesPage, UnusedSlidesActionPerformed));
91 mxClearNodes->connect_toggled(LINK(this, SlidesPage, DeleteNotesActionPerformed));
94 void SlidesPage::Init(const css::uno::Sequence<OUString>& rCustomShowList)
96 mxComboBox->clear();
97 for (const auto& a : rCustomShowList)
98 mxComboBox->append_text(a);
99 mxUnusedSlides->set_sensitive(rCustomShowList.hasElements());
102 void SlidesPage::UpdateControlStates(bool bDeleteUnusedMasterPages, bool bDeleteHiddenSlides, bool bDeleteNotesPages)
104 mxMasterSlides->set_active(bDeleteUnusedMasterPages);
105 mxHiddenSlides->set_active(bDeleteHiddenSlides);
106 mxClearNodes->set_active(bDeleteNotesPages);
107 mxComboBox->set_sensitive(mxUnusedSlides->get_sensitive());
110 ImagesPage::ImagesPage(weld::Container* pPage, OptimizerDialog& rOptimizerDialog)
111 : vcl::OWizardPage(pPage, &rOptimizerDialog, "modules/simpress/ui/pmimagespage.ui", "PMImagesPage")
112 , mrOptimizerDialog(rOptimizerDialog)
113 , m_xLossLessCompression(m_xBuilder->weld_radio_button("STR_LOSSLESS_COMPRESSION"))
114 , m_xQualityLabel(m_xBuilder->weld_label("STR_QUALITY"))
115 , m_xQuality(m_xBuilder->weld_spin_button("SB_QUALITY"))
116 , m_xJpegCompression(m_xBuilder->weld_radio_button("STR_JPEG_COMPRESSION"))
117 , m_xResolution(m_xBuilder->weld_combo_box("LB_RESOLUTION"))
118 , m_xRemoveCropArea(m_xBuilder->weld_check_button("STR_REMOVE_CROP_AREA"))
119 , m_xEmbedLinkedGraphics(m_xBuilder->weld_check_button("STR_EMBED_LINKED_GRAPHICS"))
121 rOptimizerDialog.SetImagesPage(this);
122 m_xRemoveCropArea->connect_toggled(LINK(this, ImagesPage, RemoveCropAreaActionPerformed));
123 m_xEmbedLinkedGraphics->connect_toggled(LINK(this, ImagesPage, EmbedLinkedGraphicsActionPerformed));
124 m_xResolution->connect_changed(LINK(this, ImagesPage, ComboBoxActionPerformed));
125 m_xQuality->connect_value_changed(LINK(this, ImagesPage, SpinButtonActionPerformed));
127 m_xJpegCompression->connect_toggled(LINK(this, ImagesPage, CompressionActionPerformed));
128 m_xLossLessCompression->connect_toggled(LINK(this, ImagesPage, CompressionActionPerformed));
131 void ImagesPage::UpdateControlStates(bool bJPEGCompression, int nJPEGQuality, bool bRemoveCropArea,
132 int nResolution, bool bEmbedLinkedGraphics)
134 m_xLossLessCompression->set_active(!bJPEGCompression);
135 m_xJpegCompression->set_active(bJPEGCompression);
136 m_xQualityLabel->set_sensitive(bJPEGCompression);
137 m_xQuality->set_sensitive(bJPEGCompression);
138 m_xQuality->set_value(nJPEGQuality);
139 m_xResolution->set_active_id(OUString::number(nResolution));
140 m_xRemoveCropArea->set_active(bRemoveCropArea);
141 m_xEmbedLinkedGraphics->set_active(bEmbedLinkedGraphics);
144 ObjectsPage::ObjectsPage(weld::Container* pPage, OptimizerDialog& rOptimizerDialog)
145 : vcl::OWizardPage(pPage, &rOptimizerDialog, "modules/simpress/ui/pmobjectspage.ui", "PMObjectsPage")
146 , mrOptimizerDialog(rOptimizerDialog)
147 , m_xCreateStaticImage(m_xBuilder->weld_check_button("STR_OLE_REPLACE"))
148 , m_xAllOLEObjects(m_xBuilder->weld_radio_button("STR_ALL_OLE_OBJECTS"))
149 , m_xForeignOLEObjects(m_xBuilder->weld_radio_button("STR_ALIEN_OLE_OBJECTS_ONLY"))
150 , m_xLabel(m_xBuilder->weld_label("STR_OLE_OBJECTS_DESC"))
152 rOptimizerDialog.SetObjectsPage(this);
153 m_xCreateStaticImage->connect_toggled(LINK(this, ObjectsPage, OLEOptimizationActionPerformed));
154 m_xAllOLEObjects->connect_toggled(LINK(this, ObjectsPage, OLEActionPerformed));
155 m_xForeignOLEObjects->connect_toggled(LINK(this, ObjectsPage, OLEActionPerformed));
158 void ObjectsPage::Init(const OUString& rDesc)
160 m_xLabel->set_label(rDesc);
163 void ObjectsPage::UpdateControlStates(bool bConvertOLEObjects, int nOLEOptimizationType)
165 m_xCreateStaticImage->set_active(bConvertOLEObjects);
166 m_xAllOLEObjects->set_sensitive(bConvertOLEObjects);
167 m_xForeignOLEObjects->set_sensitive(bConvertOLEObjects);
168 m_xAllOLEObjects->set_active(nOLEOptimizationType == 0);
169 m_xForeignOLEObjects->set_active(nOLEOptimizationType == 1);
172 SummaryPage::SummaryPage(weld::Container* pPage, OptimizerDialog& rOptimizerDialog)
173 : vcl::OWizardPage(pPage, &rOptimizerDialog, "modules/simpress/ui/pmsummarypage.ui", "PMSummaryPage")
174 , mrOptimizerDialog(rOptimizerDialog)
175 , m_xLabel1(m_xBuilder->weld_label("LABEL1"))
176 , m_xLabel2(m_xBuilder->weld_label("LABEL2"))
177 , m_xLabel3(m_xBuilder->weld_label("LABEL3"))
178 , m_xCurrentSize(m_xBuilder->weld_label("CURRENT_FILESIZE"))
179 , m_xEstimatedSize(m_xBuilder->weld_label("ESTIMATED_FILESIZE"))
180 , m_xStatus(m_xBuilder->weld_label("STR_STATUS"))
181 , m_xProgress(m_xBuilder->weld_progress_bar("PROGRESS"))
182 , m_xApplyToCurrent(m_xBuilder->weld_radio_button("STR_APPLY_TO_CURRENT"))
183 , m_xSaveToNew(m_xBuilder->weld_radio_button("STR_SAVE_AS"))
184 , m_xComboBox(m_xBuilder->weld_combo_box("MY_SETTINGS"))
185 , m_xSaveSettings(m_xBuilder->weld_check_button("STR_SAVE_SETTINGS"))
187 rOptimizerDialog.SetSummaryPage(this);
188 m_xApplyToCurrent->connect_toggled(LINK(this, SummaryPage, SaveAsNewActionPerformed));
189 m_xSaveToNew->connect_toggled(LINK(this, SummaryPage, SaveAsNewActionPerformed));
190 m_xSaveSettings->connect_toggled(LINK(this, SummaryPage, SaveSettingsActionPerformed));
193 void SummaryPage::Init(const OUString& rSettingsName, bool bIsReadonly)
195 m_xComboBox->set_entry_text(rSettingsName);
196 m_xApplyToCurrent->set_sensitive(!bIsReadonly);
197 m_xSaveToNew->set_sensitive(!bIsReadonly);
200 void SummaryPage::UpdateControlStates(bool bSaveAs, bool bSaveSettingsEnabled,
201 const std::vector<OUString>& rItemList,
202 const std::vector<OUString>& rSummaryStrings,
203 const OUString& rCurrentFileSize,
204 const OUString& rEstimatedFileSize)
206 m_xApplyToCurrent->set_active(!bSaveAs);
207 m_xSaveToNew->set_active(bSaveAs);
209 for (const auto& a : rItemList)
210 m_xComboBox->append_text(a);
212 m_xSaveSettings->set_sensitive(bSaveSettingsEnabled);
213 m_xComboBox->set_sensitive(bSaveSettingsEnabled && m_xSaveSettings->get_active());
215 assert(rSummaryStrings.size() == 3);
216 m_xLabel1->set_label(rSummaryStrings[0]);
217 m_xLabel2->set_label(rSummaryStrings[1]);
218 m_xLabel3->set_label(rSummaryStrings[2]);
220 m_xCurrentSize->set_label(rCurrentFileSize);
221 m_xEstimatedSize->set_label(rEstimatedFileSize);
224 void SummaryPage::UpdateStatusLabel(const OUString& rStatus)
226 m_xStatus->set_label(rStatus);
229 void SummaryPage::UpdateProgressValue(int nProgress)
231 m_xProgress->set_percentage(nProgress);
234 void OptimizerDialog::InitDialog()
236 set_title(getString(STR_SUN_OPTIMIZATION_WIZARD2));
239 void OptimizerDialog::InitRoadmap()
241 declarePath(
243 {ITEM_ID_INTRODUCTION,
244 ITEM_ID_SLIDES,
245 ITEM_ID_GRAPHIC_OPTIMIZATION,
246 ITEM_ID_OLE_OPTIMIZATION,
247 ITEM_ID_SUMMARY}
250 m_xAssistant->set_page_side_image(BMP_PRESENTATION_MINIMIZER);
253 void OptimizerDialog::UpdateConfiguration()
255 // page0
256 OUString sTKName(mpPage0->Get_TK_Name());
257 if (!sTKName.isEmpty())
258 SetConfigProperty(TK_Name, Any(sTKName));
260 // page1
261 OUString sTKCustomShowName(mpPage1->Get_TK_CustomShowName());
262 if (!sTKCustomShowName.isEmpty())
263 SetConfigProperty(TK_CustomShowName, Any(sTKCustomShowName));
266 OptimizerDialog::OptimizerDialog( const Reference< XComponentContext > &rxContext, Reference< XFrame > const & rxFrame, Reference< XDispatch > const & rxStatusDispatcher )
267 : vcl::RoadmapWizardMachine(Application::GetFrameWeld(rxFrame->getComponentWindow()))
268 , ConfigurationAccess(rxContext)
269 , mnEndStatus(RET_CANCEL)
270 , mxFrame(rxFrame)
271 , mxController(rxFrame->getController())
272 , mxStatusDispatcher(rxStatusDispatcher)
274 Reference< XStorable > xStorable( mxController->getModel(), UNO_QUERY_THROW );
275 mbIsReadonly = xStorable->isReadonly();
277 InitDialog();
278 InitRoadmap();
279 InitNavigationBar();
280 InitPage0();
281 InitPage1();
282 InitPage2();
283 InitPage3();
284 InitPage4();
286 ActivatePage();
287 m_xAssistant->set_current_page(0);
289 OptimizationStats aStats;
290 aStats.InitializeStatusValuesFromDocument( mxController->getModel() );
291 Sequence< PropertyValue > aStatusSequence( aStats.GetStatusSequence() );
292 UpdateStatus( aStatusSequence );
295 OUString OptimizerDialog::getStateDisplayName(vcl::WizardTypes::WizardState nState) const
297 switch (nState)
299 case ITEM_ID_INTRODUCTION:
300 return getString(STR_INTRODUCTION);
301 case ITEM_ID_SLIDES:
302 return getString(STR_SLIDES);
303 case ITEM_ID_GRAPHIC_OPTIMIZATION:
304 return getString(STR_IMAGE_OPTIMIZATION);
305 case ITEM_ID_OLE_OPTIMIZATION:
306 return getString(STR_OLE_OBJECTS);
307 case ITEM_ID_SUMMARY:
308 return getString(STR_SUMMARY);
310 return OUString();
313 std::unique_ptr<BuilderPage> OptimizerDialog::createPage(vcl::WizardTypes::WizardState nState)
315 OUString sIdent(OUString::number(nState));
316 weld::Container* pPageContainer = m_xAssistant->append_page(sIdent);
318 std::unique_ptr<vcl::OWizardPage> xRet;
320 switch (nState)
322 case ITEM_ID_INTRODUCTION:
323 xRet.reset(new IntroPage(pPageContainer, *this));
324 break;
325 case ITEM_ID_SLIDES:
326 xRet.reset(new SlidesPage(pPageContainer, *this));
327 break;
328 case ITEM_ID_GRAPHIC_OPTIMIZATION:
329 xRet.reset(new ImagesPage(pPageContainer, *this));
330 break;
331 case ITEM_ID_OLE_OPTIMIZATION:
332 xRet.reset(new ObjectsPage(pPageContainer, *this));
333 break;
334 case ITEM_ID_SUMMARY:
335 xRet.reset(new SummaryPage(pPageContainer, *this));
336 break;
339 m_xAssistant->set_page_title(sIdent, getStateDisplayName(nState));
341 return xRet;
344 OptimizerDialog::~OptimizerDialog()
346 // not saving configuration if the dialog has been finished via cancel or close window
347 if (mnEndStatus == RET_OK)
348 SaveConfiguration();
351 void OptimizerDialog::execute()
353 mnEndStatus = run();
354 UpdateConfiguration(); // taking actual control settings for the configuration
357 void OptimizerDialog::UpdateControlStates( sal_Int16 nPage )
359 switch( nPage )
361 case 0 : UpdateControlStatesPage0(); break;
362 case 1 : UpdateControlStatesPage1(); break;
363 case 2 : UpdateControlStatesPage2(); break;
364 case 3 : UpdateControlStatesPage3(); break;
365 case 4 : UpdateControlStatesPage4(); break;
366 default:
368 UpdateControlStatesPage0();
369 UpdateControlStatesPage1();
370 UpdateControlStatesPage2();
371 UpdateControlStatesPage3();
372 UpdateControlStatesPage4();
377 void OptimizerDialog::UpdateStatus( const css::uno::Sequence< css::beans::PropertyValue >& rStatus )
379 maStats.InitializeStatusValues( rStatus );
380 const Any* pVal( maStats.GetStatusValue( TK_Status ) );
381 if ( pVal )
383 OUString sStatus;
384 if ( *pVal >>= sStatus )
386 mpPage4->UpdateStatusLabel(getString(TKGet(sStatus)));
389 pVal = maStats.GetStatusValue( TK_Progress );
390 if ( pVal )
392 sal_Int32 nProgress = 0;
393 if ( *pVal >>= nProgress )
394 mpPage4->UpdateProgressValue(nProgress);
396 pVal = maStats.GetStatusValue( TK_OpenNewDocument );
397 if ( pVal )
398 SetConfigProperty( TK_OpenNewDocument, *pVal );
400 Application::Reschedule(true);
403 IMPL_LINK(SummaryPage, SaveAsNewActionPerformed, weld::Toggleable&, rBox, void)
405 if (!rBox.get_active())
406 return;
408 const bool bSaveToNew = &rBox == m_xSaveToNew.get();
409 mrOptimizerDialog.SetConfigProperty( TK_SaveAs, Any(bSaveToNew) );
412 IMPL_LINK(SummaryPage, SaveSettingsActionPerformed, weld::Toggleable&, rBox, void)
414 m_xComboBox->set_sensitive(rBox.get_active());
417 IMPL_LINK(ObjectsPage, OLEActionPerformed, weld::Toggleable&, rBox, void)
419 if (!rBox.get_active())
420 return;
422 const bool bALLOles = &rBox == m_xAllOLEObjects.get();
423 sal_Int16 nInt16 = bALLOles ? 0 : 1;
424 mrOptimizerDialog.SetConfigProperty( TK_OLEOptimizationType, Any( nInt16 ) );
427 IMPL_LINK(ObjectsPage, OLEOptimizationActionPerformed, weld::Toggleable&, rBox, void)
429 const bool bOLEOptimization = rBox.get_active();
430 mrOptimizerDialog.SetConfigProperty( TK_OLEOptimization, Any(bOLEOptimization) );
431 m_xAllOLEObjects->set_sensitive(bOLEOptimization);
432 m_xForeignOLEObjects->set_sensitive(bOLEOptimization);
435 IMPL_LINK(ImagesPage, CompressionActionPerformed, weld::Toggleable&, rBox, void)
437 if (!rBox.get_active())
438 return;
440 const bool bJPEGCompression = &rBox == m_xJpegCompression.get();
441 mrOptimizerDialog.SetConfigProperty(TK_JPEGCompression, Any(bJPEGCompression));
442 m_xQualityLabel->set_sensitive(bJPEGCompression);
443 m_xQuality->set_sensitive(bJPEGCompression);
446 IMPL_LINK(ImagesPage, RemoveCropAreaActionPerformed, weld::Toggleable&, rBox, void)
448 mrOptimizerDialog.SetConfigProperty(TK_RemoveCropArea, Any(rBox.get_active()));
451 IMPL_LINK(ImagesPage, EmbedLinkedGraphicsActionPerformed, weld::Toggleable&, rBox, void)
453 mrOptimizerDialog.SetConfigProperty(TK_EmbedLinkedGraphics, Any(rBox.get_active()));
456 IMPL_LINK(SlidesPage, UnusedHiddenSlidesActionPerformed, weld::Toggleable&, rBox, void)
458 mrOptimizerDialog.SetConfigProperty(TK_DeleteHiddenSlides, Any(rBox.get_active()));
461 IMPL_LINK(SlidesPage, UnusedMasterPagesActionPerformed, weld::Toggleable&, rBox, void)
463 mrOptimizerDialog.SetConfigProperty(TK_DeleteUnusedMasterPages, Any(rBox.get_active()));
466 IMPL_LINK(SlidesPage, DeleteNotesActionPerformed, weld::Toggleable&, rBox, void)
468 mrOptimizerDialog.SetConfigProperty(TK_DeleteNotesPages, Any(rBox.get_active()));
471 IMPL_LINK(SlidesPage, UnusedSlidesActionPerformed, weld::Toggleable&, rBox, void)
473 mxComboBox->set_sensitive(rBox.get_active());
476 bool OptimizerDialog::onFinish()
478 UpdateConfiguration();
480 ShowPage(ITEM_ID_SUMMARY);
481 m_xPrevPage->set_sensitive(false);
482 m_xNextPage->set_sensitive(false);
483 m_xFinish->set_sensitive(false);
484 m_xCancel->set_sensitive(false);
486 // check if we have to open the FileDialog
487 bool bSuccessfullyExecuted = true;
488 if (mpPage4->GetSaveAsNew())
490 // Duplicate presentation before applying changes
491 OUString aSaveAsURL;
492 FileOpenDialog aFileOpenDialog(mxContext);
494 // generating default file name
495 OUString aName;
496 Reference< XStorable > xStorable( mxController->getModel(), UNO_QUERY );
497 if ( xStorable.is() && xStorable->hasLocation() )
499 INetURLObject aURLObj( xStorable->getLocation() );
500 if ( !aURLObj.hasFinalSlash() )
502 // tdf#105382 uri-decode file name
503 aURLObj.removeExtension(INetURLObject::LAST_SEGMENT, false);
504 aName = aURLObj.getName(INetURLObject::LAST_SEGMENT, false,
505 INetURLObject::DecodeMechanism::WithCharset);
508 else
510 // If no filename, try to use model title ("Untitled 1" or something like this)
511 Reference<XTitle> xTitle(
512 GetFrame()->getController()->getModel(), UNO_QUERY);
513 aName = xTitle->getTitle();
516 if (!aName.isEmpty())
518 aName += " " + getString(STR_FILENAME_SUFFIX);
519 aFileOpenDialog.setDefaultName(aName);
522 if (aFileOpenDialog.execute() == dialogs::ExecutableDialogResults::OK)
524 aSaveAsURL = aFileOpenDialog.getURL();
525 SetConfigProperty( TK_SaveAsURL, Any( aSaveAsURL ) );
526 SetConfigProperty( TK_FilterName, Any( aFileOpenDialog.getFilterName() ) );
528 if ( aSaveAsURL.isEmpty() )
530 // something goes wrong...
531 bSuccessfullyExecuted = false;
534 // waiting for 500ms
535 Application::Reschedule(true);
536 for ( sal_uInt32 i = osl_getGlobalTimer(); ( i + 500 ) > ( osl_getGlobalTimer() ); )
537 Application::Reschedule(true);
539 else
541 // Apply changes to current presentation
542 Reference<XModifiable> xModifiable(mxController->getModel(),
543 UNO_QUERY_THROW );
544 if ( xModifiable->isModified() )
546 SolarMutexGuard aSolarGuard;
547 std::unique_ptr<weld::MessageDialog> popupDlg(Application::CreateMessageDialog(
548 m_xAssistant.get(), VclMessageType::Question, VclButtonsType::YesNo,
549 getString(STR_WARN_UNSAVED_PRESENTATION)));
550 if (popupDlg->run() != RET_YES)
552 // Selected not "yes" ("no" or dialog was cancelled) so return to previous step
553 m_xPrevPage->set_sensitive(true);
554 m_xNextPage->set_sensitive(true);
555 m_xFinish->set_sensitive(true);
556 m_xCancel->set_sensitive(true);
557 return false;
561 if ( bSuccessfullyExecuted )
563 // now check if we have to store a session template
564 const bool bSaveSettings = mpPage4->GetSaveSettings();
565 OUString aSettingsName = mpPage4->GetSettingsName();
566 if (bSaveSettings && !aSettingsName.isEmpty())
568 std::vector< OptimizerSettings >::iterator aIter( GetOptimizerSettingsByName( aSettingsName ) );
569 std::vector< OptimizerSettings >& rSettings( GetOptimizerSettings() );
570 OptimizerSettings aNewSettings( rSettings[ 0 ] );
571 aNewSettings.maName = aSettingsName;
572 if ( aIter == rSettings.end() )
573 rSettings.push_back( aNewSettings );
574 else
575 *aIter = aNewSettings;
578 if ( bSuccessfullyExecuted )
580 URL aURL;
581 aURL.Protocol = "vnd.com.sun.star.comp.PPPOptimizer:";
582 aURL.Path = "optimize";
584 Sequence< PropertyValue > lArguments{
585 comphelper::makePropertyValue("Settings", GetConfigurationSequence()),
586 comphelper::makePropertyValue("StatusDispatcher", GetStatusDispatcher()),
587 comphelper::makePropertyValue("DocumentFrame", GetFrame()),
588 comphelper::makePropertyValue("DialogParentWindow", m_xAssistant->GetXWindow())
591 ErrCode errorCode;
594 ImpOptimizer aOptimizer(mxContext, GetFrame()->getController()->getModel());
595 aOptimizer.Optimize(lArguments);
597 catch (css::io::IOException&)
599 // We always receive just ERRCODE_IO_CANTWRITE in case of problems, so no need to bother
600 // about extracting error code from exception text
601 errorCode = ERRCODE_IO_CANTWRITE;
603 catch (css::uno::Exception&)
605 // Other general exception
606 errorCode = ERRCODE_IO_GENERAL;
609 if (errorCode != ERRCODE_NONE)
611 // Restore wizard controls
612 maStats.SetStatusValue(TK_Progress, Any(static_cast<sal_Int32>(0)));
613 m_xPrevPage->set_sensitive(true);
614 m_xNextPage->set_sensitive(false);
615 m_xFinish->set_sensitive(true);
616 m_xCancel->set_sensitive(true);
618 OUString aFileName;
619 GetConfigProperty(TK_SaveAsURL) >>= aFileName;
620 SfxErrorContext aEc(ERRCTX_SFX_SAVEASDOC, aFileName);
621 ErrorHandler::HandleError(errorCode);
622 return false;
625 else
627 m_xPrevPage->set_sensitive(true);
628 m_xNextPage->set_sensitive(false);
629 m_xFinish->set_sensitive(true);
630 m_xCancel->set_sensitive(true);
633 return vcl::RoadmapWizardMachine::onFinish();
636 IMPL_LINK_NOARG(IntroPage, ButtonActionPerformed, weld::Button&, void)
638 // delete configuration
639 OUString aSelectedItem(mxComboBox->get_active_text());
640 if ( !aSelectedItem.isEmpty() )
642 std::vector< OptimizerSettings >::iterator aIter( mrOptimizerDialog.GetOptimizerSettingsByName( aSelectedItem ) );
643 std::vector< OptimizerSettings >& rList( mrOptimizerDialog.GetOptimizerSettings() );
644 if ( aIter != rList.end() )
646 rList.erase( aIter );
647 mrOptimizerDialog.UpdateControlStates();
652 IMPL_LINK(IntroPage, ComboBoxActionPerformed, weld::ComboBox&, rBox, void)
654 OUString sActionCommand(rBox.get_active_text());
655 if (!sActionCommand.isEmpty())
657 std::vector< OptimizerSettings >::iterator aIter( mrOptimizerDialog.GetOptimizerSettingsByName(sActionCommand) );
658 std::vector< OptimizerSettings >& rList( mrOptimizerDialog.GetOptimizerSettings() );
659 if ( aIter != rList.end() )
660 rList[ 0 ] = *aIter;
662 mrOptimizerDialog.UpdateControlStates();
665 IMPL_LINK(ImagesPage, SpinButtonActionPerformed, weld::SpinButton&, rBox, void)
667 mrOptimizerDialog.SetConfigProperty( TK_JPEGQuality, Any( static_cast<sal_Int32>(rBox.get_value()) ) );
670 IMPL_LINK_NOARG(ImagesPage, ComboBoxActionPerformed, weld::ComboBox&, void)
672 mrOptimizerDialog.SetConfigProperty( TK_ImageResolution, Any( m_xResolution->get_active_id().toInt32() ) );
675 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */