[gnome-calendar/ui-rewrite] build: add GcalSubscriber abstract class



commit dec8bcb3c9e3f3d88999972d42fdf39a15a7d0c0
Author: Erick Pérez Castellanos <erick red gmail com>
Date:   Tue Oct 21 00:21:25 2014 -0400

    build: add GcalSubscriber abstract class
    
    GcalSubscriber abstract class is meant for handling the implementation
    of ECalDataModelSubscriber interface. The code in each vfunc implemented
    is the same for each view, then it makes sense to have a class holding
    these implementations and make every views descend from it. This class
    sits in the middle between GtkContainer and each of the views.

 src/Makefile.am       |    2 +
 src/gcal-subscriber.c |  157 +++++++++++++++++++++++++++++++++++++++++++++++++
 src/gcal-subscriber.h |   53 +++++++++++++++++
 3 files changed, 212 insertions(+), 0 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index b7dbcb3..077106c 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -31,6 +31,8 @@ gnome_calendar_SOURCES =                                  \
     gcal-window.c                                         \
     gcal-view.c                                           \
     gcal-view.h                                           \
+    gcal-subscriber.c                                     \
+    gcal-subscriber.h                                     \
     gcal-month-view.c                                     \
     gcal-month-view.h                                     \
     gcal-week-view.c                                      \
