LibreOffice Module dbaccess (master) 1
imageprovider.cxx
Go to the documentation of this file.
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 <bitmaps.hlst>
22
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>
27
29
30namespace dbaui
31{
32
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;
42
43 namespace GraphicColorMode = css::graphic::GraphicColorMode;
44 namespace DatabaseObject = css::sdb::application::DatabaseObject;
45
46 namespace
47 {
48 void lcl_getConnectionProvidedTableIcon_nothrow(
49 const css::uno::Reference< css::sdb::application::XTableUIProvider >& _xTableUI,
50 const OUString& _rName, Reference< XGraphic >& _out_rxGraphic )
51 {
52 try
53 {
54 if ( _xTableUI.is() )
55 _out_rxGraphic = _xTableUI->getTableIcon( _rName, GraphicColorMode::NORMAL );
56 }
57 catch( const Exception& )
58 {
59 DBG_UNHANDLED_EXCEPTION("dbaccess");
60 }
61 }
62
63 void lcl_getTableImageResourceID_nothrow(
64 const css::uno::Reference< css::container::XNameAccess >& _xViews,
65 const OUString& _rName,
66 OUString& _out_rResourceID)
67 {
68 _out_rResourceID = OUString();
69 try
70 {
71 bool bIsView = _xViews.is() && _xViews->hasByName( _rName );
72 if ( bIsView )
73 {
74 _out_rResourceID = VIEW_TREE_ICON;
75 }
76 else
77 {
78 _out_rResourceID = TABLE_TREE_ICON;
79 }
80 }
81 catch( const Exception& )
82 {
83 DBG_UNHANDLED_EXCEPTION("dbaccess");
84 }
85 }
86 }
87 // ImageProvider
88 ImageProvider::ImageProvider()
89 {
90 }
91
92 ImageProvider::ImageProvider( const Reference< XConnection >& _rxConnection )
93 : mxConnection(_rxConnection)
94 {
95 try
96 {
97 Reference< XViewsSupplier > xSuppViews( mxConnection, UNO_QUERY );
98 if ( xSuppViews.is() )
99 mxViews.set( xSuppViews->getViews(), UNO_SET_THROW );
100
101 mxTableUI.set( _rxConnection, UNO_QUERY );
102 }
103 catch( const Exception& )
104 {
105 DBG_UNHANDLED_EXCEPTION("dbaccess");
106 }
107 }
108
109 OUString ImageProvider::getImageId(const OUString& _rName, const sal_Int32 _nDatabaseObjectType)
110 {
111 if (_nDatabaseObjectType != DatabaseObject::TABLE)
112 {
113 // for types other than tables, the icon does not depend on the concrete object
114 return getDefaultImageResourceID( _nDatabaseObjectType );
115 }
116 else
117 {
118 // no -> determine by type
119 OUString sImageResourceID;
120 lcl_getTableImageResourceID_nothrow( mxViews, _rName, sImageResourceID );
121 return sImageResourceID;
122 }
123 }
124
125 Reference<XGraphic> ImageProvider::getXGraphic(const OUString& _rName, const sal_Int32 _nDatabaseObjectType)
126 {
127 Reference<XGraphic> xGraphic;
128 if (_nDatabaseObjectType == DatabaseObject::TABLE)
129 {
130 // check whether the connection can give us an icon
131 lcl_getConnectionProvidedTableIcon_nothrow( mxTableUI, _rName, xGraphic );
132 }
133 return xGraphic;
134 }
135
136 OUString ImageProvider::getDefaultImageResourceID( sal_Int32 _nDatabaseObjectType)
137 {
138 OUString sImageResourceID;
139 switch ( _nDatabaseObjectType )
140 {
142 sImageResourceID = QUERY_TREE_ICON;
143 break;
144 case DatabaseObject::FORM:
145 sImageResourceID = FORM_TREE_ICON;
146 break;
148 sImageResourceID = REPORT_TREE_ICON;
149 break;
151 sImageResourceID = TABLE_TREE_ICON;
152 break;
153 default:
154 OSL_FAIL( "ImageProvider::getDefaultImage: invalid database object type!" );
155 break;
156 }
157 return sImageResourceID;
158 }
159
160 OUString ImageProvider::getFolderImageId( sal_Int32 _nDatabaseObjectType )
161 {
162 OUString sImageResourceID;
163 switch ( _nDatabaseObjectType )
164 {
166 sImageResourceID = QUERYFOLDER_TREE_ICON;
167 break;
168 case DatabaseObject::FORM:
169 sImageResourceID = FORMFOLDER_TREE_ICON;
170 break;
172 sImageResourceID = REPORTFOLDER_TREE_ICON;
173 break;
175 sImageResourceID = TABLEFOLDER_TREE_ICON;
176 break;
177 default:
178 OSL_FAIL( "ImageProvider::getDefaultImage: invalid database object type!" );
179 break;
180 }
181
182 return sImageResourceID;
183 }
184
185 OUString ImageProvider::getDatabaseImage()
186 {
187 return DATABASE_TREE_ICON;
188 }
189
190} // namespace dbaui
191
192/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
#define DBG_UNHANDLED_EXCEPTION(...)