diff options
author | Jon Trowbridge <trow@ximian.com> | 2001-10-25 08:37:00 +0800 |
---|---|---|
committer | Jon Trowbridge <trow@src.gnome.org> | 2001-10-25 08:37:00 +0800 |
commit | 0f9a7b1c32e4546e4990c40a27be55a8950e4c7c (patch) | |
tree | a2342706fe728746e6d2ca3c759dcb67f9b47860 /addressbook | |
parent | d9545bc20c23425f71583e8966f64fdb5c613941 (diff) | |
download | gsoc2013-evolution-0f9a7b1c32e4546e4990c40a27be55a8950e4c7c.tar gsoc2013-evolution-0f9a7b1c32e4546e4990c40a27be55a8950e4c7c.tar.gz gsoc2013-evolution-0f9a7b1c32e4546e4990c40a27be55a8950e4c7c.tar.bz2 gsoc2013-evolution-0f9a7b1c32e4546e4990c40a27be55a8950e4c7c.tar.lz gsoc2013-evolution-0f9a7b1c32e4546e4990c40a27be55a8950e4c7c.tar.xz gsoc2013-evolution-0f9a7b1c32e4546e4990c40a27be55a8950e4c7c.tar.zst gsoc2013-evolution-0f9a7b1c32e4546e4990c40a27be55a8950e4c7c.zip |
Initialize gnome-vfs.
2001-10-24 Jon Trowbridge <trow@ximian.com>
* gui/component/addressbook-factory.c (main): Initialize
gnome-vfs.
* gui/component/addressbook-component.c (xfer_file): Added.
(Copied from the calendar.)
(xfer_folder): Fixed to allow renaming of contact folders.
svn path=/trunk/; revision=14080
Diffstat (limited to 'addressbook')
-rw-r--r-- | addressbook/ChangeLog | 9 | ||||
-rw-r--r-- | addressbook/gui/component/Makefile.am | 2 | ||||
-rw-r--r-- | addressbook/gui/component/addressbook-component.c | 129 | ||||
-rw-r--r-- | addressbook/gui/component/addressbook-factory.c | 6 |
4 files changed, 134 insertions, 12 deletions
diff --git a/addressbook/ChangeLog b/addressbook/ChangeLog index 9cce046894..3850f1d622 100644 --- a/addressbook/ChangeLog +++ b/addressbook/ChangeLog @@ -1,3 +1,12 @@ +2001-10-24 Jon Trowbridge <trow@ximian.com> + + * gui/component/addressbook-factory.c (main): Initialize + gnome-vfs. + + * gui/component/addressbook-component.c (xfer_file): Added. + (Copied from the calendar.) + (xfer_folder): Fixed to allow renaming of contact folders. + 2001-10-24 Christopher James Lahey <clahey@ximian.com> * gui/widgets/e-addressbook-view.c diff --git a/addressbook/gui/component/Makefile.am b/addressbook/gui/component/Makefile.am index 68138c8390..8d8c7198bc 100644 --- a/addressbook/gui/component/Makefile.am +++ b/addressbook/gui/component/Makefile.am @@ -16,6 +16,7 @@ INCLUDES = \ -I$(top_srcdir)/addressbook/backend \ -I$(top_builddir)/addressbook/backend \ $(BONOBO_HTML_GNOME_CFLAGS) \ + $(GNOME_VFS_CFLAGS) \ -DEVOLUTION_DATADIR=\""$(datadir)"\" \ -DEVOLUTION_GLADEDIR=\""$(gladedir)"\" \ -DEVOLUTION_ICONSDIR=\""$(iconsdir)"\" \ @@ -49,6 +50,7 @@ evolution_addressbook_LDADD = \ $(top_builddir)/shell/libeshell.la \ $(EXTRA_GNOME_LIBS) \ $(BONOBO_HTML_GNOME_LIBS) \ + $(GNOME_VFS_LIBS) \ $(BONOBO_CONF_LIBS) \ $(top_builddir)/addressbook/gui/widgets/libeminicard.a \ $(top_builddir)/addressbook/backend/ebook/libebook.la \ diff --git a/addressbook/gui/component/addressbook-component.c b/addressbook/gui/component/addressbook-component.c index 43dcb6098f..62ef784ecd 100644 --- a/addressbook/gui/component/addressbook-component.c +++ b/addressbook/gui/component/addressbook-component.c @@ -25,6 +25,12 @@ #include <config.h> #endif +#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 <libgnomevfs/gnome-vfs-file-info.h> + #include <sys/types.h> #include <sys/stat.h> #include <errno.h> @@ -183,6 +189,92 @@ remove_folder (EvolutionShellComponent *shell_component, CORBA_exception_free(&ev); } +/* ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** */ + +/* This code is cut & pasted from calendar/gui/component-factory.c */ + +static GNOME_Evolution_ShellComponentListener_Result +xfer_file (GnomeVFSURI *base_src_uri, + GnomeVFSURI *base_dest_uri, + const char *file_name, + int remove_source) +{ + GnomeVFSURI *src_uri, *dest_uri; + GnomeVFSHandle *hin, *hout; + GnomeVFSResult result; + GnomeVFSFileInfo file_info; + GnomeVFSFileSize size; + char *buffer; + + src_uri = gnome_vfs_uri_append_file_name (base_src_uri, file_name); + + result = gnome_vfs_open_uri (&hin, src_uri, GNOME_VFS_OPEN_READ); + if (result == GNOME_VFS_ERROR_NOT_FOUND) { + gnome_vfs_uri_unref (src_uri); + return GNOME_Evolution_ShellComponentListener_OK; /* No need to xfer anything. */ + } + if (result != GNOME_VFS_OK) { + gnome_vfs_uri_unref (src_uri); + return GNOME_Evolution_ShellComponentListener_PERMISSION_DENIED; + } + + result = gnome_vfs_get_file_info_uri (src_uri, &file_info, GNOME_VFS_FILE_INFO_DEFAULT); + if (result != GNOME_VFS_OK) { + gnome_vfs_uri_unref (src_uri); + return GNOME_Evolution_ShellComponentListener_PERMISSION_DENIED; + } + + dest_uri = gnome_vfs_uri_append_file_name (base_dest_uri, file_name); + + result = gnome_vfs_create_uri (&hout, dest_uri, GNOME_VFS_OPEN_WRITE, FALSE, 0600); + if (result != GNOME_VFS_OK) { + gnome_vfs_close (hin); + gnome_vfs_uri_unref (src_uri); + gnome_vfs_uri_unref (dest_uri); + return GNOME_Evolution_ShellComponentListener_PERMISSION_DENIED; + } + + /* 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); + gnome_vfs_uri_unref (src_uri); + gnome_vfs_uri_unref (dest_uri); + g_free (buffer); + return GNOME_Evolution_ShellComponentListener_PERMISSION_DENIED; + } + + result = gnome_vfs_write (hout, buffer, file_info.size, &size); + if (result != GNOME_VFS_OK) { + gnome_vfs_close (hin); + gnome_vfs_close (hout); + gnome_vfs_uri_unref (src_uri); + gnome_vfs_uri_unref (dest_uri); + g_free (buffer); + return GNOME_Evolution_ShellComponentListener_PERMISSION_DENIED; + } + + if (remove_source) { + char *text_uri; + + /* Sigh, we have to do this as there is no gnome_vfs_unlink_uri(). :-( */ + + text_uri = gnome_vfs_uri_to_string (src_uri, GNOME_VFS_URI_HIDE_NONE); + result = gnome_vfs_unlink (text_uri); + g_free (text_uri); + } + + gnome_vfs_close (hin); + gnome_vfs_close (hout); + gnome_vfs_uri_unref (src_uri); + gnome_vfs_uri_unref (dest_uri); + g_free (buffer); + + return GNOME_Evolution_ShellComponentListener_OK; +} + static void xfer_folder (EvolutionShellComponent *shell_component, const char *source_physical_uri, @@ -193,8 +285,12 @@ xfer_folder (EvolutionShellComponent *shell_component, void *closure) { CORBA_Environment ev; - char *source_path; - char *destination_path; + + GnomeVFSURI *src_uri; + GnomeVFSURI *dest_uri; + GnomeVFSResult result; + + CORBA_exception_init (&ev); if (!IS_CONTACT_TYPE (type)) { GNOME_Evolution_ShellComponentListener_notifyResult (listener, @@ -212,6 +308,7 @@ xfer_folder (EvolutionShellComponent *shell_component, CORBA_exception_free(&ev); return; } + if (strncmp (source_physical_uri, "file://", 7) || strncmp (destination_physical_uri, "file://", 7)) { GNOME_Evolution_ShellComponentListener_notifyResult (listener, @@ -221,18 +318,28 @@ xfer_folder (EvolutionShellComponent *shell_component, return; } - /* strip the 'file://' from the beginning of each uri and add addressbook.db */ - source_path = g_concat_dir_and_file (source_physical_uri + 7, "addressbook.db"); - destination_path = g_concat_dir_and_file (destination_physical_uri + 7, "addressbook.db"); + /* check URIs */ + src_uri = gnome_vfs_uri_new (source_physical_uri); + dest_uri = gnome_vfs_uri_new (destination_physical_uri); + if (!src_uri || ! dest_uri) { + GNOME_Evolution_ShellComponentListener_notifyResult ( + listener, + GNOME_Evolution_ShellComponentListener_INVALID_URI, + &ev); + gnome_vfs_uri_unref (src_uri); + gnome_vfs_uri_unref (dest_uri); + CORBA_exception_free (&ev); + return; + } - CORBA_exception_init (&ev); + result = xfer_file (src_uri, dest_uri, "addressbook.db", remove_source); + + GNOME_Evolution_ShellComponentListener_notifyResult (listener, result, &ev); - /* XXX always fail for now, until the above stuff is written */ - GNOME_Evolution_ShellComponentListener_notifyResult (listener, GNOME_Evolution_ShellComponentListener_PERMISSION_DENIED, &ev); + gnome_vfs_uri_unref (src_uri); + gnome_vfs_uri_unref (dest_uri); - g_free (source_path); - g_free (destination_path); - CORBA_exception_free (&ev); + CORBA_exception_free (&ev); } static char* diff --git a/addressbook/gui/component/addressbook-factory.c b/addressbook/gui/component/addressbook-factory.c index d0172be328..d7a52c9a6d 100644 --- a/addressbook/gui/component/addressbook-factory.c +++ b/addressbook/gui/component/addressbook-factory.c @@ -15,6 +15,7 @@ #include <libgnomeui/gnome-init.h> #include <liboaf/liboaf.h> #include <bonobo/bonobo-main.h> +#include <libgnomevfs/gnome-vfs-init.h> #include <glade/glade.h> #include <gal/widgets/e-cursors.h> #include <e-util/e-passwords.h> @@ -65,6 +66,9 @@ main (int argc, char **argv) init_bonobo (argc, argv); + if (!gnome_vfs_init ()) + g_error (_("Could not initialize gnome-vfs")); + /* FIXME: Messy names here. This file should be `main.c'. `addressbook.c' should be `addressbook-control-factory.c' and the functions should be called `addressbook_control_factory_something()'. And `addressbook-component.c' @@ -88,7 +92,7 @@ main (int argc, char **argv) g_log_set_always_fatal (G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING); #endif - g_thread_init (NULL); + /*g_thread_init (NULL);*/ camel_type_init (); bonobo_main (); |