[nautilus-actions] Move string ids list from NAObjectMenu to NAObjectItem
- From: Pierre Wieser <pwieser src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [nautilus-actions] Move string ids list from NAObjectMenu to NAObjectItem
- Date: Wed, 14 Oct 2009 17:30:42 +0000 (UTC)
commit eaf6a6e9be2de344ee6ba9e90542e620821afc36
Author: pierre <pierre vfedora10 virtuals pwi>
Date: Tue Oct 13 16:28:35 2009 +0200
Move string ids list from NAObjectMenu to NAObjectItem
ChangeLog | 23 +++++++++
src/runtime/na-gconf-provider-keys.h | 6 ++-
src/runtime/na-gconf-provider.c | 71 +++++++++++++----------------
src/runtime/na-iio-provider.c | 2 +-
src/runtime/na-object-item-fn.h | 4 ++
src/runtime/na-object-item-priv.h | 5 ++
src/runtime/na-object-item.c | 84 ++++++++++++++++++++++++++++++++++
src/runtime/na-object-menu-fn.h | 4 --
src/runtime/na-object-menu-priv.h | 5 --
src/runtime/na-object-menu.c | 84 ----------------------------------
10 files changed, 154 insertions(+), 134 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index d67daf4..3738720 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -10,6 +10,29 @@
* src/nact/nact-iactions-list.c (on_tab_updatable_item_updated):
Recursively update the display of parents of the updated item.
+ * src/runtime/na-gconf-provider-keys.h:
+ OBJECT_ITEM_TYPE_ENTRY: new key which defines the type of the entry.
+ MENU_ITEMS_ENTRY: renamed to OBJECT_ITEM_LIST_ENTRY.
+
+ * src/runtime/na-gconf-provider.c (read_item):
+ Only use the item's type to distinguish between action and menu.
+ (read_object_item_properties, write_object_item): actions and
+ menus may have ordered subitems
+ (write_item_action, write_item_menu): Write the item's type.
+
+ * src/runtime/na-iio-provider.c (build_hierarchy):
+ Use na_object_item_get_items_string_list.
+
+ * src/runtime/na-object-item-fn.h:
+ * src/runtime/na-object-item-priv.h:
+ * src/runtime/na-object-item.c:
+ List of string id of subitems is moved from NAObjectMenu.
+
+ * src/runtime/na-object-menu-fn.h:
+ * src/runtime/na-object-menu-priv.h:
+ * src/runtime/na-object-menu.c:
+ List of string id of subitems is moved to NAObjectItem.
+
2009-10-12 Pierre Wieser <pwieser trychlos org>
* src/common/na-object-api.h
diff --git a/src/runtime/na-gconf-provider-keys.h b/src/runtime/na-gconf-provider-keys.h
index e4c6772..c96a807 100644
--- a/src/runtime/na-gconf-provider-keys.h
+++ b/src/runtime/na-gconf-provider-keys.h
@@ -43,10 +43,14 @@
#define OBJECT_ITEM_TOOLTIP_ENTRY "tooltip"
#define OBJECT_ITEM_ICON_ENTRY "icon"
#define OBJECT_ITEM_ENABLED_ENTRY "enabled"
+#define OBJECT_ITEM_LIST_ENTRY "items"
+#define OBJECT_ITEM_TYPE_ENTRY "type"
+
+#define OBJECT_ITEM_TYPE_MENU "menu"
+#define OBJECT_ITEM_TYPE_ACTION "action"
/* GConf key names (specific to menu)
*/
-#define MENU_ITEMS_ENTRY "items"
/* GConf key names (specific to action)
*/
diff --git a/src/runtime/na-gconf-provider.c b/src/runtime/na-gconf-provider.c
index a218e93..ff15dca 100644
--- a/src/runtime/na-gconf-provider.c
+++ b/src/runtime/na-gconf-provider.c
@@ -459,46 +459,42 @@ iio_provider_read_items_list( const NAIIOProvider *provider )
return( items_list );
}
-/*
- * if there is an "items" entry, this is a menu and there must not
- * be any subdirectories
- * else, this is an action, and there must have at least one subdir..
- */
static NAObjectItem *
read_item( NAGConfProvider *provider, const gchar *path )
{
static const gchar *thisfn = "na_gconf_provider_read_item";
NAObjectItem *item;
- gboolean have_items;
- gboolean have_subdir;
+ gboolean have_type;
+ gchar *full_path;
+ gchar *type;
/*g_debug( "%s: provider=%p, path=%s", thisfn, ( void * ) provider, path );*/
g_return_val_if_fail( NA_IS_GCONF_PROVIDER( provider ), NULL );
g_return_val_if_fail( NA_IS_IIO_PROVIDER( provider ), NULL );
g_return_val_if_fail( !provider->private->dispose_has_run, NULL );
- have_subdir = na_gconf_utils_have_subdir( provider->private->gconf, path );
- have_items = na_gconf_utils_have_entry( provider->private->gconf, path, MENU_ITEMS_ENTRY );
- /*g_debug( "%s: have_subdir=%s, have_items=%s", thisfn, have_subdir ? "True":"False", have_items ? "True":"False" );*/
+ have_type = na_gconf_utils_have_entry( provider->private->gconf, path, OBJECT_ITEM_TYPE_ENTRY );
+ full_path = gconf_concat_dir_and_key( path, OBJECT_ITEM_TYPE_ENTRY );
+ type = na_gconf_utils_read_string( provider->private->gconf, full_path, TRUE, OBJECT_ITEM_TYPE_ACTION );
+ g_free( full_path );
- if( have_subdir && have_items ){
- g_warning( "%s: found both subdir(s) and \"items\" entry at %s", thisfn, path );
- return( NULL );
- }
-
- /* it has a (maybe empty) 'items' entry: this is a menu
+ /* a menu has a 'type' = 'menu'
*/
- if( have_items ){
+ if( have_type && !strcmp( type, OBJECT_ITEM_TYPE_MENU )){
item = NA_OBJECT_ITEM( na_object_menu_new());
read_item_menu( provider, path, NA_OBJECT_MENU( item ));
- /* else this should be an action
+ /* else this should be an action (no type, or 'type' = 'action')
*/
- } else {
+ } else if( !have_type || !strcmp( type, OBJECT_ITEM_TYPE_ACTION )){
item = NA_OBJECT_ITEM( na_object_action_new());
read_item_action( provider, path, NA_OBJECT_ACTION( item ));
+ } else {
+ g_warning( "%s: unknown type '%s' at %s", thisfn, type, path );
}
+ g_free( type );
+
return( item );
}
@@ -701,14 +697,7 @@ read_item_menu( NAGConfProvider *provider, const gchar *path, NAObjectMenu *menu
static void
read_item_menu_properties( NAGConfProvider *provider, GSList *entries, NAObjectMenu *menu )
{
- GSList *items;
-
read_object_item_properties( provider, entries, NA_OBJECT_ITEM( menu ) );
-
- if( na_gconf_utils_get_string_list_from_entries( entries, MENU_ITEMS_ENTRY, &items )){
- na_object_menu_set_items_string_list( menu, items );
- na_utils_free_string_list( items );
- }
}
/*
@@ -720,6 +709,7 @@ read_object_item_properties( NAGConfProvider *provider, GSList *entries, NAObjec
static const gchar *thisfn = "na_gconf_provider_read_object_item_properties";
gchar *id, *label, *tooltip, *icon;
gboolean enabled;
+ GSList *subitems;
if( !na_gconf_utils_get_string_from_entries( entries, OBJECT_ITEM_LABEL_ENTRY, &label )){
id = na_object_get_id( item );
@@ -743,6 +733,11 @@ read_object_item_properties( NAGConfProvider *provider, GSList *entries, NAObjec
if( na_gconf_utils_get_bool_from_entries( entries, OBJECT_ITEM_ENABLED_ENTRY, &enabled )){
na_object_set_enabled( item, enabled );
}
+
+ if( na_gconf_utils_get_string_list_from_entries( entries, OBJECT_ITEM_LIST_ENTRY, &subitems )){
+ na_object_item_set_items_string_list( item, subitems );
+ na_utils_free_string_list( subitems );
+ }
}
static gboolean
@@ -832,13 +827,12 @@ write_item_action( NAGConfProvider *provider, const NAObjectAction *action, gcha
GList *profiles, *ip;
NAObjectProfile *profile;
- if( !write_object_item( provider, NA_OBJECT_ITEM( action ), message )){
- return( FALSE );
- }
-
uuid = na_object_get_id( action );
- ret = write_str( provider, uuid, NULL, ACTION_VERSION_ENTRY, na_object_action_get_version( action ), message );
+ ret =
+ write_object_item( provider, NA_OBJECT_ITEM( action ), message ) &&
+ write_str( provider, uuid, NULL, ACTION_VERSION_ENTRY, na_object_action_get_version( action ), message ) &&
+ write_str( provider, uuid, NULL, OBJECT_ITEM_TYPE_ENTRY, g_strdup( OBJECT_ITEM_TYPE_ACTION ), message );
profiles = na_object_get_items_list( action );
@@ -870,19 +864,17 @@ write_item_action( NAGConfProvider *provider, const NAObjectAction *action, gcha
static gboolean
write_item_menu( NAGConfProvider *provider, const NAObjectMenu *menu, gchar **message )
{
- gchar *uuid;
gboolean ret;
+ gchar *uuid;
- if( !write_object_item( provider, NA_OBJECT_ITEM( menu ), message )){
- return( FALSE );
- }
-
- uuid = na_object_get_id( NA_OBJECT( menu ));
+ uuid = na_object_get_id( menu );
ret =
- write_list( provider, uuid, NULL, MENU_ITEMS_ENTRY, na_object_menu_rebuild_items_list( menu ), message );
+ write_object_item( provider, NA_OBJECT_ITEM( menu ), message ) &&
+ write_str( provider, uuid, NULL, OBJECT_ITEM_TYPE_ENTRY, g_strdup( OBJECT_ITEM_TYPE_MENU ), message );
g_free( uuid );
+
return( ret );
}
@@ -898,7 +890,8 @@ write_object_item( NAGConfProvider *provider, const NAObjectItem *item, gchar **
write_str( provider, uuid, NULL, OBJECT_ITEM_LABEL_ENTRY, na_object_get_label( NA_OBJECT( item )), message ) &&
write_str( provider, uuid, NULL, OBJECT_ITEM_TOOLTIP_ENTRY, na_object_get_tooltip( item ), message ) &&
write_str( provider, uuid, NULL, OBJECT_ITEM_ICON_ENTRY, na_object_get_icon( item ), message ) &&
- write_bool( provider, uuid, NULL, OBJECT_ITEM_ENABLED_ENTRY, na_object_is_enabled( item ), message );
+ write_bool( provider, uuid, NULL, OBJECT_ITEM_ENABLED_ENTRY, na_object_is_enabled( item ), message ) &&
+ write_list( provider, uuid, NULL, OBJECT_ITEM_LIST_ENTRY, na_object_item_rebuild_items_list( item ), message );
g_free( uuid );
return( ret );
diff --git a/src/runtime/na-iio-provider.c b/src/runtime/na-iio-provider.c
index 9350eaf..9571d62 100644
--- a/src/runtime/na-iio-provider.c
+++ b/src/runtime/na-iio-provider.c
@@ -248,7 +248,7 @@ build_hierarchy( GList **tree, GSList *level_zero, gboolean list_if_empty )
*tree = g_list_remove_link( *tree, it );
if( NA_IS_OBJECT_MENU( it->data )){
- subitems_ids = na_object_menu_get_items_string_list( NA_OBJECT_MENU( it->data ));
+ subitems_ids = na_object_item_get_items_string_list( NA_OBJECT_ITEM( it->data ));
subitems = build_hierarchy( tree, subitems_ids, FALSE );
na_object_set_items_list( it->data, subitems );
na_utils_free_string_list( subitems_ids );
diff --git a/src/runtime/na-object-item-fn.h b/src/runtime/na-object-item-fn.h
index f1a3840..5541ed6 100644
--- a/src/runtime/na-object-item-fn.h
+++ b/src/runtime/na-object-item-fn.h
@@ -66,6 +66,10 @@ void na_object_item_set_items_list( NAObjectItem *item, GList *items )
void na_object_item_append_item( NAObjectItem *object, const NAObject *item );
void na_object_item_remove_item( NAObjectItem *object, const NAObject *item );
+GSList *na_object_item_get_items_string_list( const NAObjectItem *item );
+GSList *na_object_item_rebuild_items_list( const NAObjectItem *item );
+void na_object_item_set_items_string_list( NAObjectItem *item, GSList *items );
+
G_END_DECLS
#endif /* __NA_RUNTIME_OBJECT_ITEM_FN_H__ */
diff --git a/src/runtime/na-object-item-priv.h b/src/runtime/na-object-item-priv.h
index 1f9e7c2..e838bb5 100644
--- a/src/runtime/na-object-item-priv.h
+++ b/src/runtime/na-object-item-priv.h
@@ -50,6 +50,11 @@ struct NAObjectItemPrivate {
*/
GList *items;
+ /* this is the list of subitems as a list of id strings
+ * as readen from IIOProviders
+ */
+ GSList *items_ids;
+
/* the original provider
* required to be able to edit/delete the item
*/
diff --git a/src/runtime/na-object-item.c b/src/runtime/na-object-item.c
index 9ab9106..d707df5 100644
--- a/src/runtime/na-object-item.c
+++ b/src/runtime/na-object-item.c
@@ -307,6 +307,9 @@ instance_finalize( GObject *object )
g_free( self->private->tooltip );
g_free( self->private->icon );
+ /* release string list of subitems */
+ na_utils_free_string_list( self->private->items_ids );
+
g_free( self->private );
/* chain call to parent class */
@@ -657,6 +660,87 @@ na_object_item_remove_item( NAObjectItem *item, const NAObject *object )
}
}
+/**
+ * na_object_item_get_items_string_list:
+ * @item: this #NAObjectItem object.
+ *
+ * Returns: the items_ids string list, as readen from the IIOProvider.
+ *
+ * The returned list should be na_utils_free_string_list() by the caller.
+ */
+GSList *
+na_object_item_get_items_string_list( const NAObjectItem *item )
+{
+ GSList *list = NULL;
+
+ g_return_val_if_fail( NA_IS_OBJECT_ITEM( item ), NULL );
+
+ if( !item->private->dispose_has_run ){
+ list = na_utils_duplicate_string_list( item->private->items_ids );
+ }
+
+ return( list );
+}
+
+/**
+ * na_object_item_rebuild_items_list:
+ * @item: this #NAObjectItem object.
+ *
+ * Returns: a string list which contains the ordered list of ids of
+ * subitems.
+ *
+ * Note that the returned list is built on each call to this function,
+ * and is so an exact image of the current situation.
+ *
+ * The returned list should be na_utils_free_string_list() by the caller.
+ */
+GSList *
+na_object_item_rebuild_items_list( const NAObjectItem *item )
+{
+ GSList *list = NULL;
+ GList *items, *it;
+ gchar *uuid;
+
+ g_return_val_if_fail( NA_IS_OBJECT_ITEM( item ), NULL );
+
+ if( !item->private->dispose_has_run ){
+
+ items = na_object_get_items_list( item );
+
+ for( it = items ; it ; it = it->next ){
+ NAObjectItem *item = NA_OBJECT_ITEM( it->data );
+ uuid = na_object_get_id( item );
+ list = g_slist_prepend( list, uuid );
+ }
+
+ list = g_slist_reverse( list );
+ }
+
+ return( list );
+}
+
+/**
+ * na_object_item_set_items_string_list:
+ * @item: this #NAObjectItem object.
+ * @subitems: an ordered list of UUID of subitems.
+ *
+ * Set the internal list of uuids of subitems.
+ *
+ * This function takes a copy of the provided list. This later may so
+ * be safely released by the caller after this function has returned.
+ */
+void
+na_object_item_set_items_string_list( NAObjectItem *item, GSList *subitems )
+{
+ g_return_if_fail( NA_IS_OBJECT_ITEM( item ));
+
+ if( !item->private->dispose_has_run ){
+
+ na_utils_free_string_list( item->private->items_ids );
+ item->private->items_ids = na_utils_duplicate_string_list( subitems );
+ }
+}
+
static void
object_dump( const NAObject *item )
{
diff --git a/src/runtime/na-object-menu-fn.h b/src/runtime/na-object-menu-fn.h
index f7b5e11..2216617 100644
--- a/src/runtime/na-object-menu-fn.h
+++ b/src/runtime/na-object-menu-fn.h
@@ -48,10 +48,6 @@ G_BEGIN_DECLS
NAObjectMenu *na_object_menu_new( void );
-GSList *na_object_menu_get_items_string_list( const NAObjectMenu *menu );
-GSList *na_object_menu_rebuild_items_list( const NAObjectMenu *menu );
-void na_object_menu_set_items_string_list( NAObjectMenu *menu, GSList *items );
-
G_END_DECLS
#endif /* __NA_RUNTIME_OBJECT_MENU_FN_H__ */
diff --git a/src/runtime/na-object-menu-priv.h b/src/runtime/na-object-menu-priv.h
index 6fd07a5..c53f055 100644
--- a/src/runtime/na-object-menu-priv.h
+++ b/src/runtime/na-object-menu-priv.h
@@ -39,11 +39,6 @@ G_BEGIN_DECLS
*/
struct NAObjectMenuPrivate {
gboolean dispose_has_run;
-
- /* this is the list of subitems as a list of id strings
- * as readen from IIOProviders
- */
- GSList *items_ids;
};
G_END_DECLS
diff --git a/src/runtime/na-object-menu.c b/src/runtime/na-object-menu.c
index 6e838ab..a262153 100644
--- a/src/runtime/na-object-menu.c
+++ b/src/runtime/na-object-menu.c
@@ -160,9 +160,6 @@ instance_finalize( GObject *object )
g_return_if_fail( NA_IS_OBJECT_MENU( object ));
self = NA_OBJECT_MENU( object );
- /* release string list of subitems */
- na_utils_free_string_list( self->private->items_ids );
-
g_free( self->private );
/* chain call to parent class */
@@ -194,87 +191,6 @@ na_object_menu_new( void )
return( menu );
}
-/**
- * na_object_menu_get_items_string_list:
- * @menu: this #NAObjectMenu object.
- *
- * Returns: the items_ids string list, as readen from the IIOProvider.
- *
- * The returned list should be na_utils_free_string_list() by the caller.
- */
-GSList *
-na_object_menu_get_items_string_list( const NAObjectMenu *menu )
-{
- GSList *list = NULL;
-
- g_return_val_if_fail( NA_IS_OBJECT_MENU( menu ), NULL );
-
- if( !menu->private->dispose_has_run ){
- list = na_utils_duplicate_string_list( menu->private->items_ids );
- }
-
- return( list );
-}
-
-/**
- * na_object_menu_rebuild_items_list:
- * @menu: this #NAObjectMenu object.
- *
- * Returns: a string list which contains the ordered list of ids of
- * subitems.
- *
- * Note that the returned list is built on each call to this function,
- * and is so an exact image of the current situation.
- *
- * The returned list should be na_utils_free_string_list() by the caller.
- */
-GSList *
-na_object_menu_rebuild_items_list( const NAObjectMenu *menu )
-{
- GSList *list = NULL;
- GList *items, *it;
- gchar *uuid;
-
- g_return_val_if_fail( NA_IS_OBJECT_MENU( menu ), NULL );
-
- if( !menu->private->dispose_has_run ){
-
- items = na_object_get_items_list( menu );
-
- for( it = items ; it ; it = it->next ){
- NAObjectItem *item = NA_OBJECT_ITEM( it->data );
- uuid = na_object_get_id( item );
- list = g_slist_prepend( list, uuid );
- }
-
- list = g_slist_reverse( list );
- }
-
- return( list );
-}
-
-/**
- * na_object_menu_set_items_string_list:
- * @menu: this #NAObjectMenu object.
- * @items: an ordered list of UUID of subitems.
- *
- * Set the internal list of uuids of subitems.
- *
- * This function takes a copy of the provided list. This later may so
- * be safely released by the caller after this function has returned.
- */
-void
-na_object_menu_set_items_string_list( NAObjectMenu *menu, GSList *items )
-{
- g_return_if_fail( NA_IS_OBJECT_MENU( menu ));
-
- if( !menu->private->dispose_has_run ){
-
- na_utils_free_string_list( menu->private->items_ids );
- menu->private->items_ids = na_utils_duplicate_string_list( items );
- }
-}
-
static void
object_dump( const NAObject *menu )
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]