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

Generated by: LCOV version 1.10