1 /** \file IconProvider.h
2 * \brief Declaration of IconProvider class
4 * Tieto Open Communicator - Client for the Telepathy communications framework.
5 * Copyright (c) 2010, Tieto Corporation
8 * Redistribution and use in source and binary forms, with or without modification,
9 * are permitted provided that the following conditions are met:
11 * Redistributions of source code must retain the above copyright notice,
12 * this list of conditions and the following disclaimer.
13 * Redistributions in binary form must reproduce the above copyright notice,
14 * this list of conditions and the following disclaimer in the documentation
15 * and/or other materials provided with the distribution.
16 * Neither the name of the Tieto Corporation nor the names of its contributors
17 * may be used to endorse or promote products derived from this software without
18 * specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
28 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #ifndef ICONPROVIDER_H
33 #define ICONPROVIDER_H
41 /** \brief IconProvider class
43 * Purpose of this class is to create centralize way to access icons for contacts.
44 * It contains repository of all contact icons both default and custom marged with status frames.
51 /** \brief Static public constructor
53 * @return Pointer to the static instance
55 static IconProvider* getInstance();
62 /** \brief This method finds suitable icon for a given contact and its presence.
64 * Function looks for an icon inside one of maps _defaultIcons when no custom icon
65 * was set (customIconPath field is empty) and _customIcons when setCustomIcon
66 * function was called for a given contact.
68 * @param pContact Contact for which image is requested.
69 * @return Pointer to an image of user's Avatar composed with presence information (green, red or yellow frame)
71 QImage* matchIcon(const TocContact* pContact) const;
73 /** \brief This method finds suitable default icon for a given gender.
75 * It's convenience function for cases when there's no possibility to set Qt::DecorationRole.
77 * @param gender Gender for which icon needs to be matched.
78 * @return Default icon for a given gender.
80 QIcon matchIcon(Gender gender) const;
82 /** \brief Extends repository of custom icons for a given contact.
84 * This method adds new set of images to _customIcons map for a contact. It also assigns _customIconId.
85 * Icon id is used later by matchIcon method to access right image. New image is created out of file
86 * from customIconPath.
88 * @param pContact Contact for which new custom icons are going to be added.
90 void setCustomIcon(TocContact* pContact);
95 /** \brief Private constructor
100 /** \brief Used to compose presence picture in case presence was changed
102 * This method is used to compose picture showed in contact list.
103 * It use contactImage and Presence to create resultImage which is used in contact list.
105 * @param contactImage Image of user's Avatar
106 * @param presence Presence which will be displayed on resultImage
107 * @return resultImage Image of user's Avatar composed with presence information
109 QImage* addStatusFrame(const QImage* baseImage, Presence presence) const;
113 static IconProvider* mp_self;
115 QMap<int,QImage*> _customIcons; ///Map of custom images. Created at the begining out of contacts from settings or updated by setCustomIcon.
116 QMap<int,QImage*> _defaultIcons; ///Map of default images. Created inside the constructor. Used for contacts with no custom icon assign.
117 int _customIconId; ///This id 'generated' by incrementation when adding new custom icon inside setCustomIcon and enables fast access to images in _customIcons map.
119 QString _defaultMaleImagePath;
120 QString _defaultFemaleImagePath;
121 QString _defaultUnknownImagePath;
126 #endif // ICONPROVIDER_H