2011-01-18 01:16:25 -08:00
|
|
|
#include "mooedit/mooeditprogress.h"
|
|
|
|
#include "mooedit/mooeditprogress-gxml.h"
|
|
|
|
#include "mooutils/mooutils-script.h"
|
|
|
|
|
|
|
|
#define MOO_TYPE_EDIT_PROGRESS (moo_edit_progress_get_type ())
|
|
|
|
#define MOO_EDIT_PROGRESS(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), MOO_TYPE_EDIT_PROGRESS, MooEditProgress))
|
|
|
|
#define MOO_EDIT_PROGRESS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MOO_TYPE_EDIT_PROGRESS, MooEditProgressClass))
|
|
|
|
#define MOO_IS_EDIT_PROGRESS(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), MOO_TYPE_EDIT_PROGRESS))
|
|
|
|
#define MOO_IS_EDIT_PROGRESS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MOO_TYPE_EDIT_PROGRESS))
|
|
|
|
#define MOO_EDIT_PROGRESS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MOO_TYPE_EDIT_PROGRESS, MooEditProgressClass))
|
|
|
|
|
|
|
|
#define PROGRESS_TIMEOUT 100
|
|
|
|
#define INITIAL_TIMEOUT 500
|
|
|
|
|
|
|
|
typedef struct MooEditProgressClass MooEditProgressClass;
|
|
|
|
|
|
|
|
struct MooEditProgress
|
|
|
|
{
|
|
|
|
GtkAlignment base;
|
|
|
|
|
|
|
|
ProgressWidgetXml *xml;
|
|
|
|
|
|
|
|
guint timeout;
|
2016-01-03 06:13:38 -08:00
|
|
|
moo::gstr text;
|
2011-01-18 01:16:25 -08:00
|
|
|
GDestroyNotify cancel_op;
|
|
|
|
gpointer cancel_data;
|
2016-01-03 06:13:38 -08:00
|
|
|
|
|
|
|
void update();
|
2011-01-18 01:16:25 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct MooEditProgressClass
|
|
|
|
{
|
|
|
|
GtkAlignmentClass base_class;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void cancel_clicked (MooEditProgress *pr);
|
|
|
|
|
|
|
|
MOO_DEFINE_TYPE_STATIC (MooEditProgress, moo_edit_progress, GTK_TYPE_ALIGNMENT)
|
|
|
|
|
|
|
|
static void
|
|
|
|
moo_edit_progress_init (MooEditProgress *pr)
|
|
|
|
{
|
2016-01-03 06:13:38 -08:00
|
|
|
new(pr)(MooEditProgress);
|
2011-01-18 01:16:25 -08:00
|
|
|
pr->xml = progress_widget_xml_new_with_root (GTK_WIDGET (pr));
|
|
|
|
g_signal_connect_swapped (pr->xml->cancel, "clicked", G_CALLBACK (cancel_clicked), pr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
moo_edit_progress_dispose (GObject *object)
|
|
|
|
{
|
|
|
|
MooEditProgress *pr = MOO_EDIT_PROGRESS (object);
|
|
|
|
|
|
|
|
if (pr->timeout)
|
|
|
|
{
|
|
|
|
g_source_remove (pr->timeout);
|
|
|
|
pr->timeout = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (moo_edit_progress_parent_class)->dispose (object);
|
|
|
|
}
|
|
|
|
|
2016-01-03 06:13:38 -08:00
|
|
|
static void
|
|
|
|
moo_edit_progress_finalize(GObject* object)
|
|
|
|
{
|
|
|
|
MooEditProgress* pr = MOO_EDIT_PROGRESS(object);
|
|
|
|
pr->~MooEditProgress();
|
|
|
|
G_OBJECT_CLASS(moo_edit_progress_parent_class)->finalize(object);
|
|
|
|
}
|
|
|
|
|
2011-01-18 01:16:25 -08:00
|
|
|
static void
|
|
|
|
moo_edit_progress_class_init (MooEditProgressClass *klass)
|
|
|
|
{
|
2016-01-03 06:13:38 -08:00
|
|
|
G_OBJECT_CLASS(klass)->finalize = moo_edit_progress_finalize;
|
|
|
|
G_OBJECT_CLASS(klass)->dispose = moo_edit_progress_dispose;
|
2011-01-18 01:16:25 -08:00
|
|
|
}
|
|
|
|
|
2016-01-04 10:24:03 -08:00
|
|
|
EditProgressPtr
|
2011-01-18 01:16:25 -08:00
|
|
|
_moo_edit_progress_new (void)
|
|
|
|
{
|
2016-01-03 06:13:38 -08:00
|
|
|
return moo::wrap_new(MOO_EDIT_PROGRESS(g_object_new(MOO_TYPE_EDIT_PROGRESS, NULL)));
|
2011-01-18 01:16:25 -08:00
|
|
|
}
|
|
|
|
|
2016-01-03 06:13:38 -08:00
|
|
|
void MooEditProgress::update()
|
2011-01-18 01:16:25 -08:00
|
|
|
{
|
2016-01-04 03:56:42 -08:00
|
|
|
g_return_if_fail (!text.empty());
|
2016-01-03 06:13:38 -08:00
|
|
|
gtk_progress_bar_set_text(xml->progressbar, text);
|
2011-01-18 01:16:25 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-01-03 06:13:38 -08:00
|
|
|
_moo_edit_progress_set_text (MooEditProgress& progress,
|
|
|
|
const char* text)
|
2011-01-18 01:16:25 -08:00
|
|
|
{
|
2016-01-21 03:16:33 -08:00
|
|
|
progress.text.set(text);
|
2016-01-03 06:13:38 -08:00
|
|
|
progress.update();
|
2011-01-18 01:16:25 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
pulse_progress (MooEditProgress *progress)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (MOO_IS_EDIT_PROGRESS (progress), FALSE);
|
|
|
|
g_return_val_if_fail (GTK_IS_WIDGET (progress->xml->progressbar), FALSE);
|
|
|
|
gtk_progress_bar_pulse (GTK_PROGRESS_BAR (progress->xml->progressbar));
|
2016-01-03 06:13:38 -08:00
|
|
|
progress->update();
|
2011-01-18 01:16:25 -08:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
cancel_clicked (MooEditProgress *progress)
|
|
|
|
{
|
|
|
|
g_return_if_fail (MOO_IS_EDIT_PROGRESS (progress));
|
|
|
|
if (progress->cancel_op)
|
|
|
|
progress->cancel_op (progress->cancel_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
show_progress (MooEditProgress *progress)
|
|
|
|
{
|
|
|
|
g_source_remove (progress->timeout);
|
|
|
|
|
|
|
|
progress->timeout =
|
|
|
|
gdk_threads_add_timeout (PROGRESS_TIMEOUT,
|
|
|
|
(GSourceFunc) pulse_progress,
|
|
|
|
progress);
|
2016-01-03 06:13:38 -08:00
|
|
|
progress->update();
|
2011-01-18 01:16:25 -08:00
|
|
|
|
|
|
|
gtk_widget_show (GTK_WIDGET (progress));
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-01-03 06:13:38 -08:00
|
|
|
_moo_edit_progress_set_cancel_func (MooEditProgress& progress,
|
|
|
|
GDestroyNotify cancel_func,
|
|
|
|
gpointer cancel_func_data)
|
2011-01-18 01:16:25 -08:00
|
|
|
{
|
2016-01-03 06:13:38 -08:00
|
|
|
progress.cancel_op = cancel_func;
|
|
|
|
progress.cancel_data = cancel_func_data;
|
|
|
|
gtk_widget_set_sensitive (GTK_WIDGET (progress.xml->cancel),
|
2011-01-18 01:16:25 -08:00
|
|
|
cancel_func != NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-01-03 06:13:38 -08:00
|
|
|
_moo_edit_progress_start (MooEditProgress& progress,
|
|
|
|
const char* text,
|
2011-01-18 01:16:25 -08:00
|
|
|
GDestroyNotify cancel_func,
|
|
|
|
gpointer cancel_func_data)
|
|
|
|
{
|
2016-01-03 06:13:38 -08:00
|
|
|
g_return_if_fail(progress.timeout == 0);
|
2011-01-18 01:16:25 -08:00
|
|
|
|
2016-01-21 03:16:33 -08:00
|
|
|
progress.text.set_new(g_strdup(text));
|
2011-01-18 01:16:25 -08:00
|
|
|
|
2016-01-03 06:13:38 -08:00
|
|
|
_moo_edit_progress_set_cancel_func(progress, cancel_func, cancel_func_data);
|
2011-01-18 01:16:25 -08:00
|
|
|
|
2016-01-03 06:13:38 -08:00
|
|
|
progress.timeout =
|
|
|
|
gdk_threads_add_timeout(INITIAL_TIMEOUT,
|
|
|
|
(GSourceFunc) show_progress,
|
|
|
|
&progress);
|
2011-01-18 01:16:25 -08:00
|
|
|
}
|