Beispiel #1
0
QStringList Dir::m_entry_list()
{
    QStringList entries;

    if(m_info->isDir())
    {
        GError *err = NULL;
        GFileEnumerator *enumerator = g_file_enumerate_children(m_file, "*", G_FILE_QUERY_INFO_NONE, NULL, &err);
        if(!enumerator)
        {
            g_object_unref(enumerator);
            return entries;
        }

        for(GFileInfo *info = g_file_enumerator_next_file(enumerator, NULL, &err); !(info == 0); info = g_file_enumerator_next_file(enumerator , NULL, &err))
        {
            entries.append(QString(g_file_get_uri(m_file)) + "/" + QString(g_file_info_get_name(info)));
            g_object_unref(info);
        }
        g_file_enumerator_close(enumerator, NULL, &err);
        g_object_unref(enumerator);
    }

    return entries;
}
Beispiel #2
0
static void
_delete_trash_file (GFile *file,
                    gboolean del_file,
                    gboolean del_children)
{
    GFileInfo *info;
    GFile *child;
    GFileEnumerator *enumerator;

    if (del_children)
    {
        enumerator = g_file_enumerate_children (file,
                                                G_FILE_ATTRIBUTE_STANDARD_NAME ","
                                                G_FILE_ATTRIBUTE_STANDARD_TYPE,
                                                G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
                                                NULL, NULL);
        if (enumerator)
        {
            while ((info = g_file_enumerator_next_file (enumerator, NULL, NULL)) != NULL)
            {
                child = g_file_get_child (file, g_file_info_get_name (info));
                _delete_trash_file (child, TRUE,
                                    g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY);
                g_object_unref (child);
                g_object_unref (info);
            }
            g_file_enumerator_close (enumerator, NULL, NULL);
            g_object_unref (enumerator);
        }
    }
    if (del_file)
    {
        g_file_delete (file, NULL, NULL);
    }
}
Beispiel #3
0
static gboolean
xmms_gvfs_browse (xmms_xform_t *xform, const gchar *url, xmms_error_t *error)
{
    GError *err = NULL;
    GFile *file;
    GFileInfo *info;
    GFileEnumerator *enumerator;

    /* Same hack as in _init */
    if (!g_ascii_strncasecmp (url, "file://", 7)) {
        file = g_file_new_for_path (url+7);
    } else {
        file = g_file_new_for_uri (url);
    }
    enumerator = g_file_enumerate_children (file,
                                            G_FILE_ATTRIBUTE_STANDARD_NAME ","
                                            G_FILE_ATTRIBUTE_STANDARD_TYPE ","
                                            G_FILE_ATTRIBUTE_STANDARD_SIZE,
                                            G_FILE_QUERY_INFO_NONE,
                                            NULL,
                                            &err);

    g_object_unref (file);

    if (!enumerator) {
        xmms_error_set (error, XMMS_ERROR_GENERIC, err->message);
        return FALSE;
    }

    while ((info = g_file_enumerator_next_file (enumerator, NULL, NULL))) {
        guint32 child_type, flags = 0;
        guint64 child_size;
        const gchar *child_name;

        child_name = g_file_info_get_attribute_byte_string (info,
                     G_FILE_ATTRIBUTE_STANDARD_NAME);
        child_type = g_file_info_get_attribute_uint32 (info,
                     G_FILE_ATTRIBUTE_STANDARD_TYPE);
        child_size = g_file_info_get_attribute_uint64 (info,
                     G_FILE_ATTRIBUTE_STANDARD_SIZE);

        if (child_type & G_FILE_TYPE_DIRECTORY) {
            flags |= XMMS_XFORM_BROWSE_FLAG_DIR;
        }

        xmms_xform_browse_add_entry (xform, child_name, flags);

        if (~child_type & G_FILE_TYPE_DIRECTORY) {
            xmms_xform_browse_add_entry_property_int (xform,
                    XMMS_MEDIALIB_ENTRY_PROPERTY_SIZE,
                    child_size);
        }

        g_object_unref (info);
    }

    g_file_enumerator_close (enumerator, NULL, NULL);

    return TRUE;
}
static gboolean
xplayer_pl_parser_load_directory (GFile *file, GList **list, gboolean *unhandled)
{
	GFileEnumerator *e;
	GFileInfo *info;
	GError *err = NULL;

	*list = NULL;
	*unhandled = FALSE;

	e = g_file_enumerate_children (file,
				       G_FILE_ATTRIBUTE_STANDARD_NAME,
				       G_FILE_QUERY_INFO_NONE,
				       NULL, &err);
	if (e == NULL) {
		if (g_error_matches (err, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED) != FALSE)
			*unhandled = TRUE;
		g_error_free (err);
		return FALSE;
	}

	while ((info = g_file_enumerator_next_file (e, NULL, NULL)) != NULL)
		*list = g_list_prepend (*list, info);

	g_file_enumerator_close (e, NULL, NULL);
	g_object_unref (e);
	return TRUE;
}
Beispiel #5
0
/**
 * Call back for the g_slist_foreach function that carves one directory
 * and sub directories in a recursive way.
 * @param data is an element of opt->list ie: a gchar * that represents
 *        a directory name
 * @param user_data is the main_struct_t * pointer to the main structure.
 */
