3 * A Nautilus extension which offers configurable context menu actions.
5 * Copyright (C) 2005 The GNOME Foundation
6 * Copyright (C) 2006-2008 Frederic Ruaudel and others (see AUTHORS)
7 * Copyright (C) 2009-2015 Pierre Wieser and others (see AUTHORS)
9 * Nautilus-Actions 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 * Nautilus-Actions 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 GNU
17 * General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with Nautilus-Actions; see the file COPYING. If not, see
21 * <http://www.gnu.org/licenses/>.
24 * Frederic Ruaudel <grumz@grumz.net>
25 * Rodrigo Moya <rodrigo@gnome-db.org>
26 * Pierre Wieser <pwieser@trychlos.org>
27 * ... and many others (see AUTHORS)
30 /* A class with implements an interface
31 * This interface itself requiring the class...
35 #include <glib-object.h>
37 /* ********************************************************************
38 * Declaring the interface
39 * ********************************************************************/
40 #define TEST_IFACE_TYPE ( test_iface_get_type())
41 #define TEST_IFACE( object ) ( G_TYPE_CHECK_INSTANCE_CAST( object, TEST_IFACE_TYPE, TestIFace ))
42 #define TEST_IS_IFACE( object ) ( G_TYPE_CHECK_INSTANCE_TYPE( object, TEST_IFACE_TYPE ))
43 #define TEST_IFACE_GET_INTERFACE( instance )( G_TYPE_INSTANCE_GET_INTERFACE(( instance ), TEST_IFACE_TYPE, TestIFaceInterface ))
45 typedef struct TestIFace TestIFace
;
47 typedef struct TestIFaceInterfacePrivate TestIFaceInterfacePrivate
;
50 GTypeInterface parent
;
51 TestIFaceInterfacePrivate
*private;
55 GType
test_iface_get_type( void );
57 /* ********************************************************************
59 * ********************************************************************/
60 #define TEST_BASE_TYPE ( test_base_get_type())
61 #define TEST_BASE( object ) ( G_TYPE_CHECK_INSTANCE_CAST( object, TEST_BASE_TYPE, TestBase ))
62 #define TEST_BASE_CLASS( klass ) ( G_TYPE_CHECK_CLASS_CAST( klass, TEST_BASE_TYPE, TestBaseClass ))
63 #define TEST_IS_BASE( object ) ( G_TYPE_CHECK_INSTANCE_TYPE( object, TEST_BASE_TYPE ))
64 #define TEST_IS_BASE_CLASS( klass ) ( G_TYPE_CHECK_CLASS_TYPE(( klass ), TEST_BASE_TYPE ))
65 #define TEST_BASE_GET_CLASS( object ) ( G_TYPE_INSTANCE_GET_CLASS(( object ), TEST_BASE_TYPE, TestBaseClass ))
67 typedef struct TestBasePrivate TestBasePrivate
;
71 TestBasePrivate
*private;
75 typedef struct TestBaseClassPrivate TestBaseClassPrivate
;
79 TestBaseClassPrivate
*private;
83 GType
test_base_get_type( void );
85 static TestBase
*test_base_new( void );
87 /* ********************************************************************
88 * Implementing the interface
89 * ********************************************************************/
91 /* private interface data
93 struct TestIFaceInterfacePrivate
{
94 void *empty
; /* so that gcc -pedantic is happy */
97 static guint st_initializations
= 0;
99 static GType
iface_register_type( void );
100 static void interface_base_init( TestIFaceInterface
*klass
);
101 static void interface_base_finalize( TestIFaceInterface
*klass
);
104 test_iface_get_type( void )
106 static GType iface_type
= 0;
109 iface_type
= iface_register_type();
112 return( iface_type
);
116 iface_register_type( void )
118 static const gchar
*thisfn
= "test_iface_iface_register_type";
121 static const GTypeInfo info
= {
122 sizeof( TestIFaceInterface
),
123 ( GBaseInitFunc
) interface_base_init
,
124 ( GBaseFinalizeFunc
) interface_base_finalize
,
133 g_debug( "%s", thisfn
);
135 type
= g_type_register_static( G_TYPE_INTERFACE
, "TestIFace", &info
, 0 );
137 g_type_interface_add_prerequisite( type
, TEST_BASE_TYPE
);
143 interface_base_init( TestIFaceInterface
*klass
)
145 static const gchar
*thisfn
= "test_iface_iface_interface_base_init";
147 if( !st_initializations
){
149 g_debug( "%s: klass=%p", thisfn
, ( void * ) klass
);
151 klass
->private = g_new0( TestIFaceInterfacePrivate
, 1 );
154 st_initializations
+= 1;
158 interface_base_finalize( TestIFaceInterface
*klass
)
160 static const gchar
*thisfn
= "test_iface_iface_interface_base_finalize";
162 st_initializations
-= 1;
164 if( !st_initializations
){
166 g_debug( "%s: klass=%p", thisfn
, ( void * ) klass
);
168 g_free( klass
->private );
172 /* ********************************************************************
173 * Implementing the class
174 * ********************************************************************/
176 /* private class data
178 struct TestBaseClassPrivate
{
179 void *empty
; /* so that gcc -pedantic is happy */
182 /* private instance data
184 struct TestBasePrivate
{
185 gboolean dispose_has_run
;
188 static GObjectClass
*st_parent_class
= NULL
;
190 static GType
base_register_type( void );
191 static void class_init( TestBaseClass
*klass
);
192 static void instance_init( GTypeInstance
*instance
, gpointer klass
);
193 static void instance_dispose( GObject
*object
);
194 static void instance_finalize( GObject
*object
);
196 static void iface_iface_init( TestIFaceInterface
*iface
, void *user_data
);
199 test_base_get_type( void )
201 static GType object_type
= 0;
203 static const GInterfaceInfo iface_iface_info
= {
204 ( GInterfaceInitFunc
) iface_iface_init
,
210 object_type
= base_register_type();
211 g_type_add_interface_static( object_type
, TEST_IFACE_TYPE
, &iface_iface_info
);
214 return( object_type
);
218 base_register_type( void )
220 static const gchar
*thisfn
= "test_iface_base_register_type";
223 static GTypeInfo info
= {
224 sizeof( TestBaseClass
),
225 ( GBaseInitFunc
) NULL
,
226 ( GBaseFinalizeFunc
) NULL
,
227 ( GClassInitFunc
) class_init
,
232 ( GInstanceInitFunc
) instance_init
235 g_debug( "%s", thisfn
);
237 type
= g_type_register_static( G_TYPE_OBJECT
, "TestBase", &info
, 0 );
243 class_init( TestBaseClass
*klass
)
245 static const gchar
*thisfn
= "test_iface_base_class_init";
246 GObjectClass
*object_class
;
248 g_debug( "%s: klass=%p", thisfn
, ( void * ) klass
);
250 st_parent_class
= g_type_class_peek_parent( klass
);
252 object_class
= G_OBJECT_CLASS( klass
);
253 object_class
->dispose
= instance_dispose
;
254 object_class
->finalize
= instance_finalize
;
256 klass
->private = g_new0( TestBaseClassPrivate
, 1 );
260 instance_init( GTypeInstance
*instance
, gpointer klass
)
262 static const gchar
*thisfn
= "test_iface_base_instance_init";
265 g_return_if_fail( TEST_IS_BASE( instance
));
267 self
= TEST_BASE( instance
);
269 g_debug( "%s: instance=%p, klass=%p", thisfn
, ( void * ) instance
, ( void * ) klass
);
271 self
->private = g_new0( TestBasePrivate
, 1 );
273 self
->private->dispose_has_run
= FALSE
;
277 instance_dispose( GObject
*object
)
279 static const gchar
*thisfn
= "test_iface_base_instance_dispose";
282 g_return_if_fail( TEST_IS_BASE( object
));
284 self
= TEST_BASE( object
);
286 if( !self
->private->dispose_has_run
){
288 g_debug( "%s: object=%p", thisfn
, ( void * ) object
);
290 self
->private->dispose_has_run
= TRUE
;
292 /* chain up to the parent class */
293 if( G_OBJECT_CLASS( st_parent_class
)->dispose
){
294 G_OBJECT_CLASS( st_parent_class
)->dispose( object
);
300 instance_finalize( GObject
*object
)
302 static const gchar
*thisfn
= "test_iface_base_instance_finalize";
305 g_return_if_fail( TEST_IS_BASE( object
));
307 self
= ( TestBase
* ) object
;
309 g_debug( "%s: object=%p", thisfn
, ( void * ) object
);
311 g_free( self
->private );
313 /* chain call to parent class */
314 if( G_OBJECT_CLASS( st_parent_class
)->finalize
){
315 G_OBJECT_CLASS( st_parent_class
)->finalize( object
);
320 test_base_new( void )
322 TestBase
*object
= g_object_new( TEST_BASE_TYPE
, NULL
);
328 iface_iface_init( TestIFaceInterface
*iface
, void *user_data
)
330 static const gchar
*thisfn
= "test_iface_base_iface_iface_init";
332 g_debug( "%s: iface=%p, user_data=%p", thisfn
, ( void * ) iface
, ( void * ) user_data
);
335 /* ********************************************************************
337 * ********************************************************************/
340 main( int argc
, char **argv
)
344 #if !GLIB_CHECK_VERSION( 2,36, 0 )
348 g_debug( "allocating TestBase -------------------------------------" );
349 base
= test_base_new();
351 g_debug( "unreffing TestBase ------------------------------------" );
352 g_object_unref( base
);
354 g_debug( "end -----------------------------------------------------" );