Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 36 additions & 3 deletions core/Model/CalendarModel.vala
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ public class Maya.Model.CalendarModel : Object {
/* The start of week, ie. Monday=1 or Sunday=7 */
public GLib.DateWeekday week_starts_on { get; set; default = GLib.DateWeekday.MONDAY; }

/* The event that is currently dragged */
public ECal.Component drag_component {get; set;}

/* Notifies when events are added, updated, or removed */
public signal void events_added (E.Source source, Gee.Collection<ECal.Component> events);
public signal void events_updated (E.Source source, Gee.Collection<ECal.Component> events);
Expand Down Expand Up @@ -292,6 +289,42 @@ public class Maya.Model.CalendarModel : Object {
return events;
}

private static int search_rid (ECal.Component a, string? rid) {
string? a_rid = a.get_recurid_as_string ();
if (a_rid == null && rid == null) {
return 0;
}

return GLib.strcmp (a_rid, rid);
}

public ECal.Component? get_event (string uid, string? rid) {
List<weak ECal.Client> clients = source_client.get_values ();
foreach (unowned ECal.Client client in clients) {
GLib.SList<ECal.Component> ecalcomps;
try {
client.get_objects_for_uid_sync (uid, out ecalcomps, null);
if (ecalcomps.length () > 0) {
unowned GLib.SList<ECal.Component> results = ecalcomps.search<string> (rid, search_rid);

if (results.length () > 0) {
unowned ECal.Component comp = results.data;
comp.set_data ("source", client.source);
return comp;
} else {
unowned ECal.Component comp = ecalcomps.data;
comp.set_data ("source", client.source);
return comp;
}
}
} catch (Error e) {
debug (e.message);
}
}

return null;
}

//--- Helper Methods ---//

private DateTime get_page () {
Expand Down
47 changes: 31 additions & 16 deletions src/Grid/EventButton.vala
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 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, see <http://www.gnu.org/licenses/>.
*
Expand Down Expand Up @@ -81,22 +81,37 @@ public class Maya.View.EventButton : Gtk.Revealer {
return true;
});

Gtk.TargetEntry dnd = {"binary/calendar", 0, 0};
Gtk.TargetEntry dnd2 = {"text/uri-list", 0, 0};
Gtk.drag_source_set (event_box, Gdk.ModifierType.BUTTON1_MASK, {dnd, dnd2}, Gdk.DragAction.MOVE);
const Gtk.TargetEntry DND = {"text/x-io-elementary-calendar", 0, 0};
const Gtk.TargetEntry DND2 = {"text/uri-list", 0, 1};
const Gtk.TargetEntry DND3 = {"text/calendar", 0, 2};
Gtk.drag_source_set (event_box, Gdk.ModifierType.BUTTON1_MASK, {DND, DND2, DND3}, Gdk.DragAction.MOVE);

event_box.drag_data_get.connect ( (ctx, sel, info, time) => {
Model.CalendarModel.get_default ().drag_component = comp;
unowned ICal.Component icalcomp = comp.get_icalcomponent ();
var ical_str = icalcomp.as_ical_string ();
sel.set_text (ical_str, ical_str.length);
try {
var path = GLib.Path.build_filename (GLib.Environment.get_tmp_dir (), icalcomp.get_summary () + ".ics");
var file = File.new_for_path (path);
if (file.replace_contents (ical_str.data, null, false, FileCreateFlags.PRIVATE, null))
sel.set_uris ({file.get_uri ()});
} catch (Error e) {
critical (e.message);
if (info == 0) {
var comp_id = comp.get_id ();
if (comp_id.rid != null) {
var data = "%s\n%s".printf (comp_id.uid, comp_id.rid);
sel.set (Gdk.Atom.intern_static_string ("text/x-io-elementary-calendar"),
(int)sizeof (char), data.data);
} else {
sel.set (Gdk.Atom.intern_static_string ("text/x-io-elementary-calendar"),
(int)sizeof (char), comp_id.uid.data);
}
} else if (info == 1) {
comp.commit_sequence ();
var ical_str = comp.get_as_string ();
try {
var path = GLib.Path.build_filename (GLib.Environment.get_tmp_dir (), comp.get_summary ().value + ".ics");
var file = File.new_for_path (path);
if (file.replace_contents (ical_str.data, null, false, FileCreateFlags.PRIVATE, null))
sel.set_uris ({file.get_uri ()});
} catch (Error e) {
critical (e.message);
}
} else if (info == 2) {
comp.commit_sequence ();
var ical_str = comp.get_as_string ();
sel.set_text (ical_str, ical_str.length);
}
});

Expand Down
60 changes: 33 additions & 27 deletions src/Grid/GridDay.vala
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 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, see <http://www.gnu.org/licenses/>.
*
Expand Down Expand Up @@ -96,8 +96,8 @@ public class Maya.View.GridDay : Gtk.EventBox {
key_press_event.connect (on_key_press);
scroll_event.connect ((event) => {return GesturesUtils.on_scroll_event (event);});

Gtk.TargetEntry dnd = {"binary/calendar", 0, 0};
Gtk.drag_dest_set (this, Gtk.DestDefaults.MOTION, {dnd}, Gdk.DragAction.MOVE);
const Gtk.TargetEntry DND = {"text/x-io-elementary-calendar", 0, 0};
Gtk.drag_dest_set (this, Gtk.DestDefaults.MOTION, {DND}, Gdk.DragAction.MOVE);

this.notify["date"].connect (() => {
label.label = date.get_day_of_month ().to_string ();
Expand All @@ -112,30 +112,36 @@ public class Maya.View.GridDay : Gtk.EventBox {
}

public override void drag_data_received (Gdk.DragContext context, int x, int y, Gtk.SelectionData selection_data, uint info, uint time_) {
var calmodel = Model.CalendarModel.get_default ();
var comp = calmodel.drag_component;
unowned ICal.Component icalcomp = comp.get_icalcomponent ();
E.Source src = comp.get_data ("source");
var start = icalcomp.get_dtstart ();
var end = icalcomp.get_dtend ();
var gap = date.get_day_of_month () - start.get_day ();
#if E_CAL_2_0
start.set_day (start.get_day () + gap);
#else
start.day += gap;
#endif

if (!end.is_null_time ()) {
#if E_CAL_2_0
end.set_day (end.get_day () + gap);
#else
end.day += gap;
#endif
icalcomp.set_dtend (end);
}
string? compid = (string)selection_data.get_data ();
if (compid != null) {
string uid;
string? rid = null;
if ("\n" in compid) {
var parts = compid.split ("\n", 2);
uid = parts[0];
rid = parts[1];
} else {
uid = compid;
}

icalcomp.set_dtstart (start);
calmodel.update_event (src, comp, ECal.ObjModType.ALL);
var calmodel = Model.CalendarModel.get_default ();
ECal.Component? comp = calmodel.get_event (uid, rid);

unowned ICal.Component icalcomp = comp.get_icalcomponent ();
E.Source src = comp.get_data ("source");
var start = icalcomp.get_dtstart ();
var end = icalcomp.get_dtend ();
var gap = date.get_day_of_month () - start.day;
start.day += gap;

if (!end.is_null_time ()) {
end.day += gap;
icalcomp.set_dtend (end);
}

icalcomp.set_dtstart (start);
calmodel.update_event (src, comp, ECal.ObjModType.ALL);
}
}

public void add_event_button (EventButton button) {
Expand Down