static void carve_one_directory(gpointer data, gpointer user_data)
{
    gchar *directory = (gchar *) data;
    main_struct_t *main_struct = (main_struct_t *) user_data;

    GFile *a_dir = NULL;
    GFileEnumerator *file_enum = NULL;
    GError *error = NULL;

    if (directory != NULL && main_struct != NULL)
    {
        a_dir = g_file_new_for_path(directory);
        file_enum = g_file_enumerate_children(a_dir, "*", G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, NULL, &error);

        if (error == NULL && file_enum != NULL)
        {
            iterate_over_enum(main_struct, directory, file_enum);
            g_file_enumerator_close(file_enum, NULL, NULL);
            file_enum = free_object(file_enum);
        }
        else
        {
            print_error(__FILE__, __LINE__, _("Unable to enumerate directory %s: %s\n"), directory, error->message);
            error = free_error(error);
        }

        a_dir = free_object(a_dir);
    }
}
static void
delete_batch (GObject      *source,
              GAsyncResult *res,
              gpointer      user_data)
{
        GFileEnumerator *enumerator = G_FILE_ENUMERATOR (source);
        DeleteData *data = user_data;
        GList *files, *f;
        GFile *child_file;
        DeleteData *child;
        GFileInfo *info;
        GError *error = NULL;

        files = g_file_enumerator_next_files_finish (enumerator, res, &error);

        g_debug ("GsdHousekeeping: purging %d children of %s", g_list_length (files), data->name);

        if (files) {
                for (f = files; f; f = f->next) {
                        if (g_cancellable_is_cancelled (data->cancellable))
                                break;
                        info = f->data;

                        child_file = g_file_get_child (data->file, g_file_info_get_name (info));
                        child = delete_data_new (child_file,
                                                 data->cancellable,
                                                 data->old,
                                                 data->dry_run,
                                                 data->trash,
                                                 data->depth + 1);
                        delete_recursively_by_age (child);
                        delete_data_unref (child);
                        g_object_unref (child_file);
                }
                g_list_free_full (files, g_object_unref);
                if (!g_cancellable_is_cancelled (data->cancellable)) {
                        g_file_enumerator_next_files_async (enumerator, 20,
                                                            0,
                                                            data->cancellable,
                                                            delete_batch,
                                                            data);
                        return;
                }
        }

        g_file_enumerator_close (enumerator, data->cancellable, NULL);
        g_object_unref (enumerator);

        if (data->depth > 0 && !g_cancellable_is_cancelled (data->cancellable)) {
                if ((data->trash && data->depth > 1) ||
                     should_purge_file (data->file, data->cancellable, data->old)) {
                        g_debug ("GsdHousekeeping: purging %s\n", data->name);
                        if (!data->dry_run) {
                                g_file_delete (data->file, data->cancellable, NULL);
                        }
                }
        }
        delete_data_unref (data);
}
Beispiel #7
0
void locke_appmanager_scan_for_deploys(LockeAppManager *lam, GFile *deployDir) {
	if (g_file_query_file_type(deployDir, G_FILE_QUERY_INFO_NONE, NULL)
			!= G_FILE_TYPE_DIRECTORY) {
		g_log(LSVR_DOMAIN, G_LOG_LEVEL_WARNING,
				"Hey, autodeploy dir '%s' does not exist!! Create it to be able to make deploys. ",
				g_file_get_path(deployDir));
		return;
	}
	g_log(LSVR_DOMAIN, G_LOG_LEVEL_INFO, "Scanning folder '%s' for application deployments",
			g_file_get_path(deployDir));

	/* Get file enumerator */
	GError *err = NULL;
	GFileEnumerator *files = g_file_enumerate_children(deployDir, "*",
			G_FILE_QUERY_INFO_NONE, NULL, &err);
	if (err != NULL) {
		/* Report error to user, and free error */
		g_log(LSVR_DOMAIN, G_LOG_LEVEL_ERROR, "Unable to get file list for directory '%s': %s",
				g_file_get_path(deployDir), err->message);
		g_error_free(err);
		goto scan_for_deploys_finally;
	}

	/* process each file individually */
	GFileInfo *fileInfo = NULL;
	do {
		fileInfo = g_file_enumerator_next_file(files, NULL, &err);
		if (err != NULL) {
			/* Report error to user, and free error */
			g_log(LSVR_DOMAIN, G_LOG_LEVEL_ERROR,  "Unable to get file for directory '%s': %s",
					g_file_get_path(deployDir), err->message);
			g_error_free(err);
			goto scan_for_deploys_finally;
		}
		/* stop condition */
		if (fileInfo == NULL)
			break;
		/* finally, process the file */
		g_log(LSVR_DOMAIN, G_LOG_LEVEL_INFO, " =========> Processing file '%s'",
				g_file_info_get_display_name(fileInfo));
		locke_appmanager_add_application(lam, g_file_get_path(deployDir),
				g_file_info_get_name(fileInfo));
	} while (TRUE);

	/* Close open things */
	g_file_enumerator_close(files, NULL, &err);
	if (err != NULL) {
		/* Report error to user, and free error */
		g_log(LSVR_DOMAIN, G_LOG_LEVEL_ERROR,
				"Error closing file enumerator for directory '%s': %s",
				g_file_get_path(deployDir), err->message);
		g_error_free(err);
		goto scan_for_deploys_finally;
	}
	/* Free allocated memory  */
	scan_for_deploys_finally: g_object_unref(files);
}
void clean_enumerate (gpointer data){
  FilebrowserBackend *filebackend= FILEBROWSER_BACKEND(data);
  FilebrowserBackendDetails *directory = FILEBROWSER_BACKEND_GET_PRIVATE(filebackend);
  if (directory->enumerator){
    g_file_enumerator_close(directory->enumerator,directory->cancellable,NULL);
    g_object_unref(directory->enumerator);
  }
  g_cancellable_reset (directory->cancellable);
  g_signal_emit (G_OBJECT (filebackend), signals[DONE_LOADING], 0);
}
Beispiel #9
0
static gboolean
dir_project_list_directory (DirProject *project, DirGroup* parent, GError **error) 
{
	gboolean ok;
	GFileEnumerator *enumerator;

	enumerator = g_file_enumerate_children (DIR_GROUP_DATA (parent)->base.directory,
	    G_FILE_ATTRIBUTE_STANDARD_NAME,
	    G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
	    NULL,
	    error);

	ok = enumerator != NULL;
	if (ok)
	{
		GFileInfo *info;
		
		while ((info = g_file_enumerator_next_file (enumerator, NULL, error)) != NULL)
		{
			const gchar *name;
			GFile *file;

			name = g_file_info_get_name (info);
			file = g_file_get_child (DIR_GROUP_DATA (parent)->base.directory, name);
			g_object_unref (info);

			/* Check if file is a source */
			if (!dir_pattern_stack_is_match (project->sources, file)) continue;
			
			if (g_file_query_file_type (file, G_FILE_QUERY_INFO_NONE, NULL) == G_FILE_TYPE_DIRECTORY)
			{
				/* Create a group for directory */
				DirGroup *group;
				
				group = dir_group_new (file);
				g_hash_table_insert (project->groups, g_file_get_uri (file), group);
				anjuta_project_node_append (parent, group);
				ok = dir_project_list_directory (project, group, error);
				if (!ok) break;
			}
			else
			{
				/* Create a source for files */
				DirSource *source;

				source = dir_source_new (file);
				anjuta_project_node_append (parent, source);
			}
		}
        g_file_enumerator_close (enumerator, NULL, NULL);
        g_object_unref (enumerator);
	}

	return ok;
}
Beispiel #10
0
static gboolean
find_metatests_in_directory (GFile     *directory,
                             GPtrArray *results,
                             GError   **error)
{
  GFileEnumerator *enumerator = g_file_enumerate_children (directory,
                                                           "standard::name,standard::type",
                                                           G_FILE_QUERY_INFO_NONE,
                                                           NULL, error);
  if (!enumerator)
    return FALSE;

  while (*error == NULL)
    {
      GFileInfo *info = g_file_enumerator_next_file (enumerator, NULL, error);
      if (info == NULL)
        break;

      GFile *child = g_file_enumerator_get_child (enumerator, info);
      switch (g_file_info_get_file_type (info))
        {
        case G_FILE_TYPE_REGULAR:
          {
            const char *name = g_file_info_get_name (info);
            if (g_str_has_suffix (name, ".metatest"))
              g_ptr_array_add (results, g_file_get_path (child));
            break;
          }
        case G_FILE_TYPE_DIRECTORY:
          find_metatests_in_directory (child, results, error);
          break;
        default:
          break;
        }

      g_object_unref (child);
      g_object_unref (info);
    }

  {
    GError *tmp_error = NULL;
    if (!g_file_enumerator_close (enumerator, NULL, &tmp_error))
      {
        if (*error != NULL)
          g_clear_error (&tmp_error);
        else
          g_propagate_error (error, tmp_error);
      }
  }

  g_object_unref (enumerator);
  return *error == NULL;
}
Beispiel #11
0
static void
g_file_enumerator_finalize (GObject *object)
{
  GFileEnumerator *enumerator;

  enumerator = G_FILE_ENUMERATOR (object);
  
  if (!enumerator->priv->closed)
    g_file_enumerator_close (enumerator, NULL, NULL);

  G_OBJECT_CLASS (g_file_enumerator_parent_class)->finalize (object);
}
Beispiel #12
0
static VALUE
fileenumerator_close(int argc, VALUE *argv, VALUE self)
{
        VALUE cancellable;
        GError *error = NULL;

        rb_scan_args(argc, argv, "01", &cancellable);
        if (!g_file_enumerator_close(_SELF(self), RVAL2GCANCELLABLE(cancellable), &error))
                rbgio_raise_error(error);

        return self;
}
/**
 * gtr_scan_dir:
 * @dir: the dir to parse
 * @list: the list where to store the GFiles
 * @po_name: the name of the specific po file to search or NULL.
 *
 * Scans the directory and subdirectories of @dir looking for filenames remained
 * with .po or files that matches @po_name. @list must be freed with
 * g_slist_free_full (list, g_object_unref).
 */
void
gtr_scan_dir (GFile * dir, GSList ** list, const gchar * po_name)
{
  GFileInfo *info;
  GError *error;
  GFile *file;
  GFileEnumerator *enumerator;

  error = NULL;
  enumerator = g_file_enumerate_children (dir,
                                          G_FILE_ATTRIBUTE_STANDARD_NAME,
                                          G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
                                          NULL, &error);
  if (enumerator)
    {
      error = NULL;

      while ((info =
              g_file_enumerator_next_file (enumerator, NULL, &error)) != NULL)
        {
          const gchar *name;
          gchar *filename;

          name = g_file_info_get_name (info);
          file = g_file_get_child (dir, name);

          if (po_name != NULL)
            {
              if (g_str_has_suffix (po_name, ".po"))
                filename = g_strdup (po_name);
              else
                filename = g_strconcat (po_name, ".po", NULL);
            }
          else
            filename = g_strdup (".po");

          if (g_str_has_suffix (name, filename))
            *list = g_slist_prepend (*list, file);
          g_free (filename);

          gtr_scan_dir (file, list, po_name);
          g_object_unref (info);
        }
      g_file_enumerator_close (enumerator, NULL, NULL);
      g_object_unref (enumerator);

      if (error)
        {
          g_warning ("%s", error->message);
        }
    }
}
Beispiel #14
0
void search_directory(const gchar *path, GSList **list, int n_params, const gchar **mimes)
{
        GFile *file = NULL;
        GFileInfo *next_file;
        GFileType type;
        GFileEnumerator *listing;
        const gchar *next_path;
        const gchar *file_mime;
        gchar *full_path = NULL;
        MediaInfo *media;
        guint i;

        file = g_file_new_for_path(path);
        type = g_file_query_file_type(file, G_FILE_QUERY_INFO_NONE, NULL);
        if (type == G_FILE_TYPE_DIRECTORY) {
                /* Enumerate children (needs less query flags!) */
                listing = g_file_enumerate_children(file, "standard::*", G_FILE_QUERY_INFO_NONE,
                        NULL, NULL);

                /* Lets go through them */
                while ((next_file = g_file_enumerator_next_file(listing, NULL, NULL)) != NULL) {
                        next_path = g_file_info_get_name(next_file);
                        full_path = g_strdup_printf("%s/%s", path, next_path);

                        /* Recurse if its a directory */
                        if (g_file_info_get_file_type(next_file) == G_FILE_TYPE_DIRECTORY) {
                                search_directory(full_path, list, n_params, mimes);
                        } else {
                                /* Not exactly a regex but it'll do for now */
                                file_mime = g_file_info_get_content_type(next_file);
                                for (i=0; i < n_params; i++) {
                                        if (g_str_has_prefix(file_mime, mimes[i])) {
                                                media = media_from_file(full_path, next_file, file_mime);
                                                /* Probably switch to a new struct in the future */
                                                *list = g_slist_append(*list, media);
                                        }
                                }
                        }
                        g_free(full_path);
                        g_object_unref(next_file);
                        full_path = NULL;
                }
                g_file_enumerator_close(listing, NULL, NULL);
                g_object_unref(listing);
        }

        g_object_unref(file);
}
Beispiel #15
0
static void
list (GFile *file)
{
  GFileEnumerator *enumerator;
  GFileInfo *info;
  GError *error;
  
  if (file == NULL)
    return;

  error = NULL;
  enumerator = g_file_enumerate_children (file,
                                          attributes, 
                                          nofollow_symlinks ? G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS : 0,
                                          NULL,
                                          &error);
  if (enumerator == NULL)
    {
      g_printerr ("Error: %s\n", error->message);
      g_error_free (error);
      error = NULL;
      return;
    }
  
  while ((info = g_file_enumerator_next_file (enumerator, NULL, &error)) != NULL)
    {
      show_info (info);
      
      g_object_unref (info);
    }

  if (error)
    {
      g_printerr ("Error: %s\n", error->message);
      g_error_free (error);
      error = NULL;
    }
	 
  if (!g_file_enumerator_close (enumerator, NULL, &error))
    {
      g_printerr ("Error closing enumerator: %s\n", error->message);
      g_error_free (error);
      error = NULL;
    }
}
gboolean
custom_theme_dir_is_empty (void)
{
        char            *dir;
        GFile           *file;
        gboolean         is_empty;
        GFileEnumerator *enumerator;
        GFileInfo       *info;
        GError          *error = NULL;

        dir = custom_theme_dir_path (NULL);
        file = g_file_new_for_path (dir);
        g_free (dir);

        is_empty = TRUE;

        enumerator = g_file_enumerate_children (file,
                                                G_FILE_ATTRIBUTE_STANDARD_NAME ","
                                                G_FILE_ATTRIBUTE_STANDARD_TYPE,
                                                G_FILE_QUERY_INFO_NONE,
                                                NULL, &error);
        if (enumerator == NULL) {
                g_warning ("Unable to enumerate files: %s", error->message);
                g_error_free (error);
                goto out;
        }

        while (is_empty &&
               (info = g_file_enumerator_next_file (enumerator, NULL, NULL))) {

                if (strcmp ("index.theme", g_file_info_get_name (info)) != 0) {
                        is_empty = FALSE;
                }

                g_object_unref (info);
        }
        g_file_enumerator_close (enumerator, NULL, NULL);

 out:
        g_object_unref (file);

        return is_empty;
}
static void
xfdesktop_special_file_icon_update_trash_count(XfdesktopSpecialFileIcon *special_file_icon)
{
    GFileEnumerator *enumerator;
    GFileInfo *f_info;
    gint n = 0;

    g_return_if_fail(XFDESKTOP_IS_SPECIAL_FILE_ICON(special_file_icon));

    if(special_file_icon->priv->file_info == NULL
       || special_file_icon->priv->type != XFDESKTOP_SPECIAL_FILE_ICON_TRASH)
    {
        return;
    }

    /* The trash count may return a number of files the user can't
     * currently delete, for example if the file is in a removable
     * drive that isn't mounted.
     */
    enumerator = g_file_enumerate_children(special_file_icon->priv->file,
                                           G_FILE_ATTRIBUTE_ACCESS_CAN_DELETE,
                                           G_FILE_QUERY_INFO_NONE,
                                           NULL,
                                           NULL);
    if(enumerator == NULL)
        return;

    for(f_info = g_file_enumerator_next_file(enumerator, NULL, NULL);
        f_info != NULL;
        f_info = g_file_enumerator_next_file(enumerator, NULL, NULL))
    {
          n++;
          g_object_unref(f_info);
    }

    g_file_enumerator_close(enumerator, NULL, NULL);
    g_object_unref(enumerator);

    special_file_icon->priv->trash_item_count = n;
    TRACE("exiting, trash count %d", n);
}
static void mate_wp_xml_load_from_dir (const gchar *path,
                                       AppearanceData *data) {
    GFile *directory;
    GFileEnumerator *enumerator;
    GError *error = NULL;
    GFileInfo *info;

    if (!g_file_test (path, G_FILE_TEST_IS_DIR)) {
        return;
    }

    directory = g_file_new_for_path (path);
    enumerator = g_file_enumerate_children (directory,
                                            G_FILE_ATTRIBUTE_STANDARD_NAME,
                                            G_FILE_QUERY_INFO_NONE,
                                            NULL,
                                            &error);
    if (error != NULL) {
        g_warning ("Unable to check directory %s: %s", path, error->message);
        g_error_free (error);
        g_object_unref (directory);
        return;
    }

    while ((info = g_file_enumerator_next_file (enumerator, NULL, NULL))) {
        const gchar *filename;
        gchar *fullpath;

        filename = g_file_info_get_name (info);
        fullpath = g_build_filename (path, filename, NULL);
        g_object_unref (info);

        mate_wp_xml_load_xml (data, fullpath);
        g_free (fullpath);
    }
    g_file_enumerator_close (enumerator, NULL, NULL);

    mate_wp_xml_add_monitor (directory, data);

    g_object_unref (directory);
}
Beispiel #19
0
static void
gnac_profiles_mgr_import_default_profiles(void)
{
  gnac_profiles_mgr_clear();

  GFileEnumerator *files = gnac_profiles_mgr_get_default_profiles_enumerator();

  GFile *profile_file = g_file_enumerator_get_container(files);
  gchar *profile_file_path = g_file_get_path(profile_file);

  GFileInfo *file_info;
  while ((file_info = g_file_enumerator_next_file(files, NULL, NULL))) {
    if (g_file_info_get_file_type(file_info) == G_FILE_TYPE_REGULAR) {
      GError *error = NULL;
      const gchar *profile_file_name = g_file_info_get_name(file_info);
      gchar *profile_file_full_path = g_build_filename(profile_file_path,
          profile_file_name, NULL);
      gpointer profile = gnac_profiles_properties_load_profile_from_file(
          profile_file_full_path, profile_file_name, &error);

      if (profile) {
        gnac_profiles_properties_save_profile(profile);
      } else if (error) {
        libgnac_warning("%s", error->message);
        g_clear_error(&error);
      }

      g_free(profile_file_full_path);
      gnac_profiles_properties_free_audio_profile(profile);
    }

    g_object_unref(file_info);
  }

  g_free(profile_file_path);
  g_file_enumerator_close(files, NULL, NULL);
  g_object_unref(files);
}
static gboolean
webkit_soup_directory_input_stream_close (GInputStream  *input,
					  GCancellable  *cancellable,
					  GError       **error)
{
	WebKitSoupDirectoryInputStream *stream = WEBKIT_SOUP_DIRECTORY_INPUT_STREAM (input);
	gboolean result;

	if (stream->buffer) {
		soup_buffer_free (stream->buffer);
		stream->buffer = NULL;
	}

	result = g_file_enumerator_close (stream->enumerator,
					  cancellable,
					  error);
	g_object_unref (stream->enumerator);
	stream->enumerator = NULL;

	g_free (stream->uri);
	stream->uri = NULL;

	return result;
}
static gboolean
directory_delete_recursive (GFile *directory, GError **error)
{
        GFileEnumerator *enumerator;
        GFileInfo *info;
        gboolean success = TRUE;

        enumerator = g_file_enumerate_children (directory,
                                                G_FILE_ATTRIBUTE_STANDARD_NAME ","
                                                G_FILE_ATTRIBUTE_STANDARD_TYPE,
                                                G_FILE_QUERY_INFO_NONE,
                                                NULL, error);
        if (enumerator == NULL)
                return FALSE;

        while (success &&
               (info = g_file_enumerator_next_file (enumerator, NULL, NULL))) {
                GFile *child;

                child = g_file_get_child (directory, g_file_info_get_name (info));

                if (g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY) {
                        success = directory_delete_recursive (child, error);
                }
                g_object_unref (info);

                if (success)
                        success = g_file_delete (child, NULL, error);
        }
        g_file_enumerator_close (enumerator, NULL, NULL);

        if (success)
                success = g_file_delete (directory, NULL, error);

        return success;
}
Beispiel #22
0
int
ddb_gvfs_scandir (const char *dir, struct dirent ***namelist, int (*selector) (const struct dirent *), int (*cmp) (const struct dirent **, const struct dirent **))
{
  GQueue *file_list = g_queue_new ();
  GQueue *dir_list = g_queue_new ();
  g_queue_push_head (dir_list, g_file_new_for_uri (dir));

  GFile *gdir;
  while ((gdir = g_queue_pop_head (dir_list)) != NULL)
    {
      GFileEnumerator *file_enumerator = g_file_enumerate_children (gdir, G_FILE_ATTRIBUTE_STANDARD_NAME, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, NULL, NULL);
      if (file_enumerator == NULL)
        {
          g_object_unref (gdir);
          continue;
        }

      GFileInfo *file_info;
      GFile *child_file;

     while ((file_info = g_file_enumerator_next_file (file_enumerator, NULL, NULL)) != NULL)
        {
          child_file = g_file_get_child (gdir, g_file_info_get_name (file_info));
          g_object_unref (file_info);

          if (g_file_query_file_type (child_file, G_FILE_QUERY_INFO_NONE, NULL) == G_FILE_TYPE_DIRECTORY)
            g_queue_push_head (dir_list, child_file);
          else
            {
              g_queue_push_tail (file_list, g_file_get_uri (child_file));
              g_object_unref (child_file);
            }
        }

      g_file_enumerator_close (file_enumerator, NULL, NULL);
      g_object_unref (file_enumerator);

      g_object_unref (gdir);
    }

  g_queue_free (dir_list);

  int num_files = 0;
  *namelist = malloc (sizeof(void *) * g_queue_get_length (file_list));

  char *fname;
  while ((fname = g_queue_pop_head (file_list)) != NULL)
    {
      struct dirent entry;
      strncpy (entry.d_name, fname, sizeof(entry.d_name) - 1);
      entry.d_name[sizeof(entry.d_name) - 1] = '\0';

      if (selector == NULL || (selector && selector(&entry)))
        {
          (*namelist)[num_files] = calloc (1, sizeof (struct dirent));
          strcpy ((*namelist)[num_files]->d_name, entry.d_name);
          num_files++;
        }

      g_free (fname);
    }

  g_queue_free (file_list);
  return num_files;
}
static gboolean fm_dir_list_job_run_gio(FmDirListJob* job)
{
    GFileEnumerator *enu;
    GFileInfo *inf;
    FmFileInfo* fi;
    GError *err = NULL;
    FmJob* fmjob = FM_JOB(job);
    GFile* gf;
    const char* query;

    gf = fm_path_to_gfile(job->dir_path);
_retry:
    inf = g_file_query_info(gf, gfile_info_query_attribs, 0, fm_job_get_cancellable(fmjob), &err);
    if(!inf )
    {
        FmJobErrorAction act = fm_job_emit_error(fmjob, err, FM_JOB_ERROR_MODERATE);
        g_error_free(err);
        if( act == FM_JOB_RETRY )
        {
            err = NULL;
            goto _retry;
        }
        else
        {
            g_object_unref(gf);
            return FALSE;
        }
    }

    if( g_file_info_get_file_type(inf) != G_FILE_TYPE_DIRECTORY)
    {
        char *path_str = fm_path_to_str(job->dir_path);
        err = g_error_new(G_IO_ERROR, G_IO_ERROR_NOT_DIRECTORY,
                          _("The specified directory '%s' is not valid"),
                          path_str);
        fm_job_emit_error(fmjob, err, FM_JOB_ERROR_CRITICAL);
        g_free(path_str);
        g_error_free(err);
        g_object_unref(gf);
        g_object_unref(inf);
        return FALSE;
    }

    /* check if FS is R/O and set attr. into inf */
    _fm_file_info_job_update_fs_readonly(gf, inf, NULL, NULL);

    job->dir_fi = fm_file_info_new_from_g_file_data(gf, inf, job->dir_path);
    g_object_unref(inf);

    if(G_UNLIKELY(job->flags & FM_DIR_LIST_JOB_DIR_ONLY))
    {
        query = G_FILE_ATTRIBUTE_STANDARD_TYPE","G_FILE_ATTRIBUTE_STANDARD_NAME","
                G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN","G_FILE_ATTRIBUTE_STANDARD_IS_BACKUP","
                G_FILE_ATTRIBUTE_STANDARD_IS_SYMLINK","G_FILE_ATTRIBUTE_STANDARD_IS_VIRTUAL","
                G_FILE_ATTRIBUTE_STANDARD_EDIT_NAME","
                G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME","G_FILE_ATTRIBUTE_STANDARD_ICON","
                G_FILE_ATTRIBUTE_STANDARD_SIZE","G_FILE_ATTRIBUTE_STANDARD_TARGET_URI","
                "unix::*,time::*,access::*,id::filesystem";
    }
    else
        query = gfile_info_query_attribs;

    enu = g_file_enumerate_children (gf, query, 0, fm_job_get_cancellable(fmjob), &err);
    g_object_unref(gf);
    if(enu)
    {
        while( ! fm_job_is_cancelled(fmjob) )
        {
            inf = g_file_enumerator_next_file(enu, fm_job_get_cancellable(fmjob), &err);
            if(inf)
            {
                FmPath *dir, *sub;
                GFile *child;
                if(G_UNLIKELY(job->flags & FM_DIR_LIST_JOB_DIR_ONLY))
                {
                    /* FIXME: handle symlinks */
                    if(g_file_info_get_file_type(inf) != G_FILE_TYPE_DIRECTORY)
                    {
                        g_object_unref(inf);
                        continue;
                    }
                }

                /* virtual folders may return children not within them */
                dir = fm_path_new_for_gfile(g_file_enumerator_get_container(enu));
                if (fm_path_equal(job->dir_path, dir))
                    sub = fm_path_new_child(job->dir_path, g_file_info_get_name(inf));
                else
                    sub = fm_path_new_child(dir, g_file_info_get_name(inf));
                child = g_file_get_child(g_file_enumerator_get_container(enu),
                                         g_file_info_get_name(inf));
                if (g_file_info_get_file_type(inf) == G_FILE_TYPE_DIRECTORY)
                    /* for dir: check if its FS is R/O and set attr. into inf */
                    _fm_file_info_job_update_fs_readonly(child, inf, NULL, NULL);
                fi = fm_file_info_new_from_g_file_data(child, inf, sub);
                fm_path_unref(sub);
                fm_path_unref(dir);
                g_object_unref(child);
                fm_dir_list_job_add_found_file(job, fi);
                fm_file_info_unref(fi);
            }
            else
            {
                if(err)
                {
                    FmJobErrorAction act = fm_job_emit_error(fmjob, err, FM_JOB_ERROR_MILD);
                    g_error_free(err);
                    /* FM_JOB_RETRY is not supported. */
                    if(act == FM_JOB_ABORT)
                        fm_job_cancel(fmjob);
                }
                /* otherwise it's EOL */
                break;
            }
            g_object_unref(inf);
        }
        g_file_enumerator_close(enu, NULL, &err);
        g_object_unref(enu);
    }
    else
    {
        fm_job_emit_error(fmjob, err, FM_JOB_ERROR_CRITICAL);
        g_error_free(err);
        return FALSE;
    }
    return TRUE;
}
static gboolean
migrate_rpm_and_yumdb (GFile          *targetroot,
                       GFile          *yumroot,
                       GCancellable   *cancellable,
                       GError        **error)

