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

Generated by: LCOV version 1.10