From: <dg...@su...> - 2009-01-11 00:26:32
|
Author: ianmartin Date: Sun Jan 11 01:25:49 2009 New Revision: 5088 URL: http://www.opensync.org/changeset/5088 Log: Utilities added to tools directory list_sources creates a list of sources known to the eds. Could be useful when trying to connect to another source than the default. test_uri tries to open the passed uri as an EBook or ECal Added: plugins/evolution2/tools/ plugins/evolution2/tools/CMakeLists.txt plugins/evolution2/tools/list_sources.c plugins/evolution2/tools/test_uri.c Modified: plugins/evolution2/CMakeLists.txt plugins/evolution2/src/evolution2_sync.c Modified: plugins/evolution2/CMakeLists.txt ============================================================================== --- plugins/evolution2/CMakeLists.txt Sun Jan 11 01:25:45 2009 (r5087) +++ plugins/evolution2/CMakeLists.txt Sun Jan 11 01:25:49 2009 (r5088) @@ -16,6 +16,7 @@ INCLUDE( Testing ) ADD_SUBDIRECTORY( src ) +ADD_SUBDIRECTORY( tools ) ADD_SUBDIRECTORY( tests ) Modified: plugins/evolution2/src/evolution2_sync.c ============================================================================== --- plugins/evolution2/src/evolution2_sync.c Sun Jan 11 01:25:45 2009 (r5087) +++ plugins/evolution2/src/evolution2_sync.c Sun Jan 11 01:25:49 2009 (r5088) @@ -56,132 +56,7 @@ g_free(env); } -GList *evo2_list_calendars(OSyncEvoEnv *env, void *data, OSyncError **error) -{ - GList *paths = NULL; - ESourceList *sources = NULL; - ESource *source = NULL; - osync_bool first = FALSE; - - if (!e_cal_get_sources(&sources, E_CAL_SOURCE_TYPE_EVENT, NULL)) { - osync_error_set(error, OSYNC_ERROR_GENERIC, "Unable to list calendars. Unable to get sources"); - return NULL; - } - - GSList *g = NULL; - for (g = e_source_list_peek_groups (sources); g; g = g->next) { - ESourceGroup *group = E_SOURCE_GROUP (g->data); - GSList *s = NULL; - for (s = e_source_group_peek_sources (group); s; s = s->next) { - source = E_SOURCE (s->data); - evo2_location *path = g_malloc0(sizeof(evo2_location)); - if (!first) { - first = TRUE; - path->uri = g_strdup("default"); - } else { - path->uri = g_strdup(e_source_get_uri(source)); - } - path->name = g_strdup(e_source_peek_name(source)); - paths = g_list_append(paths, path); - } - } - return paths; -} - -GList *evo2_list_memos(OSyncEvoEnv *env, void *data, OSyncError **error) -{ - GList *paths = NULL; - ESourceList *sources = NULL; - ESource *source = NULL; - osync_bool first = FALSE; - - if (!e_cal_get_sources(&sources, E_CAL_SOURCE_TYPE_JOURNAL, NULL)) { - osync_error_set(error, OSYNC_ERROR_GENERIC, "Unable to list memos. Unable to get sources"); - return NULL; - } - - GSList *g = NULL; - for (g = e_source_list_peek_groups (sources); g; g = g->next) { - ESourceGroup *group = E_SOURCE_GROUP (g->data); - GSList *s = NULL; - for (s = e_source_group_peek_sources (group); s; s = s->next) { - source = E_SOURCE (s->data); - evo2_location *path = g_malloc0(sizeof(evo2_location)); - if (!first) { - first = TRUE; - path->uri = g_strdup("default"); - } else { - path->uri = g_strdup(e_source_get_uri(source)); - } - path->name = g_strdup(e_source_peek_name(source)); - paths = g_list_append(paths, path); - } - } - return paths; -} -GList *evo2_list_tasks(OSyncEvoEnv *env, void *data, OSyncError **error) -{ - GList *paths = NULL; - ESourceList *sources = NULL; - ESource *source = NULL; - osync_bool first = FALSE; - - if (!e_cal_get_sources(&sources, E_CAL_SOURCE_TYPE_TODO, NULL)) { - osync_error_set(error, OSYNC_ERROR_GENERIC, "Unable to list tasks. Unable to get sources"); - return NULL; - } - - GSList *g = NULL; - for (g = e_source_list_peek_groups (sources); g; g = g->next) { - ESourceGroup *group = E_SOURCE_GROUP (g->data); - GSList *s = NULL; - for (s = e_source_group_peek_sources (group); s; s = s->next) { - source = E_SOURCE (s->data); - evo2_location *path = g_malloc0(sizeof(evo2_location)); - if (!first) { - first = TRUE; - path->uri = g_strdup("default"); - } else { - path->uri = g_strdup(e_source_get_uri(source)); - } - path->name = g_strdup(e_source_peek_name(source)); - paths = g_list_append(paths, path); - } - } - return paths; -} - -GList *evo2_list_addressbooks(OSyncEvoEnv *env, void *data, OSyncError **error) -{ - GList *paths = NULL; - ESourceList *sources = NULL; - ESource *source = NULL; - osync_bool first = FALSE; - if (!e_book_get_addressbooks(&sources, NULL)) { - osync_error_set(error, OSYNC_ERROR_GENERIC, "Unable to list addressbooks. Unable to get sources"); - return NULL; - } - - GSList *g = NULL; - for (g = e_source_list_peek_groups (sources); g; g = g->next) { - ESourceGroup *group = E_SOURCE_GROUP (g->data); - GSList *s = NULL; - for (s = e_source_group_peek_sources (group); s; s = s->next) { - source = E_SOURCE (s->data); - evo2_location *path = g_malloc0(sizeof(evo2_location)); - if (!first) { - first = TRUE; - path->uri = g_strdup("default"); - } else { - path->uri = g_strdup(e_source_get_uri(source)); - } - path->name = g_strdup(e_source_peek_name(source)); - paths = g_list_append(paths, path); - } - } - return paths; -} ESource *evo2_find_source(ESourceList *list, char *uri) { Added: plugins/evolution2/tools/CMakeLists.txt ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ plugins/evolution2/tools/CMakeLists.txt Sun Jan 11 01:25:49 2009 (r5088) @@ -0,0 +1,13 @@ +LINK_DIRECTORIES( ${OPENSYNC_LIBRARY_DIRS} ${GLIB2_LIBRARY_DIRS} ${LIBEBOOK_LIBRARY_DIRS} ${LIBECAL_LIBRARY_DIRS} ${LIBEDATABOOK_LIBRARY_DIRS} ${LIBEDATACAL_LIBRARY_DIRS} ${LIBEDATASERVER_LIBRARY_DIRS} ) +INCLUDE_DIRECTORIES( ${LIBEBOOK_INCLUDE_DIRS} ${LIBECAL_INCLUDE_DIRS} ${LIBEDATABOOK_INCLUDE_DIRS} ${LIBEDATACAL_INCLUDE_DIRS} ${LIBEDATASERVER_INCLUDE_DIRS} ${OPENSYNC_INCLUDE_DIRS} ${GLIB2_INCLUDE_DIRS} ) + +SET( list_sources_SRCS +list_sources.c +) + +ADD_EXECUTABLE( list_sources ${list_sources_SRCS} ) +TARGET_LINK_LIBRARIES( list_sources ${OPENSYNC_LIBRARIES} ${GLIB2_LIBRARIES} ${LIBEBOOK_LIBRARIES} ${LIBECAL_LIBRARIES} ${LIBEDATASERVER_LIBRARIES} ) + +ADD_EXECUTABLE( test_uri test_uri.c ) +TARGET_LINK_LIBRARIES( test_uri ${OPENSYNC_LIBRARIES} ${GLIB2_LIBRARIES} ${LIBEBOOK_LIBRARIES} ${LIBECAL_LIBRARIES} ${LIBEDATASERVER_LIBRARIES} ) + Added: plugins/evolution2/tools/list_sources.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ plugins/evolution2/tools/list_sources.c Sun Jan 11 01:25:49 2009 (r5088) @@ -0,0 +1,67 @@ +#include <glib.h> +#include <libecal/e-cal.h> +#include <libebook/e-book.h> +#include <libedataserver/e-data-server-util.h> + + +void print_sources(ESourceList *sources) +{ + ESource *source = NULL; + + GSList *g = NULL; + for (g = e_source_list_peek_groups (sources); g; g = g->next) { + ESourceGroup *group = E_SOURCE_GROUP (g->data); + printf("Group: %s\n", e_source_group_peek_name(group)); + + GSList *s = NULL; + for (s = e_source_group_peek_sources (group); s; s = s->next) { + source = E_SOURCE (s->data); + printf(" %s: %s\n", e_source_peek_name(source), e_source_get_uri(source)); + } + } +} + +void print_calendars(ECalSourceType source_type) { + ESourceList *sources = NULL; + if (e_cal_get_sources(&sources, source_type, NULL)) { + print_sources(sources); + } +} + +void print_memos() +{ + print_calendars(E_CAL_SOURCE_TYPE_JOURNAL); +} + +void print_tasks() +{ + print_calendars(E_CAL_SOURCE_TYPE_TODO); +} + +void print_events() +{ + print_calendars(E_CAL_SOURCE_TYPE_EVENT); +} + + +int main () { + ESourceList *sources = NULL; + printf("Addressbooks:\n"); + if (e_book_get_addressbooks(&sources, NULL)) { + print_sources(sources); + } + printf("\n"); + printf("Events:\n"); + print_events(); + printf("\n"); + + printf("Tasks:\n"); + print_tasks(); + printf("\n"); + + printf("Memos:\n"); + print_memos(); + + + return 0; +} Added: plugins/evolution2/tools/test_uri.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ plugins/evolution2/tools/test_uri.c Sun Jan 11 01:25:49 2009 (r5088) @@ -0,0 +1,79 @@ +#include <string.h> +#include <glib.h> +#include <libecal/e-cal.h> +#include <libebook/e-book.h> +#include <libedataserver/e-data-server-util.h> + +void open_calendar(const char *uri, ECalSourceType source_type) +{ + ECal *cal = NULL; + GError *gerror = NULL; + cal = e_cal_new_from_uri(uri, source_type); + + if (!cal) { + printf("Failed to allocate calendar\n"); + return; + } + if (!e_cal_open(cal, TRUE, &gerror)) { + printf("Failed to open calendar:\n%s\n", gerror->message); + g_clear_error(&gerror); + return; + } + printf("Successfully opened %s\n", uri); + g_object_unref(cal); +} + +void open_book(const char *uri) +{ + EBook *book = NULL; + GError *gerror = NULL; + book = e_book_new_from_uri(uri, &gerror); + + if (book) { + if (e_book_open(book, TRUE, &gerror)) { + printf("Successfully opened %s\n", uri); + } + g_object_unref(book); + } + if (gerror) { + printf("Failed to open addressbook:\n%s\n", gerror->message); + g_clear_error(&gerror); + } +} + +static void usage(char *progname, int exitcode) +{ + fprintf (stderr, "Usage: %s <objtype> <uri>\n\n", progname); + fprintf (stderr, "objtype may be one of:\n"); + fprintf (stderr, "--contact\n"); + fprintf (stderr, "--event\n"); + fprintf (stderr, "--note\n"); + fprintf (stderr, "--todo\n"); + fprintf (stderr, "\nWARNING: This program allows you to attempt to open ECals with the wrong source type. Doing so may break everything\n"); + exit(exitcode); +} + +int main(int argc, char *argv[]) +{ + + g_type_init(); + if (argc < 2) + usage(argv[0], 1); + if (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")) + usage(argv[0], 0); + + if (argc <3) + usage(argv[0], 1); + if (!strcmp(argv[1], "--contact")) { + open_book(argv[2]); + } else if (!strcmp(argv[1], "--event")) { + open_calendar(argv[2], E_CAL_SOURCE_TYPE_EVENT); + } else if (!strcmp(argv[1], "--todo")) { + open_calendar(argv[2], E_CAL_SOURCE_TYPE_TODO); + } else if (!strcmp(argv[1], "--note")) { + open_calendar(argv[2], E_CAL_SOURCE_TYPE_JOURNAL); + } else { + usage(argv[0], 1); + } + return 0; +} |