aboutsummaryrefslogtreecommitdiffstats
path: root/calendar
diff options
context:
space:
mode:
authorMatthew Barnes <mbarnes@src.gnome.org>2008-09-13 22:12:22 +0800
committerMatthew Barnes <mbarnes@src.gnome.org>2008-09-13 22:12:22 +0800
commit8f2b4cc6faf5a2fedbe6e11f340d492d4698072a (patch)
treea96b93fc0fb9c22699493eb9de1a7638663e2f4d /calendar
parent7ee6ef65f1019389c172478a80b8f0aa73a1453e (diff)
downloadgsoc2013-evolution-8f2b4cc6faf5a2fedbe6e11f340d492d4698072a.tar
gsoc2013-evolution-8f2b4cc6faf5a2fedbe6e11f340d492d4698072a.tar.gz
gsoc2013-evolution-8f2b4cc6faf5a2fedbe6e11f340d492d4698072a.tar.bz2
gsoc2013-evolution-8f2b4cc6faf5a2fedbe6e11f340d492d4698072a.tar.lz
gsoc2013-evolution-8f2b4cc6faf5a2fedbe6e11f340d492d4698072a.tar.xz
gsoc2013-evolution-8f2b4cc6faf5a2fedbe6e11f340d492d4698072a.tar.zst
gsoc2013-evolution-8f2b4cc6faf5a2fedbe6e11f340d492d4698072a.zip
Forgot to commit a couple files.
svn path=/branches/kill-bonobo/; revision=36318
Diffstat (limited to 'calendar')
-rw-r--r--calendar/gui/e-calendar-selector.c290
-rw-r--r--calendar/gui/e-calendar-selector.h66
2 files changed, 356 insertions, 0 deletions
diff --git a/calendar/gui/e-calendar-selector.c b/calendar/gui/e-calendar-selector.c
new file mode 100644
index 0000000000..b23ef1b32a
--- /dev/null
+++ b/calendar/gui/e-calendar-selector.c
@@ -0,0 +1,290 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+/* e-calendar-selector.c
+ *
+ * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
+ *
+ * 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., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "e-calendar-selector.h"
+
+#include <libecal/e-cal.h>
+#include "common/authentication.h"
+
+#define E_CALENDAR_SELECTOR_GET_PRIVATE(obj) \
+ (G_TYPE_INSTANCE_GET_PRIVATE \
+ ((obj), E_TYPE_CALENDAR_SELECTOR, ECalendarSelectorPrivate))
+
+struct _ECalendarSelectorPrivate {
+ gint dummy_value;
+};
+
+enum {
+ DND_TARGET_TYPE_CALENDAR_LIST
+};
+
+static GtkTargetEntry drag_types[] = {
+ { "text/calendar", 0, DND_TARGET_TYPE_CALENDAR_LIST },
+ { "text/x-calendar", 0, DND_TARGET_TYPE_CALENDAR_LIST }
+};
+
+static gpointer parent_class;
+
+static void
+calendar_selector_drag_leave (GtkWidget *widget,
+ GdkDragContext *context,
+ guint time_)
+{
+ /* XXX This is exactly the same as in EAddressbookSelector.
+ * Consider merging this callback into ESourceSelector. */
+
+ GtkTreeView *tree_view;
+ GtkTreeViewDropPosition pos;
+
+ tree_view = GTK_TREE_VIEW (widget);
+ pos = GTK_TREE_VIEW_DROP_BEFORE;
+
+ gtk_tree_view_set_drag_dest_row (tree_view, NULL, pos);
+}
+
+static gboolean
+calendar_selector_drag_motion (GtkWidget *widget,
+ GdkDragContext *context,
+ gint x,
+ gint y,
+ guint time_)
+{
+ /* XXX This is exactly the same as in EAddressbookSelector.
+ * Consider merging this callback into ESourceSelector. */
+
+ GtkTreeView *tree_view;
+ GtkTreeModel *model;
+ GtkTreePath *path = NULL;
+ GtkTreeIter iter;
+ GtkTreeViewDropPosition pos;
+ GdkDragAction action = 0;
+ gpointer object;
+
+ tree_view = GTK_TREE_VIEW (widget);
+ model = gtk_tree_view_get_model (tree_view);
+
+ if (!gtk_tree_view_get_dest_row_at_pos (tree_view, x, y, &path, NULL))
+ goto exit;
+
+ if (!gtk_tree_model_get_iter (model, &iter, path))
+ goto exit;
+
+ gtk_tree_model_get (model, &iter, 0, &object, -1);
+
+ if (E_IS_SOURCE_GROUP (object) || e_source_get_readonly (object))
+ goto exit;
+
+ pos = GTK_TREE_VIEW_DROP_INTO_OR_BEFORE;
+ gtk_tree_view_set_drag_dest_row (tree_view, path, pos);
+
+ if (context->actions & GDK_ACTION_MOVE)
+ action = GDK_ACTION_MOVE;
+ else
+ action = context->suggested_action;
+
+exit:
+ if (path != NULL)
+ gtk_tree_path_free (path);
+
+ if (object != NULL)
+ g_object_unref (object);
+
+ gdk_drag_status (context, action, time_);
+
+ return TRUE;
+}
+
+static gboolean
+calendar_selector_drag_drop (GtkWidget *widget,
+ GdkDragContext *context,
+ gint x,
+ gint y,
+ guint time_)
+{
+ /* XXX This is exactly the same as in EAddressbookSelector.
+ * Consider merging this callback into ESourceSelector. */
+
+ GtkTreeView *tree_view;
+ GtkTreeModel *model;
+ GtkTreePath *path;
+ GtkTreeIter iter;
+ gboolean drop_zone;
+ gboolean valid;
+ gpointer object;
+
+ tree_view = GTK_TREE_VIEW (widget);
+ model = gtk_tree_view_get_model (tree_view);
+
+ if (!gtk_tree_view_get_path_at_pos (
+ tree_view, x, y, &path, NULL, NULL, NULL))
+ return FALSE;
+
+ valid = gtk_tree_model_get_iter (model, &iter, path);
+ gtk_tree_path_free (path);
+ g_return_val_if_fail (valid, FALSE);
+
+ gtk_tree_model_get (model, &iter, 0, &object, -1);
+ drop_zone = E_IS_SOURCE (object);
+ g_object_unref (object);
+
+ return drop_zone;
+}
+
+static void
+calendar_selector_drag_data_received (GtkWidget *widget,
+ GdkDragContext *context,
+ gint x,
+ gint y,
+ GtkSelectionData *selection_data,
+ guint info,
+ guint time_)
+{
+ /* XXX This is NEARLY the same as in EAddressbookSelector.
+ * Consider merging this callback into ESourceSelector.
+ * Use a callback to allow subclasses to handle the
+ * received selection data. */
+
+ GtkTreeView *tree_view;
+ GtkTreeModel *model;
+ GtkTreePath *path = NULL;
+ GtkTreeIter iter;
+ ECal *client;
+ icalcomponent *icalcomp;
+ const gchar *string;
+ gboolean remove_from_source;
+ gboolean success = FALSE;
+ gpointer object;
+
+ tree_view = GTK_TREE_VIEW (widget);
+ model = gtk_tree_view_get_model (tree_view);
+
+ string = (const gchar *) selection_data->data;
+ remove_from_source = (context->action == GDK_ACTION_MOVE);
+
+ if (!gtk_tree_view_get_dest_row_at_pos (tree_view, x, y, &path, NULL))
+ goto exit;
+
+ if (!gtk_tree_model_get_iter (model, &iter, path))
+ goto exit;
+
+ gtk_tree_model_get (model, &iter, 0, &object, -1);
+
+ if (!E_IS_SOURCE (object) || e_source_get_readonly (object))
+ goto exit;
+
+ icalcomp = icalparser_parse_string (string);
+
+ if (icalcomp == NULL)
+ goto exit;
+
+ /* FIXME Deal with GDK_ACTION_ASK. */
+ if (context->action == GDK_ACTION_COPY) {
+ gchar *uid;
+
+ uid = e_cal_component_gen_uid ();
+ icalcomponent_set_uid (icalcomp, uid);
+ }
+
+ client = auth_new_cal_from_source (
+ E_SOURCE (object), E_CAL_SOURCE_TYPE_EVENT);
+
+ if (client != NULL) {
+ if (e_cal_open (client, TRUE, NULL)) {
+ success = TRUE;
+ update_objects (client, icalcomp);
+ }
+
+ g_object_unref (client);
+ }
+
+ icalcomponent_free (icalcomp);
+
+exit:
+ if (path != NULL)
+ gtk_tree_path_free (path);
+
+ if (object != NULL)
+ g_object_unref (object);
+
+ gtk_drag_finish (context, success, remove_from_source, time_);
+}
+
+static void
+calendar_selector_class_init (ECalendarSelectorClass *class)
+{
+ GtkWidgetClass *widget_class;
+
+ parent_class = g_type_class_peek_parent (class);
+ g_type_class_add_private (class, sizeof (ECalendarSelectorPrivate));
+
+ widget_class = GTK_WIDGET_CLASS (class);
+ widget_class->drag_leave = calendar_selector_drag_leave;
+ widget_class->drag_motion = calendar_selector_drag_motion;
+ widget_class->drag_drop = calendar_selector_drag_drop;
+ widget_class->drag_data_received = calendar_selector_drag_data_received;
+}
+
+static void
+calendar_selector_init (ECalendarSelector *selector)
+{
+ selector->priv = E_CALENDAR_SELECTOR_GET_PRIVATE (selector);
+
+ gtk_drag_dest_set (
+ GTK_WIDGET (selector), GTK_DEST_DEFAULT_ALL,
+ drag_types, G_N_ELEMENTS (drag_types),
+ GDK_ACTION_COPY | GDK_ACTION_MOVE);
+}
+
+GType
+e_calendar_selector_get_type (void)
+{
+ static GType type = 0;
+
+ if (G_UNLIKELY (type == 0)) {
+ const GTypeInfo type_info = {
+ sizeof (ECalendarSelectorClass),
+ (GBaseInitFunc) NULL,
+ (GBaseFinalizeFunc) NULL,
+ (GClassInitFunc) calendar_selector_class_init,
+ (GClassFinalizeFunc) NULL,
+ NULL, /* class_data */
+ sizeof (ECalendarSelector),
+ 0, /* n_preallocs */
+ (GInstanceInitFunc) calendar_selector_init,
+ NULL /* value_table */
+ };
+
+ type = g_type_register_static (
+ E_TYPE_SOURCE_SELECTOR, "ECalendarSelector",
+ &type_info, 0);
+ }
+
+ return type;
+}
+
+GtkWidget *
+e_calendar_selector_new (ESourceList *source_list)
+{
+ g_return_val_if_fail (E_IS_SOURCE_LIST (source_list), NULL);
+
+ return g_object_new (
+ E_TYPE_CALENDAR_SELECTOR,
+ "source-list", source_list, NULL);
+}
diff --git a/calendar/gui/e-calendar-selector.h b/calendar/gui/e-calendar-selector.h
new file mode 100644
index 0000000000..65d9a2fc81
--- /dev/null
+++ b/calendar/gui/e-calendar-selector.h
@@ -0,0 +1,66 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+/* e-calendar-selector.h
+ *
+ * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
+ *
+ * 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., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef E_CALENDAR_SELECTOR_H
+#define E_CALENDAR_SELECTOR_H
+
+#include <libedataserver/e-source-list.h>
+#include <libedataserverui/e-source-selector.h>
+
+/* Standard GObject macros */
+#define E_TYPE_CALENDAR_SELECTOR \
+ (e_calendar_selector_get_type ())
+#define E_CALENDAR_SELECTOR(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST \
+ ((obj), E_TYPE_CALENDAR_SELECTOR, ECalendarSelector))
+#define E_CALENDAR_SELECTOR_CLASS(cls) \
+ (G_TYPE_CHECK_CLASS_CAST \
+ ((cls), E_TYPE_CALENDAR_SELECTOR, ECalendarSelectorClass))
+#define E_IS_CALENDAR_SELECTOR(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE \
+ ((obj), E_TYPE_CALENDAR_SELECTOR))
+#define E_IS_CALENDAR_SELECTOR_CLASS(cls) \
+ (G_TYPE_CHECK_CLASS_TYPE \
+ ((cls), E_TYPE_CALENDAR_SELECTOR))
+#define E_CALENDAR_SELECTOR_GET_CLASS(obj) \
+ (G_TYPE_INSTANCE_GET_CLASS \
+ ((obj), E_TYPE_CALENDAR_SELECTOR, ECalendarSelectorClass))
+
+G_BEGIN_DECLS
+
+typedef struct _ECalendarSelector ECalendarSelector;
+typedef struct _ECalendarSelectorClass ECalendarSelectorClass;
+typedef struct _ECalendarSelectorPrivate ECalendarSelectorPrivate;
+
+struct _ECalendarSelector {
+ ESourceSelector parent;
+ ECalendarSelectorPrivate *priv;
+};
+
+struct _ECalendarSelectorClass {
+ ESourceSelectorClass parent_class;
+};
+
+GType e_calendar_selector_get_type (void);
+GtkWidget * e_calendar_selector_new (ESourceList *source_list);
+
+G_END_DECLS
+
+#endif /* E_CALENDAR_SELECTOR_H */