event: add a wrapper around events
Instead of relying on confusing structures, raw data and direct access to components, add a wrapper for events.
This commit is contained in:
@@ -34,6 +34,8 @@ gnome_calendar_SOURCES = \
|
|||||||
gcal-date-selector.h \
|
gcal-date-selector.h \
|
||||||
gcal-edit-dialog.c \
|
gcal-edit-dialog.c \
|
||||||
gcal-edit-dialog.h \
|
gcal-edit-dialog.h \
|
||||||
|
gcal-event.c \
|
||||||
|
gcal-event.h \
|
||||||
gcal-event-widget.c \
|
gcal-event-widget.c \
|
||||||
gcal-event-widget.h \
|
gcal-event-widget.h \
|
||||||
gcal-manager.c \
|
gcal-manager.c \
|
||||||
|
|||||||
+1168
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,98 @@
|
|||||||
|
/* gcal-event.h
|
||||||
|
*
|
||||||
|
* Copyright (C) 2016 Georges Basile Stavracas Neto <georges.stavracas@gmail.com>
|
||||||
|
*
|
||||||
|
* 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 3 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_EVENT_H
|
||||||
|
#define GCAL_EVENT_H
|
||||||
|
|
||||||
|
#include <glib-object.h>
|
||||||
|
#include <gtk/gtk.h>
|
||||||
|
#include <libecal/libecal.h>
|
||||||
|
#include <libedataserver/libedataserver.h>
|
||||||
|
|
||||||
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
|
#define GCAL_TYPE_EVENT (gcal_event_get_type())
|
||||||
|
|
||||||
|
G_DECLARE_FINAL_TYPE (GcalEvent, gcal_event, GCAL, EVENT, GObject)
|
||||||
|
|
||||||
|
GcalEvent* gcal_event_new (ESource *source,
|
||||||
|
ECalComponent *component);
|
||||||
|
|
||||||
|
gboolean gcal_event_get_all_day (GcalEvent *self);
|
||||||
|
|
||||||
|
void gcal_event_set_all_day (GcalEvent *self,
|
||||||
|
gboolean all_day);
|
||||||
|
|
||||||
|
GdkRGBA* gcal_event_get_color (GcalEvent *self);
|
||||||
|
|
||||||
|
void gcal_event_set_color (GcalEvent *self,
|
||||||
|
GdkRGBA *color);
|
||||||
|
|
||||||
|
ECalComponent* gcal_event_get_component (GcalEvent *self);
|
||||||
|
|
||||||
|
GDateTime* gcal_event_get_date_end (GcalEvent *self);
|
||||||
|
|
||||||
|
void gcal_event_set_date_end (GcalEvent *self,
|
||||||
|
GDateTime *dt);
|
||||||
|
|
||||||
|
GDateTime* gcal_event_get_date_start (GcalEvent *self);
|
||||||
|
|
||||||
|
void gcal_event_set_date_start (GcalEvent *self,
|
||||||
|
GDateTime *dt);
|
||||||
|
|
||||||
|
const gchar* gcal_event_get_description (GcalEvent *self);
|
||||||
|
|
||||||
|
void gcal_event_set_description (GcalEvent *self,
|
||||||
|
const gchar *description);
|
||||||
|
|
||||||
|
const gchar* gcal_event_get_location (GcalEvent *self);
|
||||||
|
|
||||||
|
void gcal_event_set_location (GcalEvent *self,
|
||||||
|
const gchar *location);
|
||||||
|
|
||||||
|
ESource* gcal_event_get_source (GcalEvent *self);
|
||||||
|
|
||||||
|
void gcal_event_set_source (GcalEvent *self,
|
||||||
|
ESource *source);
|
||||||
|
|
||||||
|
const gchar* gcal_event_get_summary (GcalEvent *self);
|
||||||
|
|
||||||
|
void gcal_event_set_summary (GcalEvent *self,
|
||||||
|
const gchar *summary);
|
||||||
|
|
||||||
|
GTimeZone* gcal_event_get_timezone (GcalEvent *self);
|
||||||
|
|
||||||
|
void gcal_event_set_timezone (GcalEvent *self,
|
||||||
|
GTimeZone *timezone);
|
||||||
|
|
||||||
|
const gchar* gcal_event_get_uid (GcalEvent *self);
|
||||||
|
|
||||||
|
/* Utilities */
|
||||||
|
|
||||||
|
gboolean gcal_event_is_multiday (GcalEvent *self);
|
||||||
|
|
||||||
|
gint gcal_event_compare (GcalEvent *event1,
|
||||||
|
GcalEvent *event2);
|
||||||
|
|
||||||
|
gint gcal_event_compare_with_current (GcalEvent *event1,
|
||||||
|
GcalEvent *event2,
|
||||||
|
time_t *current_time);
|
||||||
|
|
||||||
|
G_END_DECLS
|
||||||
|
|
||||||
|
#endif /* GCAL_EVENT_H */
|
||||||
+61
-2
@@ -63,6 +63,61 @@ month_item[12] =
|
|||||||
|
|
||||||
G_DEFINE_BOXED_TYPE (icaltimetype, icaltime, gcal_dup_icaltime, g_free)
|
G_DEFINE_BOXED_TYPE (icaltimetype, icaltime, gcal_dup_icaltime, g_free)
|
||||||
|
|
||||||
|
icaltimetype*
|
||||||
|
datetime_to_icaltime (GDateTime *dt)
|
||||||
|
{
|
||||||
|
icaltimetype *idt;
|
||||||
|
|
||||||
|
if (!dt)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
idt = g_new0 (icaltimetype, 1);
|
||||||
|
|
||||||
|
idt->year = g_date_time_get_year (dt);
|
||||||
|
idt->month = g_date_time_get_month (dt);
|
||||||
|
idt->day = g_date_time_get_day_of_month (dt);
|
||||||
|
idt->hour = g_date_time_get_hour (dt);
|
||||||
|
idt->minute = g_date_time_get_minute (dt);
|
||||||
|
idt->second = g_date_time_get_seconds (dt);
|
||||||
|
idt->is_date = (idt->hour == 0 &&
|
||||||
|
idt->minute == 0 &&
|
||||||
|
idt->second == 0);
|
||||||
|
|
||||||
|
return idt;
|
||||||
|
}
|
||||||
|
|
||||||
|
GDateTime*
|
||||||
|
icaltime_to_datetime (const icaltimetype *date,
|
||||||
|
GTimeZone **timezone)
|
||||||
|
{
|
||||||
|
GDateTime *dt;
|
||||||
|
GTimeZone *tz;
|
||||||
|
|
||||||
|
tz = date->zone ? g_time_zone_new (icaltime_get_tzid (*date)) : g_time_zone_new_utc ();
|
||||||
|
dt = g_date_time_new (tz,
|
||||||
|
date->year,
|
||||||
|
date->month,
|
||||||
|
date->day,
|
||||||
|
date->is_date ? 0 : date->hour,
|
||||||
|
date->is_date ? 0 : date->minute,
|
||||||
|
date->is_date ? 0 : date->second);
|
||||||
|
|
||||||
|
if (timezone)
|
||||||
|
*timezone = tz;
|
||||||
|
else
|
||||||
|
g_clear_pointer (&tz, g_time_zone_unref);
|
||||||
|
|
||||||
|
return dt;
|
||||||
|
}
|
||||||
|
|
||||||
|
gboolean
|
||||||
|
datetime_is_date (GDateTime *dt)
|
||||||
|
{
|
||||||
|
return g_date_time_get_hour (dt) == 0 &&
|
||||||
|
g_date_time_get_minute (dt) == 0 &&
|
||||||
|
g_date_time_get_seconds (dt) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
icaltimetype*
|
icaltimetype*
|
||||||
gcal_dup_icaltime (const icaltimetype *date)
|
gcal_dup_icaltime (const icaltimetype *date)
|
||||||
{
|
{
|
||||||
@@ -351,15 +406,17 @@ build_component_from_details (const gchar *summary,
|
|||||||
const icaltimetype *final_date)
|
const icaltimetype *final_date)
|
||||||
{
|
{
|
||||||
ECalComponent *event;
|
ECalComponent *event;
|
||||||
|
|
||||||
ECalComponentDateTime dt;
|
ECalComponentDateTime dt;
|
||||||
ECalComponentText summ;
|
ECalComponentText summ;
|
||||||
|
GTimeZone *tz;
|
||||||
|
|
||||||
|
tz = g_time_zone_new_local ();
|
||||||
|
|
||||||
event = e_cal_component_new ();
|
event = e_cal_component_new ();
|
||||||
e_cal_component_set_new_vtype (event, E_CAL_COMPONENT_EVENT);
|
e_cal_component_set_new_vtype (event, E_CAL_COMPONENT_EVENT);
|
||||||
|
|
||||||
dt.value = (icaltimetype*) initial_date;
|
dt.value = (icaltimetype*) initial_date;
|
||||||
dt.tzid = NULL;
|
dt.tzid = g_time_zone_get_abbreviation (tz, 0);
|
||||||
e_cal_component_set_dtstart (event, &dt);
|
e_cal_component_set_dtstart (event, &dt);
|
||||||
|
|
||||||
if (final_date != NULL)
|
if (final_date != NULL)
|
||||||
@@ -382,6 +439,8 @@ build_component_from_details (const gchar *summary,
|
|||||||
|
|
||||||
e_cal_component_commit_sequence (event);
|
e_cal_component_commit_sequence (event);
|
||||||
|
|
||||||
|
g_clear_pointer (&tz, g_time_zone_unref);
|
||||||
|
|
||||||
return event;
|
return event;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -52,6 +52,13 @@ const gchar* (*GcalTranslateFunc) (GtkWidget
|
|||||||
|
|
||||||
GType icaltime_get_type (void) G_GNUC_CONST;
|
GType icaltime_get_type (void) G_GNUC_CONST;
|
||||||
|
|
||||||
|
icaltimetype* datetime_to_icaltime (GDateTime *dt);
|
||||||
|
|
||||||
|
gboolean datetime_is_date (GDateTime *dt);
|
||||||
|
|
||||||
|
GDateTime* icaltime_to_datetime (const icaltimetype *date,
|
||||||
|
GTimeZone **timezone);
|
||||||
|
|
||||||
icaltimetype* gcal_dup_icaltime (const icaltimetype *date);
|
icaltimetype* gcal_dup_icaltime (const icaltimetype *date);
|
||||||
|
|
||||||
gchar* gcal_get_weekday (gint i);
|
gchar* gcal_get_weekday (gint i);
|
||||||
|
|||||||
Reference in New Issue
Block a user