aboutsummaryrefslogtreecommitdiffstats
path: root/widgets
diff options
context:
space:
mode:
Diffstat (limited to 'widgets')
-rw-r--r--widgets/misc/ChangeLog27
-rw-r--r--widgets/misc/e-activity-handler.c300
-rw-r--r--widgets/misc/e-activity-handler.h21
-rw-r--r--widgets/misc/e-task-bar.c59
-rw-r--r--widgets/misc/e-task-bar.h4
-rw-r--r--widgets/misc/e-task-widget.c101
-rw-r--r--widgets/misc/e-task-widget.h14
7 files changed, 500 insertions, 26 deletions
diff --git a/widgets/misc/ChangeLog b/widgets/misc/ChangeLog
index 78e8a29da4..bc3cef32dd 100644
--- a/widgets/misc/ChangeLog
+++ b/widgets/misc/ChangeLog
@@ -1,3 +1,30 @@
+2007-12-17 Srinivasa Ragavan <sragavan@novell.com>
+
+ ** Revamped Activity handler and task bar/widget for non-intrusive
+ error reporting
+
+ * e-activity-handler.c: (activity_info_new), (activity_info_free),
+ (task_widget_new_from_activity_info), (setup_task_bar),
+ (e_activity_handler_init),
+ (e_activity_handler_set_error_flush_time),
+ (e_activity_handler_set_logger), (cancel_wrapper),
+ (e_activity_handler_cancelable_operation_started),
+ (e_activity_handler_operation_started), (handle_error),
+ (error_cleanup), (e_activity_handler_make_error),
+ (e_activity_handler_operation_set_error),
+ (e_activity_handler_operation_progressing),
+ (e_activity_handler_operation_finished):
+ * e-activity-handler.h:
+ * e-task-bar.c: (e_task_bar_prepend_task),
+ (e_task_bar_remove_task_from_id), (e_task_bar_remove_task),
+ (e_task_bar_get_task_widget_from_id):
+ * e-task-bar.h:
+ * e-task-widget.c: (e_task_widget_init), (button_press_event_cb),
+ (prepare_popup), (e_task_widget_construct),
+ (e_task_widget_new_with_cancel), (e_task_widget_new),
+ (e_task_widget_update_image):
+ * e-task-widget.h:
+
2007-12-05 Matthew Barnes <mbarnes@redhat.com>
** Fixes part of bug #392747 (extra cleanup work)
diff --git a/widgets/misc/e-activity-handler.c b/widgets/misc/e-activity-handler.c
index b9351878a6..305d2cc5f3 100644
--- a/widgets/misc/e-activity-handler.c
+++ b/widgets/misc/e-activity-handler.c
@@ -45,6 +45,10 @@ struct _ActivityInfo {
gboolean cancellable;
double progress;
GtkWidget *menu;
+ void (*cancel_func) (gpointer data);
+ gpointer data;
+ gpointer error;
+ time_t error_time;
};
typedef struct _ActivityInfo ActivityInfo;
@@ -52,12 +56,18 @@ struct _EActivityHandlerPrivate {
guint next_activity_id;
GList *activity_infos;
GSList *task_bars;
+ ELogger *logger;
+ guint error_timer;
+ guint error_flush_interval;
+
};
G_DEFINE_TYPE (EActivityHandler, e_activity_handler, G_TYPE_OBJECT)
/* Utility functions. */
+static void handle_error (ETaskWidget *task);
+
static unsigned int
get_new_activity_id (EActivityHandler *activity_handler)
{
@@ -126,12 +136,14 @@ activity_info_new (const char *component_id,
info = g_new (ActivityInfo, 1);
info->component_id = g_strdup (component_id);
info->id = id;
- info->icon_pixbuf = g_object_ref (icon);
+ info->icon_pixbuf = icon ? g_object_ref (icon): NULL;
info->information = g_strdup (information);
info->cancellable = cancellable;
info->progress = -1.0; /* (Unknown) */
info->menu = NULL;
-
+ info->error = NULL;
+ info->cancel_func = NULL;
+
return info;
}
@@ -140,7 +152,8 @@ activity_info_free (ActivityInfo *info)
{
g_free (info->component_id);
- g_object_unref (info->icon_pixbuf);
+ if (info->icon_pixbuf)
+ g_object_unref (info->icon_pixbuf);
g_free (info->information);
if (info->menu != NULL)
@@ -153,10 +166,13 @@ static ETaskWidget *
task_widget_new_from_activity_info (ActivityInfo *activity_info)
{
GtkWidget *widget;
+ ETaskWidget *etw;
- widget = e_task_widget_new (activity_info->icon_pixbuf,
+ widget = e_task_widget_new_with_cancel (activity_info->icon_pixbuf,
activity_info->component_id,
- activity_info->information);
+ activity_info->information, activity_info->cancel_func, activity_info->data);
+ etw = (ETaskWidget *) widget;
+ etw->id = activity_info->id;
gtk_widget_show (widget);
g_signal_connect (widget, "button_press_event",
@@ -179,8 +195,21 @@ setup_task_bar (EActivityHandler *activity_handler,
priv = activity_handler->priv;
for (p = g_list_last (priv->activity_infos); p != NULL; p = p->prev) {
- e_task_bar_prepend_task (task_bar,
- task_widget_new_from_activity_info ((ActivityInfo *) p->data));
+ ActivityInfo *info = p->data;
+ ETaskWidget *task_widget = task_widget_new_from_activity_info (info);
+ task_widget->id = info->id;
+ e_task_bar_prepend_task (task_bar, task_widget);
+ if (info->error) {
+ /* Prepare to handle existing errors*/
+ GtkWidget *tool;
+
+ tool = e_task_widget_update_image (task_widget, "stock_dialog-warning", g_object_get_data (info->error, "error"));
+ g_object_set_data ((GObject *) task_widget, "tool", tool);
+ g_object_set_data ((GObject *) task_widget, "error", info->error);
+ g_object_set_data ((GObject *) task_widget, "activity-handler", activity_handler);
+ g_object_set_data ((GObject *) task_widget, "activity", GINT_TO_POINTER(info->id));
+ g_signal_connect_swapped (tool, "clicked", G_CALLBACK(handle_error), task_widget);
+ }
}
}
@@ -260,7 +289,9 @@ e_activity_handler_init (EActivityHandler *activity_handler)
priv->next_activity_id = 1;
priv->activity_infos = NULL;
priv->task_bars = NULL;
-
+ priv->logger = NULL;
+ priv->error_timer = 0;
+ priv->error_flush_interval = 0;
activity_handler->priv = priv;
}
@@ -272,6 +303,17 @@ e_activity_handler_new (void)
}
void
+e_activity_handler_set_error_flush_time (EActivityHandler *handler, int time)
+{
+ handler->priv->error_flush_interval = time;
+}
+void
+e_activity_handler_set_logger (EActivityHandler *handler, ELogger *logger)
+{
+ handler->priv->logger = logger;
+}
+
+void
e_activity_handler_set_message (EActivityHandler *activity_handler,
const char *message)
{
@@ -316,7 +358,93 @@ e_activity_handler_attach_task_bar (EActivityHandler *activity_handler,
setup_task_bar (activity_handler, task_bar);
}
+struct _cancel_wdata {
+ EActivityHandler *handler;
+ ActivityInfo *info;
+ guint id;
+ void (*cancel)(gpointer);
+ gpointer data;
+};
+
+static void
+cancel_wrapper (gpointer pdata)
+{
+ struct _cancel_wdata *data = (struct _cancel_wdata *) pdata;
+ /* This can be invoked in two scenario. Either to cancel or to hide error */
+ if (data->info->error) {
+ /* Hide the error */
+ EActivityHandler *handler = data->handler;
+ int order, len;
+ GSList *sp;
+ GList *p = lookup_activity (handler->priv->activity_infos, data->id, &order);
+ e_logger_log (handler->priv->logger, E_LOG_ERROR, g_object_get_data (data->info->error, "primary"),
+ g_object_get_data (data->info->error, "secondary"));
+ gtk_widget_destroy (data->info->error);
+ printf("%p %p %d\n", data->info->error, data->info, data->info->id);
+ data->info->error = NULL;
+ for (sp = handler->priv->task_bars; sp != NULL; sp = sp->next) {
+ ETaskBar *task_bar;
+
+ task_bar = E_TASK_BAR (sp->data);
+ e_task_bar_remove_task_from_id (task_bar, data->info->id);
+ }
+ activity_info_free (data->info);
+ len = g_list_length (handler->priv->activity_infos);
+ handler->priv->activity_infos = g_list_remove_link (handler->priv->activity_infos, p);
+ if (len == 1)
+ handler->priv->activity_infos = NULL;
+ } else {
+ /* Cancel the operation */
+ data->cancel (data->data);
+ }
+ /* No need to free the data. It will be freed as part of the task widget destroy */
+}
+
/* CORBA methods. */
+guint e_activity_handler_cancelable_operation_started (EActivityHandler *activity_handler,
+ const char *component_id,
+ GdkPixbuf *icon_pixbuf,
+ const char *information,
+ gboolean cancellable,
+ void (*cancel_func)(gpointer),
+ gpointer user_data)
+{
+ EActivityHandlerPrivate *priv;
+ ActivityInfo *activity_info;
+ unsigned int activity_id;
+ GSList *p;
+ struct _cancel_wdata *data;
+ gboolean bfree = FALSE;
+ priv = activity_handler->priv;
+
+ activity_id = get_new_activity_id (activity_handler);
+ activity_info = activity_info_new (component_id, activity_id, icon_pixbuf, information, cancellable);
+
+ data = g_new(struct _cancel_wdata, 1);
+ data->handler = activity_handler;
+ data->id = activity_id;
+ data->info = activity_info;
+ data->cancel = cancel_func;
+ data->data = user_data;
+
+ activity_info->cancel_func = cancel_wrapper;
+ activity_info->data = data;
+ for (p = priv->task_bars; p != NULL; p = p->next) {
+ ETaskWidget *tw = task_widget_new_from_activity_info (activity_info);
+ tw->id = activity_id;
+ if (!bfree) {
+ /* The data will be freed part of the widget destroy */
+ g_object_set_data_full ((GObject *) tw, "free-data", data, g_free);
+ bfree = TRUE;
+ }
+ e_task_bar_prepend_task (E_TASK_BAR (p->data), tw);
+ }
+
+ priv->activity_infos = g_list_prepend (priv->activity_infos, activity_info);
+
+ return activity_id;
+
+}
guint
e_activity_handler_operation_started (EActivityHandler *activity_handler,
@@ -337,16 +465,162 @@ e_activity_handler_operation_started (EActivityHandler *activity_handler,
activity_info = activity_info_new (component_id, activity_id, icon_pixbuf, information, cancellable);
for (p = priv->task_bars; p != NULL; p = p->next) {
- e_task_bar_prepend_task (E_TASK_BAR (p->data),
- task_widget_new_from_activity_info (activity_info));
+ ETaskWidget *tw = task_widget_new_from_activity_info (activity_info);
+ tw->id = activity_id;
+ e_task_bar_prepend_task (E_TASK_BAR (p->data), tw);
+ }
+
+ priv->activity_infos = g_list_prepend (priv->activity_infos, activity_info);
+
+ return activity_id;
+}
+
+static void
+handle_error (ETaskWidget *task)
+{
+ GtkWidget *tool, *error;
+ EActivityHandler *activity_handler;
+ guint id;
+
+ tool = g_object_get_data ((GObject *) task, "tool");
+ error = g_object_get_data ((GObject *) task, "error");
+ activity_handler = g_object_get_data ((GObject *) task, "activity-handler");
+ id = GPOINTER_TO_UINT (g_object_get_data ((GObject *) task, "activity"));
+ e_activity_handler_operation_finished (activity_handler, id);
+ gtk_widget_show (error);
+ e_logger_log (activity_handler->priv->logger, E_LOG_ERROR, g_object_get_data ((GObject *) error, "primary"),
+ g_object_get_data ((GObject *) error, "secondary"));
+}
+
+static gboolean
+error_cleanup (EActivityHandler *activity_handler)
+{
+ EActivityHandlerPrivate *priv = activity_handler->priv;
+ GList *p, *node;
+ GSList *sp;
+ int i;
+ time_t now = time (NULL);
+ gboolean berror = FALSE;
+
+ for (p = priv->activity_infos, i = 0; p != NULL; i++) {
+ ActivityInfo *info;
+
+ info = (ActivityInfo *) p->data;
+ if (info->error)
+ berror = TRUE;
+ if (info->error && info->error_time && (now - info->error_time) > 5 ) {
+ /* Error older than wanted time. So cleanup */
+ e_logger_log (priv->logger, E_LOG_ERROR, g_object_get_data (info->error, "primary"),
+ g_object_get_data (info->error, "secondary"));
+ gtk_widget_destroy (info->error);
+ node = p;
+ p = p->next;
+
+ for (sp = priv->task_bars; sp != NULL; sp = sp->next) {
+ ETaskBar *task_bar;
+
+ task_bar = E_TASK_BAR (sp->data);
+ e_task_bar_remove_task_from_id (task_bar, info->id);
+ }
+ activity_info_free (info);
+ priv->activity_infos = g_list_remove_link (priv->activity_infos, node);
+
+ } else
+ p = p->next;
+ }
+ if (!berror)
+ priv->error_timer = 0;
+ return berror;
+}
+
+guint
+e_activity_handler_make_error (EActivityHandler *activity_handler,
+ const char *component_id,
+ const char *information,
+ GtkWidget *error)
+{
+ EActivityHandlerPrivate *priv;
+ ActivityInfo *activity_info;
+ unsigned int activity_id;
+ GSList *p;
+
+ priv = activity_handler->priv;
+
+ activity_id = get_new_activity_id (activity_handler);
+
+ activity_info = activity_info_new (component_id, activity_id, NULL, information, TRUE);
+ activity_info->error = error;
+ activity_info->error_time = time (NULL);
+
+ for (p = priv->task_bars; p != NULL; p = p->next) {
+ ETaskBar *task_bar;
+ ETaskWidget *task_widget;
+ GtkWidget *tool;
+
+ task_bar = E_TASK_BAR (p->data);
+ task_widget = task_widget_new_from_activity_info (activity_info);
+ task_widget->id = activity_id;
+ e_task_bar_prepend_task (E_TASK_BAR (p->data), task_widget);
+
+ tool = e_task_widget_update_image (task_widget, "stock_dialog-warning", g_object_get_data ((GObject *) error, "primary"));
+ g_object_set_data ((GObject *) task_widget, "tool", tool);
+ g_object_set_data ((GObject *) task_widget, "error", error);
+ g_object_set_data ((GObject *) task_widget, "activity-handler", activity_handler);
+ g_object_set_data ((GObject *) task_widget, "activity", GINT_TO_POINTER(activity_id));
+ g_signal_connect_swapped (tool, "clicked", G_CALLBACK(handle_error), task_widget);
}
priv->activity_infos = g_list_prepend (priv->activity_infos, activity_info);
+ if (!activity_handler->priv->error_timer)
+ activity_handler->priv->error_timer = g_timeout_add (activity_handler->priv->error_flush_interval, (GSourceFunc)error_cleanup, activity_handler);
+
return activity_id;
}
void
+e_activity_handler_operation_set_error(EActivityHandler *activity_handler,
+ guint activity_id,
+ GtkWidget *error)
+{
+ EActivityHandlerPrivate *priv = activity_handler->priv;
+ ActivityInfo *activity_info;
+ GList *p;
+ GSList *sp;
+ int order_number;
+
+ p = lookup_activity (priv->activity_infos, activity_id, &order_number);
+ if (p == NULL) {
+ g_warning ("EActivityHandler: unknown operation %d", activity_id);
+ return;
+ }
+
+ activity_info = (ActivityInfo *) p->data;
+ activity_info->error = error;
+ activity_info->error_time = time (NULL);
+ for (sp = priv->task_bars; sp != NULL; sp = sp->next) {
+ ETaskBar *task_bar;
+ ETaskWidget *task_widget;
+ GtkWidget *tool;
+
+ task_bar = E_TASK_BAR (sp->data);
+ task_widget = e_task_bar_get_task_widget_from_id (task_bar, activity_info->id);
+ if (!task_widget)
+ continue;
+
+ tool = e_task_widget_update_image (task_widget, "stock_dialog-warning", g_object_get_data ((GObject *) error, "primary"));
+ g_object_set_data ((GObject *) task_widget, "tool", tool);
+ g_object_set_data ((GObject *) task_widget, "error", error);
+ g_object_set_data ((GObject *) task_widget, "activity-handler", activity_handler);
+ g_object_set_data ((GObject *) task_widget, "activity", GINT_TO_POINTER(activity_id));
+ g_signal_connect_swapped (tool, "clicked", G_CALLBACK(handle_error), task_widget);
+ }
+
+ if (!activity_handler->priv->error_timer)
+ activity_handler->priv->error_timer = g_timeout_add (activity_handler->priv->error_flush_interval, (GSourceFunc) error_cleanup, activity_handler);
+}
+
+void
e_activity_handler_operation_progressing (EActivityHandler *activity_handler,
guint activity_id,
const char *information,
@@ -376,7 +650,9 @@ e_activity_handler_operation_progressing (EActivityHandler *activity_handler,
ETaskWidget *task_widget;
task_bar = E_TASK_BAR (sp->data);
- task_widget = e_task_bar_get_task_widget (task_bar, order_number);
+ task_widget = e_task_bar_get_task_widget_from_id (task_bar, activity_info->id);
+ if (!task_widget)
+ continue;
e_task_widget_update (task_widget, information, progress);
}
@@ -404,7 +680,7 @@ e_activity_handler_operation_finished (EActivityHandler *activity_handler,
ETaskBar *task_bar;
task_bar = E_TASK_BAR (sp->data);
- e_task_bar_remove_task (task_bar, order_number);
+ e_task_bar_remove_task_from_id (task_bar, activity_id);
}
}
diff --git a/widgets/misc/e-activity-handler.h b/widgets/misc/e-activity-handler.h
index 304882fe57..619359bf28 100644
--- a/widgets/misc/e-activity-handler.h
+++ b/widgets/misc/e-activity-handler.h
@@ -24,7 +24,7 @@
#define _E_ACTIVITY_HANDLER_H_
#include "e-task-bar.h"
-
+#include "e-util/e-logger.h"
#include <glib-object.h>
#ifdef __cplusplus
@@ -71,6 +71,13 @@ guint e_activity_handler_operation_started (EActivityHandler *activity_handler
GdkPixbuf *icon_pixbuf,
const char *information,
gboolean cancellable);
+guint e_activity_handler_cancelable_operation_started (EActivityHandler *activity_handler,
+ const char *component_id,
+ GdkPixbuf *icon_pixbuf,
+ const char *information,
+ gboolean cancellable,
+ void (*cancel_func)(gpointer),
+ gpointer user_data);
void e_activity_handler_operation_progressing (EActivityHandler *activity_handler,
guint activity_id,
@@ -80,6 +87,18 @@ void e_activity_handler_operation_progressing (EActivityHandler *activity_hand
void e_activity_handler_operation_finished (EActivityHandler *activity_handler,
guint activity_id);
+void e_activity_handler_set_logger (EActivityHandler *handler, ELogger *logger);
+guint e_activity_handler_make_error (EActivityHandler *activity_handler,
+ const char *component_id,
+ const char *information,
+ GtkWidget *error);
+void
+e_activity_handler_operation_set_error (EActivityHandler *activity_handler,
+ guint activity_id,
+ GtkWidget *error);
+
+void
+e_activity_handler_set_error_flush_time (EActivityHandler *handler, int time);
#ifdef __cplusplus
}
diff --git a/widgets/misc/e-task-bar.c b/widgets/misc/e-task-bar.c
index 075322dd97..ff18cf7bdb 100644
--- a/widgets/misc/e-task-bar.c
+++ b/widgets/misc/e-task-bar.c
@@ -40,6 +40,7 @@ struct _ETaskBarPrivate
G_DEFINE_TYPE (ETaskBar, e_task_bar, GTK_TYPE_HBOX)
+#if 0
static void
reduce_displayed_activities_per_component (ETaskBar *task_bar)
{
@@ -82,7 +83,7 @@ reduce_displayed_activities_per_component (ETaskBar *task_bar)
g_hash_table_destroy (component_ids_hash);
}
-
+#endif
static void
e_task_bar_class_init (ETaskBarClass *klass)
@@ -185,12 +186,37 @@ e_task_bar_prepend_task (ETaskBar *task_bar,
gtk_widget_queue_resize (GTK_WIDGET (task_widget));
}
- reduce_displayed_activities_per_component (task_bar);
+ /* We don't restrict */
+ /* reduce_displayed_activities_per_component (task_bar);*/
gtk_widget_show (GTK_WIDGET (task_bar->priv->hbox));
}
void
+e_task_bar_remove_task_from_id (ETaskBar *task_bar,
+ guint id)
+{
+ ETaskWidget *task_widget;
+
+ g_return_if_fail (task_bar != NULL);
+ g_return_if_fail (E_IS_TASK_BAR (task_bar));
+
+ task_widget = e_task_bar_get_task_widget_from_id (task_bar, id);
+ if (!task_widget) {
+ printf("Failed...\n");
+ return;
+ }
+
+ gtk_widget_destroy (GTK_WIDGET (task_widget));
+
+ /* We don't restrict here on */
+ /* reduce_displayed_activities_per_component (task_bar); */
+
+ if (g_list_length (GTK_BOX (task_bar->priv->hbox)->children) == 0)
+ gtk_widget_hide (GTK_WIDGET (task_bar->priv->hbox));
+}
+
+void
e_task_bar_remove_task (ETaskBar *task_bar,
int n)
{
@@ -203,13 +229,40 @@ e_task_bar_remove_task (ETaskBar *task_bar,
task_widget = e_task_bar_get_task_widget (task_bar, n);
gtk_widget_destroy (GTK_WIDGET (task_widget));
- reduce_displayed_activities_per_component (task_bar);
+ /* We don't restrict here on */
+ /* reduce_displayed_activities_per_component (task_bar); */
if (g_list_length (GTK_BOX (task_bar->priv->hbox)->children) == 0)
gtk_widget_hide (GTK_WIDGET (task_bar->priv->hbox));
}
ETaskWidget *
+e_task_bar_get_task_widget_from_id (ETaskBar *task_bar,
+ guint id)
+{
+ GtkBoxChild *child_info;
+ ETaskWidget *w = NULL;
+ GList *list;
+
+ g_return_val_if_fail (task_bar != NULL, NULL);
+ g_return_val_if_fail (E_IS_TASK_BAR (task_bar), NULL);
+
+ list = GTK_BOX (task_bar->priv->hbox)->children;
+ while (list) {
+ child_info = list->data;
+ w = (ETaskWidget *) child_info->widget;
+ if (w && w->id == id)
+ break;
+
+ w = NULL;
+ list = list->next;
+ }
+
+ return w;
+}
+
+ETaskWidget *
+
e_task_bar_get_task_widget (ETaskBar *task_bar,
int n)
{
diff --git a/widgets/misc/e-task-bar.h b/widgets/misc/e-task-bar.h
index 50301326d6..4cacf4cf79 100644
--- a/widgets/misc/e-task-bar.h
+++ b/widgets/misc/e-task-bar.h
@@ -66,7 +66,11 @@ void e_task_bar_prepend_task (ETaskBar *task_bar,
ETaskWidget *task_widget);
void e_task_bar_remove_task (ETaskBar *task_bar,
int n);
+ETaskWidget * e_task_bar_get_task_widget_from_id (ETaskBar *task_bar,
+ guint id);
+void e_task_bar_remove_task_from_id (ETaskBar *task_bar,
+ guint id);
ETaskWidget *e_task_bar_get_task_widget (ETaskBar *task_bar,
int n);
diff --git a/widgets/misc/e-task-widget.c b/widgets/misc/e-task-widget.c
index 50d459d3f0..bb9a6026d9 100644
--- a/widgets/misc/e-task-widget.c
+++ b/widgets/misc/e-task-widget.c
@@ -26,12 +26,15 @@
#include "e-task-widget.h"
#include "e-spinner.h"
+#include <e-util/e-icon-factory.h>
#include <gtk/gtkframe.h>
#include <gtk/gtkhbox.h>
#include <gtk/gtklabel.h>
#include <gtk/gtkimage.h>
#include <gtk/gtktooltips.h>
+#include <gtk/gtktoolbutton.h>
+#include <gtk/gtkbox.h>
#include <glib/gi18n.h>
@@ -45,7 +48,11 @@ struct _ETaskWidgetPrivate {
GdkPixbuf *icon_pixbuf;
GtkWidget *label;
+ GtkWidget *box;
GtkWidget *image;
+
+ void (*cancel_func) (gpointer data);
+ gpointer data;
};
G_DEFINE_TYPE (ETaskWidget, e_task_widget, GTK_TYPE_EVENT_BOX)
@@ -112,8 +119,35 @@ e_task_widget_init (ETaskWidget *task_widget)
priv->icon_pixbuf = NULL;
priv->label = NULL;
priv->image = NULL;
+ priv->box = NULL;
task_widget->priv = priv;
+ task_widget->id = 0;
+}
+
+static gboolean
+button_press_event_cb (GtkWidget *w, gpointer data)
+{
+ ETaskWidget *tw = (ETaskWidget *) data;
+ ETaskWidgetPrivate *priv = tw->priv;
+
+ priv->cancel_func (priv->data);
+
+ return TRUE;
+}
+
+static gboolean
+prepare_popup (ETaskWidget *widget, GdkEventButton *event)
+{
+ if (event->type != GDK_BUTTON_PRESS)
+ return FALSE;
+
+ if (event->button != 3)
+ return FALSE;
+
+ /* FIXME: Implement Cancel */
+
+ return TRUE;
}
@@ -121,17 +155,20 @@ void
e_task_widget_construct (ETaskWidget *task_widget,
GdkPixbuf *icon_pixbuf,
const char *component_id,
- const char *information)
+ const char *information,
+ void (*cancel_func) (gpointer data),
+ gpointer data)
{
ETaskWidgetPrivate *priv;
/*GdkPixmap *pixmap;
GdkBitmap *mask;*/
GtkWidget *box;
GtkWidget *frame;
+ GtkWidget *image = e_icon_factory_get_image ("gtk-stop", E_ICON_SIZE_MENU);
+ GtkWidget *tool;
g_return_if_fail (task_widget != NULL);
g_return_if_fail (E_IS_TASK_WIDGET (task_widget));
- g_return_if_fail (icon_pixbuf != NULL);
g_return_if_fail (component_id != NULL);
g_return_if_fail (information != NULL);
@@ -154,22 +191,34 @@ e_task_widget_construct (ETaskWidget *task_widget,
/* priv->icon_pixbuf = g_object_ref (icon_pixbuf); */
/* gdk_pixbuf_render_pixmap_and_mask (icon_pixbuf, &pixmap, &mask, 128); */
-
+ priv->box = gtk_hbox_new (FALSE, 0);
priv->image = e_spinner_new ();
e_spinner_set_size (E_SPINNER (priv->image), GTK_ICON_SIZE_SMALL_TOOLBAR);
e_spinner_start (E_SPINNER (priv->image));
/* gtk_image_new_from_pixmap (pixmap, mask); */
gtk_widget_show (priv->image);
- gtk_box_pack_start (GTK_BOX (box), priv->image, FALSE, TRUE, 0);
-
+ gtk_widget_show (priv->box);
+ gtk_box_pack_start (GTK_BOX (priv->box), priv->image, FALSE, TRUE, 0);
+ gtk_box_pack_start (GTK_BOX (box), priv->box, FALSE, TRUE, 0);
priv->label = gtk_label_new ("");
gtk_misc_set_alignment (GTK_MISC (priv->label), 0.0, 0.5);
gtk_widget_show (priv->label);
gtk_box_pack_start (GTK_BOX (box), priv->label, TRUE, TRUE, 0);
+ if (cancel_func) {
+ tool = (GtkWidget *) gtk_tool_button_new (image, NULL);
+ gtk_box_pack_end (GTK_BOX (box), tool, FALSE, TRUE, 0);
+ gtk_widget_show_all (tool);
+
+ gtk_widget_set_sensitive (tool, cancel_func != NULL);
+ priv->cancel_func = cancel_func;
+ priv->data = data;
+ g_signal_connect (tool, "clicked", G_CALLBACK (button_press_event_cb), task_widget);
+ /* g_object_unref (pixmap);
+ if (mask)
+ g_object_unref (mask); */
+ g_signal_connect (task_widget, "button-press-event", G_CALLBACK (prepare_popup), task_widget);
- /* g_object_unref (pixmap);
- if (mask)
- g_object_unref (mask); */
+ }
priv->tooltips = gtk_tooltips_new ();
g_object_ref_sink (priv->tooltips);
@@ -178,6 +227,23 @@ e_task_widget_construct (ETaskWidget *task_widget,
}
GtkWidget *
+e_task_widget_new_with_cancel (GdkPixbuf *icon_pixbuf,
+ const char *component_id,
+ const char *information,
+ void (*cancel_func) (gpointer data),
+ gpointer data)
+{
+ ETaskWidget *task_widget;
+
+ g_return_val_if_fail (information != NULL, NULL);
+
+ task_widget = g_object_new (e_task_widget_get_type (), NULL);
+ e_task_widget_construct (task_widget, icon_pixbuf, component_id, information, cancel_func, data);
+
+ return GTK_WIDGET (task_widget);
+}
+
+GtkWidget *
e_task_widget_new (GdkPixbuf *icon_pixbuf,
const char *component_id,
const char *information)
@@ -188,11 +254,28 @@ e_task_widget_new (GdkPixbuf *icon_pixbuf,
g_return_val_if_fail (information != NULL, NULL);
task_widget = g_object_new (e_task_widget_get_type (), NULL);
- e_task_widget_construct (task_widget, icon_pixbuf, component_id, information);
+ e_task_widget_construct (task_widget, icon_pixbuf, component_id, information, NULL, NULL);
return GTK_WIDGET (task_widget);
}
+GtkWidget *
+e_task_widget_update_image (ETaskWidget *task_widget,
+ char *stock, char *text)
+{
+ GtkWidget *img, *tool;
+
+ img = e_icon_factory_get_image ("stock_dialog-warning", E_ICON_SIZE_MENU);
+ tool = (GtkWidget *) gtk_tool_button_new (img, NULL);
+ gtk_box_pack_start (GTK_BOX(task_widget->priv->box), tool, FALSE, TRUE, 0);
+ gtk_widget_destroy (task_widget->priv->image);
+ gtk_widget_show_all (task_widget->priv->box);
+ task_widget->priv->image = img;
+ gtk_label_set_text (GTK_LABEL (task_widget->priv->label), text);
+
+ return tool;
+}
+
void
e_task_widget_update (ETaskWidget *task_widget,
diff --git a/widgets/misc/e-task-widget.h b/widgets/misc/e-task-widget.h
index 0eb4fbb167..fb47b95095 100644
--- a/widgets/misc/e-task-widget.h
+++ b/widgets/misc/e-task-widget.h
@@ -46,6 +46,7 @@ struct _ETaskWidget {
GtkEventBox parent;
ETaskWidgetPrivate *priv;
+ guint id;
};
struct _ETaskWidgetClass {
@@ -57,14 +58,25 @@ GtkType e_task_widget_get_type (void);
void e_task_widget_construct (ETaskWidget *task_widget,
GdkPixbuf *icon_pixbuf,
const char *component_id,
- const char *information);
+ const char *information,
+ void (*cancel_func) (gpointer data),
+ gpointer data);
GtkWidget *e_task_widget_new (GdkPixbuf *icon_pixbuf,
const char *component_id,
const char *information);
+GtkWidget *
+e_task_widget_new_with_cancel (GdkPixbuf *icon_pixbuf,
+ const char *component_id,
+ const char *information,
+ void (*cancel_func) (gpointer data),
+ gpointer data);
void e_task_widget_update (ETaskWidget *task_widget,
const char *information,
double completion);
+GtkWidget *
+e_task_widget_update_image (ETaskWidget *task_widget,
+ char *stock, char *text);
void e_task_wiget_alert (ETaskWidget *task_widget);
void e_task_wiget_unalert (ETaskWidget *task_widget);