aboutsummaryrefslogtreecommitdiffstats
path: root/widgets/misc
diff options
context:
space:
mode:
authorMatthew Barnes <mbarnes@redhat.com>2010-08-27 07:32:36 +0800
committerMatthew Barnes <mbarnes@redhat.com>2010-08-27 07:32:36 +0800
commit8223eaf57016792a4fcbe90b8923eadb2cd87a45 (patch)
tree5123bfa28050b5efec2b5c9e75681d37a24d08d0 /widgets/misc
parent87a3fac95cfdcb3dde4e0b75718239de20d8812f (diff)
downloadgsoc2013-evolution-8223eaf57016792a4fcbe90b8923eadb2cd87a45.tar
gsoc2013-evolution-8223eaf57016792a4fcbe90b8923eadb2cd87a45.tar.gz
gsoc2013-evolution-8223eaf57016792a4fcbe90b8923eadb2cd87a45.tar.bz2
gsoc2013-evolution-8223eaf57016792a4fcbe90b8923eadb2cd87a45.tar.lz
gsoc2013-evolution-8223eaf57016792a4fcbe90b8923eadb2cd87a45.tar.xz
gsoc2013-evolution-8223eaf57016792a4fcbe90b8923eadb2cd87a45.tar.zst
gsoc2013-evolution-8223eaf57016792a4fcbe90b8923eadb2cd87a45.zip
Convert EAttachmentHandler to an EExtension.
EAttachmentHandler predates EExtension, so this is really just a code cleanup to use the extension framework. But this also demonstrates that extensions can target interfaces as well as instantiable types, since EAttachmentView is an interface. What's also nice is EAttachmentView no longer has to directly interact with attachment handlers. Instead of EAttachmentView having to query each attachment handler for drag-and-drop info, each handler now pushes its own drag-and-drop info to its EAttachmentView during initialization.
Diffstat (limited to 'widgets/misc')
-rw-r--r--widgets/misc/e-attachment-handler.c114
-rw-r--r--widgets/misc/e-attachment-handler.h5
-rw-r--r--widgets/misc/e-attachment-icon-view.c7
-rw-r--r--widgets/misc/e-attachment-tree-view.c5
-rw-r--r--widgets/misc/e-attachment-view.c47
-rw-r--r--widgets/misc/e-attachment-view.h6
6 files changed, 61 insertions, 123 deletions
diff --git a/widgets/misc/e-attachment-handler.c b/widgets/misc/e-attachment-handler.c
index 947ae666d9..0b9c057b65 100644
--- a/widgets/misc/e-attachment-handler.c
+++ b/widgets/misc/e-attachment-handler.c
@@ -26,113 +26,53 @@
((obj), E_TYPE_ATTACHMENT_HANDLER, EAttachmentHandlerPrivate))
struct _EAttachmentHandlerPrivate {
- gpointer view; /* weak pointer */
-};
-
-enum {
- PROP_0,
- PROP_VIEW
+ gpointer placeholder;
};
G_DEFINE_TYPE (
EAttachmentHandler,
e_attachment_handler,
- G_TYPE_OBJECT)
-
-static void
-attachment_handler_set_view (EAttachmentHandler *handler,
- EAttachmentView *view)
-{
- g_return_if_fail (handler->priv->view == NULL);
-
- handler->priv->view = view;
-
- g_object_add_weak_pointer (
- G_OBJECT (view), &handler->priv->view);
-}
-
-static void
-attachment_handler_set_property (GObject *object,
- guint property_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- switch (property_id) {
- case PROP_VIEW:
- attachment_handler_set_view (
- E_ATTACHMENT_HANDLER (object),
- g_value_get_object (value));
- return;
- }
-
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
-}
-
-static void
-attachment_handler_get_property (GObject *object,
- guint property_id,
- GValue *value,
- GParamSpec *pspec)
-{
- switch (property_id) {
- case PROP_VIEW:
- g_value_set_object (
- value, e_attachment_handler_get_view (
- E_ATTACHMENT_HANDLER (object)));
- return;
- }
-
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
-}
+ E_TYPE_EXTENSION)
static void
attachment_handler_constructed (GObject *object)
{
- /* This allows subclasses to chain up safely since GObject
- * does not implement this method, and we might want to do
- * something here in the future. */
-}
+ EAttachmentView *view;
+ EAttachmentHandler *handler;
+ GdkDragAction drag_actions;
+ GtkTargetList *target_list;
+ const GtkTargetEntry *targets;
+ guint n_targets;
-static void
-attachment_handler_dispose (GObject *object)
-{
- EAttachmentHandlerPrivate *priv;
+ handler = E_ATTACHMENT_HANDLER (object);
+ drag_actions = e_attachment_handler_get_drag_actions (handler);
+ targets = e_attachment_handler_get_target_table (handler, &n_targets);
+
+ view = e_attachment_handler_get_view (handler);
- priv = E_ATTACHMENT_HANDLER_GET_PRIVATE (object);
+ target_list = e_attachment_view_get_target_list (view);
+ gtk_target_list_add_table (target_list, targets, n_targets);
- if (priv->view != NULL) {
- g_object_remove_weak_pointer (
- G_OBJECT (priv->view), &priv->view);
- priv->view = NULL;
- }
+ e_attachment_view_add_drag_actions (view, drag_actions);
- /* Chain up to parent's dispose() method. */
- G_OBJECT_CLASS (e_attachment_handler_parent_class)->dispose (object);
+ /* Chain up to parent's constructed() method. */
+ G_OBJECT_CLASS (e_attachment_handler_parent_class)->
+ constructed (object);
}
static void
e_attachment_handler_class_init (EAttachmentHandlerClass *class)
{
GObjectClass *object_class;
+ EExtensionClass *extension_class;
g_type_class_add_private (class, sizeof (EAttachmentHandlerPrivate));
object_class = G_OBJECT_CLASS (class);
- object_class->set_property = attachment_handler_set_property;
- object_class->get_property = attachment_handler_get_property;
object_class->constructed = attachment_handler_constructed;
- object_class->dispose = attachment_handler_dispose;
-
- g_object_class_install_property (
- object_class,
- PROP_VIEW,
- g_param_spec_object (
- "view",
- "View",
- NULL,
- E_TYPE_ATTACHMENT_VIEW,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT_ONLY));
+
+ extension_class = E_EXTENSION_CLASS (class);
+ extension_class->extensible_type = E_TYPE_ATTACHMENT_VIEW;
}
static void
@@ -144,9 +84,15 @@ e_attachment_handler_init (EAttachmentHandler *handler)
EAttachmentView *
e_attachment_handler_get_view (EAttachmentHandler *handler)
{
+ EExtensible *extensible;
+
+ /* This is purely a convenience function. */
+
g_return_val_if_fail (E_IS_ATTACHMENT_HANDLER (handler), NULL);
- return E_ATTACHMENT_VIEW (handler->priv->view);
+ extensible = e_extension_get_extensible (E_EXTENSION (handler));
+
+ return E_ATTACHMENT_VIEW (extensible);
}
GdkDragAction
diff --git a/widgets/misc/e-attachment-handler.h b/widgets/misc/e-attachment-handler.h
index e7e52c8c18..e85cd9b2ee 100644
--- a/widgets/misc/e-attachment-handler.h
+++ b/widgets/misc/e-attachment-handler.h
@@ -22,6 +22,7 @@
#ifndef E_ATTACHMENT_HANDLER_H
#define E_ATTACHMENT_HANDLER_H
+#include <e-util/e-extension.h>
#include <misc/e-attachment-view.h>
/* Standard GObject macros */
@@ -50,12 +51,12 @@ typedef struct _EAttachmentHandlerClass EAttachmentHandlerClass;
typedef struct _EAttachmentHandlerPrivate EAttachmentHandlerPrivate;
struct _EAttachmentHandler {
- GObject parent;
+ EExtension parent;
EAttachmentHandlerPrivate *priv;
};
struct _EAttachmentHandlerClass {
- GObjectClass parent_class;
+ EExtensionClass parent_class;
GdkDragAction (*get_drag_actions) (EAttachmentHandler *handler);
const GtkTargetEntry *
diff --git a/widgets/misc/e-attachment-icon-view.c b/widgets/misc/e-attachment-icon-view.c
index 5c874f8bca..9ec8fce83d 100644
--- a/widgets/misc/e-attachment-icon-view.c
+++ b/widgets/misc/e-attachment-icon-view.c
@@ -22,6 +22,7 @@
#include "e-attachment-icon-view.h"
#include <glib/gi18n.h>
+#include <e-util/e-extensible.h>
#include "e-attachment.h"
#include "e-attachment-store.h"
@@ -53,7 +54,9 @@ G_DEFINE_TYPE_WITH_CODE (
GTK_TYPE_ICON_VIEW,
G_IMPLEMENT_INTERFACE (
E_TYPE_ATTACHMENT_VIEW,
- e_attachment_icon_view_interface_init))
+ e_attachment_icon_view_interface_init)
+ G_IMPLEMENT_INTERFACE (
+ E_TYPE_EXTENSIBLE, NULL))
void
e_attachment_icon_view_set_default_icon_size (gint size)
@@ -522,6 +525,8 @@ e_attachment_icon_view_init (EAttachmentIconView *icon_view)
gtk_cell_layout_add_attribute (
cell_layout, renderer, "visible",
E_ATTACHMENT_STORE_COLUMN_SAVING);
+
+ e_extensible_load_extensions (E_EXTENSIBLE (icon_view));
}
static void
diff --git a/widgets/misc/e-attachment-tree-view.c b/widgets/misc/e-attachment-tree-view.c
index c404920d33..a2210db5a6 100644
--- a/widgets/misc/e-attachment-tree-view.c
+++ b/widgets/misc/e-attachment-tree-view.c
@@ -22,6 +22,7 @@
#include "e-attachment-tree-view.h"
#include <glib/gi18n.h>
+#include <e-util/e-extensible.h>
#include "e-attachment.h"
#include "e-attachment-store.h"
@@ -51,7 +52,9 @@ G_DEFINE_TYPE_WITH_CODE (
GTK_TYPE_TREE_VIEW,
G_IMPLEMENT_INTERFACE (
E_TYPE_ATTACHMENT_VIEW,
- e_attachment_tree_view_interface_init))
+ e_attachment_tree_view_interface_init)
+ G_IMPLEMENT_INTERFACE (
+ E_TYPE_EXTENSIBLE, NULL))
static void
attachment_tree_view_set_property (GObject *object,
diff --git a/widgets/misc/e-attachment-view.c b/widgets/misc/e-attachment-view.c
index 06ec2e5d2c..a80fe32ec0 100644
--- a/widgets/misc/e-attachment-view.c
+++ b/widgets/misc/e-attachment-view.c
@@ -778,27 +778,7 @@ attachment_view_update_actions (EAttachmentView *view)
}
static void
-attachment_view_add_handler (GType type,
- EAttachmentView *view)
-{
- EAttachmentViewPrivate *priv;
- EAttachmentHandler *handler;
- const GtkTargetEntry *targets;
- guint n_targets;
-
- priv = e_attachment_view_get_private (view);
-
- handler = g_object_new (type, "view", view, NULL);
-
- targets = e_attachment_handler_get_target_table (handler, &n_targets);
- gtk_target_list_add_table (priv->target_list, targets, n_targets);
- priv->drag_actions |= e_attachment_handler_get_drag_actions (handler);
-
- g_ptr_array_add (priv->handlers, handler);
-}
-
-static void
-attachment_view_init_handlers (EAttachmentView *view)
+attachment_view_init_drag_dest (EAttachmentView *view)
{
EAttachmentViewPrivate *priv;
GtkTargetList *target_list;
@@ -812,13 +792,8 @@ attachment_view_init_handlers (EAttachmentView *view)
e_target_list_add_calendar_targets (target_list, 0);
e_target_list_add_directory_targets (target_list, 0);
- priv->handlers = g_ptr_array_new ();
priv->target_list = target_list;
priv->drag_actions = GDK_ACTION_COPY;
-
- e_type_traverse (
- E_TYPE_ATTACHMENT_HANDLER, (ETypeFunc)
- attachment_view_add_handler, view);
}
static void
@@ -904,7 +879,7 @@ e_attachment_view_init (EAttachmentView *view)
if (error != NULL)
g_error ("%s", error->message);
- attachment_view_init_handlers (view);
+ attachment_view_init_drag_dest (view);
e_attachment_view_drag_source_set (view);
@@ -934,9 +909,6 @@ e_attachment_view_dispose (EAttachmentView *view)
priv = e_attachment_view_get_private (view);
- g_ptr_array_foreach (priv->handlers, (GFunc) g_object_unref, NULL);
- g_ptr_array_set_size (priv->handlers, 0);
-
if (priv->target_list != NULL) {
gtk_target_list_unref (priv->target_list);
priv->target_list = NULL;
@@ -955,8 +927,6 @@ e_attachment_view_finalize (EAttachmentView *view)
priv = e_attachment_view_get_private (view);
- g_ptr_array_free (priv->handlers, TRUE);
-
g_list_foreach (priv->event_list, (GFunc) gdk_event_free, NULL);
g_list_free (priv->event_list);
@@ -1073,6 +1043,19 @@ e_attachment_view_get_drag_actions (EAttachmentView *view)
return priv->drag_actions;
}
+void
+e_attachment_view_add_drag_actions (EAttachmentView *view,
+ GdkDragAction drag_actions)
+{
+ EAttachmentViewPrivate *priv;
+
+ g_return_if_fail (E_IS_ATTACHMENT_VIEW (view));
+
+ priv = e_attachment_view_get_private (view);
+
+ priv->drag_actions |= drag_actions;
+}
+
GList *
e_attachment_view_get_selected_attachments (EAttachmentView *view)
{
diff --git a/widgets/misc/e-attachment-view.h b/widgets/misc/e-attachment-view.h
index b95c84bb5b..164413221c 100644
--- a/widgets/misc/e-attachment-view.h
+++ b/widgets/misc/e-attachment-view.h
@@ -92,9 +92,6 @@ struct _EAttachmentViewInterface {
struct _EAttachmentViewPrivate {
- /* Attachment Handlers */
- GPtrArray *handlers;
-
/* Drag Destination */
GtkTargetList *target_list;
GdkDragAction drag_actions;
@@ -133,6 +130,9 @@ GtkTargetList * e_attachment_view_get_target_list
(EAttachmentView *view);
GdkDragAction e_attachment_view_get_drag_actions
(EAttachmentView *view);
+void e_attachment_view_add_drag_actions
+ (EAttachmentView *view,
+ GdkDragAction drag_actions);
GList * e_attachment_view_get_selected_attachments
(EAttachmentView *view);
void e_attachment_view_open_path (EAttachmentView *view,