2 * This program is free software; you can redistribute it and/or
3 * modify it under the terms of the GNU Lesser General Public
4 * License as published by the Free Software Foundation; either
5 * version 2 of the License, or (at your option) version 3.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 * Lesser General Public License for more details.
12 * You should have received a copy of the GNU Lesser General Public
13 * License along with the program; if not, see <http://www.gnu.org/licenses/>
17 * Jeffrey Stedfast <fejj@ximian.com>
19 * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
30 #include <libedataserver/e-sexp.h>
32 #include "e-filter-int.h"
37 E_TYPE_FILTER_ELEMENT
)
40 filter_int_spin_changed (GtkSpinButton
*spin_button
,
41 EFilterElement
*element
)
43 EFilterInt
*filter_int
= E_FILTER_INT (element
);
45 filter_int
->val
= gtk_spin_button_get_value_as_int (spin_button
);
49 filter_int_finalize (GObject
*object
)
51 EFilterInt
*filter_int
= E_FILTER_INT (object
);
53 g_free (filter_int
->type
);
55 /* Chain up to parent's finalize() method. */
56 G_OBJECT_CLASS (e_filter_int_parent_class
)->finalize (object
);
60 filter_int_eq (EFilterElement
*element_a
,
61 EFilterElement
*element_b
)
63 EFilterInt
*filter_int_a
= E_FILTER_INT (element_a
);
64 EFilterInt
*filter_int_b
= E_FILTER_INT (element_b
);
66 /* Chain up to parent's eq() method. */
67 if (!E_FILTER_ELEMENT_CLASS (e_filter_int_parent_class
)->
68 eq (element_a
, element_b
))
71 return (filter_int_a
->val
== filter_int_b
->val
);
74 static EFilterElement
*
75 filter_int_clone (EFilterElement
*element
)
77 EFilterInt
*filter_int
= E_FILTER_INT (element
);
80 clone
= (EFilterInt
*) e_filter_int_new_type (
81 filter_int
->type
, filter_int
->min
, filter_int
->max
);
82 clone
->val
= filter_int
->val
;
84 E_FILTER_ELEMENT (clone
)->name
= g_strdup (element
->name
);
86 return E_FILTER_ELEMENT (clone
);
90 filter_int_xml_encode (EFilterElement
*element
)
92 EFilterInt
*filter_int
= E_FILTER_INT (element
);
97 type
= filter_int
->type
? filter_int
->type
: "integer";
99 value
= xmlNewNode (NULL
, (xmlChar
*)"value");
100 xmlSetProp (value
, (xmlChar
*) "name", (xmlChar
*) element
->name
);
101 xmlSetProp (value
, (xmlChar
*) "type", (xmlChar
*) type
);
103 sprintf (intval
, "%d", filter_int
->val
);
104 xmlSetProp (value
, (xmlChar
*)type
, (xmlChar
*)intval
);
110 filter_int_xml_decode (EFilterElement
*element
,
113 EFilterInt
*filter_int
= E_FILTER_INT (element
);
117 name
= (gchar
*)xmlGetProp (node
, (xmlChar
*)"name");
118 xmlFree (element
->name
);
119 element
->name
= name
;
121 type
= (gchar
*)xmlGetProp (node
, (xmlChar
*)"type");
122 g_free (filter_int
->type
);
123 filter_int
->type
= g_strdup (type
);
126 intval
= (gchar
*)xmlGetProp (
127 node
, (xmlChar
*) (filter_int
->type
?
128 filter_int
->type
: "integer"));
130 filter_int
->val
= atoi (intval
);
140 filter_int_get_widget (EFilterElement
*element
)
142 EFilterInt
*filter_int
= E_FILTER_INT (element
);
144 GtkAdjustment
*adjustment
;
146 adjustment
= GTK_ADJUSTMENT (gtk_adjustment_new (
147 0.0, (gfloat
) filter_int
->min
,
148 (gfloat
) filter_int
->max
, 1.0, 1.0, 0));
149 widget
= gtk_spin_button_new (
151 filter_int
->max
> filter_int
->min
+ 1000 ? 5.0 : 1.0, 0);
152 gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (widget
), TRUE
);
155 gtk_spin_button_set_value (
156 GTK_SPIN_BUTTON (widget
), (gfloat
) filter_int
->val
);
159 widget
, "value-changed",
160 G_CALLBACK (filter_int_spin_changed
), element
);
166 filter_int_format_sexp (EFilterElement
*element
,
169 EFilterInt
*filter_int
= E_FILTER_INT (element
);
171 if (filter_int
->val
< 0)
172 /* See #364731 #457523 C6*/
173 g_string_append_printf (out
, "(- %d)", (filter_int
->val
* -1));
175 g_string_append_printf (out
, "%d", filter_int
->val
);
179 e_filter_int_class_init (EFilterIntClass
*class)
181 GObjectClass
*object_class
;
182 EFilterElementClass
*filter_element_class
;
184 object_class
= G_OBJECT_CLASS (class);
185 object_class
->finalize
= filter_int_finalize
;
187 filter_element_class
= E_FILTER_ELEMENT_CLASS (class);
188 filter_element_class
->eq
= filter_int_eq
;
189 filter_element_class
->clone
= filter_int_clone
;
190 filter_element_class
->xml_encode
= filter_int_xml_encode
;
191 filter_element_class
->xml_decode
= filter_int_xml_decode
;
192 filter_element_class
->get_widget
= filter_int_get_widget
;
193 filter_element_class
->format_sexp
= filter_int_format_sexp
;
197 e_filter_int_init (EFilterInt
*filter_int
)
200 filter_int
->max
= G_MAXINT
;
204 e_filter_int_new (void)
206 return g_object_new (E_TYPE_FILTER_INT
, NULL
);
210 e_filter_int_new_type (const gchar
*type
,
214 EFilterInt
*filter_int
;
216 filter_int
= g_object_new (E_TYPE_FILTER_INT
, NULL
);
218 filter_int
->type
= g_strdup (type
);
219 filter_int
->min
= min
;
220 filter_int
->max
= max
;
222 return E_FILTER_ELEMENT (filter_int
);
226 e_filter_int_set_value (EFilterInt
*filter_int
,
229 g_return_if_fail (E_IS_FILTER_INT (filter_int
));
231 filter_int
->val
= value
;