aboutsummaryrefslogtreecommitdiffstats
path: root/calendar/gui/calendar-model.c
diff options
context:
space:
mode:
authorDamon Chaplin <damon@ximian.com>2001-10-23 08:23:42 +0800
committerDamon Chaplin <damon@src.gnome.org>2001-10-23 08:23:42 +0800
commit04bda8ad1e0cb676d711dbf0f22ff9f4fb615891 (patch)
tree7f1ff1303c52e9b48a0006c500b204902b9d77c5 /calendar/gui/calendar-model.c
parent68de308a89a844dcc579e1d9f24d7813d645c956 (diff)
downloadgsoc2013-evolution-04bda8ad1e0cb676d711dbf0f22ff9f4fb615891.tar
gsoc2013-evolution-04bda8ad1e0cb676d711dbf0f22ff9f4fb615891.tar.gz
gsoc2013-evolution-04bda8ad1e0cb676d711dbf0f22ff9f4fb615891.tar.bz2
gsoc2013-evolution-04bda8ad1e0cb676d711dbf0f22ff9f4fb615891.tar.lz
gsoc2013-evolution-04bda8ad1e0cb676d711dbf0f22ff9f4fb615891.tar.xz
gsoc2013-evolution-04bda8ad1e0cb676d711dbf0f22ff9f4fb615891.tar.zst
gsoc2013-evolution-04bda8ad1e0cb676d711dbf0f22ff9f4fb615891.zip
added setDefaultTimezone() method.
2001-10-22 Damon Chaplin <damon@ximian.com> * idl/evolution-calendar.idl: added setDefaultTimezone() method. * pcs/cal-backend.c (cal_backend_get_default_timezone): (cal_backend_set_default_timezone): new functions to call class methods. * pcs/cal-backend-file.c: lots of changes to handle the default timezone and use it. * pcs/query.c: use the default timezone. * gui/dialogs/task-details-page.c (date_changed_cb): initialized completed_tt. * gui/dialogs/event-page.c: changed it to handle DATE values. The 'All Day Event' checkbox is only set now when the DTSTART and DTEND are DATE values. * gui/dialogs/comp-editor-util.c (comp_editor_free_dates): free the CalComponentDateTime structs as well. * gui/e-tasks.c: set the default timezone on the server. * gui/tag-calendar.c: * gui/gnome-cal.c: * gui/e-week-view.c: * gui/e-day-view.c: updates to handle DATE values. * gui/e-calendar-table.c (date_compare_cb): updated to use the new ECellDateEditValue values, so it now works. (percent_compare_cb): updated to use GPOINTER_TO_INT values. (e_calendar_table_init): use an ECellPercent for the percent field and an ECellDateEditText for the date fields. * gui/comp-util.c (cal_comp_util_compare_event_timezones): return TRUE if the DTSTART or DTEND is a DATE value. We don't want to show the timezone icons for DATE values. * gui/comp-editor-factory.c (resolve_pending_requests): set the default timezone on the server. * gui/calendar-model.c: major changes to support sorting properly. For date and percent fields we now use subclasses of ECellText, so we don't use a char* as the model value. For the percent field we now use a GINT_TO_POINTER. For the date fields we now use a ECellDateEditValue* as the value. * gui/calendar-config.c (calendar_config_configure_e_cell_date_edit): set the timezone and use_24_hour flags of the new ECellDateEditText. * conduits/todo/todo-conduit.c (pre_sync): * conduits/calendar/calendar-conduit.c (pre_sync): set the default timezone on the server. * cal-util/timeutil.c (time_days_in_month): removed debug message. * cal-util/test-recur.c: try to handle timezones in the iCalendar file properly, and updated to pass default timezone. * cal-util/cal-util.c (cal_util_generate_alarms_for_comp): (cal_util_generate_alarms_for_list): added default timezone argument. * cal-util/cal-recur.c: changed many of the functions to take a default timezone, to use to resolve DATE and floating DATE-TIME values. * cal-client/cal-client.c (cal_client_set_default_timezone): new function to set the default timezone. (cal_client_ensure_timezone_on_server): new function to ensure that a given timezone is on the server. * gui/e-cell-date-edit-text.c: new subclass of ECellText to display and edit a date value. * cal-util/cal-recur.c (cal_obj_byday_expand_monthly): changed week_num to -week_num when calculating the weeks to go back from the end of the month for things like BYDAY=-2WE. Fixes bug #11525. (cal_recur_generate_instances_of_rule): only go up to MAX_YEAR (2037). We can't really handle anything past that anyway. (cal_recur_ensure_rule_end_date): initialize cb_date.end_date to 0, so if the RULE doesn't generate COUNT instances we save 0 as the time_t. svn path=/trunk/; revision=13920
Diffstat (limited to 'calendar/gui/calendar-model.c')
-rw-r--r--calendar/gui/calendar-model.c480
1 files changed, 245 insertions, 235 deletions
diff --git a/calendar/gui/calendar-model.c b/calendar/gui/calendar-model.c
index 6b0dd31540..bb57586767 100644
--- a/calendar/gui/calendar-model.c
+++ b/calendar/gui/calendar-model.c
@@ -40,6 +40,7 @@
#include "itip-utils.h"
#include "calendar-model.h"
#include "evolution-activity-client.h"
+#include "e-cell-date-edit-text.h"
/* This specifies how often we refresh the list, so that completed tasks are
hidden according to the config setting, and overdue tasks change color etc.
@@ -48,6 +49,19 @@
lose their edit, so this isn't ideal. */
#define CALENDAR_MODEL_REFRESH_TIMEOUT 1000 * 60 * 10
+/* These hold the date values of the objects, so we can free the values when
+ we no longer need them. */
+typedef struct _CalendarModelObjectData CalendarModelObjectData;
+struct _CalendarModelObjectData {
+ ECellDateEditValue *dtstart;
+ ECellDateEditValue *dtend;
+ ECellDateEditValue *due;
+ ECellDateEditValue *completed;
+};
+
+/* We use a pointer to this value to indicate that the property is not set. */
+static ECellDateEditValue unset_date_edit_value;
+
/* Private part of the ECalendarModel structure */
struct _CalendarModelPrivate {
/* Calendar client we are using */
@@ -63,6 +77,10 @@ struct _CalendarModelPrivate {
/* Array of pointers to calendar objects */
GArray *objects;
+ /* Array of CalendarModelObjectData* holding data for each of the
+ objects in the objects array above. */
+ GArray *objects_data;
+
/* UID -> array index hash */
GHashTable *uid_index_hash;
@@ -207,6 +225,7 @@ calendar_model_init (CalendarModel *model)
priv->query = NULL;
priv->objects = g_array_new (FALSE, TRUE, sizeof (CalComponent *));
+ priv->objects_data = g_array_new (FALSE, FALSE, sizeof (CalendarModelObjectData));
priv->uid_index_hash = g_hash_table_new (g_str_hash, g_str_equal);
priv->new_comp_vtype = CAL_COMPONENT_EVENT;
priv->use_24_hour_format = TRUE;
@@ -221,6 +240,23 @@ calendar_model_init (CalendarModel *model)
priv->activity = NULL;
}
+static void
+calendar_model_free_object_data (CalendarModel *model,
+ CalendarModelObjectData *object_data)
+{
+ if (object_data->dtstart != &unset_date_edit_value)
+ g_free (object_data->dtstart);
+
+ if (object_data->dtend != &unset_date_edit_value)
+ g_free (object_data->dtend);
+
+ if (object_data->due != &unset_date_edit_value)
+ g_free (object_data->due);
+
+ if (object_data->completed != &unset_date_edit_value)
+ g_free (object_data->completed);
+}
+
/* Called from g_hash_table_foreach_remove(), frees a stored UID->index
* mapping.
*/
@@ -248,13 +284,19 @@ free_objects (CalendarModel *model)
for (i = 0; i < priv->objects->len; i++) {
CalComponent *comp;
+ CalendarModelObjectData *object_data;
comp = g_array_index (priv->objects, CalComponent *, i);
g_assert (comp != NULL);
gtk_object_unref (GTK_OBJECT (comp));
+
+ object_data = &g_array_index (priv->objects_data,
+ CalendarModelObjectData, i);
+ calendar_model_free_object_data (model, object_data);
}
g_array_set_size (priv->objects, 0);
+ g_array_set_size (priv->objects_data, 0);
}
/* Destroy handler for the calendar table model */
@@ -304,6 +346,9 @@ calendar_model_destroy (GtkObject *object)
g_array_free (priv->objects, TRUE);
priv->objects = NULL;
+ g_array_free (priv->objects_data, TRUE);
+ priv->objects_data = NULL;
+
g_free (priv->default_category);
itip_addresses_free (priv->addresses);
@@ -346,44 +391,6 @@ calendar_model_row_count (ETableModel *etm)
return priv->objects->len;
}
-/* Creates a nice string representation of a time value. If show_midnight is
- FALSE, and the time is midnight, then we just show the date. */
-static char*
-get_time_t (CalendarModel *model, time_t *t, gboolean show_midnight)
-{
- static char buffer[64];
- struct tm tmp_tm;
- struct icaltimetype tt;
-
- if (*t <= 0) {
- buffer[0] = '\0';
- } else {
- /* Note that although the property may be in a different
- timezone, we convert it to the current timezone to display
- it in the table. If the user actually edits the value,
- it will be set to the current timezone. See set_datetime. */
- tt = icaltime_from_timet_with_zone (*t, FALSE,
- model->priv->zone);
- tmp_tm.tm_year = tt.year - 1900;
- tmp_tm.tm_mon = tt.month - 1;
- tmp_tm.tm_mday = tt.day;
- tmp_tm.tm_hour = tt.hour;
- tmp_tm.tm_min = tt.minute;
- tmp_tm.tm_sec = tt.second;
- tmp_tm.tm_isdst = -1;
-
- tmp_tm.tm_wday = time_day_of_week (tt.day, tt.month - 1,
- tt.year);
-
- e_time_format_date_and_time (&tmp_tm,
- model->priv->use_24_hour_format,
- show_midnight, FALSE,
- buffer, sizeof (buffer));
- }
-
- return buffer;
-}
-
/* Builds a string based on the list of CATEGORIES properties of a calendar
* component.
*/
@@ -417,79 +424,92 @@ get_classification (CalComponent *comp)
}
}
-/* Builds a string for the COMPLETED property of a calendar component */
-static char *
+/* Returns an ECellDateEditValue* for a COMPLETED property of a
+ calendar component. Note that we cache these in the objects_data array so
+ we can free them eventually. */
+static ECellDateEditValue*
get_completed (CalendarModel *model,
- CalComponent *comp)
+ CalComponent *comp,
+ int row)
{
+ CalendarModelPrivate *priv;
+ CalComponentDateTime dt;
+ CalendarModelObjectData *object_data;
struct icaltimetype *completed;
- time_t t;
- cal_component_get_completed (comp, &completed);
+ priv = model->priv;
+
+ object_data = &g_array_index (priv->objects_data,
+ CalendarModelObjectData, row);
- if (!completed)
- t = 0;
- else {
- /* Note that COMPLETED is stored in UTC, though we show it in
- the current timezone. */
- t = icaltime_as_timet_with_zone (*completed, icaltimezone_get_utc_timezone ());
- cal_component_free_icaltimetype (completed);
+ if (!object_data->completed) {
+ cal_component_get_completed (comp, &completed);
+
+ if (completed) {
+ object_data->completed = g_new (ECellDateEditValue, 1);
+ object_data->completed->tt = *dt.value;
+ object_data->completed->zone = icaltimezone_get_utc_timezone ();
+ cal_component_free_icaltimetype (completed);
+ } else {
+ object_data->completed = &unset_date_edit_value;
+ }
}
- return get_time_t (model, &t, TRUE);
+ return (object_data->completed == &unset_date_edit_value)
+ ? NULL : object_data->completed;
}
-/* Builds a string for and frees a date/time value */
-static char *
-get_and_free_datetime (CalendarModel *model, CalComponentDateTime dt)
+/* Returns an ECellDateEditValue* for a DTSTART, DTEND or DUE property of a
+ calendar component. Note that we cache these in the objects_data array so
+ we can free them eventually. */
+static ECellDateEditValue*
+get_date_edit_value (CalendarModel *model, CalComponent *comp,
+ int col, int row)
{
- time_t t;
-
- if (!dt.value)
- t = 0;
- else {
- CalClientGetStatus status;
- icaltimezone *zone;
+ CalendarModelPrivate *priv;
+ CalComponentDateTime dt;
+ CalendarModelObjectData *object_data;
+ ECellDateEditValue **value;
- /* FIXME: TIMEZONES: Handle error. */
- status = cal_client_get_timezone (model->priv->client, dt.tzid,
- &zone);
- t = icaltime_as_timet_with_zone (*dt.value, zone);
- }
+ priv = model->priv;
- cal_component_free_datetime (&dt);
+ object_data = &g_array_index (priv->objects_data,
+ CalendarModelObjectData, row);
- return get_time_t (model, &t, TRUE);
-}
+ if (col == CAL_COMPONENT_FIELD_DTSTART)
+ value = &object_data->dtstart;
+ else if (col == CAL_COMPONENT_FIELD_DTEND)
+ value = &object_data->dtend;
+ else
+ value = &object_data->due;
-/* Builds a string for the DTEND property of a calendar component */
-static char *
-get_dtend (CalendarModel *model, CalComponent *comp)
-{
- CalComponentDateTime dt;
+ if (!(*value)) {
+ if (col == CAL_COMPONENT_FIELD_DTSTART)
+ cal_component_get_dtstart (comp, &dt);
+ else if (col == CAL_COMPONENT_FIELD_DTEND)
+ cal_component_get_dtend (comp, &dt);
+ else
+ cal_component_get_due (comp, &dt);
- cal_component_get_dtend (comp, &dt);
- return get_and_free_datetime (model, dt);
-}
+ if (dt.value) {
+ CalClientGetStatus status;
+ icaltimezone *zone;
-/* Builds a string for the DTSTART property of a calendar component */
-static char *
-get_dtstart (CalendarModel *model, CalComponent *comp)
-{
- CalComponentDateTime dt;
+ *value = g_new (ECellDateEditValue, 1);
+ (*value)->tt = *dt.value;
- cal_component_get_dtstart (comp, &dt);
- return get_and_free_datetime (model, dt);
-}
+ /* FIXME: TIMEZONES: Handle error. */
+ status = cal_client_get_timezone (model->priv->client,
+ dt.tzid, &zone);
+ (*value)->zone = zone;
+ } else {
+ *value = &unset_date_edit_value;
+ }
-/* Builds a string for the DUE property of a calendar component */
-static char *
-get_due (CalendarModel *model, CalComponent *comp)
-{
- CalComponentDateTime dt;
+ cal_component_free_datetime (&dt);
+ }
- cal_component_get_due (comp, &dt);
- return get_and_free_datetime (model, dt);
+ return (*value == &unset_date_edit_value) ? NULL : *value;
}
/* Builds a string for the GEO property of a calendar component */
@@ -516,22 +536,21 @@ get_geo (CalComponent *comp)
}
/* Builds a string for the PERCENT property of a calendar component */
-static char *
+static int
get_percent (CalComponent *comp)
{
- int *percent;
- static char buf[32];
+ int *percent, retval;
cal_component_get_percent (comp, &percent);
- if (!percent)
- buf[0] = '\0';
- else {
- g_snprintf (buf, sizeof (buf), "%d%%", *percent);
+ if (percent) {
+ retval = *percent;
cal_component_free_percent (percent);
+ } else {
+ retval = -1;
}
- return buf;
+ return retval;
}
/* Builds a string for the PRIORITY property of a calendar component */
@@ -748,7 +767,7 @@ get_location (CalComponent *comp)
const char *location;
cal_component_get_location (comp, &location);
- return location;
+ return (void*) location;
}
/* value_at handler for the calendar table model */
@@ -780,22 +799,18 @@ calendar_model_value_at (ETableModel *etm, int col, int row)
return get_classification (comp);
case CAL_COMPONENT_FIELD_COMPLETED:
- return get_completed (model, comp);
+ return get_completed (model, comp, row);
case CAL_COMPONENT_FIELD_DTEND:
- return get_dtend (model, comp);
-
case CAL_COMPONENT_FIELD_DTSTART:
- return get_dtstart (model, comp);
-
case CAL_COMPONENT_FIELD_DUE:
- return get_due (model, comp);
+ return get_date_edit_value (model, comp, col, row);
case CAL_COMPONENT_FIELD_GEO:
return get_geo (comp);
case CAL_COMPONENT_FIELD_PERCENT:
- return get_percent (comp);
+ return GINT_TO_POINTER (get_percent (comp));
case CAL_COMPONENT_FIELD_PRIORITY:
return get_priority (comp);
@@ -900,7 +915,7 @@ string_is_empty (const char *value)
if (value) {
p = value;
while (*p) {
- if (!isspace (*p)) {
+ if (!isspace ((unsigned char) *p)) {
empty = FALSE;
break;
}
@@ -911,40 +926,6 @@ string_is_empty (const char *value)
}
-/* FIXME: We need to set the "transient_for" property for the dialog, but
- the model doesn't know anything about the windows. */
-static void
-show_date_warning (CalendarModel *model)
-{
- GtkWidget *dialog;
- char buffer[64], message[256], *format;
- time_t t;
- struct tm *tmp_tm;
-
- t = time (NULL);
- /* We are only using this as an example, so the timezone doesn't
- matter. */
- tmp_tm = localtime (&t);
-
- if (model->priv->use_24_hour_format)
- /* strftime format of a weekday, a date and a time, 24-hour. */
- format = _("%a %m/%d/%Y %H:%M:%S");
- else
- /* strftime format of a weekday, a date and a time, 12-hour. */
- format = _("%a %m/%d/%Y %I:%M:%S %p");
-
- strftime (buffer, sizeof (buffer), format, tmp_tm);
-
- g_snprintf (message, 256,
- _("The date must be entered in the format: \n\n%s"),
- buffer);
-
- dialog = gnome_message_box_new (message,
- GNOME_MESSAGE_BOX_ERROR,
- GNOME_STOCK_BUTTON_OK, NULL);
- gtk_widget_show (dialog);
-}
-
/* Builds a list of categories from a comma-delimited string */
static GSList *
categories_from_string (const char *value)
@@ -1028,31 +1009,18 @@ set_classification (CalComponent *comp,
/* Called to set the "Date Completed" field. We also need to update the
Status and Percent fields to make sure they match. */
static void
-set_completed (CalendarModel *model, CalComponent *comp, const char *value)
+set_completed (CalendarModel *model, CalComponent *comp, const void *value)
{
- ETimeParseStatus status;
- struct tm tmp_tm;
- time_t t;
+ ECellDateEditValue *dv = (ECellDateEditValue*) value;
- status = e_time_parse_date_and_time (value, &tmp_tm);
-
- if (status == E_TIME_PARSE_INVALID) {
- show_date_warning (model);
- } else if (status == E_TIME_PARSE_NONE) {
+ if (!dv) {
ensure_task_not_complete (comp);
} else {
- struct icaltimetype itt = icaltime_null_time ();
-
- itt.year = tmp_tm.tm_year + 1900;
- itt.month = tmp_tm.tm_mon + 1;
- itt.day = tmp_tm.tm_mday;
- itt.hour = tmp_tm.tm_hour;
- itt.minute = tmp_tm.tm_min;
- itt.second = tmp_tm.tm_sec;
+ time_t t;
/* We assume that COMPLETED is entered in the current timezone,
even though it gets stored in UTC. */
- t = icaltime_as_timet_with_zone (itt, model->priv->zone);
+ t = icaltime_as_timet_with_zone (dv->tt, dv->zone);
ensure_task_complete (comp, t);
}
@@ -1060,33 +1028,18 @@ set_completed (CalendarModel *model, CalComponent *comp, const char *value)
/* Sets a CalComponentDateTime value */
static void
-set_datetime (CalendarModel *model, CalComponent *comp, const char *value,
+set_datetime (CalendarModel *model, CalComponent *comp, const void *value,
void (* set_func) (CalComponent *comp, CalComponentDateTime *dt))
{
- ETimeParseStatus status;
- struct tm tmp_tm;
+ ECellDateEditValue *dv = (ECellDateEditValue*) value;
- status = e_time_parse_date_and_time (value, &tmp_tm);
-
- if (status == E_TIME_PARSE_INVALID) {
- show_date_warning (model);
- } else if (status == E_TIME_PARSE_NONE) {
+ if (!dv) {
(* set_func) (comp, NULL);
} else {
CalComponentDateTime dt;
- struct icaltimetype itt = icaltime_null_time ();
-
- itt.year = tmp_tm.tm_year + 1900;
- itt.month = tmp_tm.tm_mon + 1;
- itt.day = tmp_tm.tm_mday;
- itt.hour = tmp_tm.tm_hour;
- itt.minute = tmp_tm.tm_min;
- itt.second = tmp_tm.tm_sec;
- dt.value = &itt;
- /* FIXME: We assume it is being set to the current timezone.
- Is that OK? */
- dt.tzid = icaltimezone_get_tzid (model->priv->zone);
+ dt.value = &dv->tt;
+ dt.tzid = icaltimezone_get_tzid (dv->zone);
(* set_func) (comp, &dt);
}
@@ -1132,45 +1085,27 @@ set_geo (CalComponent *comp, const char *value)
cal_component_set_geo (comp, &geo);
}
-/* FIXME: We need to set the "transient_for" property for the dialog, but the
- * model doesn't know anything about the windows.
- */
-static void
-show_percent_warning (void)
-{
- GtkWidget *dialog;
-
- dialog = gnome_message_box_new (_("The percent value must be between 0 and 100, inclusive"),
- GNOME_MESSAGE_BOX_ERROR,
- GNOME_STOCK_BUTTON_OK, NULL);
- gtk_widget_show (dialog);
-}
-
/* Sets the percent value of a calendar component */
static void
-set_percent (CalComponent *comp, const char *value)
+set_percent (CalComponent *comp, const void *value)
{
- int matched, percent;
+ gint percent = GPOINTER_TO_INT (value);
- if (string_is_empty (value)) {
+ g_return_if_fail (percent >= -1);
+ g_return_if_fail (percent <= 100);
+
+ /* A value of -1 means it isn't set. */
+ if (percent == -1) {
cal_component_set_percent (comp, NULL);
ensure_task_not_complete (comp);
- return;
- }
-
- matched = sscanf (value, "%i", &percent);
+ } else {
+ cal_component_set_percent (comp, &percent);
- if (matched != 1 || percent < 0 || percent > 100) {
- show_percent_warning ();
- return;
+ if (percent == 100)
+ ensure_task_complete (comp, -1);
+ else
+ ensure_task_not_complete (comp);
}
-
- cal_component_set_percent (comp, &percent);
-
- if (percent == 100)
- ensure_task_complete (comp, -1);
- else
- ensure_task_not_complete (comp);
}
/* Sets the priority of a calendar component */
@@ -1476,6 +1411,19 @@ dup_string (const char *value)
return g_strdup (value);
}
+static void*
+dup_date_edit_value (const void *value)
+{
+ ECellDateEditValue *dv, *orig_dv;
+
+ orig_dv = (ECellDateEditValue*) value;
+
+ dv = g_new (ECellDateEditValue, 1);
+ *dv = *orig_dv;
+
+ return dv;
+}
+
/* duplicate_value handler for the calendar table model */
static void *
calendar_model_duplicate_value (ETableModel *etm, int col, const void *value)
@@ -1489,12 +1437,7 @@ calendar_model_duplicate_value (ETableModel *etm, int col, const void *value)
switch (col) {
case CAL_COMPONENT_FIELD_CATEGORIES:
case CAL_COMPONENT_FIELD_CLASSIFICATION:
- case CAL_COMPONENT_FIELD_COMPLETED:
- case CAL_COMPONENT_FIELD_DTEND:
- case CAL_COMPONENT_FIELD_DTSTART:
- case CAL_COMPONENT_FIELD_DUE:
case CAL_COMPONENT_FIELD_GEO:
- case CAL_COMPONENT_FIELD_PERCENT:
case CAL_COMPONENT_FIELD_PRIORITY:
case CAL_COMPONENT_FIELD_SUMMARY:
case CAL_COMPONENT_FIELD_TRANSPARENCY:
@@ -1502,9 +1445,16 @@ calendar_model_duplicate_value (ETableModel *etm, int col, const void *value)
case CAL_COMPONENT_FIELD_STATUS:
return dup_string (value);
+ case CAL_COMPONENT_FIELD_COMPLETED:
+ case CAL_COMPONENT_FIELD_DTEND:
+ case CAL_COMPONENT_FIELD_DTSTART:
+ case CAL_COMPONENT_FIELD_DUE:
+ return dup_date_edit_value (value);
+
case CAL_COMPONENT_FIELD_HAS_ALARMS:
case CAL_COMPONENT_FIELD_ICON:
case CAL_COMPONENT_FIELD_COMPLETE:
+ case CAL_COMPONENT_FIELD_PERCENT:
case CAL_COMPONENT_FIELD_RECURRING:
case CAL_COMPONENT_FIELD_OVERDUE:
case CAL_COMPONENT_FIELD_COLOR:
@@ -1544,7 +1494,6 @@ calendar_model_free_value (ETableModel *etm, int col, void *value)
case CAL_COMPONENT_FIELD_DTSTART:
case CAL_COMPONENT_FIELD_DUE:
case CAL_COMPONENT_FIELD_GEO:
- case CAL_COMPONENT_FIELD_PERCENT:
case CAL_COMPONENT_FIELD_PRIORITY:
case CAL_COMPONENT_FIELD_SUMMARY:
case CAL_COMPONENT_FIELD_STATUS:
@@ -1560,6 +1509,7 @@ calendar_model_free_value (ETableModel *etm, int col, void *value)
g_free (value);
break;
+ case CAL_COMPONENT_FIELD_PERCENT:
case CAL_COMPONENT_FIELD_HAS_ALARMS:
case CAL_COMPONENT_FIELD_ICON:
case CAL_COMPONENT_FIELD_COMPLETE:
@@ -1600,12 +1550,7 @@ calendar_model_initialize_value (ETableModel *etm, int col)
return g_strdup (model->priv->default_category ? model->priv->default_category : "");
case CAL_COMPONENT_FIELD_CLASSIFICATION:
- case CAL_COMPONENT_FIELD_COMPLETED:
- case CAL_COMPONENT_FIELD_DTEND:
- case CAL_COMPONENT_FIELD_DTSTART:
- case CAL_COMPONENT_FIELD_DUE:
case CAL_COMPONENT_FIELD_GEO:
- case CAL_COMPONENT_FIELD_PERCENT:
case CAL_COMPONENT_FIELD_PRIORITY:
case CAL_COMPONENT_FIELD_SUMMARY:
case CAL_COMPONENT_FIELD_TRANSPARENCY:
@@ -1613,6 +1558,10 @@ calendar_model_initialize_value (ETableModel *etm, int col)
case CAL_COMPONENT_FIELD_STATUS:
return init_string ();
+ case CAL_COMPONENT_FIELD_COMPLETED:
+ case CAL_COMPONENT_FIELD_DTEND:
+ case CAL_COMPONENT_FIELD_DTSTART:
+ case CAL_COMPONENT_FIELD_DUE:
case CAL_COMPONENT_FIELD_HAS_ALARMS:
case CAL_COMPONENT_FIELD_ICON:
case CAL_COMPONENT_FIELD_COMPLETE:
@@ -1622,6 +1571,9 @@ calendar_model_initialize_value (ETableModel *etm, int col)
case CAL_COMPONENT_FIELD_COMPONENT:
return NULL;
+ case CAL_COMPONENT_FIELD_PERCENT:
+ return GINT_TO_POINTER (-1);
+
default:
g_message ("calendar_model_initialize_value(): Requested invalid column %d", col);
return NULL;
@@ -1657,12 +1609,7 @@ calendar_model_value_is_empty (ETableModel *etm, int col, const void *value)
return string_is_empty (value);
case CAL_COMPONENT_FIELD_CLASSIFICATION: /* actually goes here, not by itself */
- case CAL_COMPONENT_FIELD_COMPLETED:
- case CAL_COMPONENT_FIELD_DTEND:
- case CAL_COMPONENT_FIELD_DTSTART:
- case CAL_COMPONENT_FIELD_DUE:
case CAL_COMPONENT_FIELD_GEO:
- case CAL_COMPONENT_FIELD_PERCENT:
case CAL_COMPONENT_FIELD_PRIORITY:
case CAL_COMPONENT_FIELD_SUMMARY:
case CAL_COMPONENT_FIELD_TRANSPARENCY:
@@ -1670,6 +1617,15 @@ calendar_model_value_is_empty (ETableModel *etm, int col, const void *value)
case CAL_COMPONENT_FIELD_STATUS:
return string_is_empty (value);
+ case CAL_COMPONENT_FIELD_COMPLETED:
+ case CAL_COMPONENT_FIELD_DTEND:
+ case CAL_COMPONENT_FIELD_DTSTART:
+ case CAL_COMPONENT_FIELD_DUE:
+ return value ? FALSE : TRUE;
+
+ case CAL_COMPONENT_FIELD_PERCENT:
+ return (GPOINTER_TO_INT (value) < 0) ? TRUE : FALSE;
+
case CAL_COMPONENT_FIELD_HAS_ALARMS:
case CAL_COMPONENT_FIELD_ICON:
case CAL_COMPONENT_FIELD_COMPLETE:
@@ -1685,6 +1641,43 @@ calendar_model_value_is_empty (ETableModel *etm, int col, const void *value)
}
}
+static char*
+date_value_to_string (ETableModel *etm, const void *value)
+{
+ CalendarModel *model;
+ CalendarModelPrivate *priv;
+ ECellDateEditValue *dv = (ECellDateEditValue *) value;
+ struct icaltimetype tt;
+ struct tm tmp_tm;
+ char buffer[64];
+
+ model = CALENDAR_MODEL (etm);
+ priv = model->priv;
+
+ if (!dv)
+ return g_strdup ("");
+
+ /* We currently convert all the dates to the current timezone. */
+ tt = dv->tt;
+ icaltimezone_convert_time (&tt, dv->zone, priv->zone);
+
+ tmp_tm.tm_year = tt.year - 1900;
+ tmp_tm.tm_mon = tt.month - 1;
+ tmp_tm.tm_mday = tt.day;
+ tmp_tm.tm_hour = tt.hour;
+ tmp_tm.tm_min = tt.minute;
+ tmp_tm.tm_sec = tt.second;
+ tmp_tm.tm_isdst = -1;
+
+ tmp_tm.tm_wday = time_day_of_week (tt.day, tt.month - 1, tt.year);
+
+ e_time_format_date_and_time (&tmp_tm, priv->use_24_hour_format,
+ TRUE, FALSE,
+ buffer, sizeof (buffer));
+ return g_strdup (buffer);
+}
+
+
static char *
calendar_model_value_to_string (ETableModel *etm, int col, const void *value)
{
@@ -1693,12 +1686,7 @@ calendar_model_value_to_string (ETableModel *etm, int col, const void *value)
switch (col) {
case CAL_COMPONENT_FIELD_CATEGORIES:
case CAL_COMPONENT_FIELD_CLASSIFICATION:
- case CAL_COMPONENT_FIELD_COMPLETED:
- case CAL_COMPONENT_FIELD_DTEND:
- case CAL_COMPONENT_FIELD_DTSTART:
- case CAL_COMPONENT_FIELD_DUE:
case CAL_COMPONENT_FIELD_GEO:
- case CAL_COMPONENT_FIELD_PERCENT:
case CAL_COMPONENT_FIELD_PRIORITY:
case CAL_COMPONENT_FIELD_SUMMARY:
case CAL_COMPONENT_FIELD_TRANSPARENCY:
@@ -1706,10 +1694,16 @@ calendar_model_value_to_string (ETableModel *etm, int col, const void *value)
case CAL_COMPONENT_FIELD_STATUS:
return e_utf8_from_locale_string (value);
+ case CAL_COMPONENT_FIELD_COMPLETED:
+ case CAL_COMPONENT_FIELD_DTEND:
+ case CAL_COMPONENT_FIELD_DTSTART:
+ case CAL_COMPONENT_FIELD_DUE:
+ return date_value_to_string (etm, value);
+
case CAL_COMPONENT_FIELD_ICON:
- if ((int)value == 0)
+ if (GPOINTER_TO_INT (value) == 0)
return e_utf8_from_locale_string (_("Normal"));
- else if ((int)value == 1)
+ else if (GPOINTER_TO_INT (value) == 1)
return e_utf8_from_locale_string (_("Recurring"));
else
return e_utf8_from_locale_string (_("Assigned"));
@@ -1726,6 +1720,12 @@ calendar_model_value_to_string (ETableModel *etm, int col, const void *value)
case CAL_COMPONENT_FIELD_COMPONENT:
return NULL;
+ case CAL_COMPONENT_FIELD_PERCENT:
+ if (GPOINTER_TO_INT (value) < 0)
+ return NULL;
+ else
+ return g_strdup_printf ("%i%%", GPOINTER_TO_INT (value));
+
default:
g_message ("calendar_model_value_as_string(): Requested invalid column %d", col);
return NULL;
@@ -1762,6 +1762,7 @@ query_obj_updated_cb (CalQuery *query, const char *uid,
const char *new_comp_uid;
int *new_idx;
CalClientGetStatus status;
+ CalendarModelObjectData new_object_data = { NULL, NULL, NULL, NULL };
model = CALENDAR_MODEL (data);
priv = model->priv;
@@ -1780,6 +1781,7 @@ query_obj_updated_cb (CalQuery *query, const char *uid,
/* The object not in the model originally, so we just append it */
g_array_append_val (priv->objects, new_comp);
+ g_array_append_val (priv->objects_data, new_object_data);
new_idx = g_new (int, 1);
*new_idx = priv->objects->len - 1;
@@ -1792,6 +1794,8 @@ query_obj_updated_cb (CalQuery *query, const char *uid,
/* Insert the new version of the object in its old position */
g_array_insert_val (priv->objects, orig_idx, new_comp);
+ g_array_insert_val (priv->objects_data, orig_idx,
+ new_object_data);
new_idx = g_new (int, 1);
*new_idx = orig_idx;
@@ -2053,6 +2057,7 @@ remove_object (CalendarModel *model, const char *uid)
CalComponent *orig_comp;
int i;
int n;
+ CalendarModelObjectData *object_data;
priv = model->priv;
@@ -2089,6 +2094,11 @@ remove_object (CalendarModel *model, const char *uid)
g_hash_table_remove (priv->uid_index_hash, uid);
g_array_remove_index (priv->objects, *idx);
+ object_data = &g_array_index (priv->objects_data,
+ CalendarModelObjectData, *idx);
+ calendar_model_free_object_data (model, object_data);
+ g_array_remove_index (priv->objects_data, *idx);
+
gtk_object_unref (GTK_OBJECT (orig_comp));
n = *idx;