Skip to content

Commit

Permalink
fix progress bar, again
Browse files Browse the repository at this point in the history
  • Loading branch information
jcupitt committed Jul 23, 2023
1 parent 523a969 commit 6ed8c7f
Showing 3 changed files with 31 additions and 12 deletions.
19 changes: 14 additions & 5 deletions src/imagewindow.c
Original file line number Diff line number Diff line change
@@ -262,6 +262,14 @@ image_window_bestfit( ImageWindow *win )
}
}

static void
image_window_preeval( VipsImage *image,
VipsProgress *progress, ImageWindow *win )
{
gtk_action_bar_set_revealed( GTK_ACTION_BAR( win->progress_bar ),
TRUE );
}

typedef struct _EvalUpdate {
ImageWindow *win;
int eta;
@@ -277,11 +285,6 @@ image_window_eval_idle( void *user_data )
char str[256];
VipsBuf buf = VIPS_BUF_STATIC( str );

// you'd think we could do this in preeval, but it doesn't always seem to
// fire for some reason
gtk_action_bar_set_revealed( GTK_ACTION_BAR( win->progress_bar ),
TRUE );

vips_buf_appendf( &buf, "%d%% complete, %d seconds to go",
update->percent, update->eta );
gtk_progress_bar_set_text( GTK_PROGRESS_BAR( win->progress ),
@@ -1462,6 +1465,8 @@ image_window_set_tile_source( ImageWindow *win, TileSource *tile_source )
"tile-cache", win->tile_cache,
NULL );

g_signal_connect_object( win->tile_source, "preeval",
G_CALLBACK( image_window_preeval ), win, 0 );
g_signal_connect_object( win->tile_source, "eval",
G_CALLBACK( image_window_eval ), win, 0 );
g_signal_connect_object( win->tile_source, "posteval",
@@ -1509,6 +1514,10 @@ image_window_set_tile_source( ImageWindow *win, TileSource *tile_source )
tile_source->active =
g_settings_get_boolean( win->settings, "control" );

/* Everything is set up ... start loading the image.
*/
tile_source_background_load( tile_source );

image_window_changed( win );
}

22 changes: 15 additions & 7 deletions src/tilesource.c
Original file line number Diff line number Diff line change
@@ -1037,12 +1037,12 @@ tile_source_background_load_done_idle( void *user_data )
/* This runs for the background load threadpool.
*/
static void
tile_source_background_load( void *data, void *user_data )
tile_source_background_load_worker( void *data, void *user_data )
{
TileSource *tile_source = (TileSource *) data;

#ifdef DEBUG
printf( "tile_source_background_load: starting ..\n" );
printf( "tile_source_background_load_worker: starting ..\n" );
#endif /*DEBUG*/

g_assert( tile_source->image_region );
@@ -1052,7 +1052,7 @@ tile_source_background_load( void *data, void *user_data )
g_idle_add( tile_source_background_load_done_idle, tile_source );

#ifdef DEBUG
printf( "tile_source_background_load: .. done\n" );
printf( "tile_source_background_load_worker: .. done\n" );
#endif /*DEBUG*/
}

@@ -1185,7 +1185,7 @@ tile_source_class_init( TileSourceClass *class )

g_assert( !tile_source_background_load_pool );
tile_source_background_load_pool = g_thread_pool_new(
tile_source_background_load,
tile_source_background_load_worker,
NULL, -1, FALSE, NULL );

}
@@ -1746,9 +1746,6 @@ tile_source_new_from_source( VipsSource *source )

tile_source_attach_progress( tile_source );

g_thread_pool_push( tile_source_background_load_pool,
tile_source, NULL );

return( tile_source );
}

@@ -1811,6 +1808,17 @@ tile_source_new_from_file( GFile *file )
return( tile_source );
}

/* Call this some time after tile_source_new_from_file() or
* tile_source_new_from_source(), and once all callbacks have been
* attached, to trigger a bg load.
*/
void
tile_source_background_load( TileSource *tile_source )
{
g_thread_pool_push( tile_source_background_load_pool,
tile_source, NULL );
}

int
tile_source_fill_tile( TileSource *tile_source, Tile *tile )
{
2 changes: 2 additions & 0 deletions src/tilesource.h
Original file line number Diff line number Diff line change
@@ -220,6 +220,8 @@ GType tile_source_get_type( void );
TileSource *tile_source_new_from_source( VipsSource *source );
TileSource *tile_source_new_from_file( GFile *file );

void tile_source_background_load( TileSource *tile_source );

int tile_source_fill_tile( TileSource *tile_source, Tile *tile );

const char *tile_source_get_path( TileSource *tile_source );

0 comments on commit 6ed8c7f

Please sign in to comment.