From 22298fcae3440320bc6a2a5e160ceb5bed8db0a7 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Sat, 15 Mar 2025 10:53:49 +0000 Subject: [PATCH] progress: Add support for a status message Signed-off-by: Michael Tremer --- src/pakfire/progress.c | 32 ++++++++++++++++++++++++++++++++ src/pakfire/progress.h | 5 ++++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/pakfire/progress.c b/src/pakfire/progress.c index 14084cd98..cb7fa931d 100644 --- a/src/pakfire/progress.c +++ b/src/pakfire/progress.c @@ -33,6 +33,9 @@ struct pakfire_progress { // Title char* title; + // Status + char* status; + // Flags what to show int flags; @@ -75,6 +78,8 @@ static void pakfire_progress_free(struct pakfire_progress* p) { if (p->parent) pakfire_progress_unref(p->parent); + if (p->status) + free(p->status); if (p->title) free(p->title); if (p->ctx) @@ -339,6 +344,33 @@ int pakfire_progress_set_title(struct pakfire_progress* p, const char* format, . r = vasprintf(&p->title, format, args); va_end(args); + // Fail + if (r < 0) + return r; + + // If we have a parent, we set this title as their status + if (p->parent) { + r = pakfire_progress_set_status(p->parent, "%s", p->title); + if (r < 0) + return r; + } + + return 0; +} + +const char* pakfire_progress_get_status(struct pakfire_progress* p) { + return p->status; +} + +int pakfire_progress_set_status(struct pakfire_progress* p, const char* format, ...) { + va_list args; + int r; + + // Format the status + va_start(args, format); + r = vasprintf(&p->status, format, args); + va_end(args); + // Fail if (r < 0) return r; diff --git a/src/pakfire/progress.h b/src/pakfire/progress.h index 42205ea14..bbac640ea 100644 --- a/src/pakfire/progress.h +++ b/src/pakfire/progress.h @@ -65,7 +65,6 @@ void pakfire_progress_set_free_callback( struct pakfire_progress* pakfire_progress_get_parent(struct pakfire_progress* p); unsigned long int pakfire_progress_get_value(struct pakfire_progress* p); unsigned long int pakfire_progress_get_max_value(struct pakfire_progress* p); -const char* pakfire_progress_get_title(struct pakfire_progress* p); double pakfire_progress_get_percentage(struct pakfire_progress* p); time_t pakfire_progress_get_elapsed_time(struct pakfire_progress* p); time_t pakfire_progress_get_eta(struct pakfire_progress* p); @@ -83,8 +82,12 @@ int pakfire_progress_update(struct pakfire_progress* p, unsigned long int value) int pakfire_progress_increment(struct pakfire_progress* p, unsigned long int value); int pakfire_progress_reset(struct pakfire_progress* p); +const char* pakfire_progress_get_title(struct pakfire_progress* p); int pakfire_progress_set_title(struct pakfire_progress* p, const char* format, ...) __attribute__((format(printf, 2, 3))); +const char* pakfire_progress_get_status(struct pakfire_progress* p); +int pakfire_progress_set_status(struct pakfire_progress* p, const char* format, ...) + __attribute__((format(printf, 2, 3))); void pakfire_progress_set_max_value(struct pakfire_progress* p, unsigned long int value); #endif /* PAKFIRE_PROGRESS_H */ -- 2.39.5