diff options
author | Christopher James Lahey <clahey@ximian.com> | 2002-02-14 03:35:38 +0800 |
---|---|---|
committer | Chris Lahey <clahey@src.gnome.org> | 2002-02-14 03:35:38 +0800 |
commit | c2bf443756e31fb5d360f81a265a4529ea64ebe4 (patch) | |
tree | 83253af071f5c73c4e3355df0e4e7f34df5a197e /addressbook/gui/widgets/e-addressbook-util.c | |
parent | 22c314f7226679706f06cbd9d2b7dcc0edaf7279 (diff) | |
download | gsoc2013-evolution-c2bf443756e31fb5d360f81a265a4529ea64ebe4.tar.gz gsoc2013-evolution-c2bf443756e31fb5d360f81a265a4529ea64ebe4.tar.zst gsoc2013-evolution-c2bf443756e31fb5d360f81a265a4529ea64ebe4.zip |
Finishing commit that failed in the middle:
2002-02-13 Christopher James Lahey <clahey@ximian.com>
* backend/ebook/e-book-util.c, backend/ebook/e-book-util.h
(e_book_expand_uri, e_book_load_address_book_by_uri,
e_book_use_address_book_by_uri): New functions that take a file://
url ending in the directory name and automatically append the
addressbook.db and do the appropriate thing.
* backend/pas/pas-backend-card-sexp.c,
backend/pas/pas-backend-card-sexp.h: Added copyright notice here.
* gui/component/addressbook-component.c
(destination_folder_handle_drop), gui/component/addressbook.c
(set_prop): Use e_book_expand_uri instead of
addressbook_expand_uri.
* gui/component/addressbook-storage.c: Fixed the fcntl include
here.
* gui/component/addressbook.c (ContactsCopyToFolder,
ContactsMoveToFolder): Added handlers for these two verbs.
* gui/component/addressbook.h: Removed addressbook_expand_uri in
favor of e_book_expand_uri.
* gui/widgets/e-addressbook-reflow-adapter.c (transfer_cards):
Added code to handle Move to and Copy to right click menu items.
* gui/widgets/e-addressbook-util.c,
gui/widgets/e-addressbook-util.h (e_addressbook_transfer_cards):
New function to pop up a dialog and transfer a set of cards to the
given folder.
* gui/widgets/e-addressbook-view.c,
gui/widgets/e-addressbook-view.h (display_view): Don't attach to
the view if it doesn't exist yet. We have to make this then
attach later.
(e_addressbook_view_copy_to_folder,
e_addressbook_view_move_to_folder): New functions utilizing
e_addressbook_transfer_cards.
(table_right_click): Add copy_to_folder and move_to_folder to the
right click menu for tables here.
(e_addressbook_view_discard_menus): Handle menu unmerging here.
* gui/widgets/e-minicard-view-widget.h (struct
_EMinicardViewWidget): Removed unused field.
svn path=/trunk/; revision=15711
Diffstat (limited to 'addressbook/gui/widgets/e-addressbook-util.c')
-rw-r--r-- | addressbook/gui/widgets/e-addressbook-util.c | 161 |
1 files changed, 160 insertions, 1 deletions
diff --git a/addressbook/gui/widgets/e-addressbook-util.c b/addressbook/gui/widgets/e-addressbook-util.c index c53e16a45c..ea01e4ec5b 100644 --- a/addressbook/gui/widgets/e-addressbook-util.c +++ b/addressbook/gui/widgets/e-addressbook-util.c @@ -20,11 +20,13 @@ */ #include <config.h> +#include "e-addressbook-util.h" #include <gnome.h> -#include "e-addressbook-util.h" #include "e-card-merging.h" +#include <shell/evolution-shell-client.h> +#include <addressbook/backend/ebook/e-book-util.h> void e_addressbook_error_dialog (const gchar *msg, EBookStatus status) @@ -222,3 +224,160 @@ e_addressbook_show_multiple_cards (EBook *book, } } } + + + +typedef struct CardCopyProcess_ CardCopyProcess; + +typedef void (*CardCopyDone) (CardCopyProcess *process); + +struct CardCopyProcess_ { + int count; + GList *cards; + EBook *source; + EBook *destination; + CardCopyDone done_cb; +}; + +static void +card_deleted_cb (EBook* book, EBookStatus status, gpointer user_data) +{ + if (status != E_BOOK_STATUS_SUCCESS) { + e_addressbook_error_dialog (_("Error removing card"), status); + } +} + +static void +do_delete (gpointer data, gpointer user_data) +{ + EBook *book = user_data; + ECard *card = data; + + e_book_remove_card(book, card, card_deleted_cb, NULL); +} + +static void +delete_cards (CardCopyProcess *process) +{ + g_list_foreach (process->cards, + do_delete, + process->source); +} + +static void +process_unref (CardCopyProcess *process) +{ + process->count --; + if (process->count == 0) { + if (process->done_cb) { + process->done_cb (process); + } + e_free_object_list(process->cards); + gtk_object_unref (GTK_OBJECT (process->source)); + gtk_object_unref (GTK_OBJECT (process->destination)); + g_free (process); + } +} + +static void +card_added_cb (EBook* book, EBookStatus status, const char *id, gpointer user_data) +{ + CardCopyProcess *process = user_data; + + if (status != E_BOOK_STATUS_SUCCESS) { + e_addressbook_error_dialog (_("Error adding card"), status); + } else { + process_unref (process); + } +} + +static void +do_copy (gpointer data, gpointer user_data) +{ + EBook *book; + ECard *card; + CardCopyProcess *process; + + process = user_data; + card = data; + + book = process->destination; + + process->count ++; + e_book_add_card(book, card, card_added_cb, process); +} + +static void +got_book_cb (EBook *book, gpointer closure) +{ + CardCopyProcess *process; + process = closure; + if (book) { + process->destination = book; + gtk_object_ref (GTK_OBJECT (book)); + g_list_foreach (process->cards, + do_copy, + process); + } + process_unref (process); +} + +void +e_addressbook_transfer_cards (EBook *source, GList *cards /* adopted */, gboolean delete_from_source, GtkWindow *parent_window) +{ + const char *allowed_types[] = { "contacts", NULL }; + extern EvolutionShellClient *global_shell_client; + char *uri, *physical, *path, *desc; + static char *last = NULL; + CardCopyProcess *process; + + if (cards == NULL) + return; + + if (last == NULL) + last = g_strdup (""); + + if (cards->next == NULL) { + if (delete_from_source) + desc = _("Move card to"); + else + desc = _("Copy card to"); + } else { + if (delete_from_source) + desc = _("Move cards to"); + else + desc = _("Copy cards to"); + } + + uri = NULL; + physical = NULL; + evolution_shell_client_user_select_folder (global_shell_client, + parent_window, + desc, last, + allowed_types, &uri, &physical); + if (!uri) + return; + + path = strchr (uri, '/'); + if (path && strcmp (last, path) != 0) { + g_free (last); + last = g_strdup_printf ("evolution:%s", path); + } + g_free (uri); + + process = g_new (CardCopyProcess, 1); + process->count = 1; + process->source = source; + gtk_object_ref (GTK_OBJECT (source)); + process->cards = cards; + process->destination = NULL; + + if (delete_from_source) + process->done_cb = delete_cards; + else + process->done_cb = NULL; + + e_book_use_address_book_by_uri (physical, got_book_cb, process); + + g_free(physical); +} |