Ejemplo n.º 1
0
void vfs_dir_emit_file_changed( VFSDir* dir, const char* file_name,
                                        VFSFileInfo* file, gboolean force )
{
    GList* l;
//printf("vfs_dir_emit_file_changed dir=%s file_name=%s avoid=%s\n", dir->path, file_name, dir->avoid_changes ? "TRUE" : "FALSE" );

    if ( !force && dir->avoid_changes )
        return;

    if ( G_UNLIKELY( 0 == strcmp(file_name, dir->path) ) )
    {
        // Special Case: The directory itself was changed
        g_signal_emit( dir, signals[ FILE_CHANGED_SIGNAL ], 0, NULL );
        return;
    }

    g_mutex_lock( dir->mutex );

    l = vfs_dir_find_file( dir, file_name, file );
    if ( G_LIKELY( l ) )
    {
        file = vfs_file_info_ref( ( VFSFileInfo* ) l->data );
        if( !g_slist_find( dir->changed_files, file ) )
        {
            if ( force )
            {
                dir->changed_files = g_slist_prepend( dir->changed_files, file );
                if ( 0 == change_notify_timeout )
                {
                    change_notify_timeout = g_timeout_add_full( G_PRIORITY_LOW,
                                                                100,
                                                                notify_file_change,
                                                                NULL, NULL );
                }
            }
            else if( G_LIKELY( update_file_info( dir, file ) ) ) // update file info the first time
            {
                dir->changed_files = g_slist_prepend( dir->changed_files, file );
                if ( 0 == change_notify_timeout )
                {
                    change_notify_timeout = g_timeout_add_full( G_PRIORITY_LOW,
                                                                500,
                                                                notify_file_change,
                                                                NULL, NULL );
                }
                g_signal_emit( dir, signals[ FILE_CHANGED_SIGNAL ], 0, file );
            }
        }
        else
            vfs_file_info_unref( file );
    }

    g_mutex_unlock( dir->mutex );
}
Ejemplo n.º 2
0
void update_created_files( gpointer key, gpointer data, gpointer user_data )
{
    VFSDir* dir = (VFSDir*)data;
    GSList* l;
    char* full_path;
    VFSFileInfo* file;
    GList* ll;

    if ( dir->created_files )
    {
        g_mutex_lock( dir->mutex );
        for ( l = dir->created_files; l; l = l->next )
        {
            if ( !( ll = vfs_dir_find_file( dir, (char*)l->data, NULL ) ) )
            {
                // file is not in dir file_list
                full_path = g_build_filename( dir->path, (char*)l->data, NULL );
                file = vfs_file_info_new();
                if ( vfs_file_info_get( file, full_path, NULL ) )
                {
                    // add new file to dir file_list
                    vfs_file_info_load_special_info( file, full_path );
                    dir->file_list = g_list_prepend( dir->file_list,
                                                    vfs_file_info_ref( file ) );
                    ++dir->n_files;
                    g_signal_emit( dir, signals[ FILE_CREATED_SIGNAL ], 0, file );
                }
                // else file doesn't exist in filesystem
                vfs_file_info_unref( file );
                g_free( full_path );
            }
            else
            {
                // file already exists in dir file_list
                file = vfs_file_info_ref( (VFSFileInfo*)ll->data );
                if ( update_file_info( dir, file ) )
                {
                    g_signal_emit( dir, signals[ FILE_CHANGED_SIGNAL ], 0, file );
                    vfs_file_info_unref( file );
                }
                // else was deleted, signaled, and unrefed in update_file_info
            }
            g_free( (char*)l->data );  // free file_name string
        }
        g_slist_free( dir->created_files );
        dir->created_files = NULL;
        g_mutex_unlock( dir->mutex );
    }
}
Ejemplo n.º 3
0
void vfs_dir_emit_thumbnail_loaded( VFSDir* dir, VFSFileInfo* file )
{
    GList* l;
    g_mutex_lock( dir->mutex );
    l = vfs_dir_find_file( dir, file->name, file );
    if( l )
    {
        g_assert( file == (VFSFileInfo*)l->data );
        file = vfs_file_info_ref( (VFSFileInfo*)l->data );
    }
    else
        file = NULL;
    g_mutex_unlock( dir->mutex );

    if ( G_LIKELY( file ) )
    {
        g_signal_emit( dir, signals[ THUMBNAIL_LOADED_SIGNAL ], 0, file );
        vfs_file_info_unref( file );
    }
}
Ejemplo n.º 4
0
void vfs_dir_emit_file_deleted( VFSDir* dir, const char* file_name, VFSFileInfo* file )
{
    GList* l;
    VFSFileInfo* file_found;

    if( G_UNLIKELY( 0 == strcmp(file_name, dir->path) ) )
    {
        /* Special Case: The directory itself was deleted... */
        file = NULL;
        /* clear the whole list */
        g_mutex_lock( dir->mutex );
        g_list_foreach( dir->file_list, (GFunc)vfs_file_info_unref, NULL );
        g_list_free( dir->file_list );
        dir->file_list = NULL;
        g_mutex_unlock( dir->mutex );

        g_signal_emit( dir, signals[ FILE_DELETED_SIGNAL ], 0, file );
        return;
    }

    l = vfs_dir_find_file( dir, file_name, file );
    if ( G_LIKELY( l ) )
    {
        file_found = vfs_file_info_ref( ( VFSFileInfo* ) l->data );
        if( !g_slist_find( dir->changed_files, file_found ) )
        {
            dir->changed_files = g_slist_prepend( dir->changed_files, file_found );
            if ( 0 == change_notify_timeout )
            {
                change_notify_timeout = g_timeout_add_full( G_PRIORITY_LOW,
                                                            200,
                                                            notify_file_change,
                                                            NULL, NULL );
            }
        }
        else
            vfs_file_info_unref( file_found );
    }
}