source: globalnotifiergen.pl @ 5b80b87

release-1.10release-1.7release-1.8release-1.9
Last change on this file since 5b80b87 was 5b80b87, checked in by David Benjamin <davidben@mit.edu>, 14 years ago
Avoid flagrant violations of layering and just g_object_notify in the setters. g_object_set_property calls g_object_freeze_notify and g_object_thaw_notify, so it should Just Work.
  • Property mode set to 100755
File size: 6.7 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_VERT_OFFSET,
42  /* generated from variable listings */
43EOT
44
45for my $var (@vars) {
46  print "  " . $var->{propname} . ",\n";
47}
48
49print <<EOT;
50};
51
52G_DEFINE_TYPE(OwlGlobalNotifier, owl_global_notifier, G_TYPE_OBJECT)
53
54static void owl_global_notifier_set_property(GObject *object,
55                                             guint property_id,
56                                             const GValue *value,
57                                             GParamSpec *pspec)
58{
59  OwlGlobalNotifier *notifier = OWL_GLOBAL_NOTIFIER(object);
60
61  switch (property_id) {
62    /* normal properties */
63    case PROP_RIGHTSHIFT:
64      owl_global_set_rightshift(notifier->g, g_value_get_int(value));
65      break;
66    case PROP_CURMSG_VERT_OFFSET:
67      owl_global_set_curmsg_vert_offset(notifier->g, g_value_get_int(value));
68      break;
69    /* generated from variable listings */
70EOT
71
72for my $var (@vars) {
73    my $varname = $var->{name};
74    my $propname = $var->{propname};
75    print "    case $propname:\n";
76
77    if ($var->{type} =~ /^BOOL/) {
78      print <<EOT;
79      if (g_value_get_boolean(value)) {
80        owl_variable_set_bool_on(&notifier->g->vars, "$varname");
81      } else {
82        owl_variable_set_bool_off(&notifier->g->vars, "$varname");
83      }
84EOT
85    } elsif ($var->{type} =~ /^PATH/ or $var->{type} =~ /^STRING/) {
86      print "      owl_variable_set_string(&notifier->g->vars, \"$varname\", g_value_get_string(value));\n";
87    } elsif ($var->{type} =~ /^INT/ or $var->{type} =~ /^ENUM/) {
88      print "      owl_variable_set_int(&notifier->g->vars, \"$varname\", g_value_get_int(value));\n";
89    } 
90    print "      break;\n";
91}
92
93print <<EOT;
94    default:
95      G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
96  }
97}
98
99static void owl_global_notifier_get_property(GObject *object,
100                                             guint property_id,
101                                             GValue *value,
102                                             GParamSpec *pspec)
103{
104  OwlGlobalNotifier *notifier = OWL_GLOBAL_NOTIFIER(object);
105
106  switch (property_id) {
107    /* normal properties */
108    case PROP_RIGHTSHIFT:
109      g_value_set_int(value, owl_global_get_rightshift(notifier->g));
110      break;
111    case PROP_CURMSG_VERT_OFFSET:
112      g_value_set_int(value, owl_global_get_curmsg_vert_offset(notifier->g));
113      break;
114    /* generated from variable listings */
115EOT
116for my $var (@vars) {
117    my $varname = $var->{name};
118    my $propname = $var->{propname};
119    print "    case $propname:\n";
120
121    if ($var->{type} =~ /^BOOL/) {
122      print "      g_value_set_boolean(value, owl_variable_get_bool(&notifier->g->vars, \"$varname\"));\n";
123    } elsif ($var->{type} =~ /^PATH/ or $var->{type} =~ /^STRING/) {
124      print "      g_value_set_string(value, owl_variable_get_string(&notifier->g->vars, \"$varname\"));\n";
125    } elsif ($var->{type} =~ /^INT/ or $var->{type} =~ /^ENUM/) {
126      print "      g_value_set_int(value, owl_variable_get_int(&notifier->g->vars, \"$varname\"));\n";
127    } 
128    print "      break;\n";
129}
130print <<EOT;
131    default:
132      G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
133  }
134}
135
136static void owl_global_notifier_class_init(OwlGlobalNotifierClass *klass)
137{
138  GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
139  GParamSpec *pspec;
140
141  gobject_class->get_property = owl_global_notifier_get_property;
142  gobject_class->set_property = owl_global_notifier_set_property;
143
144  /* Register properties */
145 
146  pspec = g_param_spec_int("rightshift",
147                           "rightshift",
148                           "How much we shift to the right",
149                           0,
150                           INT_MAX,
151                           0,
152                           G_PARAM_READABLE|G_PARAM_WRITABLE
153                          |G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB);
154  g_object_class_install_property(gobject_class, PROP_RIGHTSHIFT, pspec);
155
156EOT
157for my $var (@vars) {
158    my $varname = $var->{name};
159    my $propname = $var->{propname};
160    my $detailname = $var->{detailname};
161    if ($var->{type} =~ /^BOOL/) {
162      print <<EOT
163  pspec = g_param_spec_boolean("$detailname",
164                               "$varname",
165                               "$varname", /* TODO: parse out the summary too */
166                               FALSE,
167                               G_PARAM_READABLE|G_PARAM_WRITABLE
168                              |G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB);
169EOT
170    } elsif ($var->{type} =~ /^PATH/ or $var->{type} =~ /^STRING/) {
171      print <<EOT
172  pspec = g_param_spec_string("$detailname",
173                              "$varname",
174                              "$varname", /* TODO: parse out the summary too */
175                              "",
176                              G_PARAM_READABLE|G_PARAM_WRITABLE
177                             |G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB);
178EOT
179    } elsif ($var->{type} =~ /^INT/ or $var->{type} =~ /^ENUM/) {
180      print <<EOT
181  pspec = g_param_spec_int("$detailname",
182                           "$varname",
183                           "$varname", /* TODO: parse out the summary too */
184                           INT_MIN,
185                           INT_MAX,
186                           0,
187                           G_PARAM_READABLE|G_PARAM_WRITABLE
188                          |G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB);
189EOT
190    } 
191    print "  g_object_class_install_property(gobject_class, $propname, pspec);\n\n";
192}
193print <<EOT;
194}
195
196static void owl_global_notifier_init(OwlGlobalNotifier *self)
197{
198}
199
200OwlGlobalNotifier *owl_global_notifier_new(owl_global *g)
201{
202  OwlGlobalNotifier *gn;
203 
204  gn = g_object_new(OWL_TYPE_GLOBAL_NOTIFIER, NULL);
205  gn->g = g;
206  return gn;
207}
208EOT
Note: See TracBrowser for help on using the repository browser.