return cli_progressbar_add_widget(p, cli_progressbar_string, free, 0, s);
}
+static const char* cli_progressbar_title(struct cli_progressbar* p,
+ struct cli_progressbar_widget* widget, unsigned int width, void* data) {
+ return pakfire_progress_get_title(p->progress);
+}
+
+static int cli_progressbar_add_title(struct cli_progressbar* p) {
+ return cli_progressbar_add_widget(p, cli_progressbar_title, NULL, 0, NULL);
+}
+
static const char* cli_progressbar_counter(struct cli_progressbar* p,
struct cli_progressbar_widget* widget, unsigned int width, void* data) {
int r;
int cli_setup_progressbar(struct pakfire* pakfire, struct pakfire_progress* p, void* data) {
struct cli_progressbar* progressbar = NULL;
- const char* title = NULL;
int r;
// Allocate a new progressbar
pakfire_progress_set_free_callback(p, __cli_progressbar_free);
// Add the title
- title = pakfire_progress_get_title(p);
- if (title) {
- r = cli_progressbar_add_string(progressbar, "%s", title);
- if (r)
- goto ERROR;
- }
+ r = cli_progressbar_add_title(progressbar);
+ if (r)
+ goto ERROR;
// Show the bar
r = cli_progressbar_add_bar(progressbar);
progress_flags |= PAKFIRE_PROGRESS_SHOW_TRANSFER_SPEED;
// Create the progressbar indicator
- r = pakfire_progress_create(&data.progress, pakfire, message, progress_flags);
+ r = pakfire_progress_create(&data.progress, pakfire, progress_flags);
+ if (r)
+ goto ERROR;
+
+ // Set the title
+ r = pakfire_progress_set_title(data.progress, "%s", message);
if (r)
goto ERROR;
#include <pakfire/pakfire.h>
int pakfire_progress_create(struct pakfire_progress** progress,
- struct pakfire* pakfire, const char* title, int flags);
+ struct pakfire* pakfire, int flags);
struct pakfire_progress* pakfire_progress_ref(struct pakfire_progress* p);
struct pakfire_progress* pakfire_progress_unref(struct pakfire_progress* p);
int pakfire_progress_start(struct pakfire_progress* p, unsigned long int value);
int pakfire_progress_finish(struct pakfire_progress* p);
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_set_title(struct pakfire_progress* p, const char* format, ...);
#endif
int nrefs;
// Title
- const char* title;
+ char* title;
// Flags what to show
int flags;
if (p->callbacks.free)
p->callbacks.free(p->pakfire, p, p->callbacks.data);
+ if (p->title)
+ free(p->title);
pakfire_unref(p->pakfire);
free(p);
}
int pakfire_progress_create(struct pakfire_progress** progress,
- struct pakfire* pakfire, const char* title, int flags) {
+ struct pakfire* pakfire, int flags) {
struct pakfire_progress* p = NULL;
int r;
// Initialize the reference counter
p->nrefs = 1;
- // Store title
- p->title = title;
-
// Store the flags
p->flags = flags;
return p->title;
}
+int pakfire_progress_set_title(struct pakfire_progress* p, const char* format, ...) {
+ va_list args;
+ int r;
+
+ // Format the title
+ va_start(args, format);
+ r = vasprintf(&p->title, format, args);
+ va_end(args);
+
+ // Fail
+ if (r < 0)
+ return r;
+
+ return 0;
+}
+
PAKFIRE_EXPORT double pakfire_progress_get_percentage(struct pakfire_progress* p) {
if (!p->max_value)
return 0;