bump product version to 6.3.0.0.beta1
[LibreOffice.git] / cui / source / dialogs / about.cxx
blobcdafad532c2cf691bb0a303a17d4a98938fe7c14
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 <config_features.h>
21 #include <osl/process.h>
22 #include <sal/log.hxx>
23 #include <osl/diagnose.h>
24 #include <rtl/character.hxx>
25 #include <vcl/layout.hxx>
26 #include <vcl/weld.hxx>
27 #include <vcl/svapp.hxx>
28 #include <vcl/settings.hxx>
30 #include <tools/stream.hxx>
31 #include <rtl/bootstrap.hxx>
32 #include <unotools/configmgr.hxx>
33 #include <unotools/bootstrap.hxx>
34 #include <com/sun/star/uno/Any.h>
35 #include <vcl/graph.hxx>
36 #include <vcl/graphicfilter.hxx>
37 #include <svtools/langhelp.hxx>
38 #include <i18nlangtag/languagetag.hxx>
40 #include <com/sun/star/system/SystemShellExecuteFlags.hpp>
41 #include <com/sun/star/system/SystemShellExecute.hpp>
42 #include <comphelper/processfactory.hxx>
43 #include <comphelper/anytostring.hxx>
44 #include <cppuhelper/exc_hlp.hxx>
45 #include <cppuhelper/bootstrap.hxx>
46 #include <basegfx/numeric/ftools.hxx>
47 #include <com/sun/star/geometry/RealRectangle2D.hpp>
48 #include <svtools/optionsdrawinglayer.hxx>
50 #include <sfx2/sfxuno.hxx>
51 #include <about.hxx>
52 #include <config_buildid.h>
53 #include <sfx2/app.hxx>
54 #include <rtl/ustrbuf.hxx>
55 #include <vcl/bitmap.hxx>
57 #if HAVE_FEATURE_OPENCL
58 #include <opencl/openclwrapper.hxx>
59 #endif
60 #include <officecfg/Office/Common.hxx>
61 #include <officecfg/Office/Calc.hxx>
63 using namespace ::com::sun::star::uno;
64 using namespace ::com::sun::star::beans;
65 using namespace ::com::sun::star;
67 AboutDialog::AboutDialog(vcl::Window* pParent)
68 : SfxModalDialog(pParent, "AboutDialog", "cui/ui/aboutdialog.ui")
70 get(m_pLogoReplacement, "logoreplacement");
71 get(m_pLogoImage, "logo");
72 get(m_pVersion, "version");
73 get(m_pDescriptionText, "description");
74 get(m_pCopyrightText, "copyright");
75 get(m_pBuildIdLink, "buildIdLink");
76 m_aCopyrightTextStr = m_pCopyrightText->GetText();
77 get(m_pWebsiteButton, "website");
78 get(m_pCreditsButton, "credits");
79 get(m_pReleaseNotesButton, "btnReleaseNotes");
80 m_aCreditsLinkStr = get<FixedText>("link")->GetText();
81 m_sBuildStr = get<FixedText>("buildid")->GetText();
82 m_aVendorTextStr = get<FixedText>("vendor")->GetText();
83 m_aVersionTextStr = m_pVersion->GetText();
84 m_aBasedTextStr = get<FixedText>("libreoffice")->GetText();
85 m_aBasedDerivedTextStr = get<FixedText>("derived")->GetText();
86 m_aLocaleStr = get<FixedText>("locale")->GetText();
87 m_aUILocaleStr = get<FixedText>("uilocale")->GetText();
88 m_buildIdLinkString = m_pBuildIdLink->GetText();
90 m_pVersion->SetText(GetVersionString());
92 OUString aCopyrightString = GetCopyrightString();
93 m_pCopyrightText->SetText( aCopyrightString );
95 SetBuildIdLink();
97 StyleControls();
99 SetLogo();
101 // Connect all handlers
102 m_pCreditsButton->SetClickHdl( LINK( this, AboutDialog, HandleClick ) );
103 m_pWebsiteButton->SetClickHdl( LINK( this, AboutDialog, HandleClick ) );
104 m_pReleaseNotesButton->SetClickHdl( LINK( this, AboutDialog, HandleClick ) );
106 get<PushButton>("close")->GrabFocus();
109 AboutDialog::~AboutDialog()
111 disposeOnce();
114 void AboutDialog::dispose()
116 m_pVersion.clear();
117 m_pDescriptionText.clear();
118 m_pCopyrightText.clear();
119 m_pLogoImage.clear();
120 m_pLogoReplacement.clear();
121 m_pCreditsButton.clear();
122 m_pWebsiteButton.clear();
123 m_pBuildIdLink.clear();
124 m_pReleaseNotesButton.clear();
125 SfxModalDialog::dispose();
128 IMPL_LINK( AboutDialog, HandleClick, Button*, pButton, void )
130 OUString sURL = "";
132 // Find which button was pressed and from this, get the URL to be opened
133 if (pButton == m_pCreditsButton)
134 sURL = m_aCreditsLinkStr;
135 else if (pButton == m_pWebsiteButton)
137 sURL = officecfg::Office::Common::Help::StartCenter::InfoURL::get();
138 localizeWebserviceURI(sURL);
140 else if (pButton == m_pReleaseNotesButton)
142 sURL = officecfg::Office::Common::Menus::ReleaseNotesURL::get() +
143 "?LOvers=" + utl::ConfigManager::getProductVersion() +
144 "&LOlocale=" + LanguageTag(utl::ConfigManager::getUILocale()).getLanguage();
147 // If the URL is empty, don't do anything
148 if ( sURL.isEmpty() )
149 return;
152 Reference< css::system::XSystemShellExecute > xSystemShellExecute(
153 css::system::SystemShellExecute::create(::comphelper::getProcessComponentContext() ) );
154 xSystemShellExecute->execute( sURL, OUString(), css::system::SystemShellExecuteFlags::URIS_ONLY );
156 catch (const Exception&)
158 Any exc( ::cppu::getCaughtException() );
159 OUString msg( ::comphelper::anyToString( exc ) );
160 const SolarMutexGuard guard;
161 std::unique_ptr<weld::MessageDialog> xErrorBox(Application::CreateMessageDialog(pButton->GetFrameWeld(),
162 VclMessageType::Warning, VclButtonsType::Ok, msg));
163 xErrorBox->set_title(GetText());
164 xErrorBox->run();
168 void AboutDialog::SetBuildIdLink()
170 const OUString buildId = GetBuildId();
172 if (IsStringValidGitHash(buildId))
174 if (m_buildIdLinkString.indexOf("$GITHASH") == -1)
176 SAL_WARN( "cui.dialogs", "translated git hash string in translations doesn't contain $GITHASH placeholder" );
177 m_buildIdLinkString += " $GITHASH";
180 m_pBuildIdLink->SetText(m_buildIdLinkString.replaceAll("$GITHASH", buildId));
181 m_pBuildIdLink->SetURL("https://hub.libreoffice.org/git-core/" + buildId);
183 else
185 m_pBuildIdLink->Hide();
189 void AboutDialog::StyleControls()
191 // Make all the controls have a transparent background
192 m_pLogoImage->SetBackground();
193 m_pLogoReplacement->SetPaintTransparent(true);
194 m_pVersion->SetPaintTransparent(true);
195 m_pDescriptionText->SetPaintTransparent(true);
196 m_pCopyrightText->SetPaintTransparent(true);
198 const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
200 const vcl::Font& aLabelFont = rStyleSettings.GetLabelFont();
201 vcl::Font aLargeFont = aLabelFont;
202 aLargeFont.SetFontSize(Size( 0, aLabelFont.GetFontSize().Height() * 3));
204 // Logo Replacement Text
205 m_pLogoReplacement->SetControlFont(aLargeFont);
207 // Description Text
208 aLargeFont.SetFontSize(Size(0, aLabelFont.GetFontSize().Height() * 1.3));
209 m_pDescriptionText->SetControlFont(aLargeFont);
212 void AboutDialog::SetLogo()
214 long nWidth = get_content_area()->get_preferred_size().Width();
216 // fdo#67401 set AntiAliasing for SVG logo
217 SvtOptionsDrawinglayer aDrawOpt;
218 bool bOldAntiAliasSetting = aDrawOpt.IsAntiAliasing();
219 aDrawOpt.SetAntiAliasing(true);
221 // load svg logo, specify desired width, scale height isotropically
222 if (SfxApplication::loadBrandSvg("flat_logo", aLogoBitmap, nWidth) &&
223 !aLogoBitmap.IsEmpty())
225 m_pLogoImage->SetImage(Image(aLogoBitmap));
226 m_pLogoReplacement->Hide();
227 m_pLogoImage->Show();
229 else
231 m_pLogoImage->Hide();
232 m_pLogoReplacement->Show();
234 aDrawOpt.SetAntiAliasing(bOldAntiAliasSetting);
237 void AboutDialog::Resize()
239 SfxModalDialog::Resize();
241 // Load background image
242 if (isInitialLayout(this) && !(Application::GetSettings().GetStyleSettings().GetHighContrastMode()))
244 SfxApplication::loadBrandSvg("shell/about", aBackgroundBitmap, GetSizePixel().Width());
248 void AboutDialog::Paint(vcl::RenderContext& rRenderContext, const ::tools::Rectangle& rRect)
250 rRenderContext.SetClipRegion(vcl::Region(rRect));
252 Size aSize(GetOutputSizePixel());
253 Point aPos(aSize.Width() - aBackgroundBitmap.GetSizePixel().Width(),
254 aSize.Height() - aBackgroundBitmap.GetSizePixel().Height());
256 rRenderContext.DrawBitmapEx(aPos, aBackgroundBitmap);
259 OUString AboutDialog::GetBuildId()
261 OUString sDefault;
262 OUString sBuildId(utl::Bootstrap::getBuildVersion(sDefault));
263 if (!sBuildId.isEmpty())
264 return sBuildId;
266 sBuildId = utl::Bootstrap::getBuildIdData(sDefault);
268 if (!sBuildId.isEmpty())
270 return sBuildId.getToken( 0, '-' );
273 OSL_ENSURE( !sBuildId.isEmpty(), "No BUILDID in bootstrap file" );
274 return sBuildId;
277 OUString AboutDialog::GetLocaleString()
279 OUString aLocaleStr;
280 rtl_Locale * pLocale;
282 osl_getProcessLocale( &pLocale );
284 if ( pLocale && pLocale->Language )
286 if (pLocale->Country && rtl_uString_getLength( pLocale->Country) > 0)
287 aLocaleStr = OUString(pLocale->Language) + "_" + OUString(pLocale->Country);
288 else
289 aLocaleStr = OUString(pLocale->Language);
290 if (pLocale->Variant && rtl_uString_getLength( pLocale->Variant) > 0)
291 aLocaleStr += OUString(pLocale->Variant);
294 return aLocaleStr;
297 bool AboutDialog::IsStringValidGitHash(const OUString& hash)
299 for (int i = 0; i < hash.getLength(); i++)
301 if (!rtl::isAsciiHexDigit(hash[i]))
303 return false;
307 return true;
310 OUString AboutDialog::GetVersionString()
312 OUString sVersion = m_aVersionTextStr;
314 #ifdef _WIN64
315 sVersion += " (x64)";
316 #elif defined(_WIN32)
317 sVersion += " (x86)";
318 #endif
320 OUString sBuildId = GetBuildId();
322 OUString aLocaleStr = Application::GetSettings().GetLanguageTag().getBcp47() + " (" + GetLocaleString() + ")";
323 OUString aUILocaleStr = Application::GetSettings().GetUILanguageTag().getBcp47();
325 if (!sBuildId.trim().isEmpty())
327 sVersion += "\n";
328 if (m_sBuildStr.indexOf("$BUILDID") == -1)
330 SAL_WARN( "cui.dialogs", "translated Build Id string in translations doesn't contain $BUILDID placeholder" );
331 m_sBuildStr += " $BUILDID";
333 sVersion += m_sBuildStr.replaceAll("$BUILDID", sBuildId);
336 sVersion += "\n" + Application::GetHWOSConfInfo();
338 bool const extra = EXTRA_BUILDID[0] != '\0';
339 // extracted from the 'if' to avoid Clang -Wunreachable-code
340 if (extra)
342 sVersion += "\n" EXTRA_BUILDID;
345 if (m_aLocaleStr.indexOf("$LOCALE") == -1)
347 SAL_WARN( "cui.dialogs", "translated locale string in translations doesn't contain $LOCALE placeholder" );
348 m_aLocaleStr += " $LOCALE";
350 sVersion += "\n" + m_aLocaleStr.replaceAll("$LOCALE", aLocaleStr);
352 if (m_aUILocaleStr.indexOf("$LOCALE") == -1)
354 SAL_WARN( "cui.dialogs", "translated uilocale string in translations doesn't contain $LOCALE placeholder" );
355 m_aUILocaleStr += " $LOCALE";
357 sVersion += "; " + m_aUILocaleStr.replaceAll("$LOCALE", aUILocaleStr);
359 OUString aCalcMode = "Calc: "; // Calc calculation mode
361 #if HAVE_FEATURE_OPENCL
362 bool bOpenCL = openclwrapper::GPUEnv::isOpenCLEnabled();
363 if (bOpenCL)
364 aCalcMode += "CL";
365 #else
366 const bool bOpenCL = false;
367 #endif
369 static const bool bThreadingProhibited = std::getenv("SC_NO_THREADED_CALCULATION");
370 bool bThreadedCalc = officecfg::Office::Calc::Formula::Calculation::UseThreadedCalculationForFormulaGroups::get();
372 if (!bThreadingProhibited && !bOpenCL && bThreadedCalc)
374 if (!aCalcMode.endsWith(" "))
375 aCalcMode += " ";
376 aCalcMode += "threaded";
379 sVersion += "\n" + aCalcMode;
381 return sVersion;
384 OUString AboutDialog::GetCopyrightString()
386 OUString aCopyrightString = m_aVendorTextStr + "\n"
387 + m_aCopyrightTextStr + "\n";
389 if (utl::ConfigManager::getProductName() == "LibreOffice")
390 aCopyrightString += m_aBasedTextStr;
391 else
392 aCopyrightString += m_aBasedDerivedTextStr;
394 return aCopyrightString;
397 bool AboutDialog::Close()
399 EndDialog( RET_OK );
400 return false;
403 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */