LCOV - code coverage report
Current view: top level - dbaccess/source/ui/misc - imageprovider.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 54 77 70.1 %
Date: 2015-06-13 12:38:46 Functions: 10 11 90.9 %
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 "imageprovider.hxx"
      21             : #include "dbu_resource.hrc"
      22             : #include "moduledbu.hxx"
      23             : #include "dbustrings.hrc"
      24             : 
      25             : #include <com/sun/star/beans/XPropertySet.hpp>
      26             : #include <com/sun/star/graphic/XGraphic.hpp>
      27             : #include <com/sun/star/graphic/GraphicColorMode.hpp>
      28             : #include <com/sun/star/sdb/application/XTableUIProvider.hpp>
      29             : #include <com/sun/star/sdbcx/XViewsSupplier.hpp>
      30             : 
      31             : #include <tools/diagnose_ex.h>
      32             : 
      33             : namespace dbaui
      34             : {
      35             : 
      36             :     using ::com::sun::star::uno::Reference;
      37             :     using ::com::sun::star::sdbc::XConnection;
      38             :     using ::com::sun::star::uno::Exception;
      39             :     using ::com::sun::star::uno::UNO_QUERY_THROW;
      40             :     using ::com::sun::star::container::XNameAccess;
      41             :     using ::com::sun::star::beans::XPropertySet;
      42             :     using ::com::sun::star::graphic::XGraphic;
      43             :     using ::com::sun::star::sdb::application::XTableUIProvider;
      44             :     using ::com::sun::star::uno::UNO_QUERY;
      45             :     using ::com::sun::star::sdbcx::XViewsSupplier;
      46             :     using ::com::sun::star::uno::UNO_SET_THROW;
      47             : 
      48             :     namespace GraphicColorMode = css::graphic::GraphicColorMode;
      49             :     namespace DatabaseObject = css::sdb::application::DatabaseObject;
      50             : 
      51             :     // ImageProvider_Data
      52          18 :     struct ImageProvider_Data
      53             :     {
      54             :         /// the connection we work with
      55             :         Reference< XConnection >        xConnection;
      56             :         /// the views of the connection, if the DB supports views
      57             :         Reference< XNameAccess >        xViews;
      58             :         /// interface for providing table's UI
      59             :         Reference< XTableUIProvider >   xTableUI;
      60             :     };
      61             : 
      62             :     namespace
      63             :     {
      64           1 :         static void lcl_getConnectionProvidedTableIcon_nothrow(  const ImageProvider_Data& _rData,
      65             :             const OUString& _rName, Reference< XGraphic >& _out_rxGraphic )
      66             :         {
      67             :             try
      68             :             {
      69           1 :                 if ( _rData.xTableUI.is() )
      70           1 :                     _out_rxGraphic = _rData.xTableUI->getTableIcon( _rName, GraphicColorMode::NORMAL );
      71             :             }
      72           0 :             catch( const Exception& )
      73             :             {
      74             :                 DBG_UNHANDLED_EXCEPTION();
      75             :             }
      76           1 :         }
      77             : 
      78           1 :         static void lcl_getTableImageResourceID_nothrow( const ImageProvider_Data& _rData, const OUString& _rName,
      79             :             sal_uInt16& _out_rResourceID)
      80             :         {
      81           1 :             _out_rResourceID = 0;
      82             :             try
      83             :             {
      84           1 :                 bool bIsView = _rData.xViews.is() && _rData.xViews->hasByName( _rName );
      85           1 :                 if ( bIsView )
      86             :                 {
      87           0 :                     _out_rResourceID = VIEW_TREE_ICON;
      88             :                 }
      89             :                 else
      90             :                 {
      91           1 :                     _out_rResourceID = TABLE_TREE_ICON;
      92             :                 }
      93             :             }
      94           0 :             catch( const Exception& )
      95             :             {
      96             :                 DBG_UNHANDLED_EXCEPTION();
      97             :             }
      98           1 :         }
      99             :     }
     100             :     // ImageProvider
     101           8 :     ImageProvider::ImageProvider()
     102           8 :         :m_pData( new ImageProvider_Data )
     103             :     {
     104           8 :     }
     105             : 
     106           1 :     ImageProvider::ImageProvider( const Reference< XConnection >& _rxConnection )
     107           1 :         :m_pData( new ImageProvider_Data )
     108             :     {
     109           1 :         m_pData->xConnection = _rxConnection;
     110             :         try
     111             :         {
     112           1 :             Reference< XViewsSupplier > xSuppViews( m_pData->xConnection, UNO_QUERY );
     113           1 :             if ( xSuppViews.is() )
     114           0 :                 m_pData->xViews.set( xSuppViews->getViews(), UNO_SET_THROW );
     115             : 
     116           1 :             m_pData->xTableUI.set( _rxConnection, UNO_QUERY );
     117             :         }
     118           0 :         catch( const Exception& )
     119             :         {
     120             :             DBG_UNHANDLED_EXCEPTION();
     121             :         }
     122           1 :     }
     123             : 
     124           1 :     void ImageProvider::getImages( const OUString& _rName, const sal_Int32 _nDatabaseObjectType, Image& _out_rImage )
     125             :     {
     126           1 :         if ( _nDatabaseObjectType != DatabaseObject::TABLE )
     127             :         {
     128             :             // for types other than tables, the icon does not depend on the concrete object
     129           0 :             _out_rImage = getDefaultImage( _nDatabaseObjectType );
     130             :         }
     131             :         else
     132             :         {
     133             :             // check whether the connection can give us an icon
     134           1 :             Reference< XGraphic > xGraphic;
     135           1 :             lcl_getConnectionProvidedTableIcon_nothrow( *m_pData, _rName, xGraphic );
     136           1 :             if ( xGraphic.is() )
     137           0 :                 _out_rImage = Image( xGraphic );
     138             : 
     139           1 :             if ( !_out_rImage )
     140             :             {
     141             :                 // no -> determine by type
     142           1 :                 sal_uInt16 nImageResourceID = 0;
     143           1 :                 lcl_getTableImageResourceID_nothrow( *m_pData, _rName, nImageResourceID );
     144             : 
     145           1 :                 if ( nImageResourceID && !_out_rImage )
     146           1 :                     _out_rImage = Image( ModuleRes( nImageResourceID ) );
     147           1 :             }
     148             :         }
     149           1 :     }
     150             : 
     151           0 :     Image ImageProvider::getDefaultImage( sal_Int32 _nDatabaseObjectType )
     152             :     {
     153           0 :         Image aObjectImage;
     154           0 :         sal_uInt16 nImageResourceID( getDefaultImageResourceID( _nDatabaseObjectType) );
     155           0 :         if ( nImageResourceID )
     156           0 :             aObjectImage = Image( ModuleRes( nImageResourceID ) );
     157           0 :         return aObjectImage;
     158             :     }
     159             : 
     160           3 :     sal_uInt16 ImageProvider::getDefaultImageResourceID( sal_Int32 _nDatabaseObjectType)
     161             :     {
     162           3 :         sal_uInt16 nImageResourceID( 0 );
     163           3 :         switch ( _nDatabaseObjectType )
     164             :         {
     165             :         case DatabaseObject::QUERY:
     166           0 :             nImageResourceID = QUERY_TREE_ICON;
     167           0 :             break;
     168             :         case DatabaseObject::FORM:
     169           3 :             nImageResourceID = FORM_TREE_ICON;
     170           3 :             break;
     171             :         case DatabaseObject::REPORT:
     172           0 :             nImageResourceID = REPORT_TREE_ICON;
     173           0 :             break;
     174             :         case DatabaseObject::TABLE:
     175           0 :             nImageResourceID = TABLE_TREE_ICON;
     176           0 :             break;
     177             :         default:
     178             :             OSL_FAIL( "ImageProvider::getDefaultImage: invalid database object type!" );
     179           0 :             break;
     180             :         }
     181           3 :         return nImageResourceID;
     182             :     }
     183             : 
     184          12 :     Image ImageProvider::getFolderImage( sal_Int32 _nDatabaseObjectType )
     185             :     {
     186          12 :         sal_uInt16 nImageResourceID( 0 );
     187          12 :         switch ( _nDatabaseObjectType )
     188             :         {
     189             :         case DatabaseObject::QUERY:
     190           1 :             nImageResourceID = QUERYFOLDER_TREE_ICON;
     191           1 :             break;
     192             :         case DatabaseObject::FORM:
     193          10 :             nImageResourceID = FORMFOLDER_TREE_ICON;
     194          10 :             break;
     195             :         case DatabaseObject::REPORT:
     196           0 :             nImageResourceID = REPORTFOLDER_TREE_ICON;
     197           0 :             break;
     198             :         case DatabaseObject::TABLE:
     199           1 :             nImageResourceID = TABLEFOLDER_TREE_ICON;
     200           1 :             break;
     201             :         default:
     202             :             OSL_FAIL( "ImageProvider::getDefaultImage: invalid database object type!" );
     203           0 :             break;
     204             :         }
     205             : 
     206          12 :         Image aFolderImage;
     207          12 :         if ( nImageResourceID )
     208          12 :             aFolderImage = Image( ModuleRes( nImageResourceID ) );
     209          12 :         return aFolderImage;
     210             :     }
     211             : 
     212           1 :     Image ImageProvider::getDatabaseImage()
     213             :     {
     214           1 :         return Image( ModuleRes( DATABASE_TREE_ICON ) );
     215             :     }
     216             : 
     217             : } // namespace dbaui
     218             : 
     219             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11