evolution r37396 - in branches/kill-bonobo: calendar/gui/dialogs e-util mail shell shell/test widgets/misc
- From: mbarnes svn gnome org
- To: svn-commits-list gnome org
- Subject: evolution r37396 - in branches/kill-bonobo: calendar/gui/dialogs e-util mail shell shell/test widgets/misc
- Date: Tue, 10 Mar 2009 01:06:18 +0000 (UTC)
Author: mbarnes
Date: Tue Mar 10 01:06:18 2009
New Revision: 37396
URL: http://svn.gnome.org/viewvc/evolution?rev=37396&view=rev
Log:
Add e_lookup_action() and e_lookup_action_group() to e-util, so
I don't have to keep writing the algorithm over and over again.
Add EFileActivity, which provides a GCancellable for GIO operations.
Cancelling the activity cancels the GIO operation, and vice versa.
Also provides a handy GFileProgressCallback function which updates
the activity's "percent" property.
Added:
branches/kill-bonobo/widgets/misc/e-file-activity.c
branches/kill-bonobo/widgets/misc/e-file-activity.h
Modified:
branches/kill-bonobo/calendar/gui/dialogs/comp-editor.c
branches/kill-bonobo/e-util/e-util.c
branches/kill-bonobo/e-util/e-util.h
branches/kill-bonobo/mail/mail-mt.c
branches/kill-bonobo/shell/e-shell-window.c
branches/kill-bonobo/shell/test/e-test-shell-view.c
branches/kill-bonobo/widgets/misc/Makefile.am
branches/kill-bonobo/widgets/misc/e-activity-proxy.c
branches/kill-bonobo/widgets/misc/e-activity.c
branches/kill-bonobo/widgets/misc/e-activity.h
branches/kill-bonobo/widgets/misc/e-attachment-bar.c
branches/kill-bonobo/widgets/misc/e-attachment-bar.h
Modified: branches/kill-bonobo/calendar/gui/dialogs/comp-editor.c
==============================================================================
--- branches/kill-bonobo/calendar/gui/dialogs/comp-editor.c (original)
+++ branches/kill-bonobo/calendar/gui/dialogs/comp-editor.c Tue Mar 10 01:06:18 2009
@@ -2341,46 +2341,28 @@
comp_editor_get_action (CompEditor *editor,
const gchar *action_name)
{
- GtkAction *action = NULL;
- GList *iter;
+ GtkUIManager *ui_manager;
g_return_val_if_fail (IS_COMP_EDITOR (editor), NULL);
g_return_val_if_fail (action_name != NULL, NULL);
- iter = gtk_ui_manager_get_action_groups (editor->priv->manager);
- while (iter != NULL && action == NULL) {
- GtkActionGroup *action_group = iter->data;
+ ui_manager = comp_editor_get_ui_manager (editor);
- action = gtk_action_group_get_action (
- action_group, action_name);
- iter = g_list_next (iter);
- }
- g_return_val_if_fail (action != NULL, NULL);
-
- return action;
+ return e_lookup_action (ui_manager, action_name);
}
GtkActionGroup *
comp_editor_get_action_group (CompEditor *editor,
const gchar *group_name)
{
- GList *iter;
+ GtkUIManager *ui_manager;
g_return_val_if_fail (IS_COMP_EDITOR (editor), NULL);
g_return_val_if_fail (group_name != NULL, NULL);
- iter = gtk_ui_manager_get_action_groups (editor->priv->manager);
- while (iter != NULL) {
- GtkActionGroup *action_group = iter->data;
- const gchar *name;
-
- name = gtk_action_group_get_name (action_group);
- if (strcmp (name, group_name) == 0)
- return action_group;
- iter = g_list_next (iter);
- }
+ ui_manager = comp_editor_get_ui_manager (editor);
- g_return_val_if_reached (NULL);
+ return e_lookup_action_group (ui_manager, group_name);
}
GtkWidget *
Modified: branches/kill-bonobo/e-util/e-util.c
==============================================================================
--- branches/kill-bonobo/e-util/e-util.c (original)
+++ branches/kill-bonobo/e-util/e-util.c Tue Mar 10 01:06:18 2009
@@ -213,6 +213,86 @@
}
/**
+ * e_lookup_action:
+ * @ui_manager: a #GtkUIManager
+ * @action_name: the name of an action
+ *
+ * Returns the first #GtkAction named @action_name by traversing the
+ * list of action groups in @ui_manager. If no such action exists, the
+ * function emits a critical warning before returning %NULL, since this
+ * probably indicates a programming error and most code is not prepared
+ * to deal with lookup failures.
+ *
+ * Returns: the first #GtkAction named @action_name
+ **/
+GtkAction *
+e_lookup_action (GtkUIManager *ui_manager,
+ const gchar *action_name)
+{
+ GtkAction *action = NULL;
+ GList *iter;
+
+ g_return_val_if_fail (GTK_IS_UI_MANAGER (ui_manager), NULL);
+ g_return_val_if_fail (action_name != NULL, NULL);
+
+ iter = gtk_ui_manager_get_action_groups (ui_manager);
+
+ while (iter != NULL) {
+ GtkActionGroup *action_group = iter->data;
+
+ action = gtk_action_group_get_action (
+ action_group, action_name);
+ if (action != NULL)
+ return action;
+
+ iter = g_list_next (iter);
+ }
+
+ g_critical ("%s: action `%s' not found", G_STRFUNC, action_name);
+
+ return NULL;
+}
+
+/**
+ * e_lookup_action_group:
+ * @ui_manager: a #GtkUIManager
+ * @group_name: the name of an action group
+ *
+ * Returns the #GtkActionGroup in @ui_manager named @group_name. If no
+ * such action group exists, the function emits a critical warnings before
+ * returning %NULL, since this probably indicates a programming error and
+ * most code is not prepared to deal with lookup failures.
+ *
+ * Returns: the #GtkActionGroup named @group_name
+ **/
+GtkActionGroup *
+e_lookup_action_group (GtkUIManager *ui_manager,
+ const gchar *group_name)
+{
+ GList *iter;
+
+ g_return_val_if_fail (GTK_IS_UI_MANAGER (ui_manager), NULL);
+ g_return_val_if_fail (group_name != NULL, NULL);
+
+ iter = gtk_ui_manager_get_action_groups (ui_manager);
+
+ while (iter != NULL) {
+ GtkActionGroup *action_group = iter->data;
+ const gchar *name;
+
+ name = gtk_action_group_get_name (action_group);
+ if (strcmp (name, group_name) == 0)
+ return action_group;
+
+ iter = g_list_next (iter);
+ }
+
+ g_critical ("%s: action group `%s' not found", G_STRFUNC, group_name);
+
+ return NULL;
+}
+
+/**
* e_load_ui_definition:
* @ui_manager: a #GtkUIManager
* @basename: basename of the UI definition file
Modified: branches/kill-bonobo/e-util/e-util.h
==============================================================================
--- branches/kill-bonobo/e-util/e-util.h (original)
+++ branches/kill-bonobo/e-util/e-util.h Tue Mar 10 01:06:18 2009
@@ -48,6 +48,10 @@
const gchar *link_id);
gint e_file_open_tmp (gchar **name_used,
GError **error);
+GtkAction * e_lookup_action (GtkUIManager *ui_manager,
+ const gchar *action_name);
+GtkActionGroup *e_lookup_action_group (GtkUIManager *ui_manager,
+ const gchar *group_name);
guint e_load_ui_definition (GtkUIManager *ui_manager,
const gchar *basename);
gint e_action_compare_by_label (GtkAction *action1,
Modified: branches/kill-bonobo/mail/mail-mt.c
==============================================================================
--- branches/kill-bonobo/mail/mail-mt.c (original)
+++ branches/kill-bonobo/mail/mail-mt.c Tue Mar 10 01:06:18 2009
@@ -988,7 +988,7 @@
}
data->activity = e_activity_new (what);
- e_activity_set_cancellable (data->activity, TRUE);
+ e_activity_set_allow_cancel (data->activity, TRUE);
e_activity_set_percent (data->activity, 0.0);
e_shell_module_add_activity (mail_shell_module, data->activity);
Modified: branches/kill-bonobo/shell/e-shell-window.c
==============================================================================
--- branches/kill-bonobo/shell/e-shell-window.c (original)
+++ branches/kill-bonobo/shell/e-shell-window.c Tue Mar 10 01:06:18 2009
@@ -555,29 +555,13 @@
const gchar *action_name)
{
GtkUIManager *ui_manager;
- GtkAction *action = NULL;
- GList *iter;
g_return_val_if_fail (E_IS_SHELL_WINDOW (shell_window), NULL);
g_return_val_if_fail (action_name != NULL, NULL);
ui_manager = e_shell_window_get_ui_manager (shell_window);
- iter = gtk_ui_manager_get_action_groups (ui_manager);
- while (iter != NULL) {
- GtkActionGroup *action_group = iter->data;
-
- action = gtk_action_group_get_action (
- action_group, action_name);
- if (action != NULL)
- return action;
-
- iter = g_list_next (iter);
- }
-
- g_critical ("%s: action `%s' not found", G_STRFUNC, action_name);
-
- return NULL;
+ return e_lookup_action (ui_manager, action_name);
}
/**
@@ -596,28 +580,13 @@
const gchar *group_name)
{
GtkUIManager *ui_manager;
- GList *iter;
g_return_val_if_fail (E_IS_SHELL_WINDOW (shell_window), NULL);
g_return_val_if_fail (group_name != NULL, NULL);
ui_manager = e_shell_window_get_ui_manager (shell_window);
- iter = gtk_ui_manager_get_action_groups (ui_manager);
-
- while (iter != NULL) {
- GtkActionGroup *action_group = iter->data;
- const gchar *name;
-
- name = gtk_action_group_get_name (action_group);
- if (strcmp (name, group_name) == 0)
- return action_group;
-
- iter = g_list_next (iter);
- }
-
- g_critical ("%s: action group `%s' not found", G_STRFUNC, group_name);
- return NULL;
+ return e_lookup_action_group (ui_manager, group_name);
}
/**
Modified: branches/kill-bonobo/shell/test/e-test-shell-view.c
==============================================================================
--- branches/kill-bonobo/shell/test/e-test-shell-view.c (original)
+++ branches/kill-bonobo/shell/test/e-test-shell-view.c Tue Mar 10 01:06:18 2009
@@ -95,7 +95,7 @@
gtk_widget_show (widget);
activity = e_activity_new ("Test Activity");
- e_activity_set_cancellable (activity, TRUE);
+ e_activity_set_allow_cancel (activity, TRUE);
e_shell_module_add_activity (shell_module, activity);
priv->activity = activity;
}
Modified: branches/kill-bonobo/widgets/misc/Makefile.am
==============================================================================
--- branches/kill-bonobo/widgets/misc/Makefile.am (original)
+++ branches/kill-bonobo/widgets/misc/Makefile.am Tue Mar 10 01:06:18 2009
@@ -57,6 +57,7 @@
e-cursors.h \
e-dateedit.h \
e-expander.h \
+ e-file-activity.h \
e-gui-utils.h \
e-hsv-utils.h \
e-icon-entry.h \
@@ -114,6 +115,7 @@
e-cursors.c \
e-dateedit.c \
e-expander.c \
+ e-file-activity.c \
e-gui-utils.c \
e-hsv-utils.c \
e-icon-entry.c \
Modified: branches/kill-bonobo/widgets/misc/e-activity-proxy.c
==============================================================================
--- branches/kill-bonobo/widgets/misc/e-activity-proxy.c (original)
+++ branches/kill-bonobo/widgets/misc/e-activity-proxy.c Tue Mar 10 01:06:18 2009
@@ -49,14 +49,14 @@
{
EActivity *activity = proxy->priv->activity;
const gchar *icon_name;
- gboolean cancellable;
+ gboolean allow_cancel;
gboolean cancelled;
gboolean clickable;
gboolean completed;
gboolean sensitive;
gchar *description;
- cancellable = e_activity_get_cancellable (activity);
+ allow_cancel = e_activity_get_allow_cancel (activity);
cancelled = e_activity_is_cancelled (activity);
clickable = e_activity_get_clickable (activity);
completed = e_activity_is_completed (activity);
@@ -91,7 +91,7 @@
gtk_widget_hide (proxy->priv->image);
}
- if (cancellable)
+ if (allow_cancel)
gtk_widget_show (proxy->priv->cancel);
else
gtk_widget_hide (proxy->priv->cancel);
Modified: branches/kill-bonobo/widgets/misc/e-activity.c
==============================================================================
--- branches/kill-bonobo/widgets/misc/e-activity.c (original)
+++ branches/kill-bonobo/widgets/misc/e-activity.c Tue Mar 10 01:06:18 2009
@@ -33,8 +33,8 @@
gchar *secondary_text;
gdouble percent;
+ guint allow_cancel : 1;
guint blocking : 1;
- guint cancellable : 1;
guint cancelled : 1;
guint clickable : 1;
guint completed : 1;
@@ -42,8 +42,8 @@
enum {
PROP_0,
+ PROP_ALLOW_CANCEL,
PROP_BLOCKING,
- PROP_CANCELLABLE,
PROP_CLICKABLE,
PROP_ICON_NAME,
PROP_PERCENT,
@@ -68,14 +68,14 @@
GParamSpec *pspec)
{
switch (property_id) {
- case PROP_BLOCKING:
- e_activity_set_blocking (
+ case PROP_ALLOW_CANCEL:
+ e_activity_set_allow_cancel (
E_ACTIVITY (object),
g_value_get_boolean (value));
return;
- case PROP_CANCELLABLE:
- e_activity_set_cancellable (
+ case PROP_BLOCKING:
+ e_activity_set_blocking (
E_ACTIVITY (object),
g_value_get_boolean (value));
return;
@@ -121,15 +121,15 @@
GParamSpec *pspec)
{
switch (property_id) {
- case PROP_BLOCKING:
+ case PROP_ALLOW_CANCEL:
g_value_set_boolean (
- value, e_activity_get_blocking (
+ value, e_activity_get_allow_cancel (
E_ACTIVITY (object)));
return;
- case PROP_CANCELLABLE:
+ case PROP_BLOCKING:
g_value_set_boolean (
- value, e_activity_get_cancellable (
+ value, e_activity_get_blocking (
E_ACTIVITY (object)));
return;
@@ -256,23 +256,23 @@
g_object_class_install_property (
object_class,
- PROP_BLOCKING,
+ PROP_ALLOW_CANCEL,
g_param_spec_boolean (
- "blocking",
+ "allow-cancel",
NULL,
NULL,
- TRUE,
+ FALSE,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT));
g_object_class_install_property (
object_class,
- PROP_CANCELLABLE,
+ PROP_BLOCKING,
g_param_spec_boolean (
- "cancellable",
+ "blocking",
NULL,
NULL,
- FALSE,
+ TRUE,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT));
@@ -405,7 +405,7 @@
e_activity_cancel (EActivity *activity)
{
g_return_if_fail (E_IS_ACTIVITY (activity));
- g_return_if_fail (activity->priv->cancellable);
+ g_return_if_fail (activity->priv->allow_cancel);
if (activity->priv->cancelled)
return;
@@ -468,41 +468,41 @@
}
gboolean
-e_activity_get_blocking (EActivity *activity)
+e_activity_get_allow_cancel (EActivity *activity)
{
g_return_val_if_fail (E_IS_ACTIVITY (activity), FALSE);
- return activity->priv->blocking;
+ return activity->priv->allow_cancel;
}
void
-e_activity_set_blocking (EActivity *activity,
- gboolean blocking)
+e_activity_set_allow_cancel (EActivity *activity,
+ gboolean allow_cancel)
{
g_return_if_fail (E_IS_ACTIVITY (activity));
- activity->priv->blocking = blocking;
+ activity->priv->allow_cancel = allow_cancel;
- g_object_notify (G_OBJECT (activity), "blocking");
+ g_object_notify (G_OBJECT (activity), "allow-cancel");
}
gboolean
-e_activity_get_cancellable (EActivity *activity)
+e_activity_get_blocking (EActivity *activity)
{
g_return_val_if_fail (E_IS_ACTIVITY (activity), FALSE);
- return activity->priv->cancellable;
+ return activity->priv->blocking;
}
void
-e_activity_set_cancellable (EActivity *activity,
- gboolean cancellable)
+e_activity_set_blocking (EActivity *activity,
+ gboolean blocking)
{
g_return_if_fail (E_IS_ACTIVITY (activity));
- activity->priv->cancellable = cancellable;
+ activity->priv->blocking = blocking;
- g_object_notify (G_OBJECT (activity), "cancellable");
+ g_object_notify (G_OBJECT (activity), "blocking");
}
gboolean
Modified: branches/kill-bonobo/widgets/misc/e-activity.h
==============================================================================
--- branches/kill-bonobo/widgets/misc/e-activity.h (original)
+++ branches/kill-bonobo/widgets/misc/e-activity.h Tue Mar 10 01:06:18 2009
@@ -74,12 +74,12 @@
gchar * e_activity_describe (EActivity *activity);
gboolean e_activity_is_cancelled (EActivity *activity);
gboolean e_activity_is_completed (EActivity *activity);
+gboolean e_activity_get_allow_cancel (EActivity *activity);
+void e_activity_set_allow_cancel (EActivity *activity,
+ gboolean allow_cancel);
gboolean e_activity_get_blocking (EActivity *activity);
void e_activity_set_blocking (EActivity *activity,
gboolean blocking);
-gboolean e_activity_get_cancellable (EActivity *activity);
-void e_activity_set_cancellable (EActivity *activity,
- gboolean cancellable);
gboolean e_activity_get_clickable (EActivity *activity);
void e_activity_set_clickable (EActivity *activity,
gboolean clickable);
Modified: branches/kill-bonobo/widgets/misc/e-attachment-bar.c
==============================================================================
--- branches/kill-bonobo/widgets/misc/e-attachment-bar.c (original)
+++ branches/kill-bonobo/widgets/misc/e-attachment-bar.c Tue Mar 10 01:06:18 2009
@@ -1261,11 +1261,9 @@
editable = e_attachment_bar_get_editable (attachment_bar);
if (editable && event->keyval == GDK_Delete) {
- GtkActionGroup *action_group;
GtkAction *action;
- action_group = attachment_bar->priv->editable_actions;
- action = gtk_action_group_get_action (action_group, "remove");
+ action = e_attachment_bar_get_action (attachment_bar, "remove");
gtk_action_activate (action);
}
@@ -1375,27 +1373,22 @@
is_image = e_attachment_is_image (attachment);
}
- ui_manager = e_attachment_bar_get_ui_manager (attachment_bar);
-
- action_group = attachment_bar->priv->standard_actions;
+ action = e_attachment_bar_get_action (attachment_bar, "properties");
+ gtk_action_set_visible (action, n_selected == 1);
- action = gtk_action_group_get_action (action_group, "save-as");
+ action = e_attachment_bar_get_action (attachment_bar, "remove");
gtk_action_set_visible (action, n_selected > 0);
- action = gtk_action_group_get_action (action_group, "set-background");
- gtk_action_set_visible (action, is_image);
-
- action_group = attachment_bar->priv->editable_actions;
-
- action = gtk_action_group_get_action (action_group, "properties");
- gtk_action_set_visible (action, n_selected == 1);
-
- action = gtk_action_group_get_action (action_group, "remove");
+ action = e_attachment_bar_get_action (attachment_bar, "save-as");
gtk_action_set_visible (action, n_selected > 0);
- action_group = attachment_bar->priv->open_actions;
+ action = e_attachment_bar_get_action (attachment_bar, "set-background");
+ gtk_action_set_visible (action, is_image);
+ /* Clear out the "open" action group. */
merge_id = attachment_bar->priv->merge_id;
+ action_group = attachment_bar->priv->open_actions;
+ ui_manager = e_attachment_bar_get_ui_manager (attachment_bar);
gtk_ui_manager_remove_ui (ui_manager, merge_id);
e_action_group_remove_all_actions (action_group);
@@ -2218,3 +2211,31 @@
return attachment_bar->priv->ui_manager;
}
+
+GtkAction *
+e_attachment_bar_get_action (EAttachmentBar *attachment_bar,
+ const gchar *action_name)
+{
+ GtkUIManager *ui_manager;
+
+ g_return_val_if_fail (E_IS_ATTACHMENT_BAR (attachment_bar), NULL);
+ g_return_val_if_fail (action_name != NULL, NULL);
+
+ ui_manager = e_attachment_bar_get_ui_manager (attachment_bar);
+
+ return e_lookup_action (ui_manager, action_name);
+}
+
+GtkActionGroup *
+e_attachment_bar_get_action_group (EAttachmentBar *attachment_bar,
+ const gchar *group_name)
+{
+ GtkUIManager *ui_manager;
+
+ g_return_val_if_fail (E_IS_ATTACHMENT_BAR (attachment_bar), NULL);
+ g_return_val_if_fail (group_name != NULL, NULL);
+
+ ui_manager = e_attachment_bar_get_ui_manager (attachment_bar);
+
+ return e_lookup_action_group (ui_manager, group_name);
+}
Modified: branches/kill-bonobo/widgets/misc/e-attachment-bar.h
==============================================================================
--- branches/kill-bonobo/widgets/misc/e-attachment-bar.h (original)
+++ branches/kill-bonobo/widgets/misc/e-attachment-bar.h Tue Mar 10 01:06:18 2009
@@ -130,6 +130,11 @@
void e_attachment_bar_set_editable (EAttachmentBar *attachment_bar,
gboolean editable);
GtkUIManager * e_attachment_bar_get_ui_manager (EAttachmentBar *attachment_bar);
+GtkAction * e_attachment_bar_get_action (EAttachmentBar *attachment_bar,
+ const gchar *action_name);
+GtkActionGroup *e_attachment_bar_get_action_group
+ (EAttachmentBar *attachment_bar,
+ const gchar *group_name);
G_END_DECLS
Added: branches/kill-bonobo/widgets/misc/e-file-activity.c
==============================================================================
--- (empty file)
+++ branches/kill-bonobo/widgets/misc/e-file-activity.c Tue Mar 10 01:06:18 2009
@@ -0,0 +1,234 @@
+/*
+ * e-file-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-file-activity.h"
+
+#define E_FILE_ACTIVITY_GET_PRIVATE(obj) \
+ (G_TYPE_INSTANCE_GET_PRIVATE \
+ ((obj), E_TYPE_FILE_ACTIVITY, EFileActivityPrivate))
+
+struct _EFileActivityPrivate {
+ GCancellable *cancellable;
+ gulong handler_id;
+};
+
+enum {
+ PROP_0,
+ PROP_CANCELLABLE
+};
+
+static gpointer parent_class;
+
+static void
+file_activity_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ switch (property_id) {
+ case PROP_CANCELLABLE:
+ e_file_activity_set_cancellable (
+ E_FILE_ACTIVITY (object),
+ g_value_get_object (value));
+ return;
+ }
+
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+}
+
+static void
+file_activity_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ switch (property_id) {
+ case PROP_CANCELLABLE:
+ g_value_set_object (
+ value, e_file_activity_get_cancellable (
+ E_FILE_ACTIVITY (object)));
+ return;
+ }
+
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+}
+
+static void
+file_activity_dispose (GObject *object)
+{
+ EFileActivityPrivate *priv;
+
+ priv = E_FILE_ACTIVITY_GET_PRIVATE (object);
+
+ if (priv->cancellable != NULL) {
+ g_signal_handler_disconnect (
+ priv->cancellable, priv->handler_id);
+ g_object_unref (priv->cancellable);
+ priv->cancellable = NULL;
+ }
+
+ /* Chain up to parent's dispose() method. */
+ G_OBJECT_CLASS (parent_class)->dispose (object);
+}
+
+static void
+file_activity_cancelled (EActivity *activity)
+{
+ EFileActivity *file_activity;
+ GCancellable *cancellable;
+
+ file_activity = E_FILE_ACTIVITY (activity);
+ cancellable = e_file_activity_get_cancellable (file_activity);
+ g_cancellable_cancel (cancellable);
+
+ /* Chain up to parent's cancelled() method. */
+ E_ACTIVITY_CLASS (parent_class)->cancelled (activity);
+}
+
+static void
+file_activity_class_init (EFileActivityClass *class)
+{
+ GObjectClass *object_class;
+ EActivityClass *activity_class;
+
+ parent_class = g_type_class_peek_parent (class);
+ g_type_class_add_private (class, sizeof (EFileActivityPrivate));
+
+ object_class = G_OBJECT_CLASS (class);
+ object_class->set_property = file_activity_set_property;
+ object_class->get_property = file_activity_get_property;
+ object_class->dispose = file_activity_dispose;
+
+ activity_class = E_ACTIVITY_CLASS (class);
+ activity_class->cancelled = file_activity_cancelled;
+
+ g_object_class_install_property (
+ object_class,
+ PROP_CANCELLABLE,
+ g_param_spec_object (
+ "cancellable",
+ "Cancellable",
+ NULL,
+ G_TYPE_CANCELLABLE,
+ G_PARAM_READWRITE));
+}
+
+static void
+file_activity_init (EFileActivity *file_activity)
+{
+ GCancellable *cancellable;
+
+ file_activity->priv = E_FILE_ACTIVITY_GET_PRIVATE (file_activity);
+
+ e_activity_set_allow_cancel (E_ACTIVITY (file_activity), TRUE);
+
+ cancellable = g_cancellable_new ();
+ e_file_activity_set_cancellable (file_activity, cancellable);
+ g_object_unref (cancellable);
+}
+
+GType
+e_file_activity_get_type (void)
+{
+ static GType type = 0;
+
+ if (G_UNLIKELY (type == 0)) {
+ static const GTypeInfo type_info = {
+ sizeof (EFileActivityClass),
+ (GBaseInitFunc) NULL,
+ (GBaseFinalizeFunc) NULL,
+ (GClassInitFunc) file_activity_class_init,
+ (GClassFinalizeFunc) NULL,
+ NULL, /* class_data */
+ sizeof (EFileActivity),
+ 0, /* n_preallocs */
+ (GInstanceInitFunc) file_activity_init,
+ NULL /* value_table */
+ };
+
+ type = g_type_register_static (
+ E_TYPE_ACTIVITY, "EFileActivity", &type_info, 0);
+ }
+
+ return type;
+}
+
+EActivity *
+e_file_activity_new (const gchar *primary_text)
+{
+ return g_object_new (
+ E_TYPE_FILE_ACTIVITY,
+ "primary-text", primary_text, NULL);
+}
+
+GCancellable *
+e_file_activity_get_cancellable (EFileActivity *file_activity)
+{
+ g_return_val_if_fail (E_IS_FILE_ACTIVITY (file_activity), NULL);
+
+ return file_activity->priv->cancellable;
+}
+
+void
+e_file_activity_set_cancellable (EFileActivity *file_activity,
+ GCancellable *cancellable)
+{
+ g_return_if_fail (E_IS_FILE_ACTIVITY (file_activity));
+
+ if (cancellable != NULL) {
+ g_return_if_fail (G_IS_CANCELLABLE (cancellable));
+ g_object_ref (cancellable);
+ }
+
+ if (file_activity->priv->cancellable != NULL) {
+ g_signal_handler_disconnect (
+ file_activity->priv->cancellable,
+ file_activity->priv->handler_id);
+ g_object_unref (file_activity->priv->cancellable);
+ file_activity->priv->handler_id = 0;
+ }
+
+ file_activity->priv->cancellable = cancellable;
+
+ if (cancellable != NULL)
+ file_activity->priv->handler_id =
+ g_signal_connect_swapped (
+ cancellable, "cancelled",
+ G_CALLBACK (e_activity_cancel),
+ file_activity);
+
+ g_object_notify (G_OBJECT (file_activity), "cancellable");
+}
+
+void
+e_file_activity_progress (goffset current_num_bytes,
+ goffset total_num_bytes,
+ gpointer activity)
+{
+ gdouble percent = -1.0;
+
+ g_return_if_fail (E_IS_ACTIVITY (activity));
+
+ if (current_num_bytes > 0 && total_num_bytes > 0)
+ percent = (gdouble) current_num_bytes / total_num_bytes;
+
+ e_activity_set_percent (activity, percent);
+}
Added: branches/kill-bonobo/widgets/misc/e-file-activity.h
==============================================================================
--- (empty file)
+++ branches/kill-bonobo/widgets/misc/e-file-activity.h Tue Mar 10 01:06:18 2009
@@ -0,0 +1,75 @@
+/*
+ * e-file-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_FILE_ACTIVITY_H
+#define E_FILE_ACTIVITY_H
+
+#include <gio/gio.h>
+#include <e-activity.h>
+
+/* Standard GObject macros */
+#define E_TYPE_FILE_ACTIVITY \
+ (e_file_activity_get_type ())
+#define E_FILE_ACTIVITY(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST \
+ ((obj), E_TYPE_FILE_ACTIVITY, EFileActivity))
+#define E_FILE_ACTIVITY_CLASS(cls) \
+ (G_TYPE_CHECK_CLASS_CAST \
+ ((cls), E_TYPE_FILE_ACTIVITY, EFileActivityClass))
+#define E_IS_FILE_ACTIVITY(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE \
+ ((obj), E_TYPE_FILE_ACTIVITY))
+#define E_IS_FILE_ACTIVITY_CLASS(cls) \
+ (G_TYPE_CHECK_CLASS_TYPE \
+ ((cls), E_TYPE_FILE_ACTIVITY))
+#define E_FILE_ACTIVITY_GET_CLASS(obj) \
+ (G_TYPE_INSTANCE_GET_CLASS \
+ ((obj), E_TYPE_FILE_ACTIVITY, EFileActivityClass))
+
+G_BEGIN_DECLS
+
+typedef struct _EFileActivity EFileActivity;
+typedef struct _EFileActivityClass EFileActivityClass;
+typedef struct _EFileActivityPrivate EFileActivityPrivate;
+
+struct _EFileActivity {
+ EActivity parent;
+ EFileActivityPrivate *priv;
+};
+
+struct _EFileActivityClass {
+ EActivityClass parent_class;
+};
+
+GType e_file_activity_get_type (void);
+EActivity * e_file_activity_new (const gchar *primary_text);
+GCancellable * e_file_activity_get_cancellable (EFileActivity *file_activity);
+void e_file_activity_set_cancellable (EFileActivity *file_activity,
+ GCancellable *cancellable);
+
+/* This can be used as a GFileProgressCallback. */
+void e_file_activity_progress (goffset current_num_bytes,
+ goffset total_num_bytes,
+ gpointer activity);
+
+G_END_DECLS
+
+#endif /* E_FILE_ACTIVITY_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]