[epiphany/mwleeds/webapp-dbus-api: 17/17] Fix web app icon url vs path confusion




commit 4439580d81f406c71e322df3f3dcdf1bc4759eed
Author: Phaedrus Leeds <mwleeds protonmail com>
Date:   Wed Feb 23 15:43:50 2022 -0800

    Fix web app icon url vs path confusion
    
    Confusingly, the icon_url member of EphyWebApplication is actually a
    path not a URL or URI. The only place where it gets set to a URI is in
    prefs-general-page.c when the user changes the icon, and there it is
    happening erroneously since all the other code that deals with it
    assumes it is a path. So, rename the struct member and ensure all the
    use of it treats it as a path.

 embed/ephy-about-handler.c                       | 16 ++++++++--------
 lib/ephy-web-app-utils.c                         | 16 ++++++++--------
 lib/ephy-web-app-utils.h                         |  4 ++--
 src/preferences/prefs-general-page.c             | 24 ++++++++++++------------
 src/profile-migrator/ephy-legacy-web-app-utils.c |  2 +-
 5 files changed, 31 insertions(+), 31 deletions(-)
---
diff --git a/embed/ephy-about-handler.c b/embed/ephy-about-handler.c
index cd8b1c381..fc0459c97 100644
--- a/embed/ephy-about-handler.c
+++ b/embed/ephy-about-handler.c
@@ -264,8 +264,8 @@ handle_applications_finished_cb (EphyAboutHandler       *handler,
 
     for (p = applications; p; p = p->next) {
       EphyWebApplication *app = (EphyWebApplication *)p->data;
-      const char *icon_url;
-      g_autofree char *encoded_icon_url = NULL;
+      const char *icon_path = NULL;
+      g_autofree char *encoded_icon_path = NULL;
       g_autofree char *encoded_name = NULL;
       g_autofree char *encoded_url = NULL;
       g_autofree char *js_encoded_id = NULL;
@@ -281,12 +281,12 @@ handle_applications_finished_cb (EphyAboutHandler       *handler,
 
       /* In the sandbox we don't have access to the host side icon file */
       if (ephy_is_running_inside_sandbox ())
-        icon_url = app->tmp_icon_url;
+        icon_path = app->tmp_icon_path;
       else
-        icon_url = app->icon_url;
+        icon_path = app->icon_path;
 
-      if (!icon_url) {
-        g_warning ("Failed to get icon url for app %s", app->id);
+      if (!icon_path) {
+        g_warning ("Failed to get icon path for app %s", app->id);
         continue;
       }
 
@@ -297,7 +297,7 @@ handle_applications_finished_cb (EphyAboutHandler       *handler,
        * anything at all, so those need to be encoded for sure. Install date
        * should be fine because it's constructed by Epiphany.
        */
-      encoded_icon_url = ephy_encode_for_html_attribute (icon_url);
+      encoded_icon_path = ephy_encode_for_html_attribute (icon_path);
       encoded_name = ephy_encode_for_html_entity (app->name);
       encoded_url = ephy_encode_for_html_entity (app->url);
       g_string_append_printf (data_str,
@@ -307,7 +307,7 @@ handle_applications_finished_cb (EphyAboutHandler       *handler,
                               "<td class=\"input\"><input type=\"button\" value=\"%s\" 
onclick=\"deleteWebApp('%s');\" "
                               "class=\"destructive-action\"></td>"
                               "<td class=\"date\">%s <br /> %s</td></tr></tbody>",
-                              app->id, encoded_icon_url, encoded_name, encoded_url, _("Delete"), app->id,
+                              app->id, encoded_icon_path, encoded_name, encoded_url, _("Delete"), app->id,
                               /* Note for translators: this refers to the installation date. */
                               _("Installed on:"), install_date);
     }
diff --git a/lib/ephy-web-app-utils.c b/lib/ephy-web-app-utils.c
index 0f70dbfcd..756d57320 100644
--- a/lib/ephy-web-app-utils.c
+++ b/lib/ephy-web-app-utils.c
@@ -564,8 +564,8 @@ ephy_web_application_free (EphyWebApplication *app)
 {
   g_free (app->id);
   g_free (app->name);
-  g_free (app->icon_url);
-  g_free (app->tmp_icon_url);
+  g_free (app->icon_path);
+  g_free (app->tmp_icon_path);
   g_free (app->url);
   g_free (app->desktop_file);
   g_free (app->desktop_path);
@@ -672,11 +672,11 @@ ephy_web_application_for_profile_directory (const char            *profile_dir,
     }
 
     app->name = g_key_file_get_string (key_file, "Desktop Entry", "Name", NULL);
-    app->icon_url = g_key_file_get_string (key_file, "Desktop Entry", "Icon", NULL);
+    app->icon_path = g_key_file_get_string (key_file, "Desktop Entry", "Icon", NULL);
 
     if (ephy_is_running_inside_sandbox () && need_tmp_icon == EPHY_WEB_APP_NEED_TMP_ICON) {
-      app->tmp_icon_url = ephy_web_application_get_tmp_icon_path (app->desktop_path, &error);
-      if (!app->tmp_icon_url)
+      app->tmp_icon_path = ephy_web_application_get_tmp_icon_path (app->desktop_path, &error);
+      if (!app->tmp_icon_path)
         g_warning ("Failed to get tmp icon path for app %s: %s", app->id, error->message);
     }
 
@@ -706,7 +706,7 @@ ephy_web_application_for_profile_directory (const char            *profile_dir,
   }
 
   app->name = g_strdup (g_app_info_get_name (G_APP_INFO (desktop_info)));
-  app->icon_url = g_desktop_app_info_get_string (desktop_info, "Icon");
+  app->icon_path = g_desktop_app_info_get_string (desktop_info, "Icon");
   exec = g_app_info_get_commandline (G_APP_INFO (desktop_info));
   if (g_shell_parse_argv (exec, &argc, &argv, NULL))
     app->url = g_strdup (argv[argc - 1]);
@@ -997,11 +997,11 @@ ephy_web_application_save (EphyWebApplication *app)
     }
 
     icon = g_key_file_get_string (key, "Desktop Entry", "Icon", NULL);
-    if (g_strcmp0 (icon, app->icon_url) != 0) {
+    if (g_strcmp0 (icon, app->icon_path) != 0) {
       g_autoptr (GFile) new_icon = NULL;
       g_autoptr (GFile) old_icon = NULL;
       changed = TRUE;
-      new_icon = g_file_new_for_path (app->icon_url);
+      new_icon = g_file_new_for_path (app->icon_path);
       old_icon = g_file_new_for_path (icon);
       g_file_copy_async (new_icon, old_icon, G_FILE_COPY_OVERWRITE,
                          G_PRIORITY_DEFAULT, NULL, NULL, NULL,
diff --git a/lib/ephy-web-app-utils.h b/lib/ephy-web-app-utils.h
index 3870d63a8..66530f9c0 100644
--- a/lib/ephy-web-app-utils.h
+++ b/lib/ephy-web-app-utils.h
@@ -29,8 +29,8 @@ G_BEGIN_DECLS
 typedef struct {
   char *id;
   char *name;
-  char *icon_url;
-  char *tmp_icon_url;
+  char *icon_path;
+  char *tmp_icon_path;
   char *url;
   char *desktop_file; /* only used for legacy apps */
   char *desktop_path;
diff --git a/src/preferences/prefs-general-page.c b/src/preferences/prefs-general-page.c
index 297201850..ba795bdf3 100644
--- a/src/preferences/prefs-general-page.c
+++ b/src/preferences/prefs-general-page.c
@@ -808,10 +808,10 @@ save_web_application (PrefsGeneralPage *general_page)
     changed = TRUE;
   }
 
-  text = (const char *)g_object_get_data (G_OBJECT (general_page->webapp_icon), "ephy-webapp-icon-url");
-  if (g_strcmp0 (general_page->webapp->icon_url, text) != 0) {
-    g_free (general_page->webapp->icon_url);
-    general_page->webapp->icon_url = g_strdup (text);
+  text = (const char *)g_object_get_data (G_OBJECT (general_page->webapp_icon), "ephy-webapp-icon-path");
+  if (g_strcmp0 (general_page->webapp->icon_path, text) != 0) {
+    g_free (general_page->webapp->icon_path);
+    general_page->webapp->icon_path = g_strdup (text);
     changed = TRUE;
   }
 
@@ -833,9 +833,9 @@ prefs_general_page_save_web_application (PrefsGeneralPage *general_page)
 
 static void
 prefs_general_page_update_webapp_icon (PrefsGeneralPage *general_page,
-                                       const char       *icon_url)
+                                       const char       *icon_path)
 {
-  g_autoptr (GdkPixbuf) icon = gdk_pixbuf_new_from_file (icon_url, NULL);
+  g_autoptr (GdkPixbuf) icon = gdk_pixbuf_new_from_file (icon_path, NULL);
 
   if (!icon)
     return;
@@ -845,8 +845,8 @@ prefs_general_page_update_webapp_icon (PrefsGeneralPage *general_page,
                             GTK_ICON_SIZE_DND);
   gtk_image_set_pixel_size (GTK_IMAGE (general_page->webapp_icon), 32);
 
-  g_object_set_data_full (G_OBJECT (general_page->webapp_icon), "ephy-webapp-icon-url",
-                          g_strdup (icon_url), g_free);
+  g_object_set_data_full (G_OBJECT (general_page->webapp_icon), "ephy-webapp-icon-path",
+                          g_strdup (icon_path), g_free);
 }
 
 static void
@@ -856,11 +856,11 @@ webapp_icon_chooser_response_cb (GtkNativeDialog  *file_chooser,
 {
   if (response == GTK_RESPONSE_ACCEPT) {
     g_autoptr (GFile) icon_file = NULL;
-    g_autofree char *icon_url = NULL;
+    g_autofree char *icon_path = NULL;
 
     icon_file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (file_chooser));
-    icon_url = g_file_get_uri (icon_file);
-    prefs_general_page_update_webapp_icon (general_page, icon_url);
+    icon_path = g_file_get_path (icon_file);
+    prefs_general_page_update_webapp_icon (general_page, icon_path);
     prefs_general_page_save_web_application (general_page);
   }
 
@@ -1181,7 +1181,7 @@ setup_general_page (PrefsGeneralPage *general_page)
     g_assert (general_page->webapp);
 
     if (!g_settings_get_boolean (EPHY_SETTINGS_WEB_APP, EPHY_PREFS_WEB_APP_SYSTEM)) {
-      prefs_general_page_update_webapp_icon (general_page, general_page->webapp->icon_url);
+      prefs_general_page_update_webapp_icon (general_page, general_page->webapp->icon_path);
       gtk_entry_set_text (GTK_ENTRY (general_page->webapp_url), general_page->webapp->url);
       gtk_entry_set_text (GTK_ENTRY (general_page->webapp_title), general_page->webapp->name);
     }
diff --git a/src/profile-migrator/ephy-legacy-web-app-utils.c 
b/src/profile-migrator/ephy-legacy-web-app-utils.c
index c256bf1ac..13b49c78a 100644
--- a/src/profile-migrator/ephy-legacy-web-app-utils.c
+++ b/src/profile-migrator/ephy-legacy-web-app-utils.c
@@ -254,7 +254,7 @@ ephy_legacy_web_application_for_profile_directory (const char *profile_dir)
   }
 
   app->name = g_strdup (g_app_info_get_name (G_APP_INFO (desktop_info)));
-  app->icon_url = g_desktop_app_info_get_string (desktop_info, "Icon");
+  app->icon_path = g_desktop_app_info_get_string (desktop_info, "Icon");
   exec = g_app_info_get_commandline (G_APP_INFO (desktop_info));
   if (g_shell_parse_argv (exec, &argc, &argv, NULL))
     app->url = g_strdup (argv[argc - 1]);


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