[gnome-software: 62/110] gs-removal-dialog: Subclass GtkDialog




commit aa6a0ab988e517350fb6e304cf5a18995f46bd1c
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Wed Aug 25 09:03:38 2021 -0300

    gs-removal-dialog: Subclass GtkDialog
    
    GtkMessageDialog is a final class now. Subclass GtkDialog and mimic
    what GtkMessageDialog does.

 src/gs-removal-dialog.c  | 62 ++++++++++++++++------------------
 src/gs-removal-dialog.h  |  2 +-
 src/gs-removal-dialog.ui | 88 +++++++++++++++++++++++++++++++++++++-----------
 3 files changed, 99 insertions(+), 53 deletions(-)
---
diff --git a/src/gs-removal-dialog.c b/src/gs-removal-dialog.c
index e79c22fd0..e26b70229 100644
--- a/src/gs-removal-dialog.c
+++ b/src/gs-removal-dialog.c
@@ -16,12 +16,13 @@
 
 struct _GsRemovalDialog
 {
-       GtkMessageDialog         parent_instance;
+       GtkDialog                parent_instance;
+       GtkLabel                *label;
        GtkWidget               *listbox;
-       GtkWidget               *scrolledwindow;
+       GtkLabel                *secondary_label;
 };
 
-G_DEFINE_TYPE (GsRemovalDialog, gs_removal_dialog, GTK_TYPE_MESSAGE_DIALOG)
+G_DEFINE_TYPE (GsRemovalDialog, gs_removal_dialog, GTK_TYPE_DIALOG)
 
 static gint
 list_sort_func (GtkListBoxRow *a,
@@ -72,44 +73,26 @@ add_app (GtkListBox *listbox, GsApp *app)
        gtk_list_box_row_set_activatable (GTK_LIST_BOX_ROW (row), FALSE);
 }
 
