a326a6177ea8d46c0663377f95e2989b6a8b99e0
[claws.git] / src / stock_pixmap.c
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2007 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 2 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, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  */
19
20 #include "defs.h"
21 #include <glib.h>
22 #include <gtk/gtkwidget.h>
23 #include <gtk/gtkimage.h>
24 #include <string.h>
25 #include <dirent.h>
26
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/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/interface.xpm"
49 #include "pixmaps/jpilot.xpm"
50 #include "pixmaps/key.xpm"
51 #include "pixmaps/ldap.xpm"
52 #include "pixmaps/linewrap.xpm"
53 #include "pixmaps/linewrapcurrent.xpm"
54 #include "pixmaps/mark.xpm"
55 #include "pixmaps/locked.xpm"
56 #include "pixmaps/new.xpm"
57 #include "pixmaps/replied.xpm"
58 #include "pixmaps/close.xpm"
59 #include "pixmaps/down_arrow.xpm"
60 #include "pixmaps/up_arrow.xpm"
61 #include "pixmaps/exec.xpm"
62 #include "pixmaps/mail.xpm"
63 #include "pixmaps/mail_attach.xpm"
64 #include "pixmaps/mail_compose.xpm"
65 #include "pixmaps/mail_forward.xpm"
66 #include "pixmaps/mail_receive.xpm"
67 #include "pixmaps/mail_receive_all.xpm"
68 #include "pixmaps/mail_reply.xpm"
69 #include "pixmaps/mail_reply_to_all.xpm"
70 #include "pixmaps/mail_reply_to_author.xpm"
71 #include "pixmaps/mail_send.xpm"
72 #include "pixmaps/mail_send_queue.xpm"
73 #include "pixmaps/mail_sign.xpm"
74 #include "pixmaps/open_mail.xpm"
75 #include "pixmaps/news_compose.xpm"
76 #include "pixmaps/paste.xpm"
77 #include "pixmaps/preferences.xpm"
78 #include "pixmaps/properties.xpm"
79 #include "pixmaps/claws-mail_icon.xpm"
80 #include "pixmaps/claws-mail_logo.xpm"
81 #include "pixmaps/address_book.xpm"
82 #include "pixmaps/unread.xpm"
83 #include "pixmaps/read.xpm"
84 #include "pixmaps/vcard.xpm"
85 #include "pixmaps/ignorethread.xpm"
86 #include "pixmaps/online.xpm"
87 #include "pixmaps/offline.xpm"
88 #include "pixmaps/notice_warn.xpm"
89 #include "pixmaps/notice_error.xpm"
90 #include "pixmaps/notice_note.xpm"
91 #include "pixmaps/quicksearch.xpm"
92 #include "pixmaps/clip_gpg_signed.xpm"
93 #include "pixmaps/gpg_signed.xpm"
94 #include "pixmaps/mime_text_plain.xpm"
95 #include "pixmaps/mime_text_html.xpm"
96 #include "pixmaps/mime_application.xpm"
97 #include "pixmaps/mime_image.xpm"
98 #include "pixmaps/mime_audio.xpm"
99 #include "pixmaps/mime_text_enriched.xpm"
100 #include "pixmaps/mime_unknown.xpm"
101 #include "pixmaps/mime_pdf.xpm"
102 #include "pixmaps/mime_ps.xpm"
103 #include "pixmaps/mime_calendar.xpm"
104 #include "pixmaps/mime_pgpsig.xpm"
105 #include "pixmaps/privacy_signed.xpm"
106 #include "pixmaps/privacy_passed.xpm"
107 #include "pixmaps/privacy_failed.xpm"
108 #include "pixmaps/privacy_unknown.xpm"
109 #include "pixmaps/privacy_expired.xpm"
110 #include "pixmaps/privacy_warn.xpm"                 
111 #include "pixmaps/privacy_emblem_encrypted.xpm"
112 #include "pixmaps/privacy_emblem_signed.xpm"
113 #include "pixmaps/privacy_emblem_passed.xpm"
114 #include "pixmaps/privacy_emblem_failed.xpm"
115 #include "pixmaps/privacy_emblem_warn.xpm"
116 #include "pixmaps/mime_message.xpm"                  
117 #include "pixmaps/address_search.xpm"
118 #include "pixmaps/check_spelling.xpm"
119
120 #include "pixmaps/dir_close.xpm"
121 #include "pixmaps/dir_open.xpm"
122 #include "pixmaps/dir_open_hrm.xpm"
123 #include "pixmaps/inbox.xpm"
124 #include "pixmaps/inbox_hrm.xpm"
125 #include "pixmaps/outbox.xpm"
126 #include "pixmaps/outbox_hrm.xpm"
127 #include "pixmaps/trash.xpm"
128 #include "pixmaps/trash_btn.xpm"
129 #include "pixmaps/trash_hrm.xpm"
130 #include "pixmaps/drafts_close.xpm"
131 #include "pixmaps/drafts_open.xpm"
132 #include "pixmaps/dir_close_mark.xpm"
133 #include "pixmaps/dir_open_mark.xpm"
134 #include "pixmaps/dir_open_hrm_mark.xpm"
135 #include "pixmaps/inbox_mark.xpm"
136 #include "pixmaps/inbox_hrm_mark.xpm"
137 #include "pixmaps/outbox_mark.xpm"
138 #include "pixmaps/outbox_hrm_mark.xpm"
139 #include "pixmaps/trash_mark.xpm"
140 #include "pixmaps/trash_hrm_mark.xpm"
141 #include "pixmaps/drafts_close_mark.xpm"
142 #include "pixmaps/drafts_open_mark.xpm"
143 #include "pixmaps/dir_noselect.xpm"
144 #include "pixmaps/spam.xpm"
145 #include "pixmaps/spam_btn.xpm"
146 #include "pixmaps/ham_btn.xpm"
147 #include "pixmaps/moved.xpm"
148 #include "pixmaps/copied.xpm"
149 #include "pixmaps/active.xpm"
150 #include "pixmaps/inactive.xpm"
151 #include "pixmaps/empty.xpm"
152
153 typedef struct _StockPixmapData StockPixmapData;
154
155 struct _StockPixmapData
156 {
157         gchar **data;
158         GdkPixmap *pixmap;
159         GdkBitmap *mask;
160         gchar *file;
161         gchar *icon_path;
162         GdkPixbuf *pixbuf;
163 };
164
165 typedef struct _OverlayData OverlayData;
166
167 struct _OverlayData
168 {
169         GdkPixmap *base_pixmap;
170         GdkBitmap *base_mask;
171         GdkPixmap *overlay_pixmap;
172         GdkBitmap *overlay_mask;
173         guint base_height;
174         guint base_width;
175         guint overlay_height;
176         guint overlay_width;
177         OverlayPosition position;
178         gint border_x;
179         gint border_y;
180 };
181
182 static void stock_pixmap_find_themes_in_dir(GList **list, const gchar *dirname);
183
184 static StockPixmapData pixmaps[] =
185 {
186         {addr_one_xpm                           , NULL, NULL, "addr_one", NULL},
187         {addr_two_xpm                           , NULL, NULL, "addr_two", NULL},
188         {address_xpm                            , NULL, NULL, "address", NULL},
189         {address_book_xpm                       , NULL, NULL, "address_book", NULL},
190         {address_search_xpm                     , NULL, NULL, "address_search", NULL},
191         {book_xpm                               , NULL, NULL, "book", NULL},
192         {category_xpm                           , NULL, NULL, "category", NULL},
193         {checkbox_off_xpm                       , NULL, NULL, "checkbox_off", NULL},
194         {checkbox_on_xpm                        , NULL, NULL, "checkbox_on", NULL},
195         {check_spelling_xpm                     , NULL, NULL, "check_spelling", NULL},
196         {clip_xpm                               , NULL, NULL, "clip", NULL},
197         {clipkey_xpm                            , NULL, NULL, "clipkey", NULL},
198         {clip_gpg_signed_xpm                    , NULL, NULL, "clip_gpg_signed", NULL},
199         {close_xpm                              , NULL, NULL, "close", NULL},
200         {complete_xpm                           , NULL, NULL, "complete", NULL},
201         {continue_xpm                           , NULL, NULL, "continue", NULL},
202         {deleted_xpm                            , NULL, NULL, "deleted", NULL},
203         {dir_close_xpm                          , NULL, NULL, "dir_close", NULL},
204         {dir_close_xpm                          , NULL, NULL, "dir_close_hrm", NULL},
205         {dir_open_xpm                           , NULL, NULL, "dir_open", NULL},
206         {dir_open_hrm_xpm                       , NULL, NULL, "dir_open_hrm", NULL},
207         {dir_close_mark_xpm                     , NULL, NULL, "dir_close_mark", NULL},
208         {dir_close_mark_xpm                     , NULL, NULL, "dir_close_hrm_mark", NULL},
209         {dir_open_mark_xpm                      , NULL, NULL, "dir_open_mark", NULL},
210         {dir_open_hrm_mark_xpm                  , NULL, NULL, "dir_open_hrm_mark", NULL},
211         {down_arrow_xpm                         , NULL, NULL, "down_arrow", NULL},
212         {up_arrow_xpm                           , NULL, NULL, "up_arrow", NULL},
213         {edit_extern_xpm                        , NULL, NULL, "edit_extern", NULL},
214         {error_xpm                              , NULL, NULL, "error", NULL},
215         {exec_xpm                               , NULL, NULL, "exec", NULL},
216         {forwarded_xpm                          , NULL, NULL, "forwarded", NULL},
217         {group_xpm                              , NULL, NULL, "group", NULL},
218         {ignorethread_xpm                       , NULL, NULL, "ignorethread", NULL},
219         {inbox_xpm                              , NULL, NULL, "inbox_close", NULL},
220         {inbox_hrm_xpm                          , NULL, NULL, "inbox_close_hrm", NULL},
221         {inbox_xpm                              , NULL, NULL, "inbox_open", NULL},
222         {inbox_hrm_xpm                          , NULL, NULL, "inbox_open_hrm", NULL},
223         {inbox_mark_xpm                         , NULL, NULL, "inbox_close_mark", NULL},
224         {inbox_hrm_mark_xpm                     , NULL, NULL, "inbox_close_hrm_mark", NULL},
225         {inbox_mark_xpm                         , NULL, NULL, "inbox_open_mark", NULL},
226         {inbox_hrm_mark_xpm                     , NULL, NULL, "inbox_open_hrm_mark", NULL},
227         {paste_xpm                              , NULL, NULL, "insert_file", NULL},
228         {interface_xpm                          , NULL, NULL, "interface", NULL},
229         {jpilot_xpm                             , NULL, NULL, "jpilot", NULL},
230         {key_xpm                                , NULL, NULL, "key", NULL},
231         {ldap_xpm                               , NULL, NULL, "ldap", NULL},
232         {linewrapcurrent_xpm                    , NULL, NULL, "linewrapcurrent", NULL},
233         {linewrap_xpm                           , NULL, NULL, "linewrap", NULL},
234         {locked_xpm                             , NULL, NULL, "locked", NULL},
235         {mail_xpm                               , NULL, NULL, "mail", NULL},
236         {mail_attach_xpm                        , NULL, NULL, "mail_attach", NULL},
237         {mail_compose_xpm                       , NULL, NULL, "mail_compose", NULL},
238         {mail_forward_xpm                       , NULL, NULL, "mail_forward", NULL},
239         {mail_receive_xpm                       , NULL, NULL, "mail_receive", NULL},
240         {mail_receive_all_xpm                   , NULL, NULL, "mail_receive_all", NULL},
241         {mail_reply_xpm                         , NULL, NULL, "mail_reply", NULL},
242         {mail_reply_to_all_xpm                  , NULL, NULL, "mail_reply_to_all", NULL},
243         {mail_reply_to_author_xpm               , NULL, NULL, "mail_reply_to_author", NULL},
244         {mail_send_xpm                          , NULL, NULL, "mail_send", NULL},
245         {mail_send_queue_xpm                    , NULL, NULL, "mail_send_queue", NULL},
246         {mail_sign_xpm                          , NULL, NULL, "mail_sign", NULL},
247         {open_mail_xpm                          , NULL, NULL, "open_mail", NULL},
248         {mark_xpm                               , NULL, NULL, "mark", NULL},
249         {new_xpm                                , NULL, NULL, "new", NULL},
250         {news_compose_xpm                       , NULL, NULL, "news_compose", NULL},
251         {outbox_xpm                             , NULL, NULL, "outbox_close", NULL},
252         {outbox_hrm_xpm                         , NULL, NULL, "outbox_close_hrm", NULL},
253         {outbox_xpm                             , NULL, NULL, "outbox_open", NULL},
254         {outbox_hrm_xpm                         , NULL, NULL, "outbox_open_hrm", NULL},
255         {outbox_mark_xpm                        , NULL, NULL, "outbox_close_mark", NULL},
256         {outbox_hrm_mark_xpm                    , NULL, NULL, "outbox_close_hrm_mark", NULL},
257         {outbox_mark_xpm                        , NULL, NULL, "outbox_open_mark", NULL},
258         {outbox_hrm_mark_xpm                    , NULL, NULL, "outbox_open_hrm_mark", NULL},
259         {replied_xpm                            , NULL, NULL, "replied", NULL},
260         {paste_xpm                              , NULL, NULL, "paste", NULL},
261         {preferences_xpm                        , NULL, NULL, "preferences", NULL},
262         {properties_xpm                         , NULL, NULL, "properties", NULL},
263         {outbox_xpm                             , NULL, NULL, "queue_close", NULL},
264         {outbox_hrm_xpm                         , NULL, NULL, "queue_close_hrm", NULL},
265         {outbox_xpm                             , NULL, NULL, "queue_open", NULL},
266         {outbox_hrm_xpm                         , NULL, NULL, "queue_open_hrm", NULL},
267         {trash_xpm                              , NULL, NULL, "trash_open", NULL},
268         {trash_hrm_xpm                          , NULL, NULL, "trash_open_hrm", NULL},
269         {trash_xpm                              , NULL, NULL, "trash_close", NULL},
270         {trash_hrm_xpm                          , NULL, NULL, "trash_close_hrm", NULL},
271         {outbox_mark_xpm                        , NULL, NULL, "queue_close_mark", NULL},
272         {outbox_hrm_mark_xpm                    , NULL, NULL, "queue_close_hrm_mark", NULL},
273         {outbox_mark_xpm                        , NULL, NULL, "queue_open_mark", NULL},
274         {outbox_hrm_mark_xpm                    , NULL, NULL, "queue_open_hrm_mark", NULL},
275         {trash_mark_xpm                         , NULL, NULL, "trash_open_mark", NULL},
276         {trash_hrm_mark_xpm                     , NULL, NULL, "trash_open_hrm_mark", NULL},
277         {trash_mark_xpm                         , NULL, NULL, "trash_close_mark", NULL},
278         {trash_hrm_mark_xpm                     , NULL, NULL, "trash_close_hrm_mark", NULL},
279         {unread_xpm                             , NULL, NULL, "unread", NULL},
280         {vcard_xpm                              , NULL, NULL, "vcard", NULL},
281         {online_xpm                             , NULL, NULL, "online", NULL},
282         {offline_xpm                            , NULL, NULL, "offline", NULL},
283         {notice_warn_xpm                        , NULL, NULL, "notice_warn",  NULL},
284         {notice_error_xpm                       , NULL, NULL, "notice_error",  NULL},
285         {notice_note_xpm                        , NULL, NULL, "notice_note",  NULL},
286         {quicksearch_xpm                        , NULL, NULL, "quicksearch",  NULL},
287         {gpg_signed_xpm                         , NULL, NULL, "gpg_signed", NULL},
288         {drafts_close_xpm                       , NULL, NULL, "drafts_close", NULL},
289         {drafts_open_xpm                        , NULL, NULL, "drafts_open", NULL},
290         {drafts_close_mark_xpm                  , NULL, NULL, "drafts_close_mark", NULL},
291         {drafts_open_mark_xpm                   , NULL, NULL, "drafts_open_mark", NULL},
292         {mime_text_plain_xpm                    , NULL, NULL, "mime_text_plain", NULL},
293         {mime_text_html_xpm                     , NULL, NULL, "mime_text_html", NULL},
294         {mime_application_xpm                   , NULL, NULL, "mime_application", NULL},
295         {mime_image_xpm                         , NULL, NULL, "mime_image", NULL},
296         {mime_audio_xpm                         , NULL, NULL, "mime_audio", NULL},
297         {mime_text_enriched_xpm                 , NULL, NULL, "mime_text_enriched", NULL},
298         {mime_unknown_xpm                       , NULL, NULL, "mime_unknown", NULL},    
299         {mime_pdf_xpm                           , NULL, NULL, "mime_pdf", NULL},        
300         {mime_ps_xpm                            , NULL, NULL, "mime_ps", NULL}, 
301         {mime_calendar_xpm                      , NULL, NULL, "mime_calendar", NULL},   
302         {mime_pgpsig_xpm                        , NULL, NULL, "mime_pgpsig", NULL},     
303         {privacy_signed_xpm                     , NULL, NULL, "privacy_signed", NULL},
304         {privacy_passed_xpm                     , NULL, NULL, "privacy_passed", NULL},
305         {privacy_failed_xpm                     , NULL, NULL, "privacy_failed", NULL},  
306         {privacy_unknown_xpm                    , NULL, NULL, "privacy_unknown", NULL},
307         {privacy_expired_xpm                    , NULL, NULL, "privacy_expired", NULL},
308         {privacy_warn_xpm                       , NULL, NULL, "privacy_warn", NULL},
309         {privacy_emblem_encrypted_xpm           , NULL, NULL, "privacy_emblem_encrypted", NULL},
310         {privacy_emblem_signed_xpm              , NULL, NULL, "privacy_emblem_signed", NULL},
311         {privacy_emblem_passed_xpm              , NULL, NULL, "privacy_emblem_passed", NULL},
312         {privacy_emblem_failed_xpm              , NULL, NULL, "privacy_emblem_failed", NULL},   
313         {privacy_emblem_warn_xpm                , NULL, NULL, "privacy_emblem_warn", NULL},
314         {mime_message_xpm                       , NULL, NULL, "mime_message", NULL},
315         {claws_mail_icon_xpm                    , NULL, NULL, "claws_mail_icon", NULL},
316         {read_xpm                               , NULL, NULL, "read", NULL},
317         {trash_btn_xpm                          , NULL, NULL, "trash_btn", NULL},
318         {claws_mail_logo_xpm                    , NULL, NULL, "claws_mail_logo", NULL},
319         {dir_noselect_xpm                       , NULL, NULL, "dir_noselect" , NULL},
320         {spam_xpm                               , NULL, NULL, "spam" , NULL},
321         {spam_btn_xpm                           , NULL, NULL, "spam_btn" , NULL},
322         {ham_btn_xpm                            , NULL, NULL, "ham_btn" , NULL},
323         {moved_xpm                              , NULL, NULL, "moved", NULL},
324         {copied_xpm                             , NULL, NULL, "copied", NULL},
325         {active_xpm                             , NULL, NULL, "active", NULL},
326         {inactive_xpm                           , NULL, NULL, "inactive", NULL},
327         {empty_xpm                              , NULL, NULL, "empty" , NULL}
328 };
329
330 /* return newly constructed GtkPixmap from GdkPixmap */
331 GtkWidget *stock_pixmap_widget(GtkWidget *window, StockPixmap icon)
332 {
333         GdkPixmap *pixmap;
334         GdkBitmap *mask;
335
336         g_return_val_if_fail(window != NULL, NULL);
337         g_return_val_if_fail(icon >= 0 && icon < N_STOCK_PIXMAPS, NULL);
338
339         if (stock_pixmap_gdk(window, icon, &pixmap, &mask) != -1)
340                 return gtk_image_new_from_pixmap(pixmap, mask);
341         
342         return NULL;
343 }
344
345 /*!
346  *\brief        
347  */
348 gint stock_pixbuf_gdk(GtkWidget *window, StockPixmap icon, GdkPixbuf **pixbuf)
349 {
350         StockPixmapData *pix_d;
351
352         if (pixbuf)
353                 *pixbuf = NULL;
354                 
355         g_return_val_if_fail(icon >= 0 && icon < N_STOCK_PIXMAPS, -1);
356
357         pix_d = &pixmaps[icon];
358
359         if (!pix_d->pixbuf || (strcmp2(pix_d->icon_path, prefs_common.pixmap_theme_path) != 0)) {
360                 GdkPixbuf *pix = NULL;
361         
362                 if (strcmp(prefs_common.pixmap_theme_path, DEFAULT_PIXMAP_THEME) != 0) {
363                         if (is_dir_exist(prefs_common.pixmap_theme_path)) {
364                                 char *icon_file_name; 
365                                 
366                                 icon_file_name = g_strconcat(prefs_common.pixmap_theme_path,
367                                                              G_DIR_SEPARATOR_S,
368                                                              pix_d->file,
369                                                              ".xpm",
370                                                              NULL);
371                                 if (is_file_exist(icon_file_name)) {
372                                         GError *err = NULL;
373                                         pix = gdk_pixbuf_new_from_file(icon_file_name, &err);   
374                                         if (err) g_error_free(err);
375                                 }                                       
376                                 if (pix) {
377                                         g_free(pix_d->icon_path);
378                                         pix_d->icon_path = g_strdup(prefs_common.pixmap_theme_path);
379                                 }
380                                 g_free(icon_file_name);
381                         } else {
382                                 /* even the path does not exist (deleted between two sessions), so
383                                 set the preferences to the internal theme */
384                                 prefs_common.pixmap_theme_path = g_strdup(DEFAULT_PIXMAP_THEME);
385                         }
386                 }
387                 pix_d->pixbuf = pix;
388         }
389
390         if (!pix_d->pixbuf) {
391                 pix_d->pixbuf = gdk_pixbuf_new_from_xpm_data((const gchar **) pix_d->data);
392                 if (pix_d->pixbuf) {
393                         g_free(pix_d->icon_path);
394                         pix_d->icon_path = g_strdup(DEFAULT_PIXMAP_THEME);      
395                 }
396         }
397
398         g_return_val_if_fail(pix_d->pixbuf != NULL, -1);
399
400         if (pixbuf)
401                 *pixbuf = pix_d->pixbuf;
402
403         /* pixbuf should have one ref outstanding */            
404
405         return 0;
406 }
407
408 /* create GdkPixmap if it has not created yet */
409 gint stock_pixmap_gdk(GtkWidget *window, StockPixmap icon,
410                       GdkPixmap **pixmap, GdkBitmap **mask)
411 {
412         StockPixmapData *pix_d;
413
414         if (pixmap) *pixmap = NULL;
415         if (mask)   *mask   = NULL;
416
417         g_return_val_if_fail(window != NULL, -1);
418         g_return_val_if_fail(icon >= 0 && icon < N_STOCK_PIXMAPS, -1);
419
420         pix_d = &pixmaps[icon];
421
422         if (!pix_d->pixmap || (strcmp2(pix_d->icon_path, prefs_common.pixmap_theme_path) != 0)) {
423                 GdkPixmap *pix = NULL;
424         
425                 if (strcmp(prefs_common.pixmap_theme_path, DEFAULT_PIXMAP_THEME) != 0) {
426                         if ( is_dir_exist(prefs_common.pixmap_theme_path) ) {
427                                 char *icon_file_name; 
428                                 
429                                 icon_file_name = g_strconcat(prefs_common.pixmap_theme_path,
430                                                              G_DIR_SEPARATOR_S,
431                                                              pix_d->file,
432                                                              ".xpm",
433                                                              NULL);
434                                 if (is_file_exist(icon_file_name))
435                                         PIXMAP_CREATE_FROM_FILE(window, pix, pix_d->mask, icon_file_name);
436                                 if (pix) {
437                                         g_free(pix_d->icon_path);
438                                         pix_d->icon_path = g_strdup(prefs_common.pixmap_theme_path);
439                                 }
440                                 g_free(icon_file_name);
441                         } else {
442                                 /* even the path does not exist (deleted between two sessions), so
443                                 set the preferences to the internal theme */
444                                 prefs_common.pixmap_theme_path = g_strdup(DEFAULT_PIXMAP_THEME);
445                         }
446                 }
447                 pix_d->pixmap = pix;
448         }
449
450         if (!pix_d->pixmap) {
451                 PIXMAP_CREATE(window, pix_d->pixmap, pix_d->mask, pix_d->data);
452                 if (pix_d->pixmap) {
453                         g_free(pix_d->icon_path);
454                         pix_d->icon_path = g_strdup(DEFAULT_PIXMAP_THEME);      
455                 }
456         }
457
458         g_return_val_if_fail(pix_d->pixmap != NULL, -1);
459         
460         if (pixmap) 
461                 *pixmap = pix_d->pixmap;
462         if (mask)   
463                 *mask   = pix_d->mask;
464
465         return 0;
466 }
467
468 static void stock_pixmap_find_themes_in_dir(GList **list, const gchar *dirname)
469 {
470         struct dirent *d;
471         DIR *dp;
472         
473         if ((dp = opendir(dirname)) == NULL) {
474                 debug_print("dir %s not found, skipping theme scan", dirname);
475                 return;
476         }
477         
478         while ((d = readdir(dp)) != NULL) {
479                 gchar *entry;
480                 gchar *fullentry;
481
482                 entry     = d->d_name;
483                 fullentry = g_strconcat(dirname, G_DIR_SEPARATOR_S, entry, NULL);
484                 
485                 if (strcmp(entry, ".") != 0 && strcmp(entry, "..") != 0 && is_dir_exist(fullentry)) {
486                         gchar *filetoexist;
487                         int i;
488                         
489                         for (i = 0; i < N_STOCK_PIXMAPS; i++) {
490                                 filetoexist = g_strconcat(fullentry, G_DIR_SEPARATOR_S, pixmaps[i].file, ".xpm", NULL);
491                                 if (is_file_exist(filetoexist)) {
492                                         *list = g_list_append(*list, fullentry);
493                                         g_free(filetoexist);
494                                         break;
495                                 }
496                                 g_free(filetoexist);
497                         }
498                         if (i == N_STOCK_PIXMAPS) 
499                                 g_free(fullentry);
500                 } else 
501                         g_free(fullentry);
502         }
503         closedir(dp);
504 }
505
506 GList *stock_pixmap_themes_list_new(void)
507 {
508         gchar *defaulttheme;
509         gchar *userthemes;
510         gchar *systemthemes;
511         GList *list = NULL;
512         
513         defaulttheme = g_strdup(DEFAULT_PIXMAP_THEME);
514         userthemes   = g_strconcat(get_home_dir(), G_DIR_SEPARATOR_S,
515                                    RC_DIR, G_DIR_SEPARATOR_S, 
516                                    PIXMAP_THEME_DIR, NULL);
517         systemthemes = g_strconcat(PACKAGE_DATA_DIR, G_DIR_SEPARATOR_S,
518                                    PIXMAP_THEME_DIR, NULL);
519
520         list = g_list_append(list, defaulttheme);
521         
522         stock_pixmap_find_themes_in_dir(&list, userthemes);
523         stock_pixmap_find_themes_in_dir(&list, systemthemes);
524
525         g_free(userthemes);
526         g_free(systemthemes);
527         return list;
528 }
529
530 void stock_pixmap_themes_list_free(GList *list)
531 {
532         GList *ptr;
533
534         for (ptr = g_list_first(list); ptr != NULL; ptr = g_list_next(ptr)) 
535                 g_free(ptr->data);
536         g_list_free(list);              
537 }
538
539 gchar *stock_pixmap_get_name (StockPixmap icon)
540 {
541         g_return_val_if_fail(icon >= 0 && icon < N_STOCK_PIXMAPS, NULL);
542         
543         return pixmaps[icon].file;
544
545 }
546
547 StockPixmap stock_pixmap_get_icon (gchar *file)
548 {
549         gint i;
550         
551         for (i = 0; i < N_STOCK_PIXMAPS; i++) {
552                 if (strcmp (pixmaps[i].file, file) == 0)
553                         return i;
554         }
555         return -1;
556 }
557
558 static gboolean pixmap_with_overlay_expose_event_cb(GtkWidget *widget, GdkEventExpose *expose,
559                                                     OverlayData *data) 
560 {
561         GdkDrawable *drawable = widget->window; 
562         GdkGC *gc_pix;
563         gint left = 0;
564         gint top = 0;
565
566         g_return_val_if_fail(data->base_pixmap != NULL, FALSE);
567         g_return_val_if_fail(data->base_mask != NULL, FALSE);
568
569         gc_pix = gdk_gc_new((GdkWindow *)drawable);
570                                                  
571         gdk_window_clear_area (drawable, expose->area.x, expose->area.y,
572                                expose->area.width, expose->area.height);
573
574         gdk_gc_set_tile(gc_pix, data->base_pixmap);
575         gdk_gc_set_ts_origin(gc_pix, data->border_x, data->border_y);
576         gdk_gc_set_clip_mask(gc_pix, data->base_mask);
577         gdk_gc_set_clip_origin(gc_pix, data->border_x, data->border_y);
578         gdk_gc_set_fill(gc_pix, GDK_TILED);
579
580         gdk_draw_rectangle(drawable, gc_pix, TRUE, data->border_x, data->border_y, 
581                            data->base_width, data->base_height);
582
583         if (data->position != OVERLAY_NONE) {
584                 g_return_val_if_fail(data->overlay_pixmap != NULL, FALSE);
585                 g_return_val_if_fail(data->overlay_mask != NULL, FALSE);
586
587                 gdk_gc_set_tile(gc_pix, data->overlay_pixmap);
588                 gdk_gc_set_clip_mask(gc_pix, data->overlay_mask);
589
590                 switch (data->position) {
591                         case OVERLAY_TOP_LEFT:
592                         case OVERLAY_MID_LEFT:
593                         case OVERLAY_BOTTOM_LEFT:
594                                 left = 0;
595                                 break;
596
597                         case OVERLAY_TOP_CENTER:
598                         case OVERLAY_MID_CENTER:
599                         case OVERLAY_BOTTOM_CENTER:
600                                 left = (data->base_width + data->border_x * 2  - data->overlay_width)/2;
601                                 break;
602
603                         case OVERLAY_TOP_RIGHT:
604                         case OVERLAY_MID_RIGHT:
605                         case OVERLAY_BOTTOM_RIGHT:
606                                 left = data->base_width + data->border_x * 2 - data->overlay_width;
607                                 break;
608
609                         default:
610                                 break;
611                 }
612                 switch (data->position) {
613                         case OVERLAY_TOP_LEFT:
614                         case OVERLAY_TOP_CENTER:
615                         case OVERLAY_TOP_RIGHT:
616                                 top = 0;
617                                 break;
618
619                         case OVERLAY_MID_LEFT:
620                         case OVERLAY_MID_CENTER:
621                         case OVERLAY_MID_RIGHT:
622                                 top = (data->base_height + data->border_y * 2  - data->overlay_height)/2;
623                                 break;
624                                         
625                         case OVERLAY_BOTTOM_LEFT:
626                         case OVERLAY_BOTTOM_CENTER:
627                         case OVERLAY_BOTTOM_RIGHT:
628                                 top = data->base_height + data->border_y * 2 - data->overlay_height;
629                                 break;
630
631                         default:
632                                 break;
633                 }
634
635                 gdk_gc_set_ts_origin(gc_pix, left, top);
636                 gdk_gc_set_clip_origin(gc_pix, left, top);
637                 gdk_gc_set_fill(gc_pix, GDK_TILED);
638                 gdk_draw_rectangle(drawable, gc_pix, TRUE, left, top, 
639                                    data->overlay_width, data->overlay_height);
640         }
641         g_object_unref(gc_pix);
642         
643         return TRUE;
644 }
645
646 static void pixmap_with_overlay_destroy_cb(GtkObject *object, OverlayData *data) 
647 {
648         g_object_unref(data->base_pixmap);
649         g_object_unref(data->base_mask);
650         if (data->position != OVERLAY_NONE) {
651                 g_object_unref(data->overlay_pixmap);
652                 g_object_unref(data->overlay_mask);
653         }
654         g_free(data);
655 }
656
657 /**
658  * \brief Get a widget showing one icon with another overlaid on top of it.
659  *
660  * The base icon is always centralised, the other icon can be positioned.
661  * The overlay icon is ignored if pos=OVERLAY_NONE is used
662  *
663  * \param window   top-level window widget
664  * \param icon     the base icon
665  * \param overlay  the icon to overlay
666  * \param pos      how to align the overlay widget, or OVERLAY_NONE for no overlay
667  * \param border_x size of the border around the base icon (left and right)
668  * \param border_y size of the border around the base icon (top and bottom)
669  */
670 GtkWidget *stock_pixmap_widget_with_overlay(GtkWidget *window, StockPixmap icon,
671                                             StockPixmap overlay, OverlayPosition pos,
672                                             gint border_x, gint border_y)
673 {
674         GdkPixmap *stock_pixmap;
675         GdkBitmap *stock_mask;
676         GtkWidget *widget;
677         GtkWidget *stock_wid;
678         OverlayData *data;
679         
680         data = g_new0(OverlayData, 1);
681
682         stock_wid = stock_pixmap_widget(window, icon);
683         gtk_image_get_pixmap(GTK_IMAGE(stock_wid), &stock_pixmap, &stock_mask);
684         g_object_ref(stock_pixmap);
685         g_object_ref(stock_mask);
686         data->base_pixmap = stock_pixmap;
687         data->base_mask   = stock_mask;
688         data->base_height = stock_wid->requisition.height;
689         data->base_width  = stock_wid->requisition.width;
690         gtk_widget_destroy(stock_wid);
691
692         if (pos == OVERLAY_NONE) {
693                 data->overlay_pixmap = NULL;
694                 data->overlay_mask   = NULL;
695         } else {
696                 stock_wid = stock_pixmap_widget(window, overlay);
697                 gtk_image_get_pixmap(GTK_IMAGE(stock_wid), &stock_pixmap, &stock_mask);
698                 g_object_ref(stock_pixmap);
699                 g_object_ref(stock_mask);
700                 data->overlay_pixmap = stock_pixmap;
701                 data->overlay_mask   = stock_mask;
702                 data->overlay_height = stock_wid->requisition.height;
703                 data->overlay_width  = stock_wid->requisition.width;
704
705                 gtk_widget_destroy(stock_wid);
706         }
707         
708         data->position = pos;
709         data->border_x = border_x;
710         data->border_y = border_y;
711
712         widget = gtk_drawing_area_new();
713         gtk_drawing_area_size(GTK_DRAWING_AREA(widget), data->base_width + border_x * 2, 
714                               data->base_height + border_y * 2);
715         g_signal_connect(G_OBJECT(widget), "expose_event", 
716                          G_CALLBACK(pixmap_with_overlay_expose_event_cb), data);
717         g_signal_connect(G_OBJECT(widget), "destroy",
718                          G_CALLBACK(pixmap_with_overlay_destroy_cb), data);
719         return widget;
720
721 }