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