static void
g_local_file_monitor_mounts_changed (GUnixMountMonitor *mount_monitor,
                                     gpointer           user_data)
{
  GLocalFileMonitor *local_monitor = user_data;
  GUnixMountEntry *mount;
  gboolean is_mounted;
  GFile *file;

  /* Emulate unmount detection */
  mount = g_unix_mount_at (local_monitor->source->dirname, NULL);

  is_mounted = mount != NULL;

  if (mount)
    g_unix_mount_free (mount);

  if (local_monitor->was_mounted != is_mounted)
    {
      if (local_monitor->was_mounted && !is_mounted)
        {
          file = g_file_new_for_path (local_monitor->source->dirname);
          g_file_monitor_emit_event (G_FILE_MONITOR (local_monitor), file, NULL, G_FILE_MONITOR_EVENT_UNMOUNTED);
          g_object_unref (file);
        }
      local_monitor->was_mounted = is_mounted;
    }
}
static GObject *
g_local_directory_monitor_constructor (GType                  type,
                                       guint                  n_construct_properties,
                                       GObjectConstructParam *construct_properties)
{
  GObject *obj;
  GLocalDirectoryMonitorClass *klass;
  GObjectClass *parent_class;
  GLocalDirectoryMonitor *local_monitor;
  const gchar *dirname = NULL;
  gint i;
  
  klass = G_LOCAL_DIRECTORY_MONITOR_CLASS (g_type_class_peek (G_TYPE_LOCAL_DIRECTORY_MONITOR));
  parent_class = G_OBJECT_CLASS (g_type_class_peek_parent (klass));
  obj = parent_class->constructor (type,
                                   n_construct_properties,
                                   construct_properties);

  local_monitor = G_LOCAL_DIRECTORY_MONITOR (obj);

  for (i = 0; i < n_construct_properties; i++)
    {
      if (strcmp ("dirname", g_param_spec_get_name (construct_properties[i].pspec)) == 0)
        {
          g_warn_if_fail (G_VALUE_HOLDS_STRING (construct_properties[i].value));
          dirname = g_value_get_string (construct_properties[i].value);
          break;
        }
    }

  local_monitor->dirname = g_strdup (dirname);

  if (!klass->mount_notify)
    {
#ifdef G_OS_WIN32
      /*claim everything was mounted */
      local_monitor->was_mounted = TRUE;
#else
      GUnixMountEntry *mount;
      
      /* Emulate unmount detection */
      
      mount = g_unix_mount_at (local_monitor->dirname, NULL);
      
      local_monitor->was_mounted = mount != NULL;
      
      if (mount)
        g_unix_mount_free (mount);

      local_monitor->mount_monitor = g_unix_mount_monitor_new ();
      g_signal_connect_object (local_monitor->mount_monitor, "mounts-changed",
			       G_CALLBACK (mounts_changed), local_monitor, 0);
#endif
    }

  return obj;
}
static void
ldsm_free_mount_info (gpointer data)
{
        LdsmMountInfo *mount = data;

        g_return_if_fail (mount != NULL);

        g_unix_mount_free (mount->mount);
        g_free (mount);
}
Beispiel #4
0
static GMount *
get_mount_for_mount_path (const char *mount_path,
                          GCancellable *cancellable)
{
  GUnixMountEntry *mount_entry;
  GUnixMount *mount;

  mount_entry = g_unix_mount_at (mount_path, NULL);

  if (!mount_entry)
    return NULL;

  /* TODO: Set mountable volume? */
  mount = _g_unix_mount_new (NULL, mount_entry, NULL);

  g_unix_mount_free (mount_entry);

  return G_MOUNT (mount);
}
static void
mounts_changed (GUnixMountMonitor *mount_monitor,
                gpointer           user_data)
{
  GLocalDirectoryMonitor *local_monitor = user_data;
  GUnixMountEntry *mount;
  gboolean is_mounted;
  GFile *file;
  
  /* Emulate unmount detection */
#ifdef G_OS_WIN32
  mount = NULL;
  /*claim everything was mounted */
  is_mounted = TRUE;
#else  
  mount = g_unix_mount_at (local_monitor->dirname, NULL);
  
  is_mounted = mount != NULL;
  
  if (mount)
    g_unix_mount_free (mount);
#endif

  if (local_monitor->was_mounted != is_mounted)
    {
      if (local_monitor->was_mounted && !is_mounted)
        {
          file = g_file_new_for_path (local_monitor->dirname);
          g_file_monitor_emit_event (G_FILE_MONITOR (local_monitor),
				     file, NULL,
				     G_FILE_MONITOR_EVENT_UNMOUNTED);
          g_object_unref (file);
        }
      local_monitor->was_mounted = is_mounted;
    }
}
Beispiel #6
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;
}