1 /* images.c
2 * Copyright (C) 2005 Sylvain Cresto <scresto@gmail.com>
3 *
4 * This file is part of graveman!
5 *
6 * graveman! is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2, or
9 * (at your option) any later version.
10 *
11 * graveman! is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with program; see the file COPYING. If not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
19 * MA 02111-1307, USA.
20 *
21 * URL: http://www.nongnu.org/graveman/
22 *
23 */
24
25
26 #include "graveman.h"
27
28
29 GHashTable *Gimages = NULL;
30 GHashTable *Ganimationpath = NULL;
31
32 /*GdkPixbuf *GDirIcone, *GFileIcone, *GCDIcone, *GAudioIcone, *GCDRWIcone, *GCDpetiteIcone,
33 *GCDRWpetiteIcone, *GpetiteGraver, *GGraver, *GISOpetiteIcone, *GEraseCdrw, *GFileImage,
34 *GDVDpetiteIcone, *GDVDRWpetiteIcone, *GcharsetpetiteIcone, *GiconeOK, *GiconePASOK, *GiconeMITIGE,
35 *GMenuAudio = NULL, *GMenuData = NULL, *GMenuCopy = NULL, *GMenuOther = NULL, *GMenuDvd = NULL;*/
36
37 Timages Lotherimages[] = {
38 { "DirIcon", "directory icon", _IMG_PNG },
39 { "FileIcon", "file icon", _IMG_PNG },
40 { "FileImage", "file image", _IMG_PNG },
41 { "CDIcon", "cd icon", _IMG_PNG },
42 { "AudioIcon", "audio icon", _IMG_PNG },
43 { "CDRWIcon", "cdrw icon", _IMG_PNG },
44 { "CDRWsmallIcon", "cdrw small icon", _IMG_PNG },
45 { "DVDsmallIcon", "dvd small icon", _IMG_PNG },
46 { "DVDRWsmallIcon", "dvdrw small icon", _IMG_PNG },
47 { "CDsmallIcon", "cd small icon", _IMG_PNG },
48 { "ISOsmallIcon", "iso small icon", _IMG_PNG },
49 { "BurnsmallIcon", "burn small icon", _IMG_PNG },
50 { "BurnIcon", "burn icon", _IMG_PNG },
51 { "EraseCDRWIcon", "erase cdrw icon", _IMG_PNG },
52 { "CharsetSmallIcon", "charset small icon", _IMG_PNG },
53 { "OKIcon", "ok icon", _IMG_PNG },
54 { "BADIcon", "bad icon", _IMG_PNG },
55 { "WARNIcon", "warning icon", _IMG_PNG },
56 { "Themes", "theme icon", _IMG_PNG },
57 { "Working", "graveman animation", _IMG_MNG },
58 { NULL }
59 };
60
61 Timages Lmenuimages[] = {
62 { "Menu-Audio-", "menu audio icon", _IMG_PNG },
63 { "Menu-Data-", "menu data icon", _IMG_PNG },
64 { "Menu-Dvd-", "menu dvd icon", _IMG_PNG },
65 { "Menu-Copy-", "menu copy icon", _IMG_PNG },
66 { "Menu-Other-", "menu other icon", _IMG_PNG },
67 { NULL }
68 };
69
70 /* charger toutes les images a partir du bon r�pertoire */
load_all_images()71 gboolean load_all_images()
72 {
73 GHashTable *Limagespath = get_imagespath_plus_from_theme(Lotherimages, conf_get_string("theme"), NULL, NULL);
74 gchar *Lpath;
75 gboolean Laumoinsun = FALSE;
76 Timages *Lcurimage;
77
78 if (!Limagespath) return FALSE;
79
80 Gimages = _hash();
81 Ganimationpath = _hash();
82
83 for (Lcurimage = Lotherimages; Lcurimage->code; Lcurimage++) {
84 Lpath = g_hash_table_lookup(Limagespath, Lcurimage->code);
85 if (!Lpath) continue;
86 if (Lcurimage->type == _IMG_PNG) {
87 g_hash_table_insert(Gimages, Lcurimage->code, gdk_pixbuf_new_from_file((const gchar *)Lpath, NULL));
88 g_free(Lpath);
89 } else {
90 g_hash_table_insert(Ganimationpath, Lcurimage->code, Lpath);
91 }
92 Laumoinsun = TRUE;
93 }
94
95 g_hash_table_destroy(Limagespath);
96 return Laumoinsun;
97 }
98
get_image(gchar * Aident)99 GdkPixbuf *get_image(gchar *Aident)
100 {
101 return (GdkPixbuf *) g_hash_table_lookup(Gimages, Aident);
102 }
103
get_animation(gchar * Aident)104 gchar *get_animation(gchar *Aident)
105 {
106 return (gchar *) g_hash_table_lookup(Ganimationpath, Aident);
107 }
108
load_menu_images(gchar * Lquel)109 gboolean load_menu_images(gchar *Lquel) {
110 Timages *Lcurimages;
111 GdkPixbuf *Limg;
112 GHashTable *Limagespath = get_imagespath_plus_from_theme(Lmenuimages,
113 conf_get_string("theme"), Lquel, NULL);
114 Timages *Lcurimage;
115 gboolean Laumoinsun = FALSE;
116 gchar *Lpath;
117
118 if (!Limagespath) return FALSE;
119
120 if (Gimages) {
121 for (Lcurimages = Lmenuimages; Lcurimages->code; Lcurimages++) {
122 Limg = (GdkPixbuf *) g_hash_table_lookup(Gimages, Lcurimages->code);
123
124 if (Limg) {
125 g_object_unref(Limg);
126 g_hash_table_remove(Gimages, Lcurimages->code);
127 }
128 }
129 }
130
131 for (Lcurimage = Lmenuimages; Lcurimage->code; Lcurimage++) {
132 Lpath = g_hash_table_lookup(Limagespath, Lcurimage->code);
133 if (!Lpath) continue;
134
135 g_hash_table_insert(Gimages, Lcurimage->code, gdk_pixbuf_new_from_file((const gchar *)Lpath, NULL));
136 Laumoinsun = TRUE;
137
138 g_free(Lpath);
139 }
140
141 g_hash_table_destroy(Limagespath);
142
143 return Laumoinsun;
144 }
145
prepare_menu_images(Tgrave * Ag)146 gboolean prepare_menu_images(Tgrave *Ag)
147 {
148 gchar *Limg = conf_get_string("iconsize");
149 gchar *Lcurrent = sc_grave_get_data(Ag, "_current_size");
150 gboolean Lstatus = TRUE;
151
152 if (!Lcurrent || strcmp(Lcurrent, Limg)) {
153 Lstatus = load_menu_images(Limg);
154
155 g_free(Lcurrent);
156 sc_grave_replace_data(Ag, g_strdup(Limg), "_current_size");
157 }
158
159 return Lstatus;
160 }
161
162
free_all_images()163 void free_all_images()
164 {
165 /* g_object_unref(GiconeOK);
166 g_object_unref(GiconePASOK);
167 g_object_unref(GiconeMITIGE);
168 g_object_unref(GcharsetpetiteIcone);
169 g_object_unref(GEraseCdrw);
170 g_object_unref(GGraver);
171 g_object_unref(GISOpetiteIcone);
172 g_object_unref(GpetiteGraver);
173 g_object_unref(GDVDRWpetiteIcone);
174 g_object_unref(GCDRWpetiteIcone);
175 g_object_unref(GDVDpetiteIcone);
176 g_object_unref(GCDpetiteIcone);
177 if (G_IS_OBJECT(GMenuOther)) g_object_unref(GMenuOther);
178 if (G_IS_OBJECT(GMenuCopy)) g_object_unref(GMenuCopy);
179 if (G_IS_OBJECT(GMenuData)) g_object_unref(GMenuData);
180 if (G_IS_OBJECT(GMenuDvd)) g_object_unref(GMenuDvd);
181 if (G_IS_OBJECT(GMenuAudio)) g_object_unref(GMenuAudio);
182 g_object_unref(GCDRWIcone);
183 g_object_unref(GAudioIcone);
184 g_object_unref(GCDIcone);
185 g_object_unref(GFileImage);
186 g_object_unref(GFileIcone);
187 g_object_unref(GDirIcone);
188 */
189 }
190
191 /* load dynamic image used by main window */
image_prepare_main_window(Tgrave * Ag)192 gboolean image_prepare_main_window(Tgrave *Ag)
193 {
194 gtk_image_set_from_pixbuf(GTK_IMAGE(sc_grave_get_widget(Ag, "imgburnaudio2")), get_image("BurnsmallIcon"));
195 gtk_image_set_from_pixbuf(GTK_IMAGE(sc_grave_get_widget(Ag, "imgburndata2")), get_image("BurnsmallIcon"));
196 gtk_image_set_from_pixbuf(GTK_IMAGE(sc_grave_get_widget(Ag, "imgburndata3")), get_image("BurnsmallIcon"));
197 gtk_image_set_from_pixbuf(GTK_IMAGE(sc_grave_get_widget(Ag, "imgburncopy1")), get_image("BurnsmallIcon"));
198 gtk_image_set_from_pixbuf(GTK_IMAGE(sc_grave_get_widget(Ag, "imgfixcdother1")), get_image("BurnsmallIcon"));
199 gtk_image_set_from_pixbuf(GTK_IMAGE(sc_grave_get_widget(Ag, "imgburndvddata2")), get_image("BurnsmallIcon"));
200 gtk_image_set_from_pixbuf(GTK_IMAGE(sc_grave_get_widget(Ag, "imgburndvddata3")), get_image("BurnsmallIcon"));
201 gtk_image_set_from_pixbuf(GTK_IMAGE(sc_grave_get_widget(Ag, "imgerasecdrwother1")), get_image("EraseCDRWIcon"));
202 gtk_image_set_from_pixbuf(GTK_IMAGE(sc_grave_get_widget(Ag, "imgformatdvdrwother1")), get_image("EraseCDRWIcon"));
203
204 return TRUE;
205 }
206
207 /*
208 * vim:et:ts=8:sts=2:sw=2
209 */
210