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