update credits
[LibreOffice.git] / cui / source / dialogs / about.cxx
blob4243180652dc6aa91b1161ffccb2e071f455b9e3
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 <vcl/layout.hxx>
21 #include <vcl/svapp.hxx>
22 #include <vcl/msgbox.hxx>
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>
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>
42 #include <sfx2/sfxuno.hxx>
43 #include <sfx2/sfxcommands.h>
44 #include "about.hxx"
45 #include <config_buildid.h>
46 #include <sfx2/sfxdefs.hxx>
47 #include <sfx2/app.hxx>
48 #include <rtl/ustrbuf.hxx>
49 #include <vcl/bitmap.hxx>
50 #include <officecfg/Office/Common.hxx>
52 using namespace ::com::sun::star::uno;
53 using namespace ::com::sun::star::beans;
54 using namespace ::com::sun::star;
56 enum AboutDialogButton
58 CREDITS_BUTTON,
59 WEBSITE_BUTTON
62 AboutDialog::AboutDialog(Window* pParent)
63 : SfxModalDialog(pParent, "AboutDialog", "cui/ui/aboutdialog.ui")
65 get(m_pLogoReplacement, "logoreplacement");
66 get(m_pLogoImage, "logo");
67 get(m_pVersion, "version");
68 get(m_pDescriptionText, "description");
69 get(m_pCopyrightText, "copyright");
70 m_aCopyrightTextStr = m_pCopyrightText->GetText();
71 get(m_pWebsiteButton, "website");
72 get(m_pCreditsButton, "credits");
73 m_aCreditsLinkStr = get<FixedText>("link")->GetText();
74 m_sBuildStr = get<FixedText>("buildid")->GetText();
75 m_aVendorTextStr = get<FixedText>("vendor")->GetText();
76 m_aVersionTextStr = m_pVersion->GetText();
77 m_aBasedTextStr = get<FixedText>("libreoffice")->GetText();
78 m_aBasedDerivedTextStr = get<FixedText>("derived")->GetText();
80 m_pVersion->SetText(GetVersionString());
82 OUString aCopyrightString = GetCopyrightString();
83 m_pCopyrightText->SetText( aCopyrightString );
85 StyleControls();
87 SetLogo();
89 // Allow the button to be identifiable once they are clicked
90 m_pCreditsButton->SetData( (void*)CREDITS_BUTTON );
91 m_pWebsiteButton->SetData( (void*)WEBSITE_BUTTON );
93 // Connect all handlers
94 m_pCreditsButton->SetClickHdl( LINK( this, AboutDialog, HandleClick ) );
95 m_pWebsiteButton->SetClickHdl( LINK( this, AboutDialog, HandleClick ) );
97 get<PushButton>("close")->GrabFocus();
100 IMPL_LINK( AboutDialog, HandleClick, PushButton*, pButton )
102 OUString sURL = "";
104 // Find which button was pressed and from this, get the URL to be opened
105 AboutDialogButton* pDialogButton = (AboutDialogButton*)pButton->GetData();
106 if ( pDialogButton == (AboutDialogButton*)CREDITS_BUTTON )
107 sURL = m_aCreditsLinkStr;
108 else if ( pDialogButton == (AboutDialogButton*)WEBSITE_BUTTON )
110 sURL = officecfg::Office::Common::Help::StartCenter::InfoURL::get();
111 localizeWebserviceURI(sURL);
114 // If the URL is empty, don't do anything
115 if ( sURL.isEmpty() )
116 return 1;
119 Reference< com::sun::star::system::XSystemShellExecute > xSystemShellExecute(
120 com::sun::star::system::SystemShellExecute::create(::comphelper::getProcessComponentContext() ) );
121 xSystemShellExecute->execute( sURL, OUString(), com::sun::star::system::SystemShellExecuteFlags::URIS_ONLY );
123 catch (const Exception&)
125 Any exc( ::cppu::getCaughtException() );
126 OUString msg( ::comphelper::anyToString( exc ) );
127 const SolarMutexGuard guard;
128 ErrorBox aErrorBox( NULL, WB_OK, msg );
129 aErrorBox.SetText( GetText() );
130 aErrorBox.Execute();
133 return 1;
136 void AboutDialog::StyleControls()
138 // Make all the controls have a transparent background
139 m_pLogoImage->SetBackground();
140 m_pLogoReplacement->SetPaintTransparent(true);
141 m_pVersion->SetPaintTransparent(true);
142 m_pDescriptionText->SetPaintTransparent(true);
143 m_pCopyrightText->SetPaintTransparent(true);
145 Font aLabelFont = GetSettings().GetStyleSettings().GetLabelFont();
146 Font aLargeFont = aLabelFont;
147 aLargeFont.SetSize( Size( 0, aLabelFont.GetSize().Height() * 3 ) );
149 // Logo Replacement Text
150 m_pLogoReplacement->SetControlFont( aLargeFont );
152 // Description Text
153 aLargeFont.SetSize( Size( 0, aLabelFont.GetSize().Height() * 1.3 ) );
154 m_pDescriptionText->SetControlFont(aLargeFont);
156 // Version Text
157 aLargeFont.SetSize( Size( 0, aLabelFont.GetSize().Height() * 1.2 ) );
158 m_pVersion->SetControlFont(aLargeFont);
160 // If not in high-contrast mode, hard-code colors
161 if ( !(Application::GetSettings().GetStyleSettings().GetHighContrastMode()) )
163 m_pLogoReplacement->SetControlForeground(Color(51, 51, 51));
164 m_pVersion->SetControlForeground(Color(102, 102, 102));
165 m_pDescriptionText->SetControlForeground(Color(51, 51, 51));
166 m_pCopyrightText->SetControlForeground(Color(102, 102, 102));
170 void AboutDialog::SetLogo()
172 long nWidth = get_content_area()->get_preferred_size().Width();
174 // load svg logo, specify desired width, scale height isotrophically
175 if( SfxApplication::loadBrandSvg("flat_logo", aLogoBitmap, nWidth) &&
176 !aLogoBitmap.IsEmpty() )
178 m_pLogoImage->SetImage(Image(aLogoBitmap));
179 m_pLogoReplacement->Hide();
180 m_pLogoImage->Show();
182 else
184 m_pLogoImage->Hide();
185 m_pLogoReplacement->Show();
189 void AboutDialog::Resize()
191 SfxModalDialog::Resize();
192 // Load background image
193 if (isInitialLayout(this) && !(Application::GetSettings().GetStyleSettings().GetHighContrastMode()))
195 SfxApplication::loadBrandSvg("shell/about", aBackgroundBitmap, GetOutputSizePixel().Width());
199 void AboutDialog::Paint( const Rectangle& rRect )
201 SetClipRegion(Region(rRect));
203 Size aSize(GetOutputSizePixel());
204 Point aPos(aSize.Width() - aBackgroundBitmap.GetSizePixel().Width(),
205 aSize.Height() - aBackgroundBitmap.GetSizePixel().Height());
206 DrawBitmapEx(aPos, aBackgroundBitmap);
209 OUString AboutDialog::GetBuildId()
211 OUString sDefault;
212 OUString sBuildId(utl::Bootstrap::getBuildVersion(sDefault));
213 if (!sBuildId.isEmpty())
214 return sBuildId;
216 sBuildId = utl::Bootstrap::getBuildIdData(sDefault);
218 if (!sBuildId.isEmpty())
220 sal_Int32 nIndex = 0;
221 return sBuildId.getToken( 0, '-', nIndex );
224 OSL_ENSURE( !sBuildId.isEmpty(), "No BUILDID in bootstrap file" );
225 return sBuildId;
228 OUString AboutDialog::GetVersionString()
230 OUString sVersion = m_aVersionTextStr;
232 OUString sBuildId = GetBuildId();
234 if (!sBuildId.trim().isEmpty())
236 sVersion += "\n";
237 if (m_sBuildStr.indexOf("$BUILDID") == -1)
239 SAL_WARN( "cui.dialogs", "translated Build Id string in translations doesn't contain $BUILDID placeholder" );
240 m_sBuildStr += " $BUILDID";
242 sVersion += m_sBuildStr.replaceAll("$BUILDID", sBuildId);
245 if (strlen(EXTRA_BUILDID) > 0)
247 sVersion += "\n";
248 sVersion += EXTRA_BUILDID;
251 return sVersion;
254 OUString AboutDialog::GetCopyrightString()
256 OUString aCopyrightString = m_aVendorTextStr;
257 aCopyrightString += "\n";
259 aCopyrightString += m_aCopyrightTextStr;
260 aCopyrightString += "\n";
262 if (utl::ConfigManager::getProductName().equals("LibreOffice"))
263 aCopyrightString += m_aBasedTextStr;
264 else
265 aCopyrightString += m_aBasedDerivedTextStr;
267 return aCopyrightString;
270 sal_Bool AboutDialog::Close()
272 EndDialog( RET_OK );
273 return sal_False;
276 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */