From 787dde3f7b90664fd55e7fc57d00c5cc2b4a0804 Mon Sep 17 00:00:00 2001 From: Ivan Yarcev Date: Mon, 2 Sep 2024 12:45:40 +0600 Subject: [PATCH 1/2] Added funcion to block entry from inserting anything but figits --- source/libublsettings-gtk3.c | 21 +++++++++++++++++++++ source/libublsettings-gtk3.h | 2 ++ 2 files changed, 23 insertions(+) diff --git a/source/libublsettings-gtk3.c b/source/libublsettings-gtk3.c index 1c42cac..4f0a552 100644 --- a/source/libublsettings-gtk3.c +++ b/source/libublsettings-gtk3.c @@ -1190,6 +1190,27 @@ rmb_menu_window *yon_rmb_menu_setup(GtkWidget *target_widget, int (show_function } } +void yon_on_text_insert_only_digits(GtkEditable *editable, const gchar *text, gint length, gint *position, gpointer user_data){ + gchar *new_text = g_new(gchar, length + 1); + gint i, j = 0; + + for (i = 0; i < length; i++) { + if (g_ascii_isdigit(text[i])) { + new_text[j] = text[i]; + j++; + } + } + + if (j < length) { + g_signal_handlers_block_by_func(editable, G_CALLBACK(yon_on_text_insert_only_digits), user_data); + gtk_editable_insert_text(editable, new_text, j, position); + g_signal_handlers_unblock_by_func(editable, G_CALLBACK(yon_on_text_insert_only_digits), user_data); + g_signal_stop_emission_by_name(editable, "insert-text"); + } + + g_free(new_text); +} + // GtkEntry section // struct entry_pattern_data { // GtkEntry *entry; diff --git a/source/libublsettings-gtk3.h b/source/libublsettings-gtk3.h index 6567988..2382910 100644 --- a/source/libublsettings-gtk3.h +++ b/source/libublsettings-gtk3.h @@ -482,6 +482,8 @@ typedef struct { rmb_menu_window *yon_rmb_menu_setup(GtkWidget *target_widget, int (*show_function)(void*), void *show_data, const char *button_label, const char *icon_name, GCallback function, gpointer data,...); #endif +void yon_on_text_insert_only_digits(GtkEditable *editable, const gchar *text, gint length, gint *position, gpointer user_data); + // GtkTreeStore section dictionary *yon_gtk_tree_store_get_children(GtkTreeStore *tree, GtkTreeIter *parent,int column); From b17c31192582b048974609cea8ef673cb91d91bb Mon Sep 17 00:00:00 2001 From: Ivan Yarcev Date: Thu, 5 Sep 2024 17:48:56 +0600 Subject: [PATCH 2/2] Leaks fixes --- source/libublsettings-gtk3.c | 1 + 1 file changed, 1 insertion(+) diff --git a/source/libublsettings-gtk3.c b/source/libublsettings-gtk3.c index 4f0a552..89ef2a1 100644 --- a/source/libublsettings-gtk3.c +++ b/source/libublsettings-gtk3.c @@ -1441,6 +1441,7 @@ config_str yon_resource_open_file(const char *path, int *size){ gsize sz; GFile *file = g_file_new_for_uri(path); g_file_load_contents(file,NULL,&modules,&sz,NULL,NULL); + g_object_unref(G_OBJECT(file)); parsed = yon_char_parse(modules,size,"\n"); return parsed; }