Beispiel #1
0
/* This is a somewhat hacky way to get FTP to almost work. The proper way to
 * get FTP to _really_ work involves hacking GIO to have APIs to handle
 * canoncial URLs.
 */
static GFile *
webkit_soup_request_file_ensure_file_ftp (SoupURI       *uri,
					  GCancellable  *cancellable,
					  GError       **error)
{
	SoupURI *host;
	char *s;
	GFile *file, *result;
	GMount *mount;

	host = soup_uri_copy_host (uri);
	s = soup_uri_to_string (host, FALSE);
	file = g_file_new_for_uri (s);
	soup_uri_free (host);
	g_free (s);

	mount = g_file_find_enclosing_mount (file, cancellable, error);
	if (mount == NULL && g_file_supports_thread_contexts (file)) {
		GMainContext *context = g_main_context_new ();
		GMainLoop *loop = g_main_loop_new (context, FALSE);

		g_clear_error (error);
		g_main_context_push_thread_default (context);
		g_file_mount_enclosing_volume (file,
					       G_MOUNT_MOUNT_NONE,
					       NULL, /* FIXME! */
					       cancellable,
					       webkit_soup_request_file_ftp_main_loop_quit,
					       loop);
		g_main_loop_run (loop);
		g_main_context_pop_thread_default (context);
		g_main_loop_unref (loop);
		g_main_context_unref (context);
		mount = g_file_find_enclosing_mount (file, cancellable, error);
	}
	if (mount == NULL)
		return NULL;
	g_object_unref (file);

	file = g_mount_get_default_location (mount);
	g_object_unref (mount);

	s = g_strdup (uri->path);
	if (strchr (s, ';'))
		*strchr (s, ';') = 0;

	result = g_file_resolve_relative_path (file, s);
	g_free (s);
	g_object_unref (file);

	return result;
}
GMount *
nautilus_get_mounted_mount_for_root (GFile *location)
{
	GVolumeMonitor *volume_monitor;
	GList *mounts;
	GList *l;
	GMount *mount;
	GMount *result = NULL;
	GFile *root = NULL;
	GFile *default_location = NULL;

	volume_monitor = g_volume_monitor_get ();
	mounts = g_volume_monitor_get_mounts (volume_monitor);

	for (l = mounts; l != NULL; l = l->next) {
		mount = l->data;

		if (g_mount_is_shadowed (mount)) {
			continue;
		}

		root = g_mount_get_root (mount);
		if (g_file_equal (location, root)) {
			result = g_object_ref (mount);
			break;
		}

		default_location = g_mount_get_default_location (mount);
		if (!g_file_equal (default_location, root) &&
		    g_file_equal (location, default_location)) {
			result = g_object_ref (mount);
			break;
		}
	}

	g_clear_object (&root);
	g_clear_object (&default_location);
	g_list_free_full (mounts, g_object_unref);

	return result;
}
Beispiel #3
0
Gio_mount::Gio_mount(GMount *src) {
  char* p_name = g_mount_get_name(src);
  name = QString::fromLocal8Bit(p_name);
  g_free(p_name);

  GFile* file = g_mount_get_root(src);
  char* p_path = g_file_get_path(file);
  if (p_path) {
    path = QString::fromLocal8Bit(p_path);
    g_free(p_path);
  }
  char* p_uri = g_file_get_uri(file);
  if (p_uri) {
    uri = QString::fromLocal8Bit(p_uri);
    g_free(p_uri);
  }
  g_object_unref(file);

  file = g_mount_get_default_location(src);
  char* p_dl = g_file_get_uri(file);
  if (p_dl) {
    default_location = QString::fromLocal8Bit(p_dl);
    g_free(p_dl);
  }
  GVolume* volume = g_mount_get_volume(src);
  if (volume) {
    g_object_unref(volume);
    default_location = path;
    uri = path;
  }
  //qDebug() << "path" << path;
  //qDebug() << "default_location" << default_location;
  //qDebug() << "uri" << uri;
  uri = Directory::canonize(uri);
  default_location = Directory::canonize(default_location);
  g_object_unref(file);
}
Beispiel #4
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);
    }
}
Beispiel #5
0
static VALUE
rg_default_location(VALUE self)
{
        return GOBJ2RVAL_UNREF(g_mount_get_default_location(_SELF(self)));
}
Beispiel #6
0
static int
dt_film_import_blocking(const char *dirname, const int blocking)
{
  int rc;
  sqlite3_stmt *stmt;

  /* intialize a film object*/
  dt_film_t *film = (dt_film_t *)malloc(sizeof(dt_film_t));
  dt_film_init(film);
  film->id = -1;

  /* lookup if film exists and reuse id */
  DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db),
                              "select id from film_rolls where folder = ?1", -1, &stmt, NULL);
  DT_DEBUG_SQLITE3_BIND_TEXT(stmt, 1, dirname, strlen(dirname),
                             SQLITE_STATIC);
  if(sqlite3_step(stmt) == SQLITE_ROW)
    film->id = sqlite3_column_int(stmt, 0);
  sqlite3_finalize(stmt);

  /* if we didnt find a id, lets instansiate a new filmroll */
  if(film->id <= 0)
  {
    char datetime[20];
    dt_gettime(datetime);
#if 0
    /* Should we use one for the whole app? */
    GVolumeMonitor *gv_monitor;
    gv_monitor = g_volume_monitor_get ();

    GList *mounts;
    mounts = g_volume_monitor_get_mounts(gv_monitor);

    gchar *mount_name = NULL;
    if (mounts != NULL)
    {
      GFile *mount_gfile;
      GMount *filmroll_mount;
      GError *error = NULL;
      gchar *filmroll_path;
      GFile *gdirname = g_file_new_for_path(dirname);

      filmroll_mount = g_file_find_enclosing_mount(gdirname, NULL, &error);
      g_object_unref(gdirname);

      if (!error)
      /* We are considering that the only error is that there is no mount
       * because the filmroll added is in a local drive */
      {
        filmroll_path = g_file_get_path((g_mount_get_default_location(filmroll_mount)));

        for (int i=0; i < g_list_length (mounts); i++)
        {
          gchar *p;

          mount_gfile = g_mount_get_default_location((GMount *)g_list_nth_data(mounts, i));
          p = g_file_get_path(mount_gfile);

          if (g_strcmp0(p, filmroll_path))
          {
            mount_name = g_mount_get_name(g_list_nth_data(mounts, i));
            break;
          }

          g_free(p);
          g_object_unref (mount_gfile);
        }

        g_free (filmroll_path);
      }

      if (filmroll_mount != NULL) g_object_unref (filmroll_mount);

      /* We haven't found the device in the list of connected devices. Let's suppose it is local */
      if (mount_name == NULL)
        mount_name = g_strdup("Local");
    }
    else
      mount_name = g_strdup("Local");
#endif
    /* insert a new film roll into database */
    DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db),
