Line data Source code
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 <vcl/layout.hxx>
21 : #include <vcl/svapp.hxx>
22 : #include <vcl/settings.hxx>
23 :
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>
32 :
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>
42 :
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 :
52 : using namespace ::com::sun::star::uno;
53 : using namespace ::com::sun::star::beans;
54 : using namespace ::com::sun::star;
55 :
56 : enum AboutDialogButton
57 : {
58 : CREDITS_BUTTON,
59 : WEBSITE_BUTTON
60 : };
61 :
62 0 : AboutDialog::AboutDialog(vcl::Window* pParent)
63 0 : : SfxModalDialog(pParent, "AboutDialog", "cui/ui/aboutdialog.ui")
64 : {
65 0 : get(m_pLogoReplacement, "logoreplacement");
66 0 : get(m_pLogoImage, "logo");
67 0 : get(m_pVersion, "version");
68 0 : get(m_pDescriptionText, "description");
69 0 : get(m_pCopyrightText, "copyright");
70 0 : m_aCopyrightTextStr = m_pCopyrightText->GetText();
71 0 : get(m_pWebsiteButton, "website");
72 0 : get(m_pCreditsButton, "credits");
73 0 : m_aCreditsLinkStr = get<FixedText>("link")->GetText();
74 0 : m_sBuildStr = get<FixedText>("buildid")->GetText();
75 0 : m_aVendorTextStr = get<FixedText>("vendor")->GetText();
76 0 : m_aVersionTextStr = m_pVersion->GetText();
77 0 : m_aBasedTextStr = get<FixedText>("libreoffice")->GetText();
78 0 : m_aBasedDerivedTextStr = get<FixedText>("derived")->GetText();
79 0 : m_aLocaleStr = get<FixedText>("locale")->GetText();;
80 :
81 0 : m_pVersion->SetText(GetVersionString());
82 :
83 0 : OUString aCopyrightString = GetCopyrightString();
84 0 : m_pCopyrightText->SetText( aCopyrightString );
85 :
86 0 : StyleControls();
87 :
88 0 : SetLogo();
89 :
90 : // Allow the button to be identifiable once they are clicked
91 0 : m_pCreditsButton->SetData( reinterpret_cast<void*>(CREDITS_BUTTON) );
92 0 : m_pWebsiteButton->SetData( reinterpret_cast<void*>(WEBSITE_BUTTON) );
93 :
94 : // Connect all handlers
95 0 : m_pCreditsButton->SetClickHdl( LINK( this, AboutDialog, HandleClick ) );
96 0 : m_pWebsiteButton->SetClickHdl( LINK( this, AboutDialog, HandleClick ) );
97 :
98 0 : get<PushButton>("close")->GrabFocus();
99 0 : }
100 :
101 0 : AboutDialog::~AboutDialog()
102 : {
103 0 : disposeOnce();
104 0 : }
105 :
106 0 : void AboutDialog::dispose()
107 : {
108 0 : m_pVersion.clear();
109 0 : m_pDescriptionText.clear();
110 0 : m_pCopyrightText.clear();
111 0 : m_pLogoImage.clear();
112 0 : m_pLogoReplacement.clear();
113 0 : m_pCreditsButton.clear();
114 0 : m_pWebsiteButton.clear();
115 0 : SfxModalDialog::dispose();
116 0 : }
117 :
118 0 : IMPL_LINK( AboutDialog, HandleClick, PushButton*, pButton )
119 : {
120 0 : OUString sURL = "";
121 :
122 : // Find which button was pressed and from this, get the URL to be opened
123 0 : AboutDialogButton aDialogButton = static_cast<AboutDialogButton>(reinterpret_cast<sal_Int64>(pButton->GetData()));
124 0 : if ( aDialogButton == CREDITS_BUTTON )
125 0 : sURL = m_aCreditsLinkStr;
126 0 : else if ( aDialogButton == WEBSITE_BUTTON )
127 : {
128 0 : sURL = officecfg::Office::Common::Help::StartCenter::InfoURL::get();
129 0 : localizeWebserviceURI(sURL);
130 : }
131 :
132 : // If the URL is empty, don't do anything
133 0 : if ( sURL.isEmpty() )
134 0 : return 1;
135 : try
136 : {
137 : Reference< com::sun::star::system::XSystemShellExecute > xSystemShellExecute(
138 0 : com::sun::star::system::SystemShellExecute::create(::comphelper::getProcessComponentContext() ) );
139 0 : xSystemShellExecute->execute( sURL, OUString(), com::sun::star::system::SystemShellExecuteFlags::URIS_ONLY );
140 : }
141 0 : catch (const Exception&)
142 : {
143 0 : Any exc( ::cppu::getCaughtException() );
144 0 : OUString msg( ::comphelper::anyToString( exc ) );
145 0 : const SolarMutexGuard guard;
146 0 : ScopedVclPtrInstance< MessageDialog > aErrorBox(nullptr, msg);
147 0 : aErrorBox->SetText( GetText() );
148 0 : aErrorBox->Execute();
149 : }
150 :
151 0 : return 1;
152 : }
153 :
154 0 : void AboutDialog::StyleControls()
155 : {
156 : // Make all the controls have a transparent background
157 0 : m_pLogoImage->SetBackground();
158 0 : m_pLogoReplacement->SetPaintTransparent(true);
159 0 : m_pVersion->SetPaintTransparent(true);
160 0 : m_pDescriptionText->SetPaintTransparent(true);
161 0 : m_pCopyrightText->SetPaintTransparent(true);
162 :
163 0 : const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
164 :
165 0 : vcl::Font aLabelFont = rStyleSettings.GetLabelFont();
166 0 : vcl::Font aLargeFont = aLabelFont;
167 0 : aLargeFont.SetSize(Size( 0, aLabelFont.GetSize().Height() * 3));
168 :
169 : // Logo Replacement Text
170 0 : m_pLogoReplacement->SetControlFont(aLargeFont);
171 :
172 : // Description Text
173 0 : aLargeFont.SetSize(Size(0, aLabelFont.GetSize().Height() * 1.3));
174 0 : m_pDescriptionText->SetControlFont(aLargeFont);
175 :
176 : // Version Text
177 0 : aLargeFont.SetSize(Size(0, aLabelFont.GetSize().Height() * 1.2));
178 0 : m_pVersion->SetControlFont(aLargeFont);
179 :
180 : // If not in high-contrast mode, hard-code colors
181 0 : if (!rStyleSettings.GetHighContrastMode())
182 : {
183 0 : m_pLogoReplacement->SetControlForeground(Color(51, 51, 51));
184 0 : m_pVersion->SetControlForeground(Color(102, 102, 102));
185 0 : m_pDescriptionText->SetControlForeground(Color(51, 51, 51));
186 0 : m_pCopyrightText->SetControlForeground(Color(102, 102, 102));
187 0 : }
188 0 : }
189 :
190 0 : void AboutDialog::SetLogo()
191 : {
192 0 : long nWidth = get_content_area()->get_preferred_size().Width();
193 :
194 : // fdo#67401 set AntiAliasing for SVG logo
195 0 : SvtOptionsDrawinglayer aDrawOpt;
196 0 : bool bOldAntiAliasSetting = aDrawOpt.IsAntiAliasing();
197 0 : aDrawOpt.SetAntiAliasing(true);
198 :
199 : // load svg logo, specify desired width, scale height isotrophically
200 0 : if (SfxApplication::loadBrandSvg("flat_logo", aLogoBitmap, nWidth) &&
201 0 : !aLogoBitmap.IsEmpty())
202 : {
203 0 : m_pLogoImage->SetImage(Image(aLogoBitmap));
204 0 : m_pLogoReplacement->Hide();
205 0 : m_pLogoImage->Show();
206 : }
207 : else
208 : {
209 0 : m_pLogoImage->Hide();
210 0 : m_pLogoReplacement->Show();
211 : }
212 0 : aDrawOpt.SetAntiAliasing(bOldAntiAliasSetting);
213 0 : }
214 :
215 0 : void AboutDialog::Resize()
216 : {
217 0 : SfxModalDialog::Resize();
218 :
219 : // Load background image
220 0 : if (isInitialLayout(this) && !(Application::GetSettings().GetStyleSettings().GetHighContrastMode()))
221 : {
222 0 : SfxApplication::loadBrandSvg("shell/about", aBackgroundBitmap, GetSizePixel().Width());
223 : }
224 0 : }
225 :
226 0 : void AboutDialog::Paint(vcl::RenderContext& rRenderContext, const Rectangle& rRect)
227 : {
228 0 : rRenderContext.SetClipRegion(vcl::Region(rRect));
229 :
230 0 : Size aSize(rRenderContext.GetOutputSizePixel());
231 0 : Point aPos(aSize.Width() - aBackgroundBitmap.GetSizePixel().Width(),
232 0 : aSize.Height() - aBackgroundBitmap.GetSizePixel().Height());
233 :
234 0 : rRenderContext.DrawBitmapEx(aPos, aBackgroundBitmap);
235 0 : }
236 :
237 0 : OUString AboutDialog::GetBuildId()
238 : {
239 0 : OUString sDefault;
240 0 : OUString sBuildId(utl::Bootstrap::getBuildVersion(sDefault));
241 0 : if (!sBuildId.isEmpty())
242 0 : return sBuildId;
243 :
244 0 : sBuildId = utl::Bootstrap::getBuildIdData(sDefault);
245 :
246 0 : if (!sBuildId.isEmpty())
247 : {
248 0 : sal_Int32 nIndex = 0;
249 0 : return sBuildId.getToken( 0, '-', nIndex );
250 : }
251 :
252 : OSL_ENSURE( !sBuildId.isEmpty(), "No BUILDID in bootstrap file" );
253 0 : return sBuildId;
254 : }
255 :
256 0 : OUString AboutDialog::GetLocaleString()
257 : {
258 0 : OUString aLocaleStr;
259 : rtl_Locale * pLocale;
260 :
261 0 : osl_getProcessLocale( &pLocale );
262 :
263 0 : if ( pLocale && pLocale->Language )
264 : {
265 0 : if (pLocale->Country && rtl_uString_getLength( pLocale->Country) > 0)
266 0 : aLocaleStr = OUString(pLocale->Language) + "_" + OUString(pLocale->Country);
267 : else
268 0 : aLocaleStr = OUString(pLocale->Language);
269 0 : if (pLocale->Variant && rtl_uString_getLength( pLocale->Variant) > 0)
270 0 : aLocaleStr += OUString(pLocale->Variant);
271 : }
272 :
273 0 : return aLocaleStr;
274 : }
275 :
276 0 : OUString AboutDialog::GetVersionString()
277 : {
278 0 : OUString sVersion = m_aVersionTextStr;
279 :
280 : #ifdef _WIN64
281 : sVersion += " (x64)";
282 : #endif
283 :
284 0 : OUString sBuildId = GetBuildId();
285 :
286 0 : OUString aLocaleStr = Application::GetSettings().GetLanguageTag().getBcp47() + " (" + GetLocaleString() + ")";
287 :
288 0 : if (!sBuildId.trim().isEmpty())
289 : {
290 0 : sVersion += "\n";
291 0 : if (m_sBuildStr.indexOf("$BUILDID") == -1)
292 : {
293 : SAL_WARN( "cui.dialogs", "translated Build Id string in translations doesn't contain $BUILDID placeholder" );
294 0 : m_sBuildStr += " $BUILDID";
295 : }
296 0 : sVersion += m_sBuildStr.replaceAll("$BUILDID", sBuildId);
297 : }
298 :
299 0 : if (EXTRA_BUILDID[0] != '\0')
300 : {
301 0 : sVersion += "\n" EXTRA_BUILDID;
302 : }
303 :
304 0 : if (!aLocaleStr.trim().isEmpty())
305 : {
306 0 : sVersion += "\n";
307 0 : if (m_aLocaleStr.indexOf("$LOCALE") == -1)
308 : {
309 : SAL_WARN( "cui.dialogs", "translated locale string in translations doesn't contain $LOCALE placeholder" );
310 0 : m_aLocaleStr += " $LOCALE";
311 : }
312 0 : sVersion += m_aLocaleStr.replaceAll("$LOCALE", aLocaleStr);
313 : }
314 :
315 0 : return sVersion;
316 : }
317 :
318 0 : OUString AboutDialog::GetCopyrightString()
319 : {
320 0 : OUString aCopyrightString = m_aVendorTextStr;
321 0 : aCopyrightString += "\n";
322 :
323 0 : aCopyrightString += m_aCopyrightTextStr;
324 0 : aCopyrightString += "\n";
325 :
326 0 : if (utl::ConfigManager::getProductName() == "LibreOffice")
327 0 : aCopyrightString += m_aBasedTextStr;
328 : else
329 0 : aCopyrightString += m_aBasedDerivedTextStr;
330 :
331 0 : return aCopyrightString;
332 : }
333 :
334 0 : bool AboutDialog::Close()
335 : {
336 0 : EndDialog( RET_OK );
337 0 : return false;
338 0 : }
339 :
340 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|