aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Barnes <mbarnes@redhat.com>2010-11-01 05:11:35 +0800
committerMatthew Barnes <mbarnes@redhat.com>2010-11-01 10:54:30 +0800
commitccc2b3a14bf19b3db1d837887a07e74f50db078c (patch)
tree639b3deaf2fa7e15ebb149a705095fbb0d717a7b
parent82925c6be94e9e48e4ef521a88a9feec24cf9eef (diff)
downloadgsoc2013-evolution-ccc2b3a14bf19b3db1d837887a07e74f50db078c.tar.gz
gsoc2013-evolution-ccc2b3a14bf19b3db1d837887a07e74f50db078c.tar.zst
gsoc2013-evolution-ccc2b3a14bf19b3db1d837887a07e74f50db078c.zip
EActivity: Add an "alert-sink" property.
This is just for convenience, EActivity does not use this property. Especially useful in async function callbacks when the operation failed and now you have to do something useful with the GError.
-rw-r--r--composer/e-msg-composer.c42
-rw-r--r--doc/reference/shell/eshell-sections.txt3
-rw-r--r--doc/reference/shell/tmpl/e-activity.sgml16
-rw-r--r--doc/reference/shell/tmpl/eshell-unused.sgml9
-rw-r--r--e-util/e-activity.c75
-rw-r--r--e-util/e-activity.h6
-rw-r--r--mail/em-composer-utils.c15
7 files changed, 129 insertions, 37 deletions
diff --git a/composer/e-msg-composer.c b/composer/e-msg-composer.c
index 2bca57d3fd..48410f89dc 100644
--- a/composer/e-msg-composer.c
+++ b/composer/e-msg-composer.c
@@ -3499,9 +3499,12 @@ msg_composer_send_cb (EMsgComposer *composer,
AsyncContext *context)
{
CamelMimeMessage *message;
+ EAlertSink *alert_sink;
GtkhtmlEditor *editor;
GError *error = NULL;
+ alert_sink = e_activity_get_alert_sink (context->activity);
+
message = e_msg_composer_get_message_finish (composer, result, &error);
/* Ignore cancellations. */
@@ -3514,11 +3517,11 @@ msg_composer_send_cb (EMsgComposer *composer,
if (error != NULL) {
g_warn_if_fail (message == NULL);
- async_context_free (context);
e_alert_submit (
- E_ALERT_SINK (composer),
+ alert_sink,
"mail-composer:no-build-message",
error->message, NULL);
+ async_context_free (context);
g_error_free (error);
return;
}
@@ -3548,6 +3551,7 @@ void
e_msg_composer_send (EMsgComposer *composer)
{
AsyncContext *context;
+ EAlertSink *alert_sink;
EActivityBar *activity_bar;
GCancellable *cancellable;
gboolean proceed_with_send = TRUE;
@@ -3563,6 +3567,9 @@ e_msg_composer_send (EMsgComposer *composer)
context = g_slice_new0 (AsyncContext);
context->activity = e_composer_activity_new (composer);
+ alert_sink = E_ALERT_SINK (composer);
+ e_activity_set_alert_sink (context->activity, alert_sink);
+
cancellable = camel_operation_new ();
e_activity_set_cancellable (context->activity, cancellable);
g_object_unref (cancellable);
@@ -3582,9 +3589,12 @@ msg_composer_save_to_drafts_cb (EMsgComposer *composer,
AsyncContext *context)
{
CamelMimeMessage *message;
+ EAlertSink *alert_sink;
GtkhtmlEditor *editor;
GError *error = NULL;
+ alert_sink = e_activity_get_alert_sink (context->activity);
+
message = e_msg_composer_get_message_draft_finish (
composer, result, &error);
@@ -3598,11 +3608,11 @@ msg_composer_save_to_drafts_cb (EMsgComposer *composer,
if (error != NULL) {
g_warn_if_fail (message == NULL);
- async_context_free (context);
e_alert_submit (
- E_ALERT_SINK (composer),
+ alert_sink,
"mail-composer:no-build-message",
error->message, NULL);
+ async_context_free (context);
g_error_free (error);
return;
}
@@ -3632,6 +3642,7 @@ void
e_msg_composer_save_to_drafts (EMsgComposer *composer)
{
AsyncContext *context;
+ EAlertSink *alert_sink;
EActivityBar *activity_bar;
GCancellable *cancellable;
@@ -3640,6 +3651,9 @@ e_msg_composer_save_to_drafts (EMsgComposer *composer)
context = g_slice_new0 (AsyncContext);
context->activity = e_composer_activity_new (composer);
+ alert_sink = E_ALERT_SINK (composer);
+ e_activity_set_alert_sink (context->activity, alert_sink);
+
cancellable = camel_operation_new ();
e_activity_set_cancellable (context->activity, cancellable);
g_object_unref (cancellable);
@@ -3659,9 +3673,12 @@ msg_composer_save_to_outbox_cb (EMsgComposer *composer,
AsyncContext *context)
{
CamelMimeMessage *message;
+ EAlertSink *alert_sink;
GtkhtmlEditor *editor;
GError *error = NULL;
+ alert_sink = e_activity_get_alert_sink (context->activity);
+
message = e_msg_composer_get_message_finish (composer, result, &error);
/* Ignore cancellations. */
@@ -3674,11 +3691,11 @@ msg_composer_save_to_outbox_cb (EMsgComposer *composer,
if (error != NULL) {
g_warn_if_fail (message == NULL);
- async_context_free (context);
e_alert_submit (
- E_ALERT_SINK (composer),
+ alert_sink,
"mail-composer:no-build-message",
error->message, NULL);
+ async_context_free (context);
g_error_free (error);
return;
}
@@ -3708,6 +3725,7 @@ void
e_msg_composer_save_to_outbox (EMsgComposer *composer)
{
AsyncContext *context;
+ EAlertSink *alert_sink;
EActivityBar *activity_bar;
GCancellable *cancellable;
gboolean proceed_with_save = TRUE;
@@ -3723,6 +3741,9 @@ e_msg_composer_save_to_outbox (EMsgComposer *composer)
context = g_slice_new0 (AsyncContext);
context->activity = e_composer_activity_new (composer);
+ alert_sink = E_ALERT_SINK (composer);
+ e_activity_set_alert_sink (context->activity, alert_sink);
+
cancellable = camel_operation_new ();
e_activity_set_cancellable (context->activity, cancellable);
g_object_unref (cancellable);
@@ -3742,8 +3763,11 @@ msg_composer_print_cb (EMsgComposer *composer,
AsyncContext *context)
{
CamelMimeMessage *message;
+ EAlertSink *alert_sink;
GError *error = NULL;
+ alert_sink = e_activity_get_alert_sink (context->activity);
+
message = e_msg_composer_get_message_print_finish (
composer, result, &error);
@@ -3759,7 +3783,7 @@ msg_composer_print_cb (EMsgComposer *composer,
g_warn_if_fail (message == NULL);
async_context_free (context);
e_alert_submit (
- E_ALERT_SINK (composer),
+ alert_sink,
"mail-composer:no-build-message",
error->message, NULL);
g_error_free (error);
@@ -3789,6 +3813,7 @@ e_msg_composer_print (EMsgComposer *composer,
GtkPrintOperationAction print_action)
{
AsyncContext *context;
+ EAlertSink *alert_sink;
EActivityBar *activity_bar;
GCancellable *cancellable;
@@ -3798,6 +3823,9 @@ e_msg_composer_print (EMsgComposer *composer,
context->activity = e_composer_activity_new (composer);
context->print_action = print_action;
+ alert_sink = E_ALERT_SINK (composer);
+ e_activity_set_alert_sink (context->activity, alert_sink);
+
cancellable = camel_operation_new ();
e_activity_set_cancellable (context->activity, cancellable);
g_object_unref (cancellable);
diff --git a/doc/reference/shell/eshell-sections.txt b/doc/reference/shell/eshell-sections.txt
index 6e03f4ddd7..12f66667f6 100644
--- a/doc/reference/shell/eshell-sections.txt
+++ b/doc/reference/shell/eshell-sections.txt
@@ -470,10 +470,11 @@ EActionComboBoxPrivate
<FILE>e-activity</FILE>
EActivity
e_activity_new
-e_activity_newv
e_activity_complete
e_activity_describe
e_activity_is_completed
+e_activity_get_alert_sink
+e_activity_set_alert_sink
e_activity_get_cancellable
e_activity_set_cancellable
e_activity_get_icon_name
diff --git a/doc/reference/shell/tmpl/e-activity.sgml b/doc/reference/shell/tmpl/e-activity.sgml
index 1d4d1b3f3c..3d9fb20107 100644
--- a/doc/reference/shell/tmpl/e-activity.sgml
+++ b/doc/reference/shell/tmpl/e-activity.sgml
@@ -35,17 +35,16 @@ e-activity
@Returns:
-<!-- ##### FUNCTION e_activity_newv ##### -->
+<!-- ##### FUNCTION e_activity_describe ##### -->
<para>
</para>
-@format:
-@Varargs:
+@activity:
@Returns:
-<!-- ##### FUNCTION e_activity_describe ##### -->
+<!-- ##### FUNCTION e_activity_get_alert_sink ##### -->
<para>
</para>
@@ -54,6 +53,15 @@ e-activity
@Returns:
+<!-- ##### FUNCTION e_activity_set_alert_sink ##### -->
+<para>
+
+</para>
+
+@activity:
+@alert_sink:
+
+
<!-- ##### FUNCTION e_activity_get_cancellable ##### -->
<para>
diff --git a/doc/reference/shell/tmpl/eshell-unused.sgml b/doc/reference/shell/tmpl/eshell-unused.sgml
index 2b172b25de..0ce25a6249 100644
--- a/doc/reference/shell/tmpl/eshell-unused.sgml
+++ b/doc/reference/shell/tmpl/eshell-unused.sgml
@@ -307,6 +307,15 @@ e-shell-window.sgml
@activity:
@Returns:
+<!-- ##### FUNCTION e_activity_newv ##### -->
+<para>
+
+</para>
+
+@format:
+@Varargs:
+@Returns:
+
<!-- ##### FUNCTION e_activity_set_allow_cancel ##### -->
<para>
diff --git a/e-util/e-activity.c b/e-util/e-activity.c
index 7e0cb1c8be..74d0eeda26 100644
--- a/e-util/e-activity.c
+++ b/e-util/e-activity.c
@@ -34,6 +34,7 @@
struct _EActivityPrivate {
GCancellable *cancellable;
+ EAlertSink *alert_sink;
EActivityState state;
gchar *icon_name;
@@ -43,6 +44,7 @@ struct _EActivityPrivate {
enum {
PROP_0,
+ PROP_ALERT_SINK,
PROP_CANCELLABLE,
PROP_ICON_NAME,
PROP_PERCENT,
@@ -75,6 +77,12 @@ activity_set_property (GObject *object,
GParamSpec *pspec)
{
switch (property_id) {
+ case PROP_ALERT_SINK:
+ e_activity_set_alert_sink (
+ E_ACTIVITY (object),
+ g_value_get_object (value));
+ return;
+
case PROP_CANCELLABLE:
e_activity_set_cancellable (
E_ACTIVITY (object),
@@ -116,6 +124,12 @@ activity_get_property (GObject *object,
GParamSpec *pspec)
{
switch (property_id) {
+ case PROP_ALERT_SINK:
+ g_value_set_object (
+ value, e_activity_get_alert_sink (
+ E_ACTIVITY (object)));
+ return;
+
case PROP_CANCELLABLE:
g_value_set_object (
value, e_activity_get_cancellable (
@@ -157,6 +171,11 @@ activity_dispose (GObject *object)
priv = E_ACTIVITY_GET_PRIVATE (object);
+ if (priv->alert_sink != NULL) {
+ g_object_unref (priv->alert_sink);
+ priv->alert_sink = NULL;
+ }
+
if (priv->cancellable != NULL) {
g_signal_handlers_disconnect_matched (
priv->cancellable,
@@ -245,6 +264,17 @@ e_activity_class_init (EActivityClass *class)
g_object_class_install_property (
object_class,
+ PROP_ALERT_SINK,
+ g_param_spec_object (
+ "alert-sink",
+ NULL,
+ NULL,
+ E_TYPE_ALERT_SINK,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT));
+
+ g_object_class_install_property (
+ object_class,
PROP_CANCELLABLE,
g_param_spec_object (
"cancellable",
@@ -314,24 +344,6 @@ e_activity_new (void)
return g_object_new (E_TYPE_ACTIVITY, NULL);
}
-EActivity *
-e_activity_newv (const gchar *format, ...)
-{
- EActivity *activity;
- gchar *text;
- va_list args;
-
- activity = e_activity_new ();
-
- va_start (args, format);
- text = g_strdup_vprintf (format, args);
- e_activity_set_text (activity, text);
- g_free (text);
- va_end (args);
-
- return activity;
-}
-
gchar *
e_activity_describe (EActivity *activity)
{
@@ -345,6 +357,33 @@ e_activity_describe (EActivity *activity)
return class->describe (activity);
}
+EAlertSink *
+e_activity_get_alert_sink (EActivity *activity)
+{
+ g_return_val_if_fail (E_IS_ACTIVITY (activity), NULL);
+
+ return activity->priv->alert_sink;
+}
+
+void
+e_activity_set_alert_sink (EActivity *activity,
+ EAlertSink *alert_sink)
+{
+ g_return_if_fail (E_IS_ACTIVITY (activity));
+
+ if (alert_sink != NULL) {
+ g_return_if_fail (E_IS_ALERT_SINK (alert_sink));
+ g_object_ref (alert_sink);
+ }
+
+ if (activity->priv->alert_sink != NULL)
+ g_object_unref (activity->priv->alert_sink);
+
+ activity->priv->alert_sink = alert_sink;
+
+ g_object_notify (G_OBJECT (activity), "alert-sink");
+}
+
GCancellable *
e_activity_get_cancellable (EActivity *activity)
{
diff --git a/e-util/e-activity.h b/e-util/e-activity.h
index 63195b770a..4602a5696e 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-alert-sink.h>
#include <e-util/e-util-enums.h>
/* Standard GObject macros */
@@ -64,9 +65,10 @@ struct _EActivityClass {
GType e_activity_get_type (void);
EActivity * e_activity_new (void);
-EActivity * e_activity_newv (const gchar *format,
- ...) G_GNUC_PRINTF (1, 2);
gchar * e_activity_describe (EActivity *activity);
+EAlertSink * e_activity_get_alert_sink (EActivity *activity);
+void e_activity_set_alert_sink (EActivity *activity,
+ EAlertSink *alert_sink);
GCancellable * e_activity_get_cancellable (EActivity *activity);
void e_activity_set_cancellable (EActivity *activity,
GCancellable *cancellable);
diff --git a/mail/em-composer-utils.c b/mail/em-composer-utils.c
index 85d5bb26d4..99df9ed1a7 100644
--- a/mail/em-composer-utils.c
+++ b/mail/em-composer-utils.c
@@ -598,9 +598,14 @@ composer_save_to_drafts_cleanup (CamelFolder *drafts_folder,
AsyncContext *context)
{
CamelSession *session;
+ EAlertSink *alert_sink;
GCancellable *cancellable;
GError *error = NULL;
+ session = e_msg_composer_get_session (context->composer);
+ alert_sink = e_activity_get_alert_sink (context->activity);
+ cancellable = e_activity_get_cancellable (context->activity);
+
e_mail_folder_append_message_finish (
drafts_folder, result, &context->message_uid, &error);
@@ -615,7 +620,7 @@ composer_save_to_drafts_cleanup (CamelFolder *drafts_folder,
if (error != NULL) {
g_warn_if_fail (context->message_uid == NULL);
e_alert_submit (
- E_ALERT_SINK (context->composer),
+ alert_sink,
"mail-composer:save-to-drafts-error",
error->message, NULL);
async_context_free (context);
@@ -623,9 +628,6 @@ composer_save_to_drafts_cleanup (CamelFolder *drafts_folder,
return;
}
- session = e_msg_composer_get_session (context->composer);
- cancellable = e_activity_get_cancellable (context->activity);
-
/* Mark the previously saved draft message for deletion.
* Note: This is just a nice-to-have; ignore failures. */
e_mail_session_handle_draft_headers (
@@ -761,8 +763,11 @@ composer_save_to_outbox_completed (CamelFolder *outbox_folder,
GAsyncResult *result,
AsyncContext *context)
{
+ EAlertSink *alert_sink;
GError *error = NULL;
+ alert_sink = e_activity_get_alert_sink (context->activity);
+
e_mail_folder_append_message_finish (
outbox_folder, result, NULL, &error);
@@ -775,7 +780,7 @@ composer_save_to_outbox_completed (CamelFolder *outbox_folder,
if (error != NULL) {
e_alert_submit (
- E_ALERT_SINK (context->composer),
+ alert_sink,
"mail-composer:append-to-outbox-error",
error->message, NULL);
g_error_free (error);