diff options
-rw-r--r-- | modules/addressbook/Makefile.am | 2 | ||||
-rw-r--r-- | modules/addressbook/addressbook-config.c | 1357 | ||||
-rw-r--r-- | modules/addressbook/addressbook-config.h | 53 | ||||
-rw-r--r-- | modules/addressbook/autocompletion-config.c | 197 | ||||
-rw-r--r-- | modules/addressbook/e-book-shell-backend.c | 201 | ||||
-rw-r--r-- | modules/addressbook/e-book-shell-backend.h | 3 | ||||
-rw-r--r-- | modules/addressbook/e-book-shell-content.c | 8 | ||||
-rw-r--r-- | modules/addressbook/e-book-shell-migrate.c | 183 | ||||
-rw-r--r-- | modules/addressbook/e-book-shell-sidebar.c | 38 | ||||
-rw-r--r-- | modules/addressbook/e-book-shell-sidebar.h | 6 | ||||
-rw-r--r-- | modules/addressbook/e-book-shell-view-actions.c | 98 | ||||
-rw-r--r-- | modules/addressbook/e-book-shell-view-private.c | 71 | ||||
-rw-r--r-- | modules/addressbook/e-book-shell-view-private.h | 15 | ||||
-rw-r--r-- | modules/addressbook/e-book-shell-view.c | 80 | ||||
-rw-r--r-- | widgets/misc/Makefile.am | 2 | ||||
-rw-r--r-- | widgets/misc/e-autocomplete-selector.h | 64 |
16 files changed, 245 insertions, 2133 deletions
diff --git a/modules/addressbook/Makefile.am b/modules/addressbook/Makefile.am index 3c21012ec4..f18d871f0d 100644 --- a/modules/addressbook/Makefile.am +++ b/modules/addressbook/Makefile.am @@ -27,8 +27,6 @@ module_addressbook_la_CPPFLAGS = \ module_addressbook_la_SOURCES = \ evolution-module-addressbook.c \ - addressbook-config.c \ - addressbook-config.h \ autocompletion-config.c \ autocompletion-config.h \ eab-composer-util.c \ diff --git a/modules/addressbook/addressbook-config.c b/modules/addressbook/addressbook-config.c deleted file mode 100644 index 7e09c1b5da..0000000000 --- a/modules/addressbook/addressbook-config.c +++ /dev/null @@ -1,1357 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Chris Toshok <toshok@ximian.com> - * Chris Lahey <clahey@ximian.com> - * Michael Zucchi <notzed@ximian.com> - * And no doubt others ... - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -/*#define STANDALONE*/ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <string.h> -#include <stdlib.h> -#include <sys/time.h> - -#include <gtk/gtk.h> -#include <glib/gi18n.h> - -#ifdef G_OS_WIN32 -/* Include <windows.h> early and work around DATADIR lossage */ -#define DATADIR crap_DATADIR -#include <windows.h> -#undef DATADIR -#endif - -#include "addressbook-config.h" - -#include "e-util/e-util.h" -#include "libevolution-utils/e-alert-dialog.h" -#include "e-util/e-util-private.h" - -#include "addressbook/gui/widgets/eab-config.h" - -#define d(x) - -#ifdef HAVE_LDAP -#ifndef G_OS_WIN32 -#include <ldap.h> -#ifndef SUNLDAP -#include <ldap_schema.h> -#endif -#else -#include <winldap.h> -#include "openldap-extract.h" -#endif -#endif - -#define LDAP_PORT_STRING "389" -#define LDAPS_PORT_STRING "636" - -/* default objectclasses */ -#define TOP "top" -#define PERSON "person" -#define ORGANIZATIONALPERSON "organizationalPerson" -#define INETORGPERSON "inetOrgPerson" -#define EVOLUTIONPERSON "evolutionPerson" -#define CALENTRY "calEntry" - -typedef struct _AddressbookSourceDialog AddressbookSourceDialog; - -struct _AddressbookSourceDialog { - GtkBuilder *builder; - - EABConfig *config; /* the config manager */ - - GtkWidget *window; - - /* Source selection (assistant only) */ - ESourceList *source_list; - GSList *menu_source_groups; - - /* ESource we're currently editing */ - ESource *source; - /* The original source in edit mode. Also used to flag when we are in edit mode. */ - ESource *original_source; - - /* Source group we're creating/editing a source in */ - ESourceGroup *source_group; - - /* info page fields */ - GtkWidget *host; - GtkWidget *auth_combobox; - AddressbookLDAPAuthType auth; - GtkWidget *auth_principal; - - /* connecting page fields */ - GtkWidget *port_comboentry; - GtkWidget *ssl_combobox; - AddressbookLDAPSSLType ssl; - - /* searching page fields */ - GtkWidget *rootdn; - AddressbookLDAPScopeType scope; - GtkWidget *scope_combobox; - GtkWidget *search_filter; - GtkWidget *timeout_scale; - GtkWidget *limit_spinbutton; - GtkWidget *canbrowsecheck; - - /* display name page fields */ - GtkWidget *display_name; -}; - -#ifdef HAVE_LDAP - -static const gchar * -ldap_unparse_auth (AddressbookLDAPAuthType auth_type) -{ - switch (auth_type) { - case ADDRESSBOOK_LDAP_AUTH_NONE: - return "none"; - case ADDRESSBOOK_LDAP_AUTH_SIMPLE_EMAIL: - return "ldap/simple-email"; - case ADDRESSBOOK_LDAP_AUTH_SIMPLE_BINDDN: - return "ldap/simple-binddn"; - default: - g_return_val_if_reached ("none"); - } -} - -static AddressbookLDAPAuthType -ldap_parse_auth (const gchar *auth) -{ - if (!auth) - return ADDRESSBOOK_LDAP_AUTH_NONE; - - if (!strcmp (auth, "ldap/simple-email") || !strcmp (auth, "simple")) - return ADDRESSBOOK_LDAP_AUTH_SIMPLE_EMAIL; - else if (!strcmp (auth, "ldap/simple-binddn")) - return ADDRESSBOOK_LDAP_AUTH_SIMPLE_BINDDN; - else - return ADDRESSBOOK_LDAP_AUTH_NONE; -} - -static const gchar * -ldap_unparse_scope (AddressbookLDAPScopeType scope_type) -{ - switch (scope_type) { - case ADDRESSBOOK_LDAP_SCOPE_BASE: - return "base"; - case ADDRESSBOOK_LDAP_SCOPE_ONELEVEL: - return "one"; - case ADDRESSBOOK_LDAP_SCOPE_SUBTREE: - return "sub"; - default: - g_return_val_if_reached (""); - } -} - -static const gchar * -ldap_unparse_ssl (AddressbookLDAPSSLType ssl_type) -{ - switch (ssl_type) { - case ADDRESSBOOK_LDAP_SSL_NEVER: - return "never"; - case ADDRESSBOOK_LDAP_SSL_WHENEVER_POSSIBLE: - return "whenever_possible"; - case ADDRESSBOOK_LDAP_SSL_ALWAYS: - return "always"; - default: - g_return_val_if_reached (""); - } -} - -static AddressbookLDAPSSLType -ldap_parse_ssl (const gchar *ssl) -{ - if (!ssl) - return ADDRESSBOOK_LDAP_SSL_WHENEVER_POSSIBLE; - - if (!strcmp (ssl, "always")) - return ADDRESSBOOK_LDAP_SSL_ALWAYS; - else if (!strcmp (ssl, "whenever_possible")) - return ADDRESSBOOK_LDAP_SSL_WHENEVER_POSSIBLE; - else - return ADDRESSBOOK_LDAP_SSL_NEVER; -} - -static const gchar * -ldap_get_ssl_tooltip (AddressbookLDAPSSLType ssl_type) -{ - switch (ssl_type) { - case ADDRESSBOOK_LDAP_SSL_ALWAYS: - return _("Selecting this option means that Evolution will only connect to your LDAP server if your LDAP server supports SSL."); - case ADDRESSBOOK_LDAP_SSL_WHENEVER_POSSIBLE: - return _("Selecting this option means that Evolution will only connect to your LDAP server if your LDAP server supports TLS."); - case ADDRESSBOOK_LDAP_SSL_NEVER: - return _("Selecting this option means that your server does not support either SSL or TLS. This means that your connection will be insecure, and that you will be vulnerable to security exploits."); - } - - return NULL; -} - -static gboolean -source_to_uri_parts (ESource *source, - gchar **host, - gchar **rootdn, - AddressbookLDAPScopeType *scope, - gchar **search_filter, - gint *port) -{ - gchar *uri; - LDAPURLDesc *lud; - gint ldap_error; - - g_return_val_if_fail (source, FALSE); - - uri = e_source_get_uri (source); - ldap_error = ldap_url_parse ((gchar *) uri, &lud); - g_free (uri); - - if (ldap_error != LDAP_SUCCESS) - return FALSE; - - if (host) - *host = g_strdup (lud->lud_host ? lud->lud_host : ""); - if (rootdn) - *rootdn = g_strdup (lud->lud_dn ? lud->lud_dn : ""); - if (port) - *port = lud->lud_port ? lud->lud_port : LDAP_PORT; - if (scope) - *scope = lud->lud_scope == LDAP_SCOPE_BASE ? ADDRESSBOOK_LDAP_SCOPE_BASE : - lud->lud_scope == LDAP_SCOPE_ONELEVEL ? ADDRESSBOOK_LDAP_SCOPE_ONELEVEL : - lud->lud_scope == LDAP_SCOPE_SUBTREE ? ADDRESSBOOK_LDAP_SCOPE_SUBTREE : - ADDRESSBOOK_LDAP_SCOPE_ONELEVEL; - if (search_filter && lud->lud_filter) - *search_filter = g_strdup (lud->lud_filter); - - ldap_free_urldesc (lud); - return TRUE; -} - -static gboolean -source_group_is_remote (ESourceGroup *group) -{ - return strncmp ("ldap:", e_source_group_peek_base_uri (group), 5) == 0; -} - -/* ldap api foo */ -static LDAP * -addressbook_ldap_init (GtkWidget *window, - ESource *source) -{ - LDAP *ldap; - gchar *host; - gint port; - gint ldap_error; - gint protocol_version = LDAP_VERSION3; - - if (!source_to_uri_parts (source, &host, NULL, NULL, NULL, &port)) - return NULL; - - if (!(ldap = ldap_init (host, port))) { - e_alert_run_dialog_for_args ((GtkWindow *) window, "addressbook:ldap-init", NULL); - goto done; - } - - ldap_error = ldap_set_option (ldap, LDAP_OPT_PROTOCOL_VERSION, &protocol_version); - if (LDAP_SUCCESS != ldap_error) - g_warning ("failed to set protocol version to LDAPv3"); - - /* XXX do TLS if it's configured in */ - - done: - g_free (host); - return ldap; -} - -static gint -addressbook_ldap_auth (GtkWidget *window, - LDAP *ldap) -{ - gint ldap_error; - - /* XXX use auth info from source */ - ldap_error = ldap_simple_bind_s (ldap, NULL, NULL); - if (LDAP_SUCCESS != ldap_error) - e_alert_run_dialog_for_args ((GtkWindow *) window, "addressbook:ldap-auth", NULL); - - return ldap_error; -} - -static gint -addressbook_root_dse_query (AddressbookSourceDialog *dialog, - LDAP *ldap, - const gchar **attrs, - LDAPMessage **resp) -{ - GtkAdjustment *adjustment; - GtkRange *range; - gint ldap_error; - struct timeval timeout; - - range = GTK_RANGE (dialog->timeout_scale); - adjustment = gtk_range_get_adjustment (range); - - timeout.tv_sec = (gint) gtk_adjustment_get_value (adjustment); - timeout.tv_usec = 0; - - ldap_error = ldap_search_ext_s (ldap, - LDAP_ROOT_DSE, LDAP_SCOPE_BASE, - "(objectclass=*)", - (gchar **) attrs, 0, NULL, NULL, &timeout, LDAP_NO_LIMIT, resp); - if (LDAP_SUCCESS != ldap_error) - e_alert_run_dialog_for_args (GTK_WINDOW (dialog->window), "addressbook:ldap-search-base", NULL); - - return ldap_error; -} - -static gboolean -do_ldap_root_dse_query (AddressbookSourceDialog *sdialog, - GtkListStore *model, - ESource *source) -{ - LDAP *ldap; - const gchar *attrs[2]; - gint ldap_error; - gchar **values; - LDAPMessage *resp; - gint i; - - ldap = addressbook_ldap_init (sdialog->window, source); - if (!ldap) - return FALSE; - - if (LDAP_SUCCESS != addressbook_ldap_auth (sdialog->window, ldap)) - goto fail; - - attrs[0] = "namingContexts"; - attrs[1] = NULL; - - ldap_error = addressbook_root_dse_query (sdialog, ldap, attrs, &resp); - - if (ldap_error != LDAP_SUCCESS) - goto fail; - - values = ldap_get_values (ldap, resp, "namingContexts"); - if (!values || values[0] == NULL || strlen (values[0]) == 0) { - e_alert_run_dialog_for_args (GTK_WINDOW (sdialog->window), "addressbook:ldap-search-base", NULL); - goto fail; - } - - for (i = 0; values[i]; i++) { - GtkTreeIter iter; - - gtk_list_store_append (model, &iter); - gtk_list_store_set (model, &iter, 0, values[i], -1); - } - - ldap_value_free (values); - ldap_unbind_s (ldap); - return TRUE; - - fail: - ldap_unbind_s (ldap); - return FALSE; -} - -static void -search_base_selection_model_changed (GtkTreeSelection *selection, - GtkWidget *dialog) -{ - gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), - GTK_RESPONSE_OK, - gtk_tree_selection_get_selected (selection, NULL, NULL)); -} - -static void -query_for_supported_bases (GtkWidget *button, - AddressbookSourceDialog *sdialog) -{ - GtkTreeSelection *selection; - GtkTreeModel *model; - GtkWidget *dialog; - GtkWidget *container; - GtkWidget *supported_bases_table; - GtkBuilder *builder; - GtkTreeIter iter; - - builder = gtk_builder_new (); - e_load_ui_builder_definition (builder, "ldap-config.ui"); - - dialog = e_builder_get_widget (builder, "supported-bases-dialog"); - - gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (sdialog->window)); - gtk_window_set_modal (GTK_WINDOW (dialog), TRUE); - - gtk_widget_ensure_style (dialog); - - container = gtk_dialog_get_action_area (GTK_DIALOG (dialog)); - gtk_container_set_border_width (GTK_CONTAINER (container), 12); - - container = gtk_dialog_get_content_area (GTK_DIALOG (dialog)); - gtk_container_set_border_width (GTK_CONTAINER (container), 0); - - supported_bases_table = e_builder_get_widget (builder, "supported-bases-table"); - model = gtk_tree_view_get_model (GTK_TREE_VIEW (supported_bases_table)); - selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (supported_bases_table)); - g_signal_connect ( - selection, "changed", - G_CALLBACK (search_base_selection_model_changed), dialog); - search_base_selection_model_changed (selection, dialog); - - if (do_ldap_root_dse_query (sdialog, GTK_LIST_STORE (model), sdialog->source)) { - gtk_widget_show (dialog); - - if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_OK - && gtk_tree_selection_get_selected (selection, &model, &iter)) { - gchar *dn; - - gtk_tree_model_get (model, &iter, 0, &dn, -1); - gtk_entry_set_text ((GtkEntry *) sdialog->rootdn, dn); - g_free (dn); - } - } - - gtk_widget_destroy (dialog); -} - -#endif /* HAVE_LDAP */ - -GtkWidget * -addressbook_config_create_new_source (GtkWidget *parent) -{ - return addressbook_config_edit_source (parent, NULL); -} - -/* ********************************************************************** */ - -static void -eabc_type_changed (GtkComboBox *dropdown, - AddressbookSourceDialog *sdialog) -{ - gint id = gtk_combo_box_get_active (dropdown); - GtkTreeModel *model; - GtkTreeIter iter; - - model = gtk_combo_box_get_model (dropdown); - if (id == -1 || !gtk_tree_model_iter_nth_child (model, &iter, NULL, id)) - return; - - /* TODO: when we change the group type, we lose all of the pre-filled dialog info */ - - gtk_tree_model_get (model, &iter, 1, &sdialog->source_group, -1); - /* HACK: doesn't work if you don't do this */ - e_source_set_absolute_uri (sdialog->source, NULL); - e_source_set_group (sdialog->source, sdialog->source_group); - - /* BIG HACK: We load the defaults for each type here. - * I guess plugins will have to use the do it in their factory callbacks */ - if (!strncmp(e_source_group_peek_base_uri(sdialog->source_group), "groupwise:", 10)) { - GSList *l; - ESource *source; - gchar *tmp; - - l = e_source_group_peek_sources (sdialog->source_group); - if (l && l->data ) { - source = l->data; - e_source_set_property(sdialog->source, "auth", e_source_get_property(source, "auth")); - e_source_set_property(sdialog->source, "user", e_source_get_property(source, "user")); - e_source_set_property(sdialog->source, "user_ssl", e_source_get_property(source, "use_ssl")); - } - - e_source_set_property(sdialog->source, "auth-domain", "Groupwise"); - tmp = g_strconcat (";", e_source_get_display_name(sdialog->source), NULL); - e_source_set_relative_uri (sdialog->source, tmp); - g_free (tmp); -#ifdef HAVE_LDAP - } else if (!strncmp(e_source_group_peek_base_uri(sdialog->source_group), "ldap:", 5)) { - gchar *tmp; - - tmp = g_strdup_printf ("%s:%s/%s?" /* trigraph prevention */ "?%s", - "", LDAP_PORT_STRING, - "", - "one"); - e_source_set_relative_uri (sdialog->source, tmp); - g_free (tmp); - e_source_set_property(sdialog->source, "timeout", "3"); - e_source_set_property(sdialog->source, "limit", "100"); -#endif - } else { - e_source_set_relative_uri (sdialog->source, e_source_get_uid (sdialog->source)); - } - - e_config_target_changed ((EConfig *) sdialog->config, E_CONFIG_TARGET_CHANGED_REBUILD); -} - -static GtkWidget * -eabc_general_type (EConfig *ec, - EConfigItem *item, - GtkWidget *parent, - GtkWidget *old, - gint position, - gpointer data) -{ - AddressbookSourceDialog *sdialog = data; - GtkComboBox *dropdown; - GtkCellRenderer *cell; - GtkListStore *store; - GtkTreeIter iter; - GSList *l; - GtkWidget *w, *label; - gint i, row = 0; - - if (old) - return old; - - w = gtk_hbox_new (FALSE, 6); - label = gtk_label_new_with_mnemonic(_("_Type:")); - gtk_box_pack_start ((GtkBox *) w, label, FALSE, FALSE, 0); - - dropdown = (GtkComboBox *) gtk_combo_box_new (); - cell = gtk_cell_renderer_text_new (); - store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_POINTER); - i = 0; - for (l = sdialog->menu_source_groups; l; l = g_slist_next (l)) { - ESourceGroup *group = l->data; - - gtk_list_store_append (store, &iter); - gtk_list_store_set (store, &iter, 0, e_source_group_peek_name (group), 1, group, -1); - if (e_source_peek_group (sdialog->source) == group) - row = i; - i++; - } - - gtk_cell_layout_pack_start ((GtkCellLayout *) dropdown, cell, TRUE); - gtk_cell_layout_set_attributes((GtkCellLayout *)dropdown, cell, "text", 0, NULL); - gtk_combo_box_set_model (dropdown, (GtkTreeModel *) store); - gtk_combo_box_set_active (dropdown, -1); - gtk_combo_box_set_active (dropdown, row); - g_signal_connect ( - dropdown, "changed", - G_CALLBACK (eabc_type_changed), sdialog); - gtk_widget_show ((GtkWidget *) dropdown); - gtk_box_pack_start ((GtkBox *) w, (GtkWidget *) dropdown, TRUE, TRUE, 0); - gtk_label_set_mnemonic_widget ((GtkLabel *) label, (GtkWidget *) dropdown); - - gtk_box_pack_start ((GtkBox *) parent, (GtkWidget *) w, FALSE, FALSE, 0); - - gtk_widget_show_all (w); - - return (GtkWidget *) w; -} - -static void -name_changed_cb (GtkWidget *w, - AddressbookSourceDialog *sdialog) -{ - const gchar *text; - gchar *stripped_name; - gboolean changed; - - text = gtk_entry_get_text (GTK_ENTRY (sdialog->display_name)); - - stripped_name = g_strstrip (g_strdup (text)); - changed = g_strcmp0 (stripped_name, e_source_get_display_name (sdialog->source)) != 0; - e_source_set_name (sdialog->source, stripped_name); - g_free (stripped_name); - - if (changed && g_strcmp0 ("system", e_source_peek_relative_uri (sdialog->source)) == 0) - e_source_set_property (sdialog->source, "name-changed", "true"); -} - -static GtkWidget * -eabc_general_name (EConfig *ec, - EConfigItem *item, - GtkWidget *parent, - GtkWidget *old, - gint position, - gpointer data) -{ - AddressbookSourceDialog *sdialog = data; - const gchar *uri; - GtkWidget *w; - GtkBuilder *builder; - - if (old) - return old; - - builder = gtk_builder_new (); - e_load_ui_builder_definition (builder, "ldap-config.ui"); - - w = e_builder_get_widget (builder, item->label); - gtk_box_pack_start ((GtkBox *) parent, w, FALSE, FALSE, 0); - - sdialog->display_name = e_builder_get_widget (builder, "account-editor-display-name-entry"); - g_signal_connect ( - sdialog->display_name, "changed", - G_CALLBACK (name_changed_cb), sdialog); - gtk_entry_set_text ((GtkEntry *) sdialog->display_name, e_source_get_display_name (sdialog->source)); - - /* Hardcoded: groupwise can't edit the name (or anything else) */ - if (sdialog->original_source) { - uri = e_source_group_peek_base_uri (sdialog->source_group); - if (uri && strncmp(uri, "groupwise:", 10) == 0) { - gtk_widget_set_sensitive (GTK_WIDGET (sdialog->display_name), FALSE); - } - } - - g_object_unref (builder); - - return w; -} - -/* TODO: This should be moved to plugins if B&A calendar setup is moved there */ -static void -use_in_cal_changed_cb (GtkWidget *widget, - AddressbookSourceDialog *sdialog) -{ - e_source_set_property (sdialog->source, "use-in-contacts-calendar", gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)) ? "1" : "0"); -} - -static GtkWidget * -eabc_general_use_in_cal (EConfig *ec, - EConfigItem *item, - GtkWidget *parent, - GtkWidget *old, - gint position, - gpointer data) -{ - AddressbookSourceDialog *sdialog = data; - GtkWidget *use_in_cal_setting; - const gchar *use_in_cal, *base_uri = NULL; - ESourceGroup *group; - - if (old) - return old; - - use_in_cal_setting = gtk_check_button_new_with_mnemonic (_("U_se in Birthday & Anniversaries calendar")); - gtk_widget_show (use_in_cal_setting); - gtk_container_add (GTK_CONTAINER (parent), use_in_cal_setting); - - use_in_cal = e_source_get_property (sdialog->source, "use-in-contacts-calendar"); - group = e_source_peek_group (sdialog->source); - - if (group) - base_uri = e_source_group_peek_base_uri (group); - - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (use_in_cal_setting), (use_in_cal && g_str_equal (use_in_cal, "1")) || (!use_in_cal && base_uri && g_str_has_prefix (base_uri, "local:"))); - - g_signal_connect ( - use_in_cal_setting, "toggled", - G_CALLBACK (use_in_cal_changed_cb), sdialog); - - return use_in_cal_setting; -} - -static void -offline_status_changed_cb (GtkWidget *widget, - AddressbookSourceDialog *sdialog) -{ - e_source_set_property (sdialog->source, "offline_sync", gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)) ? "1" : "0"); -} - -static GtkWidget * -eabc_general_offline (EConfig *ec, - EConfigItem *item, - GtkWidget *parent, - GtkWidget *old, - gint position, - gpointer data) -{ - AddressbookSourceDialog *sdialog = data; - GtkWidget *offline_setting; - const gchar *offline_sync; - gboolean is_local_book; - - is_local_book = g_str_has_prefix (e_source_group_peek_base_uri (sdialog->source_group), "local:"); - offline_sync = e_source_get_property (sdialog->source, "offline_sync"); - if (old) - return old; - else { - offline_setting = gtk_check_button_new_with_mnemonic (_("Copy _book content locally for offline operation")); - gtk_widget_show (offline_setting); - gtk_container_add (GTK_CONTAINER (parent), offline_setting); - g_signal_connect ( - offline_setting, "toggled", - G_CALLBACK (offline_status_changed_cb), sdialog); - - } - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (offline_setting), (offline_sync && g_str_equal (offline_sync, "1")) ? TRUE : FALSE); - if (is_local_book) - gtk_widget_hide (offline_setting); - return offline_setting; - -} - -#ifdef HAVE_LDAP -static gchar * -form_ldap_search_filter (GtkWidget *w) -{ - gchar *filter; - const gchar *search_filter = gtk_entry_get_text ((GtkEntry *) w); - - /* this function can be used to format the search filter entered */ - if ((strlen (search_filter) !=0) && *search_filter != '(' && *(search_filter + (strlen (search_filter - 1))) != ')') - filter = g_strdup_printf ("(%s)", search_filter); - else - filter = g_strdup_printf ("%s", search_filter); - - return filter; -} - -static void -url_changed (AddressbookSourceDialog *sdialog) -{ - gchar *str, *search_filter; - - search_filter = form_ldap_search_filter (sdialog->search_filter); - str = g_strdup_printf ("%s:%s/%s?" /* trigraph prevention */ "?%s?%s", - gtk_entry_get_text (GTK_ENTRY (sdialog->host)), - gtk_entry_get_text (GTK_ENTRY (gtk_bin_get_child (GTK_BIN (sdialog->port_comboentry)))), - gtk_entry_get_text (GTK_ENTRY (sdialog->rootdn)), - ldap_unparse_scope (sdialog->scope), - search_filter); - e_source_set_relative_uri (sdialog->source, str); - g_free (search_filter); - g_free (str); -} - -static void -host_changed_cb (GtkWidget *w, - AddressbookSourceDialog *sdialog) -{ - url_changed (sdialog); -} - -static void -port_entry_changed_cb (GtkWidget *w, - AddressbookSourceDialog *sdialog) -{ - const gchar *port = gtk_entry_get_text ((GtkEntry *) w); - - if (!strcmp (port, LDAPS_PORT_STRING)) { - sdialog->ssl = ADDRESSBOOK_LDAP_SSL_ALWAYS; - gtk_combo_box_set_active (GTK_COMBO_BOX (sdialog->ssl_combobox), sdialog->ssl); - gtk_widget_set_sensitive (sdialog->ssl_combobox, FALSE); - } else { - gtk_widget_set_sensitive (sdialog->ssl_combobox, TRUE); - } - - url_changed (sdialog); -} - -static void -ssl_combobox_changed_cb (GtkWidget *w, - AddressbookSourceDialog *sdialog) -{ - sdialog->ssl = gtk_combo_box_get_active (GTK_COMBO_BOX (w)); - e_source_set_property (sdialog->source, "ssl", ldap_unparse_ssl (sdialog->ssl)); - - gtk_widget_set_tooltip_text (sdialog->ssl_combobox, ldap_get_ssl_tooltip (sdialog->ssl)); -} - -static GtkWidget * -eabc_general_host (EConfig *ec, - EConfigItem *item, - GtkWidget *parent, - GtkWidget *old, - gint position, - gpointer data) -{ - AddressbookSourceDialog *sdialog = data; - const gchar *tmp; - GtkWidget *w; - gchar *uri, port[16]; - LDAPURLDesc *lud; - GtkBuilder *builder; - - if (!source_group_is_remote (sdialog->source_group)) - return NULL; - - builder = gtk_builder_new (); - e_load_ui_builder_definition (builder, "ldap-config.ui"); - - w = e_builder_get_widget (builder, item->label); - gtk_box_pack_start ((GtkBox *) parent, w, FALSE, FALSE, 0); - - uri = e_source_get_uri (sdialog->source); - if (ldap_url_parse (uri, &lud) != LDAP_SUCCESS) - lud = NULL; - g_free (uri); - - sdialog->host = e_builder_get_widget (builder, "server-name-entry"); - gtk_entry_set_text((GtkEntry *)sdialog->host, lud && lud->lud_host ? lud->lud_host : ""); - g_signal_connect ( - sdialog->host, "changed", - G_CALLBACK (host_changed_cb), sdialog); - - sdialog->port_comboentry = e_builder_get_widget (builder, "port-comboentry"); - gtk_widget_set_has_tooltip (sdialog->port_comboentry, TRUE); - gtk_widget_set_tooltip_text (sdialog->port_comboentry, _("This is the port on the LDAP server that Evolution will try to connect to. A list of standard ports has been provided. Ask your system administrator what port you should specify.")); - sprintf(port, "%u", lud && lud->lud_port? lud->lud_port : LDAP_PORT); - gtk_entry_set_text (GTK_ENTRY (gtk_bin_get_child (GTK_BIN (sdialog->port_comboentry))), port); - g_signal_connect ( - gtk_bin_get_child ( - GTK_BIN (sdialog->port_comboentry)), "changed", - G_CALLBACK (port_entry_changed_cb), sdialog); - - if (lud) - ldap_free_urldesc (lud); - - sdialog->ssl_combobox = e_builder_get_widget (builder, "ssl-combobox"); - gtk_widget_set_has_tooltip (sdialog->ssl_combobox, TRUE); - tmp = e_source_get_property (sdialog->source, "ssl"); - sdialog->ssl = ldap_parse_ssl (tmp); - gtk_combo_box_set_active (GTK_COMBO_BOX (sdialog->ssl_combobox), sdialog->ssl); - gtk_widget_set_tooltip_text (sdialog->ssl_combobox, ldap_get_ssl_tooltip (sdialog->ssl)); - gtk_widget_set_sensitive (sdialog->ssl_combobox, strcmp (port, LDAPS_PORT_STRING) != 0); - g_signal_connect ( - sdialog->ssl_combobox, "changed", - G_CALLBACK (ssl_combobox_changed_cb), sdialog); - - g_object_unref (builder); - - return w; -} - -static void -auth_entry_changed_cb (GtkWidget *w, - AddressbookSourceDialog *sdialog) -{ - const gchar *principal = gtk_entry_get_text ((GtkEntry *) w); - - /* seems messy ... but the api is */ - switch (sdialog->auth) { - case ADDRESSBOOK_LDAP_AUTH_SIMPLE_BINDDN: - e_source_set_property(sdialog->source, "email_addr", NULL); - e_source_set_property(sdialog->source, "binddn", principal); - break; - case ADDRESSBOOK_LDAP_AUTH_SIMPLE_EMAIL: - e_source_set_property(sdialog->source, "binddn", NULL); - e_source_set_property(sdialog->source, "email_addr", principal); - break; - case ADDRESSBOOK_LDAP_AUTH_NONE: - default: - e_source_set_property(sdialog->source, "email_addr", NULL); - e_source_set_property(sdialog->source, "binddn", NULL); - break; - } -} - -static void -auth_combobox_changed_cb (GtkWidget *w, - AddressbookSourceDialog *sdialog) -{ - sdialog->auth = gtk_combo_box_get_active (GTK_COMBO_BOX (w)); - e_source_set_property (sdialog->source, "auth", ldap_unparse_auth (sdialog->auth)); - - /* make sure the right property is set for the auth - ugh, funny api */ - auth_entry_changed_cb (sdialog->auth_principal, sdialog); -} - -static GtkWidget * -eabc_general_auth (EConfig *ec, - EConfigItem *item, - GtkWidget *parent, - GtkWidget *old, - gint position, - gpointer data) -{ - AddressbookSourceDialog *sdialog = data; - GtkWidget *w; - const gchar *tmp; - GtkBuilder *builder; - - if (!source_group_is_remote (sdialog->source_group)) - return NULL; - - builder = gtk_builder_new (); - e_load_ui_builder_definition (builder, "ldap-config.ui"); - - w = e_builder_get_widget (builder, item->label); - gtk_box_pack_start ((GtkBox *) parent, w, FALSE, FALSE, 0); - - sdialog->auth_combobox = e_builder_get_widget (builder, "auth-combobox"); - gtk_widget_set_has_tooltip (sdialog->auth_combobox, TRUE); - gtk_widget_set_tooltip_text (sdialog->auth_combobox, _("This is the method Evolution will use to authenticate you. Note that setting this to \"Email Address\" requires anonymous access to your LDAP server.")); - tmp = e_source_get_property(sdialog->source, "auth"); - sdialog->auth = tmp ? ldap_parse_auth (tmp) : ADDRESSBOOK_LDAP_AUTH_NONE; - gtk_combo_box_set_active (GTK_COMBO_BOX (sdialog->auth_combobox), sdialog->auth); - g_signal_connect ( - sdialog->auth_combobox, "changed", - G_CALLBACK (auth_combobox_changed_cb), sdialog); - - sdialog->auth_principal = e_builder_get_widget (builder, "auth-entry"); - switch (sdialog->auth) { - case ADDRESSBOOK_LDAP_AUTH_SIMPLE_EMAIL: - tmp = e_source_get_property(sdialog->source, "email_addr"); - break; - case ADDRESSBOOK_LDAP_AUTH_SIMPLE_BINDDN: - tmp = e_source_get_property(sdialog->source, "binddn"); - break; - case ADDRESSBOOK_LDAP_AUTH_NONE: - default: - tmp = ""; - break; - } - gtk_entry_set_text((GtkEntry *)sdialog->auth_principal, tmp?tmp:""); - g_signal_connect ( - sdialog->auth_principal, "changed", - G_CALLBACK (auth_entry_changed_cb), sdialog); - - g_object_unref (builder); - - return w; -} - -static void -rootdn_changed_cb (GtkWidget *w, - AddressbookSourceDialog *sdialog) -{ - url_changed (sdialog); -} - -static void -search_filter_changed_cb (GtkWidget *w, - AddressbookSourceDialog *sdialog) -{ - url_changed (sdialog); -} - -static void -scope_combobox_changed_cb (GtkWidget *w, - AddressbookSourceDialog *sdialog) -{ - sdialog->scope = gtk_combo_box_get_active (GTK_COMBO_BOX (w)); - url_changed (sdialog); -} - -static GtkWidget * -eabc_details_search (EConfig *ec, - EConfigItem *item, - GtkWidget *parent, - GtkWidget *old, - gint position, - gpointer data) -{ - AddressbookSourceDialog *sdialog = data; - GtkWidget *w; - LDAPURLDesc *lud; - gchar *uri; - GtkBuilder *builder; - - if (!source_group_is_remote (sdialog->source_group)) - return NULL; - - builder = gtk_builder_new (); - e_load_ui_builder_definition (builder, "ldap-config.ui"); - - w = e_builder_get_widget (builder, item->label); - gtk_box_pack_start ((GtkBox *) parent, w, FALSE, FALSE, 0); - - uri = e_source_get_uri (sdialog->source); - if (ldap_url_parse (uri, &lud) != LDAP_SUCCESS) - lud = NULL; - g_free (uri); - - sdialog->rootdn = e_builder_get_widget (builder, "rootdn-entry"); - gtk_entry_set_text((GtkEntry *)sdialog->rootdn, lud && lud->lud_dn ? lud->lud_dn : ""); - g_signal_connect ( - sdialog->rootdn, "changed", - G_CALLBACK (rootdn_changed_cb), sdialog); - - sdialog->scope_combobox = e_builder_get_widget (builder, "scope-combobox"); - gtk_widget_set_has_tooltip (sdialog->scope_combobox, TRUE); - gtk_widget_set_tooltip_text (sdialog->scope_combobox, _("The search scope defines how deep you would like the search to extend down the directory tree. A search scope of \"sub\" will include all entries below your search base. A search scope of \"one\" will only include the entries one level beneath your base.")); - if (lud) { - switch (lud->lud_scope) { - case LDAP_SCOPE_BASE: - sdialog->scope = ADDRESSBOOK_LDAP_SCOPE_BASE; - break; - default: - case LDAP_SCOPE_ONELEVEL: - sdialog->scope = ADDRESSBOOK_LDAP_SCOPE_ONELEVEL; - break; - case LDAP_SCOPE_SUBTREE: - sdialog->scope = ADDRESSBOOK_LDAP_SCOPE_SUBTREE; - break; - } - } - gtk_combo_box_set_active (GTK_COMBO_BOX (sdialog->scope_combobox), sdialog->scope); - g_signal_connect ( - sdialog->scope_combobox, "changed", - G_CALLBACK (scope_combobox_changed_cb), sdialog); - - sdialog->search_filter = e_builder_get_widget (builder, "search-filter-entry"); - gtk_entry_set_text((GtkEntry *)sdialog->search_filter, lud && lud->lud_filter ? lud->lud_filter : ""); - g_signal_connect ( - sdialog->search_filter, "changed", - G_CALLBACK (search_filter_changed_cb), sdialog); - - g_signal_connect ( - e_builder_get_widget (builder, "rootdn-button"), "clicked", - G_CALLBACK (query_for_supported_bases), sdialog); - - if (lud) - ldap_free_urldesc (lud); - - g_object_unref (builder); - - return w; -} - -static void -timeout_changed_cb (GtkWidget *w, - AddressbookSourceDialog *sdialog) -{ - GtkAdjustment *adjustment; - GtkRange *range; - gchar *timeout; - - range = GTK_RANGE (sdialog->timeout_scale); - adjustment = gtk_range_get_adjustment (range); - timeout = g_strdup_printf("%f", gtk_adjustment_get_value (adjustment)); - e_source_set_property(sdialog->source, "timeout", timeout); - g_free (timeout); -} - -static void -limit_changed_cb (GtkWidget *w, - AddressbookSourceDialog *sdialog) -{ - gchar limit[16]; - - sprintf(limit, "%d", gtk_spin_button_get_value_as_int((GtkSpinButton *)sdialog->limit_spinbutton)); - e_source_set_property(sdialog->source, "limit", limit); -} - -static void -canbrowse_toggled_cb (GtkWidget *toggle_button, - ESource *source) -{ - if (!source || !toggle_button) - return; - - e_source_set_property (source, "can-browse", gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (toggle_button)) ? "1" : NULL); -} - -static GtkWidget * -eabc_details_limit (EConfig *ec, - EConfigItem *item, - GtkWidget *parent, - GtkWidget *old, - gint position, - gpointer data) -{ - AddressbookSourceDialog *sdialog = data; - GtkAdjustment *adjustment; - GtkRange *range; - GtkWidget *w; - const gchar *tmp; - GtkBuilder *builder; - - if (!source_group_is_remote (sdialog->source_group)) - return NULL; - - builder = gtk_builder_new (); - e_load_ui_builder_definition (builder, "ldap-config.ui"); - - w = e_builder_get_widget (builder, item->label); - gtk_box_pack_start ((GtkBox *) parent, w, FALSE, FALSE, 0); - - sdialog->timeout_scale = e_builder_get_widget (builder, "timeout-scale"); - range = GTK_RANGE (sdialog->timeout_scale); - adjustment = gtk_range_get_adjustment (range); - tmp = e_source_get_property(sdialog->source, "timeout"); - gtk_adjustment_set_value (adjustment, tmp ? g_strtod (tmp, NULL) : 3.0); - g_signal_connect ( - adjustment, "value_changed", - G_CALLBACK (timeout_changed_cb), sdialog); - - sdialog->limit_spinbutton = e_builder_get_widget (builder, "download-limit-spinbutton"); - tmp = e_source_get_property(sdialog->source, "limit"); - gtk_spin_button_set_value ((GtkSpinButton *) sdialog->limit_spinbutton, tmp ? g_strtod (tmp, NULL) : 100.0); - g_signal_connect ( - sdialog->limit_spinbutton, "value_changed", - G_CALLBACK (limit_changed_cb), sdialog); - - sdialog->canbrowsecheck = e_builder_get_widget (builder, "canbrowsecheck"); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (sdialog->canbrowsecheck), e_source_get_property (sdialog->source, "can-browse") && strcmp (e_source_get_property (sdialog->source, "can-browse"), "1") == 0); - g_signal_connect ( - sdialog->canbrowsecheck, "toggled", - G_CALLBACK (canbrowse_toggled_cb), sdialog->source); - - g_object_unref (builder); - - return w; -} -#endif - -static EConfigItem eabc_items[] = { - { E_CONFIG_BOOK, (gchar *) (gchar *) "", }, - { E_CONFIG_PAGE, (gchar *) "00.general", (gchar *) N_("General") }, - { E_CONFIG_SECTION, (gchar *) "00.general/10.display", (gchar *) N_("Address Book") }, - { E_CONFIG_ITEM, (gchar *) "00.general/10.display/10.name", (gchar *) "hbox122", eabc_general_name }, - { E_CONFIG_ITEM, (gchar *) "00.general/10.display/20.calendar", NULL, eabc_general_use_in_cal }, - { E_CONFIG_ITEM, (gchar *) "00.general/10.display/30.offline", NULL, eabc_general_offline }, -#ifdef HAVE_LDAP - { E_CONFIG_SECTION, (gchar *) "00.general/20.server", (gchar *) N_("Server Information") }, - { E_CONFIG_ITEM, (gchar *) "00.general/20.server/00.host", (gchar *) "table31", eabc_general_host }, - { E_CONFIG_SECTION, (gchar *) "00.general/30.auth", (gchar *) N_("Authentication") }, - { E_CONFIG_ITEM, (gchar *) "00.general/30.auth/00.auth", (gchar *) "table32", eabc_general_auth }, - - { E_CONFIG_PAGE, (gchar *) "10.details", (gchar *) N_("Details") }, - { E_CONFIG_SECTION, (gchar *) "10.details/00.search", (gchar *) N_("Searching") }, - { E_CONFIG_ITEM, (gchar *) "10.details/00.search/00.search", (gchar *) "table33", eabc_details_search }, - { E_CONFIG_SECTION, (gchar *) "10.details/10.limit", (gchar *) N_("Downloading") }, - { E_CONFIG_ITEM, (gchar *) "10.details/10.limit/00.limit", (gchar *) "table34", eabc_details_limit }, -#endif - { 0 }, -}; - -/* items needed for the 'new addressbook' window */ -static EConfigItem eabc_new_items[] = { - { E_CONFIG_ITEM, (gchar *) "00.general/10.display/00.type", NULL, eabc_general_type }, - { 0 }, -}; - -static void -eabc_commit (EConfig *ec, - AddressbookSourceDialog *sdialog) -{ - xmlNodePtr xml; -#if d(!)0 - gchar *txt; -#endif - if (sdialog->original_source) { - d(printf("committing addressbook changes\n")); - - /* these api's kinda suck */ - xml = xmlNewNode(NULL, (const guchar *)"dummy"); - e_source_dump_to_xml_node (sdialog->source, xml); - e_source_update_from_xml_node (sdialog->original_source, xml->children, NULL); - xmlFreeNode (xml); -#if d(!)0 - txt = e_source_to_standalone_xml (sdialog->original_source); - printf("source is now:\n%s\n", txt); - g_free (txt); -#endif - } else { - d(printf("committing new source\n")); - e_source_group_add_source (sdialog->source_group, sdialog->source, -1); - e_source_list_sync (sdialog->source_list, NULL); - } - -#if d(!)0 - txt = e_source_to_standalone_xml (sdialog->source); - printf("running source is now:\n%s\n", txt); - g_free (txt); -#endif -} - -static void -eabc_free (EConfig *ec, - GSList *items, - gpointer data) -{ - AddressbookSourceDialog *sdialog = data; - - g_slist_free (items); - - g_object_unref (sdialog->source); - if (sdialog->original_source) - g_object_unref (sdialog->original_source); - if (sdialog->source_list) - g_object_unref (sdialog->source_list); - g_slist_free (sdialog->menu_source_groups); - - g_object_unref (sdialog->builder); - - g_free (sdialog); -} - -static gboolean -eabc_check_complete (EConfig *ec, - const gchar *pageid, - gpointer data) -{ - AddressbookSourceDialog *sdialog = data; - gint valid = TRUE; - const gchar *tmp; - ESource *source; - - d(printf("check complete, pageid = '%s'\n", pageid?pageid:"<all>")); - /* have name, and unique */ - tmp = e_source_get_display_name (sdialog->source); - valid = tmp && tmp[0] != 0 - && ((source = e_source_group_peek_source_by_name (sdialog->source_group, tmp)) == NULL - || source == sdialog->original_source); - -#ifdef HAVE_LDAP - if (valid && source_group_is_remote (sdialog->source_group)) { - gchar *uri = e_source_get_uri (sdialog->source); - LDAPURLDesc *lud; - - /* check host and port set */ - if (ldap_url_parse (uri, &lud) == LDAP_SUCCESS) { - valid = lud->lud_host != NULL - && lud->lud_host[0] != 0 - && lud->lud_port != 0; - ldap_free_urldesc (lud); - } else - valid = FALSE; - g_free (uri); - - /* check auth name provided if auth set */ - if (valid && (tmp = e_source_get_property(sdialog->source, "auth"))) { - switch (ldap_parse_auth (tmp)) { - case ADDRESSBOOK_LDAP_AUTH_SIMPLE_EMAIL: - tmp = e_source_get_property(sdialog->source, "email_addr"); - break; - case ADDRESSBOOK_LDAP_AUTH_SIMPLE_BINDDN: - tmp = e_source_get_property(sdialog->source, "binddn"); - break; - default: - tmp = "dummy"; - break; - } - valid = tmp && tmp[0]; - } - - /* check timeout isn't too short (why don't we just force it?) */ - if (valid) { - tmp = e_source_get_property(sdialog->source, "timeout"); - valid = tmp && g_strtod (tmp, NULL) > 0.0; - } - } -#endif - return valid; -} - -/* debug only: */ -#if d(!)0 -static void -source_changed (ESource *source, - AddressbookSourceDialog *sdialog) -{ - gchar *xml; - - xml = e_source_to_standalone_xml (source); - printf("source changed:\n%s\n", xml); - g_free (xml); -} -#endif - -GtkWidget * -addressbook_config_edit_source (GtkWidget *parent, - ESource *source) -{ - AddressbookSourceDialog *sdialog = g_new0 (AddressbookSourceDialog, 1); - EABConfig *ec; - gint i; - GSList *items = NULL; - EABConfigTargetSource *target; - gchar *xml; - - sdialog->builder = gtk_builder_new (); - e_load_ui_builder_definition (sdialog->builder, "ldap-config.ui"); - - if (source) { - sdialog->original_source = source; - g_object_ref (source); - sdialog->source_group = e_source_peek_group (source); - xml = e_source_to_standalone_xml (source); - sdialog->source = e_source_new_from_standalone_xml (xml); - g_free (xml); - } else { - GConfClient *gconf; - GSList *l; - - sdialog->source = e_source_new ("", ""); - e_source_set_property (sdialog->source, "completion", "true"); - gconf = gconf_client_get_default (); - sdialog->source_list = e_source_list_new_for_gconf(gconf, "/apps/evolution/addressbook/sources"); - l = e_source_list_peek_groups (sdialog->source_list); - if (!l) { - g_warning ("Address Book source groups are missing! Check your GConf setup."); - g_object_unref (gconf); - g_free (sdialog); - return NULL; - } - - sdialog->menu_source_groups = g_slist_copy (l); -#ifndef HAVE_LDAP - for (; l; l = g_slist_next (l)) - if (!strncmp("ldap:", e_source_group_peek_base_uri(l->data), 5)) - sdialog->menu_source_groups = g_slist_remove (sdialog->menu_source_groups, l->data); -#endif - sdialog->source_group = (ESourceGroup *) sdialog->menu_source_groups->data; - for (i = 0; eabc_new_items[i].path; i++) - items = g_slist_prepend (items, &eabc_new_items[i]); - g_object_unref (gconf); - } - - /* HACK: doesn't work if you don't do this */ - e_source_set_group (sdialog->source, sdialog->source_group); - -#if d(!)0 - xml = e_source_to_standalone_xml (sdialog->source); - printf("but working standalone xml: %s\n", xml); - g_free (xml); - g_signal_connect ( - sdialog->source, "changed", - source_changed, sdialog); -#endif - - sdialog->config = ec = eab_config_new(E_CONFIG_BOOK, "com.novell.evolution.addressbook.config.accountEditor"); - - for (i = 0; eabc_items[i].path; i++) { - if (eabc_items[i].label) - eabc_items[i].label = gettext (eabc_items[i].label); - items = g_slist_prepend (items, &eabc_items[i]); - } - - e_config_add_items ((EConfig *) ec, items, eabc_free, sdialog); - e_config_add_page_check ((EConfig *) ec, NULL, eabc_check_complete, sdialog); - g_signal_connect_after ( - ec, "commit", - G_CALLBACK (eabc_commit), sdialog); - - target = eab_config_target_new_source (ec, sdialog->source); - e_config_set_target ((EConfig *) ec, (EConfigTarget *) target); - - if (source) - sdialog->window = e_config_create_window((EConfig *)ec, NULL, _("Address Book Properties")); - else - sdialog->window = e_config_create_window((EConfig *)ec, NULL, _("New Address Book")); - - /* forces initial validation */ - if (!sdialog->original_source) { - e_source_set_relative_uri (sdialog->source, e_source_get_uid (sdialog->source)); - e_config_target_changed ((EConfig *) ec, E_CONFIG_TARGET_CHANGED_STATE); - } - - return sdialog->window; -} diff --git a/modules/addressbook/addressbook-config.h b/modules/addressbook/addressbook-config.h deleted file mode 100644 index e316392497..0000000000 --- a/modules/addressbook/addressbook-config.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Chris Toshok <toshok@ximian.com> - * Chris Lahey <clahey@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifndef __ADDRESSBOOK_CONFIG_H__ -#define __ADDRESSBOOK_CONFIG_H__ - -#include <gtk/gtk.h> -#include <libedataserver/e-source.h> - -typedef enum { - ADDRESSBOOK_LDAP_AUTH_NONE, - ADDRESSBOOK_LDAP_AUTH_SIMPLE_EMAIL, - ADDRESSBOOK_LDAP_AUTH_SIMPLE_BINDDN -} AddressbookLDAPAuthType; - -typedef enum { - ADDRESSBOOK_LDAP_SCOPE_ONELEVEL, - ADDRESSBOOK_LDAP_SCOPE_SUBTREE, - ADDRESSBOOK_LDAP_SCOPE_BASE, - ADDRESSBOOK_LDAP_SCOPE_LAST -} AddressbookLDAPScopeType; - -/* the order matches order of items in "ssl-combobox" */ -typedef enum { - ADDRESSBOOK_LDAP_SSL_WHENEVER_POSSIBLE, /* TLS */ - ADDRESSBOOK_LDAP_SSL_ALWAYS, /* SSL */ - ADDRESSBOOK_LDAP_SSL_NEVER /* No encryption */ -} AddressbookLDAPSSLType; - -GtkWidget * addressbook_config_edit_source (GtkWidget *parent, ESource *source); -GtkWidget * addressbook_config_create_new_source (GtkWidget *parent); - -#endif /* __ADDRESSBOOK_CONFIG_H__ */ diff --git a/modules/addressbook/autocompletion-config.c b/modules/addressbook/autocompletion-config.c index f8199eef84..d57e8f50ea 100644 --- a/modules/addressbook/autocompletion-config.c +++ b/modules/addressbook/autocompletion-config.c @@ -22,78 +22,17 @@ * */ -#include <config.h> - #include "autocompletion-config.h" #include <gtk/gtk.h> #include <glib/gi18n.h> -#include <libedataserver/e-source-list.h> +#include <libedataserver/e-source-address-book.h> +#include <libedataserver/e-source-autocomplete.h> #include <libedataserverui/e-source-selector.h> #include <libedataserverui/e-name-selector-entry.h> -#include "e-util/e-config.h" #include "e-util/e-datetime-format.h" -#include "addressbook/gui/widgets/eab-config.h" - -static void -source_selection_changed_cb (ESourceSelector *source_selector) -{ - ESourceList *source_list; - GSList *selection; - GSList *l; - GSList *groups; - - source_list = e_source_selector_get_source_list (source_selector); - - /* first we clear all the completion flags from all sources */ - for (groups = e_source_list_peek_groups (source_list); groups; groups = groups->next) { - ESourceGroup *group = E_SOURCE_GROUP (groups->data); - GSList *sources; - - for (sources = e_source_group_peek_sources (group); sources; sources = sources->next) { - ESource *source = E_SOURCE (sources->data); - - e_source_set_property (source, "completion", NULL); - } - } - - /* then we loop over the selector's selection, setting the - * property on those sources */ - selection = e_source_selector_get_selection (source_selector); - for (l = selection; l; l = l->next) { - ESource *source = E_SOURCE (l->data); - - e_source_set_property (source, "completion", "true"); - } - e_source_selector_free_selection (selection); - - /* XXX we should pop up a dialog if this fails */ - e_source_list_sync (source_list, NULL); -} - -static void -initialize_selection (ESourceSelector *source_selector) -{ - ESourceList *source_list; - GSList *groups; - - source_list = e_source_selector_get_source_list (source_selector); - - for (groups = e_source_list_peek_groups (source_list); groups; groups = groups->next) { - ESourceGroup *group = E_SOURCE_GROUP (groups->data); - GSList *sources; - - for (sources = e_source_group_peek_sources (group); sources; sources = sources->next) { - ESource *source = E_SOURCE (sources->data); - const gchar *completion; - - completion = e_source_get_property (source, "completion"); - if (completion && !g_ascii_strcasecmp (completion, "true")) - e_source_selector_select_source (source_selector, source); - } - } -} +#include "misc/e-autocomplete-selector.h" static GtkWidget * add_section (GtkWidget *container, @@ -131,56 +70,25 @@ add_section (GtkWidget *container, return widget; } -static GtkWidget * -acc_get_toplevel_notebook (EConfig *ec, - EConfigItem *item, - GtkWidget *parent, - GtkWidget *old, - gint position, - gpointer data) -{ - if (old) - return old; - - old = gtk_notebook_new (); - gtk_widget_show (old); - - return old; -} - -static GtkWidget * -acc_get_general_page (EConfig *ec, - EConfigItem *item, - GtkWidget *parent, - GtkWidget *old, - gint position, - gpointer data) +GtkWidget * +autocompletion_config_new (EPreferencesWindow *window) { EShellSettings *shell_settings; - ESourceList *source_list; - GtkWidget *scrolled_window; - GtkWidget *source_selector; + ESourceRegistry *registry; + GtkWidget *container; GtkWidget *itembox; GtkWidget *widget; GtkWidget *vbox; EShell *shell; - if (old) - return old; - - g_return_val_if_fail (GTK_IS_NOTEBOOK (parent), NULL); - - shell = data; + shell = e_preferences_window_get_shell (window); g_return_val_if_fail (E_IS_SHELL (shell), NULL); + registry = e_shell_get_registry (shell); shell_settings = e_shell_get_shell_settings (shell); - source_list = e_source_list_new_for_gconf_default ( - "/apps/evolution/addressbook/sources"); - - vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12); - gtk_container_set_border_width (GTK_CONTAINER (vbox), 12); + vbox = gtk_vbox_new (FALSE, 12); gtk_widget_show (vbox); itembox = add_section (vbox, _("Date/Time Format"), FALSE); @@ -216,87 +124,20 @@ acc_get_general_page (EConfig *ec, gtk_box_pack_start (GTK_BOX (itembox), widget, FALSE, FALSE, 0); gtk_widget_show (widget); - scrolled_window = gtk_scrolled_window_new (NULL, NULL); + widget = gtk_scrolled_window_new (NULL, NULL); gtk_scrolled_window_set_policy ( - GTK_SCROLLED_WINDOW (scrolled_window), + GTK_SCROLLED_WINDOW (widget), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_scrolled_window_set_shadow_type ( - GTK_SCROLLED_WINDOW (scrolled_window), GTK_SHADOW_IN); - gtk_widget_show (scrolled_window); - - source_selector = e_source_selector_new (source_list); - initialize_selection (E_SOURCE_SELECTOR (source_selector)); - g_signal_connect ( - source_selector, "selection_changed", - G_CALLBACK (source_selection_changed_cb), NULL); - gtk_container_add (GTK_CONTAINER (scrolled_window), source_selector); - gtk_widget_show (source_selector); - - gtk_box_pack_start (GTK_BOX (itembox), scrolled_window, TRUE, TRUE, 0); - gtk_widget_show_all (vbox); - - gtk_notebook_append_page (GTK_NOTEBOOK (parent), vbox, gtk_label_new (_("General"))); - - return vbox; -} - -/* plugin meta-data */ -static EConfigItem acc_items[] = { - { E_CONFIG_BOOK, (gchar *) "", (gchar *) "acc_toplevel_notebook", acc_get_toplevel_notebook }, - { E_CONFIG_PAGE, (gchar *) "00.general", (gchar *) "acc_general", acc_get_general_page } -}; - -static void -acc_free (EConfig *ec, - GSList *items, - gpointer data) -{ - g_slist_free (items); -} - -GtkWidget * -autocompletion_config_new (EPreferencesWindow *window) -{ - GtkWidget *toplevel; - GtkWidget *vbox; - GSList *l; - gint ii; - EShell *shell; - EABConfig *eab; - EABConfigTargetPrefs *target; - GSettings *settings; - - shell = e_preferences_window_get_shell (window); - - g_return_val_if_fail (E_IS_SHELL (shell), NULL); - - vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); - gtk_container_set_border_width (GTK_CONTAINER (vbox), 0); - gtk_widget_show (vbox); - - /** @HookPoint-EABConfig: Contacts Preferences Page - * @Id: org.gnome.evolution.addressbook.prefs - * @Type: E_CONFIG_BOOK - * @Class: org.gnome.evolution.addressbook.config:1.0 - * @Target: EABConfigTargetPrefs - * - * The main contacts preferences page. - */ - eab = eab_config_new (E_CONFIG_BOOK, "org.gnome.evolution.addressbook.prefs"); - - l = NULL; - for (ii = 0; ii < G_N_ELEMENTS (acc_items); ii++) - l = g_slist_prepend (l, &acc_items[ii]); - e_config_add_items ((EConfig *) eab, l, acc_free, shell); - - settings = g_settings_new ("org.gnome.evolution.addressbook"); + GTK_SCROLLED_WINDOW (widget), GTK_SHADOW_IN); + gtk_box_pack_start (GTK_BOX (itembox), widget, TRUE, TRUE, 0); + gtk_widget_show (widget); - target = eab_config_target_new_prefs (eab, settings); - e_config_set_target ((EConfig *) eab, (EConfigTarget *) target); - toplevel = e_config_create_widget ((EConfig *) eab); - gtk_box_pack_start (GTK_BOX (vbox), toplevel, TRUE, TRUE, 0); + container = widget; - g_object_unref (settings); + widget = e_autocomplete_selector_new (registry); + gtk_container_add (GTK_CONTAINER (container), widget); + gtk_widget_show (widget); return vbox; } diff --git a/modules/addressbook/e-book-shell-backend.c b/modules/addressbook/e-book-shell-backend.c index a10eefa01d..ac6f8b27b6 100644 --- a/modules/addressbook/e-book-shell-backend.c +++ b/modules/addressbook/e-book-shell-backend.c @@ -30,21 +30,23 @@ #include <libebook/e-book-client.h> #include <libedataserver/e-url.h> #include <libedataserver/e-source.h> -#include <libedataserver/e-source-group.h> +#include <libedataserver/e-source-address-book.h> #include <libedataserverui/e-client-utils.h> +#include <libedataserverui/e-book-auth-util.h> #include "e-util/e-import.h" #include "shell/e-shell.h" #include "shell/e-shell-window.h" #include "widgets/misc/e-preferences-window.h" +#include "widgets/misc/e-source-config-dialog.h" #include "addressbook/gui/widgets/eab-gui-util.h" +#include "addressbook/gui/widgets/e-book-source-config.h" #include "addressbook/gui/contact-editor/e-contact-editor.h" #include "addressbook/gui/contact-editor/e-contact-quick-add.h" #include "addressbook/gui/contact-list-editor/e-contact-list-editor.h" #include "addressbook/importers/evolution-addressbook-importers.h" -#include "addressbook-config.h" #include "autocompletion-config.h" #include "e-book-shell-migrate.h" @@ -61,12 +63,7 @@ ((obj), E_TYPE_BOOK_SHELL_BACKEND, EBookShellBackendPrivate)) struct _EBookShellBackendPrivate { - ESourceList *source_list; -}; - -enum { - PROP_0, - PROP_SOURCE_LIST + gint placeholder; }; G_DEFINE_DYNAMIC_TYPE ( @@ -75,75 +72,6 @@ G_DEFINE_DYNAMIC_TYPE ( E_TYPE_SHELL_BACKEND) static void -book_shell_backend_ensure_sources (EShellBackend *shell_backend) -{ - /* XXX This is basically the same algorithm across all backends. - * Maybe we could somehow integrate this into EShellBackend? */ - - EBookShellBackendPrivate *priv; - ESourceGroup *on_this_computer; - ESource *personal; - GSList *sources, *iter; - const gchar *name; - GError *error = NULL; - - on_this_computer = NULL; - personal = NULL; - - priv = E_BOOK_SHELL_BACKEND_GET_PRIVATE (shell_backend); - - e_book_client_get_sources (&priv->source_list, &error); - - if (error != NULL) { - g_warning ( - "Could not get addressbook sources: %s", - error->message); - g_error_free (error); - return; - } - - on_this_computer = e_source_list_ensure_group ( - priv->source_list, _("On This Computer"), "local:", TRUE); - e_source_list_ensure_group ( - priv->source_list, _("On LDAP Servers"), "ldap://", FALSE); - - g_return_if_fail (on_this_computer != NULL); - - sources = e_source_group_peek_sources (on_this_computer); - - /* Make sure this group includes a "Personal" source. */ - for (iter = sources; iter != NULL; iter = iter->next) { - ESource *source = iter->data; - const gchar *relative_uri; - - relative_uri = e_source_peek_relative_uri (source); - if (g_strcmp0 (relative_uri, "system") == 0) { - personal = source; - break; - } - } - - name = _("Personal"); - - if (personal == NULL) { - ESource *source; - - /* Create the default Personal address book. */ - source = e_source_new (name, "system"); - e_source_group_add_source (on_this_computer, source, -1); - e_source_set_property (source, "completion", "true"); - g_object_unref (source); - e_source_list_sync (priv->source_list, NULL); - } else if (!e_source_get_property (personal, "name-changed")) { - /* Force the source name to the current locale. */ - e_source_set_name (personal, name); - e_source_list_sync (priv->source_list, NULL); - } - - g_object_unref (on_this_computer); -} - -static void book_shell_backend_init_importers (void) { EImportClass *import_class; @@ -252,58 +180,59 @@ action_contact_new_cb (GtkAction *action, EShellWindow *shell_window) { EShell *shell; - EShellBackend *shell_backend; - GSettings *settings; - ESourceList *source_list; - ESource *source = NULL; + ESource *source; + ESourceRegistry *registry; const gchar *action_name; - gchar *uid; /* This callback is used for both contacts and contact lists. */ shell = e_shell_window_get_shell (shell_window); - shell_backend = e_shell_get_backend_by_name (shell, "addressbook"); - - g_object_get (shell_backend, "source-list", &source_list, NULL); - g_return_if_fail (E_IS_SOURCE_LIST (source_list)); - - settings = g_settings_new ("org.gnome.evolution.addressbook"); - uid = g_settings_get_string (settings, "primary-addressbook"); - g_object_unref (settings); - - if (uid != NULL) { - source = e_source_list_peek_source_by_uid (source_list, uid); - g_free (uid); - } - if (source == NULL) - source = e_source_list_peek_default_source (source_list); - - g_return_if_fail (E_IS_SOURCE (source)); + registry = e_shell_get_registry (shell); + source = e_source_registry_ref_default_address_book (registry); /* Use a callback function appropriate for the action. */ action_name = gtk_action_get_name (action); if (strcmp (action_name, "contact-new") == 0) e_client_utils_open_new ( source, E_CLIENT_SOURCE_TYPE_CONTACTS, FALSE, NULL, - e_client_utils_authenticate_handler, GTK_WINDOW (shell_window), book_shell_backend_new_contact_cb, g_object_ref (shell)); if (strcmp (action_name, "contact-new-list") == 0) e_client_utils_open_new ( source, E_CLIENT_SOURCE_TYPE_CONTACTS, FALSE, NULL, - e_client_utils_authenticate_handler, GTK_WINDOW (shell_window), book_shell_backend_new_contact_list_cb, g_object_ref (shell)); - g_object_unref (source_list); + g_object_unref (source); } static void action_address_book_new_cb (GtkAction *action, EShellWindow *shell_window) { - addressbook_config_create_new_source (NULL); + EShell *shell; + ESourceRegistry *registry; + GtkWidget *config; + GtkWidget *dialog; + const gchar *icon_name; + + shell = e_shell_window_get_shell (shell_window); + + registry = e_shell_get_registry (shell); + config = e_book_source_config_new (registry, NULL); + + dialog = e_source_config_dialog_new (E_SOURCE_CONFIG (config)); + + gtk_window_set_transient_for ( + GTK_WINDOW (dialog), GTK_WINDOW (shell_window)); + + icon_name = gtk_action_get_icon_name (action); + gtk_window_set_icon_name (GTK_WINDOW (dialog), icon_name); + + gtk_window_set_title (GTK_WINDOW (dialog), _("New Address Book")); + + gtk_widget_show (dialog); } static GtkActionEntry item_entries[] = { @@ -370,20 +299,26 @@ static void book_shell_backend_quick_add_email_cb (EShell *shell, const gchar *email) { + ESourceRegistry *registry; + /* XXX This is an ugly hack but it's the only way I could think * of to integrate this feature with other shell modules. */ - e_contact_quick_add_email (email, NULL, NULL); + registry = e_shell_get_registry (shell); + e_contact_quick_add_email (registry, email, NULL, NULL); } static void book_shell_backend_quick_add_vcard_cb (EShell *shell, const gchar *vcard) { + ESourceRegistry *registry; + /* XXX This is an ugly hack but it's the only way I could think * of to integrate this feature with other shell modules. */ - e_contact_quick_add_vcard (vcard, NULL, NULL); + registry = e_shell_get_registry (shell); + e_contact_quick_add_vcard (registry, vcard, NULL, NULL); } static gboolean @@ -473,40 +408,6 @@ book_shell_backend_window_added_cb (EShellBackend *shell_backend, } static void -book_shell_backend_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec) -{ - switch (property_id) { - case PROP_SOURCE_LIST: - g_value_set_object ( - value, - e_book_shell_backend_get_source_list ( - E_BOOK_SHELL_BACKEND (object))); - return; - } - - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); -} - -static void -book_shell_backend_dispose (GObject *object) -{ - EBookShellBackendPrivate *priv; - - priv = E_BOOK_SHELL_BACKEND_GET_PRIVATE (object); - - if (priv->source_list != NULL) { - g_object_unref (priv->source_list); - priv->source_list = NULL; - } - - /* Chain up to parent's dispose() method. */ - G_OBJECT_CLASS (e_book_shell_backend_parent_class)->dispose (object); -} - -static void book_shell_backend_constructed (GObject *object) { EShell *shell; @@ -522,7 +423,6 @@ book_shell_backend_constructed (GObject *object) #endif book_shell_backend_init_importers (); - book_shell_backend_ensure_sources (shell_backend); g_signal_connect ( shell, "event::contact-quick-add-email", @@ -561,8 +461,6 @@ e_book_shell_backend_class_init (EBookShellBackendClass *class) g_type_class_add_private (class, sizeof (EBookShellBackendPrivate)); object_class = G_OBJECT_CLASS (class); - object_class->get_property = book_shell_backend_get_property; - object_class->dispose = book_shell_backend_dispose; object_class->constructed = book_shell_backend_constructed; shell_backend_class = E_SHELL_BACKEND_CLASS (class); @@ -574,16 +472,6 @@ e_book_shell_backend_class_init (EBookShellBackendClass *class) shell_backend_class->preferences_page = "contacts"; shell_backend_class->start = NULL; shell_backend_class->migrate = e_book_shell_backend_migrate; - - g_object_class_install_property ( - object_class, - PROP_SOURCE_LIST, - g_param_spec_object ( - "source-list", - "Source List", - "The registry of address books", - E_TYPE_SOURCE_LIST, - G_PARAM_READABLE)); } static void @@ -606,12 +494,3 @@ e_book_shell_backend_type_register (GTypeModule *type_module) * order to register types from a separate compilation unit. */ e_book_shell_backend_register_type (type_module); } - -ESourceList * -e_book_shell_backend_get_source_list (EBookShellBackend *book_shell_backend) -{ - g_return_val_if_fail ( - E_IS_BOOK_SHELL_BACKEND (book_shell_backend), NULL); - - return book_shell_backend->priv->source_list; -} diff --git a/modules/addressbook/e-book-shell-backend.h b/modules/addressbook/e-book-shell-backend.h index 00ebe3d536..73a799a130 100644 --- a/modules/addressbook/e-book-shell-backend.h +++ b/modules/addressbook/e-book-shell-backend.h @@ -23,7 +23,6 @@ #define E_BOOK_SHELL_BACKEND_H #include <shell/e-shell-backend.h> -#include <libedataserver/e-source-list.h> /* Standard GObject macros */ #define E_TYPE_BOOK_SHELL_BACKEND \ @@ -62,8 +61,6 @@ struct _EBookShellBackendClass { GType e_book_shell_backend_get_type (void); void e_book_shell_backend_type_register (GTypeModule *type_module); -ESourceList * e_book_shell_backend_get_source_list - (EBookShellBackend *book_shell_backend); G_END_DECLS diff --git a/modules/addressbook/e-book-shell-content.c b/modules/addressbook/e-book-shell-content.c index f3457e8999..05f8bd8d03 100644 --- a/modules/addressbook/e-book-shell-content.c +++ b/modules/addressbook/e-book-shell-content.c @@ -348,6 +348,7 @@ book_shell_content_check_state (EShellContent *shell_content) ESelectionModel *selection_model; EAddressbookModel *model; EAddressbookView *view; + GtkNotebook *notebook; gboolean has_email = TRUE; gboolean is_contact_list = TRUE; guint32 state = 0; @@ -359,6 +360,13 @@ book_shell_content_check_state (EShellContent *shell_content) } foreach_data; book_shell_content = E_BOOK_SHELL_CONTENT (shell_content); + + /* This function may be triggered at startup before any address + * book views are added. Check for that and return silently. */ + notebook = GTK_NOTEBOOK (book_shell_content->priv->notebook); + if (gtk_notebook_get_n_pages (notebook) == 0) + return 0; + view = e_book_shell_content_get_current_view (book_shell_content); model = e_addressbook_view_get_model (view); diff --git a/modules/addressbook/e-book-shell-migrate.c b/modules/addressbook/e-book-shell-migrate.c index d2d26c8b9e..2e3de84b32 100644 --- a/modules/addressbook/e-book-shell-migrate.c +++ b/modules/addressbook/e-book-shell-migrate.c @@ -26,168 +26,8 @@ #include <config.h> #endif -#include <string.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <unistd.h> -#include <fcntl.h> -#include <errno.h> - -#include <glib/gstdio.h> - -#include <gtk/gtk.h> - -#include <libebook/e-destination.h> -#include <libebook/e-book-client.h> -#include <glib/gi18n.h> - -#include <libedataserver/e-xml-utils.h> - -#include "e-util/e-util.h" -#include "e-util/e-util-private.h" -#include "libevolution-utils/e-xml-utils.h" - #include "e-book-shell-migrate.h" -/*#define SLOW_MIGRATION*/ - -typedef struct { - /* this hash table maps old folder uris to new uids. It's - * build in migrate_contact_folder and it's used in - * migrate_completion_folders. */ - GHashTable *folder_uid_map; - - ESourceList *source_list; - - const gchar *data_dir; - - GtkWidget *window; - GtkWidget *label; - GtkWidget *folder_label; - GtkWidget *progress; -} MigrationContext; - -#define LOCAL_BASE_URI "local:" -#define LDAP_BASE_URI "ldap://" -#define PERSONAL_RELATIVE_URI "system" - -static void -create_groups (MigrationContext *context, - ESourceGroup **on_this_computer, - ESourceGroup **on_ldap_servers, - ESource **personal_source) -{ - GSList *groups; - ESourceGroup *group; - - *on_this_computer = NULL; - *on_ldap_servers = NULL; - *personal_source = NULL; - - groups = e_source_list_peek_groups (context->source_list); - if (groups) { - /* groups are already there, we need to search for things... */ - GSList *g; - gchar *base_dir, *base_uri; - - base_dir = g_build_filename (context->data_dir, "local", NULL); - base_uri = g_filename_to_uri (base_dir, NULL, NULL); - - for (g = groups; g; g = g->next) { - group = E_SOURCE_GROUP (g->data); - - if (strcmp (base_uri, e_source_group_peek_base_uri (group)) == 0) - e_source_group_set_base_uri (group, LOCAL_BASE_URI); - - if (!*on_this_computer && - !strcmp (LOCAL_BASE_URI, - e_source_group_peek_base_uri (group))) - *on_this_computer = g_object_ref (group); - else if (!*on_ldap_servers && - !strcmp (LDAP_BASE_URI, - e_source_group_peek_base_uri (group))) - *on_ldap_servers = g_object_ref (group); - } - - g_free (base_dir); - g_free (base_uri); - } - - if (*on_this_computer) { - /* make sure "Personal" shows up as a source under - * this group */ - GSList *sources = e_source_group_peek_sources (*on_this_computer); - GSList *s; - for (s = sources; s; s = s->next) { - ESource *source = E_SOURCE (s->data); - const gchar *relative_uri; - - relative_uri = e_source_peek_relative_uri (source); - if (relative_uri == NULL) - continue; - if (!strcmp (PERSONAL_RELATIVE_URI, relative_uri)) { - *personal_source = g_object_ref (source); - break; - } - } - } - else { - /* create the local source group */ - group = e_source_group_new (_("On This Computer"), LOCAL_BASE_URI); - e_source_list_add_group (context->source_list, group, -1); - - *on_this_computer = group; - } - - if (!*personal_source) { - /* Create the default Person addressbook */ - ESource *source = e_source_new (_("Personal"), PERSONAL_RELATIVE_URI); - e_source_group_add_source (*on_this_computer, source, -1); - - e_source_set_property (source, "completion", "true"); - - *personal_source = source; - } - - if (!*on_ldap_servers) { - /* Create the LDAP source group */ - group = e_source_group_new (_("On LDAP Servers"), LDAP_BASE_URI); - e_source_list_add_group (context->source_list, group, -1); - - *on_ldap_servers = group; - } -} - -static MigrationContext * -migration_context_new (const gchar *data_dir) -{ - MigrationContext *context = g_new (MigrationContext, 1); - - /* set up the mapping from old uris to new uids */ - context->folder_uid_map = g_hash_table_new_full ( - g_str_hash, g_str_equal, - (GDestroyNotify) g_free, - (GDestroyNotify) g_free); - - e_book_client_get_sources (&context->source_list, NULL); - - context->data_dir = data_dir; - - return context; -} - -static void -migration_context_free (MigrationContext *context) -{ - e_source_list_sync (context->source_list, NULL); - - g_hash_table_destroy (context->folder_uid_map); - - g_object_unref (context->source_list); - - g_free (context); -} - gboolean e_book_shell_backend_migrate (EShellBackend *shell_backend, gint major, @@ -195,30 +35,7 @@ e_book_shell_backend_migrate (EShellBackend *shell_backend, gint micro, GError **error) { - ESourceGroup *on_this_computer; - ESourceGroup *on_ldap_servers; - ESource *personal_source; - MigrationContext *context; - const gchar *data_dir; - g_return_val_if_fail (E_IS_SHELL_BACKEND (shell_backend), FALSE); - data_dir = e_shell_backend_get_data_dir (shell_backend); - context = migration_context_new (data_dir); - - /* we call this unconditionally now - create_groups either - * creates the groups/sources or it finds the necessary - * groups/sources. */ - create_groups (context, &on_this_computer, &on_ldap_servers, &personal_source); - - if (on_this_computer) - g_object_unref (on_this_computer); - if (on_ldap_servers) - g_object_unref (on_ldap_servers); - if (personal_source) - g_object_unref (personal_source); - - migration_context_free (context); - return TRUE; } diff --git a/modules/addressbook/e-book-shell-sidebar.c b/modules/addressbook/e-book-shell-sidebar.c index d47dbd75f9..57ea7d3a2c 100644 --- a/modules/addressbook/e-book-shell-sidebar.c +++ b/modules/addressbook/e-book-shell-sidebar.c @@ -28,6 +28,8 @@ #include <string.h> #include <glib/gi18n.h> +#include <libedataserver/e-source-address-book.h> + #include <e-util/e-util.h> #include "e-book-shell-view.h" @@ -94,7 +96,7 @@ book_shell_sidebar_constructed (GObject *object) EShellBackend *shell_backend; EShellSidebar *shell_sidebar; EShellSettings *shell_settings; - ESourceList *source_list; + ESourceRegistry *registry; GtkContainer *container; GtkWidget *widget; @@ -110,9 +112,6 @@ book_shell_sidebar_constructed (GObject *object) shell = e_shell_backend_get_shell (shell_backend); shell_settings = e_shell_get_shell_settings (shell); - source_list = e_book_shell_backend_get_source_list ( - E_BOOK_SHELL_BACKEND (shell_backend)); - container = GTK_CONTAINER (shell_sidebar); widget = gtk_scrolled_window_new (NULL, NULL); @@ -126,8 +125,8 @@ book_shell_sidebar_constructed (GObject *object) container = GTK_CONTAINER (widget); - widget = e_addressbook_selector_new (source_list); - e_source_selector_show_selection (E_SOURCE_SELECTOR (widget), FALSE); + registry = e_shell_get_registry (shell); + widget = e_addressbook_selector_new (registry); gtk_container_add (GTK_CONTAINER (container), widget); priv->selector = g_object_ref (widget); gtk_widget_show (widget); @@ -139,7 +138,7 @@ book_shell_sidebar_constructed (GObject *object) G_BINDING_SYNC_CREATE, (GBindingTransformFunc) e_binding_transform_uid_to_source, (GBindingTransformFunc) e_binding_transform_source_to_uid, - g_object_ref (source_list), + g_object_ref (registry), (GDestroyNotify) g_object_unref); } @@ -149,8 +148,8 @@ book_shell_sidebar_check_state (EShellSidebar *shell_sidebar) EBookShellSidebar *book_shell_sidebar; ESourceSelector *selector; ESource *source; - gboolean can_delete = FALSE; - gboolean is_system = FALSE; + gboolean removable = FALSE; + gboolean writable = FALSE; gboolean has_primary_source = FALSE; guint32 state = 0; @@ -159,27 +158,18 @@ book_shell_sidebar_check_state (EShellSidebar *shell_sidebar) source = e_source_selector_ref_primary_selection (selector); if (source != NULL) { - const gchar *uri; - const gchar *delete; - has_primary_source = TRUE; - - uri = e_source_peek_relative_uri (source); - is_system = (uri == NULL || strcmp (uri, "system") == 0); - - can_delete = !is_system; - delete = e_source_get_property (source, "delete"); - can_delete &= (delete == NULL || strcmp (delete, "no") != 0); - + removable = e_source_get_removable (source); + writable = e_source_get_writable (source); g_object_unref (source); } if (has_primary_source) state |= E_BOOK_SHELL_SIDEBAR_HAS_PRIMARY_SOURCE; - if (can_delete) - state |= E_BOOK_SHELL_SIDEBAR_CAN_DELETE_PRIMARY_SOURCE; - if (is_system) - state |= E_BOOK_SHELL_SIDEBAR_PRIMARY_SOURCE_IS_SYSTEM; + if (removable) + state |= E_BOOK_SHELL_SIDEBAR_PRIMARY_SOURCE_IS_REMOVABLE; + if (writable) + state |= E_BOOK_SHELL_SIDEBAR_PRIMARY_SOURCE_IS_WRITABLE; return state; } diff --git a/modules/addressbook/e-book-shell-sidebar.h b/modules/addressbook/e-book-shell-sidebar.h index 104a4d4b47..bf1cdd0baa 100644 --- a/modules/addressbook/e-book-shell-sidebar.h +++ b/modules/addressbook/e-book-shell-sidebar.h @@ -53,9 +53,9 @@ typedef struct _EBookShellSidebarClass EBookShellSidebarClass; typedef struct _EBookShellSidebarPrivate EBookShellSidebarPrivate; enum { - E_BOOK_SHELL_SIDEBAR_HAS_PRIMARY_SOURCE = 1 << 0, - E_BOOK_SHELL_SIDEBAR_CAN_DELETE_PRIMARY_SOURCE = 1 << 1, - E_BOOK_SHELL_SIDEBAR_PRIMARY_SOURCE_IS_SYSTEM = 1 << 2 + E_BOOK_SHELL_SIDEBAR_HAS_PRIMARY_SOURCE = 1 << 0, + E_BOOK_SHELL_SIDEBAR_PRIMARY_SOURCE_IS_REMOVABLE = 1 << 1, + E_BOOK_SHELL_SIDEBAR_PRIMARY_SOURCE_IS_WRITABLE = 1 << 2 }; struct _EBookShellSidebar { diff --git a/modules/addressbook/e-book-shell-view-actions.c b/modules/addressbook/e-book-shell-view-actions.c index 2c174a3545..fe7f9e4b20 100644 --- a/modules/addressbook/e-book-shell-view-actions.c +++ b/modules/addressbook/e-book-shell-view-actions.c @@ -33,8 +33,6 @@ #include <widgets/misc/e-contact-map-window.h> #endif -#include <addressbook-config.h> - static void action_address_book_copy_cb (GtkAction *action, EBookShellView *book_shell_view) @@ -55,22 +53,14 @@ action_address_book_delete_cb (GtkAction *action, { EShellView *shell_view; EShellWindow *shell_window; - EBookShellBackend *book_shell_backend; EBookShellSidebar *book_shell_sidebar; ESource *source; ESourceSelector *selector; - ESourceGroup *source_group; - ESourceList *source_list; - EBookClient *book; gint response; - GError *error = NULL; shell_view = E_SHELL_VIEW (book_shell_view); shell_window = e_shell_view_get_shell_window (shell_view); - book_shell_backend = book_shell_view->priv->book_shell_backend; - source_list = e_book_shell_backend_get_source_list (book_shell_backend); - book_shell_sidebar = book_shell_view->priv->book_shell_sidebar; selector = e_book_shell_sidebar_get_selector (book_shell_sidebar); source = e_source_selector_ref_primary_selection (selector); @@ -81,38 +71,10 @@ action_address_book_delete_cb (GtkAction *action, "addressbook:ask-delete-addressbook", e_source_get_display_name (source), NULL); - if (response != GTK_RESPONSE_YES) { - g_object_unref (source); - return; - } - - book = e_book_client_new (source, &error); - if (error != NULL) { - g_warning ("Error removing addressbook: %s", error->message); - g_object_unref (source); - g_error_free (error); - return; - } - - if (!e_client_remove_sync (E_CLIENT (book), NULL, NULL)) { - e_alert_run_dialog_for_args ( - GTK_WINDOW (shell_window), - "addressbook:remove-addressbook", NULL); - g_object_unref (source); - g_object_unref (book); - return; - } - - if (e_source_selector_source_is_selected (selector, source)) - e_source_selector_unselect_source (selector, source); - - source_group = e_source_peek_group (source); - e_source_group_remove_source (source_group, source); - - e_source_list_sync (source_list, NULL); + if (response == GTK_RESPONSE_YES) + e_shell_view_remove_source (shell_view, source); g_object_unref (source); - g_object_unref (book); } static void @@ -135,11 +97,28 @@ action_address_book_new_cb (GtkAction *action, { EShellView *shell_view; EShellWindow *shell_window; + ESourceRegistry *registry; + GtkWidget *config; + GtkWidget *dialog; + const gchar *icon_name; shell_view = E_SHELL_VIEW (book_shell_view); shell_window = e_shell_view_get_shell_window (shell_view); - addressbook_config_create_new_source (GTK_WIDGET (shell_window)); + registry = book_shell_view->priv->registry; + config = e_book_source_config_new (registry, NULL); + + dialog = e_source_config_dialog_new (E_SOURCE_CONFIG (config)); + + gtk_window_set_transient_for ( + GTK_WINDOW (config), GTK_WINDOW (shell_window)); + + icon_name = gtk_action_get_icon_name (action); + gtk_window_set_icon_name (GTK_WINDOW (dialog), icon_name); + + gtk_window_set_title (GTK_WINDOW (dialog), _("New Address Book")); + + gtk_widget_show (dialog); } static void @@ -183,9 +162,10 @@ action_address_book_properties_cb (GtkAction *action, EBookShellSidebar *book_shell_sidebar; ESource *source; ESourceSelector *selector; - EditorUidClosure *closure; - GHashTable *uid_to_editor; - const gchar *uid; + ESourceRegistry *registry; + GtkWidget *config; + GtkWidget *dialog; + const gchar *icon_name; shell_view = E_SHELL_VIEW (book_shell_view); shell_window = e_shell_view_get_shell_window (shell_view); @@ -195,31 +175,23 @@ action_address_book_properties_cb (GtkAction *action, source = e_source_selector_ref_primary_selection (selector); g_return_if_fail (source != NULL); - uid = e_source_get_uid (source); - uid_to_editor = book_shell_view->priv->uid_to_editor; - - closure = g_hash_table_lookup (uid_to_editor, uid); - if (closure == NULL) { - GtkWidget *editor; + registry = e_source_selector_get_registry (selector); + config = e_book_source_config_new (registry, source); - editor = addressbook_config_edit_source ( - GTK_WIDGET (shell_window), source); + g_object_unref (source); - closure = g_new (EditorUidClosure, 1); - closure->editor = editor; - closure->uid = g_strdup (uid); - closure->view = book_shell_view; + dialog = e_source_config_dialog_new (E_SOURCE_CONFIG (config)); - g_hash_table_insert (uid_to_editor, closure->uid, closure); + gtk_window_set_transient_for ( + GTK_WINDOW (dialog), GTK_WINDOW (shell_window)); - g_object_weak_ref ( - G_OBJECT (closure->editor), (GWeakNotify) - e_book_shell_view_editor_weak_notify, closure); - } + icon_name = gtk_action_get_icon_name (action); + gtk_window_set_icon_name (GTK_WINDOW (dialog), icon_name); - gtk_window_present (GTK_WINDOW (closure->editor)); + gtk_window_set_title ( + GTK_WINDOW (dialog), _("Address Book Properties")); - g_object_unref (source); + gtk_widget_show (dialog); } #ifdef WITH_CONTACT_MAPS diff --git a/modules/addressbook/e-book-shell-view-private.c b/modules/addressbook/e-book-shell-view-private.c index 62793f3e50..641861284e 100644 --- a/modules/addressbook/e-book-shell-view-private.c +++ b/modules/addressbook/e-book-shell-view-private.c @@ -256,7 +256,6 @@ book_shell_view_activate_selected_source (EBookShellView *book_shell_view, ESourceSelector *selector) { EShellView *shell_view; - EShellWindow *shell_window; EBookShellContent *book_shell_content; EAddressbookView *view; EAddressbookModel *model; @@ -268,7 +267,6 @@ book_shell_view_activate_selected_source (EBookShellView *book_shell_view, gchar *view_id; shell_view = E_SHELL_VIEW (book_shell_view); - shell_window = e_shell_view_get_shell_window (shell_view); book_shell_content = book_shell_view->priv->book_shell_content; source = e_source_selector_ref_primary_selection (selector); @@ -293,8 +291,6 @@ book_shell_view_activate_selected_source (EBookShellView *book_shell_view, e_client_utils_open_new ( source, E_CLIENT_SOURCE_TYPE_CONTACTS, FALSE, NULL, - e_client_utils_authenticate_handler, - GTK_WINDOW (shell_window), book_shell_view_loaded_cb, g_object_ref (view)); @@ -341,7 +337,6 @@ book_shell_view_activate_selected_source (EBookShellView *book_shell_view, /* XXX No way to cancel this? */ e_client_utils_open_new ( source, E_CLIENT_SOURCE_TYPE_CONTACTS, FALSE, NULL, - e_client_utils_authenticate_handler, GTK_WINDOW (shell_window), book_shell_view_loaded_cb, g_object_ref (view)); g_signal_connect_object ( @@ -435,6 +430,30 @@ book_shell_view_selector_key_press_event_cb (EShellView *shell_view, } static void +book_shell_view_source_removed_cb (ESourceRegistry *registry, + ESource *source, + EBookShellView *book_shell_view) +{ + EBookShellViewPrivate *priv = book_shell_view->priv; + EBookShellContent *book_shell_content; + EAddressbookView *view; + const gchar *uid; + + uid = e_source_get_uid (source); + + book_shell_content = book_shell_view->priv->book_shell_content; + + /* Remove the EAddressbookView for the deleted source. */ + view = g_hash_table_lookup (priv->uid_to_view, uid); + if (view != NULL) { + e_book_shell_content_remove_view (book_shell_content, view); + g_hash_table_remove (priv->uid_to_view, uid); + } + + e_shell_view_update_actions (E_SHELL_VIEW (book_shell_view)); +} + +static void book_shell_view_load_view_collection (EShellViewClass *shell_view_class) { GalViewCollection *collection; @@ -495,20 +514,13 @@ e_book_shell_view_private_init (EBookShellView *book_shell_view, { EBookShellViewPrivate *priv = book_shell_view->priv; GHashTable *uid_to_view; - GHashTable *uid_to_editor; uid_to_view = g_hash_table_new_full ( g_str_hash, g_str_equal, (GDestroyNotify) g_free, (GDestroyNotify) g_object_unref); - uid_to_editor = g_hash_table_new_full ( - g_str_hash, g_str_equal, - (GDestroyNotify) g_free, - (GDestroyNotify) g_free); - priv->uid_to_view = uid_to_view; - priv->uid_to_editor = uid_to_editor; priv->preview_index = -1; if (!gal_view_collection_loaded (shell_view_class->view_collection)) @@ -523,11 +535,12 @@ void e_book_shell_view_private_constructed (EBookShellView *book_shell_view) { EBookShellViewPrivate *priv = book_shell_view->priv; + EShell *shell; + EShellView *shell_view; + EShellWindow *shell_window; EShellContent *shell_content; EShellSidebar *shell_sidebar; EShellBackend *shell_backend; - EShellView *shell_view; - EShellWindow *shell_window; ESourceSelector *selector; shell_view = E_SHELL_VIEW (book_shell_view); @@ -535,6 +548,7 @@ e_book_shell_view_private_constructed (EBookShellView *book_shell_view) shell_content = e_shell_view_get_shell_content (shell_view); shell_sidebar = e_shell_view_get_shell_sidebar (shell_view); shell_window = e_shell_view_get_shell_window (shell_view); + shell = e_shell_window_get_shell (shell_window); e_shell_window_add_action_group (shell_window, "contacts"); e_shell_window_add_action_group (shell_window, "contacts-filter"); @@ -544,9 +558,18 @@ e_book_shell_view_private_constructed (EBookShellView *book_shell_view) priv->book_shell_content = g_object_ref (shell_content); priv->book_shell_sidebar = g_object_ref (shell_sidebar); + /* Keep our own reference to this so we can + * disconnect our signal handler in dispose(). */ + priv->registry = g_object_ref (e_shell_get_registry (shell)); + selector = e_book_shell_sidebar_get_selector ( E_BOOK_SHELL_SIDEBAR (shell_sidebar)); + g_signal_connect ( + priv->registry, "source-removed", + G_CALLBACK (book_shell_view_source_removed_cb), + book_shell_view); + g_signal_connect_object ( selector, "button-press-event", G_CALLBACK (book_shell_view_selector_button_press_event_cb), @@ -585,8 +608,15 @@ e_book_shell_view_private_dispose (EBookShellView *book_shell_view) DISPOSE (priv->book_shell_content); DISPOSE (priv->book_shell_sidebar); + if (priv->registry != NULL) { + g_signal_handlers_disconnect_matched ( + priv->registry, G_SIGNAL_MATCH_DATA, + 0, 0, NULL, NULL, book_shell_view); + g_object_unref (priv->registry); + priv->registry = NULL; + } + g_hash_table_remove_all (priv->uid_to_view); - g_hash_table_remove_all (priv->uid_to_editor); } void @@ -595,15 +625,4 @@ e_book_shell_view_private_finalize (EBookShellView *book_shell_view) EBookShellViewPrivate *priv = book_shell_view->priv; g_hash_table_destroy (priv->uid_to_view); - g_hash_table_destroy (priv->uid_to_editor); -} - -void -e_book_shell_view_editor_weak_notify (EditorUidClosure *closure, - GObject *where_the_object_was) -{ - GHashTable *hash_table; - - hash_table = closure->view->priv->uid_to_editor; - g_hash_table_remove (hash_table, closure->uid); } diff --git a/modules/addressbook/e-book-shell-view-private.h b/modules/addressbook/e-book-shell-view-private.h index d1b30efec4..a110d37771 100644 --- a/modules/addressbook/e-book-shell-view-private.h +++ b/modules/addressbook/e-book-shell-view-private.h @@ -41,6 +41,7 @@ #include "shell/e-shell-utils.h" #include "misc/e-popup-action.h" #include "misc/e-selectable.h" +#include "misc/e-source-config-dialog.h" #include "addressbook/util/eab-book-util.h" #include "addressbook/gui/contact-editor/e-contact-editor.h" @@ -48,6 +49,7 @@ #include "addressbook/gui/widgets/eab-gui-util.h" #include "addressbook/gui/widgets/e-addressbook-view.h" #include "addressbook/gui/widgets/e-addressbook-selector.h" +#include "addressbook/gui/widgets/e-book-source-config.h" #include "e-book-shell-backend.h" #include "e-book-shell-content.h" @@ -75,14 +77,6 @@ G_BEGIN_DECLS -typedef struct _EditorUidClosure EditorUidClosure; - -struct _EditorUidClosure { - GtkWidget *editor; - gchar *uid; - EBookShellView *view; -}; - /* List these in the order to be displayed. * Positive values are reserved for categories. */ enum { @@ -105,8 +99,8 @@ struct _EBookShellViewPrivate { EBookShellContent *book_shell_content; EBookShellSidebar *book_shell_sidebar; + ESourceRegistry *registry; GHashTable *uid_to_view; - GHashTable *uid_to_editor; gint preview_index; @@ -129,9 +123,6 @@ void e_book_shell_view_private_finalize void e_book_shell_view_actions_init (EBookShellView *book_shell_view); -void e_book_shell_view_editor_weak_notify - (EditorUidClosure *closure, - GObject *where_the_object_was); void e_book_shell_view_update_search_filter (EBookShellView *book_shell_view); diff --git a/modules/addressbook/e-book-shell-view.c b/modules/addressbook/e-book-shell-view.c index 84526e4a98..53136c2e02 100644 --- a/modules/addressbook/e-book-shell-view.c +++ b/modules/addressbook/e-book-shell-view.c @@ -29,59 +29,6 @@ static gpointer parent_class; static GType book_shell_view_type; static void -book_shell_view_source_list_changed_cb (EBookShellView *book_shell_view, - ESourceList *source_list) -{ - EBookShellViewPrivate *priv = book_shell_view->priv; - EBookShellContent *book_shell_content; - EShellView *shell_view; - GList *keys, *iter; - - g_return_if_fail (E_IS_SHELL_VIEW (book_shell_view)); - g_return_if_fail (book_shell_view->priv != NULL); - - shell_view = E_SHELL_VIEW (book_shell_view); - book_shell_content = book_shell_view->priv->book_shell_content; - - keys = g_hash_table_get_keys (priv->uid_to_view); - for (iter = keys; iter != NULL; iter = iter->next) { - gchar *uid = iter->data; - EAddressbookView *view; - - /* If the source still exists, move on. */ - if (e_source_list_peek_source_by_uid (source_list, uid)) - continue; - - /* Remove the view for the deleted source. */ - view = g_hash_table_lookup (priv->uid_to_view, uid); - e_book_shell_content_remove_view (book_shell_content, view); - g_hash_table_remove (priv->uid_to_view, uid); - } - g_list_free (keys); - - keys = g_hash_table_get_keys (priv->uid_to_editor); - for (iter = keys; iter != NULL; iter = iter->next) { - gchar *uid = iter->data; - EditorUidClosure *closure; - - /* If the source still exists, move on. */ - if (e_source_list_peek_source_by_uid (source_list, uid)) - continue; - - /* Remove the editor for the deleted source. */ - closure = g_hash_table_lookup (priv->uid_to_editor, uid); - g_object_weak_unref ( - G_OBJECT (closure->editor), (GWeakNotify) - e_book_shell_view_editor_weak_notify, closure); - gtk_widget_destroy (closure->editor); - g_hash_table_remove (priv->uid_to_editor, uid); - } - g_list_free (keys); - - e_shell_view_update_actions (shell_view); -} - -static void book_shell_view_dispose (GObject *object) { EBookShellView *book_shell_view; @@ -109,22 +56,12 @@ static void book_shell_view_constructed (GObject *object) { EBookShellView *book_shell_view; - EBookShellBackend *book_shell_backend; - ESourceList *source_list; /* Chain up to parent's constructed() method. */ G_OBJECT_CLASS (parent_class)->constructed (object); book_shell_view = E_BOOK_SHELL_VIEW (object); e_book_shell_view_private_constructed (book_shell_view); - - book_shell_backend = book_shell_view->priv->book_shell_backend; - source_list = e_book_shell_backend_get_source_list (book_shell_backend); - - g_signal_connect_object ( - source_list, "changed", - G_CALLBACK (book_shell_view_source_list_changed_cb), - book_shell_view, G_CONNECT_SWAPPED); } static void @@ -262,9 +199,10 @@ book_shell_view_update_actions (EShellView *shell_view) /* Be descriptive. */ gboolean any_contacts_selected; - gboolean can_delete_primary_source; gboolean has_primary_source; gboolean multiple_contacts_selected; + gboolean primary_source_is_removable; + gboolean primary_source_is_writable; gboolean single_contact_selected; gboolean selection_is_contact_list; gboolean selection_has_email; @@ -297,8 +235,10 @@ book_shell_view_update_actions (EShellView *shell_view) has_primary_source = (state & E_BOOK_SHELL_SIDEBAR_HAS_PRIMARY_SOURCE); - can_delete_primary_source = - (state & E_BOOK_SHELL_SIDEBAR_CAN_DELETE_PRIMARY_SOURCE); + primary_source_is_removable = + (state & E_BOOK_SHELL_SIDEBAR_PRIMARY_SOURCE_IS_REMOVABLE); + primary_source_is_writable = + (state & E_BOOK_SHELL_SIDEBAR_PRIMARY_SOURCE_IS_WRITABLE); any_contacts_selected = (single_contact_selected || multiple_contacts_selected); @@ -308,7 +248,7 @@ book_shell_view_update_actions (EShellView *shell_view) gtk_action_set_sensitive (action, sensitive); action = ACTION (ADDRESS_BOOK_DELETE); - sensitive = can_delete_primary_source; + sensitive = primary_source_is_removable; gtk_action_set_sensitive (action, sensitive); action = ACTION (ADDRESS_BOOK_PRINT); @@ -319,8 +259,12 @@ book_shell_view_update_actions (EShellView *shell_view) sensitive = has_primary_source; gtk_action_set_sensitive (action, sensitive); + action = ACTION (ADDRESS_BOOK_PROPERTIES); + sensitive = primary_source_is_writable; + gtk_action_set_sensitive (action, sensitive); + action = ACTION (ADDRESS_BOOK_RENAME); - sensitive = can_delete_primary_source; + sensitive = primary_source_is_writable; gtk_action_set_sensitive (action, sensitive); action = ACTION (ADDRESS_BOOK_STOP); diff --git a/widgets/misc/Makefile.am b/widgets/misc/Makefile.am index 69f5d87bf8..6aed9f013b 100644 --- a/widgets/misc/Makefile.am +++ b/widgets/misc/Makefile.am @@ -21,6 +21,7 @@ widgetsinclude_HEADERS = \ e-attachment-tree-view.h \ e-attachment-view.h \ e-auth-combo-box.h \ + e-autocomplete-selector.h \ e-buffer-tagger.h \ e-calendar.h \ e-calendar-item.h \ @@ -108,6 +109,7 @@ libemiscwidgets_la_SOURCES = \ e-attachment-tree-view.c \ e-attachment-view.c \ e-auth-combo-box.c \ + e-autocomplete-selector.c \ e-buffer-tagger.c \ e-calendar.c \ e-calendar-item.c \ diff --git a/widgets/misc/e-autocomplete-selector.h b/widgets/misc/e-autocomplete-selector.h new file mode 100644 index 0000000000..8caa13268e --- /dev/null +++ b/widgets/misc/e-autocomplete-selector.h @@ -0,0 +1,64 @@ +/* + * e-autocomplete-selector.h + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) version 3. + * + * 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 the program; if not, see <http://www.gnu.org/licenses/> + * + */ + +#ifndef E_AUTOCOMPLETE_SELECTOR_H +#define E_AUTOCOMPLETE_SELECTOR_H + +#include <libedataserverui/e-source-selector.h> + +/* Standard GObject macros */ +#define E_TYPE_AUTOCOMPLETE_SELECTOR \ + (e_autocomplete_selector_get_type ()) +#define E_AUTOCOMPLETE_SELECTOR(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST \ + ((obj), E_TYPE_AUTOCOMPLETE_SELECTOR, EAutocompleteSelector)) +#define E_AUTOCOMPLETE_SELECTOR_CLASS(cls) \ + (G_TYPE_CHECK_CLASS_CAST \ + ((cls), E_TYPE_AUTOCOMPLETE_SELECTOR, EAutocompleteSelectorClass)) +#define E_IS_AUTOCOMPLETE_SELECTOR(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE \ + ((obj), E_TYPE_AUTOCOMPLETE_SELECTOR)) +#define E_IS_AUTOCOMPLETE_SELECTOR_CLASS(cls) \ + (G_TYPE_CHECK_CLASS_TYPE \ + ((cls), E_TYPE_AUTOCOMPLETE_SELECTOR)) +#define E_AUTOCOMPLETE_SELECTOR_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS \ + ((obj), E_TYPE_AUTOCOMPLETE_SELECTOR, EAutocompleteSelectorClass)) + +G_BEGIN_DECLS + +typedef struct _EAutocompleteSelector EAutocompleteSelector; +typedef struct _EAutocompleteSelectorClass EAutocompleteSelectorClass; +typedef struct _EAutocompleteSelectorPrivate EAutocompleteSelectorPrivate; + +struct _EAutocompleteSelector { + ESourceSelector parent; + EAutocompleteSelectorPrivate *priv; +}; + +struct _EAutocompleteSelectorClass { + ESourceSelectorClass parent_class; +}; + +GType e_autocomplete_selector_get_type + (void) G_GNUC_CONST; +GtkWidget * e_autocomplete_selector_new (ESourceRegistry *registry); + +G_END_DECLS + +#endif /* E_AUTOCOMPLETE_SELECTOR_H */ |