[recipes] Fix up mail prototype



commit b56a1db59ee39c4f5935bc8d81cc4aed2467bf56
Author: Matthias Clasen <mclasen redhat com>
Date:   Tue Feb 14 18:44:00 2017 -0500

    Fix up mail prototype
    
    We do async calls here, so we don't really have the opportunity
    to return an error. Instead of going full-blown async, just
    swallow the possible errors here, and simplify the callers.
    
    At the same time, take a window argument and pass its handle
    to the portal, so we have a chance to get window stacking right.

 src/gr-mail.c            |   38 +++++++++++++++++++++++---------------
 src/gr-mail.h            |   10 +++++-----
 src/gr-recipe-exporter.c |   20 +-------------------
 src/gr-shopping-page.c   |   21 +++------------------
 4 files changed, 32 insertions(+), 57 deletions(-)
---
diff --git a/src/gr-mail.c b/src/gr-mail.c
index f68dfb1..8769819 100644
--- a/src/gr-mail.c
+++ b/src/gr-mail.c
@@ -21,8 +21,10 @@
 #include "config.h"
 
 #include "gr-mail.h"
+#include "gr-utils.h"
 
 typedef struct {
+        GtkWindow *window;
         char *address;
         char *subject;
         char *body;
@@ -34,6 +36,7 @@ mail_data_free (gpointer data)
 {
         MailData *md = data;
 
+        window_unexport_handle (md->window);
         g_free (md->address);
         g_free (md->subject);
         g_free (md->body);
@@ -65,7 +68,7 @@ send_mail_using_mailto (MailData *data)
                 g_string_append_printf (url, "&attach=%s", path);
         }
 
-        g_app_info_launch_default_for_uri (url->str, NULL, NULL);
+        gtk_show_uri_on_window (data->window, url->str, GDK_CURRENT_TIME, NULL);
 
         mail_data_free (data);
 }
@@ -99,32 +102,38 @@ callback (GObject      *source,
         reply = g_dbus_proxy_call_finish (G_DBUS_PROXY (source), result, &error);
         if (g_error_matches (error, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_INTERFACE) ||
             g_error_matches (error, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_METHOD)) {
-                /* Email portal not present, fall back to mailto: */
+                g_message ("Email portal not present, falling back to mailto: url");
                 send_mail_using_mailto (md);
                 return;
         }
+        else if (error) {
+                g_message ("Sending mail using Email portal failed: %s", error->message);
+        }
 
         mail_data_free (md);
 }
 
 static void
-send_mail_using_mail_portal (MailData *data)
+window_handle_exported (GtkWindow  *window,
+                        const char *handle_str,
+                        gpointer    data)
 {
+        MailData *md = data;
         GVariantBuilder opt_builder;
         GDBusProxy *proxy;
 
         proxy = get_mail_portal_proxy ();
 
         g_variant_builder_init (&opt_builder, G_VARIANT_TYPE ("a{sv}"));
-        g_variant_builder_add (&opt_builder, "{sv}", "address", g_variant_new_string (data->address));
-        g_variant_builder_add (&opt_builder, "{sv}", "subject", g_variant_new_string (data->subject));
-        g_variant_builder_add (&opt_builder, "{sv}", "body", g_variant_new_string (data->body));
-        g_variant_builder_add (&opt_builder, "{sv}", "attachments", g_variant_new_strv ((const char * const 
*)data->attachments, -1));
+        g_variant_builder_add (&opt_builder, "{sv}", "address", g_variant_new_string (md->address));
+        g_variant_builder_add (&opt_builder, "{sv}", "subject", g_variant_new_string (md->subject));
+        g_variant_builder_add (&opt_builder, "{sv}", "body", g_variant_new_string (md->body));
+        g_variant_builder_add (&opt_builder, "{sv}", "attachments", g_variant_new_strv ((const char * const 
*)md->attachments, -1));
 
         g_dbus_proxy_call (proxy,
                            "ComposeEmail",
                            g_variant_new ("(sa{sv})",
-                                          "",
+                                          handle_str,
                                           &opt_builder),
                            G_DBUS_CALL_FLAGS_NONE,
                            G_MAXINT,
@@ -133,22 +142,21 @@ send_mail_using_mail_portal (MailData *data)
                            data);
 }
 
