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