summaryrefslogtreecommitdiff
path: root/cui/source/dialogs/about.cxx
blob: 6295f6dea6dde661d761d4a5fa0aa1c0f644b50a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

#include <about.hxx>

#include <osl/process.h>     //osl_getProcessLocale
#include <sal/log.hxx>       //SAL_WARN
#include <vcl/settings.hxx>  //GetSettings
#include <vcl/svapp.hxx>     //Application::
#include <vcl/virdev.hxx>    //VirtualDevice
#include <vcl/weld.hxx>
#include <unotools/resmgr.hxx> //Translate

#include <config_buildid.h> //EXTRA_BUILDID
#include <config_features.h>
#include <dialmgr.hxx>      //CuiResId
#include <i18nlangtag/languagetag.hxx>
#include <sfx2/app.hxx> //SfxApplication::loadBrandSvg
#include <strings.hrc>
#include <svtools/langhelp.hxx>
#include <unotools/bootstrap.hxx> //utl::Bootstrap::getBuildIdData
#include <unotools/configmgr.hxx> //ConfigManager::

#include <com/sun/star/datatransfer/clipboard/SystemClipboard.hpp>
#include <vcl/unohelp2.hxx>

#include <config_feature_opencl.h>
#if HAVE_FEATURE_OPENCL
#include <opencl/openclwrapper.hxx>
#endif
#include <officecfg/Office/Calc.hxx>
#include <officecfg/Office/Common.hxx>

using namespace ::com::sun::star::uno;

AboutDialog::AboutDialog(weld::Window *pParent)
    : GenericDialogController(pParent, "cui/ui/aboutdialog.ui", "AboutDialog"),
      m_pCreditsButton(m_xBuilder->weld_link_button("btnCredits")),
      m_pWebsiteButton(m_xBuilder->weld_link_button("btnWebsite")),
      m_pReleaseNotesButton(m_xBuilder->weld_link_button("btnReleaseNotes")),
      m_pCloseButton(m_xBuilder->weld_button("btnClose")),
      m_pCopyButton(m_xBuilder->weld_button("btnCopyVersion")),
      m_pBrandImage(m_xBuilder->weld_image("imBrand")),
      m_pAboutImage(m_xBuilder->weld_image("imAbout")),
      m_pVersionLabel(m_xBuilder->weld_label("lbVersionString")),
      m_pBuildCaption(m_xBuilder->weld_label("lbBuild")),
      m_pBuildLabel(m_xBuilder->weld_link_button("lbBuildString")),
      m_pEnvLabel(m_xBuilder->weld_label("lbEnvString")),
      m_pUILabel(m_xBuilder->weld_label("lbUIString")),
      m_pLocaleLabel(m_xBuilder->weld_label("lbLocaleString")),
      m_pMiscLabel(m_xBuilder->weld_label("lbMiscString")),
      m_pCopyrightLabel(m_xBuilder->weld_label("lbCopyright")) {

  // Labels
  m_pVersionLabel->set_label(GetVersionString());

  OUString sbuildId = GetBuildString();
  if (IsStringValidGitHash(sbuildId)) {
    const tools::Long nMaxChar = 25;
    m_pBuildLabel->set_uri("https://gerrit.libreoffice.org/gitweb?p=core.git;a=log;h="
                           + sbuildId);
    m_pBuildLabel->set_label(sbuildId.getLength() > nMaxChar ? sbuildId.replaceAt(
                                 nMaxChar, sbuildId.getLength() - nMaxChar, "...")
                                                             : sbuildId);
  } else {
    m_pBuildCaption->hide();
    m_pBuildLabel->hide();
  }

  m_pEnvLabel->set_label(Application::GetHWOSConfInfo(1));
  m_pUILabel->set_label(Application::GetHWOSConfInfo(2));
  m_pLocaleLabel->set_label(GetLocaleString());
  m_pMiscLabel->set_label(GetMiscString());
  m_pCopyrightLabel->set_label(GetCopyrightString());

  // Images
  const tools::Long nWidth(m_pCopyrightLabel->get_preferred_size().getWidth());
  BitmapEx aBackgroundBitmap;

  if (SfxApplication::loadBrandSvg(Application::GetSettings()
                                           .GetStyleSettings()
                                           .GetDialogColor()
                                           .IsDark()
                                       ? "shell/logo_inverted"
                                       : "shell/logo",
                                   aBackgroundBitmap, nWidth * 0.8)) {
    ScopedVclPtr<VirtualDevice> m_pVirDev =
        m_pBrandImage->create_virtual_device();
    m_pVirDev->SetOutputSizePixel(aBackgroundBitmap.GetSizePixel());
    m_pVirDev->DrawBitmapEx(Point(0, 0), aBackgroundBitmap);
    m_pBrandImage->set_image(m_pVirDev.get());
    m_pVirDev.disposeAndClear();
  }
  if (SfxApplication::loadBrandSvg("shell/about", aBackgroundBitmap, nWidth * 0.9)) {
    ScopedVclPtr<VirtualDevice> m_pVirDev =
        m_pAboutImage->create_virtual_device();
    m_pVirDev->SetOutputSizePixel(aBackgroundBitmap.GetSizePixel());
    m_pVirDev->DrawBitmapEx(Point(0, 0), aBackgroundBitmap);
    m_pAboutImage->set_image(m_pVirDev.get());
    m_pVirDev.disposeAndClear();
  }

  // Links
  m_pCreditsButton->set_uri(CuiResId(RID_SVXSTR_ABOUT_CREDITS_URL));

  OUString sURL(officecfg::Office::Common::Help::StartCenter::InfoURL::get());
  // localizeWebserviceURI(sURL);
  m_pWebsiteButton->set_uri(sURL);

  // See also SID_WHATSNEW in sfx2/source/appl/appserv.cxx
  sURL = officecfg::Office::Common::Menus::ReleaseNotesURL::get() +
         "?LOvers=" + utl::ConfigManager::getProductVersion() + "&LOlocale=" +
         LanguageTag(utl::ConfigManager::getUILocale()).getBcp47();
  m_pReleaseNotesButton->set_uri(sURL);

  // Handler
  m_pCopyButton->connect_clicked(LINK(this, AboutDialog, HandleClick));
  m_pCloseButton->grab_focus();
}