{
  gboolean ret = FALSE;
  gs_unref_object GFile *usrbin_rpm =
    g_file_resolve_relative_path (targetroot, "usr/bin/rpm");
  gs_unref_object GFile *legacyrpm_path =
    g_file_resolve_relative_path (yumroot, "var/lib/rpm");
  gs_unref_object GFile *newrpm_path =
    g_file_resolve_relative_path (targetroot, "usr/share/rpm");
  gs_unref_object GFile *src_yum_rpmdb_indexes =
    g_file_resolve_relative_path (yumroot, "var/lib/yum");
  gs_unref_object GFile *target_yum_rpmdb_indexes =
    g_file_resolve_relative_path (targetroot, "usr/share/yumdb");
  gs_unref_object GFile *yumroot_yumlib =
    g_file_get_child (yumroot, "var/lib/yum");
  gs_unref_object GFileEnumerator *direnum = NULL;

  direnum = g_file_enumerate_children (legacyrpm_path, "standard::name",
                                       G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
                                       cancellable, error);
  if (!direnum)
    goto out;

  while (TRUE)
    {
      const char *name;
      GFileInfo *file_info;
      GFile *child;

      if (!gs_file_enumerator_iterate (direnum, &file_info, &child,
                                       cancellable, error))
        goto out;
      if (!file_info)
        break;

      name = g_file_info_get_name (file_info);

      if (g_str_has_prefix (name, "__db.") ||
          strcmp (name, ".dbenv.lock") == 0 ||
          strcmp (name, ".rpm.lock") == 0)
        {
          if (!gs_file_unlink (child, cancellable, error))
            goto out;
        }
    }

  (void) g_file_enumerator_close (direnum, cancellable, error);
    
  g_print ("Placing RPM db in /usr/share/rpm\n");
  if (!gs_file_rename (legacyrpm_path, newrpm_path, cancellable, error))
    goto out;
    
  /* Move the yum database to usr/share/yumdb; disabled for now due
   * to bad conflict with OSTree's current
   * one-http-request-per-file.
   */
#if 0
  if (g_file_query_exists (src_yum_rpmdb_indexes, NULL))
    {
      g_print ("Moving %s to %s\n", gs_file_get_path_cached (src_yum_rpmdb_indexes),
               gs_file_get_path_cached (target_yum_rpmdb_indexes));
      if (!gs_file_rename (src_yum_rpmdb_indexes, target_yum_rpmdb_indexes,
                           cancellable, error))
        goto out;
        
      if (!clean_yumdb_extraneous_files (target_yum_rpmdb_indexes, cancellable, error))
        goto out;
    }
#endif

  /* Remove /var/lib/yum; we don't want it here. */
  if (!gs_shutil_rm_rf (yumroot_yumlib, cancellable, error))
    goto out;

  ret = TRUE;
 out:
  return ret;
}
/**
 * cong_dispspec_registry_add_dir:
 * @registry:
 * @xds_directory:
 * @toplevel_window:
 * @raise_errs:
 *
 * TODO: Write me
 */
