diff options
Diffstat (limited to 'src/gtkext')
-rw-r--r-- | src/gtkext/gtkstatusstack.c | 160 | ||||
-rw-r--r-- | src/gtkext/gtkstatusstack.h | 3 |
2 files changed, 99 insertions, 64 deletions
diff --git a/src/gtkext/gtkstatusstack.c b/src/gtkext/gtkstatusstack.c index d84f179..95166d7 100644 --- a/src/gtkext/gtkstatusstack.c +++ b/src/gtkext/gtkstatusstack.c @@ -24,6 +24,7 @@ #include "gtkstatusstack.h" +#include <assert.h> #include <inttypes.h> #include <malloc.h> #include <string.h> @@ -878,6 +879,43 @@ activity_id_t gtk_status_stack_add_activity(GtkStatusStack *stack, const char *m } + +/****************************************************************************** +* * +* Paramètres : stack = barre de statut à actualiser. * +* id = identifiant de l'activité à cibler. * +* extra = nouvelle échéance supplémentaire des traitements. * +* * +* Description : Etend la portée des travaux d'une nouvelle activité. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +void gtk_status_stack_extend_activity(GtkStatusStack *stack, activity_id_t id, unsigned long extra) +{ + progress_info *info; /* Informations à consulter */ + size_t i; /* Boucle de parcours */ + + info = stack->prog_info; + + g_mutex_lock(&info->access); + + for (i = 0; i < info->count; i++) + if (info->statuses[i].id == id) + break; + + assert(i < info->count); + + info->statuses[i].max += extra; + + g_mutex_unlock(&info->access); + +} + + /****************************************************************************** * * * Paramètres : stack = barre de statut à actualiser. * @@ -907,38 +945,36 @@ void gtk_status_stack_update_activity(GtkStatusStack *stack, activity_id_t id, c if (info->statuses[i].id == id) break; - if (i < info->count) - { - /* Intitulé */ + assert(i < info->count); - if (info->statuses[i].message != NULL) - { - if (msg == NULL) - msg_changed = true; - else - msg_changed = (strcmp(info->statuses[i].message, msg) != 0); - - free(info->statuses[i].message); - - } - else - msg_changed = (msg != NULL); + /* Intitulé */ + if (info->statuses[i].message != NULL) + { if (msg == NULL) - info->statuses[i].message = NULL; + msg_changed = true; else - info->statuses[i].message = strdup(msg); + msg_changed = (strcmp(info->statuses[i].message, msg) != 0); - /* On n'actualise que le sommet de la pile */ + free(info->statuses[i].message); - if ((i + 1) == info->count) - { - if (info->tag != 0) - g_source_remove(info->tag); + } + else + msg_changed = (msg != NULL); - info->tag = g_idle_add((GSourceFunc)gtk_status_stack_show_current_activity, stack); + if (msg == NULL) + info->statuses[i].message = NULL; + else + info->statuses[i].message = strdup(msg); - } + /* On n'actualise que le sommet de la pile */ + + if ((i + 1) == info->count) + { + if (info->tag != 0) + g_source_remove(info->tag); + + info->tag = g_idle_add((GSourceFunc)gtk_status_stack_show_current_activity, stack); } @@ -977,30 +1013,28 @@ void gtk_status_stack_update_activity_value(GtkStatusStack *stack, activity_id_t if (info->statuses[i].id == id) break; - if (i < info->count) - { - status = &info->statuses[i]; + assert(i < info->count); - /* Valeur */ + status = &info->statuses[i]; - status->current += inc; + /* Valeur */ - new = (status->current * 1.0) / status->max; + status->current += inc; - /* On n'actualise que le sommet de la pile */ + new = (status->current * 1.0) / status->max; + /* On n'actualise que le sommet de la pile */ - //fprintf(stderr, "PROG %g -> %g <=> %g ==> %d\n", old, new, new - old, (new - old) > 0.1); + //fprintf(stderr, "PROG %g -> %g <=> %g ==> %d\n", old, new, new - old, (new - old) > 0.1); - if ((i + 1) == info->count && (new - status->last_updated) > 0.1) - { - if (info->tag != 0) - g_source_remove(info->tag); - info->tag = g_idle_add((GSourceFunc)gtk_status_stack_show_current_activity, stack); + if ((i + 1) == info->count && (new - status->last_updated) > 0.1) + { + if (info->tag != 0) + g_source_remove(info->tag); - } + info->tag = g_idle_add((GSourceFunc)gtk_status_stack_show_current_activity, stack); } @@ -1034,40 +1068,38 @@ void gtk_status_stack_remove_activity(GtkStatusStack *stack, activity_id_t id) if (info->statuses[i].id == id) break; - if (i < info->count) - { - if (info->tag != 0) - g_source_remove(info->tag); + assert(i < info->count); - if (info->statuses[i].message != NULL) - free(info->statuses[i].message); + if (info->tag != 0) + g_source_remove(info->tag); - if (info->count == 1) - { - free(info->statuses); - info->statuses = NULL; - } - else - { - memmove(&info->statuses[i], &info->statuses[i + 1], - (info->count - i - 1) * sizeof(progress_status)); + if (info->statuses[i].message != NULL) + free(info->statuses[i].message); - info->statuses = (progress_status *)realloc(info->statuses, - (info->count - 1) * sizeof(progress_status)); + if (info->count == 1) + { + free(info->statuses); + info->statuses = NULL; + } + else + { + memmove(&info->statuses[i], &info->statuses[i + 1], + (info->count - i - 1) * sizeof(progress_status)); - } + info->statuses = (progress_status *)realloc(info->statuses, + (info->count - 1) * sizeof(progress_status)); - info->count--; + } - if (info->count == 0) - { - info->tag = 0; - g_idle_add((GSourceFunc)gtk_status_stack_show_current_instruction, stack); - } - else - info->tag = g_idle_add((GSourceFunc)gtk_status_stack_show_current_activity, stack); + info->count--; + if (info->count == 0) + { + info->tag = 0; + g_idle_add((GSourceFunc)gtk_status_stack_show_current_instruction, stack); } + else + info->tag = g_idle_add((GSourceFunc)gtk_status_stack_show_current_activity, stack); g_mutex_unlock(&info->access); diff --git a/src/gtkext/gtkstatusstack.h b/src/gtkext/gtkstatusstack.h index 590f562..1701d77 100644 --- a/src/gtkext/gtkstatusstack.h +++ b/src/gtkext/gtkstatusstack.h @@ -79,6 +79,9 @@ typedef unsigned long activity_id_t; /* Démarre le suivi d'une nouvelle activité. */ activity_id_t gtk_status_stack_add_activity(GtkStatusStack *, const char *, unsigned long); +/* Etend la portée des travaux d'une nouvelle activité. */ +void gtk_status_stack_extend_activity(GtkStatusStack *, activity_id_t, unsigned long); + /* Actualise les informations concernant une activité. */ void gtk_status_stack_update_activity(GtkStatusStack *, activity_id_t, const char *); |