[gnome-calendar] Added reminders widget.



commit 0709722107638f387d6a51968086bebddfaf80c4
Author: Erick PÃrez Castellanos <erick red gmail com>
Date:   Sun Jul 1 00:05:34 2012 -0400

    Added reminders widget.
    
    This one implies a lot of assumptions/simplification,
    mostly because the API to manage Alarm in e-d-s is huge,
    and we want simplicity.

 src/Makefile.am              |    2 +
 src/gcal-editable-reminder.c |  494 ++++++++++++++++++++++++++++++++++++++++++
 src/gcal-editable-reminder.h |   61 +++++
 src/gcal-event-view.c        |   31 +++-
 src/gcal-manager.c           |  105 +++++++++
 src/gcal-manager.h           |    4 +
 6 files changed, 693 insertions(+), 4 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index ef9dc18..faf4494 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -43,6 +43,8 @@ gnome_calendar_SOURCES =                                \
 	gcal-editable-date.h                                  \
 	gcal-editable-combo.c                                 \
 	gcal-editable-combo.h                                 \
+	gcal-editable-reminder.c                              \
+	gcal-editable-reminder.h                              \
 	gcal-manager.c                                        \
 	gcal-manager.h                                        \
 	gcal-utils.c                                          \
diff --git a/src/gcal-editable-reminder.c b/src/gcal-editable-reminder.c
new file mode 100644
index 0000000..442e275
--- /dev/null
+++ b/src/gcal-editable-reminder.c
@@ -0,0 +1,494 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 2 -*- */
+/*
+ * gcal-editable-reminder.c
+ *
+ * Copyright (C) 2012 - 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-editable-reminder.h"
+
+#include <glib/gi18n.h>
+
+struct _GcalEditableReminderPrivate
+{
+  GtkWidget *view_widget;
+  GtkWidget *edit_widget;
+
+  GtkWidget *left_box;
+
+  GList     *labels;
+
+  GList     *reminders;
+  GtkWidget *add_button;
+
+  gboolean   update_edit_mode;
+};
+
+static void     gcal_editable_reminder_constructed         (GObject              *object);
+
+static void     gcal_editable_reminder_finalize            (GObject              *object);
+
+static void     gcal_editable_reminder_enter_edit_mode     (GcalEditable         *editable);
+
+static void     gcal_editable_reminder_leave_edit_mode     (GcalEditable         *editable);
+
+static void     gcal_editable_reminder_clear               (GcalEditable         *editable);
+
+static void     gcal_editable_reminder_add_button_clicked  (GtkButton            *button,
+                                                            gpointer              user_data);
+
+static void     gcal_editable_reminder_insert_content      (GcalEditableReminder *editable,
+                                                            const gchar          *content);
+
+static void     gcal_editable_reminder_insert_reminder     (GcalEditableReminder *editable,
+                                                            const gchar          *type,
+                                                            gint                  number,
+                                                            const gchar          *time);
+static void     gcal_editable_reminder_remove_reminder     (GtkButton            *button,
+                                                            gpointer              user_data);
+
+G_DEFINE_TYPE (GcalEditableReminder, gcal_editable_reminder, GCAL_TYPE_EDITABLE);
+
+static void gcal_editable_reminder_class_init (GcalEditableReminderClass *klass)
+{
+  GcalEditableClass *editable_class;
+  GObjectClass *object_class;
+
+  editable_class = GCAL_EDITABLE_CLASS (klass);
+  editable_class->enter_edit_mode = gcal_editable_reminder_enter_edit_mode;
+  editable_class->leave_edit_mode = gcal_editable_reminder_leave_edit_mode;
+  editable_class->clear = gcal_editable_reminder_clear;
+
+  object_class = G_OBJECT_CLASS (klass);
+  object_class->constructed = gcal_editable_reminder_constructed;
+  object_class->finalize = gcal_editable_reminder_finalize;
+
+  g_type_class_add_private ((gpointer)klass, sizeof (GcalEditableReminderPrivate));
+}
+
+
+
+static void gcal_editable_reminder_init (GcalEditableReminder *self)
+{
+  self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
+                                            GCAL_TYPE_EDITABLE_REMINDER,
+                                            GcalEditableReminderPrivate);
+}
+
+static void
+gcal_editable_reminder_constructed (GObject *object)
+{
+  GcalEditableReminderPrivate *priv;
+
+  priv = GCAL_EDITABLE_REMINDER (object)->priv;
+
+  if (G_OBJECT_CLASS (gcal_editable_reminder_parent_class)->constructed != NULL)
+    G_OBJECT_CLASS (gcal_editable_reminder_parent_class)->constructed (object);
+
+  priv->view_widget = gtk_grid_new ();
+  g_object_set (priv->view_widget,
+                "row-spacing", 6,
+                "valign", GTK_ALIGN_START,
+                "halign", GTK_ALIGN_START,
+                "orientation", GTK_ORIENTATION_VERTICAL,
+                NULL);
+  gtk_widget_show (priv->view_widget);
+  gcal_editable_set_view_widget (GCAL_EDITABLE (object), priv->view_widget);
+
+  priv->edit_widget = gtk_grid_new ();
+  gtk_grid_set_column_spacing (GTK_GRID (priv->edit_widget), 6);
+  priv->left_box = gtk_grid_new ();
+  g_object_set (priv->left_box,
+                "orientation", GTK_ORIENTATION_VERTICAL,
+                "row-spacing", 6,
+                "column-spacing", 6,
+                "vexpand", FALSE,
+                "valign", GTK_ALIGN_START,
+                NULL);
+  gtk_grid_attach (GTK_GRID (priv->edit_widget), priv->left_box, 0, 0, 1, 1);
+  gcal_editable_reminder_insert_reminder (GCAL_EDITABLE_REMINDER (object),
+                                          NULL,
+                                          1,
+                                          NULL);
+
+  priv->add_button = gtk_button_new ();
+  g_object_ref_sink (priv->add_button);
+  g_object_set (priv->add_button,
+                "valign", GTK_ALIGN_START,
+                "halign", GTK_ALIGN_END,
+                "relief", GTK_RELIEF_NONE,
+                NULL);
+  gtk_container_add (
+      GTK_CONTAINER (priv->add_button),
+      gtk_image_new_from_icon_name ("list-add-symbolic",
+                                    GTK_ICON_SIZE_MENU));
+  gtk_grid_attach (GTK_GRID (priv->edit_widget), priv->add_button, 1, 0, 1, 1);
+  g_signal_connect (priv->add_button,
+                    "clicked",
+                    G_CALLBACK (gcal_editable_reminder_add_button_clicked),
+                    object);
+
+  gtk_widget_show_all (priv->edit_widget);
+  gcal_editable_set_edit_widget (GCAL_EDITABLE (object), priv->edit_widget);
+
+  priv->update_edit_mode = FALSE;
+}
+
+static void
+gcal_editable_reminder_finalize (GObject  *object)
+{
+  GcalEditableReminderPrivate *priv;
+
+  g_return_if_fail (GCAL_IS_EDITABLE_REMINDER (object));
+  priv = GCAL_EDITABLE_REMINDER (object)->priv;
+
+  if (priv->add_button != NULL)
+    g_clear_object (&(priv->add_button));
+
+  if (G_OBJECT_CLASS (gcal_editable_reminder_parent_class)->finalize != NULL)
+    G_OBJECT_CLASS (gcal_editable_reminder_parent_class)->finalize (object);
+}
+
+static void
+gcal_editable_reminder_enter_edit_mode (GcalEditable *editable)
+{
+  GcalEditableReminderPrivate *priv;
+  GList *l;
+
+  g_return_if_fail (GCAL_IS_EDITABLE_REMINDER (editable));
+  priv = GCAL_EDITABLE_REMINDER (editable)->priv;
+
+  if (priv->update_edit_mode)
+    {
+      /* will parse everything */
+      g_list_free_full (priv->reminders, (GDestroyNotify) gtk_widget_destroy);
+      priv->reminders = NULL;
+
+      for (l = priv->labels; l != NULL; l = l->next)
+        {
+          gchar **tokens;
+          gchar *type;
+          gint number;
+          gchar *time;
+
+          tokens = g_strsplit (gtk_label_get_text (GTK_LABEL (l->data)), " ", -1);
+          if (g_strcmp0 (_("Email"), tokens[0]) == 0)
+            type = g_strdup ("email");
+          else
+            type = g_strdup ("notification");
+
+          number = g_strtod (tokens[1], NULL);
+
+          if (g_str_has_prefix (tokens[2], _("minute")))
+            time = g_strdup ("minutes");
+          else if (g_str_has_prefix (tokens[2], _("hour")))
+            time = g_strdup ("hours");
+          else if (g_str_has_prefix (tokens[2], _("day")))
+            time = g_strdup ("days");
+          else
+            time = g_strdup ("weeks");
+
+          gcal_editable_reminder_insert_reminder (
+              GCAL_EDITABLE_REMINDER (editable),
+              type,
+              number,
+              time);
+
+          g_free (time);
+          g_free (type);
+          g_strfreev (tokens);
+        }
+      priv->update_edit_mode = FALSE;
+    }
+}
+
+static void
+gcal_editable_reminder_leave_edit_mode (GcalEditable *editable)
+{
+  GcalEditableReminderPrivate *priv;
+  GList *l;
+
+  g_return_if_fail (GCAL_IS_EDITABLE_REMINDER (editable));
+  priv = GCAL_EDITABLE_REMINDER (editable)->priv;
+
+  /* clearing */
+  g_list_free_full (priv->labels, (GDestroyNotify) gtk_widget_destroy);
+  priv->labels = NULL;
+
+  for (l = priv->reminders; l != NULL; l = l->next)
+    {
+      gchar *text;
+      gchar *c, *c2;
+      GtkWidget *type_combo;
+      GtkWidget *number_spin;
+      GtkWidget *time_combo;
+
+      type_combo = gtk_grid_get_child_at (GTK_GRID (l->data), 0, 0);
+      number_spin = gtk_grid_get_child_at (GTK_GRID (l->data), 1, 0);
+      time_combo = gtk_grid_get_child_at (GTK_GRID (l->data), 2, 0);
+
+      text =
+        gtk_combo_box_text_get_active_text (GTK_COMBO_BOX_TEXT (type_combo));
+      c = g_strdup_printf (
+          "%s %d",
+          text,
+          gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (number_spin)));
+      g_free (text);
+      text = c;
+      c2 = gtk_combo_box_text_get_active_text (GTK_COMBO_BOX_TEXT (time_combo));
+      c = g_strdup_printf ("%s %s %s",
+                           text,
+                           c2,
+                           _("before"));
+      g_free (c2);
+      g_free (text);
+
+      gcal_editable_reminder_insert_content (GCAL_EDITABLE_REMINDER (editable),
+                                             c);
+      g_free (c);
+    }
+}
+
+static void
+gcal_editable_reminder_clear (GcalEditable  *editable)
+{
+  GcalEditableReminderPrivate *priv;
+
+  g_return_if_fail (GCAL_IS_EDITABLE_REMINDER (editable));
+  priv = GCAL_EDITABLE_REMINDER (editable)->priv;
+
+  g_list_free_full (priv->reminders, (GDestroyNotify) gtk_widget_destroy);
+  priv->reminders = NULL;
+  gcal_editable_reminder_insert_reminder (GCAL_EDITABLE_REMINDER (editable),
+                                          NULL,
+                                          1,
+                                          NULL);
+
+  g_list_free_full (priv->labels, (GDestroyNotify) gtk_widget_destroy);
+  priv->labels = NULL;
+}
+
+static void
+gcal_editable_reminder_add_button_clicked (GtkButton *button,
+                                           gpointer   user_data)
+{
+  gcal_editable_reminder_insert_reminder (GCAL_EDITABLE_REMINDER (user_data),
+                                          NULL,
+                                          0,
+                                          NULL);
+}
+
+static void
+gcal_editable_reminder_insert_content (GcalEditableReminder *editable,
+                                       const gchar          *content)
+{
+  GcalEditableReminderPrivate *priv;
+  GtkWidget *label;
+
+  g_return_if_fail (GCAL_IS_EDITABLE_REMINDER (editable));
+  priv = editable->priv;
+
+  label = gtk_label_new (content);
+  gtk_widget_set_halign (label, GTK_ALIGN_START);
+
+  gtk_container_add (GTK_CONTAINER (priv->view_widget), label);
+  gtk_widget_show_all (priv->view_widget);
+
+  priv->labels = g_list_append (priv->labels, label);
+}
+
+static void
+gcal_editable_reminder_insert_reminder (GcalEditableReminder *editable,
+                                        const gchar          *type,
+                                        gint                  number,
+                                        const gchar          *time)
+{
+  GcalEditableReminderPrivate *priv;
+
+  GtkWidget *hbox;
+  GtkWidget *type_combo;
+  GtkWidget *number_spin;
+  GtkWidget *time_combo;
+  GtkWidget *del_button;
+
+  g_return_if_fail (GCAL_IS_EDITABLE_REMINDER (editable));
+  priv = editable->priv;
+
+  hbox = gtk_grid_new ();
+  g_object_set (hbox,
+                "orientation", GTK_ORIENTATION_HORIZONTAL,
+                "column-spacing", 6,
+                NULL);
+
+  type_combo = gtk_combo_box_text_new ();
+
+  number_spin = gtk_spin_button_new (gtk_adjustment_new (1, 1, 99, 1, 1, 0),
+                                     1,
+                                     0);
+
+  time_combo = gtk_combo_box_text_new ();
+
+  del_button = gtk_button_new ();
+  g_signal_connect (del_button,
+                    "clicked",
+                    G_CALLBACK (gcal_editable_reminder_remove_reminder),
+                    editable);
+  gtk_button_set_relief (GTK_BUTTON (del_button), GTK_RELIEF_NONE);
+  gtk_container_add (
+      GTK_CONTAINER (del_button),
+      gtk_image_new_from_icon_name ("list-remove-symbolic",
+                                    GTK_ICON_SIZE_MENU));
+
+  gtk_container_add (GTK_CONTAINER (hbox), type_combo);
+  gtk_container_add (GTK_CONTAINER (hbox), number_spin);
+  gtk_container_add (GTK_CONTAINER (hbox), time_combo);
+  gtk_container_add (GTK_CONTAINER (hbox), del_button);
+
+  /* loading values and defaults */
+  gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (type_combo),
+                             "email",
+                             _("Email"));
+  gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (type_combo),
+                             "notification",
+                             _("Notification"));
+  gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (time_combo),
+                             "minutes",
+                             _("minutes"));
+  gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (time_combo),
+                             "hours",
+                             _("hours"));
+  gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (time_combo),
+                             "days",
+                             _("days"));
+  gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (time_combo),
+                             "weeks",
+                             _("weeks"));
+
+  gtk_combo_box_set_active_id (GTK_COMBO_BOX (type_combo),
+                               type != NULL ? type : "email");
+  gtk_spin_button_set_value (GTK_SPIN_BUTTON (number_spin),
+                             number > 1 ? number : 1);
+  gtk_combo_box_set_active_id (GTK_COMBO_BOX (time_combo),
+                               time != NULL ? time : "hours");
+
+  gtk_container_add (GTK_CONTAINER (priv->left_box), hbox);
+
+  gtk_widget_show_all (hbox);
+  priv->reminders = g_list_append (priv->reminders, hbox);
+
+  /* hack for activating/deactivating first del_button */
+  if (g_list_length (priv->reminders) == 1)
+    {
+      gtk_widget_set_sensitive (del_button, FALSE);
+    }
+  else
+    {
+      del_button = gtk_grid_get_child_at (
+          GTK_GRID (g_list_first (priv->reminders)->data),
+          3, 0);
+      gtk_widget_set_sensitive (del_button, TRUE);
+    }
+}
+
+static void
+gcal_editable_reminder_remove_reminder (GtkButton *button,
+                                        gpointer   user_data)
+{
+  GcalEditableReminderPrivate *priv;
+  GtkWidget *parent;
+  gint index;
+
+  g_return_if_fail (GCAL_IS_EDITABLE_REMINDER (user_data));
+  priv = ((GcalEditableReminder*)user_data)->priv;
+
+  parent = gtk_widget_get_parent (GTK_WIDGET (button));
+  index = g_list_index (priv->reminders, parent);
+  if (index != -1)
+    {
+      priv->reminders = g_list_remove (priv->reminders, parent);
+      gtk_container_remove (GTK_CONTAINER (priv->left_box), parent);
+
+      /* hack for activating/deactivating first del_button */
+      if (g_list_length (priv->reminders) == 1)
+        {
+          GtkWidget *del_button;
+          del_button = gtk_grid_get_child_at (
+              GTK_GRID (g_list_last (priv->reminders)->data),
+              3, 0);
+          gtk_widget_set_sensitive (del_button, FALSE);
+        }
+    }
+}
+
+/**
+ * gcal_editable_reminder_new:
+ *
+ * Init the reminder in EDIT_MODE
+ *
+ * Since: 0.1
+ * Returns: (transfer full):
+ **/
+GtkWidget*
+gcal_editable_reminder_new (void)
+{
+  GtkWidget *reminder = g_object_new (GCAL_TYPE_EDITABLE_REMINDER, NULL);
+  gcal_editable_enter_edit_mode (GCAL_EDITABLE (reminder));
+  return reminder;
+}
+
+/**
+ * gcal_editable_reminder_new_with_content:
+ *
+ * Init the reminder in VIEW_MODE
+ *
+ * Since 0.2
+ * Returns: (transfer full)
+ */
+GtkWidget*
+gcal_editable_reminder_new_with_content (GList* content)
+{
+  GtkWidget *reminder;
+  reminder = g_object_new (GCAL_TYPE_EDITABLE_REMINDER, NULL);
+  gcal_editable_reminder_set_content (GCAL_EDITABLE_REMINDER (reminder), content);
+  gcal_editable_leave_edit_mode (GCAL_EDITABLE (reminder));
+  return reminder;
+}
+
+void
+gcal_editable_reminder_set_content (GcalEditableReminder *reminder,
+                                    GList                *content)
+{
+  GcalEditableReminderPrivate *priv;
+  GList *l;
+
+  g_return_if_fail (GCAL_IS_EDITABLE_REMINDER (reminder));
+  priv = reminder->priv;
+
+  if (content != NULL)
+    {
+      g_list_free_full (priv->labels, (GDestroyNotify) gtk_widget_destroy);
+      priv->labels = NULL;
+    }
+
+  for (l = content; l != NULL; l = l->next)
+    {
+      if (l->data != NULL)
+        {
+          priv->update_edit_mode = TRUE;
+          gcal_editable_reminder_insert_content (reminder, l->data);
+        }
+    }
+}
diff --git a/src/gcal-editable-reminder.h b/src/gcal-editable-reminder.h
new file mode 100644
index 0000000..a33ee49
--- /dev/null
+++ b/src/gcal-editable-reminder.h
@@ -0,0 +1,61 @@
+/*
+ * gcal-editable-reminder.h
+ *
+ * Copyright (C) 2012 - 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_EDITABLE_REMINDER_H__
+#define __GCAL_EDITABLE_REMINDER_H__
+
+#include "gcal-editable.h"
+
+G_BEGIN_DECLS
+
+#define GCAL_TYPE_EDITABLE_REMINDER                       (gcal_editable_reminder_get_type ())
+#define GCAL_EDITABLE_REMINDER(obj)                       (G_TYPE_CHECK_INSTANCE_CAST((obj), GCAL_TYPE_EDITABLE_REMINDER, GcalEditableReminder))
+#define GCAL_EDITABLE_REMINDER_CLASS(klass)               (G_TYPE_CHECK_CLASS_CAST((klass), GCAL_TYPE_EDITABLE_REMINDER, GcalEditableReminderClass))
+#define GCAL_IS_EDITABLE_REMINDER(obj)                    (G_TYPE_CHECK_INSTANCE_TYPE((obj), GCAL_TYPE_EDITABLE_REMINDER))
+#define GCAL_IS_EDITABLE_REMINDER_CLASS(klass)            (G_TYPE_CHECK_CLASS_TYPE((klass), GCAL_TYPE_EDITABLE_REMINDER))
+#define GCAL_EDITABLE_REMINDER_GET_CLASS(obj)             (G_TYPE_INSTANCE_GET_CLASS((obj), GCAL_TYPE_EDITABLE_REMINDER, GcalEditableReminderClass))
+
+typedef struct _GcalEditableReminder                       GcalEditableReminder;
+typedef struct _GcalEditableReminderClass                  GcalEditableReminderClass;
+typedef struct _GcalEditableReminderPrivate                GcalEditableReminderPrivate;
+
+struct _GcalEditableReminder
+{
+  GcalEditable parent;
+
+  /* add your public declarations here */
+  GcalEditableReminderPrivate *priv;
+};
+
+struct _GcalEditableReminderClass
+{
+  GcalEditableClass parent_class;
+};
+
+GType          gcal_editable_reminder_get_type           (void);
+
+GtkWidget*     gcal_editable_reminder_new                (void);
+
+GtkWidget*     gcal_editable_reminder_new_with_content   (GList                *content);
+
+void           gcal_editable_reminder_set_content        (GcalEditableReminder *entry,
+                                                          GList                *content);
+G_END_DECLS
+
+#endif /* __GCAL_EDITABLE_REMINDER_H__ */
diff --git a/src/gcal-event-view.c b/src/gcal-event-view.c
index 478bc67..15da314 100644
--- a/src/gcal-event-view.c
+++ b/src/gcal-event-view.c
@@ -22,6 +22,7 @@
 #include "gcal-editable-text.h"
 #include "gcal-editable-date.h"
 #include "gcal-editable-combo.h"
