diff options
-rw-r--r-- | addressbook/ChangeLog | 21 | ||||
-rw-r--r-- | addressbook/backend/ebook/e-card.c | 18 | ||||
-rw-r--r-- | addressbook/backend/ebook/e-card.h | 1 | ||||
-rw-r--r-- | addressbook/gui/component/addressbook-component.c | 32 | ||||
-rw-r--r-- | addressbook/gui/component/addressbook.c | 47 | ||||
-rw-r--r-- | addressbook/gui/component/addressbook.h | 3 |
6 files changed, 102 insertions, 20 deletions
diff --git a/addressbook/ChangeLog b/addressbook/ChangeLog index 2bfab4a623..39b4f0173e 100644 --- a/addressbook/ChangeLog +++ b/addressbook/ChangeLog @@ -1,3 +1,24 @@ +2001-05-13 Chris Toshok <toshok@ximian.com> + + * gui/component/addressbook.h: add prototype for + addressbook_expand_uri. + + * gui/component/addressbook-component.c + (destination_folder_handle_drop): create an EBook for + @physical_uri. + (dnd_drop_book_open_cb): actually add the dropped cards. + + * gui/component/addressbook.c (addressbook_expand_uri): abstract + this code out from the set_prop method so we can use it in the + component. + (set_prop): call addressbook_expand_uri. + + * backend/ebook/e-card.c (e_card_load_cards_from_string): new + function. + + * backend/ebook/e-card.h: add prototype for + e_card_load_cards_from_string. + 2001-05-12 Chris Toshok <toshok@ximian.com> * gui/component/addressbook-component.c diff --git a/addressbook/backend/ebook/e-card.c b/addressbook/backend/ebook/e-card.c index 3845ac8227..55b91e26d7 100644 --- a/addressbook/backend/ebook/e-card.c +++ b/addressbook/backend/ebook/e-card.c @@ -2013,6 +2013,24 @@ e_card_load_cards_from_file(const char *filename) return list; } +GList * +e_card_load_cards_from_string(const char *str) +{ + VObject *vobj = Parse_MIME(str, strlen (str)); + GList *list = NULL; + while(vobj) { + VObject *next; + ECard *card = E_CARD(gtk_type_new(e_card_get_type())); + parse(card, vobj); + next = nextVObjectInList(vobj); + cleanVObject(vobj); + vobj = next; + list = g_list_prepend(list, card); + } + list = g_list_reverse(list); + return list; +} + void e_card_free_empty_lists (ECard *card) { diff --git a/addressbook/backend/ebook/e-card.h b/addressbook/backend/ebook/e-card.h index 3714324081..ae0ab3c1ef 100644 --- a/addressbook/backend/ebook/e-card.h +++ b/addressbook/backend/ebook/e-card.h @@ -154,6 +154,7 @@ gboolean e_card_email_match_string (const ECard /* Specialized functionality */ GList *e_card_load_cards_from_file (const char *filename); +GList *e_card_load_cards_from_string (const char *str); void e_card_free_empty_lists (ECard *card); enum _ECardDisposition { diff --git a/addressbook/gui/component/addressbook-component.c b/addressbook/gui/component/addressbook-component.c index 90a976473e..f27384dd36 100644 --- a/addressbook/gui/component/addressbook-component.c +++ b/addressbook/gui/component/addressbook-component.c @@ -35,6 +35,9 @@ #include "evolution-shell-component-dnd.h" #include "evolution-storage.h" +#include "ebook/e-book.h" +#include "ebook/e-card.h" + #include "addressbook-storage.h" #include "addressbook-component.h" #include "addressbook.h" @@ -273,6 +276,9 @@ owner_unset_cb (EvolutionShellComponent *shell_component, gtk_main_quit(); } + +/* Destination side DnD */ + static CORBA_boolean destination_folder_handle_motion (EvolutionShellComponentDndDestinationFolder *folder, const char *physical_uri, @@ -285,6 +291,18 @@ destination_folder_handle_motion (EvolutionShellComponentDndDestinationFolder *f return TRUE; } +static void +dnd_drop_book_open_cb (EBook *book, EBookStatus status, GList *card_list) +{ + GList *l; + + for (l = card_list; l; l = l->next) { + ECard *card = l->data; + + e_book_add_card (book, card, NULL /* XXX */, NULL); + } +} + static CORBA_boolean destination_folder_handle_drop (EvolutionShellComponentDndDestinationFolder *folder, const char *physical_uri, @@ -293,12 +311,24 @@ destination_folder_handle_drop (EvolutionShellComponentDndDestinationFolder *fol const GNOME_Evolution_ShellComponentDnd_Data * data, gpointer user_data) { + EBook *book; + GList *card_list; + char *expanded_uri; + if (action == GNOME_Evolution_ShellComponentDnd_ACTION_LINK) return FALSE; /* we can't create links in our addressbook format */ g_print ("in destination_folder_handle_drop (%s)\n", physical_uri); - g_print ("data = %s\n", data->bytes._buffer); + card_list = e_card_load_cards_from_string (data->bytes._buffer); + + expanded_uri = addressbook_expand_uri (physical_uri); + + book = e_book_new (); + e_book_load_uri (book, expanded_uri, + (EBookCallback)dnd_drop_book_open_cb, card_list); + + g_free (expanded_uri); return TRUE; } diff --git a/addressbook/gui/component/addressbook.c b/addressbook/gui/component/addressbook.c index 027a777621..3e3cf862da 100644 --- a/addressbook/gui/component/addressbook.c +++ b/addressbook/gui/component/addressbook.c @@ -510,6 +510,33 @@ get_prop (BonoboPropertyBag *bag, } } +char * +addressbook_expand_uri (const char *uri) +{ + char *new_uri; + + if (!strncmp (uri, "file:", 5)) { + if (strlen (uri + 7) > 3 + && !strcmp (uri + strlen(uri) - 3, ".db")) { + /* it's a .db file */ + new_uri = g_strdup (uri); + } + else { + char *file_name; + /* we assume it's a dir and glom addressbook.db onto the end. */ + file_name = g_concat_dir_and_file(uri + 7, "addressbook.db"); + new_uri = g_strdup_printf("file://%s", file_name); + g_free(file_name); + } + } + else { + new_uri = g_strdup (uri); + } + + return new_uri; +} + + static void set_prop (BonoboPropertyBag *bag, const BonoboArg *arg, @@ -538,25 +565,7 @@ set_prop (BonoboPropertyBag *bag, view->uri = g_strdup(BONOBO_ARG_GET_STRING (arg)); - if (!strncmp (view->uri, "file:", 5)) { - - if (strlen (view->uri + 7) > 3 - && !strcmp (view->uri + strlen(view->uri) - 3, ".db")) { - /* it's a .db file */ - uri_data = g_strdup (view->uri); - } - else { - char *file_name; - /* we assume it's a dir and glom addressbook.db onto the end. */ - file_name = g_concat_dir_and_file(view->uri + 7, "addressbook.db"); - uri_data = g_strdup_printf("file://%s", file_name); - g_free(file_name); - } - - } - else { - uri_data = g_strdup (view->uri); - } + uri_data = addressbook_expand_uri (view->uri); if (! e_book_load_uri (book, uri_data, book_open_cb, view)) printf ("error calling load_uri!\n"); diff --git a/addressbook/gui/component/addressbook.h b/addressbook/gui/component/addressbook.h index 66c5a7e4e6..717b40e150 100644 --- a/addressbook/gui/component/addressbook.h +++ b/addressbook/gui/component/addressbook.h @@ -3,6 +3,9 @@ #include <bonobo/bonobo-control.h> +/* expand file:///foo/foo/ to file:///foo/foo/addressbook.db */ +char * addressbook_expand_uri (const char *uri); + BonoboControl *addressbook_factory_new_control (void); void addressbook_factory_init (void); |