LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/toolkit/source/helper - tkresmgr.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 34 2.9 %
Date: 2013-07-09 Functions: 2 7 28.6 %
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 <toolkit/helper/tkresmgr.hxx>
      21             : #include <tools/simplerm.hxx>
      22             : #include <comphelper/processfactory.hxx>
      23             : #include <comphelper/namedvaluecollection.hxx>
      24             : #include <com/sun/star/graphic/GraphicProvider.hpp>
      25             : #include <com/sun/star/graphic/XGraphicProvider.hpp>
      26             : #include <tools/resmgr.hxx>
      27             : #include <tools/diagnose_ex.h>
      28             : 
      29             : #include <vcl/svapp.hxx>
      30             : 
      31             : using ::com::sun::star::uno::Reference;
      32             : using ::com::sun::star::graphic::XGraphic;
      33             : using ::com::sun::star::graphic::XGraphicProvider;
      34             : using namespace ::com::sun::star;
      35             : // -----------------------------------------------------------------------------
      36             : // TkResMgr
      37             : // -----------------------------------------------------------------------------
      38             : 
      39             : SimpleResMgr*   TkResMgr::m_pSimpleResMgr = NULL;
      40             : ResMgr*         TkResMgr::m_pResMgr = NULL;
      41             : 
      42             : // -----------------------------------------------------------------------------
      43             : 
      44           0 : TkResMgr::EnsureDelete::~EnsureDelete()
      45             : {
      46           0 :     delete TkResMgr::m_pSimpleResMgr;
      47             : //    delete TkResMgr::m_pResMgr;
      48           0 : }
      49             : 
      50             : // -----------------------------------------------------------------------------
      51             : 
      52           0 : void TkResMgr::ensureImplExists()
      53             : {
      54           0 :     if (m_pSimpleResMgr)
      55           0 :         return;
      56             : 
      57           0 :     m_pSimpleResMgr = SimpleResMgr::Create( "tk", Application::GetSettings().GetUILanguageTag() );
      58           0 :     m_pResMgr = ResMgr::CreateResMgr( "tk" );
      59             : 
      60           0 :     if (m_pSimpleResMgr)
      61             :     {
      62             :         // now that we have a impl class, make sure it's deleted on unloading the library
      63           0 :         static TkResMgr::EnsureDelete s_aDeleteTheImplClass;
      64             :     }
      65             : }
      66             : 
      67             : // -----------------------------------------------------------------------------
      68           0 : OUString TkResMgr::loadString( sal_uInt16 nResId )
      69             : {
      70           0 :     OUString sReturn;
      71             : 
      72           0 :     ensureImplExists();
      73           0 :     if ( m_pSimpleResMgr )
      74           0 :         sReturn = m_pSimpleResMgr->ReadString( nResId );
      75             : 
      76           0 :     return sReturn;
      77             : }
      78             : 
      79             : // -----------------------------------------------------------------------------
      80           0 : Image TkResMgr::loadImage( sal_uInt16 nResId )
      81             : {
      82           0 :     Image aReturn;
      83             : 
      84           0 :     ensureImplExists();
      85           0 :     if ( m_pResMgr )
      86           0 :         aReturn = Image( ResId( nResId, *m_pResMgr ) );
      87             : 
      88           0 :     return aReturn;
      89             : }
      90             : 
      91             : // -----------------------------------------------------------------------------
      92           0 : Image TkResMgr::getImageFromURL( const OUString& i_rImageURL )
      93             : {
      94           0 :     if ( i_rImageURL.isEmpty() )
      95           0 :         return Image();
      96             : 
      97             :     try
      98             :     {
      99           0 :         Reference< uno::XComponentContext > xContext( ::comphelper::getProcessComponentContext() );
     100           0 :         Reference< XGraphicProvider > xProvider( graphic::GraphicProvider::create(xContext) );
     101           0 :         ::comphelper::NamedValueCollection aMediaProperties;
     102           0 :         aMediaProperties.put( "URL", i_rImageURL );
     103           0 :         Reference< XGraphic > xGraphic = xProvider->queryGraphic( aMediaProperties.getPropertyValues() );
     104           0 :         return Image( xGraphic );
     105             :     }
     106           0 :     catch( const uno::Exception& )
     107             :     {
     108             :         DBG_UNHANDLED_EXCEPTION();
     109             :     }
     110           0 :     return Image();
     111         465 : }
     112             : 
     113             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10