[california/wip/740088-invite] Use xdg-email for launching mail client
- From: Jim Nelson <jnelson src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [california/wip/740088-invite] Use xdg-email for launching mail client
- Date: Thu, 20 Nov 2014 03:32:01 +0000 (UTC)
commit 6e9466dc3b2869a3e0d4392fab5da2861a6406af
Author: Jim Nelson <jim yorba org>
Date: Wed Nov 19 18:48:48 2014 -0800
Use xdg-email for launching mail client
src/host/host-attendees-editor.vala | 2 +-
src/host/host-create-update-event.vala | 61 +++++++++++++++++--------------
2 files changed, 34 insertions(+), 29 deletions(-)
---
diff --git a/src/host/host-attendees-editor.vala b/src/host/host-attendees-editor.vala
index 3db3fe6..91355e5 100644
--- a/src/host/host-attendees-editor.vala
+++ b/src/host/host-attendees-editor.vala
@@ -38,7 +38,7 @@ public class AttendeesEditor : Gtk.Box, Toolkit.Card {
private void update_invite_button() {
invite_button.image = new Gtk.Image.from_icon_name(
- attendee.rsvp ? "mail-unread-symbolic" : "mail-read-symbolic",
+ attendee.send_invite ? "mail-unread-symbolic" : "mail-read-symbolic",
Gtk.IconSize.BUTTON);
invite_button.tooltip_text = attendee.send_invite ? _("Send invite") : _("Don't send invite");
diff --git a/src/host/host-create-update-event.vala b/src/host/host-create-update-event.vala
index 0203f00..36f4a12 100644
--- a/src/host/host-create-update-event.vala
+++ b/src/host/host-create-update-event.vala
@@ -433,64 +433,69 @@ public class CreateUpdateEvent : Gtk.Grid, Toolkit.Card {
}
private void invite_attendees(Component.Event event, iCal.icalproperty_method method) {
- // no attendees, no invites
- if (event.attendees.size == 0)
+ // Make list of invitees, which are attendees who are not organizers
+ Gee.List<Component.Person> invitees = traverse<Component.Person>(event.attendees)
+ .filter(attendee => !event.organizers.contains(attendee))
+ .sort()
+ .to_array_list();
+
+ // no invitees, no invites
+ if (invitees.size == 0)
return;
+ // TODO: Differentiate between instance updates and master updates
Component.iCalendar ics = event.export_master(method);
// export .ics to temporary directory so the filename is a pristine "invite.ics"
- string temporary_filename;
+ string? temporary_filename = null;
try {
// "invite.ics" is the name of the file for an event invite delivered via email ...
// please translate but keep the .ics extension, as that's common to most calendar
// applications
temporary_filename =
File.new_for_path(DirUtils.make_tmp("california-XXXXXX")).get_child(_("invite.ics")).get_path();
- debug(temporary_filename);
FileUtils.set_contents(temporary_filename, ics.source);
// ensure this file is only readable by the user
FileUtils.chmod(temporary_filename, (int) (Posix.S_IRUSR | Posix.S_IWUSR));
} catch (Error err) {
Application.instance.error_message(deck.get_toplevel() as Gtk.Window,
- _("Unable to export .ics: %s").printf(err.message));
+ _("Unable to export .ics to %s: %s").printf(
+ temporary_filename ?? "(filename not generated)", err.message));
return;
}
- // build the mailto: for the default mail application
- StringBuilder mailto = new StringBuilder("mailto:");
- mailto.append(traverse<Component.Person>(event.attendees)
- .sort()
- .to_string(attendee_to_uri)
- );
+ //
+ // send using xdg-email, *not* Gtk.show_uri() w/ a mailto: URI, as handling attachments
+ // is best left to xdg-email
+ //
- if (!String.is_empty(event.summary))
- mailto.append_printf("?subject=%s", GLib.Uri.escape_string(_("Invitation:
%s").printf(event.summary)));
- else
- mailto.append_printf("?subject=%s", GLib.Uri.escape_string(_("Invitation")));
+ string[] argv = new string[0];
+ argv += "xdg-email";
+ argv += "--utf8";
- mailto.append_printf("&body=%s", GLib.Uri.escape_string(
- _("Attached is an invitation to an event")
- ));
+ foreach (Component.Person invitee in invitees)
+ argv += invitee.mailbox;
- mailto.append_printf("&attachment=%s", GLib.Uri.escape_string(temporary_filename));
+ argv += "--subject";
+ argv += String.is_empty(event.summary) ? _("Event invitation") : _("Invitation:
%s").printf(event.summary);
- debug("%s", mailto.str);
+ // TODO: Generate a better body for the email (w/ event summary)
+ argv += "--body";
+ argv += _("Attached is an invitation to a new event.");
+
+ argv += "--attach";
+ argv += temporary_filename;
try {
- Gtk.show_uri(deck.get_screen(), mailto.str, Gdk.CURRENT_TIME);
- } catch (Error err) {
+ Pid child_pid;
+ Process.spawn_async(null, argv, null, SpawnFlags.SEARCH_PATH, null, out child_pid);
+ Process.close_pid(child_pid);
+ } catch (SpawnError err) {
Application.instance.error_message(deck.get_toplevel() as Gtk.Window,
_("Unable to launch mail client: %s").printf(err.message));
}
}
-
- private string? attendee_to_uri(Component.Person attendee, bool is_first, bool is_last) {
- string to_mailbox = is_last ? attendee.mailbox : "%s,".printf(attendee.mailbox);
-
- return GLib.Uri.escape_string(to_mailbox, "@,");
- }
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]