Skip to content

Commit

Permalink
Add support for libecal-2.0 (#202)
Browse files Browse the repository at this point in the history
  • Loading branch information
Corentin Noël authored and danirabbit committed Dec 6, 2019
1 parent 2185278 commit 3ccd05d
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 11 deletions.
16 changes: 14 additions & 2 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@ gresource = gnome.compile_resources(
wingpanel_dep = dependency('wingpanel-2.0')
wingpanel_indicatorsdir = wingpanel_dep.get_pkgconfig_variable('indicatorsdir', define_variable: ['libdir', libdir])


libecal_dep = dependency('libecal-2.0', required: false)
if libecal_dep.found()
libical_dep = dependency('libical-glib')
add_project_arguments('--define=E_CAL_2_0', language: 'vala')
add_project_arguments('-DLIBICAL_GLIB_UNSTABLE_API=1', language: 'c')
else
libecal_dep = dependency('libecal-1.2', version: '>=3.8.0')
libical_dep = dependency('libical')
add_project_arguments('--vapidir', join_paths(meson.current_source_dir(), 'vapi'), language: 'vala')
endif

shared_module(
meson.project_name(),
gresource,
Expand All @@ -43,9 +55,9 @@ shared_module(
dependency('gobject-2.0'),
dependency('granite'),
dependency('gtk+-3.0'),
dependency('libecal-1.2'),
libecal_dep,
dependency('libedataserver-1.2'),
dependency('libical'),
libical_dep,
wingpanel_dep,
],
install: true,
Expand Down
28 changes: 21 additions & 7 deletions src/Widgets/calendar/CalendarModel.vala
Original file line number Diff line number Diff line change
Expand Up @@ -260,25 +260,35 @@ namespace DateTime.Widgets {
return view;
}

private void on_objects_added (E.Source source, ECal.Client client, SList<unowned ICal.Component> objects) {
#if E_CAL_2_0
private void on_objects_added (E.Source source, ECal.Client client, SList<ICal.Component> objects) {
#else
private void on_objects_added (E.Source source, ECal.Client client, SList<weak ICal.Component> objects) {
#endif
debug (@"Received $(objects.length()) added event(s) for source '%s'", source.dup_display_name ());
var events = source_events.get (source);
var added_events = new Gee.ArrayList<ECal.Component> ((Gee.EqualDataFunc<ECal.Component>?) Util.calcomponent_equal_func);

objects.foreach ((comp) => {
unowned string uid = comp.get_uid ();
#if E_CAL_2_0
client.generate_instances_for_object_sync (comp, (time_t) data_range.first_dt.to_unix (), (time_t) data_range.last_dt.to_unix (), null, (comp, start, end) => {
var event = new ECal.Component.from_icalcomponent (comp);
#else
client.generate_instances_for_object_sync (comp, (time_t) data_range.first_dt.to_unix (), (time_t) data_range.last_dt.to_unix (), (event, start, end) => {
#endif
debug_event (source, event);
events.set (uid, event);
added_events.add (event);
return true;
});
});

events_added (source, added_events.read_only_view);
}

private void on_objects_modified (E.Source source, ECal.Client client, SList<unowned ICal.Component> objects) {
#if E_CAL_2_0
private void on_objects_modified (E.Source source, ECal.Client client, SList<ICal.Component> objects) {
#else
private void on_objects_modified (E.Source source, ECal.Client client, SList<weak ICal.Component> objects) {
#endif
debug (@"Received $(objects.length()) modified event(s) for source '%s'", source.dup_display_name ());
var updated_events = new Gee.ArrayList<ECal.Component> ((Gee.EqualDataFunc<ECal.Component>?) Util.calcomponent_equal_func);

Expand All @@ -294,7 +304,11 @@ namespace DateTime.Widgets {
events_updated (source, updated_events.read_only_view);
}

private void on_objects_removed (E.Source source, ECal.Client client, SList<unowned ECal.ComponentId?> cids) {
#if E_CAL_2_0
private void on_objects_removed (E.Source source, ECal.Client client, SList<ECal.ComponentId?> cids) {
#else
private void on_objects_removed (E.Source source, ECal.Client client, SList<weak ECal.ComponentId?> cids) {
#endif
debug (@"Received $(cids.length()) removed event(s) for source '%s'", source.dup_display_name ());
var events = source_events.get (source);
var removed_events = new Gee.ArrayList<ECal.Component> ((Gee.EqualDataFunc<ECal.Component>?) Util.calcomponent_equal_func);
Expand All @@ -304,7 +318,7 @@ namespace DateTime.Widgets {
return;
}

var comps = events.get (cid.uid);
var comps = events.get (cid.get_uid ());
foreach (ECal.Component event in comps) {
removed_events.add (event);
debug_event (source, event);
Expand Down
12 changes: 10 additions & 2 deletions src/Widgets/calendar/Util.vala
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,16 @@ namespace Util {
* XXX : Track next versions of evolution in order to convert ICal.Timezone to GLib.TimeZone with a dedicated function…
*/
public GLib.DateTime ical_to_date_time (ICal.Time date) {
#if E_CAL_2_0
int year, month, day, hour, minute, second;
date.get_date (out year, out month, out day);
date.get_time (out hour, out minute, out second);
return new GLib.DateTime (timezone_from_ical (date), year, month,
day, hour, minute, second);
#else
return new GLib.DateTime (timezone_from_ical (date), date.year, date.month,
date.day, date.hour, date.minute, date.second);
#endif
}

/**
Expand Down Expand Up @@ -162,9 +170,9 @@ namespace Util {

var a_id = a.get_id ();
var b_id = b.get_id ();
int res = GLib.strcmp (a_id.uid, b_id.uid);
int res = GLib.strcmp (a_id.get_uid (), b_id.get_uid ());
if (res == 0) {
return GLib.strcmp (a_id.rid, b_id.rid);
return GLib.strcmp (a_id.get_rid (), b_id.get_rid ());
}

return res;
Expand Down

0 comments on commit 3ccd05d

Please sign in to comment.