]> git.ipfire.org Git - pakfire.git/commitdiff
progress: Add support for a status message
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 15 Mar 2025 10:53:49 +0000 (10:53 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 15 Mar 2025 10:53:49 +0000 (10:53 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/progress.c
src/pakfire/progress.h

index 14084cd985e6bad768b4be642cbc78d084a8b7b7..cb7fa931decd107ce838ac8ae662afd23b2a48d6 100644 (file)
@@ -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;
index 42205ea14138487fa169a44784f8bb7bffdf8b28..bbac640ea886347a24ec4a0e443931339b57b01c 100644 (file)
@@ -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 */