+#include "gcal-editable-reminder.h"
 
 #include <glib/gi18n.h>
 
@@ -43,6 +44,8 @@ struct _GcalEventViewPrivate
 
   GtkWidget         *t_desc;
 
+  GtkWidget         *reminders;
+
   GtkWidget         *attending_yes;
   GtkWidget         *attending_maybe;
   GtkWidget         *attending_no;
@@ -94,6 +97,7 @@ gcal_event_view_constructed (GObject *object)
   GtkWidget *calendar;
   GtkWidget *where;
   GtkWidget *desc;
+  GtkWidget *rem;
   GtkWidget *attending;
   GtkWidget *attending_box;
 
@@ -125,6 +129,9 @@ gcal_event_view_constructed (GObject *object)
   priv->t_desc = gcal_editable_text_new ();
   priv->e_widgets = g_slist_append (priv->e_widgets, priv->t_desc);
 
+  priv->reminders = gcal_editable_reminder_new ();
+  priv->e_widgets = g_slist_append (priv->e_widgets, priv->reminders);
+
   /* FIXME: do something with this to add it on the slist of widget
    * something like, turning all the three into on widget
    */
@@ -173,13 +180,19 @@ gcal_event_view_constructed (GObject *object)
   gtk_widget_set_size_request (priv->t_desc, -1, 200);
   gtk_grid_attach (GTK_GRID (object), priv->t_desc, 1, 4, 3, 1);
 
