glade-signal-class.c 4.07 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
/* glade-signal-class.c
 *
 * Copyright (C) 2011 Openismus GmbH
 *
 * Authors:
 *      Tristan Van Berkom <tristanvb@openismus.com>
 *
 * This library is free software; you can redistribute it and/or it
 * 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.
				*/
  GSignalQuery        query;

  guint16             version_since_major; /* Version in which this signal was */
  guint16             version_since_minor; /* introduced
					    */

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

GladeSignalClass *
glade_signal_class_new  (GladeWidgetAdaptor *adaptor,
			 GType               for_type,
			 guint               signal_id)
{
  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));
58
  if (class->query.signal_id == 0)
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
    {
      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);

  /* Initialize signal versions to adaptor version */
  class->version_since_major = GWA_VERSION_SINCE_MAJOR (adaptor);
  class->version_since_minor = GWA_VERSION_SINCE_MINOR (adaptor);

  return class;
}

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

void
glade_signal_class_update_from_node (GladeSignalClass   *signal_class,
				     GladeXmlNode       *node,
				     const gchar        *domain)
{
  g_return_if_fail (signal_class != NULL);
  g_return_if_fail (node != NULL);

  glade_xml_get_property_version (node, GLADE_TAG_VERSION_SINCE,
				  &signal_class->version_since_major, 
				  &signal_class->version_since_minor);
}

GladeWidgetAdaptor *
glade_signal_class_get_adaptor (GladeSignalClass *signal_class)
{
  g_return_val_if_fail (signal_class != NULL, NULL);

  return signal_class->adaptor;
}

G_CONST_RETURN gchar *
glade_signal_class_get_name (GladeSignalClass  *signal_class)
{
  g_return_val_if_fail (signal_class != NULL, NULL);

  return signal_class->name;
}

G_CONST_RETURN gchar *
glade_signal_class_get_type (GladeSignalClass  *signal_class)
{
  g_return_val_if_fail (signal_class != NULL, NULL);

  return signal_class->type;
}

GSignalFlags
glade_signal_class_get_flags (GladeSignalClass *signal_class)
{
  g_return_val_if_fail (signal_class != NULL, 0);

  return signal_class->query.signal_flags;
}

void
glade_signal_class_set_since (GladeSignalClass   *signal_class,
			      guint16             since_major,
			      guint16             since_minor)
{
  g_return_if_fail (signal_class != NULL);

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

guint16
glade_signal_class_since_major (GladeSignalClass   *signal_class)
{
  g_return_val_if_fail (signal_class != NULL, 0);

  return signal_class->version_since_major;
}

guint16
glade_signal_class_since_minor (GladeSignalClass   *signal_class)
{
  g_return_val_if_fail (signal_class != NULL, 0);

  return signal_class->version_since_minor;
}