[epiphany/mcatanzaro/file-launching: 3/4] file-helpers: further simplify application launching



commit db28a69a5fd0ff2cf93e77a39c46aefea20d6455
Author: Michael Catanzaro <mcatanzaro igalia com>
Date:   Mon Jan 7 21:29:19 2019 -0600

    file-helpers: further simplify application launching
    
    Remove some unused parameters, make sure we warn on failure, convert to
    autoptrs, etc.

 lib/ephy-file-helpers.c | 69 ++++++++++++++-----------------------------------
 lib/ephy-file-helpers.h |  2 --
 src/window-commands.c   |  6 ++---
 3 files changed, 23 insertions(+), 54 deletions(-)
---
diff --git a/lib/ephy-file-helpers.c b/lib/ephy-file-helpers.c
index 0101fa07e..9d574a005 100644
--- a/lib/ephy-file-helpers.c
+++ b/lib/ephy-file-helpers.c
@@ -463,45 +463,33 @@ ephy_ensure_dir_exists (const char *dir,
   return TRUE;
 }
 
-/**
- * ephy_file_launch_application:
- * @app: the application to launch
- * @list: files to pass to @app
- * @user_time: user time to prevent focus stealing
- * @widget: a relevant widget from where to get the #GdkScreen and #GdkDisplay
- *
- * Launches @app to open @files. If @widget is set the screen and display from
- * it will be used to launch the application, otherwise the defaults will be
- * used.
- *
- * Returns: %TRUE if g_app_info_launch() succeeded
- **/
 static gboolean
-ephy_file_launch_application (GAppInfo  *app,
-                              GList     *list,
-                              guint32    user_time,
-                              GtkWidget *widget)
+launch_application (GAppInfo  *app,
+                    GList     *files,
+                    guint32    user_time)
 {
-  GdkAppLaunchContext *context;
+  g_autoptr(GdkAppLaunchContext) context = NULL;
+  g_autoptr(GError) error = NULL;
   GdkDisplay *display;
   GdkScreen *screen;
   gboolean res;
 
-  if (widget) {
-    display = gtk_widget_get_display (widget);
-    screen = gtk_widget_get_screen (widget);
-  } else {
-    display = gdk_display_get_default ();
-    screen = gdk_screen_get_default ();
-  }
+  /* This is impossible to implement inside flatpak. Higher layers must
+   * ensure we don't get here.
+   */
+  g_assert (!ephy_is_running_inside_flatpak ());
+
+  display = gdk_display_get_default ();
+  screen = gdk_screen_get_default ();
 
   context = gdk_display_get_app_launch_context (display);
   gdk_app_launch_context_set_screen (context, screen);
   gdk_app_launch_context_set_timestamp (context, user_time);
 
-  res = g_app_info_launch (app, list,
-                           G_APP_LAUNCH_CONTEXT (context), NULL);
-  g_object_unref (context);
+  res = g_app_info_launch (app, files,
+                           G_APP_LAUNCH_CONTEXT (context), &error);
+  if (!res)
+    g_warning ("Failed to launch %s: %s", g_app_info_get_display_name (app), error->message);
 
   return res;
 }
@@ -509,27 +497,18 @@ ephy_file_launch_application (GAppInfo  *app,
 /**
  * ephy_file_launch_desktop_file:
  * @filename: the path to the .desktop file
- * @parameter: path to an optional parameter file to pass to the application
- * @user_time: user time to prevent focus stealing
- * @widget: an optional widget for ephy_file_launch_application()
  * @tag: used to guard against improper usage
  *
- * Calls ephy_file_launch_application() for the application described by the
- * .desktop file @filename. Can pass @parameter as optional file arguments.
+ * Launches the application described by the desktop file @filename.
  *
  * Returns: %TRUE if the application launch was successful
  **/
 gboolean
 ephy_file_launch_desktop_file (const char                   *filename,
-                               const char                   *parameter,
                                guint32                       user_time,
-                               GtkWidget                    *widget,
                                EphyFileHelpersNotFlatpakTag  tag)
 {
-  GDesktopAppInfo *app;
-  GFile *file = NULL;
-  GList *list = NULL;
-  gboolean ret;
+  g_autoptr(GDesktopAppInfo) app = NULL;
 
   /* This is impossible to implement inside flatpak. Higher layers must
    * ensure we don't get here.
@@ -538,16 +517,8 @@ ephy_file_launch_desktop_file (const char                   *filename,
   g_assert (!ephy_is_running_inside_flatpak ());
 
   app = g_desktop_app_info_new (filename);
-  if (parameter) {
-    file = g_file_new_for_path (parameter);
-    list = g_list_append (list, file);
-  }
 
-  ret = ephy_file_launch_application (G_APP_INFO (app), list, user_time, widget);
-  g_list_free (list);
-  if (file)
-    g_object_unref (file);
-  return ret;
+  return launch_application (G_APP_INFO (app), NULL, user_time);
 }
 
 static gboolean
@@ -608,7 +579,7 @@ ephy_file_launch_handler (GFile   *file,
   }
 
   list = g_list_append (list, file);
-  ret = ephy_file_launch_application (app, list, user_time, NULL);
+  ret = launch_application (app, list, user_time);
 
   return ret;
 }
diff --git a/lib/ephy-file-helpers.h b/lib/ephy-file-helpers.h
index d2c79a4ab..6ac1ff8a1 100644
--- a/lib/ephy-file-helpers.h
+++ b/lib/ephy-file-helpers.h
@@ -81,9 +81,7 @@ void               ephy_open_incognito_window               (const char
  * careful!
  */
 gboolean           ephy_file_launch_desktop_file            (const char                   *filename,
-                                                             const char                   *parameter,
                                                              guint32                       user_time,
-                                                             GtkWidget                    *widget,
                                                              EphyFileHelpersNotFlatpakTag  tag);
 gboolean           ephy_file_open_uri_in_default_browser    (const char                   *uri,
                                                              guint32                       timestamp,
diff --git a/src/window-commands.c b/src/window-commands.c
index e93d03ac8..7dae14056 100644
--- a/src/window-commands.c
+++ b/src/window-commands.c
@@ -1221,14 +1221,14 @@ notify_launch_cb (NotifyNotification *notification,
                   char               *action,
                   gpointer            user_data)
 {
-  char *desktop_file = user_data;
+  g_autofree char *desktop_file = user_data;
 
   /* We can't get here under flatpak because all web app functionality
    * is disabled when running under flatpak.
    */
-  ephy_file_launch_desktop_file (desktop_file, NULL, 0, NULL,
+  ephy_file_launch_desktop_file (desktop_file,
+                                 gtk_get_current_event_time (),
                                  EPHY_FILE_HELPERS_I_UNDERSTAND_I_MUST_NOT_USE_THIS_FUNCTION_UNDER_FLATPAK);
-  g_free (desktop_file);
 }
 
 static gboolean


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