views/dazzling-month-view: Handle events
Most of the code is copied from GcalMonthView, so it sucks slightly. But it seems to work reasonably well so far.
This commit is contained in:
@@ -26,6 +26,7 @@
|
||||
#include "gcal-dazzling-month-view.h"
|
||||
#include "gcal-debug.h"
|
||||
#include "gcal-month-view-row.h"
|
||||
#include "gcal-range-tree.h"
|
||||
#include "gcal-timeline-subscriber.h"
|
||||
#include "gcal-utils.h"
|
||||
#include "gcal-view-private.h"
|
||||
@@ -50,6 +51,8 @@ struct _GcalDazzlingMonthView
|
||||
GtkWidget *weekday_label[7];
|
||||
|
||||
GPtrArray *week_rows;
|
||||
GcalRangeTree *events;
|
||||
GHashTable *events2;
|
||||
|
||||
/* Ranges from [0.0, 1.0] */
|
||||
gdouble row_offset;
|
||||
@@ -511,6 +514,44 @@ static void
|
||||
gcal_dazzling_month_view_add_event (GcalTimelineSubscriber *subscriber,
|
||||
GcalEvent *event)
|
||||
{
|
||||
GcalDazzlingMonthView *self;
|
||||
|
||||
GCAL_ENTRY;
|
||||
|
||||
g_assert (event != NULL);
|
||||
|
||||
self = GCAL_DAZZLING_MONTH_VIEW (subscriber);
|
||||
|
||||
if (!g_hash_table_add (self->events2, g_object_ref (event)))
|
||||
{
|
||||
g_warning ("Event with uuid: %s already added", gcal_event_get_uid (event));
|
||||
GCAL_RETURN ();
|
||||
}
|
||||
|
||||
for (guint i = 0; i < self->week_rows->len; i++)
|
||||
{
|
||||
g_autoptr (GcalRange) row_range = NULL;
|
||||
GcalRangePosition position;
|
||||
GcalRangeOverlap overlap;
|
||||
GcalMonthViewRow *row;
|
||||
|
||||
row = g_ptr_array_index (self->week_rows, i);
|
||||
row_range = gcal_month_view_row_get_range (row);
|
||||
|
||||
overlap = gcal_range_calculate_overlap (row_range, gcal_event_get_range (event), &position);
|
||||
if (overlap != GCAL_RANGE_NO_OVERLAP)
|
||||
{
|
||||
g_message ("Adding event %s to row %u", gcal_event_get_uid (event), i);
|
||||
gcal_month_view_row_add_event (row, event);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (position == GCAL_RANGE_AFTER)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
GCAL_EXIT;
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -523,6 +564,48 @@ static void
|
||||
gcal_dazzling_month_view_remove_event (GcalTimelineSubscriber *subscriber,
|
||||
GcalEvent *event)
|
||||
{
|
||||
g_autoptr (GcalEvent) owned_event = NULL;
|
||||
GcalDazzlingMonthView *self;
|
||||
|
||||
GCAL_ENTRY;
|
||||
|
||||
g_assert (event != NULL);
|
||||
|
||||
self = GCAL_DAZZLING_MONTH_VIEW (subscriber);
|
||||
|
||||
/* Keep event alive while removing it */
|
||||
owned_event = g_object_ref (event);
|
||||
|
||||
if (!g_hash_table_remove (self->events2, event))
|
||||
{
|
||||
g_warning ("Event with uuid: %s not in %s", gcal_event_get_uid (event), G_OBJECT_TYPE_NAME (self));
|
||||
GCAL_RETURN ();
|
||||
}
|
||||
|
||||
for (guint i = 0; i < self->week_rows->len; i++)
|
||||
{
|
||||
g_autoptr (GcalRange) row_range = NULL;
|
||||
GcalRangePosition position;
|
||||
GcalRangeOverlap overlap;
|
||||
GcalMonthViewRow *row;
|
||||
|
||||
row = g_ptr_array_index (self->week_rows, i);
|
||||
row_range = gcal_month_view_row_get_range (row);
|
||||
|
||||
overlap = gcal_range_calculate_overlap (row_range, gcal_event_get_range (event), &position);
|
||||
if (overlap != GCAL_RANGE_NO_OVERLAP)
|
||||
{
|
||||
g_message ("Remove event %s to row %u", gcal_event_get_uid (event), i);
|
||||
gcal_month_view_row_remove_event (row, event);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (position == GCAL_RANGE_AFTER)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
GCAL_EXIT;
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -814,6 +897,9 @@ gcal_dazzling_month_view_dispose (GObject *object)
|
||||
|
||||
GCAL_ENTRY;
|
||||
|
||||
g_clear_pointer (&self->events2, g_hash_table_destroy);
|
||||
g_clear_pointer (&self->events, gcal_range_tree_unref);
|
||||
|
||||
g_clear_object (&self->kinetic_scroll_animation);
|
||||
g_clear_object (&self->row_offset_animation);
|
||||
|
||||
@@ -932,6 +1018,9 @@ gcal_dazzling_month_view_init (GcalDazzlingMonthView *self)
|
||||
{
|
||||
g_autoptr (GDateTime) now = NULL;
|
||||
|
||||
self->events = gcal_range_tree_new_with_free_func (g_object_unref);
|
||||
self->events2 = g_hash_table_new_full (g_direct_hash, g_direct_equal, g_object_unref, NULL);
|
||||
|
||||
gtk_widget_init_template (GTK_WIDGET (self));
|
||||
update_weekday_labels (self);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user