Real fix for Coverity 1372362.
[claws.git] / src / plugins / notification / notification_pixbuf.c
1 /* Notification plugin for Claws-Mail
2  * Copyright (C) 2005-2007 Holger Berndt
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17
18 #include "notification_pixbuf.h"
19 #include "common/utils.h"
20 #include "stock_pixmap.h"
21
22 static GdkPixbuf* notification_pixbuf[NOTIFICATION_PIXBUF_LAST];
23
24 GdkPixbuf* notification_pixbuf_get(NotificationPixbuf wanted)
25 {
26   if(!notification_pixbuf[wanted]) {
27     switch(wanted) {
28     case NOTIFICATION_CM_LOGO_64x64:
29                         stock_pixbuf_gdk(STOCK_PIXMAP_CLAWS_MAIL_ICON_64, &(notification_pixbuf[wanted]));
30       g_object_ref(notification_pixbuf[wanted]);
31       break;
32     case NOTIFICATION_TRAYICON_NEWMAIL:
33                         stock_pixbuf_gdk(STOCK_PIXMAP_TRAY_NEWMAIL, &(notification_pixbuf[wanted]));
34       g_object_ref(notification_pixbuf[wanted]);
35       break;
36     case NOTIFICATION_TRAYICON_NEWMAIL_OFFLINE:
37                         stock_pixbuf_gdk(STOCK_PIXMAP_TRAY_NEWMAIL_OFFLINE, &(notification_pixbuf[wanted]));
38       g_object_ref(notification_pixbuf[wanted]);
39       break;
40     case NOTIFICATION_TRAYICON_NEWMARKEDMAIL:
41                         stock_pixbuf_gdk(STOCK_PIXMAP_TRAY_NEWMARKEDMAIL, &(notification_pixbuf[wanted]));
42       g_object_ref(notification_pixbuf[wanted]);
43       break;
44     case NOTIFICATION_TRAYICON_NEWMARKEDMAIL_OFFLINE:
45                         stock_pixbuf_gdk(STOCK_PIXMAP_TRAY_NEWMARKEDMAIL_OFFLINE, &(notification_pixbuf[wanted]));
46       g_object_ref(notification_pixbuf[wanted]);
47       break;
48     case NOTIFICATION_TRAYICON_NOMAIL:
49                         stock_pixbuf_gdk(STOCK_PIXMAP_TRAY_NOMAIL, &(notification_pixbuf[wanted]));
50       g_object_ref(notification_pixbuf[wanted]);
51       break;
52     case NOTIFICATION_TRAYICON_NOMAIL_OFFLINE:
53                         stock_pixbuf_gdk(STOCK_PIXMAP_TRAY_NOMAIL_OFFLINE, &(notification_pixbuf[wanted]));
54       g_object_ref(notification_pixbuf[wanted]);
55       break;
56     case NOTIFICATION_TRAYICON_UNREADMAIL:
57                         stock_pixbuf_gdk(STOCK_PIXMAP_TRAY_UNREADMAIL, &(notification_pixbuf[wanted]));
58       g_object_ref(notification_pixbuf[wanted]);
59       break;
60     case NOTIFICATION_TRAYICON_UNREADMAIL_OFFLINE:
61                         stock_pixbuf_gdk(STOCK_PIXMAP_TRAY_UNREADMAIL_OFFLINE, &(notification_pixbuf[wanted]));
62       g_object_ref(notification_pixbuf[wanted]);
63       break;
64     case NOTIFICATION_TRAYICON_UNREADMARKEDMAIL:
65                         stock_pixbuf_gdk(STOCK_PIXMAP_TRAY_UNREADMARKEDMAIL, &(notification_pixbuf[wanted]));
66       g_object_ref(notification_pixbuf[wanted]);
67       break;
68     case NOTIFICATION_TRAYICON_UNREADMARKEDMAIL_OFFLINE:
69                         stock_pixbuf_gdk(STOCK_PIXMAP_TRAY_UNREADMARKEDMAIL_OFFLINE, &(notification_pixbuf[wanted]));
70       g_object_ref(notification_pixbuf[wanted]);
71       break;
72     case NOTIFICATION_PIXBUF_LAST:
73       break;
74     }
75   }
76   cm_return_val_if_fail(wanted < NOTIFICATION_PIXBUF_LAST, NULL);
77   return notification_pixbuf[wanted];
78 }
79
80 void notification_pixbuf_free_all(void)
81 {
82   gint ii;
83
84   for(ii = NOTIFICATION_CM_LOGO_64x64; ii < NOTIFICATION_PIXBUF_LAST; ii++) {
85     if(notification_pixbuf[ii]) {
86       g_object_unref(notification_pixbuf[ii]);
87       notification_pixbuf[ii] = NULL;
88     }
89   }
90 }