LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/vcl/source/app - brand.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 25 26 96.2 %
Date: 2013-07-09 Functions: 5 5 100.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 <rtl/ustring.hxx>
      21             : #include <rtl/bootstrap.hxx>
      22             : #include <osl/process.h>
      23             : #include <tools/urlobj.hxx>
      24             : #include <tools/stream.hxx>
      25             : #include <vcl/pngread.hxx>
      26             : #include <vcl/svapp.hxx>
      27             : #include <vcl/svgdata.hxx>
      28             : 
      29             : namespace {
      30           9 :     static bool loadPng( const OUString & rPath, BitmapEx &rBitmap)
      31             :     {
      32           9 :         INetURLObject aObj( rPath );
      33          18 :         SvFileStream aStrm( aObj.PathToFileName(), STREAM_STD_READ );
      34           9 :         if ( !aStrm.GetError() ) {
      35           3 :             vcl::PNGReader aReader( aStrm );
      36           3 :             rBitmap = aReader.Read();
      37           3 :             return !rBitmap.IsEmpty();
      38             :         }
      39             :         else
      40          15 :             return false;
      41             :     }
      42           9 :     static bool tryLoadPng( const OUString& rBaseDir, const OUString& rName, BitmapEx& rBitmap )
      43             :     {
      44           9 :         return loadPng( rBaseDir + "/program" + rName, rBitmap);
      45             :     }
      46             : }
      47             : 
      48           3 : bool Application::LoadBrandBitmap (const char* pName, BitmapEx &rBitmap)
      49             : {
      50             :     // TODO - if we want more flexibility we could add a branding path
      51             :     // in an rc file perhaps fallback to "about.bmp"
      52           3 :     OUString aBaseDir( "$BRAND_BASE_DIR");
      53           3 :     rtl::Bootstrap::expandMacros( aBaseDir );
      54           6 :     OUString aBaseName( "/" + OUString::createFromAscii( pName ) );
      55           6 :     OUString aPng( ".png" );
      56             : 
      57           3 :     rtl_Locale *pLoc = NULL;
      58           3 :     osl_getProcessLocale (&pLoc);
      59           6 :     LanguageTag aLanguageTag( *pLoc);
      60             : 
      61           6 :     ::std::vector< OUString > aFallbacks( aLanguageTag.getFallbackStrings());
      62           9 :     for (size_t i=0; i < aFallbacks.size(); ++i)
      63             :     {
      64           6 :         if (tryLoadPng( aBaseDir, aBaseName + "-" + aFallbacks[i] + aPng, rBitmap))
      65           0 :             return true;
      66             :     }
      67             : 
      68           3 :     if (tryLoadPng( aBaseDir, aBaseName + aPng, rBitmap))
      69           3 :         return true;
      70             : 
      71           3 :     return false;
      72         465 : }
      73             : 
      74             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10