aboutsummaryrefslogtreecommitdiffstats
path: root/filter/filter-arg.c
blob: 44dc90471e619c820c103688dd54e2eb6774ed62 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
/*
 *  Copyright (C) 2000 Helix Code Inc.
 *
 *  Authors: Michael Zucchi <notzed@helixcode.com>
 *
 *  Abstract filter argument class.
 *
 *  This program is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Library General Public License
 *  as published by the Free Software Foundation; either version 2 of
 *  the License, or (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Library General Public License for more details.
 *
 *  You should have received a copy of the GNU Library General Public
 *  License along with this program; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#include "filter-arg.h"


static void filter_arg_class_init (FilterArgClass *class);
static void filter_arg_init       (FilterArg      *gspaper);

static GtkObjectClass *parent_class;

enum {
    CHANGED,
    LAST_SIGNAL
};

static guint signals[LAST_SIGNAL] = { 0 };

guint
filter_arg_get_type (void)
{
    static guint type = 0;
    
    if (!type) {
        GtkTypeInfo type_info = {
            "FilterArg",
            sizeof (FilterArg),
            sizeof (FilterArgClass),
            (GtkClassInitFunc) filter_arg_class_init,
            (GtkObjectInitFunc) filter_arg_init,
            (GtkArgSetFunc) NULL,
            (GtkArgGetFunc) NULL
        };
        
        type = gtk_type_unique (gtk_object_get_type (), &type_info);
    }
    
    return type;
}

static void
write_html_nothing(FilterArg *arg, GtkHTML *html, GtkHTMLStreamHandle *stream)
{
    /* empty */
}

static void
write_text_nothing(FilterArg *arg, GString *string)
{
    /* empty */
}

static void
edit_values_nothing(FilterArg *arg)
{
    /* empty */
}

static void
free_value_nothing(FilterArg *arg, void *v)
{
    /* empty */
}

static gint
compare_pointers(gpointer a, gpointer b)
{
    return a==b;
}

static void
filter_arg_class_init (FilterArgClass *class)
{
    GtkObjectClass *object_class;
    
    object_class = (GtkObjectClass *) class;
    parent_class = gtk_type_class (gtk_object_get_type ());

    class->write_html = write_html_nothing;
    class->write_text = write_text_nothing;
    class->edit_values = edit_values_nothing;
    class->free_value = free_value_nothing;
    
    signals[CHANGED] =
        gtk_signal_new ("changed",
                GTK_RUN_LAST,
                object_class->type,
                GTK_SIGNAL_OFFSET (FilterArgClass, changed),
                gtk_marshal_NONE__NONE,
                GTK_TYPE_NONE, 0);
    gtk_object_class_add_signals (object_class, signals, LAST_SIGNAL);
}

static void
filter_arg_init (FilterArg *arg)
{
    arg->values = NULL;
}

/**
 * filter_arg_new:
 *
 * Create a new FilterArg widget.
 * 
 * Return value: A new FilterArg widget.
 **/
FilterArg *
filter_arg_new (char *name)
{
    FilterArg *a = FILTER_ARG ( gtk_type_new (filter_arg_get_type ()));
    if (name)
        a->name = g_strdup(name);
    return a;
}

void
filter_arg_add(FilterArg *arg, void *v)
{
    arg->values = g_list_append(arg->values, v);
    gtk_signal_emit(GTK_OBJECT(arg), signals[CHANGED]);
}

void
filter_arg_remove(FilterArg *arg, void *v)
{
    arg->values = g_list_remove(arg->values, v);
    ((FilterArgClass *)(arg->object.klass))->free_value(arg, v);
    gtk_signal_emit(GTK_OBJECT(arg), signals[CHANGED]);
}

void
filter_arg_write_html(FilterArg *arg, GtkHTML *html, GtkHTMLStreamHandle *stream)
{
    ((FilterArgClass *)(arg->object.klass))->write_html(arg, html, stream);
}
void
filter_arg_write_text(FilterArg *arg, GString *string)
{
    ((FilterArgClass *)(arg->object.klass))->write_text(arg, string);
}
void
filter_arg_edit_values(FilterArg *arg)
{
    ((FilterArgClass *)(arg->object.klass))->edit_values(arg);
}

xmlNodePtr
filter_arg_values_get_xml(FilterArg *arg)
{
    return ((FilterArgClass *)(arg->object.klass))->values_get_xml(arg);
}
void
filter_arg_values_add_xml(FilterArg *arg, xmlNodePtr node)
{
    ((FilterArgClass *)(arg->object.klass))->values_add_xml(arg, node);
}

/* returns the number of args in the arg list */
int
filter_arg_get_count(FilterArg *arg)
{
    int count=0;
    GList *l;

    for (l = arg->values;l;l=g_list_next(l))
        count++;
    return count;
}

void *
filter_arg_get_value(FilterArg *arg, int index)
{
    int count=0;
    GList *l;

    for (l = arg->values;l && count<index;l=g_list_next(l))
        count++;
    if (l)
        return l->data;
    return NULL;
}

char *
filter_arg_get_value_as_string(FilterArg *arg, int index)
{
    int count=0;
    GList *l;
    void *data;

    data = filter_arg_get_value(arg, index);
    if (data) {
        return ((FilterArgClass *)(arg->object.klass))->get_value_as_string(arg, data);
    } else {
        return "";
    }
}