LibreOffice Module cui (master) 1
about.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#include <sal/config.h>
21
22#include <cassert>
23
24#include <about.hxx>
25
26#include <osl/process.h> //osl_getProcessLocale
27#include <rtl/bootstrap.hxx>
28#include <sal/log.hxx> //SAL_WARN
29#include <vcl/graph.hxx> //Graphic
30#include <vcl/settings.hxx> //GetSettings
31#include <vcl/svapp.hxx> //Application::
32#include <vcl/weld.hxx>
33#include <unotools/resmgr.hxx> //Translate
34
35#include <config_buildid.h> //EXTRA_BUILDID
36#include <config_features.h>
37#include <dialmgr.hxx> //CuiResId
39#include <sfx2/app.hxx> //SfxApplication::loadBrandSvg
40#include <strings.hrc>
41#include <svtools/langhelp.hxx>
42#include <unotools/bootstrap.hxx> //utl::Bootstrap::getBuildIdData
43#include <unotools/configmgr.hxx> //ConfigManager::
44
45#include <com/sun/star/datatransfer/clipboard/SystemClipboard.hpp>
46#include <vcl/unohelp2.hxx>
47
48#include <config_feature_opencl.h>
49#if HAVE_FEATURE_OPENCL
51#endif
52#include <officecfg/Office/Calc.hxx>
53#include <officecfg/Office/Common.hxx>
54
55using namespace ::com::sun::star::uno;
56
58 : GenericDialogController(pParent, "cui/ui/aboutdialog.ui", "AboutDialog"),
59 m_pCreditsButton(m_xBuilder->weld_link_button("btnCredits")),
60 m_pWebsiteButton(m_xBuilder->weld_link_button("btnWebsite")),
61 m_pReleaseNotesButton(m_xBuilder->weld_link_button("btnReleaseNotes")),
62 m_pCloseButton(m_xBuilder->weld_button("btnClose")),
63 m_pCopyButton(m_xBuilder->weld_button("btnCopyVersion")),
64 m_pBrandImage(m_xBuilder->weld_image("imBrand")),
65 m_pAboutImage(m_xBuilder->weld_image("imAbout")),
66 m_pVersionLabel(m_xBuilder->weld_label("lbVersionString")),
67 m_pBuildCaption(m_xBuilder->weld_label("lbBuild")),
68 m_pBuildLabel(m_xBuilder->weld_link_button("lbBuildString")),
69 m_pEnvLabel(m_xBuilder->weld_label("lbEnvString")),
70 m_pUILabel(m_xBuilder->weld_label("lbUIString")),
71 m_pLocaleLabel(m_xBuilder->weld_label("lbLocaleString")),
72 m_pMiscLabel(m_xBuilder->weld_label("lbMiscString")),
73 m_pCopyrightLabel(m_xBuilder->weld_label("lbCopyright")) {
74
75 // Labels
77
78 OUString sbuildId = GetBuildString();
79 if (IsStringValidGitHash(sbuildId)) {
80 const tools::Long nMaxChar = 25;
81 m_pBuildLabel->set_uri("https://gerrit.libreoffice.org/gitweb?p=core.git;a=log;h="
82 + sbuildId);
83 m_pBuildLabel->set_label(sbuildId.getLength() > nMaxChar ? sbuildId.replaceAt(
84 nMaxChar, sbuildId.getLength() - nMaxChar, u"...")
85 : sbuildId);
86 } else {
87 m_pBuildCaption->hide();
88 m_pBuildLabel->hide();
89 }
90
93 m_pLocaleLabel->set_label(GetLocaleString());
94 m_pMiscLabel->set_label(GetMiscString());
96
97 // Images
98 const tools::Long nWidth(m_pCopyrightLabel->get_preferred_size().getWidth());
99 BitmapEx aBackgroundBitmap;
100
102 .GetStyleSettings()
103 .GetDialogColor()
104 .IsDark()
105 ? "shell/logo_inverted"
106 : "shell/logo",
107 aBackgroundBitmap, nWidth * 0.8)) {
108 // Eliminate white background when Skia is disabled by not drawing the
109 // background bitmap to a VirtualDevice. On most platforms, non-Skia
110 // VirtualDevices will be filled with a solid color when drawing
111 // the bitmap.
112 Graphic aGraphic(aBackgroundBitmap);
113 m_pBrandImage->set_image(aGraphic.GetXGraphic());
114 }
115 if (SfxApplication::loadBrandSvg("shell/about", aBackgroundBitmap, nWidth * 0.9)) {
116 // Eliminate white background when Skia is disabled by not drawing the
117 // background bitmap to a VirtualDevice. On most platforms, non-Skia
118 // VirtualDevices will be filled with a solid color when drawing
119 // the bitmap.
120 Graphic aGraphic(aBackgroundBitmap);
121 m_pAboutImage->set_image(aGraphic.GetXGraphic());
122 }
123
124 // Links
125 m_pCreditsButton->set_uri(officecfg::Office::Common::Menus::CreditsURL::get());
126
127 OUString sURL(officecfg::Office::Common::Help::StartCenter::InfoURL::get());
129 m_pWebsiteButton->set_uri(sURL);
130
131 // See also SID_WHATSNEW in sfx2/source/appl/appserv.cxx
132 sURL = officecfg::Office::Common::Menus::ReleaseNotesURL::get() +
133 "?LOvers=" + utl::ConfigManager::getProductVersion() + "&LOlocale=" +
135 m_pReleaseNotesButton->set_uri(sURL);
136
137 // Handler
138 m_pCopyButton->connect_clicked(LINK(this, AboutDialog, HandleClick));
139 m_pCloseButton->grab_focus();
140}
141
143
144bool AboutDialog::IsStringValidGitHash(std::u16string_view hash) {
145 return std::all_of(hash.begin(), hash.end(),
146 [](auto &rSymbol) { return std::isxdigit(rSymbol); });
147}
148
150 OUString arch;
151 auto const ok = rtl::Bootstrap::get("_ARCH", arch);
152 assert(ok); (void) ok;
153 OUString sVersion = CuiResId(TranslateId(nullptr, "%ABOUTBOXPRODUCTVERSION%ABOUTBOXPRODUCTVERSIONSUFFIX")) + " (" + arch + ")";
154
155#if HAVE_FEATURE_COMMUNITY_FLAVOR
156 sVersion += " / LibreOffice Community";
157#endif
158
159 return sVersion;
160}
161
163{
164 OUString sBuildId(utl::Bootstrap::getBuildIdData(""));
165 SAL_WARN_IF(sBuildId.isEmpty(), "cui.dialogs", "No BUILDID in bootstrap file");
166
167 return sBuildId;
168}
169
170OUString AboutDialog::GetLocaleString(const bool bLocalized) {
171
172 OUString sLocaleStr;
173
174 rtl_Locale *pLocale;
175 osl_getProcessLocale(&pLocale);
176 if (pLocale && pLocale->Language) {
177 if (pLocale->Country && rtl_uString_getLength(pLocale->Country) > 0)
178 sLocaleStr = OUString::unacquired(&pLocale->Language) + "_" +
179 OUString::unacquired(&pLocale->Country);
180 else
181 sLocaleStr = OUString(pLocale->Language);
182 if (pLocale->Variant && rtl_uString_getLength(pLocale->Variant) > 0)
183 sLocaleStr += OUString(pLocale->Variant);
184 }
185
186 sLocaleStr = Application::GetSettings().GetLanguageTag().getBcp47() + " (" +
187 sLocaleStr + ")";
188
189 OUString aUILocaleStr =
191 OUString sUILocaleStr;
192 if (bLocalized)
193 sUILocaleStr = CuiResId(RID_CUISTR_ABOUT_UILOCALE);
194 else
195 sUILocaleStr = Translate::get(RID_CUISTR_ABOUT_UILOCALE, Translate::Create("cui", LanguageTag("en-US")));
196
197 if (sUILocaleStr.indexOf("$LOCALE") == -1) {
198 SAL_WARN("cui.dialogs", "translated uilocale string in translations "
199 "doesn't contain $LOCALE placeholder");
200 sUILocaleStr += " $LOCALE";
201 }
202 sUILocaleStr = sUILocaleStr.replaceAll("$LOCALE", aUILocaleStr);
203
204 return sLocaleStr + "; " + sUILocaleStr;
205}
206
208
209 OUString sMisc;
210
211 bool const extra = EXTRA_BUILDID[0] != '\0';
212 // extracted from the 'if' to avoid Clang -Wunreachable-code
213 if (extra) {
214 sMisc = EXTRA_BUILDID "\n";
215 }
216
217 OUString aCalcMode; // Calc calculation mode
218
219#if HAVE_FEATURE_OPENCL
221 aCalcMode += " CL";
222#endif
223
224 static const bool bThreadingProhibited =
225 std::getenv("SC_NO_THREADED_CALCULATION");
226 bool bThreadedCalc = officecfg::Office::Calc::Formula::Calculation::
227 UseThreadedCalculationForFormulaGroups::get();
228
229 if (!bThreadingProhibited && bThreadedCalc) {
230 aCalcMode += " threaded";
231 }
232
233 if (officecfg::Office::Calc::Defaults::Sheet::JumboSheets::get())
234 {
235 aCalcMode += " Jumbo";
236 }
237
238 if (aCalcMode.isEmpty())
239 aCalcMode = " default";
240 sMisc += "Calc:" + aCalcMode;
241
242 return sMisc;
243}
244
246 OUString sVendorTextStr(CuiResId(RID_CUISTR_ABOUT_VENDOR));
247 OUString aCopyrightString =
248 sVendorTextStr + "\n" + CuiResId(RID_CUISTR_ABOUT_COPYRIGHT) + "\n";
249
250 if (utl::ConfigManager::getProductName() == "LibreOffice")
251 aCopyrightString += CuiResId(RID_CUISTR_ABOUT_BASED_ON);
252 else
253 aCopyrightString += CuiResId(RID_CUISTR_ABOUT_DERIVED);
254
255 return aCopyrightString;
256}
257
258// special labels to comply with previous version info
259// untranslated English for QA
261 css::uno::Reference<css::datatransfer::clipboard::XClipboard> xClipboard =
262 css::datatransfer::clipboard::SystemClipboard::create(
264
265 OUString sInfo = "Version: " + m_pVersionLabel->get_label() + "\n" // version
266 "Build ID: " + GetBuildString() + "\n" + // build id
267 Application::GetHWOSConfInfo(0,false) + "\n" // env+UI
268 "Locale: " + GetLocaleString(false) + "\n" + // locale
269 GetMiscString(); // misc
270
272}
273/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
IMPL_LINK_NOARG(AboutDialog, HandleClick, weld::Button &, void)
Definition: about.cxx:260
std::unique_ptr< weld::Label > m_pBuildCaption
Definition: about.hxx:35
std::unique_ptr< weld::Button > m_pCopyButton
Definition: about.hxx:30
std::unique_ptr< weld::Image > m_pAboutImage
Definition: about.hxx:33
std::unique_ptr< weld::Label > m_pMiscLabel
Definition: about.hxx:40
virtual ~AboutDialog() override
Definition: about.cxx:142
static OUString GetCopyrightString()
Definition: about.cxx:245
static bool IsStringValidGitHash(std::u16string_view hash)
Definition: about.cxx:144
static OUString GetLocaleString(bool bLocalized=true)
Definition: about.cxx:170
std::unique_ptr< weld::Label > m_pVersionLabel
Definition: about.hxx:34
std::unique_ptr< weld::Button > m_pCloseButton
Definition: about.hxx:29
std::unique_ptr< weld::Image > m_pBrandImage
Definition: about.hxx:32
std::unique_ptr< weld::LinkButton > m_pBuildLabel
Definition: about.hxx:36
std::unique_ptr< weld::Label > m_pCopyrightLabel
Definition: about.hxx:41
std::unique_ptr< weld::Label > m_pEnvLabel
Definition: about.hxx:37
std::unique_ptr< weld::Label > m_pLocaleLabel
Definition: about.hxx:39
std::unique_ptr< weld::LinkButton > m_pCreditsButton
Definition: about.hxx:26
std::unique_ptr< weld::LinkButton > m_pReleaseNotesButton
Definition: about.hxx:28
std::unique_ptr< weld::LinkButton > m_pWebsiteButton
Definition: about.hxx:27
static OUString GetBuildString()
Definition: about.cxx:162
static OUString GetVersionString()
Definition: about.cxx:149
AboutDialog(weld::Window *pParent)
Definition: about.cxx:57
std::unique_ptr< weld::Label > m_pUILabel
Definition: about.hxx:38
static OUString GetMiscString()
Definition: about.cxx:207
const LanguageTag & GetLanguageTag() const
const LanguageTag & GetUILanguageTag() const
static OUString GetHWOSConfInfo(const int bSelection=0, bool bLocalize=true)
static const AllSettings & GetSettings()
css::uno::Reference< css::graphic::XGraphic > GetXGraphic() const
const OUString & getBcp47(bool bResolveSystem=true) const
static bool loadBrandSvg(const char *pName, BitmapEx &rBitmap, int nWidth)
static OUString getBuildIdData(OUString const &_sDefault)
static OUString getProductVersion()
static OUString getUILocale()
static OUString getProductName()
static void CopyStringTo(const OUString &rContent, const css::uno::Reference< css::datatransfer::clipboard::XClipboard > &rxClipboard, const vcl::ILibreOfficeKitNotifier *pNotifier=nullptr)
OUString CuiResId(TranslateId aKey)
Definition: cuiresmgr.cxx:23
float u
SVT_DLLPUBLIC void localizeWebserviceURI(OUString &io_rURI)
const char * pLocale
#define SAL_WARN_IF(condition, area, stream)
#define SAL_WARN(area, stream)
std::locale Create(std::string_view aPrefixName, const LanguageTag &rLocale)
OUString get(TranslateId sContextAndId, const std::locale &loc)
Reference< XComponentContext > getProcessComponentContext()
long Long
static bool isOpenCLEnabled()