Skip to content

Commit 18654f3

Browse files
authored
CalendarView: use returned file for export (#923)
1 parent 3ae6733 commit 18654f3

2 files changed

Lines changed: 11 additions & 35 deletions

File tree

core/Utils.vala

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -60,30 +60,6 @@ namespace Maya.Util {
6060
return _("On this computer");
6161
}
6262

63-
/*
64-
* ical Exportation
65-
*/
66-
67-
public void save_temp_selected_calendars () {
68-
var calmodel = Calendar.EventStore.get_default ();
69-
var events = calmodel.get_events ();
70-
var builder = new StringBuilder ();
71-
builder.append ("BEGIN:VCALENDAR\n");
72-
builder.append ("VERSION:2.0\n");
73-
foreach (ECal.Component event in events) {
74-
builder.append (event.get_as_string ());
75-
}
76-
builder.append ("END:VCALENDAR");
77-
78-
string file_path = GLib.Environment.get_tmp_dir () + "/calendar.ics";
79-
try {
80-
var file = File.new_for_path (file_path);
81-
file.replace_contents (builder.data, null, false, FileCreateFlags.REPLACE_DESTINATION, null);
82-
} catch (Error e) {
83-
warning ("%s\n", e.message);
84-
}
85-
}
86-
8763
public ECal.Component? copy_ecal_component (ECal.Component? original) {
8864
if (original == null) {
8965
return null;

src/Grid/CalendarView.vala

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,6 @@ public class Maya.View.CalendarView : Gtk.Box {
196196
}
197197

198198
private void action_export () {
199-
/* creates a .ics file */
200-
Util.save_temp_selected_calendars ();
201-
202199
var filter = new Gtk.FileFilter ();
203200
filter.add_mime_type ("text/calendar");
204201

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

216213
if (filechooser.run () == Gtk.ResponseType.ACCEPT) {
217-
var destination = filechooser.get_filename ();
218-
if (destination == null) {
219-
destination = filechooser.get_current_folder ();
220-
} else if (!destination.has_suffix (".ics")) {
221-
destination += ".ics";
214+
var events = Calendar.EventStore.get_default ().get_events ();
215+
var builder = new StringBuilder ();
216+
builder.append ("BEGIN:VCALENDAR\n");
217+
foreach (ECal.Component event in events) {
218+
builder.append (event.get_as_string ());
222219
}
220+
builder.append ("END:VCALENDAR");
221+
222+
var file = filechooser.get_file ();
223223
try {
224-
GLib.Process.spawn_command_line_async ("mv " + GLib.Environment.get_tmp_dir () + "/calendar.ics " + destination);
225-
} catch (SpawnError e) {
226-
warning (e.message);
224+
file.replace_contents (builder.data, null, false, FileCreateFlags.REPLACE_DESTINATION, null);
225+
} catch (Error e) {
226+
warning ("%s\n", e.message);
227227
}
228228
}
229229

0 commit comments

Comments
 (0)