Esempio n. 1
0
gboolean populate_files (gpointer data)     //TODO:: show an spinner while loading
{
  FilebrowserBackend *filebackend= FILEBROWSER_BACKEND(data);
  FilebrowserBackendDetails *directory = FILEBROWSER_BACKEND_GET_PRIVATE(filebackend);
  GDK_THREADS_ENTER();
  if (g_cancellable_is_cancelled (directory->cancellable)){
  GDK_THREADS_LEAVE();
  return FALSE; /* remove source */
  }
  GError *error=NULL;
  GFileInfo *info = g_file_enumerator_next_file (directory->enumerator, directory->cancellable, &error);
  if (info){
	  const gchar *mime= g_file_info_get_content_type (info);
	  if (!g_file_info_get_is_hidden (info)  && !g_file_info_get_is_backup (info)){
	    if (MIME_ISDIR(mime)){
		//if has dot in name pos 0 don't process
		const gchar *folder=g_file_info_get_display_name(info);
		if(folder[0]!='.'){
		  FOLDERFILE *current;
		  current=new_folderfile();
		  current->mime=g_strdup(mime);
      GIcon *icon =g_file_info_get_icon(info); 
      current->icon= g_icon_to_string (icon);
		  current->display_name=g_strdup(folder);
		  /* add to list */
		 directory->filesinfolder = g_slist_append(directory->filesinfolder, current);
		  }
	  } else {
	    if (IS_TEXT(mime) && !IS_APPLICATION(mime)){
	      //files
	      FOLDERFILE *current;
	      current=new_folderfile();
	      current->mime=g_strdup(mime);
	      GIcon *icon =g_file_info_get_icon(info); 
	      current->icon= g_icon_to_string (icon);
	      current->display_name=g_strdup(g_file_info_get_display_name(info));
	      /* add to list */
	      directory->filesinfolder = g_slist_append(directory->filesinfolder, current);
	      }
	    }
	  }	
	g_object_unref(info);
   } else {
   	if (error){
   		g_print(_("Error::%s"),error->message);
   		g_error_free (error);
   	}
	GDK_THREADS_LEAVE();
	return FALSE; /* remove source */
   }
    GDK_THREADS_LEAVE();
    return TRUE;
}
Esempio n. 2
0
/**
 * gwy_module_load_directory:
 * @path: Name of directory to be scanned for modules and module libraries.
 *        Subdirectories are <emphasis>not</emphasis> scanned.
 * @errorlist: (allow-none):
 *             Location to store possible errors.
 *             Errors from %GWY_MODULE_ERROR or %G_IO_ERROR domain can occur.
 *
 * Loads modules and module libraries from a directory.
 *
 * This function only loads the modules or libraries and queues them for
 * registration.  You need to call also gwy_module_register_types() some time
 * in the future to finish the registration.
 *
 * Returns: The number of shared libraries that were found and loaded as either
 *          modules of module libraries.
 **/
guint
gwy_module_load_directory(const gchar *path,
                          GwyErrorList **errorlist)
{
    static const gchar attrs[] = (G_FILE_ATTRIBUTE_STANDARD_TYPE ","
                                  G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN ","
                                  G_FILE_ATTRIBUTE_STANDARD_IS_BACKUP ","
                                  G_FILE_ATTRIBUTE_STANDARD_NAME);

    g_return_val_if_fail(path, 0);
    GFile *file = g_file_new_for_path(path);
    GError *error = NULL;
    GFileEnumerator *enumerator = g_file_enumerate_children(file, attrs, 0,
                                                            NULL, &error);
    if (!enumerator) {
        gwy_error_list_propagate(errorlist, error);
        g_object_unref(file);
        return 0;
    }

    guint count = 0;
    for (GFileInfo *fileinfo = g_file_enumerator_next_file(enumerator, NULL,
                                                           &error);
         fileinfo;
         (void)g_object_unref(fileinfo),
         (fileinfo = g_file_enumerator_next_file(enumerator, NULL, &error))) {
        if (g_file_info_get_is_hidden(fileinfo)
            || g_file_info_get_is_backup(fileinfo))
            continue;

        GFileType filetype = g_file_info_get_file_type(fileinfo);
        if (filetype != G_FILE_TYPE_REGULAR
            && filetype != G_FILE_TYPE_SYMBOLIC_LINK)
            continue;

        const gchar *name = g_file_info_get_name(fileinfo);
        if (!g_str_has_suffix(name, "." G_MODULE_SUFFIX))
            continue;

        gchar *fullname = g_build_filename(path, name, NULL);
        if (queue_one_module_or_library(fullname, errorlist))
            count++;
        g_free(fullname);
    }

    if (error)
        gwy_error_list_propagate(errorlist, error);

    g_object_unref(enumerator);
    g_object_unref(file);
    return count;
}