aboutsummaryrefslogtreecommitdiffstats
path: root/filter/filter-int.c
diff options
context:
space:
mode:
authorNot Zed <NotZed@Ximian.com>2002-07-15 09:46:17 +0800
committerMichael Zucci <zucchi@src.gnome.org>2002-07-15 09:46:17 +0800
commit68ec840bca073bc8e8ea2f58ad36078df9c619c1 (patch)
tree64083ad8df8983d37c2658c51e1c961e4671f160 /filter/filter-int.c
parente785008af08bdc913ce2711dcd7998efb51f694b (diff)
downloadgsoc2013-evolution-68ec840bca073bc8e8ea2f58ad36078df9c619c1.tar
gsoc2013-evolution-68ec840bca073bc8e8ea2f58ad36078df9c619c1.tar.gz
gsoc2013-evolution-68ec840bca073bc8e8ea2f58ad36078df9c619c1.tar.bz2
gsoc2013-evolution-68ec840bca073bc8e8ea2f58ad36078df9c619c1.tar.lz
gsoc2013-evolution-68ec840bca073bc8e8ea2f58ad36078df9c619c1.tar.xz
gsoc2013-evolution-68ec840bca073bc8e8ea2f58ad36078df9c619c1.tar.zst
gsoc2013-evolution-68ec840bca073bc8e8ea2f58ad36078df9c619c1.zip
** fixes for #10781
2002-07-10 Not Zed <NotZed@Ximian.com> ** fixes for #10781 * filter-int.c (xml_encode): (xml_decode): Handle encoding/decoding with a type name, in a manner compatible with the score/label elemtns. (filter_int_new_type): New constructor to create a generic 'int' type. * filter-score.c: Removed. Now relies on using a filter-int with appropriate settings. * filter-label.[ch]: Now inherits from filter-int. * rule-context.c (rule_context_revert): New method to revert a filter context back to a user-file's definition. (revert): implementation. * filter-rule.h: Added new virtual method _eq and wrapper, and fixed all subclasses to implement it. * filter-element.h: Added new virtual method _eq and wrapper. Fixed all subclasses to implement it. svn path=/trunk/; revision=17448
Diffstat (limited to 'filter/filter-int.c')
-rw-r--r--filter/filter-int.c70
1 files changed, 50 insertions, 20 deletions
diff --git a/filter/filter-int.c b/filter/filter-int.c
index 25d70e43e2..a92b0b1b2b 100644
--- a/filter/filter-int.c
+++ b/filter/filter-int.c
@@ -32,6 +32,7 @@
#define d(x)
+static int int_eq(FilterElement *fe, FilterElement *cm);
static void xml_create (FilterElement *fe, xmlNodePtr node);
static xmlNodePtr xml_encode (FilterElement *fe);
static int xml_decode (FilterElement *fe, xmlNodePtr node);
@@ -90,6 +91,7 @@ filter_int_class_init (FilterIntClass *class)
object_class->finalize = filter_int_finalise;
/* override methods */
+ filter_element->eq = int_eq;
filter_element->xml_create = xml_create;
filter_element->xml_encode = xml_encode;
filter_element->xml_decode = xml_decode;
@@ -105,6 +107,8 @@ filter_int_class_init (FilterIntClass *class)
static void
filter_int_init (FilterInt *o)
{
+ o->min = 0;
+ o->max = G_MAXINT;
o->priv = g_malloc0 (sizeof (*o->priv));
}
@@ -112,8 +116,8 @@ static void
filter_int_finalise(GtkObject *obj)
{
FilterInt *o = (FilterInt *)obj;
-
- o = o;
+
+ g_free(o->type);
((GtkObjectClass *)(parent_class))->finalize(obj);
}
@@ -132,6 +136,29 @@ filter_int_new (void)
return o;
}
+FilterInt *
+filter_int_new_type(const char *type, int min, int max)
+{
+ FilterInt *o = (FilterInt *)gtk_type_new(filter_int_get_type ());
+ o->type = g_strdup(type);
+ o->min = min;
+ o->max = max;
+ return o;
+}
+
+void
+filter_int_set_value(FilterInt *fi, int val)
+{
+ fi->val = val;
+}
+
+static int
+int_eq(FilterElement *fe, FilterElement *cm)
+{
+ return ((FilterElementClass *)(parent_class))->eq(fe, cm)
+ && ((FilterInt *)fe)->val == ((FilterInt *)cm)->val;
+}
+
static void
xml_create (FilterElement *fe, xmlNodePtr node)
{
@@ -144,17 +171,19 @@ xml_encode (FilterElement *fe)
{
xmlNodePtr value;
FilterInt *fs = (FilterInt *)fe;
- char *intval;
+ char intval[32];
+ const char *type;
- d(printf("Encoding integer as xml\n"));
+ type = fs->type?fs->type:"integer";
+
+ d(printf("Encoding %s as xml\n", type));
value = xmlNewNode (NULL, "value");
xmlSetProp (value, "name", fe->name);
- xmlSetProp (value, "type", "integer");
+ xmlSetProp (value, "type", type);
- intval = g_strdup_printf ("%d", fs->val);
- xmlSetProp (value, "integer", intval);
- g_free (intval);
+ sprintf(intval, "%d", fs->val);
+ xmlSetProp (value, type, intval);
return value;
}
@@ -163,7 +192,7 @@ static int
xml_decode (FilterElement *fe, xmlNodePtr node)
{
FilterInt *fs = (FilterInt *)fe;
- char *name;
+ char *name, *type;
char *intval;
d(printf("Decoding integer from xml %p\n", fe));
@@ -172,7 +201,13 @@ xml_decode (FilterElement *fe, xmlNodePtr node)
d(printf ("Name = %s\n", name));
xmlFree (fe->name);
fe->name = name;
- intval = xmlGetProp (node, "integer");
+
+ type = xmlGetProp(node, "type");
+ g_free(fs->type);
+ fs->type = g_strdup(type);
+ xmlFree(type);
+
+ intval = xmlGetProp (node, type?type:"integer");
if (intval) {
fs->val = atoi (intval);
xmlFree (intval);
@@ -197,14 +232,12 @@ get_widget (FilterElement *fe)
GtkObject *adjustment;
FilterInt *fs = (FilterInt *)fe;
- adjustment = gtk_adjustment_new (0.0, 0.0, (gfloat)G_MAXINT,
- 1.0, 1.0, 1.0);
- spin = gtk_spin_button_new (GTK_ADJUSTMENT (adjustment), 5.0, 0);
+ adjustment = gtk_adjustment_new (0.0, (gfloat)fs->min, (gfloat)fs->max, 1.0, 1.0, 1.0);
+ spin = gtk_spin_button_new (GTK_ADJUSTMENT (adjustment), fs->max>fs->min+1000?5.0:1.0, 0);
gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spin), TRUE);
- if (fs->val) {
+ if (fs->val)
gtk_spin_button_set_value (GTK_SPIN_BUTTON (spin), (gfloat) fs->val);
- }
gtk_signal_connect (GTK_OBJECT (spin), "changed", spin_changed, fe);
@@ -221,9 +254,6 @@ static void
format_sexp (FilterElement *fe, GString *out)
{
FilterInt *fs = (FilterInt *)fe;
- char *str;
-
- str = g_strdup_printf ("%d", fs->val);
- g_string_append (out, str);
- g_free (str);
+
+ g_string_sprintfa(out, "%d", fs->val);
}