LCOV - code coverage report
Current view: top level - dbaccess/source/ui/misc - imageprovider.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 46 77 59.7 %
Date: 2012-08-25 Functions: 9 11 81.8 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 34 112 30.4 %

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

Generated by: LCOV version 1.10