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