1 | print qq(/* THIS FILE WAS AUTOGENERATED BY GLOBALNOTIFIERGEN.PL --- DO NOT EDIT BY HAND!!! */\n\n); |
---|
2 | |
---|
3 | my @vars = (); |
---|
4 | foreach $file (@ARGV) { |
---|
5 | open(FILE, $file); |
---|
6 | |
---|
7 | while (<FILE>) { |
---|
8 | if (m|^\s*OWLVAR_([A-Z_0-9]+)\s*\(\s*"([^"]+)"\s*/\*\s*%OwlVarStub:?([a-z0-9_]+)?\s*\*/|) { # " |
---|
9 | my $vartype = $1; |
---|
10 | my $varname = $2; |
---|
11 | my $altvarname = $2; |
---|
12 | $altvarname = $3 if ($3); |
---|
13 | |
---|
14 | my $propname = $altvarname; |
---|
15 | $propname =~ tr/a-z/A-Z/; |
---|
16 | $propname = "PROP_$propname"; |
---|
17 | |
---|
18 | my $detailname = $altvarname; |
---|
19 | $detailname =~ s/[^a-zA-Z0-9]/-/g; |
---|
20 | $detailname =~ s/^[^a-zA-Z]+//; |
---|
21 | |
---|
22 | push @vars, {type => $vartype, |
---|
23 | name => $varname, |
---|
24 | altname => $altvarname, |
---|
25 | propname => $propname, |
---|
26 | detailname => $detailname}; |
---|
27 | } |
---|
28 | } |
---|
29 | close(FILE); |
---|
30 | } |
---|
31 | |
---|
32 | print <<EOT; |
---|
33 | #include "globalnotifier.h" |
---|
34 | #include "owl.h" |
---|
35 | |
---|
36 | /* properties */ |
---|
37 | enum { |
---|
38 | PROP_NONE, |
---|
39 | /* normal properties */ |
---|
40 | PROP_RIGHTSHIFT, |
---|
41 | PROP_CURMSG_VERT_OFFSET, |
---|
42 | /* generated from variable listings */ |
---|
43 | EOT |
---|
44 | |
---|
45 | for my $var (@vars) { |
---|
46 | print " " . $var->{propname} . ",\n"; |
---|
47 | } |
---|
48 | |
---|
49 | print <<EOT; |
---|
50 | }; |
---|
51 | |
---|
52 | /* signals */ |
---|
53 | enum { |
---|
54 | VIEW_CHANGED, |
---|
55 | MESSAGE_RECEIVED, |
---|
56 | LAST_SIGNAL |
---|
57 | }; |
---|
58 | |
---|
59 | static guint notifier_signals[LAST_SIGNAL] = { 0 }; |
---|
60 | |
---|
61 | G_DEFINE_TYPE(OwlGlobalNotifier, owl_global_notifier, G_TYPE_OBJECT) |
---|
62 | |
---|
63 | static void owl_global_notifier_set_property(GObject *object, |
---|
64 | guint property_id, |
---|
65 | const GValue *value, |
---|
66 | GParamSpec *pspec) |
---|
67 | { |
---|
68 | OwlGlobalNotifier *notifier = OWL_GLOBAL_NOTIFIER(object); |
---|
69 | |
---|
70 | switch (property_id) { |
---|
71 | /* normal properties */ |
---|
72 | case PROP_RIGHTSHIFT: |
---|
73 | owl_global_set_rightshift(notifier->g, g_value_get_int(value)); |
---|
74 | break; |
---|
75 | case PROP_CURMSG_VERT_OFFSET: |
---|
76 | owl_global_set_curmsg_vert_offset(notifier->g, g_value_get_int(value)); |
---|
77 | break; |
---|
78 | /* generated from variable listings */ |
---|
79 | EOT |
---|
80 | |
---|
81 | for my $var (@vars) { |
---|
82 | my $varname = $var->{name}; |
---|
83 | my $propname = $var->{propname}; |
---|
84 | print " case $propname:\n"; |
---|
85 | |
---|
86 | if ($var->{type} =~ /^BOOL/) { |
---|
87 | print <<EOT; |
---|
88 | if (g_value_get_boolean(value)) { |
---|
89 | owl_variable_set_bool_on(¬ifier->g->vars, "$varname"); |
---|
90 | } else { |
---|
91 | owl_variable_set_bool_off(¬ifier->g->vars, "$varname"); |
---|
92 | } |
---|
93 | EOT |
---|
94 | } elsif ($var->{type} =~ /^PATH/ or $var->{type} =~ /^STRING/) { |
---|
95 | print " owl_variable_set_string(¬ifier->g->vars, \"$varname\", g_value_get_string(value));\n"; |
---|
96 | } elsif ($var->{type} =~ /^INT/ or $var->{type} =~ /^ENUM/) { |
---|
97 | print " owl_variable_set_int(¬ifier->g->vars, \"$varname\", g_value_get_int(value));\n"; |
---|
98 | } |
---|
99 | print " break;\n"; |
---|
100 | } |
---|
101 | |
---|
102 | print <<EOT; |
---|
103 | default: |
---|
104 | G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec); |
---|
105 | } |
---|
106 | } |
---|
107 | |
---|
108 | static void owl_global_notifier_get_property(GObject *object, |
---|
109 | guint property_id, |
---|
110 | GValue *value, |
---|
111 | GParamSpec *pspec) |
---|
112 | { |
---|
113 | OwlGlobalNotifier *notifier = OWL_GLOBAL_NOTIFIER(object); |
---|
114 | |
---|
115 | switch (property_id) { |
---|
116 | /* normal properties */ |
---|
117 | case PROP_RIGHTSHIFT: |
---|
118 | g_value_set_int(value, owl_global_get_rightshift(notifier->g)); |
---|
119 | break; |
---|
120 | case PROP_CURMSG_VERT_OFFSET: |
---|
121 | g_value_set_int(value, owl_global_get_curmsg_vert_offset(notifier->g)); |
---|
122 | break; |
---|
123 | /* generated from variable listings */ |
---|
124 | EOT |
---|
125 | for my $var (@vars) { |
---|
126 | my $varname = $var->{name}; |
---|
127 | my $propname = $var->{propname}; |
---|
128 | print " case $propname:\n"; |
---|
129 | |
---|
130 | if ($var->{type} =~ /^BOOL/) { |
---|
131 | print " g_value_set_boolean(value, owl_variable_get_bool(¬ifier->g->vars, \"$varname\"));\n"; |
---|
132 | } elsif ($var->{type} =~ /^PATH/ or $var->{type} =~ /^STRING/) { |
---|
133 | print " g_value_set_string(value, owl_variable_get_string(¬ifier->g->vars, \"$varname\"));\n"; |
---|
134 | } elsif ($var->{type} =~ /^INT/ or $var->{type} =~ /^ENUM/) { |
---|
135 | print " g_value_set_int(value, owl_variable_get_int(¬ifier->g->vars, \"$varname\"));\n"; |
---|
136 | } |
---|
137 | print " break;\n"; |
---|
138 | } |
---|
139 | print <<EOT; |
---|
140 | default: |
---|
141 | G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec); |
---|
142 | } |
---|
143 | } |
---|
144 | |
---|
145 | static void owl_global_notifier_class_init(OwlGlobalNotifierClass *klass) |
---|
146 | { |
---|
147 | GObjectClass *gobject_class = G_OBJECT_CLASS(klass); |
---|
148 | GParamSpec *pspec; |
---|
149 | |
---|
150 | gobject_class->get_property = owl_global_notifier_get_property; |
---|
151 | gobject_class->set_property = owl_global_notifier_set_property; |
---|
152 | |
---|
153 | /* Create signals */ |
---|
154 | |
---|
155 | notifier_signals[VIEW_CHANGED] = |
---|
156 | g_signal_new("view-changed", |
---|
157 | G_TYPE_FROM_CLASS(gobject_class), |
---|
158 | G_SIGNAL_RUN_FIRST, |
---|
159 | 0, |
---|
160 | NULL, NULL, |
---|
161 | g_cclosure_marshal_VOID__VOID, |
---|
162 | G_TYPE_NONE, |
---|
163 | 0, |
---|
164 | NULL); |
---|
165 | |
---|
166 | notifier_signals[MESSAGE_RECEIVED] = |
---|
167 | g_signal_new("message-received", |
---|
168 | G_TYPE_FROM_CLASS(gobject_class), |
---|
169 | G_SIGNAL_RUN_FIRST, |
---|
170 | 0, |
---|
171 | NULL, NULL, |
---|
172 | g_cclosure_marshal_VOID__POINTER, |
---|
173 | G_TYPE_NONE, |
---|
174 | 1, |
---|
175 | G_TYPE_POINTER, NULL); |
---|
176 | |
---|
177 | /* Register properties */ |
---|
178 | |
---|
179 | pspec = g_param_spec_int("rightshift", |
---|
180 | "rightshift", |
---|
181 | "How much we shift to the right", |
---|
182 | 0, |
---|
183 | INT_MAX, |
---|
184 | 0, |
---|
185 | G_PARAM_READABLE|G_PARAM_WRITABLE |
---|
186 | |G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB); |
---|
187 | g_object_class_install_property(gobject_class, PROP_RIGHTSHIFT, pspec); |
---|
188 | |
---|
189 | EOT |
---|
190 | for my $var (@vars) { |
---|
191 | my $varname = $var->{name}; |
---|
192 | my $propname = $var->{propname}; |
---|
193 | my $detailname = $var->{detailname}; |
---|
194 | if ($var->{type} =~ /^BOOL/) { |
---|
195 | print <<EOT |
---|
196 | pspec = g_param_spec_boolean("$detailname", |
---|
197 | "$varname", |
---|
198 | "$varname", /* TODO: parse out the summary too */ |
---|
199 | FALSE, |
---|
200 | G_PARAM_READABLE|G_PARAM_WRITABLE |
---|
201 | |G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB); |
---|
202 | EOT |
---|
203 | } elsif ($var->{type} =~ /^PATH/ or $var->{type} =~ /^STRING/) { |
---|
204 | print <<EOT |
---|
205 | pspec = g_param_spec_string("$detailname", |
---|
206 | "$varname", |
---|
207 | "$varname", /* TODO: parse out the summary too */ |
---|
208 | "", |
---|
209 | G_PARAM_READABLE|G_PARAM_WRITABLE |
---|
210 | |G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB); |
---|
211 | EOT |
---|
212 | } elsif ($var->{type} =~ /^INT/ or $var->{type} =~ /^ENUM/) { |
---|
213 | print <<EOT |
---|
214 | pspec = g_param_spec_int("$detailname", |
---|
215 | "$varname", |
---|
216 | "$varname", /* TODO: parse out the summary too */ |
---|
217 | INT_MIN, |
---|
218 | INT_MAX, |
---|
219 | 0, |
---|
220 | G_PARAM_READABLE|G_PARAM_WRITABLE |
---|
221 | |G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB); |
---|
222 | EOT |
---|
223 | } |
---|
224 | print " g_object_class_install_property(gobject_class, $propname, pspec);\n\n"; |
---|
225 | } |
---|
226 | print <<EOT; |
---|
227 | } |
---|
228 | |
---|
229 | static void owl_global_notifier_init(OwlGlobalNotifier *self) |
---|
230 | { |
---|
231 | } |
---|
232 | |
---|
233 | OwlGlobalNotifier *owl_global_notifier_new(owl_global *g) |
---|
234 | { |
---|
235 | OwlGlobalNotifier *gn; |
---|
236 | |
---|
237 | gn = g_object_new(OWL_TYPE_GLOBAL_NOTIFIER, NULL); |
---|
238 | gn->g = g; |
---|
239 | return gn; |
---|
240 | } |
---|
241 | |
---|
242 | void owl_global_notifier_emit_view_changed(OwlGlobalNotifier *gn) |
---|
243 | { |
---|
244 | g_signal_emit(gn, notifier_signals[VIEW_CHANGED], 0); |
---|
245 | } |
---|
246 | |
---|
247 | void owl_global_notifier_emit_message_received(OwlGlobalNotifier *gn, owl_message *msg) |
---|
248 | { |
---|
249 | g_signal_emit(gn, notifier_signals[MESSAGE_RECEIVED], 0, msg); |
---|
250 | } |
---|
251 | EOT |
---|