LibreOffice Module sdext (master) 1
informationdialog.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 "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>
30
31using namespace ::com::sun::star;
32using namespace ::com::sun::star::ui;
33using namespace ::com::sun::star::awt;
34using namespace ::com::sun::star::uno;
35using namespace ::com::sun::star::util;
36using namespace ::com::sun::star::lang;
37using namespace ::com::sun::star::beans;
38using namespace ::com::sun::star::container;
39
40static OUString ImpValueOfInMB( sal_Int64 rVal )
41{
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();
50}
51
53{
55
56 sal_Int64 nSource = mnSourceSize;
57 sal_Int64 nDest = mnDestSize;
58
60 if ( mnSourceSize )
61 {
62 if ( mnDestSize )
63 eInfoString = STR_INFO_SECONDARY_1;
64 else
65 {
66 eInfoString = STR_INFO_SECONDARY_2;
67 nDest = mnApproxSize;
68 }
69 }
70 else if ( mnDestSize )
71 eInfoString = STR_INFO_SECONDARY_3;
72 else
73 {
74 eInfoString = STR_INFO_SECONDARY_4;
75 nDest = mnApproxSize;
76 }
77
78 OUString aTitle;
79 if ( !maSaveAsURL.isEmpty() )
80 {
81 Reference< XURLTransformer > xURLTransformer( URLTransformer::create(mxContext) );
82 util::URL aURL, aPresentationURL;
83 aURL.Complete = maSaveAsURL;
84 xURLTransformer->parseSmart( aURL, OUString() );
85
86 static const OUStringLiteral sFileProtocol( u"file:///" );
87 aPresentationURL.Complete = sFileProtocol + aURL.Name;
88 aTitle = xURLTransformer->getPresentation( aPresentationURL, false );
89
90 if ( aTitle.match( sFileProtocol ) )
91 aTitle = aTitle.replaceAt( 0, sFileProtocol.getLength(), u"" );
92 }
93
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'") );
100
101 sal_Int32 i = sSecondary.indexOf( aOldSizePlaceholder );
102 if ( i >= 0 )
103 sSecondary = sSecondary.replaceAt( i, aOldSizePlaceholder.getLength(), ImpValueOfInMB( nSource ) );
104
105 sal_Int32 j = sSecondary.indexOf( aNewSizePlaceholder );
106 if ( j >= 0 )
107 sSecondary = sSecondary.replaceAt( j, aNewSizePlaceholder.getLength(), ImpValueOfInMB( nDest ) );
108
109 sal_Int32 k = sPrimary.indexOf( aTitlePlaceholder );
110 if ( k >= 0 )
111 sPrimary = sPrimary.replaceAt( k, aTitlePlaceholder.getLength(), aTitle );
112
113 set_primary_text(sPrimary);
114 set_secondary_text(sSecondary);
115 mxCheckBox->set_visible(!maSaveAsURL.isEmpty());
116 mxCheckBox->set_active(mrbOpenNewDocument);
117}
118
119InformationDialog::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)
130{
131 InitDialog();
132}
133
135{
136}
137
139{
140 run();
141 if (!maSaveAsURL.isEmpty())
142 mrbOpenNewDocument = mxCheckBox->get_active();
143}
144
145/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
OUString getString(const PPPOptimizerTokenEnum) const
css::uno::Reference< css::uno::XComponentContext > mxContext
InformationDialog(const css::uno::Reference< css::uno::XComponentContext > &rxContext, const css::uno::Reference< css::awt::XWindow > &rxDialogParent, const OUString &rSaveAsURL, bool &bOpenNewDocument, sal_Int64 nSourceSize, sal_Int64 nDestSize, sal_Int64 nApproxDest)
const OUString & maSaveAsURL
std::unique_ptr< weld::CheckButton > mxCheckBox
virtual short run()
void set_title(const OUString &rTitle)
void set_primary_text(const OUString &rText)
void set_secondary_text(const OUString &rText)
weld::Window * GetFrameWeld(const SfxFrame *pFrame)
URL aURL
float u
static OUString ImpValueOfInMB(sal_Int64 rVal)
int i
PPPOptimizerTokenEnum
@ STR_SUN_OPTIMIZATION_WIZARD2
@ STR_INFO_SECONDARY_1
@ STR_INFO_PRIMARY
@ STR_INFO_SECONDARY_3
@ STR_INFO_SECONDARY_2
@ STR_INFO_SECONDARY_4