diff options
author | Federico Mena Quintero <federico@helixcode.com> | 2000-06-09 15:04:09 +0800 |
---|---|---|
committer | Federico Mena Quintero <federico@src.gnome.org> | 2000-06-09 15:04:09 +0800 |
commit | 943862dd20ad79007900192fec5c705e9748542a (patch) | |
tree | 01330a057de763ae84f14e8ce004928d835012f1 /calendar/pcs | |
parent | 95ebc1fc92ebe028654b8842bc9d7e5174a0090e (diff) | |
download | gsoc2013-evolution-943862dd20ad79007900192fec5c705e9748542a.tar gsoc2013-evolution-943862dd20ad79007900192fec5c705e9748542a.tar.gz gsoc2013-evolution-943862dd20ad79007900192fec5c705e9748542a.tar.bz2 gsoc2013-evolution-943862dd20ad79007900192fec5c705e9748542a.tar.lz gsoc2013-evolution-943862dd20ad79007900192fec5c705e9748542a.tar.xz gsoc2013-evolution-943862dd20ad79007900192fec5c705e9748542a.tar.zst gsoc2013-evolution-943862dd20ad79007900192fec5c705e9748542a.zip |
Added a get_n_objects() method.
2000-06-09 Federico Mena Quintero <federico@helixcode.com>
* idl/evolution-calendar.idl (Cal): Added a get_n_objects()
method.
* pcs/cal-backend.c (cal_backend_get_n_objects): New function.
* pcs/cal-backend-imc.c (cal_backend_imc_get_n_objects):
Implemented.
* pcs/cal.c (Cal_get_n_objects): Implemented.
* cal-client/cal-client.c (cal_client_get_uids): Free the ev.
(cal_client_get_n_objects): Implemented.
* cal-util/calobj.h (iCalObjectField): New enumeration to identify
the fields in an iCalObject.
svn path=/trunk/; revision=3486
Diffstat (limited to 'calendar/pcs')
-rw-r--r-- | calendar/pcs/cal-backend-imc.c | 55 | ||||
-rw-r--r-- | calendar/pcs/cal-backend.c | 19 | ||||
-rw-r--r-- | calendar/pcs/cal-backend.h | 4 | ||||
-rw-r--r-- | calendar/pcs/cal.c | 29 |
4 files changed, 107 insertions, 0 deletions
diff --git a/calendar/pcs/cal-backend-imc.c b/calendar/pcs/cal-backend-imc.c index a85c8ce535..713cddd7fe 100644 --- a/calendar/pcs/cal-backend-imc.c +++ b/calendar/pcs/cal-backend-imc.c @@ -74,6 +74,8 @@ static GnomeVFSURI *cal_backend_imc_get_uri (CalBackend *backend); static void cal_backend_imc_add_cal (CalBackend *backend, Cal *cal); static CalBackendLoadStatus cal_backend_imc_load (CalBackend *backend, GnomeVFSURI *uri); static void cal_backend_imc_create (CalBackend *backend, GnomeVFSURI *uri); + +static int cal_backend_imc_get_n_objects (CalBackend *backend, CalObjType type); static char *cal_backend_imc_get_object (CalBackend *backend, const char *uid); static GList *cal_backend_imc_get_uids (CalBackend *backend, CalObjType type); static GList *cal_backend_imc_get_events_in_range (CalBackend *backend, time_t start, time_t end); @@ -137,6 +139,7 @@ cal_backend_imc_class_init (CalBackendIMCClass *class) backend_class->add_cal = cal_backend_imc_add_cal; backend_class->load = cal_backend_imc_load; backend_class->create = cal_backend_imc_create; + backend_class->get_n_objects = cal_backend_imc_get_n_objects; backend_class->get_object = cal_backend_imc_get_object; backend_class->get_uids = cal_backend_imc_get_uids; backend_class->get_events_in_range = cal_backend_imc_get_events_in_range; @@ -829,6 +832,58 @@ cal_backend_imc_create (CalBackend *backend, GnomeVFSURI *uri) save (cbimc); } +struct get_n_objects_closure { + CalObjType type; + int n; +}; + +/* Counts the number of objects of the specified type. Called from + * g_hash_table_foreach(). + */ +static void +count_objects (gpointer key, gpointer value, gpointer data) +{ + iCalObject *ico; + struct get_n_objects_closure *c; + gboolean store; + + ico = value; + c = data; + + store = FALSE; + + if (ico->type == ICAL_EVENT) + store = (c->type & CALOBJ_TYPE_EVENT) != 0; + else if (ico->type == ICAL_TODO) + store = (c->type & CALOBJ_TYPE_TODO) != 0; + else if (ico->type == ICAL_JOURNAL) + store = (c->type & CALOBJ_TYPE_JOURNAL) != 0; + else + store = (c->type & CALOBJ_TYPE_OTHER) != 0; + + if (store) + c->n++; +} + +/* Get_n_objects handler for the IMC backend */ +static int +cal_backend_imc_get_n_objects (CalBackend *backend, CalObjType type) +{ + CalBackendIMC *cbimc; + IMCPrivate *priv; + struct get_n_objects_closure c; + + cbimc = CAL_BACKEND_IMC (backend); + priv = cbimc->priv; + + g_return_val_if_fail (priv->loaded, -1); + + c.type = type; + c.n = 0; + + g_hash_table_foreach (priv->object_hash, count_objects, &c); +} + /* Get_object handler for the IMC backend */ static char * cal_backend_imc_get_object (CalBackend *backend, const char *uid) diff --git a/calendar/pcs/cal-backend.c b/calendar/pcs/cal-backend.c index 15cfb1e7bc..7956f77473 100644 --- a/calendar/pcs/cal-backend.c +++ b/calendar/pcs/cal-backend.c @@ -177,6 +177,25 @@ cal_backend_create (CalBackend *backend, GnomeVFSURI *uri) } /** + * cal_backend_get_n_objects: + * @backend: A calendar backend. + * @type: Types of objects that will be included in the count. + * + * Queries the number of calendar objects of a particular type. + * + * Return value: Number of objects of the specified @type. + **/ +int +cal_backend_get_n_objects (CalBackend *backend, CalObjType type) +{ + g_return_val_if_fail (backend != NULL, -1); + g_return_val_if_fail (IS_CAL_BACKEND (backend), -1); + + g_assert (CLASS (backend)->get_n_objects != NULL); + return (* CLASS (backend)->get_n_objects) (backend, type); +} + +/** * cal_backend_get_object: * @backend: A calendar backend. * @uid: Unique identifier for a calendar object. diff --git a/calendar/pcs/cal-backend.h b/calendar/pcs/cal-backend.h index 2bbac4b3d4..57f3acf18e 100644 --- a/calendar/pcs/cal-backend.h +++ b/calendar/pcs/cal-backend.h @@ -64,6 +64,8 @@ struct _CalBackendClass { void (* add_cal) (CalBackend *backend, Cal *cal); CalBackendLoadStatus (* load) (CalBackend *backend, GnomeVFSURI *uri); void (* create) (CalBackend *backend, GnomeVFSURI *uri); + + int (* get_n_objects) (CalBackend *backend, CalObjType type); char *(* get_object) (CalBackend *backend, const char *uid); GList *(* get_uids) (CalBackend *backend, CalObjType type); GList *(* get_events_in_range) (CalBackend *backend, time_t start, time_t end); @@ -85,6 +87,8 @@ CalBackendLoadStatus cal_backend_load (CalBackend *backend, GnomeVFSURI *uri); void cal_backend_create (CalBackend *backend, GnomeVFSURI *uri); +int cal_backend_get_n_objects (CalBackend *backend, CalObjType type); + char *cal_backend_get_object (CalBackend *backend, const char *uid); GList *cal_backend_get_uids (CalBackend *backend, CalObjType type); diff --git a/calendar/pcs/cal.c b/calendar/pcs/cal.c index 13fab067f8..a01c0ce8dc 100644 --- a/calendar/pcs/cal.c +++ b/calendar/pcs/cal.c @@ -166,7 +166,35 @@ Cal_get_uri (PortableServer_Servant servant, g_free (str_uri); return str_uri_copy; +} + +/* Cal::get_n_objects method */ +static CORBA_long +Cal_get_n_objects (PortableServer_Servant servant, + Evolution_Calendar_CalObjType type, + CORBA_Environment *ev) +{ + Cal *cal; + CalPrivate *priv; + int t; + int n; + + cal = CAL (bonobo_object_from_servant (servant)); + priv = cal->priv; + + /* Translate the CORBA flags to our own flags */ + + t = (((type & Evolution_Calendar_TYPE_EVENT) ? CALOBJ_TYPE_EVENT : 0) + | ((type & Evolution_Calendar_TYPE_TODO) ? CALOBJ_TYPE_TODO : 0) + | ((type & Evolution_Calendar_TYPE_JOURNAL) ? CALOBJ_TYPE_JOURNAL : 0) + | ((type & Evolution_Calendar_TYPE_OTHER) ? CALOBJ_TYPE_OTHER : 0) + /* + | ((type & Evolution_Calendar_TYPE_ANY) ? CALOBJ_TYPE_ANY : 0) + */ + ); + n = cal_backend_get_n_objects (priv->backend, t); + return n; } /* Cal::get_object method */ @@ -504,6 +532,7 @@ cal_get_epv (void) epv = g_new0 (POA_Evolution_Calendar_Cal__epv, 1); epv->_get_uri = Cal_get_uri; + epv->get_n_objects = Cal_get_n_objects; epv->get_object = Cal_get_object; epv->get_uids = Cal_get_uids; epv->get_events_in_range = Cal_get_events_in_range; |