AboutDialog::~AboutDialog() {}

bool AboutDialog::IsStringValidGitHash(const OUString &hash) {
  for (int i = 0; i < hash.getLength(); i++) {
    if (!std::isxdigit(hash[i])) {
      return false;
    }
  }
  return true;
}

OUString AboutDialog::GetVersionString() {
  OUString sVersion = CuiResId("%ABOUTBOXPRODUCTVERSION%ABOUTBOXPRODUCTVERSIONSUFFIX");

#ifdef _WIN64
  sVersion += " (x64)";
#elif defined(_WIN32)
  sVersion += " (x86)";
#endif

#if HAVE_FEATURE_COMMUNITY_FLAVOR
  sVersion += " / LibreOffice Community";
#endif

  return sVersion;
}

OUString AboutDialog::GetBuildString()
{
  OUString sBuildId(utl::Bootstrap::getBuildIdData(""));
  SAL_WARN_IF(sBuildId.isEmpty(), "cui.dialogs", "No BUILDID in bootstrap file");

  return sBuildId;
}

OUString AboutDialog::GetLocaleString(const bool bLocalized) {

  OUString sLocaleStr;

  rtl_Locale *pLocale;
  osl_getProcessLocale(&pLocale);
  if (pLocale && pLocale->Language) {
    if (pLocale->Country && rtl_uString_getLength(pLocale->Country) > 0)
      sLocaleStr = OUString::unacquired(&pLocale->Language) + "_" +
                   OUString::unacquired(&pLocale->Country);
    else
      sLocaleStr = OUString(pLocale->Language);
    if (pLocale->Variant && rtl_uString_getLength(pLocale->Variant) > 0)
      sLocaleStr += OUString(pLocale->Variant);
  }

  sLocaleStr = Application::GetSettings().GetLanguageTag().getBcp47() + " (" +
               sLocaleStr + ")";

  OUString aUILocaleStr =
      Application::GetSettings().GetUILanguageTag().getBcp47();
  OUString sUILocaleStr;
  if (bLocalized)
     sUILocaleStr = CuiResId(RID_SVXSTR_ABOUT_UILOCALE);
  else
     sUILocaleStr = Translate::get(RID_SVXSTR_ABOUT_UILOCALE, Translate::Create("cui", LanguageTag("en-US")));

  if (sUILocaleStr.indexOf("$LOCALE") == -1) {
    SAL_WARN("cui.dialogs", "translated uilocale string in translations "
                            "doesn't contain $LOCALE placeholder");
    sUILocaleStr += " $LOCALE";
  }
  sUILocaleStr = sUILocaleStr.replaceAll("$LOCALE", aUILocaleStr);

  return sLocaleStr + "; " + sUILocaleStr;
}

OUString AboutDialog::GetMiscString() {

  OUString sMisc;

  bool const extra = EXTRA_BUILDID[0] != '\0';
  // extracted from the 'if' to avoid Clang -Wunreachable-code
  if (extra) {
    sMisc = EXTRA_BUILDID "\n";
  }

  OUString aCalcMode = "Calc: "; // Calc calculation mode

#if HAVE_FEATURE_OPENCL
  bool bOpenCL = openclwrapper::GPUEnv::isOpenCLEnabled();
  if (bOpenCL)
    aCalcMode += "CL";
#else
  const bool bOpenCL = false;
#endif

  static const bool bThreadingProhibited =
      std::getenv("SC_NO_THREADED_CALCULATION");
  bool bThreadedCalc = officecfg::Office::Calc::Formula::Calculation::
      UseThreadedCalculationForFormulaGroups::get();

  if (!bThreadingProhibited && !bOpenCL && bThreadedCalc) {
    if (!aCalcMode.endsWith(" "))
      aCalcMode += " ";
    aCalcMode += "threaded";
  }

  sMisc += aCalcMode;

  return sMisc;
}

OUString AboutDialog::GetCopyrightString() {
  OUString sVendorTextStr(CuiResId(RID_SVXSTR_ABOUT_VENDOR));
  OUString aCopyrightString =
      sVendorTextStr + "\n" + CuiResId(RID_SVXSTR_ABOUT_COPYRIGHT) + "\n";

  if (utl::ConfigManager::getProductName() == "LibreOffice")
    aCopyrightString += CuiResId(RID_SVXSTR_ABOUT_BASED_ON);
  else
    aCopyrightString += CuiResId(RID_SVXSTR_ABOUT_DERIVED);

  return aCopyrightString;
}

// special labels to comply with previous version info
// untranslated English for QA
IMPL_LINK_NOARG(AboutDialog, HandleClick, weld::Button &, void) {
  css::uno::Reference<css::datatransfer::clipboard::XClipboard> xClipboard =
      css::datatransfer::clipboard::SystemClipboard::create(
          comphelper::getProcessComponentContext());

  OUString sInfo = "Version: " + m_pVersionLabel->get_label() + "\n" // version
                   "Build ID: " + GetBuildString() + "\n" + // build id
                   Application::GetHWOSConfInfo(0,false) + "\n" // env+UI
                   "Locale: " + GetLocaleString(false) + "\n" + // locale
                   GetMiscString(); // misc

  vcl::unohelper::TextDataObject::CopyStringTo(sInfo, xClipboard);
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */