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