[gnome-software: 1/2] context-dialog-row: Make it an AdwActionRow
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software: 1/2] context-dialog-row: Make it an AdwActionRow
- Date: Thu, 3 Feb 2022 10:58:02 +0000 (UTC)
commit df0dad70849ab39f30ba4073bfd110d6c6a04a3d
Author: Adrien Plazas <kekun plazas laposte net>
Date: Wed Feb 2 13:09:29 2022 +0100
context-dialog-row: Make it an AdwActionRow
This makes the code simpler and makes the style in line with other rows.
src/gs-age-rating-context-dialog.c | 4 +-
src/gs-context-dialog-row.c | 93 ++------------------------------------
src/gs-context-dialog-row.h | 5 +-
src/gs-context-dialog-row.ui | 90 +++++++++---------------------------
4 files changed, 31 insertions(+), 161 deletions(-)
---
diff --git a/src/gs-age-rating-context-dialog.c b/src/gs-age-rating-context-dialog.c
index 8d60aa21d..ecd885ad8 100644
--- a/src/gs-age-rating-context-dialog.c
+++ b/src/gs-age-rating-context-dialog.c
@@ -745,8 +745,8 @@ sort_cb (GtkListBoxRow *row1,
if (importance1 != importance2)
return importance2 - importance1;
- title1 = gs_context_dialog_row_get_title (_row1);
- title2 = gs_context_dialog_row_get_title (_row2);
+ title1 = adw_preferences_row_get_title (ADW_PREFERENCES_ROW (_row1));
+ title2 = adw_preferences_row_get_title (ADW_PREFERENCES_ROW (_row2));
return g_strcmp0 (title1, title2);
}
diff --git a/src/gs-context-dialog-row.c b/src/gs-context-dialog-row.c
index 26e9c845e..3bbe9b036 100644
--- a/src/gs-context-dialog-row.c
+++ b/src/gs-context-dialog-row.c
@@ -23,6 +23,7 @@
#include "config.h"
+#include <adwaita.h>
#include <glib.h>
#include <glib-object.h>
#include <glib/gi18n.h>
@@ -33,28 +34,24 @@
struct _GsContextDialogRow
{
- GtkListBoxRow parent_instance;
+ AdwActionRow parent_instance;
GsContextDialogRowImportance importance;
GtkWidget *lozenge; /* (unowned) */
GtkImage *lozenge_content_image; /* (unowned) */
GtkLabel *lozenge_content_text; /* (unowned) */
- GtkLabel *title; /* (unowned) */
- GtkLabel *description; /* (unowned) */
};
-G_DEFINE_TYPE (GsContextDialogRow, gs_context_dialog_row, GTK_TYPE_LIST_BOX_ROW)
+G_DEFINE_TYPE (GsContextDialogRow, gs_context_dialog_row, ADW_TYPE_ACTION_ROW)
typedef enum {
PROP_ICON_NAME = 1,
PROP_CONTENT,
PROP_IMPORTANCE,
- PROP_TITLE,
- PROP_DESCRIPTION,
} GsContextDialogRowProperty;
-static GParamSpec *obj_props[PROP_DESCRIPTION + 1] = { NULL, };
+static GParamSpec *obj_props[PROP_IMPORTANCE + 1] = { NULL, };
/* These match the CSS classes from gtk-style.css. */
static const gchar *
@@ -98,12 +95,6 @@ gs_context_dialog_row_get_property (GObject *object,
case PROP_IMPORTANCE:
g_value_set_enum (value, gs_context_dialog_row_get_importance (self));
break;
- case PROP_TITLE:
- g_value_set_string (value, gs_context_dialog_row_get_title (self));
- break;
- case PROP_DESCRIPTION:
- g_value_set_string (value, gs_context_dialog_row_get_description (self));
- break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -146,12 +137,6 @@ gs_context_dialog_row_set_property (GObject *object,
gtk_style_context_add_class (context, css_class);
break;
}
- case PROP_TITLE:
- gtk_label_set_text (self->title, g_value_get_string (value));
- break;
- case PROP_DESCRIPTION:
- gtk_label_set_text (self->description, g_value_get_string (value));
- break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -211,34 +196,6 @@ gs_context_dialog_row_class_init (GsContextDialogRowClass *klass)
GS_TYPE_CONTEXT_DIALOG_ROW_IMPORTANCE,
GS_CONTEXT_DIALOG_ROW_IMPORTANCE_NEUTRAL,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
- /**
- * GsContextDialogRow:title: (not nullable)
- *
- * The human readable and translated title of the row.
- *
- * This may not be %NULL.
- *
- * Since: 41
- */
- obj_props[PROP_TITLE] =
- g_param_spec_string ("title", NULL, NULL,
- NULL,
- G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
-
- /**
- * GsContextDialogRow:description: (not nullable)
- *
- * The human readable and translated description of the row.
- *
- * This may not be %NULL.
- *
- * Since: 41
- */
- obj_props[PROP_DESCRIPTION] =
- g_param_spec_string ("description", NULL, NULL,
- NULL,
- G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
-
g_object_class_install_properties (object_class, G_N_ELEMENTS (obj_props), obj_props);
/* This uses the same CSS name as a standard #GtkListBoxRow in order to
@@ -249,8 +206,6 @@ gs_context_dialog_row_class_init (GsContextDialogRowClass *klass)
gtk_widget_class_bind_template_child (widget_class, GsContextDialogRow, lozenge);
gtk_widget_class_bind_template_child (widget_class, GsContextDialogRow, lozenge_content_image);
gtk_widget_class_bind_template_child (widget_class, GsContextDialogRow, lozenge_content_text);
- gtk_widget_class_bind_template_child (widget_class, GsContextDialogRow, title);
- gtk_widget_class_bind_template_child (widget_class, GsContextDialogRow, description);
}
/**
@@ -279,7 +234,7 @@ gs_context_dialog_row_new (const gchar *icon_name,
"icon-name", icon_name,
"importance", importance,
"title", title,
- "description", description,
+ "subtitle", description,
NULL);
}
@@ -364,40 +319,6 @@ gs_context_dialog_row_get_importance (GsContextDialogRow *self)
return self->importance;
}
-/**
- * gs_context_dialog_row_get_title:
- * @self: a #GsContextDialogRow
- *
- * Get the value of #GsContextDialogRow:title.
- *
- * Returns: (not nullable): title for the row
- * Since: 41
- */
-const gchar *
-gs_context_dialog_row_get_title (GsContextDialogRow *self)
-{
- g_return_val_if_fail (GS_IS_CONTEXT_DIALOG_ROW (self), NULL);
-
- return gtk_label_get_text (self->title);
-}
-
-/**
- * gs_context_dialog_row_get_description:
- * @self: a #GsContextDialogRow
- *
- * Get the value of #GsContextDialogRow:description.
- *
- * Returns: (not nullable): description for the row
- * Since: 41
- */
-const gchar *
-gs_context_dialog_row_get_description (GsContextDialogRow *self)
-{
- g_return_val_if_fail (GS_IS_CONTEXT_DIALOG_ROW (self), NULL);
-
- return gtk_label_get_text (self->description);
-}
-
/**
* gs_context_dialog_row_set_size_groups:
* @self: a #GsContextDialogRow
@@ -423,8 +344,4 @@ gs_context_dialog_row_set_size_groups (GsContextDialogRow *self,
if (lozenge != NULL)
gtk_size_group_add_widget (lozenge, self->lozenge);
- if (title != NULL)
- gtk_size_group_add_widget (title, GTK_WIDGET (self->title));
- if (description != NULL)
- gtk_size_group_add_widget (description, GTK_WIDGET (self->description));
}
diff --git a/src/gs-context-dialog-row.h b/src/gs-context-dialog-row.h
index e6f03462e..97b3681e1 100644
--- a/src/gs-context-dialog-row.h
+++ b/src/gs-context-dialog-row.h
@@ -10,6 +10,7 @@
#pragma once
+#include <adwaita.h>
#include <glib.h>
#include <glib-object.h>
#include <gtk/gtk.h>
@@ -40,7 +41,7 @@ typedef enum
#define GS_TYPE_CONTEXT_DIALOG_ROW (gs_context_dialog_row_get_type ())
-G_DECLARE_FINAL_TYPE (GsContextDialogRow, gs_context_dialog_row, GS, CONTEXT_DIALOG_ROW, GtkListBoxRow)
+G_DECLARE_FINAL_TYPE (GsContextDialogRow, gs_context_dialog_row, GS, CONTEXT_DIALOG_ROW, AdwActionRow)
GtkListBoxRow *gs_context_dialog_row_new (const gchar *icon_name,
GsContextDialogRowImportance importance,
@@ -54,8 +55,6 @@ GtkListBoxRow *gs_context_dialog_row_new_text (const gchar *content,
const gchar *gs_context_dialog_row_get_icon_name (GsContextDialogRow *self);
const gchar *gs_context_dialog_row_get_content (GsContextDialogRow *self);
GsContextDialogRowImportance gs_context_dialog_row_get_importance (GsContextDialogRow *self);
-const gchar *gs_context_dialog_row_get_title (GsContextDialogRow *self);
-const gchar *gs_context_dialog_row_get_description (GsContextDialogRow *self);
void gs_context_dialog_row_set_size_groups (GsContextDialogRow *self,
GtkSizeGroup *lozenge,
diff --git a/src/gs-context-dialog-row.ui b/src/gs-context-dialog-row.ui
index 43deca35e..7777b4dd6 100644
--- a/src/gs-context-dialog-row.ui
+++ b/src/gs-context-dialog-row.ui
@@ -1,82 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<requires lib="gtk+" version="3.10"/>
- <template class="GsContextDialogRow" parent="GtkListBoxRow">
+ <template class="GsContextDialogRow" parent="AdwActionRow">
<property name="activatable">False</property>
<property name="focusable">False</property>
- <child>
- <object class="GtkBox">
- <property name="margin-top">18</property>
- <property name="margin-bottom">18</property>
- <property name="margin-start">18</property>
- <property name="margin-end">18</property>
- <property name="orientation">horizontal</property>
- <property name="spacing">18</property>
+ <child type="prefix">
+ <object class="GtkBox" id="lozenge">
+ <property name="halign">center</property>
+ <property name="valign">center</property>
+ <property name="hexpand">False</property>
+ <style>
+ <class name="context-tile-lozenge"/>
+ <class name="grey"/>
+ </style>
<child>
- <object class="GtkBox" id="lozenge">
+ <object class="GtkImage" id="lozenge_content_image">
<property name="halign">center</property>
- <property name="valign">start</property>
- <property name="hexpand">False</property>
- <style>
- <class name="context-tile-lozenge"/>
- <class name="grey"/>
- </style>
- <child>
- <object class="GtkImage" id="lozenge_content_image">
- <property name="halign">center</property>
- <property name="hexpand">True</property>
- <!-- this is a placeholder: the icon is actually set in code -->
- <property name="icon-name">safety-symbolic</property>
- <property name="pixel-size">16</property>
- <accessibility>
- <relation name="labelled-by">title</relation>
- <relation name="details">description</relation>
- </accessibility>
- </object>
- </child>
- <child>
- <object class="GtkLabel" id="lozenge_content_text">
- <property name="halign">center</property>
- <property name="hexpand">True</property>
- <!-- this is a placeholder: the text is actually set in code -->
- <property name="label">20 MB</property>
- <property name="visible">False</property>
- <property name="xalign">0.5</property>
- <accessibility>
- <relation name="labelled-by">title</relation>
- <relation name="details">description</relation>
- </accessibility>
- </object>
- </child>
+ <property name="hexpand">True</property>
+ <!-- this is a placeholder: the icon is actually set in code -->
+ <property name="icon-name">safety-symbolic</property>
+ <property name="pixel-size">16</property>
</object>
</child>
<child>
- <object class="GtkBox">
- <property name="orientation">vertical</property>
- <property name="spacing">8</property>
- <child>
- <object class="GtkLabel" id="title">
- <!-- this is a placeholder: the text is actually set in code -->
- <property name="label">Download Size</property>
- <property name="xalign">0</property>
- <style>
- <class name="heading"/>
- </style>
- </object>
- </child>
- <child>
- <object class="GtkLabel" id="description">
- <!-- this is a placeholder: the text is actually set in code -->
- <property name="label">Needs 150 MB of additional system downloads</property>
- <property name="natural-wrap-mode">none</property>
- <property name="wrap">True</property>
- <property name="xalign">0</property>
- <style>
- <class name="context-tile-description"/>
- </style>
- </object>
- </child>
+ <object class="GtkLabel" id="lozenge_content_text">
+ <property name="halign">center</property>
+ <property name="hexpand">True</property>
+ <!-- this is a placeholder: the text is actually set in code -->
+ <property name="label">20 MB</property>
+ <property name="visible">False</property>
+ <property name="xalign">0.5</property>
</object>
</child>
</object>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]