From b79607a8c7124b1b20ae960d3f25dc05bda5700c Mon Sep 17 00:00:00 2001 From: Andrey Kutejko Date: Mon, 20 May 2024 11:35:42 +0200 Subject: [PATCH 1/3] Fix chmod bug when non-english locale is used --- src/dialogs/gnome-cmd-chmod-dialog.cc | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/dialogs/gnome-cmd-chmod-dialog.cc b/src/dialogs/gnome-cmd-chmod-dialog.cc index bfa221969..500f3df87 100644 --- a/src/dialogs/gnome-cmd-chmod-dialog.cc +++ b/src/dialogs/gnome-cmd-chmod-dialog.cc @@ -123,10 +123,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_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; + ChmodRecursiveMode mode = (ChmodRecursiveMode) gtk_combo_box_get_active (GTK_COMBO_BOX (dialog->priv->recurse_combo)); do_chmod (f, dialog->priv->permissions, recursive, mode); g_signal_emit (dialog, signals[MODE_CHANGED], 0); @@ -225,7 +222,8 @@ static void gnome_cmd_chmod_dialog_init (GnomeCmdChmodDialog *dialog) dialog->priv->recurse_check = create_check (chmod_dialog, _("Apply Recursively for"), "check"); gtk_box_append (GTK_BOX (vbox), dialog->priv->recurse_check); - dialog->priv->recurse_combo = create_combo_box_text_with_entry (chmod_dialog); + dialog->priv->recurse_combo = gtk_combo_box_text_new (); + gtk_widget_show (dialog->priv->recurse_combo); gtk_box_append (GTK_BOX (vbox), dialog->priv->recurse_combo); gtk_widget_set_sensitive (dialog->priv->recurse_combo, FALSE); -- GitLab From 4f333df8b9dd40d2db8a2c37d976364e553c8ec0 Mon Sep 17 00:00:00 2001 From: Andrey Kutejko Date: Mon, 20 May 2024 13:05:29 +0200 Subject: [PATCH 2/3] Rework chown component to use model-based combo boxes and get rid of free-form text entry --- src/gnome-cmd-chown-component.cc | 102 +++++++++++++++++++++++-------- 1 file changed, 75 insertions(+), 27 deletions(-) diff --git a/src/gnome-cmd-chown-component.cc b/src/gnome-cmd-chown-component.cc index e7e8f3cff..d5358baae 100644 --- a/src/gnome-cmd-chown-component.cc +++ b/src/gnome-cmd-chown-component.cc @@ -64,13 +64,15 @@ static void gnome_cmd_chown_component_init (GnomeCmdChownComponent *comp) label = create_label (GTK_WIDGET (comp), _("Group:")); gtk_grid_attach (GTK_GRID (comp), label, 0, 1, 1, 1); - priv->user_combo = create_combo_box_text_with_entry (GTK_WIDGET (comp)); + priv->user_combo = gtk_combo_box_text_new (); gtk_widget_set_hexpand (priv->user_combo, TRUE); gtk_grid_attach (GTK_GRID (comp), priv->user_combo, 1, 0, 1, 1); - priv->group_combo = create_combo_box_text_with_entry (GTK_WIDGET (comp)); + priv->group_combo = gtk_combo_box_text_new (); gtk_widget_set_hexpand (priv->group_combo, TRUE); gtk_grid_attach (GTK_GRID (comp), priv->group_combo, 1, 1, 1, 1); + + gtk_widget_show_all (GTK_WIDGET (comp)); } @@ -82,16 +84,35 @@ inline void load_users_and_groups (GnomeCmdChownComponent *comp) { auto priv = static_cast(gnome_cmd_chown_component_get_instance_private (comp)); + GtkListStore *users_model = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_LONG); + for (auto list = gcmd_owner.users.get_names(); list; list = list->next) + { + const char *name = (const char *) list->data; + uid_t uid = gcmd_owner.users[name]; + + GtkTreeIter iter; + gtk_list_store_append (users_model, &iter); + gtk_list_store_set (users_model, &iter, 0, name, 1, (glong) uid, -1); + } + gtk_combo_box_set_model (GTK_COMBO_BOX (priv->user_combo), GTK_TREE_MODEL (users_model)); + // disable user combo if user is not root, else fill the combo with all users in the system - if (gcmd_owner.is_root()) - for (auto list = gcmd_owner.users.get_names(); list; list = list->next) - gtk_combo_box_text_append_text ((GtkComboBoxText*) priv->user_combo, (const gchar*) list->data); - else + if (!gcmd_owner.is_root()) gtk_widget_set_sensitive (priv->user_combo, FALSE); + GtkListStore *groups_model = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_LONG); + gtk_combo_box_set_model (GTK_COMBO_BOX (priv->group_combo), GTK_TREE_MODEL (groups_model)); + if (gcmd_owner.get_group_names()) 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*) priv->group_combo, (const gchar*) list->data); // if ordinary user or all groups if root + { // if ordinary user or all groups if root + const char *name = (const char *) list->data; + gid_t gid = gcmd_owner.groups[name]; + + GtkTreeIter iter; + gtk_list_store_append (groups_model, &iter); + gtk_list_store_set (groups_model, &iter, 0, name, 1, (glong) gid, -1); + } else gtk_widget_set_sensitive (priv->group_combo, FALSE); // disable group combo if yet not loaded } @@ -107,34 +128,49 @@ GtkWidget *gnome_cmd_chown_component_new () } +static bool find_iter (GtkTreeModel *model, glong id, GtkTreeIter *iter) +{ + if (gtk_tree_model_get_iter_first (model, iter)) + { + do + { + glong item_id; + gtk_tree_model_get (model, iter, 1, &item_id, -1); + + if (item_id == id) + return true; + } + while (gtk_tree_model_iter_next (model, iter)); + } + return false; +} + + void gnome_cmd_chown_component_set (GnomeCmdChownComponent *comp, uid_t uid, gid_t gid) { auto priv = static_cast(gnome_cmd_chown_component_get_instance_private (comp)); - const gchar *uid_name = gcmd_owner.users[uid]; - const gchar *gid_name = gcmd_owner.groups[gid]; + GtkTreeIter iter; - if (uid_name) - { - gtk_entry_set_text (GTK_ENTRY (gtk_bin_get_child (GTK_BIN (priv->user_combo))), uid_name); - } - else + auto user_combo_model = gtk_combo_box_get_model (GTK_COMBO_BOX (priv->user_combo)); + if (!find_iter (user_combo_model, uid, &iter)) { - auto uidString = g_strdup_printf("%u", uid); - gtk_entry_set_text (GTK_ENTRY (gtk_bin_get_child (GTK_BIN (priv->user_combo))), uidString); + gtk_list_store_append (GTK_LIST_STORE (user_combo_model), &iter); + gchar *uidString = g_strdup_printf("%u", uid); + gtk_list_store_set (GTK_LIST_STORE (user_combo_model), &iter, 0, uidString, 1, (glong) uid, -1); g_free(uidString); } + gtk_combo_box_set_active_iter (GTK_COMBO_BOX (priv->user_combo), &iter); - if (gid_name) + auto group_combo_model = gtk_combo_box_get_model (GTK_COMBO_BOX (priv->group_combo)); + if (!find_iter (group_combo_model, gid, &iter)) { - gtk_entry_set_text (GTK_ENTRY (gtk_bin_get_child (GTK_BIN (priv->group_combo))), gid_name); - } - else - { - auto gidString = g_strdup_printf("%u", gid); - gtk_entry_set_text (GTK_ENTRY (gtk_bin_get_child (GTK_BIN (priv->group_combo))), gidString); + gtk_list_store_append (GTK_LIST_STORE (group_combo_model), &iter); + gchar *gidString = g_strdup_printf("%u", gid); + gtk_list_store_set (GTK_LIST_STORE (group_combo_model), &iter, 0, gidString, 1, (glong) gid, -1); g_free(gidString); } + gtk_combo_box_set_active_iter (GTK_COMBO_BOX (priv->group_combo), &iter); } @@ -142,9 +178,15 @@ uid_t gnome_cmd_chown_component_get_owner (GnomeCmdChownComponent *component) { auto priv = static_cast(gnome_cmd_chown_component_get_instance_private (component)); - const gchar *owner = get_combo_box_entry_text (priv->user_combo); + GtkTreeIter iter; + if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (priv->user_combo), &iter)) + return -1; - return gcmd_owner.users[owner]; + auto model = gtk_combo_box_get_model (GTK_COMBO_BOX (priv->user_combo)); + glong uid; + gtk_tree_model_get (model, &iter, 1, &uid, -1); + + return uid; } @@ -152,7 +194,13 @@ gid_t gnome_cmd_chown_component_get_group (GnomeCmdChownComponent *component) { auto priv = static_cast(gnome_cmd_chown_component_get_instance_private (component)); - const gchar *group = get_combo_box_entry_text (priv->group_combo); + GtkTreeIter iter; + if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (priv->group_combo), &iter)) + return -1; + + auto model = gtk_combo_box_get_model (GTK_COMBO_BOX (priv->group_combo)); + glong gid; + gtk_tree_model_get (model, &iter, 1, &gid, -1); - return gcmd_owner.groups[group]; + return gid; } -- GitLab From 12b7133d3c84bc9d56915b6268d45e44d4b7992d Mon Sep 17 00:00:00 2001 From: Andrey Kutejko Date: Mon, 20 May 2024 14:02:21 +0200 Subject: [PATCH 3/3] Forbid free-form editing of an archive extension --- libgcmd/libgcmd-widget-factory.cc | 5 +++-- plugins/fileroller/file-roller-plugin.cc | 12 +++++++----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/libgcmd/libgcmd-widget-factory.cc b/libgcmd/libgcmd-widget-factory.cc index 328e03feb..3aead0611 100644 --- a/libgcmd/libgcmd-widget-factory.cc +++ b/libgcmd/libgcmd-widget-factory.cc @@ -541,8 +541,9 @@ GtkWidget *create_combo_box_text (GtkWidget *parent, const gchar **items) g_object_set_data_full (G_OBJECT (parent), "combo", combo, g_object_unref); gtk_widget_show (combo); - for (gint i = 0; items[i]; i++) - gtk_combo_box_text_append_text ((GtkComboBoxText*) combo, items[i]); + if (items) + for (gint i = 0; items[i]; i++) + gtk_combo_box_text_append_text ((GtkComboBoxText*) combo, items[i]); return combo; } diff --git a/plugins/fileroller/file-roller-plugin.cc b/plugins/fileroller/file-roller-plugin.cc index ae3762d3f..8a15a7550 100644 --- a/plugins/fileroller/file-roller-plugin.cc +++ b/plugins/fileroller/file-roller-plugin.cc @@ -550,7 +550,7 @@ static void on_configure_close (GtkButton *btn, FileRollerPlugin *plugin) { FileRollerPluginPrivate *priv = (FileRollerPluginPrivate *) file_roller_plugin_get_instance_private (plugin); - priv->default_ext = g_strdup (gtk_entry_get_text (GTK_ENTRY (gtk_bin_get_child (GTK_BIN (priv->conf_combo))))); + priv->default_ext = gtk_combo_box_text_get_active_text (GTK_COMBO_BOX_TEXT (priv->conf_combo)); priv->file_prefix_pattern = g_strdup (get_entry_text (priv->conf_entry, "file_prefix_pattern_entry")); g_settings_set_string (priv->settings->file_roller_plugin, GCMD_PLUGINS_FILE_ROLLER_DEFAULT_TYPE, priv->default_ext); @@ -564,8 +564,8 @@ static void on_date_format_update (GtkEditable *editable, GtkWidget *options_dia { GtkWidget *format_entry = lookup_widget (options_dialog, "file_prefix_pattern_entry"); GtkWidget *test_label = lookup_widget (options_dialog, "date_format_test_label"); - GtkWidget *combo_entry = lookup_widget (options_dialog, "combo"); - const gchar *file_suffix = gtk_entry_get_text (GTK_ENTRY (gtk_bin_get_child (GTK_BIN (combo_entry)))); + GtkWidget *combo = lookup_widget (options_dialog, "combo"); + gchar *file_suffix = gtk_combo_box_text_get_active_text (GTK_COMBO_BOX_TEXT (combo)); const char *format = gtk_entry_get_text (GTK_ENTRY (format_entry)); gchar *locale_format = g_locale_from_utf8 (format, -1, nullptr, nullptr, nullptr); @@ -587,6 +587,7 @@ static void on_date_format_update (GtkEditable *editable, GtkWidget *options_dia gchar *filename = new_string_with_replaced_keyword(filename_tmp, "$N", replacement); gtk_label_set_text (GTK_LABEL (test_label), filename); g_free (file_prefix); + g_free (file_suffix); g_free (replacement); g_free (filename); g_free (filename_tmp); @@ -619,7 +620,7 @@ static void configure (GnomeCmdPlugin *plugin) label = create_label (dialog, _("Default archive type")); gtk_grid_attach (GTK_GRID (grid), label, 0, 0, 1, 1); - combo = create_combo_box_text_with_entry (dialog); + combo = create_combo_box_text (dialog, nullptr); g_signal_connect (G_OBJECT(combo), "changed", G_CALLBACK (on_date_format_update), dialog); gtk_widget_set_hexpand (combo, TRUE); gtk_grid_attach (GTK_GRID (grid), combo, 1, 0, 1, 1); @@ -661,11 +662,12 @@ static void configure (GnomeCmdPlugin *plugin) // The text entry stored in default_ext (set in init()) should be the active entry in the combo now. // If strlen of the active comby == 0, prepend the stored value to the list. - const gchar* test = gtk_entry_get_text (GTK_ENTRY (gtk_bin_get_child (GTK_BIN (combo)))); + gchar* test = gtk_combo_box_text_get_active_text (GTK_COMBO_BOX_TEXT (combo)); if (test && strlen(test) == 0) { gtk_combo_box_text_prepend_text ((GtkComboBoxText*) combo, priv->default_ext); gtk_combo_box_set_active((GtkComboBox*) combo, 0); + g_free (test); } priv->conf_dialog = dialog; -- GitLab