Define new 'pivot-prop-loadable' property
[nautilus-actions.git] / src / test / test-iface-iface.c
blob4dd5707b7c087f4a0e6031ef7fe4814371428afb
1 /*
2 * Nautilus-Actions
3 * A Nautilus extension which offers configurable context menu actions.
5 * Copyright (C) 2005 The GNOME Foundation
6 * Copyright (C) 2006, 2007, 2008 Frederic Ruaudel and others (see AUTHORS)
7 * Copyright (C) 2009, 2010, 2011 Pierre Wieser and others (see AUTHORS)
9 * This Program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of
12 * the License, or (at your option) any later version.
14 * This Program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public
20 * License along with this Library; see the file COPYING. If not,
21 * write to the Free Software Foundation, Inc., 59 Temple Place,
22 * Suite 330, Boston, MA 02111-1307, USA.
24 * Authors:
25 * Frederic Ruaudel <grumz@grumz.net>
26 * Rodrigo Moya <rodrigo@gnome-db.org>
27 * Pierre Wieser <pwieser@trychlos.org>
28 * ... and many others (see AUTHORS)
31 #ifdef HAVE_CONFIG_H
32 #include <config.h>
33 #endif
35 #include "test-iface-iface.h"
36 #include "test-iface-base.h"
38 /* private interface data
40 struct TestIFaceInterfacePrivate {
41 void *empty; /* so that gcc -pedantic is happy */
44 static GType register_type( void );
45 static void interface_base_init( TestIFaceInterface *klass );
46 static void interface_base_finalize( TestIFaceInterface *klass );
48 static void v_fna( TestIFace *object );
50 static void do_fna( TestIFace *object );
52 GType
53 test_iface_get_type( void )
55 static GType iface_type = 0;
57 if( !iface_type ){
58 iface_type = register_type();
61 return( iface_type );
64 static GType
65 register_type( void )
67 static const gchar *thisfn = "test_iface_iface_register_type";
68 GType type;
70 static const GTypeInfo info = {
71 sizeof( TestIFaceInterface ),
72 ( GBaseInitFunc ) interface_base_init,
73 ( GBaseFinalizeFunc ) interface_base_finalize,
74 NULL,
75 NULL,
76 NULL,
79 NULL
82 g_debug( "%s", thisfn );
84 type = g_type_register_static( G_TYPE_INTERFACE, "TestIFace", &info, 0 );
86 g_type_interface_add_prerequisite( type, G_TYPE_OBJECT );
88 return( type );
91 static void
92 interface_base_init( TestIFaceInterface *klass )
94 static const gchar *thisfn = "test_iface_iface_interface_base_init";
95 static gboolean initialized = FALSE;
97 if( !initialized ){
98 g_debug( "%s: klass=%p", thisfn, ( void * ) klass );
100 klass->private = g_new0( TestIFaceInterfacePrivate, 1 );
102 initialized = TRUE;
106 static void
107 interface_base_finalize( TestIFaceInterface *klass )
109 static const gchar *thisfn = "test_iface_iface_interface_base_finalize";
110 static gboolean finalized = FALSE ;
112 if( !finalized ){
113 finalized = TRUE;
115 g_debug( "%s: klass=%p", thisfn, ( void * ) klass );
117 g_free( klass->private );
122 * only call the implementation of the most-derived class (if any)
123 * if the most-derived class has not implemented the function,
124 * then fallback to local default
126 void
127 test_iface_fna( TestIFace *object )
129 static const gchar *thisfn = "test_iface_iface_fna";
130 g_debug( "%s: %s at %p", thisfn, G_OBJECT_TYPE_NAME( object ), ( void * ) object );
131 v_fna( object );
134 static void
135 v_fna( TestIFace *object )
137 static const gchar *thisfn = "test_iface_iface_v_fna";
138 g_debug( "%s: %s at %p", thisfn, G_OBJECT_TYPE_NAME( object ), ( void * ) object );
139 if( TEST_IFACE_GET_INTERFACE( object )->fna ){
140 TEST_IFACE_GET_INTERFACE( object )->fna( object );
141 } else {
142 do_fna( object );
146 static void
147 do_fna( TestIFace *object )
149 static const gchar *thisfn = "test_iface_iface_do_fna";
150 g_debug( "%s: %s at %p", thisfn, G_OBJECT_TYPE_NAME( object ), ( void * ) object );
154 * successively call the implementation (if any) of each derived class
155 * in the hierarchy order, from topmost base class to most-derived class
156 * if any of class in the hierarchy has not implemented the function, the
157 * do nothing and go to next class
159 void
160 test_iface_fnb( TestIFace *object )
162 static const gchar *thisfn = "test_iface_iface_fnb";
163 GSList *hierarchy;
164 GObjectClass *class;
165 GType type;
166 GType base_type;
167 GSList *ic;
168 GTypeInterface *iface;
170 g_debug( "%s: %s at %p", thisfn, G_OBJECT_TYPE_NAME( object ), ( void * ) object );
171 g_debug( "%s: g_type_from_instance=%d", thisfn, ( gint ) G_TYPE_FROM_INSTANCE( object ));
172 g_debug( "%s: g_type_from_interface=%d", thisfn, ( gint ) G_TYPE_FROM_INTERFACE( object ));
174 hierarchy = NULL;
175 base_type = TEST_BASE_TYPE;
176 type = G_OBJECT_TYPE( object );
177 g_debug( "%s: type=%d %s", thisfn, ( gint ) type, G_OBJECT_TYPE_NAME( object ));
178 while( TRUE ){
179 /*hierarchy = g_slist_prepend( hierarchy, class );*/
180 hierarchy = g_slist_prepend( hierarchy, GINT_TO_POINTER( type ));
181 /*type = G_TYPE_FROM_CLASS( class );*/
182 if( type == base_type ){
183 break;
185 type = g_type_parent( type );
186 if( !type ){
187 g_debug( "%s: GOT ZERO TYPE", thisfn );
188 break;
192 for( ic = hierarchy ; ic ; ic = ic->next ){
193 type = GPOINTER_TO_INT( ic->data );
194 g_debug( "%s: iterating on %d type", thisfn, ( gint ) type );
195 class = g_type_class_peek_static( type );
196 g_debug( "%s: class is %s at %p", thisfn, G_OBJECT_CLASS_NAME( class ), ( void * ) class );
197 iface = g_type_interface_peek( class, TEST_IFACE_TYPE );
198 g_debug( "%s: iface at %p", thisfn, ( void * ) iface );
199 if( (( TestIFaceInterface * ) iface )->fnb ){
200 (( TestIFaceInterface * ) iface )->fnb( object );