diff options
17 files changed, 627 insertions, 880 deletions
@@ -1,3 +1,56 @@ +2001-01-29 Ramiro Estrugo <ramiro@eazel.com> + + reviewed by: Arik Devens <arik@eazel.com> + + Bug fixes. + + 5776 - Preferences dialog layout updates incorrectly after + switching user level. + + 5791 - Preference section title are visible even when section is + empty. + + * libnautilus-extensions/nautilus-preferences-box.h: + * libnautilus-extensions/nautilus-preferences-box.c: + (nautilus_preferences_box_initialize_class), + (nautilus_preferences_box_initialize), + (nautilus_preferences_box_destroy), (preferences_box_select_pane), + (preferences_box_category_list_recreate), (pane_info_new), + (pane_info_free), (category_list_select_row_callback), + (nautilus_preferences_box_new), + (nautilus_preferences_box_add_pane), + (nautilus_preferences_box_update): + Lots of cleanup. Fix typos in many class macros and methods. + Comply with the Nautilus style more. Remove unused code. + + Recreate the category list whenever the preference box gets + updated in order to honor user level visibilities. + + * libnautilus-extensions/nautilus-preferences-dialog.h: + * libnautilus-extensions/nautilus-preferences-dialog.c: + (nautilus_preferences_dialog_destroy), + (nautilus_preferences_dialog_get_prefs_box), + (nautilus_preferences_dialog_update), + (user_level_changed_callback): + Fix class macros typos. + + * libnautilus-extensions/nautilus-preferences-group.h: + * libnautilus-extensions/nautilus-preferences-group.c: + (nautilus_preferences_group_get_num_visible_items): + Fix misspelled method. + + * libnautilus-extensions/nautilus-preferences-pane.h: + * libnautilus-extensions/nautilus-preferences-pane.c: + (nautilus_preferences_pane_destroy), + (nautilus_preferences_pane_set_title), + (nautilus_preferences_pane_set_description), + (nautilus_preferences_pane_add_group), + (nautilus_preferences_pane_add_item_to_nth_group), + (nautilus_preferences_pane_update), + (nautilus_preferences_pane_get_num_visible_groups): + Lots of cleanup. Remove unused and crufty code. Made the widget + a lot simpler. + 2001-01-29 Arik Devens <arik@eazel.com> reviewed by: Maciej Stachowiak <mjs@eazel.com> diff --git a/libnautilus-extensions/nautilus-preferences-box.c b/libnautilus-extensions/nautilus-preferences-box.c index 9bec7c679..91039e34a 100644 --- a/libnautilus-extensions/nautilus-preferences-box.c +++ b/libnautilus-extensions/nautilus-preferences-box.c @@ -26,6 +26,7 @@ #include <config.h> #include "nautilus-preferences-box.h" #include "nautilus-gtk-macros.h" +#include "nautilus-string.h" #include <gtk/gtkclist.h> #include <gtk/gtknotebook.h> @@ -36,63 +37,50 @@ enum LAST_SIGNAL }; -static const guint PREFS_BOX_NUM_CATEGORY_COLUMNS = 1; -static const guint PREFS_BOX_CATEGORY_COLUMN = 0; -static const guint PREFS_BOX_SPACING = 4; -static const guint PREFS_SELECTED_PANE_UNKNOWN = -1; -static const guint PREFS_BOX_PANE_LEFT_OFFSET = 10; +static const guint NUM_CATEGORY_COLUMNS = 1; +static const guint CATEGORY_COLUMN = 0; +static const guint SPACING_BETWEEN_CATEGORIES_AND_PANES = 4; +static const guint SELECTED_PANE_UNKNOWN = -1; typedef struct { - gchar *pane_name; - GtkWidget *pane_widget; - gboolean constructed; + char *pane_name; + GtkWidget *pane_widget; } PaneInfo; struct _NautilusPreferencesBoxDetails { - GtkWidget *category_list; - GtkWidget *pane_container; - - GList *panes; - - gint selected_pane; + GtkWidget *category_list; + GtkWidget *pane_notebook; + GList *panes; + int selected_pane; }; -typedef void (*GnomeBoxSignal1) (GtkObject* object, - gint arg1, - gpointer data); - /* NautilusPreferencesBoxClass methods */ -static void nautilus_preferences_box_initialize_class (NautilusPreferencesBoxClass *klass); -static void nautilus_preferences_box_initialize (NautilusPreferencesBox *prefs_box); +static void nautilus_preferences_box_initialize_class (NautilusPreferencesBoxClass *preferences_box_class); +static void nautilus_preferences_box_initialize (NautilusPreferencesBox *preferences_box); /* GtkObjectClass methods */ -static void nautilus_preferences_box_destroy (GtkObject *object); +static void nautilus_preferences_box_destroy (GtkObject *object); /* Misc private stuff */ -static void prefs_box_construct (NautilusPreferencesBox *prefs_box); -static void prefs_box_select_pane (NautilusPreferencesBox *prefs_box, - guint pane_row); - - - +static void preferences_box_category_list_recreate (NautilusPreferencesBox *preferences_box); +static void preferences_box_select_pane (NautilusPreferencesBox *preferences_box, + guint pane_row, + const char *name); /* PaneInfo functions */ -static PaneInfo *pane_info_alloc (const gchar *pane_name); -static void pane_info_free (PaneInfo *info); - - - +static PaneInfo *pane_info_new (const char *pane_name); +static void pane_info_free (PaneInfo *info); /* Category list callbacks */ -static void category_list_select_row (GtkCList *clist, - gint row, - gint column, - GdkEventButton *event, - gpointer user_data); +static void category_list_select_row_callback (GtkCList *clist, + int row, + int column, + GdkEventButton *event, + gpointer user_data); NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusPreferencesBox, nautilus_preferences_box, GTK_TYPE_HBOX) @@ -100,30 +88,21 @@ NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusPreferencesBox, nautilus_preferences_ * NautilusPreferencesBoxClass methods */ static void -nautilus_preferences_box_initialize_class (NautilusPreferencesBoxClass *prefs_box_class) +nautilus_preferences_box_initialize_class (NautilusPreferencesBoxClass *preferences_box_class) { GtkObjectClass *object_class; - GtkWidgetClass *widget_class; - object_class = GTK_OBJECT_CLASS (prefs_box_class); - widget_class = GTK_WIDGET_CLASS (prefs_box_class); - - parent_class = gtk_type_class (gtk_hbox_get_type ()); + object_class = GTK_OBJECT_CLASS (preferences_box_class); /* GtkObjectClass */ object_class->destroy = nautilus_preferences_box_destroy; } static void -nautilus_preferences_box_initialize (NautilusPreferencesBox *prefs_box) +nautilus_preferences_box_initialize (NautilusPreferencesBox *preferences_box) { - prefs_box->details = g_new (NautilusPreferencesBoxDetails, 1); - - prefs_box->details->category_list = NULL; - prefs_box->details->pane_container = NULL; - prefs_box->details->panes = NULL; - - prefs_box->details->selected_pane = PREFS_SELECTED_PANE_UNKNOWN; + preferences_box->details = g_new0 (NautilusPreferencesBoxDetails, 1); + preferences_box->details->selected_pane = SELECTED_PANE_UNKNOWN; } /* @@ -132,139 +111,98 @@ nautilus_preferences_box_initialize (NautilusPreferencesBox *prefs_box) static void nautilus_preferences_box_destroy (GtkObject *object) { - NautilusPreferencesBox * prefs_box; + NautilusPreferencesBox *preferences_box; - g_return_if_fail (object != NULL); - g_return_if_fail (NAUTILUS_IS_PREFS_BOX (object)); + g_return_if_fail (NAUTILUS_IS_PREFERENCES_BOX (object)); - prefs_box = NAUTILUS_PREFERENCES_BOX (object); + preferences_box = NAUTILUS_PREFERENCES_BOX (object); - if (prefs_box->details->panes) - { + if (preferences_box->details->panes) { GList *panes; + + panes = preferences_box->details->panes; - panes = prefs_box->details->panes; - - while (panes) - { + while (panes) { PaneInfo * info = panes->data; - + g_assert (info != NULL); - pane_info_free (info); - panes = panes->next; } - g_list_free (prefs_box->details->panes); + g_list_free (preferences_box->details->panes); } - g_free (prefs_box->details); + g_free (preferences_box->details); - /* Chain */ - if (GTK_OBJECT_CLASS (parent_class)->destroy != NULL) - (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); + /* Chain destroy */ + NAUTILUS_CALL_PARENT_CLASS (GTK_OBJECT_CLASS, destroy, (object)); } /* * Misc private stuff */ static void -prefs_box_construct (NautilusPreferencesBox *prefs_box) +preferences_box_select_pane (NautilusPreferencesBox *preferences_box, + guint pane_row, + const char *pane_name) { - g_assert (prefs_box != NULL); - g_assert (prefs_box->details != NULL); - - g_assert (prefs_box->details->category_list == NULL); - g_assert (prefs_box->details->panes == NULL); - - /* Configure ourselves */ - gtk_box_set_homogeneous (GTK_BOX (prefs_box), FALSE); - - gtk_box_set_spacing (GTK_BOX (prefs_box), PREFS_BOX_SPACING); + GList *pane_node; + PaneInfo *pane_info; + GList *pane_iterator; + + g_return_if_fail (NAUTILUS_IS_PREFERENCES_BOX (preferences_box)); + g_return_if_fail (preferences_box->details != NULL); + g_return_if_fail (preferences_box->details->panes != NULL); + g_return_if_fail (pane_row < g_list_length (preferences_box->details->panes)); + g_return_if_fail (pane_name != NULL); - /* The category list */ - prefs_box->details->category_list = - gtk_clist_new (PREFS_BOX_NUM_CATEGORY_COLUMNS); + pane_node = g_list_nth (preferences_box->details->panes, pane_row); - gtk_signal_connect (GTK_OBJECT (prefs_box->details->category_list), - "select_row", - GTK_SIGNAL_FUNC (category_list_select_row), - (gpointer) prefs_box); + g_return_if_fail (pane_node != NULL); - gtk_clist_set_selection_mode (GTK_CLIST (prefs_box->details->category_list), - GTK_SELECTION_BROWSE); + pane_info = pane_node->data; - gtk_clist_set_column_auto_resize (GTK_CLIST (prefs_box->details->category_list), - PREFS_BOX_CATEGORY_COLUMN, - TRUE); - - gtk_box_pack_start (GTK_BOX (prefs_box), - prefs_box->details->category_list, - FALSE, - TRUE, - 0); + /* Show only the corresponding pane widget */ + pane_iterator = preferences_box->details->panes; - /* The gtk notebook that the panes go into. */ - prefs_box->details->pane_container = gtk_notebook_new (); + while (pane_iterator) { + PaneInfo *info = pane_iterator->data; - gtk_notebook_set_show_tabs (GTK_NOTEBOOK (prefs_box->details->pane_container), FALSE); - gtk_notebook_set_show_border (GTK_NOTEBOOK (prefs_box->details->pane_container), FALSE); - - gtk_box_pack_start (GTK_BOX (prefs_box), - prefs_box->details->pane_container, - TRUE, - TRUE, - 0); - - gtk_widget_show (prefs_box->details->category_list); - gtk_widget_show (prefs_box->details->pane_container); + g_assert (info != NULL); + + if (nautilus_str_is_equal (pane_name, info->pane_name)) { + gtk_widget_show (info->pane_widget); + gtk_notebook_set_page (GTK_NOTEBOOK (preferences_box->details->pane_notebook), + g_list_position (preferences_box->details->panes, pane_iterator)); + } + + pane_iterator = pane_iterator->next; + } } static void -prefs_box_select_pane (NautilusPreferencesBox *prefs_box, - guint pane_row) +preferences_box_category_list_recreate (NautilusPreferencesBox *preferences_box) { - GList *pane_node; - PaneInfo *pane_info; - GList *pane_iterator; - - g_assert (prefs_box != NULL); - g_assert (NAUTILUS_IS_PREFS_BOX (prefs_box)); - g_assert (prefs_box->details != NULL); - g_assert (prefs_box->details->panes != NULL); - - g_assert (pane_row < g_list_length (prefs_box->details->panes)); - - pane_node = g_list_nth (prefs_box->details->panes, pane_row); - - g_assert (pane_node != NULL); - - pane_info = pane_node->data; + GList *iterator; - /* Show only the corresponding pane widget */ - pane_iterator = prefs_box->details->panes; + g_return_if_fail (NAUTILUS_IS_PREFERENCES_BOX (preferences_box)); + g_return_if_fail (GTK_IS_CLIST (preferences_box->details->category_list)); - while (pane_iterator) - { - PaneInfo * info = pane_iterator->data; - - g_assert (info != NULL); + gtk_clist_clear (GTK_CLIST (preferences_box->details->category_list)); - if (pane_info == info) - { - /* Construct pane for first time if needed */ - if (!info->constructed) - { - - info->constructed = TRUE; - } - - gtk_widget_show (info->pane_widget); - gtk_notebook_set_page (GTK_NOTEBOOK (prefs_box->details->pane_container), g_list_position (prefs_box->details->panes, pane_iterator)); + for (iterator = preferences_box->details->panes; iterator != NULL; iterator = iterator->next) { + PaneInfo *info = iterator->data; + + g_assert (NAUTILUS_IS_PREFERENCES_PANE (info->pane_widget)); + + if (nautilus_preferences_pane_get_num_visible_groups + (NAUTILUS_PREFERENCES_PANE (info->pane_widget)) > 0) { + char *text_array[NUM_CATEGORY_COLUMNS]; + + text_array[CATEGORY_COLUMN] = info->pane_name; + gtk_clist_append (GTK_CLIST (preferences_box->details->category_list), text_array); } - - pane_iterator = pane_iterator->next; } } @@ -272,13 +210,13 @@ prefs_box_select_pane (NautilusPreferencesBox *prefs_box, * PaneInfo functions */ static PaneInfo * -pane_info_alloc (const gchar *pane_name) +pane_info_new (const char *pane_name) { PaneInfo * info; g_assert (pane_name != NULL); - info = g_new (PaneInfo, 1); + info = g_new0 (PaneInfo, 1); info->pane_name = g_strdup (pane_name); @@ -289,9 +227,8 @@ static void pane_info_free (PaneInfo *info) { g_assert (info != NULL); - + g_free (info->pane_name); - g_free (info); } @@ -299,78 +236,119 @@ pane_info_free (PaneInfo *info) * Category list callbacks */ static void -category_list_select_row (GtkCList *clist, - gint row, - gint column, - GdkEventButton *event, - gpointer user_data) +category_list_select_row_callback (GtkCList *clist, + int row, + int column, + GdkEventButton *event, + gpointer callback_data) { - NautilusPreferencesBox *prefs_box = (NautilusPreferencesBox *) user_data; + const char *pane_name = NULL; + + g_return_if_fail (NAUTILUS_IS_PREFERENCES_BOX (callback_data)); - g_assert (prefs_box != NULL); - g_assert (NAUTILUS_IS_PREFS_BOX (prefs_box)); + /* The cast here is needed because of the broken gtk_clist api */ + if (gtk_clist_get_text (clist, row, column, (char **) &pane_name) != 1) { + return; + } - prefs_box_select_pane (prefs_box, (guint) row); + g_return_if_fail (pane_name != NULL); + + preferences_box_select_pane (NAUTILUS_PREFERENCES_BOX (callback_data), row, pane_name); } /* * NautilusPreferencesBox public methods */ GtkWidget* -nautilus_preferences_box_new (const gchar *box_title) +nautilus_preferences_box_new (const char *box_title) { - NautilusPreferencesBox *prefs_box; + NautilusPreferencesBox *preferences_box; - prefs_box = NAUTILUS_PREFERENCES_BOX + preferences_box = NAUTILUS_PREFERENCES_BOX (gtk_widget_new (nautilus_preferences_box_get_type (), NULL)); - prefs_box_construct (prefs_box); + /* Configure ourselves */ + gtk_box_set_homogeneous (GTK_BOX (preferences_box), FALSE); + gtk_box_set_spacing (GTK_BOX (preferences_box), SPACING_BETWEEN_CATEGORIES_AND_PANES); + + /* The category list */ + preferences_box->details->category_list = gtk_clist_new (NUM_CATEGORY_COLUMNS); + + gtk_signal_connect (GTK_OBJECT (preferences_box->details->category_list), + "select_row", + GTK_SIGNAL_FUNC (category_list_select_row_callback), + preferences_box); + + gtk_clist_set_selection_mode (GTK_CLIST (preferences_box->details->category_list), + GTK_SELECTION_BROWSE); - return GTK_WIDGET (prefs_box); + gtk_clist_set_column_auto_resize (GTK_CLIST (preferences_box->details->category_list), + CATEGORY_COLUMN, + TRUE); + + gtk_box_pack_start (GTK_BOX (preferences_box), + preferences_box->details->category_list, + FALSE, + TRUE, + 0); + + /* The gtk notebook that the panes go into. */ + preferences_box->details->pane_notebook = gtk_notebook_new (); + + gtk_notebook_set_show_tabs (GTK_NOTEBOOK (preferences_box->details->pane_notebook), FALSE); + gtk_notebook_set_show_border (GTK_NOTEBOOK (preferences_box->details->pane_notebook), FALSE); + + gtk_box_pack_start (GTK_BOX (preferences_box), + preferences_box->details->pane_notebook, + TRUE, + TRUE, + 0); + + gtk_widget_show (preferences_box->details->category_list); + gtk_widget_show (preferences_box->details->pane_notebook); + + return GTK_WIDGET (preferences_box); } GtkWidget * -nautilus_preferences_box_add_pane (NautilusPreferencesBox *prefs_box, - const gchar *pane_title, - const gchar *pane_description) +nautilus_preferences_box_add_pane (NautilusPreferencesBox *preferences_box, + const char *pane_title, + const char *pane_description) { - PaneInfo *info; - gint new_row; - gchar *text[PREFS_BOX_NUM_CATEGORY_COLUMNS]; + PaneInfo *info; - g_return_val_if_fail (prefs_box != NULL, NULL); - g_return_val_if_fail (NAUTILUS_IS_PREFS_BOX (prefs_box), NULL); + g_return_val_if_fail (NAUTILUS_IS_PREFERENCES_BOX (preferences_box), NULL); g_return_val_if_fail (pane_title != NULL, NULL); g_return_val_if_fail (pane_description != NULL, NULL); - info = pane_info_alloc (pane_title); - - prefs_box->details->panes = g_list_append (prefs_box->details->panes, - (gpointer) info); + info = pane_info_new (pane_title); - info->pane_widget = nautilus_preferences_pane_new (pane_title, - pane_description); + preferences_box->details->panes = g_list_append (preferences_box->details->panes, info); - gtk_notebook_append_page (GTK_NOTEBOOK (prefs_box->details->pane_container), info->pane_widget, NULL); - - text[PREFS_BOX_CATEGORY_COLUMN] = (gchar *) pane_title; - - new_row = gtk_clist_append (GTK_CLIST (prefs_box->details->category_list), - text); + info->pane_widget = nautilus_preferences_pane_new (pane_title, pane_description); + + gtk_notebook_append_page (GTK_NOTEBOOK (preferences_box->details->pane_notebook), + info->pane_widget, + NULL); return info->pane_widget; } void -nautilus_preferences_box_update (NautilusPreferencesBox *prefs_box) +nautilus_preferences_box_update (NautilusPreferencesBox *preferences_box) { GList *iterator; - g_return_if_fail (NAUTILUS_IS_PREFS_BOX (prefs_box)); + g_return_if_fail (NAUTILUS_IS_PREFERENCES_BOX (preferences_box)); - for (iterator = prefs_box->details->panes; iterator != NULL; iterator = iterator->next) { + for (iterator = preferences_box->details->panes; iterator != NULL; iterator = iterator->next) { PaneInfo *info = iterator->data; - + + g_assert (NAUTILUS_IS_PREFERENCES_PANE (info->pane_widget)); + nautilus_preferences_pane_update (NAUTILUS_PREFERENCES_PANE (info->pane_widget)); } + + preferences_box_category_list_recreate (preferences_box); + } diff --git a/libnautilus-extensions/nautilus-preferences-box.h b/libnautilus-extensions/nautilus-preferences-box.h index e6d9f9b82..e688f1ee3 100644 --- a/libnautilus-extensions/nautilus-preferences-box.h +++ b/libnautilus-extensions/nautilus-preferences-box.h @@ -31,37 +31,37 @@ BEGIN_GNOME_DECLS -#define NAUTILUS_TYPE_PREFS_BOX (nautilus_preferences_box_get_type ()) -#define NAUTILUS_PREFERENCES_BOX(obj) (GTK_CHECK_CAST ((obj), NAUTILUS_TYPE_PREFS_BOX, NautilusPreferencesBox)) -#define NAUTILUS_PREFERENCES_BOX_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), NAUTILUS_TYPE_PREFS_BOX, NautilusPreferencesBoxClass)) -#define NAUTILUS_IS_PREFS_BOX(obj) (GTK_CHECK_TYPE ((obj), NAUTILUS_TYPE_PREFS_BOX)) -#define NAUTILUS_IS_PREFS_BOX_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), NAUTILUS_TYPE_PREFS_BOX)) +#define NAUTILUS_TYPE_PREFERENCES_BOX (nautilus_preferences_box_get_type ()) +#define NAUTILUS_PREFERENCES_BOX(obj) (GTK_CHECK_CAST ((obj), NAUTILUS_TYPE_PREFERENCES_BOX, NautilusPreferencesBox)) +#define NAUTILUS_PREFERENCES_BOX_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), NAUTILUS_TYPE_PREFERENCES_BOX, NautilusPreferencesBoxClass)) +#define NAUTILUS_IS_PREFERENCES_BOX(obj) (GTK_CHECK_TYPE ((obj), NAUTILUS_TYPE_PREFERENCES_BOX)) +#define NAUTILUS_IS_PREFERENCES_BOX_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), NAUTILUS_TYPE_PREFERENCES_BOX)) -typedef struct _NautilusPreferencesBox NautilusPreferencesBox; +typedef struct _NautilusPreferencesBox NautilusPreferencesBox; typedef struct _NautilusPreferencesBoxClass NautilusPreferencesBoxClass; typedef struct _NautilusPreferencesBoxDetails NautilusPreferencesBoxDetails; struct _NautilusPreferencesBox { /* Super Class */ - GtkHBox hbox; + GtkHBox hbox; /* Private stuff */ - NautilusPreferencesBoxDetails *details; + NautilusPreferencesBoxDetails *details; }; struct _NautilusPreferencesBoxClass { - GtkHBoxClass parent_class; - - void (*activate) (GtkWidget * prefs_box, gint entry_number); + GtkHBoxClass parent_class; + + void (*activate) (GtkWidget *preferences_box, gint entry_number); }; GtkType nautilus_preferences_box_get_type (void); -GtkWidget* nautilus_preferences_box_new (const gchar *box_title); +GtkWidget* nautilus_preferences_box_new (const char *box_title); GtkWidget* nautilus_preferences_box_add_pane (NautilusPreferencesBox *prefs_box, - const gchar *pane_title, - const gchar *pane_description); + const char *pane_title, + const char *pane_description); void nautilus_preferences_box_update (NautilusPreferencesBox *prefs_box); END_GNOME_DECLS diff --git a/libnautilus-extensions/nautilus-preferences-dialog.c b/libnautilus-extensions/nautilus-preferences-dialog.c index 7b1d07345..62b883377 100644 --- a/libnautilus-extensions/nautilus-preferences-dialog.c +++ b/libnautilus-extensions/nautilus-preferences-dialog.c @@ -237,7 +237,7 @@ nautilus_preferences_dialog_destroy(GtkObject* object) NautilusPreferencesDialog * prefs_dialog; g_return_if_fail (object != NULL); - g_return_if_fail (NAUTILUS_IS_PREFS_DIALOG (object)); + g_return_if_fail (NAUTILUS_IS_PREFERENCES_DIALOG (object)); prefs_dialog = NAUTILUS_PREFERENCES_DIALOG(object); @@ -254,7 +254,7 @@ GtkWidget* nautilus_preferences_dialog_get_prefs_box (NautilusPreferencesDialog *prefs_dialog) { g_return_val_if_fail (prefs_dialog != NULL, NULL); - g_return_val_if_fail (NAUTILUS_IS_PREFS_DIALOG (prefs_dialog), NULL); + g_return_val_if_fail (NAUTILUS_IS_PREFERENCES_DIALOG (prefs_dialog), NULL); return prefs_dialog->details->prefs_box; } @@ -262,7 +262,7 @@ nautilus_preferences_dialog_get_prefs_box (NautilusPreferencesDialog *prefs_dial void nautilus_preferences_dialog_update (NautilusPreferencesDialog *preferences_dialog) { - g_return_if_fail (NAUTILUS_IS_PREFS_DIALOG (preferences_dialog)); + g_return_if_fail (NAUTILUS_IS_PREFERENCES_DIALOG (preferences_dialog)); nautilus_preferences_box_update (NAUTILUS_PREFERENCES_BOX (preferences_dialog->details->prefs_box)); } @@ -270,7 +270,7 @@ nautilus_preferences_dialog_update (NautilusPreferencesDialog *preferences_dialo static void user_level_changed_callback (gpointer callback_data) { - g_return_if_fail (NAUTILUS_IS_PREFS_DIALOG (callback_data)); + g_return_if_fail (NAUTILUS_IS_PREFERENCES_DIALOG (callback_data)); nautilus_preferences_dialog_update (NAUTILUS_PREFERENCES_DIALOG (callback_data)); } diff --git a/libnautilus-extensions/nautilus-preferences-dialog.h b/libnautilus-extensions/nautilus-preferences-dialog.h index acf5701a2..95158a1e3 100644 --- a/libnautilus-extensions/nautilus-preferences-dialog.h +++ b/libnautilus-extensions/nautilus-preferences-dialog.h @@ -30,11 +30,11 @@ BEGIN_GNOME_DECLS -#define NAUTILUS_TYPE_PREFS_DIALOG (nautilus_preferences_dialog_get_type ()) -#define NAUTILUS_PREFERENCES_DIALOG(obj) (GTK_CHECK_CAST ((obj), NAUTILUS_TYPE_PREFS_DIALOG, NautilusPreferencesDialog)) -#define NAUTILUS_PREFERENCES_DIALOG_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), NAUTILUS_TYPE_PREFS_DIALOG, NautilusPreferencesDialogClass)) -#define NAUTILUS_IS_PREFS_DIALOG(obj) (GTK_CHECK_TYPE ((obj), NAUTILUS_TYPE_PREFS_DIALOG)) -#define NAUTILUS_IS_PREFS_DIALOG_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), NAUTILUS_TYPE_PREFS_DIALOG)) +#define NAUTILUS_TYPE_PREFERENCES_DIALOG (nautilus_preferences_dialog_get_type ()) +#define NAUTILUS_PREFERENCES_DIALOG(obj) (GTK_CHECK_CAST ((obj), NAUTILUS_TYPE_PREFERENCES_DIALOG, NautilusPreferencesDialog)) +#define NAUTILUS_PREFERENCES_DIALOG_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), NAUTILUS_TYPE_PREFERENCES_DIALOG, NautilusPreferencesDialogClass)) +#define NAUTILUS_IS_PREFERENCES_DIALOG(obj) (GTK_CHECK_TYPE ((obj), NAUTILUS_TYPE_PREFERENCES_DIALOG)) +#define NAUTILUS_IS_PREFERENCES_DIALOG_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), NAUTILUS_TYPE_PREFERENCES_DIALOG)) typedef struct _NautilusPreferencesDialog NautilusPreferencesDialog; diff --git a/libnautilus-extensions/nautilus-preferences-group.c b/libnautilus-extensions/nautilus-preferences-group.c index 24bfb9e08..55ba8cb4d 100644 --- a/libnautilus-extensions/nautilus-preferences-group.c +++ b/libnautilus-extensions/nautilus-preferences-group.c @@ -250,7 +250,7 @@ nautilus_preferences_group_update (NautilusPreferencesGroup *group) } guint -nautilus_preferences_get_num_visible_items (const NautilusPreferencesGroup *group) +nautilus_preferences_group_get_num_visible_items (const NautilusPreferencesGroup *group) { guint n = 0; GList *iterator; diff --git a/libnautilus-extensions/nautilus-preferences-group.h b/libnautilus-extensions/nautilus-preferences-group.h index ec9e8ea52..1e0a3fc2a 100644 --- a/libnautilus-extensions/nautilus-preferences-group.h +++ b/libnautilus-extensions/nautilus-preferences-group.h @@ -56,13 +56,13 @@ struct _NautilusPreferencesGroupClass GtkFrameClass parent_class; }; -GtkType nautilus_preferences_group_get_type (void); -GtkWidget* nautilus_preferences_group_new (const gchar *title); -GtkWidget* nautilus_preferences_group_add_item (NautilusPreferencesGroup *group, - const char *preference_name, - NautilusPreferencesItemType item_type); -void nautilus_preferences_group_update (NautilusPreferencesGroup *group); -guint nautilus_preferences_get_num_visible_items (const NautilusPreferencesGroup *group); +GtkType nautilus_preferences_group_get_type (void); +GtkWidget* nautilus_preferences_group_new (const gchar *title); +GtkWidget* nautilus_preferences_group_add_item (NautilusPreferencesGroup *group, + const char *preference_name, + NautilusPreferencesItemType item_type); +void nautilus_preferences_group_update (NautilusPreferencesGroup *group); +guint nautilus_preferences_group_get_num_visible_items (const NautilusPreferencesGroup *group); END_GNOME_DECLS diff --git a/libnautilus-extensions/nautilus-preferences-pane.c b/libnautilus-extensions/nautilus-preferences-pane.c index 7c66c1219..34b561e4a 100644 --- a/libnautilus-extensions/nautilus-preferences-pane.c +++ b/libnautilus-extensions/nautilus-preferences-pane.c @@ -27,50 +27,23 @@ #include "nautilus-preferences-pane.h" #include "nautilus-gtk-macros.h" -#include <gtk/gtklabel.h> -#include <gtk/gtkframe.h> #include <gtk/gtkhbox.h> -#include <gnome.h> - -enum -{ - ACTIVATE, - LAST_SIGNAL -}; - -static const guint PREFS_PANE_GROUPS_BOX_TOP_OFFSET = 0; -static const guint PREFS_PANE_IN_BETWEEN_OFFSET = 4; +static const guint GROUPS_BOX_TOP_OFFSET = 0; +static const guint IN_BETWEEN_OFFSET = 4; struct _NautilusPreferencesPaneDetails { - GtkWidget *title_box; - GtkWidget *title_frame; - GtkWidget *title_label; - GtkWidget *description_label; - - GtkWidget *groups_box; - - gboolean show_title; - - GList *groups; + GtkWidget *groups_box; + GList *groups; }; -typedef void (*GnomeBoxSignal1) (GtkObject* object, - gint arg1, - gpointer data); - /* NautilusPreferencesPaneClass methods */ -static void nautilus_preferences_pane_initialize_class (NautilusPreferencesPaneClass *klass); -static void nautilus_preferences_pane_initialize (NautilusPreferencesPane *prefs_pane); +static void nautilus_preferences_pane_initialize_class (NautilusPreferencesPaneClass *preferences_pane_class); +static void nautilus_preferences_pane_initialize (NautilusPreferencesPane *preferences_pane); /* GtkObjectClass methods */ -static void nautilus_preferences_pane_destroy (GtkObject *object); - -/* Private stuff */ -static void prefs_pane_construct (NautilusPreferencesPane *prefs_pane, - const gchar *pane_title, - const gchar *pane_description); +static void nautilus_preferences_pane_destroy (GtkObject *object); NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusPreferencesPane, nautilus_preferences_pane, GTK_TYPE_VBOX) @@ -78,206 +51,92 @@ NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusPreferencesPane, nautilus_preferences * NautilusPreferencesPaneClass methods */ static void -nautilus_preferences_pane_initialize_class (NautilusPreferencesPaneClass *prefs_pane_class) +nautilus_preferences_pane_initialize_class (NautilusPreferencesPaneClass *preferences_pane_class) { GtkObjectClass *object_class; - GtkWidgetClass *widget_class; - object_class = GTK_OBJECT_CLASS (prefs_pane_class); - widget_class = GTK_WIDGET_CLASS (prefs_pane_class); - - parent_class = gtk_type_class (gtk_vbox_get_type ()); - + object_class = GTK_OBJECT_CLASS (preferences_pane_class); + /* GtkObjectClass */ object_class->destroy = nautilus_preferences_pane_destroy; } static void -nautilus_preferences_pane_initialize (NautilusPreferencesPane *prefs_pane) +nautilus_preferences_pane_initialize (NautilusPreferencesPane *preferences_pane) { - prefs_pane->details = g_new (NautilusPreferencesPaneDetails, 1); - - prefs_pane->details->title_label = NULL; - prefs_pane->details->description_label = NULL; - prefs_pane->details->title_box = NULL; - prefs_pane->details->title_frame = NULL; - prefs_pane->details->groups_box = NULL; - prefs_pane->details->groups = NULL; - prefs_pane->details->show_title = FALSE; + preferences_pane->details = g_new0 (NautilusPreferencesPaneDetails, 1); } /* * GtkObjectClass methods */ static void -nautilus_preferences_pane_destroy(GtkObject* object) +nautilus_preferences_pane_destroy (GtkObject* object) { - NautilusPreferencesPane * prefs_pane; + NautilusPreferencesPane *preferences_pane; - g_return_if_fail (object != NULL); - g_return_if_fail (NAUTILUS_IS_PREFS_PANE (object)); + g_return_if_fail (NAUTILUS_IS_PREFERENCES_PANE (object)); - prefs_pane = NAUTILUS_PREFERENCES_PANE (object); - - if (prefs_pane->details->groups) - { - g_list_free (prefs_pane->details->groups); - } + preferences_pane = NAUTILUS_PREFERENCES_PANE (object); - g_free (prefs_pane->details); + g_list_free (preferences_pane->details->groups); + g_free (preferences_pane->details); /* Chain destroy */ NAUTILUS_CALL_PARENT_CLASS (GTK_OBJECT_CLASS, destroy, (object)); } /* - * Private stuff - */ -static void -prefs_pane_construct (NautilusPreferencesPane *prefs_pane, - const gchar *pane_title, - const gchar *pane_description) -{ - g_assert (prefs_pane != NULL); - g_assert (prefs_pane->details != NULL); - - g_assert (pane_title != NULL); - g_assert (pane_description != NULL); - - g_assert (prefs_pane->details->title_label == NULL); - g_assert (prefs_pane->details->description_label == NULL); - g_assert (prefs_pane->details->title_box == NULL); - g_assert (prefs_pane->details->groups_box == NULL); - g_assert (prefs_pane->details->title_frame == NULL); - g_assert (prefs_pane->details->groups == NULL); - - if (prefs_pane->details->show_title) - { - /* Title frame */ - prefs_pane->details->title_frame = gtk_frame_new (NULL); - - gtk_frame_set_shadow_type (GTK_FRAME (prefs_pane->details->title_frame), - GTK_SHADOW_ETCHED_IN); - - /* Title box */ - prefs_pane->details->title_box = gtk_hbox_new (FALSE, 0); - - /* Title labels */ - prefs_pane->details->title_label = gtk_label_new (pane_title); - prefs_pane->details->description_label = gtk_label_new (pane_description); - - gtk_box_pack_start (GTK_BOX (prefs_pane->details->title_box), - prefs_pane->details->title_label, - FALSE, - FALSE, - 0); - - gtk_box_pack_end (GTK_BOX (prefs_pane->details->title_box), - prefs_pane->details->description_label, - FALSE, - FALSE, - 0); - - gtk_widget_show (prefs_pane->details->title_label); - gtk_widget_show (prefs_pane->details->description_label); - - /* Add title box to title frame */ - gtk_container_add (GTK_CONTAINER (prefs_pane->details->title_frame), - prefs_pane->details->title_box); - - gtk_widget_show (prefs_pane->details->title_box); - - /* Add title frame to ourselves */ - gtk_box_pack_start (GTK_BOX (prefs_pane), - prefs_pane->details->title_frame, - TRUE, - TRUE, - 0); - - gtk_widget_show (prefs_pane->details->title_frame); - } - - /* Groups box */ - prefs_pane->details->groups_box = gtk_vbox_new (FALSE, 0); - - /* Add groups box to ourselves */ - gtk_box_pack_start (GTK_BOX (prefs_pane), - prefs_pane->details->groups_box, - FALSE, - FALSE, - PREFS_PANE_GROUPS_BOX_TOP_OFFSET); - - gtk_widget_show (prefs_pane->details->groups_box); - gtk_widget_show (GTK_WIDGET (prefs_pane)); -} - - -/* * NautilusPreferencesPane public methods */ GtkWidget * nautilus_preferences_pane_new (const gchar *pane_title, const gchar *pane_description) { - NautilusPreferencesPane *prefs_pane; + NautilusPreferencesPane *preferences_pane; g_return_val_if_fail (pane_title != NULL, NULL); g_return_val_if_fail (pane_description != NULL, NULL); - prefs_pane = NAUTILUS_PREFERENCES_PANE + preferences_pane = NAUTILUS_PREFERENCES_PANE (gtk_widget_new (nautilus_preferences_pane_get_type (), NULL)); - prefs_pane_construct (prefs_pane, pane_title, pane_description); - - return GTK_WIDGET (prefs_pane); -} - -void -nautilus_preferences_pane_set_title (NautilusPreferencesPane *prefs_pane, - const gchar *pane_title) -{ - g_return_if_fail (prefs_pane != NULL); - g_return_if_fail (NAUTILUS_IS_PREFS_PANE (prefs_pane)); - - g_assert (prefs_pane->details->title_label != NULL); - - gtk_label_set_text (GTK_LABEL (prefs_pane->details->title_label), - pane_title); -} + /* Groups box */ + preferences_pane->details->groups_box = gtk_vbox_new (FALSE, 0); -void -nautilus_preferences_pane_set_description (NautilusPreferencesPane *prefs_pane, - const gchar *pane_description) -{ - g_return_if_fail (prefs_pane != NULL); - g_return_if_fail (NAUTILUS_IS_PREFS_PANE (prefs_pane)); + /* Add groups box to ourselves */ + gtk_box_pack_start (GTK_BOX (preferences_pane), + preferences_pane->details->groups_box, + FALSE, + FALSE, + GROUPS_BOX_TOP_OFFSET); - g_assert (prefs_pane->details->description_label != NULL); + gtk_widget_show (preferences_pane->details->groups_box); + gtk_widget_show (GTK_WIDGET (preferences_pane)); - gtk_label_set_text (GTK_LABEL (prefs_pane->details->description_label), - pane_description); + return GTK_WIDGET (preferences_pane); } GtkWidget * -nautilus_preferences_pane_add_group (NautilusPreferencesPane *prefs_pane, +nautilus_preferences_pane_add_group (NautilusPreferencesPane *preferences_pane, const char *group_title) { GtkWidget *group; - g_return_val_if_fail (prefs_pane != NULL, NULL); - g_return_val_if_fail (NAUTILUS_IS_PREFS_PANE (prefs_pane), NULL); + g_return_val_if_fail (preferences_pane != NULL, NULL); + g_return_val_if_fail (NAUTILUS_IS_PREFERENCES_PANE (preferences_pane), NULL); g_return_val_if_fail (group_title != NULL, NULL); group = nautilus_preferences_group_new (group_title); - prefs_pane->details->groups = g_list_append (prefs_pane->details->groups, + preferences_pane->details->groups = g_list_append (preferences_pane->details->groups, (gpointer) group); - gtk_box_pack_start (GTK_BOX (prefs_pane->details->groups_box), + gtk_box_pack_start (GTK_BOX (preferences_pane->details->groups_box), group, TRUE, TRUE, - PREFS_PANE_IN_BETWEEN_OFFSET); + IN_BETWEEN_OFFSET); gtk_widget_show (group); @@ -285,7 +144,7 @@ nautilus_preferences_pane_add_group (NautilusPreferencesPane *prefs_pane, } GtkWidget * -nautilus_preferences_pane_add_item_to_nth_group (NautilusPreferencesPane *prefs_pane, +nautilus_preferences_pane_add_item_to_nth_group (NautilusPreferencesPane *preferences_pane, guint n, const char *preference_name, NautilusPreferencesItemType item_type) @@ -293,53 +152,68 @@ nautilus_preferences_pane_add_item_to_nth_group (NautilusPreferencesPane *prefs_ GtkWidget *item; GtkWidget *group; - g_return_val_if_fail (prefs_pane != NULL, NULL); - g_return_val_if_fail (NAUTILUS_IS_PREFS_PANE (prefs_pane), NULL); + g_return_val_if_fail (preferences_pane != NULL, NULL); + g_return_val_if_fail (NAUTILUS_IS_PREFERENCES_PANE (preferences_pane), NULL); g_return_val_if_fail (preference_name != NULL, NULL); - if (!prefs_pane->details->groups) { + if (!preferences_pane->details->groups) { g_warning ("nautilus_preferences_pane_add_item_to_nth_group () There are no groups!"); - return NULL; } - if (n >= g_list_length (prefs_pane->details->groups)) { + if (n >= g_list_length (preferences_pane->details->groups)) { g_warning ("nautilus_preferences_pane_add_item_to_nth_group (n = %d) n is out of bounds!", n); - return NULL; } - g_assert (g_list_nth_data (prefs_pane->details->groups, n) != NULL); - g_assert (GTK_IS_WIDGET (g_list_nth_data (prefs_pane->details->groups, n))); + g_return_val_if_fail (g_list_nth_data (preferences_pane->details->groups, n) != NULL, NULL); + g_return_val_if_fail (GTK_IS_WIDGET (g_list_nth_data (preferences_pane->details->groups, n)), NULL); - group = GTK_WIDGET (g_list_nth_data (prefs_pane->details->groups, n)); + group = GTK_WIDGET (g_list_nth_data (preferences_pane->details->groups, n)); item = nautilus_preferences_group_add_item (NAUTILUS_PREFERENCES_GROUP (group), preference_name, item_type); - g_assert (item != NULL); - return item; } void -nautilus_preferences_pane_update (NautilusPreferencesPane *prefs_pane) +nautilus_preferences_pane_update (NautilusPreferencesPane *preferences_pane) { GList *iterator; - g_return_if_fail (NAUTILUS_IS_PREFS_PANE (prefs_pane)); + g_return_if_fail (NAUTILUS_IS_PREFERENCES_PANE (preferences_pane)); - for (iterator = prefs_pane->details->groups; iterator != NULL; iterator = iterator->next) { + for (iterator = preferences_pane->details->groups; iterator != NULL; iterator = iterator->next) { NautilusPreferencesGroup *group = NAUTILUS_PREFERENCES_GROUP (iterator->data); nautilus_preferences_group_update (group); - if (nautilus_preferences_get_num_visible_items (group) == 0) { + if (nautilus_preferences_group_get_num_visible_items (group) == 0) { gtk_widget_hide (GTK_WIDGET (group)); } else { gtk_widget_show (GTK_WIDGET (group)); } } } + +guint +nautilus_preferences_pane_get_num_visible_groups (const NautilusPreferencesPane *pane) +{ + guint n = 0; + GList *iterator; + + g_return_val_if_fail (NAUTILUS_IS_PREFERENCES_PANE (pane), 0); + + for (iterator = pane->details->groups; iterator != NULL; iterator = iterator->next) { + NautilusPreferencesGroup *group = NAUTILUS_PREFERENCES_GROUP (iterator->data); + + if (GTK_WIDGET_VISIBLE (group)) { + n++; + } + } + + return n; +} diff --git a/libnautilus-extensions/nautilus-preferences-pane.h b/libnautilus-extensions/nautilus-preferences-pane.h index 32bae4c47..c1071a470 100644 --- a/libnautilus-extensions/nautilus-preferences-pane.h +++ b/libnautilus-extensions/nautilus-preferences-pane.h @@ -31,11 +31,11 @@ BEGIN_GNOME_DECLS -#define NAUTILUS_TYPE_PREFS_PANE (nautilus_preferences_pane_get_type ()) -#define NAUTILUS_PREFERENCES_PANE(obj) (GTK_CHECK_CAST ((obj), NAUTILUS_TYPE_PREFS_PANE, NautilusPreferencesPane)) -#define NAUTILUS_PREFERENCES_PANE_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), NAUTILUS_TYPE_PREFS_PANE, NautilusPreferencesPaneClass)) -#define NAUTILUS_IS_PREFS_PANE(obj) (GTK_CHECK_TYPE ((obj), NAUTILUS_TYPE_PREFS_PANE)) -#define NAUTILUS_IS_PREFS_PANE_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), NAUTILUS_TYPE_PREFS_PANE)) +#define NAUTILUS_TYPE_PREFERENCES_PANE (nautilus_preferences_pane_get_type ()) +#define NAUTILUS_PREFERENCES_PANE(obj) (GTK_CHECK_CAST ((obj), NAUTILUS_TYPE_PREFERENCES_PANE, NautilusPreferencesPane)) +#define NAUTILUS_PREFERENCES_PANE_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), NAUTILUS_TYPE_PREFERENCES_PANE, NautilusPreferencesPaneClass)) +#define NAUTILUS_IS_PREFERENCES_PANE(obj) (GTK_CHECK_TYPE ((obj), NAUTILUS_TYPE_PREFERENCES_PANE)) +#define NAUTILUS_IS_PREFERENCES_PANE_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), NAUTILUS_TYPE_PREFERENCES_PANE)) typedef struct _NautilusPreferencesPane NautilusPreferencesPane; typedef struct _NautilusPreferencesPaneClass NautilusPreferencesPaneClass; @@ -44,33 +44,28 @@ typedef struct _NautilusPreferencesPaneDetails NautilusPreferencesPaneDetails struct _NautilusPreferencesPane { /* Super Class */ - GtkVBox vbox; + GtkVBox vbox; /* Private stuff */ - NautilusPreferencesPaneDetails *details; + NautilusPreferencesPaneDetails *details; }; struct _NautilusPreferencesPaneClass { - GtkVBoxClass parent_class; - - void (*construct) (NautilusPreferencesPane *prefs_pane, GtkWidget *box); + GtkVBoxClass parent_class; }; -GtkType nautilus_preferences_pane_get_type (void); -GtkWidget* nautilus_preferences_pane_new (const gchar *pane_title, - const gchar *pane_description); -void nautilus_preferences_pane_set_title (NautilusPreferencesPane *prefs_pane, - const gchar *pane_title); -void nautilus_preferences_pane_set_description (NautilusPreferencesPane *prefs_pane, - const gchar *pane_description); -GtkWidget *nautilus_preferences_pane_add_group (NautilusPreferencesPane *prefs_pane, - const char *group_title); -GtkWidget *nautilus_preferences_pane_add_item_to_nth_group (NautilusPreferencesPane *prefs_pane, - guint n, - const char *preference_name, - NautilusPreferencesItemType item_type); -void nautilus_preferences_pane_update (NautilusPreferencesPane *prefs_pane); +GtkType nautilus_preferences_pane_get_type (void); +GtkWidget* nautilus_preferences_pane_new (const gchar *pane_title, + const gchar *pane_description); +GtkWidget *nautilus_preferences_pane_add_group (NautilusPreferencesPane *preferences_pane, + const char *group_title); +GtkWidget *nautilus_preferences_pane_add_item_to_nth_group (NautilusPreferencesPane *preferences_pane, + guint n, + const char *preference_name, + NautilusPreferencesItemType item_type); +void nautilus_preferences_pane_update (NautilusPreferencesPane *preferences_pane); +guint nautilus_preferences_pane_get_num_visible_groups (const NautilusPreferencesPane *pane); END_GNOME_DECLS diff --git a/libnautilus-private/nautilus-preferences-box.c b/libnautilus-private/nautilus-preferences-box.c index 9bec7c679..91039e34a 100644 --- a/libnautilus-private/nautilus-preferences-box.c +++ b/libnautilus-private/nautilus-preferences-box.c @@ -26,6 +26,7 @@ #include <config.h> #include "nautilus-preferences-box.h" #include "nautilus-gtk-macros.h" +#include "nautilus-string.h" #include <gtk/gtkclist.h> #include <gtk/gtknotebook.h> @@ -36,63 +37,50 @@ enum LAST_SIGNAL }; -static const guint PREFS_BOX_NUM_CATEGORY_COLUMNS = 1; -static const guint PREFS_BOX_CATEGORY_COLUMN = 0; -static const guint PREFS_BOX_SPACING = 4; -static const guint PREFS_SELECTED_PANE_UNKNOWN = -1; -static const guint PREFS_BOX_PANE_LEFT_OFFSET = 10; +static const guint NUM_CATEGORY_COLUMNS = 1; +static const guint CATEGORY_COLUMN = 0; +static const guint SPACING_BETWEEN_CATEGORIES_AND_PANES = 4; +static const guint SELECTED_PANE_UNKNOWN = -1; typedef struct { - gchar *pane_name; - GtkWidget *pane_widget; - gboolean constructed; + char *pane_name; + GtkWidget *pane_widget; } PaneInfo; struct _NautilusPreferencesBoxDetails { - GtkWidget *category_list; - GtkWidget *pane_container; - - GList *panes; - - gint selected_pane; + GtkWidget *category_list; + GtkWidget *pane_notebook; + GList *panes; + int selected_pane; }; -typedef void (*GnomeBoxSignal1) (GtkObject* object, - gint arg1, - gpointer data); - /* NautilusPreferencesBoxClass methods */ -static void nautilus_preferences_box_initialize_class (NautilusPreferencesBoxClass *klass); -static void nautilus_preferences_box_initialize (NautilusPreferencesBox *prefs_box); +static void nautilus_preferences_box_initialize_class (NautilusPreferencesBoxClass *preferences_box_class); +static void nautilus_preferences_box_initialize (NautilusPreferencesBox *preferences_box); /* GtkObjectClass methods */ -static void nautilus_preferences_box_destroy (GtkObject *object); +static void nautilus_preferences_box_destroy (GtkObject *object); /* Misc private stuff */ -static void prefs_box_construct (NautilusPreferencesBox *prefs_box); -static void prefs_box_select_pane (NautilusPreferencesBox *prefs_box, - guint pane_row); - - - +static void preferences_box_category_list_recreate (NautilusPreferencesBox *preferences_box); +static void preferences_box_select_pane (NautilusPreferencesBox *preferences_box, + guint pane_row, + const char *name); /* PaneInfo functions */ -static PaneInfo *pane_info_alloc (const gchar *pane_name); -static void pane_info_free (PaneInfo *info); - - - +static PaneInfo *pane_info_new (const char *pane_name); +static void pane_info_free (PaneInfo *info); /* Category list callbacks */ -static void category_list_select_row (GtkCList *clist, - gint row, - gint column, - GdkEventButton *event, - gpointer user_data); +static void category_list_select_row_callback (GtkCList *clist, + int row, + int column, + GdkEventButton *event, + gpointer user_data); NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusPreferencesBox, nautilus_preferences_box, GTK_TYPE_HBOX) @@ -100,30 +88,21 @@ NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusPreferencesBox, nautilus_preferences_ * NautilusPreferencesBoxClass methods */ static void -nautilus_preferences_box_initialize_class (NautilusPreferencesBoxClass *prefs_box_class) +nautilus_preferences_box_initialize_class (NautilusPreferencesBoxClass *preferences_box_class) { GtkObjectClass *object_class; - GtkWidgetClass *widget_class; - object_class = GTK_OBJECT_CLASS (prefs_box_class); - widget_class = GTK_WIDGET_CLASS (prefs_box_class); - - parent_class = gtk_type_class (gtk_hbox_get_type ()); + object_class = GTK_OBJECT_CLASS (preferences_box_class); /* GtkObjectClass */ object_class->destroy = nautilus_preferences_box_destroy; } static void -nautilus_preferences_box_initialize (NautilusPreferencesBox *prefs_box) +nautilus_preferences_box_initialize (NautilusPreferencesBox *preferences_box) { - prefs_box->details = g_new (NautilusPreferencesBoxDetails, 1); - - prefs_box->details->category_list = NULL; - prefs_box->details->pane_container = NULL; - prefs_box->details->panes = NULL; - - prefs_box->details->selected_pane = PREFS_SELECTED_PANE_UNKNOWN; + preferences_box->details = g_new0 (NautilusPreferencesBoxDetails, 1); + preferences_box->details->selected_pane = SELECTED_PANE_UNKNOWN; } /* @@ -132,139 +111,98 @@ nautilus_preferences_box_initialize (NautilusPreferencesBox *prefs_box) static void nautilus_preferences_box_destroy (GtkObject *object) { - NautilusPreferencesBox * prefs_box; + NautilusPreferencesBox *preferences_box; - g_return_if_fail (object != NULL); - g_return_if_fail (NAUTILUS_IS_PREFS_BOX (object)); + g_return_if_fail (NAUTILUS_IS_PREFERENCES_BOX (object)); - prefs_box = NAUTILUS_PREFERENCES_BOX (object); + preferences_box = NAUTILUS_PREFERENCES_BOX (object); - if (prefs_box->details->panes) - { + if (preferences_box->details->panes) { GList *panes; + + panes = preferences_box->details->panes; - panes = prefs_box->details->panes; - - while (panes) - { + while (panes) { PaneInfo * info = panes->data; - + g_assert (info != NULL); - pane_info_free (info); - panes = panes->next; } - g_list_free (prefs_box->details->panes); + g_list_free (preferences_box->details->panes); } - g_free (prefs_box->details); + g_free (preferences_box->details); - /* Chain */ - if (GTK_OBJECT_CLASS (parent_class)->destroy != NULL) - (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); + /* Chain destroy */ + NAUTILUS_CALL_PARENT_CLASS (GTK_OBJECT_CLASS, destroy, (object)); } /* * Misc private stuff */ static void -prefs_box_construct (NautilusPreferencesBox *prefs_box) +preferences_box_select_pane (NautilusPreferencesBox *preferences_box, + guint pane_row, + const char *pane_name) { - g_assert (prefs_box != NULL); - g_assert (prefs_box->details != NULL); - - g_assert (prefs_box->details->category_list == NULL); - g_assert (prefs_box->details->panes == NULL); - - /* Configure ourselves */ - gtk_box_set_homogeneous (GTK_BOX (prefs_box), FALSE); - - gtk_box_set_spacing (GTK_BOX (prefs_box), PREFS_BOX_SPACING); + GList *pane_node; + PaneInfo *pane_info; + GList *pane_iterator; + + g_return_if_fail (NAUTILUS_IS_PREFERENCES_BOX (preferences_box)); + g_return_if_fail (preferences_box->details != NULL); + g_return_if_fail (preferences_box->details->panes != NULL); + g_return_if_fail (pane_row < g_list_length (preferences_box->details->panes)); + g_return_if_fail (pane_name != NULL); - /* The category list */ - prefs_box->details->category_list = - gtk_clist_new (PREFS_BOX_NUM_CATEGORY_COLUMNS); + pane_node = g_list_nth (preferences_box->details->panes, pane_row); - gtk_signal_connect (GTK_OBJECT (prefs_box->details->category_list), - "select_row", - GTK_SIGNAL_FUNC (category_list_select_row), - (gpointer) prefs_box); + g_return_if_fail (pane_node != NULL); - gtk_clist_set_selection_mode (GTK_CLIST (prefs_box->details->category_list), - GTK_SELECTION_BROWSE); + pane_info = pane_node->data; - gtk_clist_set_column_auto_resize (GTK_CLIST (prefs_box->details->category_list), - PREFS_BOX_CATEGORY_COLUMN, - TRUE); - - gtk_box_pack_start (GTK_BOX (prefs_box), - prefs_box->details->category_list, - FALSE, - TRUE, - 0); + /* Show only the corresponding pane widget */ + pane_iterator = preferences_box->details->panes; - /* The gtk notebook that the panes go into. */ - prefs_box->details->pane_container = gtk_notebook_new (); + while (pane_iterator) { + PaneInfo *info = pane_iterator->data; - gtk_notebook_set_show_tabs (GTK_NOTEBOOK (prefs_box->details->pane_container), FALSE); - gtk_notebook_set_show_border (GTK_NOTEBOOK (prefs_box->details->pane_container), FALSE); - - gtk_box_pack_start (GTK_BOX (prefs_box), - prefs_box->details->pane_container, - TRUE, - TRUE, - 0); - - gtk_widget_show (prefs_box->details->category_list); - gtk_widget_show (prefs_box->details->pane_container); + g_assert (info != NULL); + + if (nautilus_str_is_equal (pane_name, info->pane_name)) { + gtk_widget_show (info->pane_widget); + gtk_notebook_set_page (GTK_NOTEBOOK (preferences_box->details->pane_notebook), + g_list_position (preferences_box->details->panes, pane_iterator)); + } + + pane_iterator = pane_iterator->next; + } } static void -prefs_box_select_pane (NautilusPreferencesBox *prefs_box, - guint pane_row) +preferences_box_category_list_recreate (NautilusPreferencesBox *preferences_box) { - GList *pane_node; - PaneInfo *pane_info; - GList *pane_iterator; - - g_assert (prefs_box != NULL); - g_assert (NAUTILUS_IS_PREFS_BOX (prefs_box)); - g_assert (prefs_box->details != NULL); - g_assert (prefs_box->details->panes != NULL); - - g_assert (pane_row < g_list_length (prefs_box->details->panes)); - - pane_node = g_list_nth (prefs_box->details->panes, pane_row); - - g_assert (pane_node != NULL); - - pane_info = pane_node->data; + GList *iterator; - /* Show only the corresponding pane widget */ - pane_iterator = prefs_box->details->panes; + g_return_if_fail (NAUTILUS_IS_PREFERENCES_BOX (preferences_box)); + g_return_if_fail (GTK_IS_CLIST (preferences_box->details->category_list)); - while (pane_iterator) - { - PaneInfo * info = pane_iterator->data; - - g_assert (info != NULL); + gtk_clist_clear (GTK_CLIST (preferences_box->details->category_list)); - if (pane_info == info) - { - /* Construct pane for first time if needed */ - if (!info->constructed) - { - - info->constructed = TRUE; - } - - gtk_widget_show (info->pane_widget); - gtk_notebook_set_page (GTK_NOTEBOOK (prefs_box->details->pane_container), g_list_position (prefs_box->details->panes, pane_iterator)); + for (iterator = preferences_box->details->panes; iterator != NULL; iterator = iterator->next) { + PaneInfo *info = iterator->data; + + g_assert (NAUTILUS_IS_PREFERENCES_PANE (info->pane_widget)); + + if (nautilus_preferences_pane_get_num_visible_groups + (NAUTILUS_PREFERENCES_PANE (info->pane_widget)) > 0) { + char *text_array[NUM_CATEGORY_COLUMNS]; + + text_array[CATEGORY_COLUMN] = info->pane_name; + gtk_clist_append (GTK_CLIST (preferences_box->details->category_list), text_array); } - - pane_iterator = pane_iterator->next; } } @@ -272,13 +210,13 @@ prefs_box_select_pane (NautilusPreferencesBox *prefs_box, * PaneInfo functions */ static PaneInfo * -pane_info_alloc (const gchar *pane_name) +pane_info_new (const char *pane_name) { PaneInfo * info; g_assert (pane_name != NULL); - info = g_new (PaneInfo, 1); + info = g_new0 (PaneInfo, 1); info->pane_name = g_strdup (pane_name); @@ -289,9 +227,8 @@ static void pane_info_free (PaneInfo *info) { g_assert (info != NULL); - + g_free (info->pane_name); - g_free (info); } @@ -299,78 +236,119 @@ pane_info_free (PaneInfo *info) * Category list callbacks */ static void -category_list_select_row (GtkCList *clist, - gint row, - gint column, - GdkEventButton *event, - gpointer user_data) +category_list_select_row_callback (GtkCList *clist, + int row, + int column, + GdkEventButton *event, + gpointer callback_data) { - NautilusPreferencesBox *prefs_box = (NautilusPreferencesBox *) user_data; + const char *pane_name = NULL; + + g_return_if_fail (NAUTILUS_IS_PREFERENCES_BOX (callback_data)); - g_assert (prefs_box != NULL); - g_assert (NAUTILUS_IS_PREFS_BOX (prefs_box)); + /* The cast here is needed because of the broken gtk_clist api */ + if (gtk_clist_get_text (clist, row, column, (char **) &pane_name) != 1) { + return; + } - prefs_box_select_pane (prefs_box, (guint) row); + g_return_if_fail (pane_name != NULL); + + preferences_box_select_pane (NAUTILUS_PREFERENCES_BOX (callback_data), row, pane_name); } /* * NautilusPreferencesBox public methods */ GtkWidget* -nautilus_preferences_box_new (const gchar *box_title) +nautilus_preferences_box_new (const char *box_title) { - NautilusPreferencesBox *prefs_box; + NautilusPreferencesBox *preferences_box; - prefs_box = NAUTILUS_PREFERENCES_BOX + preferences_box = NAUTILUS_PREFERENCES_BOX (gtk_widget_new (nautilus_preferences_box_get_type (), NULL)); - prefs_box_construct (prefs_box); + /* Configure ourselves */ + gtk_box_set_homogeneous (GTK_BOX (preferences_box), FALSE); + gtk_box_set_spacing (GTK_BOX (preferences_box), SPACING_BETWEEN_CATEGORIES_AND_PANES); + + /* The category list */ + preferences_box->details->category_list = gtk_clist_new (NUM_CATEGORY_COLUMNS); + + gtk_signal_connect (GTK_OBJECT (preferences_box->details->category_list), + "select_row", + GTK_SIGNAL_FUNC (category_list_select_row_callback), + preferences_box); + + gtk_clist_set_selection_mode (GTK_CLIST (preferences_box->details->category_list), + GTK_SELECTION_BROWSE); - return GTK_WIDGET (prefs_box); + gtk_clist_set_column_auto_resize (GTK_CLIST (preferences_box->details->category_list), + CATEGORY_COLUMN, + TRUE); + + gtk_box_pack_start (GTK_BOX (preferences_box), + preferences_box->details->category_list, + FALSE, + TRUE, + 0); + + /* The gtk notebook that the panes go into. */ + preferences_box->details->pane_notebook = gtk_notebook_new (); + + gtk_notebook_set_show_tabs (GTK_NOTEBOOK (preferences_box->details->pane_notebook), FALSE); + gtk_notebook_set_show_border (GTK_NOTEBOOK (preferences_box->details->pane_notebook), FALSE); + + gtk_box_pack_start (GTK_BOX (preferences_box), + preferences_box->details->pane_notebook, + TRUE, + TRUE, + 0); + + gtk_widget_show (preferences_box->details->category_list); + gtk_widget_show (preferences_box->details->pane_notebook); + + return GTK_WIDGET (preferences_box); } GtkWidget * -nautilus_preferences_box_add_pane (NautilusPreferencesBox *prefs_box, - const gchar *pane_title, - const gchar *pane_description) +nautilus_preferences_box_add_pane (NautilusPreferencesBox *preferences_box, + const char *pane_title, + const char *pane_description) { - PaneInfo *info; - gint new_row; - gchar *text[PREFS_BOX_NUM_CATEGORY_COLUMNS]; + PaneInfo *info; - g_return_val_if_fail (prefs_box != NULL, NULL); - g_return_val_if_fail (NAUTILUS_IS_PREFS_BOX (prefs_box), NULL); + g_return_val_if_fail (NAUTILUS_IS_PREFERENCES_BOX (preferences_box), NULL); g_return_val_if_fail (pane_title != NULL, NULL); g_return_val_if_fail (pane_description != NULL, NULL); - info = pane_info_alloc (pane_title); - - prefs_box->details->panes = g_list_append (prefs_box->details->panes, - (gpointer) info); + info = pane_info_new (pane_title); - info->pane_widget = nautilus_preferences_pane_new (pane_title, - pane_description); + preferences_box->details->panes = g_list_append (preferences_box->details->panes, info); - gtk_notebook_append_page (GTK_NOTEBOOK (prefs_box->details->pane_container), info->pane_widget, NULL); - - text[PREFS_BOX_CATEGORY_COLUMN] = (gchar *) pane_title; - - new_row = gtk_clist_append (GTK_CLIST (prefs_box->details->category_list), - text); + info->pane_widget = nautilus_preferences_pane_new (pane_title, pane_description); + + gtk_notebook_append_page (GTK_NOTEBOOK (preferences_box->details->pane_notebook), + info->pane_widget, + NULL); return info->pane_widget; } void -nautilus_preferences_box_update (NautilusPreferencesBox *prefs_box) +nautilus_preferences_box_update (NautilusPreferencesBox *preferences_box) { GList *iterator; - g_return_if_fail (NAUTILUS_IS_PREFS_BOX (prefs_box)); + g_return_if_fail (NAUTILUS_IS_PREFERENCES_BOX (preferences_box)); - for (iterator = prefs_box->details->panes; iterator != NULL; iterator = iterator->next) { + for (iterator = preferences_box->details->panes; iterator != NULL; iterator = iterator->next) { PaneInfo *info = iterator->data; - + + g_assert (NAUTILUS_IS_PREFERENCES_PANE (info->pane_widget)); + nautilus_preferences_pane_update (NAUTILUS_PREFERENCES_PANE (info->pane_widget)); } + + preferences_box_category_list_recreate (preferences_box); + } diff --git a/libnautilus-private/nautilus-preferences-box.h b/libnautilus-private/nautilus-preferences-box.h index e6d9f9b82..e688f1ee3 100644 --- a/libnautilus-private/nautilus-preferences-box.h +++ b/libnautilus-private/nautilus-preferences-box.h @@ -31,37 +31,37 @@ BEGIN_GNOME_DECLS -#define NAUTILUS_TYPE_PREFS_BOX (nautilus_preferences_box_get_type ()) -#define NAUTILUS_PREFERENCES_BOX(obj) (GTK_CHECK_CAST ((obj), NAUTILUS_TYPE_PREFS_BOX, NautilusPreferencesBox)) -#define NAUTILUS_PREFERENCES_BOX_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), NAUTILUS_TYPE_PREFS_BOX, NautilusPreferencesBoxClass)) -#define NAUTILUS_IS_PREFS_BOX(obj) (GTK_CHECK_TYPE ((obj), NAUTILUS_TYPE_PREFS_BOX)) -#define NAUTILUS_IS_PREFS_BOX_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), NAUTILUS_TYPE_PREFS_BOX)) +#define NAUTILUS_TYPE_PREFERENCES_BOX (nautilus_preferences_box_get_type ()) +#define NAUTILUS_PREFERENCES_BOX(obj) (GTK_CHECK_CAST ((obj), NAUTILUS_TYPE_PREFERENCES_BOX, NautilusPreferencesBox)) +#define NAUTILUS_PREFERENCES_BOX_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), NAUTILUS_TYPE_PREFERENCES_BOX, NautilusPreferencesBoxClass)) +#define NAUTILUS_IS_PREFERENCES_BOX(obj) (GTK_CHECK_TYPE ((obj), NAUTILUS_TYPE_PREFERENCES_BOX)) +#define NAUTILUS_IS_PREFERENCES_BOX_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), NAUTILUS_TYPE_PREFERENCES_BOX)) -typedef struct _NautilusPreferencesBox NautilusPreferencesBox; +typedef struct _NautilusPreferencesBox NautilusPreferencesBox; typedef struct _NautilusPreferencesBoxClass NautilusPreferencesBoxClass; typedef struct _NautilusPreferencesBoxDetails NautilusPreferencesBoxDetails; struct _NautilusPreferencesBox { /* Super Class */ - GtkHBox hbox; + GtkHBox hbox; /* Private stuff */ - NautilusPreferencesBoxDetails *details; + NautilusPreferencesBoxDetails *details; }; struct _NautilusPreferencesBoxClass { - GtkHBoxClass parent_class; - - void (*activate) (GtkWidget * prefs_box, gint entry_number); + GtkHBoxClass parent_class; + + void (*activate) (GtkWidget *preferences_box, gint entry_number); }; GtkType nautilus_preferences_box_get_type (void); -GtkWidget* nautilus_preferences_box_new (const gchar *box_title); +GtkWidget* nautilus_preferences_box_new (const char *box_title); GtkWidget* nautilus_preferences_box_add_pane (NautilusPreferencesBox *prefs_box, - const gchar *pane_title, - const gchar *pane_description); + const char *pane_title, + const char *pane_description); void nautilus_preferences_box_update (NautilusPreferencesBox *prefs_box); END_GNOME_DECLS diff --git a/libnautilus-private/nautilus-preferences-dialog.c b/libnautilus-private/nautilus-preferences-dialog.c index 7b1d07345..62b883377 100644 --- a/libnautilus-private/nautilus-preferences-dialog.c +++ b/libnautilus-private/nautilus-preferences-dialog.c @@ -237,7 +237,7 @@ nautilus_preferences_dialog_destroy(GtkObject* object) NautilusPreferencesDialog * prefs_dialog; g_return_if_fail (object != NULL); - g_return_if_fail (NAUTILUS_IS_PREFS_DIALOG (object)); + g_return_if_fail (NAUTILUS_IS_PREFERENCES_DIALOG (object)); prefs_dialog = NAUTILUS_PREFERENCES_DIALOG(object); @@ -254,7 +254,7 @@ GtkWidget* nautilus_preferences_dialog_get_prefs_box (NautilusPreferencesDialog *prefs_dialog) { g_return_val_if_fail (prefs_dialog != NULL, NULL); - g_return_val_if_fail (NAUTILUS_IS_PREFS_DIALOG (prefs_dialog), NULL); + g_return_val_if_fail (NAUTILUS_IS_PREFERENCES_DIALOG (prefs_dialog), NULL); return prefs_dialog->details->prefs_box; } @@ -262,7 +262,7 @@ nautilus_preferences_dialog_get_prefs_box (NautilusPreferencesDialog *prefs_dial void nautilus_preferences_dialog_update (NautilusPreferencesDialog *preferences_dialog) { - g_return_if_fail (NAUTILUS_IS_PREFS_DIALOG (preferences_dialog)); + g_return_if_fail (NAUTILUS_IS_PREFERENCES_DIALOG (preferences_dialog)); nautilus_preferences_box_update (NAUTILUS_PREFERENCES_BOX (preferences_dialog->details->prefs_box)); } @@ -270,7 +270,7 @@ nautilus_preferences_dialog_update (NautilusPreferencesDialog *preferences_dialo static void user_level_changed_callback (gpointer callback_data) { - g_return_if_fail (NAUTILUS_IS_PREFS_DIALOG (callback_data)); + g_return_if_fail (NAUTILUS_IS_PREFERENCES_DIALOG (callback_data)); nautilus_preferences_dialog_update (NAUTILUS_PREFERENCES_DIALOG (callback_data)); } diff --git a/libnautilus-private/nautilus-preferences-dialog.h b/libnautilus-private/nautilus-preferences-dialog.h index acf5701a2..95158a1e3 100644 --- a/libnautilus-private/nautilus-preferences-dialog.h +++ b/libnautilus-private/nautilus-preferences-dialog.h @@ -30,11 +30,11 @@ BEGIN_GNOME_DECLS -#define NAUTILUS_TYPE_PREFS_DIALOG (nautilus_preferences_dialog_get_type ()) -#define NAUTILUS_PREFERENCES_DIALOG(obj) (GTK_CHECK_CAST ((obj), NAUTILUS_TYPE_PREFS_DIALOG, NautilusPreferencesDialog)) -#define NAUTILUS_PREFERENCES_DIALOG_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), NAUTILUS_TYPE_PREFS_DIALOG, NautilusPreferencesDialogClass)) -#define NAUTILUS_IS_PREFS_DIALOG(obj) (GTK_CHECK_TYPE ((obj), NAUTILUS_TYPE_PREFS_DIALOG)) -#define NAUTILUS_IS_PREFS_DIALOG_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), NAUTILUS_TYPE_PREFS_DIALOG)) +#define NAUTILUS_TYPE_PREFERENCES_DIALOG (nautilus_preferences_dialog_get_type ()) +#define NAUTILUS_PREFERENCES_DIALOG(obj) (GTK_CHECK_CAST ((obj), NAUTILUS_TYPE_PREFERENCES_DIALOG, NautilusPreferencesDialog)) +#define NAUTILUS_PREFERENCES_DIALOG_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), NAUTILUS_TYPE_PREFERENCES_DIALOG, NautilusPreferencesDialogClass)) +#define NAUTILUS_IS_PREFERENCES_DIALOG(obj) (GTK_CHECK_TYPE ((obj), NAUTILUS_TYPE_PREFERENCES_DIALOG)) +#define NAUTILUS_IS_PREFERENCES_DIALOG_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), NAUTILUS_TYPE_PREFERENCES_DIALOG)) typedef struct _NautilusPreferencesDialog NautilusPreferencesDialog; diff --git a/libnautilus-private/nautilus-preferences-group.c b/libnautilus-private/nautilus-preferences-group.c index 24bfb9e08..55ba8cb4d 100644 --- a/libnautilus-private/nautilus-preferences-group.c +++ b/libnautilus-private/nautilus-preferences-group.c @@ -250,7 +250,7 @@ nautilus_preferences_group_update (NautilusPreferencesGroup *group) } guint -nautilus_preferences_get_num_visible_items (const NautilusPreferencesGroup *group) +nautilus_preferences_group_get_num_visible_items (const NautilusPreferencesGroup *group) { guint n = 0; GList *iterator; diff --git a/libnautilus-private/nautilus-preferences-group.h b/libnautilus-private/nautilus-preferences-group.h index ec9e8ea52..1e0a3fc2a 100644 --- a/libnautilus-private/nautilus-preferences-group.h +++ b/libnautilus-private/nautilus-preferences-group.h @@ -56,13 +56,13 @@ struct _NautilusPreferencesGroupClass GtkFrameClass parent_class; }; -GtkType nautilus_preferences_group_get_type (void); -GtkWidget* nautilus_preferences_group_new (const gchar *title); -GtkWidget* nautilus_preferences_group_add_item (NautilusPreferencesGroup *group, - const char *preference_name, - NautilusPreferencesItemType item_type); -void nautilus_preferences_group_update (NautilusPreferencesGroup *group); -guint nautilus_preferences_get_num_visible_items (const NautilusPreferencesGroup *group); +GtkType nautilus_preferences_group_get_type (void); +GtkWidget* nautilus_preferences_group_new (const gchar *title); +GtkWidget* nautilus_preferences_group_add_item (NautilusPreferencesGroup *group, + const char *preference_name, + NautilusPreferencesItemType item_type); +void nautilus_preferences_group_update (NautilusPreferencesGroup *group); +guint nautilus_preferences_group_get_num_visible_items (const NautilusPreferencesGroup *group); END_GNOME_DECLS diff --git a/libnautilus-private/nautilus-preferences-pane.c b/libnautilus-private/nautilus-preferences-pane.c index 7c66c1219..34b561e4a 100644 --- a/libnautilus-private/nautilus-preferences-pane.c +++ b/libnautilus-private/nautilus-preferences-pane.c @@ -27,50 +27,23 @@ #include "nautilus-preferences-pane.h" #include "nautilus-gtk-macros.h" -#include <gtk/gtklabel.h> -#include <gtk/gtkframe.h> #include <gtk/gtkhbox.h> -#include <gnome.h> - -enum -{ - ACTIVATE, - LAST_SIGNAL -}; - -static const guint PREFS_PANE_GROUPS_BOX_TOP_OFFSET = 0; -static const guint PREFS_PANE_IN_BETWEEN_OFFSET = 4; +static const guint GROUPS_BOX_TOP_OFFSET = 0; +static const guint IN_BETWEEN_OFFSET = 4; struct _NautilusPreferencesPaneDetails { - GtkWidget *title_box; - GtkWidget *title_frame; - GtkWidget *title_label; - GtkWidget *description_label; - - GtkWidget *groups_box; - - gboolean show_title; - - GList *groups; + GtkWidget *groups_box; + GList *groups; }; -typedef void (*GnomeBoxSignal1) (GtkObject* object, - gint arg1, - gpointer data); - /* NautilusPreferencesPaneClass methods */ -static void nautilus_preferences_pane_initialize_class (NautilusPreferencesPaneClass *klass); -static void nautilus_preferences_pane_initialize (NautilusPreferencesPane *prefs_pane); +static void nautilus_preferences_pane_initialize_class (NautilusPreferencesPaneClass *preferences_pane_class); +static void nautilus_preferences_pane_initialize (NautilusPreferencesPane *preferences_pane); /* GtkObjectClass methods */ -static void nautilus_preferences_pane_destroy (GtkObject *object); - -/* Private stuff */ -static void prefs_pane_construct (NautilusPreferencesPane *prefs_pane, - const gchar *pane_title, - const gchar *pane_description); +static void nautilus_preferences_pane_destroy (GtkObject *object); NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusPreferencesPane, nautilus_preferences_pane, GTK_TYPE_VBOX) @@ -78,206 +51,92 @@ NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusPreferencesPane, nautilus_preferences * NautilusPreferencesPaneClass methods */ static void -nautilus_preferences_pane_initialize_class (NautilusPreferencesPaneClass *prefs_pane_class) +nautilus_preferences_pane_initialize_class (NautilusPreferencesPaneClass *preferences_pane_class) { GtkObjectClass *object_class; - GtkWidgetClass *widget_class; - object_class = GTK_OBJECT_CLASS (prefs_pane_class); - widget_class = GTK_WIDGET_CLASS (prefs_pane_class); - - parent_class = gtk_type_class (gtk_vbox_get_type ()); - + object_class = GTK_OBJECT_CLASS (preferences_pane_class); + /* GtkObjectClass */ object_class->destroy = nautilus_preferences_pane_destroy; } static void -nautilus_preferences_pane_initialize (NautilusPreferencesPane *prefs_pane) +nautilus_preferences_pane_initialize (NautilusPreferencesPane *preferences_pane) { - prefs_pane->details = g_new (NautilusPreferencesPaneDetails, 1); - - prefs_pane->details->title_label = NULL; - prefs_pane->details->description_label = NULL; - prefs_pane->details->title_box = NULL; - prefs_pane->details->title_frame = NULL; - prefs_pane->details->groups_box = NULL; - prefs_pane->details->groups = NULL; - prefs_pane->details->show_title = FALSE; + preferences_pane->details = g_new0 (NautilusPreferencesPaneDetails, 1); } /* * GtkObjectClass methods */ static void -nautilus_preferences_pane_destroy(GtkObject* object) +nautilus_preferences_pane_destroy (GtkObject* object) { - NautilusPreferencesPane * prefs_pane; + NautilusPreferencesPane *preferences_pane; - g_return_if_fail (object != NULL); - g_return_if_fail (NAUTILUS_IS_PREFS_PANE (object)); + g_return_if_fail (NAUTILUS_IS_PREFERENCES_PANE (object)); - prefs_pane = NAUTILUS_PREFERENCES_PANE (object); - - if (prefs_pane->details->groups) - { - g_list_free (prefs_pane->details->groups); - } + preferences_pane = NAUTILUS_PREFERENCES_PANE (object); - g_free (prefs_pane->details); + g_list_free (preferences_pane->details->groups); + g_free (preferences_pane->details); /* Chain destroy */ NAUTILUS_CALL_PARENT_CLASS (GTK_OBJECT_CLASS, destroy, (object)); } /* - * Private stuff - */ -static void -prefs_pane_construct (NautilusPreferencesPane *prefs_pane, - const gchar *pane_title, - const gchar *pane_description) -{ - g_assert (prefs_pane != NULL); - g_assert (prefs_pane->details != NULL); - - g_assert (pane_title != NULL); - g_assert (pane_description != NULL); - - g_assert (prefs_pane->details->title_label == NULL); - g_assert (prefs_pane->details->description_label == NULL); - g_assert (prefs_pane->details->title_box == NULL); - g_assert (prefs_pane->details->groups_box == NULL); - g_assert (prefs_pane->details->title_frame == NULL); - g_assert (prefs_pane->details->groups == NULL); - - if (prefs_pane->details->show_title) - { - /* Title frame */ - prefs_pane->details->title_frame = gtk_frame_new (NULL); - - gtk_frame_set_shadow_type (GTK_FRAME (prefs_pane->details->title_frame), - GTK_SHADOW_ETCHED_IN); - - /* Title box */ - prefs_pane->details->title_box = gtk_hbox_new (FALSE, 0); - - /* Title labels */ - prefs_pane->details->title_label = gtk_label_new (pane_title); - prefs_pane->details->description_label = gtk_label_new (pane_description); - - gtk_box_pack_start (GTK_BOX (prefs_pane->details->title_box), - prefs_pane->details->title_label, - FALSE, - FALSE, - 0); - - gtk_box_pack_end (GTK_BOX (prefs_pane->details->title_box), - prefs_pane->details->description_label, - FALSE, - FALSE, - 0); - - gtk_widget_show (prefs_pane->details->title_label); - gtk_widget_show (prefs_pane->details->description_label); - - /* Add title box to title frame */ - gtk_container_add (GTK_CONTAINER (prefs_pane->details->title_frame), - prefs_pane->details->title_box); - - gtk_widget_show (prefs_pane->details->title_box); - - /* Add title frame to ourselves */ - gtk_box_pack_start (GTK_BOX (prefs_pane), - prefs_pane->details->title_frame, - TRUE, - TRUE, - 0); - - gtk_widget_show (prefs_pane->details->title_frame); - } - - /* Groups box */ - prefs_pane->details->groups_box = gtk_vbox_new (FALSE, 0); - - /* Add groups box to ourselves */ - gtk_box_pack_start (GTK_BOX (prefs_pane), - prefs_pane->details->groups_box, - FALSE, - FALSE, - PREFS_PANE_GROUPS_BOX_TOP_OFFSET); - - gtk_widget_show (prefs_pane->details->groups_box); - gtk_widget_show (GTK_WIDGET (prefs_pane)); -} - - -/* * NautilusPreferencesPane public methods */ GtkWidget * nautilus_preferences_pane_new (const gchar *pane_title, const gchar *pane_description) { - NautilusPreferencesPane *prefs_pane; + NautilusPreferencesPane *preferences_pane; g_return_val_if_fail (pane_title != NULL, NULL); g_return_val_if_fail (pane_description != NULL, NULL); - prefs_pane = NAUTILUS_PREFERENCES_PANE + preferences_pane = NAUTILUS_PREFERENCES_PANE (gtk_widget_new (nautilus_preferences_pane_get_type (), NULL)); - prefs_pane_construct (prefs_pane, pane_title, pane_description); - - return GTK_WIDGET (prefs_pane); -} - -void -nautilus_preferences_pane_set_title (NautilusPreferencesPane *prefs_pane, - const gchar *pane_title) -{ - g_return_if_fail (prefs_pane != NULL); - g_return_if_fail (NAUTILUS_IS_PREFS_PANE (prefs_pane)); - - g_assert (prefs_pane->details->title_label != NULL); - - gtk_label_set_text (GTK_LABEL (prefs_pane->details->title_label), - pane_title); -} + /* Groups box */ + preferences_pane->details->groups_box = gtk_vbox_new (FALSE, 0); -void -nautilus_preferences_pane_set_description (NautilusPreferencesPane *prefs_pane, - const gchar *pane_description) -{ - g_return_if_fail (prefs_pane != NULL); - g_return_if_fail (NAUTILUS_IS_PREFS_PANE (prefs_pane)); + /* Add groups box to ourselves */ + gtk_box_pack_start (GTK_BOX (preferences_pane), + preferences_pane->details->groups_box, + FALSE, + FALSE, + GROUPS_BOX_TOP_OFFSET); - g_assert (prefs_pane->details->description_label != NULL); + gtk_widget_show (preferences_pane->details->groups_box); + gtk_widget_show (GTK_WIDGET (preferences_pane)); - gtk_label_set_text (GTK_LABEL (prefs_pane->details->description_label), - pane_description); + return GTK_WIDGET (preferences_pane); } GtkWidget * -nautilus_preferences_pane_add_group (NautilusPreferencesPane *prefs_pane, +nautilus_preferences_pane_add_group (NautilusPreferencesPane *preferences_pane, const char *group_title) { GtkWidget *group; - g_return_val_if_fail (prefs_pane != NULL, NULL); - g_return_val_if_fail (NAUTILUS_IS_PREFS_PANE (prefs_pane), NULL); + g_return_val_if_fail (preferences_pane != NULL, NULL); + g_return_val_if_fail (NAUTILUS_IS_PREFERENCES_PANE (preferences_pane), NULL); g_return_val_if_fail (group_title != NULL, NULL); group = nautilus_preferences_group_new (group_title); - prefs_pane->details->groups = g_list_append (prefs_pane->details->groups, + preferences_pane->details->groups = g_list_append (preferences_pane->details->groups, (gpointer) group); - gtk_box_pack_start (GTK_BOX (prefs_pane->details->groups_box), + gtk_box_pack_start (GTK_BOX (preferences_pane->details->groups_box), group, TRUE, TRUE, - PREFS_PANE_IN_BETWEEN_OFFSET); + IN_BETWEEN_OFFSET); gtk_widget_show (group); @@ -285,7 +144,7 @@ nautilus_preferences_pane_add_group (NautilusPreferencesPane *prefs_pane, } GtkWidget * -nautilus_preferences_pane_add_item_to_nth_group (NautilusPreferencesPane *prefs_pane, +nautilus_preferences_pane_add_item_to_nth_group (NautilusPreferencesPane *preferences_pane, guint n, const char *preference_name, NautilusPreferencesItemType item_type) @@ -293,53 +152,68 @@ nautilus_preferences_pane_add_item_to_nth_group (NautilusPreferencesPane *prefs_ GtkWidget *item; GtkWidget *group; - g_return_val_if_fail (prefs_pane != NULL, NULL); - g_return_val_if_fail (NAUTILUS_IS_PREFS_PANE (prefs_pane), NULL); + g_return_val_if_fail (preferences_pane != NULL, NULL); + g_return_val_if_fail (NAUTILUS_IS_PREFERENCES_PANE (preferences_pane), NULL); g_return_val_if_fail (preference_name != NULL, NULL); - if (!prefs_pane->details->groups) { + if (!preferences_pane->details->groups) { g_warning ("nautilus_preferences_pane_add_item_to_nth_group () There are no groups!"); - return NULL; } - if (n >= g_list_length (prefs_pane->details->groups)) { + if (n >= g_list_length (preferences_pane->details->groups)) { g_warning ("nautilus_preferences_pane_add_item_to_nth_group (n = %d) n is out of bounds!", n); - return NULL; } - g_assert (g_list_nth_data (prefs_pane->details->groups, n) != NULL); - g_assert (GTK_IS_WIDGET (g_list_nth_data (prefs_pane->details->groups, n))); + g_return_val_if_fail (g_list_nth_data (preferences_pane->details->groups, n) != NULL, NULL); + g_return_val_if_fail (GTK_IS_WIDGET (g_list_nth_data (preferences_pane->details->groups, n)), NULL); - group = GTK_WIDGET (g_list_nth_data (prefs_pane->details->groups, n)); + group = GTK_WIDGET (g_list_nth_data (preferences_pane->details->groups, n)); item = nautilus_preferences_group_add_item (NAUTILUS_PREFERENCES_GROUP (group), preference_name, item_type); - g_assert (item != NULL); - return item; } void -nautilus_preferences_pane_update (NautilusPreferencesPane *prefs_pane) +nautilus_preferences_pane_update (NautilusPreferencesPane *preferences_pane) { GList *iterator; - g_return_if_fail (NAUTILUS_IS_PREFS_PANE (prefs_pane)); + g_return_if_fail (NAUTILUS_IS_PREFERENCES_PANE (preferences_pane)); - for (iterator = prefs_pane->details->groups; iterator != NULL; iterator = iterator->next) { + for (iterator = preferences_pane->details->groups; iterator != NULL; iterator = iterator->next) { NautilusPreferencesGroup *group = NAUTILUS_PREFERENCES_GROUP (iterator->data); nautilus_preferences_group_update (group); - if (nautilus_preferences_get_num_visible_items (group) == 0) { + if (nautilus_preferences_group_get_num_visible_items (group) == 0) { gtk_widget_hide (GTK_WIDGET (group)); } else { gtk_widget_show (GTK_WIDGET (group)); } } } + +guint +nautilus_preferences_pane_get_num_visible_groups (const NautilusPreferencesPane *pane) +{ + guint n = 0; + GList *iterator; + + g_return_val_if_fail (NAUTILUS_IS_PREFERENCES_PANE (pane), 0); + + for (iterator = pane->details->groups; iterator != NULL; iterator = iterator->next) { + NautilusPreferencesGroup *group = NAUTILUS_PREFERENCES_GROUP (iterator->data); + + if (GTK_WIDGET_VISIBLE (group)) { + n++; + } + } + + return n; +} diff --git a/libnautilus-private/nautilus-preferences-pane.h b/libnautilus-private/nautilus-preferences-pane.h index 32bae4c47..c1071a470 100644 --- a/libnautilus-private/nautilus-preferences-pane.h +++ b/libnautilus-private/nautilus-preferences-pane.h @@ -31,11 +31,11 @@ BEGIN_GNOME_DECLS -#define NAUTILUS_TYPE_PREFS_PANE (nautilus_preferences_pane_get_type ()) -#define NAUTILUS_PREFERENCES_PANE(obj) (GTK_CHECK_CAST ((obj), NAUTILUS_TYPE_PREFS_PANE, NautilusPreferencesPane)) -#define NAUTILUS_PREFERENCES_PANE_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), NAUTILUS_TYPE_PREFS_PANE, NautilusPreferencesPaneClass)) -#define NAUTILUS_IS_PREFS_PANE(obj) (GTK_CHECK_TYPE ((obj), NAUTILUS_TYPE_PREFS_PANE)) -#define NAUTILUS_IS_PREFS_PANE_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), NAUTILUS_TYPE_PREFS_PANE)) +#define NAUTILUS_TYPE_PREFERENCES_PANE (nautilus_preferences_pane_get_type ()) +#define NAUTILUS_PREFERENCES_PANE(obj) (GTK_CHECK_CAST ((obj), NAUTILUS_TYPE_PREFERENCES_PANE, NautilusPreferencesPane)) +#define NAUTILUS_PREFERENCES_PANE_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), NAUTILUS_TYPE_PREFERENCES_PANE, NautilusPreferencesPaneClass)) +#define NAUTILUS_IS_PREFERENCES_PANE(obj) (GTK_CHECK_TYPE ((obj), NAUTILUS_TYPE_PREFERENCES_PANE)) +#define NAUTILUS_IS_PREFERENCES_PANE_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), NAUTILUS_TYPE_PREFERENCES_PANE)) typedef struct _NautilusPreferencesPane NautilusPreferencesPane; typedef struct _NautilusPreferencesPaneClass NautilusPreferencesPaneClass; @@ -44,33 +44,28 @@ typedef struct _NautilusPreferencesPaneDetails NautilusPreferencesPaneDetails struct _NautilusPreferencesPane { /* Super Class */ - GtkVBox vbox; + GtkVBox vbox; /* Private stuff */ - NautilusPreferencesPaneDetails *details; + NautilusPreferencesPaneDetails *details; }; struct _NautilusPreferencesPaneClass { - GtkVBoxClass parent_class; - - void (*construct) (NautilusPreferencesPane *prefs_pane, GtkWidget *box); + GtkVBoxClass parent_class; }; -GtkType nautilus_preferences_pane_get_type (void); -GtkWidget* nautilus_preferences_pane_new (const gchar *pane_title, - const gchar *pane_description); -void nautilus_preferences_pane_set_title (NautilusPreferencesPane *prefs_pane, - const gchar *pane_title); -void nautilus_preferences_pane_set_description (NautilusPreferencesPane *prefs_pane, - const gchar *pane_description); -GtkWidget *nautilus_preferences_pane_add_group (NautilusPreferencesPane *prefs_pane, - const char *group_title); -GtkWidget *nautilus_preferences_pane_add_item_to_nth_group (NautilusPreferencesPane *prefs_pane, - guint n, - const char *preference_name, - NautilusPreferencesItemType item_type); -void nautilus_preferences_pane_update (NautilusPreferencesPane *prefs_pane); +GtkType nautilus_preferences_pane_get_type (void); +GtkWidget* nautilus_preferences_pane_new (const gchar *pane_title, + const gchar *pane_description); +GtkWidget *nautilus_preferences_pane_add_group (NautilusPreferencesPane *preferences_pane, + const char *group_title); +GtkWidget *nautilus_preferences_pane_add_item_to_nth_group (NautilusPreferencesPane *preferences_pane, + guint n, + const char *preference_name, + NautilusPreferencesItemType item_type); +void nautilus_preferences_pane_update (NautilusPreferencesPane *preferences_pane); +guint nautilus_preferences_pane_get_num_visible_groups (const NautilusPreferencesPane *pane); END_GNOME_DECLS |