glade-signal-class.c 5.22 KB
Newer Older
1 2 3 4 5 6 7
/* glade-signal-class.c
 *
 * Copyright (C) 2011 Openismus GmbH
 *
 * Authors:
 *      Tristan Van Berkom <tristanvb@openismus.com>
 *
8
 * This library is free software; you can redistribute it and/or modify it
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public 
 * License along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */


#include <config.h>
#include "glade-signal-class.h"
#include "glade-widget-adaptor.h"

struct _GladeSignalClass
{
  GladeWidgetAdaptor *adaptor; /* The adaptor that originated this signal.
31
                                */
32 33 34 35
  GSignalQuery        query;

  guint16             version_since_major; /* Version in which this signal was */
  guint16             version_since_minor; /* introduced
36
                                            */
37 38 39

  const gchar        *name;                /* Name of the signal, eg clicked */
  const gchar        *type;                /* Name of the object class that this signal 
40
                                            * belongs to eg GtkButton */
41 42

  guint deprecated : 1;                    /* True if this signal is deprecated */
43 44 45 46
};

GladeSignalClass *
glade_signal_class_new  (GladeWidgetAdaptor *adaptor,
47 48
                         GType               for_type,
                         guint               signal_id)
49 50 51 52 53 54 55 56 57 58 59
{
  GladeSignalClass *class;

  class = g_slice_new0 (GladeSignalClass);

  class->adaptor = adaptor;

  /* Since glib gave us this signal id... it should
   * exist no matter what.
   */
  g_signal_query (signal_id, &(class->query));
60
  if (class->query.signal_id == 0)
61 62 63 64 65 66 67 68 69 70
    {
      g_critical ("glade_signal_class_new() called with an invalid signal id");

      glade_signal_class_free (class);
      return NULL;
    }

  class->name = (class->query.signal_name);
  class->type = g_type_name (for_type);

71
  /* Initialize signal versions & deprecated to adaptor version */
72 73
  class->version_since_major = GWA_VERSION_SINCE_MAJOR (adaptor);
  class->version_since_minor = GWA_VERSION_SINCE_MINOR (adaptor);
74
  class->deprecated          = GWA_DEPRECATED (adaptor);
75 76 77 78 79 80 81 82 83 84 85

  return class;
}

void
glade_signal_class_free (GladeSignalClass *signal_class)
{
  g_slice_free (GladeSignalClass, signal_class);
}

void
86
glade_signal_class_update_from_node (GladeSignalClass *signal_class,
87 88
                                     GladeXmlNode     *node,
                                     const gchar      *domain)
89 90 91 92 93
{
  g_return_if_fail (signal_class != NULL);
  g_return_if_fail (node != NULL);

  glade_xml_get_property_version (node, GLADE_TAG_VERSION_SINCE,
94 95
                                  &signal_class->version_since_major, 
                                  &signal_class->version_since_minor);
96 97 98

  signal_class->deprecated =
    glade_xml_get_property_boolean (node,
99 100
                                    GLADE_TAG_DEPRECATED,
                                    signal_class->deprecated);
101 102
}

103 104 105 106 107 108
/**
 * glade_signal_class_get_adaptor:
 * @signal_class: a #GladeSignalClass
 *
 * Returns: (transfer none): a #GladeWidgetAdaptor
 */
109
GladeWidgetAdaptor *
110
glade_signal_class_get_adaptor (const GladeSignalClass *signal_class)
111 112 113 114 115 116 117
{
  g_return_val_if_fail (signal_class != NULL, NULL);

  return signal_class->adaptor;
}

G_CONST_RETURN gchar *
118
glade_signal_class_get_name (const GladeSignalClass *signal_class)
119 120 121 122 123 124 125
{
  g_return_val_if_fail (signal_class != NULL, NULL);

  return signal_class->name;
}

G_CONST_RETURN gchar *
126
glade_signal_class_get_type (const GladeSignalClass *signal_class)
127 128 129 130 131 132 133
{
  g_return_val_if_fail (signal_class != NULL, NULL);

  return signal_class->type;
}

GSignalFlags
134
glade_signal_class_get_flags (const GladeSignalClass *signal_class)
135 136 137 138 139 140 141
{
  g_return_val_if_fail (signal_class != NULL, 0);

  return signal_class->query.signal_flags;
}

void
142
glade_signal_class_set_since (GladeSignalClass *signal_class,
143 144
                              guint16           since_major,
                              guint16           since_minor)
145 146 147 148 149 150 151 152
{
  g_return_if_fail (signal_class != NULL);

  signal_class->version_since_major = since_major;
  signal_class->version_since_minor = since_minor;
}

guint16
153
glade_signal_class_since_major (GladeSignalClass *signal_class)
154 155 156 157 158 159 160
{
  g_return_val_if_fail (signal_class != NULL, 0);

  return signal_class->version_since_major;
}

guint16
161
glade_signal_class_since_minor (GladeSignalClass *signal_class)
162 163 164 165 166 167
{
  g_return_val_if_fail (signal_class != NULL, 0);

  return signal_class->version_since_minor;
}

168
void
169
glade_signal_class_set_deprecated (GladeSignalClass *signal_class,
170
                                   gboolean          deprecated)
171 172 173 174 175 176 177
{
  g_return_if_fail (signal_class != NULL);

  signal_class->deprecated = deprecated;
}

gboolean
178
glade_signal_class_deprecated (GladeSignalClass *signal_class)
179 180 181 182 183
{
  g_return_val_if_fail (signal_class != NULL, FALSE);

  return signal_class->deprecated;
}