[gnome-software] Use AsAppQuirk to simplify future code
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] Use AsAppQuirk to simplify future code
- Date: Fri, 26 Feb 2016 15:15:36 +0000 (UTC)
commit e57b6b9b536e880ba2527b73032039e31874b4f1
Author: Richard Hughes <richard hughsie com>
Date: Fri Feb 26 14:47:01 2016 +0000
Use AsAppQuirk to simplify future code
src/gs-app-row.c | 5 ++-
src/gs-app.c | 40 ++++++++---------------------
src/gs-app.h | 10 +++----
src/gs-plugin-loader.c | 2 +-
src/gs-self-test.c | 2 +-
src/gs-shell-details.c | 22 +++++++++------
src/gs-shell-installed.c | 8 +++--
src/gs-shell-moderate.c | 2 +-
src/plugins/gs-appstream.c | 2 +-
src/plugins/gs-plugin-fedora-provenance.c | 6 ++--
src/plugins/gs-plugin-moduleset.c | 4 +-
11 files changed, 45 insertions(+), 58 deletions(-)
---
diff --git a/src/gs-app-row.c b/src/gs-app-row.c
index 5719693..32fa2f3 100644
--- a/src/gs-app-row.c
+++ b/src/gs-app-row.c
@@ -183,7 +183,8 @@ gs_app_row_refresh (GsAppRow *app_row)
gtk_widget_set_visible (priv->label_tag_nonfree,
!gs_app_get_licence_is_free (priv->app));
gtk_widget_set_visible (priv->label_tag_foreign,
- !gs_app_get_provenance (priv->app));
+ !gs_app_has_quirk (priv->app,
+ AS_APP_QUIRK_PROVENANCE));
break;
}
}
@@ -295,7 +296,7 @@ gs_app_row_refresh (GsAppRow *app_row)
break;
case AS_APP_STATE_UPDATABLE:
case AS_APP_STATE_INSTALLED:
- if (!gs_app_get_compulsory (priv->app))
+ if (!gs_app_has_quirk (priv->app, AS_APP_QUIRK_COMPULSORY))
gtk_widget_set_visible (priv->button, TRUE);
/* TRANSLATORS: this is a button next to the search results that
* allows the application to be easily removed */
diff --git a/src/gs-app.c b/src/gs-app.c
index 4c37315..6ea0d82 100644
--- a/src/gs-app.c
+++ b/src/gs-app.c
@@ -99,8 +99,7 @@ struct _GsApp
guint64 install_date;
guint64 kudos;
gboolean to_be_installed;
- gboolean provenance;
- gboolean compulsory;
+ AsAppQuirk quirk;
gboolean licence_is_free;
GsApp *runtime;
};
@@ -148,7 +147,8 @@ gs_app_to_string (GsApp *app)
g_string_append_printf (str, "\tkind:\t%s\n",
as_app_kind_to_string (app->kind));
g_string_append_printf (str, "\tcompulsory:\t%s\n",
- app->compulsory ? "True" : "False");
+ gs_app_has_quirk (app, AS_APP_QUIRK_COMPULSORY)
+ ? "True" : "False");
g_string_append_printf (str, "\tstate:\t%s\n",
as_app_state_to_string (app->state));
if (app->progress > 0)
@@ -2020,39 +2020,21 @@ gs_app_set_to_be_installed (GsApp *app, gboolean to_be_installed)
}
/**
- * gs_app_get_provenance:
- */
-gboolean
-gs_app_get_provenance (GsApp *app)
-{
- return app->provenance;
-}
-
-/**
- * gs_app_set_provenance:
- */
-void
-gs_app_set_provenance (GsApp *app, gboolean provenance)
-{
- app->provenance = provenance;
-}
-
-/**
- * gs_app_get_compulsory:
- */
+ * gs_app_has_quirk:
+ **/
gboolean
-gs_app_get_compulsory (GsApp *app)
+gs_app_has_quirk (GsApp *app, AsAppQuirk quirk)
{
- return app->compulsory;
+ return (app->quirk & quirk) > 0;
}
/**
- * gs_app_set_compulsory:
- */
+ * gs_app_add_quirk:
+ **/
void
-gs_app_set_compulsory (GsApp *app, gboolean compulsory)
+gs_app_add_quirk (GsApp *app, AsAppQuirk quirk)
{
- app->compulsory = compulsory;
+ app->quirk |= quirk;
}
/**
diff --git a/src/gs-app.h b/src/gs-app.h
index 18bfe5a..9f805da 100644
--- a/src/gs-app.h
+++ b/src/gs-app.h
@@ -228,12 +228,10 @@ void gs_app_set_search_sort_key (GsApp *app,
guint match_value);
const gchar *gs_app_get_search_sort_key (GsApp *app);
-gboolean gs_app_get_provenance (GsApp *app);
-void gs_app_set_provenance (GsApp *app,
- gboolean provenance);
-gboolean gs_app_get_compulsory (GsApp *app);
-void gs_app_set_compulsory (GsApp *app,
- gboolean compulsory);
+gboolean gs_app_has_quirk (GsApp *app,
+ AsAppQuirk quirk);
+void gs_app_add_quirk (GsApp *app,
+ AsAppQuirk quirk);
G_END_DECLS
diff --git a/src/gs-plugin-loader.c b/src/gs-plugin-loader.c
index 1ad87fd..a2b8292 100644
--- a/src/gs-plugin-loader.c
+++ b/src/gs-plugin-loader.c
@@ -601,7 +601,7 @@ gs_plugin_loader_filter_qt_for_gtk (GsApp *app, gpointer user_data)
static gboolean
gs_plugin_loader_app_is_non_compulsory (GsApp *app, gpointer user_data)
{
- return !gs_app_get_compulsory (app);
+ return !gs_app_has_quirk (app, AS_APP_QUIRK_COMPULSORY);
}
/**
diff --git a/src/gs-self-test.c b/src/gs-self-test.c
index e7c9b98..7b12d1b 100644
--- a/src/gs-self-test.c
+++ b/src/gs-self-test.c
@@ -450,7 +450,7 @@ gs_plugin_loader_func (void)
g_assert_cmpstr (gs_app_get_summary (app), ==, "Save images of your screen or individual windows");
g_assert_cmpint (gs_app_get_state (app), ==, AS_APP_STATE_INSTALLED);
g_assert_cmpint (gs_app_get_kind (app), ==, AS_APP_KIND_DESKTOP);
- g_assert (gs_app_get_compulsory (app));
+ g_assert (gs_app_has_quirk (app, AS_APP_QUIRK_COMPULSORY));
g_assert (gs_app_get_pixbuf (app) != NULL);
gs_plugin_list_free (list);
diff --git a/src/gs-shell-details.c b/src/gs-shell-details.c
index eb4907d..20551d7 100644
--- a/src/gs-shell-details.c
+++ b/src/gs-shell-details.c
@@ -250,7 +250,7 @@ gs_shell_details_switch_to (GsShellDetails *self)
gtk_widget_set_visible (self->button_details_launch, FALSE);
/* remove button */
- if (gs_app_get_compulsory (self->app)) {
+ if (gs_app_has_quirk (self->app, AS_APP_QUIRK_COMPULSORY)) {
gtk_widget_set_visible (self->button_remove, FALSE);
} else {
switch (state) {
@@ -305,7 +305,7 @@ gs_shell_details_switch_to (GsShellDetails *self)
}
/* spinner */
- if (gs_app_get_compulsory (self->app)) {
+ if (gs_app_has_quirk (self->app, AS_APP_QUIRK_COMPULSORY)) {
gtk_widget_set_visible (self->spinner_install_remove, FALSE);
gtk_spinner_stop (GTK_SPINNER (self->spinner_install_remove));
} else {
@@ -800,7 +800,7 @@ gs_shell_details_refresh_all (GsShellDetails *self)
} else {
gtk_widget_set_visible (self->label_details_tag_webapp, FALSE);
if (gs_app_get_licence_is_free (self->app) &&
- !gs_app_get_provenance (self->app)) {
+ !gs_app_has_quirk (self->app, AS_APP_QUIRK_PROVENANCE)) {
/* free and 3rd party */
gtk_widget_set_visible (self->label_details_tag_nonfree, FALSE);
gtk_widget_set_visible (self->label_details_tag_3rdparty, TRUE);
@@ -809,7 +809,7 @@ gs_shell_details_refresh_all (GsShellDetails *self)
/* TRANSLATORS: this is the warning box */
_("This software comes from a 3rd party."));
} else if (!gs_app_get_licence_is_free (self->app) &&
- !gs_app_get_provenance (self->app)) {
+ !gs_app_has_quirk (self->app, AS_APP_QUIRK_PROVENANCE)) {
/* nonfree and 3rd party */
gtk_widget_set_visible (self->label_details_tag_nonfree, TRUE);
gtk_widget_set_visible (self->label_details_tag_3rdparty, TRUE);
@@ -818,7 +818,7 @@ gs_shell_details_refresh_all (GsShellDetails *self)
/* TRANSLATORS: this is the warning box */
_("This software comes from a 3rd party and may contain non-free
components."));
} else if (!gs_app_get_licence_is_free (self->app) &&
- gs_app_get_provenance (self->app)) {
+ gs_app_has_quirk (self->app, AS_APP_QUIRK_PROVENANCE)) {
/* nonfree and distro */
gtk_widget_set_visible (self->label_details_tag_nonfree, TRUE);
gtk_widget_set_visible (self->label_details_tag_3rdparty, FALSE);
@@ -862,7 +862,7 @@ gs_shell_details_refresh_all (GsShellDetails *self)
/* are we trying to replace something in the baseos */
gtk_widget_set_visible (self->infobar_details_package_baseos,
- gs_app_get_compulsory (self->app) &&
+ gs_app_has_quirk (self->app, AS_APP_QUIRK_COMPULSORY) &&
gs_app_get_state (self->app) == AS_APP_STATE_AVAILABLE_LOCAL);
/* is this a repo-release */
@@ -876,10 +876,12 @@ gs_shell_details_refresh_all (GsShellDetails *self)
}
/* installing a app with a repo file */
- tmp = gs_app_get_metadata_item (self->app, "PackageKit::has-source");
switch (gs_app_get_kind (self->app)) {
case AS_APP_KIND_DESKTOP:
- gtk_widget_set_visible (self->infobar_details_app_repo, tmp != NULL && gs_app_get_state
(self->app) == AS_APP_STATE_AVAILABLE_LOCAL);
+ gtk_widget_set_visible (self->infobar_details_app_repo,
+ gs_app_has_quirk (self->app,
+ AS_APP_QUIRK_HAS_SOURCE) &&
+ gs_app_get_state (self->app) == AS_APP_STATE_AVAILABLE_LOCAL);
break;
default:
gtk_widget_set_visible (self->infobar_details_app_repo, FALSE);
@@ -893,7 +895,9 @@ gs_shell_details_refresh_all (GsShellDetails *self)
gtk_widget_set_visible (self->infobar_details_app_norepo, FALSE);
} else {
gtk_widget_set_visible (self->infobar_details_app_norepo,
- tmp == NULL && gs_app_get_state (self->app) ==
AS_APP_STATE_AVAILABLE_LOCAL);
+ !gs_app_has_quirk (self->app,
+ AS_APP_QUIRK_HAS_SOURCE) &&
+ gs_app_get_state (self->app) == AS_APP_STATE_AVAILABLE_LOCAL);
}
break;
default:
diff --git a/src/gs-shell-installed.c b/src/gs-shell-installed.c
index 66e4760..0512bfb 100644
--- a/src/gs-shell-installed.c
+++ b/src/gs-shell-installed.c
@@ -342,7 +342,7 @@ gs_shell_installed_get_app_sort_key (GsApp *app)
}
/* sort normal, compulsory */
- if (!gs_app_get_compulsory (app))
+ if (!gs_app_has_quirk (app, AS_APP_QUIRK_COMPULSORY))
g_string_append (key, "1:");
else
g_string_append (key, "2:");
@@ -412,8 +412,10 @@ gs_shell_installed_list_header_func (GtkListBoxRow *row,
if (before == NULL)
return;
- if (!gs_app_get_compulsory (gs_app_row_get_app (GS_APP_ROW (before))) &&
- gs_app_get_compulsory (gs_app_row_get_app (GS_APP_ROW (row)))) {
+ if (!gs_app_has_quirk (gs_app_row_get_app (GS_APP_ROW (before)),
+ AS_APP_QUIRK_COMPULSORY) &&
+ gs_app_has_quirk (gs_app_row_get_app (GS_APP_ROW (row)),
+ AS_APP_QUIRK_COMPULSORY)) {
/* TRANSLATORS: This is the header dividing the normal
* applications and the system ones */
header = gtk_label_new (_("System Applications"));
diff --git a/src/gs-shell-moderate.c b/src/gs-shell-moderate.c
index 7516a4c..e32c464 100644
--- a/src/gs-shell-moderate.c
+++ b/src/gs-shell-moderate.c
@@ -103,7 +103,7 @@ gs_shell_moderate_add_app (GsShellModerate *self, GsApp *app)
guint i;
/* this hides the action button */
- gs_app_set_compulsory (app, TRUE);
+ gs_app_add_quirk (app, AS_APP_QUIRK_COMPULSORY);
/* add top level app */
app_row = gs_app_row_new (app);
diff --git a/src/plugins/gs-appstream.c b/src/plugins/gs-appstream.c
index 5e526a0..19278be 100644
--- a/src/plugins/gs-appstream.c
+++ b/src/plugins/gs-appstream.c
@@ -483,7 +483,7 @@ gs_appstream_refine_app (GsPlugin *plugin, GsApp *app, AsApp *item, GError **err
/* this is a core application for the desktop and cannot be removed */
if (_as_app_has_compulsory_for_desktop (item, "GNOME") &&
gs_app_get_kind (app) == AS_APP_KIND_DESKTOP)
- gs_app_set_compulsory (app, TRUE);
+ gs_app_add_quirk (app, AS_APP_QUIRK_COMPULSORY);
/* set id kind */
if (gs_app_get_kind (app) == AS_APP_KIND_UNKNOWN)
diff --git a/src/plugins/gs-plugin-fedora-provenance.c b/src/plugins/gs-plugin-fedora-provenance.c
index b5d7c61..f91eba3 100644
--- a/src/plugins/gs-plugin-fedora-provenance.c
+++ b/src/plugins/gs-plugin-fedora-provenance.c
@@ -101,7 +101,7 @@ gs_plugin_fedora_provenance_refine_app (GsApp *app)
/* simple case */
origin = gs_app_get_origin (app);
if (origin != NULL && g_strv_contains (valid, origin)) {
- gs_app_set_provenance (app, TRUE);
+ gs_app_add_quirk (app, AS_APP_QUIRK_PROVENANCE);
return;
}
@@ -116,7 +116,7 @@ gs_plugin_fedora_provenance_refine_app (GsApp *app)
origin += 10;
for (i = 0; valid[i] != NULL; i++) {
if (g_strcmp0 (origin + 1, valid[i]) == 0) {
- gs_app_set_provenance (app, TRUE);
+ gs_app_add_quirk (app, AS_APP_QUIRK_PROVENANCE);
break;
}
}
@@ -142,7 +142,7 @@ gs_plugin_refine (GsPlugin *plugin,
/* refine apps */
for (l = *list; l != NULL; l = l->next) {
app = GS_APP (l->data);
- if (gs_app_get_provenance (app))
+ if (gs_app_has_quirk (app, AS_APP_QUIRK_PROVENANCE))
continue;
gs_plugin_fedora_provenance_refine_app (app);
}
diff --git a/src/plugins/gs-plugin-moduleset.c b/src/plugins/gs-plugin-moduleset.c
index 7d32e36..4baf8f5 100644
--- a/src/plugins/gs-plugin-moduleset.c
+++ b/src/plugins/gs-plugin-moduleset.c
@@ -332,7 +332,7 @@ gs_plugin_refine (GsPlugin *plugin,
/* mark each one as system */
for (i = 0; system_apps[i] != NULL; i++) {
if (g_strcmp0 (system_apps[i], gs_app_get_id (app)) == 0) {
- gs_app_set_compulsory (app, TRUE);
+ gs_app_add_quirk (app, AS_APP_QUIRK_COMPULSORY);
break;
}
}
@@ -340,7 +340,7 @@ gs_plugin_refine (GsPlugin *plugin,
/* mark each one as core */
for (i = 0; core_pkgs[i] != NULL; i++) {
if (g_strcmp0 (core_pkgs[i], gs_app_get_source_default (app)) == 0) {
- gs_app_set_compulsory (app, TRUE);
+ gs_app_add_quirk (app, AS_APP_QUIRK_COMPULSORY);
break;
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]