source: globalnotifiergen.pl @ d6f2d21

release-1.10release-1.7release-1.8release-1.9
Last change on this file since d6f2d21 was 608681f, checked in by David Benjamin <davidben@mit.edu>, 14 years ago
Add curmsg property and finish curmsg-vert-offset
  • Property mode set to 100755
File size: 8.9 KB
Line 
1print qq(/* THIS FILE WAS AUTOGENERATED BY GLOBALNOTIFIERGEN.PL --- DO NOT EDIT BY HAND!!! */\n\n);
2
3my @vars = ();
4foreach $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
32print <<EOT;
33#include "globalnotifier.h"
34#include "owl.h"
35
36/* properties */
37enum {
38  PROP_NONE,
39  /* normal properties */
40  PROP_RIGHTSHIFT,
41  PROP_CURMSG,
42  PROP_CURMSG_VERT_OFFSET,
43  /* generated from variable listings */
44EOT
45
46for my $var (@vars) {
47  print "  " . $var->{propname} . ",\n";
48}
49
50print <<EOT;
51};
52
53/* signals */
54enum {
55  VIEW_CHANGED,
56  MESSAGE_RECEIVED,
57  LAST_SIGNAL
58};
59
60static guint notifier_signals[LAST_SIGNAL] = { 0 };
61
62G_DEFINE_TYPE(OwlGlobalNotifier, owl_global_notifier, G_TYPE_OBJECT)
63
64static void owl_global_notifier_set_property(GObject *object,
65                                             guint property_id,
66                                             const GValue *value,
67                                             GParamSpec *pspec)
68{
69  OwlGlobalNotifier *notifier = OWL_GLOBAL_NOTIFIER(object);
70
71  switch (property_id) {
72    /* normal properties */
73    case PROP_RIGHTSHIFT:
74      owl_global_set_rightshift(notifier->g, g_value_get_int(value));
75      break;
76    case PROP_CURMSG:
77      owl_global_set_curmsg(notifier->g, g_value_get_int(value));
78      break;
79    case PROP_CURMSG_VERT_OFFSET:
80      owl_global_set_curmsg_vert_offset(notifier->g, g_value_get_int(value));
81      break;
82    /* generated from variable listings */
83EOT
84
85for my $var (@vars) {
86    my $varname = $var->{name};
87    my $propname = $var->{propname};
88    print "    case $propname:\n";
89
90    if ($var->{type} =~ /^BOOL/) {
91      print <<EOT;
92      if (g_value_get_boolean(value)) {
93        owl_variable_set_bool_on(&notifier->g->vars, "$varname");
94      } else {
95        owl_variable_set_bool_off(&notifier->g->vars, "$varname");
96      }
97EOT
98    } elsif ($var->{type} =~ /^PATH/ or $var->{type} =~ /^STRING/) {
99      print "      owl_variable_set_string(&notifier->g->vars, \"$varname\", g_value_get_string(value));\n";
100    } elsif ($var->{type} =~ /^INT/ or $var->{type} =~ /^ENUM/) {
101      print "      owl_variable_set_int(&notifier->g->vars, \"$varname\", g_value_get_int(value));\n";
102    } 
103    print "      break;\n";
104}
105
106print <<EOT;
107    default:
108      G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
109  }
110}
111
112static void owl_global_notifier_get_property(GObject *object,
113                                             guint property_id,
114                                             GValue *value,
115                                             GParamSpec *pspec)
116{
117  OwlGlobalNotifier *notifier = OWL_GLOBAL_NOTIFIER(object);
118
119  switch (property_id) {
120    /* normal properties */
121    case PROP_RIGHTSHIFT:
122      g_value_set_int(value, owl_global_get_rightshift(notifier->g));
123      break;
124    case PROP_CURMSG:
125      g_value_set_int(value, owl_global_get_curmsg(notifier->g));
126      break;
127    case PROP_CURMSG_VERT_OFFSET:
128      g_value_set_int(value, owl_global_get_curmsg_vert_offset(notifier->g));
129      break;
130    /* generated from variable listings */
131EOT
132for my $var (@vars) {
133    my $varname = $var->{name};
134    my $propname = $var->{propname};
135    print "    case $propname:\n";
136
137    if ($var->{type} =~ /^BOOL/) {
138      print "      g_value_set_boolean(value, owl_variable_get_bool(&notifier->g->vars, \"$varname\"));\n";
139    } elsif ($var->{type} =~ /^PATH/ or $var->{type} =~ /^STRING/) {
140      print "      g_value_set_string(value, owl_variable_get_string(&notifier->g->vars, \"$varname\"));\n";
141    } elsif ($var->{type} =~ /^INT/ or $var->{type} =~ /^ENUM/) {
142      print "      g_value_set_int(value, owl_variable_get_int(&notifier->g->vars, \"$varname\"));\n";
143    } 
144    print "      break;\n";
145}
146print <<EOT;
147    default:
148      G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
149  }
150}
151
152static void owl_global_notifier_class_init(OwlGlobalNotifierClass *klass)
153{
154  GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
155  GParamSpec *pspec;
156
157  gobject_class->get_property = owl_global_notifier_get_property;
158  gobject_class->set_property = owl_global_notifier_set_property;
159
160  /* Create signals */
161
162  notifier_signals[VIEW_CHANGED] =
163    g_signal_new("view-changed",
164                 G_TYPE_FROM_CLASS(gobject_class),
165                 G_SIGNAL_RUN_FIRST,
166                 0,
167                 NULL, NULL,
168                 g_cclosure_marshal_VOID__VOID,
169                 G_TYPE_NONE,
170                 0,
171                 NULL);
172
173  notifier_signals[MESSAGE_RECEIVED] =
174    g_signal_new("message-received",
175                 G_TYPE_FROM_CLASS(gobject_class),
176                 G_SIGNAL_RUN_FIRST,
177                 0,
178                 NULL, NULL,
179                 g_cclosure_marshal_VOID__POINTER,
180                 G_TYPE_NONE,
181                 1,
182                 G_TYPE_POINTER, NULL);
183
184  /* Register properties */
185 
186  pspec = g_param_spec_int("rightshift",
187                           "rightshift",
188                           "How much we shift to the right",
189                           0,
190                           INT_MAX,
191                           0,
192                           G_PARAM_READABLE|G_PARAM_WRITABLE
193                          |G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB);
194  g_object_class_install_property(gobject_class, PROP_RIGHTSHIFT, pspec);
195 
196  pspec = g_param_spec_int("curmsg",
197                           "curmsg",
198                           "The current message",
199                           0,
200                           INT_MAX,
201                           0,
202                           G_PARAM_READABLE|G_PARAM_WRITABLE
203                          |G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB);
204  g_object_class_install_property(gobject_class, PROP_CURMSG, pspec);
205 
206  pspec = g_param_spec_int("curmsg-vert-offset",
207                           "curmsg_vert_offset",
208                           "How offset the current message is",
209                           0,
210                           INT_MAX,
211                           0,
212                           G_PARAM_READABLE|G_PARAM_WRITABLE
213                          |G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB);
214  g_object_class_install_property(gobject_class, PROP_CURMSG_VERT_OFFSET, pspec);
215
216EOT
217for my $var (@vars) {
218    my $varname = $var->{name};
219    my $propname = $var->{propname};
220    my $detailname = $var->{detailname};
221    if ($var->{type} =~ /^BOOL/) {
222      print <<EOT
223  pspec = g_param_spec_boolean("$detailname",
224                               "$varname",
225                               "$varname", /* TODO: parse out the summary too */
226                               FALSE,
227                               G_PARAM_READABLE|G_PARAM_WRITABLE
228                              |G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB);
229EOT
230    } elsif ($var->{type} =~ /^PATH/ or $var->{type} =~ /^STRING/) {
231      print <<EOT
232  pspec = g_param_spec_string("$detailname",
233                              "$varname",
234                              "$varname", /* TODO: parse out the summary too */
235                              "",
236                              G_PARAM_READABLE|G_PARAM_WRITABLE
237                             |G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB);
238EOT
239    } elsif ($var->{type} =~ /^INT/ or $var->{type} =~ /^ENUM/) {
240      print <<EOT
241  pspec = g_param_spec_int("$detailname",
242                           "$varname",
243                           "$varname", /* TODO: parse out the summary too */
244                           INT_MIN,
245                           INT_MAX,
246                           0,
247                           G_PARAM_READABLE|G_PARAM_WRITABLE
248                          |G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB);
249EOT
250    } 
251    print "  g_object_class_install_property(gobject_class, $propname, pspec);\n\n";
252}
253print <<EOT;
254}
255
256static void owl_global_notifier_init(OwlGlobalNotifier *self)
257{
258}
259
260OwlGlobalNotifier *owl_global_notifier_new(owl_global *g)
261{
262  OwlGlobalNotifier *gn;
263 
264  gn = g_object_new(OWL_TYPE_GLOBAL_NOTIFIER, NULL);
265  gn->g = g;
266  return gn;
267}
268
269void owl_global_notifier_emit_view_changed(OwlGlobalNotifier *gn)
270{
271  g_signal_emit(gn, notifier_signals[VIEW_CHANGED], 0);
272}
273
274void owl_global_notifier_emit_message_received(OwlGlobalNotifier *gn, owl_message *msg)
275{
276  g_signal_emit(gn, notifier_signals[MESSAGE_RECEIVED], 0, msg);
277}
278EOT
Note: See TracBrowser for help on using the repository browser.