aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--calendar/gui/dialogs/comp-editor.c30
-rw-r--r--e-util/e-util.c80
-rw-r--r--e-util/e-util.h4
-rw-r--r--mail/mail-mt.c2
-rw-r--r--shell/e-shell-window.c35
-rw-r--r--shell/test/e-test-shell-view.c2
-rw-r--r--widgets/misc/Makefile.am2
-rw-r--r--widgets/misc/e-activity-proxy.c6
-rw-r--r--widgets/misc/e-activity.c58
-rw-r--r--widgets/misc/e-activity.h6
-rw-r--r--widgets/misc/e-attachment-bar.c55
-rw-r--r--widgets/misc/e-attachment-bar.h5
-rw-r--r--widgets/misc/e-file-activity.c234
-rw-r--r--widgets/misc/e-file-activity.h75
14 files changed, 483 insertions, 111 deletions
diff --git a/calendar/gui/dialogs/comp-editor.c b/calendar/gui/dialogs/comp-editor.c
index 4e1bf9972f..7be36d043b 100644
--- a/calendar/gui/dialogs/comp-editor.c
+++ b/calendar/gui/dialogs/comp-editor.c
@@ -2341,46 +2341,28 @@ GtkAction *
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 *
diff --git a/e-util/e-util.c b/e-util/e-util.c
index 32f6169bd5..e4e9a3ac32 100644
--- a/e-util/e-util.c
+++ b/e-util/e-util.c
@@ -213,6 +213,86 @@ e_file_open_tmp (gchar **name_used,
}
/**
+ * 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
diff --git a/e-util/e-util.h b/e-util/e-util.h
index 5f431156eb..744b4a7a9d 100644
--- a/e-util/e-util.h
+++ b/e-util/e-util.h
@@ -48,6 +48,10 @@ void e_display_help (GtkWindow *parent,
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,
diff --git a/mail/mail-mt.c b/mail/mail-mt.c
index b246cd2899..77d8bf5dfb 100644
--- a/mail/mail-mt.c
+++ b/mail/mail-mt.c
@@ -988,7 +988,7 @@ op_status_exec (struct _op_status_msg *m)
}
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);
diff --git a/shell/e-shell-window.c b/shell/e-shell-window.c
index e16c22cc66..c054d6a8a0 100644
--- a/shell/e-shell-window.c
+++ b/shell/e-shell-window.c
@@ -555,29 +555,13 @@ e_shell_window_get_action (EShellWindow *shell_window,
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 @@ e_shell_window_get_action_group (EShellWindow *shell_window,
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);
}
/**
diff --git a/shell/test/e-test-shell-view.c b/shell/test/e-test-shell-view.c
index bb7da527fd..9bbffaf4cc 100644
--- a/shell/test/e-test-shell-view.c
+++ b/shell/test/e-test-shell-view.c
@@ -95,7 +95,7 @@ test_shell_view_constructed (GObject *object)
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;
}
diff --git a/widgets/misc/Makefile.am b/widgets/misc/Makefile.am
index ffbe7fa5fb..8e79779d6d 100644
--- a/widgets/misc/Makefile.am
+++ b/widgets/misc/Makefile.am
@@ -57,6 +57,7 @@ widgetsinclude_HEADERS = \
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 @@ libemiscwidgets_la_SOURCES = \
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 \
diff --git a/widgets/misc/e-activity-proxy.c b/widgets/misc/e-activity-proxy.c
index 9c08a8d9a0..bddcc124f3 100644
--- a/widgets/misc/e-activity-proxy.c
+++ b/widgets/misc/e-activity-proxy.c
@@ -49,14 +49,14 @@ activity_proxy_update (EActivityProxy *proxy)
{
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 @@ activity_proxy_update (EActivityProxy *proxy)
gtk_widget_hide (proxy->priv->image);
}
- if (cancellable)
+ if (allow_cancel)
gtk_widget_show (proxy->priv->cancel);
else
gtk_widget_hide (proxy->priv->cancel);
diff --git a/widgets/misc/e-activity.c b/widgets/misc/e-activity.c
index 40ee0df35a..352300f023 100644
--- a/widgets/misc/e-activity.c
+++ b/widgets/misc/e-activity.c
@@ -33,8 +33,8 @@ struct _EActivityPrivate {
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 @@ struct _EActivityPrivate {
enum {
PROP_0,
+ PROP_ALLOW_CANCEL,
PROP_BLOCKING,
- PROP_CANCELLABLE,
PROP_CLICKABLE,
PROP_ICON_NAME,
PROP_PERCENT,
@@ -68,14 +68,14 @@ activity_set_property (GObject *object,
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 @@ activity_get_property (GObject *object,
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 @@ activity_class_init (EActivityClass *class)
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 @@ void
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 @@ e_activity_is_completed (EActivity *activity)
}
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
diff --git a/widgets/misc/e-activity.h b/widgets/misc/e-activity.h
index 5050d9e611..9a14c073a0 100644
--- a/widgets/misc/e-activity.h
+++ b/widgets/misc/e-activity.h
@@ -74,12 +74,12 @@ void e_activity_clicked (EActivity *activity);
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);
diff --git a/widgets/misc/e-attachment-bar.c b/widgets/misc/e-attachment-bar.c
index 4608d77b9d..5a1a6359de 100644
--- a/widgets/misc/e-attachment-bar.c
+++ b/widgets/misc/e-attachment-bar.c
@@ -1261,11 +1261,9 @@ attachment_bar_key_press_event (GtkWidget *widget,
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 @@ attachment_bar_update_actions (EAttachmentBar *attachment_bar)
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 @@ e_attachment_bar_get_ui_manager (EAttachmentBar *attachment_bar)
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);
+}
diff --git a/widgets/misc/e-attachment-bar.h b/widgets/misc/e-attachment-bar.h
index a55dcb11f6..a9b0655276 100644
--- a/widgets/misc/e-attachment-bar.h
+++ b/widgets/misc/e-attachment-bar.h
@@ -130,6 +130,11 @@ gboolean e_attachment_bar_get_editable (EAttachmentBar *attachment_bar);
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
diff --git a/widgets/misc/e-file-activity.c b/widgets/misc/e-file-activity.c
new file mode 100644
index 0000000000..38dae234df
--- /dev/null
+++ b/widgets/misc/e-file-activity.c
@@ -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);
+}
diff --git a/widgets/misc/e-file-activity.h b/widgets/misc/e-file-activity.h
new file mode 100644
index 0000000000..4a57228872
--- /dev/null
+++ b/widgets/misc/e-file-activity.h
@@ -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 */