-
-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathComponentRow.vala
More file actions
153 lines (130 loc) · 5.67 KB
/
Copy pathComponentRow.vala
File metadata and controls
153 lines (130 loc) · 5.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/*
* Copyright 2019 elementary, Inc. (https://elementary.io)
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*/
public class DateTime.ComponentRow : Gtk.ListBoxRow {
public GLib.DateTime date { get; construct; }
public unowned ICal.Component component { get; construct; }
public unowned E.SourceSelectable source_selectable { get; construct; }
public GLib.DateTime start_time { get; private set; }
public GLib.DateTime? end_time { get; private set; }
public bool is_allday { get; private set; default = false; }
private static Services.TimeManager time_manager;
private static Gtk.CssProvider css_provider;
private Gtk.Grid grid;
private Gtk.Image component_image;
private Gtk.Label name_label;
private Gtk.Label time_label;
public ComponentRow (GLib.DateTime date, ICal.Component component, E.Source source) {
unowned E.SourceSelectable? source_selectable = null;
if (source.has_extension (E.SOURCE_EXTENSION_TASK_LIST)) {
source_selectable = (E.SourceSelectable?) source.get_extension (E.SOURCE_EXTENSION_TASK_LIST);
} else {
source_selectable = (E.SourceSelectable?) source.get_extension (E.SOURCE_EXTENSION_CALENDAR);
}
Object (
component: component,
date: date,
source_selectable: source_selectable
);
}
static construct {
css_provider = new Gtk.CssProvider ();
css_provider.load_from_resource ("/io/elementary/desktop/wingpanel/datetime/EventRow.css");
time_manager = Services.TimeManager.get_default ();
}
construct {
var dt_start = component.get_dtstart ();
if (dt_start.is_date ()) {
// Don't convert timezone for date with only day info, leave it at midnight UTC
start_time = Util.ical_to_date_time (dt_start);
} else {
start_time = Util.ical_to_date_time (dt_start).to_local ();
}
if (!(source_selectable is E.SourceTaskList)) {
var dt_end = component.get_dtend ();
if (dt_end.is_date ()) {
// Don't convert timezone for date with only day info, leave it at midnight UTC
end_time = Util.ical_to_date_time (dt_end);
} else {
end_time = Util.ical_to_date_time (dt_end).to_local ();
}
if (end_time != null && Util.is_the_all_day (start_time, end_time)) {
is_allday = true;
}
}
var icon_name = "office-calendar-symbolic";
if (source_selectable is E.SourceTaskList) {
icon_name = "office-task-symbolic";
} else if (end_time == null) {
icon_name = "alarm-symbolic";
}
component_image = new Gtk.Image.from_icon_name (icon_name) {
valign = Gtk.Align.START
};
component_image.get_style_context ().add_provider (css_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
name_label = new Gtk.Label (component.get_summary ()) {
hexpand = true,
ellipsize = Pango.EllipsizeMode.END,
lines = 3,
max_width_chars = 30,
wrap = true,
wrap_mode = Pango.WrapMode.WORD_CHAR,
xalign = 0
};
name_label.add_css_class ("title");
name_label.get_style_context ().add_provider (css_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
time_label = new Gtk.Label (null) {
use_markup = true,
xalign = 0,
};
time_label.add_css_class (Granite.CssClass.DIM);
grid = new Gtk.Grid () {
column_spacing = 6,
margin_top = 3,
margin_bottom = 3,
margin_start = 6,
margin_end = 6
};
grid.attach (component_image, 0, 0);
grid.attach (name_label, 1, 0);
if (!is_allday) {
grid.attach (time_label, 1, 1);
}
grid.add_css_class ("event");
grid.get_style_context ().add_provider (css_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
child = grid;
set_color ();
source_selectable.notify["color"].connect (set_color);
update_timelabel ();
time_manager.notify["is-12h"].connect (update_timelabel);
}
private void update_timelabel () {
var time_format = Granite.DateTime.get_default_time_format (time_manager.is_12h);
if (source_selectable is E.SourceTaskList) {
time_label.label = "<small>Due by %s</small>".printf (start_time.format (time_format));
} else {
time_label.label = "<small>%s – %s</small>".printf (start_time.format (time_format), end_time.format (time_format));
}
}
private void set_color () {
Util.set_component_calendar_color (source_selectable, grid);
Util.set_component_calendar_color (source_selectable, component_image);
Util.set_component_calendar_color (source_selectable, name_label);
Util.set_component_calendar_color (source_selectable, time_label);
}
}