+  rem = gtk_label_new (_("Reminders"));
+  gtk_widget_set_halign (rem, GTK_ALIGN_END);
+  gtk_widget_set_valign (rem, GTK_ALIGN_START);
+  gtk_grid_attach (GTK_GRID (object), rem, 0, 5, 1, 1);
+  gtk_grid_attach (GTK_GRID (object), priv->reminders, 1, 5, 3, 1);
+
   attending = gtk_label_new (_("Attending"));
   gtk_widget_set_halign (attending, GTK_ALIGN_END);
-  gtk_grid_attach (GTK_GRID (object), attending, 0, 5, 1, 1);
-  gtk_grid_attach (GTK_GRID (object), attending_box, 1, 5, 3, 1);
+  gtk_grid_attach (GTK_GRID (object), attending, 0, 6, 1, 1);
+  gtk_grid_attach (GTK_GRID (object), attending_box, 1, 6, 3, 1);
 
-  gtk_grid_set_row_spacing (GTK_GRID (object), 16);
-  gtk_grid_set_column_spacing (GTK_GRID (object), 16);
+  gtk_grid_set_row_spacing (GTK_GRID (object), 12);
+  gtk_grid_set_column_spacing (GTK_GRID (object), 12);
   gtk_widget_show_all (GTK_WIDGET (object));
 }
 
