2 * Copyright (C) 2006 John Ellis
3 * Copyright (C) 2008 - 2016 The Geeqie Team
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include "pan-calendar.h"
29 #include "pan-view-filter.h"
30 #include "pixbuf-util.h"
32 #define PAN_CAL_POPUP_COLOR 220, 220, 220
34 PAN_CAL_POPUP_ALPHA = 255,
35 PAN_CAL_POPUP_BORDER = 1
37 #define PAN_CAL_POPUP_BORDER_COLOR 0, 0, 0
38 #define PAN_CAL_POPUP_TEXT_COLOR 0, 0, 0
41 PAN_CAL_DAY_WIDTH = 100,
42 PAN_CAL_DAY_HEIGHT = 80
45 #define PAN_CAL_DAY_COLOR 255, 255, 255
47 PAN_CAL_DAY_ALPHA = 220,
48 PAN_CAL_DAY_BORDER = 2
50 #define PAN_CAL_DAY_BORDER_COLOR 0, 0, 0
51 #define PAN_CAL_DAY_TEXT_COLOR 0, 0, 0
53 #define PAN_CAL_MONTH_COLOR 255, 255, 255
55 PAN_CAL_MONTH_ALPHA = 200,
56 PAN_CAL_MONTH_BORDER = 4
58 #define PAN_CAL_MONTH_BORDER_COLOR 0, 0, 0
59 #define PAN_CAL_MONTH_TEXT_COLOR 0, 0, 0
65 #define PAN_CAL_DOT_COLOR 128, 128, 128
67 PAN_CAL_DOT_ALPHA = 128
70 #define PAN_CAL_DAY_OF_WEEK_COLOR 128, 128, 128
73 *-----------------------------------------------------------------------------
75 *-----------------------------------------------------------------------------
78 void pan_calendar_update(PanWindow *pw, PanItem *pi_day)
97 while ((pi = pan_item_find_by_key(pw, PAN_ITEM_NONE, "day_bubble"))) pan_item_remove(pw, pi);
99 if (!pi_day || pi_day->type != PAN_ITEM_BOX ||
100 !pi_day->key || strcmp(pi_day->key, "day") != 0) return;
102 list = pan_layout_intersect(pw, pi_day->x, pi_day->y, pi_day->width, pi_day->height);
110 dot = static_cast<PanItem *>(work->data);
114 if (dot->type != PAN_ITEM_BOX || !dot->fd ||
115 !dot->key || strcmp(dot->key, "dot") != 0)
117 list = g_list_delete_link(list, node);
121 grid = static_cast<gint>(sqrt(g_list_length(list)) + 0.5);
123 x = pi_day->x + pi_day->width + 4;
126 pbox = pan_item_box_new(pw, nullptr, x, y, PAN_BOX_BORDER, PAN_BOX_BORDER,
127 PAN_CAL_POPUP_BORDER,
128 PAN_CAL_POPUP_COLOR, PAN_CAL_POPUP_ALPHA,
129 PAN_CAL_POPUP_BORDER_COLOR, PAN_CAL_POPUP_ALPHA);
130 pan_item_set_key(pbox, "day_bubble");
137 buf = pan_date_value_string(pi_day->fd->date, PAN_DATE_LENGTH_WEEK);
138 plabel = pan_item_text_new(pw, x, y, buf, static_cast<PanTextAttrType>(PAN_TEXT_ATTR_BOLD | PAN_TEXT_ATTR_HEADING),
140 PAN_CAL_POPUP_TEXT_COLOR, 255);
141 pan_item_set_key(plabel, "day_bubble");
144 pan_item_size_by_item(pbox, plabel, 0);
161 dot = static_cast<PanItem *>(work->data);
168 pimg = pan_item_thumb_new(pw, file_data_ref(dot->fd), x, y);
169 pan_item_set_key(pimg, "day_bubble");
171 pan_item_size_by_item(pbox, pimg, PAN_BOX_BORDER);
176 x += PAN_THUMB_SIZE + PAN_THUMB_GAP;
181 x = pbox->x + PAN_BOX_BORDER;
182 y += PAN_THUMB_SIZE + PAN_THUMB_GAP;
188 x1 = pi_day->x + pi_day->width - 8;
191 y2 = pbox->y + MIN(42, pbox->height);
193 y3 = MAX(pbox->y, y2 - 30);
194 util_clip_triangle(x1, y1, x2, y2, x3, y3,
197 pi = pan_item_tri_new(pw, nullptr, x, y, w, h,
198 x1, y1, x2, y2, x3, y3,
199 PAN_CAL_POPUP_COLOR, PAN_CAL_POPUP_ALPHA);
200 pan_item_tri_border(pi, PAN_BORDER_1 | PAN_BORDER_3, PAN_CAL_POPUP_BORDER_COLOR, PAN_CAL_POPUP_ALPHA);
201 pan_item_set_key(pi, "day_bubble");
202 pan_item_added(pw, pi);
204 pan_item_box_shadow(pbox, PAN_SHADOW_OFFSET * 2, PAN_SHADOW_FADE * 2);
205 pan_item_added(pw, pbox);
207 pan_layout_resize(pw);
210 void pan_calendar_compute(PanWindow *pw, FileData *dir_fd, gint *width, gint *height)
226 list = pan_list_tree(dir_fd, SORT_NONE, TRUE, TRUE, pw->ignore_symlinks);
227 pan_filter_fd_list(&list, pw->filter_ui->filter_elements, pw->filter_ui->filter_classes);
229 if (pw->cache_list && pw->exif_date_enable)
231 pw->cache_list = pan_cache_sort(pw->cache_list, SORT_NAME, TRUE, TRUE);
232 list = filelist_sort(list, SORT_NAME, TRUE, TRUE);
233 pan_cache_sync_date(pw, list);
236 pw->cache_list = pan_cache_sort(pw->cache_list, SORT_TIME, TRUE, TRUE);
237 list = filelist_sort(list, SORT_TIME, TRUE, TRUE);
247 fd = static_cast<FileData *>(work->data);
250 if (!pan_date_compare(fd->date, tc, PAN_DATE_LENGTH_DAY))
258 if (day_max < count) day_max = count;
262 DEBUG_1("biggest day contains %d images", day_max);
264 grid = static_cast<gint>(sqrt(static_cast<gdouble>(day_max)) + 0.5) * (PAN_THUMB_SIZE + PAN_SHADOW_OFFSET * 2 + PAN_THUMB_GAP);
268 auto fd = static_cast<FileData *>(list->data);
270 year = pan_date_value(fd->date, PAN_DATE_LENGTH_YEAR);
271 month = pan_date_value(fd->date, PAN_DATE_LENGTH_MONTH);
274 work = g_list_last(list);
277 auto fd = static_cast<FileData *>(work->data);
278 end_year = pan_date_value(fd->date, PAN_DATE_LENGTH_YEAR);
279 end_month = pan_date_value(fd->date, PAN_DATE_LENGTH_MONTH);
282 *width = PAN_BOX_BORDER * 2;
283 *height = PAN_BOX_BORDER * 2;
289 while (work && (year < end_year || (year == end_year && month <= end_month)))
293 PanItem *pi_day_number;
301 /* figure last second of this month */
302 dt = pan_date_to_time((month == 12) ? year + 1 : year, (month == 12) ? 1 : month + 1, 1);
305 /* anything to show this month? */
306 if (!pan_date_compare((static_cast<FileData *>(work->data))->date, dt, PAN_DATE_LENGTH_MONTH))
317 days = pan_date_value(dt, PAN_DATE_LENGTH_DAY);
318 dt = pan_date_to_time(year, month, 1);
319 col = pan_date_value(dt, PAN_DATE_LENGTH_WEEK);
320 col = col - (date_get_first_day_of_week() - 1);
321 if (col < 0) col = col + 7;
326 pi_month = pan_item_box_new(pw, nullptr, x, y, PAN_CAL_DAY_WIDTH * 7, PAN_CAL_DAY_HEIGHT / 4,
327 PAN_CAL_MONTH_BORDER,
328 PAN_CAL_MONTH_COLOR, PAN_CAL_MONTH_ALPHA,
329 PAN_CAL_MONTH_BORDER_COLOR, PAN_CAL_MONTH_ALPHA);
330 buf = pan_date_value_string(dt, PAN_DATE_LENGTH_MONTH);
331 pi_text = pan_item_text_new(pw, x, y, buf,
332 static_cast<PanTextAttrType>(PAN_TEXT_ATTR_BOLD | PAN_TEXT_ATTR_HEADING),
334 PAN_CAL_MONTH_TEXT_COLOR, 255);
336 pi_text->x = pi_month->x + (pi_month->width - pi_text->width) / 2;
338 pi_month->height = pi_text->y + pi_text->height - pi_month->y;
340 x = PAN_BOX_BORDER + col * PAN_CAL_DAY_WIDTH;
341 y = pi_month->y + pi_month->height + PAN_BOX_BORDER;
343 for (day = 1; day <= days; day++)
352 dt = pan_date_to_time(year, month, day);
355 * Create a FileData entry that represents the given day.
356 * It does not correspond to any real file
359 g_snprintf(fake_path, sizeof(fake_path), "//%04d-%02d-%02d", year, month, day);
360 fd = file_data_new_no_grouping(fake_path);
362 pi_day = pan_item_box_new(pw, fd, x, y, PAN_CAL_DAY_WIDTH, PAN_CAL_DAY_HEIGHT,
364 PAN_CAL_DAY_COLOR, PAN_CAL_DAY_ALPHA,
365 PAN_CAL_DAY_BORDER_COLOR, PAN_CAL_DAY_ALPHA);
366 pan_item_set_key(pi_day, "day");
368 dx = x + PAN_CAL_DOT_GAP * 2;
369 dy = y + PAN_CAL_DOT_GAP * 2;
371 fd = static_cast<FileData *>((work) ? work->data : nullptr);
372 while (fd && pan_date_compare(fd->date, dt, PAN_DATE_LENGTH_DAY))
376 pi = pan_item_box_new(pw, fd, dx, dy, PAN_CAL_DOT_SIZE, PAN_CAL_DOT_SIZE,
378 PAN_CAL_DOT_COLOR, PAN_CAL_DOT_ALPHA,
380 pan_item_set_key(pi, "dot");
382 dx += PAN_CAL_DOT_SIZE + PAN_CAL_DOT_GAP;
383 if (dx + PAN_CAL_DOT_SIZE > pi_day->x + pi_day->width - PAN_CAL_DOT_GAP * 2)
385 dx = x + PAN_CAL_DOT_GAP * 2;
386 dy += PAN_CAL_DOT_SIZE + PAN_CAL_DOT_GAP;
388 if (dy + PAN_CAL_DOT_SIZE > pi_day->y + pi_day->height - PAN_CAL_DOT_GAP * 2)
390 /* must keep all dots within respective day even if it gets ugly */
391 dy = y + PAN_CAL_DOT_GAP * 2;
397 fd = static_cast<FileData *>((work) ? work->data : nullptr);
404 pi_day->color_r = MAX(pi_day->color_r - 61 - n * 3, 80);
405 pi_day->color_g = pi_day->color_r;
407 buf = g_strdup_printf("( %d )", n);
408 pi = pan_item_text_new(pw, x, y, buf, PAN_TEXT_ATTR_NONE,
410 PAN_CAL_DAY_TEXT_COLOR, 255);
413 pi->x = pi_day->x + (pi_day->width - pi->width) / 2;
414 pi->y = pi_day->y + (pi_day->height - pi->height) / 2;
417 buf = g_strdup_printf("%d", day);
418 pi_day_number = pan_item_text_new(pw, x + 4, y + 4, buf, static_cast<PanTextAttrType>(PAN_TEXT_ATTR_BOLD | PAN_TEXT_ATTR_HEADING),
420 PAN_CAL_DAY_TEXT_COLOR, 255);
423 day_of_week = date_get_first_day_of_week() + col;
424 if (day_of_week > 7) day_of_week = day_of_week - 7;
426 buf = date_get_abbreviated_day_name(day_of_week);
427 pan_item_text_new(pw, x + 4 + pi_day_number->width + 4, y + 4, buf, PAN_TEXT_ATTR_NONE,
429 PAN_CAL_DAY_OF_WEEK_COLOR, 255);
432 pan_item_size_coordinates(pi_day, PAN_BOX_BORDER, width, height);
440 y += PAN_CAL_DAY_HEIGHT;
444 x += PAN_CAL_DAY_WIDTH;
448 if (col > 0) y += PAN_CAL_DAY_HEIGHT;
449 y += PAN_BOX_BORDER * 2;
460 *height = MAX(*height, grid + PAN_BOX_BORDER * 2 * 2);
464 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */