aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFederico Mena Quintero <federico@src.gnome.org>2000-06-16 15:07:02 +0800
committerFederico Mena Quintero <federico@src.gnome.org>2000-06-16 15:07:02 +0800
commitef4fb079a43f916fb85c29467dc33da928e51692 (patch)
tree3258e90d996fe0fb953e2acbda101aecb6b0fada
parentd7480fd1c06182203a147559143931606c712759 (diff)
downloadgsoc2013-evolution-ef4fb079a43f916fb85c29467dc33da928e51692.tar.gz
gsoc2013-evolution-ef4fb079a43f916fb85c29467dc33da928e51692.tar.zst
gsoc2013-evolution-ef4fb079a43f916fb85c29467dc33da928e51692.zip
Doh, sync - Federico
svn path=/trunk/; revision=3593
-rw-r--r--calendar/ChangeLog28
-rw-r--r--calendar/cal-client/cal-client.c69
-rw-r--r--calendar/cal-util/calobj.c8
-rw-r--r--calendar/gui/Makefile.am2
-rw-r--r--calendar/gui/calendar-model.c145
-rw-r--r--calendar/gui/calendar-model.h4
-rw-r--r--calendar/pcs/cal-backend-imc.c2
7 files changed, 200 insertions, 58 deletions
diff --git a/calendar/ChangeLog b/calendar/ChangeLog
index 05d6ed68a7..d90d27d693 100644
--- a/calendar/ChangeLog
+++ b/calendar/ChangeLog
@@ -20,6 +20,34 @@
(INCLUDES): include libical src dir so we don't depend on having
ical.h already installed
+2000-06-14 Federico Mena Quintero <federico@helixcode.com>
+
+ * gui/calendar-model.c: GPtrArray cannot insert stuff in the
+ middle of the array (!), so use plain GArray everywhere. Sigh.
+
+2000-06-13 Federico Mena Quintero <federico@helixcode.com>
+
+ * cal-client/cal-client.c (cal_client_get_object): Use vCalendar
+ again.
+
+ * cal-util/calobj.c (ical_object_find_in_string): From Seth, make
+ it use vCalendar again.
+
+2000-06-13 Federico Mena Quintero <federico@helixcode.com>
+
+ * gui/calendar-model.c (obj_updated_cb): Juggle some eggs in
+ asynchronous fashion. Finished implementing.
+ (obj_removed_cb): Implemented. This one needs no juggling.
+ (calendar_model_set_cal_client): Only load the objects if we have
+ a client.
+ (calendar_model_destroy): Disconnect from the client's signals.
+
+ * gui/Makefile.am (evolution_calendar_SOURCES): Added
+ calendar-model.[ch] to the list of sources.
+
+ * pcs/cal-backend-imc.c (cal_backend_imc_get_n_objects): Doh,
+ return the computed value.
+
2000-06-13 Federico Mena Quintero <federico@helixcode.com>
* gui/calendar-model.c (CalendarModelPrivate): Added the array of
diff --git a/calendar/cal-client/cal-client.c b/calendar/cal-client/cal-client.c
index 258a7852e2..007e284b7a 100644
--- a/calendar/cal-client/cal-client.c
+++ b/calendar/cal-client/cal-client.c
@@ -603,37 +603,57 @@ cal_client_get_object (CalClient *client, const char *uid, iCalObject **ico)
{
CalClientPrivate *priv;
CORBA_Environment ev;
- Evolution_Calendar_CalObj calobj;
- char *obj_str = NULL;
+ Evolution_Calendar_CalObj calobj_str;
+ CalClientGetStatus retval;
+ CalObjFindStatus status;
-
- g_return_val_if_fail (client != NULL, CAL_CLIENT_GET_SYNTAX_ERROR);
- g_return_val_if_fail (IS_CAL_CLIENT (client), CAL_CLIENT_GET_SYNTAX_ERROR);
+ g_return_val_if_fail (client != NULL, CAL_CLIENT_GET_NOT_FOUND);
+ g_return_val_if_fail (IS_CAL_CLIENT (client), CAL_CLIENT_GET_NOT_FOUND);
priv = client->priv;
- g_return_val_if_fail (priv->load_state == LOAD_STATE_LOADED, CAL_CLIENT_GET_SYNTAX_ERROR);
+ g_return_val_if_fail (priv->load_state == LOAD_STATE_LOADED, CAL_CLIENT_GET_NOT_FOUND);
- g_return_val_if_fail (uid != NULL, CAL_CLIENT_GET_SYNTAX_ERROR);
+ g_return_val_if_fail (uid != NULL, CAL_CLIENT_GET_NOT_FOUND);
+ g_return_val_if_fail (ico != NULL, CAL_CLIENT_GET_NOT_FOUND);
- obj_str = NULL;
+ retval = CAL_CLIENT_GET_NOT_FOUND;
+ *ico = NULL;
CORBA_exception_init (&ev);
- calobj = Evolution_Calendar_Cal_get_object (priv->cal, uid, &ev);
+ calobj_str = Evolution_Calendar_Cal_get_object (priv->cal, uid, &ev);
if (ev._major == CORBA_USER_EXCEPTION
&& strcmp (CORBA_exception_id (&ev), ex_Evolution_Calendar_Cal_NotFound) == 0)
- goto decode;
+ goto out;
else if (ev._major != CORBA_NO_EXCEPTION) {
g_message ("cal_client_get_object(): could not get the object");
- goto decode;
+ goto out;
}
- obj_str = g_strdup (calobj);
- CORBA_free (calobj);
+ status = ical_object_find_in_string (uid, calobj_str, ico);
+ CORBA_free (calobj_str);
- decode:
- CORBA_exception_free (&ev);
+ switch (status) {
+ case CAL_OBJ_FIND_SUCCESS:
+ retval = CAL_CLIENT_GET_SUCCESS;
+ break;
+
+ case CAL_OBJ_FIND_SYNTAX_ERROR:
+ retval = CAL_CLIENT_GET_SYNTAX_ERROR;
+ break;
+ case CAL_OBJ_FIND_NOT_FOUND:
+ retval = CAL_CLIENT_GET_NOT_FOUND;
+ break;
+
+ default:
+ g_assert_not_reached ();
+ }
+
+ out:
+
+ CORBA_exception_free (&ev);
+ return retval;
#if 0
icalcomponent* comp = NULL;
icalcomponent *subcomp;
@@ -650,7 +670,7 @@ cal_client_get_object (CalClient *client, const char *uid, iCalObject **ico)
while (subcomp) {
ical = ical_object_create_from_icalcomponent (subcomp);
- if (ical->type != ICAL_EVENT &&
+ if (ical->type != ICAL_EVENT &&
ical->type != ICAL_TODO &&
ical->type != ICAL_JOURNAL) {
g_warning ("Skipping unsupported iCalendar component");
@@ -664,12 +684,7 @@ cal_client_get_object (CalClient *client, const char *uid, iCalObject **ico)
subcomp = icalcomponent_get_next_component (comp,
ICAL_ANY_COMPONENT);
}
-# else /* 0 */
- ical_object_find_in_string (uid, obj_str, ico);
-
-# endif /* 0 */
-
- return CAL_CLIENT_GET_NOT_FOUND;
+#endif
}
/**
@@ -740,7 +755,7 @@ build_object_instance_list (Evolution_Calendar_CalObjInstanceSeq *seq)
int i;
/* Create the list in reverse order */
-
+
list = NULL;
for (i = 0; i < seq->_length; i++) {
Evolution_Calendar_CalObjInstance *corba_icoi;
@@ -862,10 +877,10 @@ build_alarm_instance_list (Evolution_Calendar_CalAlarmInstanceSeq *seq)
* @client: A calendar client.
* @start: Start time for query.
* @end: End time for query.
- *
+ *
* Queries a calendar for the alarms that trigger in the specified range of
* time.
- *
+ *
* Return value: A list of #CalAlarmInstance structures.
**/
GList *
@@ -909,10 +924,10 @@ cal_client_get_alarms_in_range (CalClient *client, time_t start, time_t end)
* @start: Start time for query.
* @end: End time for query.
* @alarms: Return value for the list of alarm instances.
- *
+ *
* Queries a calendar for the alarms of a particular object that trigger in the
* specified range of time.
- *
+ *
* Return value: TRUE on success, FALSE if the object was not found.
**/
gboolean
diff --git a/calendar/cal-util/calobj.c b/calendar/cal-util/calobj.c
index c90657cb85..6402937938 100644
--- a/calendar/cal-util/calobj.c
+++ b/calendar/cal-util/calobj.c
@@ -1619,7 +1619,7 @@ ical_object_find_in_string (const char *uid, const char *vcalobj, iCalObject **i
printf ("CAL_OBJ_FIND_NOT_FOUND\n");
return CAL_OBJ_FIND_NOT_FOUND;
-#else /* 0 */
+#else /* 1 */
VObject *vcal;
VObjectIterator i;
CalObjFindStatus status;
@@ -1674,7 +1674,7 @@ ical_object_find_in_string (const char *uid, const char *vcalobj, iCalObject **i
cleanStrTbl ();
return status;
-#endif /* 0 */
+#endif /* 1 */
}
@@ -1737,7 +1737,7 @@ ical_object_to_string (iCalObject *ico)
out_cal_string = icalcomponent_as_ical_string (top);
return g_strdup (out_cal_string);
-#else /* 0 */
+#else /* 1 */
VObject *vcalobj, *vobj;
char *buf, *gbuf;
@@ -1757,7 +1757,7 @@ ical_object_to_string (iCalObject *ico)
free (buf);
return gbuf;
-#endif /* 0 */
+#endif /* 1 */
}
diff --git a/calendar/gui/Makefile.am b/calendar/gui/Makefile.am
index 7da994c995..7541a86c95 100644
--- a/calendar/gui/Makefile.am
+++ b/calendar/gui/Makefile.am
@@ -47,6 +47,8 @@ evolution_calendar_SOURCES = \
alarm.h \
calendar-commands.c \
calendar-commands.h \
+ calendar-model.c \
+ calendar-model.h \
control-factory.c \
control-factory.h \
component-factory.c \
diff --git a/calendar/gui/calendar-model.c b/calendar/gui/calendar-model.c
index 6562f225e1..f91a5c11dd 100644
--- a/calendar/gui/calendar-model.c
+++ b/calendar/gui/calendar-model.c
@@ -20,6 +20,7 @@
*/
#include <config.h>
+#include <gtk/gtksignal.h>
#include "calendar-model.h"
@@ -32,8 +33,8 @@ typedef struct {
/* Types of objects we are dealing with */
CalObjType type;
- /* Array of calendar objects */
- GPtrArray *objects;
+ /* Array of pointers to calendar objects */
+ GArray *objects;
/* UID -> array index hash */
GHashTable *uid_index_hash;
@@ -107,6 +108,16 @@ calendar_model_class_init (CalendarModelClass *class)
parent_class = gtk_type_class (E_TABLE_MODEL_TYPE);
object_class->destroy = calendar_model_destroy;
+
+ etm_class->column_count = calendar_model_column_count;
+ etm_class->row_count = calendar_model_row_count;
+ etm_class->value_at = calendar_model_value_at;
+ etm_class->set_value_at = calendar_model_set_value_at;
+ etm_class->is_cell_editable = calendar_model_is_cell_editable;
+ etm_class->duplicate_value = calendar_model_duplicate_value;
+ etm_class->free_value = calendar_model_free_value;
+ etm_class->initialize_value = calendar_model_initialize_value;
+ etm_class->value_is_empty = calendar_model_value_is_empty;
}
/* Object initialization function for the calendar table model */
@@ -118,7 +129,7 @@ calendar_model_init (CalendarModel *model)
priv = g_new0 (CalendarModelPrivate, 1);
model->priv = priv;
- priv->objects = g_ptr_array_new ();
+ priv->objects = g_array_new (FALSE, TRUE, sizeof (iCalObject *));
priv->uid_index_hash = g_hash_table_new (g_str_hash, g_str_equal);
}
@@ -143,19 +154,19 @@ free_objects (CalendarModel *model)
CalendarModelPrivate *priv;
int i;
- priv = model->data;
+ priv = model->priv;
- g_hash_table_foreach_remove (priv->objects, free_uid_index, NULL);
+ g_hash_table_foreach_remove (priv->uid_index_hash, free_uid_index, NULL);
for (i = 0; i < priv->objects->len; i++) {
iCalObject *ico;
- ico = g_ptr_array_index (priv->objects, i);
+ ico = g_array_index (priv->objects, iCalObject *, i);
g_assert (ico != NULL);
ical_object_unref (ico);
}
- g_ptr_array_set_size (priv->objects, 0);
+ g_array_set_size (priv->objects, 0);
}
/* Destroy handler for the calendar table model */
@@ -164,7 +175,6 @@ calendar_model_destroy (GtkObject *object)
{
CalendarModel *model;
CalendarModelPrivate *priv;
- int i;
g_return_if_fail (object != NULL);
g_return_if_fail (IS_CALENDAR_MODEL (object));
@@ -175,6 +185,7 @@ calendar_model_destroy (GtkObject *object)
/* Free the calendar client interface object */
if (priv->client) {
+ gtk_signal_disconnect_by_data (GTK_OBJECT (priv->client), model);
gtk_object_unref (GTK_OBJECT (priv->client));
priv->client = NULL;
}
@@ -186,7 +197,7 @@ calendar_model_destroy (GtkObject *object)
g_hash_table_destroy (priv->uid_index_hash);
priv->uid_index_hash = NULL;
- g_ptr_array_free (priv->objects, TRUE);
+ g_array_free (priv->objects, TRUE);
priv->objects = NULL;
/* Free the private structure */
@@ -229,7 +240,6 @@ calendar_model_value_at (ETableModel *etm, int col, int row)
CalendarModel *model;
CalendarModelPrivate *priv;
iCalObject *ico;
- void *retval;
model = CALENDAR_MODEL (etm);
priv = model->priv;
@@ -239,12 +249,12 @@ calendar_model_value_at (ETableModel *etm, int col, int row)
return NULL;
}
- ico = g_ptr_array_index (priv->objects, row);
+ ico = g_array_index (priv->objects, iCalObject *, row);
g_assert (ico != NULL);
switch (col) {
case ICAL_OBJECT_FIELD_COMMENT:
- return ico->comment ? ico->commment : "";
+ return ico->comment ? ico->comment : "";
case ICAL_OBJECT_FIELD_COMPLETED:
return &ico->completed;
@@ -289,8 +299,8 @@ calendar_model_value_at (ETableModel *etm, int col, int row)
return ico->url ? ico->url : "";
case ICAL_OBJECT_FIELD_HAS_ALARMS:
- return (ico->dalarm.enabled || ico->aalarm.enabled
- || ico->palarm.enabled || ico->malarm.enabled);
+ return (gpointer) (ico->dalarm.enabled || ico->aalarm.enabled
+ || ico->palarm.enabled || ico->malarm.enabled);
default:
g_message ("calendar_model_value_at(): Requested invalid column %d", col);
@@ -335,7 +345,7 @@ remove_object (CalendarModel *model, const char *uid)
if (!idx)
return -1;
- orig_ico = g_ptr_array_index (priv->objects, *idx);
+ orig_ico = g_array_index (priv->objects, iCalObject *, *idx);
g_assert (orig_ico != NULL);
/* Decrease the indices of all the objects that follow in the array */
@@ -344,20 +354,20 @@ remove_object (CalendarModel *model, const char *uid)
iCalObject *ico;
int *ico_idx;
- ico = g_ptr_array_index (priv->objects, i);
+ ico = g_array_index (priv->objects, iCalObject *, i);
g_assert (ico != NULL);
ico_idx = g_hash_table_lookup (priv->uid_index_hash, ico->uid);
g_assert (ico_idx != NULL);
- *ico_idx--;
+ (*ico_idx)--;
g_assert (*ico_idx >= 0);
}
/* Remove this object from the array and hash */
g_hash_table_remove (priv->uid_index_hash, uid);
- g_array_remove (priv->objects, *idx);
+ g_array_remove_index (priv->objects, *idx);
ical_object_unref (orig_ico);
@@ -374,14 +384,96 @@ obj_updated_cb (CalClient *client, const char *uid, gpointer data)
CalendarModel *model;
CalendarModelPrivate *priv;
int orig_idx;
+ iCalObject *new_ico;
+ int *new_idx;
+ CalClientGetStatus status;
+ gboolean added;
model = CALENDAR_MODEL (data);
priv = model->priv;
orig_idx = remove_object (model, uid);
-
-
+ status = cal_client_get_object (priv->client, uid, &new_ico);
+
+ added = FALSE;
+
+ switch (status) {
+ case CAL_CLIENT_GET_SUCCESS:
+ if (orig_idx == -1) {
+ /* The object not in the model originally, so we just append it */
+
+ g_array_append_val (priv->objects, new_ico);
+
+ new_idx = g_new (int, 1);
+ *new_idx = priv->objects->len - 1;
+ g_hash_table_insert (priv->uid_index_hash, new_ico->uid, new_idx);
+ } else {
+ int i;
+
+ /* Insert the new version of the object in its old position */
+
+ g_array_insert_val (priv->objects, orig_idx, new_ico);
+
+ new_idx = g_new (int, 1);
+ *new_idx = orig_idx;
+ g_hash_table_insert (priv->uid_index_hash, new_ico->uid, new_idx);
+
+ /* Increase the indices of all subsequent objects */
+
+ for (i = orig_idx + 1; i < priv->objects->len; i++) {
+ iCalObject *ico;
+ int *ico_idx;
+
+ ico = g_array_index (priv->objects, iCalObject *, i);
+ g_assert (ico != NULL);
+
+ ico_idx = g_hash_table_lookup (priv->uid_index_hash, ico->uid);
+ g_assert (ico_idx != NULL);
+
+ (*ico_idx)++;
+ }
+ }
+
+ e_table_model_row_changed (E_TABLE_MODEL (model), *new_idx);
+ break;
+
+ case CAL_CLIENT_GET_NOT_FOUND:
+ /* Nothing; the object may have been removed from the server. We just
+ * notify that the old object was deleted.
+ */
+ if (orig_idx != -1)
+ e_table_model_row_deleted (E_TABLE_MODEL (model), orig_idx);
+
+ break;
+
+ case CAL_CLIENT_GET_SYNTAX_ERROR:
+ g_message ("obj_updated_cb(): Syntax error when getting object `%s'", uid);
+
+ /* Same notification as above */
+ if (orig_idx != -1)
+ e_table_model_row_deleted (E_TABLE_MODEL (model), orig_idx);
+
+ break;
+
+ default:
+ g_assert_not_reached ();
+ }
+}
+
+/* Callback used when an object is removed in the server */
+static void
+obj_removed_cb (CalClient *client, const char *uid, gpointer data)
+{
+ CalendarModel *model;
+ int idx;
+
+ model = CALENDAR_MODEL (data);
+
+ idx = remove_object (model, uid);
+
+ if (idx != -1)
+ e_table_model_row_deleted (E_TABLE_MODEL (model), idx);
}
/* Loads the required objects from the calendar client */
@@ -414,15 +506,18 @@ load_objects (CalendarModel *model)
continue;
case CAL_CLIENT_GET_SYNTAX_ERROR:
- g_message ("load_objects(): Syntax error when getting object %s", uid);
+ g_message ("load_objects(): Syntax error when getting object `%s'", uid);
continue;
+
+ default:
+ g_assert_not_reached ();
}
g_assert (ico->uid != NULL);
idx = g_new (int, 1);
- g_ptr_array_add (priv->objects, ico);
+ g_array_append_val (priv->objects, ico);
*idx = priv->objects->len - 1;
g_hash_table_insert (priv->uid_index_hash, ico->uid, idx);
@@ -472,11 +567,11 @@ calendar_model_set_cal_client (CalendarModel *model, CalClient *client, CalObjTy
if (priv->client) {
gtk_signal_connect (GTK_OBJECT (priv->client), "obj_updated",
GTK_SIGNAL_FUNC (obj_updated_cb), model);
- gtk_signal_connect (GTK_OBJECT (priv->clinet), "obj_removed",
+ gtk_signal_connect (GTK_OBJECT (priv->client), "obj_removed",
GTK_SIGNAL_FUNC (obj_removed_cb), model);
- }
- load_objects (model);
+ load_objects (model);
+ }
e_table_model_changed (E_TABLE_MODEL (model));
}
diff --git a/calendar/gui/calendar-model.h b/calendar/gui/calendar-model.h
index 35b76a3807..7e28436e59 100644
--- a/calendar/gui/calendar-model.h
+++ b/calendar/gui/calendar-model.h
@@ -24,7 +24,7 @@
#include <libgnome/gnome-defs.h>
#include <e-table/e-table-model.h>
-#include <cal-util/cal-util.h>
+#include <cal-client/cal-client.h>
BEGIN_GNOME_DECLS
@@ -53,7 +53,7 @@ struct _CalendarModelClass {
GtkType calendar_model_get_type (void);
-CalendarModel *calendar_model_new ();
+CalendarModel *calendar_model_new (void);
void calendar_model_set_cal_client (CalendarModel *model, CalClient *client, CalObjType type);
diff --git a/calendar/pcs/cal-backend-imc.c b/calendar/pcs/cal-backend-imc.c
index 713cddd7fe..7999d97d6e 100644
--- a/calendar/pcs/cal-backend-imc.c
+++ b/calendar/pcs/cal-backend-imc.c
@@ -882,6 +882,8 @@ cal_backend_imc_get_n_objects (CalBackend *backend, CalObjType type)
c.n = 0;
g_hash_table_foreach (priv->object_hash, count_objects, &c);
+
+ return c.n;
}
/* Get_object handler for the IMC backend */