1919 * Authored by: Alain M. <alainmh23@gmail.com>
2020 */
2121
22- public class Views.Scheduled.ScheduledDay : Gtk . ListBoxRow {
22+ public class Views.Scheduled.ScheduledDay : Views . Scheduled . ScheduledSection {
2323 public GLib . DateTime date { get ; construct; }
2424
25- private Gtk . ListBox listbox;
26- private Gtk . Revealer listbox_revealer;
27-
28- #if WITH_EVOLUTION
29- private Widgets . EventsList event_list;
30- private Gtk . Revealer event_list_revealer;
31- #endif
32-
33- private Gee . HashMap<string, Layouts . ItemRow > items;
34-
35- private bool has_items {
36- get {
37- return items. size > 0 ;
38- }
39- }
40-
41- private Gee . HashMap<ulong, weak GLib . Object > signal_map = new Gee .HashMap<ulong, weak GLib . Object > ();
25+ private Gtk . Box header_content;
4226
4327 public ScheduledDay (GLib .DateTime date ) {
4428 Object (
@@ -55,19 +39,14 @@ public class Views.Scheduled.ScheduledDay : Gtk.ListBoxRow {
5539 add_css_class (" transition" );
5640 add_css_class (" no-padding" );
5741
58- items = new Gee .HashMap<string, Layouts . ItemRow > ();
59-
6042 var day_label = new Gtk .Label (date. get_day_of_month (). to_string ()) {
6143 halign = Gtk . Align . START
6244 };
6345 day_label. add_css_class (" font-bold" );
6446
65- var date_format_label = new Gtk .Label (
66- date. format (" %a " )
67- ) {
47+ var date_format_label = new Gtk .Label (date. format (" %a " )) {
6848 halign = Gtk . Align . START
6949 };
70-
7150 date_format_label. add_css_class (" dimmed" );
7251
7352 var title_box = new Gtk .Box (Gtk . Orientation . HORIZONTAL , 6 ) {
@@ -77,36 +56,10 @@ public class Views.Scheduled.ScheduledDay : Gtk.ListBoxRow {
7756 title_box. append (day_label);
7857 title_box. append (date_format_label);
7958
80- #if WITH_EVOLUTION
81- event_list = new Widgets .EventsList .for_day (date) {
82- hexpand = true ,
83- valign = Gtk . Align . START ,
84- margin_top = 6
85- };
8659
87- event_list_revealer = new Gtk .Revealer () {
88- transition_type = Gtk . RevealerTransitionType . SLIDE_DOWN ,
89- reveal_child = event_list. has_items,
90- child = event_list
91- };
92- #endif
9360
94- var header_content = new Gtk .Box (Gtk . Orientation . VERTICAL , 0 ) {
95- hexpand = true ,
96- valign = Gtk . Align . START ,
97- margin_start = 30 ,
98- margin_end = 24
99- };
100-
101- header_content. append (title_box);
102- header_content. append (new Gtk .Separator (Gtk . Orientation . HORIZONTAL ) {
103- margin_top = 6 ,
104- margin_bottom = 3
105- });
106-
107- #if WITH_EVOLUTION
108- header_content. append (event_list_revealer);
109- #endif
61+ header_content = create_header (title_box);
62+ setup_events (header_content);
11063
11164 listbox = new Gtk .ListBox () {
11265 valign = Gtk . Align . START ,
@@ -139,19 +92,16 @@ public class Views.Scheduled.ScheduledDay : Gtk.ListBoxRow {
13992 content. append (listbox_revealer);
14093
14194 child = content;
95+
96+ setup_listbox ();
97+ setup_item_signals ();
14298 add_items ();
14399
144100 Timeout . add (listbox_revealer. transition_duration, () = > {
145101 listbox_revealer. reveal_child = has_items;
146102 return GLib . Source . REMOVE ;
147103 });
148104
149- signal_map[Services . Store . instance (). item_added. connect (valid_add_item)] = Services . Store . instance ();
150- signal_map[Services . Store . instance (). item_deleted. connect (valid_delete_item)] = Services . Store . instance ();
151- signal_map[Services . Store . instance (). item_updated. connect (valid_update_item)] = Services . Store . instance ();
152- signal_map[Services . Store . instance (). item_archived. connect (valid_delete_item)] = Services . Store . instance ();
153- signal_map[Services . Store . instance (). item_unarchived. connect (valid_add_item)] = Services . Store . instance ();
154-
155105 signal_map[Services . EventBus . get_default (). item_moved. connect ((item) = > {
156106 if (items. has_key (item. id)) {
157107 items[item. id]. update_request ();
@@ -160,68 +110,14 @@ public class Views.Scheduled.ScheduledDay : Gtk.ListBoxRow {
160110 listbox. invalidate_filter ();
161111 })] = Services . EventBus . get_default ();
162112
163- signal_map[Services . Settings . get_default (). settings. changed[" scheduled-sort-order" ]. connect (() = > {
164- listbox. invalidate_sort ();
165- })] = Services . Settings . get_default ();
166-
167- listbox. set_sort_func ((lbrow, lbbefore) = > {
168- Objects . Item item1 = ((Layouts . ItemRow ) lbrow). item;
169- Objects . Item item2 = ((Layouts . ItemRow ) lbbefore). item;
170-
171- SortedByType sorted_by = SortedByType . parse (Services . Settings . get_default (). settings. get_string (" scheduled-sort-order" ));
172-
173- return Util . get_default (). set_item_sort_func (
174- item1,
175- item2,
176- sorted_by,
177- SortOrderType . ASC
178- );
179- });
180-
181- listbox. set_filter_func ((row) = > {
182- var item = ((Layouts . ItemRow ) row). item;
183- bool return_value = true ;
184-
185- if (Objects . Filters . Scheduled . get_default (). filters. size <= 0 ) {
186- return true ;
187- }
188-
189- return_value = false ;
190- foreach (Objects . Filters . FilterItem filter in Objects . Filters . Scheduled . get_default (). filters. values) {
191- if (filter. filter_type == FilterItemType . PRIORITY ) {
192- return_value = return_value || item. priority == int . parse (filter. value );
193- } else if (filter. filter_type == FilterItemType . LABEL ) {
194- return_value = return_value || item. has_label (filter. value );
195- }
196- }
197-
198- return return_value;
199- });
200-
201- signal_map[Objects . Filters . Scheduled . get_default (). filter_added. connect (() = > {
202- listbox. invalidate_filter ();
203- })] = Objects . Filters . Scheduled . get_default ();
204-
205- signal_map[Objects . Filters . Scheduled . get_default (). filter_removed. connect (() = > {
206- listbox. invalidate_filter ();
207- })] = Objects . Filters . Scheduled . get_default ();
208-
209- signal_map[Objects . Filters . Scheduled . get_default (). filter_updated. connect (() = > {
210- listbox. invalidate_filter ();
211- })] = Objects . Filters . Scheduled . get_default ();
212-
213113 signal_map[Services . EventBus . get_default (). dim_content. connect ((active, focused_item_id) = > {
214114 header_content. sensitive = ! active;
215115 })] = Services . EventBus . get_default ();
216116
217- #if WITH_EVOLUTION
218- signal_map[event_list. change. connect (() = > {
219- event_list_revealer. reveal_child = event_list. has_items;
220- })] = event_list;
221- #endif
117+
222118 }
223119
224- private void add_items () {
120+ protected override void add_items () {
225121 foreach (Objects . Item item in Services . Store . instance (). get_items_by_date (date, false )) {
226122 add_item (item);
227123 }
@@ -239,39 +135,30 @@ public class Views.Scheduled.ScheduledDay : Gtk.ListBoxRow {
239135 }
240136 }
241137
242- private void add_item (Objects .Item item ) {
243- if (! items. has_key (item. id)) {
244- items[item. id] = new Layouts .ItemRow (item);
245- items[item. id]. disable_drag_and_drop ();
246- listbox. append (items[item. id]);
247- }
248- }
249-
250- private void valid_add_item (Objects .Item item ) {
138+ protected override bool valid_item_predicate (Objects .Item item ) {
251139 bool valid_due = item. has_due && Services . Store . instance (). valid_item_by_date (item, date, false );
252- bool valid_deadline = Utils . Datetime . is_today (date) && item. has_deadline &&
253- Utils . Datetime . is_today (Utils . Datetime . get_date_only (item. deadline_datetime));
254-
255- if (! items. has_key (item. id) && (valid_due || valid_deadline)) {
256- items[item. id] = new Layouts .ItemRow (item);
257- items[item. id]. disable_drag_and_drop ();
258- listbox. append (items[item. id]);
259- }
140+ bool valid_deadline = Utils . Datetime . is_today (date) && item. has_deadline &&
141+ Utils . Datetime . is_today (Utils . Datetime . get_date_only (item. deadline_datetime));
260142
261- listbox_revealer. reveal_child = has_items;
262- listbox. invalidate_filter ();
143+ return valid_due || valid_deadline;
263144 }
264145
265- private void valid_delete_item (Objects .Item item ) {
266- if (items. has_key (item. id)) {
267- items[item. id]. hide_destroy ();
268- items. unset (item. id);
269- }
146+ #if WITH_EVOLUTION
147+ protected override Widgets .EventsList ? create_events_list () {
148+ return new Widgets .EventsList .for_day (date) {
149+ hexpand = true ,
150+ valign = Gtk . Align . START ,
151+ margin_top = 6
152+ };
153+ }
154+ #endif
270155
271- listbox_revealer. reveal_child = has_items;
156+ protected override void valid_add_item (Objects .Item item ) {
157+ base . valid_add_item (item);
158+ listbox. invalidate_filter ();
272159 }
273160
274- private void valid_update_item (Objects .Item item ) {
161+ protected override void valid_update_item (Objects .Item item , string ? update_id = null ) {
275162 if (items. has_key (item. id)) {
276163 items[item. id]. update_request ();
277164 }
@@ -301,25 +188,4 @@ public class Views.Scheduled.ScheduledDay : Gtk.ListBoxRow {
301188 listbox_revealer. reveal_child = has_items;
302189 listbox. invalidate_filter ();
303190 }
304-
305-
306-
307- public void clean_up () {
308- listbox. set_filter_func (null );
309- listbox. set_sort_func (null );
310-
311- foreach (var row in Util . get_default (). get_children (listbox)) {
312- ((Layouts . ItemRow ) row). clean_up ();
313- }
314-
315- foreach (var entry in signal_map. entries) {
316- entry. value . disconnect (entry. key);
317- }
318-
319- signal_map. clear ();
320-
321- #if WITH_EVOLUTION
322- event_list. clean_up ();
323- #endif
324- }
325191}
0 commit comments