aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMilan Crha <mcrha@redhat.com>2009-12-11 04:12:48 +0800
committerMilan Crha <mcrha@redhat.com>2009-12-11 04:12:48 +0800
commit223c2f4a75c5423db244430ca3630717e2735a52 (patch)
tree962dc68f7636586f2224f131a7ecd306d53b7589
parent4a9bf4dffd98346f9eee848708df573df56ed1d6 (diff)
downloadgsoc2013-evolution-223c2f4a75c5423db244430ca3630717e2735a52.tar.gz
gsoc2013-evolution-223c2f4a75c5423db244430ca3630717e2735a52.tar.zst
gsoc2013-evolution-223c2f4a75c5423db244430ca3630717e2735a52.zip
Bug #602998 - Contacts searches are supposed to be per address book
-rw-r--r--addressbook/gui/widgets/e-addressbook-view.c61
-rw-r--r--addressbook/gui/widgets/e-addressbook-view.h13
-rw-r--r--modules/addressbook/e-book-shell-content.c30
-rw-r--r--modules/addressbook/e-book-shell-view-private.c3
-rw-r--r--modules/addressbook/e-book-shell-view-private.h2
-rw-r--r--modules/addressbook/e-book-shell-view.c54
-rw-r--r--modules/addressbook/e-book-shell-view.h3
7 files changed, 157 insertions, 9 deletions
diff --git a/addressbook/gui/widgets/e-addressbook-view.c b/addressbook/gui/widgets/e-addressbook-view.c
index afa8bc0c1e..a48ea8c351 100644
--- a/addressbook/gui/widgets/e-addressbook-view.c
+++ b/addressbook/gui/widgets/e-addressbook-view.c
@@ -84,6 +84,12 @@ struct _EAddressbookViewPrivate {
GObject *object;
GalViewInstance *view_instance;
+
+ /* stored search setup for this view */
+ gint filter_id;
+ gchar *search_text;
+ gint search_id;
+ EFilterRule *advanced_search;
};
enum {
@@ -492,6 +498,19 @@ addressbook_view_dispose (GObject *object)
priv->view_instance = NULL;
}
+ priv->filter_id = 0;
+ priv->search_id = 0;
+
+ if (priv->search_text) {
+ g_free (priv->search_text);
+ priv->search_text = NULL;
+ }
+
+ if (priv->advanced_search) {
+ g_object_unref (priv->advanced_search);
+ priv->advanced_search = NULL;
+ }
+
/* Chain up to parent's dispose() method. */
G_OBJECT_CLASS (parent_class)->dispose (object);
}
@@ -1344,3 +1363,45 @@ e_addressbook_view_move_to_folder (EAddressbookView *view, gboolean all)
{
view_transfer_contacts (view, TRUE, all);
}
+
+void
+e_addressbook_view_set_search (EAddressbookView *view, gint filter_id, gint search_id, const gchar *search_text, EFilterRule *advanced_search)
+{
+ EAddressbookViewPrivate *priv;
+
+ g_return_if_fail (view != NULL);
+ g_return_if_fail (E_IS_ADDRESSBOOK_VIEW (view));
+
+ priv = view->priv;
+
+ if (priv->search_text)
+ g_free (priv->search_text);
+ if (priv->advanced_search)
+ g_object_unref (priv->advanced_search);
+
+ priv->filter_id = filter_id;
+ priv->search_id = search_id;
+ priv->search_text = g_strdup (search_text);
+ priv->advanced_search = advanced_search ? e_filter_rule_clone (advanced_search) : NULL;
+}
+
+/* free returned values for search_text and advanced_search, if not NULL, as these are new copies */
+void
+e_addressbook_view_get_search (EAddressbookView *view, gint *filter_id, gint *search_id, gchar **search_text, EFilterRule **advanced_search)
+{
+ EAddressbookViewPrivate *priv;
+
+ g_return_if_fail (view != NULL);
+ g_return_if_fail (E_IS_ADDRESSBOOK_VIEW (view));
+ g_return_if_fail (filter_id != NULL);
+ g_return_if_fail (search_id != NULL);
+ g_return_if_fail (search_text != NULL);
+ g_return_if_fail (advanced_search != NULL);
+
+ priv = view->priv;
+
+ *filter_id = priv->filter_id;
+ *search_id = priv->search_id;
+ *search_text = g_strdup (priv->search_text);
+ *advanced_search = priv->advanced_search ? e_filter_rule_clone (priv->advanced_search) : NULL;
+}
diff --git a/addressbook/gui/widgets/e-addressbook-view.h b/addressbook/gui/widgets/e-addressbook-view.h
index 6abab6bf7a..319d060b89 100644
--- a/addressbook/gui/widgets/e-addressbook-view.h
+++ b/addressbook/gui/widgets/e-addressbook-view.h
@@ -29,6 +29,7 @@
#include <menus/gal-view-instance.h>
#include <misc/e-selection-model.h>
#include <shell/e-shell-view.h>
+#include <filter/e-filter-rule.h>
#include "e-addressbook-model.h"
#include "eab-contact-display.h"
@@ -117,6 +118,18 @@ void e_addressbook_view_move_to_folder
gboolean e_addressbook_view_can_create (EAddressbookView *view);
+void e_addressbook_view_set_search (EAddressbookView *view,
+ gint filter_id,
+ gint search_id,
+ const gchar *search_text,
+ EFilterRule *advanced_search);
+
+void e_addressbook_view_get_search (EAddressbookView *view,
+ gint *filter_id,
+ gint *search_id,
+ gchar **search_text,
+ EFilterRule **advanced_search);
+
G_END_DECLS
#endif /* E_ADDRESSBOOK_VIEW_H */
diff --git a/modules/addressbook/e-book-shell-content.c b/modules/addressbook/e-book-shell-content.c
index f5b147bf0d..46d9824f2e 100644
--- a/modules/addressbook/e-book-shell-content.c
+++ b/modules/addressbook/e-book-shell-content.c
@@ -28,6 +28,7 @@
#include "e-util/gconf-bridge.h"
#include "shell/e-shell-utils.h"
#include "widgets/misc/e-paned.h"
+#include "e-book-shell-view.h"
#define E_BOOK_SHELL_CONTENT_GET_PRIVATE(obj) \
(G_TYPE_INSTANCE_GET_PRIVATE \
@@ -519,9 +520,10 @@ void
e_book_shell_content_set_current_view (EBookShellContent *book_shell_content,
EAddressbookView *addressbook_view)
{
+ EBookShellView *book_shell_view;
GtkNotebook *notebook;
GtkWidget *child;
- gint page_num;
+ gint page_num, old_page_num;
g_return_if_fail (E_IS_BOOK_SHELL_CONTENT (book_shell_content));
g_return_if_fail (E_IS_ADDRESSBOOK_VIEW (addressbook_view));
@@ -531,7 +533,33 @@ e_book_shell_content_set_current_view (EBookShellContent *book_shell_content,
page_num = gtk_notebook_page_num (notebook, child);
g_return_if_fail (page_num >= 0);
+ old_page_num = gtk_notebook_get_current_page (notebook);
gtk_notebook_set_current_page (notebook, page_num);
+
+ if (old_page_num != page_num) {
+ EShellContent *shell_content;
+ gint filter_id = 0, search_id = 0;
+ gchar *search_text = NULL;
+ EFilterRule *advanced_search = NULL;
+ GtkRadioAction *radio_action;
+
+ shell_content = E_SHELL_CONTENT (book_shell_content);
+ book_shell_view = E_BOOK_SHELL_VIEW (e_shell_content_get_shell_view (shell_content));
+
+ e_book_shell_view_disable_searching (book_shell_view);
+ e_addressbook_view_get_search (addressbook_view, &filter_id, &search_id, &search_text, &advanced_search);
+ if (e_shell_content_get_filter_action (shell_content))
+ e_shell_content_set_filter_value (shell_content, filter_id);
+ radio_action = e_shell_content_get_search_radio_action (shell_content);
+ gtk_radio_action_set_current_value (radio_action, search_id);
+ e_shell_content_set_search_text (shell_content, search_text ? search_text : "");
+ e_shell_content_set_search_rule (shell_content, advanced_search);
+ g_free (search_text);
+ if (advanced_search)
+ g_object_unref (advanced_search);
+ e_book_shell_view_enable_searching (book_shell_view);
+ }
+
g_object_notify (G_OBJECT (book_shell_content), "current-view");
}
diff --git a/modules/addressbook/e-book-shell-view-private.c b/modules/addressbook/e-book-shell-view-private.c
index 279cf87cf6..5b71c3c555 100644
--- a/modules/addressbook/e-book-shell-view-private.c
+++ b/modules/addressbook/e-book-shell-view-private.c
@@ -242,6 +242,9 @@ book_shell_view_activate_selected_source (EBookShellView *book_shell_view,
widget = e_addressbook_view_new (shell_view, source);
gtk_widget_show (widget);
+ /* default searching options for a new view */
+ e_addressbook_view_set_search (E_ADDRESSBOOK_VIEW (widget), CONTACT_FILTER_ANY_CATEGORY, CONTACT_SEARCH_NAME_CONTAINS, NULL, NULL);
+
e_book_shell_content_insert_view (
book_shell_content,
E_ADDRESSBOOK_VIEW (widget));
diff --git a/modules/addressbook/e-book-shell-view-private.h b/modules/addressbook/e-book-shell-view-private.h
index 6d513aa273..f1b23c2cfb 100644
--- a/modules/addressbook/e-book-shell-view-private.h
+++ b/modules/addressbook/e-book-shell-view-private.h
@@ -108,6 +108,8 @@ struct _EBookShellViewPrivate {
GHashTable *uid_to_editor;
gint preview_index;
+
+ gint search_locked; /* can track whether search changed while locked, but it is not usable at the moment */
};
void e_book_shell_view_private_init
diff --git a/modules/addressbook/e-book-shell-view.c b/modules/addressbook/e-book-shell-view.c
index 6c4c4303d1..ebbf3e79d0 100644
--- a/modules/addressbook/e-book-shell-view.c
+++ b/modules/addressbook/e-book-shell-view.c
@@ -132,20 +132,28 @@ book_shell_view_execute_search (EShellView *shell_view)
EAddressbookModel *model;
gchar *query;
gchar *temp;
- gint value;
+ gint filter_id, search_id;
+ gchar *search_text = NULL;
+ EFilterRule *advanced_search = NULL;
priv = E_BOOK_SHELL_VIEW_GET_PRIVATE (shell_view);
+ if (priv->search_locked)
+ return;
+
shell_content = e_shell_view_get_shell_content (shell_view);
shell_window = e_shell_view_get_shell_window (shell_view);
action = GTK_RADIO_ACTION (ACTION (CONTACT_SEARCH_ANY_FIELD_CONTAINS));
- value = gtk_radio_action_get_current_value (action);
+ search_id = gtk_radio_action_get_current_value (action);
- if (value == CONTACT_SEARCH_ADVANCED) {
+ if (search_id == CONTACT_SEARCH_ADVANCED) {
query = e_shell_content_get_search_rule_as_string (shell_content);
if (!query)
query = g_strdup ("");
+
+ /* internal pointer, no need to free it */
+ advanced_search = e_shell_content_get_search_rule (shell_content);
} else {
const gchar *text;
const gchar *format;
@@ -155,10 +163,12 @@ book_shell_view_execute_search (EShellView *shell_view)
if (text == NULL || *text == '\0') {
text = "";
- value = CONTACT_SEARCH_ANY_FIELD_CONTAINS;
+ search_id = CONTACT_SEARCH_ANY_FIELD_CONTAINS;
}
- switch (value) {
+ search_text = text && *text ? g_strdup (text) : NULL;
+
+ switch (search_id) {
case CONTACT_SEARCH_NAME_CONTAINS:
format = "(contains \"full_name\" %s)";
break;
@@ -184,8 +194,8 @@ book_shell_view_execute_search (EShellView *shell_view)
}
/* Apply selected filter. */
- value = e_shell_content_get_filter_value (shell_content);
- switch (value) {
+ filter_id = e_shell_content_get_filter_value (shell_content);
+ switch (filter_id) {
case CONTACT_FILTER_ANY_CATEGORY:
break;
@@ -204,7 +214,7 @@ book_shell_view_execute_search (EShellView *shell_view)
const gchar *category_name;
categories = e_categories_get_list ();
- category_name = g_list_nth_data (categories, value);
+ category_name = g_list_nth_data (categories, filter_id);
g_list_free (categories);
temp = g_strdup_printf (
@@ -220,7 +230,9 @@ book_shell_view_execute_search (EShellView *shell_view)
view = e_book_shell_content_get_current_view (book_shell_content);
model = e_addressbook_view_get_model (view);
e_addressbook_model_set_query (model, query);
+ e_addressbook_view_set_search (view, filter_id, search_id, search_text, advanced_search);
g_free (query);
+ g_free (search_text);
e_book_shell_content_set_preview_contact (book_shell_content, NULL);
priv->preview_index = -1;
@@ -441,3 +453,29 @@ e_book_shell_view_register_type (GTypeModule *type_module)
type_module, E_TYPE_SHELL_VIEW,
"EBookShellView", &type_info, 0);
}
+
+void
+e_book_shell_view_disable_searching (EBookShellView *book_shell_view)
+{
+ EBookShellViewPrivate *priv;
+
+ g_return_if_fail (book_shell_view != NULL);
+ g_return_if_fail (E_IS_BOOK_SHELL_VIEW (book_shell_view));
+
+ priv = E_BOOK_SHELL_VIEW_GET_PRIVATE (book_shell_view);
+ priv->search_locked++;
+}
+
+void
+e_book_shell_view_enable_searching (EBookShellView *book_shell_view)
+{
+ EBookShellViewPrivate *priv;
+
+ g_return_if_fail (book_shell_view != NULL);
+ g_return_if_fail (E_IS_BOOK_SHELL_VIEW (book_shell_view));
+
+ priv = E_BOOK_SHELL_VIEW_GET_PRIVATE (book_shell_view);
+ g_return_if_fail (priv->search_locked > 0);
+
+ priv->search_locked--;
+}
diff --git a/modules/addressbook/e-book-shell-view.h b/modules/addressbook/e-book-shell-view.h
index 33a0c8a75d..a5e726b422 100644
--- a/modules/addressbook/e-book-shell-view.h
+++ b/modules/addressbook/e-book-shell-view.h
@@ -61,6 +61,9 @@ struct _EBookShellViewClass {
GType e_book_shell_view_get_type (void);
void e_book_shell_view_register_type (GTypeModule *type_module);
+void e_book_shell_view_disable_searching (EBookShellView *book_shell_view);
+void e_book_shell_view_enable_searching (EBookShellView *book_shell_view);
+
G_END_DECLS
#endif /* E_BOOK_SHELL_VIEW_H */