source: globalnotifiergen.pl @ b2ea16b

release-1.10release-1.7release-1.8release-1.9
Last change on this file since b2ea16b was b2ea16b, checked in by David Benjamin <davidben@mit.edu>, 14 years ago
Add a view-changed signal to the notifier and export This really wants to live on owl_view and owl_mainwin, but whatever.
  • Property mode set to 100755
File size: 7.2 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
52/* signals */
53enum {
54  VIEW_CHANGED,
55  LAST_SIGNAL
56};
57
58static guint notifier_signals[LAST_SIGNAL] = { 0 };
59
60G_DEFINE_TYPE(OwlGlobalNotifier, owl_global_notifier, G_TYPE_OBJECT)
61
62static void owl_global_notifier_set_property(GObject *object,
63                                             guint property_id,
64                                             const GValue *value,
65                                             GParamSpec *pspec)
66{
67  OwlGlobalNotifier *notifier = OWL_GLOBAL_NOTIFIER(object);
68
69  switch (property_id) {
70    /* normal properties */
71    case PROP_RIGHTSHIFT:
72      owl_global_set_rightshift(notifier->g, g_value_get_int(value));
73      break;
74    case PROP_CURMSG_VERT_OFFSET:
75      owl_global_set_curmsg_vert_offset(notifier->g, g_value_get_int(value));
76      break;
77    /* generated from variable listings */
78EOT
79
80for my $var (@vars) {
81    my $varname = $var->{name};
82    my $propname = $var->{propname};
83    print "    case $propname:\n";
84
85    if ($var->{type} =~ /^BOOL/) {
86      print <<EOT;
87      if (g_value_get_boolean(value)) {
88        owl_variable_set_bool_on(&notifier->g->vars, "$varname");
89      } else {
90        owl_variable_set_bool_off(&notifier->g->vars, "$varname");
91      }
92EOT
93    } elsif ($var->{type} =~ /^PATH/ or $var->{type} =~ /^STRING/) {
94      print "      owl_variable_set_string(&notifier->g->vars, \"$varname\", g_value_get_string(value));\n";
95    } elsif ($var->{type} =~ /^INT/ or $var->{type} =~ /^ENUM/) {
96      print "      owl_variable_set_int(&notifier->g->vars, \"$varname\", g_value_get_int(value));\n";
97    } 
98    print "      break;\n";
99}
100
101print <<EOT;
102    default:
103      G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
104  }
105}
106
107static void owl_global_notifier_get_property(GObject *object,
108                                             guint property_id,
109                                             GValue *value,
110                                             GParamSpec *pspec)
111{
112  OwlGlobalNotifier *notifier = OWL_GLOBAL_NOTIFIER(object);
113
114  switch (property_id) {
115    /* normal properties */
116    case PROP_RIGHTSHIFT:
117      g_value_set_int(value, owl_global_get_rightshift(notifier->g));
118      break;
119    case PROP_CURMSG_VERT_OFFSET:
120      g_value_set_int(value, owl_global_get_curmsg_vert_offset(notifier->g));
121      break;
122    /* generated from variable listings */
123EOT
124for my $var (@vars) {
125    my $varname = $var->{name};
126    my $propname = $var->{propname};
127    print "    case $propname:\n";
128
129    if ($var->{type} =~ /^BOOL/) {
130      print "      g_value_set_boolean(value, owl_variable_get_bool(&notifier->g->vars, \"$varname\"));\n";
131    } elsif ($var->{type} =~ /^PATH/ or $var->{type} =~ /^STRING/) {
132      print "      g_value_set_string(value, owl_variable_get_string(&notifier->g->vars, \"$varname\"));\n";
133    } elsif ($var->{type} =~ /^INT/ or $var->{type} =~ /^ENUM/) {
134      print "      g_value_set_int(value, owl_variable_get_int(&notifier->g->vars, \"$varname\"));\n";
135    } 
136    print "      break;\n";
137}
138print <<EOT;
139    default:
140      G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
141  }
142}
143
144static void owl_global_notifier_class_init(OwlGlobalNotifierClass *klass)
145{
146  GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
147  GParamSpec *pspec;
148
149  gobject_class->get_property = owl_global_notifier_get_property;
150  gobject_class->set_property = owl_global_notifier_set_property;
151
152  /* Create signals */
153
154  notifier_signals[VIEW_CHANGED] =
155    g_signal_new("view-changed",
156                 G_TYPE_FROM_CLASS(gobject_class),
157                 G_SIGNAL_RUN_FIRST,
158                 0,
159                 NULL, NULL,
160                 g_cclosure_marshal_VOID__VOID,
161                 G_TYPE_NONE,
162                 0,
163                 NULL);
164
165  /* Register properties */
166 
167  pspec = g_param_spec_int("rightshift",
168                           "rightshift",
169                           "How much we shift to the right",
170                           0,
171                           INT_MAX,
172                           0,
173                           G_PARAM_READABLE|G_PARAM_WRITABLE
174                          |G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB);
175  g_object_class_install_property(gobject_class, PROP_RIGHTSHIFT, pspec);
176
177EOT
178for my $var (@vars) {
179    my $varname = $var->{name};
180    my $propname = $var->{propname};
181    my $detailname = $var->{detailname};
182    if ($var->{type} =~ /^BOOL/) {
183      print <<EOT
184  pspec = g_param_spec_boolean("$detailname",
185                               "$varname",
186                               "$varname", /* TODO: parse out the summary too */
187                               FALSE,
188                               G_PARAM_READABLE|G_PARAM_WRITABLE
189                              |G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB);
190EOT
191    } elsif ($var->{type} =~ /^PATH/ or $var->{type} =~ /^STRING/) {
192      print <<EOT
193  pspec = g_param_spec_string("$detailname",
194                              "$varname",
195                              "$varname", /* TODO: parse out the summary too */
196                              "",
197                              G_PARAM_READABLE|G_PARAM_WRITABLE
198                             |G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB);
199EOT
200    } elsif ($var->{type} =~ /^INT/ or $var->{type} =~ /^ENUM/) {
201      print <<EOT
202  pspec = g_param_spec_int("$detailname",
203                           "$varname",
204                           "$varname", /* TODO: parse out the summary too */
205                           INT_MIN,
206                           INT_MAX,
207                           0,
208                           G_PARAM_READABLE|G_PARAM_WRITABLE
209                          |G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB);
210EOT
211    } 
212    print "  g_object_class_install_property(gobject_class, $propname, pspec);\n\n";
213}
214print <<EOT;
215}
216
217static void owl_global_notifier_init(OwlGlobalNotifier *self)
218{
219}
220
221OwlGlobalNotifier *owl_global_notifier_new(owl_global *g)
222{
223  OwlGlobalNotifier *gn;
224 
225  gn = g_object_new(OWL_TYPE_GLOBAL_NOTIFIER, NULL);
226  gn->g = g;
227  return gn;
228}
229
230void owl_global_notifier_emit_view_changed(OwlGlobalNotifier *gn)
231{
232  g_signal_emit(gn, notifier_signals[VIEW_CHANGED], 0);
233}
234EOT
Note: See TracBrowser for help on using the repository browser.