1 /*
2  * This file is part of Licq, an instant messaging client for UNIX.
3  * Copyright (C) 2007-2014 Licq developers <licq-dev@googlegroups.com>
4  *
5  * Licq is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * Licq is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with Licq; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18  */
19 
20 #ifndef ICONMANAGER_H
21 #define ICONMANAGER_H
22 
23 #include "config.h"
24 
25 #include <QMap>
26 #include <QObject>
27 #include <QPair>
28 #include <QPixmap>
29 
30 #include <licq/contactlist/user.h>
31 #include <licq/userid.h>
32 
33 #include "core/gui-defines.h"
34 
35 namespace LicqQtGui
36 {
37 /**
38  * Manager for icon sets used in gui
39  */
40 class IconManager : public QObject
41 {
42   Q_OBJECT
43 
44 public:
45   enum IconType
46   {
47     // Message icons
48     StandardMessageIcon,
49     UrlMessageIcon,
50     ChatMessageIcon,
51     FileMessageIcon,
52     ContactMessageIcon,
53     AuthorizeMessageIcon,
54     ReqAuthorizeMessageIcon,
55 
56     // Extended icons
57     BirthdayIcon,
58     CellularIcon,
59     CollapsedIcon,
60     CustomArIcon,
61     ExpandedIcon,
62     GpgKeyDisabledIcon,
63     GpgKeyEnabledIcon,
64     IcqPhoneActiveIcon,
65     IcqPhoneBusyIcon,
66     InvisibleIcon,
67     PfmActiveIcon,
68     PfmBusyIcon,
69     PhoneIcon,
70     SharedFilesIcon,
71     TypingIcon,
72 
73     // Menu icons
74     RemoveIcon,
75     SearchIcon,
76     GpgKeyIcon,
77 
78     // Toolbar icons
79     BackColorIcon,
80     BeepIcon,
81     BoldIcon,
82     EncodingIcon,
83     HistoryIcon,
84     IgnoreIcon,
85     InfoIcon,
86     ItalicIcon,
87     MenuIcon,
88     SecureOffIcon,
89     SecureOnIcon,
90     SmileIcon,
91     StrikethroughIcon,
92     TextColorIcon,
93     ThroughServerIcon,
94     UnderlineIcon,
95     UrgentIcon,
96 
97     // Phonebook icons
98     MobileIcon,
99     SMSIcon,
100     FaxIcon,
101     PagerIcon,
102     PSTNIcon,
103   };
104 
105   enum ProtocolType
106   {
107     ProtocolIcq = ICQ_PPID,
108     ProtocolAim,
109     ProtocolMsn = MSN_PPID,
110     ProtocolXmpp = JABBER_PPID,
111   };
112 
113   /**
114    * Create the Icon Manager instance
115    *
116    * @param iconSet Initial icon set to load
117    * @param extendedIconSet Initial extended icon set to load
118    * @param parent Parent object
119    */
120   static void createInstance(const QString& iconSet,
121       const QString& extendedIconSet, QObject* parent = NULL);
122 
123   /**
124    * Get the Icon Manager
125    *
126    * @return The icon manager singleton
127    */
instance()128   static IconManager* instance()
129   { return myInstance; }
130 
131   /**
132    * Load a set of icons
133    *
134    * @param iconSet Name of icon set
135    * @return True if icon set was found and index files could be read
136    */
137   bool loadIcons(const QString& iconSet);
138 
139   /**
140    * Load a set of extended icons
141    *
142    * @param iconSet Name of extended icon set
143    * @return True if icon set was found and index files could be read
144    */
145   bool loadExtendedIcons(const QString& iconSet);
146 
147   /**
148    * Get an icon
149    *
150    * @param icon The icon type to get
151    * @return The requested icon if loaded, otherwise a null pixmap
152    */
153   const QPixmap& getIcon(IconType icon);
154 
155   /**
156    * Get icon for a protocol status
157    *
158    * @param status Status to get icon for
159    * @param userId Contact id, used to get protocol to get icon for
160    * @param allowInvisible True to allow invisible regardles if extended icons are used
161    * @return The requested icon if loaded, otherwise a null pixmap
162    */
163   const QPixmap& iconForStatus(unsigned status, const Licq::UserId& userId = Licq::UserId(),
164       bool allowInvisible = false);
165 
166   /**
167    * Get icon for a protocol
168    * Note: Will always return ICQ icon for oscar protocol, never AIM
169    *
170    * @param protocolId Protocol to get icon for
171    * @param status Status to get icon for
172    * @return Status icon for the requested protocol
173    */
174   const QPixmap& iconForProtocol(unsigned long protocolId, unsigned status = Licq::User::OnlineStatus);
175 
176   /**
177    * Get icon for a user
178    *
179    * @param user An already locked object of LicqUser type
180    * @return The requested icon if loaded, otherwise a null pixmap
181    */
iconForUser(const Licq::User * user)182   const QPixmap& iconForUser(const Licq::User* user)
183   { return iconForStatus(user->status(), user->id()); }
184 
185   /**
186    * Get icon for an event type
187    *
188    * @param eventType Type of event to get message for
189    * @return The requested icon if loaded, otherwise a null pixmap
190    */
191   const QPixmap& iconForEvent(unsigned eventType);
192 
iconSet()193   const QString& iconSet() const { return myIconSet; }
extendedIconSet()194   const QString& extendedIconSet() const { return myExtendedIconSet; }
195 
196 signals:
197   /**
198    * The icon set has changed, emitted for all icon sets
199    */
200   void iconsChanged();
201 
202   /**
203    * The general icons has changed
204    */
205   void generalIconsChanged();
206 
207   /**
208    * The status icons has changed
209    */
210   void statusIconsChanged();
211 
212   /**
213    * The extended icons has changed
214    */
215   void extendedIconsChanged();
216 
217 
218 private:
219   // Singleton instance
220   static IconManager* myInstance;
221 
222   /**
223    * Constructor, private so only createInstance() can call it
224    *
225    * @param iconSet Initial icon set to load
226    * @param extendedIconSet Initial extended icon set to load
227    * @param parent Parent object
228    */
229   IconManager(const QString& iconSet, const QString& extendedIconSet, QObject* parent = NULL);
230 
231   /**
232    * Destructor
233    */
~IconManager()234   virtual ~IconManager() {}
235 
236   const QPixmap& iconForProtocol(unsigned status, ProtocolType protocol, bool allowInvisible);
237 
238   QString myIconSet;
239   QString myExtendedIconSet;
240 
241   // Map of current icons
242   QMap<IconType, QPixmap> myIconMap;
243 
244   // Map of status icons for different protocols
245   QMap<QPair<ProtocolType, unsigned>, QPixmap> myStatusIconMap;
246 
247   // Null icon that can be returned as default
248   QPixmap myEmptyIcon;
249 };
250 
251 } // namespace LicqQtGui
252 
253 #endif
254