summaryrefslogtreecommitdiff
path: root/rcm-client-hardware-list.c
diff options
context:
space:
mode:
Diffstat (limited to 'rcm-client-hardware-list.c')
-rw-r--r--rcm-client-hardware-list.c76
1 files changed, 27 insertions, 49 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);
}