[gnome-calendar/wip/pandusonu/week-view: 24/60] week-view: display events in header
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-calendar/wip/pandusonu/week-view: 24/60] week-view: display events in header
- Date: Fri, 2 Dec 2016 01:50:31 +0000 (UTC)
commit 188d7742b4f06df12473d03eeec96decac56edab
Author: pandusonu2 <pandu sonu yahoo com>
Date: Sat Jun 18 00:17:37 2016 +0530
week-view: display events in header
Displaying events in the week-header based on duration of the event.
data/ui/week-header.ui | 2 +
src/views/gcal-week-header.c | 78 ++++++++++++++++++++++++++++++++++++++++++
src/views/gcal-week-header.h | 4 ++
src/views/gcal-week-view.c | 27 ++++++++++++--
4 files changed, 107 insertions(+), 4 deletions(-)
---
diff --git a/data/ui/week-header.ui b/data/ui/week-header.ui
index 2d498aa..02ac769 100644
--- a/data/ui/week-header.ui
+++ b/data/ui/week-header.ui
@@ -61,6 +61,8 @@
<object class="GtkGrid" id="grid">
<property name="visible">True</property>
<property name="height-request">100</property>
+ <property name="column-homogeneous">True</property>
+ <property name="row-homogeneous">True</property>
</object>
</child>
</object>
diff --git a/src/views/gcal-week-header.c b/src/views/gcal-week-header.c
index 93a5d31..bbc19cb 100644
--- a/src/views/gcal-week-header.c
+++ b/src/views/gcal-week-header.c
@@ -154,6 +154,79 @@ gcal_week_header_finalize (GObject *object)
g_clear_pointer (&self->current_date, g_free);
}
+void
+gcal_week_header_add_event (GcalWeekHeader *self,
+ GcalEvent *event)
+{
+ GDateTime *week_start, *week_end, *event_start, *event_end;
+ GtkWidget *child_widget, *place_holder_left, *place_holder_right;
+ gint start, end;
+
+ start = -1;
+ end = -1;
+ week_start = get_start_of_week (self);
+ week_end = g_date_time_add_days (week_start, 7);
+ event_start = gcal_event_get_date_start (event);
+ event_end = gcal_event_get_date_end (event);
+ child_widget = gcal_event_widget_new (event);
+ place_holder_left = gtk_invisible_new ();
+ place_holder_right = gtk_invisible_new ();
+
+ gtk_widget_set_visible (child_widget, TRUE);
+ gtk_widget_set_visible (place_holder_left, TRUE);
+ gtk_widget_set_visible (place_holder_right, TRUE);
+
+ start = (g_date_time_get_day_of_week (event_start) - self->first_weekday + 7) % 7;
+ end = (g_date_time_get_day_of_week (event_end) - self->first_weekday + 7) % 7;
+
+ if (g_date_time_compare (event_start, week_start) < 0)
+ start = 0;
+
+ if (g_date_time_compare (event_end, week_end) >= 0)
+ end = 6;
+
+ gtk_grid_insert_row (GTK_GRID (self->grid), 0);
+
+ if (gcal_event_get_all_day (event))
+ {
+ start = (g_date_time_get_day_of_week (event_start) - self->first_weekday + 7) % 7;
+ end = start;
+ }
+
+ gtk_grid_attach (GTK_GRID (self->grid),
+ child_widget,
+ start,
+ 0,
+ end - start + 1,
+ 1);
+}
+
+void
+gcal_week_header_remove_event (GcalWeekHeader *header,
+ gchar *uuid)
+{
+ GList *children, *l;
+
+ children = gtk_container_get_children (GTK_CONTAINER (header->grid));
+
+ for (l = children; l != NULL; l = g_list_next (l))
+ {
+ GcalEventWidget *child_widget;
+ GcalEvent *event;
+
+ if (!GCAL_IS_EVENT_WIDGET(l->data))
+ continue;
+
+ child_widget = GCAL_EVENT_WIDGET (l->data);
+ event = gcal_event_widget_get_event (child_widget);
+
+ if(child_widget != NULL && g_strcmp0 (uuid, gcal_event_get_uid (event)) == 0)
+ gtk_widget_destroy (GTK_WIDGET (l->data));
+ }
+
+ g_list_free (children);
+}
+
static void
gcal_week_header_get_property (GObject *object,
guint prop_id,
@@ -366,7 +439,12 @@ gcal_week_header_class_init (GcalWeekHeaderClass *kclass)
static void
gcal_week_header_init (GcalWeekHeader *self)
{
+ gint i;
+
gtk_widget_init_template (GTK_WIDGET (self));
+
+ for (i = 1; i <= 7; i++)
+ gtk_grid_insert_column (GTK_GRID (self->grid), 0);
}
/* Public API */
diff --git a/src/views/gcal-week-header.h b/src/views/gcal-week-header.h
index 527876a..db17803 100644
--- a/src/views/gcal-week-header.h
+++ b/src/views/gcal-week-header.h
@@ -39,6 +39,10 @@ void gcal_week_header_set_use_24h_format (GcalWeekHeader *self,
gboolean use_24h_format);
void gcal_week_header_set_current_date (GcalWeekHeader *self,
icaltimetype *current_date);
+void gcal_week_header_add_event (GcalWeekHeader *header,
+ GcalEvent *event);
+void gcal_week_header_remove_event (GcalWeekHeader *header,
+ gchar *uuid);
G_END_DECLS
diff --git a/src/views/gcal-week-view.c b/src/views/gcal-week-view.c
index 437bf5c..3e71a9a 100644
--- a/src/views/gcal-week-view.c
+++ b/src/views/gcal-week-view.c
@@ -225,6 +225,9 @@ gcal_week_view_component_added (ECalDataModelSubscriber *subscriber,
GcalEvent *event;
event = gcal_event_new (e_client_get_source (E_CLIENT (client)), comp, NULL);
+
+ if (gcal_event_is_multiday (event) || gcal_event_get_all_day (event))
+ gcal_week_header_add_event (GCAL_WEEK_HEADER (self->header), event);
}
static void
@@ -233,10 +236,21 @@ gcal_week_view_component_modified (ECalDataModelSubscriber *subscriber,
ECalComponent *comp)
{
GcalWeekView *self = GCAL_WEEK_VIEW (subscriber);
+ GcalEvent *event;
+ GcalWeekHeader *header;
gchar *uuid;
+ header = GCAL_WEEK_HEADER (self->header);
+
+ event = gcal_event_new (e_client_get_source (E_CLIENT (client)), comp, NULL);
uuid = get_uuid_from_component (e_client_get_source (E_CLIENT (client)), comp);
- /* TODO: Implement for week_header and week_grid with if */
+
+ if (gcal_event_is_multiday (event) || gcal_event_get_all_day (event))
+ gcal_week_header_remove_event (header, uuid);
+
+ g_free (uuid);
+
+ gcal_week_view_component_added (subscriber, client, comp);
}
static void
@@ -245,18 +259,23 @@ gcal_week_view_component_removed (ECalDataModelSubscriber *subscriber,
const gchar *uid,
const gchar *rid)
{
- GcalWeekView *week_view = GCAL_WEEK_VIEW (subscriber);
- GList *children, *l;
+ GcalWeekView *self = GCAL_WEEK_VIEW (subscriber);
+ GcalWeekHeader *header;
ESource *source;
gchar *uuid;
+ header = GCAL_WEEK_HEADER (self->header);
+
source = e_client_get_source (E_CLIENT (client));
+
if (rid != NULL)
uuid = g_strdup_printf ("%s:%s:%s", e_source_get_uid (source), uid, rid);
else
uuid = g_strdup_printf ("%s:%s", e_source_get_uid (source), uid);
- /* TODO: Implement for week_header and week_grid with if */
+ gcal_week_header_remove_event (header, uuid);
+
+ g_free (uuid);
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]