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.
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)
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
);
53 test_iface_get_type( void )
55 static GType iface_type
= 0;
58 iface_type
= register_type();
67 static const gchar
*thisfn
= "test_iface_iface_register_type";
70 static const GTypeInfo info
= {
71 sizeof( TestIFaceInterface
),
72 ( GBaseInitFunc
) interface_base_init
,
73 ( GBaseFinalizeFunc
) interface_base_finalize
,
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
);
92 interface_base_init( TestIFaceInterface
*klass
)
94 static const gchar
*thisfn
= "test_iface_iface_interface_base_init";
95 static gboolean initialized
= FALSE
;
98 g_debug( "%s: klass=%p", thisfn
, ( void * ) klass
);
100 klass
->private = g_new0( TestIFaceInterfacePrivate
, 1 );
107 interface_base_finalize( TestIFaceInterface
*klass
)
109 static const gchar
*thisfn
= "test_iface_iface_interface_base_finalize";
110 static gboolean finalized
= FALSE
;
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
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
);
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
);
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
160 test_iface_fnb( TestIFace
*object
)
162 static const gchar
*thisfn
= "test_iface_iface_fnb";
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
));
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
));
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
){
185 type
= g_type_parent( type
);
187 g_debug( "%s: GOT ZERO TYPE", thisfn
);
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
);