Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sdext / source / minimizer / informationdialog.cxx
blobad6dc2b7454891cbfdcc4e51a977629b6556289e
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::ui;
33 using namespace ::com::sun::star::awt;
34 using namespace ::com::sun::star::uno;
35 using namespace ::com::sun::star::util;
36 using namespace ::com::sun::star::lang;
37 using namespace ::com::sun::star::beans;
38 using namespace ::com::sun::star::container;
40 static OUString ImpValueOfInMB( sal_Int64 rVal )
42 double fVal( static_cast<double>( rVal ) );
43 fVal /= ( 1 << 20 );
44 fVal += 0.05;
45 OUStringBuffer aVal( OUString::number( fVal ) );
46 sal_Int32 nX( aVal.indexOf( '.' ) );
47 if ( nX > 0 )
48 aVal.setLength( nX + 2 );
49 return aVal.makeStringAndClear();
52 void InformationDialog::InitDialog()
54 set_title(getString(STR_SUN_OPTIMIZATION_WIZARD2));
56 sal_Int64 nSource = mnSourceSize;
57 sal_Int64 nDest = mnDestSize;
59 PPPOptimizerTokenEnum eInfoString( STR_INFO_SECONDARY_1 );
60 if ( mnSourceSize )
62 if ( mnDestSize )
63 eInfoString = STR_INFO_SECONDARY_1;
64 else
66 eInfoString = STR_INFO_SECONDARY_2;
67 nDest = mnApproxSize;
70 else if ( mnDestSize )
71 eInfoString = STR_INFO_SECONDARY_3;
72 else
74 eInfoString = STR_INFO_SECONDARY_4;
75 nDest = mnApproxSize;
78 OUString aTitle;
79 if ( !maSaveAsURL.isEmpty() )
81 Reference< XURLTransformer > xURLTransformer( URLTransformer::create(mxContext) );
82 util::URL aURL, aPresentationURL;
83 aURL.Complete = maSaveAsURL;
84 xURLTransformer->parseSmart( aURL, OUString() );
86 static const OUStringLiteral sFileProtocol( u"file:///" );
87 aPresentationURL.Complete = sFileProtocol + aURL.Name;
88 aTitle = xURLTransformer->getPresentation( aPresentationURL, false );
90 if ( aTitle.match( sFileProtocol ) )
91 aTitle = aTitle.replaceAt( 0, sFileProtocol.getLength(), u"" );
94 OUString sPrimary( getString( STR_INFO_PRIMARY ) );
95 OUString sSecondary( getString( eInfoString ) );
96 static const OUStringLiteral aOldSizePlaceholder( u"%OLDFILESIZE" );
97 static const OUStringLiteral aNewSizePlaceholder( u"%NEWFILESIZE" );
98 const OUString aTitlePlaceholder( !aTitle.isEmpty() ? OUString("%TITLE" )
99 : OUString("'%TITLE'") );
101 sal_Int32 i = sSecondary.indexOf( aOldSizePlaceholder );
102 if ( i >= 0 )
103 sSecondary = sSecondary.replaceAt( i, aOldSizePlaceholder.getLength(), ImpValueOfInMB( nSource ) );
105 sal_Int32 j = sSecondary.indexOf( aNewSizePlaceholder );
106 if ( j >= 0 )
107 sSecondary = sSecondary.replaceAt( j, aNewSizePlaceholder.getLength(), ImpValueOfInMB( nDest ) );
109 sal_Int32 k = sPrimary.indexOf( aTitlePlaceholder );
110 if ( k >= 0 )
111 sPrimary = sPrimary.replaceAt( k, aTitlePlaceholder.getLength(), aTitle );
113 set_primary_text(sPrimary);
114 set_secondary_text(sSecondary);
115 mxCheckBox->set_visible(!maSaveAsURL.isEmpty());
116 mxCheckBox->set_active(mrbOpenNewDocument);
119 InformationDialog::InformationDialog(const Reference< XComponentContext > &rxContext, const Reference<XWindow>& rxDialogParent,
120 const OUString& rSaveAsURL, bool& rbOpenNewDocument,
121 sal_Int64 rSourceSize, sal_Int64 rDestSize, sal_Int64 rApproxSize)
122 : MessageDialogController(Application::GetFrameWeld(rxDialogParent), "modules/simpress/ui/pminfodialog.ui", "PMInfoDialog", "ask")
123 , ConfigurationAccess(rxContext)
124 , mxCheckBox(m_xBuilder->weld_check_button("ask"))
125 , mnSourceSize(rSourceSize)
126 , mnDestSize(rDestSize)
127 , mnApproxSize(rApproxSize)
128 , mrbOpenNewDocument(rbOpenNewDocument)
129 , maSaveAsURL(rSaveAsURL)
131 InitDialog();
134 InformationDialog::~InformationDialog()
138 void InformationDialog::execute()
140 run();
141 if (!maSaveAsURL.isEmpty())
142 mrbOpenNewDocument = mxCheckBox->get_active();
145 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */