[gnome-commander: 1/2] Replace deprecated widget GtkCombo with GtkComboBoxText




commit 0b5b637a5da21efefc27da362cb23705f8d387a4
Author: Roman Pauer <roman pauer gmail com>
Date:   Wed Aug 3 17:30:27 2022 +0200

    Replace deprecated widget GtkCombo with GtkComboBoxText

 libgcmd/libgcmd-widget-factory.cc          | 12 +-----------
 libgcmd/libgcmd-widget-factory.h           | 10 ++++------
 plugins/fileroller/file-roller-plugin.cc   |  2 +-
 src/dialogs/gnome-cmd-chmod-dialog.cc      | 13 +++++--------
 src/dialogs/gnome-cmd-patternsel-dialog.cc | 15 ++++++++-------
 src/gnome-cmd-chown-component.cc           | 27 ++++++++++++++-------------
 6 files changed, 33 insertions(+), 46 deletions(-)
---
diff --git a/libgcmd/libgcmd-widget-factory.cc b/libgcmd/libgcmd-widget-factory.cc
index 82bc037d..cb4ff00a 100644
--- a/libgcmd/libgcmd-widget-factory.cc
+++ b/libgcmd/libgcmd-widget-factory.cc
@@ -534,17 +534,7 @@ GtkWidget *create_hbuttonbox (GtkWidget *parent)
     return w;
 }
 
-//deprecated since GTK2.4
-GtkWidget *create_combo (GtkWidget *parent)
-{
-    GtkWidget *combo = gtk_combo_new ();
-    g_object_ref (combo);
-    g_object_set_data_full (G_OBJECT (parent), "combo", combo, g_object_unref);
-    gtk_widget_show (combo);
-    return combo;
-}
-
-GtkWidget *create_combo_new (GtkWidget *parent)
+GtkWidget *create_combo_box_text_with_entry (GtkWidget *parent)
 {
     GtkWidget *combo = gtk_combo_box_text_new_with_entry ();
     g_object_ref (combo);
diff --git a/libgcmd/libgcmd-widget-factory.h b/libgcmd/libgcmd-widget-factory.h
index 9efc3082..81459a9e 100644
--- a/libgcmd/libgcmd-widget-factory.h
+++ b/libgcmd/libgcmd-widget-factory.h
@@ -1,4 +1,4 @@
-/** 
+/**
  * @file libgcmd-widget-factory.h
  * @copyright (C) 2001-2006 Marcus Bjurman\n
  * @copyright (C) 2007-2012 Piotr Eljasiak\n
@@ -121,15 +121,13 @@ GtkWidget *create_vbuttonbox (GtkWidget *parent);
 
 GtkWidget *create_hbuttonbox (GtkWidget *parent);
 
-GtkWidget *create_combo (GtkWidget *parent);
-
-GtkWidget *create_combo_new (GtkWidget *parent);
+GtkWidget *create_combo_box_text_with_entry (GtkWidget *parent);
 
 GtkWidget *create_option_menu (GtkWidget *parent, const gchar **items);
 
-inline const gchar *get_combo_text (GtkWidget *combo)
+inline const gchar *get_combo_box_entry_text (GtkWidget *combo)
 {
-    return gtk_entry_get_text (GTK_ENTRY (GTK_COMBO (combo)->entry));
+    return gtk_entry_get_text (GTK_ENTRY (gtk_bin_get_child (GTK_BIN (combo))));
 }
 
 inline GSList *get_radio_group (GtkWidget *radio)
diff --git a/plugins/fileroller/file-roller-plugin.cc b/plugins/fileroller/file-roller-plugin.cc
index ff2f14af..00375acc 100644
--- a/plugins/fileroller/file-roller-plugin.cc
+++ b/plugins/fileroller/file-roller-plugin.cc
@@ -620,7 +620,7 @@ static void configure (GnomeCmdPlugin *plugin)
     label = create_label (dialog, _("Default archive type"));
     table_add (table, label, 0, 1, (GtkAttachOptions) 0);
 
-    combo = create_combo_new (dialog);
+    combo = create_combo_box_text_with_entry (dialog);
     g_signal_connect (G_OBJECT(combo), "changed", G_CALLBACK (on_date_format_update), dialog);
     table_add (table, combo, 1, 1, GTK_FILL);
 
diff --git a/src/dialogs/gnome-cmd-chmod-dialog.cc b/src/dialogs/gnome-cmd-chmod-dialog.cc
index de331c17..d020a863 100644
--- a/src/dialogs/gnome-cmd-chmod-dialog.cc
+++ b/src/dialogs/gnome-cmd-chmod-dialog.cc
@@ -113,7 +113,7 @@ inline void do_chmod_files (GnomeCmdChmodDialog *dialog)
     {
         GnomeCmdFile *f = (GnomeCmdFile *) i->data;
         gboolean recursive = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->priv->recurse_check));
-        const gchar *mode_text = get_combo_text (dialog->priv->recurse_combo);
+        const gchar *mode_text = get_combo_box_entry_text (dialog->priv->recurse_combo);
         //ToDo: This needs a fix. It does not work with Gcmd working in non-english language.
         ChmodRecursiveMode mode = strcmp (mode_text, recurse_opts[CHMOD_ALL_FILES]) == 0 ? CHMOD_ALL_FILES :
                                                                                            CHMOD_DIRS_ONLY;
@@ -205,7 +205,7 @@ static void gnome_cmd_chmod_dialog_init (GnomeCmdChmodDialog *dialog)
     dialog->priv->recurse_check = create_check (chmod_dialog, _("Apply Recursively for"), "check");
     gtk_box_pack_start (GTK_BOX (vbox), dialog->priv->recurse_check, TRUE, TRUE, 0);
 
-    dialog->priv->recurse_combo = create_combo (chmod_dialog);
+    dialog->priv->recurse_combo = create_combo_box_text_with_entry (chmod_dialog);
     gtk_box_pack_start (GTK_BOX (vbox), dialog->priv->recurse_combo, TRUE, TRUE, 0);
     gtk_widget_set_sensitive (dialog->priv->recurse_combo, FALSE);
 
@@ -238,12 +238,9 @@ GtkWidget *gnome_cmd_chmod_dialog_new (GList *files)
 
     show_perms (dialog);
 
-    GList *strings = NULL;
-
-    strings = g_list_append (strings, _(recurse_opts[CHMOD_ALL_FILES]));
-    strings = g_list_append (strings, _(recurse_opts[CHMOD_DIRS_ONLY]));
-
-    gtk_combo_set_popdown_strings (GTK_COMBO (dialog->priv->recurse_combo), strings);
+    gtk_combo_box_text_append_text ((GtkComboBoxText*) dialog->priv->recurse_combo, 
_(recurse_opts[CHMOD_ALL_FILES]));
+    gtk_combo_box_text_append_text ((GtkComboBoxText*) dialog->priv->recurse_combo, 
_(recurse_opts[CHMOD_DIRS_ONLY]));
+    gtk_combo_box_set_active ((GtkComboBox*) dialog->priv->recurse_combo, 0);
 
     return GTK_WIDGET (dialog);
 }
diff --git a/src/dialogs/gnome-cmd-patternsel-dialog.cc b/src/dialogs/gnome-cmd-patternsel-dialog.cc
index 71aa5030..959eeb7f 100644
--- a/src/dialogs/gnome-cmd-patternsel-dialog.cc
+++ b/src/dialogs/gnome-cmd-patternsel-dialog.cc
@@ -1,4 +1,4 @@
-/** 
+/**
  * @file gnome-cmd-patternsel-dialog.cc
  * @copyright (C) 2001-2006 Marcus Bjurman\n
  * @copyright (C) 2007-2012 Piotr Eljasiak\n
@@ -55,7 +55,7 @@ static void on_ok (GtkButton *button, GnomeCmdPatternselDialog *dialog)
     const gchar *s = gtk_entry_get_text (GTK_ENTRY (dialog->priv->pattern_entry));
 
     Filter pattern(s, case_sens, gnome_cmd_data.search_defaults.default_profile.syntax);
-    
+
     if (dialog->priv->mode)
         dialog->priv->fl->select(pattern);
     else
@@ -100,11 +100,12 @@ static void gnome_cmd_patternsel_dialog_init (GnomeCmdPatternselDialog *dialog)
     vbox = create_vbox (GTK_WIDGET (dialog), FALSE, 6);
     hbox = create_hbox (GTK_WIDGET (dialog), FALSE, 6);
 
-    dialog->priv->pattern_combo = create_combo (GTK_WIDGET (dialog));
-    gtk_combo_disable_activate (GTK_COMBO (dialog->priv->pattern_combo));
-    if (!defaults.name_patterns.empty())
-        gtk_combo_set_popdown_strings (GTK_COMBO (dialog->priv->pattern_combo), defaults.name_patterns.ents);
-    dialog->priv->pattern_entry = GTK_COMBO (dialog->priv->pattern_combo)->entry;
+    dialog->priv->pattern_combo = create_combo_box_text_with_entry (GTK_WIDGET (dialog));
+    for (auto list = defaults.name_patterns.ents; list; list = list->next)
+        gtk_combo_box_text_append_text ((GtkComboBoxText*) dialog->priv->pattern_combo, (const gchar*) 
list->data);
+    if (defaults.name_patterns.ents)
+        gtk_combo_box_set_active ((GtkComboBox*) dialog->priv->pattern_combo, 0);
+    dialog->priv->pattern_entry = gtk_bin_get_child (GTK_BIN (dialog->priv->pattern_combo));
     g_signal_connect_swapped (dialog->priv->pattern_entry, "activate", G_CALLBACK 
(gtk_window_activate_default), dialog);
     gtk_editable_select_region (GTK_EDITABLE (dialog->priv->pattern_entry), 0, -1);
 
diff --git a/src/gnome-cmd-chown-component.cc b/src/gnome-cmd-chown-component.cc
index a5ed0e1c..021fa78b 100644
--- a/src/gnome-cmd-chown-component.cc
+++ b/src/gnome-cmd-chown-component.cc
@@ -1,4 +1,4 @@
-/** 
+/**
  * @file gnome-cmd-chown-component.cc
  * @copyright (C) 2001-2006 Marcus Bjurman\n
  * @copyright (C) 2007-2012 Piotr Eljasiak\n
@@ -89,10 +89,10 @@ static void init (GnomeCmdChownComponent *comp)
     label = create_label (GTK_WIDGET (comp), _("Group:"));
     table_add (GTK_WIDGET (comp), label, 0, 1, GTK_FILL);
 
-    comp->priv->user_combo = create_combo (GTK_WIDGET (comp));
+    comp->priv->user_combo = create_combo_box_text_with_entry (GTK_WIDGET (comp));
     table_add (GTK_WIDGET (comp), comp->priv->user_combo, 1, 0, (GtkAttachOptions) (GTK_FILL|GTK_EXPAND));
 
-    comp->priv->group_combo = create_combo (GTK_WIDGET (comp));
+    comp->priv->group_combo = create_combo_box_text_with_entry (GTK_WIDGET (comp));
     table_add (GTK_WIDGET (comp), comp->priv->group_combo, 1, 1, (GtkAttachOptions) (GTK_FILL|GTK_EXPAND));
 }
 
@@ -105,15 +105,16 @@ inline void load_users_and_groups (GnomeCmdChownComponent *comp)
 {
     // disable user combo if user is not root, else fill the combo with all users in the system
     if (gcmd_owner.is_root())
-        gtk_combo_set_popdown_strings (GTK_COMBO (comp->priv->user_combo), gcmd_owner.users.get_names());
+        for (auto list = gcmd_owner.users.get_names(); list; list = list->next)
+            gtk_combo_box_text_append_text ((GtkComboBoxText*) comp->priv->user_combo, (const gchar*) 
list->data);
     else
         gtk_widget_set_sensitive (comp->priv->user_combo, FALSE);
 
     if (gcmd_owner.get_group_names())
-        gtk_combo_set_popdown_strings (GTK_COMBO (comp->priv->group_combo), gcmd_owner.get_group_names());   
   // fill the groups combo with all groups that the user is part of
-                                                                                                             
   // if ordinary user or all groups if root
+        for (auto list = gcmd_owner.get_group_names(); list; list = list->next)                              
       // fill the groups combo with all groups that the user is part of
+            gtk_combo_box_text_append_text ((GtkComboBoxText*) comp->priv->group_combo, (const gchar*) 
list->data); // if ordinary user or all groups if root
     else
-        gtk_widget_set_sensitive (comp->priv->group_combo, FALSE);                                           
   // disable group combo if yet not loaded
+        gtk_widget_set_sensitive (comp->priv->group_combo, FALSE);                                           
       // disable group combo if yet not loaded
 }
 
 
@@ -158,23 +159,23 @@ void gnome_cmd_chown_component_set (GnomeCmdChownComponent *comp, uid_t uid, gid
 
     if (uid_name)
     {
-        gtk_entry_set_text (GTK_ENTRY (GTK_COMBO (comp->priv->user_combo)->entry), uid_name);
+        gtk_entry_set_text (GTK_ENTRY (gtk_bin_get_child (GTK_BIN (comp->priv->user_combo))), uid_name);
     }
     else
     {
         auto uidString = g_strdup_printf("%u", uid);
-        gtk_entry_set_text (GTK_ENTRY (GTK_COMBO (comp->priv->user_combo)->entry), uidString);
+        gtk_entry_set_text (GTK_ENTRY (gtk_bin_get_child (GTK_BIN (comp->priv->user_combo))), uidString);
         g_free(uidString);
     }
 
     if (gid_name)
     {
-        gtk_entry_set_text (GTK_ENTRY (GTK_COMBO (comp->priv->group_combo)->entry), gid_name);
+        gtk_entry_set_text (GTK_ENTRY (gtk_bin_get_child (GTK_BIN (comp->priv->group_combo))), gid_name);
     }
     else
     {
         auto gidString = g_strdup_printf("%u", gid);
-        gtk_entry_set_text (GTK_ENTRY (GTK_COMBO (comp->priv->group_combo)->entry), gidString);
+        gtk_entry_set_text (GTK_ENTRY (gtk_bin_get_child (GTK_BIN (comp->priv->group_combo))), gidString);
         g_free(gidString);
     }
 }
@@ -182,7 +183,7 @@ void gnome_cmd_chown_component_set (GnomeCmdChownComponent *comp, uid_t uid, gid
 
 uid_t gnome_cmd_chown_component_get_owner (GnomeCmdChownComponent *component)
 {
-    const gchar *owner = get_combo_text (component->priv->user_combo);
+    const gchar *owner = get_combo_box_entry_text (component->priv->user_combo);
 
     return gcmd_owner.users[owner];
 }
@@ -190,7 +191,7 @@ uid_t gnome_cmd_chown_component_get_owner (GnomeCmdChownComponent *component)
 
 gid_t gnome_cmd_chown_component_get_group (GnomeCmdChownComponent *component)
 {
-    const gchar *group = get_combo_text (component->priv->group_combo);
+    const gchar *group = get_combo_box_entry_text (component->priv->group_combo);
 
     return gcmd_owner.groups[group];
 }


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