Commit 98bf8d77 authored by Ramiro Estrugo's avatar Ramiro Estrugo

Add functions for hiding the preferences dialog and changing its title.

* libnautilus-extensions/nautilus-global-preferences.c:
(global_preferences_create_dialog),
(global_preferences_close_dialog_callback),
(nautilus_global_preferences_show_dialog),
(nautilus_global_preferences_hide_dialog),
(nautilus_global_preferences_set_dialog_title):
* libnautilus-extensions/nautilus-global-preferences.h:
Add functions for hiding the preferences dialog and changing its
title.  Also, connect a "closed" signal to prevent the dialog from
killing itself since its singleton and lives for the entire life
of the application.

* nautilus-widgets/nautilus-user-level-manager.c:
(nautilus_user_level_manager_get_user_level),
(nautilus_user_level_manager_make_current_gconf_key),
(nautilus_user_level_manager_get_user_level_string):
* nautilus-widgets/nautilus-user-level-manager.h:
Make nautilus_user_level_manager_get_user_level_string () public.

* src/nautilus-window-menus.c: (settings_menu_customize_callback),
(nautilus_window_initialize_menus), (user_level_changed_callback),
(update_user_level_menu_items), (get_customize_user_level_string),
(get_customize_user_level_setttings_menu_string):
Change the customize menu item's label based on the user level.
Make it insensitive for the novice user level.  Close the
preferences dialog when the user level changes to novice.
parent 42cabf1b
2000-06-02 Ramiro Estrugo <ramiro@eazel.com>
* libnautilus-extensions/nautilus-global-preferences.c:
(global_preferences_create_dialog),
(global_preferences_close_dialog_callback),
(nautilus_global_preferences_show_dialog),
(nautilus_global_preferences_hide_dialog),
(nautilus_global_preferences_set_dialog_title):
* libnautilus-extensions/nautilus-global-preferences.h:
Add functions for hiding the preferences dialog and changing its
title. Also, connect a "closed" signal to prevent the dialog from
killing itself since its singleton and lives for the entire life
of the application.
* nautilus-widgets/nautilus-user-level-manager.c:
(nautilus_user_level_manager_get_user_level),
(nautilus_user_level_manager_make_current_gconf_key),
(nautilus_user_level_manager_get_user_level_string):
* nautilus-widgets/nautilus-user-level-manager.h:
Make nautilus_user_level_manager_get_user_level_string () public.
* src/nautilus-window-menus.c: (settings_menu_customize_callback),
(nautilus_window_initialize_menus), (user_level_changed_callback),
(update_user_level_menu_items), (get_customize_user_level_string),
(get_customize_user_level_setttings_menu_string):
Change the customize menu item's label based on the user level.
Make it insensitive for the novice user level. Close the
preferences dialog when the user level changes to novice.
2000-06-02 Ramiro Estrugo <ramiro@eazel.com>
* libnautilus-extensions/nautilus-string.c:
......
......@@ -47,6 +47,8 @@ static char * global_preferences_get_sidebar_panel_key (const c
static gboolean global_preferences_is_sidebar_panel_enabled (NautilusViewIdentifier *panel_identifier,
gpointer ignore);
static GList * global_preferences_get_sidebar_panel_view_identifiers (void);
static gboolean global_preferences_close_dialog_callback (GtkWidget *dialog,
gpointer user_data);
/*
* Private stuff
......@@ -67,6 +69,11 @@ global_preferences_create_dialog (void)
*/
prefs_dialog = nautilus_preferences_dialog_new (GLOBAL_PREFERENCES_DIALOG_TITLE);
gtk_signal_connect (GTK_OBJECT (prefs_dialog),
"close",
GTK_SIGNAL_FUNC (global_preferences_close_dialog_callback),
NULL);
/* Create a preference box */
preference_box = NAUTILUS_PREFERENCES_BOX (nautilus_preferences_dialog_get_prefs_box
(NAUTILUS_PREFERENCES_DIALOG (prefs_dialog)));
......@@ -398,6 +405,15 @@ global_preferences_register_for_ui (void)
(gconstpointer) FALSE);
}
static gboolean
global_preferences_close_dialog_callback (GtkWidget *dialog,
gpointer user_data)
{
nautilus_global_preferences_hide_dialog ();
return TRUE;
}
#define USER_LEVEL_NOVICE 0
#define USER_LEVEL_INTERMEDIATE 1
#define USER_LEVEL_HACKER 2
......@@ -479,6 +495,25 @@ nautilus_global_preferences_show_dialog (void)
gtk_widget_show (global_prefs_dialog);
}
void
nautilus_global_preferences_hide_dialog (void)
{
GtkWidget * global_prefs_dialog = global_preferences_get_dialog ();
gtk_widget_hide (global_prefs_dialog);
}
void
nautilus_global_preferences_set_dialog_title (const char *title)
{
GtkWidget *global_prefs_dialog;
g_return_if_fail (title != NULL);
global_prefs_dialog = global_preferences_get_dialog ();
gtk_window_set_title (GTK_WINDOW (global_prefs_dialog), title);
}
void
nautilus_global_preferences_shutdown (void)
{
......
......@@ -77,6 +77,8 @@ void nautilus_global_preferences_startup (
char **argv);
void nautilus_global_preferences_shutdown (void);
void nautilus_global_preferences_show_dialog (void);
void nautilus_global_preferences_hide_dialog (void);
void nautilus_global_preferences_set_dialog_title (const char *title);
/* Sidebar */
GList *nautilus_global_preferences_get_enabled_sidebar_panel_view_identifiers (void);
......
......@@ -88,7 +88,6 @@ static void user_level_manager_destroy (G
static NautilusUserLevelManager *user_level_manager_new (void);
static void user_level_manager_ensure_global_manager (void);
static void user_level_set_default_if_needed (NautilusUserLevelManager *manager);
char * gconf_get_user_level_string (void);
/* Gconf callbacks */
......@@ -204,19 +203,6 @@ user_level_manager_ensure_global_manager (void)
g_assert (global_manager != NULL);
}
char *
gconf_get_user_level_string (void)
{
NautilusUserLevelManager *manager = nautilus_user_level_manager_get ();
char *user_level_string;
g_assert (manager->gconf_client != NULL);
user_level_string = gconf_client_get_string (manager->gconf_client, USER_LEVEL_KEY, NULL);
return user_level_string;
}
static void
user_level_set_default_if_needed (NautilusUserLevelManager *manager)
{
......@@ -305,7 +291,7 @@ nautilus_user_level_manager_get_user_level (void)
char *user_level_string;
gint index;
user_level_string = gconf_get_user_level_string ();
user_level_string = nautilus_user_level_manager_get_user_level_string ();
/* FIXME: Asserting based on something that's read from GConf
* seems like a bad idea. It means we core dump if
* something's wrong.
......@@ -388,7 +374,7 @@ nautilus_user_level_manager_make_current_gconf_key (const char *preference_name)
g_return_val_if_fail (preference_name != NULL, NULL);
user_level_string = gconf_get_user_level_string ();
user_level_string = nautilus_user_level_manager_get_user_level_string ();
g_assert (user_level_string != NULL);
key = g_strdup_printf ("%s/%s/%s",
......@@ -401,3 +387,15 @@ nautilus_user_level_manager_make_current_gconf_key (const char *preference_name)
return key;
}
char *
nautilus_user_level_manager_get_user_level_string (void)
{
NautilusUserLevelManager *manager = nautilus_user_level_manager_get ();
char *user_level_string;
g_assert (manager->gconf_client != NULL);
user_level_string = gconf_client_get_string (manager->gconf_client, USER_LEVEL_KEY, NULL);
return user_level_string;
}
......@@ -48,6 +48,8 @@ GtkObject *nautilus_user_level_manager_get_gconf_client (v
char *nautilus_user_level_manager_make_current_gconf_key (const char *preference_name);
char *nautilus_user_level_manager_make_gconf_key (const char *preference_name,
int user_level);
char *nautilus_user_level_manager_get_user_level_string (void);
BEGIN_GNOME_DECLS
......
......@@ -47,6 +47,8 @@ static char * global_preferences_get_sidebar_panel_key (const c
static gboolean global_preferences_is_sidebar_panel_enabled (NautilusViewIdentifier *panel_identifier,
gpointer ignore);
static GList * global_preferences_get_sidebar_panel_view_identifiers (void);
static gboolean global_preferences_close_dialog_callback (GtkWidget *dialog,
gpointer user_data);
/*
* Private stuff
......@@ -67,6 +69,11 @@ global_preferences_create_dialog (void)
*/
prefs_dialog = nautilus_preferences_dialog_new (GLOBAL_PREFERENCES_DIALOG_TITLE);
gtk_signal_connect (GTK_OBJECT (prefs_dialog),
"close",
GTK_SIGNAL_FUNC (global_preferences_close_dialog_callback),
NULL);
/* Create a preference box */
preference_box = NAUTILUS_PREFERENCES_BOX (nautilus_preferences_dialog_get_prefs_box
(NAUTILUS_PREFERENCES_DIALOG (prefs_dialog)));
......@@ -398,6 +405,15 @@ global_preferences_register_for_ui (void)
(gconstpointer) FALSE);
}
static gboolean
global_preferences_close_dialog_callback (GtkWidget *dialog,
gpointer user_data)
{
nautilus_global_preferences_hide_dialog ();
return TRUE;
}
#define USER_LEVEL_NOVICE 0
#define USER_LEVEL_INTERMEDIATE 1
#define USER_LEVEL_HACKER 2
......@@ -479,6 +495,25 @@ nautilus_global_preferences_show_dialog (void)
gtk_widget_show (global_prefs_dialog);
}
void
nautilus_global_preferences_hide_dialog (void)
{
GtkWidget * global_prefs_dialog = global_preferences_get_dialog ();
gtk_widget_hide (global_prefs_dialog);
}
void
nautilus_global_preferences_set_dialog_title (const char *title)
{
GtkWidget *global_prefs_dialog;
g_return_if_fail (title != NULL);
global_prefs_dialog = global_preferences_get_dialog ();
gtk_window_set_title (GTK_WINDOW (global_prefs_dialog), title);
}
void
nautilus_global_preferences_shutdown (void)
{
......
......@@ -77,6 +77,8 @@ void nautilus_global_preferences_startup (
char **argv);
void nautilus_global_preferences_shutdown (void);
void nautilus_global_preferences_show_dialog (void);
void nautilus_global_preferences_hide_dialog (void);
void nautilus_global_preferences_set_dialog_title (const char *title);
/* Sidebar */
GList *nautilus_global_preferences_get_enabled_sidebar_panel_view_identifiers (void);
......
......@@ -88,7 +88,6 @@ static void user_level_manager_destroy (G
static NautilusUserLevelManager *user_level_manager_new (void);
static void user_level_manager_ensure_global_manager (void);
static void user_level_set_default_if_needed (NautilusUserLevelManager *manager);
char * gconf_get_user_level_string (void);
/* Gconf callbacks */
......@@ -204,19 +203,6 @@ user_level_manager_ensure_global_manager (void)
g_assert (global_manager != NULL);
}
char *
gconf_get_user_level_string (void)
{
NautilusUserLevelManager *manager = nautilus_user_level_manager_get ();
char *user_level_string;
g_assert (manager->gconf_client != NULL);
user_level_string = gconf_client_get_string (manager->gconf_client, USER_LEVEL_KEY, NULL);
return user_level_string;
}
static void
user_level_set_default_if_needed (NautilusUserLevelManager *manager)
{
......@@ -305,7 +291,7 @@ nautilus_user_level_manager_get_user_level (void)
char *user_level_string;
gint index;
user_level_string = gconf_get_user_level_string ();
user_level_string = nautilus_user_level_manager_get_user_level_string ();
/* FIXME: Asserting based on something that's read from GConf
* seems like a bad idea. It means we core dump if
* something's wrong.
......@@ -388,7 +374,7 @@ nautilus_user_level_manager_make_current_gconf_key (const char *preference_name)
g_return_val_if_fail (preference_name != NULL, NULL);
user_level_string = gconf_get_user_level_string ();
user_level_string = nautilus_user_level_manager_get_user_level_string ();
g_assert (user_level_string != NULL);
key = g_strdup_printf ("%s/%s/%s",
......@@ -401,3 +387,15 @@ nautilus_user_level_manager_make_current_gconf_key (const char *preference_name)
return key;
}
char *
nautilus_user_level_manager_get_user_level_string (void)
{
NautilusUserLevelManager *manager = nautilus_user_level_manager_get ();
char *user_level_string;
g_assert (manager->gconf_client != NULL);
user_level_string = gconf_client_get_string (manager->gconf_client, USER_LEVEL_KEY, NULL);
return user_level_string;
}
......@@ -48,6 +48,8 @@ GtkObject *nautilus_user_level_manager_get_gconf_client (v
char *nautilus_user_level_manager_make_current_gconf_key (const char *preference_name);
char *nautilus_user_level_manager_make_gconf_key (const char *preference_name,
int user_level);
char *nautilus_user_level_manager_get_user_level_string (void);
BEGIN_GNOME_DECLS
......
......@@ -88,7 +88,6 @@ static void user_level_manager_destroy (G
static NautilusUserLevelManager *user_level_manager_new (void);
static void user_level_manager_ensure_global_manager (void);
static void user_level_set_default_if_needed (NautilusUserLevelManager *manager);
char * gconf_get_user_level_string (void);
/* Gconf callbacks */
......@@ -204,19 +203,6 @@ user_level_manager_ensure_global_manager (void)
g_assert (global_manager != NULL);
}
char *
gconf_get_user_level_string (void)
{
NautilusUserLevelManager *manager = nautilus_user_level_manager_get ();
char *user_level_string;
g_assert (manager->gconf_client != NULL);
user_level_string = gconf_client_get_string (manager->gconf_client, USER_LEVEL_KEY, NULL);
return user_level_string;
}
static void
user_level_set_default_if_needed (NautilusUserLevelManager *manager)
{
......@@ -305,7 +291,7 @@ nautilus_user_level_manager_get_user_level (void)
char *user_level_string;
gint index;
user_level_string = gconf_get_user_level_string ();
user_level_string = nautilus_user_level_manager_get_user_level_string ();
/* FIXME: Asserting based on something that's read from GConf
* seems like a bad idea. It means we core dump if
* something's wrong.
......@@ -388,7 +374,7 @@ nautilus_user_level_manager_make_current_gconf_key (const char *preference_name)
g_return_val_if_fail (preference_name != NULL, NULL);
user_level_string = gconf_get_user_level_string ();
user_level_string = nautilus_user_level_manager_get_user_level_string ();
g_assert (user_level_string != NULL);
key = g_strdup_printf ("%s/%s/%s",
......@@ -401,3 +387,15 @@ nautilus_user_level_manager_make_current_gconf_key (const char *preference_name)
return key;
}
char *
nautilus_user_level_manager_get_user_level_string (void)
{
NautilusUserLevelManager *manager = nautilus_user_level_manager_get ();
char *user_level_string;
g_assert (manager->gconf_client != NULL);
user_level_string = gconf_client_get_string (manager->gconf_client, USER_LEVEL_KEY, NULL);
return user_level_string;
}
......@@ -48,6 +48,8 @@ GtkObject *nautilus_user_level_manager_get_gconf_client (v
char *nautilus_user_level_manager_make_current_gconf_key (const char *preference_name);
char *nautilus_user_level_manager_make_gconf_key (const char *preference_name,
int user_level);
char *nautilus_user_level_manager_get_user_level_string (void);
BEGIN_GNOME_DECLS
......
......@@ -60,9 +60,17 @@ static void update_eazel_theme_menu_item (NautilusWindow
static void update_undo_menu_item (NautilusWindow *window);
static void edit_bookmarks (NautilusWindow *window);
/* User level things */
static guint convert_menu_path_to_user_level (const char *path);
static const char * convert_user_level_to_menu_path (guint user_level);
static char * get_customize_user_level_setttings_menu_string (void);
static void update_user_level_menu_items (NautilusWindow *window);
static void user_level_changed_callback (GtkObject *user_level_manager,
gpointer user_data);
static char * get_customize_user_level_string (void);
/* Struct that stores all the info necessary to activate a bookmark. */
typedef struct {
......@@ -307,7 +315,7 @@ settings_menu_customize_callback (BonoboUIHandler *ui_handler,
gpointer user_data,
const char *path)
{
nautilus_property_browser_new();
nautilus_property_browser_new ();
}
static void
......@@ -863,8 +871,8 @@ nautilus_window_initialize_menus (NautilusWindow *window)
bonobo_ui_handler_menu_new_item (ui_handler,
NAUTILUS_MENU_PATH_SETTINGS_USER_LEVEL_CUSTOMIZE,
_("Customize Current User Level..."),
_("Customize Current User Level"),
_("Customize Settings..."),
_("Customize Settings for the Current User Level"),
-1,
BONOBO_UI_HANDLER_PIXMAP_NONE,
NULL,
......@@ -877,11 +885,19 @@ nautilus_window_initialize_menus (NautilusWindow *window)
NAUTILUS_MENU_PATH_AFTER_USER_LEVEL_SEPARATOR,
-1);
/* Update the user level menus to reflect the user level reality */
bonobo_ui_handler_menu_set_radio_state (
ui_handler,
convert_user_level_to_menu_path (nautilus_user_level_manager_get_user_level ()),
TRUE);
// /* Update the user level menus to reflect the user level reality */
// bonobo_ui_handler_menu_set_radio_state (
// ui_handler,
// convert_user_level_to_menu_path (nautilus_user_level_manager_get_user_level ()),
// TRUE);
update_user_level_menu_items (window);
/* Register to find out about user level changes in order to update the customize label */
gtk_signal_connect (GTK_OBJECT (nautilus_user_level_manager_get ()),
"user_level_changed",
user_level_changed_callback,
window);
window->updating_bonobo_radio_menu_item = FALSE;
......@@ -1090,6 +1106,68 @@ update_undo_menu_item (NautilusWindow *window)
}
}
static void
user_level_changed_callback (GtkObject *user_level_manager,
gpointer user_data)
{
g_return_if_fail (user_data != NULL);
g_return_if_fail (NAUTILUS_IS_WINDOW (user_data));
update_user_level_menu_items (NAUTILUS_WINDOW (user_data));
/* Hide the customize dialog for notive user level */
if (nautilus_user_level_manager_get_user_level () == 0) {
nautilus_global_preferences_hide_dialog ();
}
/* Otherwise update its title to reflect the user level */
else {
char *dialog_title;
dialog_title = get_customize_user_level_string ();
g_assert (dialog_title != NULL);
nautilus_global_preferences_set_dialog_title (dialog_title);
}
}
static void
update_user_level_menu_items (NautilusWindow *window)
{
char *customize_string;
int user_level;
g_assert (window != NULL);
g_assert (NAUTILUS_IS_WINDOW (window));
window->updating_bonobo_radio_menu_item = TRUE;
customize_string = get_customize_user_level_setttings_menu_string ();
g_assert (customize_string != NULL);
user_level = nautilus_user_level_manager_get_user_level ();
/* Update the user radio group to reflect reality */
bonobo_ui_handler_menu_set_radio_state (window->uih,
convert_user_level_to_menu_path (user_level),
TRUE);
/* FIXME: We want to hide the customize button for the novice user level.
* It cant find a bonobo ui handler call to hide a menu item, so make it
* insensitive for now.
*/
bonobo_ui_handler_menu_set_sensitivity (window->uih,
NAUTILUS_MENU_PATH_SETTINGS_USER_LEVEL_CUSTOMIZE,
(user_level > 0));
/* Update the "Customize Settings..." item to reflect the user level to customize */
bonobo_ui_handler_menu_set_label (window->uih,
NAUTILUS_MENU_PATH_SETTINGS_USER_LEVEL_CUSTOMIZE,
customize_string);
window->updating_bonobo_radio_menu_item = FALSE;
}
static guint
convert_menu_path_to_user_level (const char *path)
{
......@@ -1131,3 +1209,42 @@ convert_user_level_to_menu_path (guint user_level)
return NAUTILUS_MENU_PATH_SETTINGS_USER_LEVEL_NOVICE;
}
static char *
get_customize_user_level_string (void)
{
char *user_level_string;
char *capitalized_user_level_string;
char *title;
user_level_string = nautilus_user_level_manager_get_user_level_string ();
g_assert (user_level_string != NULL);
capitalized_user_level_string = nautilus_str_capitalize (user_level_string);
g_assert (capitalized_user_level_string != NULL);
g_free (user_level_string);
title = g_strdup_printf ("Customize %s Settings", capitalized_user_level_string);
g_free (capitalized_user_level_string);
return title;
}
static char *
get_customize_user_level_setttings_menu_string (void)
{
char *title;
char *ellipse_suffixed_title;
title = get_customize_user_level_string ();
g_assert (title != NULL);
ellipse_suffixed_title = g_strdup_printf ("%s...", title);
g_free (title);
return ellipse_suffixed_title;
}
......@@ -60,9 +60,17 @@ static void update_eazel_theme_menu_item (NautilusWindow
static void update_undo_menu_item (NautilusWindow *window);
static void edit_bookmarks (NautilusWindow *window);
/* User level things */
static guint convert_menu_path_to_user_level (const char *path);
static const char * convert_user_level_to_menu_path (guint user_level);
static char * get_customize_user_level_setttings_menu_string (void);
static void update_user_level_menu_items (NautilusWindow *window);
static void user_level_changed_callback (GtkObject *user_level_manager,
gpointer user_data);
static char * get_customize_user_level_string (void);
/* Struct that stores all the info necessary to activate a bookmark. */
typedef struct {
......@@ -307,7 +315,7 @@ settings_menu_customize_callback (BonoboUIHandler *ui_handler,
gpointer user_data,
const char *path)
{
nautilus_property_browser_new();
nautilus_property_browser_new ();
}
static void
......@@ -863,8 +871,8 @@ nautilus_window_initialize_menus (NautilusWindow *window)
bonobo_ui_handler_menu_new_item (ui_handler,
NAUTILUS_MENU_PATH_SETTINGS_USER_LEVEL_CUSTOMIZE,
_("Customize Current User Level..."),
_("Customize Current User Level"),
_("Customize Settings..."),
_("Customize Settings for the Current User Level"),
-1,
BONOBO_UI_HANDLER_PIXMAP_NONE,
NULL,
......@@ -877,11 +885,19 @@ nautilus_window_initialize_menus (NautilusWindow *window)
NAUTILUS_MENU_PATH_AFTER_USER_LEVEL_SEPARATOR,
-1);
/* Update the user level menus to reflect the user level reality */
bonobo_ui_handler_menu_set_radio_state (
ui_handler,
convert_user_level_to_menu_path (nautilus_user_level_manager_get_user_level ()),
TRUE);
// /* Update the user level menus to reflect the user level reality */
// bonobo_ui_handler_menu_set_radio_state (
// ui_handler,
// convert_user_level_to_menu_path (nautilus_user_level_manager_get_user_level ()),
// TRUE);
update_user_level_menu_items (window);
/* Register to find out about user level changes in order to update the customize label */
gtk_signal_connect (GTK_OBJECT (nautilus_user_level_manager_get ()),
"user_level_changed",
user_level_changed_callback,
window);
window->updating_bonobo_radio_menu_item = FALSE;
......@@ -1090,6 +1106,68 @@ update_undo_menu_item (NautilusWindow *window)
}
}
static void
user_level_changed_callback (GtkObject *user_level_manager,
gpointer user_data)
{
g_return_if_fail (user_data != NULL);
g_return_if_fail (NAUTILUS_IS_WINDOW (user_data));
update_user_level_menu_items (NAUTILUS_WINDOW (user_data));
/* Hide the customize dialog for notive user level */
if (nautilus_user_level_manager_get_user_level () == 0) {
nautilus_global_preferences_hide_dialog ();
}
/* Otherwise update its title to reflect the user level */
else {
char *dialog_title;
dialog_title = get_customize_user_level_string ();
g_assert (dialog_title != NULL);
nautilus_global_preferences_set_dialog_title (dialog_title);
}
}