[geary/wip/135-contact-popovers: 17/26] Implement save contacts and open desktop contacts in Contacts
- From: Michael Gratton <mjog src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [geary/wip/135-contact-popovers: 17/26] Implement save contacts and open desktop contacts in Contacts
- Date: Mon, 8 Apr 2019 00:28:24 +0000 (UTC)
commit 41d061c8ff3f1199e879e98a82ec4cd1596554a7
Author: Michael Gratton <mike vee net>
Date: Sun Mar 17 02:02:20 2019 +1100
Implement save contacts and open desktop contacts in Contacts
src/client/application/application-contact.vala | 51 ++++++++++++++++++++++
.../conversation-contact-popover.vala | 22 +++++++++-
2 files changed, 71 insertions(+), 2 deletions(-)
---
diff --git a/src/client/application/application-contact.vala b/src/client/application/application-contact.vala
index d504f42b..67c8d661 100644
--- a/src/client/application/application-contact.vala
+++ b/src/client/application/application-contact.vala
@@ -93,6 +93,57 @@ public class Application.Contact : Geary.BaseObject {
update_individual(null);
}
+ /** Invokes the desktop contacts application to save this contact. */
+ public async void save_to_desktop(GLib.Cancellable? cancellable)
+ throws GLib.Error {
+ GLib.DBusConnection dbus = yield GLib.Bus.get(
+ GLib.BusType.SESSION, cancellable
+ );
+ GLib.DBusActionGroup contacts = DBusActionGroup.get(
+ dbus, "org.gnome.Contacts", "/org/gnome/Contacts"
+ );
+
+ GLib.Variant param = new GLib.Variant.array(
+ new GLib.VariantType("(ss)"),
+ new GLib.Variant[] {
+ new GLib.Variant.tuple(
+ new GLib.Variant[] {
+ Folks.PersonaStore.detail_key(
+ Folks.PersonaDetail.FULL_NAME
+ ),
+ this.display_name ?? ""
+ }
+ ),
+ new GLib.Variant.tuple(
+ new GLib.Variant[] {
+ Folks.PersonaStore.detail_key(
+ Folks.PersonaDetail.EMAIL_ADDRESSES
+ ),
+ this.contact.email
+ }
+ )
+ }
+ );
+
+ contacts.activate_action("create-contact", param);
+ }
+
+ /** Invokes the desktop contacts application to open this contact. */
+ public async void open_on_desktop(GLib.Cancellable? cancellable)
+ throws GLib.Error {
+ GLib.DBusConnection dbus = yield GLib.Bus.get(
+ GLib.BusType.SESSION, cancellable
+ );
+ GLib.DBusActionGroup contacts = DBusActionGroup.get(
+ dbus, "org.gnome.Contacts", "/org/gnome/Contacts"
+ );
+
+ contacts.activate_action(
+ "show-contact",
+ new GLib.Variant.string(this.individual.id)
+ );
+ }
+
/** Sets remote resource loading for this contact. */
public async void set_remote_resource_loading(bool enabled,
GLib.Cancellable? cancellable)
diff --git a/src/client/conversation-viewer/conversation-contact-popover.vala
b/src/client/conversation-viewer/conversation-contact-popover.vala
index 75386fa3..38c5615b 100644
--- a/src/client/conversation-viewer/conversation-contact-popover.vala
+++ b/src/client/conversation-viewer/conversation-contact-popover.vala
@@ -156,6 +156,24 @@ public class Conversation.ContactPopover : Gtk.Popover {
);
}
+ private async void open() {
+ try {
+ yield this.contact.open_on_desktop(null);
+ } catch (GLib.Error err) {
+ debug("Failed to open desktop app for showing contact %s:, %s",
+ this.contact.to_string(), err.message);
+ }
+ }
+
+ private async void save() {
+ try {
+ yield this.contact.save_to_desktop(null);
+ } catch (GLib.Error err) {
+ debug("Failed to open desktop app for saving contact %s:, %s",
+ this.contact.to_string(), err.message);
+ }
+ }
+
private async void set_load_remote_resources(bool enabled) {
try {
yield this.contact.set_remote_resource_loading(enabled, null);
@@ -197,11 +215,11 @@ public class Conversation.ContactPopover : Gtk.Popover {
}
private void on_open() {
-
+ this.open.begin();
}
private void on_save() {
-
+ this.save.begin();
}
private void on_show_conversations() {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]