mirror of https://github.com/Gnucash/gnucash
Add an extensions menu item for testing the progess dialog. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@3041 57a11ea4-9604-0410-9ed3-97b8803252fdzzzoldreleases/1.6
parent
417a9fba57
commit
5b7f7130ba
@ -0,0 +1,364 @@
|
||||
/********************************************************************\
|
||||
* dialog-progress.c -- GnuCash progress dialog *
|
||||
* Copyright (C) 2000 Dave Peticolas *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation; either version 2 of *
|
||||
* the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License*
|
||||
* along with this program; if not, contact: *
|
||||
* *
|
||||
* Free Software Foundation Voice: +1-617-542-5942 *
|
||||
* 59 Temple Place - Suite 330 Fax: +1-617-542-2652 *
|
||||
* Boston, MA 02111-1307, USA gnu@gnu.org *
|
||||
* *
|
||||
\********************************************************************/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <gnome.h>
|
||||
#include <guile/gh.h>
|
||||
|
||||
#include "dialog-progress.h"
|
||||
#include "glade-gnc-dialogs.h"
|
||||
#include "messages.h"
|
||||
|
||||
|
||||
struct _GNCProgressDialog
|
||||
{
|
||||
GtkWidget *dialog;
|
||||
|
||||
GtkWidget *heading_label;
|
||||
GtkWidget *progress_bar;
|
||||
|
||||
GtkWidget *ok_button;
|
||||
GtkWidget *cancel_button;
|
||||
|
||||
GNCProgressCancelFunc cancel_func;
|
||||
gpointer user_data;
|
||||
|
||||
SCM cancel_scm_func;
|
||||
|
||||
gboolean closed;
|
||||
gboolean finished;
|
||||
gboolean destroyed;
|
||||
gboolean title_set;
|
||||
};
|
||||
|
||||
|
||||
static void
|
||||
gnc_progress_maybe_destroy (GNCProgressDialog *progress)
|
||||
{
|
||||
if (!(progress->closed && progress->destroyed))
|
||||
return;
|
||||
|
||||
gtk_widget_destroy(progress->dialog);
|
||||
}
|
||||
|
||||
static void
|
||||
ok_cb(GtkWidget * widget, gpointer data)
|
||||
{
|
||||
GNCProgressDialog *progress = data;
|
||||
|
||||
gtk_widget_hide(progress->dialog);
|
||||
progress->closed = TRUE;
|
||||
gnc_progress_maybe_destroy (progress);
|
||||
}
|
||||
|
||||
static void
|
||||
cancel_cb(GtkWidget * widget, gpointer data)
|
||||
{
|
||||
GNCProgressDialog *progress = data;
|
||||
|
||||
if (progress->cancel_func && !progress->cancel_func (progress->user_data))
|
||||
return;
|
||||
|
||||
if (progress->cancel_scm_func != SCM_UNDEFINED)
|
||||
{
|
||||
SCM result;
|
||||
|
||||
result = gh_call0(progress->cancel_scm_func);
|
||||
|
||||
if (!gh_scm2bool (result))
|
||||
return;
|
||||
}
|
||||
|
||||
gtk_widget_hide(progress->dialog);
|
||||
progress->closed = TRUE;
|
||||
gnc_progress_maybe_destroy (progress);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
delete_cb(GtkWidget *widget, GdkEvent *event, gpointer data)
|
||||
{
|
||||
GNCProgressDialog *progress = data;
|
||||
|
||||
if (progress->finished)
|
||||
{
|
||||
gtk_widget_hide(progress->dialog);
|
||||
progress->closed = TRUE;
|
||||
gnc_progress_maybe_destroy (progress);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if (progress->cancel_func)
|
||||
{
|
||||
if (progress->cancel_func (progress->user_data))
|
||||
{
|
||||
gtk_widget_hide(progress->dialog);
|
||||
progress->closed = TRUE;
|
||||
gnc_progress_maybe_destroy (progress);
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
if (progress->cancel_scm_func != SCM_UNDEFINED)
|
||||
{
|
||||
SCM result;
|
||||
|
||||
result = gh_call0(progress->cancel_scm_func);
|
||||
|
||||
if (gh_scm2bool (result))
|
||||
{
|
||||
gtk_widget_hide(progress->dialog);
|
||||
progress->closed = TRUE;
|
||||
gnc_progress_maybe_destroy (progress);
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
/* Don't delete the window, wait for gnc_progress_dialog_destroy. */
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
destroy_cb(GtkObject *object, gpointer data)
|
||||
{
|
||||
GNCProgressDialog *progress = data;
|
||||
|
||||
/* Make sure the callbacks aren't invoked */
|
||||
progress->cancel_func = NULL;
|
||||
if (progress->cancel_scm_func != SCM_UNDEFINED)
|
||||
scm_unprotect_object (progress->cancel_scm_func);
|
||||
progress->cancel_scm_func = SCM_UNDEFINED;
|
||||
|
||||
g_free(progress);
|
||||
}
|
||||
|
||||
static void
|
||||
gnc_progress_dialog_create(GtkWidget * parent, GNCProgressDialog *progress)
|
||||
{
|
||||
GtkWidget *dialog;
|
||||
GtkObject *tdo;
|
||||
|
||||
dialog = create_Progress_Dialog();
|
||||
progress->dialog = dialog;
|
||||
tdo = GTK_OBJECT (dialog);
|
||||
|
||||
/* parent */
|
||||
if (parent != NULL)
|
||||
gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(parent));
|
||||
|
||||
gtk_signal_connect (tdo, "delete_event",
|
||||
GTK_SIGNAL_FUNC (delete_cb), progress);
|
||||
|
||||
gtk_signal_connect (tdo, "destroy", GTK_SIGNAL_FUNC (destroy_cb), progress);
|
||||
|
||||
progress->heading_label = gtk_object_get_data(tdo, "heading_label");
|
||||
gtk_widget_hide(progress->heading_label);
|
||||
|
||||
progress->progress_bar = gtk_object_get_data(tdo, "progress_bar");
|
||||
gtk_progress_set_show_text (GTK_PROGRESS(progress->progress_bar), TRUE);
|
||||
gtk_progress_configure (GTK_PROGRESS(progress->progress_bar),
|
||||
0.0, 0.0, 100.0);
|
||||
|
||||
progress->ok_button = gtk_object_get_data(tdo, "ok_button");
|
||||
|
||||
gtk_signal_connect(GTK_OBJECT(progress->ok_button), "clicked",
|
||||
GTK_SIGNAL_FUNC(ok_cb), progress);
|
||||
|
||||
progress->cancel_button = gtk_object_get_data(tdo, "cancel_button");
|
||||
|
||||
gtk_signal_connect(GTK_OBJECT(progress->cancel_button), "clicked",
|
||||
GTK_SIGNAL_FUNC(cancel_cb), progress);
|
||||
|
||||
progress->cancel_func = NULL;
|
||||
progress->user_data = NULL;
|
||||
|
||||
progress->cancel_scm_func = SCM_UNDEFINED;
|
||||
|
||||
progress->closed = FALSE;
|
||||
progress->finished = FALSE;
|
||||
progress->destroyed = FALSE;
|
||||
progress->title_set = FALSE;
|
||||
}
|
||||
|
||||
GNCProgressDialog *
|
||||
gnc_progress_dialog_new (GtkWidget * parent)
|
||||
{
|
||||
GNCProgressDialog *progress;
|
||||
|
||||
progress = g_new0(GNCProgressDialog, 1);
|
||||
|
||||
gnc_progress_dialog_create(parent, progress);
|
||||
|
||||
gtk_widget_show(progress->dialog);
|
||||
|
||||
gnc_progress_dialog_update (progress);
|
||||
|
||||
return progress;
|
||||
}
|
||||
|
||||
void
|
||||
gnc_progress_dialog_set_title (GNCProgressDialog *progress, const char *title)
|
||||
{
|
||||
if (progress == NULL)
|
||||
return;
|
||||
|
||||
if (title == NULL)
|
||||
title = "";
|
||||
|
||||
gtk_window_set_title (GTK_WINDOW (progress->dialog), title);
|
||||
|
||||
progress->title_set = TRUE;
|
||||
|
||||
gnc_progress_dialog_update (progress);
|
||||
}
|
||||
|
||||
void
|
||||
gnc_progress_dialog_set_heading (GNCProgressDialog *progress,
|
||||
const char *heading)
|
||||
{
|
||||
if (progress == NULL)
|
||||
return;
|
||||
|
||||
if (heading == NULL || *heading == '\0')
|
||||
gtk_widget_hide (progress->heading_label);
|
||||
else
|
||||
{
|
||||
gtk_label_set_text (GTK_LABEL (progress->heading_label), heading);
|
||||
gtk_widget_show (progress->heading_label);
|
||||
}
|
||||
|
||||
gnc_progress_dialog_update (progress);
|
||||
}
|
||||
|
||||
void
|
||||
gnc_progress_dialog_set_limits (GNCProgressDialog *progress,
|
||||
gfloat min, gfloat max)
|
||||
{
|
||||
if (progress == NULL)
|
||||
return;
|
||||
|
||||
gtk_progress_configure (GTK_PROGRESS (progress->progress_bar),
|
||||
min, min, max);
|
||||
|
||||
gnc_progress_dialog_update (progress);
|
||||
}
|
||||
|
||||
void
|
||||
gnc_progress_dialog_set_cancel_func (GNCProgressDialog *progress,
|
||||
GNCProgressCancelFunc cancel_func,
|
||||
gpointer user_data)
|
||||
{
|
||||
if (progress == NULL)
|
||||
return;
|
||||
|
||||
progress->cancel_func = cancel_func;
|
||||
progress->user_data = user_data;
|
||||
|
||||
if (cancel_func)
|
||||
gtk_widget_show (progress->cancel_button);
|
||||
}
|
||||
|
||||
void
|
||||
gnc_progress_dialog_set_cancel_scm_func (GNCProgressDialog *progress,
|
||||
SCM cancel_scm_func)
|
||||
{
|
||||
if (progress == NULL)
|
||||
return;
|
||||
|
||||
if (progress->cancel_scm_func != SCM_UNDEFINED)
|
||||
scm_unprotect_object (progress->cancel_scm_func);
|
||||
|
||||
if (gh_procedure_p(cancel_scm_func))
|
||||
{
|
||||
progress->cancel_scm_func = cancel_scm_func;
|
||||
scm_protect_object (cancel_scm_func);
|
||||
gtk_widget_show (progress->cancel_button);
|
||||
}
|
||||
else
|
||||
progress->cancel_scm_func = SCM_UNDEFINED;
|
||||
}
|
||||
|
||||
void
|
||||
gnc_progress_dialog_set_value (GNCProgressDialog *progress, gfloat value)
|
||||
{
|
||||
if (progress == NULL)
|
||||
return;
|
||||
|
||||
gtk_progress_set_value (GTK_PROGRESS (progress->progress_bar), value);
|
||||
|
||||
gnc_progress_dialog_update (progress);
|
||||
}
|
||||
|
||||
void
|
||||
gnc_progress_dialog_update (GNCProgressDialog *progress)
|
||||
{
|
||||
while (gtk_events_pending())
|
||||
gtk_main_iteration();
|
||||
}
|
||||
|
||||
void
|
||||
gnc_progress_dialog_finish (GNCProgressDialog *progress)
|
||||
{
|
||||
if (progress == NULL)
|
||||
return;
|
||||
|
||||
gtk_progress_set_percentage (GTK_PROGRESS (progress->progress_bar), 1.0);
|
||||
|
||||
gtk_widget_set_sensitive (progress->ok_button, TRUE);
|
||||
gtk_widget_set_sensitive (progress->cancel_button, FALSE);
|
||||
|
||||
if (GTK_WIDGET_VISIBLE(progress->heading_label))
|
||||
gnc_progress_dialog_set_heading (progress, _("Complete"));
|
||||
|
||||
if (!progress->title_set)
|
||||
gtk_window_set_title (GTK_WINDOW (progress->dialog), _("Complete"));
|
||||
|
||||
gtk_window_set_modal (GTK_WINDOW (progress->dialog), FALSE);
|
||||
|
||||
progress->finished = TRUE;
|
||||
|
||||
gnc_progress_dialog_update (progress);
|
||||
}
|
||||
|
||||
void
|
||||
gnc_progress_dialog_destroy (GNCProgressDialog *progress)
|
||||
{
|
||||
if (progress == NULL)
|
||||
return;
|
||||
|
||||
/* Make sure the callbacks aren't invoked */
|
||||
progress->cancel_func = NULL;
|
||||
if (progress->cancel_scm_func != SCM_UNDEFINED)
|
||||
scm_unprotect_object (progress->cancel_scm_func);
|
||||
progress->cancel_scm_func = SCM_UNDEFINED;
|
||||
|
||||
if (!progress->finished)
|
||||
{
|
||||
gtk_widget_hide (progress->dialog);
|
||||
progress->closed = TRUE;
|
||||
}
|
||||
|
||||
progress->destroyed = TRUE;
|
||||
|
||||
gnc_progress_maybe_destroy (progress);
|
||||
}
|
||||
@ -0,0 +1,85 @@
|
||||
/********************************************************************\
|
||||
* dialog-progress.h -- public GnuCash progress dialog functions *
|
||||
* Copyright (C) 2000 Dave Peticolas *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation; either version 2 of *
|
||||
* the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License*
|
||||
* along with this program; if not, contact: *
|
||||
* *
|
||||
* Free Software Foundation Voice: +1-617-542-5942 *
|
||||
* 59 Temple Place - Suite 330 Fax: +1-617-542-2652 *
|
||||
* Boston, MA 02111-1307, USA gnu@gnu.org *
|
||||
* *
|
||||
\********************************************************************/
|
||||
|
||||
#ifndef __DIALOG_PROGRESS_H__
|
||||
#define __DIALOG_PROGRESS_H__
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
|
||||
typedef struct _GNCProgressDialog GNCProgressDialog;
|
||||
|
||||
typedef gboolean (*GNCProgressCancelFunc) (gpointer user_data);
|
||||
|
||||
|
||||
/* Create and return a dialog for displaying the progress of
|
||||
* an activity. Useful for long-running operations. */
|
||||
GNCProgressDialog * gnc_progress_dialog_new (GtkWidget *parent);
|
||||
|
||||
/* Set the title of the progress dialog. */
|
||||
void gnc_progress_dialog_set_title (GNCProgressDialog *progress,
|
||||
const char *title);
|
||||
|
||||
/* Set the heading (the text above the progress meter) of
|
||||
* the progress dialog. If it is NULL or blank, the heading
|
||||
* is hidden (this is the default state). */
|
||||
void gnc_progress_dialog_set_heading (GNCProgressDialog *progress,
|
||||
const char *heading);
|
||||
|
||||
/* Set the upper and lower bound of the progress meter. */
|
||||
void gnc_progress_dialog_set_limits (GNCProgressDialog *progress,
|
||||
gfloat min, gfloat max);
|
||||
|
||||
/* Set the C function which will be called if the user hits the
|
||||
* 'cancel' button. The cancel function returns a boolean value.
|
||||
* If the value is TRUE, the window is hidden. */
|
||||
void gnc_progress_dialog_set_cancel_func (GNCProgressDialog *progress,
|
||||
GNCProgressCancelFunc cancel_func,
|
||||
gpointer user_data);
|
||||
|
||||
/* Set a guile function which will be called if the user hits cancel.
|
||||
* Will be called after the C function, if any. The function should
|
||||
* return #t if the dialog should be hidden. If there is no C or guile
|
||||
* cancel callback (the default state), the cancel button is inactive. */
|
||||
void gnc_progress_dialog_set_cancel_scm_func (GNCProgressDialog *progress,
|
||||
SCM cancel_scm_func);
|
||||
|
||||
/* Set the value of the progress dialog. */
|
||||
void gnc_progress_dialog_set_value (GNCProgressDialog *progress, gfloat value);
|
||||
|
||||
/* 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. */
|
||||
void gnc_progress_dialog_update (GNCProgressDialog *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. */
|
||||
void gnc_progress_dialog_finish (GNCProgressDialog *progress);
|
||||
|
||||
/* 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. */
|
||||
void gnc_progress_dialog_destroy (GNCProgressDialog *progress);
|
||||
|
||||
#endif
|
||||
Loading…
Reference in new issue