void
cong_dispspec_registry_add_dir(CongDispspecRegistry *registry, const gchar *xds_directory, GtkWindow *toplevel_window, gboolean raise_errs)
{
	gboolean result;
	GFile *xds_dir;
	GFileEnumerator *directory;
	GFileInfo *info;
	GError *error = NULL;

	xds_dir = g_file_new_for_path(xds_directory);

	/* Scan the directory for xds files: */

	directory = g_file_enumerate_children(xds_dir,
	                                      G_FILE_ATTRIBUTE_STANDARD_NAME,
	                                      G_FILE_QUERY_INFO_NONE,
	                                      NULL,
	                                      &error);

	if(!directory) {
		if(raise_errs) {
			GtkDialog* dialog = cong_error_dialog_new_from_file_operation_failure(toplevel_window,
			                                                                      _("Conglomerate could not read its registry of document types."),
			                                                                      xds_dir,
			                                                                      error,
			                                                                      _("Conglomerate attempted to look at all the files in the location."));
			cong_error_dialog_run(GTK_DIALOG(dialog));
			gtk_widget_destroy(GTK_WIDGET(dialog));
		}

		g_object_unref(xds_dir);
		return;
	}

	while((info = g_file_enumerator_next_file(directory, NULL, &error)) != NULL) {
		const char *rel_path = g_file_info_get_name(info);
		/* FIXME: Ultimately we should do a MIME-lookup */
		/* Search for strings that are terminated with ".xds" */
		if (g_str_has_suffix(rel_path, ".xds")) {
			/* This looks like an xds file: */
			/* get at name */
			GFile *file = g_file_get_child(xds_dir, rel_path);
			char *filename = g_file_get_path(file);
			CongDispspec* ds;
			gboolean result;

			result = cong_dispspec_new_from_xds_file(file, &ds, &error);
			if (result == TRUE) {
				if (ds!=NULL) {
					cong_dispspec_registry_add(registry, ds);
				} else {
					g_warning("Problem parsing xds file: %s.\n", filename);
				}
			} else {
				g_warning("Problem loading xds file: %s.\n",filename);
			}

			g_free(filename);
			g_object_unref(file);
		}
		g_object_unref(info);
	}

	if(raise_errs && error) {
		GtkDialog* dialog = cong_error_dialog_new_from_file_operation_failure(toplevel_window,
		                                                                      _("Conglomerate failed while reading its registry of document types."),
		                                                                      xds_dir,
		                                                                      error,
		                                                                      _("Conglomerate attempted to look at all the files in the location."));
		cong_error_dialog_run(GTK_DIALOG(dialog));
		gtk_widget_destroy(GTK_WIDGET(dialog));
	}

	result = g_file_enumerator_close(directory, NULL, &error);
	if(!result) {
		g_warning("Error closing directory '%s': %s", xds_directory, error->message);
		g_error_free(error);
	}

	g_object_unref(directory);
	g_object_unref(xds_dir);
}	
Beispiel #26
0
void
on_extensions_view_drag_data_received(GtkWidget *widget, GdkDragContext *drag_context, gint x, gint y, GtkSelectionData *selectiondata, guint info, guint time)
{
	GFile *file;
	GFileInfo *file_info;
	gchar *type_name = NULL;

	/* Check that we got data from source */
	if(selectiondata == NULL || gtk_selection_data_get_length(selectiondata) < 0)
		goto fail;

	/* Check that we got the format we can use */
	type_name = gdk_atom_name(gtk_selection_data_get_data_type(selectiondata));
	if(strcmp(type_name, "text/uri-list") != 0)
		goto fail;

	/* Do stuff with the data */
	char **extension_files = g_uri_list_extract_uris((char *)gtk_selection_data_get_data(selectiondata));
	int foo;
	/* Get a list of URIs to the dropped files */
	for(foo = 0; extension_files[foo] != NULL; foo++) {
		GError *err = NULL;
		file = g_file_new_for_uri(extension_files[foo]);
		file_info = g_file_query_info(file, G_FILE_ATTRIBUTE_STANDARD_TYPE, G_FILE_QUERY_INFO_NONE, NULL, &err);
		if(!file_info) {
			IO_ERROR_DIALOG(NULL, file, err, _("accessing a URI"));
			goto fail2;
		}

		/* Check whether a directory was dropped. if so, install contents */
		/* NOTE: not recursive (that would be kind of silly anyway) */
		if(g_file_info_get_file_type(file_info) == G_FILE_TYPE_DIRECTORY) {

			GFileEnumerator *dir = g_file_enumerate_children(file, "standard::*", G_FILE_QUERY_INFO_NONE, NULL, &err);
			if(!dir) {
				IO_ERROR_DIALOG(NULL, file, err, _("opening a directory"));
				goto fail3;
			}

			GFileInfo *entry_info;
			while((entry_info = g_file_enumerator_next_file(dir, NULL, &err)) != NULL) {
				if(g_file_info_get_file_type(entry_info) != G_FILE_TYPE_DIRECTORY) {
					GFile *extension_file = g_file_get_child(file, g_file_info_get_name(entry_info));
					i7_app_install_extension(i7_app_get(), extension_file);
					g_object_unref(extension_file);
				}
				g_object_unref(entry_info);
			}
			g_file_enumerator_close(dir, NULL, &err);
			g_object_unref(dir);

			if(err) {
				IO_ERROR_DIALOG(NULL, file, err, _("reading a directory"));
				goto fail3;
			}

		} else {
			/* just install it */
			i7_app_install_extension(i7_app_get(), file);
		}

		g_object_unref(file_info);
		g_object_unref(file);
	}

	g_strfreev(extension_files);
	g_free(type_name);
	gtk_drag_finish(drag_context, TRUE, FALSE, time);
	return;

fail3:
	g_object_unref(file_info);
fail2:
	g_object_unref(file);
	g_strfreev(extension_files);
fail:
	g_free(type_name);
	gtk_drag_finish(drag_context, FALSE, FALSE, time);
}
static gboolean
migrate_rpm_and_yumdb (GFile          *targetroot,
                       GFile          *yumroot,
                       GCancellable   *cancellable,
                       GError        **error)

{
    gboolean ret = FALSE;
    gs_unref_object GFile *usrbin_rpm =
        g_file_resolve_relative_path (targetroot, "usr/bin/rpm");
    gs_unref_object GFile *legacyrpm_path =
        g_file_resolve_relative_path (yumroot, "var/lib/rpm");
    gs_unref_object GFile *newrpm_path =
        g_file_resolve_relative_path (targetroot, "usr/share/rpm");
    gs_unref_object GFile *src_yum_rpmdb_indexes =
        g_file_resolve_relative_path (yumroot, "var/lib/yum");
    gs_unref_object GFile *target_yum_rpmdb_indexes =
        g_file_resolve_relative_path (targetroot, "usr/share/yumdb");
    gs_unref_object GFile *yumroot_yumlib =
        g_file_get_child (yumroot, "var/lib/yum");
    gs_unref_object GFileEnumerator *direnum = NULL;

    direnum = g_file_enumerate_children (legacyrpm_path, "standard::name",
                                         G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
                                         cancellable, error);
    if (!direnum)
        goto out;

    while (TRUE)
    {
        const char *name;
        GFileInfo *file_info;
        GFile *child;

        if (!gs_file_enumerator_iterate (direnum, &file_info, &child,
                                         cancellable, error))
            goto out;
        if (!file_info)
            break;

        name = g_file_info_get_name (file_info);

        if (g_str_has_prefix (name, "__db.") ||
                strcmp (name, ".dbenv.lock") == 0 ||
                strcmp (name, ".rpm.lock") == 0)
        {
            if (!gs_file_unlink (child, cancellable, error))
                goto out;
        }
    }

    (void) g_file_enumerator_close (direnum, cancellable, error);

    g_print ("Placing RPM db in /usr/share/rpm\n");
    if (!gs_file_rename (legacyrpm_path, newrpm_path, cancellable, error))
        goto out;

    /* Remove /var/lib/yum; we don't want it here. */
    if (!gs_shutil_rm_rf (yumroot_yumlib, cancellable, error))
        goto out;

    ret = TRUE;
out:
    return ret;
}
Beispiel #28
0
static void
do_tree (GFile *f, int level, guint64 pattern)
{
  GFileEnumerator *enumerator;
  GError *error = NULL;
  unsigned int n;
  GFileInfo *info;

  info = g_file_query_info (f,
			    G_FILE_ATTRIBUTE_STANDARD_TYPE ","
			    G_FILE_ATTRIBUTE_STANDARD_TARGET_URI,
			    0,
			    NULL, NULL);
  if (info != NULL)
    {
      if (g_file_info_get_attribute_uint32 (info, G_FILE_ATTRIBUTE_STANDARD_TYPE) == G_FILE_TYPE_MOUNTABLE)
	{
	  /* don't process mountables; we avoid these by getting the target_uri below */
	  g_object_unref (info);
	  return;
	}
      g_object_unref (info);
    }

  enumerator = g_file_enumerate_children (f,
					  G_FILE_ATTRIBUTE_STANDARD_NAME ","
					  G_FILE_ATTRIBUTE_STANDARD_TYPE ","
					  G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN ","
					  G_FILE_ATTRIBUTE_STANDARD_IS_SYMLINK ","
					  G_FILE_ATTRIBUTE_STANDARD_SYMLINK_TARGET ","
					  G_FILE_ATTRIBUTE_STANDARD_TARGET_URI,
					  0,
					  NULL,
					  &error);
  if (enumerator != NULL)
    {
      GList *l;
      GList *info_list;

      info_list = NULL;
      while ((info = g_file_enumerator_next_file (enumerator, NULL, NULL)) != NULL)
	{
	  if (g_file_info_get_is_hidden (info) && !show_hidden)
	    {
	      g_object_unref (info);
	    }
	  else
	    {
	      info_list = g_list_prepend (info_list, info);
	    }
	}
      g_file_enumerator_close (enumerator, NULL, NULL);

      info_list = g_list_sort (info_list, (GCompareFunc) sort_info_by_name);

      for (l = info_list; l != NULL; l = l->next)
	{
	  const char *name;
	  const char *target_uri;
	  GFileType type;
	  gboolean is_last_item;

	  info = l->data;
	  is_last_item = (l->next == NULL);

	  name = g_file_info_get_name (info);
	  type = g_file_info_get_attribute_uint32 (info, G_FILE_ATTRIBUTE_STANDARD_TYPE);
	  if (name != NULL)
	    {

	      for (n = 0; n < level; n++)
		{
		  if (pattern & (1<<n))
		    {
		      g_print ("|   ");
		    }
		  else
		    {
		      g_print ("    ");
		    }
		}

	      if (is_last_item)
		{
		  g_print ("`-- %s", name);
		}
	      else
		{
		  g_print ("|-- %s", name);
		}

	      target_uri = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_STANDARD_TARGET_URI);
	      if (target_uri != NULL)
		{
		  g_print (" -> %s", target_uri);
		}
	      else
		{
		  if (g_file_info_get_is_symlink (info))
		    {
		      const char *target;
		      target = g_file_info_get_symlink_target (info);
		      g_print (" -> %s", target);
		    }
		}

	      g_print ("\n");

	      if ((type & G_FILE_TYPE_DIRECTORY) &&
		  (follow_symlinks || !g_file_info_get_is_symlink (info)))
		{
		  guint64 new_pattern;
		  GFile *child;

		  if (is_last_item)
		    new_pattern = pattern;
		  else
		    new_pattern = pattern | (1<<level);

		  child = NULL;
		  if (target_uri != NULL)
		    {
		      if (follow_symlinks)
			child = g_file_new_for_uri (target_uri);
		    }
		  else
		    {
		      child = g_file_get_child (f, name);
		    }

		  if (child != NULL)
		    {
		      do_tree (child, level + 1, new_pattern);
		      g_object_unref (child);
		    }
		}
	    }
	  g_object_unref (info);
	}
      g_list_free (info_list);
    }
  else
    {
      for (n = 0; n < level; n++)
	{
	  if (pattern & (1<<n))
	    {
	      g_print ("|   ");
	    }
	  else
	    {
	      g_print ("    ");
	    }
	}

      g_print ("    [%s]\n", error->message);

      g_error_free (error);
    }
}
Beispiel #29
0
void
gnac_profiles_mgr_list_profiles(void)
{
  GFile *dir = gnac_profiles_mgr_get_profiles_dir();

  GError *error = NULL;
  GFileEnumerator *files = g_file_enumerate_children(dir,
      G_FILE_ATTRIBUTE_STANDARD_NAME ","
      G_FILE_ATTRIBUTE_STANDARD_TYPE,
      G_FILE_QUERY_INFO_NONE, NULL, &error);

  if (!files && error) {
    g_clear_error(&error);
    /* no profiles found, try to import the default ones */
    gnac_profiles_mgr_import_default_profiles();
    files = g_file_enumerate_children(dir,
        G_FILE_ATTRIBUTE_STANDARD_NAME ","
        G_FILE_ATTRIBUTE_STANDARD_TYPE,
        G_FILE_QUERY_INFO_NONE, NULL, &error);
    if (!files && error) {
      g_printerr(_("No profiles available"));
      libgnac_warning("%s", error->message);
      g_clear_error(&error);
      return;
    }
  }

  g_print(_("Available audio profiles:"));
  g_print("\n\n");

  gchar *last_used_profile = gnac_settings_get_string(
      GNAC_KEY_LAST_USED_PROFILE);

  GFile *profile_file = g_file_enumerator_get_container(files);
  gchar *profile_file_path = g_file_get_path(profile_file);

  GFileInfo *file_info;
  GSList *profiles = NULL;

  while ((file_info = g_file_enumerator_next_file(files, NULL, NULL))) {
    if (g_file_info_get_file_type(file_info) == G_FILE_TYPE_REGULAR) {
      AudioProfileGeneric *profile;
      const gchar *profile_file_name = g_file_info_get_name(file_info);
      gchar *profile_file_full_path = g_build_filename(profile_file_path,
          profile_file_name, NULL);
      gnac_profiles_default_load_generic_audio_profile(profile_file_full_path,
          &profile);
      if (profile) {
        gpointer name = (profile->generic)->name;
        profiles = g_slist_prepend(profiles, name);
      }

      g_free(profile_file_full_path);
    }

    g_object_unref(file_info);
  }

  g_free(profile_file_path);

  profiles = g_slist_reverse(profiles);

  guint count = g_slist_length(profiles);
  if (count == 0) {
    g_print("\t");
    g_print(_("No profiles available"));
    g_print("\n");
  } else {
    /* check if last_used_profile exists */
    if (!g_slist_find_custom(profiles, last_used_profile,
        (GCompareFunc) g_strcmp0))
    {
      last_used_profile = NULL;
    }

    GSList *tmp;
    for (tmp = profiles; tmp; tmp = g_slist_next(tmp)) {
      gint pos = g_slist_position(profiles, tmp);
      gchar *count_str = g_strdup_printf("%u", pos+1);
      /* if last_used_profile is not set, assume the
       * first profile was last used */
      gchar *name = tmp->data;
      gboolean found = ((pos == 0 && !last_used_profile)
          || gnac_utils_str_equal(name, last_used_profile));
      g_print("\t%2s) %s\n", found ? "*" : count_str, name);
      g_free(count_str);
    }
  }

  g_print("\n");

  g_slist_free(profiles);
  g_free(last_used_profile);
  g_object_unref(dir);
  g_file_enumerator_close(files, NULL, NULL);
  g_object_unref(files);
}
Beispiel #30
0
static void
gnac_profiles_mgr_populate(void)
{ 
  gnac_profiles_mgr_clear();

  GError *error = NULL;

  GFile *dir = g_file_new_for_path(saved_profiles_dir);
  if (!g_file_query_exists(dir, NULL)) {
    if (!g_file_make_directory_with_parents(dir, NULL, &error)) {
      const gchar *msg = N_("Unable to create the profiles directory");
      libgnac_warning("%s %s: %s",
          msg, _("You may not be able to save your profiles"), error->message);
      gnac_profiles_mgr_display_status_message(NULL, msg);
      g_clear_error(&error);
      return;
    } else {
      gnac_profiles_mgr_import_default_profiles();
    }
  }

  GFileEnumerator *files = g_file_enumerate_children(dir,
      G_FILE_ATTRIBUTE_STANDARD_NAME ","
      G_FILE_ATTRIBUTE_STANDARD_TYPE,
      G_FILE_QUERY_INFO_NONE, NULL, &error);
  if (!files && error) {
    const gchar *msg = N_("Unable to browse the profiles directory");
    libgnac_warning("%s: %s", msg, error->message);
    gnac_profiles_mgr_display_status_message(NULL, msg);
    g_clear_error(&error);
    return;
  }

  GFileInfo *file_info = g_file_enumerator_next_file(files, NULL, NULL);
  if (!file_info) {
    gnac_profiles_mgr_import_default_profiles();
    g_file_enumerator_close(files, NULL, NULL);
    files = g_file_enumerate_children(dir,
        G_FILE_ATTRIBUTE_STANDARD_NAME ","
        G_FILE_ATTRIBUTE_STANDARD_TYPE,
        G_FILE_QUERY_INFO_NONE, NULL, &error);
    file_info = g_file_enumerator_next_file(files, NULL, NULL);
  }

  GFile *profile_file = g_file_enumerator_get_container(files);
  gchar *profile_file_path = g_file_get_path(profile_file);

  while (file_info) {
    if (g_file_info_get_file_type(file_info) == G_FILE_TYPE_REGULAR) {
      const gchar *profile_file_name = g_file_info_get_name(file_info);
      gchar *profile_file_full_path = g_build_filename(profile_file_path,
          profile_file_name, NULL);
      gpointer profile = gnac_profiles_properties_load_profile_from_file(
          profile_file_full_path, profile_file_name, &error);

      g_free(profile_file_full_path);

      if (profile) {
        gnac_profiles_mgr_insert(profile);
      } else if (error) {
        libgnac_warning("%s", error->message);
        g_clear_error(&error);
      }
    }

    g_object_unref(file_info);
    file_info = g_file_enumerator_next_file(files, NULL, NULL);
  }

  gnac_profiles_mgr_display_status_message(NULL, NULL);

  g_object_unref(dir);
  g_free(profile_file_path);
  g_file_enumerator_close(files, NULL, NULL);
  g_object_unref(files);
}