From dc6bb0926504150b010b9313ef66216fa4cb9e3a Mon Sep 17 00:00:00 2001 From: David Härdeman Date: Mon, 20 Jul 2015 22:00:38 +0200 Subject: Change resize dialog to a properties dialog --- rcm-client-receive.c | 88 ++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 79 insertions(+), 9 deletions(-) diff --git a/rcm-client-receive.c b/rcm-client-receive.c index 6c7a3a8..61fc991 100644 --- a/rcm-client-receive.c +++ b/rcm-client-receive.c @@ -31,6 +31,7 @@ struct remote { GList *buttons; GtkWidget *widget; GtkWidget *grid; + GtkWidget *frame; GtkWidget *edit_button; GList *keymap; }; @@ -578,7 +579,7 @@ update_remote(struct remote *remote) } static void -resize_layout_dialog(GtkButton *button, gpointer user_data) +properties_dialog(GtkButton *button, gpointer user_data) { struct remote *remote = user_data; GtkWindow *parent = GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(button))); @@ -586,6 +587,12 @@ resize_layout_dialog(GtkButton *button, gpointer user_data) GtkWidget *content_area; GtkWidget *grid; GtkWidget *icon; + GtkWidget *id_label; + GtkWidget *id; + GtkWidget *name_label; + GtkWidget *name_input; + GtkWidget *desc_label; + GtkWidget *desc_input; GtkWidget *width_label; GtkAdjustment *width_adj; GtkWidget *width_input; @@ -593,10 +600,14 @@ resize_layout_dialog(GtkButton *button, gpointer user_data) GtkAdjustment *height_adj; GtkWidget *height_input; gint r; + const gchar *name; + gchar *name_cpy; + const gchar *desc; + gchar *desc_cpy; gint width; gint height; - dialog = gtk_dialog_new_with_buttons("Resize Keymap", parent, + dialog = gtk_dialog_new_with_buttons("Keymap Properties", parent, GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_MODAL, "OK", GTK_RESPONSE_ACCEPT, "Cancel", GTK_RESPONSE_REJECT, @@ -611,19 +622,46 @@ resize_layout_dialog(GtkButton *button, gpointer user_data) gtk_widget_set_valign(icon, GTK_ALIGN_START); gtk_grid_attach(GTK_GRID(grid), icon, 0, 1, 1, 2); - width_label = gtk_label_new("Width:"); + id_label = gtk_label_new("ID:"); + gtk_widget_set_halign(id_label, GTK_ALIGN_START); + id = gtk_label_new(remote->id); + gtk_widget_set_halign(id, GTK_ALIGN_START); + gtk_grid_attach(GTK_GRID(grid), id_label, 1, 1, 1, 1); + gtk_grid_attach(GTK_GRID(grid), id, 2, 1, 1, 1); + + name_label = gtk_label_new("Name:"); + gtk_widget_set_halign(name_label, GTK_ALIGN_START); + name_input = gtk_entry_new(); + gtk_widget_set_hexpand(name_input, true); + gtk_entry_set_max_length(GTK_ENTRY(name_input), 100); + gtk_entry_set_text(GTK_ENTRY(name_input), remote->name); + gtk_grid_attach(GTK_GRID(grid), name_label, 1, 2, 1, 1); + gtk_grid_attach(GTK_GRID(grid), name_input, 2, 2, 1, 1); + + desc_label = gtk_label_new("Description:"); + gtk_widget_set_halign(desc_label, GTK_ALIGN_START); + desc_input = gtk_entry_new(); + gtk_widget_set_hexpand(desc_input, true); + gtk_entry_set_max_length(GTK_ENTRY(desc_input), 100); + gtk_entry_set_text(GTK_ENTRY(desc_input), remote->description); + gtk_grid_attach(GTK_GRID(grid), desc_label, 1, 3, 1, 1); + gtk_grid_attach(GTK_GRID(grid), desc_input, 2, 3, 1, 1); + + width_label = gtk_label_new("Width"); gtk_widget_set_halign(width_label, GTK_ALIGN_START); width_adj = gtk_adjustment_new(remote->width, 1.0, 100.0, 1.0, 5.0, 0.0); width_input = gtk_spin_button_new(width_adj, 1.0, 0); - gtk_grid_attach(GTK_GRID(grid), width_label, 1, 1, 1, 1); - gtk_grid_attach(GTK_GRID(grid), width_input, 2, 1, 1, 1); + gtk_widget_set_hexpand(width_input, true); + gtk_grid_attach(GTK_GRID(grid), width_label, 1, 4, 1, 1); + gtk_grid_attach(GTK_GRID(grid), width_input, 2, 4, 1, 1); height_label = gtk_label_new("Height:"); gtk_widget_set_halign(height_label, GTK_ALIGN_START); height_adj = gtk_adjustment_new(remote->height, 1.0, 100.0, 1.0, 5.0, 0.0); height_input = gtk_spin_button_new(height_adj, 1.0, 0); - gtk_grid_attach(GTK_GRID(grid), height_label, 1, 2, 1, 1); - gtk_grid_attach(GTK_GRID(grid), height_input, 2, 2, 1, 1); + gtk_widget_set_hexpand(height_input, true); + gtk_grid_attach(GTK_GRID(grid), height_label, 1, 5, 1, 1); + gtk_grid_attach(GTK_GRID(grid), height_input, 2, 5, 1, 1); content_area = gtk_dialog_get_content_area(GTK_DIALOG(dialog)); gtk_container_set_border_width(GTK_CONTAINER(content_area), 12); @@ -634,9 +672,21 @@ resize_layout_dialog(GtkButton *button, gpointer user_data) if (r != GTK_RESPONSE_ACCEPT) goto out; + name = gtk_entry_get_text(GTK_ENTRY(name_input)); + desc = gtk_entry_get_text(GTK_ENTRY(desc_input)); width = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(width_input)); height = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(height_input)); + if (!name || strlen(name) < 1) { + printf("Invalid name: %s\n", name ? name : "NULL"); + goto out; + } + + if (!desc || strlen(desc) < 1) { + printf("Invalid description: %s\n", desc ? desc : "NULL"); + goto out; + } + if (width < 1 || width > REMOTE_LAYOUT_MAX_WIDTH) { printf("Invalid width: %i\n", width); goto out; @@ -647,10 +697,29 @@ resize_layout_dialog(GtkButton *button, gpointer user_data) goto out; } + name_cpy = strdup(name); + desc_cpy = strdup(desc); + + if (!name_cpy || !desc_cpy) { + free(name_cpy); + free(desc_cpy); + printf("strdup failed\n"); + goto out; + } + + free(remote->name); + free(remote->description); + remote->name = name_cpy; + remote->description = desc_cpy; + resize_layout(remote, width, height); update_remote(remote); + gtk_frame_set_label(GTK_FRAME(remote->frame), remote->name); + gtk_widget_set_name(gtk_frame_get_label_widget(GTK_FRAME(remote->frame)), + "RemoteControlClientRemoteLabel"); + out: gtk_widget_destroy(dialog); } @@ -672,8 +741,8 @@ set_edit_keymap(bool editing) GList *b; if (editing) { - remote->edit_button = gtk_button_new_with_label("Resize"); - g_signal_connect(remote->edit_button, "clicked", G_CALLBACK(resize_layout_dialog), remote); + remote->edit_button = gtk_button_new_with_label("Properties"); + g_signal_connect(remote->edit_button, "clicked", G_CALLBACK(properties_dialog), remote); gtk_grid_attach(GTK_GRID(remote->grid), remote->edit_button, 0, -1, remote->width, 1); gtk_widget_show_all(remote->edit_button); } else { @@ -783,6 +852,7 @@ get_keymap(RCDevice *object, const gchar *keymap_id) gtk_widget_set_name(gtk_frame_get_label_widget(GTK_FRAME(frame)), "RemoteControlClientRemoteLabel"); gtk_widget_set_name(frame, "RemoteControlClientRemoteFrame"); gtk_fixed_put(GTK_FIXED(fixed), frame, 0, 0); + remote->frame = frame; GtkWidget *grid; grid = gtk_grid_new(); -- cgit v1.2.3