-static void
-insert_details_widget (GtkMessageDialog *dialog, GtkWidget *widget)
-{
-       GtkWidget *message_area, *child;
-
-       message_area = gtk_message_dialog_get_message_area (dialog);
-       g_assert (GTK_IS_BOX (message_area));
-
-       /* find all label children and set the width chars properties */
-       for (child = gtk_widget_get_first_child (message_area);
-            child != NULL;
-            child = gtk_widget_get_next_sibling (child)) {
-               if (!GTK_IS_LABEL (child))
-                       continue;
-
-               gtk_label_set_width_chars (GTK_LABEL (child), 40);
-               gtk_label_set_max_width_chars (GTK_LABEL (child), 40);
-       }
-
-       gtk_box_append (GTK_BOX (message_area), widget);
-}
-
 void
 gs_removal_dialog_show_upgrade_removals (GsRemovalDialog *self,
                                          GsApp *upgrade)
 {
        GsAppList *removals;
+       g_autofree gchar *secondary_text = NULL;
        g_autofree gchar *name_version = NULL;
 
        name_version = g_strdup_printf ("%s %s",
                                        gs_app_get_name (upgrade),
                                        gs_app_get_version (upgrade));
-       gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (self),
-                                                 /* TRANSLATORS: This is a text displayed during a distro 
upgrade. %s
-                                                    will be replaced by the name and version of distro, e.g. 
'Fedora 23'. */
-                                                 _("Some of the currently installed software is not 
compatible with %s. "
-                                                   "If you continue, the following will be automatically 
removed during the upgrade:"),
-                                                 name_version);
+       /* TRANSLATORS: This is a text displayed during a distro upgrade. %s
+          will be replaced by the name and version of distro, e.g. 'Fedora 23'. */
+       secondary_text = g_strdup_printf (_("Some of the currently installed software is not compatible with 
%s. "
+                                           "If you continue, the following will be automatically removed 
during the upgrade:"),
+                                         name_version);
+
+       gtk_widget_add_css_class (GTK_WIDGET (self->label), "title");
+       gtk_widget_show (GTK_WIDGET (self->secondary_label));
+       gtk_label_set_text (self->secondary_label, secondary_text);
 
        removals = gs_app_get_related (upgrade);
        for (guint i = 0; i < gs_app_list_length (removals); i++) {
@@ -127,9 +110,21 @@ gs_removal_dialog_show_upgrade_removals (GsRemovalDialog *self,
 static void
 gs_removal_dialog_init (GsRemovalDialog *self)
 {
+       GtkWidget *action_area;
+       GtkSettings *settings;
+       gboolean use_caret;
+
        gtk_widget_init_template (GTK_WIDGET (self));
 
-       insert_details_widget (GTK_MESSAGE_DIALOG (self), self->scrolledwindow);
+       action_area = gtk_dialog_get_content_area (GTK_DIALOG (self));
+       action_area = gtk_widget_get_next_sibling (action_area);
+       gtk_widget_set_halign (action_area, GTK_ALIGN_FILL);
+       gtk_box_set_homogeneous (GTK_BOX (action_area), TRUE);
+
+       settings = gtk_widget_get_settings (GTK_WIDGET (self));
+       g_object_get (settings, "gtk-keynav-use-caret", &use_caret, NULL);
+       gtk_label_set_selectable (self->label, use_caret);
+       gtk_label_set_selectable (self->secondary_label, use_caret);
 
        gtk_list_box_set_sort_func (GTK_LIST_BOX (self->listbox),
                                    list_sort_func,
@@ -143,8 +138,9 @@ gs_removal_dialog_class_init (GsRemovalDialogClass *klass)
 
        gtk_widget_class_set_template_from_resource (widget_class, 
"/org/gnome/Software/gs-removal-dialog.ui");
 
+       gtk_widget_class_bind_template_child (widget_class, GsRemovalDialog, label);
        gtk_widget_class_bind_template_child (widget_class, GsRemovalDialog, listbox);
-       gtk_widget_class_bind_template_child (widget_class, GsRemovalDialog, scrolledwindow);
+       gtk_widget_class_bind_template_child (widget_class, GsRemovalDialog, secondary_label);
 }
 
 GtkWidget *
diff --git a/src/gs-removal-dialog.h b/src/gs-removal-dialog.h
index 6006afb6e..b603ace1a 100644
--- a/src/gs-removal-dialog.h
+++ b/src/gs-removal-dialog.h
@@ -16,7 +16,7 @@ G_BEGIN_DECLS
 
 #define GS_TYPE_REMOVAL_DIALOG (gs_removal_dialog_get_type ())
 
-G_DECLARE_FINAL_TYPE (GsRemovalDialog, gs_removal_dialog, GS, REMOVAL_DIALOG, GtkMessageDialog)
+G_DECLARE_FINAL_TYPE (GsRemovalDialog, gs_removal_dialog, GS, REMOVAL_DIALOG, GtkDialog)
 
 GtkWidget      *gs_removal_dialog_new                          (void);
 void            gs_removal_dialog_show_upgrade_removals        (GsRemovalDialog         *self,
diff --git a/src/gs-removal-dialog.ui b/src/gs-removal-dialog.ui
index ce7e2778a..927dcfd01 100644
--- a/src/gs-removal-dialog.ui
+++ b/src/gs-removal-dialog.ui
@@ -1,27 +1,17 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface>
-  <object class="GtkScrolledWindow" id="scrolledwindow">
-    <property name="visible">True</property>
-    <property name="can_focus">True</property>
-    <property name="min_content_height">160</property>
-    <property name="hscrollbar_policy">never</property>
-    <property name="vscrollbar_policy">automatic</property>
-    <child>
-      <object class="GtkListBox" id="listbox">
-        <property name="halign">fill</property>
-        <property name="valign">start</property>
-        <property name="visible">True</property>
-        <property name="selection_mode">none</property>
-        <style>
-          <class name="content" />
-        </style>
-      </object>
-    </child>
-  </object>
-  <template class="GsRemovalDialog" parent="GtkMessageDialog">
+  <template class="GsRemovalDialog" parent="GtkDialog">
     <property name="text" translatable="yes">Incompatible Software</property>
     <property name="modal">True</property>
     <property name="destroy_with_parent">True</property>
+    <child internal-child="headerbar">
+      <object class="GtkHeaderBar">
+        <property name="show-title-buttons">False</property>
+      </object>
+    </child>
+    <style>
+      <class name="message" />
+    </style>
     <child type="action">
       <object class="GtkButton" id="button_cancel">
         <property name="visible">True</property>
@@ -42,5 +32,65 @@
       <action-widget response="accept" default="true">button_continue</action-widget>
       <action-widget response="cancel">button_cancel</action-widget>
     </action-widgets>
+    <child internal-child="content_area">
+      <object class="GtkBox" id="dialog-vbox1">
+        <property name="orientation">vertical</property>
+        <property name="spacing">20</property>
+        <child>
+          <object class="GtkBox" id="box">
+            <property name="margin-start">30</property>
+            <property name="margin-end">30</property>
+            <property name="spacing">30</property>
+            <child>
+              <object class="GtkBox" id="message_area">
+                <property name="orientation">vertical</property>
+                <property name="spacing">10</property>
+                <property name="hexpand">1</property>
+                <child>
+                  <object class="GtkLabel" id="label">
+                    <property name="halign">center</property>
+                    <property name="valign">start</property>
+                    <property name="wrap">1</property>
+                    <property name="width-chars">40</property>
+                    <property name="max-width-chars">40</property>
+                  </object>
+                </child>
+                <child>
+                  <object class="GtkLabel" id="secondary_label">
+                    <property name="visible">False</property>
+                    <property name="margin-bottom">2</property>
+                    <property name="halign">center</property>
+                    <property name="valign">start</property>
+                    <property name="vexpand">1</property>
+                    <property name="wrap">1</property>
+                    <property name="width-chars">40</property>
+                    <property name="max-width-chars">40</property>
+                  </object>
+                </child>
+                <child>
+                  <object class="GtkScrolledWindow">
+                    <property name="can_focus">True</property>
+                    <property name="min_content_height">160</property>
+                    <property name="hscrollbar_policy">never</property>
+                    <property name="vscrollbar_policy">automatic</property>
+                    <child>
+                      <object class="GtkListBox" id="listbox">
+                        <property name="halign">fill</property>
+                        <property name="valign">start</property>
+                        <property name="visible">True</property>
+                        <property name="selection_mode">none</property>
+                        <style>
+                          <class name="content" />
+                        </style>
+                      </object>
+                    </child>
+                  </object>
+                </child>
+              </object>
+            </child>
+          </object>
+        </child>
+      </object>
+    </child>
   </template>
 </interface>


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