comparison src/image-overlay.c @ 218:f4a0555794a9

Customizable info overlay in fullscreen, based on the patch posted to gqview-devel list by Timo on 2007-09-10.
author zas_
date Mon, 31 Mar 2008 22:10:25 +0000
parents a57b153e7fa4
children 62f2f8f7cb2d
comparison
equal deleted inserted replaced
217:5bdab7ed4bcd 218:f4a0555794a9
11 11
12 #include "gqview.h" 12 #include "gqview.h"
13 #include "image-overlay.h" 13 #include "image-overlay.h"
14 14
15 #include "collect.h" 15 #include "collect.h"
16 #include "exif.h"
16 #include "filelist.h" 17 #include "filelist.h"
17 #include "image.h" 18 #include "image.h"
18 #include "img-view.h" 19 #include "img-view.h"
19 #include "layout.h" 20 #include "layout.h"
20 #include "pixbuf-renderer.h" 21 #include "pixbuf-renderer.h"
73 #define IMAGE_OSD_DEFAULT_DURATION 30 74 #define IMAGE_OSD_DEFAULT_DURATION 30
74 75
75 76
76 static void image_osd_timer_schedule(OverlayStateData *osd); 77 static void image_osd_timer_schedule(OverlayStateData *osd);
77 78
79 static gchar *image_osd_mkinfo(const gchar *str, ImageWindow *imd, GHashTable *vars)
80 {
81 gchar delim = '%', imp = '|', sep[] = " - ";
82 gchar *start, *end;
83 gint pos, prev;
84 gint last;
85 gchar *name, *data;
86 GString *new = g_string_new(str);
87 gchar *ret;
88 ExifData *exif;
89
90 exif = exif_read_fd(imd->image_fd, FALSE);
91 prev = 0;
92 last = FALSE;
93
94 while (TRUE)
95 {
96 start = strchr(new->str, delim);
97 if (!start)
98 break;
99 end = strchr(start+1, delim);
100 if (!end)
101 break;
102
103 name = g_strndup(start+1, end-start-1);
104 pos = start-new->str;
105 data = g_strdup(g_hash_table_lookup(vars, name));
106 if (!data && exif)
107 data = exif_get_data_as_text(exif, name);
108
109 g_string_erase(new, pos, end-start+1);
110 if (data)
111 g_string_insert(new, pos, data);
112 if (pos-prev == 2 && new->str[pos-1] == imp)
113 {
114 g_string_erase(new, --pos, 1);
115 if (last && data)
116 {
117 g_string_insert(new, pos, sep);
118 pos += strlen(sep);
119 }
120 }
121
122 prev = data ? pos+strlen(data)-1 : pos-1;
123 last = data ? TRUE : last;
124 g_free(name);
125 g_free(data);
126 }
127
128 /* search and destroy empty lines */
129 end = new->str;
130 while (start = strchr(end, '\n'))
131 {
132 end = start;
133 while (*++(end) == '\n')
134 ;
135 g_string_erase(new, start-new->str, end-start-1);
136 }
137
138 g_strchomp(new->str);
139
140 ret = new->str;
141 g_string_free(new, FALSE);
142
143 return ret;
144 }
78 145
79 static GdkPixbuf *image_osd_info_render(ImageWindow *imd) 146 static GdkPixbuf *image_osd_info_render(ImageWindow *imd)
80 { 147 {
81 GdkPixbuf *pixbuf; 148 GdkPixbuf *pixbuf;
82 gint width, height; 149 gint width, height;
88 gint n, t; 155 gint n, t;
89 CollectionData *cd; 156 CollectionData *cd;
90 CollectInfo *info; 157 CollectInfo *info;
91 gchar *ct; 158 gchar *ct;
92 int i; 159 int i;
93 160 gint w, h;
161 GHashTable *vars;
162
163 vars = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, g_free);
164
94 name = image_get_name(imd); 165 name = image_get_name(imd);
95 if (name) 166 if (name)
96 { 167 {
97 name_escaped = g_markup_escape_text(name, -1); 168 name_escaped = g_markup_escape_text(name, -1);
98 } 169 }
146 217
147 ct = g_strdup(""); 218 ct = g_strdup("");
148 } 219 }
149 220
150 size = text_from_size_abrev(imd->size); 221 size = text_from_size_abrev(imd->size);
151 if (!name_escaped) 222 if (!imd->unknown)
152 { 223 {
153 text = g_strdup_printf(_("Untitled"));
154 }
155 else if (imd->unknown)
156 {
157 text = g_strdup_printf("%s(%d/%d) <b>%s</b>\n%s - %s", ct,
158 n, t, name_escaped,
159 text_from_time(imd->mtime), size);
160 }
161 else
162 {
163 gint w, h;
164
165 if (imd->delay_flip && 224 if (imd->delay_flip &&
166 imd->il && imd->il->pixbuf && 225 imd->il && imd->il->pixbuf &&
167 image_get_pixbuf(imd) != imd->il->pixbuf) 226 image_get_pixbuf(imd) != imd->il->pixbuf)
168 { 227 {
169 w = gdk_pixbuf_get_width(imd->il->pixbuf); 228 w = gdk_pixbuf_get_width(imd->il->pixbuf);
172 else 231 else
173 { 232 {
174 pixbuf_renderer_get_image_size(PIXBUF_RENDERER(imd->pr), &w, &h); 233 pixbuf_renderer_get_image_size(PIXBUF_RENDERER(imd->pr), &w, &h);
175 } 234 }
176 235
177 text = g_strdup_printf("%s(%d/%d) <b>%s</b>\n%d x %d - %s - %s", ct, 236 g_hash_table_insert(vars, "width", g_strdup_printf("%d", w));
178 n, t, name_escaped, 237 g_hash_table_insert(vars, "height", g_strdup_printf("%d", h));
179 w, h, 238 g_hash_table_insert(vars, "res", g_strdup_printf("%d × %d", w, h));
180 text_from_time(imd->mtime), size); 239 }
181 240
182 } 241 g_hash_table_insert(vars, "collection", g_strdup(ct));
242 g_hash_table_insert(vars, "number", g_strdup_printf("%d", n));
243 g_hash_table_insert(vars, "total", g_strdup_printf("%d", t));
244 g_hash_table_insert(vars, "name", g_strdup(name_escaped));
245 g_hash_table_insert(vars, "date", g_strdup(text_from_time(imd->mtime)));
246 g_hash_table_insert(vars, "size", g_strdup(size));
247
248 if (!name_escaped)
249 {
250 text = g_strdup_printf(_("Untitled"));
251 }
252 else
253 {
254 text = image_osd_mkinfo(fullscreen_info, imd, vars);
255 }
256
183 g_free(size); 257 g_free(size);
184 g_free(ct); 258 g_free(ct);
185 g_free(name_escaped); 259 g_free(name_escaped);
260 g_hash_table_destroy(vars);
186 261
187 { 262 {
188 GString *buf = g_string_sized_new(FILEDATA_MARKS_SIZE * 2); 263 GString *buf = g_string_sized_new(FILEDATA_MARKS_SIZE * 2);
189 FileData *fd = image_get_fd(imd); 264 FileData *fd = image_get_fd(imd);
190 265
204 pango_layout_get_pixel_size(layout, &width, &height); 279 pango_layout_get_pixel_size(layout, &width, &height);
205 280
206 width += 10; 281 width += 10;
207 height += 10; 282 height += 10;
208 283
284 /* TODO: make osd color configurable --Zas */
209 pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, width, height); 285 pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, width, height);
210 pixbuf_set_rect_fill(pixbuf, 3, 3, width-6, height-6, 240, 240, 240, 210); 286 pixbuf_set_rect_fill(pixbuf, 3, 3, width-6, height-6, 240, 240, 240, 210);
211 pixbuf_set_rect(pixbuf, 0, 0, width, height, 240, 240, 240, 80, 1, 1, 1, 1); 287 pixbuf_set_rect(pixbuf, 0, 0, width, height, 240, 240, 240, 80, 1, 1, 1, 1);
212 pixbuf_set_rect(pixbuf, 1, 1, width-2, height-2, 240, 240, 240, 130, 1, 1, 1, 1); 288 pixbuf_set_rect(pixbuf, 1, 1, width-2, height-2, 240, 240, 240, 130, 1, 1, 1, 1);
213 pixbuf_set_rect(pixbuf, 2, 2, width-4, height-4, 240, 240, 240, 180, 1, 1, 1, 1); 289 pixbuf_set_rect(pixbuf, 2, 2, width-4, height-4, 240, 240, 240, 180, 1, 1, 1, 1);