Skip to content
Merged
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
24 changes: 0 additions & 24 deletions core/Utils.vala
Original file line number Diff line number Diff line change
Expand Up @@ -60,30 +60,6 @@ namespace Maya.Util {
return _("On this computer");
}

/*
* ical Exportation
*/

public void save_temp_selected_calendars () {
var calmodel = Calendar.EventStore.get_default ();
var events = calmodel.get_events ();
var builder = new StringBuilder ();
builder.append ("BEGIN:VCALENDAR\n");
builder.append ("VERSION:2.0\n");
foreach (ECal.Component event in events) {
builder.append (event.get_as_string ());
}
builder.append ("END:VCALENDAR");

string file_path = GLib.Environment.get_tmp_dir () + "/calendar.ics";
try {
var file = File.new_for_path (file_path);
file.replace_contents (builder.data, null, false, FileCreateFlags.REPLACE_DESTINATION, null);
} catch (Error e) {
warning ("%s\n", e.message);
}
}

public ECal.Component? copy_ecal_component (ECal.Component? original) {
if (original == null) {
return null;
Expand Down
22 changes: 11 additions & 11 deletions src/Grid/CalendarView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,6 @@ public class Maya.View.CalendarView : Gtk.Box {
}

private void action_export () {
/* creates a .ics file */
Util.save_temp_selected_calendars ();

var filter = new Gtk.FileFilter ();
filter.add_mime_type ("text/calendar");

Expand All @@ -214,16 +211,19 @@ public class Maya.View.CalendarView : Gtk.Box {
filechooser.set_current_name (_("calendar.ics"));

if (filechooser.run () == Gtk.ResponseType.ACCEPT) {
var destination = filechooser.get_filename ();
if (destination == null) {
destination = filechooser.get_current_folder ();
} else if (!destination.has_suffix (".ics")) {
destination += ".ics";
var events = Calendar.EventStore.get_default ().get_events ();
var builder = new StringBuilder ();
builder.append ("BEGIN:VCALENDAR\n");
foreach (ECal.Component event in events) {
builder.append (event.get_as_string ());
}
builder.append ("END:VCALENDAR");

var file = filechooser.get_file ();
try {
GLib.Process.spawn_command_line_async ("mv " + GLib.Environment.get_tmp_dir () + "/calendar.ics " + destination);
} catch (SpawnError e) {
warning (e.message);
file.replace_contents (builder.data, null, false, FileCreateFlags.REPLACE_DESTINATION, null);
} catch (Error e) {
warning ("%s\n", e.message);
}
}

Expand Down