[gnome-software/wip/mak/libas: 4/9] Replace AS_URL_KIND_MISSING with explicit property




commit 216a2a7d8dc00f47eed0c9b5702e1f268bde1c3c
Author: Matthias Klumpp <matthias tenstral net>
Date:   Fri Jan 8 03:48:05 2021 +0100

    Replace AS_URL_KIND_MISSING with explicit property
    
    AppStream doesn't know AS_URL_KIND_MISSING and it does not make sense to
    add this feature to the specification. Therefore, we add an explicit
    property to GsApp to support the existing funtionality in GNOME
    Software.

 lib/gs-app.c          | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++
 lib/gs-app.h          |  3 +++
 src/gs-app-row.c      |  2 +-
 src/gs-details-page.c |  2 +-
 src/gs-extras-page.c  | 12 ++++-----
 src/gs-search-page.c  |  4 +--
 6 files changed, 80 insertions(+), 10 deletions(-)
---
diff --git a/lib/gs-app.c b/lib/gs-app.c
index b6ce933a7..fdec16795 100644
--- a/lib/gs-app.c
+++ b/lib/gs-app.c
@@ -78,6 +78,7 @@ typedef struct
        GPtrArray               *key_colors;
        GHashTable              *urls;
        GHashTable              *launchables;
+       gchar                   *url_missing;
        gchar                   *license;
        GsAppQuality             license_quality;
        gchar                   **menu_path;
@@ -147,6 +148,7 @@ enum {
        PROP_PENDING_ACTION,
        PROP_KEY_COLORS,
        PROP_IS_UPDATE_DOWNLOADED,
+       PROP_URL_MISSING,
        PROP_LAST
 };
 
@@ -2384,6 +2386,52 @@ gs_app_set_url (GsApp *app, AsUrlKind kind, const gchar *url)
                             g_strdup (url));
 }
 
+/**
+ * gs_app_get_url_missing:
+ * @app: a #GsApp
+ *
+ * Gets a web address for the application with explanations
+ * why it does not have an installation candidate.
+ *
+ * Returns: (nullable): a string, or %NULL for unset
+ *
+ * Since: 40
+ **/
+const gchar *
+gs_app_get_url_missing (GsApp *app)
+{
+       GsAppPrivate *priv = gs_app_get_instance_private (app);
+       g_autoptr(GMutexLocker) locker = NULL;
+       g_return_val_if_fail (GS_IS_APP (app), NULL);
+       locker = g_mutex_locker_new (&priv->mutex);
+       return priv->url_missing;
+}
+
+/**
+ * gs_app_set_url_missing:
+ * @app: a #GsApp
+ * @url: (nullable): a web URL, e.g. `http://www.packagekit.org/pk-package-not-found.html`, or %NULL
+ *
+ * Sets a web address containing explanations why this app
+ * does not have an installation candidate.
+ *
+ * Since: 40
+ **/
+void
+gs_app_set_url_missing (GsApp *app, const gchar *url)
+{
+       GsAppPrivate *priv = gs_app_get_instance_private (app);
+       g_autoptr(GMutexLocker) locker = NULL;
+       g_return_if_fail (GS_IS_APP (app));
+       locker = g_mutex_locker_new (&priv->mutex);
+
+       if (g_strcmp0 (priv->url_missing, url) == 0)
+               return;
+       g_free (priv->url_missing);
+       priv->url_missing = g_strdup (url);
+       gs_app_queue_notify (app, obj_props[PROP_URL_MISSING]);
+}
+
 /**
  * gs_app_get_launchable:
  * @app: a #GsApp
@@ -4437,6 +4485,9 @@ gs_app_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *
        case PROP_IS_UPDATE_DOWNLOADED:
                g_value_set_boolean (value, priv->is_update_downloaded);
                break;
+       case PROP_URL_MISSING:
+               g_value_set_string (value, priv->url_missing);
+               break;
        default:
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
                break;
@@ -4508,6 +4559,9 @@ gs_app_set_property (GObject *object, guint prop_id, const GValue *value, GParam
        case PROP_IS_UPDATE_DOWNLOADED:
                gs_app_set_is_update_downloaded (app, g_value_get_boolean (value));
                break;
+       case PROP_URL_MISSING:
+               gs_app_set_url_missing (app, g_value_get_string (value));
+               break;
        default:
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
                break;
@@ -4546,6 +4600,7 @@ gs_app_finalize (GObject *object)
        g_free (priv->branch);
        g_free (priv->name);
        g_free (priv->renamed_from);
+       g_free (priv->url_missing);
        g_hash_table_unref (priv->urls);
        g_hash_table_unref (priv->launchables);
        g_free (priv->license);
@@ -4731,6 +4786,18 @@ gs_app_class_init (GsAppClass *klass)
                                               FALSE,
                                               G_PARAM_READWRITE);
 
+       /**
+        * GsApp:url-missing:
+        *
+        * A web URL pointing to explanations why this app
+        * does not have an installation candidate.
+        *
+        * Since: 40
+        */
+       obj_props[PROP_URL_MISSING] = g_param_spec_string ("url-missing", NULL, NULL,
+                                       NULL,
+                                       G_PARAM_READWRITE | G_PARAM_CONSTRUCT);
+
        g_object_class_install_properties (object_class, PROP_LAST, obj_props);
 }
 
