[nautilus-actions] Refactoring: rename src/core/na-object-menu-class.h to src/api/na-object-menu.h
- From: Pierre Wieser <pwieser src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus-actions] Refactoring: rename src/core/na-object-menu-class.h to src/api/na-object-menu.h
- Date: Fri, 19 Feb 2010 02:24:17 +0000 (UTC)
commit 936d2ed287e143c6baa28d5a2934e086d2b7c5f1
Author: Pierre Wieser <pwieser trychlos org>
Date: Mon Feb 15 17:49:25 2010 +0100
Refactoring: rename src/core/na-object-menu-class.h to src/api/na-object-menu.h
ChangeLog | 1 +
src/api/Makefile.am | 1 +
.../na-object-menu.h} | 16 +-
src/core/Makefile.am | 1 +
src/core/na-object-menu.c | 267 +++++++++++---------
5 files changed, 161 insertions(+), 125 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 70b7eb6..15f8823 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,6 @@
2009-02-15 Pierre Wieser <pwieser trychlos org>
+ Rename src/core/na-object-menu-class.h to src/api/na-object-menu.h
Rename src/core/na-object-profile-class.h to src/api/na-object-profile.h
Rename src/core/na-object-action-class.h to src/api/na-object-action.h
Rename src/core/na-object-item-class.h to src/api/na-object-item.h
diff --git a/src/api/Makefile.am b/src/api/Makefile.am
index fad7334..ab22ef2 100644
--- a/src/api/Makefile.am
+++ b/src/api/Makefile.am
@@ -44,5 +44,6 @@ api_include_HEADERS = \
na-object-item.h \
na-object-action.h \
na-object-profile.h \
+ na-object-menu.h \
na-gconf-keys.h \
$(NULL)
diff --git a/src/core/na-object-menu-class.h b/src/api/na-object-menu.h
similarity index 85%
rename from src/core/na-object-menu-class.h
rename to src/api/na-object-menu.h
index 7118039..deb4366 100644
--- a/src/core/na-object-menu-class.h
+++ b/src/api/na-object-menu.h
@@ -28,18 +28,16 @@
* ... and many others (see AUTHORS)
*/
-#ifndef __NAUTILUS_ACTIONS_NA_PRIVATE_OBJECT_MENU_CLASS_H__
-#define __NAUTILUS_ACTIONS_NA_PRIVATE_OBJECT_MENU_CLASS_H__
+#ifndef __NAUTILUS_ACTIONS_API_NA_OBJECT_MENU_H__
+#define __NAUTILUS_ACTIONS_API_NA_OBJECT_MENU_H__
/**
* SECTION: na_object_menu
* @short_description: #NAObjectMenu class definition.
- * @include: nautilus-actions/private/na-object-menu.h
- *
- * This is a menu. It embeds other menus and/or actions.
+ * @include: nautilus-actions/na-object-menu.h
*/
-#include "na-object-item-class.h"
+#include "na-object-item.h"
G_BEGIN_DECLS
@@ -50,7 +48,7 @@ G_BEGIN_DECLS
#define NA_IS_OBJECT_MENU_CLASS( klass ) ( G_TYPE_CHECK_CLASS_TYPE(( klass ), NA_OBJECT_MENU_TYPE ))
#define NA_OBJECT_MENU_GET_CLASS( object ) ( G_TYPE_INSTANCE_GET_CLASS(( object ), NA_OBJECT_MENU_TYPE, NAObjectMenuClass ))
-typedef struct NAObjectMenuPrivate NAObjectMenuPrivate;
+typedef struct NAObjectMenuPrivate NAObjectMenuPrivate;
typedef struct {
NAObjectItem parent;
@@ -68,6 +66,8 @@ typedef struct {
GType na_object_menu_get_type( void );
+NAObjectMenu *na_object_menu_new( void );
+
G_END_DECLS
-#endif /* __NAUTILUS_ACTIONS_NA_PRIVATE_OBJECT_MENU_CLASS_H__ */
+#endif /* __NAUTILUS_ACTIONS_API_NA_OBJECT_MENU_H__ */
diff --git a/src/core/Makefile.am b/src/core/Makefile.am
index 115275e..79b1735 100644
--- a/src/core/Makefile.am
+++ b/src/core/Makefile.am
@@ -47,6 +47,7 @@ libna_core_la_SOURCES = \
na-object-item.c \
na-object-action.c \
na-object-profile.c \
+ na-object-menu.c \
\
na-iabout.c \
na-iabout.h \
diff --git a/src/core/na-object-menu.c b/src/core/na-object-menu.c
index 29be49c..3ea4845 100644
--- a/src/core/na-object-menu.c
+++ b/src/core/na-object-menu.c
@@ -32,12 +32,13 @@
#include <config.h>
#endif
-#include <api/na-object-api.h>
+#include <glib/gi18n.h>
-#include <runtime/na-utils.h>
+#include <api/na-idata-factory.h>
+#include <api/na-object-menu.h>
-#include "na-iduplicable.h"
-#include "na-object-menu-priv.h"
+#include "na-io-factory.h"
+#include "na-data-factory.h"
/* private class data
*/
@@ -45,41 +46,58 @@ struct NAObjectMenuClassPrivate {
void *empty; /* so that gcc -pedantic is happy */
};
-static NAObjectClass *st_parent_class = NULL;
+/* private instance data
+ */
+struct NAObjectMenuPrivate {
+ gboolean dispose_has_run;
+};
+
+ /* i18n: default label for a new menu */
+#define NEW_NAUTILUS_MENU N_( "New Nautilus menu" )
-static GType register_type( void );
-static void class_init( NAObjectMenuClass *klass );
-static void instance_init( GTypeInstance *instance, gpointer klass );
-static void instance_dispose( GObject *object );
-static void instance_finalize( GObject *object );
+extern NadfIdGroup menu_id_groups []; /* defined in na-item-menu-enum.c */
-static void object_dump( const NAObject *menu );
-static NAObject *object_new( const NAObject *menu );
-static void object_copy( NAObject *target, const NAObject *source );
-static gboolean object_are_equal( const NAObject *a, const NAObject *b );
-static gboolean object_is_valid( const NAObject *menu );
+static NAObjectItemClass *st_parent_class = NULL;
+
+static GType register_type( void );
+static void class_init( NAObjectMenuClass *klass );
+static void instance_init( GTypeInstance *instance, gpointer klass );
+static void instance_get_property( GObject *object, guint property_id, GValue *value, GParamSpec *spec );
+static void instance_set_property( GObject *object, guint property_id, const GValue *value, GParamSpec *spec );
+static void instance_dispose( GObject *object );
+static void instance_finalize( GObject *object );
+
+static void idata_factory_iface_init( NAIDataFactoryInterface *iface );
+static guint idata_factory_get_version( const NAIDataFactory *instance );
+static gchar *idata_factory_get_default( const NAIDataFactory *instance, const NadfIdType *iddef );
+static void idata_factory_copy( NAIDataFactory *target, const NAIDataFactory *source );
+static gboolean idata_factory_are_equal( const NAIDataFactory *a, const NAIDataFactory *b );
+static void idata_factory_read_done( NAIDataFactory *instance, const NAIIOFactory *reader, void *reader_data, GSList **messages );
+static void idata_factory_write_done( NAIDataFactory *instance, const NAIIOFactory *writer, void *writer_data, GSList **messages );
GType
na_object_menu_get_type( void )
{
- static GType action_type = 0;
+ static GType menu_type = 0;
+
+ if( menu_type == 0 ){
- if( !action_type ){
- action_type = register_type();
+ menu_type = register_type();
}
- return( action_type );
+ return( menu_type );
}
static GType
register_type( void )
{
static const gchar *thisfn = "na_object_menu_register_type";
+ GType type;
static GTypeInfo info = {
sizeof( NAObjectMenuClass ),
- ( GBaseInitFunc ) NULL,
- ( GBaseFinalizeFunc ) NULL,
+ NULL,
+ NULL,
( GClassInitFunc ) class_init,
NULL,
NULL,
@@ -88,9 +106,21 @@ register_type( void )
( GInstanceInitFunc ) instance_init
};
+ static const GInterfaceInfo idata_factory_iface_info = {
+ ( GInterfaceInitFunc ) idata_factory_iface_init,
+ NULL,
+ NULL
+ };
+
g_debug( "%s", thisfn );
- return( g_type_register_static( NA_OBJECT_ITEM_TYPE, "NAObjectMenu", &info, 0 ));
+ type = g_type_register_static( NA_OBJECT_ITEM_TYPE, "NAObjectMenu", &info, 0 );
+
+ g_type_add_interface_static( type, NA_IDATA_FACTORY_TYPE, &idata_factory_iface_info );
+
+ na_io_factory_register( type, menu_id_groups );
+
+ return( type );
}
static void
@@ -105,45 +135,74 @@ class_init( NAObjectMenuClass *klass )
st_parent_class = g_type_class_peek_parent( klass );
object_class = G_OBJECT_CLASS( klass );
+ object_class->set_property = instance_set_property;
+ object_class->get_property = instance_get_property;
object_class->dispose = instance_dispose;
object_class->finalize = instance_finalize;
+ naobject_class = NA_OBJECT_CLASS( klass );
+ naobject_class->dump = NULL;
+ naobject_class->copy = NULL;
+ naobject_class->are_equal = NULL;
+ naobject_class->is_valid = NULL;
+
klass->private = g_new0( NAObjectMenuClassPrivate, 1 );
- naobject_class = NA_OBJECT_CLASS( klass );
- naobject_class->dump = object_dump;
- naobject_class->new = object_new;
- naobject_class->copy = object_copy;
- naobject_class->are_equal = object_are_equal;
- naobject_class->is_valid = object_is_valid;
- naobject_class->get_childs = NULL;
- naobject_class->ref = NULL;
- naobject_class->unref = NULL;
+ na_data_factory_properties( object_class );
}
static void
instance_init( GTypeInstance *instance, gpointer klass )
{
- /*static const gchar *thisfn = "na_object_menu_instance_init";*/
+ static const gchar *thisfn = "na_object_menu_instance_init";
NAObjectMenu *self;
- /*g_debug( "%s: instance=%p, klass=%p", thisfn, ( void * ) instance, ( void * ) klass );*/
+ g_debug( "%s: instance=%p (%s), klass=%p",
+ thisfn, ( void * ) instance, G_OBJECT_TYPE_NAME( instance ), ( void * ) klass );
+
g_return_if_fail( NA_IS_OBJECT_MENU( instance ));
+
self = NA_OBJECT_MENU( instance );
self->private = g_new0( NAObjectMenuPrivate, 1 );
- self->private->dispose_has_run = FALSE;
+ na_data_factory_init( NA_IDATA_FACTORY( instance ));
+}
+
+static void
+instance_get_property( GObject *object, guint property_id, GValue *value, GParamSpec *spec )
+{
+ g_return_if_fail( NA_IS_OBJECT_MENU( object ));
+ g_return_if_fail( NA_IS_IDATA_FACTORY( object ));
+
+ if( !NA_OBJECT_MENU( object )->private->dispose_has_run ){
+
+ na_data_factory_set_value( NA_IDATA_FACTORY( object ), property_id, value, spec );
+ }
+}
+
+static void
+instance_set_property( GObject *object, guint property_id, const GValue *value, GParamSpec *spec )
+{
+ g_return_if_fail( NA_IS_OBJECT_MENU( object ));
+ g_return_if_fail( NA_IS_IDATA_FACTORY( object ));
+
+ if( !NA_OBJECT_MENU( object )->private->dispose_has_run ){
+
+ na_data_factory_get_value( NA_IDATA_FACTORY( object ), property_id, value, spec );
+ }
}
static void
instance_dispose( GObject *object )
{
- /*static const gchar *thisfn = "na_object_menu_instance_dispose";*/
+ static const gchar *thisfn = "na_object_menu_instance_dispose";
NAObjectMenu *self;
- /*g_debug( "%s: object=%p", thisfn, ( void * ) object );*/
+ g_debug( "%s: object=%p (%s)", thisfn, ( void * ) object, G_OBJECT_TYPE_NAME( object ));
+
g_return_if_fail( NA_IS_OBJECT_MENU( object ));
+
self = NA_OBJECT_MENU( object );
if( !self->private->dispose_has_run ){
@@ -160,129 +219,103 @@ instance_dispose( GObject *object )
static void
instance_finalize( GObject *object )
{
- /*static const gchar *thisfn = "na_object_menu_instance_finalize";*/
+ static const gchar *thisfn = "na_object_menu_instance_finalize";
NAObjectMenu *self;
- /*g_debug( "%s: object=%p", thisfn, ( void * ) object );*/
+ g_debug( "%s: object=%p (%s)", thisfn, ( void * ) object, G_OBJECT_TYPE_NAME( object ));
+
g_return_if_fail( NA_IS_OBJECT_MENU( object ));
+
self = NA_OBJECT_MENU( object );
g_free( self->private );
+ na_data_factory_finalize( NA_IDATA_FACTORY( object ));
+
/* chain call to parent class */
if( G_OBJECT_CLASS( st_parent_class )->finalize ){
G_OBJECT_CLASS( st_parent_class )->finalize( object );
}
}
-/**
- * na_object_menu_new:
- *
- * Allocates a new #NAObjectMenu object.
- *
- * The new #NAObjectMenu object is initialized with suitable default values,
- * but without any profile.
- *
- * Returns: the newly allocated #NAObjectMenu object.
- */
-NAObjectMenu *
-na_object_menu_new( void )
+static void
+idata_factory_iface_init( NAIDataFactoryInterface *iface )
{
- NAObjectMenu *menu;
+ static const gchar *thisfn = "na_object_menu_idata_factory_iface_init";
- menu = g_object_new( NA_OBJECT_MENU_TYPE, NULL );
+ g_debug( "%s: iface=%p", thisfn, ( void * ) iface );
- na_object_set_new_id( menu, NULL );
- na_object_set_label( menu, NA_OBJECT_MENU_DEFAULT_LABEL );
+ iface->get_version = idata_factory_get_version;
+ iface->get_default = idata_factory_get_default;
+ iface->copy = idata_factory_copy;
+ iface->are_equal = idata_factory_are_equal;
+ iface->read_done = idata_factory_read_done;
+ iface->write_done = idata_factory_write_done;
+}
- return( menu );
+static guint
+idata_factory_get_version( const NAIDataFactory *instance )
+{
+ return( 1 );
}
-static void
-object_dump( const NAObject *menu )
+static gchar *
+idata_factory_get_default( const NAIDataFactory *instance, const NadfIdType *iddef )
{
- static const gchar *thisfn = "na_object_menu_object_dump";
- /*NAObjectMenu *self;*/
+ gchar *value;
- g_return_if_fail( NA_IS_OBJECT_MENU( menu ));
+ value = NULL;
- if( !NA_OBJECT_MENU( menu )->private->dispose_has_run ){
+ switch( iddef->id ){
- g_debug( "%s: (nothing to dump)", thisfn );
+ case NADF_DATA_LABEL:
+ value = g_strdup( NEW_NAUTILUS_MENU );
+ break;
}
-}
-static NAObject *
-object_new( const NAObject *menu )
-{
- return( NA_OBJECT( na_object_menu_new()));
+ return( value );
}
static void
-object_copy( NAObject *target, const NAObject *source )
+idata_factory_copy( NAIDataFactory *target, const NAIDataFactory *source )
{
- g_return_if_fail( NA_IS_OBJECT_MENU( target ));
- g_return_if_fail( NA_IS_OBJECT_MENU( source ));
-
- if( !NA_OBJECT_MENU( target )->private->dispose_has_run &&
- !NA_OBJECT_MENU( source )->private->dispose_has_run ){
-
- /* nothing to do */
- }
+ na_object_item_copy( NA_OBJECT_ITEM( target ), NA_OBJECT_ITEM( source ));
}
static gboolean
-object_are_equal( const NAObject *a, const NAObject *b )
+idata_factory_are_equal( const NAIDataFactory *a, const NAIDataFactory *b )
{
- gboolean equal = TRUE;
+ return( na_object_item_are_equal( NA_OBJECT_ITEM( a ), NA_OBJECT_ITEM( b )));
+}
- g_return_val_if_fail( NA_IS_OBJECT_MENU( a ), FALSE );
- g_return_val_if_fail( NA_IS_OBJECT_MENU( b ), FALSE );
+static void
+idata_factory_read_done( NAIDataFactory *instance, const NAIIOFactory *reader, void *reader_data, GSList **messages )
+{
- if( !NA_OBJECT_MENU( a )->private->dispose_has_run &&
- !NA_OBJECT_MENU( b )->private->dispose_has_run ){
+}
- /* nothing to compare */
- }
+static void
+idata_factory_write_done( NAIDataFactory *instance, const NAIIOFactory *writer, void *writer_data, GSList **messages )
+{
- return( equal );
}
-/*
- * a valid NAObjectMenu requires a not null, not empty label
- * this is checked here as NAObject doesn't have this condition
+/**
+ * na_object_menu_new:
+ *
+ * Allocates a new #NAObjectMenu object.
+ *
+ * The new #NAObjectMenu object is initialized with suitable default values,
+ * but without any profile.
*
- * also, a valid menu has at least one valid child
+ * Returns: the newly allocated #NAObjectMenu object.
*/
-static gboolean
-object_is_valid( const NAObject *menu )
+NAObjectMenu *
+na_object_menu_new( void )
{
- gchar *label;
- gboolean is_valid = TRUE;
- gint valid_subitems;
- GList *subitems, *ip;
-
- g_return_val_if_fail( NA_IS_OBJECT_MENU( menu ), FALSE );
-
- if( !NA_OBJECT_MENU( menu )->private->dispose_has_run ){
-
- if( is_valid ){
- label = na_object_get_label( menu );
- is_valid = ( label && g_utf8_strlen( label, -1 ) > 0 );
- g_free( label );
- }
+ NAObjectMenu *menu;
- if( is_valid ){
- valid_subitems = 0;
- subitems = na_object_get_items_list( menu );
- for( ip = subitems ; ip && !valid_subitems ; ip = ip->next ){
- if( na_iduplicable_is_valid( ip->data )){
- valid_subitems += 1;
- }
- }
- is_valid = ( valid_subitems > 0 );
- }
- }
+ menu = g_object_new( NA_OBJECT_MENU_TYPE, NULL );
- return( is_valid );
+ return( menu );
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]