[gnome-calendar] Made simple-add event work.
- From: Erick PÃrez Castellanos <erickpc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-calendar] Made simple-add event work.
- Date: Thu, 23 Aug 2012 13:45:11 +0000 (UTC)
commit a9da2aa5527a0449d8341d5f76ba6094e28568fe
Author: Erick PÃrez Castellanos <erick red gmail com>
Date: Wed Aug 22 01:04:36 2012 -0400
Made simple-add event work.
Fixed GcalEventOverlay handling of dates.
Added initial code and methods to handle adding events to GcalManager.
Fixed in GcalMonthView handling of dates passed to event-creation.
Fixed gcal-utils sources for gcc warning.
Fixed calling order in GcalWindow.
src/gcal-event-overlay.c | 8 ++++-
src/gcal-manager.c | 91 ++++++++++++++++++++++++++++++++++++++++++++++
src/gcal-manager.h | 6 +++
src/gcal-month-view.c | 3 ++
src/gcal-utils.c | 2 +-
src/gcal-utils.h | 38 ++++++++++----------
src/gcal-window.c | 15 ++++++--
7 files changed, 139 insertions(+), 24 deletions(-)
---
diff --git a/src/gcal-event-overlay.c b/src/gcal-event-overlay.c
index 51efa29..ab1516f 100644
--- a/src/gcal-event-overlay.c
+++ b/src/gcal-event-overlay.c
@@ -39,6 +39,7 @@ struct _GcalEventOverlayPrivate
icaltimetype *start_span;
icaltimetype *end_span;
+ gboolean one_day;
};
enum
@@ -342,7 +343,11 @@ gcal_event_overlay_gather_data (GcalEventOverlay *widget,
-1);
data->calendar_uid = uid;
data->start_date = priv->start_span;
- data->end_date = priv->end_span;
+
+ if (! priv->one_day)
+ data->end_date = priv->end_span;
+ else
+ data->end_date = NULL;
*new_data = data;
return TRUE;
@@ -507,6 +512,7 @@ gcal_event_overlay_set_span (GcalEventOverlay *widget,
*(priv->start_span) = *start_date;
real_end_date = end_date == NULL ? start_date : end_date;
+ priv->one_day = end_date == NULL;
if (priv->end_span == NULL)
priv->end_span = gcal_dup_icaltime (real_end_date);
else
diff --git a/src/gcal-manager.c b/src/gcal-manager.c
index 6914201..3965c3d 100644
--- a/src/gcal-manager.c
+++ b/src/gcal-manager.c
@@ -165,6 +165,10 @@ static void gcal_manager_send_fake_events_added (GcalManager *mana
static void gcal_manager_send_fave_events_removed (GcalManager *manager,
GcalManagerUnit *unit);
+static void gcal_manager_on_event_created (GObject *source_object,
+ GAsyncResult *result,
+ gpointer user_data);
+
G_DEFINE_TYPE(GcalManager, gcal_manager, G_TYPE_OBJECT)
static void
@@ -891,6 +895,34 @@ gcal_manager_send_fave_events_removed (GcalManager *manager,
g_slist_free_full (events_data, g_free);
}
+static void
+gcal_manager_on_event_created (GObject *source_object,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ ECalClient *client;
+ gchar *new_uid;
+ GError *error;
+
+ /* If* the view catch a signal of the newly created object the almost sure I
+ * have nothing to do here. */
+
+ client = E_CAL_CLIENT (source_object);
+ error = NULL;
+ if (e_cal_client_create_object_finish (client, result, &new_uid, &error))
+ {
+ g_debug ("Telling event: %s was created", new_uid);
+
+ g_free (new_uid);
+ }
+ else
+ {
+ /* Some error */
+ g_warning ("Error creating object: %s", error->message);
+ g_error_free (error);
+ }
+}
+
/* Public API */
/**
* gcal_manager_new:
@@ -1472,3 +1504,62 @@ gcal_manager_remove_event (GcalManager *manager,
data);
}
}
+
+void
+gcal_manager_create_event (GcalManager *manager,
+ const gchar *source_uid,
+ const gchar *summary,
+ const icaltimetype *initial_date,
+ const icaltimetype *final_date)
+{
+ GcalManagerPrivate *priv;
+ GcalManagerUnit *unit;
+ ECalComponent *event;
+ ECalComponentDateTime dt;
+ ECalComponentText summ;
+ icalcomponent *new_event_icalcomp;
+ icaltimetype *dt_start;
+
+ g_return_if_fail (GCAL_IS_MANAGER (manager));
+ priv = manager->priv;
+
+ unit = g_hash_table_lookup (priv->clients, source_uid);
+
+ event = e_cal_component_new ();
+ e_cal_component_set_new_vtype (event, E_CAL_COMPONENT_EVENT);
+
+ dt_start = gcal_dup_icaltime (initial_date);
+ dt.value = dt_start;
+ dt.tzid = NULL;
+ e_cal_component_set_dtstart (event, &dt);
+ g_debug ("dt_start :%s", icaltime_as_ical_string (*dt_start));
+
+ if (final_date != NULL)
+ {
+ g_debug ("setting final_date");
+ *dt.value = *final_date;
+ g_debug ("dt_end :%s", icaltime_as_ical_string (*final_date));
+ e_cal_component_set_dtend (event, &dt);
+ }
+ else
+ {
+ icaltime_adjust (dt_start, 1, 0, 0, 0);
+ *dt.value = *dt_start;
+ e_cal_component_set_dtend (event, &dt);
+ }
+
+ summ.altrep = NULL;
+ summ.value = summary;
+ e_cal_component_set_summary (event, &summ);
+
+ e_cal_component_commit_sequence (event);
+
+ new_event_icalcomp = e_cal_component_get_icalcomponent (event);
+ e_cal_client_create_object (unit->client,
+ new_event_icalcomp,
+ priv->async_ops,
+ gcal_manager_on_event_created,
+ manager);
+
+ g_object_unref (event);
+}
diff --git a/src/gcal-manager.h b/src/gcal-manager.h
index 554a3d5..df82b22 100644
--- a/src/gcal-manager.h
+++ b/src/gcal-manager.h
@@ -119,6 +119,12 @@ void gcal_manager_remove_event (GcalManager *manager
const gchar *source_uid,
const gchar *event_uid);
+void gcal_manager_create_event (GcalManager *manager,
+ const gchar *source_uid,
+ const gchar *summary,
+ const icaltimetype *initial_date,
+ const icaltimetype *final_date);
+
G_END_DECLS
#endif /* __GCAL_MANAGER_H__ */
diff --git a/src/gcal-month-view.c b/src/gcal-month-view.c
index 91d9333..88f4a15 100644
--- a/src/gcal-month-view.c
+++ b/src/gcal-month-view.c
@@ -550,6 +550,7 @@ gcal_month_view_button_press (GtkWidget *widget,
start_date = gcal_dup_icaltime (priv->date);
start_date->day = priv->start_mark_cell + priv->days_delay;
+ start_date->is_date = 1;
g_signal_emit_by_name (GCAL_VIEW (widget),
"create-event",
@@ -672,9 +673,11 @@ gcal_month_view_button_release (GtkWidget *widget,
start_date = gcal_dup_icaltime (priv->date);
start_date->day = priv->start_mark_cell + priv->days_delay;
+ start_date->is_date = 1;
end_date = gcal_dup_icaltime (priv->date);
end_date->day = priv->end_mark_cell + priv->days_delay;
+ end_date->is_date = 1;
g_signal_emit_by_name (GCAL_VIEW (widget),
"create-event",
diff --git a/src/gcal-utils.c b/src/gcal-utils.c
index 4b3afca..151d916 100644
--- a/src/gcal-utils.c
+++ b/src/gcal-utils.c
@@ -90,7 +90,7 @@ gcal_get_group_name (const gchar *base_uri)
}
icaltimetype*
-gcal_dup_icaltime (icaltimetype *date)
+gcal_dup_icaltime (const icaltimetype *date)
{
icaltimetype *new_date;
diff --git a/src/gcal-utils.h b/src/gcal-utils.h
index fe7ff5e..12b8df7 100644
--- a/src/gcal-utils.h
+++ b/src/gcal-utils.h
@@ -47,35 +47,35 @@ typedef enum
} GcalEditableMode;
typedef
-const gchar* (*GcalTranslateFunc) (GtkWidget *source_widget);
+const gchar* (*GcalTranslateFunc) (GtkWidget *source_widget);
GType icaltime_get_type (void) G_GNUC_CONST;
-void gcal_gtk_tree_view_set_activate_on_single_click (GtkTreeView *tree_view,
- gboolean should_activate);
+void gcal_gtk_tree_view_set_activate_on_single_click (GtkTreeView *tree_view,
+ gboolean should_activate);
-const gchar* gcal_get_group_name (const gchar *base_uri);
+const gchar* gcal_get_group_name (const gchar *base_uri);
-icaltimetype* gcal_dup_icaltime (icaltimetype *date);
+icaltimetype* gcal_dup_icaltime (const icaltimetype *date);
-gchar* gcal_get_source_name (GtkTreeModel *model,
- const gchar *uid);
+gchar* gcal_get_source_name (GtkTreeModel *model,
+ const gchar *uid);
-gchar* gcal_get_source_uid (GtkTreeModel *model,
- const gchar *name);
+gchar* gcal_get_source_uid (GtkTreeModel *model,
+ const gchar *name);
-const gchar* gcal_get_weekday (gint i);
+const gchar* gcal_get_weekday (gint i);
/* code brought from evolution */
-gsize e_strftime_fix_am_pm (gchar *str,
- gsize max,
- const gchar *fmt,
- const struct tm *tm);
-gsize e_utf8_strftime_fix_am_pm (gchar *str,
-
- gsize max,
- const gchar *fmt,
- const struct tm *tm);
+gsize e_strftime_fix_am_pm (gchar *str,
+ gsize max,
+ const gchar *fmt,
+ const struct tm *tm);
+gsize e_utf8_strftime_fix_am_pm (gchar *str,
+
+ gsize max,
+ const gchar *fmt,
+ const struct tm *tm);
#endif // __GCAL_UTILS_H__
diff --git a/src/gcal-window.c b/src/gcal-window.c
index 2202479..4c9425b 100644
--- a/src/gcal-window.c
+++ b/src/gcal-window.c
@@ -1117,17 +1117,26 @@ gcal_window_create_event (GcalEventOverlay *widget,
gpointer user_data)
{
GcalWindowPrivate *priv;
+ GcalManager *manager;
g_return_if_fail (user_data);
priv = GCAL_WINDOW (user_data)->priv;
- /* reset and hide */
- gcal_window_event_overlay_closed (widget, user_data);
-
/* create the event */
+ manager = gcal_window_get_manager (GCAL_WINDOW (user_data));
+ gcal_manager_create_event (manager,
+ new_data->calendar_uid,
+ new_data->summary,
+ new_data->start_date,
+ new_data->end_date);
+
g_debug ("NOW CREATE THE EVENT");
if (open_details)
g_debug ("Opening details window NOW");
+
+ /* reset and hide */
+ gcal_window_event_overlay_closed (widget, user_data);
+
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]