From fcccad827e84f3a66398d0be85c0e13457d3b559 Mon Sep 17 00:00:00 2001 From: James Liggett Date: Sat, 24 May 2008 21:45:56 -0700 Subject: [PATCH] Add a progress signal to AnjutaCommand and its subclasses in libanjuta --- libanjuta/anjuta-async-command.c | 20 ++++++++++++++++++++ libanjuta/anjuta-command.c | 19 +++++++++++++++++++ libanjuta/anjuta-command.h | 5 +++++ libanjuta/anjuta-sync-command.c | 7 +++++++ 4 files changed, 51 insertions(+) diff --git a/libanjuta/anjuta-async-command.c b/libanjuta/anjuta-async-command.c index d4dc152b..bd675d99 100644 --- a/libanjuta/anjuta-async-command.c +++ b/libanjuta/anjuta-async-command.c @@ -33,6 +33,8 @@ struct _AnjutaAsyncCommandPriv guint return_code; gboolean complete; gboolean new_data_arrived; + gboolean progress_changed; + gfloat progress; }; G_DEFINE_TYPE (AnjutaAsyncCommand, anjuta_async_command, ANJUTA_TYPE_COMMAND); @@ -75,6 +77,12 @@ anjuta_async_command_notification_poll (AnjutaCommand *command) self->priv->new_data_arrived = FALSE; } + if (self->priv->progress_changed) + { + g_signal_emit_by_name (command, "progress", self->priv->progress); + self->priv->progress_changed = FALSE; + } + if (self->priv->complete) { g_signal_emit_by_name (command, "command-finished", @@ -127,6 +135,17 @@ notify_complete (AnjutaCommand *command, guint return_code) } static void +notify_progress (AnjutaCommand *command, gfloat progress) +{ + AnjutaAsyncCommand *self; + + self = ANJUTA_ASYNC_COMMAND (command); + + self->priv->progress_changed = TRUE; + self->priv->progress = progress; +} + +static void anjuta_async_command_class_init (AnjutaAsyncCommandClass *klass) { GObjectClass* object_class = G_OBJECT_CLASS (klass); @@ -137,6 +156,7 @@ anjuta_async_command_class_init (AnjutaAsyncCommandClass *klass) parent_class->start = start_command; parent_class->notify_data_arrived = notify_data_arrived; parent_class->notify_complete = notify_complete; + parent_class->notify_progress = notify_progress; } void diff --git a/libanjuta/anjuta-command.c b/libanjuta/anjuta-command.c index aa99b44a..7a0b5b2b 100644 --- a/libanjuta/anjuta-command.c +++ b/libanjuta/anjuta-command.c @@ -33,6 +33,7 @@ enum { DATA_ARRIVED, COMMAND_FINISHED, + PROGRESS, LAST_SIGNAL }; @@ -72,8 +73,10 @@ anjuta_command_class_init (AnjutaCommandClass *klass) klass->start = NULL; klass->notify_data_arrived = NULL; klass->notify_complete = NULL; + klass->notify_progress = NULL; klass->set_error_message = anjuta_command_set_error_message; klass->get_error_message = anjuta_command_get_error_message; + klass->progress = NULL; anjuta_command_signals[DATA_ARRIVED] = g_signal_new ("data-arrived", @@ -94,6 +97,16 @@ anjuta_command_class_init (AnjutaCommandClass *klass) g_cclosure_marshal_VOID__UINT , G_TYPE_NONE, 1, G_TYPE_UINT); + + anjuta_command_signals[PROGRESS] = + g_signal_new ("progress", + G_OBJECT_CLASS_TYPE (klass), + G_SIGNAL_RUN_FIRST, + G_STRUCT_OFFSET (AnjutaCommandClass, progress), + NULL, NULL, + g_cclosure_marshal_VOID__FLOAT , + G_TYPE_NONE, 1, + G_TYPE_FLOAT); } void @@ -114,6 +127,12 @@ anjuta_command_notify_complete (AnjutaCommand *self, guint return_code) ANJUTA_COMMAND_GET_CLASS (self)->notify_complete (self, return_code); } +void +anjuta_command_notify_progress (AnjutaCommand *self, gfloat progress) +{ + ANJUTA_COMMAND_GET_CLASS (self)->notify_progress (self, progress); +} + void anjuta_command_set_error_message (AnjutaCommand *self, gchar *error_message) { diff --git a/libanjuta/anjuta-command.h b/libanjuta/anjuta-command.h index 3b1c2e80..3a5c58df 100644 --- a/libanjuta/anjuta-command.h +++ b/libanjuta/anjuta-command.h @@ -49,8 +49,12 @@ struct _AnjutaCommandClass void (*start) (AnjutaCommand *self); void (*notify_data_arrived) (AnjutaCommand *self); void (*notify_complete) (AnjutaCommand *self, guint return_code); + void (*notify_progress) (AnjutaCommand *self, gfloat progress); void (*set_error_message) (AnjutaCommand *self, gchar *error_message); gchar * (*get_error_message) (AnjutaCommand *self); + + /* Signals */ + void (*progress) (AnjutaCommand *command, gfloat progress); }; @@ -66,6 +70,7 @@ GType anjuta_command_get_type (void) G_GNUC_CONST; void anjuta_command_start (AnjutaCommand *self); void anjuta_command_notify_data_arrived (AnjutaCommand *self); void anjuta_command_notify_complete (AnjutaCommand *self, guint return_code); +void anjuta_command_notify_progress (AnjutaCommand *self, gfloat progress); void anjuta_command_set_error_message (AnjutaCommand *self, gchar *error_message); gchar *anjuta_command_get_error_message (AnjutaCommand *self); diff --git a/libanjuta/anjuta-sync-command.c b/libanjuta/anjuta-sync-command.c index 44b44cdb..66e5e7dc 100644 --- a/libanjuta/anjuta-sync-command.c +++ b/libanjuta/anjuta-sync-command.c @@ -61,6 +61,12 @@ notify_complete (AnjutaCommand *command, guint return_code) } static void +notify_progress (AnjutaCommand *command, gfloat progress) +{ + g_signal_emit_by_name (command, "progress", progress); +} + +static void anjuta_sync_command_class_init (AnjutaSyncCommandClass *klass) { GObjectClass* object_class = G_OBJECT_CLASS (klass); @@ -71,4 +77,5 @@ anjuta_sync_command_class_init (AnjutaSyncCommandClass *klass) parent_class->start = start_command; parent_class->notify_data_arrived = notify_data_arrived; parent_class->notify_complete = notify_complete; + parent_class->notify_progress = notify_progress; } -- 2.11.4.GIT