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