From 98d262b594caefd053a2d075e2d8482b2d8a12c8 Mon Sep 17 00:00:00 2001 From: Matthew Barnes Date: Tue, 27 Jan 2009 03:50:19 +0000 Subject: Add action groups to support lockdown, starting with printing. Other categories to follow. Editors still need lockdown support. svn path=/branches/kill-bonobo/; revision=37136 --- shell/e-shell-settings.c | 43 +++++++++++++++++++++++++ shell/e-shell-settings.h | 6 +--- shell/e-shell-window-actions.c | 36 +++++++++++++++++---- shell/e-shell-window-actions.h | 6 ++++ shell/e-shell-window-private.c | 35 ++++++++++++++++++++ shell/e-shell-window-private.h | 4 +++ shell/e-shell.c | 73 ++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 191 insertions(+), 12 deletions(-) (limited to 'shell') diff --git a/shell/e-shell-settings.c b/shell/e-shell-settings.c index b494aa17c8..b529130fd1 100644 --- a/shell/e-shell-settings.c +++ b/shell/e-shell-settings.c @@ -29,6 +29,7 @@ struct _EShellSettingsPrivate { GArray *value_array; + guint debug : 1; }; static GList *instances; @@ -51,6 +52,16 @@ shell_settings_set_property (GObject *object, g_value_copy (value, dest_value); g_object_notify (object, pspec->name); + + if (priv->debug) { + gchar *contents; + + contents = g_strdup_value_contents (value); + g_debug ( + "Setting '%s' set to '%s' (%s)", + pspec->name, contents, G_VALUE_TYPE_NAME (value)); + g_free (contents); + } } static void @@ -106,6 +117,8 @@ shell_settings_init (EShellSettings *shell_settings, GObjectClass *object_class) { GArray *value_array; + GParamSpec **pspecs; + guint ii; instances = g_list_prepend (instances, shell_settings); @@ -114,6 +127,22 @@ shell_settings_init (EShellSettings *shell_settings, shell_settings->priv = E_SHELL_SETTINGS_GET_PRIVATE (shell_settings); shell_settings->priv->value_array = value_array; + + g_object_freeze_notify (G_OBJECT (shell_settings)); + + pspecs = g_object_class_list_properties (object_class, NULL); + for (ii = 0; ii < property_count; ii++) { + GParamSpec *pspec = pspecs[ii]; + GValue *value; + + value = &g_array_index (value_array, GValue, ii); + g_value_init (value, G_PARAM_SPEC_VALUE_TYPE (pspec)); + g_param_value_set_default (pspec, value); + g_object_notify (G_OBJECT (shell_settings), pspec->name); + } + g_free (pspecs); + + g_object_thaw_notify (G_OBJECT (shell_settings)); } GType @@ -226,6 +255,20 @@ e_shell_settings_bind_to_gconf (EShellSettings *shell_settings, G_OBJECT (shell_settings), property_name); } +/** + * e_shell_settings_enable_debug: + * @shell_settings: an #EShellSettings + * + * Print a debug message to standard output when a property value changes. + **/ +void +e_shell_settings_enable_debug (EShellSettings *shell_settings) +{ + g_return_if_fail (E_IS_SHELL_SETTINGS (shell_settings)); + + shell_settings->priv->debug = TRUE; +} + /** * e_shell_settings_get_boolean: * @shell_settings: an #EShellSettings diff --git a/shell/e-shell-settings.h b/shell/e-shell-settings.h index 41d9d94ec5..d983a3291f 100644 --- a/shell/e-shell-settings.h +++ b/shell/e-shell-settings.h @@ -76,6 +76,7 @@ void e_shell_settings_install_property void e_shell_settings_bind_to_gconf (EShellSettings *shell_settings, const gchar *property_name, const gchar *gconf_key); +void e_shell_settings_enable_debug (EShellSettings *shell_settings); /* Getters and setters for common EShellSettings property types. * These are more convenient than g_object_get() / g_object_set(). @@ -97,11 +98,6 @@ gchar * e_shell_settings_get_string (EShellSettings *shell_settings, void e_shell_settings_set_string (EShellSettings *shell_settings, const gchar *property_name, const gchar *v_string); -gpointer e_shell_settings_get_object (EShellSettings *shell_settings, - const gchar *property_name); -void e_shell_settings_set_object (EShellSettings *shell_settings, - const gchar *property_name, - gpointer v_object); G_END_DECLS diff --git a/shell/e-shell-window-actions.c b/shell/e-shell-window-actions.c index 3ab8b8e7dd..f944d88eb6 100644 --- a/shell/e-shell-window-actions.c +++ b/shell/e-shell-window-actions.c @@ -1459,13 +1459,6 @@ static GtkActionEntry shell_entries[] = { N_("Create a new window displaying this view"), G_CALLBACK (action_new_window_cb) }, - { "page-setup", - GTK_STOCK_PAGE_SETUP, - NULL, - NULL, - N_("Change the page settings for your current printer"), - G_CALLBACK (action_page_setup_cb) }, - { "preferences", GTK_STOCK_PREFERENCES, NULL, @@ -1745,6 +1738,16 @@ static GtkRadioActionEntry shell_gal_view_radio_entries[] = { -1 } }; +static GtkActionEntry shell_lockdown_print_setup_entries[] = { + + { "page-setup", + GTK_STOCK_PAGE_SETUP, + NULL, + NULL, + N_("Change the page settings for your current printer"), + G_CALLBACK (action_page_setup_cb) } +}; + static void shell_window_extract_actions (EShellWindow *shell_window, GList **source_list, @@ -1864,6 +1867,25 @@ e_shell_window_actions_init (EShellWindow *shell_window) -1, G_CALLBACK (action_switcher_cb), shell_window); gtk_ui_manager_insert_action_group (ui_manager, action_group, 0); + /* Lockdown Printing Actions */ + action_group = shell_window->priv->lockdown_printing; + gtk_action_group_set_translation_domain (action_group, domain); + gtk_ui_manager_insert_action_group (ui_manager, action_group, 0); + + /* Lockdown Print Setup Actions */ + action_group = shell_window->priv->lockdown_print_setup; + gtk_action_group_set_translation_domain (action_group, domain); + gtk_action_group_add_actions ( + action_group, shell_lockdown_print_setup_entries, + G_N_ELEMENTS (shell_lockdown_print_setup_entries), + shell_window); + gtk_ui_manager_insert_action_group (ui_manager, action_group, 0); + + /* Lockdown Save-to-Disk Actions */ + action_group = shell_window->priv->lockdown_save_to_disk; + gtk_action_group_set_translation_domain (action_group, domain); + gtk_ui_manager_insert_action_group (ui_manager, action_group, 0); + /* Fine tuning. */ g_object_set (ACTION (SEND_RECEIVE), "is-important", TRUE, NULL); diff --git a/shell/e-shell-window-actions.h b/shell/e-shell-window-actions.h index 0914abcbc8..ca7e783a86 100644 --- a/shell/e-shell-window-actions.h +++ b/shell/e-shell-window-actions.h @@ -103,6 +103,12 @@ E_SHELL_WINDOW_ACTION_GROUP ((window), "custom-rules") #define E_SHELL_WINDOW_ACTION_GROUP_GAL_VIEW(window) \ E_SHELL_WINDOW_ACTION_GROUP ((window), "gal-view") +#define E_SHELL_WINDOW_ACTION_GROUP_LOCKDOWN_PRINTING(window) \ + E_SHELL_WINDOW_ACTION_GROUP ((window), "lockdown-printing") +#define E_SHELL_WINDOW_ACTION_GROUP_LOCKDOWN_PRINT_SETUP(window) \ + E_SHELL_WINDOW_ACTION_GROUP ((window), "lockdown-print-setup") +#define E_SHELL_WINDOW_ACTION_GROUP_LOCKDOWN_SAVE_TO_DISK(window) \ + E_SHELL_WINDOW_ACTION_GROUP ((window), "lockdown-save-to-disk") #define E_SHELL_WINDOW_ACTION_GROUP_NEW_ITEM(window) \ E_SHELL_WINDOW_ACTION_GROUP ((window), "new-item") #define E_SHELL_WINDOW_ACTION_GROUP_NEW_SOURCE(window) \ diff --git a/shell/e-shell-window-private.c b/shell/e-shell-window-private.c index a33f7b7852..2c2ebc5564 100644 --- a/shell/e-shell-window-private.c +++ b/shell/e-shell-window-private.c @@ -195,6 +195,12 @@ e_shell_window_private_init (EShellWindow *shell_window) priv->new_source_actions = gtk_action_group_new ("new-source"); priv->custom_rule_actions = gtk_action_group_new ("custom-rules"); priv->switcher_actions = gtk_action_group_new ("switcher"); + priv->lockdown_printing = + gtk_action_group_new ("lockdown-printing"); + priv->lockdown_print_setup = + gtk_action_group_new ("lockdown-print-setup"); + priv->lockdown_save_to_disk = + gtk_action_group_new ("lockdown-save-to-disk"); priv->loaded_views = loaded_views; priv->active_view = "unknown"; priv->signal_handler_ids = signal_handler_ids; @@ -325,15 +331,41 @@ void e_shell_window_private_constructed (EShellWindow *shell_window) { EShellWindowPrivate *priv = shell_window->priv; + EShellSettings *shell_settings; + EShell *shell; GConfBridge *bridge; + GtkActionGroup *action_group; GObject *object; const gchar *key; + shell = e_shell_window_get_shell (shell_window); + shell_settings = e_shell_get_shell_settings (shell); + /* Create the switcher actions before we set the initial * shell view, because the shell view relies on them for * default settings during construction. */ e_shell_window_create_switcher_actions (shell_window); + /* Support lockdown. */ + + action_group = ACTION_GROUP (LOCKDOWN_PRINTING); + + e_binding_new_with_negation ( + G_OBJECT (shell_settings), "disable-printing", + G_OBJECT (action_group), "sensitive"); + + action_group = ACTION_GROUP (LOCKDOWN_PRINT_SETUP); + + e_binding_new_with_negation ( + G_OBJECT (shell_settings), "disable-print-setup", + G_OBJECT (action_group), "sensitive"); + + action_group = ACTION_GROUP (LOCKDOWN_SAVE_TO_DISK); + + e_binding_new_with_negation ( + G_OBJECT (shell_settings), "disable-save-to-disk", + G_OBJECT (action_group), "sensitive"); + /* Bind GObject properties to GConf keys. */ bridge = gconf_bridge_get (); @@ -398,6 +430,9 @@ e_shell_window_private_dispose (EShellWindow *shell_window) DISPOSE (priv->new_source_actions); DISPOSE (priv->custom_rule_actions); DISPOSE (priv->switcher_actions); + DISPOSE (priv->lockdown_printing); + DISPOSE (priv->lockdown_print_setup); + DISPOSE (priv->lockdown_save_to_disk); g_hash_table_remove_all (priv->loaded_views); diff --git a/shell/e-shell-window-private.h b/shell/e-shell-window-private.h index ea69968344..ff8e5afcb2 100644 --- a/shell/e-shell-window-private.h +++ b/shell/e-shell-window-private.h @@ -28,6 +28,7 @@ #include #include +#include #include #include #include @@ -75,6 +76,9 @@ struct _EShellWindowPrivate { GtkActionGroup *new_source_actions; GtkActionGroup *custom_rule_actions; GtkActionGroup *switcher_actions; + GtkActionGroup *lockdown_printing; + GtkActionGroup *lockdown_print_setup; + GtkActionGroup *lockdown_save_to_disk; guint custom_rule_merge_id; guint gal_view_merge_id; diff --git a/shell/e-shell.c b/shell/e-shell.c index f0dcaeb3f1..a2ac783cb8 100644 --- a/shell/e-shell.c +++ b/shell/e-shell.c @@ -72,6 +72,14 @@ enum { LAST_SIGNAL }; +enum { + DEBUG_KEY_SETTINGS = 1 << 0 +}; + +static GDebugKey debug_keys[] = { + { "settings", DEBUG_KEY_SETTINGS } +}; + EShell *default_shell = NULL; static gpointer parent_class; static guint signals[LAST_SIGNAL]; @@ -80,6 +88,19 @@ static guint signals[LAST_SIGNAL]; void e_shell_dbus_initialize (EShell *shell); #endif +static void +shell_parse_debug_string (EShell *shell) +{ + guint flags; + + flags = g_parse_debug_string ( + g_getenv ("EVOLUTION_DEBUG"), + debug_keys, G_N_ELEMENTS (debug_keys)); + + if (flags & DEBUG_KEY_SETTINGS) + e_shell_settings_enable_debug (shell->priv->settings); +} + static gboolean shell_window_delete_event_cb (EShell *shell, EShellWindow *shell_window) @@ -663,6 +684,40 @@ shell_class_init (EShellClass *class) 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); + + /* Install some desktop-wide settings. */ + + e_shell_settings_install_property ( + g_param_spec_boolean ( + "disable-command-line", + NULL, + NULL, + FALSE, + G_PARAM_READWRITE)); + + e_shell_settings_install_property ( + g_param_spec_boolean ( + "disable-printing", + NULL, + NULL, + FALSE, + G_PARAM_READWRITE)); + + e_shell_settings_install_property ( + g_param_spec_boolean ( + "disable-print-setup", + NULL, + NULL, + FALSE, + G_PARAM_READWRITE)); + + e_shell_settings_install_property ( + g_param_spec_boolean ( + "disable-save-to-disk", + NULL, + NULL, + FALSE, + G_PARAM_READWRITE)); } static void @@ -687,9 +742,27 @@ shell_init (EShell *shell) e_file_lock_create (); + shell_parse_debug_string (shell); + g_signal_connect ( shell, "notify::online-mode", G_CALLBACK (shell_notify_online_mode_cb), NULL); + + e_shell_settings_bind_to_gconf ( + shell->priv->settings, "disable-command-line", + "/desktop/gnome/lockdown/disable_command_line"); + + e_shell_settings_bind_to_gconf ( + shell->priv->settings, "disable-printing", + "/desktop/gnome/lockdown/disable_printing"); + + e_shell_settings_bind_to_gconf ( + shell->priv->settings, "disable-print-setup", + "/desktop/gnome/lockdown/disable_print_setup"); + + e_shell_settings_bind_to_gconf ( + shell->priv->settings, "disable-save-to-disk", + "/desktop/gnome/lockdown/disable_save_to_disk"); } GType -- cgit