-gboolean
-gr_send_mail (const char  *address,
+void
+gr_send_mail (GtkWindow   *window,
+              const char  *address,
               const char  *subject,
               const char  *body,
-              const char **attachments,
-              GError     **error)
+              const char **attachments)
 {
         MailData *data;
 
         data = g_new (MailData, 1);
+        data->window = window;
         data->address = g_strdup (address ? address : "");
         data->subject = g_strdup (subject ? subject : "");
         data->body = g_strdup (body ? body : "");
         data->attachments = g_strdupv ((char **)attachments);
 
-        send_mail_using_mail_portal (data);
-
-        return TRUE;
+        window_export_handle (window, window_handle_exported, data);
 }
diff --git a/src/gr-mail.h b/src/gr-mail.h
index 81c8afa..623fd37 100644
--- a/src/gr-mail.h
+++ b/src/gr-mail.h
@@ -24,10 +24,10 @@
 
 G_BEGIN_DECLS
 
-gboolean gr_send_mail (const char  *address,
-                       const char  *subject,
-                       const char  *body,
-                       const char **attachments,
-                       GError     **error);
+void gr_send_mail (GtkWindow *window,
+                   const char  *address,
+                   const char  *subject,
+                   const char  *body,
+                   const char **attachments);
 
 G_END_DECLS
diff --git a/src/gr-recipe-exporter.c b/src/gr-recipe-exporter.c
index f8be949..1762247 100644
--- a/src/gr-recipe-exporter.c
+++ b/src/gr-recipe-exporter.c
@@ -175,25 +175,7 @@ completed_cb (AutoarCompressor *compressor,
         attachments[0] = path;
         attachments[1] = NULL;
 
-        if (!gr_send_mail (address, subject, body, attachments, &error)) {
-                GtkWidget *error_dialog;
-
-                g_message ("Sharing the exported recipe failed: %s", error->message);
-
-                error_dialog = gtk_message_dialog_new (GTK_WINDOW (exporter->window),
-                                                       GTK_DIALOG_MODAL |
-                                                       GTK_DIALOG_DESTROY_WITH_PARENT,
-                                                       GTK_MESSAGE_ERROR,
-                                                       GTK_BUTTONS_CLOSE,
-                                                       _("Could not share recipes"));
-                gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (error_dialog),
-                                                          _("There was an error sending the exported "
-                                                            "recipes by e-mail.\n"
-                                                            "The exported data can be found at ā€œ%sā€."),
-                                                          path);
-                g_signal_connect (error_dialog, "response", G_CALLBACK (gtk_widget_destroy), NULL);
-                gtk_widget_show (error_dialog);
-        }
+        gr_send_mail (GTK_WINDOW (exporter->window), address, subject, body, attachments);
 
         cleanup_export (exporter);
 }
diff --git a/src/gr-shopping-page.c b/src/gr-shopping-page.c
index b5bd44d..e371ac5 100644
--- a/src/gr-shopping-page.c
+++ b/src/gr-shopping-page.c
@@ -680,31 +680,16 @@ share_list (GrShoppingPage *page)
         GList *recipes, *items;
         g_autofree char *text = NULL;
         g_autoptr(GError) error = NULL;
+        GtkWidget *window;
 
         recipes = get_recipes (page);
         items = get_ingredients (page);
 
         text = gr_shopping_list_format (recipes, items);
-        if (!gr_send_mail (NULL, _("Shopping List"), text, NULL, &error)) {
-                GtkWidget *window;
-                GtkWidget *error_dialog;
-
-                g_message ("Sharing the shopping list failed: %s", error->message);
 
-                window = gtk_widget_get_ancestor (GTK_WIDGET (page), GTK_TYPE_APPLICATION_WINDOW);
-                error_dialog = gtk_message_dialog_new (GTK_WINDOW (window),
-                                                       GTK_DIALOG_MODAL |
-                                                       GTK_DIALOG_DESTROY_WITH_PARENT,
-                                                       GTK_MESSAGE_ERROR,
-                                                       GTK_BUTTONS_CLOSE,
-                                                       _("Could not share shopping list"));
-                gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (error_dialog),
-                                                          _("There was an error sending the shopping "
-                                                            "list by e-mail.\n"));
-                g_signal_connect (error_dialog, "response", G_CALLBACK (gtk_widget_destroy), NULL);
-                gtk_widget_show (error_dialog);
+        window = gtk_widget_get_ancestor (GTK_WIDGET (page), GTK_TYPE_APPLICATION_WINDOW);
 
-        }
+        gr_send_mail (GTK_WINDOW (window), NULL, _("Shopping List"), text, NULL);
 
         g_list_free_full (recipes, g_object_unref);
         g_list_free_full (items, item_free);


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