Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
imagecache: Add re-fetch images button, fixes #2996
  • Loading branch information
perexg committed Sep 10, 2015
1 parent fc7b753 commit f108e23
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 6 deletions.
22 changes: 19 additions & 3 deletions src/api/api_imagecache.c
Expand Up @@ -40,13 +40,29 @@ api_imagecache_clean
return 0;
}

static int
api_imagecache_trigger
( access_t *perm, void *opaque, const char *op, htsmsg_t *args, htsmsg_t **resp )
{
int b;
if (htsmsg_get_bool(args, "trigger", &b))
return EINVAL;
if (b) {
pthread_mutex_lock(&global_lock);
imagecache_trigger();
pthread_mutex_unlock(&global_lock);
}
return 0;
}

void
api_imagecache_init ( void )
{
static api_hook_t ah[] = {
{ "imagecache/config/load", ACCESS_ADMIN, api_idnode_load_simple, &imagecache_conf },
{ "imagecache/config/save", ACCESS_ADMIN, api_idnode_save_simple, &imagecache_conf },
{ "imagecache/config/clean", ACCESS_ADMIN, api_imagecache_clean, NULL },
{ "imagecache/config/load", ACCESS_ADMIN, api_idnode_load_simple, &imagecache_conf },
{ "imagecache/config/save", ACCESS_ADMIN, api_idnode_save_simple, &imagecache_conf },
{ "imagecache/config/clean" , ACCESS_ADMIN, api_imagecache_clean, NULL },
{ "imagecache/config/trigger", ACCESS_ADMIN, api_imagecache_trigger, NULL },
{ NULL },
};

Expand Down
23 changes: 21 additions & 2 deletions src/imagecache.c
Expand Up @@ -451,13 +451,13 @@ imagecache_clean( void )
#endif

tvhinfo("imagecache", "clean request");
/* remove unassociated data*/
/* remove unassociated data */
if (hts_settings_buildpath(path, sizeof(path), "imagecache/data")) {
tvherror("imagecache", "clean - buildpath");
return;
}
if((n = fb_scandir(path, &namelist)) < 0)
return;
goto done;
for (i = 0; i < n; i++) {
name = namelist[i]->name;
if (name[0] == '.')
Expand All @@ -471,6 +471,25 @@ imagecache_clean( void )
hts_settings_remove("imagecache/data/%s", name);
}
free(namelist);
done:
imagecache_trigger();
}

/*
* Trigger
*/
void
imagecache_trigger( void )
{
imagecache_image_t *img;

lock_assert(&global_lock);

tvhinfo("imagecache", "load triggered");
RB_FOREACH(img, &imagecache_by_url, url_link) {
if (img->state != IDLE) continue;
imagecache_image_add(img);
}
}

#endif /* ENABLE_IMAGECACHE */
Expand Down
1 change: 1 addition & 0 deletions src/imagecache.h
Expand Up @@ -39,6 +39,7 @@ void imagecache_init ( void );
void imagecache_done ( void );

void imagecache_clean ( void );
void imagecache_trigger ( void );

// Note: will return 0 if invalid (must serve original URL)
uint32_t imagecache_get_id ( const char *url );
Expand Down
19 changes: 18 additions & 1 deletion src/webui/static/app/config.js
Expand Up @@ -280,13 +280,30 @@ tvheadend.imgcacheconf = function(panel, index) {
}
};

var triggerButton = {
name: 'trigger',
builder: function() {
return new Ext.Toolbar.Button({
tooltip: _('Re-fetch images'),
iconCls: 'trigger',
text: _('Re-fetch images'),
});
},
callback: function(conf) {
tvheadend.Ajax({
url: 'api/imagecache/config/trigger',
params: { trigger: 1 },
});
}
};

tvheadend.idnode_simple(panel, {
url: 'api/imagecache/config',
title: _('Image cache'),
iconCls: 'imgcacheconf',
tabIndex: index,
comet: 'imagecache',
tbar: [cleanButton],
tbar: [cleanButton, triggerButton],
help: function() {
new tvheadend.help(_('General Configuration'), 'config_general.html');
}
Expand Down

0 comments on commit f108e23

Please sign in to comment.