diff options
author | Christopher James Lahey <clahey@ximian.com> | 2002-01-21 23:11:50 +0800 |
---|---|---|
committer | Chris Lahey <clahey@src.gnome.org> | 2002-01-21 23:11:50 +0800 |
commit | 43c9ba9a203084dc5a341c781593d7d7337e2b9a (patch) | |
tree | b432d469caf6b4356ced3db998df8ab5c9ddca04 /addressbook | |
parent | fa21c59a5f421322ad1b678c6b9328c8c074dc6e (diff) | |
download | gsoc2013-evolution-43c9ba9a203084dc5a341c781593d7d7337e2b9a.tar gsoc2013-evolution-43c9ba9a203084dc5a341c781593d7d7337e2b9a.tar.gz gsoc2013-evolution-43c9ba9a203084dc5a341c781593d7d7337e2b9a.tar.bz2 gsoc2013-evolution-43c9ba9a203084dc5a341c781593d7d7337e2b9a.tar.lz gsoc2013-evolution-43c9ba9a203084dc5a341c781593d7d7337e2b9a.tar.xz gsoc2013-evolution-43c9ba9a203084dc5a341c781593d7d7337e2b9a.tar.zst gsoc2013-evolution-43c9ba9a203084dc5a341c781593d7d7337e2b9a.zip |
Set the number of cards to return to the value specified in the ldap uri,
2002-01-21 Christopher James Lahey <clahey@ximian.com>
* backend/pas/pas-backend-ldap.c (ldap_search_handler): Set the
number of cards to return to the value specified in the ldap uri,
leaving the default at 100. Fixes Ximian bug #13953.
* gui/component/addressbook-config.c (addressbook_source_dialog),
gui/component/addressbook-config.glade: Added a limit entry here
to edit the limit field of the source.
* gui/component/addressbook-storage.c,
gui/component/addressbook-storage.h
(addressbook_storage_init_source_uri): Added a limit field to this
class and pass that value through in the uri that's generated.
svn path=/trunk/; revision=15415
Diffstat (limited to 'addressbook')
-rw-r--r-- | addressbook/ChangeLog | 15 | ||||
-rw-r--r-- | addressbook/backend/pas/pas-backend-ldap.c | 38 | ||||
-rw-r--r-- | addressbook/gui/component/addressbook-config.c | 12 | ||||
-rw-r--r-- | addressbook/gui/component/addressbook-config.glade | 78 | ||||
-rw-r--r-- | addressbook/gui/component/addressbook-storage.c | 56 | ||||
-rw-r--r-- | addressbook/gui/component/addressbook-storage.h | 1 |
6 files changed, 190 insertions, 10 deletions
diff --git a/addressbook/ChangeLog b/addressbook/ChangeLog index 507ee7ed35..770acc94e2 100644 --- a/addressbook/ChangeLog +++ b/addressbook/ChangeLog @@ -1,3 +1,18 @@ +2002-01-21 Christopher James Lahey <clahey@ximian.com> + + * backend/pas/pas-backend-ldap.c (ldap_search_handler): Set the + number of cards to return to the value specified in the ldap uri, + leaving the default at 100. Fixes Ximian bug #13953. + + * gui/component/addressbook-config.c (addressbook_source_dialog), + gui/component/addressbook-config.glade: Added a limit entry here + to edit the limit field of the source. + + * gui/component/addressbook-storage.c, + gui/component/addressbook-storage.h + (addressbook_storage_init_source_uri): Added a limit field to this + class and pass that value through in the uri that's generated. + 2002-01-18 Christopher James Lahey <clahey@ximian.com> * backend/ebook/e-card-compare.c: Made username match with no diff --git a/addressbook/backend/pas/pas-backend-ldap.c b/addressbook/backend/pas/pas-backend-ldap.c index 1432133fd3..ff5c29168b 100644 --- a/addressbook/backend/pas/pas-backend-ldap.c +++ b/addressbook/backend/pas/pas-backend-ldap.c @@ -44,6 +44,8 @@ #include "pas-book.h" #include "pas-card-cursor.h" +#include <stdlib.h> + #define LDAP_MAX_SEARCH_RESPONSES 100 @@ -69,6 +71,7 @@ struct _PASBackendLDAPPrivate { gchar *ldap_rootdn; int ldap_port; int ldap_scope; + int ldap_limit; GList *book_views; LDAP *ldap; @@ -2285,7 +2288,7 @@ ldap_search_handler (PASBackend *backend, LDAPOp *op) NULL, /* XXX */ NULL, /* XXX */ NULL, - LDAP_MAX_SEARCH_RESPONSES, &view->search_msgid); + bl->priv->ldap_limit, &view->search_msgid); if (ldap_err != LDAP_SUCCESS) { pas_book_view_notify_status_message (view->book_view, ldap_err2string(ldap_err)); @@ -2538,10 +2541,39 @@ pas_backend_ldap_load_uri (PASBackend *backend, PASBackendLDAP *bl = PAS_BACKEND_LDAP (backend); LDAPURLDesc *lud; int ldap_error; + char **attributes; + int i; + int limit = 100; g_assert (bl->priv->connected == FALSE); - ldap_error = ldap_url_parse ((char*)uri, &lud); + attributes = g_strsplit (uri, ";", 0); + + if (attributes[0] == NULL) + return FALSE; + + for (i = 1; attributes[i]; i++) { + char *equals; + char *value; + int key_length; + equals = strchr (attributes[i], '='); + if (equals) { + key_length = equals - attributes[i]; + value = equals + 1; + } else { + key_length = strlen (attributes[i]); + value = NULL; + } + + if (key_length == strlen("limit") && !strncmp (attributes[i], "limit", key_length)) { + if (value) + limit = atoi(value); + } + } + + ldap_error = ldap_url_parse ((char*)attributes[0], &lud); + g_strfreev (attributes); + if (ldap_error == LDAP_SUCCESS) { g_free(bl->priv->uri); bl->priv->uri = g_strdup (uri); @@ -2551,6 +2583,7 @@ pas_backend_ldap_load_uri (PASBackend *backend, if (bl->priv->ldap_port == 0) bl->priv->ldap_port = LDAP_PORT; bl->priv->ldap_rootdn = g_strdup(lud->lud_dn); + bl->priv->ldap_limit = limit; bl->priv->ldap_scope = lud->lud_scope; ldap_free_urldesc(lud); @@ -2746,6 +2779,7 @@ pas_backend_ldap_init (PASBackendLDAP *backend) priv = g_new0 (PASBackendLDAPPrivate, 1); priv->supported_fields = e_list_new ((EListCopyFunc)g_strdup, (EListFreeFunc)g_free, NULL); + priv->ldap_limit = 100; backend->priv = priv; } diff --git a/addressbook/gui/component/addressbook-config.c b/addressbook/gui/component/addressbook-config.c index de65019a97..33feb391ab 100644 --- a/addressbook/gui/component/addressbook-config.c +++ b/addressbook/gui/component/addressbook-config.c @@ -13,6 +13,7 @@ #include <e-util/e-html-utils.h> #include "addressbook-config.h" #include "addressbook-storage.h" +#include <stdlib.h> typedef struct _AddressbookSourceDialog AddressbookSourceDialog; typedef struct _AddressbookSourcePageItem AddressbookSourcePageItem; @@ -33,6 +34,7 @@ struct _AddressbookSourceDialog { GtkWidget *port; GtkWidget *rootdn; + GtkWidget *limit; GtkWidget *scope_optionmenu; AddressbookLDAPScopeType ldap_scope; GtkWidget *auth_checkbutton; @@ -126,11 +128,15 @@ add_focus_handler (GtkWidget *widget, GtkWidget *notebook, int page_num) static void addressbook_source_dialog_set_source (AddressbookSourceDialog *dialog, AddressbookSource *source) { + char *string; e_utf8_gtk_entry_set_text (GTK_ENTRY (dialog->name), source ? source->name : ""); e_utf8_gtk_entry_set_text (GTK_ENTRY (dialog->host), source ? source->host : ""); e_utf8_gtk_entry_set_text (GTK_ENTRY (dialog->email), source ? source->email_addr : ""); e_utf8_gtk_entry_set_text (GTK_ENTRY (dialog->port), source ? source->port : "389"); e_utf8_gtk_entry_set_text (GTK_ENTRY (dialog->rootdn), source ? source->rootdn : ""); + string = g_strdup_printf ("%d", source ? source->limit : 100); + e_utf8_gtk_entry_set_text (GTK_ENTRY (dialog->limit), string); + g_free (string); gtk_option_menu_set_history (GTK_OPTION_MENU(dialog->scope_optionmenu), source ? source->scope : ADDRESSBOOK_LDAP_SCOPE_ONELEVEL); dialog->ldap_scope = source ? source->scope : ADDRESSBOOK_LDAP_SCOPE_ONELEVEL; @@ -150,6 +156,7 @@ addressbook_source_dialog_get_source (AddressbookSourceDialog *dialog) source->email_addr = e_utf8_gtk_entry_get_text (GTK_ENTRY (dialog->email)); source->port = e_utf8_gtk_entry_get_text (GTK_ENTRY (dialog->port)); source->rootdn = e_utf8_gtk_entry_get_text (GTK_ENTRY (dialog->rootdn)); + source->limit = atoi(e_utf8_gtk_entry_get_text (GTK_ENTRY (dialog->limit))); source->scope = dialog->ldap_scope; source->auth = (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->auth_checkbutton)) ? ADDRESSBOOK_LDAP_AUTH_SIMPLE : ADDRESSBOOK_LDAP_AUTH_NONE); @@ -235,6 +242,11 @@ addressbook_source_dialog (GladeXML *gui, AddressbookSource *source, GtkWidget * menu = gtk_option_menu_get_menu (GTK_OPTION_MENU(dialog->scope_optionmenu)); gtk_container_foreach (GTK_CONTAINER (menu), (GtkCallback)add_activate_cb, dialog); + dialog->limit = glade_xml_get_widget (gui, "limit-entry"); + gtk_signal_connect (GTK_OBJECT (dialog->limit), "changed", + GTK_SIGNAL_FUNC (addressbook_source_edit_changed), dialog); + add_focus_handler (dialog->limit, dialog->advanced_notebook, 3); + /* fill in source info if there is some */ addressbook_source_dialog_set_source (dialog, source); diff --git a/addressbook/gui/component/addressbook-config.glade b/addressbook/gui/component/addressbook-config.glade index 50241167c2..50b36e2462 100644 --- a/addressbook/gui/component/addressbook-config.glade +++ b/addressbook/gui/component/addressbook-config.glade @@ -432,7 +432,7 @@ <class>GtkTable</class> <name>table2</name> <border_width>3</border_width> - <rows>3</rows> + <rows>4</rows> <columns>2</columns> <homogeneous>False</homogeneous> <row_spacing>3</row_spacing> @@ -604,6 +604,57 @@ Sub <initial_choice>0</initial_choice> </widget> </widget> + + <widget> + <class>GtkLabel</class> + <name>label49</name> + <label>_Download Limit</label> + <justify>GTK_JUSTIFY_CENTER</justify> + <wrap>False</wrap> + <xalign>0</xalign> + <yalign>0.5</yalign> + <xpad>0</xpad> + <ypad>0</ypad> + <default_focus_target>limit-entry</default_focus_target> + <child> + <left_attach>0</left_attach> + <right_attach>1</right_attach> + <top_attach>3</top_attach> + <bottom_attach>4</bottom_attach> + <xpad>0</xpad> + <ypad>0</ypad> + <xexpand>False</xexpand> + <yexpand>False</yexpand> + <xshrink>False</xshrink> + <yshrink>False</yshrink> + <xfill>True</xfill> + <yfill>False</yfill> + </child> + </widget> + + <widget> + <class>GtkEntry</class> + <name>limit-entry</name> + <can_focus>True</can_focus> + <editable>True</editable> + <text_visible>True</text_visible> + <text_max_length>0</text_max_length> + <text>100</text> + <child> + <left_attach>1</left_attach> + <right_attach>2</right_attach> + <top_attach>3</top_attach> + <bottom_attach>4</bottom_attach> + <xpad>0</xpad> + <ypad>0</ypad> + <xexpand>True</xexpand> + <yexpand>False</yexpand> + <xshrink>False</xshrink> + <yshrink>False</yshrink> + <xfill>True</xfill> + <yfill>False</yfill> + </child> + </widget> </widget> <widget> @@ -696,6 +747,31 @@ Sub <xpad>0</xpad> <ypad>0</ypad> </widget> + + <widget> + <class>GtkLabel</class> + <name>label51</name> + <label>This is the maximum number of cards to download. Setting this number too large will slow down this addressbook.</label> + <justify>GTK_JUSTIFY_CENTER</justify> + <wrap>True</wrap> + <xalign>0.5</xalign> + <yalign>0.5</yalign> + <xpad>0</xpad> + <ypad>0</ypad> + </widget> + + <widget> + <class>GtkLabel</class> + <child_name>Notebook:tab</child_name> + <name>label50</name> + <label>label50</label> + <justify>GTK_JUSTIFY_CENTER</justify> + <wrap>True</wrap> + <xalign>0.5</xalign> + <yalign>0.5</yalign> + <xpad>0</xpad> + <ypad>0</ypad> + </widget> </widget> </widget> diff --git a/addressbook/gui/component/addressbook-storage.c b/addressbook/gui/component/addressbook-storage.c index 8f22ac359a..ed8a58ed11 100644 --- a/addressbook/gui/component/addressbook-storage.c +++ b/addressbook/gui/component/addressbook-storage.c @@ -31,6 +31,7 @@ <rootdn></rootdn> <authmethod>simple</authmethod> <emailaddr>toshok@blubag.com</emailaddr> + <limit>100</limit> <rememberpass/> </contactserver> </addressbooks> @@ -231,6 +232,30 @@ get_string_value (xmlNode *node, return retval; } + +static int +get_integer_value (xmlNode *node, + const char *name, + int defval) +{ + xmlNode *p; + xmlChar *xml_string; + int retval; + + p = e_xml_get_child_by_name (node, (xmlChar *) name); + if (p == NULL) + return defval; + + p = e_xml_get_child_by_name (p, (xmlChar *) "text"); + if (p == NULL) /* there's no text between the tags, return the default */ + return defval; + + xml_string = xmlNodeListGetString (node->doc, p, 1); + retval = atoi (xml_string); + xmlFree (xml_string); + + return retval; +} #endif static char * @@ -299,9 +324,15 @@ addressbook_storage_init_source_uri (AddressbookSource *source) if (source->uri) g_free (source->uri); - source->uri = g_strdup_printf ("ldap://%s:%s/%s??%s", - source->host, source->port, - source->rootdn, ldap_unparse_scope(source->scope)); + if (source->limit != 100) + source->uri = g_strdup_printf ("ldap://%s:%s/%s?"/*trigraph prevention*/ "?%s;limit=%d", + source->host, source->port, + source->rootdn, ldap_unparse_scope(source->scope), + source->limit); + else + source->uri = g_strdup_printf ("ldap://%s:%s/%s?"/*trigraph prevention*/ "?%s", + source->host, source->port, + source->rootdn, ldap_unparse_scope(source->scope)); } #ifdef HAVE_LDAP @@ -330,7 +361,7 @@ load_source_data (const char *file_path) if (rv < 0) { g_error ("Failed to rename %s: %s\n", - ADDRESSBOOK_SOURCES_XML, + file_path, strerror(errno)); return FALSE; } else @@ -361,6 +392,7 @@ load_source_data (const char *file_path) source->scope = ldap_parse_scope (get_string_value (child, "scope")); source->auth = ldap_parse_auth (get_string_value (child, "authmethod")); source->email_addr = get_string_value (child, "emailaddr"); + source->limit = get_integer_value (child, "limit", 100); } else { g_warning ("unknown node '%s' in %s", child->name, file_path); @@ -414,6 +446,15 @@ ldap_source_foreach(AddressbookSource *source, xmlNode *root) (xmlChar *) ldap_unparse_scope(source->scope)); xmlNewChild (source_root, NULL, (xmlChar *) "authmethod", (xmlChar *) ldap_unparse_auth(source->auth)); + + if (source->limit != 100) { + char *string; + string = g_strdup_printf ("%d", source->limit); + xmlNewChild (source_root, NULL, (xmlChar *) "limit", + (xmlChar *) string); + g_free (string); + } + if (source->auth == ADDRESSBOOK_LDAP_AUTH_SIMPLE) { xmlNewChild (source_root, NULL, (xmlChar *) "emailaddr", (xmlChar *) source->email_addr); @@ -445,7 +486,7 @@ save_source_data (const char *file_path) xmlDocDumpMemory (doc, &buf, &buf_size); if (buf == NULL) { - g_error ("Failed to write %s: xmlBufferCreate() == NULL", ADDRESSBOOK_SOURCES_XML); + g_error ("Failed to write %s: xmlBufferCreate() == NULL", file_path); return FALSE; } @@ -454,13 +495,13 @@ save_source_data (const char *file_path) close (fd); if (0 > rv) { - g_error ("Failed to write new %s: %s\n", ADDRESSBOOK_SOURCES_XML, strerror(errno)); + g_error ("Failed to write new %s: %s\n", file_path, strerror(errno)); unlink (new_path); return FALSE; } else { if (0 > rename (new_path, file_path)) { - g_error ("Failed to rename %s: %s\n", ADDRESSBOOK_SOURCES_XML, strerror(errno)); + g_error ("Failed to rename %s: %s\n", file_path, strerror(errno)); unlink (new_path); return FALSE; } @@ -597,6 +638,7 @@ addressbook_source_copy (const AddressbookSource *source) copy->auth = source->auth; copy->email_addr = g_strdup (source->email_addr); copy->remember_passwd = source->remember_passwd; + copy->limit = source->limit; return copy; } diff --git a/addressbook/gui/component/addressbook-storage.h b/addressbook/gui/component/addressbook-storage.h index 8416d4de83..b59ec467f7 100644 --- a/addressbook/gui/component/addressbook-storage.h +++ b/addressbook/gui/component/addressbook-storage.h @@ -57,6 +57,7 @@ typedef struct { char *email_addr; /* used in AUTH_SIMPLE */ gboolean remember_passwd; char *uri; /* filled in from the above */ + int limit; } AddressbookSource; void addressbook_storage_setup (EvolutionShellComponent *shell_component, |