[nautilus-actions] Improve pre-v2 to v3 conversions
- From: Pierre Wieser <pwieser src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus-actions] Improve pre-v2 to v3 conversions
- Date: Wed, 18 Aug 2010 22:14:36 +0000 (UTC)
commit 00d9c39618f41eaeac2b8a98e954d32d6d5a7cfd
Author: Pierre Wieser <pwieser trychlos org>
Date: Thu Aug 19 00:14:08 2010 +0200
Improve pre-v2 to v3 conversions
Fix bug where only one successfull conversion was executed (instead of all).
Fix bug of not displaying matchcase status in NACT.
Improve conversion from '%d/%f' to '%f'.
ChangeLog | 19 ++++++++
src/api/na-object-item.h | 1 +
src/api/na-object-profile.h | 2 +
src/core/na-object-action.c | 99 ++++++++++------------------------------
src/core/na-object-item.c | 41 ++++++++++++++++
src/core/na-object-menu.c | 12 ++---
src/core/na-object-profile.c | 69 ++++++++++++++++++++--------
src/io-xml/naxml-reader.c | 24 ++--------
src/nact/nact-ibasenames-tab.c | 22 ++++++++-
9 files changed, 166 insertions(+), 123 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index feadae9..1e42b21 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,22 @@
+2010-08-19 Pierre Wieser <pwieser trychlos org>
+
+ * src/api/na-object-item.h:
+ * src/core/na-object-item.c
+ (na_object_item_deals_with_version): New function.
+
+ * src/api/na-object-profile.h:
+ * src/core/na-object-profile.c
+ (na_object_profile_convert_v2_to_last): New function.
+
+ * src/core/na-object-action.c:
+ * src/core/na-object-menu.c
+ (ifactory_object_read_start): Removed (unused) function.
+
+ * src/io-xml/naxml-reader.c (naxml_reader_read_done): Cleanup code.
+
+ * src/nact/nact-ibasenames-tab.c (on_tab_updatable_selection_changed):
+ Display matchcase status for the current context.
+
2010-08-18 Pierre Wieser <pwieser trychlos org>
* src/core/na-object-profile.c (convert_pre_v3_parameters_str):
diff --git a/src/api/na-object-item.h b/src/api/na-object-item.h
index 91b865b..f18b4d5 100644
--- a/src/api/na-object-item.h
+++ b/src/api/na-object-item.h
@@ -92,6 +92,7 @@ void na_object_item_count_items( GList *items, gint *menus, gint *actions
void na_object_item_unref_items( GList *items );
void na_object_item_unref_items_rec( GList *items );
+void na_object_item_deals_with_version ( NAObjectItem *item );
void na_object_item_rebuild_children_slist( NAObjectItem *item );
G_END_DECLS
diff --git a/src/api/na-object-profile.h b/src/api/na-object-profile.h
index 8106234..e8b255a 100644
--- a/src/api/na-object-profile.h
+++ b/src/api/na-object-profile.h
@@ -79,6 +79,8 @@ GType na_object_profile_get_type( void );
NAObjectProfile *na_object_profile_new( void );
NAObjectProfile *na_object_profile_new_with_defaults( void );
+void na_object_profile_convert_v2_to_last( NAObjectProfile *profile );
+
G_END_DECLS
#endif /* __NAUTILUS_ACTIONS_API_NA_OBJECT_PROFILE_H__ */
diff --git a/src/core/na-object-action.c b/src/core/na-object-action.c
index 2cb6ba6..a2b990b 100644
--- a/src/core/na-object-action.c
+++ b/src/core/na-object-action.c
@@ -79,7 +79,6 @@ static guint ifactory_object_get_version( const NAIFactoryObject *instanc
static NADataGroup *ifactory_object_get_groups( const NAIFactoryObject *instance );
static gboolean ifactory_object_are_equal( const NAIFactoryObject *a, const NAIFactoryObject *b );
static gboolean ifactory_object_is_valid( const NAIFactoryObject *object );
-static void ifactory_object_read_start( NAIFactoryObject *instance, const NAIFactoryProvider *reader, void *reader_data, GSList **messages );
static void ifactory_object_read_done( NAIFactoryObject *instance, const NAIFactoryProvider *reader, void *reader_data, GSList **messages );
static guint ifactory_object_write_start( NAIFactoryObject *instance, const NAIFactoryProvider *writer, void *writer_data, GSList **messages );
static guint ifactory_object_write_done( NAIFactoryObject *instance, const NAIFactoryProvider *writer, void *writer_data, GSList **messages );
@@ -87,9 +86,8 @@ static guint ifactory_object_write_done( NAIFactoryObject *instance, cons
static void icontext_iface_init( NAIContextInterface *iface );
static gboolean icontext_is_candidate( NAIContext *object, guint target, GList *selection );
-static void read_done_convert_v1_to_v2( NAIFactoryObject *instance );
+static gboolean read_done_convert_v1_to_last( NAIFactoryObject *instance );
static void read_done_deals_with_toolbar_label( NAIFactoryObject *instance );
-static void read_done_deals_with_version( NAIFactoryObject *instance );
static guint write_done_write_profiles( NAIFactoryObject *instance, const NAIFactoryProvider *writer, void *writer_data, GSList **messages );
@@ -295,7 +293,7 @@ ifactory_object_iface_init( NAIFactoryObjectInterface *iface )
iface->copy = NULL;
iface->are_equal = ifactory_object_are_equal;
iface->is_valid = ifactory_object_is_valid;
- iface->read_start = ifactory_object_read_start;
+ iface->read_start = NULL;
iface->read_done = ifactory_object_read_done;
iface->write_start = ifactory_object_write_start;
iface->write_done = ifactory_object_write_done;
@@ -327,11 +325,6 @@ ifactory_object_is_valid( const NAIFactoryObject *object )
return( object_object_is_valid( NA_OBJECT_ACTION( object )));
}
-static void
-ifactory_object_read_start( NAIFactoryObject *instance, const NAIFactoryProvider *reader, void *reader_data, GSList **messages )
-{
-}
-
/*
* at this time, we don't yet have readen the profiles as this will be
* done in ifactory_provider_read_done - we so just be able to deal with
@@ -340,17 +333,24 @@ ifactory_object_read_start( NAIFactoryObject *instance, const NAIFactoryProvider
static void
ifactory_object_read_done( NAIFactoryObject *instance, const NAIFactoryProvider *reader, void *reader_data, GSList **messages )
{
+ guint iversion;
+
g_debug( "na_object_action_ifactory_object_read_done: instance=%p", ( void * ) instance );
+ na_object_item_deals_with_version( NA_OBJECT_ITEM( instance ));
+
/* may attach a new profile if we detect a pre-v2 action
+ * the v1_to_v2 conversion must be followed by a v2_to_v3 one
*/
- read_done_convert_v1_to_v2( instance );
+ iversion = na_object_get_iversion( instance );
+ if( iversion < 2 ){
+ read_done_convert_v1_to_last( instance );
+ }
/* deals with obsoleted data, i.e. data which may have been written in the past
- * but are no long written by now
+ * but are no long written by now - not relevant for a menu
*/
read_done_deals_with_toolbar_label( instance );
- read_done_deals_with_version( instance );
/* prepare the context after the reading
*/
@@ -402,45 +402,25 @@ icontext_is_candidate( NAIContext *object, guint target, GList *selection )
/*
* do we have a pre-v2 action ?
* it is be identified by an version = "1.x"
- * or by any data found in data_def_action_v1 (defined in na-object-action-factory.c)
- * -> move obsoleted data to a new profile, updating the version string
+ * any data found in data_def_action_v1 (defined in na-object-action-factory.c)
+ * is obsoleted and moved to a new profile
*
- * actions readen from .desktop already have iversion=3 (cf. desktop_read_start)
- * and v1 actions may only come from xml or gconf
+ * actions readen from .desktop already have iversion=3 (cf. desktop_read_start)
+ * and v1 actions may only come from xml or gconf
+ *
+ * returns TRUE if this actually was a v1 action which has been converted to v2
*/
-static void
-read_done_convert_v1_to_v2( NAIFactoryObject *instance )
+static gboolean
+read_done_convert_v1_to_last( NAIFactoryObject *instance )
{
- static const gchar *thisfn = "na_object_action_read_done_convert_v1_to_v2";
- guint iversion;
- gchar *version;
+ static const gchar *thisfn = "na_object_action_read_done_read_done_convert_v1_to_last";
GList *to_move;
NADataDef *def;
NADataBoxed *boxed;
GList *ibox;
NAObjectProfile *profile;
- /* check for new numeric version
- */
- iversion = na_object_get_iversion( instance );
- if( iversion >= 2 ){
- return;
- }
-
- /* check for older alpha version
- * was not set in 2.30 serie
- */
- version = na_object_get_version( instance );
- if( version ){
- iversion = atoi( version );
- g_free( version );
- }
- if( iversion >= 2 ){
- return;
- }
-
- /* we so have here a not-versioned action, in very old 1.x or in 2.30
- * search for old data in the body: this is only possible before profiles
+ /* search for old data in the body: this is only possible before profiles
* because starting with contexts, iversion was written
*/
to_move = NULL;
@@ -457,7 +437,7 @@ read_done_convert_v1_to_v2( NAIFactoryObject *instance )
}
if( !to_move ){
- return;
+ return( FALSE );
}
/* now create a new profile
@@ -475,7 +455,8 @@ read_done_convert_v1_to_v2( NAIFactoryObject *instance )
}
na_factory_object_set_defaults( NA_IFACTORY_OBJECT( profile ));
- na_object_set_version( instance, "2.0" );
+ na_object_profile_convert_v2_to_last( profile );
+ return( TRUE );
}
/*
@@ -505,36 +486,6 @@ read_done_deals_with_toolbar_label( NAIFactoryObject *instance )
}
/*
- * manage the conversion from version string to version number
- * -> pre-v2 actions have already been converted to a version string "2.0"
- * -> if we have here no version string nor version number, then we may
- * consider that this is an item written by the 2.30 N-A version
- * so we just force a version number to 2
- */
-static void
-read_done_deals_with_version( NAIFactoryObject *instance )
-{
- guint version_uint;
- gchar *version_str;
-
- version_uint = na_object_get_iversion( instance );
-
- if( !version_uint ){
- version_str = na_object_get_version( instance );
-
- if( !version_str || !strlen( version_str )){
- g_free( version_str );
- version_str = g_strdup( "2.0" );
- }
-
- version_uint = atoi( version_str );
- na_object_set_iversion( instance, version_uint );
-
- g_free( version_str );
- }
-}
-
-/*
* write the profiles of the action
* note that subitems string list has been rebuilt on write_start
*/
diff --git a/src/core/na-object-item.c b/src/core/na-object-item.c
index 47406bd..98343cc 100644
--- a/src/core/na-object-item.c
+++ b/src/core/na-object-item.c
@@ -32,6 +32,7 @@
#include <config.h>
#endif
+#include <stdlib.h>
#include <string.h>
#include <uuid/uuid.h>
@@ -696,6 +697,46 @@ na_object_item_unref_items_rec( GList *items )
}
/**
+ * na_object_item_deals_with_version:
+ * @item: this #NAObjectItem-derived object.
+ *
+ * Just after the @item has been readen from NAIFactoryProvider, setup
+ * the version. This is needed because some conversions may occur in
+ * this object.
+ *
+ * Note that there is only some 2.x versions where the version string
+ * was not systematically written. If @item has been readen from a
+ * .desktop file, then iversion is already set to (at least) 3.
+ */
+void
+na_object_item_deals_with_version( NAObjectItem *item )
+{
+ guint version_uint;
+ gchar *version_str;
+
+ g_return_if_fail( NA_IS_OBJECT_ITEM( item ));
+
+ if( !item->private->dispose_has_run ){
+
+ version_uint = na_object_get_iversion( item );
+
+ if( !version_uint ){
+ version_str = na_object_get_version( item );
+
+ if( !version_str || !strlen( version_str )){
+ g_free( version_str );
+ version_str = g_strdup( "2.0" );
+ }
+
+ version_uint = atoi( version_str );
+ na_object_set_iversion( item, version_uint );
+
+ g_free( version_str );
+ }
+ }
+}
+
+/**
* na_object_item_rebuild_children_slist:
* @item: this #NAObjectItem-derived object.
*
diff --git a/src/core/na-object-menu.c b/src/core/na-object-menu.c
index a482627..572e25b 100644
--- a/src/core/na-object-menu.c
+++ b/src/core/na-object-menu.c
@@ -77,7 +77,6 @@ static guint ifactory_object_get_version( const NAIFactoryObject *instanc
static NADataGroup *ifactory_object_get_groups( const NAIFactoryObject *instance );
static gboolean ifactory_object_are_equal( const NAIFactoryObject *a, const NAIFactoryObject *b );
static gboolean ifactory_object_is_valid( const NAIFactoryObject *object );
-static void ifactory_object_read_start( NAIFactoryObject *instance, const NAIFactoryProvider *reader, void *reader_data, GSList **messages );
static void ifactory_object_read_done( NAIFactoryObject *instance, const NAIFactoryProvider *reader, void *reader_data, GSList **messages );
static guint ifactory_object_write_start( NAIFactoryObject *instance, const NAIFactoryProvider *writer, void *writer_data, GSList **messages );
static guint ifactory_object_write_done( NAIFactoryObject *instance, const NAIFactoryProvider *writer, void *writer_data, GSList **messages );
@@ -286,7 +285,7 @@ ifactory_object_iface_init( NAIFactoryObjectInterface *iface )
iface->copy = NULL;
iface->are_equal = ifactory_object_are_equal;
iface->is_valid = ifactory_object_is_valid;
- iface->read_start = ifactory_object_read_start;
+ iface->read_start = NULL;
iface->read_done = ifactory_object_read_done;
iface->write_start = ifactory_object_write_start;
iface->write_done = ifactory_object_write_done;
@@ -319,18 +318,15 @@ ifactory_object_is_valid( const NAIFactoryObject *object )
}
static void
-ifactory_object_read_start( NAIFactoryObject *instance, const NAIFactoryProvider *reader, void *reader_data, GSList **messages )
-{
-}
-
-static void
ifactory_object_read_done( NAIFactoryObject *instance, const NAIFactoryProvider *reader, void *reader_data, GSList **messages )
{
+ na_object_item_deals_with_version( NA_OBJECT_ITEM( instance ));
+
/* prepare the context after the reading
*/
na_icontext_read_done( NA_ICONTEXT( instance ));
- /* last, set other action defaults
+ /* last, set other menu defaults
*/
na_factory_object_set_defaults( instance );
}
diff --git a/src/core/na-object-profile.c b/src/core/na-object-profile.c
index 9b65165..20ac099 100644
--- a/src/core/na-object-profile.c
+++ b/src/core/na-object-profile.c
@@ -90,6 +90,7 @@ static gboolean convert_pre_v3_parameters( NAObjectProfile *profile );
static gboolean convert_pre_v3_parameters_str( gchar *str );
static gboolean convert_pre_v3_multiple( NAObjectProfile *profile );
static gboolean convert_pre_v3_isfiledir( NAObjectProfile *profile );
+static void read_done_ending( NAObjectProfile *profile );
static void split_path_parameters( NAObjectProfile *profile );
static gboolean profile_is_valid( const NAObjectProfile *profile );
static gboolean is_valid_path_parameters( const NAObjectProfile *profile );
@@ -346,27 +347,10 @@ ifactory_object_read_done( NAIFactoryObject *instance, const NAIFactoryProvider
g_debug( "%s: iversion=%d", thisfn, iversion );
if( iversion < 3 ){
-
- if( convert_pre_v3_parameters( NA_OBJECT_PROFILE( instance )) ||
- convert_pre_v3_multiple( NA_OBJECT_PROFILE( instance )) ||
- convert_pre_v3_isfiledir( NA_OBJECT_PROFILE( instance ))){
-
- na_object_set_iversion( action, 3 );
- }
+ na_object_profile_convert_v2_to_last( NA_OBJECT_PROFILE( instance ));
}
- /* split path+parameters
- * not done in io-desktop because some actions may have all arguments in path
- */
- split_path_parameters( NA_OBJECT_PROFILE( instance ));
-
- /* prepare the context after the reading
- */
- na_icontext_read_done( NA_ICONTEXT( instance ));
-
- /* last, set other action defaults
- */
- na_factory_object_set_defaults( instance );
+ read_done_ending( NA_OBJECT_PROFILE( instance ));
}
static guint
@@ -539,6 +523,7 @@ convert_pre_v3_multiple( NAObjectProfile *profile )
accept_multiple = na_object_is_multiple( profile );
selection_count = g_strdup( accept_multiple ? ">0" : "=1" );
na_object_set_selection_count( profile, selection_count );
+ g_debug( "na_object_profile_convert_pre_v3_multiple: set selection_count=%s", selection_count );
g_free( selection_count );
return( TRUE );
@@ -602,6 +587,23 @@ convert_pre_v3_isfiledir( NAObjectProfile *profile )
}
static void
+read_done_ending( NAObjectProfile *profile )
+{
+ /* split path+parameters
+ * not done in io-desktop because some actions may have all arguments in path
+ */
+ split_path_parameters( profile );
+
+ /* prepare the context after the reading
+ */
+ na_icontext_read_done( NA_ICONTEXT( profile ));
+
+ /* last, set other action defaults
+ */
+ na_factory_object_set_defaults( NA_IFACTORY_OBJECT( profile ));
+}
+
+static void
split_path_parameters( NAObjectProfile *profile )
{
gchar *path, *parameters;
@@ -728,3 +730,32 @@ na_object_profile_new_with_defaults( void )
return( profile );
}
+
+/**
+ * na_object_profile_convert_v2_to_last:
+ *
+ * Converts to v3 a @profile which has just been created from a pre-v2 action.
+ */
+void
+na_object_profile_convert_v2_to_last( NAObjectProfile *profile )
+{
+ NAObjectAction *action;
+ guint iversion;
+ gboolean parms_converted, multiple_converted, isfiledir_converted;
+
+ g_return_if_fail( NA_IS_OBJECT_PROFILE( profile ));
+
+ action = NA_OBJECT_ACTION( na_object_get_parent( profile ));
+ iversion = na_object_get_iversion( action );
+ g_return_if_fail( iversion < 3 );
+
+ parms_converted = convert_pre_v3_parameters( profile );
+ multiple_converted = convert_pre_v3_multiple( profile );
+ isfiledir_converted = convert_pre_v3_isfiledir( profile );
+
+ if( parms_converted || multiple_converted || isfiledir_converted ){
+ na_object_set_iversion( action, 3 );
+ }
+
+ read_done_ending( profile );
+}
diff --git a/src/io-xml/naxml-reader.c b/src/io-xml/naxml-reader.c
index 0815281..ba2c9b8 100644
--- a/src/io-xml/naxml-reader.c
+++ b/src/io-xml/naxml-reader.c
@@ -159,12 +159,10 @@ static RootNodeStr st_root_node_str[] = {
static void read_start_profile_attach_profile( NAXMLReader *reader, NAObjectProfile *profile );
static gboolean read_data_is_path_adhoc_for_object( NAXMLReader *reader, const NAIFactoryObject *object, xmlChar *text );
static NADataBoxed *read_data_boxed_from_node( NAXMLReader *reader, xmlChar *text, xmlNode *parent, const NADataDef *def );
-static void read_done_item( NAXMLReader *reader, NAObjectItem *item );
static void read_done_item_set_localized_icon( NAXMLReader *reader, NAObjectItem *item );
-static void read_done_action( NAXMLReader *reader, NAObjectAction *action );
+static void read_done_action_read_profiles( NAXMLReader *reader, NAObjectAction *action );
static gchar *read_done_action_get_next_profile_id( NAXMLReader *reader );
static void read_done_action_load_profile( NAXMLReader *reader, const gchar *profile_id );
-static void read_done_profile( NAXMLReader *reader, NAObjectProfile *profile );
static void read_done_profile_set_localized_label( NAXMLReader *reader, NAObjectProfile *profile );
static guint reader_parse_xmldoc( NAXMLReader *reader );
@@ -757,26 +755,20 @@ naxml_reader_read_done( const NAIFactoryProvider *provider, void *reader_data, c
( void * ) messages );
if( NA_IS_OBJECT_ITEM( object )){
- read_done_item( NAXML_READER( reader_data ), NA_OBJECT_ITEM( object ));
+ read_done_item_set_localized_icon( NAXML_READER( reader_data ), NA_OBJECT_ITEM( object ));
}
if( NA_IS_OBJECT_ACTION( object )){
- read_done_action( NAXML_READER( reader_data ), NA_OBJECT_ACTION( object ));
+ read_done_action_read_profiles( NAXML_READER( reader_data ), NA_OBJECT_ACTION( object ));
}
if( NA_IS_OBJECT_PROFILE( object )){
- read_done_profile( NAXML_READER( reader_data ), NA_OBJECT_PROFILE( object ));
+ read_done_profile_set_localized_label( NAXML_READER( reader_data ), NA_OBJECT_PROFILE( object ));
}
g_debug( "%s: quitting for %s at %p", thisfn, G_OBJECT_TYPE_NAME( object ), ( void * ) object );
}
-static void
-read_done_item( NAXMLReader *reader, NAObjectItem *item )
-{
- read_done_item_set_localized_icon( reader, item );
-}
-
/*
* just having readen this NAObjectItem
* so deals with unlocalized/localized icon name/path
@@ -812,7 +804,7 @@ read_done_item_set_localized_icon( NAXMLReader *reader, NAObjectItem *item )
* Also note that profiles order has been introduced in 2.29 serie
*/
static void
-read_done_action( NAXMLReader *reader, NAObjectAction *action )
+read_done_action_read_profiles( NAXMLReader *reader, NAObjectAction *action )
{
GSList *order, *ip;
gchar *profile_id;
@@ -897,12 +889,6 @@ read_done_action_load_profile( NAXMLReader *reader, const gchar *profile_id )
&reader->private->parms->messages );
}
-static void
-read_done_profile( NAXMLReader *reader, NAObjectProfile *profile )
-{
- read_done_profile_set_localized_label( reader, profile );
-}
-
/*
* just having readen this NAObjectProfile
* so deals with unlocalized/localized desc-name
diff --git a/src/nact/nact-ibasenames-tab.c b/src/nact/nact-ibasenames-tab.c
index d898e44..7436d7b 100644
--- a/src/nact/nact-ibasenames-tab.c
+++ b/src/nact/nact-ibasenames-tab.c
@@ -37,6 +37,7 @@
#include <api/na-object-api.h>
#include "nact-main-tab.h"
+#include "nact-gtk-utils.h"
#include "nact-match-list.h"
#include "nact-ibasenames-tab.h"
@@ -239,11 +240,26 @@ nact_ibasenames_tab_dispose( NactIBasenamesTab *instance )
static void
on_tab_updatable_selection_changed( BaseWindow *window, gint count_selected )
{
- st_on_selection_change = TRUE;
+ NAIContext *context;
+ gboolean editable;
+ GtkToggleButton *matchcase_button;
+ gboolean matchcase;
+
+ if( st_initialized && !st_finalized ){
- nact_match_list_on_selection_changed( window, ITAB_NAME, count_selected );
+ context = nact_main_tab_get_context( NACT_MAIN_WINDOW( window ), &editable );
+
+ st_on_selection_change = TRUE;
+
+ nact_match_list_on_selection_changed( window, ITAB_NAME, count_selected );
- st_on_selection_change = FALSE;
+ matchcase_button = GTK_TOGGLE_BUTTON( base_window_get_widget( window, "BasenamesMatchcaseButton" ));
+ matchcase = context ? na_object_get_matchcase( context ) : FALSE;
+ gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( matchcase_button ), matchcase );
+ nact_gtk_utils_set_editable( GTK_OBJECT( matchcase_button ), editable );
+
+ st_on_selection_change = FALSE;
+ }
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]