diff --git a/src/gcal-subscriber.c b/src/gcal-subscriber.c
new file mode 100644
index 0000000..2b41078
--- /dev/null
+++ b/src/gcal-subscriber.c
@@ -0,0 +1,157 @@
+/* -*- mode: c; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/*
+ * gcal-subscriber.c
+ *
+ * Copyright (C) 2014 - Erick Pérez Castellanos
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "gcal-subscriber.h"
+
+#include "gcal-view.h"
+#include "gcal-event-widget.h"
+
+static void           gcal_data_model_subscriber_interface_init (ECalDataModelSubscriberInterface *iface);
+
+static void           gcal_subscriber_subscriber_component_added    (ECalDataModelSubscriber *subscriber,
+                                                                     ECalClient              *client,
+                                                                     ECalComponent           *comp);
+
+static void           gcal_subscriber_subscriber_component_modified (ECalDataModelSubscriber *subscriber,
+                                                                     ECalClient              *client,
+                                                                     ECalComponent           *comp);
+
+static void           gcal_subscriber_subscriber_component_removed  (ECalDataModelSubscriber *subscriber,
+                                                                     ECalClient              *client,
+                                                                     const gchar             *uid,
+                                                                     const gchar             *rid);
+
+static void           gcal_subscriber_subscriber_freeze             (ECalDataModelSubscriber *subscriber);
+
+static void           gcal_subscriber_subscriber_thaw               (ECalDataModelSubscriber *subscriber);
+
+G_DEFINE_TYPE_WITH_CODE (GcalSubscriber,
+                         gcal_subscriber,
+                         GTK_TYPE_CONTAINER,
+                         G_IMPLEMENT_INTERFACE (E_TYPE_CAL_DATA_MODEL_SUBSCRIBER,
+                                                gcal_data_model_subscriber_interface_init));
+
+
+static void
+gcal_subscriber_class_init (GcalSubscriberClass *klass)
+{
+  ;
+}
+
+static void
+gcal_subscriber_init (GcalSubscriber *self)
+{
+  ;
+}
+
+static void
+gcal_data_model_subscriber_interface_init (ECalDataModelSubscriberInterface *iface)
+{
+  iface->component_added = gcal_subscriber_subscriber_component_added;
+  iface->component_modified = gcal_subscriber_subscriber_component_modified;
+  iface->component_removed = gcal_subscriber_subscriber_component_removed;
+  iface->freeze = gcal_subscriber_subscriber_freeze;
+  iface->thaw = gcal_subscriber_subscriber_thaw;
+}
+
+/* ECalDataModelSubscriber interface API */
+static void
+gcal_subscriber_subscriber_component_added (ECalDataModelSubscriber *subscriber,
+                                            ECalClient              *client,
+                                            ECalComponent           *comp)
+{
+  GtkWidget *event;
+  GcalEventData *data;
+
+  data = g_new0 (GcalEventData, 1);
+  data->source = e_client_get_source (E_CLIENT (client));
+  data->event_component = e_cal_component_clone (comp);
+
+  event = gcal_event_widget_new_from_data (data);
+  g_free (data);
+
+  gtk_widget_show (event);
+  gtk_container_add (GTK_CONTAINER (subscriber), event);
+}
+
+static void
+gcal_subscriber_subscriber_component_modified (ECalDataModelSubscriber *subscriber,
+                                               ECalClient              *client,
+                                               ECalComponent           *comp)
+{
+  GtkWidget *event;
+  GtkWidget *widget;
+  GcalEventData *data;
+
+  data = g_new0 (GcalEventData, 1);
+  data->source = e_client_get_source (E_CLIENT (client));
+  data->event_component = e_cal_component_clone (comp);
+
+  event = gcal_event_widget_new_from_data (data);
+  g_free (data);
+
+  widget =
+    gcal_view_get_by_uuid (GCAL_VIEW (subscriber),
+                           gcal_event_widget_peek_uuid (GCAL_EVENT_WIDGET (event)));
+  if (widget != NULL)
+    {
+      gtk_widget_destroy (widget);
+
+      gtk_widget_show (event);
+      gtk_container_add (GTK_CONTAINER (subscriber), event);
+    }
+}
+
+static void
+gcal_subscriber_subscriber_component_removed (ECalDataModelSubscriber *subscriber,
+                                              ECalClient              *client,
+                                              const gchar             *uid,
+                                              const gchar             *rid)
+{
+  GtkWidget *widget;
+  const gchar *sid;
+  gchar *uuid;
+
+  sid = e_source_get_uid (e_client_get_source (E_CLIENT (client)));
+
+  if (rid != NULL)
+      uuid = g_strdup_printf ("%s:%s:%s", sid, uid, rid);
+  else
+    uuid = g_strdup_printf ("%s:%s", sid, uid);
+
+  widget = gcal_view_get_by_uuid (GCAL_VIEW (subscriber), uuid);
+  if (widget != NULL)
+    gtk_widget_destroy (widget);
+  else
+    g_warning ("%s: Widget with uuid: %s not found",
+               G_STRFUNC, uuid);
+
+  g_free (uuid);
+}
+
+static void
+gcal_subscriber_subscriber_freeze (ECalDataModelSubscriber *subscriber)
+{
+}
+
+static void
+gcal_subscriber_subscriber_thaw (ECalDataModelSubscriber *subscriber)
+{
+}
diff --git a/src/gcal-subscriber.h b/src/gcal-subscriber.h
new file mode 100644
index 0000000..a9e0225
--- /dev/null
+++ b/src/gcal-subscriber.h
@@ -0,0 +1,53 @@
+/*
+ * gcal-subscriber.h
+ *
+ * Copyright (C) 2014 - Erick Pérez Castellanos
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __GCAL_SUBSCRIBER_H__
+#define __GCAL_SUBSCRIBER_H__
+
+#include "gcal-manager.h"
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define GCAL_TYPE_SUBSCRIBER                       (gcal_subscriber_get_type ())
+#define GCAL_SUBSCRIBER(obj)                       (G_TYPE_CHECK_INSTANCE_CAST((obj), GCAL_TYPE_SUBSCRIBER, 
GcalSubscriber))
+#define GCAL_SUBSCRIBER_CLASS(klass)               (G_TYPE_CHECK_CLASS_CAST((klass), GCAL_TYPE_SUBSCRIBER, 
GcalSubscriberClass))
+#define GCAL_IS_SUBSCRIBER(obj)                    (G_TYPE_CHECK_INSTANCE_TYPE((obj), GCAL_TYPE_SUBSCRIBER))
+#define GCAL_IS_SUBSCRIBER_CLASS(klass)            (G_TYPE_CHECK_CLASS_TYPE((klass), GCAL_TYPE_SUBSCRIBER))
+#define GCAL_SUBSCRIBER_GET_CLASS(obj)             (G_TYPE_INSTANCE_GET_CLASS((obj), GCAL_TYPE_SUBSCRIBER, 
GcalSubscriberClass))
+
+typedef struct _GcalSubscriber                       GcalSubscriber;
+typedef struct _GcalSubscriberClass                  GcalSubscriberClass;
+
+struct _GcalSubscriber
+{
+  GtkContainer parent;
+};
+
+struct _GcalSubscriberClass
+{
+  GtkContainerClass parent_class;
+};
+
+GType          gcal_subscriber_get_type         (void);
+
+G_END_DECLS
+
+#endif /* __GCAL_SUBSCRIBER_H__ */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]