@@ -237,6 +250,7 @@ gcal_event_view_update (GcalEventView *view)
       gchar *when;
       const gchar *location;
       gchar *description;
+      GList *reminders;
 
       g_slist_foreach (priv->e_widgets, (GFunc) gcal_editable_leave_edit_mode, NULL);
 
@@ -296,9 +310,18 @@ gcal_event_view_update (GcalEventView *view)
       gcal_editable_text_set_content (GCAL_EDITABLE_TEXT (priv->t_desc),
                                       description);
 
+      reminders = gcal_manager_get_event_reminders (priv->manager,
+                                                    priv->source_uid,
+                                                    priv->event_uid);
+
+      gcal_editable_reminder_set_content (
+          GCAL_EDITABLE_REMINDER (priv->reminders),
+          reminders);
+
       g_free (description);
       g_free (when);
       g_free (summary);
+      g_list_free_full (reminders, (GDestroyNotify) g_free);
     }
 }
 
diff --git a/src/gcal-manager.c b/src/gcal-manager.c
index cbd2da8..b35b288 100644
--- a/src/gcal-manager.c
+++ b/src/gcal-manager.c
@@ -1080,3 +1080,108 @@ gcal_manager_get_event_color (GcalManager *manager,
 
   return color;
 }
+
+GList*
+gcal_manager_get_event_reminders (GcalManager *manager,
+                                  const gchar *source_uid,
+                                  const gchar *event_uid)
+{
+  GcalManagerPrivate *priv;
+  GcalManagerUnit *unit;
+  ECalComponent *event;
+  GList *reminders;
+
+  g_return_val_if_fail (GCAL_IS_MANAGER (manager), NULL);
+  priv = manager->priv;
+  reminders = NULL;
+
+  unit = g_hash_table_lookup (priv->clients, source_uid);
+  event = g_hash_table_lookup (unit->events, event_uid);
+
+  if (e_cal_component_has_alarms (event))
+    {
+      GList *alarms;
+      GList *l;
+
+      alarms = e_cal_component_get_alarm_uids (event);
+      for (l = alarms; l != NULL; l = l->next)
+        {
+          gchar *type;
+          gint number;
+          gchar *time;
+          ECalComponentAlarm *alarm;
+          ECalComponentAlarmAction action;
+          ECalComponentAlarmTrigger trigger;
+
+          type = NULL;
+          time = NULL;
+          alarm = e_cal_component_get_alarm (event, l->data);
+
+          e_cal_component_alarm_get_action (alarm, &action);
+          /* here, this are the tricky bits.
+           * We assume a bunch of differents AlarmAction(s) as one:
+           * "Notification". In case we need to add extra-refinemen. This is the
+           * place to change stuff t*/
+          if (action == E_CAL_COMPONENT_ALARM_AUDIO
+              || action == E_CAL_COMPONENT_ALARM_DISPLAY)
+            type = g_strdup (_("Notification"));
+          else if (action == E_CAL_COMPONENT_ALARM_EMAIL)
+            type = g_strdup (_("Email"));
+
+          e_cal_component_alarm_get_trigger (alarm, &trigger);
+          /* Second part of tricky bits. We will ignore triggers types other
+           * than E_CAL_COMPONENT_ALARM_TRIGGER_RELATIVE_START, and other than
+           * before. In case of extra tweaking (almost sure it will be needed)
+           * this is the place of doing it. */
+          if (trigger.type == E_CAL_COMPONENT_ALARM_TRIGGER_RELATIVE_START)
+            {
+              /* cut/pasted/tweaking chunk of code from
+               * evo:calendar/gui/e-alarm-list.c +435 */
+              if (trigger.u.rel_duration.is_neg && trigger.u.rel_duration.days >= 1)
+                {
+                  number = trigger.u.rel_duration.days;
+                  time = g_strdup (_("days"));
+                }
+
+              if (trigger.u.rel_duration.is_neg && trigger.u.rel_duration.weeks >= 1)
+                {
+                  number = trigger.u.rel_duration.weeks;
+                  time = g_strdup (_("weeks"));
+                }
+
+              if (trigger.u.rel_duration.is_neg && trigger.u.rel_duration.hours >= 1)
+                {
+                  number = trigger.u.rel_duration.hours;
+                  time = g_strdup (_("hours"));
+                }
+
+              if (trigger.u.rel_duration.is_neg && trigger.u.rel_duration.minutes >= 1)
+                {
+                  number = trigger.u.rel_duration.minutes;
+                  time = g_strdup (_("minutes"));
+                }
+            }
+
+          if (type != NULL && time != NULL)
+            {
+              gchar *one_reminder;
+
+              one_reminder = g_strdup_printf ("%s %d %s %s",
+                                              type,
+                                              number,
+                                              time,
+                                              _("before"));
+              reminders = g_list_prepend (reminders, one_reminder);
+
+              g_free (type);
+              g_free (time);
+            }
+
+          e_cal_component_alarm_free (alarm);
+        }
+      cal_obj_uid_list_free (alarms);
+    }
+
+  reminders = g_list_reverse (reminders);
+  return reminders;
+}
diff --git a/src/gcal-manager.h b/src/gcal-manager.h
index cec794b..658f2a7 100644
--- a/src/gcal-manager.h
+++ b/src/gcal-manager.h
@@ -108,6 +108,10 @@ GdkRGBA*       gcal_manager_get_event_color         (GcalManager        *manager
                                                      const gchar        *source_uid,
                                                      const gchar        *event_uid);
 
+GList*         gcal_manager_get_event_reminders     (GcalManager        *manager,
+                                                     const gchar        *source_uid,
+                                                     const gchar        *event_uid);
+
 G_END_DECLS
 
 #endif /* __GCAL_MANAGER_H__ */



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