static void _devices_changed_cb(BluetoothApplet *applet, DawatiBtShell *shell) { DawatiBtShellPrivate *priv = GET_PRIVATE (shell); GList *devices; ClutterActorIter iter; ClutterActor *child; devices = bluetooth_applet_get_devices (applet); g_list_foreach (devices, (GFunc)_handle_device, shell); g_list_free_full (devices, _bluetooth_simple_device_free); clutter_actor_iter_init (&iter, priv->device_box); while (clutter_actor_iter_next (&iter, &child)) _remove_non_connected_device (child, shell); dawati_bt_shell_update (shell); }
static void update_device_list (BluetoothApplet *applet, gpointer user_data) { GtkUIManager *uimanager; GList *actions, *devices, *l; gboolean has_devices = FALSE; uimanager = GTK_UI_MANAGER (gtk_builder_get_object (xml, "bluetooth-applet-ui-manager")); devices = bluetooth_applet_get_devices (applet); if (devices == NULL) { /* No devices? Remove everything */ actions = gtk_action_group_list_actions (devices_action_group); g_list_foreach (actions, (GFunc) remove_action_item, uimanager); g_list_free (actions); goto done; } /* Get a list of actions, and we'll remove the ones with a * device in the list. We remove the submenu items first */ actions = gtk_action_group_list_actions (devices_action_group); for (l = actions; l != NULL; l = l->next) { if (bluetooth_verify_address (gtk_action_get_name (l->data)) == FALSE) l->data = NULL; } actions = g_list_remove_all (actions, NULL); for (l = devices; l != NULL; l = g_list_next (l)) { BluetoothSimpleDevice *device = l->data; GtkAction *action, *status, *oper; char *name; if (device_has_submenu (device) == FALSE) { g_boxed_free (BLUETOOTH_TYPE_SIMPLE_DEVICE, device); continue; } has_devices = TRUE; action = gtk_action_group_get_action (devices_action_group, device->bdaddr); oper = NULL; status = NULL; if (action) { char *action_name; actions = g_list_remove (actions, action); action_name = g_strdup_printf ("%s-status", device->bdaddr); status = gtk_action_group_get_action (devices_action_group, action_name); g_free (action_name); action_name = g_strdup_printf ("%s-action", device->bdaddr); oper = gtk_action_group_get_action (devices_action_group, action_name); g_free (action_name); } name = escape_label_for_action (device->alias); if (action == NULL) { guint menu_merge_id; char *action_path; /* The menu item with descendants */ action = gtk_action_new (device->bdaddr, name, NULL, NULL); gtk_action_group_add_action (devices_action_group, action); g_object_unref (action); menu_merge_id = gtk_ui_manager_new_merge_id (uimanager); gtk_ui_manager_add_ui (uimanager, menu_merge_id, "/bluetooth-applet-popup/devices-placeholder", device->bdaddr, device->bdaddr, GTK_UI_MANAGER_MENU, FALSE); g_object_set_data_full (G_OBJECT (action), "merge-id", GUINT_TO_POINTER (menu_merge_id), NULL); /* The status menu item */ status = add_menu_item (device->bdaddr, "status", device->connected ? _("Connected") : _("Disconnected"), uimanager, menu_merge_id, NULL); gtk_action_set_sensitive (status, FALSE); if (device->can_connect) { action_path = g_strdup_printf ("/bluetooth-applet-popup/devices-placeholder/%s/%s-status", device->bdaddr, device->bdaddr); action_set_bold (uimanager, status, action_path); g_free (action_path); } else { gtk_action_set_visible (status, FALSE); } /* The connect button */ oper = add_menu_item (device->bdaddr, "action", device->connected ? _("Disconnect") : _("Connect"), uimanager, menu_merge_id, G_CALLBACK (on_connect_activate)); if (!device->can_connect) gtk_action_set_visible (oper, FALSE); add_separator_item (device->bdaddr, "connect-sep", uimanager, menu_merge_id); /* The Send to... button */ if (device->capabilities & BLUETOOTH_CAPABILITIES_OBEX_PUSH) { add_menu_item (device->bdaddr, "sendto", _("Send files..."), uimanager, menu_merge_id, G_CALLBACK (sendto_callback)); g_object_set_data_full (G_OBJECT (action), "alias", g_strdup (device->alias), g_free); } if (device->capabilities & BLUETOOTH_CAPABILITIES_OBEX_FILE_TRANSFER) { add_menu_item (device->bdaddr, "browse", _("Browse files..."), uimanager, menu_merge_id, G_CALLBACK (browse_callback)); } add_separator_item (device->bdaddr, "files-sep", uimanager, menu_merge_id); if (device->type == BLUETOOTH_TYPE_KEYBOARD && program_available (GNOMECC)) { add_menu_item (device->bdaddr, "keyboard", _("Keyboard Settings"), uimanager, menu_merge_id, G_CALLBACK (keyboard_callback)); } if (device->type == BLUETOOTH_TYPE_MOUSE && program_available (GNOMECC)) { add_menu_item (device->bdaddr, "mouse", _("Mouse and Touchpad Settings"), uimanager, menu_merge_id, G_CALLBACK (mouse_callback)); } if ((device->type == BLUETOOTH_TYPE_HEADSET || device->type == BLUETOOTH_TYPE_HEADPHONES || device->type == BLUETOOTH_TYPE_OTHER_AUDIO) && program_available (GNOMECC)) { add_menu_item (device->bdaddr, "sound", _("Sound Settings"), uimanager, menu_merge_id, G_CALLBACK (sound_callback)); } } else { gtk_action_set_label (action, name); if (device->can_connect) { gtk_action_set_visible (status, TRUE); gtk_action_set_visible (oper, TRUE); set_device_status_label (device->bdaddr, device->connected ? CONNECTED : DISCONNECTED); gtk_action_set_label (oper, device->connected ? _("Disconnect") : _("Connect")); } else { gtk_action_set_visible (status, FALSE); gtk_action_set_visible (oper, FALSE); } } g_free (name); if (oper != NULL) { g_object_set_data_full (G_OBJECT (oper), "connected", GINT_TO_POINTER (device->connected ? CONNECTED : DISCONNECTED), NULL); g_object_set_data_full (G_OBJECT (oper), "device-path", g_strdup (device->device_path), g_free); } /* And now for the trick of the day */ if (device->connected != FALSE) { char *path; path = g_strdup_printf ("/bluetooth-applet-popup/devices-placeholder/%s", device->bdaddr); action_set_bold (uimanager, action, path); g_free (path); } g_boxed_free (BLUETOOTH_TYPE_SIMPLE_DEVICE, device); } /* Remove the left-over devices */ g_list_foreach (actions, (GFunc) remove_action_item, uimanager); g_list_free (actions); /* Cleanup */ g_list_free (devices); done: gtk_ui_manager_ensure_update (uimanager); gtk_action_set_visible (GTK_ACTION (gtk_builder_get_object (xml, "devices-label")), has_devices); }