aboutsummaryrefslogtreecommitdiffstats
path: root/calendar/gui
diff options
context:
space:
mode:
authorRodrigo Moya <rodrigo@src.gnome.org>2003-08-09 17:01:35 +0800
committerRodrigo Moya <rodrigo@src.gnome.org>2003-08-09 17:01:35 +0800
commit8f65ff7000f89f936e46007d0db78c0aa602f0b8 (patch)
tree447afd042dd278f088acc87f38503b3f4a17c0c6 /calendar/gui
parentd0ce2a3d39fbb2386a75fc4b55768fa7d708691e (diff)
downloadgsoc2013-evolution-8f65ff7000f89f936e46007d0db78c0aa602f0b8.tar
gsoc2013-evolution-8f65ff7000f89f936e46007d0db78c0aa602f0b8.tar.gz
gsoc2013-evolution-8f65ff7000f89f936e46007d0db78c0aa602f0b8.tar.bz2
gsoc2013-evolution-8f65ff7000f89f936e46007d0db78c0aa602f0b8.tar.lz
gsoc2013-evolution-8f65ff7000f89f936e46007d0db78c0aa602f0b8.tar.xz
gsoc2013-evolution-8f65ff7000f89f936e46007d0db78c0aa602f0b8.tar.zst
gsoc2013-evolution-8f65ff7000f89f936e46007d0db78c0aa602f0b8.zip
Merged missing bits from branch
svn path=/trunk/; revision=22152
Diffstat (limited to 'calendar/gui')
-rw-r--r--calendar/gui/e-cal-model-calendar.c36
-rw-r--r--calendar/gui/e-cal-model-calendar.h2
-rw-r--r--calendar/gui/e-cal-model-tasks.c161
-rw-r--r--calendar/gui/e-cal-model-tasks.h4
-rw-r--r--calendar/gui/e-cal-model.c239
-rw-r--r--calendar/gui/e-cal-model.h10
6 files changed, 380 insertions, 72 deletions
diff --git a/calendar/gui/e-cal-model-calendar.c b/calendar/gui/e-cal-model-calendar.c
index 246d1c5ca8..73ecaf3e94 100644
--- a/calendar/gui/e-cal-model-calendar.c
+++ b/calendar/gui/e-cal-model-calendar.c
@@ -37,13 +37,15 @@ static int ecmc_column_count (ETableModel *etm);
static void *ecmc_value_at (ETableModel *etm, int col, int row);
static void ecmc_set_value_at (ETableModel *etm, int col, int row, const void *value);
static gboolean ecmc_is_cell_editable (ETableModel *etm, int col, int row);
-static void ecmc_append_row (ETableModel *etm, ETableModel *source, int row);
static void *ecmc_duplicate_value (ETableModel *etm, int col, const void *value);
static void ecmc_free_value (ETableModel *etm, int col, void *value);
static void *ecmc_initialize_value (ETableModel *etm, int col);
static gboolean ecmc_value_is_empty (ETableModel *etm, int col, const void *value);
static char *ecmc_value_to_string (ETableModel *etm, int col, const void *value);
+static void ecmc_fill_component_from_model (ECalModel *model, ECalModelComponent *comp_data,
+ ECalModel *source_model, gint row);
+
static GObjectClass *parent_class = NULL;
E_MAKE_TYPE (e_cal_model_calendar, "ECalModelCalendar", ECalModelCalendar, ecmc_class_init,
@@ -54,6 +56,7 @@ ecmc_class_init (ECalModelCalendarClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
ETableModelClass *etm_class = E_TABLE_MODEL_CLASS (klass);
+ ECalModelClass *model_class = E_CAL_MODEL_CLASS (klass);
parent_class = g_type_class_peek_parent (klass);
@@ -63,12 +66,13 @@ ecmc_class_init (ECalModelCalendarClass *klass)
etm_class->value_at = ecmc_value_at;
etm_class->set_value_at = ecmc_set_value_at;
etm_class->is_cell_editable = ecmc_is_cell_editable;
- etm_class->append_row = ecmc_append_row;
etm_class->duplicate_value = ecmc_duplicate_value;
etm_class->free_value = ecmc_free_value;
etm_class->initialize_value = ecmc_initialize_value;
etm_class->value_is_empty = ecmc_value_is_empty;
etm_class->value_to_string = ecmc_value_to_string;
+
+ model_class->fill_component_from_model = ecmc_fill_component_from_model;
}
static void
@@ -330,16 +334,6 @@ ecmc_is_cell_editable (ETableModel *etm, int col, int row)
return FALSE;
}
-static void
-ecmc_append_row (ETableModel *etm, ETableModel *source, gint row)
-{
- ECalModelCalendar *model = (ECalModelCalendar *) etm;
-
- g_return_if_fail (E_IS_CAL_MODEL_CALENDAR (model));
-
- /* FIXME: how to chain to ecm_append_row? */
-}
-
static void *
ecmc_duplicate_value (ETableModel *etm, int col, const void *value)
{
@@ -437,6 +431,24 @@ ecmc_value_to_string (ETableModel *etm, int col, const void *value)
return NULL;
}
+/* ECalModel class methods */
+
+static void
+ecmc_fill_component_from_model (ECalModel *model, ECalModelComponent *comp_data,
+ ECalModel *source_model, gint row)
+{
+ g_return_if_fail (E_IS_CAL_MODEL_CALENDAR (model));
+ g_return_if_fail (comp_data != NULL);
+ g_return_if_fail (E_IS_CAL_MODEL_CALENDAR (source_model));
+
+ set_dtend (comp_data,
+ e_table_model_value_at (E_TABLE_MODEL (source_model), E_CAL_MODEL_CALENDAR_FIELD_DTEND, row));
+ set_location (comp_data,
+ e_table_model_value_at (E_TABLE_MODEL (source_model), E_CAL_MODEL_CALENDAR_FIELD_LOCATION, row));
+ set_transparency (comp_data,
+ e_table_model_value_at (E_TABLE_MODEL (source_model), E_CAL_MODEL_CALENDAR_FIELD_TRANSPARENCY, row));
+}
+
/**
* e_cal_model_calendar_new
*/
diff --git a/calendar/gui/e-cal-model-calendar.h b/calendar/gui/e-cal-model-calendar.h
index 6ddf312a27..450871c88f 100644
--- a/calendar/gui/e-cal-model-calendar.h
+++ b/calendar/gui/e-cal-model-calendar.h
@@ -35,6 +35,8 @@ G_BEGIN_DECLS
typedef struct _ECalModelCalendarPrivate ECalModelCalendarPrivate;
typedef enum {
+ /* If you add new items here or reorder them, you have to update the
+ .etspec files for the tables using this model */
E_CAL_MODEL_CALENDAR_FIELD_DTEND = E_CAL_MODEL_FIELD_LAST,
E_CAL_MODEL_CALENDAR_FIELD_LOCATION,
E_CAL_MODEL_CALENDAR_FIELD_TRANSPARENCY,
diff --git a/calendar/gui/e-cal-model-tasks.c b/calendar/gui/e-cal-model-tasks.c
index 7c97f5ba01..7e00aca84d 100644
--- a/calendar/gui/e-cal-model-tasks.c
+++ b/calendar/gui/e-cal-model-tasks.c
@@ -24,6 +24,7 @@
#include <gtk/gtkmessagedialog.h>
#include <libgnome/gnome-i18n.h>
#include <gal/util/e-util.h>
+#include "calendar-config.h"
#include "e-cal-model-tasks.h"
#include "e-cell-date-edit-text.h"
#include "misc.h"
@@ -39,13 +40,15 @@ static int ecmt_column_count (ETableModel *etm);
static void *ecmt_value_at (ETableModel *etm, int col, int row);
static void ecmt_set_value_at (ETableModel *etm, int col, int row, const void *value);
static gboolean ecmt_is_cell_editable (ETableModel *etm, int col, int row);
-static void ecmt_append_row (ETableModel *etm, ETableModel *source, int row);
static void *ecmt_duplicate_value (ETableModel *etm, int col, const void *value);
static void ecmt_free_value (ETableModel *etm, int col, void *value);
static void *ecmt_initialize_value (ETableModel *etm, int col);
static gboolean ecmt_value_is_empty (ETableModel *etm, int col, const void *value);
static char *ecmt_value_to_string (ETableModel *etm, int col, const void *value);
+
static const char *ecmt_get_color_for_component (ECalModel *model, ECalModelComponent *comp_data);
+static void ecmt_fill_component_from_model (ECalModel *model, ECalModelComponent *comp_data,
+ ECalModel *source_model, gint row);
static GObjectClass *parent_class = NULL;
@@ -57,6 +60,7 @@ ecmt_class_init (ECalModelTasksClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
ETableModelClass *etm_class = E_TABLE_MODEL_CLASS (klass);
+ ECalModelClass *model_class = E_CAL_MODEL_CLASS (klass);
parent_class = g_type_class_peek_parent (klass);
@@ -66,12 +70,14 @@ ecmt_class_init (ECalModelTasksClass *klass)
etm_class->value_at = ecmt_value_at;
etm_class->set_value_at = ecmt_set_value_at;
etm_class->is_cell_editable = ecmt_is_cell_editable;
- etm_class->append_row = ecmt_append_row;
etm_class->duplicate_value = ecmt_duplicate_value;
etm_class->free_value = ecmt_free_value;
etm_class->initialize_value = ecmt_initialize_value;
etm_class->value_is_empty = ecmt_value_is_empty;
etm_class->value_to_string = ecmt_value_to_string;
+
+ model_class->get_color_for_component = ecmt_get_color_for_component;
+ model_class->fill_component_from_model = ecmt_fill_component_from_model;
}
static void
@@ -197,9 +203,61 @@ ensure_task_not_complete (ECalModelComponent *comp_data)
static ECellDateEditValue *
get_completed (ECalModelComponent *comp_data)
{
- /* FIXME */
+ struct icaltimetype tt_completed;
- return NULL;
+ if (!comp_data->completed) {
+ icaltimezone *zone;
+ icalproperty *prop;
+
+ prop = icalcomponent_get_first_property (comp_data->icalcomp, ICAL_COMPLETED_PROPERTY);
+ if (!prop)
+ return NULL;
+
+ tt_completed = icalproperty_get_completed (prop);
+ if (!icaltime_is_valid_time (tt_completed))
+ return NULL;
+
+ comp_data->completed = g_new0 (ECellDateEditValue, 1);
+ comp_data->completed->tt = tt_completed;
+
+ /* FIXME: handle errors */
+ cal_client_get_timezone (comp_data->client,
+ icaltimezone_get_tzid (icaltimezone_get_builtin_timezone (tt_completed.zone)),
+ &zone);
+ comp_data->completed->zone = zone;
+ }
+
+ return comp_data->completed;
+}
+
+static ECellDateEditValue *
+get_due (ECalModelComponent *comp_data)
+{
+ struct icaltimetype tt_due;
+
+ if (!comp_data->due) {
+ icaltimezone *zone;
+ icalproperty *prop;
+
+ prop = icalcomponent_get_first_property (comp_data->icalcomp, ICAL_DUE_PROPERTY);
+ if (!prop)
+ return NULL;
+
+ tt_due = icalproperty_get_due (prop);
+ if (!icaltime_is_valid_time (tt_due))
+ return NULL;
+
+ comp_data->due = g_new0 (ECellDateEditValue, 1);
+ comp_data->due->tt = tt_due;
+
+ /* FIXME: handle errors */
+ cal_client_get_timezone (comp_data->client,
+ icaltimezone_get_tzid (icaltimezone_get_builtin_timezone (tt_due.zone)),
+ &zone);
+ comp_data->due->zone = zone;
+ }
+
+ return comp_data->due;
}
static char *
@@ -403,8 +461,7 @@ ecmt_value_at (ETableModel *etm, int col, int row)
case E_CAL_MODEL_TASKS_FIELD_COMPLETE :
return GINT_TO_POINTER (is_complete (comp_data));
case E_CAL_MODEL_TASKS_FIELD_DUE :
- /* FIXME */
- break;
+ return get_due (comp_data);
case E_CAL_MODEL_TASKS_FIELD_GEO :
return get_geo (comp_data);
case E_CAL_MODEL_TASKS_FIELD_OVERDUE :
@@ -458,6 +515,29 @@ set_complete (ECalModelComponent *comp_data, const void *value)
ensure_task_not_complete (comp_data);
}
+static void
+set_due (ECalModelComponent *comp_data, const void *value)
+{
+ icalproperty *prop;
+ ECellDateEditValue *dv = (ECellDateEditValue *) value;
+
+ prop = icalcomponent_get_first_property (comp_data->icalcomp, ICAL_DUE_PROPERTY);
+
+ if (!dv) {
+ if (prop) {
+ icalcomponent_remove_property (comp_data->icalcomp, prop);
+ icalproperty_free (prop);
+ }
+ } else {
+ if (prop)
+ icalproperty_set_due (prop, dv->tt);
+ else {
+ prop = icalproperty_new_due (dv->tt);
+ icalcomponent_add_property (comp_data->icalcomp, prop);
+ }
+ }
+}
+
/* FIXME: We need to set the "transient_for" property for the dialog, but the
* model doesn't know anything about the windows.
*/
@@ -660,7 +740,7 @@ ecmt_set_value_at (ETableModel *etm, int col, int row, const void *value)
set_complete (comp_data, value);
break;
case E_CAL_MODEL_TASKS_FIELD_DUE :
- /* FIXME */
+ set_due (comp_data, value);
break;
case E_CAL_MODEL_TASKS_FIELD_GEO :
set_geo (comp_data, value);
@@ -712,19 +792,6 @@ ecmt_is_cell_editable (ETableModel *etm, int col, int row)
return FALSE;
}
-static void
-ecmt_append_row (ETableModel *etm, ETableModel *source, gint row)
-{
- ECalModelTasksPrivate *priv;
- ECalModelTasks *model = (ECalModelTasks *) etm;
-
- g_return_if_fail (E_IS_CAL_MODEL_TASKS (model));
-
- priv = model->priv;
-
- /* FIXME: how to chain to ecm_append_row? */
-}
-
static void *
ecmt_duplicate_value (ETableModel *etm, int col, const void *value)
{
@@ -874,6 +941,8 @@ ecmt_value_to_string (ETableModel *etm, int col, const void *value)
return NULL;
}
+/* ECalModel class methods */
+
static const char *
ecmt_get_color_for_component (ECalModel *model, ECalModelComponent *comp_data)
{
@@ -881,17 +950,40 @@ ecmt_get_color_for_component (ECalModel *model, ECalModelComponent *comp_data)
g_return_val_if_fail (comp_data != NULL, NULL);
switch (get_due_status ((ECalModelTasks *) model, comp_data)) {
- case E_CAL_MODEL_TASKS_DUE_NEVER:
- case E_CAL_MODEL_TASKS_DUE_FUTURE:
- case E_CAL_MODEL_TASKS_DUE_COMPLETE:
- return NULL;
case E_CAL_MODEL_TASKS_DUE_TODAY:
return calendar_config_get_tasks_due_today_color ();
case E_CAL_MODEL_TASKS_DUE_OVERDUE:
return calendar_config_get_tasks_overdue_color ();
+ case E_CAL_MODEL_TASKS_DUE_NEVER:
+ case E_CAL_MODEL_TASKS_DUE_FUTURE:
+ case E_CAL_MODEL_TASKS_DUE_COMPLETE:
}
- return NULL;
+ return E_CAL_MODEL_CLASS (parent_class)->get_color_for_component (model, comp_data);
+}
+
+static void
+ecmt_fill_component_from_model (ECalModel *model, ECalModelComponent *comp_data,
+ ECalModel *source_model, gint row)
+{
+ g_return_if_fail (E_IS_CAL_MODEL_TASKS (model));
+ g_return_if_fail (comp_data != NULL);
+ g_return_if_fail (E_IS_CAL_MODEL_TASKS (source_model));
+
+ set_completed ((ECalModelTasks *) model, comp_data,
+ e_table_model_value_at (E_TABLE_MODEL (source_model), E_CAL_MODEL_TASKS_FIELD_COMPLETED, row));
+ set_due (comp_data,
+ e_table_model_value_at (E_TABLE_MODEL (source_model), E_CAL_MODEL_TASKS_FIELD_DUE, row));
+ set_geo (comp_data,
+ e_table_model_value_at (E_TABLE_MODEL (source_model), E_CAL_MODEL_TASKS_FIELD_GEO, row));
+ set_percent (comp_data,
+ e_table_model_value_at (E_TABLE_MODEL (source_model), E_CAL_MODEL_TASKS_FIELD_PERCENT, row));
+ set_priority (comp_data,
+ e_table_model_value_at (E_TABLE_MODEL (source_model), E_CAL_MODEL_TASKS_FIELD_PRIORITY, row));
+ set_status (comp_data,
+ e_table_model_value_at (E_TABLE_MODEL (source_model), E_CAL_MODEL_TASKS_FIELD_STATUS, row));
+ set_url (comp_data,
+ e_table_model_value_at (E_TABLE_MODEL (source_model), E_CAL_MODEL_TASKS_FIELD_URL, row));
}
/**
@@ -902,3 +994,22 @@ e_cal_model_tasks_new (void)
{
return g_object_new (E_TYPE_CAL_MODEL_TASKS, NULL);
}
+
+/**
+ * e_cal_model_tasks_mark_task_complete
+ */
+void
+e_cal_model_tasks_mark_task_complete (ECalModelTasks *model, gint model_row)
+{
+ ECalModelTasksPrivate *priv;
+ ECalModelComponent *comp_data;
+
+ g_return_if_fail (E_IS_CAL_MODEL_TASKS (model));
+ g_return_if_fail (model_row >= 0 && model_row < e_table_model_row_count (E_TABLE_MODEL (model)));
+
+ priv = model->priv;
+
+ comp_data = e_cal_model_get_component_at (E_CAL_MODEL (model), model_row);
+ if (comp_data)
+ ensure_task_complete (comp_data, -1);
+}
diff --git a/calendar/gui/e-cal-model-tasks.h b/calendar/gui/e-cal-model-tasks.h
index 852484dcc6..b7c5786ab4 100644
--- a/calendar/gui/e-cal-model-tasks.h
+++ b/calendar/gui/e-cal-model-tasks.h
@@ -35,6 +35,8 @@ G_BEGIN_DECLS
typedef struct _ECalModelTasksPrivate ECalModelTasksPrivate;
typedef enum {
+ /* If you add new items here or reorder them, you have to update the
+ .etspec files for the tables using this model */
E_CAL_MODEL_TASKS_FIELD_COMPLETED = E_CAL_MODEL_FIELD_LAST,
E_CAL_MODEL_TASKS_FIELD_COMPLETE,
E_CAL_MODEL_TASKS_FIELD_DUE,
@@ -59,6 +61,8 @@ typedef struct {
GType e_cal_model_tasks_get_type (void);
ECalModelTasks *e_cal_model_tasks_new (void);
+void e_cal_model_tasks_mark_task_complete (ECalModelTasks *model, gint model_row);
+
G_END_DECLS
#endif
diff --git a/calendar/gui/e-cal-model.c b/calendar/gui/e-cal-model.c
index a184fabe48..92f5649270 100644
--- a/calendar/gui/e-cal-model.c
+++ b/calendar/gui/e-cal-model.c
@@ -23,9 +23,11 @@
#include <glib/garray.h>
#include <libgnome/gnome-i18n.h>
#include <gal/util/e-util.h>
+#include <e-util/e-config-listener.h>
#include <e-util/e-time-utils.h>
#include <cal-util/timeutil.h>
#include "calendar-config.h"
+#include "comp-util.h"
#include "e-cal-model.h"
#include "itip-utils.h"
#include "misc.h"
@@ -53,6 +55,9 @@ struct _ECalModelPrivate {
/* Addresses for determining icons */
EAccountList *accounts;
+
+ /* Whether we display dates in 24-hour format. */
+ gboolean use_24_hour_format;
};
static void e_cal_model_class_init (ECalModelClass *klass);
@@ -101,6 +106,7 @@ e_cal_model_class_init (ECalModelClass *klass)
etm_class->value_to_string = ecm_value_to_string;
klass->get_color_for_component = ecm_get_color_for_component;
+ klass->fill_component_from_model = NULL;
}
static void
@@ -117,6 +123,8 @@ e_cal_model_init (ECalModel *model, ECalModelClass *klass)
priv->kind = ICAL_NO_COMPONENT;
priv->accounts = itip_addresses_get ();
+
+ priv->use_24_hour_format = TRUE;
}
static void
@@ -141,6 +149,16 @@ free_comp_data (ECalModelComponent *comp_data)
comp_data->dtend = NULL;
}
+ if (comp_data->due) {
+ g_free (comp_data->due);
+ comp_data->due = NULL;
+ }
+
+ if (comp_data->completed) {
+ g_free (comp_data->completed);
+ comp_data->completed = NULL;
+ }
+
g_free (comp_data);
}
@@ -172,7 +190,20 @@ e_cal_model_finalize (GObject *object)
priv = model->priv;
if (priv) {
if (priv->clients) {
- e_cal_model_remove_all_clients (model);
+ while (priv->clients != NULL) {
+ ECalModelClient *client_data = (ECalModelClient *) priv->clients->data;
+
+ g_signal_handlers_disconnect_matched (client_data->client, G_SIGNAL_MATCH_DATA,
+ 0, 0, NULL, NULL, model);
+ g_signal_handlers_disconnect_matched (client_data->query, G_SIGNAL_MATCH_DATA,
+ 0, 0, NULL, NULL, model);
+
+ priv->clients = g_list_remove (priv->clients, client_data);
+ g_object_unref (client_data->client);
+ g_object_unref (client_data->query);
+ g_free (client_data);
+ }
+
priv->clients = NULL;
}
@@ -291,8 +322,13 @@ get_dtstart (ECalModel *model, ECalModelComponent *comp_data)
if (!comp_data->dtstart) {
icaltimezone *zone;
+ icalproperty *prop;
- tt_start = icalcomponent_get_dtstart (comp_data->icalcomp);
+ prop = icalcomponent_get_first_property (comp_data->icalcomp, ICAL_DTSTART_PROPERTY);
+ if (!prop)
+ return NULL;
+
+ tt_start = icalproperty_get_dtstart (prop);
if (!icaltime_is_valid_time (tt_start))
return NULL;
@@ -350,13 +386,13 @@ ecm_value_at (ETableModel *etm, int col, int row)
case E_CAL_MODEL_FIELD_CLASSIFICATION :
return get_classification (comp_data);
case E_CAL_MODEL_FIELD_COLOR :
- return GINT_TO_POINTER (get_color (model, comp_data));
+ return (void *) get_color (model, comp_data);
case E_CAL_MODEL_FIELD_COMPONENT :
return comp_data->icalcomp;
case E_CAL_MODEL_FIELD_DESCRIPTION :
return get_description (comp_data);
case E_CAL_MODEL_FIELD_DTSTART :
- return get_dtstart (model, comp_data);
+ return (void *) get_dtstart (model, comp_data);
case E_CAL_MODEL_FIELD_HAS_ALARMS :
return GINT_TO_POINTER ((icalcomponent_get_first_component (comp_data->icalcomp,
ICAL_VALARM_COMPONENT) != NULL));
@@ -410,58 +446,58 @@ ecm_value_at (ETableModel *etm, int col, int row)
}
static void
-set_categories (icalcomponent *icalcomp, const char *value)
+set_categories (ECalModelComponent *comp_data, const char *value)
{
icalproperty *prop;
- prop = icalcomponent_get_first_property (icalcomp, ICAL_CATEGORIES_PROPERTY);
+ prop = icalcomponent_get_first_property (comp_data->icalcomp, ICAL_CATEGORIES_PROPERTY);
if (!value || !(*value)) {
if (prop) {
- icalcomponent_remove_property (icalcomp, prop);
+ icalcomponent_remove_property (comp_data->icalcomp, prop);
icalproperty_free (prop);
}
} else {
if (!prop) {
prop = icalproperty_new_categories (value);
- icalcomponent_add_property (icalcomp, prop);
+ icalcomponent_add_property (comp_data->icalcomp, prop);
} else
icalproperty_set_categories (prop, value);
}
}
static void
-set_classification (icalcomponent *icalcomp, const char *value)
+set_classification (ECalModelComponent *comp_data, const char *value)
{
icalproperty *prop;
- prop = icalcomponent_get_first_property (icalcomp, ICAL_CLASS_PROPERTY);
+ prop = icalcomponent_get_first_property (comp_data->icalcomp, ICAL_CLASS_PROPERTY);
if (!value || !(*value)) {
if (prop) {
- icalcomponent_remove_property (icalcomp, prop);
+ icalcomponent_remove_property (comp_data->icalcomp, prop);
icalproperty_free (prop);
}
} else {
if (!prop) {
prop = icalproperty_new_class (value);
- icalcomponent_add_property (icalcomp, prop);
+ icalcomponent_add_property (comp_data->icalcomp, prop);
} else
icalproperty_set_class (prop, value);
}
}
static void
-set_description (icalcomponent *icalcomp, const char *value)
+set_description (ECalModelComponent *comp_data, const char *value)
{
icalproperty *prop;
/* remove old description(s) */
- prop = icalcomponent_get_first_property (icalcomp, ICAL_DESCRIPTION_PROPERTY);
+ prop = icalcomponent_get_first_property (comp_data->icalcomp, ICAL_DESCRIPTION_PROPERTY);
while (prop) {
icalproperty *next;
- next = icalcomponent_get_next_property (icalcomp, ICAL_DESCRIPTION_PROPERTY);
+ next = icalcomponent_get_next_property (comp_data->icalcomp, ICAL_DESCRIPTION_PROPERTY);
- icalcomponent_remove_property (icalcomp, prop);
+ icalcomponent_remove_property (comp_data->icalcomp, prop);
icalproperty_free (prop);
prop = next;
@@ -472,7 +508,7 @@ set_description (icalcomponent *icalcomp, const char *value)
return;
prop = icalproperty_new_description (value);
- icalcomponent_add_property (icalcomp, prop);
+ icalcomponent_add_property (comp_data->icalcomp, prop);
}
static void
@@ -492,9 +528,25 @@ set_dtstart (ECalModel *model, ECalModelComponent *comp_data, const void *value)
}
static void
-set_summary (icalcomponent *icalcomp, const char *value)
+set_summary (ECalModelComponent *comp_data, const char *value)
{
- icalcomponent_set_summary (icalcomp, value);
+ icalproperty *prop;
+
+ prop = icalcomponent_get_first_property (comp_data->icalcomp, ICAL_SUMMARY_PROPERTY);
+
+ if (string_is_empty (value)) {
+ if (prop) {
+ icalcomponent_remove_property (comp_data->icalcomp, prop);
+ icalproperty_free (prop);
+ }
+ } else {
+ if (prop)
+ icalproperty_set_summary (prop, value);
+ else {
+ prop = icalproperty_new_summary (value);
+ icalcomponent_add_property (comp_data->icalcomp, prop);
+ }
+ }
}
static void
@@ -561,7 +613,8 @@ ecm_is_cell_editable (ETableModel *etm, int col, int row)
static void
ecm_append_row (ETableModel *etm, ETableModel *source, int row)
{
- ECalModelComponent *comp_data;
+ ECalModelClass *model_class;
+ ECalModelComponent comp_data;
icalcomponent *icalcomp;
ECalModel *source_model = (ECalModel *) source;
ECalModel *model = (ECalModel *) etm;
@@ -569,21 +622,29 @@ ecm_append_row (ETableModel *etm, ETableModel *source, int row)
g_return_if_fail (E_IS_CAL_MODEL (model));
g_return_if_fail (E_IS_CAL_MODEL (source_model));
- comp_data = g_ptr_array_index (source_model->priv->objects, row);
- g_assert (comp_data != NULL);
+ memset (&comp_data, 0, sizeof (comp_data));
+ comp_data.client = e_cal_model_get_default_client (model);
/* guard against saving before the calendar is open */
- if (!(comp_data->client && cal_client_get_load_state (comp_data->client) == CAL_CLIENT_LOAD_LOADED))
+ if (!(comp_data.client && cal_client_get_load_state (comp_data.client) == CAL_CLIENT_LOAD_LOADED))
return;
- icalcomp = e_cal_model_create_component_with_defaults (model);
+ comp_data.icalcomp = e_cal_model_create_component_with_defaults (model);
- set_categories (icalcomp, e_table_model_value_at (source, E_CAL_MODEL_FIELD_CATEGORIES, row));
- set_classification (icalcomp, e_table_model_value_at (source, E_CAL_MODEL_FIELD_CLASSIFICATION, row));
- set_description (icalcomp, e_table_model_value_at (source, E_CAL_MODEL_FIELD_DESCRIPTION, row));
- set_summary (icalcomp, e_table_model_value_at (source, E_CAL_MODEL_FIELD_SUMMARY, row));
+ /* set values for our fields */
+ set_categories (&comp_data, e_table_model_value_at (source, E_CAL_MODEL_FIELD_CATEGORIES, row));
+ set_classification (&comp_data, e_table_model_value_at (source, E_CAL_MODEL_FIELD_CLASSIFICATION, row));
+ set_description (&comp_data, e_table_model_value_at (source, E_CAL_MODEL_FIELD_DESCRIPTION, row));
+ set_dtstart (model, &comp_data, e_table_model_value_at (source, E_CAL_MODEL_FIELD_DTSTART, row));
+ set_summary (&comp_data, e_table_model_value_at (source, E_CAL_MODEL_FIELD_SUMMARY, row));
+
+ /* call the class' method for filling the component */
+ model_class = (ECalModelClass *) G_OBJECT_GET_CLASS (model);
+ if (model_class->fill_component_from_model != NULL) {
+ model_class->fill_component_from_model (model, &comp_data, source_model, row);
+ }
- if (cal_client_update_objects (comp_data->client, icalcomp) != CAL_CLIENT_RESULT_SUCCESS) {
+ if (cal_client_update_objects (comp_data.client, icalcomp) != CAL_CLIENT_RESULT_SUCCESS) {
/* FIXME: show error dialog */
}
@@ -696,7 +757,7 @@ ecm_value_is_empty (ETableModel *etm, int col, const void *value)
* contains the default category, then it possibly means that
* the user has not entered anything at all in the click-to-add;
* the category is in the value because we put it there in
- * calendar_model_initialize_value().
+ * ecm_initialize_value().
*/
if (priv->default_category && value && strcmp (priv->default_category, value) == 0)
return TRUE;
@@ -756,7 +817,20 @@ ecm_get_color_for_component (ECalModel *model, ECalModelComponent *comp_data)
ECalModelPrivate *priv;
gint i, pos;
GList *l;
- gchar *colors[] = { "gray", "green", "darkblue" };
+ gchar *colors[] = {
+ "#718DA9", /* 113 141 169 */
+ "#C6E2E2", /* 198 226 226 */
+ "#8DC671", /* 141 198 113 */
+ "#C6E2A9", /* 198 226 169 */
+ "#C6A971", /* 198 169 113 */
+ "#FFE271", /* 255 226 113 */
+ "#E27171", /* 226 113 113 */
+ "#FFA9A9", /* 255 169 169 */
+ "#C68DC6", /* 198 141 198 */
+ "#E2C6E2", /* 226 198 226 */
+ "#D6D684", /* 214 214 132 */
+ "#5B5B84" /* 91 91 132 */
+ };
g_return_val_if_fail (E_IS_CAL_MODEL (model), NULL);
g_return_val_if_fail (comp_data != NULL, NULL);
@@ -834,6 +908,85 @@ e_cal_model_set_timezone (ECalModel *model, icaltimezone *zone)
}
}
+/**
+ * e_cal_model_set_default_category
+ */
+void
+e_cal_model_set_default_category (ECalModel *model, const gchar *default_cat)
+{
+ g_return_if_fail (E_IS_CAL_MODEL (model));
+
+ if (model->priv->default_category)
+ g_free (model->priv->default_category);
+
+ model->priv->default_category = g_strdup (default_cat);
+}
+
+/**
+ * e_cal_model_set_use_24_hour_format
+ */
+void
+e_cal_model_set_use_24_hour_format (ECalModel *model, gboolean use24)
+{
+ g_return_if_fail (E_IS_CAL_MODEL (model));
+
+ if (model->priv->use_24_hour_format != use24) {
+ e_table_model_pre_change (E_TABLE_MODEL (model));
+ model->priv->use_24_hour_format = use24;
+ /* Get the views to redraw themselves. */
+ e_table_model_changed (E_TABLE_MODEL (model));
+ }
+}
+
+/**
+ * e_cal_model_get_default_client
+ */
+CalClient *
+e_cal_model_get_default_client (ECalModel *model)
+{
+ ECalModelPrivate *priv;
+ GList *l;
+ gchar *default_uri = NULL;
+ EConfigListener *db;
+ ECalModelClient *client_data;
+
+ g_return_val_if_fail (E_IS_CAL_MODEL (model), NULL);
+
+ priv = model->priv;
+
+ if (!priv->clients)
+ return NULL;
+
+ db = e_config_listener_new ();
+
+ /* look at the configuration and return the real default calendar if we've got it loaded */
+ if (priv->kind == ICAL_VEVENT_COMPONENT)
+ default_uri = e_config_listener_get_string (db, "/apps/evolution/shell/default_folders/calendar_uri");
+ else if (priv->kind == ICAL_VTODO_COMPONENT)
+ default_uri = e_config_listener_get_string (db, "/apps/evolution/shell/default_folders/tasks_uri");
+
+ g_object_unref (db);
+
+ if (!default_uri) {
+ client_data = (ECalModelClient *) priv->clients->data;
+ return client_data->client;
+ }
+
+ for (l = priv->clients; l != NULL; l = l->next) {
+ client_data = (ECalModelClient *) l->data;
+
+ if (!strcmp (default_uri, cal_client_get_uri (client_data->client))) {
+ g_free (default_uri);
+ return client_data->client;
+ }
+ }
+
+ g_free (default_uri);
+
+ client_data = (ECalModelClient *) priv->clients->data;
+ return client_data->client;
+}
+
static ECalModelComponent *
search_by_uid_and_client (ECalModelPrivate *priv, CalClient *client, const char *uid)
{
@@ -895,6 +1048,23 @@ query_obj_updated_cb (CalQuery *query, const char *uid,
if (comp_data) {
if (comp_data->icalcomp)
icalcomponent_free (comp_data->icalcomp);
+ if (comp_data->dtstart) {
+ g_free (comp_data->dtstart);
+ comp_data->dtstart = NULL;
+ }
+ if (comp_data->dtend) {
+ g_free (comp_data->dtend);
+ comp_data->dtend = NULL;
+ }
+ if (comp_data->due) {
+ g_free (comp_data->due);
+ comp_data->due = NULL;
+ }
+ if (comp_data->completed) {
+ g_free (comp_data->completed);
+ comp_data->completed = NULL;
+ }
+
comp_data->icalcomp = new_icalcomp;
e_table_model_row_changed (E_TABLE_MODEL (model), get_position_in_array (priv->objects, comp_data));
@@ -1060,10 +1230,8 @@ cal_opened_cb (CalClient *client, CalClientOpenStatus status, gpointer user_data
{
ECalModel *model = (ECalModel *) user_data;
- if (status != CAL_CLIENT_OPEN_SUCCESS) {
- e_cal_model_remove_client (model, client);
+ if (status != CAL_CLIENT_OPEN_SUCCESS)
return;
- }
add_new_client (model, client);
}
@@ -1296,7 +1464,8 @@ e_cal_model_date_value_to_string (ECalModel *model, const void *value)
tmp_tm.tm_wday = time_day_of_week (tt.day, tt.month - 1, tt.year);
- e_time_format_date_and_time (&tmp_tm, calendar_config_get_24_hour_format (),
+ memset (buffer, 0, sizeof (buffer));
+ e_time_format_date_and_time (&tmp_tm, priv->use_24_hour_format,
TRUE, FALSE,
buffer, sizeof (buffer));
return g_strdup (buffer);
diff --git a/calendar/gui/e-cal-model.h b/calendar/gui/e-cal-model.h
index 69d9e785ba..bb19ba7329 100644
--- a/calendar/gui/e-cal-model.h
+++ b/calendar/gui/e-cal-model.h
@@ -37,6 +37,8 @@ G_BEGIN_DECLS
typedef struct _ECalModelPrivate ECalModelPrivate;
typedef enum {
+ /* If you add new items here or reorder them, you have to update the
+ .etspec files for the tables using this model */
E_CAL_MODEL_FIELD_CATEGORIES,
E_CAL_MODEL_FIELD_CLASSIFICATION,
E_CAL_MODEL_FIELD_COLOR, /* not a real field */
@@ -57,6 +59,8 @@ typedef struct {
/* private data */
ECellDateEditValue *dtstart;
ECellDateEditValue *dtend;
+ ECellDateEditValue *due;
+ ECellDateEditValue *completed;
} ECalModelComponent;
typedef struct {
@@ -69,6 +73,8 @@ typedef struct {
/* virtual methods */
const gchar * (* get_color_for_component) (ECalModel *model, ECalModelComponent *comp_data);
+ void (* fill_component_from_model) (ECalModel *model, ECalModelComponent *comp_data,
+ ECalModel *source_model, gint row);
} ECalModelClass;
GType e_cal_model_get_type (void);
@@ -78,6 +84,10 @@ void e_cal_model_set_component_kind (ECalModel *model, icalcompon
icaltimezone *e_cal_model_get_timezone (ECalModel *model);
void e_cal_model_set_timezone (ECalModel *model, icaltimezone *zone);
+void e_cal_model_set_default_category (ECalModel *model, const gchar *default_cat);
+void e_cal_model_set_use_24_hour_format (ECalModel *model, gboolean use24);
+
+CalClient *e_cal_model_get_default_client (ECalModel *model);
void e_cal_model_add_client (ECalModel *model, CalClient *client);
void e_cal_model_remove_client (ECalModel *model, CalClient *client);
void e_cal_model_remove_all_clients (ECalModel *model);