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