#include #include #include #include #include #include #include "generated.h" #include "rcm-client-main.h" #include "rcm-client-hardware-list.h" #include "rcm-client-receive.h" static GList *hw_list = NULL; struct hwentry { GDBusObject *hw; GtkWidget *widget; }; static gint find_hwentry_by_object(gconstpointer a, gconstpointer user_data) { const struct hwentry *hwe = a; return hwe->hw == user_data ? 0 : -1; } void rcng_client_hardware_list_remove(GDBusObject *hw) { GList *entry; struct hwentry *hwe; entry = g_list_find_custom(hw_list, hw, find_hwentry_by_object); if (!entry) return; hwe = entry->data; hw_list = g_list_remove_all(hw_list, hwe); g_print(" - Object removed %s\n", g_dbus_object_get_object_path(hwe->hw)); gtk_widget_destroy(hwe->widget); g_free(hwe); if (!hw_list) gtk_stack_set_visible_child_name(global->stack, "status_page"); } static void edit_keymaps_cb(GtkButton *button, gpointer user_data) { GDBusObject *hw = user_data; rcng_client_receive_init_ui(hw); } static void hardware_properties_cb(GtkButton *button, gpointer user_data) { RCDevice *object = user_data; GtkWidget *dialog; GtkLabel *dev; GtkLabel *desc; GtkLabel *driver; GtkLabel *kernelmap; dialog = GTK_WIDGET(gtk_builder_get_object(global->builder, "hardware_properties")); dev = GTK_LABEL(gtk_builder_get_object(global->builder, "hardware_properties_dev_value")); gtk_label_set_text(dev, rcdevice_get_sys_name(object)); desc = GTK_LABEL(gtk_builder_get_object(global->builder, "hardware_properties_desc_value")); gtk_label_set_text(desc, rcdevice_get_description(object)); driver = GTK_LABEL(gtk_builder_get_object(global->builder, "hardware_properties_driver_value")); gtk_label_set_text(driver, rcdevice_get_driver_name(object)); kernelmap = GTK_LABEL(gtk_builder_get_object(global->builder, "hardware_properties_kernelmap_value")); gtk_label_set_text(kernelmap, rcdevice_get_kernel_keymap_name(object)); gtk_widget_show_all(dialog); gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_hide(dialog); } 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; GtkWidget *hw_list_swin; GtkWidget *hw_list_box; GDBusInterface *interface; RCDevice *object; g_print(" - Object at %s\n", g_dbus_object_get_object_path(hw)); interfaces = g_dbus_object_get_interfaces(hw); for (ll = interfaces; ll != NULL; ll = ll->next) { GDBusInterface *iface = G_DBUS_INTERFACE(ll->data); g_print (" - Interface %s\n", g_dbus_interface_get_info(iface)->name); } g_list_free_full(interfaces, g_object_unref); interface = g_dbus_object_get_interface(hw, "org.gnome.RemoteControlManager.Device"); if (!interface) return; object = RCDEVICE(interface); printf("Name: %s, Desc: %s, Driver: %s, Kernel keymap: %s, HW: %s\n", rcdevice_get_sys_name(object), rcdevice_get_description(object), rcdevice_get_driver_name(object), rcdevice_get_kernel_keymap_name(object), rcdevice_get_hardware_type(object)); row = gtk_list_box_row_new(); box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 12); gtk_widget_set_margin_top(box, 6); gtk_widget_set_margin_bottom(box, 6); gtk_widget_set_margin_start(box, 12); gtk_widget_set_margin_end(box, 12); icon = gtk_image_new_from_icon_name("input-dialpad-symbolic", GTK_ICON_SIZE_MENU); gtk_widget_set_valign(icon, GTK_ALIGN_CENTER); gtk_widget_set_halign(icon, GTK_ALIGN_START); gtk_box_pack_start(GTK_BOX(box), icon, FALSE, FALSE, 0); labeltxt = g_strdup_printf("%s: %s", rcdevice_get_sys_name(object), rcdevice_get_description(object)); label = gtk_label_new(labeltxt); g_free(labeltxt); gtk_widget_set_valign(label, GTK_ALIGN_CENTER); gtk_box_pack_start(GTK_BOX(box), label, FALSE, FALSE, 0); button = gtk_button_new_from_icon_name("emblem-system-symbolic", GTK_ICON_SIZE_MENU); gtk_widget_set_valign(button, GTK_ALIGN_CENTER); gtk_widget_set_halign(button, GTK_ALIGN_END); g_signal_connect(button, "clicked", G_CALLBACK(hardware_properties_cb), object); gtk_box_pack_end(GTK_BOX(box), button, FALSE, FALSE, 0); button = gtk_button_new_from_icon_name("accessories-calculator-symbolic", GTK_ICON_SIZE_MENU); gtk_widget_set_valign(button, GTK_ALIGN_CENTER); gtk_widget_set_halign(button, GTK_ALIGN_END); g_signal_connect(button, "clicked", G_CALLBACK(edit_keymaps_cb), hw); gtk_box_pack_end(GTK_BOX(box), button, FALSE, FALSE, 0); gtk_container_add(GTK_CONTAINER(row), box); gtk_widget_show_all(row); hw_list_swin = GTK_WIDGET(gtk_builder_get_object(global->builder, "hardware_page_swin")); for (hw_list_box = gtk_bin_get_child(GTK_BIN(hw_list_swin)); hw_list_box && !GTK_IS_LIST_BOX(hw_list_box); hw_list_box = gtk_bin_get_child(GTK_BIN(hw_list_box))) /* Do nothing */; if (!hw_list_box) { hw_list_box = gtk_list_box_new(); gtk_list_box_set_selection_mode(GTK_LIST_BOX(hw_list_box), GTK_SELECTION_NONE); gtk_container_add(GTK_CONTAINER(hw_list_swin), hw_list_box); gtk_widget_show_all(hw_list_swin); } gtk_list_box_insert(GTK_LIST_BOX(hw_list_box), row, -1); if (!hw_list) gtk_stack_set_visible_child_name(global->stack, "hardware_page"); hwe = g_malloc(sizeof(*hwe)); hwe->hw = hw; hwe->widget = box; hw_list = g_list_append(hw_list, hwe); } void rcng_client_hardware_list_update_status(gchar *status) { GtkLabel *status_msg; status_msg = GTK_LABEL(gtk_stack_get_child_by_name(global->stack, "status_page")); gtk_label_set_text(status_msg, status); }