Mercurial > geeqie
annotate src/pan-calendar.c @ 639:8b95e1859fee
Rework read_*_option():
- read_u?int_option() now interpret a value of "true" as 1
- read_bool_option() now interpret any value different from 0 as true.
- make functions return TRUE on successful read, FALSE else
Theses changes will help to maintain compatibility when options are modified.
author | zas_ |
---|---|
date | Mon, 12 May 2008 08:52:17 +0000 |
parents | 135570a8bd96 |
children | 8268cbe682f1 |
rev | line source |
---|---|
105 | 1 /* |
196 | 2 * Geeqie |
105 | 3 * (C) 2006 John Ellis |
475 | 4 * Copyright (C) 2008 The Geeqie Team |
105 | 5 * |
6 * Author: John Ellis | |
7 * | |
8 * This software is released under the GNU General Public License (GNU GPL). | |
9 * Please read the included file COPYING for more information. | |
10 * This software comes with no warranty of any kind, use at your own risk! | |
11 */ | |
12 | |
13 | |
281 | 14 #include "main.h" |
105 | 15 #include "pan-types.h" |
16 | |
507 | 17 #include "debug.h" |
18 | |
105 | 19 #include <math.h> |
20 | |
21 | |
22 #define PAN_CAL_POPUP_COLOR 220, 220, 220 | |
23 #define PAN_CAL_POPUP_ALPHA 255 | |
24 #define PAN_CAL_POPUP_BORDER 1 | |
25 #define PAN_CAL_POPUP_BORDER_COLOR 0, 0, 0 | |
26 #define PAN_CAL_POPUP_TEXT_COLOR 0, 0, 0 | |
27 | |
28 #define PAN_CAL_DAY_WIDTH 100 | |
29 #define PAN_CAL_DAY_HEIGHT 80 | |
30 | |
31 #define PAN_CAL_DAY_COLOR 255, 255, 255 | |
32 #define PAN_CAL_DAY_ALPHA 220 | |
33 #define PAN_CAL_DAY_BORDER 2 | |
34 #define PAN_CAL_DAY_BORDER_COLOR 0, 0, 0 | |
35 #define PAN_CAL_DAY_TEXT_COLOR 0, 0, 0 | |
36 | |
37 #define PAN_CAL_MONTH_COLOR 255, 255, 255 | |
38 #define PAN_CAL_MONTH_ALPHA 200 | |
39 #define PAN_CAL_MONTH_BORDER 4 | |
40 #define PAN_CAL_MONTH_BORDER_COLOR 0, 0, 0 | |
41 #define PAN_CAL_MONTH_TEXT_COLOR 0, 0, 0 | |
42 | |
43 #define PAN_CAL_DOT_SIZE 3 | |
44 #define PAN_CAL_DOT_GAP 2 | |
45 #define PAN_CAL_DOT_COLOR 128, 128, 128 | |
46 #define PAN_CAL_DOT_ALPHA 128 | |
47 | |
48 | |
49 /* | |
50 *----------------------------------------------------------------------------- | |
51 * calendar | |
52 *----------------------------------------------------------------------------- | |
53 */ | |
54 | |
55 void pan_calendar_update(PanWindow *pw, PanItem *pi_day) | |
56 { | |
57 PanItem *pbox; | |
58 PanItem *pi; | |
59 GList *list; | |
60 GList *work; | |
61 gint x1, y1, x2, y2, x3, y3; | |
62 gint x, y, w, h; | |
63 gint grid; | |
64 gint column; | |
442 | 65 |
105 | 66 while ((pi = pan_item_find_by_key(pw, PAN_ITEM_NONE, "day_bubble"))) pan_item_remove(pw, pi); |
67 | |
68 if (!pi_day || pi_day->type != PAN_ITEM_BOX || | |
69 !pi_day->key || strcmp(pi_day->key, "day") != 0) return; | |
70 | |
71 list = pan_layout_intersect(pw, pi_day->x, pi_day->y, pi_day->width, pi_day->height); | |
72 | |
73 work = list; | |
74 while (work) | |
75 { | |
76 PanItem *dot; | |
77 GList *node; | |
78 | |
79 dot = work->data; | |
80 node = work; | |
81 work = work->next; | |
82 | |
83 if (dot->type != PAN_ITEM_BOX || !dot->fd || | |
84 !dot->key || strcmp(dot->key, "dot") != 0) | |
85 { | |
86 list = g_list_delete_link(list, node); | |
87 } | |
88 } | |
89 | |
90 #if 0 | |
91 if (!list) return; | |
92 #endif | |
93 | |
94 grid = (gint)(sqrt(g_list_length(list)) + 0.5); | |
95 | |
96 x = pi_day->x + pi_day->width + 4; | |
97 y = pi_day->y; | |
98 | |
99 #if 0 | |
100 if (y + grid * (PAN_THUMB_SIZE + PAN_THUMB_GAP) + PAN_BOX_BORDER * 4 > pw->pr->image_height) | |
101 { | |
102 y = pw->pr->image_height - (grid * (PAN_THUMB_SIZE + PAN_THUMB_GAP) + PAN_BOX_BORDER * 4); | |
103 } | |
104 #endif | |
105 | |
106 pbox = pan_item_box_new(pw, NULL, x, y, PAN_BOX_BORDER, PAN_BOX_BORDER, | |
107 PAN_CAL_POPUP_BORDER, | |
108 PAN_CAL_POPUP_COLOR, PAN_CAL_POPUP_ALPHA, | |
109 PAN_CAL_POPUP_BORDER_COLOR, PAN_CAL_POPUP_ALPHA); | |
110 pan_item_set_key(pbox, "day_bubble"); | |
111 | |
112 if (pi_day->fd) | |
113 { | |
114 PanItem *plabel; | |
115 gchar *buf; | |
116 | |
117 buf = pan_date_value_string(pi_day->fd->date, PAN_DATE_LENGTH_WEEK); | |
118 plabel = pan_item_text_new(pw, x, y, buf, PAN_TEXT_ATTR_BOLD | PAN_TEXT_ATTR_HEADING, | |
119 PAN_TEXT_BORDER_SIZE, | |
120 PAN_CAL_POPUP_TEXT_COLOR, 255); | |
121 pan_item_set_key(plabel, "day_bubble"); | |
122 g_free(buf); | |
123 | |
124 pan_item_size_by_item(pbox, plabel, 0); | |
125 | |
126 y += plabel->height; | |
127 } | |
128 | |
129 if (list) | |
130 { | |
131 column = 0; | |
132 | |
133 x += PAN_BOX_BORDER; | |
134 y += PAN_BOX_BORDER; | |
135 | |
136 work = list; | |
137 while (work) | |
138 { | |
139 PanItem *dot; | |
140 | |
141 dot = work->data; | |
142 work = work->next; | |
143 | |
144 if (dot->fd) | |
145 { | |
146 PanItem *pimg; | |
147 | |
138 | 148 pimg = pan_item_thumb_new(pw, file_data_ref(dot->fd), x, y); |
105 | 149 pan_item_set_key(pimg, "day_bubble"); |
150 | |
151 pan_item_size_by_item(pbox, pimg, PAN_BOX_BORDER); | |
152 | |
153 column++; | |
154 if (column < grid) | |
155 { | |
156 x += PAN_THUMB_SIZE + PAN_THUMB_GAP; | |
157 } | |
158 else | |
159 { | |
160 column = 0; | |
161 x = pbox->x + PAN_BOX_BORDER; | |
162 y += PAN_THUMB_SIZE + PAN_THUMB_GAP; | |
163 } | |
164 } | |
165 } | |
166 } | |
167 | |
168 x1 = pi_day->x + pi_day->width - 8; | |
169 y1 = pi_day->y + 8; | |
170 x2 = pbox->x + 1; | |
171 y2 = pbox->y + MIN(42, pbox->height); | |
172 x3 = pbox->x + 1; | |
173 y3 = MAX(pbox->y, y2 - 30); | |
174 util_clip_triangle(x1, y1, x2, y2, x3, y3, | |
175 &x, &y, &w, &h); | |
176 | |
177 pi = pan_item_tri_new(pw, NULL, x, y, w, h, | |
178 x1, y1, x2, y2, x3, y3, | |
179 PAN_CAL_POPUP_COLOR, PAN_CAL_POPUP_ALPHA); | |
180 pan_item_tri_border(pi, PAN_BORDER_1 | PAN_BORDER_3, PAN_CAL_POPUP_BORDER_COLOR, PAN_CAL_POPUP_ALPHA); | |
181 pan_item_set_key(pi, "day_bubble"); | |
182 pan_item_added(pw, pi); | |
183 | |
184 pan_item_box_shadow(pbox, PAN_SHADOW_OFFSET * 2, PAN_SHADOW_FADE * 2); | |
185 pan_item_added(pw, pbox); | |
186 | |
187 pan_layout_resize(pw); | |
188 } | |
189 | |
190 void pan_calendar_compute(PanWindow *pw, const gchar *path, gint *width, gint *height) | |
191 { | |
192 GList *list; | |
193 GList *work; | |
194 gint x, y; | |
195 time_t tc; | |
196 gint count; | |
197 gint day_max; | |
198 gint day_width; | |
199 gint day_height; | |
200 gint grid; | |
201 gint year = 0; | |
202 gint month = 0; | |
203 gint end_year = 0; | |
204 gint end_month = 0; | |
205 | |
206 list = pan_list_tree(path, SORT_NONE, TRUE, pw->ignore_symlinks); | |
207 | |
208 if (pw->cache_list && pw->exif_date_enable) | |
209 { | |
138 | 210 pw->cache_list = pan_cache_sort(pw->cache_list, SORT_NAME, TRUE); |
105 | 211 list = filelist_sort(list, SORT_NAME, TRUE); |
212 pan_cache_sync_date(pw, list); | |
213 } | |
214 | |
138 | 215 pw->cache_list = pan_cache_sort(pw->cache_list, SORT_TIME, TRUE); |
105 | 216 list = filelist_sort(list, SORT_TIME, TRUE); |
217 | |
218 day_max = 0; | |
219 count = 0; | |
220 tc = 0; | |
221 work = list; | |
222 while (work) | |
223 { | |
224 FileData *fd; | |
225 | |
226 fd = work->data; | |
227 work = work->next; | |
228 | |
229 if (!pan_date_compare(fd->date, tc, PAN_DATE_LENGTH_DAY)) | |
230 { | |
231 count = 0; | |
232 tc = fd->date; | |
233 } | |
234 else | |
235 { | |
236 count++; | |
237 if (day_max < count) day_max = count; | |
238 } | |
239 } | |
240 | |
506
fc9c8a3e1a8b
Handle the newline in DEBUG_N() macro instead of adding one
zas_
parents:
495
diff
changeset
|
241 DEBUG_1("biggest day contains %d images", day_max); |
105 | 242 |
243 grid = (gint)(sqrt((double)day_max) + 0.5) * (PAN_THUMB_SIZE + PAN_SHADOW_OFFSET * 2 + PAN_THUMB_GAP); | |
244 day_width = MAX(PAN_CAL_DAY_WIDTH, grid); | |
245 day_height = MAX(PAN_CAL_DAY_HEIGHT, grid); | |
246 | |
247 if (list) | |
248 { | |
249 FileData *fd = list->data; | |
250 | |
251 year = pan_date_value(fd->date, PAN_DATE_LENGTH_YEAR); | |
252 month = pan_date_value(fd->date, PAN_DATE_LENGTH_MONTH); | |
253 } | |
254 | |
255 work = g_list_last(list); | |
256 if (work) | |
257 { | |
258 FileData *fd = work->data; | |
259 end_year = pan_date_value(fd->date, PAN_DATE_LENGTH_YEAR); | |
260 end_month = pan_date_value(fd->date, PAN_DATE_LENGTH_MONTH); | |
261 } | |
262 | |
263 *width = PAN_BOX_BORDER * 2; | |
264 *height = PAN_BOX_BORDER * 2; | |
265 | |
266 x = PAN_BOX_BORDER; | |
267 y = PAN_BOX_BORDER; | |
268 | |
269 work = list; | |
270 while (work && (year < end_year || (year == end_year && month <= end_month))) | |
271 { | |
272 PanItem *pi_month; | |
273 PanItem *pi_text; | |
274 gint day; | |
275 gint days; | |
276 gint col; | |
277 gint row; | |
278 time_t dt; | |
279 gchar *buf; | |
280 | |
281 /* figure last second of this month */ | |
282 dt = pan_date_to_time((month == 12) ? year + 1 : year, (month == 12) ? 1 : month + 1, 1); | |
283 dt -= 60 * 60 * 24; | |
284 | |
285 /* anything to show this month? */ | |
286 if (!pan_date_compare(((FileData *)(work->data))->date, dt, PAN_DATE_LENGTH_MONTH)) | |
287 { | |
288 month ++; | |
289 if (month > 12) | |
290 { | |
291 year++; | |
292 month = 1; | |
293 } | |
294 continue; | |
295 } | |
296 | |
297 days = pan_date_value(dt, PAN_DATE_LENGTH_DAY); | |
298 dt = pan_date_to_time(year, month, 1); | |
299 col = pan_date_value(dt, PAN_DATE_LENGTH_WEEK); | |
300 row = 1; | |
301 | |
302 x = PAN_BOX_BORDER; | |
303 | |
304 pi_month = pan_item_box_new(pw, NULL, x, y, PAN_CAL_DAY_WIDTH * 7, PAN_CAL_DAY_HEIGHT / 4, | |
305 PAN_CAL_MONTH_BORDER, | |
306 PAN_CAL_MONTH_COLOR, PAN_CAL_MONTH_ALPHA, | |
307 PAN_CAL_MONTH_BORDER_COLOR, PAN_CAL_MONTH_ALPHA); | |
308 buf = pan_date_value_string(dt, PAN_DATE_LENGTH_MONTH); | |
309 pi_text = pan_item_text_new(pw, x, y, buf, | |
310 PAN_TEXT_ATTR_BOLD | PAN_TEXT_ATTR_HEADING, | |
311 PAN_TEXT_BORDER_SIZE, | |
312 PAN_CAL_MONTH_TEXT_COLOR, 255); | |
313 g_free(buf); | |
314 pi_text->x = pi_month->x + (pi_month->width - pi_text->width) / 2; | |
315 | |
316 pi_month->height = pi_text->y + pi_text->height - pi_month->y; | |
317 | |
318 x = PAN_BOX_BORDER + col * PAN_CAL_DAY_WIDTH; | |
319 y = pi_month->y + pi_month->height + PAN_BOX_BORDER; | |
320 | |
321 for (day = 1; day <= days; day++) | |
322 { | |
323 FileData *fd; | |
324 PanItem *pi_day; | |
325 gint dx, dy; | |
326 gint n = 0; | |
301 | 327 char fake_path[20]; |
105 | 328 |
329 dt = pan_date_to_time(year, month, day); | |
442 | 330 |
331 /* | |
332 * Create a FileData entry that represents the given day. | |
301 | 333 * It does not correspond to any real file |
442 | 334 */ |
335 | |
336 g_snprintf(fake_path, sizeof(fake_path), "//%04d-%02d-%02d", year, month, day); | |
301 | 337 fd = file_data_new_simple(fake_path); |
105 | 338 fd->date = dt; |
339 pi_day = pan_item_box_new(pw, fd, x, y, PAN_CAL_DAY_WIDTH, PAN_CAL_DAY_HEIGHT, | |
340 PAN_CAL_DAY_BORDER, | |
341 PAN_CAL_DAY_COLOR, PAN_CAL_DAY_ALPHA, | |
342 PAN_CAL_DAY_BORDER_COLOR, PAN_CAL_DAY_ALPHA); | |
343 pan_item_set_key(pi_day, "day"); | |
344 | |
345 dx = x + PAN_CAL_DOT_GAP * 2; | |
346 dy = y + PAN_CAL_DOT_GAP * 2; | |
347 | |
348 fd = (work) ? work->data : NULL; | |
349 while (fd && pan_date_compare(fd->date, dt, PAN_DATE_LENGTH_DAY)) | |
350 { | |
351 PanItem *pi; | |
352 | |
353 pi = pan_item_box_new(pw, fd, dx, dy, PAN_CAL_DOT_SIZE, PAN_CAL_DOT_SIZE, | |
354 0, | |
355 PAN_CAL_DOT_COLOR, PAN_CAL_DOT_ALPHA, | |
356 0, 0, 0, 0); | |
357 pan_item_set_key(pi, "dot"); | |
358 | |
359 dx += PAN_CAL_DOT_SIZE + PAN_CAL_DOT_GAP; | |
360 if (dx + PAN_CAL_DOT_SIZE > pi_day->x + pi_day->width - PAN_CAL_DOT_GAP * 2) | |
361 { | |
362 dx = x + PAN_CAL_DOT_GAP * 2; | |
363 dy += PAN_CAL_DOT_SIZE + PAN_CAL_DOT_GAP; | |
364 } | |
365 if (dy + PAN_CAL_DOT_SIZE > pi_day->y + pi_day->height - PAN_CAL_DOT_GAP * 2) | |
366 { | |
367 /* must keep all dots within respective day even if it gets ugly */ | |
368 dy = y + PAN_CAL_DOT_GAP * 2; | |
369 } | |
370 | |
371 n++; | |
372 | |
373 work = work->next; | |
374 fd = (work) ? work->data : NULL; | |
375 } | |
376 | |
377 if (n > 0) | |
378 { | |
379 PanItem *pi; | |
380 | |
381 pi_day->color_r = MAX(pi_day->color_r - 61 - n * 3, 80); | |
382 pi_day->color_g = pi_day->color_r; | |
383 | |
384 buf = g_strdup_printf("( %d )", n); | |
385 pi = pan_item_text_new(pw, x, y, buf, PAN_TEXT_ATTR_NONE, | |
386 PAN_TEXT_BORDER_SIZE, | |
387 PAN_CAL_DAY_TEXT_COLOR, 255); | |
388 g_free(buf); | |
389 | |
390 pi->x = pi_day->x + (pi_day->width - pi->width) / 2; | |
391 pi->y = pi_day->y + (pi_day->height - pi->height) / 2; | |
392 } | |
393 | |
394 buf = g_strdup_printf("%d", day); | |
395 pan_item_text_new(pw, x + 4, y + 4, buf, PAN_TEXT_ATTR_BOLD | PAN_TEXT_ATTR_HEADING, | |
396 PAN_TEXT_BORDER_SIZE, | |
397 PAN_CAL_DAY_TEXT_COLOR, 255); | |
398 g_free(buf); | |
399 | |
400 | |
401 pan_item_size_coordinates(pi_day, PAN_BOX_BORDER, width, height); | |
402 | |
403 col++; | |
404 if (col > 6) | |
405 { | |
406 col = 0; | |
407 row++; | |
408 x = PAN_BOX_BORDER; | |
409 y += PAN_CAL_DAY_HEIGHT; | |
410 } | |
411 else | |
412 { | |
413 x += PAN_CAL_DAY_WIDTH; | |
414 } | |
415 } | |
416 | |
417 if (col > 0) y += PAN_CAL_DAY_HEIGHT; | |
418 y += PAN_BOX_BORDER * 2; | |
419 | |
420 month ++; | |
421 if (month > 12) | |
422 { | |
423 year++; | |
424 month = 1; | |
425 } | |
426 } | |
427 | |
428 *width += grid; | |
429 *height = MAX(*height, grid + PAN_BOX_BORDER * 2 * 2); | |
430 | |
431 g_list_free(list); | |
432 } |