diff --git a/lib/gs-app.h b/lib/gs-app.h
index 78af6e526..6b7dd5b46 100644
--- a/lib/gs-app.h
+++ b/lib/gs-app.h
@@ -309,6 +309,9 @@ const gchar *gs_app_get_url                 (GsApp          *app,
 void            gs_app_set_url                 (GsApp          *app,
                                                 AsUrlKind       kind,
                                                 const gchar    *url);
+const gchar    *gs_app_get_url_missing         (GsApp          *app);
+void            gs_app_set_url_missing         (GsApp          *app,
+                                                const gchar    *url);
 const gchar    *gs_app_get_launchable          (GsApp          *app,
                                                 AsLaunchableKind kind);
 void            gs_app_set_launchable          (GsApp          *app,
diff --git a/src/gs-app-row.c b/src/gs-app-row.c
index a2fd6e8f2..c2d4e629b 100644
--- a/src/gs-app-row.c
+++ b/src/gs-app-row.c
@@ -252,7 +252,7 @@ gs_app_row_actually_refresh (GsAppRow *app_row)
 
        /* is this a missing search result from the extras page? */
        missing_search_result = (gs_app_get_state (priv->app) == GS_APP_STATE_UNAVAILABLE &&
-                                gs_app_get_url (priv->app, AS_URL_KIND_MISSING) != NULL);
+                                gs_app_get_url_missing (priv->app) != NULL);
 
        /* do a fill bar for the current progress */
        switch (gs_app_get_state (priv->app)) {
diff --git a/src/gs-details-page.c b/src/gs-details-page.c
index bd24f51b8..0dd4fa297 100644
--- a/src/gs-details-page.c
+++ b/src/gs-details-page.c
@@ -924,7 +924,7 @@ gs_details_page_refresh_buttons (GsDetailsPage *self)
                }
                break;
        case GS_APP_STATE_UNAVAILABLE:
-               if (gs_app_get_url (self->app, AS_URL_KIND_MISSING) != NULL) {
+               if (gs_app_get_url_missing (self->app) != NULL) {
                        gtk_widget_set_visible (self->button_install, FALSE);
                } else {
                        gtk_widget_set_visible (self->button_install, TRUE);
diff --git a/src/gs-extras-page.c b/src/gs-extras-page.c
index 21af40ce3..d5fc9c918 100644
--- a/src/gs-extras-page.c
+++ b/src/gs-extras-page.c
@@ -282,9 +282,9 @@ app_row_button_clicked_cb (GsAppRow *app_row,
        GsApp *app = gs_app_row_get_app (app_row);
 
        if (gs_app_get_state (app) == GS_APP_STATE_UNAVAILABLE &&
-           gs_app_get_url (app, AS_URL_KIND_MISSING) != NULL) {
+           gs_app_get_url_missing (app) != NULL) {
                gs_shell_show_uri (self->shell,
-                                  gs_app_get_url (app, AS_URL_KIND_MISSING));
+                                  gs_app_get_url_missing (app));
        } else if (gs_app_get_state (app) == GS_APP_STATE_AVAILABLE ||
                   gs_app_get_state (app) == GS_APP_STATE_AVAILABLE_LOCAL ||
                   gs_app_get_state (app) == GS_APP_STATE_UNAVAILABLE) {
@@ -450,7 +450,7 @@ create_missing_app (SearchData *search_data)
 
        gs_app_set_kind (app, AS_COMPONENT_KIND_GENERIC);
        gs_app_set_state (app, GS_APP_STATE_UNAVAILABLE);
-       gs_app_set_url (app, AS_URL_KIND_MISSING, search_data->url_not_found);
+       gs_app_set_url_missing (app, search_data->url_not_found);
 
        return app;
 }
@@ -479,7 +479,7 @@ build_no_results_label (GsExtrasPage *self)
        g_ptr_array_add (array, NULL);
 
        url = g_strdup_printf ("<a href=\"%s\">%s</a>",
-                              gs_app_get_url (app, AS_URL_KIND_MISSING),
+                              gs_app_get_url_missing (app),
                                /* TRANSLATORS: hyperlink title */
                                _("the documentation"));
 
@@ -1110,9 +1110,9 @@ row_activated_cb (GtkListBox *list_box,
        app = gs_app_row_get_app (GS_APP_ROW (row));
 
        if (gs_app_get_state (app) == GS_APP_STATE_UNAVAILABLE &&
-           gs_app_get_url (app, AS_URL_KIND_MISSING) != NULL) {
+           gs_app_get_url_missing (app) != NULL) {
                gs_shell_show_uri (self->shell,
-                                  gs_app_get_url (app, AS_URL_KIND_MISSING));
+                                  gs_app_get_url_missing (app));
        } else {
                gs_shell_show_app (self->shell, app);
        }
diff --git a/src/gs-search-page.c b/src/gs-search-page.c
index 0ff612845..a44758d39 100644
--- a/src/gs-search-page.c
+++ b/src/gs-search-page.c
@@ -58,14 +58,14 @@ gs_search_page_app_row_clicked_cb (GsAppRow *app_row,
        else if (gs_app_get_state (app) == GS_APP_STATE_INSTALLED)
                gs_page_remove_app (GS_PAGE (self), app, self->cancellable);
        else if (gs_app_get_state (app) == GS_APP_STATE_UNAVAILABLE) {
-               if (gs_app_get_url (app, AS_URL_KIND_MISSING) == NULL) {
+               if (gs_app_get_url_missing (app) == NULL) {
                        gs_page_install_app (GS_PAGE (self), app,
                                             GS_SHELL_INTERACTION_FULL,
                                             self->cancellable);
                        return;
                }
                gs_shell_show_uri (self->shell,
-                                  gs_app_get_url (app, AS_URL_KIND_MISSING));
+                                  gs_app_get_url_missing (app));
        }
 }
 


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