[gnome-software/wip/mak/libas: 10/12] Replace AS_URL_KIND_MISSING with explicit property




commit 2f22d2eff10a5c9452fc06f4f7dfbec396caa00a
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          | 44 ++++++++++++++++++++++++++++++++++++++++++++
 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, 57 insertions(+), 10 deletions(-)
---
diff --git a/lib/gs-app.c b/lib/gs-app.c
index 4278997b8..3ab129893 100644
--- a/lib/gs-app.c
+++ b/lib/gs-app.c
@@ -73,6 +73,7 @@ typedef struct
        GPtrArray               *key_colors;
        GHashTable              *urls;
        GHashTable              *launchables;
+       gchar                   *url_missing;
        gchar                   *license;
        GsAppQuality             license_quality;
        gchar                   **menu_path;
@@ -2384,6 +2385,48 @@ 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: 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: a web URL, e.g. "http://www.packagekit.org/pk-package-not-found.html";
+ *
+ * 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);
+       g_free (priv->url_missing);
+       priv->url_missing = g_strdup (url);
+}
+
 /**
  * gs_app_get_launchable:
  * @app: a #GsApp
@@ -4479,6 +4522,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);
diff --git a/lib/gs-app.h b/lib/gs-app.h
index e624200e6..fceee9877 100644
--- a/lib/gs-app.h
+++ b/lib/gs-app.h
@@ -313,6 +313,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 938f98279..edbafdc28 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 8ac574144..9369bdb63 100644
--- a/src/gs-details-page.c
+++ b/src/gs-details-page.c
@@ -963,7 +963,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 07832e9ad..24c0477ae 100644
--- a/src/gs-search-page.c
+++ b/src/gs-search-page.c
@@ -57,14 +57,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]