aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMilan Crha <mcrha@redhat.com>2012-07-10 23:01:12 +0800
committerMilan Crha <mcrha@redhat.com>2012-07-10 23:02:20 +0800
commita3bd7ff42fe0e2be150cfad7640a5e8d62d8821b (patch)
tree288c40f33a685c4fa838ed756e47d64deaa59b95
parent0163eacc4ac1826a53cfdd4adac9f7a5fa139890 (diff)
downloadgsoc2013-evolution-a3bd7ff42fe0e2be150cfad7640a5e8d62d8821b.tar
gsoc2013-evolution-a3bd7ff42fe0e2be150cfad7640a5e8d62d8821b.tar.gz
gsoc2013-evolution-a3bd7ff42fe0e2be150cfad7640a5e8d62d8821b.tar.bz2
gsoc2013-evolution-a3bd7ff42fe0e2be150cfad7640a5e8d62d8821b.tar.lz
gsoc2013-evolution-a3bd7ff42fe0e2be150cfad7640a5e8d62d8821b.tar.xz
gsoc2013-evolution-a3bd7ff42fe0e2be150cfad7640a5e8d62d8821b.tar.zst
gsoc2013-evolution-a3bd7ff42fe0e2be150cfad7640a5e8d62d8821b.zip
Add "auto-update" option to Search Folder Editor
-rw-r--r--libemail-engine/mail-vfolder.c34
-rw-r--r--libemail-utils/em-vfolder-rule.c98
-rw-r--r--libemail-utils/em-vfolder-rule.h11
-rw-r--r--mail/em-vfolder-editor-rule.c25
4 files changed, 121 insertions, 47 deletions
diff --git a/libemail-engine/mail-vfolder.c b/libemail-engine/mail-vfolder.c
index d1fb0a52f1..08e6e22fe5 100644
--- a/libemail-engine/mail-vfolder.c
+++ b/libemail-engine/mail-vfolder.c
@@ -399,12 +399,9 @@ mail_vfolder_add_folder (CamelStore *store,
* they must be explictly listed as a source. */
if (rule->source
&& !CAMEL_IS_VEE_STORE (store)
- && ((((EMVFolderRule *) rule)->with ==
- EM_VFOLDER_RULE_WITH_LOCAL && !remote)
- || (((EMVFolderRule *) rule)->with ==
- EM_VFOLDER_RULE_WITH_REMOTE_ACTIVE && remote)
- || (((EMVFolderRule *) rule)->with ==
- EM_VFOLDER_RULE_WITH_LOCAL_REMOTE_ACTIVE)))
+ && ((em_vfolder_rule_get_with ((EMVFolderRule *) rule) == EM_VFOLDER_RULE_WITH_LOCAL && !remote)
+ || (em_vfolder_rule_get_with ((EMVFolderRule *) rule) == EM_VFOLDER_RULE_WITH_REMOTE_ACTIVE && remote)
+ || (em_vfolder_rule_get_with ((EMVFolderRule *) rule) == EM_VFOLDER_RULE_WITH_LOCAL_REMOTE_ACTIVE)))
found = TRUE;
source = NULL;
@@ -760,17 +757,20 @@ rule_changed (EFilterRule *rule,
d(printf("Filter rule changed? for folder '%s'!!\n", folder->name));
- /* find any (currently available) folders, and add them to the ones to open */
- rule_add_sources (
- session, &((EMVFolderRule *) rule)->sources,
- &sources_folder, &sources_uri);
+ camel_vee_folder_set_auto_update (CAMEL_VEE_FOLDER (folder),
+ em_vfolder_rule_get_autoupdate ((EMVFolderRule *) rule));
+
+ if (em_vfolder_rule_get_with ((EMVFolderRule *) rule) == EM_VFOLDER_RULE_WITH_SPECIFIC) {
+ /* find any (currently available) folders, and add them to the ones to open */
+ rule_add_sources (
+ session, em_vfolder_rule_get_sources ((EMVFolderRule *) rule),
+ &sources_folder, &sources_uri);
+ }
G_LOCK (vfolder);
- if (((EMVFolderRule *) rule)->with ==
- EM_VFOLDER_RULE_WITH_LOCAL ||
- ((EMVFolderRule *) rule)->with ==
- EM_VFOLDER_RULE_WITH_LOCAL_REMOTE_ACTIVE) {
+ if (em_vfolder_rule_get_with ((EMVFolderRule *) rule) == EM_VFOLDER_RULE_WITH_LOCAL ||
+ em_vfolder_rule_get_with ((EMVFolderRule *) rule) == EM_VFOLDER_RULE_WITH_LOCAL_REMOTE_ACTIVE) {
MailFolderCache *cache;
GQueue queue = G_QUEUE_INIT;
@@ -785,10 +785,8 @@ rule_changed (EFilterRule *rule,
g_free (g_queue_pop_head (&queue));
}
- if (((EMVFolderRule *) rule)->with ==
- EM_VFOLDER_RULE_WITH_REMOTE_ACTIVE ||
- ((EMVFolderRule *) rule)->with ==
- EM_VFOLDER_RULE_WITH_LOCAL_REMOTE_ACTIVE) {
+ if (em_vfolder_rule_get_with ((EMVFolderRule *) rule) == EM_VFOLDER_RULE_WITH_REMOTE_ACTIVE ||
+ em_vfolder_rule_get_with ((EMVFolderRule *) rule) == EM_VFOLDER_RULE_WITH_LOCAL_REMOTE_ACTIVE) {
MailFolderCache *cache;
GQueue queue = G_QUEUE_INIT;
diff --git a/libemail-utils/em-vfolder-rule.c b/libemail-utils/em-vfolder-rule.c
index 812202585e..237c99d5ca 100644
--- a/libemail-utils/em-vfolder-rule.c
+++ b/libemail-utils/em-vfolder-rule.c
@@ -46,7 +46,9 @@
((obj), EM_TYPE_VFOLDER_RULE, EMVFolderRulePrivate))
struct _EMVFolderRulePrivate {
- gint placeholder;
+ em_vfolder_rule_with_t with;
+ GQueue sources; /* uri's of the source folders */
+ gboolean autoupdate;
};
static gint validate (EFilterRule *, EAlert **alert);
@@ -75,7 +77,7 @@ vfolder_rule_finalize (GObject *object)
EMVFolderRule *rule = EM_VFOLDER_RULE (object);
gchar *uri;
- while ((uri = g_queue_pop_head (&rule->sources)) != NULL)
+ while ((uri = g_queue_pop_head (&rule->priv->sources)) != NULL)
g_free (uri);
/* Chain up to parent's finalize() method. */
@@ -106,7 +108,8 @@ static void
em_vfolder_rule_init (EMVFolderRule *rule)
{
rule->priv = EM_VFOLDER_RULE_GET_PRIVATE (rule);
- rule->with = EM_VFOLDER_RULE_WITH_SPECIFIC;
+ rule->priv->with = EM_VFOLDER_RULE_WITH_SPECIFIC;
+ rule->priv->autoupdate = TRUE;
rule->rule.source = g_strdup ("incoming");
}
@@ -124,7 +127,7 @@ em_vfolder_rule_add_source (EMVFolderRule *rule,
g_return_if_fail (EM_IS_VFOLDER_RULE (rule));
g_return_if_fail (uri);
- g_queue_push_tail (&rule->sources, g_strdup (uri));
+ g_queue_push_tail (&rule->priv->sources, g_strdup (uri));
e_filter_rule_emit_changed (E_FILTER_RULE (rule));
}
@@ -140,7 +143,7 @@ em_vfolder_rule_find_source (EMVFolderRule *rule,
/* only does a simple string or address comparison, should
* probably do a decoded url comparison */
link = g_queue_find_custom (
- &rule->sources, uri, (GCompareFunc) strcmp);
+ &rule->priv->sources, uri, (GCompareFunc) strcmp);
return (link != NULL) ? link->data : NULL;
}
@@ -155,7 +158,7 @@ em_vfolder_rule_remove_source (EMVFolderRule *rule,
found =(gchar *) em_vfolder_rule_find_source (rule, uri);
if (found != NULL) {
- g_queue_remove (&rule->sources, found);
+ g_queue_remove (&rule->priv->sources, found);
g_free (found);
e_filter_rule_emit_changed (E_FILTER_RULE (rule));
}
@@ -168,11 +171,11 @@ em_vfolder_rule_next_source (EMVFolderRule *rule,
GList *link;
if (last == NULL) {
- link = g_queue_peek_head_link (&rule->sources);
+ link = g_queue_peek_head_link (&rule->priv->sources);
} else {
- link = g_queue_find (&rule->sources, last);
+ link = g_queue_find (&rule->priv->sources, last);
if (link == NULL)
- link = g_queue_peek_head_link (&rule->sources);
+ link = g_queue_peek_head_link (&rule->priv->sources);
else
link = g_list_next (link);
}
@@ -180,6 +183,48 @@ em_vfolder_rule_next_source (EMVFolderRule *rule,
return (link != NULL) ? link->data : NULL;
}
+void
+em_vfolder_rule_set_with (EMVFolderRule *rule,
+ em_vfolder_rule_with_t with)
+{
+ g_return_if_fail (rule != NULL);
+
+ rule->priv->with = with;
+}
+
+em_vfolder_rule_with_t
+em_vfolder_rule_get_with (EMVFolderRule *rule)
+{
+ g_return_val_if_fail (rule != NULL, FALSE);
+
+ return rule->priv->with;
+}
+
+GQueue *
+em_vfolder_rule_get_sources (EMVFolderRule *rule)
+{
+ g_return_val_if_fail (rule != NULL, NULL);
+
+ return &rule->priv->sources;
+}
+
+void
+em_vfolder_rule_set_autoupdate (EMVFolderRule *rule,
+ gboolean autoupdate)
+{
+ g_return_if_fail (rule != NULL);
+
+ rule->priv->autoupdate = autoupdate;
+}
+
+gboolean
+em_vfolder_rule_get_autoupdate (EMVFolderRule *rule)
+{
+ g_return_val_if_fail (rule != NULL, EM_VFOLDER_RULE_WITH_SPECIFIC);
+
+ return rule->priv->autoupdate;
+}
+
static gint
validate (EFilterRule *fr,
EAlert **alert)
@@ -195,8 +240,8 @@ validate (EFilterRule *fr,
/* We have to have at least one source set in the "specific" case.
* Do not translate this string! */
- if (((EMVFolderRule *) fr)->with == EM_VFOLDER_RULE_WITH_SPECIFIC &&
- g_queue_is_empty (&((EMVFolderRule *) fr)->sources)) {
+ if (((EMVFolderRule *) fr)->priv->with == EM_VFOLDER_RULE_WITH_SPECIFIC &&
+ g_queue_is_empty (&((EMVFolderRule *) fr)->priv->sources)) {
if (alert)
*alert = e_alert_new ("mail:vfolder-no-source", NULL);
return 0;
@@ -235,8 +280,8 @@ vfolder_eq (EFilterRule *fr,
{
return E_FILTER_RULE_CLASS (em_vfolder_rule_parent_class)->eq (fr, cm)
&& queue_eq (
- &((EMVFolderRule *) fr)->sources,
- &((EMVFolderRule *) cm)->sources);
+ &((EMVFolderRule *) fr)->priv->sources,
+ &((EMVFolderRule *) cm)->priv->sources);
}
static xmlNodePtr
@@ -248,13 +293,14 @@ xml_encode (EFilterRule *fr)
node = E_FILTER_RULE_CLASS (em_vfolder_rule_parent_class)->xml_encode (fr);
g_return_val_if_fail (node != NULL, NULL);
- g_return_val_if_fail (vr->with < G_N_ELEMENTS (with_names), NULL);
+ g_return_val_if_fail (vr->priv->with < G_N_ELEMENTS (with_names), NULL);
set = xmlNewNode(NULL, (const guchar *)"sources");
xmlAddChild (node, set);
- xmlSetProp(set, (const guchar *)"with", (guchar *)with_names[vr->with]);
+ xmlSetProp(set, (const guchar *)"with", (guchar *)with_names[vr->priv->with]);
+ xmlSetProp(set, (const guchar *)"autoupdate", (guchar *) (vr->priv->autoupdate ? "true" : "false"));
- head = g_queue_peek_head_link (&vr->sources);
+ head = g_queue_peek_head_link (&vr->priv->sources);
for (link = head; link != NULL; link = g_list_next (link)) {
const gchar *uri = link->data;
@@ -274,12 +320,12 @@ set_with (EMVFolderRule *vr,
for (i = 0; i < G_N_ELEMENTS (with_names); i++) {
if (!strcmp (name, with_names[i])) {
- vr->with = i;
+ vr->priv->with = i;
return;
}
}
- vr->with = 0;
+ vr->priv->with = 0;
}
static gint
@@ -312,12 +358,17 @@ xml_decode (EFilterRule *fr,
set_with (vr, tmp);
xmlFree (tmp);
}
+ tmp = (gchar *) xmlGetProp (set, (const guchar *) "autoupdate");
+ if (tmp) {
+ vr->priv->autoupdate = g_str_equal (tmp, "true");
+ xmlFree (tmp);
+ }
work = set->children;
while (work) {
if (!strcmp((gchar *)work->name, "folder")) {
tmp = (gchar *)xmlGetProp(work, (const guchar *)"uri");
if (tmp) {
- g_queue_push_tail (&vr->sources, g_strdup (tmp));
+ g_queue_push_tail (&vr->priv->sources, g_strdup (tmp));
xmlFree (tmp);
}
}
@@ -340,16 +391,17 @@ rule_copy (EFilterRule *dest,
vdest =(EMVFolderRule *) dest;
vsrc =(EMVFolderRule *) src;
- while ((uri = g_queue_pop_head (&vdest->sources)) != NULL)
+ while ((uri = g_queue_pop_head (&vdest->priv->sources)) != NULL)
g_free (uri);
- head = g_queue_peek_head_link (&vsrc->sources);
+ head = g_queue_peek_head_link (&vsrc->priv->sources);
for (link = head; link != NULL; link = g_list_next (link)) {
const gchar *uri = link->data;
- g_queue_push_tail (&vdest->sources, g_strdup (uri));
+ g_queue_push_tail (&vdest->priv->sources, g_strdup (uri));
}
- vdest->with = vsrc->with;
+ vdest->priv->with = vsrc->priv->with;
+ vdest->priv->autoupdate = vsrc->priv->autoupdate;
E_FILTER_RULE_CLASS (em_vfolder_rule_parent_class)->copy (dest, src);
}
diff --git a/libemail-utils/em-vfolder-rule.h b/libemail-utils/em-vfolder-rule.h
index 892aded2bc..f6dbfa0d03 100644
--- a/libemail-utils/em-vfolder-rule.h
+++ b/libemail-utils/em-vfolder-rule.h
@@ -64,9 +64,6 @@ typedef enum _em_vfolder_rule_with_t em_vfolder_rule_with_t;
struct _EMVFolderRule {
EFilterRule rule;
EMVFolderRulePrivate *priv;
-
- em_vfolder_rule_with_t with;
- GQueue sources; /* uri's of the source folders */
};
struct _EMVFolderRuleClass {
@@ -83,6 +80,14 @@ const gchar * em_vfolder_rule_find_source (EMVFolderRule *rule,
const gchar *uri);
const gchar * em_vfolder_rule_next_source (EMVFolderRule *rule,
const gchar *last);
+void em_vfolder_rule_set_with (EMVFolderRule *rule,
+ em_vfolder_rule_with_t with);
+em_vfolder_rule_with_t
+ em_vfolder_rule_get_with (EMVFolderRule *rule);
+GQueue * em_vfolder_rule_get_sources (EMVFolderRule *rule);
+void em_vfolder_rule_set_autoupdate (EMVFolderRule *rule,
+ gboolean autoupdate);
+gboolean em_vfolder_rule_get_autoupdate (EMVFolderRule *rule);
G_END_DECLS
diff --git a/mail/em-vfolder-editor-rule.c b/mail/em-vfolder-editor-rule.c
index c5473a5a94..b1fdadd1ea 100644
--- a/mail/em-vfolder-editor-rule.c
+++ b/mail/em-vfolder-editor-rule.c
@@ -251,7 +251,14 @@ select_source_with_changed (GtkWidget *widget,
gtk_widget_set_sensitive (data->source_selector, !with);
- data->vr->with = with;
+ em_vfolder_rule_set_with (data->vr, with);
+}
+
+static void
+autoupdate_toggled_cb (GtkToggleButton *toggle,
+ struct _source_data *data)
+{
+ em_vfolder_rule_set_autoupdate (data->vr, gtk_toggle_button_get_active (toggle));
}
static void
@@ -302,7 +309,7 @@ vfr_folder_response (EMFolderSelector *selector,
g_hash_table_insert (known_uris, g_strdup (uri), GINT_TO_POINTER (1));
- g_queue_push_tail (&data->vr->sources, g_strdup (uri));
+ g_queue_push_tail (em_vfolder_rule_get_sources (data->vr), g_strdup (uri));
markup = e_mail_folder_uri_to_markup (session, uri, NULL);
@@ -444,6 +451,7 @@ get_widget (EFilterRule *fr,
EMVFolderRule *vr = (EMVFolderRule *) fr;
EMailSession *session;
GtkWidget *widget, *frame, *label, *combobox, *hgrid, *vgrid, *tree_view, *scrolled_window;
+ GtkWidget *autoupdate;
GtkListStore *model;
GtkCellRenderer *renderer;
struct _source_data *data;
@@ -495,6 +503,17 @@ get_widget (EFilterRule *fr,
gtk_grid_set_column_spacing (GTK_GRID (hgrid), 6);
gtk_container_add (GTK_CONTAINER (vgrid), hgrid);
+ autoupdate = gtk_check_button_new_with_mnemonic (_("Automatically update on any _source folder change"));
+ gtk_container_add (GTK_CONTAINER (hgrid), autoupdate);
+
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (autoupdate), em_vfolder_rule_get_autoupdate (vr));
+ g_signal_connect (autoupdate, "toggled", G_CALLBACK (autoupdate_toggled_cb), data);
+
+ hgrid = gtk_grid_new ();
+ gtk_orientable_set_orientation (GTK_ORIENTABLE (hgrid), GTK_ORIENTATION_HORIZONTAL);
+ gtk_grid_set_column_spacing (GTK_GRID (hgrid), 6);
+ gtk_container_add (GTK_CONTAINER (vgrid), hgrid);
+
combobox = gtk_combo_box_text_new ();
gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (combobox), NULL, _("All local folders"));
gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (combobox), NULL, _("All active remote folders"));
@@ -573,7 +592,7 @@ get_widget (EFilterRule *fr,
data->source_selector = hgrid;
- gtk_combo_box_set_active (GTK_COMBO_BOX (combobox), 3 - vr->with);
+ gtk_combo_box_set_active (GTK_COMBO_BOX (combobox), 3 - em_vfolder_rule_get_with (vr));
g_signal_connect (
combobox, "changed",
G_CALLBACK (select_source_with_changed), data);