[evince/wip/gpoo/gtk4-rebase-port: 15/72] shell: Port EvProgressMessageArea to gtk4 using composite




commit 4e32fb570f6aed7b38594845725e16dee8baa243
Author: Qiu Wenbo <qiuwenbo kylinos com cn>
Date:   Tue Aug 3 00:20:15 2021 +0800

    shell: Port EvProgressMessageArea to gtk4 using composite
    
    Signed-off-by: Qiu Wenbo <qiuwenbo kylinos com cn>

 shell/ev-progress-message-area.c      | 38 +++++++++--------------------------
 shell/evince-progress-message-area.ui | 27 +++++++++++++++++++++++++
 shell/evince.gresource.xml            |  1 +
 3 files changed, 38 insertions(+), 28 deletions(-)
---
diff --git a/shell/ev-progress-message-area.c b/shell/ev-progress-message-area.c
index 16cfa48a0..ef3b8d301 100644
--- a/shell/ev-progress-message-area.c
+++ b/shell/ev-progress-message-area.c
@@ -52,10 +52,15 @@ static void
 ev_progress_message_area_class_init (EvProgressMessageAreaClass *class)
 {
        GObjectClass *gobject_class = G_OBJECT_CLASS (class);
+       GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
 
        gobject_class->set_property = ev_progress_message_area_set_property;
        gobject_class->get_property = ev_progress_message_area_get_property;
 
+       gtk_widget_class_set_template_from_resource (widget_class, 
"/org/gnome/evince/ui/progress-message-area.ui");
+       gtk_widget_class_bind_template_child_private (widget_class, EvProgressMessageArea, label);
+       gtk_widget_class_bind_template_child_private (widget_class, EvProgressMessageArea, progress_bar);
+
        g_object_class_install_property (gobject_class,
                                         PROP_STATUS,
                                         g_param_spec_string ("status",
@@ -77,31 +82,7 @@ ev_progress_message_area_class_init (EvProgressMessageAreaClass *class)
 static void
 ev_progress_message_area_init (EvProgressMessageArea *area)
 {
-       GtkWidget *contents;
-       GtkWidget *vbox;
-       EvProgressMessageAreaPrivate *priv;
-
-       priv = ev_progress_message_area_get_instance_private (area);
-
-       contents = _ev_message_area_get_main_box (EV_MESSAGE_AREA (area));
-       
-       vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
-       
-       priv->label = gtk_label_new (NULL);
-       gtk_label_set_use_markup (GTK_LABEL (priv->label), TRUE);
-       gtk_label_set_ellipsize (GTK_LABEL (priv->label),
-                                PANGO_ELLIPSIZE_END);
-       g_object_set (G_OBJECT (priv->label), "xalign", 0., "yalign", 0.5, NULL);
-       gtk_box_pack_start (GTK_BOX (vbox), priv->label, TRUE, TRUE, 0);
-       gtk_widget_show (priv->label);
-
-       priv->progress_bar = gtk_progress_bar_new ();
-       gtk_widget_set_size_request (priv->progress_bar, -1, 15);
-       gtk_box_pack_start (GTK_BOX (vbox), priv->progress_bar, TRUE, FALSE, 0);
-       gtk_widget_show (priv->progress_bar);
-
-       gtk_box_pack_start (GTK_BOX (contents), vbox, TRUE, TRUE, 0);
-       gtk_widget_show (vbox);
+       gtk_widget_init_template (GTK_WIDGET (area));
 }
 
 static void
@@ -158,11 +139,14 @@ ev_progress_message_area_new (const gchar *icon_name,
                              ...)
 {
        GtkWidget *widget;
+       GtkWidget *info_bar;
 
        widget = g_object_new (EV_TYPE_PROGRESS_MESSAGE_AREA,
-                              "message-type", GTK_MESSAGE_OTHER,
                               "text", text,
                               NULL);
+       info_bar = ev_message_area_get_info_bar (EV_MESSAGE_AREA (widget));
+       gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_OTHER);
+
        if (first_button_text) {
                va_list args;
 
@@ -176,8 +160,6 @@ ev_progress_message_area_new (const gchar *icon_name,
        ev_message_area_set_image_from_icon_name (EV_MESSAGE_AREA (widget),
                                                  icon_name);
 
-       gtk_info_bar_set_show_close_button (GTK_INFO_BAR (widget), TRUE);
-
        return widget;
 }
 
diff --git a/shell/evince-progress-message-area.ui b/shell/evince-progress-message-area.ui
new file mode 100644
index 000000000..ed41b73fb
--- /dev/null
+++ b/shell/evince-progress-message-area.ui
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <requires lib="gtk" version="4.0"/>
+  <requires lib="libadwaita" version="1.0"/>
+  <template class="EvProgressMessageArea" parent="EvMessageArea">
+    <child internal-child="main_box">
+      <object class="GtkBox">
+        <property name="spacing">6</property>
+        <child type="start">
+          <object class="GtkLabel" id="label">
+            <property name="use-markup">True</property>
+            <property name="ellipsize">3</property>
+            <property name="valign">fill</property>
+            <property name="vexpand">True</property>
+          </object>
+        </child>
+        <child type="start">
+          <object class="GtkProgressBar" id="progress_bar">
+            <property name="width-request">-1</property>
+            <property name="height-request">15</property>
+            <property name="vexpand">True</property>
+          </object>
+        </child>
+      </object>
+    </child>
+  </template>
+</interface>
diff --git a/shell/evince.gresource.xml b/shell/evince.gresource.xml
index d8eb58deb..f0ec07af8 100644
--- a/shell/evince.gresource.xml
+++ b/shell/evince.gresource.xml
@@ -23,6 +23,7 @@
     <file alias="gtk/menus.ui" compressed="true" preprocess="xml-stripblanks">evince-menus.ui</file>
     <file alias="ui/message-area.ui" compressed="true" 
preprocess="xml-stripblanks">evince-message-area.ui</file>
     <file alias="ui/password-view.ui" compressed="true" 
preprocess="xml-stripblanks">evince-password-view.ui</file>
+    <file alias="ui/progress-message-area.ui" compressed="true" 
preprocess="xml-stripblanks">evince-progress-message-area.ui</file>
     <file alias="ui/properties-fonts.ui" compressed="true" 
preprocess="xml-stripblanks">evince-properties-fonts.ui</file>
     <file alias="ui/zoom-action.ui" compressed="true" 
preprocess="xml-stripblanks">evince-zoom-action.ui</file>
   </gresource>


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