[gtranslator/gtk4: 58/79] Use BoxedList in DL view




commit 5abbe56ef05902414086460b1a4544d0a5635f3b
Author: Daniel GarcĂ­a Moreno <dani danigm net>
Date:   Wed Aug 3 20:02:54 2022 +0200

    Use BoxedList in DL view
    
    This patch updates the download from damned lies view using the more
    modern preferences interface with BoxedList and AdwPreferencesGroup.

 src/gtr-dl-teams-old.ui | 279 ------------------------------------------------
 src/gtr-dl-teams.c      |  44 +++-----
 src/gtr-dl-teams.ui     | 136 +++++++++++++++++------
 3 files changed, 115 insertions(+), 344 deletions(-)
---
diff --git a/src/gtr-dl-teams.c b/src/gtr-dl-teams.c
index cf9d0219..bce0479f 100644
--- a/src/gtr-dl-teams.c
+++ b/src/gtr-dl-teams.c
@@ -37,14 +37,12 @@ typedef struct
 {
   GtkWidget *titlebar;
   GtkWidget *main_box;
-  GtkWidget *select_box;
   GtkWidget *open_button;
   GtkWidget *load_button;
   GtkWidget *reserve_button;
   GtkWidget *stats_label;
   GtkWidget *module_state_label;
   GtkWidget *file_label;
-  GtkWidget *instructions;
 
   GtkWidget *teams_combobox;
   GListStore *teams_model;
@@ -202,7 +200,6 @@ gtr_dl_teams_load_module_details_json (GtkWidget  *widget,
 
   gtk_widget_hide (priv->file_label);
   gtk_widget_hide (priv->module_state_label);
-  gtk_widget_show (priv->instructions);
   gtk_label_set_text (GTK_LABEL (priv->stats_label), "");
 
   /* Disable (down)load button */
@@ -370,14 +367,9 @@ void gtr_dl_teams_verify_and_load (GtrDlTeams *self)
       priv->selected_branch != NULL &&
       priv->selected_domain != NULL)
     {
-      gtk_widget_hide (priv->instructions);
       // get stats and path from DL API and enable (down)load button
       gtr_dl_teams_get_file_info (self);
     }
-  else
-    {
-      gtk_widget_show (priv->instructions);
-    }
 }
 
 static void
@@ -481,7 +473,7 @@ gtr_dl_teams_get_file_info (GtrDlTeams *self)
                                     json_object_get_int_member (stats_object, "untrans"));
 
   gtk_label_set_markup (GTK_LABEL (priv->stats_label), markup);
-  gtk_label_set_text (GTK_LABEL (priv->file_label), g_strconcat("File: ", strrchr (priv->file_path, '/') + 
1, NULL));
+  gtk_label_set_text (GTK_LABEL (priv->file_label), strrchr (priv->file_path, '/') + 1);
   gtk_widget_show (priv->file_label);
   module_state = g_strdup_printf (_("The current state is: %s"), priv->module_state);
   gtk_label_set_text (GTK_LABEL (priv->module_state_label), module_state);
@@ -863,15 +855,18 @@ gtr_dl_teams_class_init (GtrDlTeamsClass *klass)
 
   gtk_widget_class_bind_template_child_private (widget_class, GtrDlTeams, titlebar);
   gtk_widget_class_bind_template_child_private (widget_class, GtrDlTeams, main_box);
-  gtk_widget_class_bind_template_child_private (widget_class, GtrDlTeams, select_box);
   gtk_widget_class_bind_template_child_private (widget_class, GtrDlTeams, file_label);
   gtk_widget_class_bind_template_child_private (widget_class, GtrDlTeams, stats_label);
   gtk_widget_class_bind_template_child_private (widget_class, GtrDlTeams, module_state_label);
   gtk_widget_class_bind_template_child_private (widget_class, GtrDlTeams, load_button);
   gtk_widget_class_bind_template_child_private (widget_class, GtrDlTeams, reserve_button);
-  gtk_widget_class_bind_template_child_private (widget_class, GtrDlTeams, instructions);
 
   gtk_widget_class_bind_template_child_private (widget_class, GtrDlTeams, open_button);
+
+  gtk_widget_class_bind_template_child_private (widget_class, GtrDlTeams, teams_combobox);
+  gtk_widget_class_bind_template_child_private (widget_class, GtrDlTeams, modules_combobox);
+  gtk_widget_class_bind_template_child_private (widget_class, GtrDlTeams, domains_combobox);
+  gtk_widget_class_bind_template_child_private (widget_class, GtrDlTeams, branches_combobox);
 }
 
 static void
@@ -895,24 +890,22 @@ gtr_dl_teams_init (GtrDlTeams *self)
   /* Add combo boxes for DL teams and modules */
   expression = gtk_property_expression_new (GTR_TYPE_DROP_DOWN_OPTION, NULL, "description");
   priv->teams_model = g_list_store_new (GTR_TYPE_DROP_DOWN_OPTION);
-  priv->teams_combobox = GTK_WIDGET (
-    gtk_drop_down_new (G_LIST_MODEL (priv->teams_model), expression)
+  gtk_drop_down_set_model (
+    GTK_DROP_DOWN (priv->teams_combobox),
+    G_LIST_MODEL (priv->teams_model)
   );
-  gtk_widget_set_name (priv->teams_combobox, "combo_teams");
+  gtk_drop_down_set_expression (GTK_DROP_DOWN (priv->teams_combobox), expression);
   gtk_drop_down_set_enable_search (GTK_DROP_DOWN (priv->teams_combobox), TRUE);
-
-  gtk_box_append (GTK_BOX (priv->select_box), priv->teams_combobox);
   gtk_widget_set_sensitive (priv->teams_combobox, FALSE);
 
   expression = gtk_property_expression_new (GTR_TYPE_DROP_DOWN_OPTION, NULL, "name");
   priv->modules_model = g_list_store_new (GTR_TYPE_DROP_DOWN_OPTION);
-  priv->modules_combobox = GTK_WIDGET (
-    gtk_drop_down_new (G_LIST_MODEL (priv->modules_model), expression)
+  gtk_drop_down_set_model (
+    GTK_DROP_DOWN (priv->modules_combobox),
+    G_LIST_MODEL (priv->modules_model)
   );
-  gtk_widget_set_name (priv->modules_combobox, "combo_modules");
+  gtk_drop_down_set_expression (GTK_DROP_DOWN (priv->modules_combobox), expression);
   gtk_drop_down_set_enable_search (GTK_DROP_DOWN (priv->modules_combobox), TRUE);
-
-  gtk_box_append (GTK_BOX (priv->select_box), priv->modules_combobox);
   gtk_widget_set_sensitive (priv->modules_combobox, FALSE);
 
   g_signal_connect (priv->open_button,
@@ -920,15 +913,6 @@ gtr_dl_teams_init (GtrDlTeams *self)
                     G_CALLBACK (team_add_cb),
                     self);
 
-  /* Add empty combo boxes for DL domains and branches and hide them */
-  priv->domains_combobox = gtk_combo_box_text_new ();
-  gtk_widget_set_name (priv->domains_combobox, "combo_domains");
-  gtk_box_append (GTK_BOX (priv->select_box), priv->domains_combobox);
-
-  priv->branches_combobox = gtk_combo_box_text_new ();
-  gtk_widget_set_name (priv->branches_combobox, "combo_branches");
-  gtk_box_append (GTK_BOX (priv->select_box), priv->branches_combobox);
-
   /* Load teams and modules automatically */
   gtr_dl_teams_load_json (self);
 
diff --git a/src/gtr-dl-teams.ui b/src/gtr-dl-teams.ui
index 4ecd5a7b..9ae3005a 100644
--- a/src/gtr-dl-teams.ui
+++ b/src/gtr-dl-teams.ui
@@ -31,7 +31,7 @@
   <template class="GtrDlTeams" parent="AdwBin">
     <child>
       <object class="AdwClamp">
-        <property name="maximum-size">600</property>
+        <property name="maximum-size">900</property>
         <property name="tightening-threshold">400</property>
         <child>
           <object class="GtkBox" id="main_box">
@@ -49,44 +49,115 @@
                 <property name="icon_name">view-restore-symbolic</property>
               </object>
             </child>
+
             <child>
-              <object class="GtkBox" id="select_box">
-                <property name="margin_top">24</property>
-                <property name="margin_bottom">24</property>
-                <property name="vexpand">0</property>
-                <property name="valign">center</property>
-                <property name="orientation">vertical</property>
-                <property name="spacing">14</property>
-              </object>
-            </child>
-            <child>
-              <object class="GtkLabel" id="file_label">
-                <property name="visible">0</property>
-              </object>
-            </child>
-            <child>
-              <object class="GtkLabel" id="module_state_label">
-                <property name="visible">0</property>
-              </object>
-            </child>
-            <child>
-              <object class="GtkLabel" id="instructions">
-                <property name="label" translatable="1">Select team, module, branch and domain to get the 
translation file.</property>
-              </object>
-            </child>
-            <child>
-              <object class="GtkLabel" id="stats_label">
-                <property name="visible">0</property>
+              <object class="GtkListBox">
+                <property name="selection-mode">none</property>
+                <style>
+                  <class name="boxed-list"/>
+                </style>
+                <child>
+                  <object class="AdwActionRow">
+                    <property name="title" translatable="true">Team</property>
+                    <child>
+                      <object class="GtkDropDown" id="teams_combobox">
+                        <property name="name">combo_teams</property>
+                        <property name="valign">center</property>
+                      </object>
+                    </child>
+                  </object>
+                </child>
+                <child>
+                  <object class="AdwActionRow">
+                    <property name="title" translatable="true">Module</property>
+                    <child>
+                      <object class="GtkDropDown" id="modules_combobox">
+                        <property name="name">combo_modules</property>
+                        <property name="valign">center</property>
+                      </object>
+                    </child>
+                  </object>
+                </child>
+                <child>
+                  <object class="AdwActionRow">
+                    <property name="title" translatable="true">Domain</property>
+                    <child>
+                      <object class="GtkComboBoxText" id="domains_combobox">
+                        <property name="name">combo_domains</property>
+                        <property name="valign">center</property>
+                      </object>
+                    </child>
+                  </object>
+                </child>
+                <child>
+                  <object class="AdwActionRow">
+                    <property name="title" translatable="true">Branch</property>
+                    <child>
+                      <object class="GtkComboBoxText" id="branches_combobox">
+                        <property name="name">combo_branches</property>
+                        <property name="valign">center</property>
+                      </object>
+                    </child>
+                  </object>
+                </child>
+                <child>
+                  <object class="AdwActionRow">
+                    <property name="title" translatable="true">Reserve for translation</property>
+                    <child>
+                      <object class="GtkSwitch" id="reserve_button">
+                        <property name="valign">center</property>
+                      </object>
+                    </child>
+                  </object>
+                </child>
               </object>
             </child>
+
             <child>
-              <object class="GtkCheckButton" id="reserve_button">
-                <property name="label" translatable="1">Reserve for translation</property>
+              <object class="AdwPreferencesGroup">
+                <property name="title" translatable="true">Info</property>
+                <child>
+                  <object class="AdwActionRow">
+                    <property name="title" translatable="true">File</property>
+                    <child>
+                      <object class="GtkLabel" id="file_label">
+                        <property name="valign">center</property>
+                      </object>
+                    </child>
+                  </object>
+                </child>
+                <child>
+                  <object class="AdwActionRow">
+                    <property name="title" translatable="true">Translation State</property>
+                    <child>
+                      <object class="GtkLabel" id="module_state_label">
+                        <property name="valign">center</property>
+                      </object>
+                    </child>
+                  </object>
+                </child>
+                <child>
+                  <object class="AdwActionRow">
+                    <property name="title" translatable="true">Stats</property>
+                    <child>
+                      <object class="GtkLabel" id="stats_label">
+                        <property name="valign">center</property>
+                      </object>
+                    </child>
+                  </object>
+                </child>
+
               </object>
             </child>
+
             <child>
               <object class="GtkButton" id="load_button">
                 <property name="label" translatable="1">Load file</property>
+                <property name="halign">end</property>
+                <style>
+                  <class name="pill"/>
+                  <class name="suggested-action"/>
+                </style>
               </object>
             </child>
           </object>
@@ -113,11 +184,6 @@
             <property name="icon_name">open-menu-symbolic</property>
           </object>
         </child>
-        <!--<child internal-child="accessible">
-          <object class="AtkObject" id="main_menu-atkobject">
-            <property name="AtkObject::accessible-name" translatable="1">Main Menu</property>
-          </object>
-        </child>-->
         <accessibility>
           <property name="label" translatable="yes">Main Menu</property>
         </accessibility>


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