Example #1
0
static VALUE
rg_guess_content_type_sync(int argc, VALUE *argv, VALUE self)
{
        VALUE force_rescan, cancellable;
        GError *error = NULL;
        gchar **content_types;

        rb_scan_args(argc, argv, "02", &force_rescan, &cancellable);
        content_types = g_mount_guess_content_type_sync(_SELF(self),
                                                        RVAL2CBOOL(force_rescan),
                                                        RVAL2GCANCELLABLE(cancellable),
                                                        &error);
        if (content_types == NULL)
                rbgio_raise_error(error);

        return STRV2RVAL_FREE(content_types);
}
gboolean
rb_audiocd_is_mount_audiocd (GMount *mount)
{
	gboolean result = FALSE;
	char **types;
	guint i;
	GError *error = NULL;

	types = g_mount_guess_content_type_sync (mount, FALSE, NULL, &error);
	if (types == NULL) {
		rb_debug ("error guessing content type: %s", error->message);
		g_clear_error (&error);
	} else {
		for (i = 0; types[i] != NULL; i++) {
			if (g_str_equal (types[i], "x-content/audio-cdda") != FALSE) {
				result = TRUE;
				break;
			}
		}
		g_strfreev (types);
	}
	return result;
}
Example #3
0
static void
list_mounts (GList *mounts,
             int indent,
             gboolean only_with_no_volume)
{
  GList *l;
  int c;
  GMount *mount;
  GVolume *volume;
  char *name, *uuid, *uri;
  GFile *root, *default_location;
  GIcon *icon;
  char **x_content_types;
  char *type_name;
  const gchar *sort_key;

  for (c = 0, l = mounts; l != NULL; l = l->next, c++)
    {
      mount = (GMount *) l->data;

      if (only_with_no_volume)
        {
          volume = g_mount_get_volume (mount);
          if (volume != NULL)
            {
              g_object_unref (volume);
              continue;
            }
        }

      name = g_mount_get_name (mount);
      root = g_mount_get_root (mount);
      uri = g_file_get_uri (root);

      g_print ("%*sMount(%d): %s -> %s\n", indent, "", c, name, uri);

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

      if (extra_detail)
        {
          uuid = g_mount_get_uuid (mount);
          if (uuid)
            g_print ("%*suuid=%s\n", indent + 2, "", uuid);

          default_location = g_mount_get_default_location (mount);
          if (default_location)
            {
              char *loc_uri = g_file_get_uri (default_location);
              g_print ("%*sdefault_location=%s\n", indent + 2, "", loc_uri);
              g_free (loc_uri);
              g_object_unref (default_location);
            }

          icon = g_mount_get_icon (mount);
          if (icon)
            {
              if (G_IS_THEMED_ICON (icon))
                show_themed_icon_names (G_THEMED_ICON (icon), indent + 2);

              g_object_unref (icon);
            }

          x_content_types = g_mount_guess_content_type_sync (mount, FALSE, NULL, NULL);
          if (x_content_types != NULL && g_strv_length (x_content_types) > 0)
            {
              int n;
              g_print ("%*sx_content_types:", indent + 2, "");
              for (n = 0; x_content_types[n] != NULL; n++)
                  g_print (" %s", x_content_types[n]);
              g_print ("\n");
            }
          g_strfreev (x_content_types);

          g_print ("%*scan_unmount=%d\n", indent + 2, "", g_mount_can_unmount (mount));
          g_print ("%*scan_eject=%d\n", indent + 2, "", g_mount_can_eject (mount));
          g_print ("%*sis_shadowed=%d\n", indent + 2, "", g_mount_is_shadowed (mount));
          sort_key = g_mount_get_sort_key (mount);
          if (sort_key != NULL)
            g_print ("%*ssort_key=%s\n", indent + 2, "", sort_key);
          g_free (uuid);
        }

      g_object_unref (root);
      g_free (name);
      g_free (uri);
    }
}
Example #4
0
static gchar *
mount_guess_content_type (GMount   *mount,
                          gboolean *is_optical,
                          gboolean *is_multimedia,
                          gboolean *is_blank)
{
	gchar *content_type = NULL;
	gchar **guess_type;

	*is_optical = FALSE;
	*is_multimedia = FALSE;
	*is_blank = FALSE;

	/* This function has 2 purposes:
	 *
	 * 1. Detect if we are using optical media
	 * 2. Detect if we are video or music, we can't index those types
	 *
	 * We try to determine the content type because we don't want
	 * to store Volume information in Tracker about DVDs and media
	 * which has no real data for us to mine.
	 *
	 * Generally, if is_multimedia is TRUE then we end up ignoring
	 * the media.
	 */
	guess_type = g_mount_guess_content_type_sync (mount, TRUE, NULL, NULL);

	if (guess_type) {
		gint i = 0;

		while (!content_type && guess_type[i]) {
			if (!g_strcmp0 (guess_type[i], "x-content/image-picturecd")) {
				/* Images */
				content_type = g_strdup (guess_type[i]);
			} else if (!g_strcmp0 (guess_type[i], "x-content/video-bluray") ||
			           !g_strcmp0 (guess_type[i], "x-content/video-dvd") ||
			           !g_strcmp0 (guess_type[i], "x-content/video-hddvd") ||
			           !g_strcmp0 (guess_type[i], "x-content/video-svcd") ||
			           !g_strcmp0 (guess_type[i], "x-content/video-vcd")) {
				/* Videos */
				*is_multimedia = TRUE;
				content_type = g_strdup (guess_type[i]);
			} else if (!g_strcmp0 (guess_type[i], "x-content/audio-cdda") ||
			           !g_strcmp0 (guess_type[i], "x-content/audio-dvd") ||
			           !g_strcmp0 (guess_type[i], "x-content/audio-player")) {
				/* Audios */
				*is_multimedia = TRUE;
				content_type = g_strdup (guess_type[i]);
			} else if (!g_strcmp0 (guess_type[i], "x-content/blank-bd") ||
			           !g_strcmp0 (guess_type[i], "x-content/blank-cd") ||
			           !g_strcmp0 (guess_type[i], "x-content/blank-dvd") ||
			           !g_strcmp0 (guess_type[i], "x-content/blank-hddvd")) {
				/* Blank */
				*is_blank = TRUE;
				content_type = g_strdup (guess_type[i]);
			} else if (!g_strcmp0 (guess_type[i], "x-content/software") ||
			           !g_strcmp0 (guess_type[i], "x-content/unix-software") ||
			           !g_strcmp0 (guess_type[i], "x-content/win32-software")) {
				/* NOTE: This one is a guess, can we
				 * have this content type on
				 * none-optical mount points?
				 */
				content_type = g_strdup (guess_type[i]);
			} else {
				/* else, keep on with the next guess, if any */
				i++;
			}
		}

		/* If we didn't have an exact match on possible guessed content types,
		 *  then use the first one returned (best guess always first) if any */
		if (!content_type && guess_type[0]) {
			content_type = g_strdup (guess_type[0]);
		}

		g_strfreev (guess_type);
	}

	if (content_type) {
		if (strstr (content_type, "vcd") ||
		    strstr (content_type, "cdda") ||
		    strstr (content_type, "dvd") ||
		    strstr (content_type, "bluray")) {
			*is_optical = TRUE;
		}
	} else {
		GUnixMountEntry *entry;
		gchar *mount_path;
		GFile *mount_root;

		/* No content type was guessed, try to find out
		 * at least whether it's an optical media or not
		 */
		mount_root = g_mount_get_root (mount);
		mount_path = g_file_get_path (mount_root);

		/* FIXME: Try to assume we have a unix mount :(
		 * EEK, once in a while, I have to write crack, oh well
		 */
		if (mount_path &&
		    (entry = g_unix_mount_at (mount_path, NULL)) != NULL) {
			const gchar *filesystem_type;
			gchar *device_path = NULL;
			GVolume *volume;

			volume = g_mount_get_volume (mount);
			filesystem_type = g_unix_mount_get_fs_type (entry);
			g_debug ("  Using filesystem type:'%s'",
			         filesystem_type);

			/* Volume may be NULL */
			if (volume) {
				device_path = g_volume_get_identifier (volume, G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE);
				g_debug ("  Using device path:'%s'",
				         device_path);
				g_object_unref (volume);
			}

			/* NOTE: This code was taken from guess_mount_type()
			 * in GIO's gunixmounts.c and adapted purely for
			 * guessing optical media. We don't use the guessing
			 * code for other types such as MEMSTICKS, ZIPs,
			 * IPODs, etc.
			 *
			 * This code may need updating over time since it is
			 * very situational depending on how distributions
			 * mount their devices and how devices are named in
			 * /dev.
			 */
			if (strcmp (filesystem_type, "udf") == 0 ||
			    strcmp (filesystem_type, "iso9660") == 0 ||
			    strcmp (filesystem_type, "cd9660") == 0 ||
			    (device_path &&
			     (g_str_has_prefix (device_path, "/dev/cdrom") ||
			      g_str_has_prefix (device_path, "/dev/acd") ||
			      g_str_has_prefix (device_path, "/dev/cd")))) {
				*is_optical = TRUE;
			} else if (device_path &&
			           g_str_has_prefix (device_path, "/vol/")) {
				const gchar *name;

				name = mount_path + strlen ("/");

				if (g_str_has_prefix (name, "cdrom")) {
					*is_optical = TRUE;
				}
			} else {
				gchar *basename = g_path_get_basename (mount_path);

				if (g_str_has_prefix (basename, "cdr") ||
				    g_str_has_prefix (basename, "cdwriter") ||
				    g_str_has_prefix (basename, "burn") ||
				    g_str_has_prefix (basename, "dvdr")) {
					*is_optical = TRUE;
				}

				g_free (basename);
			}

			g_free (device_path);
			g_free (mount_path);
			g_unix_mount_free (entry);
		} else {
			g_debug ("  No GUnixMountEntry found, needed for detecting if optical media... :(");
			g_free (mount_path);
		}

		g_object_unref (mount_root);
	}

	return content_type;
}
static void
add_tile_from_mount (MpdDevicesTile *self,
                     GMount         *mount)
{
  MpdDevicesTilePrivate *priv = GET_PRIVATE (self);
  GFile         *file;
  char          *uri;
  GVolume       *volume;
  char          *name = NULL;
  char         **mime_types;
  GIcon         *icon;
  GtkIconInfo   *icon_info;
  char const    *icon_file;
  ClutterActor  *tile;
  GError        *error = NULL;

  volume = g_mount_get_volume (mount);
  if (volume) {
    name = g_volume_get_identifier (volume, G_VOLUME_IDENTIFIER_KIND_LABEL);
    g_object_unref (volume);
  }

  if (!name) {
    name = g_mount_get_name (mount);
  }

  /* Mount point */
  file = g_mount_get_root (mount);
  uri = g_file_get_uri (file);

  mime_types = g_mount_guess_content_type_sync (mount, false, NULL, &error);
  for (int i = 0; mime_types && mime_types[i]; i++)
  {
    g_debug ("%s", mime_types[i]);
  }
  if (error)
  {
    g_warning ("%s : %s", G_STRLOC, error->message);
    g_clear_error (&error);
  }

  /* Icon */
  icon = g_mount_get_icon (mount);
  icon_info = gtk_icon_theme_lookup_by_gicon (gtk_icon_theme_get_default (),
                                              icon,
                                              MPD_STORAGE_DEVICE_TILE_ICON_SIZE,
                                              GTK_ICON_LOOKUP_NO_SVG);
  icon_file = gtk_icon_info_get_filename (icon_info);
  g_debug ("%s() %s", __FUNCTION__, icon_file);

  tile = mpd_storage_device_tile_new (name,
                                      uri,
                                      mime_types ? mime_types[0] : NULL,
                                      icon_file);
  g_signal_connect (tile, "eject",
                    G_CALLBACK (_tile_eject_cb), self);
  g_signal_connect (tile, "request-hide",
                    G_CALLBACK (_device_tile_request_hide_cb), self);
  g_signal_connect (tile, "request-show",
                    G_CALLBACK (_device_tile_request_show_cb), self);
  mx_box_layout_add_actor (MX_BOX_LAYOUT (priv->vbox), tile, 0);

  g_hash_table_insert (priv->tiles, mount, tile);

  gtk_icon_info_free (icon_info);
  g_object_unref (icon);
  g_strfreev (mime_types);
  g_free (uri);
  g_object_unref (file);
}