bump product version to 5.0.4.1
[LibreOffice.git] / cui / source / dialogs / about.cxx
blob4121887933ff86dd62792790653cbcd49a97f2ed
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 .
20 #include <vcl/layout.hxx>
21 #include <vcl/svapp.hxx>
22 #include <vcl/settings.hxx>
24 #include <tools/stream.hxx>
25 #include <rtl/bootstrap.hxx>
26 #include <unotools/configmgr.hxx>
27 #include <unotools/bootstrap.hxx>
28 #include <com/sun/star/uno/Any.h>
29 #include <vcl/graph.hxx>
30 #include <vcl/graphicfilter.hxx>
31 #include <svtools/langhelp.hxx>
33 #include "com/sun/star/system/SystemShellExecuteFlags.hpp"
34 #include "com/sun/star/system/SystemShellExecute.hpp"
35 #include <comphelper/processfactory.hxx>
36 #include "comphelper/anytostring.hxx"
37 #include "cppuhelper/exc_hlp.hxx"
38 #include "cppuhelper/bootstrap.hxx"
39 #include <basegfx/numeric/ftools.hxx>
40 #include <com/sun/star/geometry/RealRectangle2D.hpp>
41 #include <svtools/optionsdrawinglayer.hxx>
43 #include <sfx2/sfxuno.hxx>
44 #include <sfx2/sfxcommands.h>
45 #include "about.hxx"
46 #include <config_buildid.h>
47 #include <sfx2/app.hxx>
48 #include <rtl/ustrbuf.hxx>
49 #include <vcl/bitmap.hxx>
50 #include <officecfg/Office/Common.hxx>
51 #include <vcl/opengl/OpenGLWrapper.hxx>
53 using namespace ::com::sun::star::uno;
54 using namespace ::com::sun::star::beans;
55 using namespace ::com::sun::star;
57 enum AboutDialogButton
59 CREDITS_BUTTON,
60 WEBSITE_BUTTON
63 AboutDialog::AboutDialog(vcl::Window* pParent)
64 : SfxModalDialog(pParent, "AboutDialog", "cui/ui/aboutdialog.ui")
66 get(m_pLogoReplacement, "logoreplacement");
67 get(m_pLogoImage, "logo");
68 get(m_pVersion, "version");
69 get(m_pDescriptionText, "description");
70 get(m_pCopyrightText, "copyright");
71 m_aCopyrightTextStr = m_pCopyrightText->GetText();
72 get(m_pWebsiteButton, "website");
73 get(m_pCreditsButton, "credits");
74 m_aCreditsLinkStr = get<FixedText>("link")->GetText();
75 m_sBuildStr = get<FixedText>("buildid")->GetText();
76 m_aVendorTextStr = get<FixedText>("vendor")->GetText();
77 m_aVersionTextStr = m_pVersion->GetText();
78 m_aBasedTextStr = get<FixedText>("libreoffice")->GetText();
79 m_aBasedDerivedTextStr = get<FixedText>("derived")->GetText();
80 m_aLocaleStr = get<FixedText>("locale")->GetText();;
82 m_pVersion->SetText(GetVersionString());
84 OUString aCopyrightString = GetCopyrightString();
85 m_pCopyrightText->SetText( aCopyrightString );
87 StyleControls();
89 SetLogo();
91 // Allow the button to be identifiable once they are clicked
92 m_pCreditsButton->SetData( reinterpret_cast<void*>(CREDITS_BUTTON) );
93 m_pWebsiteButton->SetData( reinterpret_cast<void*>(WEBSITE_BUTTON) );
95 // Connect all handlers
96 m_pCreditsButton->SetClickHdl( LINK( this, AboutDialog, HandleClick ) );
97 m_pWebsiteButton->SetClickHdl( LINK( this, AboutDialog, HandleClick ) );
99 get<PushButton>("close")->GrabFocus();
102 AboutDialog::~AboutDialog()
104 disposeOnce();
107 void AboutDialog::dispose()
109 m_pVersion.clear();
110 m_pDescriptionText.clear();
111 m_pCopyrightText.clear();
112 m_pLogoImage.clear();
113 m_pLogoReplacement.clear();
114 m_pCreditsButton.clear();
115 m_pWebsiteButton.clear();
116 SfxModalDialog::dispose();
119 IMPL_LINK( AboutDialog, HandleClick, PushButton*, pButton )
121 OUString sURL = "";
123 // Find which button was pressed and from this, get the URL to be opened
124 AboutDialogButton aDialogButton = static_cast<AboutDialogButton>(reinterpret_cast<sal_Int64>(pButton->GetData()));
125 if ( aDialogButton == CREDITS_BUTTON )
126 sURL = m_aCreditsLinkStr;
127 else if ( aDialogButton == WEBSITE_BUTTON )
129 sURL = officecfg::Office::Common::Help::StartCenter::InfoURL::get();
130 localizeWebserviceURI(sURL);
133 // If the URL is empty, don't do anything
134 if ( sURL.isEmpty() )
135 return 1;
138 Reference< com::sun::star::system::XSystemShellExecute > xSystemShellExecute(
139 com::sun::star::system::SystemShellExecute::create(::comphelper::getProcessComponentContext() ) );
140 xSystemShellExecute->execute( sURL, OUString(), com::sun::star::system::SystemShellExecuteFlags::URIS_ONLY );
142 catch (const Exception&)
144 Any exc( ::cppu::getCaughtException() );
145 OUString msg( ::comphelper::anyToString( exc ) );
146 const SolarMutexGuard guard;
147 ScopedVclPtrInstance< MessageDialog > aErrorBox(nullptr, msg);
148 aErrorBox->SetText( GetText() );
149 aErrorBox->Execute();
152 return 1;
155 void AboutDialog::StyleControls()
157 // Make all the controls have a transparent background
158 m_pLogoImage->SetBackground();
159 m_pLogoReplacement->SetPaintTransparent(true);
160 m_pVersion->SetPaintTransparent(true);
161 m_pDescriptionText->SetPaintTransparent(true);
162 m_pCopyrightText->SetPaintTransparent(true);
164 const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
166 vcl::Font aLabelFont = rStyleSettings.GetLabelFont();
167 vcl::Font aLargeFont = aLabelFont;
168 aLargeFont.SetSize(Size( 0, aLabelFont.GetSize().Height() * 3));
170 // Logo Replacement Text
171 m_pLogoReplacement->SetControlFont(aLargeFont);
173 // Description Text
174 aLargeFont.SetSize(Size(0, aLabelFont.GetSize().Height() * 1.3));
175 m_pDescriptionText->SetControlFont(aLargeFont);
177 // Version Text
178 aLargeFont.SetSize(Size(0, aLabelFont.GetSize().Height() * 1.2));
179 m_pVersion->SetControlFont(aLargeFont);
181 // If not in high-contrast mode, hard-code colors
182 if (!rStyleSettings.GetHighContrastMode())
184 m_pLogoReplacement->SetControlForeground(Color(51, 51, 51));
185 m_pVersion->SetControlForeground(Color(102, 102, 102));
186 m_pDescriptionText->SetControlForeground(Color(51, 51, 51));
187 m_pCopyrightText->SetControlForeground(Color(102, 102, 102));
191 void AboutDialog::SetLogo()
193 long nWidth = get_content_area()->get_preferred_size().Width();
195 // fdo#67401 set AntiAliasing for SVG logo
196 SvtOptionsDrawinglayer aDrawOpt;
197 bool bOldAntiAliasSetting = aDrawOpt.IsAntiAliasing();
198 aDrawOpt.SetAntiAliasing(true);
200 // load svg logo, specify desired width, scale height isotrophically
201 if (SfxApplication::loadBrandSvg("flat_logo", aLogoBitmap, nWidth) &&
202 !aLogoBitmap.IsEmpty())
204 m_pLogoImage->SetImage(Image(aLogoBitmap));
205 m_pLogoReplacement->Hide();
206 m_pLogoImage->Show();
208 else
210 m_pLogoImage->Hide();
211 m_pLogoReplacement->Show();
213 aDrawOpt.SetAntiAliasing(bOldAntiAliasSetting);
216 void AboutDialog::Resize()
218 SfxModalDialog::Resize();
220 // Load background image
221 if (isInitialLayout(this) && !(Application::GetSettings().GetStyleSettings().GetHighContrastMode()))
223 SfxApplication::loadBrandSvg("shell/about", aBackgroundBitmap, GetSizePixel().Width());
227 void AboutDialog::Paint(vcl::RenderContext& rRenderContext, const Rectangle& rRect)
229 rRenderContext.SetClipRegion(vcl::Region(rRect));
231 Size aSize(GetOutputSizePixel());
232 Point aPos(aSize.Width() - aBackgroundBitmap.GetSizePixel().Width(),
233 aSize.Height() - aBackgroundBitmap.GetSizePixel().Height());
235 rRenderContext.DrawBitmapEx(aPos, aBackgroundBitmap);
238 OUString AboutDialog::GetBuildId()
240 OUString sDefault;
241 OUString sBuildId(utl::Bootstrap::getBuildVersion(sDefault));
242 if (!sBuildId.isEmpty())
243 return sBuildId;
245 sBuildId = utl::Bootstrap::getBuildIdData(sDefault);
247 if (!sBuildId.isEmpty())
249 sal_Int32 nIndex = 0;
250 return sBuildId.getToken( 0, '-', nIndex );
253 OSL_ENSURE( !sBuildId.isEmpty(), "No BUILDID in bootstrap file" );
254 return sBuildId;
257 OUString AboutDialog::GetLocaleString()
259 OUString aLocaleStr;
260 rtl_Locale * pLocale;
262 osl_getProcessLocale( &pLocale );
264 if ( pLocale && pLocale->Language )
266 if (pLocale->Country && rtl_uString_getLength( pLocale->Country) > 0)
267 aLocaleStr = OUString(pLocale->Language) + "_" + OUString(pLocale->Country);
268 else
269 aLocaleStr = OUString(pLocale->Language);
270 if (pLocale->Variant && rtl_uString_getLength( pLocale->Variant) > 0)
271 aLocaleStr += OUString(pLocale->Variant);
274 return aLocaleStr;
277 OUString AboutDialog::GetVersionString()
279 OUString sVersion = m_aVersionTextStr;
281 #ifdef _WIN64
282 sVersion += " (x64)";
283 #endif
285 OUString sBuildId = GetBuildId();
287 OUString aLocaleStr = Application::GetSettings().GetLanguageTag().getBcp47() + " (" + GetLocaleString() + ")";
289 if (!sBuildId.trim().isEmpty())
291 sVersion += "\n";
292 if (m_sBuildStr.indexOf("$BUILDID") == -1)
294 SAL_WARN( "cui.dialogs", "translated Build Id string in translations doesn't contain $BUILDID placeholder" );
295 m_sBuildStr += " $BUILDID";
297 sVersion += m_sBuildStr.replaceAll("$BUILDID", sBuildId);
300 if (OpenGLWrapper::isVCLOpenGLEnabled())
302 sVersion += "-GL";
305 if (EXTRA_BUILDID[0] != '\0')
307 sVersion += "\n" EXTRA_BUILDID;
310 if (!aLocaleStr.trim().isEmpty())
312 sVersion += "\n";
313 if (m_aLocaleStr.indexOf("$LOCALE") == -1)
315 SAL_WARN( "cui.dialogs", "translated locale string in translations doesn't contain $LOCALE placeholder" );
316 m_aLocaleStr += " $LOCALE";
318 sVersion += m_aLocaleStr.replaceAll("$LOCALE", aLocaleStr);
321 return sVersion;
324 OUString AboutDialog::GetCopyrightString()
326 OUString aCopyrightString = m_aVendorTextStr;
327 aCopyrightString += "\n";
329 aCopyrightString += m_aCopyrightTextStr;
330 aCopyrightString += "\n";
332 if (utl::ConfigManager::getProductName() == "LibreOffice")
333 aCopyrightString += m_aBasedTextStr;
334 else
335 aCopyrightString += m_aBasedDerivedTextStr;
337 return aCopyrightString;
340 bool AboutDialog::Close()
342 EndDialog( RET_OK );
343 return false;
346 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */