static gboolean
ignore_drive (GDrive *drive)
{
  GIcon *icon;

  if (g_drive_can_eject (drive) == FALSE ||
      g_drive_has_media (drive) == FALSE) {
    GRL_DEBUG ("%s: Not adding %s as cannot eject or has no media", __FUNCTION__,
               g_drive_get_name (drive));
    return TRUE;
  }

  /* Hack to avoid USB devices showing up
   * https://bugzilla.gnome.org/show_bug.cgi?id=679624 */
  icon = g_drive_get_icon (drive);
  if (icon && G_IS_THEMED_ICON (icon)) {
    const gchar * const * names;
    names = g_themed_icon_get_names (G_THEMED_ICON (icon));
    if (names && names[0] && !g_str_has_prefix (names[0], "drive-optical")) {
      g_object_unref (icon);
      GRL_DEBUG ("%s: Not adding drive %s as is not optical drive", __FUNCTION__,
                 g_drive_get_name (drive));
      return TRUE;
    }
  }
  g_clear_object (&icon);

  return FALSE;
}
Esempio n. 2
0
static void
list_drives (GList *drives,
	     int indent)
{
  GList *volumes, *l;
  int c, i;
  GDrive *drive;
  char *name;
  char **ids;
  GIcon *icon;
  
  for (c = 0, l = drives; l != NULL; l = l->next, c++)
    {
      drive = (GDrive *) l->data;
      name = g_drive_get_name (drive);
      
      g_print ("%*sDrive(%d): %s\n", indent, "", c, name);
      g_free (name);
      
      if (mount_list_info)
	{
	  ids = g_drive_enumerate_identifiers (drive);
	  if (ids && ids[0] != NULL)
	    {
	      g_print ("%*sids:\n", indent+2, "");
	      for (i = 0; ids[i] != NULL; i++)
		{
		  char *id = g_drive_get_identifier (drive,
						     ids[i]);
		  g_print ("%*s %s: '%s'\n", indent+2, "", ids[i], id);
		  g_free (id);
		}
	    }
	  g_strfreev (ids);

          icon = g_drive_get_icon (drive);
          if (icon)
          {
                  if (G_IS_THEMED_ICON (icon))
                          show_themed_icon_names (G_THEMED_ICON (icon), indent + 2);
                  g_object_unref (icon);
          }

	  g_print ("%*sis_media_removable=%d\n", indent + 2, "", g_drive_is_media_removable (drive));
	  g_print ("%*shas_media=%d\n", indent + 2, "", g_drive_has_media (drive));
	  g_print ("%*sis_media_check_automatic=%d\n", indent + 2, "", g_drive_is_media_check_automatic (drive));
	  g_print ("%*scan_poll_for_media=%d\n", indent + 2, "", g_drive_can_poll_for_media (drive));
	  g_print ("%*scan_eject=%d\n", indent + 2, "", g_drive_can_eject (drive));
	}
      
      volumes = g_drive_get_volumes (drive);
      list_volumes (volumes, indent + 2, FALSE);
      g_list_foreach (volumes, (GFunc)g_object_unref, NULL);
      g_list_free (volumes);
    }
}
static gboolean _cd_find_can_eject_from_drive_name (const gchar *cName)
{
	cd_debug ("%s (%s)", __func__, cName);
	GDrive *pDrive = _cd_find_drive_from_name (cName);
	g_return_val_if_fail (pDrive != NULL, FALSE);
	
	gboolean bCanEject = g_drive_can_eject (pDrive);
	//g_object_unref (pDrive);
	return bCanEject;
}
Esempio n. 4
0
static GList *
add_drive (GList *media_list,
           GDrive *drive,
           GrlOpticalMediaSource *source)
{
  GList *volumes, *i;
  GIcon *icon;

  if (g_drive_can_eject (drive) == FALSE ||
      g_drive_has_media (drive) == FALSE) {
    return media_list;
  }

  /* Hack to avoid USB devices showing up
   * https://bugzilla.gnome.org/show_bug.cgi?id=679624 */
  icon = g_drive_get_icon (drive);
  if (icon && G_IS_THEMED_ICON (icon)) {
    const gchar * const * names;
    names = g_themed_icon_get_names (G_THEMED_ICON (icon));
    if (names && names[0] && !g_str_has_prefix (names[0], "drive-optical")) {
      g_object_unref (icon);
      return media_list;
    }
  }
  g_clear_object (&icon);

  /* Repeat for all the drive's volumes */
  volumes = g_drive_get_volumes (drive);

  for (i = volumes; i != NULL; i = i->next) {
    GVolume *volume = i->data;
    media_list = add_volume (media_list, volume, drive, source);
    g_object_unref (volume);
  }

  g_list_free (volumes);

  return media_list;
}
Esempio n. 5
0
static void
list_drives (GList *drives,
             int indent)
{
  GList *volumes, *l;
  int c, i;
  GDrive *drive;
  char *name;
  char **ids;
  GIcon *icon;
  char *type_name;
  const gchar *sort_key;

  for (c = 0, l = drives; l != NULL; l = l->next, c++)
    {
      drive = (GDrive *) l->data;
      name = g_drive_get_name (drive);

      g_print ("%*sDrive(%d): %s\n", indent, "", c, name);
      g_free (name);

      type_name = get_type_name (drive);
      g_print ("%*sType: %s\n", indent+2, "", type_name);
      g_free (type_name);

      if (extra_detail)
        {
          GEnumValue *enum_value;
          gpointer klass;

          ids = g_drive_enumerate_identifiers (drive);
          if (ids && ids[0] != NULL)
            {
              g_print ("%*sids:\n", indent+2, "");
              for (i = 0; ids[i] != NULL; i++)
                {
                  char *id = g_drive_get_identifier (drive,
                                                     ids[i]);
                  g_print ("%*s %s: '%s'\n", indent+2, "", ids[i], id);
                  g_free (id);
                }
            }
          g_strfreev (ids);

          icon = g_drive_get_icon (drive);
          if (icon)
          {
                  if (G_IS_THEMED_ICON (icon))
                          show_themed_icon_names (G_THEMED_ICON (icon), indent + 2);
                  g_object_unref (icon);
          }

          g_print ("%*sis_media_removable=%d\n", indent + 2, "", g_drive_is_media_removable (drive));
          g_print ("%*shas_media=%d\n", indent + 2, "", g_drive_has_media (drive));
          g_print ("%*sis_media_check_automatic=%d\n", indent + 2, "", g_drive_is_media_check_automatic (drive));
          g_print ("%*scan_poll_for_media=%d\n", indent + 2, "", g_drive_can_poll_for_media (drive));
          g_print ("%*scan_eject=%d\n", indent + 2, "", g_drive_can_eject (drive));
          g_print ("%*scan_start=%d\n", indent + 2, "", g_drive_can_start (drive));
          g_print ("%*scan_stop=%d\n", indent + 2, "", g_drive_can_stop (drive));

          enum_value = NULL;
          klass = g_type_class_ref (G_TYPE_DRIVE_START_STOP_TYPE);
          if (klass != NULL)
            {
              enum_value = g_enum_get_value (klass, g_drive_get_start_stop_type (drive));
              g_print ("%*sstart_stop_type=%s\n", indent + 2, "",
                       enum_value != NULL ? enum_value->value_nick : "UNKNOWN");
              g_type_class_unref (klass);
            }

          sort_key = g_drive_get_sort_key (drive);
          if (sort_key != NULL)
            g_print ("%*ssort_key=%s\n", indent + 2, "", sort_key);
        }
      volumes = g_drive_get_volumes (drive);
      list_volumes (volumes, indent + 2, FALSE);
      g_list_foreach (volumes, (GFunc)g_object_unref, NULL);
      g_list_free (volumes);
    }
}
Esempio n. 6
0
gboolean
brasero_gio_operation_eject_drive (GDrive *gdrive,
				   GCancellable *cancel,
				   gboolean wait,
				   GError **error)
{
	gboolean result;

	if (!gdrive) {
		BRASERO_MEDIA_LOG ("No GDrive");
		return FALSE;
	}

	if (!g_drive_can_eject (gdrive)) {
		BRASERO_MEDIA_LOG ("GDrive can't eject");
		return FALSE;
	}

	if (wait) {
		gulong eject_sig;
		gulong disconnect_sig;
		BraseroGioOperation *op;

		op = g_new0 (BraseroGioOperation, 1);
		op->cancel = cancel;

		eject_sig = g_signal_connect (gdrive,
					      "changed",
					      G_CALLBACK (brasero_gio_operation_ejected_cb),
					      op);

		disconnect_sig = g_signal_connect (gdrive,
						   "disconnected",
						   G_CALLBACK (brasero_gio_operation_disconnected_cb),
						   op);

		g_drive_eject_with_operation (gdrive,
			       		      G_MOUNT_UNMOUNT_NONE,
			                      NULL,
					      cancel,
			                      brasero_gio_operation_eject_finish,
			                      op);

		/* Ref gdrive as it could be unreffed 
		 * while we are in the loop */
		g_object_ref (gdrive);

		result = brasero_gio_operation_wait_for_operation_end (op, error);
		brasero_gio_operation_destroy (op);
		g_signal_handler_disconnect (gdrive, eject_sig);
		g_signal_handler_disconnect (gdrive, disconnect_sig);

		g_object_unref (gdrive);
	}
	else {
		g_drive_eject_with_operation (gdrive,
			       		      G_MOUNT_UNMOUNT_NONE,
					      NULL,
			         	      cancel,
			       		      NULL,
			       		      NULL);
		result = TRUE;
	}

	return result;
}
static void
_tile_eject_cb (MpdStorageDeviceTile  *tile,
                MpdDevicesTile        *self)
{
  MpdDevicesTilePrivate *priv = GET_PRIVATE (self);
  char const  *uri;
  GList       *mounts;
  GList       *iter;

  uri = mpd_storage_device_tile_get_mount_point (tile);

  mounts = g_volume_monitor_get_mounts (priv->monitor);
  iter = g_list_find_custom (mounts, uri, (GCompareFunc) _find_mount_cb);
  if (iter)
  {
    GMount *mount = G_MOUNT (iter->data);
    GDrive *drive;
    GVolume *vol;
    gboolean ejected = TRUE;

    drive = g_mount_get_drive (mount);
    vol = g_mount_get_volume (mount);

    if (drive && g_drive_can_eject (drive)) {
      g_debug ("%s() ejecting drive %s", __FUNCTION__, uri);
      g_drive_eject_with_operation (drive,
                                    G_MOUNT_UNMOUNT_NONE, NULL, NULL,
                                    (GAsyncReadyCallback)_drive_eject_cb,
                                    tile);
    } else if (vol && g_volume_can_eject (vol)) {
      g_debug ("%s() ejecting volume %s", __FUNCTION__, uri);
      g_volume_eject_with_operation (vol,
                                     G_MOUNT_UNMOUNT_NONE, NULL, NULL,
                                     (GAsyncReadyCallback)_vol_eject_cb,
                                     tile);
    } else if (g_mount_can_eject (mount)) {
      g_debug ("%s() ejecting mount %s", __FUNCTION__, uri);
      g_mount_eject_with_operation (mount,
                                    G_MOUNT_UNMOUNT_NONE, NULL, NULL,
                                    (GAsyncReadyCallback) _mount_eject_cb,
                                    tile);
    } else if (g_mount_can_unmount (mount)) {
      g_debug ("%s() unmounting mount %s", __FUNCTION__, uri);
      g_mount_unmount_with_operation (mount,
                                      G_MOUNT_UNMOUNT_NONE, NULL, NULL,
                                     (GAsyncReadyCallback) _mount_unmount_cb,
                                     tile);
    } else {
      ejected = FALSE;
      g_warning ("Eject or unmount not possible");
    }

    mx_widget_set_disabled (MX_WIDGET (tile), ejected);
    /* TODO: inform user of ejection with text inside the tile:
     * For that (and other reasons) this code really should be inside
     * MpdStorageDeviceTile  */

    /* TODO: we want to start a 2s timeout here, and if not done sync'ing when
     * expired show the message "Ejecting ..." */

    if (drive) {
      g_object_unref (drive);
    }
    if (vol) {
      g_object_unref (vol);
    }
  }

  g_list_foreach (mounts, (GFunc) g_object_unref, NULL);
  g_list_free (mounts);
}