VFSMimeType* vfs_mime_type_get_from_file_name( const char* ufile_name ) { const char * type; /* type = xdg_mime_get_mime_type_from_file_name( ufile_name ); */ type = mime_type_get_by_filename( ufile_name, NULL ); return vfs_mime_type_get_from_type( type ); }
VFSMimeType* vfs_mime_type_get_from_file( const char* file_path, const char* base_name, struct stat64* pstat ) { const char * type; type = mime_type_get_by_file( file_path, pstat, base_name ); return vfs_mime_type_get_from_type( type ); }
gboolean vfs_file_info_get( VFSFileInfo* fi, const char* file_path, const char* base_name ) { struct stat64 file_stat; vfs_file_info_clear( fi ); if ( base_name ) fi->name = g_strdup( base_name ); else fi->name = g_path_get_basename( file_path ); if ( lstat64( file_path, &file_stat ) == 0 ) { /* This is time-consuming but can save much memory */ fi->mode = file_stat.st_mode; fi->dev = file_stat.st_dev; fi->uid = file_stat.st_uid; fi->gid = file_stat.st_gid; fi->size = file_stat.st_size; //printf("size %s %llu\n", fi->name, fi->size ); fi->mtime = file_stat.st_mtime; fi->atime = file_stat.st_atime; fi->blksize = file_stat.st_blksize; fi->blocks = file_stat.st_blocks; if ( G_LIKELY( utf8_file_name && g_utf8_validate ( fi->name, -1, NULL ) ) ) { fi->disp_name = fi->name; /* Don't duplicate the name and save memory */ } else { fi->disp_name = g_filename_display_name( fi->name ); } fi->mime_type = vfs_mime_type_get_from_file( file_path, fi->disp_name, &file_stat ); //sfm get collate keys fi->collate_key = g_utf8_collate_key_for_filename( fi->disp_name, -1 ); char* str = g_utf8_casefold( fi->disp_name, -1 ); fi->collate_icase_key = g_utf8_collate_key_for_filename( str, -1 ); g_free( str ); return TRUE; } else fi->mime_type = vfs_mime_type_get_from_type( XDG_MIME_TYPE_UNKNOWN ); return FALSE; }
GdkPixbuf* vfs_mime_type_get_icon( VFSMimeType* mime_type, gboolean big ) { GdkPixbuf * icon = NULL; const char* sep; char icon_name[ 100 ]; GtkIconTheme *icon_theme; int size; if ( big ) { if ( G_LIKELY( mime_type->big_icon ) ) /* big icon */ return g_object_ref( mime_type->big_icon ); size = big_icon_size; } else /* small icon */ { if ( G_LIKELY( mime_type->small_icon ) ) return g_object_ref( mime_type->small_icon ); size = small_icon_size; } icon_theme = gtk_icon_theme_get_default (); if ( G_UNLIKELY( 0 == strcmp( mime_type->type, XDG_MIME_TYPE_DIRECTORY ) ) ) { icon = vfs_load_icon ( icon_theme, "folder", size ); if( G_UNLIKELY( !icon) ) icon = vfs_load_icon ( icon_theme, "gnome-fs-directory", size ); if( G_UNLIKELY( !icon) ) icon = vfs_load_icon ( icon_theme, "gtk-directory", size ); if ( big ) mime_type->big_icon = icon; else mime_type->small_icon = icon; return icon ? g_object_ref( icon ) : NULL; } sep = strchr( mime_type->type, '/' ); if ( sep ) { /* convert mime-type foo/bar to foo-bar */ strcpy( icon_name, mime_type->type ); icon_name[ (sep - mime_type->type) ] = '-'; /* is there an icon named foo-bar? */ icon = vfs_load_icon ( icon_theme, icon_name, size ); if ( ! icon ) { /* maybe we can find a legacy icon named gnome-mime-foo-bar */ strcpy( icon_name, "gnome-mime-" ); strncat( icon_name, mime_type->type, ( sep - mime_type->type ) ); strcat( icon_name, "-" ); strcat( icon_name, sep + 1 ); icon = vfs_load_icon ( icon_theme, icon_name, size ); } // hack for x-xz-compressed-tar missing icon if ( !icon && strstr( mime_type->type, "compressed" ) ) { icon = vfs_load_icon ( icon_theme, "application-x-archive", size ); if ( !icon ) icon = vfs_load_icon ( icon_theme, "gnome-mime-application-x-archive", size ); } /* try gnome-mime-foo */ if ( G_UNLIKELY( ! icon ) ) { icon_name[ 11 ] = '\0'; /* strlen("gnome-mime-") = 11 */ strncat( icon_name, mime_type->type, ( sep - mime_type->type ) ); icon = vfs_load_icon ( icon_theme, icon_name, size ); } /* try foo-x-generic */ if ( G_UNLIKELY( ! icon ) ) { strncpy( icon_name, mime_type->type, ( sep - mime_type->type ) ); icon_name[ (sep - mime_type->type) ] = '\0'; strcat( icon_name, "-x-generic" ); icon = vfs_load_icon ( icon_theme, icon_name, size ); } } if( G_UNLIKELY( !icon ) ) { /* prevent endless recursion of XDG_MIME_TYPE_UNKNOWN */ if( G_LIKELY( strcmp(mime_type->type, XDG_MIME_TYPE_UNKNOWN) ) ) { /* FIXME: fallback to icon of parent mime-type */ VFSMimeType* unknown; unknown = vfs_mime_type_get_from_type( XDG_MIME_TYPE_UNKNOWN ); icon = vfs_mime_type_get_icon( unknown, big ); vfs_mime_type_unref( unknown ); } else /* unknown */ { icon = vfs_load_icon ( icon_theme, "unknown", size ); } } if ( big ) mime_type->big_icon = icon; else mime_type->small_icon = icon; return icon ? g_object_ref( icon ) : NULL; }