LCOV - code coverage report
Current view: top level - cui/source/dialogs - about.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 0 126 0.0 %
Date: 2014-11-03 Functions: 0 13 0.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10