GnuCash 2.4.99
dialog-progress.c
00001 /********************************************************************\
00002  * dialog-progress.c -- GnuCash progress dialog                     *
00003  * Copyright (C) 2000 Dave Peticolas                                *
00004  *                                                                  *
00005  * This program is free software; you can redistribute it and/or    *
00006  * modify it under the terms of the GNU General Public License as   *
00007  * published by the Free Software Foundation; either version 2 of   *
00008  * the License, or (at your option) any later version.              *
00009  *                                                                  *
00010  * This program is distributed in the hope that it will be useful,  *
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of   *
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    *
00013  * GNU General Public License for more details.                     *
00014  *                                                                  *
00015  * You should have received a copy of the GNU General Public License*
00016  * along with this program; if not, contact:                        *
00017  *                                                                  *
00018  * Free Software Foundation           Voice:  +1-617-542-5942       *
00019  * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
00020  * Boston, MA  02110-1301,  USA       gnu@gnu.org                   *
00021  *                                                                  *
00022 \********************************************************************/
00023 
00024 #include "config.h"
00025 
00026 #include <gtk/gtk.h>
00027 #include <glib/gi18n.h>
00028 #include <libguile.h>
00029 #include "guile-mappings.h"
00030 
00031 #include "dialog-progress.h"
00032 #include "dialog-utils.h"
00033 
00034 
00035 struct _GNCProgressDialog
00036 {
00037     GtkWidget *dialog;
00038 
00039     GtkWidget *primary_label;
00040     GtkWidget *secondary_label;
00041     GtkWidget *progress_bar;
00042     GtkWidget *sub_label;
00043     GtkWidget *log;
00044 
00045     GtkWidget *ok_button;
00046     GtkWidget *cancel_button;
00047 
00048     /* The stack of virtual progress bars. */
00049     GList     *bars;
00050     /* The fraction of the current bar that is filled. */
00051     gdouble    bar_value;
00052     /* The value of the real (top-level) bar before the last push. */
00053     gdouble    total_offset;
00054     /* The product of all weights in the stack. */
00055     gdouble    total_weight;
00056 
00057     GNCProgressCancelFunc cancel_func;
00058     gpointer user_data;
00059 
00060     SCM cancel_scm_func;
00061 
00062     gboolean use_ok_button;
00063     gboolean closed;
00064     gboolean finished;
00065     gboolean destroyed;
00066     gboolean title_set;
00067 };
00068 
00069 typedef struct
00070 {
00071     gdouble offset;
00072     gdouble weight;
00073 } VirtualBar;
00074 
00075 static void
00076 gnc_progress_maybe_destroy(GNCProgressDialog *progress)
00077 {
00078     g_return_if_fail(progress);
00079 
00080     if (!(progress->closed && progress->destroyed))
00081         return;
00082 
00083     if (progress->dialog != NULL)
00084         gtk_widget_destroy(progress->dialog);
00085 }
00086 
00087 
00088 static void
00089 ok_cb(GtkWidget * widget, gpointer data)
00090 {
00091     GNCProgressDialog *progress = data;
00092 
00093     g_return_if_fail(progress);
00094 
00095     if (progress->dialog != NULL)
00096         gtk_widget_hide(progress->dialog);
00097     progress->closed = TRUE;
00098     gnc_progress_maybe_destroy(progress);
00099 }
00100 
00101 
00102 static void
00103 cancel_cb(GtkWidget * widget, gpointer data)
00104 {
00105     GNCProgressDialog *progress = data;
00106 
00107     g_return_if_fail(progress);
00108 
00109     if (progress->cancel_func && !progress->cancel_func(progress->user_data))
00110         return;
00111 
00112     if (progress->cancel_scm_func != SCM_UNDEFINED)
00113     {
00114         SCM result;
00115 
00116         result = scm_call_0(progress->cancel_scm_func);
00117 
00118         if (!scm_is_true(result))
00119             return;
00120     }
00121 
00122     if (progress->dialog != NULL)
00123         gtk_widget_hide(progress->dialog);
00124     progress->closed = TRUE;
00125     gnc_progress_maybe_destroy(progress);
00126 }
00127 
00128 
00129 static gboolean
00130 delete_cb(GtkWidget *widget, GdkEvent  *event, gpointer data)
00131 {
00132     GNCProgressDialog *progress = data;
00133 
00134     g_return_val_if_fail(progress, TRUE);
00135 
00136     if (progress->finished)
00137     {
00138         if (progress->dialog != NULL)
00139             gtk_widget_hide(progress->dialog);
00140         progress->closed = TRUE;
00141         gnc_progress_maybe_destroy(progress);
00142         return TRUE;
00143     }
00144 
00145     if (progress->cancel_func)
00146     {
00147         if (progress->cancel_func(progress->user_data))
00148         {
00149             if (progress->dialog != NULL)
00150                 gtk_widget_hide(progress->dialog);
00151             progress->closed = TRUE;
00152             gnc_progress_maybe_destroy(progress);
00153             return TRUE;
00154         }
00155     }
00156 
00157     if (progress->cancel_scm_func != SCM_UNDEFINED)
00158     {
00159         SCM result;
00160 
00161         result = scm_call_0(progress->cancel_scm_func);
00162 
00163         if (scm_is_true(result))
00164         {
00165             if (progress->dialog != NULL)
00166                 gtk_widget_hide(progress->dialog);
00167             progress->closed = TRUE;
00168             gnc_progress_maybe_destroy(progress);
00169             return TRUE;
00170         }
00171     }
00172 
00173     /* Don't delete the window, wait for gnc_progress_dialog_destroy. */
00174     return TRUE;
00175 }
00176 
00177 
00178 static void
00179 destroy_cb(GtkObject *object, gpointer data)
00180 {
00181     GNCProgressDialog *progress = data;
00182 
00183     g_return_if_fail(progress);
00184 
00185     /* Make sure the callbacks aren't invoked */
00186     progress->cancel_func = NULL;
00187     if (progress->cancel_scm_func != SCM_UNDEFINED)
00188         scm_gc_unprotect_object(progress->cancel_scm_func);
00189     progress->cancel_scm_func = SCM_UNDEFINED;
00190 
00191     g_free(progress);
00192 }
00193 
00194 
00195 static void
00196 gnc_progress_dialog_create(GtkWidget * parent, GNCProgressDialog *progress)
00197 {
00198     GtkWidget *dialog;
00199     GtkObject *tdo;
00200     GtkBuilder *builder;
00201 
00202     g_return_if_fail(progress);
00203 
00204     builder = gtk_builder_new();
00205     gnc_builder_add_from_file (builder, "dialog-progress.glade", "Progress Dialog");
00206 
00207 
00208     dialog = GTK_WIDGET(gtk_builder_get_object (builder, "Progress Dialog"));
00209     progress->dialog = dialog;
00210     tdo = GTK_OBJECT(dialog);
00211 
00212     /* parent */
00213     if (parent != NULL)
00214         gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(parent));
00215 
00216     g_signal_connect(tdo, "delete_event", G_CALLBACK(delete_cb), progress);
00217 
00218     g_signal_connect(tdo, "destroy", G_CALLBACK(destroy_cb), progress);
00219 
00220     progress->primary_label = GTK_WIDGET(gtk_builder_get_object (builder, "primary_label"));
00221     gtk_widget_hide(progress->primary_label);
00222 
00223     progress->secondary_label = GTK_WIDGET(gtk_builder_get_object (builder, "secondary_label"));
00224     gtk_widget_hide(progress->secondary_label);
00225 
00226     progress->progress_bar = GTK_WIDGET(gtk_builder_get_object (builder, "progress_bar"));
00227     progress->total_offset = 0;
00228     progress->total_weight = 1;
00229     progress->bar_value = 0;
00230 
00231     progress->sub_label = GTK_WIDGET(gtk_builder_get_object (builder, "sub_label"));
00232     gtk_widget_hide(progress->sub_label);
00233 
00234     progress->log = GTK_WIDGET(gtk_builder_get_object (builder, "progress_log"));
00235     gtk_widget_hide(GTK_WIDGET(gtk_builder_get_object (builder, "progress_log_window")));
00236 
00237     progress->ok_button = GTK_WIDGET(gtk_builder_get_object (builder, "ok_button"));
00238 
00239     g_signal_connect(progress->ok_button, "clicked",
00240                      G_CALLBACK(ok_cb), progress);
00241 
00242     if (!progress->use_ok_button)
00243         gtk_widget_hide(progress->ok_button);
00244 
00245     progress->cancel_button = GTK_WIDGET(gtk_builder_get_object (builder, "cancel_button"));
00246 
00247     g_signal_connect(progress->cancel_button, "clicked",
00248                      G_CALLBACK(cancel_cb), progress);
00249 
00250     progress->cancel_func = NULL;
00251     progress->user_data = NULL;
00252 
00253     progress->cancel_scm_func = SCM_UNDEFINED;
00254 
00255     progress->closed = FALSE;
00256     progress->finished = FALSE;
00257     progress->destroyed = FALSE;
00258     progress->title_set = FALSE;
00259 
00260     gtk_builder_connect_signals_full (builder, gnc_builder_connect_full_func, progress);
00261     g_object_unref(G_OBJECT(builder));
00262 }
00263 
00264 
00265 GNCProgressDialog *
00266 gnc_progress_dialog_new(GtkWidget * parent, gboolean use_ok_button)
00267 {
00268     GNCProgressDialog *progress;
00269 
00270     progress = g_new0(GNCProgressDialog, 1);
00271 
00272     progress->use_ok_button = use_ok_button;
00273 
00274     gnc_progress_dialog_create(parent, progress);
00275 
00276     gtk_widget_show(progress->dialog);
00277 
00278     gnc_progress_dialog_update(progress);
00279 
00280     return progress;
00281 }
00282 
00283 
00284 GNCProgressDialog *
00285 gnc_progress_dialog_custom(GtkLabel       *primary,
00286                            GtkLabel       *secondary,
00287                            GtkProgressBar *bar,
00288                            GtkLabel       *suboperation,
00289                            GtkTextView    *log)
00290 {
00291     GNCProgressDialog *progress;
00292 
00293     progress = g_new0(GNCProgressDialog, 1);
00294 
00295     /* Set up widgets. */
00296     progress->dialog = NULL;
00297     progress->primary_label = GTK_WIDGET(primary);
00298     progress->secondary_label = GTK_WIDGET(secondary);
00299     progress->progress_bar = GTK_WIDGET(bar);
00300     progress->sub_label = GTK_WIDGET(suboperation);
00301     progress->log = GTK_WIDGET(log);
00302     progress->ok_button = NULL;
00303     progress->cancel_button = NULL;
00304 
00305     /* Initialize all other items. */
00306     progress->total_offset = 0;
00307     progress->total_weight = 1;
00308     progress->bar_value = 0;
00309     progress->cancel_func = NULL;
00310     progress->user_data = NULL;
00311     progress->cancel_scm_func = SCM_UNDEFINED;
00312     progress->use_ok_button = FALSE;
00313     progress->closed = FALSE;
00314     progress->finished = FALSE;
00315     progress->destroyed = FALSE;
00316     progress->title_set = FALSE;
00317 
00318     return progress;
00319 }
00320 
00321 
00322 void
00323 gnc_progress_dialog_set_title(GNCProgressDialog *progress, const char *title)
00324 {
00325     g_return_if_fail(progress);
00326 
00327     if (!progress->dialog)
00328         return;
00329 
00330     if (title == NULL)
00331         title = "";
00332 
00333     gtk_window_set_title(GTK_WINDOW(progress->dialog), title);
00334 
00335     progress->title_set = TRUE;
00336 
00337     gnc_progress_dialog_update(progress);
00338 }
00339 
00340 
00341 void
00342 gnc_progress_dialog_set_primary(GNCProgressDialog *progress,
00343                                 const gchar *str)
00344 {
00345     g_return_if_fail(progress);
00346 
00347     if (progress->primary_label == NULL)
00348         return;
00349 
00350     if (str == NULL || *str == '\0')
00351         gtk_widget_hide(progress->primary_label);
00352     else
00353     {
00354         /* Display the primary text with the HIG-recommended style. */
00355         char *markup = g_markup_printf_escaped("<span weight=\"bold\" size=\"larger\">%s</span>", str);
00356 
00357         gtk_label_set_markup(GTK_LABEL(progress->primary_label), markup);
00358         g_free(markup);
00359         gtk_widget_show(progress->primary_label);
00360     }
00361 
00362     gnc_progress_dialog_update(progress);
00363 }
00364 
00365 
00366 void
00367 gnc_progress_dialog_set_heading(GNCProgressDialog *progress,
00368                                 const char *heading)
00369 {
00370     g_return_if_fail(progress);
00371 
00372     if (progress->primary_label == NULL)
00373         return;
00374 
00375     if (heading == NULL || *heading == '\0')
00376         gtk_widget_hide(progress->primary_label);
00377     else
00378     {
00379         gtk_label_set_text(GTK_LABEL(progress->primary_label), heading);
00380         gtk_widget_show(progress->primary_label);
00381     }
00382 
00383     gnc_progress_dialog_update(progress);
00384 }
00385 
00386 
00387 void
00388 gnc_progress_dialog_set_secondary(GNCProgressDialog *progress,
00389                                   const gchar *str)
00390 {
00391     g_return_if_fail(progress);
00392 
00393     if (progress->secondary_label == NULL)
00394         return;
00395 
00396     if (str == NULL || *str == '\0')
00397         gtk_widget_hide(progress->secondary_label);
00398     else
00399     {
00400         gtk_label_set_text(GTK_LABEL(progress->secondary_label), str);
00401         gtk_widget_show(progress->secondary_label);
00402     }
00403 
00404     gnc_progress_dialog_update(progress);
00405 }
00406 
00407 
00408 void
00409 gnc_progress_dialog_set_sub(GNCProgressDialog *progress,
00410                             const gchar *str)
00411 {
00412     g_return_if_fail(progress);
00413 
00414     if (progress->sub_label == NULL)
00415         return;
00416 
00417     if (str == NULL || *str == '\0')
00418         gtk_widget_hide(progress->sub_label);
00419     else
00420     {
00421         /* Display the suboperation text with the HIG-recommended style. */
00422         char *markup = g_markup_printf_escaped("<span style=\"italic\">%s</span>", str);
00423 
00424         gtk_label_set_markup(GTK_LABEL(progress->sub_label), markup);
00425         g_free(markup);
00426         gtk_widget_show(progress->sub_label);
00427     }
00428 
00429     gnc_progress_dialog_update(progress);
00430 }
00431 
00432 
00433 void
00434 gnc_progress_dialog_reset_log(GNCProgressDialog *progress)
00435 {
00436     GtkTextBuffer *buf;
00437 
00438     g_return_if_fail(progress);
00439 
00440     if (progress->log == NULL)
00441         return;
00442 
00443     /* Reset the text buffer. */
00444     buf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(progress->log));
00445     gtk_text_buffer_set_text(buf, "", -1);
00446     gtk_text_buffer_set_modified(buf, FALSE);
00447 
00448     /* Show the log and its parent (in case it is in a scrolled window). */
00449     gtk_widget_show(progress->log);
00450     gtk_widget_show(gtk_widget_get_parent(progress->log));
00451 
00452     gnc_progress_dialog_update(progress);
00453 }
00454 
00455 
00456 void
00457 gnc_progress_dialog_append_log(GNCProgressDialog *progress, const gchar *str)
00458 {
00459     GtkTextBuffer *buf;
00460     GtkTextIter    iter;
00461 
00462     g_return_if_fail(progress);
00463 
00464     if (progress->log == NULL || !str || !*str)
00465         return;
00466 
00467     /* Append to the text buffer. */
00468     buf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(progress->log));
00469     gtk_text_buffer_get_end_iter(buf, &iter);
00470     gtk_text_buffer_insert(buf, &iter, str, -1);
00471 
00472     gnc_progress_dialog_update(progress);
00473 }
00474 
00475 
00476 void
00477 gnc_progress_dialog_pause(GNCProgressDialog *progress)
00478 {
00479     gchar *suffix;
00480 
00481     g_return_if_fail(progress);
00482 
00483     suffix = g_strconcat(" ", _("(paused)"), NULL);
00484 
00485     if (progress->sub_label && GTK_WIDGET_VISIBLE(progress->sub_label))
00486     {
00487         const gchar *txt = gtk_label_get_text(GTK_LABEL(progress->sub_label));
00488 
00489         if (txt && !g_str_has_suffix(txt, suffix))
00490         {
00491             gchar *newtxt = g_strconcat(txt, suffix, NULL);
00492             gnc_progress_dialog_set_sub(progress, newtxt);
00493             g_free(newtxt);
00494         }
00495     }
00496     else if (progress->dialog)
00497     {
00498         const gchar *txt = gtk_window_get_title(GTK_WINDOW(progress->dialog));
00499 
00500         if (txt && !g_str_has_suffix(txt, suffix))
00501         {
00502             gchar *newtxt = g_strconcat(txt, suffix, NULL);
00503             gtk_window_set_title(GTK_WINDOW(progress->dialog), newtxt);
00504             g_free(newtxt);
00505         }
00506     }
00507     else if (progress->primary_label &&
00508              GTK_WIDGET_VISIBLE(progress->primary_label))
00509     {
00510         const gchar *txt = gtk_label_get_text(GTK_LABEL(progress->primary_label));
00511 
00512         if (txt && !g_str_has_suffix(txt, suffix))
00513         {
00514             gchar *newtxt = g_strconcat(txt, suffix, NULL);
00515             gnc_progress_dialog_set_primary(progress, newtxt);
00516             g_free(newtxt);
00517         }
00518     }
00519 
00520     g_free(suffix);
00521 
00522     gnc_progress_dialog_update(progress);
00523 }
00524 
00525 void
00526 gnc_progress_dialog_resume(GNCProgressDialog *progress)
00527 {
00528     gchar *suffix;
00529 
00530     g_return_if_fail(progress);
00531 
00532     suffix = g_strconcat(" ", _("(paused)"), NULL);
00533 
00534     /* Remove any pause indication from the suboperation label. */
00535     if (progress->sub_label)
00536     {
00537         const gchar *txt = gtk_label_get_text(GTK_LABEL(progress->sub_label));
00538 
00539         if (txt && g_str_has_suffix(txt, suffix))
00540         {
00541             gchar *newtxt = g_strndup(txt, strlen(txt) - strlen(suffix));
00542             gnc_progress_dialog_set_sub(progress, newtxt);
00543             g_free(newtxt);
00544         }
00545     }
00546 
00547     /* Remove any pause indication from the window title. */
00548     if (progress->dialog)
00549     {
00550         const gchar *txt = gtk_window_get_title(GTK_WINDOW(progress->dialog));
00551 
00552         if (txt && g_str_has_suffix(txt, suffix))
00553         {
00554             gchar *newtxt = g_strndup(txt, strlen(txt) - strlen(suffix));
00555             gtk_window_set_title(GTK_WINDOW(progress->dialog), newtxt);
00556             g_free(newtxt);
00557         }
00558     }
00559 
00560     /* Remove any pause indication from the primary text. */
00561     if (progress->primary_label)
00562     {
00563         const gchar *txt = gtk_label_get_text(GTK_LABEL(progress->primary_label));
00564 
00565         if (txt && g_str_has_suffix(txt, suffix))
00566         {
00567             gchar *newtxt = g_strndup(txt, strlen(txt) - strlen(suffix));
00568             gnc_progress_dialog_set_primary(progress, newtxt);
00569             g_free(newtxt);
00570         }
00571     }
00572 
00573     g_free(suffix);
00574 
00575     gnc_progress_dialog_update(progress);
00576 }
00577 
00578 
00579 void
00580 gnc_progress_dialog_set_cancel_func(GNCProgressDialog *progress,
00581                                     GNCProgressCancelFunc cancel_func,
00582                                     gpointer user_data)
00583 {
00584     g_return_if_fail(progress);
00585 
00586     if (progress->cancel_button == NULL)
00587         return;
00588 
00589     progress->cancel_func = cancel_func;
00590     progress->user_data = user_data;
00591 
00592     if (cancel_func)
00593         gtk_widget_show(progress->cancel_button);
00594 }
00595 
00596 
00597 void
00598 gnc_progress_dialog_set_cancel_scm_func(GNCProgressDialog *progress,
00599                                         SCM cancel_scm_func)
00600 {
00601     g_return_if_fail(progress);
00602 
00603     if (progress->cancel_button == NULL)
00604         return;
00605 
00606     if (progress->cancel_scm_func != SCM_UNDEFINED)
00607         scm_gc_unprotect_object(progress->cancel_scm_func);
00608 
00609     if (scm_is_procedure(cancel_scm_func))
00610     {
00611         progress->cancel_scm_func = cancel_scm_func;
00612         scm_gc_protect_object(cancel_scm_func);
00613         gtk_widget_show(progress->cancel_button);
00614     }
00615     else
00616         progress->cancel_scm_func = SCM_UNDEFINED;
00617 }
00618 
00619 
00620 void
00621 gnc_progress_dialog_set_value(GNCProgressDialog *progress, gdouble value)
00622 {
00623     GtkProgressBar *bar;
00624 
00625     g_return_if_fail(progress);
00626 
00627     /* Get the progress bar widget. */
00628     bar = GTK_PROGRESS_BAR(progress->progress_bar);
00629     if (bar == NULL)
00630         return;
00631 
00632     /* Update the progress bar. If value is over 1,
00633      * the bar will pulse instead of fill. */
00634     if (value > 1)
00635         gtk_progress_bar_pulse(bar);
00636     else
00637     {
00638         progress->bar_value = value > 0 ? value : 0;
00639         gtk_progress_bar_set_fraction(bar,
00640                                       progress->total_offset + progress->bar_value * progress->total_weight);
00641     }
00642 
00643     gnc_progress_dialog_update(progress);
00644 }
00645 
00646 
00647 guint
00648 gnc_progress_dialog_push(GNCProgressDialog *progress, gdouble weight)
00649 {
00650     GtkProgressBar *bar;
00651     VirtualBar     *newbar;
00652 
00653     g_return_val_if_fail(progress, 0);
00654     g_return_val_if_fail(weight > 0, 0);
00655 
00656     /* Get the progress bar widget. */
00657     bar = GTK_PROGRESS_BAR(progress->progress_bar);
00658     if (bar == NULL)
00659         return 0;
00660 
00661     /* Create the new virtual progress bar. */
00662     newbar = g_new0(VirtualBar, 1);
00663     newbar->offset = progress->bar_value;
00664     if (newbar->offset + weight > 1)
00665         /* The requested weight is more than the unfilled portion of the bar. */
00666         newbar->weight = 1 - newbar->offset;
00667     else
00668         newbar->weight = weight;
00669     progress->bars = g_list_prepend(progress->bars, newbar);
00670 
00671     /* Set the total effective offset and weight */
00672     progress->total_offset = gtk_progress_bar_get_fraction(bar);
00673     progress->total_weight *= newbar->weight;
00674 
00675     /* Set the new bar as unfilled. */
00676     progress->bar_value = 0;
00677 
00678     return g_list_length(progress->bars);
00679 }
00680 
00681 
00682 guint
00683 gnc_progress_dialog_pop(GNCProgressDialog *progress)
00684 {
00685     VirtualBar     *bar;
00686 
00687     g_return_val_if_fail(progress, 0);
00688 
00689     /* Get the progress bar widget. */
00690     if (progress->progress_bar == NULL || progress->bars == NULL)
00691         return 0;
00692 
00693     /* Pop the bar off the bar stack. */
00694     bar = progress->bars->data;
00695     progress->bars = g_list_delete_link(progress->bars, progress->bars);
00696 
00697     /* Determine the value of the current bar. */
00698     progress->bar_value = bar->offset + bar->weight * progress->bar_value;
00699 
00700     /* Set the total effective offset and weight. */
00701     if (progress->bars == NULL)
00702     {
00703         progress->total_offset = 0;
00704         progress->total_weight = 1;
00705     }
00706     else
00707     {
00708         progress->total_offset -= bar->offset *
00709                                   ((VirtualBar *) progress->bars->data)->weight;
00710         progress->total_weight /= bar->weight;
00711     }
00712     g_free(bar);
00713 
00714     if (progress->bars == NULL)
00715         return 0;
00716     return g_list_length(progress->bars);
00717 }
00718 
00719 
00720 guint
00721 gnc_progress_dialog_pop_full(GNCProgressDialog *progress)
00722 {
00723     gnc_progress_dialog_set_value(progress, 1);
00724     return gnc_progress_dialog_pop(progress);
00725 }
00726 
00727 
00728 void
00729 gnc_progress_dialog_reset_value(GNCProgressDialog *progress)
00730 {
00731     g_return_if_fail(progress);
00732 
00733     /* Return to the top level. */
00734     while (gnc_progress_dialog_pop(progress));
00735 
00736     /* Reset the bar to empty. */
00737     gnc_progress_dialog_set_value(progress, 0);
00738 }
00739 
00740 
00741 void
00742 gnc_progress_dialog_update(GNCProgressDialog *progress)
00743 {
00744     while (gtk_events_pending())
00745         gtk_main_iteration();
00746 }
00747 
00748 
00749 void
00750 gnc_progress_dialog_finish(GNCProgressDialog *progress)
00751 {
00752     g_return_if_fail(progress);
00753 
00754     if (!progress->use_ok_button)
00755     {
00756         if (progress->dialog != NULL)
00757             gtk_widget_hide(progress->dialog);
00758         progress->closed = TRUE;
00759     }
00760 
00761     gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(progress->progress_bar), 1.0);
00762 
00763     gtk_widget_set_sensitive(progress->ok_button, TRUE);
00764     gtk_widget_set_sensitive(progress->cancel_button, FALSE);
00765 
00766     if (GTK_WIDGET_VISIBLE(progress->primary_label))
00767         gnc_progress_dialog_set_heading(progress, _("Complete"));
00768 
00769     if (!progress->title_set)
00770         gtk_window_set_title(GTK_WINDOW(progress->dialog), _("Complete"));
00771 
00772     gtk_window_set_modal(GTK_WINDOW(progress->dialog), FALSE);
00773 
00774     progress->finished = TRUE;
00775 
00776     gnc_progress_dialog_update(progress);
00777 }
00778 
00779 
00780 void
00781 gnc_progress_dialog_destroy(GNCProgressDialog *progress)
00782 {
00783     g_return_if_fail(progress);
00784 
00785     /* Make sure the callbacks aren't invoked */
00786     progress->cancel_func = NULL;
00787     if (progress->cancel_scm_func != SCM_UNDEFINED)
00788         scm_gc_unprotect_object(progress->cancel_scm_func);
00789     progress->cancel_scm_func = SCM_UNDEFINED;
00790 
00791     if (!progress->finished)
00792     {
00793         if (progress->dialog != NULL)
00794             gtk_widget_hide(progress->dialog);
00795         progress->closed = TRUE;
00796     }
00797 
00798     progress->destroyed = TRUE;
00799 
00800     gnc_progress_maybe_destroy(progress);
00801 }
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines