android: Update app icon to new startcenter icon
[LibreOffice.git] / dbaccess / source / ui / misc / imageprovider.cxx
blob388df30e271fc9ff08202faac6b0a71e3dbfd3c0
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <imageprovider.hxx>
21 #include <bitmaps.hlst>
23 #include <com/sun/star/graphic/GraphicColorMode.hpp>
24 #include <com/sun/star/sdb/application/XTableUIProvider.hpp>
25 #include <com/sun/star/sdb/application/DatabaseObject.hpp>
26 #include <com/sun/star/sdbcx/XViewsSupplier.hpp>
28 #include <comphelper/diagnose_ex.hxx>
30 namespace dbaui
33 using ::com::sun::star::uno::Reference;
34 using ::com::sun::star::sdbc::XConnection;
35 using ::com::sun::star::uno::Exception;
36 using ::com::sun::star::container::XNameAccess;
37 using ::com::sun::star::graphic::XGraphic;
38 using ::com::sun::star::sdb::application::XTableUIProvider;
39 using ::com::sun::star::uno::UNO_QUERY;
40 using ::com::sun::star::sdbcx::XViewsSupplier;
41 using ::com::sun::star::uno::UNO_SET_THROW;
43 namespace GraphicColorMode = css::graphic::GraphicColorMode;
44 namespace DatabaseObject = css::sdb::application::DatabaseObject;
46 namespace
48 void lcl_getConnectionProvidedTableIcon_nothrow(
49 const css::uno::Reference< css::sdb::application::XTableUIProvider >& _xTableUI,
50 const OUString& _rName, Reference< XGraphic >& _out_rxGraphic )
52 try
54 if ( _xTableUI.is() )
55 _out_rxGraphic = _xTableUI->getTableIcon( _rName, GraphicColorMode::NORMAL );
57 catch( const Exception& )
59 DBG_UNHANDLED_EXCEPTION("dbaccess");
63 void lcl_getTableImageResourceID_nothrow(
64 const css::uno::Reference< css::container::XNameAccess >& _xViews,
65 const OUString& _rName,
66 OUString& _out_rResourceID)
68 _out_rResourceID = OUString();
69 try
71 bool bIsView = _xViews.is() && _xViews->hasByName( _rName );
72 if ( bIsView )
74 _out_rResourceID = VIEW_TREE_ICON;
76 else
78 _out_rResourceID = TABLE_TREE_ICON;
81 catch( const Exception& )
83 DBG_UNHANDLED_EXCEPTION("dbaccess");
87 // ImageProvider
88 ImageProvider::ImageProvider()
92 ImageProvider::ImageProvider( const Reference< XConnection >& _rxConnection )
93 : mxConnection(_rxConnection)
95 try
97 Reference< XViewsSupplier > xSuppViews( mxConnection, UNO_QUERY );
98 if ( xSuppViews.is() )
99 mxViews.set( xSuppViews->getViews(), UNO_SET_THROW );
101 mxTableUI.set( _rxConnection, UNO_QUERY );
103 catch( const Exception& )
105 DBG_UNHANDLED_EXCEPTION("dbaccess");
109 OUString ImageProvider::getImageId(const OUString& _rName, const sal_Int32 _nDatabaseObjectType)
111 if (_nDatabaseObjectType != DatabaseObject::TABLE)
113 // for types other than tables, the icon does not depend on the concrete object
114 return getDefaultImageResourceID( _nDatabaseObjectType );
116 else
118 // no -> determine by type
119 OUString sImageResourceID;
120 lcl_getTableImageResourceID_nothrow( mxViews, _rName, sImageResourceID );
121 return sImageResourceID;
125 Reference<XGraphic> ImageProvider::getXGraphic(const OUString& _rName, const sal_Int32 _nDatabaseObjectType)
127 Reference<XGraphic> xGraphic;
128 if (_nDatabaseObjectType == DatabaseObject::TABLE)
130 // check whether the connection can give us an icon
131 lcl_getConnectionProvidedTableIcon_nothrow( mxTableUI, _rName, xGraphic );
133 return xGraphic;
136 OUString ImageProvider::getDefaultImageResourceID( sal_Int32 _nDatabaseObjectType)
138 OUString sImageResourceID;
139 switch ( _nDatabaseObjectType )
141 case DatabaseObject::QUERY:
142 sImageResourceID = QUERY_TREE_ICON;
143 break;
144 case DatabaseObject::FORM:
145 sImageResourceID = FORM_TREE_ICON;
146 break;
147 case DatabaseObject::REPORT:
148 sImageResourceID = REPORT_TREE_ICON;
149 break;
150 case DatabaseObject::TABLE:
151 sImageResourceID = TABLE_TREE_ICON;
152 break;
153 default:
154 OSL_FAIL( "ImageProvider::getDefaultImage: invalid database object type!" );
155 break;
157 return sImageResourceID;
160 OUString ImageProvider::getFolderImageId( sal_Int32 _nDatabaseObjectType )
162 OUString sImageResourceID;
163 switch ( _nDatabaseObjectType )
165 case DatabaseObject::QUERY:
166 sImageResourceID = QUERYFOLDER_TREE_ICON;
167 break;
168 case DatabaseObject::FORM:
169 sImageResourceID = FORMFOLDER_TREE_ICON;
170 break;
171 case DatabaseObject::REPORT:
172 sImageResourceID = REPORTFOLDER_TREE_ICON;
173 break;
174 case DatabaseObject::TABLE:
175 sImageResourceID = TABLEFOLDER_TREE_ICON;
176 break;
177 default:
178 OSL_FAIL( "ImageProvider::getDefaultImage: invalid database object type!" );
179 break;
182 return sImageResourceID;
185 OUString ImageProvider::getDatabaseImage()
187 return DATABASE_TREE_ICON;
190 } // namespace dbaui
192 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */