Refernce bug
[claws.git] / src / stock_pixmap.c
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2011 Hiroyuki Yamamoto and the Claws Mail team
4  *
5  * This program 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 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
17  * 
18  */
19
20 #include "defs.h"
21 #include <glib.h>
22 #include <gtk/gtk.h>
23 #include <string.h>
24 #include <dirent.h>
25
26 #include "stock_pixmap.h"
27 #include "gtkutils.h"
28 #include "utils.h"
29 #include "prefs_common.h"
30
31 #include "pixmaps/addr_one.xpm"
32 #include "pixmaps/addr_two.xpm"
33 #include "pixmaps/address.xpm"
34 #include "pixmaps/anonymous.xpm"
35 #include "pixmaps/book.xpm"
36 #include "pixmaps/category.xpm"
37 #include "pixmaps/checkbox_off.xpm"
38 #include "pixmaps/checkbox_on.xpm"
39 #include "pixmaps/clip.xpm"
40 #include "pixmaps/clipkey.xpm"
41 #include "pixmaps/complete.xpm"
42 #include "pixmaps/continue.xpm"
43 #include "pixmaps/deleted.xpm"
44 #include "pixmaps/error.xpm"
45 #include "pixmaps/edit_extern.xpm"
46 #include "pixmaps/forwarded.xpm"
47 #include "pixmaps/group.xpm"
48 #include "pixmaps/insert_file.xpm"
49 #include "pixmaps/interface.xpm"
50 #include "pixmaps/jpilot.xpm"
51 #include "pixmaps/key.xpm"
52 #include "pixmaps/key_gpg_signed.xpm"
53 #include "pixmaps/ldap.xpm"
54 #include "pixmaps/linewrap.xpm"
55 #include "pixmaps/linewrapcurrent.xpm"
56 #include "pixmaps/mark.xpm"
57 #include "pixmaps/locked.xpm"
58 #include "pixmaps/new.xpm"
59 #include "pixmaps/replied.xpm"
60 #include "pixmaps/close.xpm"
61 #include "pixmaps/down_arrow.xpm"
62 #include "pixmaps/up_arrow.xpm"
63 #include "pixmaps/exec.xpm"
64 #include "pixmaps/mail.xpm"
65 #include "pixmaps/mail_attach.xpm"
66 #include "pixmaps/mail_compose.xpm"
67 #include "pixmaps/mail_forward.xpm"
68 #include "pixmaps/mail_receive.xpm"
69 #include "pixmaps/mail_receive_all.xpm"
70 #include "pixmaps/mail_reply.xpm"
71 #include "pixmaps/mail_reply_to_all.xpm"
72 #include "pixmaps/mail_reply_to_author.xpm"
73 #include "pixmaps/mail_reply_to_list.xpm"
74 #include "pixmaps/mail_send.xpm"
75 #include "pixmaps/mail_send_queue.xpm"
76 #include "pixmaps/mail_sign.xpm"
77 #include "pixmaps/open_mail.xpm"
78 #include "pixmaps/news_compose.xpm"
79 #include "pixmaps/paste.xpm"
80 #include "pixmaps/preferences.xpm"
81 #include "pixmaps/properties.xpm"
82 #include "pixmaps/queue_close.xpm"
83 #include "pixmaps/queue_close_hrm.xpm"
84 #include "pixmaps/queue_open.xpm"
85 #include "pixmaps/queue_open_hrm.xpm"
86 #include "pixmaps/claws-mail_icon.xpm"
87 #ifndef GENERIC_UMPC
88 #include "pixmaps/claws-mail_logo.xpm"
89 #else
90 #include "pixmaps/claws-mail_logo-small.xpm"
91 #endif
92 #include "pixmaps/address_book.xpm"
93 #include "pixmaps/unread.xpm"
94 #include "pixmaps/read.xpm"
95 #include "pixmaps/vcard.xpm"
96 #include "pixmaps/ignorethread.xpm"
97 #include "pixmaps/online.xpm"
98 #include "pixmaps/offline.xpm"
99 #include "pixmaps/notice_warn.xpm"
100 #include "pixmaps/notice_error.xpm"
101 #include "pixmaps/notice_note.xpm"
102 #include "pixmaps/quicksearch.xpm"
103 #include "pixmaps/clip_gpg_signed.xpm"
104 #include "pixmaps/gpg_signed.xpm"
105 #include "pixmaps/go_folders.xpm"
106 #include "pixmaps/mime_text_plain.xpm"
107 #include "pixmaps/mime_text_html.xpm"
108 #include "pixmaps/mime_text_patch.xpm"
109 #include "pixmaps/mime_application.xpm"
110 #include "pixmaps/mime_image.xpm"
111 #include "pixmaps/mime_audio.xpm"
112 #include "pixmaps/mime_text_enriched.xpm"
113 #include "pixmaps/mime_unknown.xpm"
114 #include "pixmaps/mime_pdf.xpm"
115 #include "pixmaps/mime_ps.xpm"
116 #include "pixmaps/mime_calendar.xpm"
117 #include "pixmaps/mime_pgpsig.xpm"
118 #include "pixmaps/printer.xpm"
119 #include "pixmaps/privacy_signed.xpm"
120 #include "pixmaps/privacy_passed.xpm"
121 #include "pixmaps/privacy_failed.xpm"
122 #include "pixmaps/privacy_unknown.xpm"
123 #include "pixmaps/privacy_expired.xpm"
124 #include "pixmaps/privacy_warn.xpm"                 
125 #include "pixmaps/privacy_emblem_encrypted.xpm"
126 #include "pixmaps/privacy_emblem_signed.xpm"
127 #include "pixmaps/privacy_emblem_passed.xpm"
128 #include "pixmaps/privacy_emblem_failed.xpm"
129 #include "pixmaps/privacy_emblem_warn.xpm"
130 #include "pixmaps/mime_message.xpm"                  
131 #include "pixmaps/address_search.xpm"
132 #include "pixmaps/check_spelling.xpm"
133
134 #include "pixmaps/dir_close.xpm"
135 #include "pixmaps/dir_close_hrm.xpm"
136 #include "pixmaps/dir_open.xpm"
137 #include "pixmaps/dir_open_hrm.xpm"
138 #include "pixmaps/inbox_open.xpm"
139 #include "pixmaps/inbox_open_hrm.xpm"
140 #include "pixmaps/inbox_close.xpm"
141 #include "pixmaps/inbox_close_hrm.xpm"
142 #include "pixmaps/outbox_open.xpm"
143 #include "pixmaps/outbox_open_hrm.xpm"
144 #include "pixmaps/outbox_close.xpm"
145 #include "pixmaps/outbox_close_hrm.xpm"
146 #include "pixmaps/trash.xpm"
147 #include "pixmaps/delete_btn.xpm"
148 #include "pixmaps/cancel.xpm"
149 #include "pixmaps/trash_btn.xpm"
150 #include "pixmaps/trash_hrm.xpm"
151 #include "pixmaps/drafts_close.xpm"
152 #include "pixmaps/drafts_open.xpm"
153 #include "pixmaps/dir_close_mark.xpm"
154 #include "pixmaps/dir_close_hrm_mark.xpm"
155 #include "pixmaps/dir_open_mark.xpm"
156 #include "pixmaps/dir_open_hrm_mark.xpm"
157 #include "pixmaps/inbox_open_mark.xpm"
158 #include "pixmaps/inbox_open_hrm_mark.xpm"
159 #include "pixmaps/inbox_close_mark.xpm"
160 #include "pixmaps/inbox_close_hrm_mark.xpm"
161 #include "pixmaps/outbox_open_mark.xpm"
162 #include "pixmaps/outbox_open_hrm_mark.xpm"
163 #include "pixmaps/outbox_close_mark.xpm"
164 #include "pixmaps/outbox_close_hrm_mark.xpm"
165 #include "pixmaps/trash_mark.xpm"
166 #include "pixmaps/queue_close_mark.xpm"
167 #include "pixmaps/queue_close_hrm_mark.xpm"
168 #include "pixmaps/queue_open_mark.xpm"
169 #include "pixmaps/queue_open_hrm_mark.xpm"
170 #include "pixmaps/trash_hrm_mark.xpm"
171 #include "pixmaps/drafts_close_mark.xpm"
172 #include "pixmaps/drafts_open_mark.xpm"
173 #include "pixmaps/dir_noselect.xpm"
174 #include "pixmaps/spam.xpm"
175 #include "pixmaps/spam_btn.xpm"
176 #include "pixmaps/ham_btn.xpm"
177 #include "pixmaps/moved.xpm"
178 #include "pixmaps/copied.xpm"
179 #include "pixmaps/selection.xpm"
180 #include "pixmaps/watchthread.xpm"
181 #include "pixmaps/empty.xpm"
182 #include "pixmaps/tray_newmail.offline.xpm"
183 #include "pixmaps/tray_newmail.xpm"
184 #include "pixmaps/tray_newmarkedmail.offline.xpm"
185 #include "pixmaps/tray_newmarkedmail.xpm"
186 #include "pixmaps/tray_nomail.offline.xpm"
187 #include "pixmaps/tray_nomail.xpm"
188 #include "pixmaps/tray_unreadmail.offline.xpm"
189 #include "pixmaps/tray_unreadmail.xpm"
190 #include "pixmaps/tray_unreadmarkedmail.offline.xpm"
191 #include "pixmaps/tray_unreadmarkedmail.xpm"
192
193 typedef struct _StockPixmapData StockPixmapData;
194
195 struct _StockPixmapData
196 {
197         gchar **data;
198         cairo_surface_t *pixmap;
199         cairo_pattern_t *mask;
200         gchar *file;
201         gchar *icon_path;
202         GdkPixbuf *pixbuf;
203 };
204
205 typedef struct _OverlayData OverlayData;
206
207 struct _OverlayData
208 {
209         gboolean is_pixmap;
210         cairo_surface_t *base_pixmap;
211         cairo_surface_t *overlay_pixmap;
212         
213         GdkPixbuf *base_pixbuf;
214         GdkPixbuf *overlay_pixbuf;
215         
216         guint base_height;
217         guint base_width;
218         guint overlay_height;
219         guint overlay_width;
220         OverlayPosition position;
221         gint border_x;
222         gint border_y;
223         gboolean highlight;
224 };
225
226 static void stock_pixmap_find_themes_in_dir(GList **list, const gchar *dirname);
227
228 static StockPixmapData pixmaps[] =
229 {
230         {addr_one_xpm                           , NULL, NULL, "addr_one", NULL},
231         {addr_two_xpm                           , NULL, NULL, "addr_two", NULL},
232         {address_xpm                            , NULL, NULL, "address", NULL},
233         {address_book_xpm                       , NULL, NULL, "address_book", NULL},
234         {address_search_xpm                     , NULL, NULL, "address_search", NULL},
235         {anonymous_xpm                          , NULL, NULL, "anonymous", NULL},
236         {book_xpm                               , NULL, NULL, "book", NULL},
237         {category_xpm                           , NULL, NULL, "category", NULL},
238         {checkbox_off_xpm                       , NULL, NULL, "checkbox_off", NULL},
239         {checkbox_on_xpm                        , NULL, NULL, "checkbox_on", NULL},
240         {check_spelling_xpm                     , NULL, NULL, "check_spelling", NULL},
241         {clip_xpm                               , NULL, NULL, "clip", NULL},
242         {clipkey_xpm                            , NULL, NULL, "clipkey", NULL},
243         {clip_gpg_signed_xpm                    , NULL, NULL, "clip_gpg_signed", NULL},
244         {close_xpm                              , NULL, NULL, "close", NULL},
245         {complete_xpm                           , NULL, NULL, "complete", NULL},
246         {continue_xpm                           , NULL, NULL, "continue", NULL},
247         {deleted_xpm                            , NULL, NULL, "deleted", NULL},
248         {dir_close_xpm                          , NULL, NULL, "dir_close", NULL},
249         {dir_close_hrm_xpm                      , NULL, NULL, "dir_close_hrm", NULL},
250         {dir_open_xpm                           , NULL, NULL, "dir_open", NULL},
251         {dir_open_hrm_xpm                       , NULL, NULL, "dir_open_hrm", NULL},
252         {dir_close_mark_xpm                     , NULL, NULL, "dir_close_mark", NULL},
253         {dir_close_hrm_mark_xpm                 , NULL, NULL, "dir_close_hrm_mark", NULL},
254         {dir_open_mark_xpm                      , NULL, NULL, "dir_open_mark", NULL},
255         {dir_open_hrm_mark_xpm                  , NULL, NULL, "dir_open_hrm_mark", NULL},
256         {down_arrow_xpm                         , NULL, NULL, "down_arrow", NULL},
257         {up_arrow_xpm                           , NULL, NULL, "up_arrow", NULL},
258         {edit_extern_xpm                        , NULL, NULL, "edit_extern", NULL},
259         {error_xpm                              , NULL, NULL, "error", NULL},
260         {exec_xpm                               , NULL, NULL, "exec", NULL},
261         {forwarded_xpm                          , NULL, NULL, "forwarded", NULL},
262         {group_xpm                              , NULL, NULL, "group", NULL},
263         {ignorethread_xpm                       , NULL, NULL, "ignorethread", NULL},
264         {inbox_close_xpm                        , NULL, NULL, "inbox_close", NULL},
265         {inbox_close_hrm_xpm                    , NULL, NULL, "inbox_close_hrm", NULL},
266         {inbox_open_xpm                         , NULL, NULL, "inbox_open", NULL},
267         {inbox_open_hrm_xpm                     , NULL, NULL, "inbox_open_hrm", NULL},
268         {inbox_close_mark_xpm                   , NULL, NULL, "inbox_close_mark", NULL},
269         {inbox_close_hrm_mark_xpm               , NULL, NULL, "inbox_close_hrm_mark", NULL},
270         {inbox_open_mark_xpm                    , NULL, NULL, "inbox_open_mark", NULL},
271         {inbox_open_hrm_mark_xpm                , NULL, NULL, "inbox_open_hrm_mark", NULL},
272         {insert_file_xpm                        , NULL, NULL, "insert_file", NULL},
273         {interface_xpm                          , NULL, NULL, "interface", NULL},
274         {jpilot_xpm                             , NULL, NULL, "jpilot", NULL},
275         {key_xpm                                , NULL, NULL, "key", NULL},
276         {key_gpg_signed_xpm                     , NULL, NULL, "key_gpg_signed_xpm", NULL},
277         {ldap_xpm                               , NULL, NULL, "ldap", NULL},
278         {linewrapcurrent_xpm                    , NULL, NULL, "linewrapcurrent", NULL},
279         {linewrap_xpm                           , NULL, NULL, "linewrap", NULL},
280         {locked_xpm                             , NULL, NULL, "locked", NULL},
281         {mail_xpm                               , NULL, NULL, "mail", NULL},
282         {mail_attach_xpm                        , NULL, NULL, "mail_attach", NULL},
283         {mail_compose_xpm                       , NULL, NULL, "mail_compose", NULL},
284         {mail_forward_xpm                       , NULL, NULL, "mail_forward", NULL},
285         {mail_receive_xpm                       , NULL, NULL, "mail_receive", NULL},
286         {mail_receive_all_xpm                   , NULL, NULL, "mail_receive_all", NULL},
287         {mail_reply_xpm                         , NULL, NULL, "mail_reply", NULL},
288         {mail_reply_to_all_xpm                  , NULL, NULL, "mail_reply_to_all", NULL},
289         {mail_reply_to_author_xpm               , NULL, NULL, "mail_reply_to_author", NULL},
290         {mail_reply_to_list_xpm                 , NULL, NULL, "mail_reply_to_list", NULL},
291         {mail_send_xpm                          , NULL, NULL, "mail_send", NULL},
292         {mail_send_queue_xpm                    , NULL, NULL, "mail_send_queue", NULL},
293         {mail_sign_xpm                          , NULL, NULL, "mail_sign", NULL},
294         {open_mail_xpm                          , NULL, NULL, "open_mail", NULL},
295         {mark_xpm                               , NULL, NULL, "mark", NULL},
296         {new_xpm                                , NULL, NULL, "new", NULL},
297         {news_compose_xpm                       , NULL, NULL, "news_compose", NULL},
298         {outbox_close_xpm                       , NULL, NULL, "outbox_close", NULL},
299         {outbox_close_hrm_xpm                   , NULL, NULL, "outbox_close_hrm", NULL},
300         {outbox_open_xpm                        , NULL, NULL, "outbox_open", NULL},
301         {outbox_open_hrm_xpm                    , NULL, NULL, "outbox_open_hrm", NULL},
302         {outbox_close_mark_xpm                  , NULL, NULL, "outbox_close_mark", NULL},
303         {outbox_close_hrm_mark_xpm              , NULL, NULL, "outbox_close_hrm_mark", NULL},
304         {outbox_open_mark_xpm                   , NULL, NULL, "outbox_open_mark", NULL},
305         {outbox_open_hrm_mark_xpm               , NULL, NULL, "outbox_open_hrm_mark", NULL},
306         {replied_xpm                            , NULL, NULL, "replied", NULL},
307         {paste_xpm                              , NULL, NULL, "paste", NULL},
308         {preferences_xpm                        , NULL, NULL, "preferences", NULL},
309         {properties_xpm                         , NULL, NULL, "properties", NULL},
310         {queue_close_xpm                        , NULL, NULL, "queue_close", NULL},
311         {queue_close_hrm_xpm                    , NULL, NULL, "queue_close_hrm", NULL},
312         {queue_open_xpm                         , NULL, NULL, "queue_open", NULL},
313         {queue_open_hrm_xpm                     , NULL, NULL, "queue_open_hrm", NULL},
314         {trash_xpm                              , NULL, NULL, "trash_open", NULL},
315         {trash_hrm_xpm                          , NULL, NULL, "trash_open_hrm", NULL},
316         {trash_xpm                              , NULL, NULL, "trash_close", NULL},
317         {trash_hrm_xpm                          , NULL, NULL, "trash_close_hrm", NULL},
318         {queue_close_mark_xpm                   , NULL, NULL, "queue_close_mark", NULL},
319         {queue_close_hrm_mark_xpm               , NULL, NULL, "queue_close_hrm_mark", NULL},
320         {queue_open_mark_xpm                    , NULL, NULL, "queue_open_mark", NULL},
321         {queue_open_hrm_mark_xpm                , NULL, NULL, "queue_open_hrm_mark", NULL},
322         {trash_mark_xpm                         , NULL, NULL, "trash_open_mark", NULL},
323         {trash_hrm_mark_xpm                     , NULL, NULL, "trash_open_hrm_mark", NULL},
324         {trash_mark_xpm                         , NULL, NULL, "trash_close_mark", NULL},
325         {trash_hrm_mark_xpm                     , NULL, NULL, "trash_close_hrm_mark", NULL},
326         {unread_xpm                             , NULL, NULL, "unread", NULL},
327         {vcard_xpm                              , NULL, NULL, "vcard", NULL},
328         {online_xpm                             , NULL, NULL, "online", NULL},
329         {offline_xpm                            , NULL, NULL, "offline", NULL},
330         {notice_warn_xpm                        , NULL, NULL, "notice_warn",  NULL},
331         {notice_error_xpm                       , NULL, NULL, "notice_error",  NULL},
332         {notice_note_xpm                        , NULL, NULL, "notice_note",  NULL},
333         {quicksearch_xpm                        , NULL, NULL, "quicksearch",  NULL},
334         {gpg_signed_xpm                         , NULL, NULL, "gpg_signed", NULL},
335         {go_folders_xpm                         , NULL, NULL, "go_folders", NULL},
336         {drafts_close_xpm                       , NULL, NULL, "drafts_close", NULL},
337         {drafts_open_xpm                        , NULL, NULL, "drafts_open", NULL},
338         {drafts_close_mark_xpm                  , NULL, NULL, "drafts_close_mark", NULL},
339         {drafts_open_mark_xpm                   , NULL, NULL, "drafts_open_mark", NULL},
340         {mime_text_plain_xpm                    , NULL, NULL, "mime_text_plain", NULL},
341         {mime_text_html_xpm                     , NULL, NULL, "mime_text_html", NULL},
342         {mime_text_patch_xpm                    , NULL, NULL, "mime_text_patch", NULL},
343         {mime_application_xpm                   , NULL, NULL, "mime_application", NULL},
344         {mime_image_xpm                         , NULL, NULL, "mime_image", NULL},
345         {mime_audio_xpm                         , NULL, NULL, "mime_audio", NULL},
346         {mime_text_enriched_xpm                 , NULL, NULL, "mime_text_enriched", NULL},
347         {mime_unknown_xpm                       , NULL, NULL, "mime_unknown", NULL},    
348         {mime_pdf_xpm                           , NULL, NULL, "mime_pdf", NULL},        
349         {mime_ps_xpm                            , NULL, NULL, "mime_ps", NULL}, 
350         {mime_calendar_xpm                      , NULL, NULL, "mime_calendar", NULL},   
351         {mime_pgpsig_xpm                        , NULL, NULL, "mime_pgpsig", NULL},     
352         {printer_xpm                            , NULL, NULL, "printer", NULL},
353         {privacy_signed_xpm                     , NULL, NULL, "privacy_signed", NULL},
354         {privacy_passed_xpm                     , NULL, NULL, "privacy_passed", NULL},
355         {privacy_failed_xpm                     , NULL, NULL, "privacy_failed", NULL},  
356         {privacy_unknown_xpm                    , NULL, NULL, "privacy_unknown", NULL},
357         {privacy_expired_xpm                    , NULL, NULL, "privacy_expired", NULL},
358         {privacy_warn_xpm                       , NULL, NULL, "privacy_warn", NULL},
359         {privacy_emblem_encrypted_xpm           , NULL, NULL, "privacy_emblem_encrypted", NULL},
360         {privacy_emblem_signed_xpm              , NULL, NULL, "privacy_emblem_signed", NULL},
361         {privacy_emblem_passed_xpm              , NULL, NULL, "privacy_emblem_passed", NULL},
362         {privacy_emblem_failed_xpm              , NULL, NULL, "privacy_emblem_failed", NULL},   
363         {privacy_emblem_warn_xpm                , NULL, NULL, "privacy_emblem_warn", NULL},
364         {mime_message_xpm                       , NULL, NULL, "mime_message", NULL},
365         {claws_mail_icon_xpm                    , NULL, NULL, "claws_mail_icon", NULL},
366         {read_xpm                               , NULL, NULL, "read", NULL},
367         {delete_btn_xpm                         , NULL, NULL, "delete_btn", NULL},
368         {cancel_xpm                             , NULL, NULL, "cancel", NULL},
369         {trash_btn_xpm                          , NULL, NULL, "trash_btn", NULL},
370 #ifndef GENERIC_UMPC
371         {claws_mail_logo_xpm                    , NULL, NULL, "claws_mail_logo", NULL},
372 #else
373         {claws_mail_logo_small_xpm              , NULL, NULL, "claws_mail_logo_small", NULL},
374 #endif
375         {dir_noselect_xpm                       , NULL, NULL, "dir_noselect" , NULL},
376         {spam_xpm                               , NULL, NULL, "spam" , NULL},
377         {spam_btn_xpm                           , NULL, NULL, "spam_btn" , NULL},
378         {ham_btn_xpm                            , NULL, NULL, "ham_btn" , NULL},
379         {moved_xpm                              , NULL, NULL, "moved", NULL},
380         {copied_xpm                             , NULL, NULL, "copied", NULL},
381         {selection_xpm                          , NULL, NULL, "selection", NULL},
382         {watchthread_xpm                        , NULL, NULL, "watchthread", NULL},
383         {tray_newmail_offline_xpm               , NULL, NULL, "tray_newmail.offline", NULL},
384         {tray_newmail_xpm                       , NULL, NULL, "tray_newmail", NULL},
385         {tray_newmarkedmail_offline_xpm         , NULL, NULL, "tray_newmarkedmail.offline", NULL},
386         {tray_newmarkedmail_xpm                 , NULL, NULL, "tray_newmarkedmail", NULL},
387         {tray_nomail_offline_xpm                , NULL, NULL, "tray_nomail.offline", NULL},
388         {tray_nomail_xpm                        , NULL, NULL, "tray_nomail", NULL},
389         {tray_unreadmail_offline_xpm            , NULL, NULL, "tray_unreadmail.offline", NULL},
390         {tray_unreadmail_xpm                    , NULL, NULL, "tray_unreadmail", NULL},
391         {tray_unreadmarkedmail_offline_xpm      , NULL, NULL, "tray_unreadmarkedmail.offline", NULL},
392         {tray_unreadmarkedmail_xpm              , NULL, NULL, "tray_unreadmarkedmail", NULL},
393         {empty_xpm                              , NULL, NULL, "empty" , NULL}
394 };
395
396 /* return newly constructed GtkPixmap from GdkPixmap */
397 GtkWidget *stock_pixmap_widget(GtkWidget *window, StockPixmap icon)
398 {
399         GdkPixbuf *pixbuf;
400
401         cm_return_val_if_fail(window != NULL, NULL);
402         cm_return_val_if_fail(icon >= 0 && icon < N_STOCK_PIXMAPS, NULL);
403
404         if (stock_pixbuf_gdk(window, icon, &pixbuf) != -1)
405                 return gtk_image_new_from_pixbuf(pixbuf);
406         
407         return NULL;
408 }
409
410 /*!
411  *\brief        
412  */
413 gint stock_pixbuf_gdk(GtkWidget *window, StockPixmap icon, GdkPixbuf **pixbuf)
414 {
415         StockPixmapData *pix_d;
416         static const char *extension[]={".png", ".xpm", NULL};
417         int i = 0;
418         gboolean theme_changed = FALSE;
419
420         if (pixbuf)
421                 *pixbuf = NULL;
422                 
423         cm_return_val_if_fail(icon >= 0 && icon < N_STOCK_PIXMAPS, -1);
424
425         pix_d = &pixmaps[icon];
426
427         theme_changed = (strcmp2(pix_d->icon_path, prefs_common.pixmap_theme_path) != 0);
428         if (!pix_d->pixbuf || theme_changed) {
429                 GdkPixbuf *pix = NULL;
430                 
431                 if (theme_changed && pix_d->pixmap) {
432                         g_object_unref(pix_d->pixmap);
433                         pix_d->pixmap = NULL;
434                 }
435
436                 if (strcmp(prefs_common.pixmap_theme_path, DEFAULT_PIXMAP_THEME) != 0) {
437                         if (is_dir_exist(prefs_common.pixmap_theme_path)) {
438                                 char *icon_file_name; 
439 try_next_extension:                             
440                                 icon_file_name = g_strconcat(prefs_common.pixmap_theme_path,
441                                                              G_DIR_SEPARATOR_S,
442                                                              pix_d->file,
443                                                              extension[i],
444                                                              NULL);
445                                 if (is_file_exist(icon_file_name)) {
446                                         GError *err = NULL;
447                                         pix = gdk_pixbuf_new_from_file(icon_file_name, &err);   
448                                         if (err) g_error_free(err);
449                                 }                                       
450                                 if (pix) {
451                                         g_free(pix_d->icon_path);
452                                         pix_d->icon_path = g_strdup(prefs_common.pixmap_theme_path);
453                                 }
454                                 g_free(icon_file_name);
455                                 if (!pix) {
456                                         i++;
457                                         if (extension[i])
458                                                 goto try_next_extension;
459                                 }
460                         } else {
461                                 /* even the path does not exist (deleted between two sessions), so
462                                 set the preferences to the internal theme */
463                                 prefs_common.pixmap_theme_path = g_strdup(DEFAULT_PIXMAP_THEME);
464                         }
465                 }
466                 pix_d->pixbuf = pix;
467         }
468
469         if (!pix_d->pixbuf) {
470                 pix_d->pixbuf = gdk_pixbuf_new_from_xpm_data((const gchar **) pix_d->data);
471                 if (pix_d->pixbuf) {
472                         g_free(pix_d->icon_path);
473                         pix_d->icon_path = g_strdup(DEFAULT_PIXMAP_THEME);      
474                 }
475         }
476
477         cm_return_val_if_fail(pix_d->pixbuf != NULL, -1);
478
479         if (pixbuf)
480                 *pixbuf = pix_d->pixbuf;
481
482         /* pixbuf should have one ref outstanding */            
483
484         return 0;
485 }
486
487 static void stock_pixmap_find_themes_in_dir(GList **list, const gchar *dirname)
488 {
489         struct dirent *d;
490         DIR *dp;
491         static const char *extension[]={".png", ".xpm", NULL};
492         
493         if ((dp = opendir(dirname)) == NULL) {
494                 debug_print("dir %s not found, skipping theme scan", dirname?dirname:"(null)");
495                 return;
496         }
497         
498         while ((d = readdir(dp)) != NULL) {
499                 gchar *entry;
500                 gchar *fullentry;
501
502                 entry     = d->d_name;
503                 fullentry = g_strconcat(dirname, G_DIR_SEPARATOR_S, entry, NULL);
504                 
505                 if (strcmp(entry, ".") != 0 && strcmp(entry, "..") != 0 && is_dir_exist(fullentry)) {
506                         gchar *filetoexist;
507                         gboolean found = FALSE;
508                         int i;
509                         int j;
510                         for (i = 0; i < N_STOCK_PIXMAPS && !found; i++) {
511                                 for (j = 0; extension[j] && !found; j++) {
512                                         filetoexist = g_strconcat(fullentry, G_DIR_SEPARATOR_S, pixmaps[i].file, extension[j], NULL);
513                                         if (is_file_exist(filetoexist)) {
514                                                 *list = g_list_append(*list, fullentry);
515                                                 found = TRUE;
516                                         }
517                                         g_free(filetoexist);
518                                 }
519                         }
520                         if (i == N_STOCK_PIXMAPS) 
521                                 g_free(fullentry);
522                 } else 
523                         g_free(fullentry);
524         }
525         closedir(dp);
526 }
527
528 gchar *stock_pixmap_get_system_theme_dir_for_theme(const gchar *theme)
529 {
530         const gchar *sep = NULL;
531         if (theme && *theme)
532                 sep = G_DIR_SEPARATOR_S;
533 #ifndef G_OS_WIN32
534         return g_strconcat(PACKAGE_DATA_DIR, G_DIR_SEPARATOR_S,
535                            PIXMAP_THEME_DIR, sep, theme, NULL);
536 #else
537         return g_strconcat(get_themes_dir(), sep, theme, NULL);
538 #endif
539 }
540
541 GList *stock_pixmap_themes_list_new(void)
542 {
543         gchar *defaulttheme;
544         gchar *userthemes;
545         gchar *systemthemes;
546         GList *list = NULL;
547         
548         defaulttheme = g_strdup(DEFAULT_PIXMAP_THEME);
549         userthemes   = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, 
550                                    PIXMAP_THEME_DIR, NULL);
551         systemthemes = stock_pixmap_get_system_theme_dir_for_theme(NULL);
552
553         list = g_list_append(list, defaulttheme);
554         stock_pixmap_find_themes_in_dir(&list, userthemes);
555         stock_pixmap_find_themes_in_dir(&list, systemthemes);
556
557         g_free(userthemes);
558         g_free(systemthemes);
559         return list;
560 }
561
562 void stock_pixmap_themes_list_free(GList *list)
563 {
564         GList *ptr;
565
566         for (ptr = g_list_first(list); ptr != NULL; ptr = g_list_next(ptr)) 
567                 g_free(ptr->data);
568         g_list_free(list);              
569 }
570
571 gchar *stock_pixmap_get_name (StockPixmap icon)
572 {
573         if (icon < 0 || icon >= N_STOCK_PIXMAPS)
574                 return NULL;
575         
576         return pixmaps[icon].file;
577
578 }
579
580 StockPixmap stock_pixmap_get_icon (gchar *file)
581 {
582         gint i;
583         
584         for (i = 0; i < N_STOCK_PIXMAPS; i++) {
585                 if (strcmp (pixmaps[i].file, file) == 0)
586                         return i;
587         }
588         return -1;
589 }
590
591 static gboolean do_pix_draw(GtkWidget *widget, cairo_t *cr,
592                             OverlayData *data) 
593 {
594         GdkWindow *drawable = gtk_widget_get_window(widget);    
595         gint left = 0;
596         gint top = 0;
597
598         if (data->is_pixmap) {
599                 cm_return_val_if_fail(data->base_pixmap != NULL, FALSE);
600         } else {
601                 cm_return_val_if_fail(data->base_pixbuf != NULL, FALSE);
602         }
603
604         if (data->highlight) {
605                 MainWindow *mw = NULL;
606
607                 mw = mainwindow_get_mainwindow();
608                 if (mw != NULL && mw->menubar != NULL) {
609                         cairo_t *cr;
610                         GdkColor color = gtk_widget_get_style(mw->menubar)->base[GTK_STATE_SELECTED];
611
612                         cr = gdk_cairo_create(drawable);
613                         gdk_cairo_set_source_color(cr, &color);
614                         cairo_set_antialias(cr, CAIRO_ANTIALIAS_NONE);
615                         cairo_set_line_width(cr, 1.);
616                         cairo_set_line_cap(cr, CAIRO_LINE_CAP_BUTT);
617                         cairo_set_line_join(cr, CAIRO_LINE_JOIN_BEVEL);
618                         cairo_rectangle(cr, data->border_x-2, data->border_y-2,
619                             data->base_width+3, data->base_height+3);
620                         cairo_stroke(cr);
621                         cairo_destroy(cr);
622                 }
623         }
624
625         if (data->is_pixmap) {
626                 cairo_set_source_surface(cr, data->base_pixmap, data->border_x, data->border_y);
627                 cairo_pattern_set_extend(cairo_get_source(cr), CAIRO_EXTEND_REPEAT);
628                 cairo_rectangle(cr, data->border_x, data->border_y, data->base_width, data->base_height);
629                 cairo_fill(cr);
630         } else {
631                 gdk_cairo_set_source_pixbuf(cr, data->base_pixbuf, data->border_x, data->border_y);
632                 cairo_paint(cr);
633         }
634
635         if (data->position != OVERLAY_NONE) {
636
637                 switch (data->position) {
638                         case OVERLAY_TOP_LEFT:
639                         case OVERLAY_MID_LEFT:
640                         case OVERLAY_BOTTOM_LEFT:
641                                 left = 0;
642                                 break;
643
644                         case OVERLAY_TOP_CENTER:
645                         case OVERLAY_MID_CENTER:
646                         case OVERLAY_BOTTOM_CENTER:
647                                 left = (data->base_width + data->border_x * 2 - data->overlay_width)/2;
648                                 break;
649
650                         case OVERLAY_TOP_RIGHT:
651                         case OVERLAY_MID_RIGHT:
652                         case OVERLAY_BOTTOM_RIGHT:
653                                 left = data->base_width + data->border_x * 2 - data->overlay_width;
654                                 break;
655
656                         default:
657                                 break;
658                 }
659                 switch (data->position) {
660                         case OVERLAY_TOP_LEFT:
661                         case OVERLAY_TOP_CENTER:
662                         case OVERLAY_TOP_RIGHT:
663                                 top = 0;
664                                 break;
665
666                         case OVERLAY_MID_LEFT:
667                         case OVERLAY_MID_CENTER:
668                         case OVERLAY_MID_RIGHT:
669                                 top = (data->base_height + data->border_y * 2 - data->overlay_height)/2;
670                                 break;
671                                         
672                         case OVERLAY_BOTTOM_LEFT:
673                         case OVERLAY_BOTTOM_CENTER:
674                         case OVERLAY_BOTTOM_RIGHT:
675                                 top = data->base_height + data->border_y * 2 - data->overlay_height;
676                                 break;
677
678                         default:
679                                 break;
680                 }
681         }
682
683         if (data->position != OVERLAY_NONE) {
684                 if (data->is_pixmap) {
685                         cm_return_val_if_fail(data->overlay_pixmap != NULL, FALSE);
686                         cairo_set_source_surface(cr, data->overlay_pixmap, left, top);
687                         cairo_pattern_set_extend (cairo_get_source (cr), CAIRO_EXTEND_REPEAT);
688                         cairo_rectangle (cr, left, top, data->overlay_width, data->overlay_height);
689                         cairo_fill(cr);
690                 } else {
691       cm_return_val_if_fail(data->overlay_pixbuf != NULL, FALSE);
692       gdk_cairo_set_source_pixbuf(cr, data->overlay_pixbuf, left, top);
693       cairo_paint(cr);
694                 }
695         }
696
697         return TRUE;
698 }
699
700 #if !GTK_CHECK_VERSION(3,0,0)
701 static gboolean pixmap_with_overlay_expose_event_cb(GtkWidget *widget, GdkEventExpose *expose,
702                                                    OverlayData *data) 
703 #else
704 static gboolean pixmap_with_overlay_expose_event_cb(GtkWidget *widget, cairo_t *cr,
705                                                     OverlayData *data) 
706 #endif
707 {
708 #if !GTK_CHECK_VERSION(3,0,0)
709         cairo_t *cr;
710         GdkWindow *drawable = gtk_widget_get_window(widget);    
711         gboolean result;
712
713         cr = gdk_cairo_create(drawable);
714         gdk_window_clear_area (drawable, expose->area.x, expose->area.y,
715                                expose->area.width, expose->area.height);
716
717         result = do_pix_draw(widget, cr, data);
718         cairo_destroy(cr);
719         return result;
720 #else
721         return do_pix_draw(widget, cr, data);
722 #endif
723 }
724
725 static void pixmap_with_overlay_destroy_cb(GtkWidget *object, OverlayData *data) 
726 {
727         if (data->is_pixmap) {
728                 cairo_surface_destroy(data->base_pixmap);
729                 if (data->position != OVERLAY_NONE) {
730                         cairo_surface_destroy(data->overlay_pixmap);
731                 }
732         } else {
733                 g_object_unref(data->base_pixbuf);
734                 if (data->position != OVERLAY_NONE) {
735                         g_object_unref(data->overlay_pixbuf);
736                 }
737         }
738         g_free(data);
739 }
740
741 /**
742  * \brief Get a widget showing one icon with another overlaid on top of it.
743  *
744  * The base icon is always centralised, the other icon can be positioned.
745  * The overlay icon is ignored if pos=OVERLAY_NONE is used
746  *
747  * \param window   top-level window widget
748  * \param icon     the base icon
749  * \param overlay  the icon to overlay
750  * \param pos      how to align the overlay widget, or OVERLAY_NONE for no overlay
751  * \param border_x size of the border around the base icon (left and right)
752  * \param border_y size of the border around the base icon (top and bottom)
753  */
754 GtkWidget *stock_pixmap_widget_with_overlay(GtkWidget *window, StockPixmap icon,
755                                             StockPixmap overlay, OverlayPosition pos,
756                                             gint border_x, gint border_y)
757 {
758         cairo_surface_t *stock_pixmap = NULL;
759         GdkPixbuf *stock_pixbuf = NULL;
760         GtkWidget *widget = NULL;
761         GtkWidget *stock_wid = NULL;
762         GtkRequisition requisition;
763         OverlayData *data = NULL;
764         
765         data = g_new0(OverlayData, 1);
766
767         stock_wid = stock_pixmap_widget(window, icon);
768         gtk_widget_get_requisition(stock_wid, &requisition);
769
770         if (gtk_image_get_storage_type(GTK_IMAGE(stock_wid)) == GTK_IMAGE_PIXMAP)
771                 data->is_pixmap = TRUE;
772         else
773                 data->is_pixmap = FALSE;
774
775         if (data->is_pixmap) {
776                 cairo_t *cr = gdk_cairo_create(gtk_widget_get_window(stock_wid));
777                 stock_pixmap = cairo_get_target(cr);
778                 cairo_surface_reference(stock_pixmap);
779                 cairo_destroy(cr);
780                 data->base_pixmap = stock_pixmap;
781                 data->base_height = requisition.height;
782                 data->base_width  = requisition.width;
783                 gtk_widget_destroy(stock_wid);
784
785                 if (pos == OVERLAY_NONE) {
786                         data->overlay_pixmap = NULL;
787                 } else {
788                         stock_wid = stock_pixmap_widget(window, overlay);
789                         cr = gdk_cairo_create(gtk_widget_get_window(stock_wid));
790                         stock_pixmap = cairo_get_target(cr);
791                         cairo_surface_reference(stock_pixmap);
792                         cairo_destroy(cr);
793                         data->overlay_pixmap = stock_pixmap;
794                         data->overlay_height = requisition.height;
795                         data->overlay_width  = requisition.width;
796
797                         gtk_widget_destroy(stock_wid);
798                 }
799         } else {
800                 data->is_pixmap = FALSE;
801                 stock_pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(stock_wid));
802                 g_object_ref(stock_pixbuf);
803                 data->base_pixbuf = stock_pixbuf;
804                 data->base_height = requisition.height;
805                 data->base_width  = requisition.width;
806                 gtk_widget_destroy(stock_wid);
807                 if (pos == OVERLAY_NONE) {
808                         data->overlay_pixmap = NULL;
809                 } else {
810                         stock_wid = stock_pixmap_widget(window, overlay);
811                         stock_pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(stock_wid));
812                         g_object_ref(stock_pixbuf);
813                         data->overlay_pixbuf = stock_pixbuf;
814                         data->overlay_height = requisition.height;
815                         data->overlay_width  = requisition.width;
816
817                         gtk_widget_destroy(stock_wid);
818                 }
819         }
820         data->position = pos;
821         data->border_x = border_x;
822         data->border_y = border_y;
823         data->highlight = FALSE;
824
825         widget = gtk_drawing_area_new();
826         gtk_widget_set_size_request(widget, data->base_width + border_x * 2, 
827                               data->base_height + border_y * 2);
828 #if !GTK_CHECK_VERSION(3, 0, 0)
829         g_signal_connect(G_OBJECT(widget), "expose_event", 
830                          G_CALLBACK(pixmap_with_overlay_expose_event_cb), data);
831 #else
832         g_signal_connect(G_OBJECT(widget), "draw", 
833                          G_CALLBACK(pixmap_with_overlay_expose_event_cb), data);
834 #endif
835         g_signal_connect(G_OBJECT(widget), "destroy",
836                          G_CALLBACK(pixmap_with_overlay_destroy_cb), data);
837         g_object_set_data(G_OBJECT(widget), "highlight", &(data->highlight));
838         return widget;
839
840 }