aboutsummaryrefslogtreecommitdiffstats
path: root/calendar/cal-client/client-test.c
diff options
context:
space:
mode:
authorFederico Mena Quintero <federico@helixcode.com>2000-02-11 19:08:08 +0800
committerArturo Espinosa <unammx@src.gnome.org>2000-02-11 19:08:08 +0800
commitd8fbc4fc0c01d174f04e8f2370131a5240764f4b (patch)
treed530001f5c312790457e2cd55585dd46eac32085 /calendar/cal-client/client-test.c
parentdb6312e2549c63372546af84fce3ce41b7c3f48d (diff)
downloadgsoc2013-evolution-d8fbc4fc0c01d174f04e8f2370131a5240764f4b.tar
gsoc2013-evolution-d8fbc4fc0c01d174f04e8f2370131a5240764f4b.tar.gz
gsoc2013-evolution-d8fbc4fc0c01d174f04e8f2370131a5240764f4b.tar.bz2
gsoc2013-evolution-d8fbc4fc0c01d174f04e8f2370131a5240764f4b.tar.lz
gsoc2013-evolution-d8fbc4fc0c01d174f04e8f2370131a5240764f4b.tar.xz
gsoc2013-evolution-d8fbc4fc0c01d174f04e8f2370131a5240764f4b.tar.zst
gsoc2013-evolution-d8fbc4fc0c01d174f04e8f2370131a5240764f4b.zip
Connect to the Cal's destroy signal. (cal_backend_remove_cal): Killed
2000-02-10 Federico Mena Quintero <federico@helixcode.com> * cal-backend.c (cal_backend_add_cal): Connect to the Cal's destroy signal. (cal_backend_remove_cal): Killed function now that removal of Cal objects is done in their destroy callback. (cal_destroy_cb): New callback to remove a Cal from the backend's list of clients. Also, the backend destroys itself when there are no more clients connected to it. (save): New placeholder function to save a backend. (destroy): New function to destroy a backend's data. (cal_backend_destroy): Save the calendar and destroy it. * cal.c (cal_destroy): Reset the priv->backend to NULL. * cal-factory.c (add_calendar_client): There is no need to call cal_backend_remove_cal(); we can now just destroy the Cal object. (create_fn): Make sure we always unref the URI. (load_fn): Move the URI unref to the end of the function for safety. * cal-factory.c (add_calendar_client): Unref the Cal only if notification of the listener was unsuccessful. Otherwise, the calendar user agent (Listener side) keeps the reference. * tl-test.c (list_uids): Free the calobj. * cal-client.c (cal_loaded_cb): Use bonobo_object_unref() to get rid of the listener. (load_or_create): Likewise. (destroy_factory): New function to get rid of the factory. (destroy_listener): New function to get rid of the listener. (destroy_cal): New function to get rid of the calendar client interface object. (cal_client_destroy): Free all resources. (cal_client_get_object): CORBA_free() the calobj string. Boy, I love memprof. * cal-listener.c (cal_listener_destroy): Reset the priv->cal to CORBA_OBJECT_NIL. * cal-backend.c (cal_backend_remove_cal): Do not unref the Cal, since the calendar user agent owns it. (cal_backend_add_cal): Do not ref the Cal, since the calendar user agent owns it. * cal-factory.c (add_calendar_client): Use bonobo_object_unref() to get rid of the calendar client interface object. * calobj.c (ical_object_create_from_vobject): Duplicate the default "PUBLIC" string. 2000-02-09 Federico Mena Quintero <federico@helixcode.com> * cal-factory.c (cal_factory_load): Added documentation comment. (load_fn): Do not print a message if the backend could not be loaded due to a non-fatal error. (queue_load_create_job): Moved the stuff from cal_factory_load() to here. Now this function serves to queue load or create requests. (cal_factory_load): Use queue_load_create_job(). (cal_factory_create): Implemented; use queue_load_create_job(). (create_fn): New job handler for creating new calendars. (create_backend): New function to create a new backend with a new calendar. (add_backend): New helper function to add backends to the factory's hash table. (load_backend): Use add_backend() instead of adding the backend by ourselves. * cal-client.c (load_or_create): Moved the functionality from cal_client_load_calendar() to here, and added an option to create a new calendar instead of loading an existing one. (cal_client_load_calendar): Use load_or_create(). (cal_client_create_calendar): Implemented. * cal-backend.c (cal_backend_create): Implemented. * evolution-calendar.idl (LoadStatus): Added an IN_USE error for create requests. * cal-listener.h (CalListenerLoadStatus): Added CAL_LISTENER_LOAD_IN_USE. * cal-listener.c (Listener_cal_loaded): Convert the IN_USE error. * cal-client.h (CalClientLoadStatus): Added CAL_CLIENT_LOAD_IN_USE. * cal-client.c (cal_loaded_cb): Handle CAL_LISTENER_LOAD_IN_USE. * tl-test.c: New test program for the calendar client side; it also exercises the server side by sending commands to it. * Makefile.am: Added the tl-test program. * tlacuache.gnorba: Updated. * tlacuache.c (create_cal_factory): Use the right GOAD id. * cal-client.c (cal_client_construct): Use the right GOAD id. svn path=/trunk/; revision=1732
Diffstat (limited to 'calendar/cal-client/client-test.c')
-rw-r--r--calendar/cal-client/client-test.c148
1 files changed, 148 insertions, 0 deletions
diff --git a/calendar/cal-client/client-test.c b/calendar/cal-client/client-test.c
new file mode 100644
index 0000000000..bebaa42d87
--- /dev/null
+++ b/calendar/cal-client/client-test.c
@@ -0,0 +1,148 @@
+#include <config.h>
+#include <libgnorba/gnorba.h>
+#include <bonobo.h>
+#include "cal-client.h"
+
+static CalClient *client1;
+static CalClient *client2;
+
+/* Prints a message with a client identifier */
+static void
+cl_printf (CalClient *client, const char *format, ...)
+{
+ va_list args;
+
+ va_start (args, format);
+ printf ("Client %s: ",
+ client == client1 ? "1" :
+ client == client2 ? "2" :
+ "UNKNOWN");
+ vprintf (format, args);
+ va_end (args);
+}
+
+/* Lists the UIDs of objects in a calendar, called as an idle handler */
+static gboolean
+list_uids (gpointer data)
+{
+ CalClient *client;
+ GList *uids;
+ GList *l;
+
+ client = CAL_CLIENT (data);
+
+ uids = cal_client_get_uids (client, CALOBJ_TYPE_ANY);
+
+ cl_printf (client, "UIDs: ");
+
+ if (!uids)
+ printf ("none\n");
+ else {
+ for (l = uids; l; l = l->next) {
+ char *uid;
+
+ uid = l->data;
+ printf ("`%s' ", uid);
+ }
+
+ printf ("\n");
+
+ for (l = uids; l; l = l->next) {
+ char *uid;
+ char *calobj;
+
+ uid = l->data;
+ calobj = cal_client_get_object (client, uid);
+
+ printf ("------------------------------\n%s", calobj);
+ printf ("------------------------------\n");
+
+ g_free (calobj);
+ }
+ }
+
+ cal_obj_uid_list_free (uids);
+
+ gtk_object_unref (GTK_OBJECT (client));
+
+ return FALSE;
+}
+
+/* Callback used when a calendar is loaded */
+static void
+cal_loaded (CalClient *client, CalClientLoadStatus status, gpointer data)
+{
+ cl_printf (client, "Load/create %s\n",
+ ((status == CAL_CLIENT_LOAD_SUCCESS) ? "success" :
+ (status == CAL_CLIENT_LOAD_ERROR) ? "error" :
+ (status == CAL_CLIENT_LOAD_IN_USE) ? "in use" :
+ "unknown status value"));
+
+ if (status == CAL_CLIENT_LOAD_SUCCESS)
+ g_idle_add (list_uids, client);
+ else
+ gtk_object_unref (GTK_OBJECT (client));
+}
+
+/* Creates a calendar client and tries to load the specified URI into it */
+static CalClient *
+create_client (const char *uri, gboolean load)
+{
+ CalClient *client;
+ gboolean result;
+
+ client = cal_client_new ();
+ if (!client) {
+ g_message ("create_client(): could not create the client");
+ exit (1);
+ }
+
+ gtk_signal_connect (GTK_OBJECT (client), "cal_loaded",
+ GTK_SIGNAL_FUNC (cal_loaded),
+ NULL);
+
+ printf ("Calendar loading `%s'...\n", uri);
+
+ if (load)
+ result = cal_client_load_calendar (client, uri);
+ else
+ result = cal_client_create_calendar (client, uri);
+
+ if (!result) {
+ g_message ("create_client(): failure when issuing calendar load/create request `%s'",
+ uri);
+ exit (1);
+ }
+
+ return client;
+}
+
+int
+main (int argc, char **argv)
+{
+ CORBA_Environment ev;
+
+ bindtextdomain (PACKAGE, GNOMELOCALEDIR);
+ textdomain (PACKAGE);
+
+ CORBA_exception_init (&ev);
+ gnome_CORBA_init ("tl-test", VERSION, &argc, argv, 0, &ev);
+ if (ev._major != CORBA_NO_EXCEPTION) {
+ g_message ("main(): could not initialize the ORB");
+ CORBA_exception_free (&ev);
+ exit (1);
+ }
+ CORBA_exception_free (&ev);
+
+ if (!bonobo_init (CORBA_OBJECT_NIL, CORBA_OBJECT_NIL, CORBA_OBJECT_NIL)) {
+ g_message ("main(): could not initialize Bonobo");
+ exit (1);
+ }
+
+ client1 = create_client ("/cvs/evolution/calendar/test2.vcf", TRUE);
+ client2 = create_client ("/cvs/evolution/calendar/test2.vcf", FALSE);
+
+ bonobo_main ();
+
+ return 0;
+}