cid#1607171 Data race condition
[LibreOffice.git] / sdext / source / minimizer / informationdialog.cxx
blob252863231bff6f0a756d182233b2d766a9405d00
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 "informationdialog.hxx"
22 #include <com/sun/star/awt/PushButtonType.hpp>
23 #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
24 #include <com/sun/star/util/URL.hpp>
25 #include <com/sun/star/util/URLTransformer.hpp>
26 #include <com/sun/star/util/XURLTransformer.hpp>
27 #include <rtl/ustrbuf.hxx>
28 #include <sal/macros.h>
29 #include <vcl/svapp.hxx>
31 using namespace ::com::sun::star;
32 using namespace ::com::sun::star::awt;
33 using namespace ::com::sun::star::uno;
34 using namespace ::com::sun::star::util;
35 using namespace ::com::sun::star::lang;
37 static OUString ImpValueOfInMB( sal_Int64 rVal )
39 double fVal( static_cast<double>( rVal ) );
40 fVal /= ( 1 << 20 );
41 fVal += 0.05;
42 OUStringBuffer aVal( OUString::number( fVal ) );
43 sal_Int32 nX( aVal.indexOf( '.' ) );
44 if ( nX > 0 )
45 aVal.setLength( nX + 2 );
46 return aVal.makeStringAndClear();
49 void InformationDialog::InitDialog()
51 set_title(getString(STR_SUN_OPTIMIZATION_WIZARD2));
53 sal_Int64 nSource = mnSourceSize;
54 sal_Int64 nDest = mnDestSize;
56 PPPOptimizerTokenEnum eInfoString( STR_INFO_SECONDARY_1 );
57 if ( mnSourceSize )
59 if ( mnDestSize )
60 eInfoString = STR_INFO_SECONDARY_1;
61 else
63 eInfoString = STR_INFO_SECONDARY_2;
64 nDest = mnApproxSize;
67 else if ( mnDestSize )
68 eInfoString = STR_INFO_SECONDARY_3;
69 else
71 eInfoString = STR_INFO_SECONDARY_4;
72 nDest = mnApproxSize;
75 OUString aTitle;
76 if ( !maSaveAsURL.isEmpty() )
78 Reference< XURLTransformer > xURLTransformer( URLTransformer::create(mxContext) );
79 util::URL aURL, aPresentationURL;
80 aURL.Complete = maSaveAsURL;
81 xURLTransformer->parseSmart( aURL, OUString() );
83 static constexpr OUString sFileProtocol( u"file:///"_ustr );
84 aPresentationURL.Complete = sFileProtocol + aURL.Name;
85 aTitle = xURLTransformer->getPresentation( aPresentationURL, false );
87 if ( aTitle.match( sFileProtocol ) )
88 aTitle = aTitle.replaceAt( 0, sFileProtocol.getLength(), u"" );
91 OUString sPrimary( getString( STR_INFO_PRIMARY ) );
92 OUString sSecondary( getString( eInfoString ) );
93 static constexpr OUString aOldSizePlaceholder( u"%OLDFILESIZE"_ustr );
94 static constexpr OUString aNewSizePlaceholder( u"%NEWFILESIZE"_ustr );
95 const OUString aTitlePlaceholder( !aTitle.isEmpty() ? u"%TITLE"_ustr
96 : u"'%TITLE'"_ustr );
98 sal_Int32 i = sSecondary.indexOf( aOldSizePlaceholder );
99 if ( i >= 0 )
100 sSecondary = sSecondary.replaceAt( i, aOldSizePlaceholder.getLength(), ImpValueOfInMB( nSource ) );
102 sal_Int32 j = sSecondary.indexOf( aNewSizePlaceholder );
103 if ( j >= 0 )
104 sSecondary = sSecondary.replaceAt( j, aNewSizePlaceholder.getLength(), ImpValueOfInMB( nDest ) );
106 sal_Int32 k = sPrimary.indexOf( aTitlePlaceholder );
107 if ( k >= 0 )
108 sPrimary = sPrimary.replaceAt( k, aTitlePlaceholder.getLength(), aTitle );
110 set_primary_text(sPrimary);
111 set_secondary_text(sSecondary);
112 mxCheckBox->set_visible(!maSaveAsURL.isEmpty());
113 mxCheckBox->set_active(mrbOpenNewDocument);
116 InformationDialog::InformationDialog(const Reference< XComponentContext > &rxContext, const Reference<XWindow>& rxDialogParent,
117 const OUString& rSaveAsURL, bool& rbOpenNewDocument,
118 sal_Int64 rSourceSize, sal_Int64 rDestSize, sal_Int64 rApproxSize)
119 : MessageDialogController(Application::GetFrameWeld(rxDialogParent), u"modules/simpress/ui/pminfodialog.ui"_ustr, u"PMInfoDialog"_ustr, u"ask"_ustr)
120 , ConfigurationAccess(rxContext)
121 , mxCheckBox(m_xBuilder->weld_check_button(u"ask"_ustr))
122 , mnSourceSize(rSourceSize)
123 , mnDestSize(rDestSize)
124 , mnApproxSize(rApproxSize)
125 , mrbOpenNewDocument(rbOpenNewDocument)
126 , maSaveAsURL(rSaveAsURL)
128 InitDialog();
131 InformationDialog::~InformationDialog()
135 void InformationDialog::execute()
137 run();
138 if (!maSaveAsURL.isEmpty())
139 mrbOpenNewDocument = mxCheckBox->get_active();
142 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */