Dialog for displaying progress of long-running operations.
More...
|
typedef struct _GNCProgressDialog | GNCProgressDialog |
|
typedef gboolean(* | GNCProgressCancelFunc )(gpointer user_data) |
|
|
GNCProgressDialog * | gnc_progress_dialog_new (GtkWidget *parent, gboolean use_ok_button) |
|
GNCProgressDialog * | gnc_progress_dialog_custom (GtkLabel *primary, GtkLabel *secondary, GtkProgressBar *bar, GtkLabel *suboperation, GtkTextView *log) |
|
void | gnc_progress_dialog_set_title (GNCProgressDialog *progress, const char *title) |
|
void | gnc_progress_dialog_set_primary (GNCProgressDialog *progress, const gchar *str) |
|
void | gnc_progress_dialog_set_heading (GNCProgressDialog *progress, const char *heading) |
|
void | gnc_progress_dialog_set_secondary (GNCProgressDialog *progress, const gchar *str) |
|
void | gnc_progress_dialog_set_sub (GNCProgressDialog *progress, const gchar *str) |
|
void | gnc_progress_dialog_reset_log (GNCProgressDialog *progress) |
|
void | gnc_progress_dialog_append_log (GNCProgressDialog *progress, const gchar *str) |
|
void | gnc_progress_dialog_pause (GNCProgressDialog *progress) |
|
void | gnc_progress_dialog_resume (GNCProgressDialog *progress) |
|
void | gnc_progress_dialog_set_cancel_func (GNCProgressDialog *progress, GNCProgressCancelFunc cancel_func, gpointer user_data) |
|
void | gnc_progress_dialog_set_cancel_scm_func (GNCProgressDialog *progress, SCM cancel_scm_func) |
|
void | gnc_progress_dialog_set_value (GNCProgressDialog *progress, gdouble value) |
|
guint | gnc_progress_dialog_push (GNCProgressDialog *progress, gdouble weight) |
|
guint | gnc_progress_dialog_pop (GNCProgressDialog *progress) |
|
guint | gnc_progress_dialog_pop_full (GNCProgressDialog *progress) |
|
void | gnc_progress_dialog_reset_value (GNCProgressDialog *progress) |
|
void | gnc_progress_dialog_update (GNCProgressDialog *progress) |
|
void | gnc_progress_dialog_finish (GNCProgressDialog *progress) |
|
void | gnc_progress_dialog_destroy (GNCProgressDialog *progress) |
|
Dialog for displaying progress of long-running operations.
These functions constitute an API for streamlining the creation and management of progress dialogs. Once registered with the API, the dialog's display and behavior can be controlled via simple calls that prevent the caller from needing to know anything about the underlying GUI.
A pop-up progress dialog can be created, displayed, and registered with the API by calling gnc_progress_dialog_new(). Alternatively, existing widgets can be registered with the API by calling gnc_progress_dialog_custom(). This method allows custom-made dialogs to hand off the management of typical progress-related widgets, and allows long-running operations report progress in a standard way.
void gnc_progress_dialog_append_log |
( |
GNCProgressDialog * |
progress, |
|
|
const gchar * |
str |
|
) |
| |
Append str to the progress log.
- Parameters
-
progress | a ::GNCProgressDialog |
str | the text to be appended |
Definition at line 457 of file dialog-progress.c.
462 g_return_if_fail(progress);
464 if (progress->log == NULL || !str || !*str)
468 buf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(progress->log));
469 gtk_text_buffer_get_end_iter(buf, &iter);
470 gtk_text_buffer_insert(buf, &iter, str, -1);
void gnc_progress_dialog_update(GNCProgressDialog *progress)
GNCProgressDialog* gnc_progress_dialog_custom |
( |
GtkLabel * |
primary, |
|
|
GtkLabel * |
secondary, |
|
|
GtkProgressBar * |
bar, |
|
|
GtkLabel * |
suboperation, |
|
|
GtkTextView * |
log |
|
) |
| |
Creates a dialog for displaying the progress of an activity using existing widgets. This allows long-running operations to update the progress in a custom dialog instead of a new pop-up.
- Parameters
-
primary | a GtkLabel widget to use for primary text |
secondary | a GtkLabel widget to use for secondary text |
bar | a GtkProgressBar widget for filling or pulsing |
suboperation | a GtkLabel widget to use for suboperation text |
log | a GtkTextView widget for logging progress textually |
Any of the parameters may be passed as NULL
if management of that visual element is not desired.
- Returns
- A ::GNCProgressDialog that identifies the dialog and is needed when making subsequent API calls.
Definition at line 285 of file dialog-progress.c.
296 progress->dialog = NULL;
297 progress->primary_label = GTK_WIDGET(primary);
298 progress->secondary_label = GTK_WIDGET(secondary);
299 progress->progress_bar = GTK_WIDGET(bar);
300 progress->sub_label = GTK_WIDGET(suboperation);
301 progress->log = GTK_WIDGET(log);
302 progress->ok_button = NULL;
303 progress->cancel_button = NULL;
306 progress->total_offset = 0;
307 progress->total_weight = 1;
308 progress->bar_value = 0;
309 progress->cancel_func = NULL;
310 progress->user_data = NULL;
311 progress->cancel_scm_func = SCM_UNDEFINED;
312 progress->use_ok_button = FALSE;
313 progress->closed = FALSE;
314 progress->finished = FALSE;
315 progress->destroyed = FALSE;
316 progress->title_set = FALSE;
Destroy the dialog. If gnc_progress_dialog_finish has been called, the dialog will not be destroyed until the user dismisses the window. This function must be called in order to reclaim the dialog's memory.
- Parameters
-
progress | a ::GNCProgressDialog |
Definition at line 781 of file dialog-progress.c.
783 g_return_if_fail(progress);
786 progress->cancel_func = NULL;
787 if (progress->cancel_scm_func != SCM_UNDEFINED)
788 scm_gc_unprotect_object(progress->cancel_scm_func);
789 progress->cancel_scm_func = SCM_UNDEFINED;
791 if (!progress->finished)
793 if (progress->dialog != NULL)
794 gtk_widget_hide(progress->dialog);
795 progress->closed = TRUE;
798 progress->destroyed = TRUE;
800 gnc_progress_maybe_destroy(progress);
Set the progress meter to fully complete, change the heading, if any, to "Complete", enable the 'OK' button, and make the dialog non-modal.
- Parameters
-
progress | a ::GNCProgressDialog |
Definition at line 750 of file dialog-progress.c.
752 g_return_if_fail(progress);
754 if (!progress->use_ok_button)
756 if (progress->dialog != NULL)
757 gtk_widget_hide(progress->dialog);
758 progress->closed = TRUE;
761 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(progress->progress_bar), 1.0);
763 gtk_widget_set_sensitive(progress->ok_button, TRUE);
764 gtk_widget_set_sensitive(progress->cancel_button, FALSE);
766 if (gtk_widget_get_visible(progress->primary_label))
769 if (!progress->title_set)
770 gtk_window_set_title(GTK_WINDOW(progress->dialog), _(
"Complete"));
772 gtk_window_set_modal(GTK_WINDOW(progress->dialog), FALSE);
774 progress->finished = TRUE;
void gnc_progress_dialog_set_heading(GNCProgressDialog *progress, const char *heading)
void gnc_progress_dialog_update(GNCProgressDialog *progress)
GNCProgressDialog* gnc_progress_dialog_new |
( |
GtkWidget * |
parent, |
|
|
gboolean |
use_ok_button |
|
) |
| |
Displays a pop-up dialog for showing the progress of a long-running activity.
By default only a title and progress bar are shown, but additional visual elements such as a Cancel button, text log, and additional labels can be activated by following with calls to some of the other API functions.
- Parameters
-
parent | The parent window for which the progress dialog becomes modal. |
use_ok_button | If TRUE , an OK button is shown and must be clicked when progress is completed. |
- Returns
- A ::GNCProgressDialog that identifies the dialog and is needed when making subsequent API calls.
Definition at line 266 of file dialog-progress.c.
272 progress->use_ok_button = use_ok_button;
274 gnc_progress_dialog_create(parent, progress);
276 gtk_widget_show(progress->dialog);
void gnc_progress_dialog_update(GNCProgressDialog *progress)
Show that progress has been paused by appending "(paused)" to the suboperation text, the window title, or the primary text. The first that is both known and currently shown will be the one used.
- Parameters
-
progress | a ::GNCProgressDialog |
Definition at line 477 of file dialog-progress.c.
481 g_return_if_fail(progress);
483 suffix = g_strconcat(
" ", _(
"(paused)"), NULL);
485 if (progress->sub_label && gtk_widget_get_visible(progress->sub_label))
487 const gchar *txt = gtk_label_get_text(GTK_LABEL(progress->sub_label));
489 if (txt && !g_str_has_suffix(txt, suffix))
491 gchar *newtxt = g_strconcat(txt, suffix, NULL);
496 else if (progress->dialog)
498 const gchar *txt = gtk_window_get_title(GTK_WINDOW(progress->dialog));
500 if (txt && !g_str_has_suffix(txt, suffix))
502 gchar *newtxt = g_strconcat(txt, suffix, NULL);
503 gtk_window_set_title(GTK_WINDOW(progress->dialog), newtxt);
507 else if (progress->primary_label &&
508 gtk_widget_get_visible(progress->primary_label))
510 const gchar *txt = gtk_label_get_text(GTK_LABEL(progress->primary_label));
512 if (txt && !g_str_has_suffix(txt, suffix))
514 gchar *newtxt = g_strconcat(txt, suffix, NULL);
void gnc_progress_dialog_set_sub(GNCProgressDialog *progress, const gchar *str)
void gnc_progress_dialog_set_primary(GNCProgressDialog *progress, const gchar *str)
void gnc_progress_dialog_update(GNCProgressDialog *progress)
Moves up one level in the stack of virtual bars. See gnc_progress_dialog_push() for an explanation of virtual bars.
- Parameters
-
progress | a ::GNCProgressDialog |
- Returns
- the number of times that gnc_progress_dialog_pop() would have to be called again to return to the top level.
Definition at line 683 of file dialog-progress.c.
687 g_return_val_if_fail(progress, 0);
690 if (progress->progress_bar == NULL || progress->bars == NULL)
694 bar = progress->bars->data;
695 progress->bars = g_list_delete_link(progress->bars, progress->bars);
698 progress->bar_value = bar->offset + bar->weight * progress->bar_value;
701 if (progress->bars == NULL)
703 progress->total_offset = 0;
704 progress->total_weight = 1;
708 progress->total_offset -= bar->offset *
709 ((
VirtualBar *) progress->bars->data)->weight;
710 progress->total_weight /= bar->weight;
714 if (progress->bars == NULL)
716 return g_list_length(progress->bars);
Fills the current progress bar, then calls gnc_progress_dialog_pop().
- Parameters
-
progress | a ::GNCProgressDialog |
- Returns
- the value returned by gnc_progress_dialog_pop()
Definition at line 721 of file dialog-progress.c.
void gnc_progress_dialog_set_value(GNCProgressDialog *progress, gdouble value)
guint gnc_progress_dialog_pop(GNCProgressDialog *progress)
Create a new "virtual" progress bar that, as it becomes full, will fill the current bar by the fraction specified by weight. All calls to gnc_progress_dialog_set_value() will operate on the new bar until gnc_progress_dialog_pop() is called.
This can be used to split an operation into weighted sub-operations. For example, if a particular suboperation should fill 30% of the bar, call gnc_progress_dialog_push() with a weight of 0.3. Calls to gnc_progress_dialog_set_value() will fill the virtual bar, which in turn trickles up at the 0.3 rate.
Multiple calls to gnc_progress_dialog_push() can be used to create a stack of virtual bars, each subordinate to the last. This allows a task to be split into any number of levels of sub-tasks.
- Parameters
-
progress | a ::GNCProgressDialog |
weight | the requested fraction of the current bar that the new bar will represent (The fraction actually assigned will be the lesser of the requested amount and the amount of the bar that is unfilled.) |
- Returns
- the number of times that gnc_progress_dialog_pop() would have to be called to return to the top level.
Definition at line 648 of file dialog-progress.c.
653 g_return_val_if_fail(progress, 0);
654 g_return_val_if_fail(weight > 0, 0);
657 bar = GTK_PROGRESS_BAR(progress->progress_bar);
663 newbar->offset = progress->bar_value;
664 if (newbar->offset + weight > 1)
666 newbar->weight = 1 - newbar->offset;
668 newbar->weight = weight;
669 progress->bars = g_list_prepend(progress->bars, newbar);
672 progress->total_offset = gtk_progress_bar_get_fraction(bar);
673 progress->total_weight *= newbar->weight;
676 progress->bar_value = 0;
678 return g_list_length(progress->bars);
Show the progress log and delete any existing text. If the dialog was created via gnc_progress_dialog_new(), the log is not shown by default. Calling this function will make it appear.
- Parameters
-
progress | a ::GNCProgressDialog |
Definition at line 434 of file dialog-progress.c.
438 g_return_if_fail(progress);
440 if (progress->log == NULL)
444 buf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(progress->log));
445 gtk_text_buffer_set_text(buf,
"", -1);
446 gtk_text_buffer_set_modified(buf, FALSE);
449 gtk_widget_show(progress->log);
450 gtk_widget_show(gtk_widget_get_parent(progress->log));
void gnc_progress_dialog_update(GNCProgressDialog *progress)
Pop up to the top level and clear the progress bar.
- Parameters
-
progress | a ::GNCProgressDialog |
Definition at line 729 of file dialog-progress.c.
731 g_return_if_fail(progress);
void gnc_progress_dialog_set_value(GNCProgressDialog *progress, gdouble value)
guint gnc_progress_dialog_pop(GNCProgressDialog *progress)
Remove any indication that progress has paused by removing any existing "(paused)" suffix from the suboperation text, the window title, and the primary text.
- Parameters
-
progress | a ::GNCProgressDialog |
Definition at line 526 of file dialog-progress.c.
530 g_return_if_fail(progress);
532 suffix = g_strconcat(
" ", _(
"(paused)"), NULL);
535 if (progress->sub_label)
537 const gchar *txt = gtk_label_get_text(GTK_LABEL(progress->sub_label));
539 if (txt && g_str_has_suffix(txt, suffix))
541 gchar *newtxt = g_strndup(txt, strlen(txt) - strlen(suffix));
548 if (progress->dialog)
550 const gchar *txt = gtk_window_get_title(GTK_WINDOW(progress->dialog));
552 if (txt && g_str_has_suffix(txt, suffix))
554 gchar *newtxt = g_strndup(txt, strlen(txt) - strlen(suffix));
555 gtk_window_set_title(GTK_WINDOW(progress->dialog), newtxt);
561 if (progress->primary_label)
563 const gchar *txt = gtk_label_get_text(GTK_LABEL(progress->primary_label));
565 if (txt && g_str_has_suffix(txt, suffix))
567 gchar *newtxt = g_strndup(txt, strlen(txt) - strlen(suffix));
void gnc_progress_dialog_set_sub(GNCProgressDialog *progress, const gchar *str)
void gnc_progress_dialog_set_primary(GNCProgressDialog *progress, const gchar *str)
void gnc_progress_dialog_update(GNCProgressDialog *progress)
void gnc_progress_dialog_set_cancel_func |
( |
GNCProgressDialog * |
progress, |
|
|
GNCProgressCancelFunc |
cancel_func, |
|
|
gpointer |
user_data |
|
) |
| |
Show a Cancel button and set the C function which will be called when it is pressed by the user. The cancel function must return a boolean value. If the value is TRUE
, the window is hidden.
- Parameters
-
progress | a ::GNCProgressDialog |
cancel_func | the callback function |
user_data | user data to be passed to cancel_func |
Definition at line 580 of file dialog-progress.c.
584 g_return_if_fail(progress);
586 if (progress->cancel_button == NULL)
589 progress->cancel_func = cancel_func;
590 progress->user_data = user_data;
593 gtk_widget_show(progress->cancel_button);
void gnc_progress_dialog_set_cancel_scm_func |
( |
GNCProgressDialog * |
progress, |
|
|
SCM |
cancel_scm_func |
|
) |
| |
Show a Cancel button and set the Guile procedure that will be called when it is pressed by the user. It will be called after any C function registered with gnc_progress_dialog_set_cancel_func(). The procedure must return #t
if the dialog should be hidden. If there is no C or Guile cancel callback (the default state), the Cancel button is hidden.
- Parameters
-
progress | a ::GNCProgressDialog |
cancel_scm_func | the Guile callback procedure |
Definition at line 598 of file dialog-progress.c.
601 g_return_if_fail(progress);
603 if (progress->cancel_button == NULL)
606 if (progress->cancel_scm_func != SCM_UNDEFINED)
607 scm_gc_unprotect_object(progress->cancel_scm_func);
609 if (scm_is_procedure(cancel_scm_func))
611 progress->cancel_scm_func = cancel_scm_func;
612 scm_gc_protect_object(cancel_scm_func);
613 gtk_widget_show(progress->cancel_button);
616 progress->cancel_scm_func = SCM_UNDEFINED;
void gnc_progress_dialog_set_heading |
( |
GNCProgressDialog * |
progress, |
|
|
const char * |
heading |
|
) |
| |
Set the primary text of the progress dialog. If str is NULL
or blank, the label is hidden (this is the default state).
- Parameters
-
progress | a ::GNCProgressDialog |
heading | the text to be displayed |
NOTE: For HIG-compliant dialogs, use gnc_progress_dialog_set_primary() instead.
Definition at line 367 of file dialog-progress.c.
370 g_return_if_fail(progress);
372 if (progress->primary_label == NULL)
375 if (heading == NULL || *heading ==
'\0')
376 gtk_widget_hide(progress->primary_label);
379 gtk_label_set_text(GTK_LABEL(progress->primary_label), heading);
380 gtk_widget_show(progress->primary_label);
void gnc_progress_dialog_update(GNCProgressDialog *progress)
void gnc_progress_dialog_set_primary |
( |
GNCProgressDialog * |
progress, |
|
|
const gchar * |
str |
|
) |
| |
Set the primary text of the progress dialog. The text will be displayed using the HIG-recommended style. If str is NULL
or blank, the label is hidden (this is the default state).
- Parameters
-
progress | a ::GNCProgressDialog |
str | the text to be displayed |
Definition at line 342 of file dialog-progress.c.
345 g_return_if_fail(progress);
347 if (progress->primary_label == NULL)
350 if (str == NULL || *str ==
'\0')
351 gtk_widget_hide(progress->primary_label);
355 char *markup = g_markup_printf_escaped(
"<span weight=\"bold\" size=\"larger\">%s</span>", str);
357 gtk_label_set_markup(GTK_LABEL(progress->primary_label), markup);
359 gtk_widget_show(progress->primary_label);
void gnc_progress_dialog_update(GNCProgressDialog *progress)
void gnc_progress_dialog_set_secondary |
( |
GNCProgressDialog * |
progress, |
|
|
const gchar * |
str |
|
) |
| |
Set the secondary text of the progress dialog. The text will be displayed using the HIG-recommended style. If str is NULL
or blank, the label is hidden (this is the default state).
- Parameters
-
progress | a ::GNCProgressDialog |
str | the text to be displayed |
Definition at line 388 of file dialog-progress.c.
391 g_return_if_fail(progress);
393 if (progress->secondary_label == NULL)
396 if (str == NULL || *str ==
'\0')
397 gtk_widget_hide(progress->secondary_label);
400 gtk_label_set_text(GTK_LABEL(progress->secondary_label), str);
401 gtk_widget_show(progress->secondary_label);
void gnc_progress_dialog_update(GNCProgressDialog *progress)
Set the suboperation text of the progress dialog. The text will be displayed using the HIG-recommended style. If str is NULL
or blank, the label is hidden (this is the default state).
- Parameters
-
progress | a ::GNCProgressDialog |
str | the text to be displayed |
Definition at line 409 of file dialog-progress.c.
412 g_return_if_fail(progress);
414 if (progress->sub_label == NULL)
417 if (str == NULL || *str ==
'\0')
418 gtk_widget_hide(progress->sub_label);
422 char *markup = g_markup_printf_escaped(
"<span style=\"italic\">%s</span>", str);
424 gtk_label_set_markup(GTK_LABEL(progress->sub_label), markup);
426 gtk_widget_show(progress->sub_label);
void gnc_progress_dialog_update(GNCProgressDialog *progress)
void gnc_progress_dialog_set_title |
( |
GNCProgressDialog * |
progress, |
|
|
const char * |
title |
|
) |
| |
Set the title of a pop-up progress dialog. This function has no effect on dialogs registered using gnc_progress_dialog_custom().
- Parameters
-
progress | a ::GNCProgressDialog |
title | the window title to display |
Definition at line 323 of file dialog-progress.c.
325 g_return_if_fail(progress);
327 if (!progress->dialog)
333 gtk_window_set_title(GTK_WINDOW(progress->dialog), title);
335 progress->title_set = TRUE;
void gnc_progress_dialog_update(GNCProgressDialog *progress)
Set the fraction of the progress bar to fill, where 0 is empty and 1 is full. If value is over 1, the bar will pulse instead of fill.
- Parameters
-
progress | a ::GNCProgressDialog |
value | the fraction of the bar to fill |
Definition at line 621 of file dialog-progress.c.
625 g_return_if_fail(progress);
628 bar = GTK_PROGRESS_BAR(progress->progress_bar);
635 gtk_progress_bar_pulse(bar);
638 progress->bar_value = value > 0 ? value : 0;
639 gtk_progress_bar_set_fraction(bar,
640 progress->total_offset + progress->bar_value * progress->total_weight);
void gnc_progress_dialog_update(GNCProgressDialog *progress)
Update the GUI of the progress dialog, and call any pending cancel callbacks. This function will be called automatically by the other functions, including gnc_progress_dialog_set_value.
- Parameters
-
progress | a ::GNCProgressDialog |
Definition at line 742 of file dialog-progress.c.
744 while (gtk_events_pending())
745 gtk_main_iteration();