aboutsummaryrefslogtreecommitdiffstats
path: root/calendar/gui/calendar-component.c
diff options
context:
space:
mode:
authorRodrigo Moya <rodrigo@ximian.com>2001-09-19 04:16:39 +0800
committerRodrigo Moya <rodrigo@src.gnome.org>2001-09-19 04:16:39 +0800
commit2b78b5294a6a047a971446595c9e7f5f32f583a2 (patch)
tree6b74cd7376bb1ab8024871a5e2b059d669ebf6d8 /calendar/gui/calendar-component.c
parent3e079da9b69b8f5c47c79bcbb269ac17cc094c6e (diff)
downloadgsoc2013-evolution-2b78b5294a6a047a971446595c9e7f5f32f583a2.tar.gz
gsoc2013-evolution-2b78b5294a6a047a971446595c9e7f5f32f583a2.tar.zst
gsoc2013-evolution-2b78b5294a6a047a971446595c9e7f5f32f583a2.zip
new class for managing multiple calendars, with an API very similar to the
2001-09-18 Rodrigo Moya <rodrigo@ximian.com> * cal-client/cal-client-multi.[ch]: new class for managing multiple calendars, with an API very similar to the CalClient one, for ease of transition from one to the other * gui/component-factory.c (xfer_folder, remove_folder, create_folder): reworked to be able to manage folders for any calendar backend, and not only the file: one 2001-09-18 Rodrigo Moya <rodrigo@ximian.com> * idl/evolution-calendar.idl: changed signature for the getFreeBusy method, to return a sequence of CalObj's, and added sequence of users as a new parameter to that method * cal-client/cal-client.c (cal_client_get_free_busy): adapted to new IDL method signature, by adding a new "GList *users" parameter, for callers to be able to specify a list of users * pcs/cal-backend.[ch] (cal_backend_get_free_busy): * pcs/cal-backend-file.c (cal_backend_file_get_free_busy): add the "GList *users" parameter. In cal_backend_file_get_free_busy, call lookup_component to get the CalComponent for each uid, instead of calling cal_backend_get_object, which meant converting the component to a string and then parsing it again. * cal-client/client-test.c (cal_opened_cb): * gui/e-itip-control.c (send_freebusy): * gui/calendar-commands.c (publish_freebusy_cmd): adapted to new getFreeBusy method signature svn path=/trunk/; revision=12951
Diffstat (limited to 'calendar/gui/calendar-component.c')
-rw-r--r--calendar/gui/calendar-component.c333
1 files changed, 202 insertions, 131 deletions
diff --git a/calendar/gui/calendar-component.c b/calendar/gui/calendar-component.c
index 786aa70003..2e6186974f 100644
--- a/calendar/gui/calendar-component.c
+++ b/calendar/gui/calendar-component.c
@@ -28,6 +28,7 @@
#include <libgnomevfs/gnome-vfs-types.h>
#include <libgnomevfs/gnome-vfs-uri.h>
#include <libgnomevfs/gnome-vfs-ops.h>
+#include <libgnomevfs/gnome-vfs-directory.h>
#include <bonobo/bonobo-generic-factory.h>
#include <bonobo/bonobo-context.h>
@@ -121,17 +122,35 @@ create_folder (EvolutionShellComponent *shell_component,
void *closure)
{
CORBA_Environment ev;
+ GnomeVFSURI *uri;
- CORBA_exception_init(&ev);
- /* FIXME: I don't think we have to do anything to create a calendar
- or tasks folder - the '.ics' files are created automatically when
- needed. But I'm not sure - Damon. */
- if (!strcmp(type, "calendar") || !strcmp(type, "tasks")) {
- GNOME_Evolution_ShellComponentListener_notifyResult(listener, GNOME_Evolution_ShellComponentListener_OK, &ev);
- } else {
- GNOME_Evolution_ShellComponentListener_notifyResult(listener, GNOME_Evolution_ShellComponentListener_UNSUPPORTED_TYPE, &ev);
+ CORBA_exception_init (&ev);
+
+ if (strcmp (type, FOLDER_CALENDAR) && strcmp (type, FOLDER_TASKS)) {
+ GNOME_Evolution_ShellComponentListener_notifyResult (
+ listener,
+ GNOME_Evolution_ShellComponentListener_UNSUPPORTED_TYPE,
+ &ev);
+ CORBA_exception_free (&ev);
+ return;
}
- CORBA_exception_free(&ev);
+
+ uri = gnome_vfs_uri_new_private (physical_uri, TRUE, TRUE, TRUE);
+ if (uri) {
+ /* we don't need to do anything */
+ GNOME_Evolution_ShellComponentListener_notifyResult (
+ listener,
+ GNOME_Evolution_ShellComponentListener_OK, &ev);
+ gnome_vfs_uri_unref (uri);
+ }
+ else {
+ GNOME_Evolution_ShellComponentListener_notifyResult (
+ listener,
+ GNOME_Evolution_ShellComponentListener_INVALID_URI,
+ &ev);
+ }
+
+ CORBA_exception_free (&ev);
}
static void
@@ -142,68 +161,91 @@ remove_folder (EvolutionShellComponent *shell_component,
void *closure)
{
CORBA_Environment ev;
- const char *file_name;
- gchar *path;
- int rv;
+ GnomeVFSURI *uri;
+ GnomeVFSResult result;
+ GList *file_list;
CORBA_exception_init(&ev);
- /* check URI */
- if (strncmp (physical_uri, "file://", 7)) {
+ /* check type */
+ if (strcmp (type, FOLDER_CALENDAR) && strcmp (type, FOLDER_TASKS)) {
GNOME_Evolution_ShellComponentListener_notifyResult (
listener,
- GNOME_Evolution_ShellComponentListener_INVALID_URI,
+ GNOME_Evolution_ShellComponentListener_UNSUPPORTED_TYPE,
&ev);
CORBA_exception_free (&ev);
return;
}
- /* FIXME: check if there are subfolders? */
-
- file_name = get_local_file_name_for_folder_type (type);
- if (file_name == NULL) {
- GNOME_Evolution_ShellComponentListener_notifyResult (listener,
- GNOME_Evolution_ShellComponentListener_UNSUPPORTED_TYPE,
- &ev);
- CORBA_exception_free (&ev);
- return;
- }
-
- /* remove the .ics file */
- path = g_concat_dir_and_file (physical_uri + 7, file_name);
- rv = unlink (path);
- g_free (path);
- if (rv == 0) {
- /* everything OK; notify the listener */
+ /* check URI */
+ uri = gnome_vfs_uri_new_private (physical_uri, TRUE, TRUE, TRUE);
+ if (!uri) {
GNOME_Evolution_ShellComponentListener_notifyResult (
listener,
- GNOME_Evolution_ShellComponentListener_OK,
+ GNOME_Evolution_ShellComponentListener_INVALID_URI,
&ev);
+ CORBA_exception_free (&ev);
+ return;
}
- else {
- if (errno == EACCES || errno == EPERM)
- GNOME_Evolution_ShellComponentListener_notifyResult (
- listener,
- GNOME_Evolution_ShellComponentListener_PERMISSION_DENIED,
- &ev);
- else
+
+ /* remove all files in that directory */
+ result = gnome_vfs_directory_list_load (&file_list, physical_uri, 0, NULL);
+ if (result == GNOME_VFS_OK) {
+ GList *l;
+ gboolean success = TRUE;
+
+ for (l = file_list; l; l = l->next) {
+ GnomeVFSFileInfo *file_info;
+ GnomeVFSURI *tmp_uri;
+
+ /* ignore hidden files */
+ file_info = (GnomeVFSFileInfo *) l->data;
+ if (!file_info || file_info->name[0] == '.')
+ continue;
+
+ if (file_info->type == GNOME_VFS_FILE_TYPE_DIRECTORY) {
+ GNOME_Evolution_ShellComponentListener_notifyResult (
+ listener,
+ GNOME_Evolution_ShellComponentListener_HAS_SUBFOLDERS,
+ &ev);
+ success = FALSE;
+ break;
+ }
+
+ tmp_uri = gnome_vfs_uri_new_private (physical_uri, TRUE, TRUE, TRUE);
+ tmp_uri = gnome_vfs_uri_append_file_name (tmp_uri, file_info->name);
+
+ result = gnome_vfs_unlink_from_uri (tmp_uri);
+ gnome_vfs_uri_unref (tmp_uri);
+ if (result != GNOME_VFS_OK) {
+ GNOME_Evolution_ShellComponentListener_notifyResult (
+ listener,
+ GNOME_Evolution_ShellComponentListener_PERMISSION_DENIED,
+ &ev);
+ success = FALSE;
+ break;
+ }
+ }
+
+ if (success) {
GNOME_Evolution_ShellComponentListener_notifyResult (
listener,
- GNOME_Evolution_ShellComponentListener_INVALID_URI, /*XXX*/
+ GNOME_Evolution_ShellComponentListener_OK,
&ev);
+ }
+ }
+ else {
+ GNOME_Evolution_ShellComponentListener_notifyResult (
+ listener,
+ GNOME_Evolution_ShellComponentListener_PERMISSION_DENIED,
+ &ev);
}
- CORBA_exception_free(&ev);
-}
-
-/* callback used from icalparser_parse */
-static char *
-get_line_fn (char *s, size_t size, void *data)
-{
- FILE *file;
+ /* free memory */
+ gnome_vfs_file_info_list_free (file_list);
+ gnome_vfs_uri_unref (uri);
- file = data;
- return fgets (s, size, file);
+ CORBA_exception_free(&ev);
}
static void
@@ -216,110 +258,139 @@ xfer_folder (EvolutionShellComponent *shell_component,
void *closure)
{
CORBA_Environment ev;
- gchar *source_path;
- FILE *fin;
- icalparser *parser;
- icalcomponent *icalcomp;
- GnomeVFSHandle *handle;
- GnomeVFSURI *uri;
- GnomeVFSFileSize out;
- char *buf;
- const char *file_name;
+ GnomeVFSURI *src_uri;
+ GnomeVFSURI *dest_uri;
+ GnomeVFSResult result;
+ GList *file_list;
+ GList *l;
+ gboolean success = TRUE;
CORBA_exception_init (&ev);
- /* check URI */
- if (strncmp (source_physical_uri, "file://", 7)
- || strncmp (destination_physical_uri, "file://", 7)) {
+ /* check type */
+ if (strcmp (type, FOLDER_CALENDAR) && strcmp (type, FOLDER_TASKS)) {
GNOME_Evolution_ShellComponentListener_notifyResult (
listener,
- GNOME_Evolution_ShellComponentListener_INVALID_URI,
+ GNOME_Evolution_ShellComponentListener_UNSUPPORTED_TYPE,
&ev);
CORBA_exception_free (&ev);
return;
}
- file_name = get_local_file_name_for_folder_type (type);
- if (file_name == NULL) {
- GNOME_Evolution_ShellComponentListener_notifyResult (listener,
- GNOME_Evolution_ShellComponentListener_UNSUPPORTED_TYPE,
- &ev);
- CORBA_exception_free (&ev);
- return;
- }
-
- /* open source and destination files */
- source_path = g_concat_dir_and_file (source_physical_uri + 7, "calendar.ics");
-
- fin = fopen (source_path, "r");
- if (!fin) {
+ /* check URIs */
+ src_uri = gnome_vfs_uri_new_private (source_physical_uri, TRUE, TRUE, TRUE);
+ dest_uri = gnome_vfs_uri_new_private (destination_physical_uri, TRUE, TRUE, TRUE);
+ if (!src_uri || ! dest_uri) {
GNOME_Evolution_ShellComponentListener_notifyResult (
listener,
- GNOME_Evolution_ShellComponentListener_PERMISSION_DENIED,
- &ev);
- g_free (source_path);
- CORBA_exception_free (&ev);
- return;
- }
- parser = icalparser_new ();
- icalparser_set_gen_data (parser, fin);
- icalcomp = icalparser_parse (parser, get_line_fn);
- icalparser_free (parser);
- if (!icalcomp
- || icalcomponent_isa (icalcomp) != ICAL_VCALENDAR_COMPONENT) {
- GNOME_Evolution_ShellComponentListener_notifyResult (
- listener,
- GNOME_Evolution_ShellComponentListener_PERMISSION_DENIED,
+ GNOME_Evolution_ShellComponentListener_INVALID_URI,
&ev);
- fclose (fin);
- g_free (source_path);
- if (icalcomp)
- icalcomponent_free (icalcomp);
+ gnome_vfs_uri_unref (src_uri);
+ gnome_vfs_uri_unref (dest_uri);
CORBA_exception_free (&ev);
return;
}
- /* now, write the new file out */
- uri = gnome_vfs_uri_new (destination_physical_uri);
- if (gnome_vfs_create_uri (&handle, uri, GNOME_VFS_OPEN_WRITE, FALSE, 0666)
- != GNOME_VFS_OK) {
+ gnome_vfs_uri_unref (src_uri);
+ gnome_vfs_uri_unref (dest_uri);
+
+ /* remove all files in that directory */
+ result = gnome_vfs_directory_list_load (&file_list, source_physical_uri, 0, NULL);
+ if (result != GNOME_VFS_OK) {
GNOME_Evolution_ShellComponentListener_notifyResult (
listener,
GNOME_Evolution_ShellComponentListener_INVALID_URI,
- &ev);
- fclose (fin);
- g_free (source_path);
- icalcomponent_free (icalcomp);
+ &ev);
CORBA_exception_free (&ev);
return;
}
- buf = icalcomponent_as_ical_string (icalcomp);
- if (gnome_vfs_write (handle, buf, strlen (buf) * sizeof (char), &out)
- != GNOME_VFS_OK) {
- GNOME_Evolution_ShellComponentListener_notifyResult (
- listener,
- GNOME_Evolution_ShellComponentListener_PERMISSION_DENIED,
- &ev);
- }
- else {
- GNOME_Evolution_ShellComponentListener_notifyResult (
- listener,
- GNOME_Evolution_ShellComponentListener_OK,
- &ev);
- }
- gnome_vfs_close (handle);
- gnome_vfs_uri_unref (uri);
-
- /* free resources */
- fclose (fin);
-
- if (remove_source)
- unlink (source_path);
-
- g_free (source_path);
- icalcomponent_free (icalcomp);
- CORBA_exception_free (&ev);
+ for (l = file_list; l; l = l->next) {
+ GnomeVFSFileInfo *file_info;
+ GnomeVFSHandle *hin;
+ GnomeVFSHandle *hout;
+ gpointer buffer;
+ GnomeVFSFileSize size;
+
+ file_info = (GnomeVFSFileInfo *) l->data;
+ if (!file_info || file_info->name[0] == '.')
+ continue;
+
+ /* open source and destination files */
+ src_uri = gnome_vfs_uri_new_private (source_physical_uri, TRUE, TRUE, TRUE);
+ src_uri = gnome_vfs_uri_append_file_name (src_uri, file_info->name);
+
+ result = gnome_vfs_open_uri (&hin, src_uri, GNOME_VFS_OPEN_READ);
+ gnome_vfs_uri_unref (src_uri);
+ if (result != GNOME_VFS_OK) {
+ GNOME_Evolution_ShellComponentListener_notifyResult (
+ listener,
+ GNOME_Evolution_ShellComponentListener_PERMISSION_DENIED,
+ &ev);
+ success = FALSE;
+ break;
+ }
+
+ dest_uri = gnome_vfs_uri_new_private (destination_physical_uri, TRUE, TRUE, TRUE);
+ dest_uri = gnome_vfs_uri_append_file_name (dest_uri, file_info->name);
+
+ result = gnome_vfs_create_uri (&hout, dest_uri, GNOME_VFS_OPEN_WRITE, FALSE, 0);
+ gnome_vfs_uri_unref (dest_uri);
+ if (result != GNOME_VFS_OK) {
+ gnome_vfs_close (hin);
+ GNOME_Evolution_ShellComponentListener_notifyResult (
+ listener,
+ GNOME_Evolution_ShellComponentListener_PERMISSION_DENIED,
+ &ev);
+ success = FALSE;
+ break;
+ }
+
+ /* write source file to destination file */
+ buffer = g_malloc (file_info->size);
+ result = gnome_vfs_read (hin, buffer, file_info->size, &size);
+ if (result != GNOME_VFS_OK) {
+ gnome_vfs_close (hin);
+ gnome_vfs_close (hout);
+ g_free (buffer);
+
+ GNOME_Evolution_ShellComponentListener_notifyResult (
+ listener,
+ GNOME_Evolution_ShellComponentListener_PERMISSION_DENIED,
+ &ev);
+ success = FALSE;
+ break;
+ }
+ result = gnome_vfs_write (hout, buffer, file_info->size, &size);
+ if (result != GNOME_VFS_OK) {
+ gnome_vfs_close (hin);
+ gnome_vfs_close (hout);
+ g_free (buffer);
+
+ GNOME_Evolution_ShellComponentListener_notifyResult (
+ listener,
+ GNOME_Evolution_ShellComponentListener_PERMISSION_DENIED,
+ &ev);
+ success = FALSE;
+ break;
+ }
+
+ /* free memory */
+ gnome_vfs_close (hin);
+ gnome_vfs_close (hout);
+ g_free (buffer);
+ }
+
+ if (success) {
+ GNOME_Evolution_ShellComponentListener_notifyResult (
+ listener,
+ GNOME_Evolution_ShellComponentListener_OK,
+ &ev);
+ }
+
+ /* free memory */
+ gnome_vfs_file_info_list_free (file_list);
+ CORBA_exception_free (&ev);
}
static GList *shells = NULL;