~ubuntu-branches/ubuntu/intrepid/glib2.0/intrepid-updates

« back to all changes in this revision

Viewing changes to docs/reference/gobject/html/gobject-properties.html

  • Committer: Bazaar Package Importer
  • Author(s): Sebastian Dröge, Loic Minier, Sebastian Dröge
  • Date: 2008-07-22 11:17:05 UTC
  • mfrom: (1.2.44 upstream)
  • Revision ID: james.westby@ubuntu.com-20080722111705-0ejknwv7o1dyxmjj
Tags: 2.17.4-1
[ Loic Minier ]
* List back m68k in arches where we could make the testsuite fatal,
  following the update on GNOME #481575.
* Document why testsuite is currently completely disabled (fails when
  there's no writable $HOME).

[ Sebastian Dröge ]
* New upstream development release, the new API might still change:
  + debian/rules,
    debian/libglib2.0-0.symbols:
    - Updated for the new symbols.
  + debian/patches/90_gio-nautilus-crash.patch:
    - Dropped, merged upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
<link rel="chapter" href="howto-interface.html" title="How to define and implement interfaces">
24
24
<link rel="chapter" href="howto-signals.html" title="How to create and use signals">
25
25
<link rel="part" href="pt03.html" title="Part V. Related Tools">
 
26
<link rel="chapter" href="tools-vala.html" title="Vala">
26
27
<link rel="chapter" href="tools-gob.html" title="GObject builder">
27
28
<link rel="chapter" href="tools-ginspector.html" title="Graphical inspection of GObjects">
28
29
<link rel="chapter" href="tools-refdb.html" title="Debugging reference count problems">
64
65
/* Implementation                               */
65
66
/************************************************/
66
67
 
67
 
enum {
68
 
  MAMAN_BAR_CONSTRUCT_NAME = 1,
69
 
  MAMAN_BAR_PAPA_NUMBER,
 
68
enum
 
69
{
 
70
  PROP_0,
 
71
 
 
72
  PROP_MAMAN_NAME,
 
73
  PROP_PAPA_NUMBER
70
74
};
71
75
 
72
76
static void
73
 
maman_bar_instance_init (GTypeInstance   *instance,
74
 
                         gpointer         g_class)
75
 
{
76
 
  MamanBar *self = (MamanBar *)instance;
77
 
}
78
 
 
79
 
static void
80
77
maman_bar_set_property (GObject      *object,
81
78
                        guint         property_id,
82
79
                        const GValue *value,
83
80
                        GParamSpec   *pspec)
84
81
{
85
 
  MamanBar *self = (MamanBar *) object;
86
 
 
87
 
  switch (property_id) {
88
 
  case MAMAN_BAR_CONSTRUCT_NAME: {
89
 
    g_free (self-&gt;priv-&gt;name);
90
 
    self-&gt;priv-&gt;name = g_value_dup_string (value);
91
 
    g_print ("maman: %s\n",self-&gt;priv-&gt;name);
92
 
  }
93
 
    break;
94
 
  case MAMAN_BAR_PAPA_NUMBER: {
95
 
    self-&gt;priv-&gt;papa_number = g_value_get_uchar (value);
96
 
    g_print ("papa: %u\n",self-&gt;priv-&gt;papa_number);
97
 
  }
98
 
    break;
99
 
  default:
100
 
    /* We don't have any other property... */
101
 
    G_OBJECT_WARN_INVALID_PROPERTY_ID(object,property_id,pspec);
102
 
    break;
103
 
  }
 
82
  MamanBar *self = MAMAN_BAR (object);
 
83
 
 
84
  switch (property_id)
 
85
    {
 
86
    case PROP_MAMAN_NAME:
 
87
      g_free (self-&gt;priv-&gt;name);
 
88
      self-&gt;priv-&gt;name = g_value_dup_string (value);
 
89
      g_print ("maman: %s\n", self-&gt;priv-&gt;name);
 
90
      break;
 
91
 
 
92
    case PROP_PAPA_NUMBER:
 
93
      self-&gt;priv-&gt;papa_number = g_value_get_uchar (value);
 
94
      g_print ("papa: %u\n", self-&gt;priv-&gt;papa_number);
 
95
      break;
 
96
 
 
97
    default:
 
98
      /* We don't have any other property... */
 
99
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 
100
      break;
 
101
    }
104
102
}
105
103
 
106
104
static void
107
 
maman_bar_get_property (GObject      *object,
108
 
                        guint         property_id,
109
 
                        GValue       *value,
110
 
                        GParamSpec   *pspec)
 
105
maman_bar_get_property (GObject    *object,
 
106
                        guint       property_id,
 
107
                        GValue     *value,
 
108
                        GParamSpec *pspec)
111
109
{
112
 
  MamanBar *self = (MamanBar *) object;
113
 
 
114
 
  switch (property_id) {
115
 
  case MAMAN_BAR_CONSTRUCT_NAME: {
116
 
    g_value_set_string (value, self-&gt;priv-&gt;name);
117
 
  }
118
 
    break;
119
 
  case MAMAN_BAR_PAPA_NUMBER: {
120
 
    g_value_set_uchar (value, self-&gt;priv-&gt;papa_number);
121
 
  }
122
 
    break;
123
 
  default:
124
 
    /* We don't have any other property... */
125
 
    G_OBJECT_WARN_INVALID_PROPERTY_ID(object,property_id,pspec);
126
 
    break;
127
 
  }
 
110
  MamanBar *self = MAMAN_BAR (object);
 
111
 
 
112
  switch (property_id)
 
113
    {
 
114
    case PROP_MAMAN_NAME:
 
115
      g_value_set_string (value, self-&gt;priv-&gt;name);
 
116
      break;
 
117
 
 
118
    case PROP_PAPA_NUMBER:
 
119
      g_value_set_uchar (value, self-&gt;priv-&gt;papa_number);
 
120
      break;
 
121
 
 
122
    default:
 
123
      /* We don't have any other property... */
 
124
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 
125
      break;
 
126
    }
128
127
}
129
128
 
130
129
static void
131
 
maman_bar_class_init (gpointer g_class,
132
 
                      gpointer g_class_data)
 
130
maman_bar_class_init (MamanBarClass *klass)
133
131
{
134
132
  GObjectClass *gobject_class = G_OBJECT_CLASS (g_class);
135
 
  MamanBarClass *klass = MAMAN_BAR_CLASS (g_class);
136
133
  GParamSpec *pspec;
137
134
 
138
135
  gobject_class-&gt;set_property = maman_bar_set_property;
144
141
                               "no-name-set" /* default value */,
145
142
                               G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE);
146
143
  g_object_class_install_property (gobject_class,
147
 
                                   MAMAN_BAR_CONSTRUCT_NAME,
 
144
                                   PROP_MAMAN_NAME_NAME,
148
145
                                   pspec);
149
146
 
150
147
  pspec = g_param_spec_uchar ("papa-number",
155
152
                              2  /* default value */,
156
153
                              G_PARAM_READWRITE);
157
154
  g_object_class_install_property (gobject_class,
158
 
                                   MAMAN_BAR_PAPA_NUMBER,
 
155
                                   PROP_PAPA_NUMBER,
159
156
                                   pspec);
160
157
}
161
158
 
164
161
/************************************************/
165
162
 
166
163
GObject *bar;
167
 
GValue val = {0,};
 
164
GValue val = { 0, };
 
165
 
168
166
bar = g_object_new (MAMAN_TYPE_SUBBAR, NULL);
 
167
 
169
168
g_value_init (&amp;val, G_TYPE_CHAR);
170
169
g_value_set_char (&amp;val, 11);
 
170
 
171
171
g_object_set_property (G_OBJECT (bar), "papa-number", &amp;val);
 
172
 
 
173
g_value_unset (&amp;val);
172
174
</pre>
173
175
<p>
174
176
      The client code just above looks simple but a lot of things happen under the hood:
187
189
      <code class="function"><a class="link" href="gobject-Generic-values.html#g-value-transform" title="g_value_transform ()">g_value_transform</a></code> will try to transform the input signed char into
188
190
      an unsigned int. Of course, the success of the transformation depends on the availability
189
191
      of the required transform function. In practice, there will almost always be a transformation
190
 
      <sup>[<a name="id3075031" href="#ftn.id3075031" class="footnote">6</a>]</sup>
 
192
      <sup>[<a name="id2569059" href="#ftn.id2569059" class="footnote">6</a>]</sup>
191
193
      which matches and conversion will be carried out if needed.
192
194
    </p>
193
195
<p>
207
209
      implementation of Foo did override this method, the code path would jump to
208
210
      <code class="function">foo_set_property</code> after having retrieved from the 
209
211
      <span class="type"><a class="link" href="gobject-GParamSpec.html#GParamSpec" title="GParamSpec">GParamSpec</a></span> the <span class="emphasis"><em>param_id</em></span>
210
 
      <sup>[<a name="id3075133" href="#ftn.id3075133" class="footnote">7</a>]</sup>
 
212
      <sup>[<a name="id2569173" href="#ftn.id2569173" class="footnote">7</a>]</sup>
211
213
      which had been stored by
212
214
      <code class="function"><a class="link" href="gobject-The-Base-Object-Type.html#g-object-class-install-property" title="g_object_class_install_property ()">g_object_class_install_property</a></code>.
213
215
    </p>
276
278
</div>
277
279
<div class="footnotes">
278
280
<br><hr width="100" align="left">
279
 
<div class="footnote"><p><sup>[<a name="ftn.id3075031" href="#id3075031" class="para">6</a>] </sup>Its behaviour might not be what you expect but it is up to you to actually avoid
 
281
<div class="footnote"><p><sup>[<a name="ftn.id2569059" href="#id2569059" class="para">6</a>] </sup>Its behaviour might not be what you expect but it is up to you to actually avoid
280
282
          relying on these transformations.
281
283
        </p></div>
282
 
<div class="footnote"><p><sup>[<a name="ftn.id3075133" href="#id3075133" class="para">7</a>] </sup>
 
284
<div class="footnote"><p><sup>[<a name="ftn.id2569173" href="#id2569173" class="para">7</a>] </sup>
283
285
          It should be noted that the param_id used here need only to uniquely identify each 
284
286
          <span class="type"><a class="link" href="gobject-GParamSpec.html#GParamSpec" title="GParamSpec">GParamSpec</a></span> within the <span class="type">FooClass</span> such that the switch
285
287
          used in the set and get methods actually works. Of course, this locally-unique