aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--mail/em-filter-folder-element.c255
1 files changed, 127 insertions, 128 deletions
diff --git a/mail/em-filter-folder-element.c b/mail/em-filter-folder-element.c
index a7be46431b..502ec5d45f 100644
--- a/mail/em-filter-folder-element.c
+++ b/mail/em-filter-folder-element.c
@@ -39,6 +39,10 @@
#include "libedataserver/e-sexp.h"
#include "e-util/e-alert.h"
+#define EM_FILTER_FOLDER_ELEMENT_GET_PRIVATE(obj) \
+ (G_TYPE_INSTANCE_GET_PRIVATE \
+ ((obj), EM_TYPE_FILTER_FOLDER_ELEMENT, EMFilterFolderElementPrivate))
+
struct _EMFilterFolderElementPrivate {
EMailBackend *backend;
gchar *uri;
@@ -49,21 +53,28 @@ enum {
PROP_BACKEND
};
-static gboolean validate (EFilterElement *fe, EAlert **alert);
-static gint folder_eq (EFilterElement *fe, EFilterElement *cm);
-static xmlNodePtr xml_encode (EFilterElement *fe);
-static gint xml_decode (EFilterElement *fe, xmlNodePtr node);
-static GtkWidget *get_widget (EFilterElement *fe);
-static void build_code (EFilterElement *fe, GString *out, EFilterPart *ff);
-static void format_sexp (EFilterElement *, GString *);
-static void emff_copy_value (EFilterElement *de, EFilterElement *se);
-
G_DEFINE_TYPE (
EMFilterFolderElement,
em_filter_folder_element,
E_TYPE_FILTER_ELEMENT)
static void
+filter_folder_element_selected_cb (EMFolderSelectionButton *button,
+ EMFilterFolderElement *ff)
+{
+ GtkWidget *toplevel;
+ const gchar *uri;
+
+ uri = em_folder_selection_button_get_selection (button);
+
+ g_free (ff->priv->uri);
+ ff->priv->uri = g_strdup (uri);
+
+ toplevel = gtk_widget_get_toplevel (GTK_WIDGET (button));
+ gtk_window_present (GTK_WINDOW (toplevel));
+}
+
+static void
filter_folder_element_set_backend (EMFilterFolderElement *element,
EMailBackend *backend)
{
@@ -123,7 +134,7 @@ filter_folder_element_dispose (GObject *object)
{
EMFilterFolderElementPrivate *priv;
- priv = EM_FILTER_FOLDER_ELEMENT (object)->priv;
+ priv = EM_FILTER_FOLDER_ELEMENT_GET_PRIVATE (object);
if (priv->backend != NULL) {
g_object_unref (priv->backend);
@@ -139,7 +150,7 @@ filter_folder_element_finalize (GObject *object)
{
EMFilterFolderElementPrivate *priv;
- priv = EM_FILTER_FOLDER_ELEMENT (object)->priv;
+ priv = EM_FILTER_FOLDER_ELEMENT_GET_PRIVATE (object);
g_free (priv->uri);
@@ -147,105 +158,26 @@ filter_folder_element_finalize (GObject *object)
G_OBJECT_CLASS (em_filter_folder_element_parent_class)->finalize (object);
}
-static void
-em_filter_folder_element_class_init (EMFilterFolderElementClass *class)
-{
- GObjectClass *object_class;
- EFilterElementClass *filter_element_class;
-
- g_type_class_add_private (class, sizeof (EMFilterFolderElementPrivate));
-
- object_class = G_OBJECT_CLASS (class);
- object_class->set_property = filter_folder_element_set_property;
- object_class->get_property = filter_folder_element_get_property;
- object_class->dispose = filter_folder_element_dispose;
- object_class->finalize = filter_folder_element_finalize;
-
- filter_element_class = E_FILTER_ELEMENT_CLASS (class);
- filter_element_class->validate = validate;
- filter_element_class->eq = folder_eq;
- filter_element_class->xml_encode = xml_encode;
- filter_element_class->xml_decode = xml_decode;
- filter_element_class->get_widget = get_widget;
- filter_element_class->build_code = build_code;
- filter_element_class->format_sexp = format_sexp;
- filter_element_class->copy_value = emff_copy_value;
-
- g_object_class_install_property (
- object_class,
- PROP_BACKEND,
- g_param_spec_object (
- "backend",
- NULL,
- NULL,
- E_TYPE_MAIL_BACKEND,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT_ONLY));
-}
-
-static void
-em_filter_folder_element_init (EMFilterFolderElement *element)
-{
- element->priv = G_TYPE_INSTANCE_GET_PRIVATE (
- element, EM_TYPE_FILTER_FOLDER_ELEMENT,
- EMFilterFolderElementPrivate);
-}
-
-EFilterElement *
-em_filter_folder_element_new (EMailBackend *backend)
-{
- g_return_val_if_fail (E_IS_MAIL_BACKEND (backend), NULL);
-
- return g_object_new (
- EM_TYPE_FILTER_FOLDER_ELEMENT,
- "backend", backend, NULL);
-}
-
-EMailBackend *
-em_filter_folder_element_get_backend (EMFilterFolderElement *element)
-{
- g_return_val_if_fail (EM_IS_FILTER_FOLDER_ELEMENT (element), NULL);
-
- return element->priv->backend;
-}
-
-const gchar *
-em_filter_folder_element_get_uri (EMFilterFolderElement *element)
-{
- g_return_val_if_fail (EM_IS_FILTER_FOLDER_ELEMENT (element), NULL);
-
- return element->priv->uri;
-}
-
-void
-em_filter_folder_element_set_uri (EMFilterFolderElement *element,
- const gchar *uri)
-{
- g_return_if_fail (EM_IS_FILTER_FOLDER_ELEMENT (element));
-
- g_free (element->priv->uri);
- element->priv->uri = g_strdup (uri);
-}
-
static gboolean
-validate (EFilterElement *fe, EAlert **alert)
+filter_folder_element_validate (EFilterElement *fe,
+ EAlert **alert)
{
EMFilterFolderElement *ff = (EMFilterFolderElement *) fe;
g_warn_if_fail (alert == NULL || *alert == NULL);
- if (ff->priv->uri && *ff->priv->uri) {
+ if (ff->priv->uri != NULL && *ff->priv->uri != '\0')
return TRUE;
- } else {
- if (alert)
- *alert = e_alert_new ("mail:no-folder", NULL);
- return FALSE;
- }
+ if (alert)
+ *alert = e_alert_new ("mail:no-folder", NULL);
+
+ return FALSE;
}
static gint
-folder_eq (EFilterElement *fe, EFilterElement *cm)
+filter_folder_element_eq (EFilterElement *fe,
+ EFilterElement *cm)
{
return E_FILTER_ELEMENT_CLASS (
em_filter_folder_element_parent_class)->eq (fe, cm) &&
@@ -254,23 +186,24 @@ folder_eq (EFilterElement *fe, EFilterElement *cm)
}
static xmlNodePtr
-xml_encode (EFilterElement *fe)
+filter_folder_element_xml_encode (EFilterElement *fe)
{
xmlNodePtr value, work;
EMFilterFolderElement *ff = (EMFilterFolderElement *) fe;
- value = xmlNewNode(NULL, (xmlChar *) "value");
- xmlSetProp(value, (xmlChar *) "name", (xmlChar *) fe->name);
- xmlSetProp(value, (xmlChar *) "type", (xmlChar *) "folder");
+ value = xmlNewNode (NULL, (xmlChar *) "value");
+ xmlSetProp (value, (xmlChar *) "name", (xmlChar *) fe->name);
+ xmlSetProp (value, (xmlChar *) "type", (xmlChar *) "folder");
- work = xmlNewChild(value, NULL, (xmlChar *) "folder", NULL);
- xmlSetProp(work, (xmlChar *) "uri", (xmlChar *) ff->priv->uri);
+ work = xmlNewChild (value, NULL, (xmlChar *) "folder", NULL);
+ xmlSetProp (work, (xmlChar *) "uri", (xmlChar *) ff->priv->uri);
return value;
}
static gint
-xml_decode (EFilterElement *fe, xmlNodePtr node)
+filter_folder_element_xml_decode (EFilterElement *fe,
+ xmlNodePtr node)
{
EMFilterFolderElement *ff = (EMFilterFolderElement *) fe;
xmlNodePtr n;
@@ -295,24 +228,8 @@ xml_decode (EFilterElement *fe, xmlNodePtr node)
return 0;
}
-static void
-folder_selected (EMFolderSelectionButton *button,
- EMFilterFolderElement *ff)
-{
- GtkWidget *toplevel;
- const gchar *uri;
-
- uri = em_folder_selection_button_get_selection (button);
-
- g_free (ff->priv->uri);
- ff->priv->uri = g_strdup (uri);
-
- toplevel = gtk_widget_get_toplevel (GTK_WIDGET (button));
- gtk_window_present (GTK_WINDOW (toplevel));
-}
-
static GtkWidget *
-get_widget (EFilterElement *fe)
+filter_folder_element_get_widget (EFilterElement *fe)
{
EMFilterFolderElement *ff = (EMFilterFolderElement *) fe;
EMailBackend *backend;
@@ -328,19 +245,22 @@ get_widget (EFilterElement *fe)
g_signal_connect (
button, "selected",
- G_CALLBACK (folder_selected), ff);
+ G_CALLBACK (filter_folder_element_selected_cb), ff);
return button;
}
static void
-build_code (EFilterElement *fe, GString *out, EFilterPart *ff)
+filter_folder_element_build_code (EFilterElement *fe,
+ GString *out,
+ EFilterPart *ff)
{
- return;
+ /* We are doing nothing on purpose. */
}
static void
-format_sexp (EFilterElement *fe, GString *out)
+filter_folder_element_format_sexp (EFilterElement *fe,
+ GString *out)
{
EMFilterFolderElement *ff = (EMFilterFolderElement *) fe;
@@ -348,7 +268,8 @@ format_sexp (EFilterElement *fe, GString *out)
}
static void
-emff_copy_value (EFilterElement *de, EFilterElement *se)
+filter_folder_element_copy_value (EFilterElement *de,
+ EFilterElement *se)
{
if (EM_IS_FILTER_FOLDER_ELEMENT (se)) {
em_filter_folder_element_set_uri (
@@ -359,3 +280,81 @@ emff_copy_value (EFilterElement *de, EFilterElement *se)
em_filter_folder_element_parent_class)->copy_value (de, se);
}
}
+static void
+em_filter_folder_element_class_init (EMFilterFolderElementClass *class)
+{
+ GObjectClass *object_class;
+ EFilterElementClass *filter_element_class;
+
+ g_type_class_add_private (class, sizeof (EMFilterFolderElementPrivate));
+
+ object_class = G_OBJECT_CLASS (class);
+ object_class->set_property = filter_folder_element_set_property;
+ object_class->get_property = filter_folder_element_get_property;
+ object_class->dispose = filter_folder_element_dispose;
+ object_class->finalize = filter_folder_element_finalize;
+
+ filter_element_class = E_FILTER_ELEMENT_CLASS (class);
+ filter_element_class->validate = filter_folder_element_validate;
+ filter_element_class->eq = filter_folder_element_eq;
+ filter_element_class->xml_encode = filter_folder_element_xml_encode;
+ filter_element_class->xml_decode = filter_folder_element_xml_decode;
+ filter_element_class->get_widget = filter_folder_element_get_widget;
+ filter_element_class->build_code = filter_folder_element_build_code;
+ filter_element_class->format_sexp = filter_folder_element_format_sexp;
+ filter_element_class->copy_value = filter_folder_element_copy_value;
+
+ g_object_class_install_property (
+ object_class,
+ PROP_BACKEND,
+ g_param_spec_object (
+ "backend",
+ NULL,
+ NULL,
+ E_TYPE_MAIL_BACKEND,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT_ONLY));
+}
+
+static void
+em_filter_folder_element_init (EMFilterFolderElement *element)
+{
+ element->priv = EM_FILTER_FOLDER_ELEMENT_GET_PRIVATE (element);
+}
+
+EFilterElement *
+em_filter_folder_element_new (EMailBackend *backend)
+{
+ g_return_val_if_fail (E_IS_MAIL_BACKEND (backend), NULL);
+
+ return g_object_new (
+ EM_TYPE_FILTER_FOLDER_ELEMENT,
+ "backend", backend, NULL);
+}
+
+EMailBackend *
+em_filter_folder_element_get_backend (EMFilterFolderElement *element)
+{
+ g_return_val_if_fail (EM_IS_FILTER_FOLDER_ELEMENT (element), NULL);
+
+ return element->priv->backend;
+}
+
+const gchar *
+em_filter_folder_element_get_uri (EMFilterFolderElement *element)
+{
+ g_return_val_if_fail (EM_IS_FILTER_FOLDER_ELEMENT (element), NULL);
+
+ return element->priv->uri;
+}
+
+void
+em_filter_folder_element_set_uri (EMFilterFolderElement *element,
+ const gchar *uri)
+{
+ g_return_if_fail (EM_IS_FILTER_FOLDER_ELEMENT (element));
+
+ g_free (element->priv->uri);
+ element->priv->uri = g_strdup (uri);
+}
+