source: globalnotifiergen.pl @ cc36f27

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