9a96420af1407d95c369abb109a05e75b41e4a96
[geeqie.git] / src / pan-view / pan-timeline.c
1 /*
2  * Copyright (C) 2006 John Ellis
3  * Copyright (C) 2008 - 2016 The Geeqie Team
4  *
5  * Author: John Ellis
6  *
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.
11  *
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.
16  *
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.
20  */
21
22 #include "pan-timeline.h"
23
24 #include "pan-item.h"
25 #include "pan-util.h"
26 #include "pan-view.h"
27
28 void pan_timeline_compute(PanWindow *pw, FileData *dir_fd, gint *width, gint *height)
29 {
30         GList *list;
31         GList *work;
32         gint x, y;
33         time_t tc;
34         gint total;
35         gint count;
36         PanItem *pi_month = NULL;
37         PanItem *pi_day = NULL;
38         gint month_start;
39         gint day_start;
40         gint x_width;
41         gint y_height;
42
43         list = pan_list_tree(dir_fd, SORT_NONE, TRUE, pw->ignore_symlinks);
44
45         if (pw->cache_list && pw->exif_date_enable)
46                 {
47                 pw->cache_list = pan_cache_sort(pw->cache_list, SORT_NAME, TRUE);
48                 list = filelist_sort(list, SORT_NAME, TRUE);
49                 pan_cache_sync_date(pw, list);
50                 }
51
52         pw->cache_list = pan_cache_sort(pw->cache_list, SORT_TIME, TRUE);
53         list = filelist_sort(list, SORT_TIME, TRUE);
54
55         *width = PAN_BOX_BORDER * 2;
56         *height = PAN_BOX_BORDER * 2;
57
58         x = 0;
59         y = 0;
60         month_start = y;
61         day_start = month_start;
62         x_width = 0;
63         y_height = 0;
64         tc = 0;
65         total = 0;
66         count = 0;
67         work = list;
68         while (work)
69                 {
70                 FileData *fd;
71                 PanItem *pi;
72
73                 fd = work->data;
74                 work = work->next;
75
76                 if (!pan_date_compare(fd->date, tc, PAN_DATE_LENGTH_DAY))
77                         {
78                         GList *needle;
79                         gchar *buf;
80
81                         if (!pan_date_compare(fd->date, tc, PAN_DATE_LENGTH_MONTH))
82                                 {
83                                 pi_day = NULL;
84
85                                 if (pi_month)
86                                         {
87                                         x = pi_month->x + pi_month->width + PAN_BOX_BORDER;
88                                         }
89                                 else
90                                         {
91                                         x = PAN_BOX_BORDER;
92                                         }
93
94                                 y = PAN_BOX_BORDER;
95
96                                 buf = pan_date_value_string(fd->date, PAN_DATE_LENGTH_MONTH);
97                                 pi = pan_item_text_new(pw, x, y, buf,
98                                                        PAN_TEXT_ATTR_BOLD | PAN_TEXT_ATTR_HEADING,
99                                                        PAN_TEXT_BORDER_SIZE,
100                                                        PAN_TEXT_COLOR, 255);
101                                 g_free(buf);
102                                 y += pi->height;
103
104                                 pi_month = pan_item_box_new(pw, file_data_ref(fd),
105                                                             x, y, 0, 0,
106                                                             PAN_BOX_OUTLINE_THICKNESS,
107                                                             PAN_BOX_COLOR, PAN_BOX_ALPHA,
108                                                             PAN_BOX_OUTLINE_COLOR, PAN_BOX_OUTLINE_ALPHA);
109
110                                 x += PAN_BOX_BORDER;
111                                 y += PAN_BOX_BORDER;
112                                 month_start = y;
113                                 }
114
115                         if (pi_day) x = pi_day->x + pi_day->width + PAN_BOX_BORDER;
116
117                         tc = fd->date;
118                         total = 1;
119                         count = 0;
120
121                         needle = work;
122                         while (needle)
123                                 {
124                                 FileData *nfd;
125
126                                 nfd = needle->data;
127                                 if (pan_date_compare(nfd->date, tc, PAN_DATE_LENGTH_DAY))
128                                         {
129                                         needle = needle->next;
130                                         total++;
131                                         }
132                                 else
133                                         {
134                                         needle = NULL;
135                                         }
136                                 }
137
138                         buf = pan_date_value_string(fd->date, PAN_DATE_LENGTH_WEEK);
139                         pi = pan_item_text_new(pw, x, y, buf, PAN_TEXT_ATTR_NONE,
140                                                PAN_TEXT_BORDER_SIZE,
141                                                PAN_TEXT_COLOR, 255);
142                         g_free(buf);
143
144                         y += pi->height;
145
146                         pi_day = pan_item_box_new(pw, file_data_ref(fd), x, y, 0, 0,
147                                                   PAN_BOX_OUTLINE_THICKNESS,
148                                                   PAN_BOX_COLOR, PAN_BOX_ALPHA,
149                                                   PAN_BOX_OUTLINE_COLOR, PAN_BOX_OUTLINE_ALPHA);
150
151                         x += PAN_BOX_BORDER;
152                         y += PAN_BOX_BORDER;
153                         day_start = y;
154                         }
155
156                 if (pw->size > PAN_IMAGE_SIZE_THUMB_LARGE)
157                         {
158                         pi = pan_item_image_new(pw, fd, x, y, 10, 10);
159                         if (pi->width > x_width) x_width = pi->width;
160                         y_height = pi->height;
161                         }
162                 else
163                         {
164                         pi = pan_item_thumb_new(pw, fd, x, y);
165                         x_width = PAN_THUMB_SIZE;
166                         y_height = PAN_THUMB_SIZE;
167                         }
168
169                 pan_item_size_by_item(pi_day, pi, PAN_BOX_BORDER);
170                 pan_item_size_by_item(pi_month, pi_day, PAN_BOX_BORDER);
171
172                 total--;
173                 count++;
174
175                 if (total > 0 && count < PAN_GROUP_MAX)
176                         {
177                         y += y_height + PAN_THUMB_GAP;
178                         }
179                 else
180                         {
181                         x += x_width + PAN_THUMB_GAP;
182                         x_width = 0;
183                         count = 0;
184
185                         if (total > 0)
186                                 y = day_start;
187                         else
188                                 y = month_start;
189                         }
190
191                 pan_item_size_coordinates(pi_month, PAN_BOX_BORDER, width, height);
192                 }
193
194         g_list_free(list);
195 }
196 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */