char * g_vfs_get_volume_symbolic_icon (GUdevDevice *device) { if (g_udev_device_has_property (device, "ID_MEDIA_PLAYER_ICON_NAME")) return g_strconcat (g_udev_device_get_property (device, "ID_MEDIA_PLAYER_ICON_NAME"), "-symbolic", NULL); else if (g_udev_device_has_property (device, "ID_MEDIA_PLAYER")) return g_strdup ("phone-symbolic"); else return g_strdup ("camera-photo-symbolic"); }
char * g_vfs_get_volume_icon (GUdevDevice *device) { if (g_udev_device_has_property (device, "ID_MEDIA_PLAYER_ICON_NAME")) return g_strdup (g_udev_device_get_property (device, "ID_MEDIA_PLAYER_ICON_NAME")); else if (g_udev_device_has_property (device, "ID_MEDIA_PLAYER")) return g_strdup ("phone"); else return g_strdup ("camera-photo"); }
char * g_vfs_get_volume_name (GUdevDevice *device, const char *device_id) { const char *gphoto_name; const char *product = NULL; const char *vendor; const char *model; /* our preference: device_id > ID_MEDIA_PLAYER_{VENDOR,PRODUCT} > product > * ID_{VENDOR,MODEL} */ gphoto_name = g_udev_device_get_property (device, device_id); if (gphoto_name != NULL && strcmp (gphoto_name, "1") != 0) return g_strdup (gphoto_name); vendor = g_udev_device_get_property (device, "ID_MEDIA_PLAYER_VENDOR"); if (vendor == NULL) vendor = g_udev_device_get_property (device, "ID_VENDOR_ENC"); model = g_udev_device_get_property (device, "ID_MEDIA_PLAYER_MODEL"); if (model == NULL) { model = g_udev_device_get_property (device, "ID_MODEL_ENC"); product = g_udev_device_get_sysfs_attr (device, "product"); } if (product != NULL && strlen (product) > 0) return g_strdup (udev_decode_string (product)); else if (vendor == NULL) { if (model != NULL) return g_strdup (udev_decode_string (model)); } else { if (model != NULL) { /* we can't call udev_decode_string() twice in one g_strdup_printf(), * it returns a static buffer */ gchar *temp = g_strconcat (vendor, " ", model, NULL); gchar *name = g_strdup (udev_decode_string (temp)); g_free (temp); return name; } else { if (g_udev_device_has_property (device, "ID_MEDIA_PLAYER")) { /* Translators: %s is the device vendor */ return g_strdup_printf (_("%s Audio Player"), udev_decode_string (vendor)); } else { /* Translators: %s is the device vendor */ return g_strdup_printf (_("%s Camera"), udev_decode_string (vendor)); } } } return g_strdup (_("Camera")); }
static gboolean partition_table_check (StoragedObject *object) { StoragedLinuxBlockObject *block_object = STORAGED_LINUX_BLOCK_OBJECT (object); gboolean ret = FALSE; /* only consider whole disks, never partitions */ if (g_strcmp0 (g_udev_device_get_devtype (block_object->device->udev_device), "disk") != 0) goto out; /* if blkid(8) already identified the device as a partition table, it's all good */ if (g_udev_device_has_property (block_object->device->udev_device, "ID_PART_TABLE_TYPE")) { /* however, if blkid(8) also think that we're a filesystem... then don't * mark us as a partition table ... except if we are partitioned by the * kernel * * (see filesystem_check() for the similar case where we don't pretend * to be a filesystem) */ if (g_strcmp0 (g_udev_device_get_property (block_object->device->udev_device, "ID_FS_USAGE"), "filesystem") == 0) { if (!disk_is_partitioned_by_kernel (block_object->device->udev_device)) { goto out; } } ret = TRUE; goto out; } /* Note that blkid(8) might not detect all partition table * formats that the kernel knows about.... so we need to * double check... * * Fortunately, note that the kernel guarantees that all children * block devices that are partitions are created before the uevent * for the parent block device.... so if the parent block device has * children... then it must be partitioned by the kernel, hence it * must contain a partition table. */ if (disk_is_partitioned_by_kernel (block_object->device->udev_device)) { ret = TRUE; goto out; } out: return ret; }
/** * cd_sensor_client_uevent_cb: **/ static void cd_sensor_client_uevent_cb (GUdevClient *gudev_client, const gchar *action, GUdevDevice *udev_device, CdSensorClient *sensor_client) { gboolean ret; /* remove */ if (g_strcmp0 (action, "remove") == 0) { g_debug ("CdSensorClient: remove %s", g_udev_device_get_sysfs_path (udev_device)); ret = g_udev_device_has_property (udev_device, "COLORD_SENSOR_KIND"); if (ret) { cd_sensor_client_remove (sensor_client, udev_device); goto out; } goto out; } /* add */ if (g_strcmp0 (action, "add") == 0) { g_debug ("CdSensorClient: add %s", g_udev_device_get_sysfs_path (udev_device)); ret = g_udev_device_has_property (udev_device, "COLORD_SENSOR_KIND"); if (ret) { cd_sensor_client_add (sensor_client, udev_device); goto out; } goto out; } out: return; }
static gboolean partition_check (UDisksLinuxBlockObject *object) { gboolean ret = FALSE; /* could be partitioned by the kernel */ if (g_strcmp0 (g_udev_device_get_devtype (object->device->udev_device), "partition") == 0) { ret = TRUE; goto out; } /* if blkid(8) already identified the device as a partition, it's all good */ if (g_udev_device_has_property (object->device->udev_device, "ID_PART_ENTRY_SCHEME")) { ret = TRUE; goto out; } out: return ret; }
static gboolean partition_check (StoragedObject *object) { StoragedLinuxBlockObject *block_object = STORAGED_LINUX_BLOCK_OBJECT (object); gboolean ret = FALSE; /* could be partitioned by the kernel */ if (g_strcmp0 (g_udev_device_get_devtype (block_object->device->udev_device), "partition") == 0) { ret = TRUE; goto out; } /* if blkid(8) already identified the device as a partition, it's all good */ if (g_udev_device_has_property (block_object->device->udev_device, "ID_PART_ENTRY_SCHEME")) { ret = TRUE; goto out; } out: return ret; }
/** * cd_sensor_set_from_device: **/ gboolean cd_sensor_set_from_device (CdSensor *sensor, GUdevDevice *device, GError **error) { CdSensorCap cap; CdSensorPrivate *priv = sensor->priv; const gchar *images[] = { "attach", "calibrate", "screen", NULL }; const gchar *images_md[] = { CD_SENSOR_METADATA_IMAGE_ATTACH, CD_SENSOR_METADATA_IMAGE_CALIBRATE, CD_SENSOR_METADATA_IMAGE_SCREEN, NULL }; const gchar *kind_str; const gchar *model_tmp = NULL; const gchar *vendor_tmp = NULL; const gchar * const *caps_str; gboolean ret; gboolean use_database; gchar *tmp; guint i; /* only use the database if we found both the VID and the PID */ use_database = g_udev_device_has_property (device, "ID_VENDOR_FROM_DATABASE") && g_udev_device_has_property (device, "ID_MODEL_FROM_DATABASE"); /* vendor */ if (use_database) vendor_tmp = g_udev_device_get_property (device, "ID_VENDOR_FROM_DATABASE"); if (vendor_tmp == NULL) vendor_tmp = g_udev_device_get_property (device, "ID_VENDOR"); if (vendor_tmp == NULL) vendor_tmp = g_udev_device_get_sysfs_attr (device, "manufacturer"); if (vendor_tmp == NULL) vendor_tmp = "unknown"; priv->vendor = g_strdup (vendor_tmp); /* make name sane */ g_strdelimit (priv->vendor, "_", ' '); /* model */ if (use_database) model_tmp = g_udev_device_get_property (device, "ID_MODEL_FROM_DATABASE"); if (model_tmp == NULL) model_tmp = g_udev_device_get_property (device, "ID_MODEL"); if (model_tmp == NULL) model_tmp = g_udev_device_get_sysfs_attr (device, "product"); if (model_tmp == NULL) model_tmp = "Unknown"; cd_sensor_set_model (sensor, model_tmp); /* make name sane */ g_strdelimit (priv->model, "_", ' '); /* try to get type */ kind_str = g_udev_device_get_property (device, "COLORD_SENSOR_KIND"); priv->kind = cd_sensor_kind_from_string (kind_str); if (priv->kind == CD_SENSOR_KIND_UNKNOWN) { ret = FALSE; g_set_error (error, 1, 0, "failed to recognize color device: %s - %s", vendor_tmp, model_tmp); goto out; } /* get caps */ caps_str = g_udev_device_get_property_as_strv (device, "COLORD_SENSOR_CAPS"); if (caps_str != NULL) { for (i = 0; caps_str[i] != NULL; i++) { cap = cd_sensor_cap_from_string (caps_str[i]); if (cap != CD_SENSOR_CAP_UNKNOWN) { cd_bitfield_add (priv->caps, cap); } else { g_warning ("Unknown sensor cap %s on %s", caps_str[i], kind_str); } } } /* is the sensor embeded, e.g. on the W700? */ ret = g_udev_device_get_property_as_boolean (device, "COLORD_SENSOR_EMBEDDED"); if (ret) priv->embedded = TRUE; /* add image metadata if the files exist */ for (i = 0; images[i] != NULL; i++) { tmp = g_strdup_printf ("%s/colord/icons/%s-%s.svg", DATADIR, kind_str, images[i]); if (g_file_test (tmp, G_FILE_TEST_EXISTS)) { g_debug ("helper image %s found", tmp); g_hash_table_insert (priv->metadata, g_strdup (images_md[i]), tmp); } else { g_debug ("helper image %s not found", tmp); g_free (tmp); } } /* some properties might not be valid in the GUdevDevice if the * device changes as this is only a snapshot */ priv->device = g_object_ref (device); /* success */ ret = TRUE; out: return ret; }
/** * cd_plugin_add: **/ static void cd_plugin_add (CdPlugin *plugin, GUdevDevice *udev_device) { const gchar *devclass; const gchar *seat; _cleanup_free_ gchar *id = NULL; _cleanup_free_ gchar *model = NULL; _cleanup_free_ gchar *vendor = NULL; _cleanup_object_unref_ CdDevice *device = NULL; /* is a scanner? */ if (!g_udev_device_has_property (udev_device, "libsane_matched")) return; /* skip hubs */ devclass = g_udev_device_get_sysfs_attr (udev_device, "bDeviceClass"); if (devclass == NULL || g_strcmp0 (devclass, "09") == 0) return; /* replace underscores with spaces */ model = g_strdup (g_udev_device_get_property (udev_device, "ID_MODEL")); if (model != NULL) { g_strdelimit (model, "_\r\n", ' '); g_strchomp (model); } vendor = g_strdup (g_udev_device_get_property (udev_device, "ID_VENDOR")); if (vendor != NULL) { g_strdelimit (vendor, "_\r\n", ' '); g_strchomp (vendor); } /* generate ID */ id = cd_plugin_get_scanner_id_for_udev_device (udev_device); /* assume device belongs to "seat0" if not tagged */ seat = g_udev_device_get_property (udev_device, "ID_SEAT"); if (seat == NULL) seat = "seat0"; /* create new device */ device = cd_device_new (); cd_device_set_id (device, id); cd_device_set_property_internal (device, "Kind", "scanner", FALSE, NULL); if (model != NULL) { cd_device_set_property_internal (device, "Model", model, FALSE, NULL); } if (vendor != NULL) { cd_device_set_property_internal (device, "Vendor", vendor, FALSE, NULL); } cd_device_set_property_internal (device, "Colorspace", "rgb", FALSE, NULL); cd_device_set_property_internal (device, "Serial", g_udev_device_get_sysfs_path (udev_device), FALSE, NULL); cd_device_set_property_internal (device, "Seat", seat, FALSE, NULL); /* keep track so we can remove with the same device */ g_hash_table_insert (plugin->priv->devices, g_strdup (g_udev_device_get_sysfs_path (udev_device)), g_object_ref (device)); g_debug ("CdPlugin: emit add: %s", id); cd_plugin_device_added (plugin, device); }
/** * cd_plugin_add: **/ static void cd_plugin_add (CdPlugin *plugin, GUdevDevice *udev_device) { const gchar *seat; g_autofree gchar *id = NULL; g_autofree gchar *model = NULL; g_autofree gchar *vendor = NULL; g_autoptr(CdDevice) device = NULL; /* is a proper camera and not a webcam */ if (!g_udev_device_has_property (udev_device, "ID_GPHOTO2")) return; /* is a scanner? */ if (!g_udev_device_has_property (udev_device, "COLORD_DEVICE")) return; /* replace underscores with spaces */ model = g_strdup (g_udev_device_get_property (udev_device, "ID_MODEL")); if (model != NULL) { g_strdelimit (model, "_\r\n", ' '); g_strchomp (model); } vendor = g_strdup (g_udev_device_get_property (udev_device, "ID_VENDOR")); if (vendor != NULL) { g_strdelimit (vendor, "_\r\n", ' '); g_strchomp (vendor); } /* generate ID */ id = cd_plugin_get_camera_id_for_udev_device (udev_device); /* assume device belongs to "seat0" if not tagged */ seat = g_udev_device_get_property (udev_device, "ID_SEAT"); if (seat == NULL) seat = "seat0"; /* create new device */ device = cd_device_new (); cd_device_set_id (device, id); cd_device_set_property_internal (device, CD_DEVICE_PROPERTY_KIND, cd_device_kind_to_string (CD_DEVICE_KIND_CAMERA), FALSE, NULL); if (model != NULL) { cd_device_set_property_internal (device, CD_DEVICE_PROPERTY_MODEL, model, FALSE, NULL); } if (vendor != NULL) { cd_device_set_property_internal (device, CD_DEVICE_PROPERTY_VENDOR, vendor, FALSE, NULL); } cd_device_set_property_internal (device, CD_DEVICE_PROPERTY_COLORSPACE, "rgb", FALSE, NULL); cd_device_set_property_internal (device, CD_DEVICE_PROPERTY_SERIAL, g_udev_device_get_sysfs_path (udev_device), FALSE, NULL); cd_device_set_property_internal (device, CD_DEVICE_PROPERTY_SEAT, seat, FALSE, NULL); if (cd_plugin_is_device_embedded (udev_device)) { cd_device_set_property_internal (device, CD_DEVICE_PROPERTY_EMBEDDED, NULL, FALSE, NULL); } /* keep track so we can remove with the same device */ g_hash_table_insert (plugin->priv->devices, g_strdup (g_udev_device_get_sysfs_path (udev_device)), g_object_ref (device)); g_debug ("CdPlugin: emit add: %s", id); cd_plugin_device_added (plugin, device); }
static gboolean tvm_block_device_autoipod (TvmContext *context, GMount *mount, GError **error) { gboolean autoipod; gboolean is_audio_player = FALSE; gboolean is_ipod = FALSE; gboolean result = FALSE; GFile *mount_point; gchar *autoipod_command; gchar *autophoto_command; gchar *mount_path; gchar *path_dcim = NULL; gint response = TVM_RESPONSE_NONE; g_return_val_if_fail (context != NULL, FALSE); g_return_val_if_fail (G_IS_MOUNT (mount), FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); autoipod = xfconf_channel_get_bool (context->channel, "/autoipod/enabled", FALSE); if (autoipod) { /* check if we have a portable audio player here */ is_audio_player = g_udev_device_has_property (context->device, "ID_MEDIA_PLAYER"); /* check if we have an iPod */ is_ipod = g_str_has_prefix (g_udev_device_get_property (context->device, "ID_MODEL"), "iPod"); if (is_ipod) { /* determine the mount point path */ mount_point = g_mount_get_root (mount); mount_path = g_file_get_path (mount_point); g_object_unref (mount_point); /* build dcim path */ path_dcim = g_build_filename (mount_path, "dcim", NULL); g_free (mount_path); /* check if the iPod has photos */ if (!g_file_test (path_dcim, G_FILE_TEST_IS_DIR)) { /* no photos */ g_free (path_dcim); path_dcim = NULL; } } autoipod_command = xfconf_channel_get_string (context->channel, "/autoipod/command", NULL); autophoto_command = xfconf_channel_get_string (context->channel, "/autophoto/command", NULL); /* check if autophoto command is specified, otherwise we cannot handle the photos * on the iPod anyway */ if (autophoto_command == NULL || *autophoto_command == '\0') { g_free (path_dcim); path_dcim = NULL; } /* iPods can carry music and photos... */ if (path_dcim != NULL) { /* ...so we need to prompt what to do */ response = tvm_prompt (context, "multimedia-player", _("Photos and Music"), _("Photos were found on your portable music player"), _("Would you like to import the photos or manage the " "music?"), _("Ig_nore"), GTK_RESPONSE_CANCEL, _("Import _Photos"), TVM_RESPONSE_PHOTOS, _("Manage _Music"), TVM_RESPONSE_MUSIC, NULL); } else if (is_audio_player || is_ipod) { response = TVM_RESPONSE_MUSIC; } /* check what to do */ if (response == TVM_RESPONSE_MUSIC) { /* run the preferred application to manage music players */ result = tvm_run_command (context, mount, autoipod_command, error); } else if (response == TVM_RESPONSE_PHOTOS) { /* run the preferred application to manage photos */ result = tvm_run_command (context, mount, autophoto_command, error); } else if (path_dcim != NULL) { /* when the user has decided to ignore photos/music, we don't want * to ask him again in autophoto and we don't want to mount the * device either... I guess? */ result = TRUE; } g_free (autophoto_command); g_free (autoipod_command); g_free (path_dcim); } return result; }