From b2b80d2f17b33f1dc48fdc0efd3db5d3e6e7908a Mon Sep 17 00:00:00 2001 From: Christopher James Lahey Date: Thu, 10 Aug 2000 03:05:55 +0000 Subject: Added a button to save to your addressbook. 2000-08-09 Christopher James Lahey * gui/minicard/e-minicard-control.c: Added a button to save to your addressbook. svn path=/trunk/; revision=4678 --- addressbook/ChangeLog | 5 +++ addressbook/gui/minicard/e-minicard-control.c | 57 ++++++++++++++++++++++++++- addressbook/gui/widgets/e-minicard-control.c | 57 ++++++++++++++++++++++++++- 3 files changed, 117 insertions(+), 2 deletions(-) (limited to 'addressbook') diff --git a/addressbook/ChangeLog b/addressbook/ChangeLog index 2f83d27c87..b93978d764 100644 --- a/addressbook/ChangeLog +++ b/addressbook/ChangeLog @@ -1,3 +1,8 @@ +2000-08-09 Christopher James Lahey + + * gui/minicard/e-minicard-control.c: Added a button to save to + your addressbook. + 2000-08-09 Cody Russell * gui/component/addressbook.c: Make the toolbar honor the user's diff --git a/addressbook/gui/minicard/e-minicard-control.c b/addressbook/gui/minicard/e-minicard-control.c index 5d6334a619..7c1838b568 100644 --- a/addressbook/gui/minicard/e-minicard-control.c +++ b/addressbook/gui/minicard/e-minicard-control.c @@ -1,3 +1,4 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ /* * e-minicard-control.c * @@ -11,6 +12,8 @@ #include #include +#include "addressbook/backend/ebook/e-book.h" + #include "e-minicard-control.h" #include "e-minicard-widget.h" #include "addressbook/backend/ebook/e-card.h" @@ -214,6 +217,45 @@ pstream_get_content_types (BonoboPersistStream *ps, void *closure, return bonobo_persist_generate_content_types (2, "text/vCard", "text/x-vCard"); } +static void +book_open_cb (EBook *book, EBookStatus status, gpointer closure) +{ + ECard *card = closure; + e_book_add_card(book, card, NULL, NULL); +} + +static void +save_in_addressbook(GtkWidget *button, EMinicardWidget *minicard) +{ + EBook *book; + gchar *path, *uri; + ECard *card; + + book = e_book_new (); + + if (!book) { + printf ("%s: %s(): Couldn't create EBook, bailing.\n", + __FILE__, + __FUNCTION__); + return; + } + + + path = g_concat_dir_and_file (g_get_home_dir (), + "evolution/local/Contacts/addressbook.db"); + uri = g_strdup_printf ("file://%s", path); + g_free (path); + + gtk_object_get(GTK_OBJECT(minicard), + "card", &card, + NULL); + + if (! e_book_load_uri (book, uri, book_open_cb, card)) { + printf ("error calling load_uri!\n"); + } + g_free(uri); +} + static BonoboObject * e_minicard_control_factory (BonoboGenericFactory *Factory, void *closure) { @@ -223,12 +265,25 @@ e_minicard_control_factory (BonoboGenericFactory *Factory, void *closure) BonoboControl *control; BonoboPersistStream *stream; GtkWidget *minicard; + GtkWidget *button; + GtkWidget *vbox; /* Create the control. */ + minicard = e_minicard_widget_new (); gtk_widget_show (minicard); - control = bonobo_control_new (minicard); + button = gtk_button_new_with_label(_("Save in addressbook")); + gtk_signal_connect(GTK_OBJECT(button), "clicked", + GTK_SIGNAL_FUNC(save_in_addressbook), minicard); + gtk_widget_show (button); + + vbox = gtk_vbox_new(FALSE, 0); + gtk_box_pack_start(GTK_BOX(vbox), minicard, TRUE, TRUE, 0); + gtk_box_pack_start(GTK_BOX(vbox), button, FALSE, FALSE, 0); + gtk_widget_show (vbox); + + control = bonobo_control_new (vbox); stream = bonobo_persist_stream_new (pstream_load, pstream_save, pstream_get_max_size, diff --git a/addressbook/gui/widgets/e-minicard-control.c b/addressbook/gui/widgets/e-minicard-control.c index 5d6334a619..7c1838b568 100644 --- a/addressbook/gui/widgets/e-minicard-control.c +++ b/addressbook/gui/widgets/e-minicard-control.c @@ -1,3 +1,4 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ /* * e-minicard-control.c * @@ -11,6 +12,8 @@ #include #include +#include "addressbook/backend/ebook/e-book.h" + #include "e-minicard-control.h" #include "e-minicard-widget.h" #include "addressbook/backend/ebook/e-card.h" @@ -214,6 +217,45 @@ pstream_get_content_types (BonoboPersistStream *ps, void *closure, return bonobo_persist_generate_content_types (2, "text/vCard", "text/x-vCard"); } +static void +book_open_cb (EBook *book, EBookStatus status, gpointer closure) +{ + ECard *card = closure; + e_book_add_card(book, card, NULL, NULL); +} + +static void +save_in_addressbook(GtkWidget *button, EMinicardWidget *minicard) +{ + EBook *book; + gchar *path, *uri; + ECard *card; + + book = e_book_new (); + + if (!book) { + printf ("%s: %s(): Couldn't create EBook, bailing.\n", + __FILE__, + __FUNCTION__); + return; + } + + + path = g_concat_dir_and_file (g_get_home_dir (), + "evolution/local/Contacts/addressbook.db"); + uri = g_strdup_printf ("file://%s", path); + g_free (path); + + gtk_object_get(GTK_OBJECT(minicard), + "card", &card, + NULL); + + if (! e_book_load_uri (book, uri, book_open_cb, card)) { + printf ("error calling load_uri!\n"); + } + g_free(uri); +} + static BonoboObject * e_minicard_control_factory (BonoboGenericFactory *Factory, void *closure) { @@ -223,12 +265,25 @@ e_minicard_control_factory (BonoboGenericFactory *Factory, void *closure) BonoboControl *control; BonoboPersistStream *stream; GtkWidget *minicard; + GtkWidget *button; + GtkWidget *vbox; /* Create the control. */ + minicard = e_minicard_widget_new (); gtk_widget_show (minicard); - control = bonobo_control_new (minicard); + button = gtk_button_new_with_label(_("Save in addressbook")); + gtk_signal_connect(GTK_OBJECT(button), "clicked", + GTK_SIGNAL_FUNC(save_in_addressbook), minicard); + gtk_widget_show (button); + + vbox = gtk_vbox_new(FALSE, 0); + gtk_box_pack_start(GTK_BOX(vbox), minicard, TRUE, TRUE, 0); + gtk_box_pack_start(GTK_BOX(vbox), button, FALSE, FALSE, 0); + gtk_widget_show (vbox); + + control = bonobo_control_new (vbox); stream = bonobo_persist_stream_new (pstream_load, pstream_save, pstream_get_max_size, -- cgit