[nautilus-actions] NAIPivotConsumer: deprecate on_display_order_changed() and on_autosave_changed() methods
- From: Pierre Wieser <pwieser src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus-actions] NAIPivotConsumer: deprecate on_display_order_changed() and on_autosave_changed() methods
- Date: Mon, 31 Jan 2011 21:41:13 +0000 (UTC)
commit 977b04388b6993d1ad7277a93face5d5cd53f78d
Author: Pierre Wieser <pwieser trychlos org>
Date: Fri Jan 28 11:08:26 2011 +0100
NAIPivotConsumer: deprecate on_display_order_changed() and on_autosave_changed() methods
ChangeLog | 10 ++++
src/core/na-settings.c | 2 +
src/nact/nact-main-menubar-file.c | 63 +++++++++++++++++++++----
src/nact/nact-main-menubar-file.h | 5 +-
src/nact/nact-main-window.c | 95 +++++++++++++-----------------------
5 files changed, 102 insertions(+), 73 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 89bb23f..c0247eb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
2011-01-28 Pierre Wieser <pwieser trychlos org>
+ * src/nact/nact-main-window.c:
+ (NAIPivotConsumer->on_display_order_changed):
+ Moved to on_settings_order_mode_changed() function.
+ (NAIPivotConsumer->on_autosave_changed):
+ Moved to nact_main_menubar_file_install_autosave() new function.
+
+ * src/nact/nact-main-menubar-file.c:
+ * src/nact/nact-main-menubar-file.h
+ (nact_main_menubar_file_install_autosave): New function.
+
* src/core/na-iprefs.c:
* src/core/na-iprefs.h (na_iprefs_get_order_mode_by_label):
New function.
diff --git a/src/core/na-settings.c b/src/core/na-settings.c
index 7000f25..1f54f7a 100644
--- a/src/core/na-settings.c
+++ b/src/core/na-settings.c
@@ -1273,6 +1273,8 @@ read_key_value_from_key_file( GKeyFile *key_file, const gchar *group, const gcha
gchar *str;
GError *error;
+ g_debug( "%s: group=%s, key=%s", thisfn, group, key );
+
value = NULL;
error = NULL;
diff --git a/src/nact/nact-main-menubar-file.c b/src/nact/nact-main-menubar-file.c
index 667a0bc..3ae2fdb 100644
--- a/src/nact/nact-main-menubar-file.c
+++ b/src/nact/nact-main-menubar-file.c
@@ -36,6 +36,7 @@
#include <libintl.h>
#include <api/na-core-utils.h>
+#include <api/na-timeout.h>
#include <core/na-io-provider.h>
#include <core/na-iprefs.h>
@@ -46,7 +47,8 @@
#include "nact-main-tab.h"
#include "nact-main-menubar-file.h"
-static guint st_event_autosave = 0;
+static NATimeout st_autosave_prefs_timeout = { 0 };
+static guint st_event_autosave = 0;
static gchar *st_save_error = N_( "Save error" );
static gchar *st_save_warning = N_( "Some items may not have been saved" );
@@ -54,6 +56,8 @@ static gchar *st_level_zero_write = N_( "Unable to rewrite the level-zero items
static gchar *st_delete_error = N_( "Some items cannot have been deleted" );
static gboolean save_item( NactMainWindow *window, NAUpdater *updater, NAObjectItem *item, GSList **messages );
+static void on_autosave_prefs_changed( const gchar *group, const gchar *key, gconstpointer new_value, gpointer user_data );
+static void on_autosave_prefs_timeout( NactMainWindow *window );
static gboolean autosave_callback( NactMainWindow *window );
static void autosave_destroyed( NactMainWindow *window );
@@ -489,17 +493,58 @@ nact_main_menubar_file_on_quit( GtkAction *gtk_action, NactMainWindow *window )
}
/**
- * nact_main_menubar_file_set_autosave:
+ * nact_main_menubar_file_install_autosave:
* @window: the #NactMainWindow main window.
- * @enabled: whether the autosave feature is enabled.
- * @period: autosave periodicity in minutes.
*
- * Setup or disabled the autosave feature.
+ * Setup the autosave feature and initialize its monitoring.
*/
void
-nact_main_menubar_file_set_autosave( NactMainWindow *window, gboolean enabled, guint period )
+nact_main_menubar_file_install_autosave( NactMainWindow *window )
{
- static const gchar *thisfn = "nact_main_menubar_file_set_autosave";
+ NactApplication *application;
+ NAUpdater *updater;
+ NASettings *settings;
+
+ g_return_if_fail( NACT_IS_MAIN_WINDOW( window ));
+
+ st_autosave_prefs_timeout.timeout = 100;
+ st_autosave_prefs_timeout.handler = ( NATimeoutFunc ) on_autosave_prefs_timeout;
+ st_autosave_prefs_timeout.user_data = window;
+
+ application = NACT_APPLICATION( base_window_get_application( BASE_WINDOW( window )));
+ updater = nact_application_get_updater( application );
+ settings = na_pivot_get_settings( NA_PIVOT( updater ));
+
+ na_settings_register_key_callback( settings, NA_IPREFS_MAIN_SAVE_AUTO, G_CALLBACK( on_autosave_prefs_changed ), NULL );
+ na_settings_register_key_callback( settings, NA_IPREFS_MAIN_SAVE_PERIOD, G_CALLBACK( on_autosave_prefs_changed ), NULL );
+
+ on_autosave_prefs_timeout( window );
+}
+
+static void
+on_autosave_prefs_changed( const gchar *group, const gchar *key, gconstpointer new_value, gpointer user_data )
+{
+ na_timeout_event( &st_autosave_prefs_timeout );
+}
+
+static void
+on_autosave_prefs_timeout( NactMainWindow *window )
+{
+ static const gchar *thisfn = "nact_main_menubar_file_on_autosave_prefs_timeout";
+ NactApplication *application;
+ NAUpdater *updater;
+ NASettings *settings;
+ gboolean autosave_on;
+ guint autosave_period;
+
+ g_return_if_fail( NACT_IS_MAIN_WINDOW( window ));
+
+ application = NACT_APPLICATION( base_window_get_application( BASE_WINDOW( window )));
+ updater = nact_application_get_updater( application );
+ settings = na_pivot_get_settings( NA_PIVOT( updater ));
+
+ autosave_on = na_settings_get_boolean( settings, NA_IPREFS_MAIN_SAVE_AUTO, NULL, NULL );
+ autosave_period = na_settings_get_uint( settings, NA_IPREFS_MAIN_SAVE_PERIOD, NULL, NULL );
if( st_event_autosave ){
if( !g_source_remove( st_event_autosave )){
@@ -508,10 +553,10 @@ nact_main_menubar_file_set_autosave( NactMainWindow *window, gboolean enabled, g
st_event_autosave = 0;
}
- if( enabled ){
+ if( autosave_on ){
st_event_autosave = g_timeout_add_seconds_full(
G_PRIORITY_DEFAULT,
- period * 60,
+ autosave_period * 60,
( GSourceFunc ) autosave_callback,
window,
( GDestroyNotify ) autosave_destroyed );
diff --git a/src/nact/nact-main-menubar-file.h b/src/nact/nact-main-menubar-file.h
index 610bc2c..8ac9ada 100644
--- a/src/nact/nact-main-menubar-file.h
+++ b/src/nact/nact-main-menubar-file.h
@@ -51,9 +51,8 @@ void nact_main_menubar_file_on_new_profile( GtkAction *action, NactMainWindow *w
void nact_main_menubar_file_on_save ( GtkAction *action, NactMainWindow *window );
void nact_main_menubar_file_on_quit ( GtkAction *action, NactMainWindow *window );
-void nact_main_menubar_file_save_items ( NactMainWindow *window );
-
-void nact_main_menubar_file_set_autosave( NactMainWindow *window, gboolean enabled, guint period );
+void nact_main_menubar_file_save_items ( NactMainWindow *window );
+void nact_main_menubar_file_install_autosave( NactMainWindow *window );
G_END_DECLS
diff --git a/src/nact/nact-main-window.c b/src/nact/nact-main-window.c
index 69e64b1..3a9b482 100644
--- a/src/nact/nact-main-window.c
+++ b/src/nact/nact-main-window.c
@@ -184,10 +184,8 @@ static void on_tab_updatable_item_updated( NactMainWindow *window, gpointer
static gboolean confirm_for_giveup_from_menu( NactMainWindow *window );
static gboolean confirm_for_giveup_from_pivot( NactMainWindow *window );
-static void install_autosave( NactMainWindow *window );
-static void ipivot_consumer_on_autosave_changed( NAIPivotConsumer *instance, gboolean enabled, guint period );
static void ipivot_consumer_on_items_changed( NAIPivotConsumer *instance, gpointer user_data );
-static void ipivot_consumer_on_display_order_changed( NAIPivotConsumer *instance, gint order_mode );
+static void on_settings_order_mode_changed( const gchar *group, const gchar *key, gconstpointer new_value, gboolean mandatory, NactMainWindow *window );
static void ipivot_consumer_on_io_provider_prefs_changed( NAIPivotConsumer *instance );
static void ipivot_consumer_on_mandatory_prefs_changed( NAIPivotConsumer *instance );
static void update_ui_after_provider_change( NactMainWindow *window );
@@ -605,10 +603,10 @@ ipivot_consumer_iface_init( NAIPivotConsumerInterface *iface )
g_debug( "%s: iface=%p", thisfn, ( void * ) iface );
- iface->on_autosave_changed = ipivot_consumer_on_autosave_changed;
+ iface->on_autosave_changed = NULL;
iface->on_create_root_menu_changed = NULL;
iface->on_display_about_changed = NULL;
- iface->on_display_order_changed = ipivot_consumer_on_display_order_changed;
+ iface->on_display_order_changed = NULL;
iface->on_io_provider_prefs_changed = ipivot_consumer_on_io_provider_prefs_changed;
iface->on_items_changed = ipivot_consumer_on_items_changed;
iface->on_mandatory_prefs_changed = ipivot_consumer_on_mandatory_prefs_changed;
@@ -1131,8 +1129,8 @@ on_base_initialize_base_window( NactMainWindow *window )
static const gchar *thisfn = "nact_main_window_on_base_initialize_base_window";
NactApplication *application;
NAUpdater *updater;
+ NASettings *settings;
GList *tree;
- gint order_mode;
g_return_if_fail( NACT_IS_MAIN_WINDOW( window ));
@@ -1146,6 +1144,8 @@ on_base_initialize_base_window( NactMainWindow *window )
application = NACT_APPLICATION( base_window_get_application( BASE_WINDOW( window )));
updater = nact_application_get_updater( application );
+ settings = na_pivot_get_settings( NA_PIVOT( updater ));
+
tree = na_pivot_get_items( NA_PIVOT( updater ));
g_debug( "%s: pivot_tree=%p", thisfn, ( void * ) tree );
@@ -1162,8 +1162,7 @@ on_base_initialize_base_window( NactMainWindow *window )
nact_main_menubar_runtime_init( window );
- order_mode = na_iprefs_get_order_mode( NA_PIVOT( updater ), NULL );
- ipivot_consumer_on_display_order_changed( NA_IPIVOT_CONSUMER( window ), order_mode );
+ na_settings_register_key_callback( settings, NA_IPREFS_ITEMS_LIST_ORDER_MODE, G_CALLBACK( on_settings_order_mode_changed ), window );
/* fill the IActionsList at last so that all signals are connected
*/
@@ -1177,6 +1176,9 @@ on_base_initialize_base_window( NactMainWindow *window )
base_window_signal_connect( BASE_WINDOW( window ),
G_OBJECT( window ), MAIN_WINDOW_SIGNAL_LEVEL_ZERO_ORDER_CHANGED, G_CALLBACK( on_main_window_level_zero_order_changed ));
+
+ nact_main_menubar_file_install_autosave( window );
+
}
}
@@ -1221,8 +1223,6 @@ on_base_all_widgets_showed( NactMainWindow *window )
nact_iactions_list_all_widgets_showed( NACT_IACTIONS_LIST( window ));
nact_sort_buttons_all_widgets_showed( window );
-
- install_autosave( window );
}
}
@@ -1480,25 +1480,6 @@ confirm_for_giveup_from_pivot( NactMainWindow *window )
return( reload_ok );
}
-static void
-install_autosave( NactMainWindow *window )
-{
- gboolean autosave_on;
- guint autosave_period;
- NactApplication *application;
- NAUpdater *updater;
- NASettings *settings;
-
- application = NACT_APPLICATION( base_window_get_application( BASE_WINDOW( window )));
- updater = nact_application_get_updater( application );
- settings = na_pivot_get_settings( NA_PIVOT( updater ));
-
- autosave_on = na_settings_get_boolean( settings, NA_IPREFS_MAIN_SAVE_AUTO, NULL, NULL );
- autosave_period = na_settings_get_uint( settings, NA_IPREFS_MAIN_SAVE_PERIOD, NULL, NULL );
-
- nact_main_menubar_file_set_autosave( window, autosave_on, autosave_period );
-}
-
/*
* called by NAPivot because this window implements the IIOConsumer
* interface, i.e. it wish to be advertised when the list of actions
@@ -1530,48 +1511,40 @@ ipivot_consumer_on_items_changed( NAIPivotConsumer *instance, gpointer user_data
}
/*
- * called by NAPivot via NAIPivotConsumer whenever the
- * autosave preferences have been modified.
- */
-static void
-ipivot_consumer_on_autosave_changed( NAIPivotConsumer *instance, gboolean enabled, guint period )
-{
- static const gchar *thisfn = "nact_main_window_ipivot_consumer_on_autosave_changed";
-
- g_return_if_fail( NACT_IS_MAIN_WINDOW( instance ));
- g_debug( "%s: instance=%p, enabled=%s, period=%d",
- thisfn, ( void * ) instance, enabled ? "True":"False", period );
-
- nact_main_menubar_file_set_autosave( NACT_MAIN_WINDOW( instance ), enabled, period );
-}
-
-/*
- * called by NAPivot via NAIPivotConsumer whenever the
- * "sort in alphabetical order" preference is modified.
+ * NASettings callback for a change on NA_IPREFS_ITEMS_LIST_ORDER_MODE key
*/
static void
-ipivot_consumer_on_display_order_changed( NAIPivotConsumer *instance, gint order_mode )
+on_settings_order_mode_changed( const gchar *group, const gchar *key, gconstpointer new_value, gboolean mandatory, NactMainWindow *window )
{
- static const gchar *thisfn = "nact_main_window_ipivot_consumer_on_display_order_changed";
+ static const gchar *thisfn = "nact_main_window_on_settings_order_mode_changed";
+ const gchar *order_mode_str;
+ guint order_mode;
NactApplication *application;
NAUpdater *updater;
GList *tree;
- g_return_if_fail( NACT_IS_MAIN_WINDOW( instance ));
- g_debug( "%s: instance=%p, order_mode=%d", thisfn, ( void * ) instance, order_mode );
+ g_return_if_fail( NACT_IS_MAIN_WINDOW( window ));
- nact_iactions_list_display_order_change( NACT_IACTIONS_LIST( instance ), order_mode );
- nact_sort_buttons_display_order_change( NACT_MAIN_WINDOW( instance ), order_mode );
+ if( !window->private->dispose_has_run ){
- application = NACT_APPLICATION( base_window_get_application( BASE_WINDOW( instance )));
- updater = nact_application_get_updater( application );
- tree = na_pivot_get_items( NA_PIVOT( updater ));
+ order_mode_str = ( const gchar * ) new_value;
+ order_mode = na_iprefs_get_order_mode_by_label( order_mode_str );
+
+ g_debug( "%s: group=%s, key=%s, order_mode=%u (%s), mandatory=%s, window=%p (%s)",
+ thisfn, group, key, order_mode, order_mode_str,
+ mandatory ? "True":"False", ( void * ) window, G_OBJECT_TYPE_NAME( window ));
- if( g_list_length( tree )){
- g_signal_emit_by_name(
- NACT_MAIN_WINDOW( instance ),
- MAIN_WINDOW_SIGNAL_LEVEL_ZERO_ORDER_CHANGED,
- GINT_TO_POINTER( TRUE ));
+ nact_iactions_list_display_order_change( NACT_IACTIONS_LIST( window ), order_mode );
+ nact_sort_buttons_display_order_change( window, order_mode );
+
+ application = NACT_APPLICATION( base_window_get_application( BASE_WINDOW( window )));
+ updater = nact_application_get_updater( application );
+ tree = na_pivot_get_items( NA_PIVOT( updater ));
+
+ if( g_list_length( tree )){
+ g_signal_emit_by_name( window,
+ MAIN_WINDOW_SIGNAL_LEVEL_ZERO_ORDER_CHANGED, GINT_TO_POINTER( TRUE ));
+ }
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]