473
476
/* full path of the file is required by this function */
474
477
gboolean vfs_file_info_is_executable( VFSFileInfo* fi, const char* file_path )
476
return xdg_mime_is_executable_file( file_path, fi->mime_type->type );
479
return mime_type_is_executable_file( file_path, fi->mime_type->type );
479
482
/* full path of the file is required by this function */
480
483
gboolean vfs_file_info_is_text( VFSFileInfo* fi, const char* file_path )
482
return xdg_mime_is_text_file( file_path, fi->mime_type->type );
485
return mime_type_is_text_file( file_path, fi->mime_type->type );
534
static void unload_thumnails_if_needed( VFSFileInfo* fi )
537
if ( fi->big_thumbnail && fi->flags == VFS_FILE_INFO_NONE )
539
w = gdk_pixbuf_get_width( fi->big_thumbnail );
540
h = gdk_pixbuf_get_height( fi->big_thumbnail );
541
if ( _MAX( w, h ) != big_thumb_size )
543
gdk_pixbuf_unref( fi->big_thumbnail );
544
fi->big_thumbnail = NULL;
547
if ( fi->small_thumbnail && fi->flags == VFS_FILE_INFO_NONE )
549
w = gdk_pixbuf_get_width( fi->small_thumbnail );
550
h = gdk_pixbuf_get_height( fi->small_thumbnail );
551
if ( MAX( w, h ) != small_thumb_size )
553
gdk_pixbuf_unref( fi->small_thumbnail );
554
fi->small_thumbnail = NULL;
559
537
gboolean vfs_file_info_is_thumbnail_loaded( VFSFileInfo* fi, gboolean big )
561
/* FIXME: I cannot find a better place to unload thumbnails */
562
unload_thumnails_if_needed( fi );
564
540
return ( fi->big_thumbnail != NULL );
565
541
return ( fi->small_thumbnail != NULL );
592
557
if ( fi->small_thumbnail )
596
if ( !gdk_pixbuf_get_file_info( full_path, &w, &h ) )
597
return FALSE; /* image format cannot be recognized */
599
/* If the image itself is very small, we should load it directly */
600
if ( w <= 128 && h <= 128 )
560
thumbnail = vfs_thumbnail_load_for_file( full_path,
561
big ? big_thumb_size : small_thumb_size , fi->mtime );
562
if( G_LIKELY( thumbnail ) )
602
size = big ? big_thumb_size : small_thumb_size;
603
thumbnail = gdk_pixbuf_new_from_file_at_scale( full_path, size, size,
606
565
fi->big_thumbnail = thumbnail;
608
567
fi->small_thumbnail = thumbnail;
609
return ( thumbnail != NULL );
612
uri = g_filename_to_uri( full_path, NULL, NULL );
614
md5_state_t md5_state;
615
md5_init( &md5_state );
616
md5_append( &md5_state, ( md5_byte_t * ) uri, strlen( uri ) );
617
md5_finish( &md5_state, md5 );
619
for ( i = 0; i < 16; ++i )
621
sprintf( ( file_name + i * 2 ), "%02x", md5[ i ] );
623
strcpy( ( file_name + i * 2 ), ".png" );
625
thumbnail_file = g_build_filename( g_get_home_dir(),
626
".thumbnails/normal",
629
/* load existing thumbnail */
630
thumbnail = gdk_pixbuf_new_from_file( thumbnail_file, NULL );
632
!( thumb_mtime = gdk_pixbuf_get_option( thumbnail, "tEXt::Thumb::MTime" ) ) ||
633
atol( thumb_mtime ) != fi->mtime )
635
/* create new thumbnail */
636
thumbnail = gdk_pixbuf_new_from_file_at_size( full_path, 128, 128, NULL );
639
sprintf( mtime_str, "%lu", fi->mtime );
640
gdk_pixbuf_save( thumbnail, thumbnail_file, "png", NULL,
641
"tEXt::Thumb::URI", uri, "tEXt::Thumb::MTime", mtime_str, NULL );
647
w = gdk_pixbuf_get_width( thumbnail );
648
h = gdk_pixbuf_get_height( thumbnail );
649
size = big ? big_thumb_size : small_thumb_size;
664
result = gdk_pixbuf_scale_simple(
666
w, h, GDK_INTERP_BILINEAR );
667
gdk_pixbuf_unref( thumbnail );
569
else /* fallback to mime_type icon */
669
fi->big_thumbnail = result;
572
fi->big_thumbnail = vfs_file_info_get_big_icon( fi );
671
fi->small_thumbnail = result;
574
fi->small_thumbnail = vfs_file_info_get_small_icon( fi );
674
g_free( thumbnail_file );
675
return ( result != NULL );
576
return ( thumbnail != NULL );
678
579
void vfs_file_info_set_thumbnail_size( int big, int small )
684
585
void vfs_file_info_load_special_info( VFSFileInfo* fi,
685
586
const char* file_path )
687
if ( g_str_has_suffix( fi->name, ".desktop" ) )
588
/*if ( G_LIKELY(fi->type) && G_UNLIKELY(fi->type->name, "application/x-desktop") ) */
589
if ( G_UNLIKELY( g_str_has_suffix( fi->name, ".desktop") ) )
689
591
VFSAppDesktop * desktop;
690
592
const char* icon_name;
691
594
fi->flags |= VFS_FILE_INFO_DESKTOP_ENTRY;
692
595
desktop = vfs_app_desktop_new( file_path );
693
596
if ( vfs_app_desktop_get_disp_name( desktop ) )
695
598
vfs_file_info_set_disp_name(
696
599
fi, vfs_app_desktop_get_disp_name( desktop ) );
698
if( fi->big_thumbnail )
700
gdk_pixbuf_unref( fi->big_thumbnail );
701
fi->big_thumbnail = NULL;
703
602
if ( (icon_name = vfs_app_desktop_get_icon_name( desktop )) )
705
char * _icon_name = strdup( icon_name );
708
vfs_mime_type_get_icon_size( &size, NULL );
709
/* icon name is a full path */
710
if ( icon_name[ 0 ] == '/' )
712
icon = gdk_pixbuf_new_from_file_at_size(
713
icon_name, size, size, NULL );
717
char* dot = strchr( _icon_name, '.' );
720
icon = gtk_icon_theme_load_icon(
721
gtk_icon_theme_get_default(),
722
_icon_name, size, 0, NULL );
724
/* save app icon in thumbnail */
725
fi->big_thumbnail = icon;
726
if ( G_LIKELY( icon ) )
727
g_object_set_data_full( G_OBJECT(icon), "name", _icon_name, g_free );
729
g_free( _icon_name );
605
int big_size, small_size;
606
vfs_mime_type_get_icon_size( &big_size, &small_size );
607
if( ! fi->big_thumbnail )
609
icon = vfs_app_desktop_get_icon( desktop, big_size, FALSE );
611
fi->big_thumbnail =icon;
613
if( ! fi->small_thumbnail )
615
icon = vfs_app_desktop_get_icon( desktop, small_size, FALSE );
617
fi->small_thumbnail =icon;
731
620
vfs_app_desktop_unref( desktop );
757
cwd = g_get_current_dir();
758
g_string_append( ret, cwd );
654
cwd_new = g_get_current_dir();
655
g_string_append( ret, cwd_new );
762
659
g_string_append( ret, cwd );
766
if( relative_path[0] != '/' )
663
if( relative_path[0] != '/' && (0 == ret->len || ret->str[ ret->len - 1 ] != '/' ) )
767
664
g_string_append_c( ret, '/' );
769
666
while( G_LIKELY( *relative_path ) )