From b9c4553423f182bb1aec8d51cb295bb2bca78abe Mon Sep 17 00:00:00 2001 From: Dan Winship Date: Tue, 3 Feb 2004 17:31:50 +0000 Subject: Moved here from shell/, since they are now used only by the components, * e-activity-handler.c: * e-activity-handler.h: * e-task-bar.c: * e-task-bar.h: * e-task-widget.c: * e-task-widget.h: Moved here from shell/, since they are now used only by the components, not the shell itself. * Makefile.am (widgetsinclude_HEADERS, libemiscwidgets_la_SOURCES): add new files svn path=/trunk/; revision=24586 --- widgets/misc/ChangeLog | 13 ++ widgets/misc/Makefile.am | 10 +- widgets/misc/e-activity-handler.c | 420 ++++++++++++++++++++++++++++++++++++++ widgets/misc/e-activity-handler.h | 88 ++++++++ widgets/misc/e-task-bar.c | 232 +++++++++++++++++++++ widgets/misc/e-task-bar.h | 77 +++++++ widgets/misc/e-task-widget.c | 251 +++++++++++++++++++++++ widgets/misc/e-task-widget.h | 78 +++++++ 8 files changed, 1165 insertions(+), 4 deletions(-) create mode 100644 widgets/misc/e-activity-handler.c create mode 100644 widgets/misc/e-activity-handler.h create mode 100644 widgets/misc/e-task-bar.c create mode 100644 widgets/misc/e-task-bar.h create mode 100644 widgets/misc/e-task-widget.c create mode 100644 widgets/misc/e-task-widget.h diff --git a/widgets/misc/ChangeLog b/widgets/misc/ChangeLog index 1d1e6af08c..ba42818801 100644 --- a/widgets/misc/ChangeLog +++ b/widgets/misc/ChangeLog @@ -1,3 +1,16 @@ +2004-02-03 Dan Winship + + * e-activity-handler.c: + * e-activity-handler.h: + * e-task-bar.c: + * e-task-bar.h: + * e-task-widget.c: + * e-task-widget.h: Moved here from shell/, since they are now used + only by the components, not the shell itself. + + * Makefile.am (widgetsinclude_HEADERS, + libemiscwidgets_la_SOURCES): add new files + 2004-02-02 Chris Toshok * e-image-chooser.c (set_image_from_data): set diff --git a/widgets/misc/Makefile.am b/widgets/misc/Makefile.am index 9db2180be2..25cce4416e 100644 --- a/widgets/misc/Makefile.am +++ b/widgets/misc/Makefile.am @@ -1,9 +1,5 @@ -# FIXME we use the EClippedLabel widget from EShortcutBar. Probably -# it should be moved somewhere else. - INCLUDES = \ -I$(top_srcdir) \ - -I$(top_srcdir)/widgets/shortcut-bar \ -I$(top_srcdir)/a11y/widgets/ \ -DMAP_DIR=\""$(imagesdir)"\" \ -DG_LOG_DOMAIN=__FILE__ \ @@ -15,6 +11,7 @@ privlib_LTLIBRARIES = \ widgetsincludedir = $(privincludedir)/widgets widgetsinclude_HEADERS = \ + e-activity-handler.h \ e-calendar.h \ e-calendar-item.h \ e-cell-date-edit.h \ @@ -34,12 +31,15 @@ widgetsinclude_HEADERS = \ e-search-bar.h \ e-source-option-menu.h \ e-source-selector.h \ + e-task-bar.h \ + e-task-widget.h \ e-title-bar.h \ e-url-entry.h libemiscwidgets_la_SOURCES = \ $(MARSHAL_GENERATED) \ $(widgetsinclude_HEADERS) \ + e-activity-handler.c \ e-calendar.c \ e-calendar-item.c \ e-cell-date-edit.c \ @@ -59,6 +59,8 @@ libemiscwidgets_la_SOURCES = \ e-search-bar.c \ e-source-option-menu.c \ e-source-selector.c \ + e-task-bar.c \ + e-task-widget.c \ e-title-bar.c \ e-url-entry.c diff --git a/widgets/misc/e-activity-handler.c b/widgets/misc/e-activity-handler.c new file mode 100644 index 0000000000..d64bcd8f6e --- /dev/null +++ b/widgets/misc/e-activity-handler.c @@ -0,0 +1,420 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ +/* e-activity-handler.c + * + * Copyright (C) 2001, 2002, 2003 Novell, Inc. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * 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 + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + * + * Author: Ettore Perazzoli + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include "e-activity-handler.h" + +#include +#include + +#include +#include + +#include +#include + + +#define PARENT_TYPE G_TYPE_OBJECT +static GObjectClass *parent_class = NULL; + + +#define ICON_SIZE 16 + + +struct _ActivityInfo { + char *component_id; + GdkPixbuf *icon_pixbuf; + guint id; + char *information; + gboolean cancellable; + double progress; + GtkWidget *menu; +}; +typedef struct _ActivityInfo ActivityInfo; + +struct _EActivityHandlerPrivate { + uint next_activity_id; + GList *activity_infos; + GSList *task_bars; +}; + + +/* Utility functions. */ + +static unsigned int +get_new_activity_id (EActivityHandler *activity_handler) +{ + EActivityHandlerPrivate *priv; + + priv = activity_handler->priv; + + return priv->next_activity_id ++; +} + +static GList * +lookup_activity (GList *list, + guint activity_id, + int *order_number_return) +{ + GList *p; + int i; + + for (p = list, i = 0; p != NULL; p = p->next, i ++) { + ActivityInfo *activity_info; + + activity_info = (ActivityInfo *) p->data; + if (activity_info->id == activity_id) { + *order_number_return = i; + return p; + } + } + + *order_number_return = -1; + return NULL; +} + + +/* ETaskWidget actions. */ + +static int +task_widget_button_press_event_callback (GtkWidget *widget, + GdkEventButton *button_event, + void *data) +{ + ActivityInfo *activity_info; + + activity_info = (ActivityInfo *) data; + + if (button_event->button == 3) + return activity_info->cancellable; + + if (button_event->button != 1) + return FALSE; + + return TRUE; +} + + +/* Creating and destroying ActivityInfos. */ + +static ActivityInfo * +activity_info_new (const char *component_id, + guint id, + GdkPixbuf *icon, + const char *information, + gboolean cancellable) +{ + ActivityInfo *info; + + info = g_new (ActivityInfo, 1); + info->component_id = g_strdup (component_id); + info->id = id; + info->icon_pixbuf = g_object_ref (icon); + info->information = g_strdup (information); + info->cancellable = cancellable; + info->progress = -1.0; /* (Unknown) */ + info->menu = NULL; + + return info; +} + +static void +activity_info_free (ActivityInfo *info) +{ + g_free (info->component_id); + + g_object_unref (info->icon_pixbuf); + g_free (info->information); + + if (info->menu != NULL) + gtk_widget_destroy (info->menu); + + g_free (info); +} + +static ETaskWidget * +task_widget_new_from_activity_info (ActivityInfo *activity_info) +{ + GtkWidget *widget; + + widget = e_task_widget_new (activity_info->icon_pixbuf, + activity_info->component_id, + activity_info->information); + gtk_widget_show (widget); + + g_signal_connect (widget, "button_press_event", + G_CALLBACK (task_widget_button_press_event_callback), + activity_info); + + return E_TASK_WIDGET (widget); +} + + +/* Task Bar handling. */ + +static void +setup_task_bar (EActivityHandler *activity_handler, + ETaskBar *task_bar) +{ + EActivityHandlerPrivate *priv; + GList *p; + + 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)); + } +} + +static void +task_bar_destroy_notify (void *data, + GObject *task_bar_instance) +{ + EActivityHandler *activity_handler; + EActivityHandlerPrivate *priv; + + activity_handler = E_ACTIVITY_HANDLER (data); + priv = activity_handler->priv; + + priv->task_bars = g_slist_remove (priv->task_bars, task_bar_instance); +} + + +/* GObject methods. */ + +static void +impl_dispose (GObject *object) +{ + EActivityHandler *handler; + EActivityHandlerPrivate *priv; + GList *p; + GSList *sp; + + handler = E_ACTIVITY_HANDLER (object); + priv = handler->priv; + + for (p = priv->activity_infos; p != NULL; p = p->next) { + ActivityInfo *info; + + info = (ActivityInfo *) p->data; + activity_info_free (info); + } + + g_list_free (priv->activity_infos); + priv->activity_infos = NULL; + + for (sp = priv->task_bars; sp != NULL; sp = sp->next) + g_object_weak_unref (G_OBJECT (sp->data), task_bar_destroy_notify, sp->data); + priv->task_bars = NULL; + + (* G_OBJECT_CLASS (parent_class)->dispose) (object); +} + +static void +impl_finalize (GObject *object) +{ + EActivityHandler *handler; + EActivityHandlerPrivate *priv; + + handler = E_ACTIVITY_HANDLER (object); + priv = handler->priv; + + g_free (priv); + + (* G_OBJECT_CLASS (parent_class)->finalize) (object); +} + + +/* GTK+ type stuff. */ + +static void +class_init (GObjectClass *object_class) +{ + parent_class = g_type_class_ref(PARENT_TYPE); + + object_class->dispose = impl_dispose; + object_class->finalize = impl_finalize; +} + +static void +init (EActivityHandler *activity_handler) +{ + EActivityHandlerPrivate *priv; + + priv = g_new (EActivityHandlerPrivate, 1); + priv->next_activity_id = 1; + priv->activity_infos = NULL; + priv->task_bars = NULL; + + activity_handler->priv = priv; +} + + +EActivityHandler * +e_activity_handler_new (void) +{ + return g_object_new (e_activity_handler_get_type (), 0); +} + +void +e_activity_handler_set_message (EActivityHandler *activity_handler, + const char *message) +{ + EActivityHandlerPrivate *priv; + GSList *i; + + priv = activity_handler->priv; + + for (i = priv->task_bars; i; i = i->next) + e_task_bar_set_message (E_TASK_BAR (i->data), message); +} + +void +e_activity_handler_unset_message (EActivityHandler *activity_handler) +{ + EActivityHandlerPrivate *priv; + GSList *i; + + priv = activity_handler->priv; + + for (i = priv->task_bars; i; i = i->next) + e_task_bar_unset_message (E_TASK_BAR (i->data)); +} + +void +e_activity_handler_attach_task_bar (EActivityHandler *activity_handler, + ETaskBar *task_bar) +{ + EActivityHandlerPrivate *priv; + + g_return_if_fail (activity_handler != NULL); + g_return_if_fail (E_IS_ACTIVITY_HANDLER (activity_handler)); + g_return_if_fail (task_bar != NULL); + g_return_if_fail (E_IS_TASK_BAR (task_bar)); + + priv = activity_handler->priv; + + g_object_weak_ref (G_OBJECT (task_bar), task_bar_destroy_notify, activity_handler); + + priv->task_bars = g_slist_prepend (priv->task_bars, task_bar); + + setup_task_bar (activity_handler, task_bar); +} + +/* CORBA methods. */ + +guint +e_activity_handler_operation_started (EActivityHandler *activity_handler, + const char *component_id, + GdkPixbuf *icon_pixbuf, + const char *information, + gboolean cancellable) +{ + 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, 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)); + } + + priv->activity_infos = g_list_prepend (priv->activity_infos, activity_info); + + return activity_id; +} + +void +e_activity_handler_operation_progressing (EActivityHandler *activity_handler, + guint activity_id, + const char *information, + double progress) +{ + 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; + + g_free (activity_info->information); + activity_info->information = g_strdup (information); + + activity_info->progress = progress; + + for (sp = priv->task_bars; sp != NULL; sp = sp->next) { + ETaskBar *task_bar; + ETaskWidget *task_widget; + + task_bar = E_TASK_BAR (sp->data); + task_widget = e_task_bar_get_task_widget (task_bar, order_number); + + e_task_widget_update (task_widget, information, progress); + } +} + +void +e_activity_handler_operation_finished (EActivityHandler *activity_handler, + guint activity_id) +{ + EActivityHandlerPrivate *priv = activity_handler->priv; + GList *p; + GSList *sp; + int order_number; + + p = lookup_activity (priv->activity_infos, activity_id, &order_number); + if (p == NULL) { + g_warning ("e_activity_handler_operation_finished: Unknown activity %d\n", activity_id); + return; + } + + activity_info_free ((ActivityInfo *) p->data); + priv->activity_infos = g_list_remove_link (priv->activity_infos, p); + + 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 (task_bar, order_number); + } +} + + +E_MAKE_TYPE (e_activity_handler, "EActivityHandler", EActivityHandler, class_init, init, PARENT_TYPE) diff --git a/widgets/misc/e-activity-handler.h b/widgets/misc/e-activity-handler.h new file mode 100644 index 0000000000..b3fe4e386d --- /dev/null +++ b/widgets/misc/e-activity-handler.h @@ -0,0 +1,88 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ +/* e-activity-handler.h + * + * Copyright (C) 2001, 2002, 2003 Novell, Inc. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * 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 + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + * + * Author: Ettore Perazzoli + */ + +#ifndef _E_ACTIVITY_HANDLER_H_ +#define _E_ACTIVITY_HANDLER_H_ + +#include "e-task-bar.h" + +#include + +#ifdef __cplusplus +extern "C" { +#pragma } +#endif /* __cplusplus */ + +#define E_TYPE_ACTIVITY_HANDLER (e_activity_handler_get_type ()) +#define E_ACTIVITY_HANDLER(obj) (GTK_CHECK_CAST ((obj), E_TYPE_ACTIVITY_HANDLER, EActivityHandler)) +#define E_ACTIVITY_HANDLER_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), E_TYPE_ACTIVITY_HANDLER, EActivityHandlerClass)) +#define E_IS_ACTIVITY_HANDLER(obj) (GTK_CHECK_TYPE ((obj), E_TYPE_ACTIVITY_HANDLER)) +#define E_IS_ACTIVITY_HANDLER_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((obj), E_TYPE_ACTIVITY_HANDLER)) + + +typedef struct _EActivityHandler EActivityHandler; +typedef struct _EActivityHandlerPrivate EActivityHandlerPrivate; +typedef struct _EActivityHandlerClass EActivityHandlerClass; + +struct _EActivityHandler { + GObject parent; + + EActivityHandlerPrivate *priv; +}; + +struct _EActivityHandlerClass { + GObjectClass parent_class; +}; + + +GtkType e_activity_handler_get_type (void); + +EActivityHandler *e_activity_handler_new (void); + +void e_activity_handler_attach_task_bar (EActivityHandler *activity_hanlder, + ETaskBar *task_bar); + +void e_activity_handler_set_message (EActivityHandler *activity_handler, + const char *message); + +void e_activity_handler_unset_message (EActivityHandler *activity_handler); + +guint e_activity_handler_operation_started (EActivityHandler *activity_handler, + const char *component_id, + GdkPixbuf *icon_pixbuf, + const char *information, + gboolean cancellable); + +void e_activity_handler_operation_progressing (EActivityHandler *activity_handler, + guint activity_id, + const char *information, + double progress); + +void e_activity_handler_operation_finished (EActivityHandler *activity_handler, + guint activity_id); + + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* _E_ACTIVITY_HANDLER_H_ */ diff --git a/widgets/misc/e-task-bar.c b/widgets/misc/e-task-bar.c new file mode 100644 index 0000000000..6f20d11505 --- /dev/null +++ b/widgets/misc/e-task-bar.c @@ -0,0 +1,232 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ +/* e-task-bar.c + * + * Copyright (C) 2001 Ximian, Inc. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * 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 + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + * + * Author: Ettore Perazzoli + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include "e-task-bar.h" + +#include +#include "widgets/misc/e-clipped-label.h" + + +struct _ETaskBarPrivate +{ + EClippedLabel *message_label; + GtkHBox *hbox; +}; + +#define PARENT_TYPE gtk_hbox_get_type () +static GtkHBoxClass *parent_class = NULL; + + +/* WARNING: Ugly hack starts here. */ + +#define MAX_ACTIVITIES_PER_COMPONENT 2 + +static void +reduce_displayed_activities_per_component (ETaskBar *task_bar) +{ + GHashTable *component_ids_hash; + GtkBox *box; + GList *p; + + component_ids_hash = g_hash_table_new (g_str_hash, g_str_equal); + + box = GTK_BOX (task_bar->priv->hbox); + + for (p = box->children; p != NULL; p = p->next) { + GtkBoxChild *child; + const char *component_id; + void *hash_item; + + child = (GtkBoxChild *) p->data; + component_id = e_task_widget_get_component_id (E_TASK_WIDGET (child->widget)); + + hash_item = g_hash_table_lookup (component_ids_hash, component_id); + + if (hash_item == NULL) { + gtk_widget_show (child->widget); + g_hash_table_insert (component_ids_hash, (void *) component_id, GINT_TO_POINTER (1)); + } else { + int num_items; + + num_items = GPOINTER_TO_INT (hash_item); + g_assert (num_items <= MAX_ACTIVITIES_PER_COMPONENT); + + if (num_items == MAX_ACTIVITIES_PER_COMPONENT) { + gtk_widget_hide (child->widget); + } else { + num_items ++; + gtk_widget_show (child->widget); + g_hash_table_insert (component_ids_hash, (void *) component_id, GINT_TO_POINTER (num_items)); + } + } + } + + g_hash_table_destroy (component_ids_hash); +} + + +static void +class_init (GtkObjectClass *object_class) +{ + parent_class = g_type_class_ref(PARENT_TYPE); +} + +static void +init (ETaskBar *task_bar) +{ + GtkWidget *label, *hbox; + + task_bar->priv = g_new (ETaskBarPrivate, 1); + + gtk_box_set_spacing (GTK_BOX (task_bar), 10); + + label = e_clipped_label_new ("", PANGO_WEIGHT_NORMAL, 1.0); + gtk_widget_show (label); + gtk_box_pack_start (GTK_BOX (task_bar), label, TRUE, TRUE, 0); + gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5); + task_bar->priv->message_label = E_CLIPPED_LABEL (label); + + hbox = gtk_hbox_new (FALSE, 0); + gtk_container_add (GTK_CONTAINER (task_bar), hbox); + task_bar->priv->hbox = GTK_HBOX (hbox); +} + + +void +e_task_bar_construct (ETaskBar *task_bar) +{ + g_return_if_fail (task_bar != NULL); + g_return_if_fail (E_IS_TASK_BAR (task_bar)); + + /* Nothing to do here. */ +} + +GtkWidget * +e_task_bar_new (void) +{ + ETaskBar *task_bar; + + task_bar = g_object_new (e_task_bar_get_type (), NULL); + e_task_bar_construct (task_bar); + + return GTK_WIDGET (task_bar); +} + +void +e_task_bar_set_message (ETaskBar *task_bar, + const char *message) +{ + if (message) { + gtk_widget_show (GTK_WIDGET (task_bar->priv->message_label)); + e_clipped_label_set_text (task_bar->priv->message_label, + message); + } else { + e_task_bar_unset_message (task_bar); + } +} + +void +e_task_bar_unset_message (ETaskBar *task_bar) +{ + gtk_widget_hide (GTK_WIDGET (task_bar->priv->message_label)); +} + +void +e_task_bar_prepend_task (ETaskBar *task_bar, + ETaskWidget *task_widget) +{ + GtkBoxChild *child_info; + GtkBox *box; + + g_return_if_fail (task_bar != NULL); + g_return_if_fail (E_IS_TASK_BAR (task_bar)); + g_return_if_fail (task_widget != NULL); + g_return_if_fail (E_IS_TASK_WIDGET (task_widget)); + + /* Hah hah. GTK+ sucks. This is adapted from `gtkhbox.c'. */ + + child_info = g_new (GtkBoxChild, 1); + child_info->widget = GTK_WIDGET (task_widget); + child_info->padding = 0; + child_info->expand = TRUE; + child_info->fill = TRUE; + child_info->pack = GTK_PACK_START; + + box = GTK_BOX (task_bar->priv->hbox); + + box->children = g_list_prepend (box->children, child_info); + + gtk_widget_set_parent (GTK_WIDGET (task_widget), GTK_WIDGET (task_bar->priv->hbox)); + + if (GTK_WIDGET_REALIZED (task_bar)) + gtk_widget_realize (GTK_WIDGET (task_widget)); + + if (GTK_WIDGET_VISIBLE (task_bar) && GTK_WIDGET_VISIBLE (task_widget)) { + if (GTK_WIDGET_MAPPED (task_bar)) + gtk_widget_map (GTK_WIDGET (task_widget)); + gtk_widget_queue_resize (GTK_WIDGET (task_widget)); + } + + reduce_displayed_activities_per_component (task_bar); + + gtk_widget_show (GTK_WIDGET (task_bar->priv->hbox)); +} + +void +e_task_bar_remove_task (ETaskBar *task_bar, + int n) +{ + ETaskWidget *task_widget; + + g_return_if_fail (task_bar != NULL); + g_return_if_fail (E_IS_TASK_BAR (task_bar)); + g_return_if_fail (n >= 0); + + 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); + + 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 (ETaskBar *task_bar, + int n) +{ + GtkBoxChild *child_info; + + g_return_val_if_fail (task_bar != NULL, NULL); + g_return_val_if_fail (E_IS_TASK_BAR (task_bar), NULL); + + child_info = (GtkBoxChild *) g_list_nth (GTK_BOX (task_bar->priv->hbox)->children, n)->data; + + return E_TASK_WIDGET (child_info->widget); +} + + +E_MAKE_TYPE (e_task_bar, "ETaskBar", ETaskBar, class_init, init, PARENT_TYPE) diff --git a/widgets/misc/e-task-bar.h b/widgets/misc/e-task-bar.h new file mode 100644 index 0000000000..e91e5fab65 --- /dev/null +++ b/widgets/misc/e-task-bar.h @@ -0,0 +1,77 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ +/* e-task-bar.h + * + * Copyright (C) 2001 Ximian, Inc. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * 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 + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + * + * Author: Ettore Perazzoli + */ + +#ifndef _E_TASK_BAR_H_ +#define _E_TASK_BAR_H_ + +#include "e-task-widget.h" + +#include + +#ifdef __cplusplus +extern "C" { +#pragma } +#endif /* __cplusplus */ + +#define E_TYPE_TASK_BAR (e_task_bar_get_type ()) +#define E_TASK_BAR(obj) (GTK_CHECK_CAST ((obj), E_TYPE_TASK_BAR, ETaskBar)) +#define E_TASK_BAR_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), E_TYPE_TASK_BAR, ETaskBarClass)) +#define E_IS_TASK_BAR(obj) (GTK_CHECK_TYPE ((obj), E_TYPE_TASK_BAR)) +#define E_IS_TASK_BAR_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((obj), E_TYPE_TASK_BAR)) + + +typedef struct _ETaskBar ETaskBar; +typedef struct _ETaskBarPrivate ETaskBarPrivate; +typedef struct _ETaskBarClass ETaskBarClass; + +struct _ETaskBar { + GtkHBox parent; + + ETaskBarPrivate *priv; +}; + +struct _ETaskBarClass { + GtkHBoxClass parent_class; +}; + + +GtkType e_task_bar_get_type (void); +void e_task_bar_construct (ETaskBar *task_bar); +GtkWidget *e_task_bar_new (void); + +void e_task_bar_set_message (ETaskBar *task_bar, + const char *message); +void e_task_bar_unset_message (ETaskBar *task_bar); + +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 (ETaskBar *task_bar, + int n); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* _E_TASK_BAR_H_ */ diff --git a/widgets/misc/e-task-widget.c b/widgets/misc/e-task-widget.c new file mode 100644 index 0000000000..c6cd524c2f --- /dev/null +++ b/widgets/misc/e-task-widget.c @@ -0,0 +1,251 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ +/* e-task-widget.c + * + * Copyright (C) 2001 Ximian, Inc. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * 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 + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + * + * Author: Ettore Perazzoli + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include "e-task-widget.h" + +#include +#include +#include +#include +#include + +#include + +#include + + +#define SPACING 2 + +#define PARENT_TYPE (gtk_event_box_get_type ()) +static GtkEventBoxClass *parent_class = NULL; + +struct _ETaskWidgetPrivate { + char *component_id; + + GtkTooltips *tooltips; + + GdkPixbuf *icon_pixbuf; + GtkWidget *label; + GtkWidget *image; +}; + + +/* GObject methods. */ + +static void +impl_dispose (GObject *object) +{ + ETaskWidget *task_widget; + ETaskWidgetPrivate *priv; + + task_widget = E_TASK_WIDGET (object); + + priv = task_widget->priv; + + if (priv->tooltips != NULL) { + g_object_unref (priv->tooltips); + priv->tooltips = NULL; + } + + if (priv->icon_pixbuf != NULL) { + g_object_unref (priv->icon_pixbuf); + priv->icon_pixbuf = NULL; + } + + (* G_OBJECT_CLASS (parent_class)->dispose) (object); +} + +static void +impl_finalize (GObject *object) +{ + ETaskWidget *task_widget; + ETaskWidgetPrivate *priv; + + task_widget = E_TASK_WIDGET (object); + priv = task_widget->priv; + + g_free (priv->component_id); + g_free (priv); + + (* G_OBJECT_CLASS (parent_class)->finalize) (object); +} + + +static void +class_init (GObjectClass *object_class) +{ + parent_class = g_type_class_ref(PARENT_TYPE); + + object_class->dispose = impl_dispose; + object_class->finalize = impl_finalize; +} + +static void +init (ETaskWidget *task_widget) +{ + ETaskWidgetPrivate *priv; + + priv = g_new (ETaskWidgetPrivate, 1); + + priv->component_id = NULL; + priv->tooltips = NULL; + priv->icon_pixbuf = NULL; + priv->label = NULL; + priv->image = NULL; + + task_widget->priv = priv; +} + + +void +e_task_widget_construct (ETaskWidget *task_widget, + GdkPixbuf *icon_pixbuf, + const char *component_id, + const char *information) +{ + ETaskWidgetPrivate *priv; + GdkPixmap *pixmap; + GdkBitmap *mask; + GtkWidget *box; + GtkWidget *frame; + + 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); + + priv = task_widget->priv; + + priv->component_id = g_strdup (component_id); + + frame = gtk_frame_new (NULL); + gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN); + gtk_container_add (GTK_CONTAINER (task_widget), frame); + gtk_widget_show (frame); + + box = gtk_hbox_new (FALSE, 0); + gtk_container_add (GTK_CONTAINER (frame), box); + gtk_widget_show (box); + + gtk_widget_set_size_request (box, 1, -1); + + priv->icon_pixbuf = g_object_ref (icon_pixbuf); + + gdk_pixbuf_render_pixmap_and_mask (icon_pixbuf, &pixmap, &mask, 128); + + 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); + + 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); + + gdk_pixmap_unref (pixmap); + g_object_unref (mask); + + priv->tooltips = gtk_tooltips_new (); + g_object_ref (priv->tooltips); + gtk_object_sink (GTK_OBJECT (priv->tooltips)); + + e_task_widget_update (task_widget, information, -1.0); +} + +GtkWidget * +e_task_widget_new (GdkPixbuf *icon_pixbuf, + const char *component_id, + const char *information) +{ + ETaskWidget *task_widget; + + g_return_val_if_fail (icon_pixbuf != NULL, NULL); + 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); + + return GTK_WIDGET (task_widget); +} + + +void +e_task_widget_update (ETaskWidget *task_widget, + const char *information, + double completion) +{ + ETaskWidgetPrivate *priv; + char *text; + + g_return_if_fail (task_widget != NULL); + g_return_if_fail (E_IS_TASK_WIDGET (task_widget)); + g_return_if_fail (information != NULL); + + priv = task_widget->priv; + + if (completion < 0.0) { + text = g_strdup_printf (_("%s (...)"), information); + } else { + int percent_complete; + + percent_complete = (int) (completion * 100.0 + .5); + text = g_strdup_printf (_("%s (%d%% complete)"), information, percent_complete); + } + + gtk_label_set_text (GTK_LABEL (priv->label), text); + + gtk_tooltips_set_tip (priv->tooltips, GTK_WIDGET (task_widget), text, NULL); + + g_free (text); +} + +void +e_task_wiget_alert (ETaskWidget *task_widget) +{ + g_return_if_fail (task_widget != NULL); + g_return_if_fail (E_IS_TASK_WIDGET (task_widget)); +} + +void +e_task_wiget_unalert (ETaskWidget *task_widget) +{ + g_return_if_fail (task_widget != NULL); + g_return_if_fail (E_IS_TASK_WIDGET (task_widget)); +} + + +const char * +e_task_widget_get_component_id (ETaskWidget *task_widget) +{ + g_return_val_if_fail (task_widget != NULL, NULL); + g_return_val_if_fail (E_IS_TASK_WIDGET (task_widget), NULL); + + return task_widget->priv->component_id; +} + + +E_MAKE_TYPE (e_task_widget, "ETaskWidget", ETaskWidget, class_init, init, PARENT_TYPE) diff --git a/widgets/misc/e-task-widget.h b/widgets/misc/e-task-widget.h new file mode 100644 index 0000000000..6173623a80 --- /dev/null +++ b/widgets/misc/e-task-widget.h @@ -0,0 +1,78 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ +/* e-task-widget.h + * + * Copyright (C) 2001 Ximian, Inc. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * 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 + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + * + * Author: Ettore Perazzoli + */ + +#ifndef _E_TASK_WIDGET_H_ +#define _E_TASK_WIDGET_H_ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#pragma } +#endif /* __cplusplus */ + +#define E_TYPE_TASK_WIDGET (e_task_widget_get_type ()) +#define E_TASK_WIDGET(obj) (GTK_CHECK_CAST ((obj), E_TYPE_TASK_WIDGET, ETaskWidget)) +#define E_TASK_WIDGET_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), E_TYPE_TASK_WIDGET, ETaskWidgetClass)) +#define E_IS_TASK_WIDGET(obj) (GTK_CHECK_TYPE ((obj), E_TYPE_TASK_WIDGET)) +#define E_IS_TASK_WIDGET_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((obj), E_TYPE_TASK_WIDGET)) + + +typedef struct _ETaskWidget ETaskWidget; +typedef struct _ETaskWidgetPrivate ETaskWidgetPrivate; +typedef struct _ETaskWidgetClass ETaskWidgetClass; + +struct _ETaskWidget { + GtkEventBox parent; + + ETaskWidgetPrivate *priv; +}; + +struct _ETaskWidgetClass { + GtkEventBoxClass parent_class; +}; + + +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); +GtkWidget *e_task_widget_new (GdkPixbuf *icon_pixbuf, + const char *component_id, + const char *information); + +void e_task_widget_update (ETaskWidget *task_widget, + const char *information, + double completion); + +void e_task_wiget_alert (ETaskWidget *task_widget); +void e_task_wiget_unalert (ETaskWidget *task_widget); + +const char *e_task_widget_get_component_id (ETaskWidget *task_widget); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* _E_TASK_WIDGET_H_ */ -- cgit v1.2.3