Initial commit
[tietoopcom] / include / TocUi / iconprovider.h
1 /** \file IconProvider.h
2  * \brief Declaration of IconProvider class
3  * 
4  * Tieto Open Communicator - Client for the Telepathy communications framework.
5  * Copyright (c) 2010, Tieto Corporation
6  *
7  * All rights reserved.
8  * Redistribution and use in source and binary forms, with or without modification,
9  * are permitted provided that the following conditions are met:
10  *
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.
19  *
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.
29  * 
30  */
31
32 #ifndef ICONPROVIDER_H
33 #define ICONPROVIDER_H
34
35 #include <QMap>
36
37 #include "defs.h"
38
39 QT_BEGIN_NAMESPACE
40
41 /** \brief IconProvider class
42  * 
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.
45  */
46 class IconProvider
47 {
48
49 public:
50
51         /** \brief Static public constructor
52          * 
53          * @return Pointer to the static instance
54          */
55         static IconProvider* getInstance();
56
57         /**
58          * Destructor
59          */
60         ~IconProvider();
61         
62         /** \brief This method finds suitable icon for a given contact and its presence.
63          *
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. 
67          *
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)
70          */     
71         QImage* matchIcon(const TocContact* pContact) const;
72
73         /** \brief This method finds suitable default icon for a given gender.
74          *
75          * It's convenience function for cases when there's no possibility to set Qt::DecorationRole.
76          *
77          * @param gender Gender for which icon needs to be matched.
78          * @return Default icon for a given gender.
79          */             
80         QIcon matchIcon(Gender gender) const;
81         
82         /** \brief Extends repository of custom icons for a given contact.
83          *
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.
87          *
88          * @param pContact Contact for which new custom icons are going to be added.
89          */             
90         void setCustomIcon(TocContact* pContact);
91
92
93 private: // Methods
94
95         /** \brief Private constructor
96          * 
97          */
98         IconProvider();
99         
100         /** \brief Used to compose presence picture in case presence was changed
101          * 
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.
104          *
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
108          */
109         QImage* addStatusFrame(const QImage* baseImage, Presence presence) const;
110
111 private: // Members
112         
113         static IconProvider* mp_self;
114         
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.
118         
119         QString _defaultMaleImagePath;
120         QString _defaultFemaleImagePath;
121         QString _defaultUnknownImagePath;
122 };
123
124 QT_END_NAMESPACE
125
126 #endif // ICONPROVIDER_H