1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
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::uno
;
51 using namespace ::com::sun::star::util
;
52 using namespace ::com::sun::star::frame
;
53 using namespace ::com::sun::star::beans
;
55 using vcl::RoadmapWizardTypes::PathId
;
57 OptimizedDialogPage::OptimizedDialogPage(weld::Container
* pPage
, OptimizerDialog
& rOptimizerDialog
,
58 const OUString
& rUIXMLDescription
, const OUString
& rID
,
60 : vcl::OWizardPage(pPage
, &rOptimizerDialog
, rUIXMLDescription
, rID
)
61 , mrOptimizerDialog(rOptimizerDialog
)
62 , m_nPageNum(nPageNum
)
66 void OptimizedDialogPage::Activate()
68 vcl::OWizardPage::Activate();
69 mrOptimizerDialog
.UpdateControlStates(m_nPageNum
);
72 IntroPage::IntroPage(weld::Container
* pPage
, OptimizerDialog
& rOptimizerDialog
)
73 : OptimizedDialogPage(pPage
, rOptimizerDialog
, u
"modules/simpress/ui/pmintropage.ui"_ustr
, u
"PMIntroPage"_ustr
, 0)
74 , mxComboBox(m_xBuilder
->weld_combo_box(u
"LB_SETTINGS"_ustr
))
75 , mxButton(m_xBuilder
->weld_button(u
"STR_REMOVE"_ustr
))
77 rOptimizerDialog
.SetIntroPage(this);
78 mxComboBox
->connect_changed(LINK(this, IntroPage
, ComboBoxActionPerformed
));
79 mxButton
->connect_clicked(LINK(this, IntroPage
, ButtonActionPerformed
));
82 void IntroPage::UpdateControlStates(const std::vector
<OUString
>& rItemList
, int nSelectedItem
, bool bRemoveButtonEnabled
)
85 for (const auto& a
: rItemList
)
86 mxComboBox
->append_text(a
);
87 mxComboBox
->set_active(nSelectedItem
);
88 mxButton
->set_sensitive(bRemoveButtonEnabled
);
91 SlidesPage::SlidesPage(weld::Container
* pPage
, OptimizerDialog
& rOptimizerDialog
)
92 : OptimizedDialogPage(pPage
, rOptimizerDialog
, u
"modules/simpress/ui/pmslidespage.ui"_ustr
, u
"PMSlidesPage"_ustr
, 1)
93 , mxMasterSlides(m_xBuilder
->weld_check_button(u
"STR_DELETE_MASTER_PAGES"_ustr
))
94 , mxHiddenSlides(m_xBuilder
->weld_check_button(u
"STR_DELETE_HIDDEN_SLIDES"_ustr
))
95 , mxUnusedSlides(m_xBuilder
->weld_check_button(u
"STR_CUSTOM_SHOW"_ustr
))
96 , mxComboBox(m_xBuilder
->weld_combo_box(u
"LB_SLIDES"_ustr
))
97 , mxClearNodes(m_xBuilder
->weld_check_button(u
"STR_DELETE_NOTES_PAGES"_ustr
))
99 rOptimizerDialog
.SetSlidesPage(this);
100 mxMasterSlides
->connect_toggled(LINK(this, SlidesPage
, UnusedMasterPagesActionPerformed
));
101 mxHiddenSlides
->connect_toggled(LINK(this, SlidesPage
, UnusedHiddenSlidesActionPerformed
));
102 mxUnusedSlides
->connect_toggled(LINK(this, SlidesPage
, UnusedSlidesActionPerformed
));
103 mxClearNodes
->connect_toggled(LINK(this, SlidesPage
, DeleteNotesActionPerformed
));
106 void SlidesPage::Init(const css::uno::Sequence
<OUString
>& rCustomShowList
)
109 for (const auto& a
: rCustomShowList
)
110 mxComboBox
->append_text(a
);
111 mxUnusedSlides
->set_sensitive(rCustomShowList
.hasElements());
114 void SlidesPage::UpdateControlStates(bool bDeleteUnusedMasterPages
, bool bDeleteHiddenSlides
, bool bDeleteNotesPages
)
116 mxMasterSlides
->set_active(bDeleteUnusedMasterPages
);
117 mxHiddenSlides
->set_active(bDeleteHiddenSlides
);
118 mxClearNodes
->set_active(bDeleteNotesPages
);
119 mxComboBox
->set_sensitive(mxUnusedSlides
->get_sensitive());
122 ImagesPage::ImagesPage(weld::Container
* pPage
, OptimizerDialog
& rOptimizerDialog
)
123 : OptimizedDialogPage(pPage
, rOptimizerDialog
, u
"modules/simpress/ui/pmimagespage.ui"_ustr
, u
"PMImagesPage"_ustr
, 2)
124 , m_xLossLessCompression(m_xBuilder
->weld_radio_button(u
"STR_LOSSLESS_COMPRESSION"_ustr
))
125 , m_xQualityLabel(m_xBuilder
->weld_label(u
"STR_QUALITY"_ustr
))
126 , m_xQuality(m_xBuilder
->weld_spin_button(u
"SB_QUALITY"_ustr
))
127 , m_xJpegCompression(m_xBuilder
->weld_radio_button(u
"STR_JPEG_COMPRESSION"_ustr
))
128 , m_xResolution(m_xBuilder
->weld_combo_box(u
"LB_RESOLUTION"_ustr
))
129 , m_xRemoveCropArea(m_xBuilder
->weld_check_button(u
"STR_REMOVE_CROP_AREA"_ustr
))
130 , m_xEmbedLinkedGraphics(m_xBuilder
->weld_check_button(u
"STR_EMBED_LINKED_GRAPHICS"_ustr
))
132 rOptimizerDialog
.SetImagesPage(this);
133 m_xRemoveCropArea
->connect_toggled(LINK(this, ImagesPage
, RemoveCropAreaActionPerformed
));
134 m_xEmbedLinkedGraphics
->connect_toggled(LINK(this, ImagesPage
, EmbedLinkedGraphicsActionPerformed
));
135 m_xResolution
->connect_changed(LINK(this, ImagesPage
, ComboBoxActionPerformed
));
136 m_xQuality
->connect_value_changed(LINK(this, ImagesPage
, SpinButtonActionPerformed
));
138 m_xJpegCompression
->connect_toggled(LINK(this, ImagesPage
, CompressionActionPerformed
));
139 m_xLossLessCompression
->connect_toggled(LINK(this, ImagesPage
, CompressionActionPerformed
));
142 void ImagesPage::UpdateControlStates(bool bJPEGCompression
, int nJPEGQuality
, bool bRemoveCropArea
,
143 int nResolution
, bool bEmbedLinkedGraphics
)
145 m_xLossLessCompression
->set_active(!bJPEGCompression
);
146 m_xJpegCompression
->set_active(bJPEGCompression
);
147 m_xQualityLabel
->set_sensitive(bJPEGCompression
);
148 m_xQuality
->set_sensitive(bJPEGCompression
);
149 m_xQuality
->set_value(nJPEGQuality
);
150 m_xResolution
->set_active_id(OUString::number(nResolution
));
151 m_xRemoveCropArea
->set_active(bRemoveCropArea
);
152 m_xEmbedLinkedGraphics
->set_active(bEmbedLinkedGraphics
);
155 ObjectsPage::ObjectsPage(weld::Container
* pPage
, OptimizerDialog
& rOptimizerDialog
)
156 : OptimizedDialogPage(pPage
, rOptimizerDialog
, u
"modules/simpress/ui/pmobjectspage.ui"_ustr
, u
"PMObjectsPage"_ustr
, 3)
157 , m_xCreateStaticImage(m_xBuilder
->weld_check_button(u
"STR_OLE_REPLACE"_ustr
))
158 , m_xAllOLEObjects(m_xBuilder
->weld_radio_button(u
"STR_ALL_OLE_OBJECTS"_ustr
))
159 , m_xForeignOLEObjects(m_xBuilder
->weld_radio_button(u
"STR_ALIEN_OLE_OBJECTS_ONLY"_ustr
))
160 , m_xLabel(m_xBuilder
->weld_label(u
"STR_OLE_OBJECTS_DESC"_ustr
))
162 rOptimizerDialog
.SetObjectsPage(this);
163 m_xCreateStaticImage
->connect_toggled(LINK(this, ObjectsPage
, OLEOptimizationActionPerformed
));
164 m_xAllOLEObjects
->connect_toggled(LINK(this, ObjectsPage
, OLEActionPerformed
));
165 m_xForeignOLEObjects
->connect_toggled(LINK(this, ObjectsPage
, OLEActionPerformed
));
168 void ObjectsPage::Init(const OUString
& rDesc
)
170 m_xLabel
->set_label(rDesc
);
173 void ObjectsPage::UpdateControlStates(bool bConvertOLEObjects
, int nOLEOptimizationType
)
175 m_xCreateStaticImage
->set_active(bConvertOLEObjects
);
176 m_xAllOLEObjects
->set_sensitive(bConvertOLEObjects
);
177 m_xForeignOLEObjects
->set_sensitive(bConvertOLEObjects
);
178 m_xAllOLEObjects
->set_active(nOLEOptimizationType
== 0);
179 m_xForeignOLEObjects
->set_active(nOLEOptimizationType
== 1);
182 SummaryPage::SummaryPage(weld::Container
* pPage
, OptimizerDialog
& rOptimizerDialog
)
183 : OptimizedDialogPage(pPage
, rOptimizerDialog
, u
"modules/simpress/ui/pmsummarypage.ui"_ustr
, u
"PMSummaryPage"_ustr
, 4)
184 , m_xLabel1(m_xBuilder
->weld_label(u
"LABEL1"_ustr
))
185 , m_xLabel2(m_xBuilder
->weld_label(u
"LABEL2"_ustr
))
186 , m_xLabel3(m_xBuilder
->weld_label(u
"LABEL3"_ustr
))
187 , m_xCurrentSize(m_xBuilder
->weld_label(u
"CURRENT_FILESIZE"_ustr
))
188 , m_xEstimatedSize(m_xBuilder
->weld_label(u
"ESTIMATED_FILESIZE"_ustr
))
189 , m_xStatus(m_xBuilder
->weld_label(u
"STR_STATUS"_ustr
))
190 , m_xProgress(m_xBuilder
->weld_progress_bar(u
"PROGRESS"_ustr
))
191 , m_xApplyToCurrent(m_xBuilder
->weld_radio_button(u
"STR_APPLY_TO_CURRENT"_ustr
))
192 , m_xSaveToNew(m_xBuilder
->weld_radio_button(u
"STR_SAVE_AS"_ustr
))
193 , m_xComboBox(m_xBuilder
->weld_combo_box(u
"MY_SETTINGS"_ustr
))
194 , m_xSaveSettings(m_xBuilder
->weld_check_button(u
"STR_SAVE_SETTINGS"_ustr
))
196 rOptimizerDialog
.SetSummaryPage(this);
197 m_xApplyToCurrent
->connect_toggled(LINK(this, SummaryPage
, SaveAsNewActionPerformed
));
198 m_xSaveToNew
->connect_toggled(LINK(this, SummaryPage
, SaveAsNewActionPerformed
));
199 m_xSaveSettings
->connect_toggled(LINK(this, SummaryPage
, SaveSettingsActionPerformed
));
202 void SummaryPage::Init(const OUString
& rSettingsName
, bool bIsReadonly
)
204 m_xComboBox
->set_entry_text(rSettingsName
);
205 m_xApplyToCurrent
->set_sensitive(!bIsReadonly
);
206 m_xSaveToNew
->set_sensitive(!bIsReadonly
);
209 void SummaryPage::UpdateControlStates(bool bSaveAs
, bool bSaveSettingsEnabled
,
210 const std::vector
<OUString
>& rItemList
,
211 const std::vector
<OUString
>& rSummaryStrings
,
212 const OUString
& rCurrentFileSize
,
213 const OUString
& rEstimatedFileSize
)
215 m_xApplyToCurrent
->set_active(!bSaveAs
);
216 m_xSaveToNew
->set_active(bSaveAs
);
218 for (const auto& a
: rItemList
)
219 m_xComboBox
->append_text(a
);
221 m_xSaveSettings
->set_sensitive(bSaveSettingsEnabled
);
222 m_xComboBox
->set_sensitive(bSaveSettingsEnabled
&& m_xSaveSettings
->get_active());
224 assert(rSummaryStrings
.size() == 3);
225 m_xLabel1
->set_label(rSummaryStrings
[0]);
226 m_xLabel2
->set_label(rSummaryStrings
[1]);
227 m_xLabel3
->set_label(rSummaryStrings
[2]);
229 m_xCurrentSize
->set_label(rCurrentFileSize
);
230 m_xEstimatedSize
->set_label(rEstimatedFileSize
);
233 void SummaryPage::UpdateStatusLabel(const OUString
& rStatus
)
235 m_xStatus
->set_label(rStatus
);
238 void SummaryPage::UpdateProgressValue(int nProgress
)
240 m_xProgress
->set_percentage(nProgress
);
243 void OptimizerDialog::InitDialog()
245 set_title(getString(STR_SUN_OPTIMIZATION_WIZARD2
));
248 void OptimizerDialog::InitRoadmap()
251 PathId::COMMON_FIRST_STATE
,
252 {ITEM_ID_INTRODUCTION
,
254 ITEM_ID_GRAPHIC_OPTIMIZATION
,
255 ITEM_ID_OLE_OPTIMIZATION
,
259 m_xAssistant
->set_page_side_image(u
"" BMP_PRESENTATION_MINIMIZER
""_ustr
);
262 void OptimizerDialog::UpdateConfiguration()
265 OUString
sTKName(mpPage0
->Get_TK_Name());
266 if (!sTKName
.isEmpty())
267 SetConfigProperty(TK_Name
, Any(sTKName
));
270 OUString
sTKCustomShowName(mpPage1
->Get_TK_CustomShowName());
271 if (!sTKCustomShowName
.isEmpty())
272 SetConfigProperty(TK_CustomShowName
, Any(sTKCustomShowName
));
275 OptimizerDialog::OptimizerDialog( const Reference
< XComponentContext
> &rxContext
, Reference
< XFrame
> const & rxFrame
, Reference
< XDispatch
> const & rxStatusDispatcher
)
276 : vcl::RoadmapWizardMachine(Application::GetFrameWeld(rxFrame
->getComponentWindow()))
277 , ConfigurationAccess(rxContext
)
278 , mnEndStatus(RET_CANCEL
)
280 , mxController(rxFrame
->getController())
281 , mxStatusDispatcher(rxStatusDispatcher
)
283 Reference
< XStorable
> xStorable( mxController
->getModel(), UNO_QUERY_THROW
);
284 mbIsReadonly
= xStorable
->isReadonly();
296 m_xAssistant
->set_current_page(0);
298 OptimizationStats aStats
;
299 aStats
.InitializeStatusValuesFromDocument( mxController
->getModel() );
300 Sequence
< PropertyValue
> aStatusSequence( aStats
.GetStatusSequence() );
301 UpdateStatus( aStatusSequence
);
304 OUString
OptimizerDialog::getStateDisplayName(vcl::WizardTypes::WizardState nState
) const
308 case ITEM_ID_INTRODUCTION
:
309 return getString(STR_INTRODUCTION
);
311 return getString(STR_SLIDES
);
312 case ITEM_ID_GRAPHIC_OPTIMIZATION
:
313 return getString(STR_IMAGE_OPTIMIZATION
);
314 case ITEM_ID_OLE_OPTIMIZATION
:
315 return getString(STR_OLE_OBJECTS
);
316 case ITEM_ID_SUMMARY
:
317 return getString(STR_SUMMARY
);
322 std::unique_ptr
<BuilderPage
> OptimizerDialog::createPage(vcl::WizardTypes::WizardState nState
)
324 OUString
sIdent(OUString::number(nState
));
325 weld::Container
* pPageContainer
= m_xAssistant
->append_page(sIdent
);
327 std::unique_ptr
<vcl::OWizardPage
> xRet
;
331 case ITEM_ID_INTRODUCTION
:
332 xRet
.reset(new IntroPage(pPageContainer
, *this));
335 xRet
.reset(new SlidesPage(pPageContainer
, *this));
337 case ITEM_ID_GRAPHIC_OPTIMIZATION
:
338 xRet
.reset(new ImagesPage(pPageContainer
, *this));
340 case ITEM_ID_OLE_OPTIMIZATION
:
341 xRet
.reset(new ObjectsPage(pPageContainer
, *this));
343 case ITEM_ID_SUMMARY
:
344 xRet
.reset(new SummaryPage(pPageContainer
, *this));
348 m_xAssistant
->set_page_title(sIdent
, getStateDisplayName(nState
));
353 OptimizerDialog::~OptimizerDialog()
355 // not saving configuration if the dialog has been finished via cancel or close window
356 if (mnEndStatus
== RET_OK
)
360 void OptimizerDialog::execute()
363 UpdateConfiguration(); // taking actual control settings for the configuration
366 void OptimizerDialog::UpdateControlStates( sal_Int16 nPage
)
370 case 0 : UpdateControlStatesPage0(); break;
371 case 1 : UpdateControlStatesPage1(); break;
372 case 2 : UpdateControlStatesPage2(); break;
373 case 3 : UpdateControlStatesPage3(); break;
374 case 4 : UpdateControlStatesPage4(); break;
377 UpdateControlStatesPage0();
378 UpdateControlStatesPage1();
379 UpdateControlStatesPage2();
380 UpdateControlStatesPage3();
381 UpdateControlStatesPage4();
386 void OptimizerDialog::UpdateStatus( const css::uno::Sequence
< css::beans::PropertyValue
>& rStatus
)
388 maStats
.InitializeStatusValues( rStatus
);
389 const Any
* pVal( maStats
.GetStatusValue( TK_Status
) );
393 if ( *pVal
>>= sStatus
)
395 mpPage4
->UpdateStatusLabel(getString(TKGet(sStatus
)));
398 pVal
= maStats
.GetStatusValue( TK_Progress
);
401 sal_Int32 nProgress
= 0;
402 if ( *pVal
>>= nProgress
)
403 mpPage4
->UpdateProgressValue(nProgress
);
405 pVal
= maStats
.GetStatusValue( TK_OpenNewDocument
);
407 SetConfigProperty( TK_OpenNewDocument
, *pVal
);
409 Application::Reschedule(true);
412 IMPL_LINK(SummaryPage
, SaveAsNewActionPerformed
, weld::Toggleable
&, rBox
, void)
414 if (!rBox
.get_active())
417 const bool bSaveToNew
= &rBox
== m_xSaveToNew
.get();
418 mrOptimizerDialog
.SetConfigProperty( TK_SaveAs
, Any(bSaveToNew
) );
421 IMPL_LINK(SummaryPage
, SaveSettingsActionPerformed
, weld::Toggleable
&, rBox
, void)
423 m_xComboBox
->set_sensitive(rBox
.get_active());
426 IMPL_LINK(ObjectsPage
, OLEActionPerformed
, weld::Toggleable
&, rBox
, void)
428 if (!rBox
.get_active())
431 const bool bALLOles
= &rBox
== m_xAllOLEObjects
.get();
432 sal_Int16 nInt16
= bALLOles
? 0 : 1;
433 mrOptimizerDialog
.SetConfigProperty( TK_OLEOptimizationType
, Any( nInt16
) );
436 IMPL_LINK(ObjectsPage
, OLEOptimizationActionPerformed
, weld::Toggleable
&, rBox
, void)
438 const bool bOLEOptimization
= rBox
.get_active();
439 mrOptimizerDialog
.SetConfigProperty( TK_OLEOptimization
, Any(bOLEOptimization
) );
440 m_xAllOLEObjects
->set_sensitive(bOLEOptimization
);
441 m_xForeignOLEObjects
->set_sensitive(bOLEOptimization
);
444 IMPL_LINK(ImagesPage
, CompressionActionPerformed
, weld::Toggleable
&, rBox
, void)
446 if (!rBox
.get_active())
449 const bool bJPEGCompression
= &rBox
== m_xJpegCompression
.get();
450 mrOptimizerDialog
.SetConfigProperty(TK_JPEGCompression
, Any(bJPEGCompression
));
451 m_xQualityLabel
->set_sensitive(bJPEGCompression
);
452 m_xQuality
->set_sensitive(bJPEGCompression
);
455 IMPL_LINK(ImagesPage
, RemoveCropAreaActionPerformed
, weld::Toggleable
&, rBox
, void)
457 mrOptimizerDialog
.SetConfigProperty(TK_RemoveCropArea
, Any(rBox
.get_active()));
460 IMPL_LINK(ImagesPage
, EmbedLinkedGraphicsActionPerformed
, weld::Toggleable
&, rBox
, void)
462 mrOptimizerDialog
.SetConfigProperty(TK_EmbedLinkedGraphics
, Any(rBox
.get_active()));
465 IMPL_LINK(SlidesPage
, UnusedHiddenSlidesActionPerformed
, weld::Toggleable
&, rBox
, void)
467 mrOptimizerDialog
.SetConfigProperty(TK_DeleteHiddenSlides
, Any(rBox
.get_active()));
470 IMPL_LINK(SlidesPage
, UnusedMasterPagesActionPerformed
, weld::Toggleable
&, rBox
, void)
472 mrOptimizerDialog
.SetConfigProperty(TK_DeleteUnusedMasterPages
, Any(rBox
.get_active()));
475 IMPL_LINK(SlidesPage
, DeleteNotesActionPerformed
, weld::Toggleable
&, rBox
, void)
477 mrOptimizerDialog
.SetConfigProperty(TK_DeleteNotesPages
, Any(rBox
.get_active()));
480 IMPL_LINK(SlidesPage
, UnusedSlidesActionPerformed
, weld::Toggleable
&, rBox
, void)
482 mxComboBox
->set_sensitive(rBox
.get_active());
485 bool OptimizerDialog::onFinish()
487 UpdateConfiguration();
489 ShowPage(ITEM_ID_SUMMARY
);
490 m_xPrevPage
->set_sensitive(false);
491 m_xNextPage
->set_sensitive(false);
492 m_xFinish
->set_sensitive(false);
493 m_xCancel
->set_sensitive(false);
495 // check if we have to open the FileDialog
496 bool bSuccessfullyExecuted
= true;
497 if (mpPage4
->GetSaveAsNew())
499 // Duplicate presentation before applying changes
501 FileOpenDialog
aFileOpenDialog(mxContext
);
503 // generating default file name
505 Reference
< XStorable
> xStorable( mxController
->getModel(), UNO_QUERY
);
506 if ( xStorable
.is() && xStorable
->hasLocation() )
508 INetURLObject
aURLObj( xStorable
->getLocation() );
509 if ( !aURLObj
.hasFinalSlash() )
511 // tdf#105382 uri-decode file name
512 aURLObj
.removeExtension(INetURLObject::LAST_SEGMENT
, false);
513 aName
= aURLObj
.getName(INetURLObject::LAST_SEGMENT
, false,
514 INetURLObject::DecodeMechanism::WithCharset
);
519 // If no filename, try to use model title ("Untitled 1" or something like this)
520 Reference
<XTitle
> xTitle(
521 GetFrame()->getController()->getModel(), UNO_QUERY
);
522 aName
= xTitle
->getTitle();
525 if (!aName
.isEmpty())
527 aName
+= " " + getString(STR_FILENAME_SUFFIX
);
528 aFileOpenDialog
.setDefaultName(aName
);
531 if (aFileOpenDialog
.execute() == dialogs::ExecutableDialogResults::OK
)
533 aSaveAsURL
= aFileOpenDialog
.getURL();
534 SetConfigProperty( TK_SaveAsURL
, Any( aSaveAsURL
) );
535 SetConfigProperty( TK_FilterName
, Any( aFileOpenDialog
.getFilterName() ) );
537 if ( aSaveAsURL
.isEmpty() )
539 // something goes wrong...
540 bSuccessfullyExecuted
= false;
544 Application::Reschedule(true);
545 for ( sal_uInt32 i
= osl_getGlobalTimer(); ( i
+ 500 ) > ( osl_getGlobalTimer() ); )
546 Application::Reschedule(true);
550 // Apply changes to current presentation
551 Reference
<XModifiable
> xModifiable(mxController
->getModel(),
553 if ( xModifiable
->isModified() )
555 SolarMutexGuard aSolarGuard
;
556 std::unique_ptr
<weld::MessageDialog
> popupDlg(Application::CreateMessageDialog(
557 m_xAssistant
.get(), VclMessageType::Question
, VclButtonsType::YesNo
,
558 getString(STR_WARN_UNSAVED_PRESENTATION
)));
559 if (popupDlg
->run() != RET_YES
)
561 // Selected not "yes" ("no" or dialog was cancelled) so return to previous step
562 m_xPrevPage
->set_sensitive(true);
563 m_xNextPage
->set_sensitive(true);
564 m_xFinish
->set_sensitive(true);
565 m_xCancel
->set_sensitive(true);
570 if ( bSuccessfullyExecuted
)
572 // now check if we have to store a session template
573 const bool bSaveSettings
= mpPage4
->GetSaveSettings();
574 OUString aSettingsName
= mpPage4
->GetSettingsName();
575 if (bSaveSettings
&& !aSettingsName
.isEmpty())
577 std::vector
< OptimizerSettings
>::iterator
aIter( GetOptimizerSettingsByName( aSettingsName
) );
578 std::vector
< OptimizerSettings
>& rSettings( GetOptimizerSettings() );
579 OptimizerSettings
aNewSettings( rSettings
[ 0 ] );
580 aNewSettings
.maName
= aSettingsName
;
581 if ( aIter
== rSettings
.end() )
582 rSettings
.push_back( aNewSettings
);
584 *aIter
= std::move(aNewSettings
);
587 if ( bSuccessfullyExecuted
)
590 aURL
.Protocol
= "vnd.com.sun.star.comp.PPPOptimizer:";
591 aURL
.Path
= "optimize";
593 Sequence
< PropertyValue
> lArguments
{
594 comphelper::makePropertyValue(u
"Settings"_ustr
, GetConfigurationSequence()),
595 comphelper::makePropertyValue(u
"StatusDispatcher"_ustr
, GetStatusDispatcher()),
596 comphelper::makePropertyValue(u
"DocumentFrame"_ustr
, GetFrame()),
597 comphelper::makePropertyValue(u
"DialogParentWindow"_ustr
, m_xAssistant
->GetXWindow())
603 ImpOptimizer
aOptimizer(mxContext
, GetFrame()->getController()->getModel());
604 aOptimizer
.Optimize(lArguments
);
606 catch (css::io::IOException
&)
608 // We always receive just ERRCODE_IO_CANTWRITE in case of problems, so no need to bother
609 // about extracting error code from exception text
610 errorCode
= ERRCODE_IO_CANTWRITE
;
612 catch (css::uno::Exception
&)
614 // Other general exception
615 errorCode
= ERRCODE_IO_GENERAL
;
618 if (errorCode
!= ERRCODE_NONE
)
620 // Restore wizard controls
621 maStats
.SetStatusValue(TK_Progress
, Any(static_cast<sal_Int32
>(0)));
622 m_xPrevPage
->set_sensitive(true);
623 m_xNextPage
->set_sensitive(false);
624 m_xFinish
->set_sensitive(true);
625 m_xCancel
->set_sensitive(true);
628 GetConfigProperty(TK_SaveAsURL
) >>= aFileName
;
629 SfxErrorContext
aEc(ERRCTX_SFX_SAVEASDOC
, aFileName
);
630 ErrorHandler::HandleError(errorCode
);
636 m_xPrevPage
->set_sensitive(true);
637 m_xNextPage
->set_sensitive(false);
638 m_xFinish
->set_sensitive(true);
639 m_xCancel
->set_sensitive(true);
642 return vcl::RoadmapWizardMachine::onFinish();
645 IMPL_LINK_NOARG(IntroPage
, ButtonActionPerformed
, weld::Button
&, void)
647 // delete configuration
648 OUString
aSelectedItem(mxComboBox
->get_active_text());
649 if ( !aSelectedItem
.isEmpty() )
651 std::vector
< OptimizerSettings
>::iterator
aIter( mrOptimizerDialog
.GetOptimizerSettingsByName( aSelectedItem
) );
652 std::vector
< OptimizerSettings
>& rList( mrOptimizerDialog
.GetOptimizerSettings() );
653 if ( aIter
!= rList
.end() )
655 rList
.erase( aIter
);
656 mrOptimizerDialog
.UpdateControlStates();
661 IMPL_LINK(IntroPage
, ComboBoxActionPerformed
, weld::ComboBox
&, rBox
, void)
663 OUString
sActionCommand(rBox
.get_active_text());
664 if (!sActionCommand
.isEmpty())
666 std::vector
< OptimizerSettings
>::iterator
aIter( mrOptimizerDialog
.GetOptimizerSettingsByName(sActionCommand
) );
667 std::vector
< OptimizerSettings
>& rList( mrOptimizerDialog
.GetOptimizerSettings() );
668 if ( aIter
!= rList
.end() )
671 mrOptimizerDialog
.UpdateControlStates();
674 IMPL_LINK(ImagesPage
, SpinButtonActionPerformed
, weld::SpinButton
&, rBox
, void)
676 mrOptimizerDialog
.SetConfigProperty( TK_JPEGQuality
, Any( static_cast<sal_Int32
>(rBox
.get_value()) ) );
679 IMPL_LINK_NOARG(ImagesPage
, ComboBoxActionPerformed
, weld::ComboBox
&, void)
681 mrOptimizerDialog
.SetConfigProperty( TK_ImageResolution
, Any( m_xResolution
->get_active_id().toInt32() ) );
684 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */