From 2f7cca97077d08faefd8c1b84c1c051401bb0308 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rgen=20Scheibengruber?= Date: Mon, 21 Jul 2008 04:10:09 +0000 Subject: =?UTF-8?q?Committing=20on=20behalf=20of=20J=C3=B6rgen=20Scheibeng?= =?UTF-8?q?ruber=20=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 2008-05-24 Jörgen Scheibengruber * Makefile.am: * google-contacts-source.c (ensure_google_contacts_source_group), (remove_google_contacts_source_group), (on_username_entry_changed), (on_update_cb_toggled), (on_interval_sb_value_changed), (plugin_google_contacts): * google-contacts-source.h: * google-source.c (e_plugin_lib_enable): * org-gnome-evolution-google.eplug.xml: Added a UI for the addressbook part svn path=/trunk/; revision=35797 --- plugins/google-account-setup/ChangeLog | 12 + plugins/google-account-setup/Makefile.am | 5 +- .../google-account-setup/google-contacts-source.c | 264 +++++++++++++++++++++ .../google-account-setup/google-contacts-source.h | 30 +++ plugins/google-account-setup/google-source.c | 5 + .../org-gnome-evolution-google.eplug.xml | 12 +- 6 files changed, 324 insertions(+), 4 deletions(-) create mode 100644 plugins/google-account-setup/google-contacts-source.c create mode 100644 plugins/google-account-setup/google-contacts-source.h (limited to 'plugins/google-account-setup') diff --git a/plugins/google-account-setup/ChangeLog b/plugins/google-account-setup/ChangeLog index a1019c05e7..186c224f21 100644 --- a/plugins/google-account-setup/ChangeLog +++ b/plugins/google-account-setup/ChangeLog @@ -1,3 +1,15 @@ +2008-05-24 Jörgen Scheibengruber + + * Makefile.am: + * google-contacts-source.c (ensure_google_contacts_source_group), + (remove_google_contacts_source_group), (on_username_entry_changed), + (on_update_cb_toggled), (on_interval_sb_value_changed), + (plugin_google_contacts): + * google-contacts-source.h: + * google-source.c (e_plugin_lib_enable): + * org-gnome-evolution-google.eplug.xml: + Added a UI for the addressbook part + 2008-03-31 Suman Manjunath ** Fix for bug #346555 diff --git a/plugins/google-account-setup/Makefile.am b/plugins/google-account-setup/Makefile.am index 898083c65a..d1c385b172 100644 --- a/plugins/google-account-setup/Makefile.am +++ b/plugins/google-account-setup/Makefile.am @@ -1,5 +1,6 @@ INCLUDES = \ $(EVOLUTION_CALENDAR_CFLAGS) \ + $(EVOLUTION_ADDRESSBOOK_CFLAGS) \ -I . \ -I$(top_srcdir) \ -DCALDAV_GLADEDIR=\""$(gladedir)"\" @@ -10,7 +11,9 @@ plugin_DATA = org-gnome-evolution-google.eplug plugin_LTLIBRARIES = liborg-gnome-evolution-google.la liborg_gnome_evolution_google_la_SOURCES = \ - google-source.c + google-source.c \ + google-contacts-source.h \ + google-contacts-source.c liborg_gnome_evolution_google_la_LIBADD = \ $(EVOLUTION_CALENDAR_LIBS) \ diff --git a/plugins/google-account-setup/google-contacts-source.c b/plugins/google-account-setup/google-contacts-source.c new file mode 100644 index 0000000000..64d3363ea9 --- /dev/null +++ b/plugins/google-account-setup/google-contacts-source.c @@ -0,0 +1,264 @@ +/* + * Copyright 2008, Joergen Scheibengruber + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU Lesser General Public + * License as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#include +#include + +#include +#include + +#include + +#include +#include +#include + +#include +#include +#include +#include + +#include "google-contacts-source.h" + + +void +ensure_google_contacts_source_group (void) +{ + ESourceList *source_list; + ESourceGroup *group; + + source_list = e_source_list_new_for_gconf_default ("/apps/evolution/addressbook/sources"); + + if (source_list == NULL) { + return; + } + + group = e_source_list_peek_group_by_name (source_list, _("Google")); + + if (group == NULL) { + gboolean res; + + group = e_source_group_new (_("Google"), "google://"); + res = e_source_list_add_group (source_list, group, -1); + + if (res == FALSE) { + g_warning ("Could not add Google source group!"); + } else { + e_source_list_sync (source_list, NULL); + } + + g_object_unref (group); + } + g_object_unref (source_list); +} + +void +remove_google_contacts_source_group (void) +{ + ESourceList *source_list; + ESourceGroup *group; + + source_list = e_source_list_new_for_gconf_default ("/apps/evolution/addressbook/sources"); + + if (source_list == NULL) { + return; + } + + group = e_source_list_peek_group_by_name (source_list, _("Google")); + + if (group) { + GSList *sources; + + sources = e_source_group_peek_sources (group); + + if (NULL == sources) { + e_source_list_remove_group (source_list, group); + e_source_list_sync (source_list, NULL); + } + } + g_object_unref (source_list); +} + +static void +on_username_entry_changed (GtkEntry *entry, gpointer user_data) +{ + ESource *source = user_data; + const char *text; + char *username; + + text = gtk_entry_get_text (entry); + + if (strstr (text, "@")) { + username = g_strdup (text); + } else { + username = g_strdup_printf ("%s@gmail.com", text); + } + + e_source_set_relative_uri (source, username); + e_source_set_property (source, "username", username); + e_source_set_property (source, "auth", "plain/password"); + g_free (username); +} + +static void +on_update_cb_toggled (GtkToggleButton *tb, gpointer user_data) +{ + ESource *source = user_data; + GtkWidget *sb = g_object_get_data (G_OBJECT (tb), "sb"); + + gtk_widget_set_sensitive (sb, gtk_toggle_button_get_active (tb)); + if (gtk_toggle_button_get_active (tb)) { + gdouble value; + char *value_string; + + value = gtk_spin_button_get_value (GTK_SPIN_BUTTON (sb)); + value_string = g_strdup_printf ("%d", (int)(value * 60.0)); + e_source_set_property (source, "refresh-interval", value_string); + g_free (value_string); + } else { + e_source_set_property (source, "refresh-interval", "-1"); + } +} + +static void +on_interval_sb_value_changed (GtkSpinButton *sb, gpointer user_data) +{ + ESource *source = user_data; + gdouble value; + char *value_string; + + value = gtk_spin_button_get_value (sb); + value_string = g_strdup_printf ("%d", (int)(value * 60.0)); + e_source_set_property (source, "refresh-interval", value_string); + g_free (value_string); +} + +GtkWidget * +plugin_google_contacts (EPlugin *epl, + EConfigHookItemFactoryData *data) +{ + EABConfigTargetSource *t = (EABConfigTargetSource *) data->target; + ESource *source; + ESourceGroup *group; + const char *base_uri; + const char *username; + const char *refresh_interval_str; + int refresh_interval; + GtkWidget *parent; + GtkWidget *vbox; + + GtkWidget *section; + GtkWidget *vbox2; + + GtkWidget *hbox; + GtkWidget *spacer; + GtkWidget *label; + GtkWidget *username_entry; + + GtkWidget *update_cb; + GtkWidget *interval_sb; + + + source = t->source; + group = e_source_peek_group (source); + + base_uri = e_source_group_peek_base_uri (group); + + g_object_set_data_full (G_OBJECT (epl), "widget", NULL, + (GDestroyNotify)gtk_widget_destroy); + + if (strcmp (base_uri, "google://")) { + return NULL; + } + + /* Build up the UI */ + parent = data->parent; + vbox = gtk_widget_get_ancestor (gtk_widget_get_parent (parent), GTK_TYPE_VBOX); + + vbox2 = gtk_vbox_new (FALSE, 6); + gtk_box_pack_start (GTK_BOX (vbox), vbox2, FALSE, FALSE, 0); + + section = gtk_label_new (NULL); + gtk_label_set_markup (GTK_LABEL (section), _("Server")); + gtk_misc_set_alignment (GTK_MISC (section), 0.0, 0.0); + gtk_box_pack_start (GTK_BOX (vbox2), section, FALSE, FALSE, 0); + + hbox = gtk_hbox_new (FALSE, 10); + gtk_box_pack_start (GTK_BOX (vbox2), hbox, TRUE, TRUE, 0); + + spacer = gtk_label_new (" "); + gtk_box_pack_start (GTK_BOX (hbox), spacer, FALSE, FALSE, 0); + + label = gtk_label_new (_("Username:")); + gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0); + + username_entry = gtk_entry_new (); + username = e_source_get_property (source, "username"); + if (username) { + gtk_entry_set_text (GTK_ENTRY (username_entry), username); + } + gtk_box_pack_start (GTK_BOX (hbox), username_entry, TRUE, TRUE, 0); + + hbox = gtk_hbox_new (FALSE, 10); + gtk_box_pack_start (GTK_BOX (vbox2), hbox, TRUE, TRUE, 0); + + spacer = gtk_label_new (" "); + gtk_box_pack_start (GTK_BOX (hbox), spacer, FALSE, FALSE, 0); + + refresh_interval_str = e_source_get_property (source, "refresh-interval"); + if (refresh_interval_str && + (1 == sscanf (refresh_interval_str, "%d", &refresh_interval))) { + } else { + refresh_interval = -1; + } + update_cb = gtk_check_button_new_with_label (_("Update every")); + gtk_box_pack_start (GTK_BOX (hbox), update_cb, FALSE, FALSE, 0); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (update_cb), + refresh_interval > 0); + + interval_sb = gtk_spin_button_new_with_range (1, 60, 1); + gtk_widget_set_sensitive (interval_sb, + refresh_interval > 0); + gtk_spin_button_set_value (GTK_SPIN_BUTTON (interval_sb), + refresh_interval > 0 ? refresh_interval / 60 : 30); + gtk_box_pack_start (GTK_BOX (hbox), interval_sb, FALSE, FALSE, 0); + + label = gtk_label_new (_("minute(s)")); + gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0); + + gtk_widget_show_all (vbox2); + + g_object_set_data (G_OBJECT (update_cb), "sb", interval_sb); + g_object_set_data_full (G_OBJECT (epl), "widget", vbox2, + (GDestroyNotify)gtk_widget_destroy); + + g_signal_connect (G_OBJECT (username_entry), "changed", + G_CALLBACK (on_username_entry_changed), + source); + g_signal_connect (G_OBJECT (update_cb), "toggled", + G_CALLBACK (on_update_cb_toggled), + source); + g_signal_connect (G_OBJECT (interval_sb), "value-changed", + G_CALLBACK (on_interval_sb_value_changed), + source); + + return NULL; +} + + diff --git a/plugins/google-account-setup/google-contacts-source.h b/plugins/google-account-setup/google-contacts-source.h new file mode 100644 index 0000000000..17421fb232 --- /dev/null +++ b/plugins/google-account-setup/google-contacts-source.h @@ -0,0 +1,30 @@ +/* + * Copyright 2008, Joergen Scheibengruber + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU Lesser General Public + * License as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#ifndef __GOOGLE_CONTACTS_SOURCE_H__ +#define __GOOGLE_CONTACTS_SOURCE_H__ + +GtkWidget *plugin_google_contacts (EPlugin *epl, + EConfigHookItemFactoryData *data); + +void ensure_google_contacts_source_group (void); + +void remove_google_contacts_source_group (void); + +#endif diff --git a/plugins/google-account-setup/google-source.c b/plugins/google-account-setup/google-source.c index d586b3027e..7e73b5b8ba 100644 --- a/plugins/google-account-setup/google-source.c +++ b/plugins/google-account-setup/google-source.c @@ -41,6 +41,8 @@ #include #include +#include "google-contacts-source.h" + #define CALENDAR_LOCATION "http://www.google.com/calendar/feeds/" #define d(x) @@ -96,6 +98,9 @@ e_plugin_lib_enable (EPluginLib *ep, int enable) if (enable) { d(printf ("\n Google Eplugin starting up ...\n")); ensure_google_source_group (); + ensure_google_contacts_source_group (); + } else { + remove_google_contacts_source_group (); } return 0; diff --git a/plugins/google-account-setup/org-gnome-evolution-google.eplug.xml b/plugins/google-account-setup/org-gnome-evolution-google.eplug.xml index d6087ad748..a172ba8923 100644 --- a/plugins/google-account-setup/org-gnome-evolution-google.eplug.xml +++ b/plugins/google-account-setup/org-gnome-evolution-google.eplug.xml @@ -3,11 +3,17 @@ - <_description>A plugin to setup google calendar. - + + <_description>A plugin to setup google calendar and contacts. + - + + + + + + -- cgit v1.2.3