evolution-data-server r9462 - trunk/libedataserverui
- From: mcrha svn gnome org
- To: svn-commits-list gnome org
- Subject: evolution-data-server r9462 - trunk/libedataserverui
- Date: Mon, 1 Sep 2008 10:06:01 +0000 (UTC)
Author: mcrha
Date: Mon Sep 1 10:06:01 2008
New Revision: 9462
URL: http://svn.gnome.org/viewvc/evolution-data-server?rev=9462&view=rev
Log:
2008-09-01 Milan Crha <mcrha redhat com>
** Fix for bug #332354
* e-name-selector-entry.h: (USER_QUERY_FIELDS),
(ens_util_populate_user_query_fields):
* e-name-selector-entry.c: (struct _ENameSelectorEntryPrivate),
(e_name_selector_entry_dispose), (ens_util_populate_user_query_fields),
(set_completion_query), (e_name_selector_entry_init):
* e-name-selector-dialog.c: (struct _ENameSelectorDialogPrivate),
(e_name_selector_dialog_init), (e_name_selector_dialog_finalize),
(search_changed): User can define his own query fields
in "/apps/evolution/addressbook/completion/user_query_fields" which
should be a string list of EContact field names to search in.
Modified:
trunk/libedataserverui/ChangeLog
trunk/libedataserverui/e-name-selector-dialog.c
trunk/libedataserverui/e-name-selector-entry.c
trunk/libedataserverui/e-name-selector-entry.h
Modified: trunk/libedataserverui/e-name-selector-dialog.c
==============================================================================
--- trunk/libedataserverui/e-name-selector-dialog.c (original)
+++ trunk/libedataserverui/e-name-selector-dialog.c Mon Sep 1 10:06:01 2008
@@ -33,6 +33,7 @@
#include "libedataserver/e-categories.h"
#include "libedataserver/libedataserver-private.h"
#include "e-name-selector-dialog.h"
+#include "e-name-selector-entry.h"
typedef struct {
gchar *name;
@@ -55,6 +56,7 @@
struct _ENameSelectorDialogPrivate
{
guint destination_index;
+ GSList *user_query_fields;
};
static void search_changed (ENameSelectorDialog *name_selector_dialog);
@@ -139,6 +141,7 @@
ENameSelectorDialogPrivate *priv = E_NAME_SELECTOR_DIALOG_GET_PRIVATE (name_selector_dialog);
priv->destination_index = 0;
+ priv->user_query_fields = NULL;
/* Get Glade GUI */
gladefile = g_build_filename (E_DATA_SERVER_UI_GLADEDIR,
@@ -211,6 +214,13 @@
name_selector_dialog->name_selector_model = e_name_selector_model_new ();
name_selector_dialog->sections = g_array_new (FALSE, FALSE, sizeof (Section));
+ gconf_client = gconf_client_get_default();
+ uid = gconf_client_get_string (gconf_client, "/apps/evolution/addressbook/display/primary_addressbook",
+ NULL);
+ /* read user_query_fields here, because we are using it in call of setup_name_selector_model */
+ priv->user_query_fields = gconf_client_get_list (gconf_client, USER_QUERY_FIELDS, GCONF_VALUE_STRING, NULL);
+ g_object_unref (gconf_client);
+
setup_name_selector_model (name_selector_dialog);
/* Create source menu */
@@ -221,10 +231,6 @@
G_CALLBACK (source_changed), name_selector_dialog);
g_object_unref (source_list);
- gconf_client = gconf_client_get_default();
- uid = gconf_client_get_string (gconf_client, "/apps/evolution/addressbook/display/primary_addressbook",
- NULL);
- g_object_unref (gconf_client);
if (uid) {
e_source_combo_box_set_active_uid (
E_SOURCE_COMBO_BOX (widget), uid);
@@ -285,6 +291,13 @@
e_name_selector_dialog_finalize (GObject *object)
{
ENameSelectorDialog *name_selector_dialog = E_NAME_SELECTOR_DIALOG (object);
+ ENameSelectorDialogPrivate *priv = E_NAME_SELECTOR_DIALOG_GET_PRIVATE (name_selector_dialog);
+
+ if (priv && priv->user_query_fields) {
+ g_slist_foreach (priv->user_query_fields, (GFunc)g_free, NULL);
+ g_slist_free (priv->user_query_fields);
+ priv->user_query_fields = NULL;
+ }
g_array_free (name_selector_dialog->sections, TRUE);
g_object_unref (name_selector_dialog->button_size_group);
@@ -721,6 +734,7 @@
static void
search_changed (ENameSelectorDialog *name_selector_dialog)
{
+ ENameSelectorDialogPrivate *priv = E_NAME_SELECTOR_DIALOG_GET_PRIVATE (name_selector_dialog);
EContactStore *contact_store;
EBookQuery *book_query;
GtkWidget *combo_box;
@@ -729,6 +743,7 @@
gchar *query_string;
gchar *category;
gchar *category_escaped;
+ gchar *user_fields_str;
combo_box = glade_xml_get_widget (
name_selector_dialog->gui, "combobox-category");
@@ -741,23 +756,27 @@
text = gtk_entry_get_text (name_selector_dialog->search_entry);
text_escaped = escape_sexp_string (text);
+ user_fields_str = ens_util_populate_user_query_fields (priv->user_query_fields, text, text_escaped);
+
if (!strcmp (category, _("Any Category")))
query_string = g_strdup_printf (
"(or (beginswith \"file_as\" %s) "
" (beginswith \"full_name\" %s) "
" (beginswith \"email\" %s) "
- " (beginswith \"nickname\" %s)))",
+ " (beginswith \"nickname\" %s)%s))",
text_escaped, text_escaped,
- text_escaped, text_escaped);
+ text_escaped, text_escaped,
+ user_fields_str ? user_fields_str : "");
else
query_string = g_strdup_printf (
"(and (is \"category_list\" %s) "
"(or (beginswith \"file_as\" %s) "
" (beginswith \"full_name\" %s) "
" (beginswith \"email\" %s) "
- " (beginswith \"nickname\" %s)))",
+ " (beginswith \"nickname\" %s)%s))",
category_escaped, text_escaped, text_escaped,
- text_escaped, text_escaped);
+ text_escaped, text_escaped,
+ user_fields_str ? user_fields_str : "");
book_query = e_book_query_from_string (query_string);
@@ -771,6 +790,7 @@
g_free (text_escaped);
g_free (category_escaped);
g_free (category);
+ g_free (user_fields_str);
}
static void
Modified: trunk/libedataserverui/e-name-selector-entry.c
==============================================================================
--- trunk/libedataserverui/e-name-selector-entry.c (original)
+++ trunk/libedataserverui/e-name-selector-entry.c Mon Sep 1 10:06:01 2008
@@ -48,6 +48,7 @@
struct _ENameSelectorEntryPrivate
{
gboolean is_completing;
+ GSList *user_query_fields;
};
#define E_NAME_SELECTOR_ENTRY_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), E_TYPE_NAME_SELECTOR_ENTRY, ENameSelectorEntryPrivate))
@@ -105,6 +106,9 @@
e_name_selector_entry_dispose (GObject *object)
{
ENameSelectorEntry *name_selector_entry = E_NAME_SELECTOR_ENTRY (object);
+ ENameSelectorEntryPrivate *priv;
+
+ priv = E_NAME_SELECTOR_ENTRY_GET_PRIVATE (name_selector_entry);
if (name_selector_entry->entry_completion) {
g_object_unref (name_selector_entry->entry_completion);
@@ -116,6 +120,12 @@
name_selector_entry->destination_store = NULL;
}
+ if (priv && priv->user_query_fields) {
+ g_slist_foreach (priv->user_query_fields, (GFunc)g_free, NULL);
+ g_slist_free (priv->user_query_fields);
+ priv->user_query_fields = NULL;
+ }
+
if (G_OBJECT_CLASS (e_name_selector_entry_parent_class)->dispose)
G_OBJECT_CLASS (e_name_selector_entry_parent_class)->dispose (object);
}
@@ -468,14 +478,58 @@
return encoded_string;
}
+/**
+ * ens_util_populate_user_query_fields:
+ * Populates list of user query fields to string usable in query string.
+ * Returned pointer is either newly allocated string, supposed to be freed with g_free,
+ * or NULL if no fields defined.
+ **/
+gchar *
+ens_util_populate_user_query_fields (GSList *user_query_fields, const char *cue_str, const char *encoded_cue_str)
+{
+ GString *user_fields;
+ GSList *s;
+
+ g_return_val_if_fail (cue_str != NULL, NULL);
+ g_return_val_if_fail (encoded_cue_str != NULL, NULL);
+
+ user_fields = g_string_new ("");
+
+ for (s = user_query_fields; s; s = s->next) {
+ const char *field = s->data;
+
+ if (!field || !*field)
+ continue;
+
+ if (*field == '$') {
+ g_string_append_printf (user_fields, " (beginswith \"%s\" %s) ", field + 1, encoded_cue_str);
+ } else if (*field == '@') {
+ g_string_append_printf (user_fields, " (is \"%s\" %s) ", field + 1, encoded_cue_str);
+ } else {
+ gchar *tmp = name_style_query (field, cue_str);
+
+ g_string_append (user_fields, " ");
+ g_string_append (user_fields, tmp);
+ g_string_append (user_fields, " ");
+ g_free (tmp);
+ }
+ }
+
+ return g_string_free (user_fields, !user_fields->str || !*user_fields->str);
+}
+
static void
set_completion_query (ENameSelectorEntry *name_selector_entry, const gchar *cue_str)
{
+ ENameSelectorEntryPrivate *priv;
EBookQuery *book_query;
gchar *query_str;
gchar *encoded_cue_str;
gchar *full_name_query_str;
gchar *file_as_query_str;
+ gchar *user_fields_str;
+
+ priv = E_NAME_SELECTOR_ENTRY_GET_PRIVATE (name_selector_entry);
if (!name_selector_entry->contact_store)
return;
@@ -489,16 +543,20 @@
encoded_cue_str = escape_sexp_string (cue_str);
full_name_query_str = name_style_query ("full_name", cue_str);
file_as_query_str = name_style_query ("file_as", cue_str);
+ user_fields_str = ens_util_populate_user_query_fields (priv->user_query_fields, cue_str, encoded_cue_str);
query_str = g_strdup_printf ("(or "
" (beginswith \"nickname\" %s) "
" (beginswith \"email\" %s) "
" %s "
" %s "
+ " %s "
")",
encoded_cue_str, encoded_cue_str,
- full_name_query_str, file_as_query_str);
+ full_name_query_str, file_as_query_str,
+ user_fields_str ? user_fields_str : "");
+ g_free (user_fields_str);
g_free (file_as_query_str);
g_free (full_name_query_str);
g_free (encoded_cue_str);
@@ -2475,6 +2533,7 @@
else COMPLETION_CUE_MIN_LEN = 3;
}
COMPLETION_FORCE_SHOW_ADDRESS = gconf_client_get_bool (gconf, FORCE_SHOW_ADDRESS, NULL);
+ priv->user_query_fields = gconf_client_get_list (gconf, USER_QUERY_FIELDS, GCONF_VALUE_STRING, NULL);
g_object_unref (G_OBJECT (gconf));
/* Edit signals */
Modified: trunk/libedataserverui/e-name-selector-entry.h
==============================================================================
--- trunk/libedataserverui/e-name-selector-entry.h (original)
+++ trunk/libedataserverui/e-name-selector-entry.h Mon Sep 1 10:06:01 2008
@@ -41,6 +41,7 @@
#define MINIMUM_QUERY_LENGTH "/apps/evolution/addressbook/completion/minimum_query_length"
#define FORCE_SHOW_ADDRESS "/apps/evolution/addressbook/completion/show_address"
+#define USER_QUERY_FIELDS "/apps/evolution/addressbook/completion/user_query_fields"
typedef struct _ENameSelectorEntry ENameSelectorEntry;
typedef struct _ENameSelectorEntryClass ENameSelectorEntryClass;
@@ -91,6 +92,8 @@
void e_name_selector_entry_set_contact_list_editor_func (ENameSelectorEntry *name_selector_entry,
gpointer func);
+gchar *ens_util_populate_user_query_fields (GSList *user_query_fields, const char *cue_str, const char *encoded_cue_str);
+
G_END_DECLS
#endif /* E_NAME_SELECTOR_ENTRY_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]