diff options
author | David Härdeman <david@hardeman.nu> | 2015-08-11 22:28:03 +0200 |
---|---|---|
committer | David Härdeman <david@hardeman.nu> | 2015-08-11 22:28:03 +0200 |
commit | 852e65956abc14f3591df70e8868635e2ed5dac9 (patch) | |
tree | fa5d2f162e108995c0407c1ae1158d11c45b221a | |
parent | 6e406cc6a8384f1a4de57591f6b7772a0f5be865 (diff) |
Remove notebook from UI and use a stack instead
-rw-r--r-- | rcm-client-hardware-list.c | 76 | ||||
-rw-r--r-- | rcm-client-main.c | 13 | ||||
-rw-r--r-- | rcm-client-main.h | 2 | ||||
-rw-r--r-- | rcm-client-receive.c | 78 | ||||
-rw-r--r-- | rcm-client-receive.h | 1 |
5 files changed, 61 insertions, 109 deletions
diff --git a/rcm-client-hardware-list.c b/rcm-client-hardware-list.c index 9f55e82..a7dceb6 100644 --- a/rcm-client-hardware-list.c +++ b/rcm-client-hardware-list.c @@ -12,7 +12,6 @@ static GtkWidget *status_msg; static GtkWidget *hw_list_box; -static GtkWidget *stack; static GList *hw_list = NULL; struct hwentry { @@ -28,14 +27,6 @@ find_hwentry_by_object(gconstpointer a, gconstpointer user_data) return hwe->hw == user_data ? 0 : -1; } -static gint -find_hwentry_by_widget(gconstpointer a, gconstpointer user_data) -{ - const struct hwentry *hwe = a; - - return hwe->widget == user_data ? 0 : -1; -} - void rcng_client_hardware_list_remove(GDBusObject *hw) { GList *entry; @@ -53,16 +44,28 @@ void rcng_client_hardware_list_remove(GDBusObject *hw) g_free(hwe); if (!hw_list) - gtk_stack_set_visible_child(GTK_STACK(stack), status_msg); + gtk_stack_set_visible_child(global->stack, status_msg); } +static void +on_hw_selected(GtkButton *button, + gpointer user_data) +{ + GDBusObject *hw = user_data; + + rcng_client_receive_init_ui(hw); +} + + void rcng_client_hardware_list_add(GDBusObject *hw) { GList *interfaces; GList *ll; + GtkWidget *row; GtkWidget *box; GtkWidget *icon; GtkWidget *label; + GtkWidget *button; struct hwentry *hwe; gchar *labeltxt; @@ -76,8 +79,9 @@ void rcng_client_hardware_list_add(GDBusObject *hw) g_list_free_full (interfaces, g_object_unref); if (!hw_list) - gtk_stack_set_visible_child(GTK_STACK(stack), hw_list_box); + gtk_stack_set_visible_child(global->stack, hw_list_box); + row = gtk_list_box_row_new(); box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); icon = gtk_image_new_from_icon_name("gtk-harddisk", GTK_ICON_SIZE_DIALOG); gtk_widget_set_valign(icon, GTK_ALIGN_START); @@ -88,11 +92,17 @@ void rcng_client_hardware_list_add(GDBusObject *hw) label = gtk_label_new(NULL); gtk_label_set_markup(GTK_LABEL(label), labeltxt); g_free(labeltxt); + button = gtk_button_new_from_icon_name("emblem-system-symbolic", GTK_ICON_SIZE_MENU); + gtk_widget_set_valign(button, GTK_ALIGN_END); + gtk_widget_set_halign(button, GTK_ALIGN_END); + g_signal_connect(button, "clicked", G_CALLBACK(on_hw_selected), hw); gtk_box_pack_start(GTK_BOX(box), icon, FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(box), label, FALSE, FALSE, 0); - gtk_widget_show_all(box); + gtk_box_pack_end(GTK_BOX(box), button, FALSE, FALSE, 0); + gtk_container_add(GTK_CONTAINER(row), box); + gtk_widget_show_all(row); - gtk_list_box_insert(GTK_LIST_BOX(hw_list_box), box, -1); + gtk_list_box_insert(GTK_LIST_BOX(hw_list_box), row, -1); hwe = g_malloc(sizeof(*hwe)); hwe->hw = hw; @@ -100,29 +110,6 @@ void rcng_client_hardware_list_add(GDBusObject *hw) hw_list = g_list_append(hw_list, hwe); } -static struct hwentry *old_hwe = NULL; - -static void -on_hw_selected(GtkListBox *box, - GtkListBoxRow *row, - gpointer user_data) -{ - GList *entry; - GtkWidget *child; - struct hwentry *hwe; - - child = row ? gtk_bin_get_child(GTK_BIN(row)) : NULL; - entry = g_list_find_custom(hw_list, child, find_hwentry_by_widget); - hwe = entry ? entry->data : NULL; - - if (hwe == old_hwe) - return; - - old_hwe = hwe; - rcng_client_receive_destroy_ui(); - rcng_client_receive_init_ui(hwe ? hwe->hw : NULL); -} - void rcng_client_hardware_list_update_status(gchar *status) { gtk_label_set_text(GTK_LABEL(status_msg), status); @@ -130,22 +117,13 @@ void rcng_client_hardware_list_update_status(gchar *status) void rcng_client_hardware_list_init_ui() { - stack = gtk_stack_new(); - gtk_widget_set_margin_start(stack, 12); - gtk_widget_set_margin_end(stack, 12); - gtk_widget_set_margin_top(stack, 12); - gtk_widget_set_margin_bottom(stack, 12); - gtk_stack_set_transition_type(GTK_STACK(stack), GTK_STACK_TRANSITION_TYPE_CROSSFADE); - status_msg = gtk_label_new("Connecting to server..."); - gtk_stack_add_named(GTK_STACK(stack), status_msg, "nohw"); - gtk_stack_set_visible_child(GTK_STACK(stack), status_msg); + gtk_stack_add_named(global->stack, status_msg, "nohw"); + gtk_stack_set_visible_child(global->stack, status_msg); hw_list_box = gtk_list_box_new(); - gtk_stack_add_named(GTK_STACK(stack), hw_list_box, "yeshw"); - g_signal_connect(hw_list_box, "row-selected", G_CALLBACK(on_hw_selected), NULL); - - gtk_notebook_append_page(global->notebook, stack, gtk_label_new("Hardware")); + gtk_stack_add_named(global->stack, hw_list_box, "yeshw"); + gtk_list_box_set_selection_mode(GTK_LIST_BOX(hw_list_box), GTK_SELECTION_NONE); } diff --git a/rcm-client-main.c b/rcm-client-main.c index ddf5f92..27862fa 100644 --- a/rcm-client-main.c +++ b/rcm-client-main.c @@ -194,13 +194,16 @@ int main (int argc, char *argv[]) gtk_header_bar_pack_end(GTK_HEADER_BAR(header), test); */ + global->stack = GTK_STACK(gtk_stack_new()); + gtk_widget_set_margin_start(GTK_WIDGET(global->stack), 12); + gtk_widget_set_margin_end(GTK_WIDGET(global->stack), 12); + gtk_widget_set_margin_top(GTK_WIDGET(global->stack), 12); + gtk_widget_set_margin_bottom(GTK_WIDGET(global->stack), 12); + gtk_stack_set_transition_type(global->stack, GTK_STACK_TRANSITION_TYPE_CROSSFADE); - global->notebook = GTK_NOTEBOOK(gtk_notebook_new()); - gtk_notebook_set_tab_pos(global->notebook, GTK_POS_LEFT); + rcng_client_hardware_list_init_ui(); - rcng_client_hardware_list_init_ui(global->notebook); - - gtk_container_add(GTK_CONTAINER(win), GTK_WIDGET(global->notebook)); + gtk_container_add(GTK_CONTAINER(win), GTK_WIDGET(global->stack)); //gtk_window_set_title(window, "Remote Control Configuration"); gtk_window_set_icon_name(global->window, "gnome-multimedia"); gtk_widget_show_all(win); diff --git a/rcm-client-main.h b/rcm-client-main.h index 64440c2..2b1461f 100644 --- a/rcm-client-main.h +++ b/rcm-client-main.h @@ -3,7 +3,7 @@ void poke_objects(); struct global_variables { GtkWindow *window; GtkHeaderBar *header; - GtkNotebook *notebook; + GtkStack *stack; }; extern struct global_variables *global; diff --git a/rcm-client-receive.c b/rcm-client-receive.c index b744806..6f64f6f 100644 --- a/rcm-client-receive.c +++ b/rcm-client-receive.c @@ -53,7 +53,6 @@ struct state { GList *remotes; GList *header_buttons; bool editing; - bool active; GtkWidget *stack; GtkWidget *stack_switch; }; @@ -411,21 +410,6 @@ new_button_add(struct remote *remote, const gchar *protocol, guint64 scancode, return rcb; } -void rcng_client_receive_destroy_ui() -{ - if (state.stack_switch) - gtk_widget_destroy(state.stack_switch); - - if (state.stack) - gtk_widget_destroy(state.stack); - - g_object_unref(state.stack_switch); - state.stack_switch = NULL; - state.stack = NULL; -} - -static gint own_page_num = -1; - /* FIXME: These two functions should probably move to the core */ static void create_header_button(const gchar *tooltip, const gchar *icon_name, gboolean end, @@ -737,7 +721,19 @@ out: static void show_hardware_list(GtkButton *button, gpointer user_data) { - gtk_notebook_set_current_page(global->notebook, 0); + remove_header_buttons(); + gtk_header_bar_set_custom_title(GTK_HEADER_BAR(global->header), NULL); + gtk_stack_set_visible_child_name(global->stack, "yeshw"); + + if (state.stack_switch) + gtk_widget_destroy(state.stack_switch); + + if (state.stack) + gtk_widget_destroy(state.stack); + + g_object_unref(state.stack_switch); + state.stack_switch = NULL; + state.stack = NULL; } static void @@ -793,25 +789,6 @@ toggle_edit_keymap(GtkButton *button, gpointer user_data) set_edit_keymap(state.editing); } -static void -on_notebook_page_change(GtkNotebook *notebook, GtkWidget *page, guint new_page_num, - gpointer user_data) -{ - if (new_page_num != own_page_num) { - remove_header_buttons(); - gtk_header_bar_set_custom_title(GTK_HEADER_BAR(global->header), NULL); - state.editing = false; - state.active = false; - return; - } - - state.active = true; - state.editing = false; - set_edit_keymap(state.editing); - g_print("Page change: %i -> %u\n", own_page_num, new_page_num); - gtk_header_bar_set_custom_title(GTK_HEADER_BAR(global->header), state.stack_switch); -} - void rcng_client_receive_key_pressed(GDBusObject *obj, const gchar *protocol, guint64 scancode, const gchar *keycode) { @@ -819,7 +796,7 @@ void rcng_client_receive_key_pressed(GDBusObject *obj, const gchar *protocol, unsigned affected = 0; /* FIXME: Use object path, this is just test code */ - if (!state.active || state.editing) + if (state.editing) return; for (l = state.remotes; l; l = l->next) { @@ -849,7 +826,7 @@ void rcng_client_receive_key_released(GDBusObject *obj, const gchar *keycode) unsigned affected = 0; /* FIXME: Use object path, this is just test code */ - if (!state.active || state.editing) + if (state.editing) return; for (l = state.remotes; l; l = l->next) { @@ -1007,23 +984,14 @@ get_keymap(RCDevice *object, const gchar *keymap_id) void rcng_client_receive_init_ui(GDBusObject *new_hw) { - static bool first = true; unsigned i; - - if (first) { - g_signal_connect(global->notebook, "switch-page", G_CALLBACK(on_notebook_page_change), NULL); - state.remotes = NULL; - state.header_buttons = NULL; - state.editing = false; - state.active = false; - first = false; - } - - rcng_client_receive_destroy_ui(); - GtkWidget *scrollda; GtkWidget *label; + state.remotes = NULL; + state.header_buttons = NULL; + state.editing = false; + state.stack = gtk_stack_new(); state.stack_switch = gtk_stack_switcher_new(); g_object_ref(state.stack_switch); @@ -1033,7 +1001,6 @@ void rcng_client_receive_init_ui(GDBusObject *new_hw) scrollda = gtk_scrolled_window_new(NULL, NULL); gtk_container_set_border_width(GTK_CONTAINER(scrollda), 12); gtk_stack_add_titled(GTK_STACK(state.stack), scrollda, "Receive", "Receive"); - own_page_num = gtk_notebook_append_page(global->notebook, state.stack, gtk_label_new("Receive")); label = gtk_label_new("Transmit"); gtk_stack_add_titled(GTK_STACK(state.stack), label, "Transmit", "Transmit"); @@ -1066,6 +1033,11 @@ void rcng_client_receive_init_ui(GDBusObject *new_hw) g_free(keymap_ids); gtk_widget_show_all(state.stack); - gtk_notebook_set_current_page(global->notebook, own_page_num); + + gtk_stack_add_named(global->stack, state.stack, "remotes"); + gtk_stack_set_visible_child(global->stack, state.stack); + + set_edit_keymap(state.editing); + gtk_header_bar_set_custom_title(GTK_HEADER_BAR(global->header), state.stack_switch); } diff --git a/rcm-client-receive.h b/rcm-client-receive.h index f0f0967..7ee5a25 100644 --- a/rcm-client-receive.h +++ b/rcm-client-receive.h @@ -1,5 +1,4 @@ -void rcng_client_receive_destroy_ui(); void rcng_client_receive_init_ui(GDBusObject *new_hw); void rcng_client_receive_key_pressed(GDBusObject *obj, const gchar *protocol, guint64 scancode, const gchar *keycode); void rcng_client_receive_key_released(GDBusObject *obj, const gchar *keycode); |