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