//                                "insert into film_rolls (id, datetime_accessed, folder, external_drive) values "
//                                "(null, ?1, ?2, ?3)", -1, &stmt, NULL);
                                "insert into film_rolls (id, datetime_accessed, folder) values "
                                "(null, ?1, ?2)", -1, &stmt, NULL);
    DT_DEBUG_SQLITE3_BIND_TEXT(stmt, 1, datetime, strlen(datetime),
                               SQLITE_STATIC);
    DT_DEBUG_SQLITE3_BIND_TEXT(stmt, 2, dirname, strlen(dirname),
                               SQLITE_STATIC);
//    DT_DEBUG_SQLITE3_BIND_TEXT(stmt, 3, mount_name, strlen(mount_name),
//                               SQLITE_STATIC);

    rc = sqlite3_step(stmt);
    if(rc != SQLITE_DONE)
      fprintf(stderr, "[film_import] failed to insert film roll! %s\n",
              sqlite3_errmsg(dt_database_get(darktable.db)));
    sqlite3_finalize(stmt);

//    if (mount_name != NULL) g_free (mount_name);

    /* requery for filmroll and fetch new id */
    DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db),
                                "select id from film_rolls where folder=?1", -1, &stmt, NULL);
    DT_DEBUG_SQLITE3_BIND_TEXT(stmt, 1, dirname, strlen(dirname),
                               SQLITE_STATIC);
    if(sqlite3_step(stmt) == SQLITE_ROW)
      film->id = sqlite3_column_int(stmt, 0);
    sqlite3_finalize(stmt);
  }

  /* bail out if we got troubles */
  if(film->id <= 0)
  {
    dt_film_cleanup(film);
    free(film);
    return 0;
  }

  /* at last put import film job on queue */
  dt_job_t j;
  film->last_loaded = 0;
  g_strlcpy(film->dirname, dirname, 512);
  film->dir = g_dir_open(film->dirname, 0, NULL);
  dt_film_import1_init(&j, film);
  dt_control_add_job(darktable.control, &j);

  return film->id;
}