Simplified the 'preview' generation process

This commit is contained in:
David Capello 2008-02-18 23:31:38 +00:00
parent 1ab947b4f1
commit 1a1ace16b1

View File

@ -41,7 +41,6 @@
#include "widgets/statebar.h" #include "widgets/statebar.h"
#define MAX_THUMBNAIL_SIZE 128 #define MAX_THUMBNAIL_SIZE 128
#define MAX_THREADS_TO_GEN_THUMBNAILS 1
typedef struct FileView typedef struct FileView
{ {
@ -52,9 +51,9 @@ typedef struct FileView
FileItem *selected; FileItem *selected;
const char *exts; const char *exts;
/* round-robin thumbnail generation process */ /* thumbnail generation process */
JLink item_to_generate_thumbnail; /* current item in the round-robin */ FileItem *item_to_generate_thumbnail;
int round_timer_id; int timer_id;
JList monitors; /* list of monitors watching threads */ JList monitors; /* list of monitors watching threads */
} FileView; } FileView;
@ -77,7 +76,6 @@ static void fileview_regenerate_list(JWidget widget);
static int fileview_get_selected_index(JWidget widget); static int fileview_get_selected_index(JWidget widget);
static void fileview_select_index(JWidget widget, int index); static void fileview_select_index(JWidget widget, int index);
static void fileview_generate_preview_of_selected_item(JWidget widget); static void fileview_generate_preview_of_selected_item(JWidget widget);
static void fileview_generate_all_thumbnails(JWidget widget);
static bool fileview_generate_thumbnail(JWidget widget, FileItem *fileitem); static bool fileview_generate_thumbnail(JWidget widget, FileItem *fileitem);
static void openfile_bg(void *data); static void openfile_bg(void *data);
@ -109,7 +107,7 @@ JWidget fileview_new(FileItem *start_folder, const char *exts)
fileview->exts = exts; fileview->exts = exts;
fileview->item_to_generate_thumbnail = NULL; fileview->item_to_generate_thumbnail = NULL;
fileview->round_timer_id = jmanager_add_timer(widget, 200); fileview->timer_id = jmanager_add_timer(widget, 200);
fileview->monitors = jlist_new(); fileview->monitors = jlist_new();
fileview_regenerate_list(widget); fileview_regenerate_list(widget);
@ -180,7 +178,7 @@ void fileview_stop_threads(JWidget widget)
JLink link, next; JLink link, next;
/* stop the generation of threads */ /* stop the generation of threads */
jmanager_stop_timer(fileview->round_timer_id); jmanager_stop_timer(fileview->timer_id);
/* join all threads (removing all monitors) */ /* join all threads (removing all monitors) */
JI_LIST_FOR_EACH_SAFE(fileview->monitors, link, next) { JI_LIST_FOR_EACH_SAFE(fileview->monitors, link, next) {
@ -207,7 +205,7 @@ static bool fileview_msg_proc(JWidget widget, JMessage msg)
assert(jlist_empty(fileview->monitors)); assert(jlist_empty(fileview->monitors));
jlist_free(fileview->monitors); jlist_free(fileview->monitors);
jmanager_remove_timer(fileview->round_timer_id); jmanager_remove_timer(fileview->timer_id);
jfree(fileview); jfree(fileview);
break; break;
@ -343,7 +341,7 @@ static bool fileview_msg_proc(JWidget widget, JMessage msg)
y = thumbnail_y-thumbnail->h/2; y = thumbnail_y-thumbnail->h/2;
y = MID(vp->y1+2, y, vp->y2-3-thumbnail->h); y = MID(vp->y1+2, y, vp->y2-3-thumbnail->h);
draw_sprite(ji_screen, thumbnail, x, y); blit(thumbnail, ji_screen, 0, 0, x, y, thumbnail->w, thumbnail->h);
rect(ji_screen, rect(ji_screen,
x-1, y-1, x+thumbnail->w, y+thumbnail->h, x-1, y-1, x+thumbnail->w, y+thumbnail->h,
makecol(0, 0, 0)); makecol(0, 0, 0));
@ -502,29 +500,14 @@ static bool fileview_msg_proc(JWidget widget, JMessage msg)
break; break;
case JM_TIMER: case JM_TIMER:
/* is time to generate the next thumbnail in the round-robin? */ /* is time to generate the thumbnail? */
if (msg->timer.timer_id == fileview->round_timer_id && if (msg->timer.timer_id == fileview->timer_id) {
jlist_length(fileview->monitors) < MAX_THREADS_TO_GEN_THUMBNAILS) { FileItem *fileitem;
JLink link = fileview->item_to_generate_thumbnail;
JLink start = link;
while (link != fileview->list->end) { jmanager_stop_timer(fileview->timer_id);
FileItem *fileitem = link->data;
link = link->next != fileview->list->end ? link->next:
link->next->next;
if (fileview_generate_thumbnail(widget, fileitem)) fileitem = fileview->item_to_generate_thumbnail;
break; fileview_generate_thumbnail(widget, fileitem);
if (link == start)
break;
}
/* did we do all the round? */
if (link == start)
jmanager_stop_timer(fileview->round_timer_id);
fileview->item_to_generate_thumbnail = link;
} }
break; break;
@ -615,9 +598,6 @@ static void fileview_regenerate_list(JWidget widget)
} }
else else
fileview->list = jlist_new(); fileview->list = jlist_new();
/* generate all thumbnails */
fileview_generate_all_thumbnails(widget);
} }
static int fileview_get_selected_index(JWidget widget) static int fileview_get_selected_index(JWidget widget)
@ -659,19 +639,11 @@ static void fileview_generate_preview_of_selected_item(JWidget widget)
if (fileview->selected && if (fileview->selected &&
!fileitem_is_folder(fileview->selected) && !fileitem_is_folder(fileview->selected) &&
!fileitem_get_thumbnail(fileview->selected)) { !fileitem_get_thumbnail(fileview->selected))
fileview->item_to_generate_thumbnail = {
jlist_find(fileview->list, fileview->selected); fileview->item_to_generate_thumbnail = fileview->selected;
} jmanager_start_timer(fileview->timer_id);
} }
static void fileview_generate_all_thumbnails(JWidget widget)
{
FileView *fileview = fileview_data(widget);
fileview->item_to_generate_thumbnail = jlist_first(fileview->list);
jmanager_start_timer(fileview->round_timer_id);
} }
/* returns true if it does some hard work like access to the disk */ /* returns true if it does some hard work like access to the disk */
@ -707,6 +679,7 @@ static bool fileview_generate_thumbnail(JWidget widget, FileItem *fileitem)
monitor_free_thumbnail_generation, data); monitor_free_thumbnail_generation, data);
jlist_append(fileview_data(widget)->monitors, data->monitor); jlist_append(fileview_data(widget)->monitors, data->monitor);
jwidget_dirty(widget);
} }
else { else {
fop_free(fop); fop_free(fop);