[gnome-software: 3/7] age-rating-context-dialog: Refactor getting attribute info
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software: 3/7] age-rating-context-dialog: Refactor getting attribute info
- Date: Tue, 8 Feb 2022 08:59:14 +0000 (UTC)
commit 9eaf529a1f20befc10f173a22e26f06efd9b0ddf
Author: Adrien Plazas <kekun plazas laposte net>
Date: Fri Feb 4 09:00:27 2022 +0100
age-rating-context-dialog: Refactor getting attribute info
This avoids some small code duplication.
src/gs-age-rating-context-dialog.c | 52 +++++++++++++++++---------------------
1 file changed, 23 insertions(+), 29 deletions(-)
---
diff --git a/src/gs-age-rating-context-dialog.c b/src/gs-age-rating-context-dialog.c
index 1263f531f..3555623a8 100644
--- a/src/gs-age-rating-context-dialog.c
+++ b/src/gs-age-rating-context-dialog.c
@@ -390,46 +390,40 @@ content_rating_attribute_get_unknown_description (const gchar *attribute)
g_assert_not_reached ();
}
-static void
-add_attribute_row (GtkListBox *list_box,
- const gchar *attribute,
- AsContentRatingValue value)
+static GsContextDialogRowImportance
+content_rating_value_get_importance (AsContentRatingValue value)
{
- GtkListBoxRow *row;
- GsContextDialogRowImportance rating;
- const gchar *icon_name, *title, *description;
-
switch (value) {
- case AS_CONTENT_RATING_VALUE_UNKNOWN:
- rating = GS_CONTEXT_DIALOG_ROW_IMPORTANCE_NEUTRAL;
- icon_name = content_rating_attribute_get_icon_name (attribute, FALSE);
- description = content_rating_attribute_get_unknown_description (attribute);
- break;
case AS_CONTENT_RATING_VALUE_NONE:
- rating = GS_CONTEXT_DIALOG_ROW_IMPORTANCE_UNIMPORTANT;
- icon_name = content_rating_attribute_get_icon_name (attribute, TRUE);
- description = as_content_rating_attribute_get_description (attribute, value);
- break;
+ return GS_CONTEXT_DIALOG_ROW_IMPORTANCE_UNIMPORTANT;
+ case AS_CONTENT_RATING_VALUE_UNKNOWN:
+ return GS_CONTEXT_DIALOG_ROW_IMPORTANCE_NEUTRAL;
case AS_CONTENT_RATING_VALUE_MILD:
- rating = GS_CONTEXT_DIALOG_ROW_IMPORTANCE_WARNING;
- icon_name = content_rating_attribute_get_icon_name (attribute, FALSE);
- description = as_content_rating_attribute_get_description (attribute, value);
- break;
case AS_CONTENT_RATING_VALUE_MODERATE:
- rating = GS_CONTEXT_DIALOG_ROW_IMPORTANCE_WARNING;
- icon_name = content_rating_attribute_get_icon_name (attribute, FALSE);
- description = as_content_rating_attribute_get_description (attribute, value);
- break;
+ return GS_CONTEXT_DIALOG_ROW_IMPORTANCE_WARNING;
case AS_CONTENT_RATING_VALUE_INTENSE:
- rating = GS_CONTEXT_DIALOG_ROW_IMPORTANCE_IMPORTANT;
- icon_name = content_rating_attribute_get_icon_name (attribute, FALSE);
- description = as_content_rating_attribute_get_description (attribute, value);
- break;
+ return GS_CONTEXT_DIALOG_ROW_IMPORTANCE_IMPORTANT;
default:
g_assert_not_reached ();
}
+}
+
+static void
+add_attribute_row (GtkListBox *list_box,
+ const gchar *attribute,
+ AsContentRatingValue value)
+{
+ GtkListBoxRow *row;
+ GsContextDialogRowImportance rating;
+ const gchar *icon_name, *title, *description;
+ rating = content_rating_value_get_importance (value);
+ icon_name = content_rating_attribute_get_icon_name (attribute, value == AS_CONTENT_RATING_VALUE_NONE);
title = content_rating_attribute_get_title (attribute);
+ if (value == AS_CONTENT_RATING_VALUE_UNKNOWN)
+ description = content_rating_attribute_get_unknown_description (attribute);
+ else
+ description = as_content_rating_attribute_get_description (attribute, value);
row = gs_context_dialog_row_new (icon_name, rating, title, description);
gtk_list_box_append (list_box, GTK_WIDGET (row));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]