diff options
author | Matthew Barnes <mbarnes@redhat.com> | 2010-10-22 04:21:19 +0800 |
---|---|---|
committer | Matthew Barnes <mbarnes@redhat.com> | 2010-10-23 02:21:22 +0800 |
commit | c881b5bc5e61d04b18d4ab46ad70533e7340d15b (patch) | |
tree | e70a3ed0d2f93dacfe20d856de4d29578beb2e50 /e-util | |
parent | f0714755e2fa8b06425907c2cf189abd3a1b7119 (diff) | |
download | gsoc2013-evolution-c881b5bc5e61d04b18d4ab46ad70533e7340d15b.tar.gz gsoc2013-evolution-c881b5bc5e61d04b18d4ab46ad70533e7340d15b.tar.zst gsoc2013-evolution-c881b5bc5e61d04b18d4ab46ad70533e7340d15b.zip |
Simplify EActivity.
With unintrusive error dialogs gone, we can cut some unnecessary bits
out of EActivity.
I'm also adding a new enum property called "state", which is one of:
E_ACTIVITY_RUNNING
E_ACTIVITY_WAITING
E_ACTIVITY_CANCELLED
E_ACTIVITY_COMPLETED
The state of an activity must be explicitly changed. In particular,
when the user cancels an activity the state should be set only after
confirming the operation has been cancelled and not when cancellation
is requested (e.g. after receiving a G_IO_ERROR_CANCELLED, not when
the GCancellable emits "cancelled"). EActivityBar and EActivityProxy
widgets have been updated to make this distinction clearer in the UI.
E_ACTIVITY_WAITING will be used when activities have to be queued and
dispatched in sequence, which I haven't written yet.
Diffstat (limited to 'e-util')
-rw-r--r-- | e-util/Makefile.am | 18 | ||||
-rw-r--r-- | e-util/e-activity.c | 277 | ||||
-rw-r--r-- | e-util/e-activity.h | 24 | ||||
-rw-r--r-- | e-util/e-file-utils.c | 78 | ||||
-rw-r--r-- | e-util/e-io-activity.c | 191 | ||||
-rw-r--r-- | e-util/e-io-activity.h | 72 | ||||
-rw-r--r-- | e-util/e-util-enums.h | 35 | ||||
-rw-r--r-- | e-util/e-util.h | 1 |
8 files changed, 166 insertions, 530 deletions
diff --git a/e-util/Makefile.am b/e-util/Makefile.am index d96b2b0bc3..3f4388ebe1 100644 --- a/e-util/Makefile.am +++ b/e-util/Makefile.am @@ -2,6 +2,14 @@ eutilincludedir = $(privincludedir)/e-util ecpsdir = $(privdatadir)/ecps ruledir = $(privdatadir) +include $(top_srcdir)/glib-gen.mak +glib_enum_headers=e-util-enums.h +glib_enum_define=E +glib_enum_prefix=e + +ENUM_GENERATED = e-util-enumtypes.h e-util-enumtypes.c +MARSHAL_GENERATED = e-marshal.c e-marshal.h + if OS_WIN32 PLATFORM_SOURCES = e-win32-reloc.c e-win32-defaults.c e-win32-defaults.h endif @@ -28,7 +36,6 @@ eutilinclude_HEADERS = \ e-html-utils.h \ e-icon-factory.h \ e-import.h \ - e-io-activity.h \ e-marshal.h \ e-mktemp.h \ e-module.h \ @@ -49,6 +56,8 @@ eutilinclude_HEADERS = \ e-text-event-processor.h \ e-ui-manager.h \ e-util.h \ + e-util-enums.h \ + e-util-enumtypes.h \ e-unicode.h \ e-xml-utils.h \ gconf-bridge.h @@ -103,7 +112,6 @@ libeutil_la_SOURCES = \ e-html-utils.c \ e-icon-factory.c \ e-import.c \ - e-io-activity.c \ e-marshal.c \ e-mktemp.c \ e-module.c \ @@ -124,15 +132,13 @@ libeutil_la_SOURCES = \ e-ui-manager.c \ e-util.c \ e-unicode.c \ + e-util-enumtypes.c \ e-util-private.h \ e-xml-utils.c \ gconf-bridge.c \ gtk-compat.h \ $(PLATFORM_SOURCES) -MARSHAL_GENERATED = e-marshal.c e-marshal.h -@EVO_MARSHAL_RULE@ - libeutil_la_LDFLAGS = $(NO_UNDEFINED) libeutil_la_LIBADD = \ @@ -149,7 +155,7 @@ EXTRA_DIST = \ e-system.error.xml \ e-marshal.list -BUILT_SOURCES = $(MARSHAL_GENERATED) $(error_DATA) +BUILT_SOURCES = $(ENUM_GENERATED) $(MARSHAL_GENERATED) $(error_DATA) CLEANFILES = $(BUILT_SOURCES) dist-hook: diff --git a/e-util/e-activity.c b/e-util/e-activity.c index 38196e8484..7e0cb1c8be 100644 --- a/e-util/e-activity.c +++ b/e-util/e-activity.c @@ -26,6 +26,7 @@ #include <camel/camel.h> #include "e-util/e-util.h" +#include "e-util/e-util-enumtypes.h" #define E_ACTIVITY_GET_PRIVATE(obj) \ (G_TYPE_INSTANCE_GET_PRIVATE \ @@ -33,36 +34,22 @@ struct _EActivityPrivate { GCancellable *cancellable; + EActivityState state; gchar *icon_name; - gchar *primary_text; - gchar *secondary_text; + gchar *text; gdouble percent; - - guint clickable : 1; - guint completed : 1; }; enum { PROP_0, PROP_CANCELLABLE, - PROP_CLICKABLE, PROP_ICON_NAME, PROP_PERCENT, - PROP_PRIMARY_TEXT, - PROP_SECONDARY_TEXT + PROP_STATE, + PROP_TEXT }; -enum { - CANCELLED, - CLICKED, - COMPLETED, - DESCRIBE, - LAST_SIGNAL -}; - -static gulong signals[LAST_SIGNAL]; - G_DEFINE_TYPE ( EActivity, e_activity, @@ -78,29 +65,7 @@ activity_camel_status_cb (EActivity *activity, g_object_set ( activity, "percent", (gdouble) percent, - "primary-text", description, NULL); -} - -static gboolean -activity_describe_accumulator (GSignalInvocationHint *ihint, - GValue *return_accu, - const GValue *handler_return, - gpointer accu_data) -{ - const gchar *string; - - string = g_value_get_string (handler_return); - g_value_set_string (return_accu, string); - - return (string == NULL); -} - -static void -activity_emit_cancelled (EActivity *activity) -{ - /* This signal should only be emitted via our GCancellable, - * which is why we don't expose this function publicly. */ - g_signal_emit (activity, signals[CANCELLED], 0); + "text", description, NULL); } static void @@ -116,12 +81,6 @@ activity_set_property (GObject *object, g_value_get_object (value)); return; - case PROP_CLICKABLE: - e_activity_set_clickable ( - E_ACTIVITY (object), - g_value_get_boolean (value)); - return; - case PROP_ICON_NAME: e_activity_set_icon_name ( E_ACTIVITY (object), @@ -134,14 +93,14 @@ activity_set_property (GObject *object, g_value_get_double (value)); return; - case PROP_PRIMARY_TEXT: - e_activity_set_primary_text ( + case PROP_STATE: + e_activity_set_state ( E_ACTIVITY (object), - g_value_get_string (value)); + g_value_get_enum (value)); return; - case PROP_SECONDARY_TEXT: - e_activity_set_secondary_text ( + case PROP_TEXT: + e_activity_set_text ( E_ACTIVITY (object), g_value_get_string (value)); return; @@ -163,12 +122,6 @@ activity_get_property (GObject *object, E_ACTIVITY (object))); return; - case PROP_CLICKABLE: - g_value_set_boolean ( - value, e_activity_get_clickable ( - E_ACTIVITY (object))); - return; - case PROP_ICON_NAME: g_value_set_string ( value, e_activity_get_icon_name ( @@ -181,15 +134,15 @@ activity_get_property (GObject *object, E_ACTIVITY (object))); return; - case PROP_PRIMARY_TEXT: - g_value_set_string ( - value, e_activity_get_primary_text ( + case PROP_STATE: + g_value_set_enum ( + value, e_activity_get_state ( E_ACTIVITY (object))); return; - case PROP_SECONDARY_TEXT: + case PROP_TEXT: g_value_set_string ( - value, e_activity_get_secondary_text ( + value, e_activity_get_text ( E_ACTIVITY (object))); return; } @@ -225,55 +178,51 @@ activity_finalize (GObject *object) priv = E_ACTIVITY_GET_PRIVATE (object); g_free (priv->icon_name); - g_free (priv->primary_text); - g_free (priv->secondary_text); + g_free (priv->text); /* Chain up to parent's finalize() method. */ G_OBJECT_CLASS (e_activity_parent_class)->finalize (object); } -static void -activity_completed (EActivity *activity) -{ - activity->priv->completed = TRUE; -} - -static void -activity_clicked (EActivity *activity) -{ - /* Allow subclasses to safely chain up. */ -} - static gchar * activity_describe (EActivity *activity) { GString *string; GCancellable *cancellable; + EActivityState state; const gchar *text; gdouble percent; string = g_string_sized_new (256); cancellable = e_activity_get_cancellable (activity); - text = e_activity_get_primary_text (activity); percent = e_activity_get_percent (activity); + state = e_activity_get_state (activity); + text = e_activity_get_text (activity); if (text == NULL) return NULL; - if (g_cancellable_is_cancelled (cancellable)) { + if (state == E_ACTIVITY_CANCELLED) { /* Translators: This is a cancelled activity. */ g_string_printf (string, _("%s (cancelled)"), text); - } else if (e_activity_is_completed (activity)) { + } else if (state == E_ACTIVITY_COMPLETED) { /* Translators: This is a completed activity. */ g_string_printf (string, _("%s (completed)"), text); + } else if (state == E_ACTIVITY_WAITING) { + /* Translators: This is an activity waiting to run. */ + g_string_printf (string, _("%s (waiting)"), text); + } else if (g_cancellable_is_cancelled (cancellable)) { + /* Translators: This is a running activity which + * the user has requested to cancel. */ + g_string_printf (string, _("%s (cancelling)"), text); } else if (percent <= 0.0) { g_string_printf (string, _("%s"), text); } else { - /* Translators: This is an activity whose percent - * complete is known. */ + /* Translators: This is a running activity whose + * percent complete is known. */ g_string_printf ( - string, _("%s (%d%% complete)"), text, - (gint) (percent)); + string, _("%s (%d%% complete)"), + text, (gint) (percent)); } return g_string_free (string, FALSE); @@ -292,8 +241,6 @@ e_activity_class_init (EActivityClass *class) object_class->dispose = activity_dispose; object_class->finalize = activity_finalize; - class->completed = activity_completed; - class->clicked = activity_clicked; class->describe = activity_describe; g_object_class_install_property ( @@ -309,17 +256,6 @@ e_activity_class_init (EActivityClass *class) g_object_class_install_property ( object_class, - PROP_CLICKABLE, - g_param_spec_boolean ( - "clickable", - NULL, - NULL, - FALSE, - G_PARAM_READWRITE | - G_PARAM_CONSTRUCT)); - - g_object_class_install_property ( - object_class, PROP_ICON_NAME, g_param_spec_string ( "icon-name", @@ -344,61 +280,26 @@ e_activity_class_init (EActivityClass *class) g_object_class_install_property ( object_class, - PROP_PRIMARY_TEXT, - g_param_spec_string ( - "primary-text", - NULL, + PROP_STATE, + g_param_spec_enum ( + "state", NULL, NULL, + E_TYPE_ACTIVITY_STATE, + E_ACTIVITY_RUNNING, G_PARAM_READWRITE | G_PARAM_CONSTRUCT)); g_object_class_install_property ( object_class, - PROP_SECONDARY_TEXT, + PROP_TEXT, g_param_spec_string ( - "secondary-text", + "text", NULL, NULL, NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT)); - - signals[CANCELLED] = g_signal_new ( - "cancelled", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION, - G_STRUCT_OFFSET (EActivityClass, cancelled), - NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); - - signals[CLICKED] = g_signal_new ( - "clicked", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION, - G_STRUCT_OFFSET (EActivityClass, clicked), - NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); - - signals[COMPLETED] = g_signal_new ( - "completed", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION, - G_STRUCT_OFFSET (EActivityClass, completed), - NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); - - signals[DESCRIBE] = g_signal_new ( - "describe", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, - G_STRUCT_OFFSET (EActivityClass, describe), - activity_describe_accumulator, NULL, - e_marshal_STRING__VOID, - G_TYPE_STRING, 0); } static void @@ -417,46 +318,20 @@ EActivity * e_activity_newv (const gchar *format, ...) { EActivity *activity; - gchar *primary_text; + gchar *text; va_list args; activity = e_activity_new (); va_start (args, format); - primary_text = g_strdup_vprintf (format, args); - e_activity_set_primary_text (activity, primary_text); - g_free (primary_text); + text = g_strdup_vprintf (format, args); + e_activity_set_text (activity, text); + g_free (text); va_end (args); return activity; } -void -e_activity_complete (EActivity *activity) -{ - GCancellable *cancellable; - - g_return_if_fail (E_IS_ACTIVITY (activity)); - - cancellable = e_activity_get_cancellable (activity); - - if (g_cancellable_is_cancelled (cancellable)) - return; - - if (activity->priv->completed) - return; - - g_signal_emit (activity, signals[COMPLETED], 0); -} - -void -e_activity_clicked (EActivity *activity) -{ - g_return_if_fail (E_IS_ACTIVITY (activity)); - - g_signal_emit (activity, signals[CLICKED], 0); -} - gchar * e_activity_describe (EActivity *activity) { @@ -470,14 +345,6 @@ e_activity_describe (EActivity *activity) return class->describe (activity); } -gboolean -e_activity_is_completed (EActivity *activity) -{ - g_return_val_if_fail (E_IS_ACTIVITY (activity), FALSE); - - return activity->priv->completed; -} - GCancellable * e_activity_get_cancellable (EActivity *activity) { @@ -506,11 +373,6 @@ e_activity_set_cancellable (EActivity *activity, activity->priv->cancellable = cancellable; - if (G_IS_CANCELLABLE (cancellable)) - g_signal_connect_swapped ( - cancellable, "cancelled", - G_CALLBACK (activity_emit_cancelled), activity); - /* If this is a CamelOperation, listen for status updates * from it and propagate them to our own status properties. */ if (CAMEL_IS_OPERATION (cancellable)) @@ -521,25 +383,6 @@ e_activity_set_cancellable (EActivity *activity, g_object_notify (G_OBJECT (activity), "cancellable"); } -gboolean -e_activity_get_clickable (EActivity *activity) -{ - g_return_val_if_fail (E_IS_ACTIVITY (activity), FALSE); - - return activity->priv->clickable; -} - -void -e_activity_set_clickable (EActivity *activity, - gboolean clickable) -{ - g_return_if_fail (E_IS_ACTIVITY (activity)); - - activity->priv->clickable = clickable; - - g_object_notify (G_OBJECT (activity), "clickable"); -} - const gchar * e_activity_get_icon_name (EActivity *activity) { @@ -579,42 +422,42 @@ e_activity_set_percent (EActivity *activity, g_object_notify (G_OBJECT (activity), "percent"); } -const gchar * -e_activity_get_primary_text (EActivity *activity) +EActivityState +e_activity_get_state (EActivity *activity) { - g_return_val_if_fail (E_IS_ACTIVITY (activity), NULL); + g_return_val_if_fail (E_IS_ACTIVITY (activity), 0); - return activity->priv->primary_text; + return activity->priv->state; } void -e_activity_set_primary_text (EActivity *activity, - const gchar *primary_text) +e_activity_set_state (EActivity *activity, + EActivityState state) { g_return_if_fail (E_IS_ACTIVITY (activity)); - g_free (activity->priv->primary_text); - activity->priv->primary_text = g_strdup (primary_text); + activity->priv->state = state; - g_object_notify (G_OBJECT (activity), "primary-text"); + g_object_notify (G_OBJECT (activity), "state"); } const gchar * -e_activity_get_secondary_text (EActivity *activity) +e_activity_get_text (EActivity *activity) { g_return_val_if_fail (E_IS_ACTIVITY (activity), NULL); - return activity->priv->secondary_text; + return activity->priv->text; } void -e_activity_set_secondary_text (EActivity *activity, - const gchar *secondary_text) +e_activity_set_text (EActivity *activity, + const gchar *text) { g_return_if_fail (E_IS_ACTIVITY (activity)); - g_free (activity->priv->secondary_text); - activity->priv->secondary_text = g_strdup (secondary_text); + g_free (activity->priv->text); + activity->priv->text = g_strdup (text); - g_object_notify (G_OBJECT (activity), "secondary-text"); + g_object_notify (G_OBJECT (activity), "text"); } + diff --git a/e-util/e-activity.h b/e-util/e-activity.h index 4573fada57..63195b770a 100644 --- a/e-util/e-activity.h +++ b/e-util/e-activity.h @@ -23,6 +23,7 @@ #define E_ACTIVITY_H #include <gtk/gtk.h> +#include <e-util/e-util-enums.h> /* Standard GObject macros */ #define E_TYPE_ACTIVITY \ @@ -57,10 +58,7 @@ struct _EActivity { struct _EActivityClass { GObjectClass parent_class; - /* Signals */ - void (*cancelled) (EActivity *activity); - void (*completed) (EActivity *activity); - void (*clicked) (EActivity *activity); + /* Methods */ gchar * (*describe) (EActivity *activity); }; @@ -68,28 +66,22 @@ GType e_activity_get_type (void); EActivity * e_activity_new (void); EActivity * e_activity_newv (const gchar *format, ...) G_GNUC_PRINTF (1, 2); -void e_activity_complete (EActivity *activity); -void e_activity_clicked (EActivity *activity); gchar * e_activity_describe (EActivity *activity); -gboolean e_activity_is_completed (EActivity *activity); GCancellable * e_activity_get_cancellable (EActivity *activity); void e_activity_set_cancellable (EActivity *activity, GCancellable *cancellable); -gboolean e_activity_get_clickable (EActivity *activity); -void e_activity_set_clickable (EActivity *activity, - gboolean clickable); const gchar * e_activity_get_icon_name (EActivity *activity); void e_activity_set_icon_name (EActivity *activity, const gchar *icon_name); gdouble e_activity_get_percent (EActivity *activity); void e_activity_set_percent (EActivity *activity, gdouble percent); -const gchar * e_activity_get_primary_text (EActivity *activity); -void e_activity_set_primary_text (EActivity *activity, - const gchar *primary_text); -const gchar * e_activity_get_secondary_text (EActivity *activity); -void e_activity_set_secondary_text (EActivity *activity, - const gchar *secondary_text); +EActivityState e_activity_get_state (EActivity *activity); +void e_activity_set_state (EActivity *activity, + EActivityState state); +const gchar * e_activity_get_text (EActivity *activity); +void e_activity_set_text (EActivity *activity, + const gchar *text); G_END_DECLS diff --git a/e-util/e-file-utils.c b/e-util/e-file-utils.c index e647b8deb1..2d5ff30ff7 100644 --- a/e-util/e-file-utils.c +++ b/e-util/e-file-utils.c @@ -51,40 +51,56 @@ #include <glib/gstdio.h> #include <glib/gi18n-lib.h> +#include "e-activity.h" #include "e-file-utils.h" -#include "e-io-activity.h" + +typedef struct _AsyncContext AsyncContext; + +struct _AsyncContext { + EActivity *activity; + gchar *new_etag; +}; + +static void +async_context_free (AsyncContext *context) +{ + if (context->activity != NULL) + g_object_unref (context->activity); + + g_free (context->new_etag); + + g_slice_free (AsyncContext, context); +} static void file_replace_contents_cb (GFile *file, GAsyncResult *result, - EActivity *activity) + GSimpleAsyncResult *simple) { - gchar *new_etag; - gboolean success; + AsyncContext *context; + gchar *new_etag = NULL; GError *error = NULL; - success = g_file_replace_contents_finish ( - file, result, &new_etag, &error); + context = g_simple_async_result_get_op_res_gpointer (simple); - result = e_io_activity_get_async_result (E_IO_ACTIVITY (activity)); + g_file_replace_contents_finish (file, result, &new_etag, &error); - if (error == NULL) { - g_object_set_data_full ( - G_OBJECT (result), - "__new_etag__", new_etag, - (GDestroyNotify) g_free); - } else { - g_simple_async_result_set_from_error ( - G_SIMPLE_ASYNC_RESULT (result), error); + if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) + e_activity_set_state (context->activity, E_ACTIVITY_CANCELLED); + else + e_activity_set_state (context->activity, E_ACTIVITY_COMPLETED); + + if (error == NULL) + context->new_etag = new_etag; + else { + g_warn_if_fail (new_etag == NULL); + g_simple_async_result_set_from_error (simple, error); g_error_free (error); } - g_simple_async_result_set_op_res_gboolean ( - G_SIMPLE_ASYNC_RESULT (result), success); - - e_activity_complete (activity); + g_simple_async_result_complete (simple); - g_object_unref (activity); + g_object_unref (simple); } /** @@ -115,9 +131,9 @@ e_file_replace_contents_async (GFile *file, GAsyncReadyCallback callback, gpointer user_data) { - EActivity *activity; GSimpleAsyncResult *simple; GCancellable *cancellable; + AsyncContext *context; const gchar *format; gchar *description; gchar *basename; @@ -148,21 +164,26 @@ e_file_replace_contents_async (GFile *file, cancellable = g_cancellable_new (); + context = g_slice_new0 (AsyncContext); + context->activity = e_activity_new (); + + e_activity_set_text (context->activity, description); + e_activity_set_cancellable (context->activity, cancellable); + simple = g_simple_async_result_new ( G_OBJECT (file), callback, user_data, e_file_replace_contents_async); - activity = e_io_activity_new ( - description, G_ASYNC_RESULT (simple), cancellable); + g_simple_async_result_set_op_res_gpointer ( + simple, context, (GDestroyNotify) async_context_free); g_file_replace_contents_async ( file, contents, length, etag, make_backup, flags, cancellable, (GAsyncReadyCallback) file_replace_contents_cb, - activity); + simple); g_object_unref (cancellable); - g_object_unref (simple); g_free (description); g_free (basename); @@ -170,7 +191,7 @@ e_file_replace_contents_async (GFile *file, g_free (hostname); g_free (uri); - return activity; + return context->activity; } /** @@ -194,18 +215,19 @@ e_file_replace_contents_finish (GFile *file, GError **error) { GSimpleAsyncResult *simple; + AsyncContext *context; g_return_val_if_fail (G_IS_FILE (file), FALSE); g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (result), FALSE); simple = G_SIMPLE_ASYNC_RESULT (result); + context = g_simple_async_result_get_op_res_gpointer (simple); if (g_simple_async_result_propagate_error (simple, error)) return FALSE; if (new_etag != NULL) - *new_etag = g_object_steal_data ( - G_OBJECT (result), "__new_etag__"); + *new_etag = g_strdup (context->new_etag); return TRUE; } diff --git a/e-util/e-io-activity.c b/e-util/e-io-activity.c deleted file mode 100644 index e519fea18b..0000000000 --- a/e-util/e-io-activity.c +++ /dev/null @@ -1,191 +0,0 @@ -/* - * e-io-activity.c - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#include "e-io-activity.h" - -#define E_IO_ACTIVITY_GET_PRIVATE(obj) \ - (G_TYPE_INSTANCE_GET_PRIVATE \ - ((obj), E_TYPE_IO_ACTIVITY, EIOActivityPrivate)) - -struct _EIOActivityPrivate { - GAsyncResult *async_result; -}; - -enum { - PROP_0, - PROP_ASYNC_RESULT -}; - -G_DEFINE_TYPE ( - EIOActivity, - e_io_activity, - E_TYPE_ACTIVITY) - -static void -io_activity_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec) -{ - switch (property_id) { - case PROP_ASYNC_RESULT: - e_io_activity_set_async_result ( - E_IO_ACTIVITY (object), - g_value_get_object (value)); - return; - } - - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); -} - -static void -io_activity_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec) -{ - switch (property_id) { - case PROP_ASYNC_RESULT: - g_value_set_object ( - value, e_io_activity_get_async_result ( - E_IO_ACTIVITY (object))); - return; - } - - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); -} - -static void -io_activity_dispose (GObject *object) -{ - EIOActivityPrivate *priv; - - priv = E_IO_ACTIVITY_GET_PRIVATE (object); - - if (priv->async_result != NULL) { - g_object_unref (priv->async_result); - priv->async_result = NULL; - } - - /* Chain up to parent's dispose() method. */ - G_OBJECT_CLASS (e_io_activity_parent_class)->dispose (object); -} - -static void -io_activity_completed (EActivity *activity) -{ - EIOActivity *io_activity; - GAsyncResult *async_result; - - /* Chain up to parent's completed() method. */ - E_ACTIVITY_CLASS (e_io_activity_parent_class)->completed (activity); - - io_activity = E_IO_ACTIVITY (activity); - async_result = e_io_activity_get_async_result (io_activity); - - /* We know how to invoke a GSimpleAsyncResult. For any other - * type of GAsyncResult the caller will have to take measures - * to invoke it himself. */ - if (G_IS_SIMPLE_ASYNC_RESULT (async_result)) - g_simple_async_result_complete ( - G_SIMPLE_ASYNC_RESULT (async_result)); -} - -static void -e_io_activity_class_init (EIOActivityClass *class) -{ - GObjectClass *object_class; - EActivityClass *activity_class; - - g_type_class_add_private (class, sizeof (EIOActivityPrivate)); - - object_class = G_OBJECT_CLASS (class); - object_class->set_property = io_activity_set_property; - object_class->get_property = io_activity_get_property; - object_class->dispose = io_activity_dispose; - - activity_class = E_ACTIVITY_CLASS (class); - activity_class->completed = io_activity_completed; - - g_object_class_install_property ( - object_class, - PROP_ASYNC_RESULT, - g_param_spec_object ( - "async-result", - "Asynchronous Result", - NULL, - G_TYPE_ASYNC_RESULT, - G_PARAM_READWRITE | - G_PARAM_CONSTRUCT)); -} - -static void -e_io_activity_init (EIOActivity *io_activity) -{ - io_activity->priv = E_IO_ACTIVITY_GET_PRIVATE (io_activity); -} - -EActivity * -e_io_activity_new (const gchar *primary_text, - GAsyncResult *async_result, - GCancellable *cancellable) -{ - g_return_val_if_fail (primary_text != NULL, NULL); - - if (async_result != NULL) - g_return_val_if_fail (G_IS_ASYNC_RESULT (async_result), NULL); - - if (cancellable != NULL) - g_return_val_if_fail (G_IS_CANCELLABLE (cancellable), NULL); - - return g_object_new ( - E_TYPE_IO_ACTIVITY, - "async-result", async_result, "cancellable", - cancellable, "primary-text", primary_text, NULL); -} - -GAsyncResult * -e_io_activity_get_async_result (EIOActivity *io_activity) -{ - g_return_val_if_fail (E_IS_IO_ACTIVITY (io_activity), NULL); - - return io_activity->priv->async_result; -} - -void -e_io_activity_set_async_result (EIOActivity *io_activity, - GAsyncResult *async_result) -{ - g_return_if_fail (E_IS_IO_ACTIVITY (io_activity)); - - if (async_result != NULL) { - g_return_if_fail (G_IS_ASYNC_RESULT (async_result)); - g_object_ref (async_result); - } - - if (io_activity->priv->async_result != NULL) - g_object_unref (io_activity->priv->async_result); - - io_activity->priv->async_result = async_result; - - g_object_notify (G_OBJECT (io_activity), "async-result"); -} - diff --git a/e-util/e-io-activity.h b/e-util/e-io-activity.h deleted file mode 100644 index 20a7a06082..0000000000 --- a/e-util/e-io-activity.h +++ /dev/null @@ -1,72 +0,0 @@ -/* - * e-io-activity.h - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifndef E_IO_ACTIVITY_H -#define E_IO_ACTIVITH_H - -#include <gio/gio.h> -#include <e-util/e-activity.h> - -/* Standard GObject macros */ -#define E_TYPE_IO_ACTIVITY \ - (e_io_activity_get_type ()) -#define E_IO_ACTIVITY(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST \ - ((obj), E_TYPE_IO_ACTIVITY, EIOActivity)) -#define E_IO_ACTIVITY_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_CAST \ - ((cls), E_TYPE_IO_ACTIVITY, EIOActivityClass)) -#define E_IS_IO_ACTIVITY(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE \ - ((obj), E_TYPE_IO_ACTIVITY)) -#define E_IS_IO_ACTIVITY_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_TYPE \ - ((cls), E_TYPE_IO_ACTIVITY)) -#define E_IS_IO_ACTIVITY_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS \ - ((obj), E_TYPE_IO_ACTIVITY, EIOActivityClass)) - -G_BEGIN_DECLS - -typedef struct _EIOActivity EIOActivity; -typedef struct _EIOActivityClass EIOActivityClass; -typedef struct _EIOActivityPrivate EIOActivityPrivate; - -struct _EIOActivity { - EActivity parent; - EIOActivityPrivate *priv; -}; - -struct _EIOActivityClass { - EActivityClass parent_class; -}; - -GType e_io_activity_get_type (void); -EActivity * e_io_activity_new (const gchar *primary_text, - GAsyncResult *async_result, - GCancellable *cancellable); -GAsyncResult * e_io_activity_get_async_result (EIOActivity *io_activity); -void e_io_activity_set_async_result (EIOActivity *io_activity, - GAsyncResult *async_result); - -G_END_DECLS - -#endif /* E_IO_ACTIVITY_H */ diff --git a/e-util/e-util-enums.h b/e-util/e-util-enums.h new file mode 100644 index 0000000000..bcf214ea33 --- /dev/null +++ b/e-util/e-util-enums.h @@ -0,0 +1,35 @@ +/* + * e-util-enums.h + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) version 3. + * + * 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with the program; if not, see <http://www.gnu.org/licenses/> + * + */ + +#ifndef E_UTIL_ENUMS_H +#define E_UTIL_ENUMS_H + +#include <glib.h> + +G_BEGIN_DECLS + +typedef enum { + E_ACTIVITY_RUNNING, + E_ACTIVITY_WAITING, + E_ACTIVITY_CANCELLED, + E_ACTIVITY_COMPLETED +} EActivityState; + +G_END_DECLS + +#endif /* E_UTIL_ENUMS_H */ diff --git a/e-util/e-util.h b/e-util/e-util.h index 9aa24f3d87..d4f29c9c34 100644 --- a/e-util/e-util.h +++ b/e-util/e-util.h @@ -29,6 +29,7 @@ #include <gconf/gconf-client.h> #include <e-util/e-marshal.h> +#include <e-util/e-util-enums.h> /* e_get_user_data_dir() used to live here, so #include its new home * for backward-compatibility (not that we really care about that). */ |