[gnome-notes] share: Use desktop portal for mail sharing



commit 6ce3d80dc8de1a9a1ee8ae502e074c5eda2807bc
Author: G√ľnther Wagner <info gunibert de>
Date:   Tue Jul 24 22:07:21 2018 +0200

    share: Use desktop portal for mail sharing
    
    Use desktop portal for mail sharing instead of xdg-email [1].
    
    [1] https://flatpak.github.io/xdg-desktop-portal/portal-docs.html#gdbus-org.freedesktop.impl.portal.Email

 src/bjb-main-toolbar.c      |  2 +-
 src/bjb-selection-toolbar.c |  4 ++-
 src/bjb-share.c             | 61 +++++++++++++++++++++++++++------------------
 src/bjb-share.h             |  3 +--
 4 files changed, 42 insertions(+), 28 deletions(-)
---
diff --git a/src/bjb-main-toolbar.c b/src/bjb-main-toolbar.c
index 82edd18..6d279bd 100644
--- a/src/bjb-main-toolbar.c
+++ b/src/bjb-main-toolbar.c
@@ -564,7 +564,7 @@ on_email_cb (BjbMainToolbar *self,
 {
   g_return_if_fail (self->note);
 
-  on_email_note_callback (menu_item, self->note);
+  on_email_note_callback (self->note);
 }
 
 static void
diff --git a/src/bjb-selection-toolbar.c b/src/bjb-selection-toolbar.c
index 1696ed2..eafa2d3 100644
--- a/src/bjb-selection-toolbar.c
+++ b/src/bjb-selection-toolbar.c
@@ -155,7 +155,9 @@ action_share_item_callback (BjbSelectionToolbar *self,
   selection = bjb_main_view_get_selected_items (self->view);
 
   for (l = selection; l != NULL; l = l->next)
-    on_email_note_callback (GTK_WIDGET (button), l->data);
+    {
+      on_email_note_callback (l->data);
+    }
 
   bjb_main_view_set_selection_mode (self->view, FALSE);
   g_list_free (selection);
diff --git a/src/bjb-share.c b/src/bjb-share.c
index 38bf6f3..6ed45bc 100644
--- a/src/bjb-share.c
+++ b/src/bjb-share.c
@@ -16,6 +16,7 @@
  */
 
 #include "bjb-share.h"
+#include <stdio.h>
 
 static gchar *
 mail_str (const gchar * string )
@@ -26,39 +27,51 @@ mail_str (const gchar * string )
   return g_strdelimit (g_strdup (string), "\n", ' ');
 }
 
-/* TODO find EOL for xdg-email */
 gboolean
-on_email_note_callback(GtkWidget *widget, BijiNoteObj *note)
+on_email_note_callback (BijiNoteObj *note)
 {
   GError *error = NULL;
-  gchar *title_mail, *text_mail;
-  const gchar *execute[7];
+  g_autofree gchar *title_mail;
+  g_autofree gchar *text_mail;
+  g_autoptr(GDBusProxy) proxy;
+  GVariantBuilder *arraybuilder;
+  GVariant *dict;
 
   title_mail = mail_str ((gchar*) biji_item_get_title (BIJI_ITEM (note)));
   text_mail = mail_str (biji_note_obj_get_raw_text (note));
 
-  execute[0] = "xdg-email";
-  execute[1] = "--utf8";
-  execute[2] = "--subject";
-  execute[3] = title_mail;
-  execute[4] = "--body";
-  execute[5] = text_mail;
-  execute[6] = NULL;
+  proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
+                                         G_DBUS_PROXY_FLAGS_NONE,
+                                         NULL,
+                                         "org.freedesktop.portal.Desktop",
+                                         "/org/freedesktop/portal/desktop",
+                                         "org.freedesktop.portal.Email",
+                                         NULL,
+                                         &error);
 
-  g_spawn_async ( NULL,
-                  (gchar **) execute,
-                  NULL,
-                  G_SPAWN_SEARCH_PATH,
-                  NULL,
-                  NULL,
-                  NULL,
-                  &error);
-  if ( error != NULL )
-    g_message("error :%s",error->message);
+  if (proxy == NULL)
+    {
+      fprintf (stderr, "Proxy creation failed: %s\n", error->message);
+      g_error_free (error);
+      return FALSE;
+    }
 
-  g_free (title_mail);
-  g_free (text_mail);
+  arraybuilder = g_variant_builder_new (G_VARIANT_TYPE ("a{sv}"));
+  g_variant_builder_add (arraybuilder, "{sv}", "subject", g_variant_new_string (title_mail));
+  g_variant_builder_add (arraybuilder, "{sv}", "body", g_variant_new_string (text_mail));
 
-  return TRUE ;
+  dict = g_variant_new ("(sa{sv})", "", arraybuilder);
+  g_variant_builder_unref (arraybuilder);
+
+  g_dbus_proxy_call_sync (proxy, "ComposeEmail", dict, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
+  if (error != NULL)
+    {
+      g_error ("%s", error->message);
+      fprintf (stderr, "ComposeEmail portal call failed: %s", error->message);
+      g_error_free (error);
+      return FALSE;
+    }
+
+  return TRUE;
 }
 
diff --git a/src/bjb-share.h b/src/bjb-share.h
index bd910d7..60ba51b 100644
--- a/src/bjb-share.h
+++ b/src/bjb-share.h
@@ -18,6 +18,5 @@
 #pragma once
 
 #include <libbiji/libbiji.h>
-#include <gtk/gtk.h>
 
-gboolean on_email_note_callback(GtkWidget *widget, BijiNoteObj *note) ;
+gboolean on_email_note_callback (BijiNoteObj *note);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]