diff options
author | Ramiro Estrugo <ramiro@src.gnome.org> | 2000-03-11 00:08:07 +0000 |
---|---|---|
committer | Ramiro Estrugo <ramiro@src.gnome.org> | 2000-03-11 00:08:07 +0000 |
commit | b948827821e27c22c1d23683d70c257290f932e9 (patch) | |
tree | 65c88f2a1c5501567e8802e879335d7992751d4f | |
parent | bddcc07d4b212d667f3f8030d8a8cf831412ed13 (diff) | |
download | nautilus-b948827821e27c22c1d23683d70c257290f932e9.tar.gz |
Moved all the preference widetry to nautilus-widgets.
Added a test program for preferences (not built).
Renamed files to user "preference" instead of "prefs".
50 files changed, 9237 insertions, 1 deletions
diff --git a/ChangeLog-20000414 b/ChangeLog-20000414 index fd7c1f2ee..d3c155c05 100644 --- a/ChangeLog-20000414 +++ b/ChangeLog-20000414 @@ -1,3 +1,26 @@ +2000-03-10 Ramiro Estrugo <ramiro@eazel.com> + + * nautilus-widgets/Makefile.am, + nautilus-widgets/nautilus-preferences-box.c + nautilus-widgets/nautilus-preferences-box.h, + nautilus-widgets/nautilus-preferences-dialog.c, + nautilus-widgets/nautilus-preferences-dialog.h, + nautilus-widgets/nautilus-preferences-group.c, + nautilus-widgets/nautilus-preferences-group.h, + nautilus-widgets/nautilus-preferences-item.c, + nautilus-widgets/nautilus-preferences-item.h, + nautilus-widgets/nautilus-preferences-pane.c, + nautilus-widgets/nautilus-preferences-pane.h, + nautilus-widgets/nautilus-preferences.c, + nautilus-widgets/nautilus-preferences.h, + nautilus-widgets/nautilus-radio-button-group.c, + nautilus-widgets/nautilus-radio-button-group.h, + nautilus-widgets/test-nautilus-widgets.c, + nautilus-widgets/test-preferences.c: + Moved all the preference widetry to nautilus-widgets. + Added a test program for preferences (not built). + Renamed files to user "preference" instead of "prefs". + 2000-03-10 Darin Adler <darin@eazel.com> * libnautilus/Makefile.am, libnautilus/gnome-icon-container-dnd.c diff --git a/libnautilus-extensions/nautilus-preferences-box.c b/libnautilus-extensions/nautilus-preferences-box.c new file mode 100644 index 000000000..9db4596cf --- /dev/null +++ b/libnautilus-extensions/nautilus-preferences-box.c @@ -0,0 +1,361 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ + +/* nautilus-prefs-box.h - Implementation for preferences box component. + + Copyright (C) 1999, 2000 Eazel, Inc. + + The Gnome Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + The Gnome Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the Gnome Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. + + Authors: Ramiro Estrugo <ramiro@eazel.com> +*/ + + +#include <nautilus-widgets/nautilus-preferences-box.h> +#include <libnautilus/nautilus-gtk-macros.h> + +#include <gtk/gtkclist.h> + +// #include <gtk/gtkmain.h> + +#include <libgnomeui/gnome-stock.h> +#include <gtk/gtkmain.h> +#include <gtk/gtksignal.h> + +enum +{ + ACTIVATE, + 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; + +typedef struct +{ + gchar *pane_name; + GtkWidget *pane_widget; + gboolean constructed; +} PaneInfo; + +struct _NautilusPrefsBoxPrivate +{ + GtkWidget *category_list; + GtkWidget *pane_container; + + GList *panes; + + gint selected_pane; +}; + +typedef void (*GnomeBoxSignal1) (GtkObject* object, + gint arg1, + gpointer data); + +/* NautilusPrefsBoxClass methods */ +static void nautilus_prefs_box_initialize_class (NautilusPrefsBoxClass *klass); +static void nautilus_prefs_box_initialize (NautilusPrefsBox *prefs_box); + + + +/* GtkObjectClass methods */ +static void nautilus_prefs_box_destroy (GtkObject *object); + + + +/* Misc private stuff */ +static void prefs_box_construct (NautilusPrefsBox *prefs_box); +static void prefs_box_select_pane (NautilusPrefsBox *prefs_box, + guint pane_row); + + + + +/* PaneInfo functions */ +static PaneInfo *pane_info_alloc (const gchar *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); + +NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusPrefsBox, nautilus_prefs_box, GTK_TYPE_HBOX) + +/* + * NautilusPrefsBoxClass methods + */ +static void +nautilus_prefs_box_initialize_class (NautilusPrefsBoxClass *prefs_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 ()); + + /* GtkObjectClass */ + object_class->destroy = nautilus_prefs_box_destroy; +} + +static void +nautilus_prefs_box_initialize (NautilusPrefsBox *prefs_box) +{ + prefs_box->priv = g_new (NautilusPrefsBoxPrivate, 1); + + prefs_box->priv->category_list = NULL; + prefs_box->priv->pane_container = NULL; + prefs_box->priv->panes = NULL; + + prefs_box->priv->selected_pane = PREFS_SELECTED_PANE_UNKNOWN; +} + +/* + * GtkObjectClass methods + */ +static void +nautilus_prefs_box_destroy (GtkObject *object) +{ + NautilusPrefsBox * prefs_box; + + g_return_if_fail (object != NULL); + g_return_if_fail (NAUTILUS_IS_PREFS_BOX (object)); + + prefs_box = NAUTILUS_PREFS_BOX (object); + + if (prefs_box->priv->panes) + { + GList *panes; + + panes = prefs_box->priv->panes; + + while (panes) + { + PaneInfo * info = panes->data; + + g_assert (info != NULL); + + pane_info_free (info); + + panes = panes->next; + } + + g_list_free (prefs_box->priv->panes); + } + + g_free (prefs_box->priv); + + /* Chain */ + if (GTK_OBJECT_CLASS (parent_class)->destroy != NULL) + (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); +} + +/* + * Misc private stuff + */ +static void +prefs_box_construct (NautilusPrefsBox *prefs_box) +{ + g_assert (prefs_box != NULL); + g_assert (prefs_box->priv != NULL); + + g_assert (prefs_box->priv->category_list == NULL); + g_assert (prefs_box->priv->panes == NULL); + + /* Configure ourselves */ + gtk_box_set_homogeneous (GTK_BOX (prefs_box), FALSE); + + gtk_box_set_spacing (GTK_BOX (prefs_box), PREFS_BOX_SPACING); + + /* The category list */ + prefs_box->priv->category_list = + gtk_clist_new (PREFS_BOX_NUM_CATEGORY_COLUMNS); + + gtk_signal_connect (GTK_OBJECT (prefs_box->priv->category_list), + "select_row", + GTK_SIGNAL_FUNC (category_list_select_row), + (gpointer) prefs_box); + + gtk_clist_set_selection_mode (GTK_CLIST (prefs_box->priv->category_list), + GTK_SELECTION_BROWSE); + + gtk_clist_set_column_auto_resize (GTK_CLIST (prefs_box->priv->category_list), + PREFS_BOX_CATEGORY_COLUMN, + TRUE); + + gtk_box_pack_start (GTK_BOX (prefs_box), + prefs_box->priv->category_list, + FALSE, + TRUE, + 0); + + gtk_widget_show (prefs_box->priv->category_list); +} + +static void +prefs_box_select_pane (NautilusPrefsBox *prefs_box, + guint pane_row) +{ + 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->priv != NULL); + g_assert (prefs_box->priv->panes != NULL); + + g_assert (pane_row < g_list_length (prefs_box->priv->panes)); + + pane_node = g_list_nth (prefs_box->priv->panes, pane_row); + + g_assert (pane_node != NULL); + + pane_info = pane_node->data; + + /* Show only the corresponding pane widget */ + pane_iterator = prefs_box->priv->panes; + + while (pane_iterator) + { + PaneInfo * info = pane_iterator->data; + + g_assert (info != NULL); + + if (pane_info == info) + { + /* Construct pane for first time if needed */ + if (!info->constructed) + { + + info->constructed = TRUE; + } + + gtk_widget_show (info->pane_widget); + } + else + { + gtk_widget_hide (info->pane_widget); + } + + pane_iterator = pane_iterator->next; + } +} + +/* + * PaneInfo functions + */ +static PaneInfo * +pane_info_alloc (const gchar *pane_name) +{ + PaneInfo * info; + + g_assert (pane_name != NULL); + + info = g_new (PaneInfo, 1); + + info->pane_name = g_strdup (pane_name); + + return info; +} + +static void +pane_info_free (PaneInfo *info) +{ + g_assert (info != NULL); + + g_free (info->pane_name); + + g_free (info); +} + +/* + * Category list callbacks + */ +static void +category_list_select_row (GtkCList *clist, + gint row, + gint column, + GdkEventButton *event, + gpointer user_data) +{ + NautilusPrefsBox *prefs_box = (NautilusPrefsBox *) user_data; + + g_assert (prefs_box != NULL); + g_assert (NAUTILUS_IS_PREFS_BOX (prefs_box)); + + prefs_box_select_pane (prefs_box, (guint) row); +} + +/* + * NautilusPrefsBox public methods + */ +GtkWidget* +nautilus_prefs_box_new (const gchar *box_title) +{ + NautilusPrefsBox *prefs_box; + + prefs_box = gtk_type_new (nautilus_prefs_box_get_type ()); + + prefs_box_construct (prefs_box); + + return GTK_WIDGET (prefs_box); +} + +GtkWidget * +nautilus_prefs_box_add_pane (NautilusPrefsBox *prefs_box, + const gchar *pane_title, + const gchar *pane_description) +{ + PaneInfo *info; + gint new_row; + gchar *text[PREFS_BOX_NUM_CATEGORY_COLUMNS]; + + 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 (pane_title != NULL, NULL); + g_return_val_if_fail (pane_description != NULL, NULL); + + info = pane_info_alloc (pane_title); + + prefs_box->priv->panes = g_list_append (prefs_box->priv->panes, + (gpointer) info); + + info->pane_widget = nautilus_prefs_pane_new (pane_title, + pane_description); + + gtk_box_pack_start (GTK_BOX (prefs_box), + info->pane_widget, + TRUE, + TRUE, + PREFS_BOX_PANE_LEFT_OFFSET); + + text[PREFS_BOX_CATEGORY_COLUMN] = (gchar *) pane_title; + + new_row = gtk_clist_append (GTK_CLIST (prefs_box->priv->category_list), + text); + + return info->pane_widget; +} diff --git a/libnautilus-extensions/nautilus-preferences-box.h b/libnautilus-extensions/nautilus-preferences-box.h new file mode 100644 index 000000000..8aa43cb21 --- /dev/null +++ b/libnautilus-extensions/nautilus-preferences-box.h @@ -0,0 +1,73 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ + +/* nautilus-prefs-box.h - Interface for preferences box component. + + Copyright (C) 1999, 2000 Eazel, Inc. + + The Gnome Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + The Gnome Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the Gnome Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. + + Authors: Ramiro Estrugo <ramiro@eazel.com> +*/ + +#ifndef NAUTILUS_PREFS_BOX_H +#define NAUTILUS_PREFS_BOX_H + +#include <libgnomeui/gnome-dialog.h> +#include <gtk/gtkhbox.h> +#include <nautilus-widgets/nautilus-preferences-pane.h> + +//#include <gnome.h> + +BEGIN_GNOME_DECLS + +#define NAUTILUS_TYPE_PREFS_BOX (nautilus_prefs_box_get_type ()) +#define NAUTILUS_PREFS_BOX(obj) (GTK_CHECK_CAST ((obj), NAUTILUS_TYPE_PREFS_BOX, NautilusPrefsBox)) +#define NAUTILUS_PREFS_BOX_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), NAUTILUS_TYPE_PREFS_BOX, NautilusPrefsBoxClass)) +#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)) + +typedef struct _NautilusPrefsBox NautilusPrefsBox; +typedef struct _NautilusPrefsBoxClass NautilusPrefsBoxClass; +typedef struct _NautilusPrefsBoxPrivate NautilusPrefsBoxPrivate; + +struct _NautilusPrefsBox +{ + /* Super Class */ + GtkHBox hbox; + + /* Private stuff */ + NautilusPrefsBoxPrivate *priv; +}; + +struct _NautilusPrefsBoxClass +{ + GtkHBoxClass parent_class; + + void (*activate) (GtkWidget * prefs_box, gint entry_number); +}; + +GtkType nautilus_prefs_box_get_type (void); +GtkWidget* nautilus_prefs_box_new (const gchar *box_title); + +GtkWidget* nautilus_prefs_box_add_pane (NautilusPrefsBox *prefs_box, + const gchar *pane_title, + const gchar *pane_description); + +BEGIN_GNOME_DECLS + +#endif /* NAUTILUS_PREFS_BOX_H */ + + diff --git a/libnautilus-extensions/nautilus-preferences-dialog.c b/libnautilus-extensions/nautilus-preferences-dialog.c new file mode 100644 index 000000000..72a16badc --- /dev/null +++ b/libnautilus-extensions/nautilus-preferences-dialog.c @@ -0,0 +1,281 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ + +/* nautilus-preferences-dialog.c - Implementation for preferences dialog. + + Copyright (C) 1999, 2000 Eazel, Inc. + + The Gnome Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + The Gnome Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the Gnome Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. + + Authors: Ramiro Estrugo <ramiro@eazel.com> +*/ + +#include <nautilus-widgets/nautilus-preferences-dialog.h> +#include <libnautilus/nautilus-gtk-macros.h> + +/* #include "caption-table.h" */ + +#include <libgnomeui/gnome-stock.h> +#include <gtk/gtkmain.h> +#include <gtk/gtksignal.h> + +#include <gnome.h> + +enum +{ + ACTIVATE, + LAST_SIGNAL +}; + +struct _NautilusPrefsDialogPrivate +{ + GtkWidget *prefs_box; +}; + +static const gchar * stock_buttons[] = +{ + "OK", + NULL +}; + +static const gint UNKNOWN_BUTTON = -1; +static const gint OK_BUTTON = 0; +static const gint DEFAULT_BUTTON = 0; +static const guint DEFAULT_BORDER_WIDTH = 0; + +static const guint PREFS_DIALOG_DEFAULT_WIDTH = 500; +static const guint PREFS_DIALOG_DEFAULT_HEIGHT = 300; + +enum +{ + COMMAND_ROW = 0, + USERNAME_ROW, + PASSWORD_ROW +}; + +/* NautilusPrefsDialogClass methods */ +static void nautilus_prefs_dialog_initialize_class (NautilusPrefsDialogClass *klass); +static void nautilus_prefs_dialog_initialize (NautilusPrefsDialog *prefs_dialog); + +/* GtkObjectClass methods */ +static void nautilus_prefs_dialog_destroy (GtkObject *object); +static void dialog_clicked (GtkWidget *widget, + gint n, + gpointer data); +static void dialog_show (GtkWidget *widget, + gpointer data); +static void dialog_destroy (GtkWidget *widget, + gpointer data); + +/* Misc private stuff */ +static void nautilus_prefs_dialog_construct (NautilusPrefsDialog *prefs_dialog, + const gchar *dialog_title); + + +NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusPrefsDialog, + nautilus_prefs_dialog, + gnome_dialog_get_type ()) + +/* + * NautilusPrefsDialogClass methods + */ +static void +nautilus_prefs_dialog_initialize_class (NautilusPrefsDialogClass * klass) +{ + GtkObjectClass * object_class; + GtkWidgetClass * widget_class; + + object_class = GTK_OBJECT_CLASS(klass); + widget_class = GTK_WIDGET_CLASS(klass); + + parent_class = gtk_type_class(gnome_dialog_get_type()); + + /* GtkObjectClass */ + object_class->destroy = nautilus_prefs_dialog_destroy; +} + +static void +nautilus_prefs_dialog_initialize (NautilusPrefsDialog * prefs_dialog) +{ + prefs_dialog->priv = g_new (NautilusPrefsDialogPrivate, 1); + + prefs_dialog->priv->prefs_box = NULL; +} + +static void +dialog_clicked(GtkWidget * widget, gint n, gpointer data) +{ + NautilusPrefsDialog * prefs_dialog = (NautilusPrefsDialog *) data; + + g_assert(prefs_dialog); + +// gtk_grab_remove(GTK_WIDGET(prefs_dialog)); + + gtk_widget_hide(GTK_WIDGET(prefs_dialog)); +} + +static void +dialog_show(GtkWidget * widget, gpointer data) +{ + NautilusPrefsDialog * prefs_dialog = (NautilusPrefsDialog *) data; + + g_assert(prefs_dialog); + +// gtk_caption_table_entry_grab_focus(GTK_CAPTION_TABLE(prefs_dialog->priv->table), +// PASSWORD_ROW); +} + +static void +dialog_destroy(GtkWidget * widget, gpointer data) +{ + NautilusPrefsDialog * prefs_dialog = (NautilusPrefsDialog *) data; + + g_assert(prefs_dialog); + +// gtk_grab_remove(GTK_WIDGET(prefs_dialog)); + +// gtk_widget_destroy (widget); +} + +static void +nautilus_prefs_dialog_construct (NautilusPrefsDialog *prefs_dialog, + const gchar *dialog_title) +{ + GnomeDialog *gnome_dialog; + + g_assert (prefs_dialog != NULL); + g_assert (prefs_dialog->priv != NULL); + + g_assert (prefs_dialog->priv->prefs_box == NULL); + + gnome_dialog = GNOME_DIALOG (prefs_dialog); + + gnome_dialog_constructv (gnome_dialog, dialog_title, stock_buttons); + + /* Setup the dialog */ + gtk_window_set_policy (GTK_WINDOW (prefs_dialog), + FALSE, /* allow_shrink */ + TRUE, /* allow_grow */ + FALSE); /* auto_shrink */ + + gtk_widget_set_usize (GTK_WIDGET (prefs_dialog), + PREFS_DIALOG_DEFAULT_WIDTH, + PREFS_DIALOG_DEFAULT_HEIGHT); + + /* Doesnt work in enlightenment or sawmill */ +#if 0 + /* This is supposed to setup the window manager functions */ + gdk_window_set_functions (GTK_WIDGET (prefs_dialog)->window, GDK_FUNC_MOVE | GDK_FUNC_RESIZE); +#endif + +// gdk_window_set_decorations (GTK_WINDOW(prefs_dialog), GDK_DECOR_ALL); + + gtk_window_set_position (GTK_WINDOW (prefs_dialog), GTK_WIN_POS_CENTER); + + gtk_container_set_border_width (GTK_CONTAINER(prefs_dialog), + DEFAULT_BORDER_WIDTH); + + gnome_dialog_set_default (GNOME_DIALOG(prefs_dialog), + DEFAULT_BUTTON); + + gtk_signal_connect (GTK_OBJECT (prefs_dialog), + "clicked", + GTK_SIGNAL_FUNC (dialog_clicked), + (gpointer) prefs_dialog); + + gtk_signal_connect (GTK_OBJECT (prefs_dialog), + "show", + GTK_SIGNAL_FUNC(dialog_show), + (gpointer) prefs_dialog); + + gtk_signal_connect (GTK_OBJECT (prefs_dialog), + "destroy", + GTK_SIGNAL_FUNC (dialog_destroy), + (gpointer) prefs_dialog); + + /* Configure the GNOME_DIALOG's vbox */ + g_assert (gnome_dialog->vbox); + + prefs_dialog->priv->prefs_box = nautilus_prefs_box_new (_("Prefs Box")); + + gtk_box_set_spacing (GTK_BOX (gnome_dialog->vbox), 10); + + gtk_box_pack_start (GTK_BOX (gnome_dialog->vbox), + prefs_dialog->priv->prefs_box, + TRUE, /* expand */ + TRUE, /* fill */ + 0); /* padding */ + + gtk_widget_show (prefs_dialog->priv->prefs_box); +} + +GtkWidget* +nautilus_prefs_dialog_new (const gchar *dialog_title) +{ + NautilusPrefsDialog *prefs_dialog; + + prefs_dialog = gtk_type_new (nautilus_prefs_dialog_get_type ()); + + nautilus_prefs_dialog_construct (prefs_dialog, dialog_title); + + return GTK_WIDGET (prefs_dialog); +} + +/* GtkObjectClass methods */ +static void +nautilus_prefs_dialog_destroy(GtkObject* object) +{ + NautilusPrefsDialog * prefs_dialog; + + g_return_if_fail (object != NULL); + g_return_if_fail (NAUTILUS_IS_PREFS_DIALOG (object)); + + prefs_dialog = NAUTILUS_PREFS_DIALOG(object); + + g_free (prefs_dialog->priv); + + /* Chain */ + if (GTK_OBJECT_CLASS (parent_class)->destroy != NULL) + (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); +} + +gboolean +nautilus_prefs_dialog_run_and_block(NautilusPrefsDialog* prefs_dialog) +{ +// g_return_val_if_fail(prefs_dialog, FALSE); + +// prefs_dialog->priv->last_button_clicked = UNKNOWN_BUTTON; + +// gtk_widget_show_all(GTK_WIDGET(prefs_dialog)); + +// gtk_grab_add(GTK_WIDGET(prefs_dialog)); + +// while (prefs_dialog->priv->last_button_clicked == UNKNOWN_BUTTON) +// gtk_main_iteration(); + +// if (prefs_dialog->priv->last_button_clicked == OK_BUTTON) +// return TRUE; + + return FALSE; +} + +GtkWidget* +nautilus_prefs_dialog_get_prefs_box (NautilusPrefsDialog *prefs_dialog) +{ + g_return_val_if_fail (prefs_dialog != NULL, NULL); + g_return_val_if_fail (NAUTILUS_IS_PREFS_DIALOG (prefs_dialog), NULL); + + return prefs_dialog->priv->prefs_box; +} diff --git a/libnautilus-extensions/nautilus-preferences-dialog.h b/libnautilus-extensions/nautilus-preferences-dialog.h new file mode 100644 index 000000000..60637d2a6 --- /dev/null +++ b/libnautilus-extensions/nautilus-preferences-dialog.h @@ -0,0 +1,71 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ + +/* nautilus-preferences-dialog.h - Interface for preferences dialog. + + Copyright (C) 1999, 2000 Eazel, Inc. + + The Gnome Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + The Gnome Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the Gnome Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. + + Authors: Ramiro Estrugo <ramiro@eazel.com> +*/ + +#ifndef NAUTILUS_PREFS_DIALOG_H +#define NAUTILUS_PREFS_DIALOG_H + +#include <libgnomeui/gnome-dialog.h> +#include <nautilus-widgets/nautilus-preferences-box.h> + +//#include <gnome.h> + +BEGIN_GNOME_DECLS + +#define NAUTILUS_TYPE_PREFS_DIALOG (nautilus_prefs_dialog_get_type ()) +#define NAUTILUS_PREFS_DIALOG(obj) (GTK_CHECK_CAST ((obj), NAUTILUS_TYPE_PREFS_DIALOG, NautilusPrefsDialog)) +#define NAUTILUS_PREFS_DIALOG_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), NAUTILUS_TYPE_PREFS_DIALOG, NautilusPrefsDialogClass)) +#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)) + + +typedef struct _NautilusPrefsDialog NautilusPrefsDialog; +typedef struct _NautilusPrefsDialogClass NautilusPrefsDialogClass; +typedef struct _NautilusPrefsDialogPrivate NautilusPrefsDialogPrivate; + +struct _NautilusPrefsDialog +{ + /* Super Class */ + GnomeDialog gnome_dialog; + + /* Private stuff */ + NautilusPrefsDialogPrivate *priv; +}; + +struct _NautilusPrefsDialogClass +{ + GnomeDialogClass parent_class; + + void (*activate) (GtkWidget * prefs_dialog, gint entry_number); +}; + +GtkType nautilus_prefs_dialog_get_type (void); +GtkWidget* nautilus_prefs_dialog_new (const gchar *dialog_title); +gboolean nautilus_prefs_dialog_run_and_block (NautilusPrefsDialog *prefs_dialog); +GtkWidget* nautilus_prefs_dialog_get_prefs_box (NautilusPrefsDialog *prefs_dialog); + +BEGIN_GNOME_DECLS + +#endif /* NAUTILUS_PREFS_DIALOG_H */ + + diff --git a/libnautilus-extensions/nautilus-preferences-group.c b/libnautilus-extensions/nautilus-preferences-group.c new file mode 100644 index 000000000..180c10ab6 --- /dev/null +++ b/libnautilus-extensions/nautilus-preferences-group.c @@ -0,0 +1,237 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ + +/* nautilus-prefs-group-radio.c - Radio button prefs group implementation. + + Copyright (C) 1999, 2000 Eazel, Inc. + + The Gnome Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + The Gnome Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the Gnome Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. + + Authors: Ramiro Estrugo <ramiro@eazel.com> +*/ + +#include "nautilus-preferences-group.h" +//#include "nautilus-prefs.h" + +#include <gnome.h> +#include <gtk/gtkradiobutton.h> +#include <gtk/gtksignal.h> +#include <libnautilus/nautilus-gtk-macros.h> + +/* Signals */ +typedef enum +{ + CHANGED, + LAST_SIGNAL +} RadioGroupSignals; + +typedef struct +{ + GtkWidget *radio_button; +} ButtonInfo; + +struct _NautilusPreferencesGroupPrivate +{ + GtkWidget *main_box; + GtkWidget *content_box; + GtkWidget *description_label; + gboolean show_description; +}; + +static const gint PREFERENCES_GROUP_NOT_FOUND = -1; + +/* NautilusPreferencesGroupClass methods */ +static void nautilus_preferences_group_initialize_class (NautilusPreferencesGroupClass *klass); +static void nautilus_preferences_group_initialize (NautilusPreferencesGroup *preferences_group); + + +/* GtkObjectClass methods */ +static void nautilus_preferences_group_destroy (GtkObject *object); + + +/* NautilusPrefsGroupClass methods */ +static void preferences_group_construct (NautilusPreferencesGroup *prefs_group, + const gchar * title); + +NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusPreferencesGroup, + nautilus_preferences_group, + GTK_TYPE_FRAME); + +/* + * NautilusPreferencesGroupClass methods + */ +static void +nautilus_preferences_group_initialize_class (NautilusPreferencesGroupClass *preferences_group_class) +{ + GtkObjectClass *object_class; + GtkWidgetClass *widget_class; + + object_class = GTK_OBJECT_CLASS (preferences_group_class); + widget_class = GTK_WIDGET_CLASS (preferences_group_class); + + parent_class = gtk_type_class (gtk_frame_get_type ()); + + /* GtkObjectClass */ + object_class->destroy = nautilus_preferences_group_destroy; +} + +static void +nautilus_preferences_group_initialize (NautilusPreferencesGroup *group) +{ + group->priv = g_new (NautilusPreferencesGroupPrivate, 1); + + group->priv->main_box = NULL; + group->priv->content_box = NULL; + group->priv->description_label = NULL; + group->priv->show_description = FALSE; +} + +/* + * GtkObjectClass methods + */ +static void +nautilus_preferences_group_destroy(GtkObject* object) +{ + NautilusPreferencesGroup *group; + + g_return_if_fail (object != NULL); + g_return_if_fail (NAUTILUS_IS_PREFERENCES_GROUP (object)); + + group = NAUTILUS_PREFERENCES_GROUP (object); + + g_free (group->priv); + + /* Chain */ + if (GTK_OBJECT_CLASS (parent_class)->destroy != NULL) + (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); +} + +static void +preferences_group_construct (NautilusPreferencesGroup *group, + const gchar * title) +{ + g_assert (group != NULL); + g_assert (title != NULL); + + g_assert (group->priv->content_box == NULL); + g_assert (group->priv->main_box == NULL); + g_assert (group->priv->description_label == NULL); + +// printf ("preferences_group_construct\n"); + +// pref_info = nautilus_prefs_get_pref_info (NAUTILUS_PREFS (prefs), +// pref_name); + +// g_assert (pref_info != NULL); + +// g_assert (pref_info->pref_description != NULL); + + /* Ourselves */ + gtk_frame_set_shadow_type (GTK_FRAME (group), + GTK_SHADOW_ETCHED_IN); + + +// gtk_object_set (GTK_OBJECT (group), +// "title_string", group_title, +// NULL); + + gtk_frame_set_label (GTK_FRAME (group), title); + + /* Main box */ + group->priv->main_box = gtk_vbox_new (FALSE, 0); + + gtk_container_add (GTK_CONTAINER (group), + group->priv->main_box); + +// gtk_container_set_border_width (GTK_CONTAINER (group->priv->content_box), +// GROUP_FRAME_BORDER_WIDTH); + + /* Description label */ + group->priv->description_label = gtk_label_new ("Blurb"); + + gtk_label_set_justify (GTK_LABEL (group->priv->description_label), + GTK_JUSTIFY_LEFT); + + gtk_box_pack_start (GTK_BOX (group->priv->main_box), + group->priv->description_label, + FALSE, + FALSE, + 0); + + if (group->priv->show_description) + { + gtk_widget_show (group->priv->description_label); + } + + /* Content box */ + group->priv->content_box = + gtk_vbox_new (FALSE, 0); + + gtk_box_pack_start (GTK_BOX (group->priv->main_box), + group->priv->content_box, + FALSE, + FALSE, + 0); + + gtk_container_set_border_width (GTK_CONTAINER (group->priv->content_box), + 4); + + gtk_widget_show (group->priv->content_box); + gtk_widget_show (group->priv->main_box); +} + +/* + * NautilusPreferencesGroup public methods + */ +GtkWidget* +nautilus_preferences_group_new (const gchar *title) +{ + NautilusPreferencesGroup *group; + + g_return_val_if_fail (title != NULL, NULL); + +/* printf("nautilus_preferences_group_new()\n"); */ + + group = gtk_type_new (nautilus_preferences_group_get_type ()); + + preferences_group_construct (group, title); + + return GTK_WIDGET (group); +} + +// void +// nautilus_preferences_group_clear (NautilusPreferencesGroup *preferences_group) +// { +// } + +void +nautilus_preferences_group_add (NautilusPreferencesGroup *group, + GtkWidget *item) +{ + g_return_if_fail (group != NULL); + g_return_if_fail (NAUTILUS_IS_PREFERENCES_GROUP (group)); + g_return_if_fail (item != NULL); + +/* printf("nautilus_preferences_group_add()\n"); */ + + gtk_box_pack_start (GTK_BOX (group->priv->content_box), + item, + TRUE, + TRUE, + 0); + +// gtk_widget_show (item); +} + diff --git a/libnautilus-extensions/nautilus-preferences-group.h b/libnautilus-extensions/nautilus-preferences-group.h new file mode 100644 index 000000000..32ff16ffd --- /dev/null +++ b/libnautilus-extensions/nautilus-preferences-group.h @@ -0,0 +1,67 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ + +/* nautilus-prefs-group-check.h - Check button prefs group interface. + + Copyright (C) 1999, 2000 Eazel, Inc. + + The Gnome Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + The Gnome Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the Gnome Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. + + Authors: Ramiro Estrugo <ramiro@eazel.com> +*/ + +#ifndef NAUTILUS_PREFERENCES_GROUP_H +#define NAUTILUS_PREFERENCES_GROUP_H + +#include <gtk/gtkframe.h> +#include <gnome.h> + +BEGIN_GNOME_DECLS + +#define NAUTILUS_TYPE_PREFERENCES_GROUP (nautilus_preferences_group_get_type ()) +#define NAUTILUS_PREFERENCES_GROUP(obj) (GTK_CHECK_CAST ((obj), NAUTILUS_TYPE_PREFERENCES_GROUP, NautilusPreferencesGroup)) +#define NAUTILUS_PREFERENCES_GROUP_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), NAUTILUS_TYPE_PREFERENCES_GROUP, NautilusPreferencesGroupClass)) +#define NAUTILUS_IS_PREFERENCES_GROUP(obj) (GTK_CHECK_TYPE ((obj), NAUTILUS_TYPE_PREFERENCES_GROUP)) +#define NAUTILUS_IS_PREFERENCES_GROUP_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), NAUTILUS_TYPE_PREFERENCES_GROUP)) + +typedef struct _NautilusPreferencesGroup NautilusPreferencesGroup; +typedef struct _NautilusPreferencesGroupClass NautilusPreferencesGroupClass; +typedef struct _NautilusPreferencesGroupPrivate NautilusPreferencesGroupPrivate; + +struct _NautilusPreferencesGroup +{ + /* Super Class */ + GtkFrame frame; + + /* Private stuff */ + NautilusPreferencesGroupPrivate *priv; +}; + +struct _NautilusPreferencesGroupClass +{ + GtkFrameClass parent_class; +}; + +GtkType nautilus_preferences_group_get_type (void); +GtkWidget* nautilus_preferences_group_new (const gchar *title); + +void nautilus_preferences_group_add (NautilusPreferencesGroup *preferences_group, + GtkWidget *item); + +BEGIN_GNOME_DECLS + +#endif /* NAUTILUS_PREFERENCES_GROUP_H */ + + diff --git a/libnautilus-extensions/nautilus-preferences-item.c b/libnautilus-extensions/nautilus-preferences-item.c new file mode 100644 index 000000000..6c636d68f --- /dev/null +++ b/libnautilus-extensions/nautilus-preferences-item.c @@ -0,0 +1,370 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ + +/* nautilus-preferences-item.c - Implementation for an individual prefs item. + + Copyright (C) 1999, 2000 Eazel, Inc. + + The Gnome Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + The Gnome Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the Gnome Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. + + Authors: Ramiro Estrugo <ramiro@eazel.com> +*/ + +#include "nautilus-preferences-item.h" +#include "nautilus-preferences.h" +#include <libnautilus/nautilus-gtk-macros.h> + +#include <gtk/gtkcheckbutton.h> +#include <nautilus-widgets/nautilus-radio-button-group.h> + +#include <gtk/gtklabel.h> +#include <gtk/gtkframe.h> +#include <gtk/gtkhbox.h> +#include <gtk/gtkvbox.h> + +// #include <gtk/gtkmain.h> +#include <gnome.h> + +#include <libgnomeui/gnome-stock.h> +#include <gtk/gtkmain.h> +#include <gtk/gtksignal.h> + +/* Arguments */ +enum +{ + ARG_0, + ARG_SHOW_DESCRIPTION, + ARG_DESCRIPTION_STRING, + ARG_TITLE_STRING +}; + +enum +{ + ACTIVATE, + LAST_SIGNAL +}; + +static const guint PREFERENCES_ITEM_TITLE_SPACING = 4; +static const guint PREFERENCES_ITEM_FRAME_BORDER_WIDTH = 6; + +struct _NautilusPreferencesItemDetails +{ + gchar *pref_name; + NautilusPreferencesItemType item_type; + GtkWidget *child; + GtkObject *prefs; +}; + +/* NautilusPreferencesItemClass methods */ +static void nautilus_preferences_item_initialize_class (NautilusPreferencesItemClass *klass); +static void nautilus_preferences_item_initialize (NautilusPreferencesItem *preferences_item); + + + +/* GtkObjectClass methods */ +static void preferences_item_destroy (GtkObject *object); +static void preferences_item_set_arg (GtkObject *object, + GtkArg *arg, + guint arg_id); +static void preferences_item_get_arg (GtkObject *object, + GtkArg *arg, + guint arg_id); + +/* Private stuff */ +static void preferences_item_construct (NautilusPreferencesItem *item, + GtkObject *prefs, + const gchar *pref_name, + NautilusPreferencesItemType item_type); + +static void test_radio_changed_signal (GtkWidget *button_group, GtkWidget * button, gpointer user_data); + +NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusPreferencesItem, nautilus_preferences_item, GTK_TYPE_VBOX) + +/* + * NautilusPreferencesItemClass methods + */ +static void +nautilus_preferences_item_initialize_class (NautilusPreferencesItemClass *preferences_item_class) +{ + GtkObjectClass *object_class; + GtkWidgetClass *widget_class; + + object_class = GTK_OBJECT_CLASS (preferences_item_class); + widget_class = GTK_WIDGET_CLASS (preferences_item_class); + + parent_class = gtk_type_class (gtk_vbox_get_type ()); + + /* Arguments */ + gtk_object_add_arg_type ("NautilusPreferencesItem::show_description", + GTK_TYPE_BOOL, + GTK_ARG_READWRITE, + ARG_SHOW_DESCRIPTION); + + gtk_object_add_arg_type ("NautilusPreferencesItem::description_string", + GTK_TYPE_STRING, + GTK_ARG_WRITABLE, + ARG_DESCRIPTION_STRING); + + gtk_object_add_arg_type ("NautilusPreferencesItem::title_string", + GTK_TYPE_STRING, + GTK_ARG_WRITABLE, + ARG_TITLE_STRING); + + /* GtkObjectClass */ + object_class->destroy = preferences_item_destroy; + object_class->set_arg = preferences_item_set_arg; + object_class->get_arg = preferences_item_get_arg; + +// /* NautilusPreferencesItemClass */ +// preferences_item_class->construct = preferences_item_construct; +// preferences_item_class->changed = NULL; +} + +static void +nautilus_preferences_item_initialize (NautilusPreferencesItem *item) +{ + item->details = g_new (NautilusPreferencesItemDetails, 1); + + item->details->pref_name = NULL; + item->details->item_type = NAUTILUS_PREFERENCES_ITEM_UNKNOWN; + item->details->child = NULL; + item->details->prefs = NULL; +} + +/* + * GtkObjectClass methods + */ +static void +preferences_item_destroy (GtkObject *object) +{ + NautilusPreferencesItem * item; + + g_return_if_fail (object != NULL); + g_return_if_fail (NAUTILUS_IS_PREFERENCES_ITEM (object)); + + item = NAUTILUS_PREFERENCES_ITEM (object); + + if (item->details->pref_name) + { + g_free (item->details->pref_name); + } + + g_free (item->details); + + /* Chain */ + if (GTK_OBJECT_CLASS (parent_class)->destroy != NULL) + (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); +} + +static void +preferences_item_set_arg (GtkObject *object, + GtkArg *arg, + guint arg_id) +{ + NautilusPreferencesItem * item; + + g_return_if_fail (object != NULL); + g_return_if_fail (NAUTILUS_IS_PREFERENCES_ITEM (object)); + + item = NAUTILUS_PREFERENCES_ITEM (object); + +#if 0 + switch (arg_id) + { + case ARG_SHOW_DESCRIPTION: + item->details->show_description = GTK_VALUE_BOOL (*arg); + + if (item->details->show_description) + { + gtk_widget_show (item->details->description_label); + } + else + { + gtk_widget_hide (item->details->description_label); + } + + break; + + case ARG_DESCRIPTION_STRING: + + gtk_label_set_text (GTK_LABEL (item->details->description_label), + GTK_VALUE_STRING (*arg)); + break; + + case ARG_TITLE_STRING: + + gtk_frame_set_label (GTK_FRAME (object), GTK_VALUE_STRING (*arg)); + + break; + } +#endif + +} + +static void +preferences_item_get_arg (GtkObject *object, + GtkArg *arg, + guint arg_id) +{ + NautilusPreferencesItem * item; + + g_return_if_fail (object != NULL); + g_return_if_fail (NAUTILUS_IS_PREFERENCES_ITEM (object)); + + item = NAUTILUS_PREFERENCES_ITEM (object); + +#if 0 + switch (arg_id) + { + case ARG_SHOW_DESCRIPTION: + GTK_VALUE_BOOL (*arg) = + GTK_WIDGET_VISIBLE (item->details->description_label); + break; + } +#endif +} + +/* + * Private stuff + */ +static void +preferences_item_construct (NautilusPreferencesItem *item, + GtkObject *prefs, + const gchar *pref_name, + NautilusPreferencesItemType item_type) +{ + g_return_if_fail (item != NULL); + g_return_if_fail (prefs != NULL); + g_return_if_fail (pref_name != NULL); + g_return_if_fail (NAUTILUS_IS_PREFERENCES_ITEM (item)); + + g_return_if_fail (item_type != NAUTILUS_PREFERENCES_ITEM_UNKNOWN); + + g_return_if_fail (item->details->child == NULL); + +// printf("preferences_item_construct (%s)\n", +// pref_name); + + item->details->prefs = prefs; + item->details->pref_name = g_strdup (pref_name); + + switch (item_type) + { + case NAUTILUS_PREFERENCES_ITEM_BOOL: + + item->details->child = gtk_check_button_new_with_label ("BOOL"); + + break; + + case NAUTILUS_PREFERENCES_ITEM_ENUM: + { + const NautilusPrefInfo * pref_info; + NautilusPrefEnumData * enum_info; + guint i; + gint value; + + + item->details->child = nautilus_radio_button_group_new (); + + pref_info = nautilus_prefs_get_pref_info (NAUTILUS_PREFS (prefs), + item->details->pref_name); + + g_assert (pref_info != NULL); + + enum_info = (NautilusPrefEnumData *) pref_info->type_data; + + g_assert (enum_info != NULL); + + + value = nautilus_prefs_get_enum (NAUTILUS_PREFS (prefs), + item->details->pref_name); + + for (i = 0; i < enum_info->num_entries; i++) + { + nautilus_radio_button_group_insert (NAUTILUS_RADIO_BUTTON_GROUP (item->details->child), + enum_info->enum_descriptions[i]); + + if (i == value) + { + nautilus_radio_button_group_set_active_index (NAUTILUS_RADIO_BUTTON_GROUP (item->details->child), i); + + } + } + + gtk_signal_connect (GTK_OBJECT (item->details->child), + "changed", + GTK_SIGNAL_FUNC (test_radio_changed_signal), + (gpointer) item); + } + break; + + case NAUTILUS_PREFERENCES_ITEM_INT: + break; + + case NAUTILUS_PREFERENCES_ITEM_UNKNOWN: + g_assert_not_reached (); + break; + } + + g_assert (item->details->child != NULL); + + gtk_box_pack_start (GTK_BOX (item), + item->details->child, + FALSE, + FALSE, + 0); + + gtk_widget_show (item->details->child); +} + +/* + * NautilusPreferencesItem public methods + */ +GtkWidget * +nautilus_preferences_item_new (GtkObject *prefs, + const gchar *pref_name, + NautilusPreferencesItemType item_type) +{ + NautilusPreferencesItem * item; + + g_return_val_if_fail (prefs != NULL, NULL); + g_return_val_if_fail (pref_name != NULL, NULL); + + item = gtk_type_new (nautilus_preferences_item_get_type ()); + +// printf ("nautilus_preferences_item_new (%s)\n", pref_name); + + preferences_item_construct (item, prefs, pref_name, item_type); + + return GTK_WIDGET (item); +} + +static void +test_radio_changed_signal (GtkWidget *buttons, GtkWidget * button, gpointer user_data) +{ + NautilusPreferencesItem * item = (NautilusPreferencesItem *) user_data; + + gint i; + + g_assert (item != NULL); + + i = nautilus_radio_button_group_get_active_index (NAUTILUS_RADIO_BUTTON_GROUP (buttons)); + +// printf ("test_radio_changed_signal (%s = %d)\n", item->details->pref_name, i); + + nautilus_prefs_set_enum (NAUTILUS_PREFS (item->details->prefs), + item->details->pref_name, + i); +} diff --git a/libnautilus-extensions/nautilus-preferences-item.h b/libnautilus-extensions/nautilus-preferences-item.h new file mode 100644 index 000000000..4a9bb30a2 --- /dev/null +++ b/libnautilus-extensions/nautilus-preferences-item.h @@ -0,0 +1,81 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ + +/* nautilus-preferences-item.h - Interface for an individual prefs item. + + Copyright (C) 1999, 2000 Eazel, Inc. + + The Gnome Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + The Gnome Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the Gnome Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. + + Authors: Ramiro Estrugo <ramiro@eazel.com> +*/ + +#ifndef NAUTILUS_PREFERENCES_ITEM_H +#define NAUTILUS_PREFERENCES_ITEM_H + +#include <gtk/gtkvbox.h> +#include <gnome.h> + +BEGIN_GNOME_DECLS + +#define NAUTILUS_TYPE_PREFERENCES_ITEM (nautilus_preferences_item_get_type ()) +#define NAUTILUS_PREFERENCES_ITEM(obj) (GTK_CHECK_CAST ((obj), NAUTILUS_TYPE_PREFERENCES_ITEM, NautilusPreferencesItem)) +#define NAUTILUS_PREFERENCES_ITEM_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), NAUTILUS_TYPE_PREFERENCES_ITEM, NautilusPreferencesItemClass)) +#define NAUTILUS_IS_PREFERENCES_ITEM(obj) (GTK_CHECK_TYPE ((obj), NAUTILUS_TYPE_PREFERENCES_ITEM)) +#define NAUTILUS_IS_PREFERENCES_ITEM_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), NAUTILUS_TYPE_PREFERENCES_ITEM)) + +typedef struct _NautilusPreferencesItem NautilusPreferencesItem; +typedef struct _NautilusPreferencesItemClass NautilusPreferencesItemClass; +typedef struct _NautilusPreferencesItemDetails NautilusPreferencesItemDetails; + +typedef enum +{ + NAUTILUS_PREFERENCES_ITEM_UNKNOWN, + NAUTILUS_PREFERENCES_ITEM_BOOL, + NAUTILUS_PREFERENCES_ITEM_ENUM, + NAUTILUS_PREFERENCES_ITEM_INT +} NautilusPreferencesItemType; + +struct _NautilusPreferencesItem +{ + /* Super Class */ + GtkVBox vbox; + + /* Private stuff */ + NautilusPreferencesItemDetails *details; +}; + +struct _NautilusPreferencesItemClass +{ + GtkVBoxClass vbox_class; + +// void (*construct) (NautilusPreferencesItem *preferences_item, +// const gchar * group_title, +// GtkObject *prefs, +// const gchar *pref_name); + +// void (*changed) (NautilusPreferencesItem *preferences_item); +}; + +GtkType nautilus_preferences_item_get_type (void); +GtkWidget* nautilus_preferences_item_new (GtkObject *prefs, + const gchar *pref_name, + NautilusPreferencesItemType item_type); + +BEGIN_GNOME_DECLS + +#endif /* NAUTILUS_PREFERENCES_ITEM_H */ + + diff --git a/libnautilus-extensions/nautilus-preferences-pane.c b/libnautilus-extensions/nautilus-preferences-pane.c new file mode 100644 index 000000000..647858eec --- /dev/null +++ b/libnautilus-extensions/nautilus-preferences-pane.c @@ -0,0 +1,283 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ + +/* nautilus-preferences-pane.h - Interface for a prefs pane superclass. + + Copyright (C) 1999, 2000 Eazel, Inc. + + The Gnome Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + The Gnome Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the Gnome Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. + + Authors: Ramiro Estrugo <ramiro@eazel.com> +*/ + + +#include <nautilus-widgets/nautilus-preferences-pane.h> +#include <libnautilus/nautilus-gtk-macros.h> + +#include <gtk/gtklabel.h> +#include <gtk/gtkframe.h> +#include <gtk/gtkhbox.h> + +// #include <gtk/gtkmain.h> +#include <gnome.h> + +#include <libgnomeui/gnome-stock.h> +#include <gtk/gtkmain.h> +#include <gtk/gtksignal.h> + +enum +{ + ACTIVATE, + LAST_SIGNAL +}; + +static const guint PREFS_PANE_GROUPS_BOX_TOP_OFFSET = 0; + +struct _NautilusPrefsPanePrivate +{ + GtkWidget *title_box; + GtkWidget *title_frame; + GtkWidget *title_label; + GtkWidget *description_label; + + GtkWidget *groups_box; + + gboolean show_title; + + GSList *groups; +}; + +typedef void (*GnomeBoxSignal1) (GtkObject* object, + gint arg1, + gpointer data); + +/* NautilusPrefsPaneClass methods */ +static void nautilus_prefs_pane_initialize_class (NautilusPrefsPaneClass *klass); +static void nautilus_prefs_pane_initialize (NautilusPrefsPane *prefs_pane); + +/* GtkObjectClass methods */ +static void nautilus_prefs_pane_destroy (GtkObject *object); + +/* Private stuff */ +static void prefs_pane_construct (NautilusPrefsPane *prefs_pane, + const gchar *pane_title, + const gchar *pane_description); + +NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusPrefsPane, nautilus_prefs_pane, GTK_TYPE_VBOX) + +/* + * NautilusPrefsPaneClass methods + */ +static void +nautilus_prefs_pane_initialize_class (NautilusPrefsPaneClass *prefs_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 ()); + + /* GtkObjectClass */ + object_class->destroy = nautilus_prefs_pane_destroy; +} + +static void +nautilus_prefs_pane_initialize (NautilusPrefsPane *prefs_pane) +{ + prefs_pane->priv = g_new (NautilusPrefsPanePrivate, 1); + + prefs_pane->priv->title_label = NULL; + prefs_pane->priv->description_label = NULL; + prefs_pane->priv->title_box = NULL; + prefs_pane->priv->title_frame = NULL; + prefs_pane->priv->groups_box = NULL; + prefs_pane->priv->groups = NULL; + prefs_pane->priv->show_title = FALSE; +} + +/* + * GtkObjectClass methods + */ +static void +nautilus_prefs_pane_destroy(GtkObject* object) +{ + NautilusPrefsPane * prefs_pane; + + g_return_if_fail (object != NULL); + g_return_if_fail (NAUTILUS_IS_PREFS_PANE (object)); + + prefs_pane = NAUTILUS_PREFS_PANE (object); + + if (prefs_pane->priv->groups) + { + g_slist_free (prefs_pane->priv->groups); + } + + g_free (prefs_pane->priv); + + /* Chain */ + if (GTK_OBJECT_CLASS (parent_class)->destroy != NULL) + (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); +} + +/* + * Private stuff + */ +static void +prefs_pane_construct (NautilusPrefsPane *prefs_pane, + const gchar *pane_title, + const gchar *pane_description) +{ + g_assert (prefs_pane != NULL); + g_assert (prefs_pane->priv != NULL); + + g_assert (pane_title != NULL); + g_assert (pane_description != NULL); + + g_assert (prefs_pane->priv->title_label == NULL); + g_assert (prefs_pane->priv->description_label == NULL); + g_assert (prefs_pane->priv->title_box == NULL); + g_assert (prefs_pane->priv->groups_box == NULL); + g_assert (prefs_pane->priv->title_frame == NULL); + g_assert (prefs_pane->priv->groups == NULL); + + prefs_pane->priv->groups = g_slist_alloc (); + + if (prefs_pane->priv->show_title) + { + /* Title frame */ + prefs_pane->priv->title_frame = gtk_frame_new (NULL); + + gtk_frame_set_shadow_type (GTK_FRAME (prefs_pane->priv->title_frame), + GTK_SHADOW_ETCHED_IN); + + /* Title box */ + prefs_pane->priv->title_box = gtk_hbox_new (FALSE, 0); + + /* Title labels */ + prefs_pane->priv->title_label = gtk_label_new (pane_title); + prefs_pane->priv->description_label = gtk_label_new (pane_description); + + gtk_box_pack_start (GTK_BOX (prefs_pane->priv->title_box), + prefs_pane->priv->title_label, + FALSE, + FALSE, + 0); + + gtk_box_pack_end (GTK_BOX (prefs_pane->priv->title_box), + prefs_pane->priv->description_label, + FALSE, + FALSE, + 0); + + gtk_widget_show (prefs_pane->priv->title_label); + gtk_widget_show (prefs_pane->priv->description_label); + + /* Add title box to title frame */ + gtk_container_add (GTK_CONTAINER (prefs_pane->priv->title_frame), + prefs_pane->priv->title_box); + + gtk_widget_show (prefs_pane->priv->title_box); + + /* Add title frame to ourselves */ + gtk_box_pack_start (GTK_BOX (prefs_pane), + prefs_pane->priv->title_frame, + FALSE, + FALSE, + 0); + + gtk_widget_show (prefs_pane->priv->title_frame); + } + + /* Groups box */ + prefs_pane->priv->groups_box = gtk_vbox_new (TRUE, 0); + + /* Add groups box to ourselves */ + gtk_box_pack_start (GTK_BOX (prefs_pane), + prefs_pane->priv->groups_box, + FALSE, + FALSE, + PREFS_PANE_GROUPS_BOX_TOP_OFFSET); + + gtk_widget_show (prefs_pane->priv->groups_box); +} + + +/* + * NautilusPrefsPane public methods + */ +GtkWidget* +nautilus_prefs_pane_new (const gchar *pane_title, + const gchar *pane_description) +{ + NautilusPrefsPane *prefs_pane; + + g_return_val_if_fail (pane_title != NULL, NULL); + g_return_val_if_fail (pane_description != NULL, NULL); + + prefs_pane = gtk_type_new (nautilus_prefs_pane_get_type ()); + + prefs_pane_construct (prefs_pane, pane_title, pane_description); + + return GTK_WIDGET (prefs_pane); +} + +void +nautilus_prefs_pane_set_title (NautilusPrefsPane *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->priv->title_label != NULL); + + gtk_label_set_text (GTK_LABEL (prefs_pane->priv->title_label), + pane_title); +} + +void +nautilus_prefs_pane_set_description (NautilusPrefsPane *prefs_pane, + const gchar *pane_description) +{ + g_return_if_fail (prefs_pane != NULL); + g_return_if_fail (NAUTILUS_IS_PREFS_PANE (prefs_pane)); + + g_assert (prefs_pane->priv->description_label != NULL); + + gtk_label_set_text (GTK_LABEL (prefs_pane->priv->description_label), + pane_description); +} + +void +nautilus_prefs_pane_add_group (NautilusPrefsPane *prefs_pane, + GtkWidget *prefs_group) +{ + g_return_if_fail (prefs_pane != NULL); + g_return_if_fail (NAUTILUS_IS_PREFS_PANE (prefs_pane)); + g_return_if_fail (prefs_group != NULL); + +// group = nautilus_prefs_group_new (group_title); + + gtk_box_pack_start (GTK_BOX (prefs_pane->priv->groups_box), + prefs_group, + TRUE, + TRUE, + 0); + +// gtk_widget_show (prefs_group); +} + diff --git a/libnautilus-extensions/nautilus-preferences-pane.h b/libnautilus-extensions/nautilus-preferences-pane.h new file mode 100644 index 000000000..3a7674b30 --- /dev/null +++ b/libnautilus-extensions/nautilus-preferences-pane.h @@ -0,0 +1,74 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ + +/* nautilus-preferences-pane.h - Interface for a prefs pane superclass. + + Copyright (C) 1999, 2000 Eazel, Inc. + + The Gnome Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + The Gnome Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the Gnome Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. + + Authors: Ramiro Estrugo <ramiro@eazel.com> +*/ + +#ifndef NAUTILUS_PREFS_PANE_H +#define NAUTILUS_PREFS_PANE_H + +#include <libgnomeui/gnome-dialog.h> +#include <gtk/gtkvbox.h> +#include <nautilus-widgets/nautilus-preferences-group.h> + +//#include <gnome.h> + +BEGIN_GNOME_DECLS + +#define NAUTILUS_TYPE_PREFS_PANE (nautilus_prefs_pane_get_type ()) +#define NAUTILUS_PREFS_PANE(obj) (GTK_CHECK_CAST ((obj), NAUTILUS_TYPE_PREFS_PANE, NautilusPrefsPane)) +#define NAUTILUS_PREFS_PANE_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), NAUTILUS_TYPE_PREFS_PANE, NautilusPrefsPaneClass)) +#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)) + +typedef struct _NautilusPrefsPane NautilusPrefsPane; +typedef struct _NautilusPrefsPaneClass NautilusPrefsPaneClass; +typedef struct _NautilusPrefsPanePrivate NautilusPrefsPanePrivate; + +struct _NautilusPrefsPane +{ + /* Super Class */ + GtkVBox vbox; + + /* Private stuff */ + NautilusPrefsPanePrivate *priv; +}; + +struct _NautilusPrefsPaneClass +{ + GtkVBoxClass parent_class; + + void (*construct) (NautilusPrefsPane *prefs_pane, GtkWidget *box); +}; + +GtkType nautilus_prefs_pane_get_type (void); +GtkWidget* nautilus_prefs_pane_new (const gchar *pane_title, + const gchar *pane_description); +void nautilus_prefs_pane_set_title (NautilusPrefsPane * prefs_pane, + const gchar *pane_title); +void nautilus_prefs_pane_set_description (NautilusPrefsPane * prefs_pane, + const gchar *pane_description); +void nautilus_prefs_pane_add_group (NautilusPrefsPane *prefs_pane, + GtkWidget *prefs_group); + +BEGIN_GNOME_DECLS + +#endif /* NAUTILUS_PREFS_PANE_H */ diff --git a/libnautilus-extensions/nautilus-preferences.c b/libnautilus-extensions/nautilus-preferences.c new file mode 100644 index 000000000..51c3768b7 --- /dev/null +++ b/libnautilus-extensions/nautilus-preferences.c @@ -0,0 +1,628 @@ + /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ + +/* nautilus-prefs.h - Preference peek/poke/notify object implementation. + + Copyright (C) 1999, 2000 Eazel, Inc. + + The Gnome Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + The Gnome Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the Gnome Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. + + Authors: Ramiro Estrugo <ramiro@eazel.com> +*/ + + +#include <nautilus-widgets/nautilus-preferences.h> +#include <libnautilus/nautilus-gtk-macros.h> + +#include <gtk/gtkclist.h> + +// #include <gtk/gtkmain.h> + +#include <libgnomeui/gnome-stock.h> +#include <gtk/gtkmain.h> +#include <gtk/gtksignal.h> + +#include <stdio.h> + +enum +{ + ACTIVATE, + LAST_SIGNAL +}; + +typedef struct +{ + NautilusPrefInfo pref_info; + gpointer pref_value; + GList *callback_list; +} PrefHashInfo; + +typedef struct +{ + NautilusPrefsCallback callback_proc; + gpointer user_data; + const PrefHashInfo *hash_info; +} PrefCallbackInfo; + +struct _NautilusPrefsPrivate +{ + gchar *domain; + GHashTable *prefs_hash_table; +}; + +/* NautilusPrefsClass methods */ +static void nautilus_prefs_initialize_class (NautilusPrefsClass *klass); +static void nautilus_prefs_initialize (NautilusPrefs *prefs); + + + + +/* GtkObjectClass methods */ +static void prefs_destroy (GtkObject *object); + + + + +/* PrefHashInfo functions */ +static PrefHashInfo * pref_hash_info_alloc (const NautilusPrefInfo *pref_info); +static void pref_hash_info_free (PrefHashInfo *pref_hash_info); +static void pref_hash_info_free_func (gpointer key, + gpointer value, + gpointer user_data); + +/* PrefCallbackInfo functions */ +static PrefCallbackInfo * pref_callback_info_alloc (NautilusPrefsCallback callback_proc, + gpointer user_data, + const PrefHashInfo *hash_info); +static void pref_callback_info_free (PrefCallbackInfo *pref_hash_info); +static void pref_callback_info_free_func (gpointer data, + gpointer user_data); +static void pref_callback_info_invoke_func (gpointer data, + gpointer user_data); +static void pref_hash_info_add_callback (PrefHashInfo *pref_hash_info, + NautilusPrefsCallback callback_proc, + gpointer user_data); + +/* Private stuff */ +static GtkFundamentalType prefs_check_supported_type (GtkFundamentalType pref_type); +static gboolean prefs_set_pref (NautilusPrefs *prefs, + const gchar *pref_name, + gpointer pref_value); +static gboolean prefs_get_pref (NautilusPrefs *prefs, + const gchar *pref_name, + GtkFundamentalType *pref_type_out, + gconstpointer *pref_value_out); +PrefHashInfo * prefs_hash_lookup (NautilusPrefs *prefs, + const gchar *pref_name); + +NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusPrefs, nautilus_prefs, GTK_TYPE_OBJECT) + +/* + * NautilusPrefsClass methods + */ +static void +nautilus_prefs_initialize_class (NautilusPrefsClass *prefs_class) +{ + GtkObjectClass *object_class; + + object_class = GTK_OBJECT_CLASS (prefs_class); + + parent_class = gtk_type_class (gtk_object_get_type ()); + + /* GtkObjectClass */ + object_class->destroy = prefs_destroy; +} + +static void +nautilus_prefs_initialize (NautilusPrefs *prefs) +{ + prefs->priv = g_new (NautilusPrefsPrivate, 1); + + prefs->priv->domain = NULL; + + prefs->priv->prefs_hash_table = g_hash_table_new (g_str_hash, + g_str_equal); +} + +/* + * GtkObjectClass methods + */ +static void +prefs_destroy (GtkObject *object) +{ + NautilusPrefs * prefs; + + g_return_if_fail (object != NULL); + g_return_if_fail (NAUTILUS_IS_PREFS (object)); + + prefs = NAUTILUS_PREFS (object); + + if (prefs->priv->domain) + { + g_free (prefs->priv->domain); + prefs->priv->domain = NULL; + } + + if (prefs->priv->prefs_hash_table) + { + g_hash_table_foreach (prefs->priv->prefs_hash_table, + pref_hash_info_free_func, + (gpointer) NULL); + + g_hash_table_destroy (prefs->priv->prefs_hash_table); + + prefs->priv->prefs_hash_table = NULL; + } + + g_free (prefs->priv); + + /* Chain */ + if (GTK_OBJECT_CLASS (parent_class)->destroy != NULL) + (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); +} + +/* + * PrefHashInfo functions + */ +static PrefHashInfo * +pref_hash_info_alloc (const NautilusPrefInfo *pref_info) +{ + PrefHashInfo * pref_hash_info; + + g_assert (pref_info != NULL); + + g_assert (pref_info->pref_name != NULL); + g_assert (pref_info->pref_description != NULL); + + pref_hash_info = g_new (PrefHashInfo, 1); + + pref_hash_info->pref_info.pref_name = g_strdup (pref_info->pref_name); + pref_hash_info->pref_info.pref_description = g_strdup (pref_info->pref_description); + pref_hash_info->pref_info.pref_type = pref_info->pref_type; + pref_hash_info->pref_info.pref_default_value = pref_info->pref_default_value; + pref_hash_info->pref_info.type_data = pref_info->type_data; + + pref_hash_info->pref_value = (gpointer) pref_info->pref_default_value; + pref_hash_info->callback_list = NULL; + + return pref_hash_info; +} + +static void +pref_hash_info_free (PrefHashInfo *pref_hash_info) +{ + g_assert (pref_hash_info != NULL); + + g_assert (pref_hash_info->pref_info.pref_name != NULL); + g_assert (pref_hash_info->pref_info.pref_description != NULL); + + if (pref_hash_info->callback_list) + { + g_list_foreach (pref_hash_info->callback_list, + pref_callback_info_free_func, + (gpointer) NULL); + } + + g_free (pref_hash_info->pref_info.pref_name); + g_free (pref_hash_info->pref_info.pref_description); + + pref_hash_info->pref_info.pref_name = NULL; + pref_hash_info->pref_info.pref_type = GTK_TYPE_INVALID; + pref_hash_info->pref_info.pref_default_value = NULL; + pref_hash_info->pref_info.type_data = NULL; + + pref_hash_info->callback_list = NULL; + pref_hash_info->pref_value = NULL; + + g_free (pref_hash_info); +} + +static void +pref_hash_info_add_callback (PrefHashInfo *pref_hash_info, + NautilusPrefsCallback callback_proc, + gpointer user_data) +{ + PrefCallbackInfo * pref_callback_info; + + g_assert (pref_hash_info != NULL); + + g_assert (callback_proc != NULL); + + pref_callback_info = pref_callback_info_alloc (callback_proc, + user_data, + pref_hash_info); + + pref_hash_info->callback_list = + g_list_append (pref_hash_info->callback_list, + (gpointer) pref_callback_info); +} + +static void +pref_hash_info_free_func (gpointer key, + gpointer value, + gpointer user_data) +{ + PrefHashInfo *pref_hash_info; + + pref_hash_info = (PrefHashInfo *) value; + + g_assert (pref_hash_info != NULL); + + pref_hash_info_free (pref_hash_info); +} + +/* + * PrefCallbackInfo functions + */ +static PrefCallbackInfo * +pref_callback_info_alloc (NautilusPrefsCallback callback_proc, + gpointer user_data, + const PrefHashInfo *hash_info) +{ + PrefCallbackInfo * pref_callback_info; + + g_assert (callback_proc != NULL); + + pref_callback_info = g_new (PrefCallbackInfo, 1); + + pref_callback_info->callback_proc = callback_proc; + pref_callback_info->user_data = user_data; + pref_callback_info->hash_info = hash_info; + + return pref_callback_info; +} + +static void +pref_callback_info_free (PrefCallbackInfo *pref_callback_info) +{ + g_assert (pref_callback_info != NULL); + + pref_callback_info->callback_proc = NULL; + pref_callback_info->user_data = NULL; + + g_free (pref_callback_info); +} + +static void +pref_callback_info_free_func (gpointer data, + gpointer user_data) +{ + PrefCallbackInfo *pref_callback_info; + + pref_callback_info = (PrefCallbackInfo *) data; + + g_assert (pref_callback_info != NULL); + + pref_callback_info_free (pref_callback_info); +} + +static void +pref_callback_info_invoke_func (gpointer data, + gpointer user_data) +{ + const NautilusPrefs *prefs; + PrefCallbackInfo *pref_callback_info; + + pref_callback_info = (PrefCallbackInfo *) data; + + g_assert (pref_callback_info != NULL); + + g_assert (pref_callback_info->callback_proc != NULL); + + prefs = (const NautilusPrefs *) user_data; + + (*pref_callback_info->callback_proc) (GTK_OBJECT (prefs), + pref_callback_info->hash_info->pref_info.pref_name, + pref_callback_info->hash_info->pref_info.pref_type, + pref_callback_info->hash_info->pref_value, + pref_callback_info->user_data); +} + +/* + * Private stuff + */ +static GtkFundamentalType +prefs_check_supported_type (GtkFundamentalType pref_type) +{ + return ((pref_type == GTK_TYPE_BOOL) || + (pref_type == GTK_TYPE_INT) || + (pref_type == GTK_TYPE_ENUM)); +} + +static gboolean +prefs_set_pref (NautilusPrefs *prefs, + const gchar *pref_name, + gpointer pref_value) +{ + PrefHashInfo * pref_hash_info; + + g_return_val_if_fail (prefs != NULL, FALSE); + g_return_val_if_fail (NAUTILUS_IS_PREFS (prefs), FALSE); + g_return_val_if_fail (pref_name != NULL, FALSE); + + pref_hash_info = prefs_hash_lookup (prefs, pref_name); + + if (!pref_hash_info) + { + return FALSE; + } + + /* + * XXX FIXME: When we support GTK_TYPE_STRING, this + * will have to strcpy() the given value + */ + pref_hash_info->pref_value = pref_value; + + if (pref_hash_info->callback_list) + { + g_list_foreach (pref_hash_info->callback_list, + pref_callback_info_invoke_func, + (gpointer) prefs); + } + + return TRUE; +} + +static gboolean +prefs_get_pref (NautilusPrefs *prefs, + const gchar *pref_name, + GtkFundamentalType *pref_type_out, + gconstpointer *pref_value_out) +{ + PrefHashInfo * pref_hash_info; + + g_return_val_if_fail (prefs != NULL, FALSE); + g_return_val_if_fail (NAUTILUS_IS_PREFS (prefs), FALSE); + g_return_val_if_fail (pref_type_out != NULL, FALSE); + g_return_val_if_fail (pref_value_out != NULL, FALSE); + + if (!pref_hash_info) + { + return FALSE; + } + + pref_hash_info = prefs_hash_lookup (prefs, pref_name); + +// printf("looking for %s\n", pref_name); + + g_assert (pref_hash_info != NULL); + +// printf("pref_name = %s\n", pref_hash_info->pref_info.pref_name); +// printf("pref_desc = %s\n", pref_hash_info->pref_info.pref_description); +// printf("pref_type = %d\n", pref_hash_info->pref_info.pref_type); + + *pref_type_out = pref_hash_info->pref_info.pref_type; + *pref_value_out = pref_hash_info->pref_value; + + return TRUE; +} + +/* + * NautilusPrefs public methods + */ +GtkObject * +nautilus_prefs_new (const gchar *domain) +{ + NautilusPrefs *prefs; + + g_return_val_if_fail (domain != NULL, NULL); + + prefs = gtk_type_new (nautilus_prefs_get_type ()); + + return GTK_OBJECT (prefs); +} + +void +nautilus_prefs_register_from_info (NautilusPrefs *prefs, + const NautilusPrefInfo *pref_info) +{ + PrefHashInfo * pref_hash_info; + + g_return_if_fail (prefs != NULL); + g_return_if_fail (NAUTILUS_IS_PREFS (prefs)); + + g_return_if_fail (pref_info != NULL); + + g_return_if_fail (pref_info->pref_name != NULL); + g_return_if_fail (prefs_check_supported_type (pref_info->pref_type)); + + pref_hash_info = prefs_hash_lookup (prefs, pref_info->pref_name); + + if (pref_hash_info) + { + g_warning ("the '%s' preference is already registered.\n", pref_info->pref_name); + + return; + } + +// printf ("%s is being registered\n", pref_info->pref_name); + + pref_hash_info = pref_hash_info_alloc (pref_info); + + g_hash_table_insert (prefs->priv->prefs_hash_table, + (gpointer) pref_info->pref_name, + (gpointer) pref_hash_info); +} + +void +nautilus_prefs_register_from_values (NautilusPrefs *prefs, + gchar *pref_name, + gchar *pref_description, + GtkFundamentalType pref_type, + gconstpointer pref_default_value, + gpointer type_data) +{ + NautilusPrefInfo pref_info; + + g_return_if_fail (prefs != NULL); + g_return_if_fail (NAUTILUS_IS_PREFS (prefs)); + + g_return_if_fail (pref_name != NULL); + g_return_if_fail (pref_description != NULL); + g_return_if_fail (prefs_check_supported_type (pref_type)); + + pref_info.pref_name = pref_name; + pref_info.pref_description = pref_description; + pref_info.pref_type = pref_type; + pref_info.pref_default_value = pref_default_value; + pref_info.type_data = type_data; + + nautilus_prefs_register_from_info (prefs, &pref_info); +} + +const NautilusPrefInfo * +nautilus_prefs_get_pref_info (NautilusPrefs *prefs, + const gchar *pref_name) +{ + PrefHashInfo * pref_hash_info; + + g_return_val_if_fail (prefs != NULL, NULL); + g_return_val_if_fail (NAUTILUS_IS_PREFS (prefs), NULL); + g_return_val_if_fail (pref_name != NULL, NULL); + + pref_hash_info = prefs_hash_lookup (prefs, pref_name); + + g_assert (pref_hash_info != NULL); + + return &pref_hash_info->pref_info; +} + +PrefHashInfo * +prefs_hash_lookup (NautilusPrefs *prefs, + const gchar *pref_name) +{ + gpointer hash_value; + + g_assert (prefs != NULL); + g_assert (pref_name != NULL); + + hash_value = g_hash_table_lookup (prefs->priv->prefs_hash_table, + (gconstpointer) pref_name); + + return (PrefHashInfo *) hash_value; +} + +gboolean +nautilus_prefs_add_callback (NautilusPrefs *prefs, + const gchar *pref_name, + NautilusPrefsCallback callback_proc, + gpointer user_data) +{ + PrefHashInfo * pref_hash_info; + + g_return_val_if_fail (prefs != NULL, FALSE); + g_return_val_if_fail (NAUTILUS_IS_PREFS (prefs), FALSE); + g_return_val_if_fail (pref_name != NULL, FALSE); + g_return_val_if_fail (callback_proc != NULL, FALSE); + + pref_hash_info = prefs_hash_lookup (prefs, pref_name); + + if (!pref_hash_info) + { + g_warning ("trying to add a callback to an unregistered preference.\n"); + + return FALSE; + } + + pref_hash_info_add_callback (pref_hash_info, + callback_proc, + user_data); + + return TRUE; +} + +void +nautilus_prefs_set_boolean (NautilusPrefs *prefs, + const gchar *pref_name, + gboolean boolean_value) +{ + gboolean rv; + + g_return_if_fail (prefs != NULL); + g_return_if_fail (NAUTILUS_IS_PREFS (prefs)); + g_return_if_fail (pref_name != NULL); + + rv = prefs_set_pref (prefs, pref_name, (gpointer) boolean_value); + + g_assert (rv); +} + +gboolean +nautilus_prefs_get_boolean (NautilusPrefs *prefs, + const gchar *pref_name) +{ + gboolean rv; + GtkFundamentalType pref_type; + gconstpointer value; + + g_return_val_if_fail (prefs != NULL, FALSE); + g_return_val_if_fail (NAUTILUS_IS_PREFS (prefs), FALSE); + g_return_val_if_fail (pref_name != NULL, FALSE); + + rv = prefs_get_pref (prefs, pref_name, &pref_type, &value); + + if (!rv) + { + g_warning ("could not get boolean preference '%s'\n", pref_name); + + return FALSE; + } + + g_assert (pref_type == GTK_TYPE_BOOL); + + return (gboolean) value; +} + +void +nautilus_prefs_set_enum (NautilusPrefs *prefs, + const gchar *pref_name, + gint enum_value) +{ + gboolean rv; + + g_return_if_fail (prefs != NULL); + g_return_if_fail (NAUTILUS_IS_PREFS (prefs)); + g_return_if_fail (pref_name != NULL); + + rv = prefs_set_pref (prefs, pref_name, (gpointer) enum_value); + + g_assert (rv); +} + +gint +nautilus_prefs_get_enum (NautilusPrefs *prefs, + const gchar *pref_name) +{ + gboolean rv; + GtkFundamentalType pref_type; + gconstpointer value; + + g_return_val_if_fail (prefs != NULL, FALSE); + g_return_val_if_fail (NAUTILUS_IS_PREFS (prefs), FALSE); + g_return_val_if_fail (pref_name != NULL, FALSE); + + rv = prefs_get_pref (prefs, pref_name, &pref_type, &value); + + if (!rv) + { + g_warning ("could not get enum preference '%s'\n", pref_name); + + return FALSE; + } + + g_assert (pref_type == GTK_TYPE_ENUM); + + return (gint) value; +} diff --git a/libnautilus-extensions/nautilus-preferences.h b/libnautilus-extensions/nautilus-preferences.h new file mode 100644 index 000000000..cfe709730 --- /dev/null +++ b/libnautilus-extensions/nautilus-preferences.h @@ -0,0 +1,116 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ + +/* nautilus-prefs.h - Preference peek/poke/notify object interface. + + Copyright (C) 1999, 2000 Eazel, Inc. + + The Gnome Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + The Gnome Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the Gnome Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. + + Authors: Ramiro Estrugo <ramiro@eazel.com> +*/ + +#ifndef NAUTILUS_PREFS_H +#define NAUTILUS_PREFS_H + +#include <gtk/gtkhbox.h> +#include <nautilus-widgets/nautilus-preferences-pane.h> + +//#include <gnome.h> + +BEGIN_GNOME_DECLS + +#define NAUTILUS_TYPE_PREFS (nautilus_prefs_get_type ()) +#define NAUTILUS_PREFS(obj) (GTK_CHECK_CAST ((obj), NAUTILUS_TYPE_PREFS, NautilusPrefs)) +#define NAUTILUS_PREFS_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), NAUTILUS_TYPE_PREFS, NautilusPrefsClass)) +#define NAUTILUS_IS_PREFS(obj) (GTK_CHECK_TYPE ((obj), NAUTILUS_TYPE_PREFS)) +#define NAUTILUS_IS_PREFS_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), NAUTILUS_TYPE_PREFS)) + +typedef struct _NautilusPrefs NautilusPrefs; +typedef struct _NautilusPrefsClass NautilusPrefsClass; +typedef struct _NautilusPrefsPrivate NautilusPrefsPrivate; + +struct _NautilusPrefs +{ + /* Super Class */ + GtkObject object; + + /* Private stuff */ + NautilusPrefsPrivate *priv; +}; + +typedef void (*NautilusPrefsCallback) (const GtkObject *prefs, + const gchar *pref_name, + GtkFundamentalType pref_type, + gconstpointer pref_value, + gpointer user_data); + +struct _NautilusPrefsClass +{ + GtkObjectClass object_class; + +// void (*activate) (GtkWidget * prefs, gint entry_number); +}; + +typedef struct +{ + gchar *pref_name; + gchar *pref_description; + GtkFundamentalType pref_type; + gconstpointer pref_default_value; + gpointer type_data; +} NautilusPrefInfo; + +typedef struct +{ + const gchar **enum_names; + const gchar **enum_descriptions; + const gint *enum_values; + guint num_entries; +} NautilusPrefEnumData; + +GtkType nautilus_prefs_get_type (void); +GtkObject* nautilus_prefs_new (const gchar *domain); +void nautilus_prefs_register_from_info (NautilusPrefs *prefs, + const NautilusPrefInfo *pref_info); +void nautilus_prefs_register_from_values (NautilusPrefs *prefs, + gchar *pref_name, + gchar *pref_description, + GtkFundamentalType pref_type, + gconstpointer pref_default_value, + gpointer type_data); +const NautilusPrefInfo *nautilus_prefs_get_pref_info (NautilusPrefs *prefs, + const gchar *pref_name); +gboolean nautilus_prefs_add_callback (NautilusPrefs *prefs, + const gchar *pref_name, + NautilusPrefsCallback callback, + gpointer user_data); +void nautilus_prefs_set_boolean (NautilusPrefs *prefs, + const gchar *pref_name, + gboolean boolean_value); +gboolean nautilus_prefs_get_boolean (NautilusPrefs *prefs, + const gchar *pref_name); +void nautilus_prefs_set_enum (NautilusPrefs *prefs, + const gchar *pref_name, + gint enum_value); +gint nautilus_prefs_get_enum (NautilusPrefs *prefs, + const gchar *pref_name); + + +BEGIN_GNOME_DECLS + +#endif /* NAUTILUS_PREFS_H */ + + diff --git a/libnautilus-extensions/nautilus-radio-button-group.c b/libnautilus-extensions/nautilus-radio-button-group.c index 07f51397d..509afe7de 100644 --- a/libnautilus-extensions/nautilus-radio-button-group.c +++ b/libnautilus-extensions/nautilus-radio-button-group.c @@ -276,3 +276,22 @@ nautilus_radio_button_group_get_active_index (NautilusRadioButtonGroup *button_g return 0; } + +void +nautilus_radio_button_group_set_active_index (NautilusRadioButtonGroup *button_group, + guint active_index) +{ + GList *node; + + g_return_if_fail (button_group != NULL); + g_return_if_fail (NAUTILUS_IS_RADIO_BUTTON_GROUP (button_group)); + + node = g_list_nth (button_group->details->buttons, active_index); + + g_assert (node != NULL); + + g_assert (GTK_TOGGLE_BUTTON (node->data)); + + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (node->data), TRUE); +} + diff --git a/libnautilus-extensions/nautilus-radio-button-group.h b/libnautilus-extensions/nautilus-radio-button-group.h index a9b8ad2c2..7d7dffb7c 100644 --- a/libnautilus-extensions/nautilus-radio-button-group.h +++ b/libnautilus-extensions/nautilus-radio-button-group.h @@ -72,6 +72,10 @@ guint nautilus_radio_button_group_insert (NautilusRadioButtonGro /* Get the active item index. By law there always is an active item */ guint nautilus_radio_button_group_get_active_index (NautilusRadioButtonGroup *button_group); +/* Set the active item index. */ +void nautilus_radio_button_group_set_active_index (NautilusRadioButtonGroup *button_group, + guint active_index); + BEGIN_GNOME_DECLS #endif /* NAUTILUS_RADIO_BUTTON_GROUP_H */ diff --git a/libnautilus-extensions/test-nautilus-widgets.c b/libnautilus-extensions/test-nautilus-widgets.c index 85eee70e7..ad86e92a1 100644 --- a/libnautilus-extensions/test-nautilus-widgets.c +++ b/libnautilus-extensions/test-nautilus-widgets.c @@ -1,17 +1,40 @@ #include <nautilus-widgets/nautilus-radio-button-group.h> +#include <nautilus-widgets/nautilus-preferences-group.h> +#include <nautilus-widgets/nautilus-preferences-item.h> +#include <nautilus-widgets/nautilus-preferences.h> + #include <gtk/gtk.h> #include <stdio.h> static void test_radio_group (void); +static void test_preferences_group (void); +static void test_preferences_item (void); + + static void test_radio_changed_signal (GtkWidget *button_group, gpointer user_data); +static GtkObject * +create_dummy_prefs (void); + +GtkWidget * +create_enum_item (void); + +GtkWidget * +create_bool_item (void); + +static GtkObject * dummy_prefs = NULL; + int main (int argc, char * argv[]) { gtk_init (&argc, &argv); + + dummy_prefs = create_dummy_prefs (); test_radio_group (); + test_preferences_group (); + test_preferences_item (); gtk_main (); @@ -24,6 +47,7 @@ test_radio_group (void) GtkWidget * window; GtkWidget * buttons; + window = gtk_window_new (GTK_WINDOW_TOPLEVEL); buttons = nautilus_radio_button_group_new (); @@ -45,6 +69,49 @@ test_radio_group (void) } static void +test_preferences_item (void) +{ + GtkWidget * window; + GtkWidget * item; + + window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + + item = create_enum_item (); + + gtk_container_add (GTK_CONTAINER (window), item); + + gtk_widget_show (item); + + gtk_widget_show (window); +} + +static void +test_preferences_group (void) +{ + GtkWidget * window; + GtkWidget * group; + + GtkWidget * item; + + window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + + group = nautilus_preferences_group_new ("A group"); + + item = create_enum_item (); + + nautilus_preferences_group_add (NAUTILUS_PREFERENCES_GROUP (group), + item); + + gtk_widget_show (item); + + gtk_container_add (GTK_CONTAINER (window), group); + + gtk_widget_show (group); + + gtk_widget_show (window); +} + +static void test_radio_changed_signal (GtkWidget *buttons, gpointer user_data) { gint i; @@ -53,3 +120,108 @@ test_radio_changed_signal (GtkWidget *buttons, gpointer user_data) printf ("test_radio_changed_signal (%d)\n", i); } + +GtkWidget * +create_enum_item (void) +{ + GtkWidget * item; + + item = nautilus_preferences_item_new (dummy_prefs, + "user_level", + NAUTILUS_PREFERENCES_ITEM_ENUM); + + return item; +} + +GtkWidget * +create_bool_item (void) +{ + GtkWidget * item; + + item = nautilus_preferences_item_new (dummy_prefs, + "foo", + NAUTILUS_PREFERENCES_ITEM_BOOL); + + return item; +} + + +static const gchar * prefs_global_user_level_names[] = +{ + "novice", + "intermediate", + "hacker", + "ettore" +}; + +static const gchar * prefs_global_user_level_descriptions[] = +{ + "Novice", + "Intermediate", + "Hacker", + "Ettore" +}; + +static const gint prefs_global_user_level_values[] = +{ + 0, + 1, + 2, + 3 +}; + +static NautilusPrefEnumData prefs_global_user_level_data = +{ + prefs_global_user_level_names, + prefs_global_user_level_descriptions, + prefs_global_user_level_values, + 4 +}; + +static NautilusPrefInfo prefs_global_static_pref_info[] = +{ + { + "user_level", + "User Level", + GTK_TYPE_ENUM, + FALSE, + (gpointer) &prefs_global_user_level_data + }, + { + "foo", + "Create new window for each new page", + GTK_TYPE_BOOL, + FALSE, + NULL + }, + { + "bar", + "Do not open more than one window with the same page", + GTK_TYPE_BOOL, + FALSE, + NULL + }, +}; + +static GtkObject * +create_dummy_prefs (void) +{ + GtkObject * dummy_prefs; + guint i; + + dummy_prefs = nautilus_prefs_new ("dummy"); + + /* Register the static prefs */ + for (i = 0; i < 3; i++) + { + nautilus_prefs_register_from_info (NAUTILUS_PREFS (dummy_prefs), + &prefs_global_static_pref_info[i]); + } + + + nautilus_prefs_set_enum (NAUTILUS_PREFS (dummy_prefs), + "user_level", + 2); + + return dummy_prefs; +} diff --git a/libnautilus-extensions/test-preferences.c b/libnautilus-extensions/test-preferences.c new file mode 100644 index 000000000..a2d1de8b6 --- /dev/null +++ b/libnautilus-extensions/test-preferences.c @@ -0,0 +1,227 @@ + +#include <nautilus-widgets/nautilus-radio-button-group.h> +#include <nautilus-widgets/nautilus-preferences-group.h> +#include <nautilus-widgets/nautilus-preferences-item.h> +#include <nautilus-widgets/nautilus-preferences.h> + +#include <gtk/gtk.h> +#include <stdio.h> + +static void test_radio_group (void); +static void test_preferences_group (void); +static void test_preferences_item (void); + + +static void test_radio_changed_signal (GtkWidget *button_group, gpointer user_data); + +static GtkObject * +create_dummy_prefs (void); + +GtkWidget * +create_enum_item (void); + +GtkWidget * +create_bool_item (void); + +static GtkObject * dummy_prefs = NULL; + +int +main (int argc, char * argv[]) +{ + gtk_init (&argc, &argv); + + dummy_prefs = create_dummy_prefs (); + +// test_radio_group (); + test_preferences_group (); + test_preferences_item (); + + gtk_main (); + + return 0; +} + +static void +test_radio_group (void) +{ + GtkWidget * window; + GtkWidget * buttons; + + + window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + + buttons = nautilus_radio_button_group_new (); + + nautilus_radio_button_group_insert (NAUTILUS_RADIO_BUTTON_GROUP (buttons), "Apples"); + nautilus_radio_button_group_insert (NAUTILUS_RADIO_BUTTON_GROUP (buttons), "Oranges"); + nautilus_radio_button_group_insert (NAUTILUS_RADIO_BUTTON_GROUP (buttons), "Strawberries"); + + gtk_signal_connect (GTK_OBJECT (buttons), + "changed", + GTK_SIGNAL_FUNC (test_radio_changed_signal), + (gpointer) NULL); + + gtk_container_add (GTK_CONTAINER (window), buttons); + + gtk_widget_show (buttons); + + gtk_widget_show (window); +} + +static void +test_preferences_item (void) +{ + GtkWidget * window; + GtkWidget * item; + + window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + + item = create_enum_item (); + + gtk_container_add (GTK_CONTAINER (window), item); + + gtk_widget_show (item); + + gtk_widget_show (window); +} + +static void +test_preferences_group (void) +{ + GtkWidget * window; + GtkWidget * group; + + GtkWidget * item; + + window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + + group = nautilus_preferences_group_new ("A group"); + + item = create_enum_item (); + + nautilus_preferences_group_add (NAUTILUS_PREFERENCES_GROUP (group), + item); + + gtk_widget_show (item); + + gtk_container_add (GTK_CONTAINER (window), group); + + gtk_widget_show (group); + + gtk_widget_show (window); +} + +static void +test_radio_changed_signal (GtkWidget *buttons, gpointer user_data) +{ + gint i; + + i = nautilus_radio_button_group_get_active_index (NAUTILUS_RADIO_BUTTON_GROUP (buttons)); + + printf ("test_radio_changed_signal (%d)\n", i); +} + +GtkWidget * +create_enum_item (void) +{ + GtkWidget * item; + + item = nautilus_preferences_item_new (dummy_prefs, + "user_level", + NAUTILUS_PREFERENCES_ITEM_ENUM); + + return item; +} + +GtkWidget * +create_bool_item (void) +{ + GtkWidget * item; + + item = nautilus_preferences_item_new (dummy_prefs, + "foo", + NAUTILUS_PREFERENCES_ITEM_BOOL); + + return item; +} + + +static const gchar * prefs_global_user_level_names[] = +{ + "novice", + "intermediate", + "hacker", + "ettore" +}; + +static const gchar * prefs_global_user_level_descriptions[] = +{ + "Novice", + "Intermediate", + "Hacker", + "Ettore" +}; + +static const gint prefs_global_user_level_values[] = +{ + 0, + 1, + 2, + 3 +}; + +static NautilusPrefEnumData prefs_global_user_level_data = +{ + prefs_global_user_level_names, + prefs_global_user_level_descriptions, + prefs_global_user_level_values, + 4 +}; + +static NautilusPrefInfo prefs_global_static_pref_info[] = +{ + { + "user_level", + "User Level", + GTK_TYPE_ENUM, + FALSE, + (gpointer) &prefs_global_user_level_data + }, + { + "foo", + "Create new window for each new page", + GTK_TYPE_BOOL, + FALSE, + NULL + }, + { + "bar", + "Do not open more than one window with the same page", + GTK_TYPE_BOOL, + FALSE, + NULL + }, +}; + +static GtkObject * +create_dummy_prefs (void) +{ + GtkObject * dummy_prefs; + guint i; + + dummy_prefs = nautilus_prefs_new ("dummy"); + + /* Register the static prefs */ + for (i = 0; i < 3; i++) + { + nautilus_prefs_register_from_info (NAUTILUS_PREFS (dummy_prefs), + &prefs_global_static_pref_info[i]); + } + + + nautilus_prefs_set_enum (NAUTILUS_PREFS (dummy_prefs), + "user_level", + 2); + + return dummy_prefs; +} diff --git a/libnautilus-private/nautilus-preferences-box.c b/libnautilus-private/nautilus-preferences-box.c new file mode 100644 index 000000000..9db4596cf --- /dev/null +++ b/libnautilus-private/nautilus-preferences-box.c @@ -0,0 +1,361 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ + +/* nautilus-prefs-box.h - Implementation for preferences box component. + + Copyright (C) 1999, 2000 Eazel, Inc. + + The Gnome Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + The Gnome Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the Gnome Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. + + Authors: Ramiro Estrugo <ramiro@eazel.com> +*/ + + +#include <nautilus-widgets/nautilus-preferences-box.h> +#include <libnautilus/nautilus-gtk-macros.h> + +#include <gtk/gtkclist.h> + +// #include <gtk/gtkmain.h> + +#include <libgnomeui/gnome-stock.h> +#include <gtk/gtkmain.h> +#include <gtk/gtksignal.h> + +enum +{ + ACTIVATE, + 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; + +typedef struct +{ + gchar *pane_name; + GtkWidget *pane_widget; + gboolean constructed; +} PaneInfo; + +struct _NautilusPrefsBoxPrivate +{ + GtkWidget *category_list; + GtkWidget *pane_container; + + GList *panes; + + gint selected_pane; +}; + +typedef void (*GnomeBoxSignal1) (GtkObject* object, + gint arg1, + gpointer data); + +/* NautilusPrefsBoxClass methods */ +static void nautilus_prefs_box_initialize_class (NautilusPrefsBoxClass *klass); +static void nautilus_prefs_box_initialize (NautilusPrefsBox *prefs_box); + + + +/* GtkObjectClass methods */ +static void nautilus_prefs_box_destroy (GtkObject *object); + + + +/* Misc private stuff */ +static void prefs_box_construct (NautilusPrefsBox *prefs_box); +static void prefs_box_select_pane (NautilusPrefsBox *prefs_box, + guint pane_row); + + + + +/* PaneInfo functions */ +static PaneInfo *pane_info_alloc (const gchar *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); + +NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusPrefsBox, nautilus_prefs_box, GTK_TYPE_HBOX) + +/* + * NautilusPrefsBoxClass methods + */ +static void +nautilus_prefs_box_initialize_class (NautilusPrefsBoxClass *prefs_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 ()); + + /* GtkObjectClass */ + object_class->destroy = nautilus_prefs_box_destroy; +} + +static void +nautilus_prefs_box_initialize (NautilusPrefsBox *prefs_box) +{ + prefs_box->priv = g_new (NautilusPrefsBoxPrivate, 1); + + prefs_box->priv->category_list = NULL; + prefs_box->priv->pane_container = NULL; + prefs_box->priv->panes = NULL; + + prefs_box->priv->selected_pane = PREFS_SELECTED_PANE_UNKNOWN; +} + +/* + * GtkObjectClass methods + */ +static void +nautilus_prefs_box_destroy (GtkObject *object) +{ + NautilusPrefsBox * prefs_box; + + g_return_if_fail (object != NULL); + g_return_if_fail (NAUTILUS_IS_PREFS_BOX (object)); + + prefs_box = NAUTILUS_PREFS_BOX (object); + + if (prefs_box->priv->panes) + { + GList *panes; + + panes = prefs_box->priv->panes; + + while (panes) + { + PaneInfo * info = panes->data; + + g_assert (info != NULL); + + pane_info_free (info); + + panes = panes->next; + } + + g_list_free (prefs_box->priv->panes); + } + + g_free (prefs_box->priv); + + /* Chain */ + if (GTK_OBJECT_CLASS (parent_class)->destroy != NULL) + (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); +} + +/* + * Misc private stuff + */ +static void +prefs_box_construct (NautilusPrefsBox *prefs_box) +{ + g_assert (prefs_box != NULL); + g_assert (prefs_box->priv != NULL); + + g_assert (prefs_box->priv->category_list == NULL); + g_assert (prefs_box->priv->panes == NULL); + + /* Configure ourselves */ + gtk_box_set_homogeneous (GTK_BOX (prefs_box), FALSE); + + gtk_box_set_spacing (GTK_BOX (prefs_box), PREFS_BOX_SPACING); + + /* The category list */ + prefs_box->priv->category_list = + gtk_clist_new (PREFS_BOX_NUM_CATEGORY_COLUMNS); + + gtk_signal_connect (GTK_OBJECT (prefs_box->priv->category_list), + "select_row", + GTK_SIGNAL_FUNC (category_list_select_row), + (gpointer) prefs_box); + + gtk_clist_set_selection_mode (GTK_CLIST (prefs_box->priv->category_list), + GTK_SELECTION_BROWSE); + + gtk_clist_set_column_auto_resize (GTK_CLIST (prefs_box->priv->category_list), + PREFS_BOX_CATEGORY_COLUMN, + TRUE); + + gtk_box_pack_start (GTK_BOX (prefs_box), + prefs_box->priv->category_list, + FALSE, + TRUE, + 0); + + gtk_widget_show (prefs_box->priv->category_list); +} + +static void +prefs_box_select_pane (NautilusPrefsBox *prefs_box, + guint pane_row) +{ + 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->priv != NULL); + g_assert (prefs_box->priv->panes != NULL); + + g_assert (pane_row < g_list_length (prefs_box->priv->panes)); + + pane_node = g_list_nth (prefs_box->priv->panes, pane_row); + + g_assert (pane_node != NULL); + + pane_info = pane_node->data; + + /* Show only the corresponding pane widget */ + pane_iterator = prefs_box->priv->panes; + + while (pane_iterator) + { + PaneInfo * info = pane_iterator->data; + + g_assert (info != NULL); + + if (pane_info == info) + { + /* Construct pane for first time if needed */ + if (!info->constructed) + { + + info->constructed = TRUE; + } + + gtk_widget_show (info->pane_widget); + } + else + { + gtk_widget_hide (info->pane_widget); + } + + pane_iterator = pane_iterator->next; + } +} + +/* + * PaneInfo functions + */ +static PaneInfo * +pane_info_alloc (const gchar *pane_name) +{ + PaneInfo * info; + + g_assert (pane_name != NULL); + + info = g_new (PaneInfo, 1); + + info->pane_name = g_strdup (pane_name); + + return info; +} + +static void +pane_info_free (PaneInfo *info) +{ + g_assert (info != NULL); + + g_free (info->pane_name); + + g_free (info); +} + +/* + * Category list callbacks + */ +static void +category_list_select_row (GtkCList *clist, + gint row, + gint column, + GdkEventButton *event, + gpointer user_data) +{ + NautilusPrefsBox *prefs_box = (NautilusPrefsBox *) user_data; + + g_assert (prefs_box != NULL); + g_assert (NAUTILUS_IS_PREFS_BOX (prefs_box)); + + prefs_box_select_pane (prefs_box, (guint) row); +} + +/* + * NautilusPrefsBox public methods + */ +GtkWidget* +nautilus_prefs_box_new (const gchar *box_title) +{ + NautilusPrefsBox *prefs_box; + + prefs_box = gtk_type_new (nautilus_prefs_box_get_type ()); + + prefs_box_construct (prefs_box); + + return GTK_WIDGET (prefs_box); +} + +GtkWidget * +nautilus_prefs_box_add_pane (NautilusPrefsBox *prefs_box, + const gchar *pane_title, + const gchar *pane_description) +{ + PaneInfo *info; + gint new_row; + gchar *text[PREFS_BOX_NUM_CATEGORY_COLUMNS]; + + 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 (pane_title != NULL, NULL); + g_return_val_if_fail (pane_description != NULL, NULL); + + info = pane_info_alloc (pane_title); + + prefs_box->priv->panes = g_list_append (prefs_box->priv->panes, + (gpointer) info); + + info->pane_widget = nautilus_prefs_pane_new (pane_title, + pane_description); + + gtk_box_pack_start (GTK_BOX (prefs_box), + info->pane_widget, + TRUE, + TRUE, + PREFS_BOX_PANE_LEFT_OFFSET); + + text[PREFS_BOX_CATEGORY_COLUMN] = (gchar *) pane_title; + + new_row = gtk_clist_append (GTK_CLIST (prefs_box->priv->category_list), + text); + + return info->pane_widget; +} diff --git a/libnautilus-private/nautilus-preferences-box.h b/libnautilus-private/nautilus-preferences-box.h new file mode 100644 index 000000000..8aa43cb21 --- /dev/null +++ b/libnautilus-private/nautilus-preferences-box.h @@ -0,0 +1,73 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ + +/* nautilus-prefs-box.h - Interface for preferences box component. + + Copyright (C) 1999, 2000 Eazel, Inc. + + The Gnome Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + The Gnome Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the Gnome Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. + + Authors: Ramiro Estrugo <ramiro@eazel.com> +*/ + +#ifndef NAUTILUS_PREFS_BOX_H +#define NAUTILUS_PREFS_BOX_H + +#include <libgnomeui/gnome-dialog.h> +#include <gtk/gtkhbox.h> +#include <nautilus-widgets/nautilus-preferences-pane.h> + +//#include <gnome.h> + +BEGIN_GNOME_DECLS + +#define NAUTILUS_TYPE_PREFS_BOX (nautilus_prefs_box_get_type ()) +#define NAUTILUS_PREFS_BOX(obj) (GTK_CHECK_CAST ((obj), NAUTILUS_TYPE_PREFS_BOX, NautilusPrefsBox)) +#define NAUTILUS_PREFS_BOX_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), NAUTILUS_TYPE_PREFS_BOX, NautilusPrefsBoxClass)) +#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)) + +typedef struct _NautilusPrefsBox NautilusPrefsBox; +typedef struct _NautilusPrefsBoxClass NautilusPrefsBoxClass; +typedef struct _NautilusPrefsBoxPrivate NautilusPrefsBoxPrivate; + +struct _NautilusPrefsBox +{ + /* Super Class */ + GtkHBox hbox; + + /* Private stuff */ + NautilusPrefsBoxPrivate *priv; +}; + +struct _NautilusPrefsBoxClass +{ + GtkHBoxClass parent_class; + + void (*activate) (GtkWidget * prefs_box, gint entry_number); +}; + +GtkType nautilus_prefs_box_get_type (void); +GtkWidget* nautilus_prefs_box_new (const gchar *box_title); + +GtkWidget* nautilus_prefs_box_add_pane (NautilusPrefsBox *prefs_box, + const gchar *pane_title, + const gchar *pane_description); + +BEGIN_GNOME_DECLS + +#endif /* NAUTILUS_PREFS_BOX_H */ + + diff --git a/libnautilus-private/nautilus-preferences-dialog.c b/libnautilus-private/nautilus-preferences-dialog.c new file mode 100644 index 000000000..72a16badc --- /dev/null +++ b/libnautilus-private/nautilus-preferences-dialog.c @@ -0,0 +1,281 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ + +/* nautilus-preferences-dialog.c - Implementation for preferences dialog. + + Copyright (C) 1999, 2000 Eazel, Inc. + + The Gnome Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + The Gnome Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the Gnome Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. + + Authors: Ramiro Estrugo <ramiro@eazel.com> +*/ + +#include <nautilus-widgets/nautilus-preferences-dialog.h> +#include <libnautilus/nautilus-gtk-macros.h> + +/* #include "caption-table.h" */ + +#include <libgnomeui/gnome-stock.h> +#include <gtk/gtkmain.h> +#include <gtk/gtksignal.h> + +#include <gnome.h> + +enum +{ + ACTIVATE, + LAST_SIGNAL +}; + +struct _NautilusPrefsDialogPrivate +{ + GtkWidget *prefs_box; +}; + +static const gchar * stock_buttons[] = +{ + "OK", + NULL +}; + +static const gint UNKNOWN_BUTTON = -1; +static const gint OK_BUTTON = 0; +static const gint DEFAULT_BUTTON = 0; +static const guint DEFAULT_BORDER_WIDTH = 0; + +static const guint PREFS_DIALOG_DEFAULT_WIDTH = 500; +static const guint PREFS_DIALOG_DEFAULT_HEIGHT = 300; + +enum +{ + COMMAND_ROW = 0, + USERNAME_ROW, + PASSWORD_ROW +}; + +/* NautilusPrefsDialogClass methods */ +static void nautilus_prefs_dialog_initialize_class (NautilusPrefsDialogClass *klass); +static void nautilus_prefs_dialog_initialize (NautilusPrefsDialog *prefs_dialog); + +/* GtkObjectClass methods */ +static void nautilus_prefs_dialog_destroy (GtkObject *object); +static void dialog_clicked (GtkWidget *widget, + gint n, + gpointer data); +static void dialog_show (GtkWidget *widget, + gpointer data); +static void dialog_destroy (GtkWidget *widget, + gpointer data); + +/* Misc private stuff */ +static void nautilus_prefs_dialog_construct (NautilusPrefsDialog *prefs_dialog, + const gchar *dialog_title); + + +NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusPrefsDialog, + nautilus_prefs_dialog, + gnome_dialog_get_type ()) + +/* + * NautilusPrefsDialogClass methods + */ +static void +nautilus_prefs_dialog_initialize_class (NautilusPrefsDialogClass * klass) +{ + GtkObjectClass * object_class; + GtkWidgetClass * widget_class; + + object_class = GTK_OBJECT_CLASS(klass); + widget_class = GTK_WIDGET_CLASS(klass); + + parent_class = gtk_type_class(gnome_dialog_get_type()); + + /* GtkObjectClass */ + object_class->destroy = nautilus_prefs_dialog_destroy; +} + +static void +nautilus_prefs_dialog_initialize (NautilusPrefsDialog * prefs_dialog) +{ + prefs_dialog->priv = g_new (NautilusPrefsDialogPrivate, 1); + + prefs_dialog->priv->prefs_box = NULL; +} + +static void +dialog_clicked(GtkWidget * widget, gint n, gpointer data) +{ + NautilusPrefsDialog * prefs_dialog = (NautilusPrefsDialog *) data; + + g_assert(prefs_dialog); + +// gtk_grab_remove(GTK_WIDGET(prefs_dialog)); + + gtk_widget_hide(GTK_WIDGET(prefs_dialog)); +} + +static void +dialog_show(GtkWidget * widget, gpointer data) +{ + NautilusPrefsDialog * prefs_dialog = (NautilusPrefsDialog *) data; + + g_assert(prefs_dialog); + +// gtk_caption_table_entry_grab_focus(GTK_CAPTION_TABLE(prefs_dialog->priv->table), +// PASSWORD_ROW); +} + +static void +dialog_destroy(GtkWidget * widget, gpointer data) +{ + NautilusPrefsDialog * prefs_dialog = (NautilusPrefsDialog *) data; + + g_assert(prefs_dialog); + +// gtk_grab_remove(GTK_WIDGET(prefs_dialog)); + +// gtk_widget_destroy (widget); +} + +static void +nautilus_prefs_dialog_construct (NautilusPrefsDialog *prefs_dialog, + const gchar *dialog_title) +{ + GnomeDialog *gnome_dialog; + + g_assert (prefs_dialog != NULL); + g_assert (prefs_dialog->priv != NULL); + + g_assert (prefs_dialog->priv->prefs_box == NULL); + + gnome_dialog = GNOME_DIALOG (prefs_dialog); + + gnome_dialog_constructv (gnome_dialog, dialog_title, stock_buttons); + + /* Setup the dialog */ + gtk_window_set_policy (GTK_WINDOW (prefs_dialog), + FALSE, /* allow_shrink */ + TRUE, /* allow_grow */ + FALSE); /* auto_shrink */ + + gtk_widget_set_usize (GTK_WIDGET (prefs_dialog), + PREFS_DIALOG_DEFAULT_WIDTH, + PREFS_DIALOG_DEFAULT_HEIGHT); + + /* Doesnt work in enlightenment or sawmill */ +#if 0 + /* This is supposed to setup the window manager functions */ + gdk_window_set_functions (GTK_WIDGET (prefs_dialog)->window, GDK_FUNC_MOVE | GDK_FUNC_RESIZE); +#endif + +// gdk_window_set_decorations (GTK_WINDOW(prefs_dialog), GDK_DECOR_ALL); + + gtk_window_set_position (GTK_WINDOW (prefs_dialog), GTK_WIN_POS_CENTER); + + gtk_container_set_border_width (GTK_CONTAINER(prefs_dialog), + DEFAULT_BORDER_WIDTH); + + gnome_dialog_set_default (GNOME_DIALOG(prefs_dialog), + DEFAULT_BUTTON); + + gtk_signal_connect (GTK_OBJECT (prefs_dialog), + "clicked", + GTK_SIGNAL_FUNC (dialog_clicked), + (gpointer) prefs_dialog); + + gtk_signal_connect (GTK_OBJECT (prefs_dialog), + "show", + GTK_SIGNAL_FUNC(dialog_show), + (gpointer) prefs_dialog); + + gtk_signal_connect (GTK_OBJECT (prefs_dialog), + "destroy", + GTK_SIGNAL_FUNC (dialog_destroy), + (gpointer) prefs_dialog); + + /* Configure the GNOME_DIALOG's vbox */ + g_assert (gnome_dialog->vbox); + + prefs_dialog->priv->prefs_box = nautilus_prefs_box_new (_("Prefs Box")); + + gtk_box_set_spacing (GTK_BOX (gnome_dialog->vbox), 10); + + gtk_box_pack_start (GTK_BOX (gnome_dialog->vbox), + prefs_dialog->priv->prefs_box, + TRUE, /* expand */ + TRUE, /* fill */ + 0); /* padding */ + + gtk_widget_show (prefs_dialog->priv->prefs_box); +} + +GtkWidget* +nautilus_prefs_dialog_new (const gchar *dialog_title) +{ + NautilusPrefsDialog *prefs_dialog; + + prefs_dialog = gtk_type_new (nautilus_prefs_dialog_get_type ()); + + nautilus_prefs_dialog_construct (prefs_dialog, dialog_title); + + return GTK_WIDGET (prefs_dialog); +} + +/* GtkObjectClass methods */ +static void +nautilus_prefs_dialog_destroy(GtkObject* object) +{ + NautilusPrefsDialog * prefs_dialog; + + g_return_if_fail (object != NULL); + g_return_if_fail (NAUTILUS_IS_PREFS_DIALOG (object)); + + prefs_dialog = NAUTILUS_PREFS_DIALOG(object); + + g_free (prefs_dialog->priv); + + /* Chain */ + if (GTK_OBJECT_CLASS (parent_class)->destroy != NULL) + (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); +} + +gboolean +nautilus_prefs_dialog_run_and_block(NautilusPrefsDialog* prefs_dialog) +{ +// g_return_val_if_fail(prefs_dialog, FALSE); + +// prefs_dialog->priv->last_button_clicked = UNKNOWN_BUTTON; + +// gtk_widget_show_all(GTK_WIDGET(prefs_dialog)); + +// gtk_grab_add(GTK_WIDGET(prefs_dialog)); + +// while (prefs_dialog->priv->last_button_clicked == UNKNOWN_BUTTON) +// gtk_main_iteration(); + +// if (prefs_dialog->priv->last_button_clicked == OK_BUTTON) +// return TRUE; + + return FALSE; +} + +GtkWidget* +nautilus_prefs_dialog_get_prefs_box (NautilusPrefsDialog *prefs_dialog) +{ + g_return_val_if_fail (prefs_dialog != NULL, NULL); + g_return_val_if_fail (NAUTILUS_IS_PREFS_DIALOG (prefs_dialog), NULL); + + return prefs_dialog->priv->prefs_box; +} diff --git a/libnautilus-private/nautilus-preferences-dialog.h b/libnautilus-private/nautilus-preferences-dialog.h new file mode 100644 index 000000000..60637d2a6 --- /dev/null +++ b/libnautilus-private/nautilus-preferences-dialog.h @@ -0,0 +1,71 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ + +/* nautilus-preferences-dialog.h - Interface for preferences dialog. + + Copyright (C) 1999, 2000 Eazel, Inc. + + The Gnome Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + The Gnome Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the Gnome Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. + + Authors: Ramiro Estrugo <ramiro@eazel.com> +*/ + +#ifndef NAUTILUS_PREFS_DIALOG_H +#define NAUTILUS_PREFS_DIALOG_H + +#include <libgnomeui/gnome-dialog.h> +#include <nautilus-widgets/nautilus-preferences-box.h> + +//#include <gnome.h> + +BEGIN_GNOME_DECLS + +#define NAUTILUS_TYPE_PREFS_DIALOG (nautilus_prefs_dialog_get_type ()) +#define NAUTILUS_PREFS_DIALOG(obj) (GTK_CHECK_CAST ((obj), NAUTILUS_TYPE_PREFS_DIALOG, NautilusPrefsDialog)) +#define NAUTILUS_PREFS_DIALOG_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), NAUTILUS_TYPE_PREFS_DIALOG, NautilusPrefsDialogClass)) +#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)) + + +typedef struct _NautilusPrefsDialog NautilusPrefsDialog; +typedef struct _NautilusPrefsDialogClass NautilusPrefsDialogClass; +typedef struct _NautilusPrefsDialogPrivate NautilusPrefsDialogPrivate; + +struct _NautilusPrefsDialog +{ + /* Super Class */ + GnomeDialog gnome_dialog; + + /* Private stuff */ + NautilusPrefsDialogPrivate *priv; +}; + +struct _NautilusPrefsDialogClass +{ + GnomeDialogClass parent_class; + + void (*activate) (GtkWidget * prefs_dialog, gint entry_number); +}; + +GtkType nautilus_prefs_dialog_get_type (void); +GtkWidget* nautilus_prefs_dialog_new (const gchar *dialog_title); +gboolean nautilus_prefs_dialog_run_and_block (NautilusPrefsDialog *prefs_dialog); +GtkWidget* nautilus_prefs_dialog_get_prefs_box (NautilusPrefsDialog *prefs_dialog); + +BEGIN_GNOME_DECLS + +#endif /* NAUTILUS_PREFS_DIALOG_H */ + + diff --git a/libnautilus-private/nautilus-preferences-group.c b/libnautilus-private/nautilus-preferences-group.c new file mode 100644 index 000000000..180c10ab6 --- /dev/null +++ b/libnautilus-private/nautilus-preferences-group.c @@ -0,0 +1,237 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ + +/* nautilus-prefs-group-radio.c - Radio button prefs group implementation. + + Copyright (C) 1999, 2000 Eazel, Inc. + + The Gnome Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + The Gnome Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the Gnome Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. + + Authors: Ramiro Estrugo <ramiro@eazel.com> +*/ + +#include "nautilus-preferences-group.h" +//#include "nautilus-prefs.h" + +#include <gnome.h> +#include <gtk/gtkradiobutton.h> +#include <gtk/gtksignal.h> +#include <libnautilus/nautilus-gtk-macros.h> + +/* Signals */ +typedef enum +{ + CHANGED, + LAST_SIGNAL +} RadioGroupSignals; + +typedef struct +{ + GtkWidget *radio_button; +} ButtonInfo; + +struct _NautilusPreferencesGroupPrivate +{ + GtkWidget *main_box; + GtkWidget *content_box; + GtkWidget *description_label; + gboolean show_description; +}; + +static const gint PREFERENCES_GROUP_NOT_FOUND = -1; + +/* NautilusPreferencesGroupClass methods */ +static void nautilus_preferences_group_initialize_class (NautilusPreferencesGroupClass *klass); +static void nautilus_preferences_group_initialize (NautilusPreferencesGroup *preferences_group); + + +/* GtkObjectClass methods */ +static void nautilus_preferences_group_destroy (GtkObject *object); + + +/* NautilusPrefsGroupClass methods */ +static void preferences_group_construct (NautilusPreferencesGroup *prefs_group, + const gchar * title); + +NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusPreferencesGroup, + nautilus_preferences_group, + GTK_TYPE_FRAME); + +/* + * NautilusPreferencesGroupClass methods + */ +static void +nautilus_preferences_group_initialize_class (NautilusPreferencesGroupClass *preferences_group_class) +{ + GtkObjectClass *object_class; + GtkWidgetClass *widget_class; + + object_class = GTK_OBJECT_CLASS (preferences_group_class); + widget_class = GTK_WIDGET_CLASS (preferences_group_class); + + parent_class = gtk_type_class (gtk_frame_get_type ()); + + /* GtkObjectClass */ + object_class->destroy = nautilus_preferences_group_destroy; +} + +static void +nautilus_preferences_group_initialize (NautilusPreferencesGroup *group) +{ + group->priv = g_new (NautilusPreferencesGroupPrivate, 1); + + group->priv->main_box = NULL; + group->priv->content_box = NULL; + group->priv->description_label = NULL; + group->priv->show_description = FALSE; +} + +/* + * GtkObjectClass methods + */ +static void +nautilus_preferences_group_destroy(GtkObject* object) +{ + NautilusPreferencesGroup *group; + + g_return_if_fail (object != NULL); + g_return_if_fail (NAUTILUS_IS_PREFERENCES_GROUP (object)); + + group = NAUTILUS_PREFERENCES_GROUP (object); + + g_free (group->priv); + + /* Chain */ + if (GTK_OBJECT_CLASS (parent_class)->destroy != NULL) + (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); +} + +static void +preferences_group_construct (NautilusPreferencesGroup *group, + const gchar * title) +{ + g_assert (group != NULL); + g_assert (title != NULL); + + g_assert (group->priv->content_box == NULL); + g_assert (group->priv->main_box == NULL); + g_assert (group->priv->description_label == NULL); + +// printf ("preferences_group_construct\n"); + +// pref_info = nautilus_prefs_get_pref_info (NAUTILUS_PREFS (prefs), +// pref_name); + +// g_assert (pref_info != NULL); + +// g_assert (pref_info->pref_description != NULL); + + /* Ourselves */ + gtk_frame_set_shadow_type (GTK_FRAME (group), + GTK_SHADOW_ETCHED_IN); + + +// gtk_object_set (GTK_OBJECT (group), +// "title_string", group_title, +// NULL); + + gtk_frame_set_label (GTK_FRAME (group), title); + + /* Main box */ + group->priv->main_box = gtk_vbox_new (FALSE, 0); + + gtk_container_add (GTK_CONTAINER (group), + group->priv->main_box); + +// gtk_container_set_border_width (GTK_CONTAINER (group->priv->content_box), +// GROUP_FRAME_BORDER_WIDTH); + + /* Description label */ + group->priv->description_label = gtk_label_new ("Blurb"); + + gtk_label_set_justify (GTK_LABEL (group->priv->description_label), + GTK_JUSTIFY_LEFT); + + gtk_box_pack_start (GTK_BOX (group->priv->main_box), + group->priv->description_label, + FALSE, + FALSE, + 0); + + if (group->priv->show_description) + { + gtk_widget_show (group->priv->description_label); + } + + /* Content box */ + group->priv->content_box = + gtk_vbox_new (FALSE, 0); + + gtk_box_pack_start (GTK_BOX (group->priv->main_box), + group->priv->content_box, + FALSE, + FALSE, + 0); + + gtk_container_set_border_width (GTK_CONTAINER (group->priv->content_box), + 4); + + gtk_widget_show (group->priv->content_box); + gtk_widget_show (group->priv->main_box); +} + +/* + * NautilusPreferencesGroup public methods + */ +GtkWidget* +nautilus_preferences_group_new (const gchar *title) +{ + NautilusPreferencesGroup *group; + + g_return_val_if_fail (title != NULL, NULL); + +/* printf("nautilus_preferences_group_new()\n"); */ + + group = gtk_type_new (nautilus_preferences_group_get_type ()); + + preferences_group_construct (group, title); + + return GTK_WIDGET (group); +} + +// void +// nautilus_preferences_group_clear (NautilusPreferencesGroup *preferences_group) +// { +// } + +void +nautilus_preferences_group_add (NautilusPreferencesGroup *group, + GtkWidget *item) +{ + g_return_if_fail (group != NULL); + g_return_if_fail (NAUTILUS_IS_PREFERENCES_GROUP (group)); + g_return_if_fail (item != NULL); + +/* printf("nautilus_preferences_group_add()\n"); */ + + gtk_box_pack_start (GTK_BOX (group->priv->content_box), + item, + TRUE, + TRUE, + 0); + +// gtk_widget_show (item); +} + diff --git a/libnautilus-private/nautilus-preferences-group.h b/libnautilus-private/nautilus-preferences-group.h new file mode 100644 index 000000000..32ff16ffd --- /dev/null +++ b/libnautilus-private/nautilus-preferences-group.h @@ -0,0 +1,67 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ + +/* nautilus-prefs-group-check.h - Check button prefs group interface. + + Copyright (C) 1999, 2000 Eazel, Inc. + + The Gnome Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + The Gnome Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the Gnome Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. + + Authors: Ramiro Estrugo <ramiro@eazel.com> +*/ + +#ifndef NAUTILUS_PREFERENCES_GROUP_H +#define NAUTILUS_PREFERENCES_GROUP_H + +#include <gtk/gtkframe.h> +#include <gnome.h> + +BEGIN_GNOME_DECLS + +#define NAUTILUS_TYPE_PREFERENCES_GROUP (nautilus_preferences_group_get_type ()) +#define NAUTILUS_PREFERENCES_GROUP(obj) (GTK_CHECK_CAST ((obj), NAUTILUS_TYPE_PREFERENCES_GROUP, NautilusPreferencesGroup)) +#define NAUTILUS_PREFERENCES_GROUP_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), NAUTILUS_TYPE_PREFERENCES_GROUP, NautilusPreferencesGroupClass)) +#define NAUTILUS_IS_PREFERENCES_GROUP(obj) (GTK_CHECK_TYPE ((obj), NAUTILUS_TYPE_PREFERENCES_GROUP)) +#define NAUTILUS_IS_PREFERENCES_GROUP_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), NAUTILUS_TYPE_PREFERENCES_GROUP)) + +typedef struct _NautilusPreferencesGroup NautilusPreferencesGroup; +typedef struct _NautilusPreferencesGroupClass NautilusPreferencesGroupClass; +typedef struct _NautilusPreferencesGroupPrivate NautilusPreferencesGroupPrivate; + +struct _NautilusPreferencesGroup +{ + /* Super Class */ + GtkFrame frame; + + /* Private stuff */ + NautilusPreferencesGroupPrivate *priv; +}; + +struct _NautilusPreferencesGroupClass +{ + GtkFrameClass parent_class; +}; + +GtkType nautilus_preferences_group_get_type (void); +GtkWidget* nautilus_preferences_group_new (const gchar *title); + +void nautilus_preferences_group_add (NautilusPreferencesGroup *preferences_group, + GtkWidget *item); + +BEGIN_GNOME_DECLS + +#endif /* NAUTILUS_PREFERENCES_GROUP_H */ + + diff --git a/libnautilus-private/nautilus-preferences-item.c b/libnautilus-private/nautilus-preferences-item.c new file mode 100644 index 000000000..6c636d68f --- /dev/null +++ b/libnautilus-private/nautilus-preferences-item.c @@ -0,0 +1,370 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ + +/* nautilus-preferences-item.c - Implementation for an individual prefs item. + + Copyright (C) 1999, 2000 Eazel, Inc. + + The Gnome Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + The Gnome Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the Gnome Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. + + Authors: Ramiro Estrugo <ramiro@eazel.com> +*/ + +#include "nautilus-preferences-item.h" +#include "nautilus-preferences.h" +#include <libnautilus/nautilus-gtk-macros.h> + +#include <gtk/gtkcheckbutton.h> +#include <nautilus-widgets/nautilus-radio-button-group.h> + +#include <gtk/gtklabel.h> +#include <gtk/gtkframe.h> +#include <gtk/gtkhbox.h> +#include <gtk/gtkvbox.h> + +// #include <gtk/gtkmain.h> +#include <gnome.h> + +#include <libgnomeui/gnome-stock.h> +#include <gtk/gtkmain.h> +#include <gtk/gtksignal.h> + +/* Arguments */ +enum +{ + ARG_0, + ARG_SHOW_DESCRIPTION, + ARG_DESCRIPTION_STRING, + ARG_TITLE_STRING +}; + +enum +{ + ACTIVATE, + LAST_SIGNAL +}; + +static const guint PREFERENCES_ITEM_TITLE_SPACING = 4; +static const guint PREFERENCES_ITEM_FRAME_BORDER_WIDTH = 6; + +struct _NautilusPreferencesItemDetails +{ + gchar *pref_name; + NautilusPreferencesItemType item_type; + GtkWidget *child; + GtkObject *prefs; +}; + +/* NautilusPreferencesItemClass methods */ +static void nautilus_preferences_item_initialize_class (NautilusPreferencesItemClass *klass); +static void nautilus_preferences_item_initialize (NautilusPreferencesItem *preferences_item); + + + +/* GtkObjectClass methods */ +static void preferences_item_destroy (GtkObject *object); +static void preferences_item_set_arg (GtkObject *object, + GtkArg *arg, + guint arg_id); +static void preferences_item_get_arg (GtkObject *object, + GtkArg *arg, + guint arg_id); + +/* Private stuff */ +static void preferences_item_construct (NautilusPreferencesItem *item, + GtkObject *prefs, + const gchar *pref_name, + NautilusPreferencesItemType item_type); + +static void test_radio_changed_signal (GtkWidget *button_group, GtkWidget * button, gpointer user_data); + +NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusPreferencesItem, nautilus_preferences_item, GTK_TYPE_VBOX) + +/* + * NautilusPreferencesItemClass methods + */ +static void +nautilus_preferences_item_initialize_class (NautilusPreferencesItemClass *preferences_item_class) +{ + GtkObjectClass *object_class; + GtkWidgetClass *widget_class; + + object_class = GTK_OBJECT_CLASS (preferences_item_class); + widget_class = GTK_WIDGET_CLASS (preferences_item_class); + + parent_class = gtk_type_class (gtk_vbox_get_type ()); + + /* Arguments */ + gtk_object_add_arg_type ("NautilusPreferencesItem::show_description", + GTK_TYPE_BOOL, + GTK_ARG_READWRITE, + ARG_SHOW_DESCRIPTION); + + gtk_object_add_arg_type ("NautilusPreferencesItem::description_string", + GTK_TYPE_STRING, + GTK_ARG_WRITABLE, + ARG_DESCRIPTION_STRING); + + gtk_object_add_arg_type ("NautilusPreferencesItem::title_string", + GTK_TYPE_STRING, + GTK_ARG_WRITABLE, + ARG_TITLE_STRING); + + /* GtkObjectClass */ + object_class->destroy = preferences_item_destroy; + object_class->set_arg = preferences_item_set_arg; + object_class->get_arg = preferences_item_get_arg; + +// /* NautilusPreferencesItemClass */ +// preferences_item_class->construct = preferences_item_construct; +// preferences_item_class->changed = NULL; +} + +static void +nautilus_preferences_item_initialize (NautilusPreferencesItem *item) +{ + item->details = g_new (NautilusPreferencesItemDetails, 1); + + item->details->pref_name = NULL; + item->details->item_type = NAUTILUS_PREFERENCES_ITEM_UNKNOWN; + item->details->child = NULL; + item->details->prefs = NULL; +} + +/* + * GtkObjectClass methods + */ +static void +preferences_item_destroy (GtkObject *object) +{ + NautilusPreferencesItem * item; + + g_return_if_fail (object != NULL); + g_return_if_fail (NAUTILUS_IS_PREFERENCES_ITEM (object)); + + item = NAUTILUS_PREFERENCES_ITEM (object); + + if (item->details->pref_name) + { + g_free (item->details->pref_name); + } + + g_free (item->details); + + /* Chain */ + if (GTK_OBJECT_CLASS (parent_class)->destroy != NULL) + (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); +} + +static void +preferences_item_set_arg (GtkObject *object, + GtkArg *arg, + guint arg_id) +{ + NautilusPreferencesItem * item; + + g_return_if_fail (object != NULL); + g_return_if_fail (NAUTILUS_IS_PREFERENCES_ITEM (object)); + + item = NAUTILUS_PREFERENCES_ITEM (object); + +#if 0 + switch (arg_id) + { + case ARG_SHOW_DESCRIPTION: + item->details->show_description = GTK_VALUE_BOOL (*arg); + + if (item->details->show_description) + { + gtk_widget_show (item->details->description_label); + } + else + { + gtk_widget_hide (item->details->description_label); + } + + break; + + case ARG_DESCRIPTION_STRING: + + gtk_label_set_text (GTK_LABEL (item->details->description_label), + GTK_VALUE_STRING (*arg)); + break; + + case ARG_TITLE_STRING: + + gtk_frame_set_label (GTK_FRAME (object), GTK_VALUE_STRING (*arg)); + + break; + } +#endif + +} + +static void +preferences_item_get_arg (GtkObject *object, + GtkArg *arg, + guint arg_id) +{ + NautilusPreferencesItem * item; + + g_return_if_fail (object != NULL); + g_return_if_fail (NAUTILUS_IS_PREFERENCES_ITEM (object)); + + item = NAUTILUS_PREFERENCES_ITEM (object); + +#if 0 + switch (arg_id) + { + case ARG_SHOW_DESCRIPTION: + GTK_VALUE_BOOL (*arg) = + GTK_WIDGET_VISIBLE (item->details->description_label); + break; + } +#endif +} + +/* + * Private stuff + */ +static void +preferences_item_construct (NautilusPreferencesItem *item, + GtkObject *prefs, + const gchar *pref_name, + NautilusPreferencesItemType item_type) +{ + g_return_if_fail (item != NULL); + g_return_if_fail (prefs != NULL); + g_return_if_fail (pref_name != NULL); + g_return_if_fail (NAUTILUS_IS_PREFERENCES_ITEM (item)); + + g_return_if_fail (item_type != NAUTILUS_PREFERENCES_ITEM_UNKNOWN); + + g_return_if_fail (item->details->child == NULL); + +// printf("preferences_item_construct (%s)\n", +// pref_name); + + item->details->prefs = prefs; + item->details->pref_name = g_strdup (pref_name); + + switch (item_type) + { + case NAUTILUS_PREFERENCES_ITEM_BOOL: + + item->details->child = gtk_check_button_new_with_label ("BOOL"); + + break; + + case NAUTILUS_PREFERENCES_ITEM_ENUM: + { + const NautilusPrefInfo * pref_info; + NautilusPrefEnumData * enum_info; + guint i; + gint value; + + + item->details->child = nautilus_radio_button_group_new (); + + pref_info = nautilus_prefs_get_pref_info (NAUTILUS_PREFS (prefs), + item->details->pref_name); + + g_assert (pref_info != NULL); + + enum_info = (NautilusPrefEnumData *) pref_info->type_data; + + g_assert (enum_info != NULL); + + + value = nautilus_prefs_get_enum (NAUTILUS_PREFS (prefs), + item->details->pref_name); + + for (i = 0; i < enum_info->num_entries; i++) + { + nautilus_radio_button_group_insert (NAUTILUS_RADIO_BUTTON_GROUP (item->details->child), + enum_info->enum_descriptions[i]); + + if (i == value) + { + nautilus_radio_button_group_set_active_index (NAUTILUS_RADIO_BUTTON_GROUP (item->details->child), i); + + } + } + + gtk_signal_connect (GTK_OBJECT (item->details->child), + "changed", + GTK_SIGNAL_FUNC (test_radio_changed_signal), + (gpointer) item); + } + break; + + case NAUTILUS_PREFERENCES_ITEM_INT: + break; + + case NAUTILUS_PREFERENCES_ITEM_UNKNOWN: + g_assert_not_reached (); + break; + } + + g_assert (item->details->child != NULL); + + gtk_box_pack_start (GTK_BOX (item), + item->details->child, + FALSE, + FALSE, + 0); + + gtk_widget_show (item->details->child); +} + +/* + * NautilusPreferencesItem public methods + */ +GtkWidget * +nautilus_preferences_item_new (GtkObject *prefs, + const gchar *pref_name, + NautilusPreferencesItemType item_type) +{ + NautilusPreferencesItem * item; + + g_return_val_if_fail (prefs != NULL, NULL); + g_return_val_if_fail (pref_name != NULL, NULL); + + item = gtk_type_new (nautilus_preferences_item_get_type ()); + +// printf ("nautilus_preferences_item_new (%s)\n", pref_name); + + preferences_item_construct (item, prefs, pref_name, item_type); + + return GTK_WIDGET (item); +} + +static void +test_radio_changed_signal (GtkWidget *buttons, GtkWidget * button, gpointer user_data) +{ + NautilusPreferencesItem * item = (NautilusPreferencesItem *) user_data; + + gint i; + + g_assert (item != NULL); + + i = nautilus_radio_button_group_get_active_index (NAUTILUS_RADIO_BUTTON_GROUP (buttons)); + +// printf ("test_radio_changed_signal (%s = %d)\n", item->details->pref_name, i); + + nautilus_prefs_set_enum (NAUTILUS_PREFS (item->details->prefs), + item->details->pref_name, + i); +} diff --git a/libnautilus-private/nautilus-preferences-item.h b/libnautilus-private/nautilus-preferences-item.h new file mode 100644 index 000000000..4a9bb30a2 --- /dev/null +++ b/libnautilus-private/nautilus-preferences-item.h @@ -0,0 +1,81 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ + +/* nautilus-preferences-item.h - Interface for an individual prefs item. + + Copyright (C) 1999, 2000 Eazel, Inc. + + The Gnome Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + The Gnome Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the Gnome Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. + + Authors: Ramiro Estrugo <ramiro@eazel.com> +*/ + +#ifndef NAUTILUS_PREFERENCES_ITEM_H +#define NAUTILUS_PREFERENCES_ITEM_H + +#include <gtk/gtkvbox.h> +#include <gnome.h> + +BEGIN_GNOME_DECLS + +#define NAUTILUS_TYPE_PREFERENCES_ITEM (nautilus_preferences_item_get_type ()) +#define NAUTILUS_PREFERENCES_ITEM(obj) (GTK_CHECK_CAST ((obj), NAUTILUS_TYPE_PREFERENCES_ITEM, NautilusPreferencesItem)) +#define NAUTILUS_PREFERENCES_ITEM_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), NAUTILUS_TYPE_PREFERENCES_ITEM, NautilusPreferencesItemClass)) +#define NAUTILUS_IS_PREFERENCES_ITEM(obj) (GTK_CHECK_TYPE ((obj), NAUTILUS_TYPE_PREFERENCES_ITEM)) +#define NAUTILUS_IS_PREFERENCES_ITEM_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), NAUTILUS_TYPE_PREFERENCES_ITEM)) + +typedef struct _NautilusPreferencesItem NautilusPreferencesItem; +typedef struct _NautilusPreferencesItemClass NautilusPreferencesItemClass; +typedef struct _NautilusPreferencesItemDetails NautilusPreferencesItemDetails; + +typedef enum +{ + NAUTILUS_PREFERENCES_ITEM_UNKNOWN, + NAUTILUS_PREFERENCES_ITEM_BOOL, + NAUTILUS_PREFERENCES_ITEM_ENUM, + NAUTILUS_PREFERENCES_ITEM_INT +} NautilusPreferencesItemType; + +struct _NautilusPreferencesItem +{ + /* Super Class */ + GtkVBox vbox; + + /* Private stuff */ + NautilusPreferencesItemDetails *details; +}; + +struct _NautilusPreferencesItemClass +{ + GtkVBoxClass vbox_class; + +// void (*construct) (NautilusPreferencesItem *preferences_item, +// const gchar * group_title, +// GtkObject *prefs, +// const gchar *pref_name); + +// void (*changed) (NautilusPreferencesItem *preferences_item); +}; + +GtkType nautilus_preferences_item_get_type (void); +GtkWidget* nautilus_preferences_item_new (GtkObject *prefs, + const gchar *pref_name, + NautilusPreferencesItemType item_type); + +BEGIN_GNOME_DECLS + +#endif /* NAUTILUS_PREFERENCES_ITEM_H */ + + diff --git a/libnautilus-private/nautilus-preferences-pane.c b/libnautilus-private/nautilus-preferences-pane.c new file mode 100644 index 000000000..647858eec --- /dev/null +++ b/libnautilus-private/nautilus-preferences-pane.c @@ -0,0 +1,283 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ + +/* nautilus-preferences-pane.h - Interface for a prefs pane superclass. + + Copyright (C) 1999, 2000 Eazel, Inc. + + The Gnome Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + The Gnome Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the Gnome Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. + + Authors: Ramiro Estrugo <ramiro@eazel.com> +*/ + + +#include <nautilus-widgets/nautilus-preferences-pane.h> +#include <libnautilus/nautilus-gtk-macros.h> + +#include <gtk/gtklabel.h> +#include <gtk/gtkframe.h> +#include <gtk/gtkhbox.h> + +// #include <gtk/gtkmain.h> +#include <gnome.h> + +#include <libgnomeui/gnome-stock.h> +#include <gtk/gtkmain.h> +#include <gtk/gtksignal.h> + +enum +{ + ACTIVATE, + LAST_SIGNAL +}; + +static const guint PREFS_PANE_GROUPS_BOX_TOP_OFFSET = 0; + +struct _NautilusPrefsPanePrivate +{ + GtkWidget *title_box; + GtkWidget *title_frame; + GtkWidget *title_label; + GtkWidget *description_label; + + GtkWidget *groups_box; + + gboolean show_title; + + GSList *groups; +}; + +typedef void (*GnomeBoxSignal1) (GtkObject* object, + gint arg1, + gpointer data); + +/* NautilusPrefsPaneClass methods */ +static void nautilus_prefs_pane_initialize_class (NautilusPrefsPaneClass *klass); +static void nautilus_prefs_pane_initialize (NautilusPrefsPane *prefs_pane); + +/* GtkObjectClass methods */ +static void nautilus_prefs_pane_destroy (GtkObject *object); + +/* Private stuff */ +static void prefs_pane_construct (NautilusPrefsPane *prefs_pane, + const gchar *pane_title, + const gchar *pane_description); + +NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusPrefsPane, nautilus_prefs_pane, GTK_TYPE_VBOX) + +/* + * NautilusPrefsPaneClass methods + */ +static void +nautilus_prefs_pane_initialize_class (NautilusPrefsPaneClass *prefs_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 ()); + + /* GtkObjectClass */ + object_class->destroy = nautilus_prefs_pane_destroy; +} + +static void +nautilus_prefs_pane_initialize (NautilusPrefsPane *prefs_pane) +{ + prefs_pane->priv = g_new (NautilusPrefsPanePrivate, 1); + + prefs_pane->priv->title_label = NULL; + prefs_pane->priv->description_label = NULL; + prefs_pane->priv->title_box = NULL; + prefs_pane->priv->title_frame = NULL; + prefs_pane->priv->groups_box = NULL; + prefs_pane->priv->groups = NULL; + prefs_pane->priv->show_title = FALSE; +} + +/* + * GtkObjectClass methods + */ +static void +nautilus_prefs_pane_destroy(GtkObject* object) +{ + NautilusPrefsPane * prefs_pane; + + g_return_if_fail (object != NULL); + g_return_if_fail (NAUTILUS_IS_PREFS_PANE (object)); + + prefs_pane = NAUTILUS_PREFS_PANE (object); + + if (prefs_pane->priv->groups) + { + g_slist_free (prefs_pane->priv->groups); + } + + g_free (prefs_pane->priv); + + /* Chain */ + if (GTK_OBJECT_CLASS (parent_class)->destroy != NULL) + (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); +} + +/* + * Private stuff + */ +static void +prefs_pane_construct (NautilusPrefsPane *prefs_pane, + const gchar *pane_title, + const gchar *pane_description) +{ + g_assert (prefs_pane != NULL); + g_assert (prefs_pane->priv != NULL); + + g_assert (pane_title != NULL); + g_assert (pane_description != NULL); + + g_assert (prefs_pane->priv->title_label == NULL); + g_assert (prefs_pane->priv->description_label == NULL); + g_assert (prefs_pane->priv->title_box == NULL); + g_assert (prefs_pane->priv->groups_box == NULL); + g_assert (prefs_pane->priv->title_frame == NULL); + g_assert (prefs_pane->priv->groups == NULL); + + prefs_pane->priv->groups = g_slist_alloc (); + + if (prefs_pane->priv->show_title) + { + /* Title frame */ + prefs_pane->priv->title_frame = gtk_frame_new (NULL); + + gtk_frame_set_shadow_type (GTK_FRAME (prefs_pane->priv->title_frame), + GTK_SHADOW_ETCHED_IN); + + /* Title box */ + prefs_pane->priv->title_box = gtk_hbox_new (FALSE, 0); + + /* Title labels */ + prefs_pane->priv->title_label = gtk_label_new (pane_title); + prefs_pane->priv->description_label = gtk_label_new (pane_description); + + gtk_box_pack_start (GTK_BOX (prefs_pane->priv->title_box), + prefs_pane->priv->title_label, + FALSE, + FALSE, + 0); + + gtk_box_pack_end (GTK_BOX (prefs_pane->priv->title_box), + prefs_pane->priv->description_label, + FALSE, + FALSE, + 0); + + gtk_widget_show (prefs_pane->priv->title_label); + gtk_widget_show (prefs_pane->priv->description_label); + + /* Add title box to title frame */ + gtk_container_add (GTK_CONTAINER (prefs_pane->priv->title_frame), + prefs_pane->priv->title_box); + + gtk_widget_show (prefs_pane->priv->title_box); + + /* Add title frame to ourselves */ + gtk_box_pack_start (GTK_BOX (prefs_pane), + prefs_pane->priv->title_frame, + FALSE, + FALSE, + 0); + + gtk_widget_show (prefs_pane->priv->title_frame); + } + + /* Groups box */ + prefs_pane->priv->groups_box = gtk_vbox_new (TRUE, 0); + + /* Add groups box to ourselves */ + gtk_box_pack_start (GTK_BOX (prefs_pane), + prefs_pane->priv->groups_box, + FALSE, + FALSE, + PREFS_PANE_GROUPS_BOX_TOP_OFFSET); + + gtk_widget_show (prefs_pane->priv->groups_box); +} + + +/* + * NautilusPrefsPane public methods + */ +GtkWidget* +nautilus_prefs_pane_new (const gchar *pane_title, + const gchar *pane_description) +{ + NautilusPrefsPane *prefs_pane; + + g_return_val_if_fail (pane_title != NULL, NULL); + g_return_val_if_fail (pane_description != NULL, NULL); + + prefs_pane = gtk_type_new (nautilus_prefs_pane_get_type ()); + + prefs_pane_construct (prefs_pane, pane_title, pane_description); + + return GTK_WIDGET (prefs_pane); +} + +void +nautilus_prefs_pane_set_title (NautilusPrefsPane *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->priv->title_label != NULL); + + gtk_label_set_text (GTK_LABEL (prefs_pane->priv->title_label), + pane_title); +} + +void +nautilus_prefs_pane_set_description (NautilusPrefsPane *prefs_pane, + const gchar *pane_description) +{ + g_return_if_fail (prefs_pane != NULL); + g_return_if_fail (NAUTILUS_IS_PREFS_PANE (prefs_pane)); + + g_assert (prefs_pane->priv->description_label != NULL); + + gtk_label_set_text (GTK_LABEL (prefs_pane->priv->description_label), + pane_description); +} + +void +nautilus_prefs_pane_add_group (NautilusPrefsPane *prefs_pane, + GtkWidget *prefs_group) +{ + g_return_if_fail (prefs_pane != NULL); + g_return_if_fail (NAUTILUS_IS_PREFS_PANE (prefs_pane)); + g_return_if_fail (prefs_group != NULL); + +// group = nautilus_prefs_group_new (group_title); + + gtk_box_pack_start (GTK_BOX (prefs_pane->priv->groups_box), + prefs_group, + TRUE, + TRUE, + 0); + +// gtk_widget_show (prefs_group); +} + diff --git a/libnautilus-private/nautilus-preferences-pane.h b/libnautilus-private/nautilus-preferences-pane.h new file mode 100644 index 000000000..3a7674b30 --- /dev/null +++ b/libnautilus-private/nautilus-preferences-pane.h @@ -0,0 +1,74 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ + +/* nautilus-preferences-pane.h - Interface for a prefs pane superclass. + + Copyright (C) 1999, 2000 Eazel, Inc. + + The Gnome Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + The Gnome Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the Gnome Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. + + Authors: Ramiro Estrugo <ramiro@eazel.com> +*/ + +#ifndef NAUTILUS_PREFS_PANE_H +#define NAUTILUS_PREFS_PANE_H + +#include <libgnomeui/gnome-dialog.h> +#include <gtk/gtkvbox.h> +#include <nautilus-widgets/nautilus-preferences-group.h> + +//#include <gnome.h> + +BEGIN_GNOME_DECLS + +#define NAUTILUS_TYPE_PREFS_PANE (nautilus_prefs_pane_get_type ()) +#define NAUTILUS_PREFS_PANE(obj) (GTK_CHECK_CAST ((obj), NAUTILUS_TYPE_PREFS_PANE, NautilusPrefsPane)) +#define NAUTILUS_PREFS_PANE_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), NAUTILUS_TYPE_PREFS_PANE, NautilusPrefsPaneClass)) +#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)) + +typedef struct _NautilusPrefsPane NautilusPrefsPane; +typedef struct _NautilusPrefsPaneClass NautilusPrefsPaneClass; +typedef struct _NautilusPrefsPanePrivate NautilusPrefsPanePrivate; + +struct _NautilusPrefsPane +{ + /* Super Class */ + GtkVBox vbox; + + /* Private stuff */ + NautilusPrefsPanePrivate *priv; +}; + +struct _NautilusPrefsPaneClass +{ + GtkVBoxClass parent_class; + + void (*construct) (NautilusPrefsPane *prefs_pane, GtkWidget *box); +}; + +GtkType nautilus_prefs_pane_get_type (void); +GtkWidget* nautilus_prefs_pane_new (const gchar *pane_title, + const gchar *pane_description); +void nautilus_prefs_pane_set_title (NautilusPrefsPane * prefs_pane, + const gchar *pane_title); +void nautilus_prefs_pane_set_description (NautilusPrefsPane * prefs_pane, + const gchar *pane_description); +void nautilus_prefs_pane_add_group (NautilusPrefsPane *prefs_pane, + GtkWidget *prefs_group); + +BEGIN_GNOME_DECLS + +#endif /* NAUTILUS_PREFS_PANE_H */ diff --git a/libnautilus-private/nautilus-preferences.c b/libnautilus-private/nautilus-preferences.c new file mode 100644 index 000000000..51c3768b7 --- /dev/null +++ b/libnautilus-private/nautilus-preferences.c @@ -0,0 +1,628 @@ + /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ + +/* nautilus-prefs.h - Preference peek/poke/notify object implementation. + + Copyright (C) 1999, 2000 Eazel, Inc. + + The Gnome Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + The Gnome Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the Gnome Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. + + Authors: Ramiro Estrugo <ramiro@eazel.com> +*/ + + +#include <nautilus-widgets/nautilus-preferences.h> +#include <libnautilus/nautilus-gtk-macros.h> + +#include <gtk/gtkclist.h> + +// #include <gtk/gtkmain.h> + +#include <libgnomeui/gnome-stock.h> +#include <gtk/gtkmain.h> +#include <gtk/gtksignal.h> + +#include <stdio.h> + +enum +{ + ACTIVATE, + LAST_SIGNAL +}; + +typedef struct +{ + NautilusPrefInfo pref_info; + gpointer pref_value; + GList *callback_list; +} PrefHashInfo; + +typedef struct +{ + NautilusPrefsCallback callback_proc; + gpointer user_data; + const PrefHashInfo *hash_info; +} PrefCallbackInfo; + +struct _NautilusPrefsPrivate +{ + gchar *domain; + GHashTable *prefs_hash_table; +}; + +/* NautilusPrefsClass methods */ +static void nautilus_prefs_initialize_class (NautilusPrefsClass *klass); +static void nautilus_prefs_initialize (NautilusPrefs *prefs); + + + + +/* GtkObjectClass methods */ +static void prefs_destroy (GtkObject *object); + + + + +/* PrefHashInfo functions */ +static PrefHashInfo * pref_hash_info_alloc (const NautilusPrefInfo *pref_info); +static void pref_hash_info_free (PrefHashInfo *pref_hash_info); +static void pref_hash_info_free_func (gpointer key, + gpointer value, + gpointer user_data); + +/* PrefCallbackInfo functions */ +static PrefCallbackInfo * pref_callback_info_alloc (NautilusPrefsCallback callback_proc, + gpointer user_data, + const PrefHashInfo *hash_info); +static void pref_callback_info_free (PrefCallbackInfo *pref_hash_info); +static void pref_callback_info_free_func (gpointer data, + gpointer user_data); +static void pref_callback_info_invoke_func (gpointer data, + gpointer user_data); +static void pref_hash_info_add_callback (PrefHashInfo *pref_hash_info, + NautilusPrefsCallback callback_proc, + gpointer user_data); + +/* Private stuff */ +static GtkFundamentalType prefs_check_supported_type (GtkFundamentalType pref_type); +static gboolean prefs_set_pref (NautilusPrefs *prefs, + const gchar *pref_name, + gpointer pref_value); +static gboolean prefs_get_pref (NautilusPrefs *prefs, + const gchar *pref_name, + GtkFundamentalType *pref_type_out, + gconstpointer *pref_value_out); +PrefHashInfo * prefs_hash_lookup (NautilusPrefs *prefs, + const gchar *pref_name); + +NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusPrefs, nautilus_prefs, GTK_TYPE_OBJECT) + +/* + * NautilusPrefsClass methods + */ +static void +nautilus_prefs_initialize_class (NautilusPrefsClass *prefs_class) +{ + GtkObjectClass *object_class; + + object_class = GTK_OBJECT_CLASS (prefs_class); + + parent_class = gtk_type_class (gtk_object_get_type ()); + + /* GtkObjectClass */ + object_class->destroy = prefs_destroy; +} + +static void +nautilus_prefs_initialize (NautilusPrefs *prefs) +{ + prefs->priv = g_new (NautilusPrefsPrivate, 1); + + prefs->priv->domain = NULL; + + prefs->priv->prefs_hash_table = g_hash_table_new (g_str_hash, + g_str_equal); +} + +/* + * GtkObjectClass methods + */ +static void +prefs_destroy (GtkObject *object) +{ + NautilusPrefs * prefs; + + g_return_if_fail (object != NULL); + g_return_if_fail (NAUTILUS_IS_PREFS (object)); + + prefs = NAUTILUS_PREFS (object); + + if (prefs->priv->domain) + { + g_free (prefs->priv->domain); + prefs->priv->domain = NULL; + } + + if (prefs->priv->prefs_hash_table) + { + g_hash_table_foreach (prefs->priv->prefs_hash_table, + pref_hash_info_free_func, + (gpointer) NULL); + + g_hash_table_destroy (prefs->priv->prefs_hash_table); + + prefs->priv->prefs_hash_table = NULL; + } + + g_free (prefs->priv); + + /* Chain */ + if (GTK_OBJECT_CLASS (parent_class)->destroy != NULL) + (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); +} + +/* + * PrefHashInfo functions + */ +static PrefHashInfo * +pref_hash_info_alloc (const NautilusPrefInfo *pref_info) +{ + PrefHashInfo * pref_hash_info; + + g_assert (pref_info != NULL); + + g_assert (pref_info->pref_name != NULL); + g_assert (pref_info->pref_description != NULL); + + pref_hash_info = g_new (PrefHashInfo, 1); + + pref_hash_info->pref_info.pref_name = g_strdup (pref_info->pref_name); + pref_hash_info->pref_info.pref_description = g_strdup (pref_info->pref_description); + pref_hash_info->pref_info.pref_type = pref_info->pref_type; + pref_hash_info->pref_info.pref_default_value = pref_info->pref_default_value; + pref_hash_info->pref_info.type_data = pref_info->type_data; + + pref_hash_info->pref_value = (gpointer) pref_info->pref_default_value; + pref_hash_info->callback_list = NULL; + + return pref_hash_info; +} + +static void +pref_hash_info_free (PrefHashInfo *pref_hash_info) +{ + g_assert (pref_hash_info != NULL); + + g_assert (pref_hash_info->pref_info.pref_name != NULL); + g_assert (pref_hash_info->pref_info.pref_description != NULL); + + if (pref_hash_info->callback_list) + { + g_list_foreach (pref_hash_info->callback_list, + pref_callback_info_free_func, + (gpointer) NULL); + } + + g_free (pref_hash_info->pref_info.pref_name); + g_free (pref_hash_info->pref_info.pref_description); + + pref_hash_info->pref_info.pref_name = NULL; + pref_hash_info->pref_info.pref_type = GTK_TYPE_INVALID; + pref_hash_info->pref_info.pref_default_value = NULL; + pref_hash_info->pref_info.type_data = NULL; + + pref_hash_info->callback_list = NULL; + pref_hash_info->pref_value = NULL; + + g_free (pref_hash_info); +} + +static void +pref_hash_info_add_callback (PrefHashInfo *pref_hash_info, + NautilusPrefsCallback callback_proc, + gpointer user_data) +{ + PrefCallbackInfo * pref_callback_info; + + g_assert (pref_hash_info != NULL); + + g_assert (callback_proc != NULL); + + pref_callback_info = pref_callback_info_alloc (callback_proc, + user_data, + pref_hash_info); + + pref_hash_info->callback_list = + g_list_append (pref_hash_info->callback_list, + (gpointer) pref_callback_info); +} + +static void +pref_hash_info_free_func (gpointer key, + gpointer value, + gpointer user_data) +{ + PrefHashInfo *pref_hash_info; + + pref_hash_info = (PrefHashInfo *) value; + + g_assert (pref_hash_info != NULL); + + pref_hash_info_free (pref_hash_info); +} + +/* + * PrefCallbackInfo functions + */ +static PrefCallbackInfo * +pref_callback_info_alloc (NautilusPrefsCallback callback_proc, + gpointer user_data, + const PrefHashInfo *hash_info) +{ + PrefCallbackInfo * pref_callback_info; + + g_assert (callback_proc != NULL); + + pref_callback_info = g_new (PrefCallbackInfo, 1); + + pref_callback_info->callback_proc = callback_proc; + pref_callback_info->user_data = user_data; + pref_callback_info->hash_info = hash_info; + + return pref_callback_info; +} + +static void +pref_callback_info_free (PrefCallbackInfo *pref_callback_info) +{ + g_assert (pref_callback_info != NULL); + + pref_callback_info->callback_proc = NULL; + pref_callback_info->user_data = NULL; + + g_free (pref_callback_info); +} + +static void +pref_callback_info_free_func (gpointer data, + gpointer user_data) +{ + PrefCallbackInfo *pref_callback_info; + + pref_callback_info = (PrefCallbackInfo *) data; + + g_assert (pref_callback_info != NULL); + + pref_callback_info_free (pref_callback_info); +} + +static void +pref_callback_info_invoke_func (gpointer data, + gpointer user_data) +{ + const NautilusPrefs *prefs; + PrefCallbackInfo *pref_callback_info; + + pref_callback_info = (PrefCallbackInfo *) data; + + g_assert (pref_callback_info != NULL); + + g_assert (pref_callback_info->callback_proc != NULL); + + prefs = (const NautilusPrefs *) user_data; + + (*pref_callback_info->callback_proc) (GTK_OBJECT (prefs), + pref_callback_info->hash_info->pref_info.pref_name, + pref_callback_info->hash_info->pref_info.pref_type, + pref_callback_info->hash_info->pref_value, + pref_callback_info->user_data); +} + +/* + * Private stuff + */ +static GtkFundamentalType +prefs_check_supported_type (GtkFundamentalType pref_type) +{ + return ((pref_type == GTK_TYPE_BOOL) || + (pref_type == GTK_TYPE_INT) || + (pref_type == GTK_TYPE_ENUM)); +} + +static gboolean +prefs_set_pref (NautilusPrefs *prefs, + const gchar *pref_name, + gpointer pref_value) +{ + PrefHashInfo * pref_hash_info; + + g_return_val_if_fail (prefs != NULL, FALSE); + g_return_val_if_fail (NAUTILUS_IS_PREFS (prefs), FALSE); + g_return_val_if_fail (pref_name != NULL, FALSE); + + pref_hash_info = prefs_hash_lookup (prefs, pref_name); + + if (!pref_hash_info) + { + return FALSE; + } + + /* + * XXX FIXME: When we support GTK_TYPE_STRING, this + * will have to strcpy() the given value + */ + pref_hash_info->pref_value = pref_value; + + if (pref_hash_info->callback_list) + { + g_list_foreach (pref_hash_info->callback_list, + pref_callback_info_invoke_func, + (gpointer) prefs); + } + + return TRUE; +} + +static gboolean +prefs_get_pref (NautilusPrefs *prefs, + const gchar *pref_name, + GtkFundamentalType *pref_type_out, + gconstpointer *pref_value_out) +{ + PrefHashInfo * pref_hash_info; + + g_return_val_if_fail (prefs != NULL, FALSE); + g_return_val_if_fail (NAUTILUS_IS_PREFS (prefs), FALSE); + g_return_val_if_fail (pref_type_out != NULL, FALSE); + g_return_val_if_fail (pref_value_out != NULL, FALSE); + + if (!pref_hash_info) + { + return FALSE; + } + + pref_hash_info = prefs_hash_lookup (prefs, pref_name); + +// printf("looking for %s\n", pref_name); + + g_assert (pref_hash_info != NULL); + +// printf("pref_name = %s\n", pref_hash_info->pref_info.pref_name); +// printf("pref_desc = %s\n", pref_hash_info->pref_info.pref_description); +// printf("pref_type = %d\n", pref_hash_info->pref_info.pref_type); + + *pref_type_out = pref_hash_info->pref_info.pref_type; + *pref_value_out = pref_hash_info->pref_value; + + return TRUE; +} + +/* + * NautilusPrefs public methods + */ +GtkObject * +nautilus_prefs_new (const gchar *domain) +{ + NautilusPrefs *prefs; + + g_return_val_if_fail (domain != NULL, NULL); + + prefs = gtk_type_new (nautilus_prefs_get_type ()); + + return GTK_OBJECT (prefs); +} + +void +nautilus_prefs_register_from_info (NautilusPrefs *prefs, + const NautilusPrefInfo *pref_info) +{ + PrefHashInfo * pref_hash_info; + + g_return_if_fail (prefs != NULL); + g_return_if_fail (NAUTILUS_IS_PREFS (prefs)); + + g_return_if_fail (pref_info != NULL); + + g_return_if_fail (pref_info->pref_name != NULL); + g_return_if_fail (prefs_check_supported_type (pref_info->pref_type)); + + pref_hash_info = prefs_hash_lookup (prefs, pref_info->pref_name); + + if (pref_hash_info) + { + g_warning ("the '%s' preference is already registered.\n", pref_info->pref_name); + + return; + } + +// printf ("%s is being registered\n", pref_info->pref_name); + + pref_hash_info = pref_hash_info_alloc (pref_info); + + g_hash_table_insert (prefs->priv->prefs_hash_table, + (gpointer) pref_info->pref_name, + (gpointer) pref_hash_info); +} + +void +nautilus_prefs_register_from_values (NautilusPrefs *prefs, + gchar *pref_name, + gchar *pref_description, + GtkFundamentalType pref_type, + gconstpointer pref_default_value, + gpointer type_data) +{ + NautilusPrefInfo pref_info; + + g_return_if_fail (prefs != NULL); + g_return_if_fail (NAUTILUS_IS_PREFS (prefs)); + + g_return_if_fail (pref_name != NULL); + g_return_if_fail (pref_description != NULL); + g_return_if_fail (prefs_check_supported_type (pref_type)); + + pref_info.pref_name = pref_name; + pref_info.pref_description = pref_description; + pref_info.pref_type = pref_type; + pref_info.pref_default_value = pref_default_value; + pref_info.type_data = type_data; + + nautilus_prefs_register_from_info (prefs, &pref_info); +} + +const NautilusPrefInfo * +nautilus_prefs_get_pref_info (NautilusPrefs *prefs, + const gchar *pref_name) +{ + PrefHashInfo * pref_hash_info; + + g_return_val_if_fail (prefs != NULL, NULL); + g_return_val_if_fail (NAUTILUS_IS_PREFS (prefs), NULL); + g_return_val_if_fail (pref_name != NULL, NULL); + + pref_hash_info = prefs_hash_lookup (prefs, pref_name); + + g_assert (pref_hash_info != NULL); + + return &pref_hash_info->pref_info; +} + +PrefHashInfo * +prefs_hash_lookup (NautilusPrefs *prefs, + const gchar *pref_name) +{ + gpointer hash_value; + + g_assert (prefs != NULL); + g_assert (pref_name != NULL); + + hash_value = g_hash_table_lookup (prefs->priv->prefs_hash_table, + (gconstpointer) pref_name); + + return (PrefHashInfo *) hash_value; +} + +gboolean +nautilus_prefs_add_callback (NautilusPrefs *prefs, + const gchar *pref_name, + NautilusPrefsCallback callback_proc, + gpointer user_data) +{ + PrefHashInfo * pref_hash_info; + + g_return_val_if_fail (prefs != NULL, FALSE); + g_return_val_if_fail (NAUTILUS_IS_PREFS (prefs), FALSE); + g_return_val_if_fail (pref_name != NULL, FALSE); + g_return_val_if_fail (callback_proc != NULL, FALSE); + + pref_hash_info = prefs_hash_lookup (prefs, pref_name); + + if (!pref_hash_info) + { + g_warning ("trying to add a callback to an unregistered preference.\n"); + + return FALSE; + } + + pref_hash_info_add_callback (pref_hash_info, + callback_proc, + user_data); + + return TRUE; +} + +void +nautilus_prefs_set_boolean (NautilusPrefs *prefs, + const gchar *pref_name, + gboolean boolean_value) +{ + gboolean rv; + + g_return_if_fail (prefs != NULL); + g_return_if_fail (NAUTILUS_IS_PREFS (prefs)); + g_return_if_fail (pref_name != NULL); + + rv = prefs_set_pref (prefs, pref_name, (gpointer) boolean_value); + + g_assert (rv); +} + +gboolean +nautilus_prefs_get_boolean (NautilusPrefs *prefs, + const gchar *pref_name) +{ + gboolean rv; + GtkFundamentalType pref_type; + gconstpointer value; + + g_return_val_if_fail (prefs != NULL, FALSE); + g_return_val_if_fail (NAUTILUS_IS_PREFS (prefs), FALSE); + g_return_val_if_fail (pref_name != NULL, FALSE); + + rv = prefs_get_pref (prefs, pref_name, &pref_type, &value); + + if (!rv) + { + g_warning ("could not get boolean preference '%s'\n", pref_name); + + return FALSE; + } + + g_assert (pref_type == GTK_TYPE_BOOL); + + return (gboolean) value; +} + +void +nautilus_prefs_set_enum (NautilusPrefs *prefs, + const gchar *pref_name, + gint enum_value) +{ + gboolean rv; + + g_return_if_fail (prefs != NULL); + g_return_if_fail (NAUTILUS_IS_PREFS (prefs)); + g_return_if_fail (pref_name != NULL); + + rv = prefs_set_pref (prefs, pref_name, (gpointer) enum_value); + + g_assert (rv); +} + +gint +nautilus_prefs_get_enum (NautilusPrefs *prefs, + const gchar *pref_name) +{ + gboolean rv; + GtkFundamentalType pref_type; + gconstpointer value; + + g_return_val_if_fail (prefs != NULL, FALSE); + g_return_val_if_fail (NAUTILUS_IS_PREFS (prefs), FALSE); + g_return_val_if_fail (pref_name != NULL, FALSE); + + rv = prefs_get_pref (prefs, pref_name, &pref_type, &value); + + if (!rv) + { + g_warning ("could not get enum preference '%s'\n", pref_name); + + return FALSE; + } + + g_assert (pref_type == GTK_TYPE_ENUM); + + return (gint) value; +} diff --git a/libnautilus-private/nautilus-preferences.h b/libnautilus-private/nautilus-preferences.h new file mode 100644 index 000000000..cfe709730 --- /dev/null +++ b/libnautilus-private/nautilus-preferences.h @@ -0,0 +1,116 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ + +/* nautilus-prefs.h - Preference peek/poke/notify object interface. + + Copyright (C) 1999, 2000 Eazel, Inc. + + The Gnome Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + The Gnome Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the Gnome Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. + + Authors: Ramiro Estrugo <ramiro@eazel.com> +*/ + +#ifndef NAUTILUS_PREFS_H +#define NAUTILUS_PREFS_H + +#include <gtk/gtkhbox.h> +#include <nautilus-widgets/nautilus-preferences-pane.h> + +//#include <gnome.h> + +BEGIN_GNOME_DECLS + +#define NAUTILUS_TYPE_PREFS (nautilus_prefs_get_type ()) +#define NAUTILUS_PREFS(obj) (GTK_CHECK_CAST ((obj), NAUTILUS_TYPE_PREFS, NautilusPrefs)) +#define NAUTILUS_PREFS_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), NAUTILUS_TYPE_PREFS, NautilusPrefsClass)) +#define NAUTILUS_IS_PREFS(obj) (GTK_CHECK_TYPE ((obj), NAUTILUS_TYPE_PREFS)) +#define NAUTILUS_IS_PREFS_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), NAUTILUS_TYPE_PREFS)) + +typedef struct _NautilusPrefs NautilusPrefs; +typedef struct _NautilusPrefsClass NautilusPrefsClass; +typedef struct _NautilusPrefsPrivate NautilusPrefsPrivate; + +struct _NautilusPrefs +{ + /* Super Class */ + GtkObject object; + + /* Private stuff */ + NautilusPrefsPrivate *priv; +}; + +typedef void (*NautilusPrefsCallback) (const GtkObject *prefs, + const gchar *pref_name, + GtkFundamentalType pref_type, + gconstpointer pref_value, + gpointer user_data); + +struct _NautilusPrefsClass +{ + GtkObjectClass object_class; + +// void (*activate) (GtkWidget * prefs, gint entry_number); +}; + +typedef struct +{ + gchar *pref_name; + gchar *pref_description; + GtkFundamentalType pref_type; + gconstpointer pref_default_value; + gpointer type_data; +} NautilusPrefInfo; + +typedef struct +{ + const gchar **enum_names; + const gchar **enum_descriptions; + const gint *enum_values; + guint num_entries; +} NautilusPrefEnumData; + +GtkType nautilus_prefs_get_type (void); +GtkObject* nautilus_prefs_new (const gchar *domain); +void nautilus_prefs_register_from_info (NautilusPrefs *prefs, + const NautilusPrefInfo *pref_info); +void nautilus_prefs_register_from_values (NautilusPrefs *prefs, + gchar *pref_name, + gchar *pref_description, + GtkFundamentalType pref_type, + gconstpointer pref_default_value, + gpointer type_data); +const NautilusPrefInfo *nautilus_prefs_get_pref_info (NautilusPrefs *prefs, + const gchar *pref_name); +gboolean nautilus_prefs_add_callback (NautilusPrefs *prefs, + const gchar *pref_name, + NautilusPrefsCallback callback, + gpointer user_data); +void nautilus_prefs_set_boolean (NautilusPrefs *prefs, + const gchar *pref_name, + gboolean boolean_value); +gboolean nautilus_prefs_get_boolean (NautilusPrefs *prefs, + const gchar *pref_name); +void nautilus_prefs_set_enum (NautilusPrefs *prefs, + const gchar *pref_name, + gint enum_value); +gint nautilus_prefs_get_enum (NautilusPrefs *prefs, + const gchar *pref_name); + + +BEGIN_GNOME_DECLS + +#endif /* NAUTILUS_PREFS_H */ + + diff --git a/libnautilus-private/nautilus-radio-button-group.c b/libnautilus-private/nautilus-radio-button-group.c index 07f51397d..509afe7de 100644 --- a/libnautilus-private/nautilus-radio-button-group.c +++ b/libnautilus-private/nautilus-radio-button-group.c @@ -276,3 +276,22 @@ nautilus_radio_button_group_get_active_index (NautilusRadioButtonGroup *button_g return 0; } + +void +nautilus_radio_button_group_set_active_index (NautilusRadioButtonGroup *button_group, + guint active_index) +{ + GList *node; + + g_return_if_fail (button_group != NULL); + g_return_if_fail (NAUTILUS_IS_RADIO_BUTTON_GROUP (button_group)); + + node = g_list_nth (button_group->details->buttons, active_index); + + g_assert (node != NULL); + + g_assert (GTK_TOGGLE_BUTTON (node->data)); + + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (node->data), TRUE); +} + diff --git a/libnautilus-private/nautilus-radio-button-group.h b/libnautilus-private/nautilus-radio-button-group.h index a9b8ad2c2..7d7dffb7c 100644 --- a/libnautilus-private/nautilus-radio-button-group.h +++ b/libnautilus-private/nautilus-radio-button-group.h @@ -72,6 +72,10 @@ guint nautilus_radio_button_group_insert (NautilusRadioButtonGro /* Get the active item index. By law there always is an active item */ guint nautilus_radio_button_group_get_active_index (NautilusRadioButtonGroup *button_group); +/* Set the active item index. */ +void nautilus_radio_button_group_set_active_index (NautilusRadioButtonGroup *button_group, + guint active_index); + BEGIN_GNOME_DECLS #endif /* NAUTILUS_RADIO_BUTTON_GROUP_H */ diff --git a/libnautilus-private/test-nautilus-widgets.c b/libnautilus-private/test-nautilus-widgets.c index 85eee70e7..ad86e92a1 100644 --- a/libnautilus-private/test-nautilus-widgets.c +++ b/libnautilus-private/test-nautilus-widgets.c @@ -1,17 +1,40 @@ #include <nautilus-widgets/nautilus-radio-button-group.h> +#include <nautilus-widgets/nautilus-preferences-group.h> +#include <nautilus-widgets/nautilus-preferences-item.h> +#include <nautilus-widgets/nautilus-preferences.h> + #include <gtk/gtk.h> #include <stdio.h> static void test_radio_group (void); +static void test_preferences_group (void); +static void test_preferences_item (void); + + static void test_radio_changed_signal (GtkWidget *button_group, gpointer user_data); +static GtkObject * +create_dummy_prefs (void); + +GtkWidget * +create_enum_item (void); + +GtkWidget * +create_bool_item (void); + +static GtkObject * dummy_prefs = NULL; + int main (int argc, char * argv[]) { gtk_init (&argc, &argv); + + dummy_prefs = create_dummy_prefs (); test_radio_group (); + test_preferences_group (); + test_preferences_item (); gtk_main (); @@ -24,6 +47,7 @@ test_radio_group (void) GtkWidget * window; GtkWidget * buttons; + window = gtk_window_new (GTK_WINDOW_TOPLEVEL); buttons = nautilus_radio_button_group_new (); @@ -45,6 +69,49 @@ test_radio_group (void) } static void +test_preferences_item (void) +{ + GtkWidget * window; + GtkWidget * item; + + window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + + item = create_enum_item (); + + gtk_container_add (GTK_CONTAINER (window), item); + + gtk_widget_show (item); + + gtk_widget_show (window); +} + +static void +test_preferences_group (void) +{ + GtkWidget * window; + GtkWidget * group; + + GtkWidget * item; + + window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + + group = nautilus_preferences_group_new ("A group"); + + item = create_enum_item (); + + nautilus_preferences_group_add (NAUTILUS_PREFERENCES_GROUP (group), + item); + + gtk_widget_show (item); + + gtk_container_add (GTK_CONTAINER (window), group); + + gtk_widget_show (group); + + gtk_widget_show (window); +} + +static void test_radio_changed_signal (GtkWidget *buttons, gpointer user_data) { gint i; @@ -53,3 +120,108 @@ test_radio_changed_signal (GtkWidget *buttons, gpointer user_data) printf ("test_radio_changed_signal (%d)\n", i); } + +GtkWidget * +create_enum_item (void) +{ + GtkWidget * item; + + item = nautilus_preferences_item_new (dummy_prefs, + "user_level", + NAUTILUS_PREFERENCES_ITEM_ENUM); + + return item; +} + +GtkWidget * +create_bool_item (void) +{ + GtkWidget * item; + + item = nautilus_preferences_item_new (dummy_prefs, + "foo", + NAUTILUS_PREFERENCES_ITEM_BOOL); + + return item; +} + + +static const gchar * prefs_global_user_level_names[] = +{ + "novice", + "intermediate", + "hacker", + "ettore" +}; + +static const gchar * prefs_global_user_level_descriptions[] = +{ + "Novice", + "Intermediate", + "Hacker", + "Ettore" +}; + +static const gint prefs_global_user_level_values[] = +{ + 0, + 1, + 2, + 3 +}; + +static NautilusPrefEnumData prefs_global_user_level_data = +{ + prefs_global_user_level_names, + prefs_global_user_level_descriptions, + prefs_global_user_level_values, + 4 +}; + +static NautilusPrefInfo prefs_global_static_pref_info[] = +{ + { + "user_level", + "User Level", + GTK_TYPE_ENUM, + FALSE, + (gpointer) &prefs_global_user_level_data + }, + { + "foo", + "Create new window for each new page", + GTK_TYPE_BOOL, + FALSE, + NULL + }, + { + "bar", + "Do not open more than one window with the same page", + GTK_TYPE_BOOL, + FALSE, + NULL + }, +}; + +static GtkObject * +create_dummy_prefs (void) +{ + GtkObject * dummy_prefs; + guint i; + + dummy_prefs = nautilus_prefs_new ("dummy"); + + /* Register the static prefs */ + for (i = 0; i < 3; i++) + { + nautilus_prefs_register_from_info (NAUTILUS_PREFS (dummy_prefs), + &prefs_global_static_pref_info[i]); + } + + + nautilus_prefs_set_enum (NAUTILUS_PREFS (dummy_prefs), + "user_level", + 2); + + return dummy_prefs; +} diff --git a/libnautilus-private/test-preferences.c b/libnautilus-private/test-preferences.c new file mode 100644 index 000000000..a2d1de8b6 --- /dev/null +++ b/libnautilus-private/test-preferences.c @@ -0,0 +1,227 @@ + +#include <nautilus-widgets/nautilus-radio-button-group.h> +#include <nautilus-widgets/nautilus-preferences-group.h> +#include <nautilus-widgets/nautilus-preferences-item.h> +#include <nautilus-widgets/nautilus-preferences.h> + +#include <gtk/gtk.h> +#include <stdio.h> + +static void test_radio_group (void); +static void test_preferences_group (void); +static void test_preferences_item (void); + + +static void test_radio_changed_signal (GtkWidget *button_group, gpointer user_data); + +static GtkObject * +create_dummy_prefs (void); + +GtkWidget * +create_enum_item (void); + +GtkWidget * +create_bool_item (void); + +static GtkObject * dummy_prefs = NULL; + +int +main (int argc, char * argv[]) +{ + gtk_init (&argc, &argv); + + dummy_prefs = create_dummy_prefs (); + +// test_radio_group (); + test_preferences_group (); + test_preferences_item (); + + gtk_main (); + + return 0; +} + +static void +test_radio_group (void) +{ + GtkWidget * window; + GtkWidget * buttons; + + + window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + + buttons = nautilus_radio_button_group_new (); + + nautilus_radio_button_group_insert (NAUTILUS_RADIO_BUTTON_GROUP (buttons), "Apples"); + nautilus_radio_button_group_insert (NAUTILUS_RADIO_BUTTON_GROUP (buttons), "Oranges"); + nautilus_radio_button_group_insert (NAUTILUS_RADIO_BUTTON_GROUP (buttons), "Strawberries"); + + gtk_signal_connect (GTK_OBJECT (buttons), + "changed", + GTK_SIGNAL_FUNC (test_radio_changed_signal), + (gpointer) NULL); + + gtk_container_add (GTK_CONTAINER (window), buttons); + + gtk_widget_show (buttons); + + gtk_widget_show (window); +} + +static void +test_preferences_item (void) +{ + GtkWidget * window; + GtkWidget * item; + + window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + + item = create_enum_item (); + + gtk_container_add (GTK_CONTAINER (window), item); + + gtk_widget_show (item); + + gtk_widget_show (window); +} + +static void +test_preferences_group (void) +{ + GtkWidget * window; + GtkWidget * group; + + GtkWidget * item; + + window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + + group = nautilus_preferences_group_new ("A group"); + + item = create_enum_item (); + + nautilus_preferences_group_add (NAUTILUS_PREFERENCES_GROUP (group), + item); + + gtk_widget_show (item); + + gtk_container_add (GTK_CONTAINER (window), group); + + gtk_widget_show (group); + + gtk_widget_show (window); +} + +static void +test_radio_changed_signal (GtkWidget *buttons, gpointer user_data) +{ + gint i; + + i = nautilus_radio_button_group_get_active_index (NAUTILUS_RADIO_BUTTON_GROUP (buttons)); + + printf ("test_radio_changed_signal (%d)\n", i); +} + +GtkWidget * +create_enum_item (void) +{ + GtkWidget * item; + + item = nautilus_preferences_item_new (dummy_prefs, + "user_level", + NAUTILUS_PREFERENCES_ITEM_ENUM); + + return item; +} + +GtkWidget * +create_bool_item (void) +{ + GtkWidget * item; + + item = nautilus_preferences_item_new (dummy_prefs, + "foo", + NAUTILUS_PREFERENCES_ITEM_BOOL); + + return item; +} + + +static const gchar * prefs_global_user_level_names[] = +{ + "novice", + "intermediate", + "hacker", + "ettore" +}; + +static const gchar * prefs_global_user_level_descriptions[] = +{ + "Novice", + "Intermediate", + "Hacker", + "Ettore" +}; + +static const gint prefs_global_user_level_values[] = +{ + 0, + 1, + 2, + 3 +}; + +static NautilusPrefEnumData prefs_global_user_level_data = +{ + prefs_global_user_level_names, + prefs_global_user_level_descriptions, + prefs_global_user_level_values, + 4 +}; + +static NautilusPrefInfo prefs_global_static_pref_info[] = +{ + { + "user_level", + "User Level", + GTK_TYPE_ENUM, + FALSE, + (gpointer) &prefs_global_user_level_data + }, + { + "foo", + "Create new window for each new page", + GTK_TYPE_BOOL, + FALSE, + NULL + }, + { + "bar", + "Do not open more than one window with the same page", + GTK_TYPE_BOOL, + FALSE, + NULL + }, +}; + +static GtkObject * +create_dummy_prefs (void) +{ + GtkObject * dummy_prefs; + guint i; + + dummy_prefs = nautilus_prefs_new ("dummy"); + + /* Register the static prefs */ + for (i = 0; i < 3; i++) + { + nautilus_prefs_register_from_info (NAUTILUS_PREFS (dummy_prefs), + &prefs_global_static_pref_info[i]); + } + + + nautilus_prefs_set_enum (NAUTILUS_PREFS (dummy_prefs), + "user_level", + 2); + + return dummy_prefs; +} diff --git a/nautilus-widgets/Makefile.am b/nautilus-widgets/Makefile.am index 635bff069..541832dbc 100644 --- a/nautilus-widgets/Makefile.am +++ b/nautilus-widgets/Makefile.am @@ -1,12 +1,17 @@ NULL= -bin_PROGRAMS=test-nautilus-widgets +bin_PROGRAMS=test-nautilus-widgets # test-preferences test_nautilus_widgets_LDADD =\ libnautilus-widgets.la \ $(GNOMEUI_LIBS) \ $(NULL) +#test_preferences_LDADD =\ +# libnautilus-widgets.la \ +# $(GNOMEUI_LIBS) \ +# $(NULL) + lib_LTLIBRARIES=libnautilus-widgets.la INCLUDES=-I$(top_srcdir) -I$(top_builddir) \ @@ -20,10 +25,22 @@ libnautilus_widgets_la_LDFLAGS=\ libnautilus_widgetsincludedir=$(includedir)/nautilus-widgets libnautilus_widgetsinclude_HEADERS =\ + nautilus-preferences-box.h \ + nautilus-preferences-dialog.h \ + nautilus-preferences-group.h \ + nautilus-preferences-item.h \ + nautilus-preferences-pane.h \ + nautilus-preferences.h \ nautilus-radio-button-group.h \ $(NULL) libnautilus_widgets_la_SOURCES =\ + nautilus-preferences-box.c \ + nautilus-preferences-dialog.c \ + nautilus-preferences-group.c \ + nautilus-preferences-item.c \ + nautilus-preferences-pane.c \ + nautilus-preferences.c \ nautilus-radio-button-group.c \ $(NULL) @@ -31,3 +48,7 @@ test_nautilus_widgets_SOURCES =\ test-nautilus-widgets.c \ $(NULL) +#test_preferences_SOURCES =\ +# test-preferences.c \ +# $(NULL) + diff --git a/nautilus-widgets/nautilus-preferences-box.c b/nautilus-widgets/nautilus-preferences-box.c new file mode 100644 index 000000000..9db4596cf --- /dev/null +++ b/nautilus-widgets/nautilus-preferences-box.c @@ -0,0 +1,361 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ + +/* nautilus-prefs-box.h - Implementation for preferences box component. + + Copyright (C) 1999, 2000 Eazel, Inc. + + The Gnome Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + The Gnome Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the Gnome Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. + + Authors: Ramiro Estrugo <ramiro@eazel.com> +*/ + + +#include <nautilus-widgets/nautilus-preferences-box.h> +#include <libnautilus/nautilus-gtk-macros.h> + +#include <gtk/gtkclist.h> + +// #include <gtk/gtkmain.h> + +#include <libgnomeui/gnome-stock.h> +#include <gtk/gtkmain.h> +#include <gtk/gtksignal.h> + +enum +{ + ACTIVATE, + 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; + +typedef struct +{ + gchar *pane_name; + GtkWidget *pane_widget; + gboolean constructed; +} PaneInfo; + +struct _NautilusPrefsBoxPrivate +{ + GtkWidget *category_list; + GtkWidget *pane_container; + + GList *panes; + + gint selected_pane; +}; + +typedef void (*GnomeBoxSignal1) (GtkObject* object, + gint arg1, + gpointer data); + +/* NautilusPrefsBoxClass methods */ +static void nautilus_prefs_box_initialize_class (NautilusPrefsBoxClass *klass); +static void nautilus_prefs_box_initialize (NautilusPrefsBox *prefs_box); + + + +/* GtkObjectClass methods */ +static void nautilus_prefs_box_destroy (GtkObject *object); + + + +/* Misc private stuff */ +static void prefs_box_construct (NautilusPrefsBox *prefs_box); +static void prefs_box_select_pane (NautilusPrefsBox *prefs_box, + guint pane_row); + + + + +/* PaneInfo functions */ +static PaneInfo *pane_info_alloc (const gchar *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); + +NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusPrefsBox, nautilus_prefs_box, GTK_TYPE_HBOX) + +/* + * NautilusPrefsBoxClass methods + */ +static void +nautilus_prefs_box_initialize_class (NautilusPrefsBoxClass *prefs_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 ()); + + /* GtkObjectClass */ + object_class->destroy = nautilus_prefs_box_destroy; +} + +static void +nautilus_prefs_box_initialize (NautilusPrefsBox *prefs_box) +{ + prefs_box->priv = g_new (NautilusPrefsBoxPrivate, 1); + + prefs_box->priv->category_list = NULL; + prefs_box->priv->pane_container = NULL; + prefs_box->priv->panes = NULL; + + prefs_box->priv->selected_pane = PREFS_SELECTED_PANE_UNKNOWN; +} + +/* + * GtkObjectClass methods + */ +static void +nautilus_prefs_box_destroy (GtkObject *object) +{ + NautilusPrefsBox * prefs_box; + + g_return_if_fail (object != NULL); + g_return_if_fail (NAUTILUS_IS_PREFS_BOX (object)); + + prefs_box = NAUTILUS_PREFS_BOX (object); + + if (prefs_box->priv->panes) + { + GList *panes; + + panes = prefs_box->priv->panes; + + while (panes) + { + PaneInfo * info = panes->data; + + g_assert (info != NULL); + + pane_info_free (info); + + panes = panes->next; + } + + g_list_free (prefs_box->priv->panes); + } + + g_free (prefs_box->priv); + + /* Chain */ + if (GTK_OBJECT_CLASS (parent_class)->destroy != NULL) + (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); +} + +/* + * Misc private stuff + */ +static void +prefs_box_construct (NautilusPrefsBox *prefs_box) +{ + g_assert (prefs_box != NULL); + g_assert (prefs_box->priv != NULL); + + g_assert (prefs_box->priv->category_list == NULL); + g_assert (prefs_box->priv->panes == NULL); + + /* Configure ourselves */ + gtk_box_set_homogeneous (GTK_BOX (prefs_box), FALSE); + + gtk_box_set_spacing (GTK_BOX (prefs_box), PREFS_BOX_SPACING); + + /* The category list */ + prefs_box->priv->category_list = + gtk_clist_new (PREFS_BOX_NUM_CATEGORY_COLUMNS); + + gtk_signal_connect (GTK_OBJECT (prefs_box->priv->category_list), + "select_row", + GTK_SIGNAL_FUNC (category_list_select_row), + (gpointer) prefs_box); + + gtk_clist_set_selection_mode (GTK_CLIST (prefs_box->priv->category_list), + GTK_SELECTION_BROWSE); + + gtk_clist_set_column_auto_resize (GTK_CLIST (prefs_box->priv->category_list), + PREFS_BOX_CATEGORY_COLUMN, + TRUE); + + gtk_box_pack_start (GTK_BOX (prefs_box), + prefs_box->priv->category_list, + FALSE, + TRUE, + 0); + + gtk_widget_show (prefs_box->priv->category_list); +} + +static void +prefs_box_select_pane (NautilusPrefsBox *prefs_box, + guint pane_row) +{ + 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->priv != NULL); + g_assert (prefs_box->priv->panes != NULL); + + g_assert (pane_row < g_list_length (prefs_box->priv->panes)); + + pane_node = g_list_nth (prefs_box->priv->panes, pane_row); + + g_assert (pane_node != NULL); + + pane_info = pane_node->data; + + /* Show only the corresponding pane widget */ + pane_iterator = prefs_box->priv->panes; + + while (pane_iterator) + { + PaneInfo * info = pane_iterator->data; + + g_assert (info != NULL); + + if (pane_info == info) + { + /* Construct pane for first time if needed */ + if (!info->constructed) + { + + info->constructed = TRUE; + } + + gtk_widget_show (info->pane_widget); + } + else + { + gtk_widget_hide (info->pane_widget); + } + + pane_iterator = pane_iterator->next; + } +} + +/* + * PaneInfo functions + */ +static PaneInfo * +pane_info_alloc (const gchar *pane_name) +{ + PaneInfo * info; + + g_assert (pane_name != NULL); + + info = g_new (PaneInfo, 1); + + info->pane_name = g_strdup (pane_name); + + return info; +} + +static void +pane_info_free (PaneInfo *info) +{ + g_assert (info != NULL); + + g_free (info->pane_name); + + g_free (info); +} + +/* + * Category list callbacks + */ +static void +category_list_select_row (GtkCList *clist, + gint row, + gint column, + GdkEventButton *event, + gpointer user_data) +{ + NautilusPrefsBox *prefs_box = (NautilusPrefsBox *) user_data; + + g_assert (prefs_box != NULL); + g_assert (NAUTILUS_IS_PREFS_BOX (prefs_box)); + + prefs_box_select_pane (prefs_box, (guint) row); +} + +/* + * NautilusPrefsBox public methods + */ +GtkWidget* +nautilus_prefs_box_new (const gchar *box_title) +{ + NautilusPrefsBox *prefs_box; + + prefs_box = gtk_type_new (nautilus_prefs_box_get_type ()); + + prefs_box_construct (prefs_box); + + return GTK_WIDGET (prefs_box); +} + +GtkWidget * +nautilus_prefs_box_add_pane (NautilusPrefsBox *prefs_box, + const gchar *pane_title, + const gchar *pane_description) +{ + PaneInfo *info; + gint new_row; + gchar *text[PREFS_BOX_NUM_CATEGORY_COLUMNS]; + + 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 (pane_title != NULL, NULL); + g_return_val_if_fail (pane_description != NULL, NULL); + + info = pane_info_alloc (pane_title); + + prefs_box->priv->panes = g_list_append (prefs_box->priv->panes, + (gpointer) info); + + info->pane_widget = nautilus_prefs_pane_new (pane_title, + pane_description); + + gtk_box_pack_start (GTK_BOX (prefs_box), + info->pane_widget, + TRUE, + TRUE, + PREFS_BOX_PANE_LEFT_OFFSET); + + text[PREFS_BOX_CATEGORY_COLUMN] = (gchar *) pane_title; + + new_row = gtk_clist_append (GTK_CLIST (prefs_box->priv->category_list), + text); + + return info->pane_widget; +} diff --git a/nautilus-widgets/nautilus-preferences-box.h b/nautilus-widgets/nautilus-preferences-box.h new file mode 100644 index 000000000..8aa43cb21 --- /dev/null +++ b/nautilus-widgets/nautilus-preferences-box.h @@ -0,0 +1,73 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ + +/* nautilus-prefs-box.h - Interface for preferences box component. + + Copyright (C) 1999, 2000 Eazel, Inc. + + The Gnome Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + The Gnome Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the Gnome Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. + + Authors: Ramiro Estrugo <ramiro@eazel.com> +*/ + +#ifndef NAUTILUS_PREFS_BOX_H +#define NAUTILUS_PREFS_BOX_H + +#include <libgnomeui/gnome-dialog.h> +#include <gtk/gtkhbox.h> +#include <nautilus-widgets/nautilus-preferences-pane.h> + +//#include <gnome.h> + +BEGIN_GNOME_DECLS + +#define NAUTILUS_TYPE_PREFS_BOX (nautilus_prefs_box_get_type ()) +#define NAUTILUS_PREFS_BOX(obj) (GTK_CHECK_CAST ((obj), NAUTILUS_TYPE_PREFS_BOX, NautilusPrefsBox)) +#define NAUTILUS_PREFS_BOX_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), NAUTILUS_TYPE_PREFS_BOX, NautilusPrefsBoxClass)) +#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)) + +typedef struct _NautilusPrefsBox NautilusPrefsBox; +typedef struct _NautilusPrefsBoxClass NautilusPrefsBoxClass; +typedef struct _NautilusPrefsBoxPrivate NautilusPrefsBoxPrivate; + +struct _NautilusPrefsBox +{ + /* Super Class */ + GtkHBox hbox; + + /* Private stuff */ + NautilusPrefsBoxPrivate *priv; +}; + +struct _NautilusPrefsBoxClass +{ + GtkHBoxClass parent_class; + + void (*activate) (GtkWidget * prefs_box, gint entry_number); +}; + +GtkType nautilus_prefs_box_get_type (void); +GtkWidget* nautilus_prefs_box_new (const gchar *box_title); + +GtkWidget* nautilus_prefs_box_add_pane (NautilusPrefsBox *prefs_box, + const gchar *pane_title, + const gchar *pane_description); + +BEGIN_GNOME_DECLS + +#endif /* NAUTILUS_PREFS_BOX_H */ + + diff --git a/nautilus-widgets/nautilus-preferences-dialog.c b/nautilus-widgets/nautilus-preferences-dialog.c new file mode 100644 index 000000000..72a16badc --- /dev/null +++ b/nautilus-widgets/nautilus-preferences-dialog.c @@ -0,0 +1,281 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ + +/* nautilus-preferences-dialog.c - Implementation for preferences dialog. + + Copyright (C) 1999, 2000 Eazel, Inc. + + The Gnome Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + The Gnome Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the Gnome Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. + + Authors: Ramiro Estrugo <ramiro@eazel.com> +*/ + +#include <nautilus-widgets/nautilus-preferences-dialog.h> +#include <libnautilus/nautilus-gtk-macros.h> + +/* #include "caption-table.h" */ + +#include <libgnomeui/gnome-stock.h> +#include <gtk/gtkmain.h> +#include <gtk/gtksignal.h> + +#include <gnome.h> + +enum +{ + ACTIVATE, + LAST_SIGNAL +}; + +struct _NautilusPrefsDialogPrivate +{ + GtkWidget *prefs_box; +}; + +static const gchar * stock_buttons[] = +{ + "OK", + NULL +}; + +static const gint UNKNOWN_BUTTON = -1; +static const gint OK_BUTTON = 0; +static const gint DEFAULT_BUTTON = 0; +static const guint DEFAULT_BORDER_WIDTH = 0; + +static const guint PREFS_DIALOG_DEFAULT_WIDTH = 500; +static const guint PREFS_DIALOG_DEFAULT_HEIGHT = 300; + +enum +{ + COMMAND_ROW = 0, + USERNAME_ROW, + PASSWORD_ROW +}; + +/* NautilusPrefsDialogClass methods */ +static void nautilus_prefs_dialog_initialize_class (NautilusPrefsDialogClass *klass); +static void nautilus_prefs_dialog_initialize (NautilusPrefsDialog *prefs_dialog); + +/* GtkObjectClass methods */ +static void nautilus_prefs_dialog_destroy (GtkObject *object); +static void dialog_clicked (GtkWidget *widget, + gint n, + gpointer data); +static void dialog_show (GtkWidget *widget, + gpointer data); +static void dialog_destroy (GtkWidget *widget, + gpointer data); + +/* Misc private stuff */ +static void nautilus_prefs_dialog_construct (NautilusPrefsDialog *prefs_dialog, + const gchar *dialog_title); + + +NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusPrefsDialog, + nautilus_prefs_dialog, + gnome_dialog_get_type ()) + +/* + * NautilusPrefsDialogClass methods + */ +static void +nautilus_prefs_dialog_initialize_class (NautilusPrefsDialogClass * klass) +{ + GtkObjectClass * object_class; + GtkWidgetClass * widget_class; + + object_class = GTK_OBJECT_CLASS(klass); + widget_class = GTK_WIDGET_CLASS(klass); + + parent_class = gtk_type_class(gnome_dialog_get_type()); + + /* GtkObjectClass */ + object_class->destroy = nautilus_prefs_dialog_destroy; +} + +static void +nautilus_prefs_dialog_initialize (NautilusPrefsDialog * prefs_dialog) +{ + prefs_dialog->priv = g_new (NautilusPrefsDialogPrivate, 1); + + prefs_dialog->priv->prefs_box = NULL; +} + +static void +dialog_clicked(GtkWidget * widget, gint n, gpointer data) +{ + NautilusPrefsDialog * prefs_dialog = (NautilusPrefsDialog *) data; + + g_assert(prefs_dialog); + +// gtk_grab_remove(GTK_WIDGET(prefs_dialog)); + + gtk_widget_hide(GTK_WIDGET(prefs_dialog)); +} + +static void +dialog_show(GtkWidget * widget, gpointer data) +{ + NautilusPrefsDialog * prefs_dialog = (NautilusPrefsDialog *) data; + + g_assert(prefs_dialog); + +// gtk_caption_table_entry_grab_focus(GTK_CAPTION_TABLE(prefs_dialog->priv->table), +// PASSWORD_ROW); +} + +static void +dialog_destroy(GtkWidget * widget, gpointer data) +{ + NautilusPrefsDialog * prefs_dialog = (NautilusPrefsDialog *) data; + + g_assert(prefs_dialog); + +// gtk_grab_remove(GTK_WIDGET(prefs_dialog)); + +// gtk_widget_destroy (widget); +} + +static void +nautilus_prefs_dialog_construct (NautilusPrefsDialog *prefs_dialog, + const gchar *dialog_title) +{ + GnomeDialog *gnome_dialog; + + g_assert (prefs_dialog != NULL); + g_assert (prefs_dialog->priv != NULL); + + g_assert (prefs_dialog->priv->prefs_box == NULL); + + gnome_dialog = GNOME_DIALOG (prefs_dialog); + + gnome_dialog_constructv (gnome_dialog, dialog_title, stock_buttons); + + /* Setup the dialog */ + gtk_window_set_policy (GTK_WINDOW (prefs_dialog), + FALSE, /* allow_shrink */ + TRUE, /* allow_grow */ + FALSE); /* auto_shrink */ + + gtk_widget_set_usize (GTK_WIDGET (prefs_dialog), + PREFS_DIALOG_DEFAULT_WIDTH, + PREFS_DIALOG_DEFAULT_HEIGHT); + + /* Doesnt work in enlightenment or sawmill */ +#if 0 + /* This is supposed to setup the window manager functions */ + gdk_window_set_functions (GTK_WIDGET (prefs_dialog)->window, GDK_FUNC_MOVE | GDK_FUNC_RESIZE); +#endif + +// gdk_window_set_decorations (GTK_WINDOW(prefs_dialog), GDK_DECOR_ALL); + + gtk_window_set_position (GTK_WINDOW (prefs_dialog), GTK_WIN_POS_CENTER); + + gtk_container_set_border_width (GTK_CONTAINER(prefs_dialog), + DEFAULT_BORDER_WIDTH); + + gnome_dialog_set_default (GNOME_DIALOG(prefs_dialog), + DEFAULT_BUTTON); + + gtk_signal_connect (GTK_OBJECT (prefs_dialog), + "clicked", + GTK_SIGNAL_FUNC (dialog_clicked), + (gpointer) prefs_dialog); + + gtk_signal_connect (GTK_OBJECT (prefs_dialog), + "show", + GTK_SIGNAL_FUNC(dialog_show), + (gpointer) prefs_dialog); + + gtk_signal_connect (GTK_OBJECT (prefs_dialog), + "destroy", + GTK_SIGNAL_FUNC (dialog_destroy), + (gpointer) prefs_dialog); + + /* Configure the GNOME_DIALOG's vbox */ + g_assert (gnome_dialog->vbox); + + prefs_dialog->priv->prefs_box = nautilus_prefs_box_new (_("Prefs Box")); + + gtk_box_set_spacing (GTK_BOX (gnome_dialog->vbox), 10); + + gtk_box_pack_start (GTK_BOX (gnome_dialog->vbox), + prefs_dialog->priv->prefs_box, + TRUE, /* expand */ + TRUE, /* fill */ + 0); /* padding */ + + gtk_widget_show (prefs_dialog->priv->prefs_box); +} + +GtkWidget* +nautilus_prefs_dialog_new (const gchar *dialog_title) +{ + NautilusPrefsDialog *prefs_dialog; + + prefs_dialog = gtk_type_new (nautilus_prefs_dialog_get_type ()); + + nautilus_prefs_dialog_construct (prefs_dialog, dialog_title); + + return GTK_WIDGET (prefs_dialog); +} + +/* GtkObjectClass methods */ +static void +nautilus_prefs_dialog_destroy(GtkObject* object) +{ + NautilusPrefsDialog * prefs_dialog; + + g_return_if_fail (object != NULL); + g_return_if_fail (NAUTILUS_IS_PREFS_DIALOG (object)); + + prefs_dialog = NAUTILUS_PREFS_DIALOG(object); + + g_free (prefs_dialog->priv); + + /* Chain */ + if (GTK_OBJECT_CLASS (parent_class)->destroy != NULL) + (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); +} + +gboolean +nautilus_prefs_dialog_run_and_block(NautilusPrefsDialog* prefs_dialog) +{ +// g_return_val_if_fail(prefs_dialog, FALSE); + +// prefs_dialog->priv->last_button_clicked = UNKNOWN_BUTTON; + +// gtk_widget_show_all(GTK_WIDGET(prefs_dialog)); + +// gtk_grab_add(GTK_WIDGET(prefs_dialog)); + +// while (prefs_dialog->priv->last_button_clicked == UNKNOWN_BUTTON) +// gtk_main_iteration(); + +// if (prefs_dialog->priv->last_button_clicked == OK_BUTTON) +// return TRUE; + + return FALSE; +} + +GtkWidget* +nautilus_prefs_dialog_get_prefs_box (NautilusPrefsDialog *prefs_dialog) +{ + g_return_val_if_fail (prefs_dialog != NULL, NULL); + g_return_val_if_fail (NAUTILUS_IS_PREFS_DIALOG (prefs_dialog), NULL); + + return prefs_dialog->priv->prefs_box; +} diff --git a/nautilus-widgets/nautilus-preferences-dialog.h b/nautilus-widgets/nautilus-preferences-dialog.h new file mode 100644 index 000000000..60637d2a6 --- /dev/null +++ b/nautilus-widgets/nautilus-preferences-dialog.h @@ -0,0 +1,71 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ + +/* nautilus-preferences-dialog.h - Interface for preferences dialog. + + Copyright (C) 1999, 2000 Eazel, Inc. + + The Gnome Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + The Gnome Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the Gnome Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. + + Authors: Ramiro Estrugo <ramiro@eazel.com> +*/ + +#ifndef NAUTILUS_PREFS_DIALOG_H +#define NAUTILUS_PREFS_DIALOG_H + +#include <libgnomeui/gnome-dialog.h> +#include <nautilus-widgets/nautilus-preferences-box.h> + +//#include <gnome.h> + +BEGIN_GNOME_DECLS + +#define NAUTILUS_TYPE_PREFS_DIALOG (nautilus_prefs_dialog_get_type ()) +#define NAUTILUS_PREFS_DIALOG(obj) (GTK_CHECK_CAST ((obj), NAUTILUS_TYPE_PREFS_DIALOG, NautilusPrefsDialog)) +#define NAUTILUS_PREFS_DIALOG_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), NAUTILUS_TYPE_PREFS_DIALOG, NautilusPrefsDialogClass)) +#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)) + + +typedef struct _NautilusPrefsDialog NautilusPrefsDialog; +typedef struct _NautilusPrefsDialogClass NautilusPrefsDialogClass; +typedef struct _NautilusPrefsDialogPrivate NautilusPrefsDialogPrivate; + +struct _NautilusPrefsDialog +{ + /* Super Class */ + GnomeDialog gnome_dialog; + + /* Private stuff */ + NautilusPrefsDialogPrivate *priv; +}; + +struct _NautilusPrefsDialogClass +{ + GnomeDialogClass parent_class; + + void (*activate) (GtkWidget * prefs_dialog, gint entry_number); +}; + +GtkType nautilus_prefs_dialog_get_type (void); +GtkWidget* nautilus_prefs_dialog_new (const gchar *dialog_title); +gboolean nautilus_prefs_dialog_run_and_block (NautilusPrefsDialog *prefs_dialog); +GtkWidget* nautilus_prefs_dialog_get_prefs_box (NautilusPrefsDialog *prefs_dialog); + +BEGIN_GNOME_DECLS + +#endif /* NAUTILUS_PREFS_DIALOG_H */ + + diff --git a/nautilus-widgets/nautilus-preferences-group.c b/nautilus-widgets/nautilus-preferences-group.c new file mode 100644 index 000000000..180c10ab6 --- /dev/null +++ b/nautilus-widgets/nautilus-preferences-group.c @@ -0,0 +1,237 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ + +/* nautilus-prefs-group-radio.c - Radio button prefs group implementation. + + Copyright (C) 1999, 2000 Eazel, Inc. + + The Gnome Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + The Gnome Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the Gnome Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. + + Authors: Ramiro Estrugo <ramiro@eazel.com> +*/ + +#include "nautilus-preferences-group.h" +//#include "nautilus-prefs.h" + +#include <gnome.h> +#include <gtk/gtkradiobutton.h> +#include <gtk/gtksignal.h> +#include <libnautilus/nautilus-gtk-macros.h> + +/* Signals */ +typedef enum +{ + CHANGED, + LAST_SIGNAL +} RadioGroupSignals; + +typedef struct +{ + GtkWidget *radio_button; +} ButtonInfo; + +struct _NautilusPreferencesGroupPrivate +{ + GtkWidget *main_box; + GtkWidget *content_box; + GtkWidget *description_label; + gboolean show_description; +}; + +static const gint PREFERENCES_GROUP_NOT_FOUND = -1; + +/* NautilusPreferencesGroupClass methods */ +static void nautilus_preferences_group_initialize_class (NautilusPreferencesGroupClass *klass); +static void nautilus_preferences_group_initialize (NautilusPreferencesGroup *preferences_group); + + +/* GtkObjectClass methods */ +static void nautilus_preferences_group_destroy (GtkObject *object); + + +/* NautilusPrefsGroupClass methods */ +static void preferences_group_construct (NautilusPreferencesGroup *prefs_group, + const gchar * title); + +NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusPreferencesGroup, + nautilus_preferences_group, + GTK_TYPE_FRAME); + +/* + * NautilusPreferencesGroupClass methods + */ +static void +nautilus_preferences_group_initialize_class (NautilusPreferencesGroupClass *preferences_group_class) +{ + GtkObjectClass *object_class; + GtkWidgetClass *widget_class; + + object_class = GTK_OBJECT_CLASS (preferences_group_class); + widget_class = GTK_WIDGET_CLASS (preferences_group_class); + + parent_class = gtk_type_class (gtk_frame_get_type ()); + + /* GtkObjectClass */ + object_class->destroy = nautilus_preferences_group_destroy; +} + +static void +nautilus_preferences_group_initialize (NautilusPreferencesGroup *group) +{ + group->priv = g_new (NautilusPreferencesGroupPrivate, 1); + + group->priv->main_box = NULL; + group->priv->content_box = NULL; + group->priv->description_label = NULL; + group->priv->show_description = FALSE; +} + +/* + * GtkObjectClass methods + */ +static void +nautilus_preferences_group_destroy(GtkObject* object) +{ + NautilusPreferencesGroup *group; + + g_return_if_fail (object != NULL); + g_return_if_fail (NAUTILUS_IS_PREFERENCES_GROUP (object)); + + group = NAUTILUS_PREFERENCES_GROUP (object); + + g_free (group->priv); + + /* Chain */ + if (GTK_OBJECT_CLASS (parent_class)->destroy != NULL) + (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); +} + +static void +preferences_group_construct (NautilusPreferencesGroup *group, + const gchar * title) +{ + g_assert (group != NULL); + g_assert (title != NULL); + + g_assert (group->priv->content_box == NULL); + g_assert (group->priv->main_box == NULL); + g_assert (group->priv->description_label == NULL); + +// printf ("preferences_group_construct\n"); + +// pref_info = nautilus_prefs_get_pref_info (NAUTILUS_PREFS (prefs), +// pref_name); + +// g_assert (pref_info != NULL); + +// g_assert (pref_info->pref_description != NULL); + + /* Ourselves */ + gtk_frame_set_shadow_type (GTK_FRAME (group), + GTK_SHADOW_ETCHED_IN); + + +// gtk_object_set (GTK_OBJECT (group), +// "title_string", group_title, +// NULL); + + gtk_frame_set_label (GTK_FRAME (group), title); + + /* Main box */ + group->priv->main_box = gtk_vbox_new (FALSE, 0); + + gtk_container_add (GTK_CONTAINER (group), + group->priv->main_box); + +// gtk_container_set_border_width (GTK_CONTAINER (group->priv->content_box), +// GROUP_FRAME_BORDER_WIDTH); + + /* Description label */ + group->priv->description_label = gtk_label_new ("Blurb"); + + gtk_label_set_justify (GTK_LABEL (group->priv->description_label), + GTK_JUSTIFY_LEFT); + + gtk_box_pack_start (GTK_BOX (group->priv->main_box), + group->priv->description_label, + FALSE, + FALSE, + 0); + + if (group->priv->show_description) + { + gtk_widget_show (group->priv->description_label); + } + + /* Content box */ + group->priv->content_box = + gtk_vbox_new (FALSE, 0); + + gtk_box_pack_start (GTK_BOX (group->priv->main_box), + group->priv->content_box, + FALSE, + FALSE, + 0); + + gtk_container_set_border_width (GTK_CONTAINER (group->priv->content_box), + 4); + + gtk_widget_show (group->priv->content_box); + gtk_widget_show (group->priv->main_box); +} + +/* + * NautilusPreferencesGroup public methods + */ +GtkWidget* +nautilus_preferences_group_new (const gchar *title) +{ + NautilusPreferencesGroup *group; + + g_return_val_if_fail (title != NULL, NULL); + +/* printf("nautilus_preferences_group_new()\n"); */ + + group = gtk_type_new (nautilus_preferences_group_get_type ()); + + preferences_group_construct (group, title); + + return GTK_WIDGET (group); +} + +// void +// nautilus_preferences_group_clear (NautilusPreferencesGroup *preferences_group) +// { +// } + +void +nautilus_preferences_group_add (NautilusPreferencesGroup *group, + GtkWidget *item) +{ + g_return_if_fail (group != NULL); + g_return_if_fail (NAUTILUS_IS_PREFERENCES_GROUP (group)); + g_return_if_fail (item != NULL); + +/* printf("nautilus_preferences_group_add()\n"); */ + + gtk_box_pack_start (GTK_BOX (group->priv->content_box), + item, + TRUE, + TRUE, + 0); + +// gtk_widget_show (item); +} + diff --git a/nautilus-widgets/nautilus-preferences-group.h b/nautilus-widgets/nautilus-preferences-group.h new file mode 100644 index 000000000..32ff16ffd --- /dev/null +++ b/nautilus-widgets/nautilus-preferences-group.h @@ -0,0 +1,67 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ + +/* nautilus-prefs-group-check.h - Check button prefs group interface. + + Copyright (C) 1999, 2000 Eazel, Inc. + + The Gnome Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + The Gnome Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the Gnome Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. + + Authors: Ramiro Estrugo <ramiro@eazel.com> +*/ + +#ifndef NAUTILUS_PREFERENCES_GROUP_H +#define NAUTILUS_PREFERENCES_GROUP_H + +#include <gtk/gtkframe.h> +#include <gnome.h> + +BEGIN_GNOME_DECLS + +#define NAUTILUS_TYPE_PREFERENCES_GROUP (nautilus_preferences_group_get_type ()) +#define NAUTILUS_PREFERENCES_GROUP(obj) (GTK_CHECK_CAST ((obj), NAUTILUS_TYPE_PREFERENCES_GROUP, NautilusPreferencesGroup)) +#define NAUTILUS_PREFERENCES_GROUP_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), NAUTILUS_TYPE_PREFERENCES_GROUP, NautilusPreferencesGroupClass)) +#define NAUTILUS_IS_PREFERENCES_GROUP(obj) (GTK_CHECK_TYPE ((obj), NAUTILUS_TYPE_PREFERENCES_GROUP)) +#define NAUTILUS_IS_PREFERENCES_GROUP_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), NAUTILUS_TYPE_PREFERENCES_GROUP)) + +typedef struct _NautilusPreferencesGroup NautilusPreferencesGroup; +typedef struct _NautilusPreferencesGroupClass NautilusPreferencesGroupClass; +typedef struct _NautilusPreferencesGroupPrivate NautilusPreferencesGroupPrivate; + +struct _NautilusPreferencesGroup +{ + /* Super Class */ + GtkFrame frame; + + /* Private stuff */ + NautilusPreferencesGroupPrivate *priv; +}; + +struct _NautilusPreferencesGroupClass +{ + GtkFrameClass parent_class; +}; + +GtkType nautilus_preferences_group_get_type (void); +GtkWidget* nautilus_preferences_group_new (const gchar *title); + +void nautilus_preferences_group_add (NautilusPreferencesGroup *preferences_group, + GtkWidget *item); + +BEGIN_GNOME_DECLS + +#endif /* NAUTILUS_PREFERENCES_GROUP_H */ + + diff --git a/nautilus-widgets/nautilus-preferences-item.c b/nautilus-widgets/nautilus-preferences-item.c new file mode 100644 index 000000000..6c636d68f --- /dev/null +++ b/nautilus-widgets/nautilus-preferences-item.c @@ -0,0 +1,370 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ + +/* nautilus-preferences-item.c - Implementation for an individual prefs item. + + Copyright (C) 1999, 2000 Eazel, Inc. + + The Gnome Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + The Gnome Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the Gnome Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. + + Authors: Ramiro Estrugo <ramiro@eazel.com> +*/ + +#include "nautilus-preferences-item.h" +#include "nautilus-preferences.h" +#include <libnautilus/nautilus-gtk-macros.h> + +#include <gtk/gtkcheckbutton.h> +#include <nautilus-widgets/nautilus-radio-button-group.h> + +#include <gtk/gtklabel.h> +#include <gtk/gtkframe.h> +#include <gtk/gtkhbox.h> +#include <gtk/gtkvbox.h> + +// #include <gtk/gtkmain.h> +#include <gnome.h> + +#include <libgnomeui/gnome-stock.h> +#include <gtk/gtkmain.h> +#include <gtk/gtksignal.h> + +/* Arguments */ +enum +{ + ARG_0, + ARG_SHOW_DESCRIPTION, + ARG_DESCRIPTION_STRING, + ARG_TITLE_STRING +}; + +enum +{ + ACTIVATE, + LAST_SIGNAL +}; + +static const guint PREFERENCES_ITEM_TITLE_SPACING = 4; +static const guint PREFERENCES_ITEM_FRAME_BORDER_WIDTH = 6; + +struct _NautilusPreferencesItemDetails +{ + gchar *pref_name; + NautilusPreferencesItemType item_type; + GtkWidget *child; + GtkObject *prefs; +}; + +/* NautilusPreferencesItemClass methods */ +static void nautilus_preferences_item_initialize_class (NautilusPreferencesItemClass *klass); +static void nautilus_preferences_item_initialize (NautilusPreferencesItem *preferences_item); + + + +/* GtkObjectClass methods */ +static void preferences_item_destroy (GtkObject *object); +static void preferences_item_set_arg (GtkObject *object, + GtkArg *arg, + guint arg_id); +static void preferences_item_get_arg (GtkObject *object, + GtkArg *arg, + guint arg_id); + +/* Private stuff */ +static void preferences_item_construct (NautilusPreferencesItem *item, + GtkObject *prefs, + const gchar *pref_name, + NautilusPreferencesItemType item_type); + +static void test_radio_changed_signal (GtkWidget *button_group, GtkWidget * button, gpointer user_data); + +NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusPreferencesItem, nautilus_preferences_item, GTK_TYPE_VBOX) + +/* + * NautilusPreferencesItemClass methods + */ +static void +nautilus_preferences_item_initialize_class (NautilusPreferencesItemClass *preferences_item_class) +{ + GtkObjectClass *object_class; + GtkWidgetClass *widget_class; + + object_class = GTK_OBJECT_CLASS (preferences_item_class); + widget_class = GTK_WIDGET_CLASS (preferences_item_class); + + parent_class = gtk_type_class (gtk_vbox_get_type ()); + + /* Arguments */ + gtk_object_add_arg_type ("NautilusPreferencesItem::show_description", + GTK_TYPE_BOOL, + GTK_ARG_READWRITE, + ARG_SHOW_DESCRIPTION); + + gtk_object_add_arg_type ("NautilusPreferencesItem::description_string", + GTK_TYPE_STRING, + GTK_ARG_WRITABLE, + ARG_DESCRIPTION_STRING); + + gtk_object_add_arg_type ("NautilusPreferencesItem::title_string", + GTK_TYPE_STRING, + GTK_ARG_WRITABLE, + ARG_TITLE_STRING); + + /* GtkObjectClass */ + object_class->destroy = preferences_item_destroy; + object_class->set_arg = preferences_item_set_arg; + object_class->get_arg = preferences_item_get_arg; + +// /* NautilusPreferencesItemClass */ +// preferences_item_class->construct = preferences_item_construct; +// preferences_item_class->changed = NULL; +} + +static void +nautilus_preferences_item_initialize (NautilusPreferencesItem *item) +{ + item->details = g_new (NautilusPreferencesItemDetails, 1); + + item->details->pref_name = NULL; + item->details->item_type = NAUTILUS_PREFERENCES_ITEM_UNKNOWN; + item->details->child = NULL; + item->details->prefs = NULL; +} + +/* + * GtkObjectClass methods + */ +static void +preferences_item_destroy (GtkObject *object) +{ + NautilusPreferencesItem * item; + + g_return_if_fail (object != NULL); + g_return_if_fail (NAUTILUS_IS_PREFERENCES_ITEM (object)); + + item = NAUTILUS_PREFERENCES_ITEM (object); + + if (item->details->pref_name) + { + g_free (item->details->pref_name); + } + + g_free (item->details); + + /* Chain */ + if (GTK_OBJECT_CLASS (parent_class)->destroy != NULL) + (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); +} + +static void +preferences_item_set_arg (GtkObject *object, + GtkArg *arg, + guint arg_id) +{ + NautilusPreferencesItem * item; + + g_return_if_fail (object != NULL); + g_return_if_fail (NAUTILUS_IS_PREFERENCES_ITEM (object)); + + item = NAUTILUS_PREFERENCES_ITEM (object); + +#if 0 + switch (arg_id) + { + case ARG_SHOW_DESCRIPTION: + item->details->show_description = GTK_VALUE_BOOL (*arg); + + if (item->details->show_description) + { + gtk_widget_show (item->details->description_label); + } + else + { + gtk_widget_hide (item->details->description_label); + } + + break; + + case ARG_DESCRIPTION_STRING: + + gtk_label_set_text (GTK_LABEL (item->details->description_label), + GTK_VALUE_STRING (*arg)); + break; + + case ARG_TITLE_STRING: + + gtk_frame_set_label (GTK_FRAME (object), GTK_VALUE_STRING (*arg)); + + break; + } +#endif + +} + +static void +preferences_item_get_arg (GtkObject *object, + GtkArg *arg, + guint arg_id) +{ + NautilusPreferencesItem * item; + + g_return_if_fail (object != NULL); + g_return_if_fail (NAUTILUS_IS_PREFERENCES_ITEM (object)); + + item = NAUTILUS_PREFERENCES_ITEM (object); + +#if 0 + switch (arg_id) + { + case ARG_SHOW_DESCRIPTION: + GTK_VALUE_BOOL (*arg) = + GTK_WIDGET_VISIBLE (item->details->description_label); + break; + } +#endif +} + +/* + * Private stuff + */ +static void +preferences_item_construct (NautilusPreferencesItem *item, + GtkObject *prefs, + const gchar *pref_name, + NautilusPreferencesItemType item_type) +{ + g_return_if_fail (item != NULL); + g_return_if_fail (prefs != NULL); + g_return_if_fail (pref_name != NULL); + g_return_if_fail (NAUTILUS_IS_PREFERENCES_ITEM (item)); + + g_return_if_fail (item_type != NAUTILUS_PREFERENCES_ITEM_UNKNOWN); + + g_return_if_fail (item->details->child == NULL); + +// printf("preferences_item_construct (%s)\n", +// pref_name); + + item->details->prefs = prefs; + item->details->pref_name = g_strdup (pref_name); + + switch (item_type) + { + case NAUTILUS_PREFERENCES_ITEM_BOOL: + + item->details->child = gtk_check_button_new_with_label ("BOOL"); + + break; + + case NAUTILUS_PREFERENCES_ITEM_ENUM: + { + const NautilusPrefInfo * pref_info; + NautilusPrefEnumData * enum_info; + guint i; + gint value; + + + item->details->child = nautilus_radio_button_group_new (); + + pref_info = nautilus_prefs_get_pref_info (NAUTILUS_PREFS (prefs), + item->details->pref_name); + + g_assert (pref_info != NULL); + + enum_info = (NautilusPrefEnumData *) pref_info->type_data; + + g_assert (enum_info != NULL); + + + value = nautilus_prefs_get_enum (NAUTILUS_PREFS (prefs), + item->details->pref_name); + + for (i = 0; i < enum_info->num_entries; i++) + { + nautilus_radio_button_group_insert (NAUTILUS_RADIO_BUTTON_GROUP (item->details->child), + enum_info->enum_descriptions[i]); + + if (i == value) + { + nautilus_radio_button_group_set_active_index (NAUTILUS_RADIO_BUTTON_GROUP (item->details->child), i); + + } + } + + gtk_signal_connect (GTK_OBJECT (item->details->child), + "changed", + GTK_SIGNAL_FUNC (test_radio_changed_signal), + (gpointer) item); + } + break; + + case NAUTILUS_PREFERENCES_ITEM_INT: + break; + + case NAUTILUS_PREFERENCES_ITEM_UNKNOWN: + g_assert_not_reached (); + break; + } + + g_assert (item->details->child != NULL); + + gtk_box_pack_start (GTK_BOX (item), + item->details->child, + FALSE, + FALSE, + 0); + + gtk_widget_show (item->details->child); +} + +/* + * NautilusPreferencesItem public methods + */ +GtkWidget * +nautilus_preferences_item_new (GtkObject *prefs, + const gchar *pref_name, + NautilusPreferencesItemType item_type) +{ + NautilusPreferencesItem * item; + + g_return_val_if_fail (prefs != NULL, NULL); + g_return_val_if_fail (pref_name != NULL, NULL); + + item = gtk_type_new (nautilus_preferences_item_get_type ()); + +// printf ("nautilus_preferences_item_new (%s)\n", pref_name); + + preferences_item_construct (item, prefs, pref_name, item_type); + + return GTK_WIDGET (item); +} + +static void +test_radio_changed_signal (GtkWidget *buttons, GtkWidget * button, gpointer user_data) +{ + NautilusPreferencesItem * item = (NautilusPreferencesItem *) user_data; + + gint i; + + g_assert (item != NULL); + + i = nautilus_radio_button_group_get_active_index (NAUTILUS_RADIO_BUTTON_GROUP (buttons)); + +// printf ("test_radio_changed_signal (%s = %d)\n", item->details->pref_name, i); + + nautilus_prefs_set_enum (NAUTILUS_PREFS (item->details->prefs), + item->details->pref_name, + i); +} diff --git a/nautilus-widgets/nautilus-preferences-item.h b/nautilus-widgets/nautilus-preferences-item.h new file mode 100644 index 000000000..4a9bb30a2 --- /dev/null +++ b/nautilus-widgets/nautilus-preferences-item.h @@ -0,0 +1,81 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ + +/* nautilus-preferences-item.h - Interface for an individual prefs item. + + Copyright (C) 1999, 2000 Eazel, Inc. + + The Gnome Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + The Gnome Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the Gnome Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. + + Authors: Ramiro Estrugo <ramiro@eazel.com> +*/ + +#ifndef NAUTILUS_PREFERENCES_ITEM_H +#define NAUTILUS_PREFERENCES_ITEM_H + +#include <gtk/gtkvbox.h> +#include <gnome.h> + +BEGIN_GNOME_DECLS + +#define NAUTILUS_TYPE_PREFERENCES_ITEM (nautilus_preferences_item_get_type ()) +#define NAUTILUS_PREFERENCES_ITEM(obj) (GTK_CHECK_CAST ((obj), NAUTILUS_TYPE_PREFERENCES_ITEM, NautilusPreferencesItem)) +#define NAUTILUS_PREFERENCES_ITEM_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), NAUTILUS_TYPE_PREFERENCES_ITEM, NautilusPreferencesItemClass)) +#define NAUTILUS_IS_PREFERENCES_ITEM(obj) (GTK_CHECK_TYPE ((obj), NAUTILUS_TYPE_PREFERENCES_ITEM)) +#define NAUTILUS_IS_PREFERENCES_ITEM_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), NAUTILUS_TYPE_PREFERENCES_ITEM)) + +typedef struct _NautilusPreferencesItem NautilusPreferencesItem; +typedef struct _NautilusPreferencesItemClass NautilusPreferencesItemClass; +typedef struct _NautilusPreferencesItemDetails NautilusPreferencesItemDetails; + +typedef enum +{ + NAUTILUS_PREFERENCES_ITEM_UNKNOWN, + NAUTILUS_PREFERENCES_ITEM_BOOL, + NAUTILUS_PREFERENCES_ITEM_ENUM, + NAUTILUS_PREFERENCES_ITEM_INT +} NautilusPreferencesItemType; + +struct _NautilusPreferencesItem +{ + /* Super Class */ + GtkVBox vbox; + + /* Private stuff */ + NautilusPreferencesItemDetails *details; +}; + +struct _NautilusPreferencesItemClass +{ + GtkVBoxClass vbox_class; + +// void (*construct) (NautilusPreferencesItem *preferences_item, +// const gchar * group_title, +// GtkObject *prefs, +// const gchar *pref_name); + +// void (*changed) (NautilusPreferencesItem *preferences_item); +}; + +GtkType nautilus_preferences_item_get_type (void); +GtkWidget* nautilus_preferences_item_new (GtkObject *prefs, + const gchar *pref_name, + NautilusPreferencesItemType item_type); + +BEGIN_GNOME_DECLS + +#endif /* NAUTILUS_PREFERENCES_ITEM_H */ + + diff --git a/nautilus-widgets/nautilus-preferences-pane.c b/nautilus-widgets/nautilus-preferences-pane.c new file mode 100644 index 000000000..647858eec --- /dev/null +++ b/nautilus-widgets/nautilus-preferences-pane.c @@ -0,0 +1,283 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ + +/* nautilus-preferences-pane.h - Interface for a prefs pane superclass. + + Copyright (C) 1999, 2000 Eazel, Inc. + + The Gnome Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + The Gnome Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the Gnome Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. + + Authors: Ramiro Estrugo <ramiro@eazel.com> +*/ + + +#include <nautilus-widgets/nautilus-preferences-pane.h> +#include <libnautilus/nautilus-gtk-macros.h> + +#include <gtk/gtklabel.h> +#include <gtk/gtkframe.h> +#include <gtk/gtkhbox.h> + +// #include <gtk/gtkmain.h> +#include <gnome.h> + +#include <libgnomeui/gnome-stock.h> +#include <gtk/gtkmain.h> +#include <gtk/gtksignal.h> + +enum +{ + ACTIVATE, + LAST_SIGNAL +}; + +static const guint PREFS_PANE_GROUPS_BOX_TOP_OFFSET = 0; + +struct _NautilusPrefsPanePrivate +{ + GtkWidget *title_box; + GtkWidget *title_frame; + GtkWidget *title_label; + GtkWidget *description_label; + + GtkWidget *groups_box; + + gboolean show_title; + + GSList *groups; +}; + +typedef void (*GnomeBoxSignal1) (GtkObject* object, + gint arg1, + gpointer data); + +/* NautilusPrefsPaneClass methods */ +static void nautilus_prefs_pane_initialize_class (NautilusPrefsPaneClass *klass); +static void nautilus_prefs_pane_initialize (NautilusPrefsPane *prefs_pane); + +/* GtkObjectClass methods */ +static void nautilus_prefs_pane_destroy (GtkObject *object); + +/* Private stuff */ +static void prefs_pane_construct (NautilusPrefsPane *prefs_pane, + const gchar *pane_title, + const gchar *pane_description); + +NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusPrefsPane, nautilus_prefs_pane, GTK_TYPE_VBOX) + +/* + * NautilusPrefsPaneClass methods + */ +static void +nautilus_prefs_pane_initialize_class (NautilusPrefsPaneClass *prefs_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 ()); + + /* GtkObjectClass */ + object_class->destroy = nautilus_prefs_pane_destroy; +} + +static void +nautilus_prefs_pane_initialize (NautilusPrefsPane *prefs_pane) +{ + prefs_pane->priv = g_new (NautilusPrefsPanePrivate, 1); + + prefs_pane->priv->title_label = NULL; + prefs_pane->priv->description_label = NULL; + prefs_pane->priv->title_box = NULL; + prefs_pane->priv->title_frame = NULL; + prefs_pane->priv->groups_box = NULL; + prefs_pane->priv->groups = NULL; + prefs_pane->priv->show_title = FALSE; +} + +/* + * GtkObjectClass methods + */ +static void +nautilus_prefs_pane_destroy(GtkObject* object) +{ + NautilusPrefsPane * prefs_pane; + + g_return_if_fail (object != NULL); + g_return_if_fail (NAUTILUS_IS_PREFS_PANE (object)); + + prefs_pane = NAUTILUS_PREFS_PANE (object); + + if (prefs_pane->priv->groups) + { + g_slist_free (prefs_pane->priv->groups); + } + + g_free (prefs_pane->priv); + + /* Chain */ + if (GTK_OBJECT_CLASS (parent_class)->destroy != NULL) + (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); +} + +/* + * Private stuff + */ +static void +prefs_pane_construct (NautilusPrefsPane *prefs_pane, + const gchar *pane_title, + const gchar *pane_description) +{ + g_assert (prefs_pane != NULL); + g_assert (prefs_pane->priv != NULL); + + g_assert (pane_title != NULL); + g_assert (pane_description != NULL); + + g_assert (prefs_pane->priv->title_label == NULL); + g_assert (prefs_pane->priv->description_label == NULL); + g_assert (prefs_pane->priv->title_box == NULL); + g_assert (prefs_pane->priv->groups_box == NULL); + g_assert (prefs_pane->priv->title_frame == NULL); + g_assert (prefs_pane->priv->groups == NULL); + + prefs_pane->priv->groups = g_slist_alloc (); + + if (prefs_pane->priv->show_title) + { + /* Title frame */ + prefs_pane->priv->title_frame = gtk_frame_new (NULL); + + gtk_frame_set_shadow_type (GTK_FRAME (prefs_pane->priv->title_frame), + GTK_SHADOW_ETCHED_IN); + + /* Title box */ + prefs_pane->priv->title_box = gtk_hbox_new (FALSE, 0); + + /* Title labels */ + prefs_pane->priv->title_label = gtk_label_new (pane_title); + prefs_pane->priv->description_label = gtk_label_new (pane_description); + + gtk_box_pack_start (GTK_BOX (prefs_pane->priv->title_box), + prefs_pane->priv->title_label, + FALSE, + FALSE, + 0); + + gtk_box_pack_end (GTK_BOX (prefs_pane->priv->title_box), + prefs_pane->priv->description_label, + FALSE, + FALSE, + 0); + + gtk_widget_show (prefs_pane->priv->title_label); + gtk_widget_show (prefs_pane->priv->description_label); + + /* Add title box to title frame */ + gtk_container_add (GTK_CONTAINER (prefs_pane->priv->title_frame), + prefs_pane->priv->title_box); + + gtk_widget_show (prefs_pane->priv->title_box); + + /* Add title frame to ourselves */ + gtk_box_pack_start (GTK_BOX (prefs_pane), + prefs_pane->priv->title_frame, + FALSE, + FALSE, + 0); + + gtk_widget_show (prefs_pane->priv->title_frame); + } + + /* Groups box */ + prefs_pane->priv->groups_box = gtk_vbox_new (TRUE, 0); + + /* Add groups box to ourselves */ + gtk_box_pack_start (GTK_BOX (prefs_pane), + prefs_pane->priv->groups_box, + FALSE, + FALSE, + PREFS_PANE_GROUPS_BOX_TOP_OFFSET); + + gtk_widget_show (prefs_pane->priv->groups_box); +} + + +/* + * NautilusPrefsPane public methods + */ +GtkWidget* +nautilus_prefs_pane_new (const gchar *pane_title, + const gchar *pane_description) +{ + NautilusPrefsPane *prefs_pane; + + g_return_val_if_fail (pane_title != NULL, NULL); + g_return_val_if_fail (pane_description != NULL, NULL); + + prefs_pane = gtk_type_new (nautilus_prefs_pane_get_type ()); + + prefs_pane_construct (prefs_pane, pane_title, pane_description); + + return GTK_WIDGET (prefs_pane); +} + +void +nautilus_prefs_pane_set_title (NautilusPrefsPane *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->priv->title_label != NULL); + + gtk_label_set_text (GTK_LABEL (prefs_pane->priv->title_label), + pane_title); +} + +void +nautilus_prefs_pane_set_description (NautilusPrefsPane *prefs_pane, + const gchar *pane_description) +{ + g_return_if_fail (prefs_pane != NULL); + g_return_if_fail (NAUTILUS_IS_PREFS_PANE (prefs_pane)); + + g_assert (prefs_pane->priv->description_label != NULL); + + gtk_label_set_text (GTK_LABEL (prefs_pane->priv->description_label), + pane_description); +} + +void +nautilus_prefs_pane_add_group (NautilusPrefsPane *prefs_pane, + GtkWidget *prefs_group) +{ + g_return_if_fail (prefs_pane != NULL); + g_return_if_fail (NAUTILUS_IS_PREFS_PANE (prefs_pane)); + g_return_if_fail (prefs_group != NULL); + +// group = nautilus_prefs_group_new (group_title); + + gtk_box_pack_start (GTK_BOX (prefs_pane->priv->groups_box), + prefs_group, + TRUE, + TRUE, + 0); + +// gtk_widget_show (prefs_group); +} + diff --git a/nautilus-widgets/nautilus-preferences-pane.h b/nautilus-widgets/nautilus-preferences-pane.h new file mode 100644 index 000000000..3a7674b30 --- /dev/null +++ b/nautilus-widgets/nautilus-preferences-pane.h @@ -0,0 +1,74 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ + +/* nautilus-preferences-pane.h - Interface for a prefs pane superclass. + + Copyright (C) 1999, 2000 Eazel, Inc. + + The Gnome Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + The Gnome Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the Gnome Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. + + Authors: Ramiro Estrugo <ramiro@eazel.com> +*/ + +#ifndef NAUTILUS_PREFS_PANE_H +#define NAUTILUS_PREFS_PANE_H + +#include <libgnomeui/gnome-dialog.h> +#include <gtk/gtkvbox.h> +#include <nautilus-widgets/nautilus-preferences-group.h> + +//#include <gnome.h> + +BEGIN_GNOME_DECLS + +#define NAUTILUS_TYPE_PREFS_PANE (nautilus_prefs_pane_get_type ()) +#define NAUTILUS_PREFS_PANE(obj) (GTK_CHECK_CAST ((obj), NAUTILUS_TYPE_PREFS_PANE, NautilusPrefsPane)) +#define NAUTILUS_PREFS_PANE_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), NAUTILUS_TYPE_PREFS_PANE, NautilusPrefsPaneClass)) +#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)) + +typedef struct _NautilusPrefsPane NautilusPrefsPane; +typedef struct _NautilusPrefsPaneClass NautilusPrefsPaneClass; +typedef struct _NautilusPrefsPanePrivate NautilusPrefsPanePrivate; + +struct _NautilusPrefsPane +{ + /* Super Class */ + GtkVBox vbox; + + /* Private stuff */ + NautilusPrefsPanePrivate *priv; +}; + +struct _NautilusPrefsPaneClass +{ + GtkVBoxClass parent_class; + + void (*construct) (NautilusPrefsPane *prefs_pane, GtkWidget *box); +}; + +GtkType nautilus_prefs_pane_get_type (void); +GtkWidget* nautilus_prefs_pane_new (const gchar *pane_title, + const gchar *pane_description); +void nautilus_prefs_pane_set_title (NautilusPrefsPane * prefs_pane, + const gchar *pane_title); +void nautilus_prefs_pane_set_description (NautilusPrefsPane * prefs_pane, + const gchar *pane_description); +void nautilus_prefs_pane_add_group (NautilusPrefsPane *prefs_pane, + GtkWidget *prefs_group); + +BEGIN_GNOME_DECLS + +#endif /* NAUTILUS_PREFS_PANE_H */ diff --git a/nautilus-widgets/nautilus-preferences.c b/nautilus-widgets/nautilus-preferences.c new file mode 100644 index 000000000..51c3768b7 --- /dev/null +++ b/nautilus-widgets/nautilus-preferences.c @@ -0,0 +1,628 @@ + /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ + +/* nautilus-prefs.h - Preference peek/poke/notify object implementation. + + Copyright (C) 1999, 2000 Eazel, Inc. + + The Gnome Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + The Gnome Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the Gnome Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. + + Authors: Ramiro Estrugo <ramiro@eazel.com> +*/ + + +#include <nautilus-widgets/nautilus-preferences.h> +#include <libnautilus/nautilus-gtk-macros.h> + +#include <gtk/gtkclist.h> + +// #include <gtk/gtkmain.h> + +#include <libgnomeui/gnome-stock.h> +#include <gtk/gtkmain.h> +#include <gtk/gtksignal.h> + +#include <stdio.h> + +enum +{ + ACTIVATE, + LAST_SIGNAL +}; + +typedef struct +{ + NautilusPrefInfo pref_info; + gpointer pref_value; + GList *callback_list; +} PrefHashInfo; + +typedef struct +{ + NautilusPrefsCallback callback_proc; + gpointer user_data; + const PrefHashInfo *hash_info; +} PrefCallbackInfo; + +struct _NautilusPrefsPrivate +{ + gchar *domain; + GHashTable *prefs_hash_table; +}; + +/* NautilusPrefsClass methods */ +static void nautilus_prefs_initialize_class (NautilusPrefsClass *klass); +static void nautilus_prefs_initialize (NautilusPrefs *prefs); + + + + +/* GtkObjectClass methods */ +static void prefs_destroy (GtkObject *object); + + + + +/* PrefHashInfo functions */ +static PrefHashInfo * pref_hash_info_alloc (const NautilusPrefInfo *pref_info); +static void pref_hash_info_free (PrefHashInfo *pref_hash_info); +static void pref_hash_info_free_func (gpointer key, + gpointer value, + gpointer user_data); + +/* PrefCallbackInfo functions */ +static PrefCallbackInfo * pref_callback_info_alloc (NautilusPrefsCallback callback_proc, + gpointer user_data, + const PrefHashInfo *hash_info); +static void pref_callback_info_free (PrefCallbackInfo *pref_hash_info); +static void pref_callback_info_free_func (gpointer data, + gpointer user_data); +static void pref_callback_info_invoke_func (gpointer data, + gpointer user_data); +static void pref_hash_info_add_callback (PrefHashInfo *pref_hash_info, + NautilusPrefsCallback callback_proc, + gpointer user_data); + +/* Private stuff */ +static GtkFundamentalType prefs_check_supported_type (GtkFundamentalType pref_type); +static gboolean prefs_set_pref (NautilusPrefs *prefs, + const gchar *pref_name, + gpointer pref_value); +static gboolean prefs_get_pref (NautilusPrefs *prefs, + const gchar *pref_name, + GtkFundamentalType *pref_type_out, + gconstpointer *pref_value_out); +PrefHashInfo * prefs_hash_lookup (NautilusPrefs *prefs, + const gchar *pref_name); + +NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusPrefs, nautilus_prefs, GTK_TYPE_OBJECT) + +/* + * NautilusPrefsClass methods + */ +static void +nautilus_prefs_initialize_class (NautilusPrefsClass *prefs_class) +{ + GtkObjectClass *object_class; + + object_class = GTK_OBJECT_CLASS (prefs_class); + + parent_class = gtk_type_class (gtk_object_get_type ()); + + /* GtkObjectClass */ + object_class->destroy = prefs_destroy; +} + +static void +nautilus_prefs_initialize (NautilusPrefs *prefs) +{ + prefs->priv = g_new (NautilusPrefsPrivate, 1); + + prefs->priv->domain = NULL; + + prefs->priv->prefs_hash_table = g_hash_table_new (g_str_hash, + g_str_equal); +} + +/* + * GtkObjectClass methods + */ +static void +prefs_destroy (GtkObject *object) +{ + NautilusPrefs * prefs; + + g_return_if_fail (object != NULL); + g_return_if_fail (NAUTILUS_IS_PREFS (object)); + + prefs = NAUTILUS_PREFS (object); + + if (prefs->priv->domain) + { + g_free (prefs->priv->domain); + prefs->priv->domain = NULL; + } + + if (prefs->priv->prefs_hash_table) + { + g_hash_table_foreach (prefs->priv->prefs_hash_table, + pref_hash_info_free_func, + (gpointer) NULL); + + g_hash_table_destroy (prefs->priv->prefs_hash_table); + + prefs->priv->prefs_hash_table = NULL; + } + + g_free (prefs->priv); + + /* Chain */ + if (GTK_OBJECT_CLASS (parent_class)->destroy != NULL) + (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); +} + +/* + * PrefHashInfo functions + */ +static PrefHashInfo * +pref_hash_info_alloc (const NautilusPrefInfo *pref_info) +{ + PrefHashInfo * pref_hash_info; + + g_assert (pref_info != NULL); + + g_assert (pref_info->pref_name != NULL); + g_assert (pref_info->pref_description != NULL); + + pref_hash_info = g_new (PrefHashInfo, 1); + + pref_hash_info->pref_info.pref_name = g_strdup (pref_info->pref_name); + pref_hash_info->pref_info.pref_description = g_strdup (pref_info->pref_description); + pref_hash_info->pref_info.pref_type = pref_info->pref_type; + pref_hash_info->pref_info.pref_default_value = pref_info->pref_default_value; + pref_hash_info->pref_info.type_data = pref_info->type_data; + + pref_hash_info->pref_value = (gpointer) pref_info->pref_default_value; + pref_hash_info->callback_list = NULL; + + return pref_hash_info; +} + +static void +pref_hash_info_free (PrefHashInfo *pref_hash_info) +{ + g_assert (pref_hash_info != NULL); + + g_assert (pref_hash_info->pref_info.pref_name != NULL); + g_assert (pref_hash_info->pref_info.pref_description != NULL); + + if (pref_hash_info->callback_list) + { + g_list_foreach (pref_hash_info->callback_list, + pref_callback_info_free_func, + (gpointer) NULL); + } + + g_free (pref_hash_info->pref_info.pref_name); + g_free (pref_hash_info->pref_info.pref_description); + + pref_hash_info->pref_info.pref_name = NULL; + pref_hash_info->pref_info.pref_type = GTK_TYPE_INVALID; + pref_hash_info->pref_info.pref_default_value = NULL; + pref_hash_info->pref_info.type_data = NULL; + + pref_hash_info->callback_list = NULL; + pref_hash_info->pref_value = NULL; + + g_free (pref_hash_info); +} + +static void +pref_hash_info_add_callback (PrefHashInfo *pref_hash_info, + NautilusPrefsCallback callback_proc, + gpointer user_data) +{ + PrefCallbackInfo * pref_callback_info; + + g_assert (pref_hash_info != NULL); + + g_assert (callback_proc != NULL); + + pref_callback_info = pref_callback_info_alloc (callback_proc, + user_data, + pref_hash_info); + + pref_hash_info->callback_list = + g_list_append (pref_hash_info->callback_list, + (gpointer) pref_callback_info); +} + +static void +pref_hash_info_free_func (gpointer key, + gpointer value, + gpointer user_data) +{ + PrefHashInfo *pref_hash_info; + + pref_hash_info = (PrefHashInfo *) value; + + g_assert (pref_hash_info != NULL); + + pref_hash_info_free (pref_hash_info); +} + +/* + * PrefCallbackInfo functions + */ +static PrefCallbackInfo * +pref_callback_info_alloc (NautilusPrefsCallback callback_proc, + gpointer user_data, + const PrefHashInfo *hash_info) +{ + PrefCallbackInfo * pref_callback_info; + + g_assert (callback_proc != NULL); + + pref_callback_info = g_new (PrefCallbackInfo, 1); + + pref_callback_info->callback_proc = callback_proc; + pref_callback_info->user_data = user_data; + pref_callback_info->hash_info = hash_info; + + return pref_callback_info; +} + +static void +pref_callback_info_free (PrefCallbackInfo *pref_callback_info) +{ + g_assert (pref_callback_info != NULL); + + pref_callback_info->callback_proc = NULL; + pref_callback_info->user_data = NULL; + + g_free (pref_callback_info); +} + +static void +pref_callback_info_free_func (gpointer data, + gpointer user_data) +{ + PrefCallbackInfo *pref_callback_info; + + pref_callback_info = (PrefCallbackInfo *) data; + + g_assert (pref_callback_info != NULL); + + pref_callback_info_free (pref_callback_info); +} + +static void +pref_callback_info_invoke_func (gpointer data, + gpointer user_data) +{ + const NautilusPrefs *prefs; + PrefCallbackInfo *pref_callback_info; + + pref_callback_info = (PrefCallbackInfo *) data; + + g_assert (pref_callback_info != NULL); + + g_assert (pref_callback_info->callback_proc != NULL); + + prefs = (const NautilusPrefs *) user_data; + + (*pref_callback_info->callback_proc) (GTK_OBJECT (prefs), + pref_callback_info->hash_info->pref_info.pref_name, + pref_callback_info->hash_info->pref_info.pref_type, + pref_callback_info->hash_info->pref_value, + pref_callback_info->user_data); +} + +/* + * Private stuff + */ +static GtkFundamentalType +prefs_check_supported_type (GtkFundamentalType pref_type) +{ + return ((pref_type == GTK_TYPE_BOOL) || + (pref_type == GTK_TYPE_INT) || + (pref_type == GTK_TYPE_ENUM)); +} + +static gboolean +prefs_set_pref (NautilusPrefs *prefs, + const gchar *pref_name, + gpointer pref_value) +{ + PrefHashInfo * pref_hash_info; + + g_return_val_if_fail (prefs != NULL, FALSE); + g_return_val_if_fail (NAUTILUS_IS_PREFS (prefs), FALSE); + g_return_val_if_fail (pref_name != NULL, FALSE); + + pref_hash_info = prefs_hash_lookup (prefs, pref_name); + + if (!pref_hash_info) + { + return FALSE; + } + + /* + * XXX FIXME: When we support GTK_TYPE_STRING, this + * will have to strcpy() the given value + */ + pref_hash_info->pref_value = pref_value; + + if (pref_hash_info->callback_list) + { + g_list_foreach (pref_hash_info->callback_list, + pref_callback_info_invoke_func, + (gpointer) prefs); + } + + return TRUE; +} + +static gboolean +prefs_get_pref (NautilusPrefs *prefs, + const gchar *pref_name, + GtkFundamentalType *pref_type_out, + gconstpointer *pref_value_out) +{ + PrefHashInfo * pref_hash_info; + + g_return_val_if_fail (prefs != NULL, FALSE); + g_return_val_if_fail (NAUTILUS_IS_PREFS (prefs), FALSE); + g_return_val_if_fail (pref_type_out != NULL, FALSE); + g_return_val_if_fail (pref_value_out != NULL, FALSE); + + if (!pref_hash_info) + { + return FALSE; + } + + pref_hash_info = prefs_hash_lookup (prefs, pref_name); + +// printf("looking for %s\n", pref_name); + + g_assert (pref_hash_info != NULL); + +// printf("pref_name = %s\n", pref_hash_info->pref_info.pref_name); +// printf("pref_desc = %s\n", pref_hash_info->pref_info.pref_description); +// printf("pref_type = %d\n", pref_hash_info->pref_info.pref_type); + + *pref_type_out = pref_hash_info->pref_info.pref_type; + *pref_value_out = pref_hash_info->pref_value; + + return TRUE; +} + +/* + * NautilusPrefs public methods + */ +GtkObject * +nautilus_prefs_new (const gchar *domain) +{ + NautilusPrefs *prefs; + + g_return_val_if_fail (domain != NULL, NULL); + + prefs = gtk_type_new (nautilus_prefs_get_type ()); + + return GTK_OBJECT (prefs); +} + +void +nautilus_prefs_register_from_info (NautilusPrefs *prefs, + const NautilusPrefInfo *pref_info) +{ + PrefHashInfo * pref_hash_info; + + g_return_if_fail (prefs != NULL); + g_return_if_fail (NAUTILUS_IS_PREFS (prefs)); + + g_return_if_fail (pref_info != NULL); + + g_return_if_fail (pref_info->pref_name != NULL); + g_return_if_fail (prefs_check_supported_type (pref_info->pref_type)); + + pref_hash_info = prefs_hash_lookup (prefs, pref_info->pref_name); + + if (pref_hash_info) + { + g_warning ("the '%s' preference is already registered.\n", pref_info->pref_name); + + return; + } + +// printf ("%s is being registered\n", pref_info->pref_name); + + pref_hash_info = pref_hash_info_alloc (pref_info); + + g_hash_table_insert (prefs->priv->prefs_hash_table, + (gpointer) pref_info->pref_name, + (gpointer) pref_hash_info); +} + +void +nautilus_prefs_register_from_values (NautilusPrefs *prefs, + gchar *pref_name, + gchar *pref_description, + GtkFundamentalType pref_type, + gconstpointer pref_default_value, + gpointer type_data) +{ + NautilusPrefInfo pref_info; + + g_return_if_fail (prefs != NULL); + g_return_if_fail (NAUTILUS_IS_PREFS (prefs)); + + g_return_if_fail (pref_name != NULL); + g_return_if_fail (pref_description != NULL); + g_return_if_fail (prefs_check_supported_type (pref_type)); + + pref_info.pref_name = pref_name; + pref_info.pref_description = pref_description; + pref_info.pref_type = pref_type; + pref_info.pref_default_value = pref_default_value; + pref_info.type_data = type_data; + + nautilus_prefs_register_from_info (prefs, &pref_info); +} + +const NautilusPrefInfo * +nautilus_prefs_get_pref_info (NautilusPrefs *prefs, + const gchar *pref_name) +{ + PrefHashInfo * pref_hash_info; + + g_return_val_if_fail (prefs != NULL, NULL); + g_return_val_if_fail (NAUTILUS_IS_PREFS (prefs), NULL); + g_return_val_if_fail (pref_name != NULL, NULL); + + pref_hash_info = prefs_hash_lookup (prefs, pref_name); + + g_assert (pref_hash_info != NULL); + + return &pref_hash_info->pref_info; +} + +PrefHashInfo * +prefs_hash_lookup (NautilusPrefs *prefs, + const gchar *pref_name) +{ + gpointer hash_value; + + g_assert (prefs != NULL); + g_assert (pref_name != NULL); + + hash_value = g_hash_table_lookup (prefs->priv->prefs_hash_table, + (gconstpointer) pref_name); + + return (PrefHashInfo *) hash_value; +} + +gboolean +nautilus_prefs_add_callback (NautilusPrefs *prefs, + const gchar *pref_name, + NautilusPrefsCallback callback_proc, + gpointer user_data) +{ + PrefHashInfo * pref_hash_info; + + g_return_val_if_fail (prefs != NULL, FALSE); + g_return_val_if_fail (NAUTILUS_IS_PREFS (prefs), FALSE); + g_return_val_if_fail (pref_name != NULL, FALSE); + g_return_val_if_fail (callback_proc != NULL, FALSE); + + pref_hash_info = prefs_hash_lookup (prefs, pref_name); + + if (!pref_hash_info) + { + g_warning ("trying to add a callback to an unregistered preference.\n"); + + return FALSE; + } + + pref_hash_info_add_callback (pref_hash_info, + callback_proc, + user_data); + + return TRUE; +} + +void +nautilus_prefs_set_boolean (NautilusPrefs *prefs, + const gchar *pref_name, + gboolean boolean_value) +{ + gboolean rv; + + g_return_if_fail (prefs != NULL); + g_return_if_fail (NAUTILUS_IS_PREFS (prefs)); + g_return_if_fail (pref_name != NULL); + + rv = prefs_set_pref (prefs, pref_name, (gpointer) boolean_value); + + g_assert (rv); +} + +gboolean +nautilus_prefs_get_boolean (NautilusPrefs *prefs, + const gchar *pref_name) +{ + gboolean rv; + GtkFundamentalType pref_type; + gconstpointer value; + + g_return_val_if_fail (prefs != NULL, FALSE); + g_return_val_if_fail (NAUTILUS_IS_PREFS (prefs), FALSE); + g_return_val_if_fail (pref_name != NULL, FALSE); + + rv = prefs_get_pref (prefs, pref_name, &pref_type, &value); + + if (!rv) + { + g_warning ("could not get boolean preference '%s'\n", pref_name); + + return FALSE; + } + + g_assert (pref_type == GTK_TYPE_BOOL); + + return (gboolean) value; +} + +void +nautilus_prefs_set_enum (NautilusPrefs *prefs, + const gchar *pref_name, + gint enum_value) +{ + gboolean rv; + + g_return_if_fail (prefs != NULL); + g_return_if_fail (NAUTILUS_IS_PREFS (prefs)); + g_return_if_fail (pref_name != NULL); + + rv = prefs_set_pref (prefs, pref_name, (gpointer) enum_value); + + g_assert (rv); +} + +gint +nautilus_prefs_get_enum (NautilusPrefs *prefs, + const gchar *pref_name) +{ + gboolean rv; + GtkFundamentalType pref_type; + gconstpointer value; + + g_return_val_if_fail (prefs != NULL, FALSE); + g_return_val_if_fail (NAUTILUS_IS_PREFS (prefs), FALSE); + g_return_val_if_fail (pref_name != NULL, FALSE); + + rv = prefs_get_pref (prefs, pref_name, &pref_type, &value); + + if (!rv) + { + g_warning ("could not get enum preference '%s'\n", pref_name); + + return FALSE; + } + + g_assert (pref_type == GTK_TYPE_ENUM); + + return (gint) value; +} diff --git a/nautilus-widgets/nautilus-preferences.h b/nautilus-widgets/nautilus-preferences.h new file mode 100644 index 000000000..cfe709730 --- /dev/null +++ b/nautilus-widgets/nautilus-preferences.h @@ -0,0 +1,116 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ + +/* nautilus-prefs.h - Preference peek/poke/notify object interface. + + Copyright (C) 1999, 2000 Eazel, Inc. + + The Gnome Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + The Gnome Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the Gnome Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. + + Authors: Ramiro Estrugo <ramiro@eazel.com> +*/ + +#ifndef NAUTILUS_PREFS_H +#define NAUTILUS_PREFS_H + +#include <gtk/gtkhbox.h> +#include <nautilus-widgets/nautilus-preferences-pane.h> + +//#include <gnome.h> + +BEGIN_GNOME_DECLS + +#define NAUTILUS_TYPE_PREFS (nautilus_prefs_get_type ()) +#define NAUTILUS_PREFS(obj) (GTK_CHECK_CAST ((obj), NAUTILUS_TYPE_PREFS, NautilusPrefs)) +#define NAUTILUS_PREFS_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), NAUTILUS_TYPE_PREFS, NautilusPrefsClass)) +#define NAUTILUS_IS_PREFS(obj) (GTK_CHECK_TYPE ((obj), NAUTILUS_TYPE_PREFS)) +#define NAUTILUS_IS_PREFS_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), NAUTILUS_TYPE_PREFS)) + +typedef struct _NautilusPrefs NautilusPrefs; +typedef struct _NautilusPrefsClass NautilusPrefsClass; +typedef struct _NautilusPrefsPrivate NautilusPrefsPrivate; + +struct _NautilusPrefs +{ + /* Super Class */ + GtkObject object; + + /* Private stuff */ + NautilusPrefsPrivate *priv; +}; + +typedef void (*NautilusPrefsCallback) (const GtkObject *prefs, + const gchar *pref_name, + GtkFundamentalType pref_type, + gconstpointer pref_value, + gpointer user_data); + +struct _NautilusPrefsClass +{ + GtkObjectClass object_class; + +// void (*activate) (GtkWidget * prefs, gint entry_number); +}; + +typedef struct +{ + gchar *pref_name; + gchar *pref_description; + GtkFundamentalType pref_type; + gconstpointer pref_default_value; + gpointer type_data; +} NautilusPrefInfo; + +typedef struct +{ + const gchar **enum_names; + const gchar **enum_descriptions; + const gint *enum_values; + guint num_entries; +} NautilusPrefEnumData; + +GtkType nautilus_prefs_get_type (void); +GtkObject* nautilus_prefs_new (const gchar *domain); +void nautilus_prefs_register_from_info (NautilusPrefs *prefs, + const NautilusPrefInfo *pref_info); +void nautilus_prefs_register_from_values (NautilusPrefs *prefs, + gchar *pref_name, + gchar *pref_description, + GtkFundamentalType pref_type, + gconstpointer pref_default_value, + gpointer type_data); +const NautilusPrefInfo *nautilus_prefs_get_pref_info (NautilusPrefs *prefs, + const gchar *pref_name); +gboolean nautilus_prefs_add_callback (NautilusPrefs *prefs, + const gchar *pref_name, + NautilusPrefsCallback callback, + gpointer user_data); +void nautilus_prefs_set_boolean (NautilusPrefs *prefs, + const gchar *pref_name, + gboolean boolean_value); +gboolean nautilus_prefs_get_boolean (NautilusPrefs *prefs, + const gchar *pref_name); +void nautilus_prefs_set_enum (NautilusPrefs *prefs, + const gchar *pref_name, + gint enum_value); +gint nautilus_prefs_get_enum (NautilusPrefs *prefs, + const gchar *pref_name); + + +BEGIN_GNOME_DECLS + +#endif /* NAUTILUS_PREFS_H */ + + diff --git a/nautilus-widgets/nautilus-radio-button-group.c b/nautilus-widgets/nautilus-radio-button-group.c index 07f51397d..509afe7de 100644 --- a/nautilus-widgets/nautilus-radio-button-group.c +++ b/nautilus-widgets/nautilus-radio-button-group.c @@ -276,3 +276,22 @@ nautilus_radio_button_group_get_active_index (NautilusRadioButtonGroup *button_g return 0; } + +void +nautilus_radio_button_group_set_active_index (NautilusRadioButtonGroup *button_group, + guint active_index) +{ + GList *node; + + g_return_if_fail (button_group != NULL); + g_return_if_fail (NAUTILUS_IS_RADIO_BUTTON_GROUP (button_group)); + + node = g_list_nth (button_group->details->buttons, active_index); + + g_assert (node != NULL); + + g_assert (GTK_TOGGLE_BUTTON (node->data)); + + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (node->data), TRUE); +} + diff --git a/nautilus-widgets/nautilus-radio-button-group.h b/nautilus-widgets/nautilus-radio-button-group.h index a9b8ad2c2..7d7dffb7c 100644 --- a/nautilus-widgets/nautilus-radio-button-group.h +++ b/nautilus-widgets/nautilus-radio-button-group.h @@ -72,6 +72,10 @@ guint nautilus_radio_button_group_insert (NautilusRadioButtonGro /* Get the active item index. By law there always is an active item */ guint nautilus_radio_button_group_get_active_index (NautilusRadioButtonGroup *button_group); +/* Set the active item index. */ +void nautilus_radio_button_group_set_active_index (NautilusRadioButtonGroup *button_group, + guint active_index); + BEGIN_GNOME_DECLS #endif /* NAUTILUS_RADIO_BUTTON_GROUP_H */ diff --git a/nautilus-widgets/test-nautilus-widgets.c b/nautilus-widgets/test-nautilus-widgets.c index 85eee70e7..ad86e92a1 100644 --- a/nautilus-widgets/test-nautilus-widgets.c +++ b/nautilus-widgets/test-nautilus-widgets.c @@ -1,17 +1,40 @@ #include <nautilus-widgets/nautilus-radio-button-group.h> +#include <nautilus-widgets/nautilus-preferences-group.h> +#include <nautilus-widgets/nautilus-preferences-item.h> +#include <nautilus-widgets/nautilus-preferences.h> + #include <gtk/gtk.h> #include <stdio.h> static void test_radio_group (void); +static void test_preferences_group (void); +static void test_preferences_item (void); + + static void test_radio_changed_signal (GtkWidget *button_group, gpointer user_data); +static GtkObject * +create_dummy_prefs (void); + +GtkWidget * +create_enum_item (void); + +GtkWidget * +create_bool_item (void); + +static GtkObject * dummy_prefs = NULL; + int main (int argc, char * argv[]) { gtk_init (&argc, &argv); + + dummy_prefs = create_dummy_prefs (); test_radio_group (); + test_preferences_group (); + test_preferences_item (); gtk_main (); @@ -24,6 +47,7 @@ test_radio_group (void) GtkWidget * window; GtkWidget * buttons; + window = gtk_window_new (GTK_WINDOW_TOPLEVEL); buttons = nautilus_radio_button_group_new (); @@ -45,6 +69,49 @@ test_radio_group (void) } static void +test_preferences_item (void) +{ + GtkWidget * window; + GtkWidget * item; + + window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + + item = create_enum_item (); + + gtk_container_add (GTK_CONTAINER (window), item); + + gtk_widget_show (item); + + gtk_widget_show (window); +} + +static void +test_preferences_group (void) +{ + GtkWidget * window; + GtkWidget * group; + + GtkWidget * item; + + window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + + group = nautilus_preferences_group_new ("A group"); + + item = create_enum_item (); + + nautilus_preferences_group_add (NAUTILUS_PREFERENCES_GROUP (group), + item); + + gtk_widget_show (item); + + gtk_container_add (GTK_CONTAINER (window), group); + + gtk_widget_show (group); + + gtk_widget_show (window); +} + +static void test_radio_changed_signal (GtkWidget *buttons, gpointer user_data) { gint i; @@ -53,3 +120,108 @@ test_radio_changed_signal (GtkWidget *buttons, gpointer user_data) printf ("test_radio_changed_signal (%d)\n", i); } + +GtkWidget * +create_enum_item (void) +{ + GtkWidget * item; + + item = nautilus_preferences_item_new (dummy_prefs, + "user_level", + NAUTILUS_PREFERENCES_ITEM_ENUM); + + return item; +} + +GtkWidget * +create_bool_item (void) +{ + GtkWidget * item; + + item = nautilus_preferences_item_new (dummy_prefs, + "foo", + NAUTILUS_PREFERENCES_ITEM_BOOL); + + return item; +} + + +static const gchar * prefs_global_user_level_names[] = +{ + "novice", + "intermediate", + "hacker", + "ettore" +}; + +static const gchar * prefs_global_user_level_descriptions[] = +{ + "Novice", + "Intermediate", + "Hacker", + "Ettore" +}; + +static const gint prefs_global_user_level_values[] = +{ + 0, + 1, + 2, + 3 +}; + +static NautilusPrefEnumData prefs_global_user_level_data = +{ + prefs_global_user_level_names, + prefs_global_user_level_descriptions, + prefs_global_user_level_values, + 4 +}; + +static NautilusPrefInfo prefs_global_static_pref_info[] = +{ + { + "user_level", + "User Level", + GTK_TYPE_ENUM, + FALSE, + (gpointer) &prefs_global_user_level_data + }, + { + "foo", + "Create new window for each new page", + GTK_TYPE_BOOL, + FALSE, + NULL + }, + { + "bar", + "Do not open more than one window with the same page", + GTK_TYPE_BOOL, + FALSE, + NULL + }, +}; + +static GtkObject * +create_dummy_prefs (void) +{ + GtkObject * dummy_prefs; + guint i; + + dummy_prefs = nautilus_prefs_new ("dummy"); + + /* Register the static prefs */ + for (i = 0; i < 3; i++) + { + nautilus_prefs_register_from_info (NAUTILUS_PREFS (dummy_prefs), + &prefs_global_static_pref_info[i]); + } + + + nautilus_prefs_set_enum (NAUTILUS_PREFS (dummy_prefs), + "user_level", + 2); + + return dummy_prefs; +} diff --git a/nautilus-widgets/test-preferences.c b/nautilus-widgets/test-preferences.c new file mode 100644 index 000000000..a2d1de8b6 --- /dev/null +++ b/nautilus-widgets/test-preferences.c @@ -0,0 +1,227 @@ + +#include <nautilus-widgets/nautilus-radio-button-group.h> +#include <nautilus-widgets/nautilus-preferences-group.h> +#include <nautilus-widgets/nautilus-preferences-item.h> +#include <nautilus-widgets/nautilus-preferences.h> + +#include <gtk/gtk.h> +#include <stdio.h> + +static void test_radio_group (void); +static void test_preferences_group (void); +static void test_preferences_item (void); + + +static void test_radio_changed_signal (GtkWidget *button_group, gpointer user_data); + +static GtkObject * +create_dummy_prefs (void); + +GtkWidget * +create_enum_item (void); + +GtkWidget * +create_bool_item (void); + +static GtkObject * dummy_prefs = NULL; + +int +main (int argc, char * argv[]) +{ + gtk_init (&argc, &argv); + + dummy_prefs = create_dummy_prefs (); + +// test_radio_group (); + test_preferences_group (); + test_preferences_item (); + + gtk_main (); + + return 0; +} + +static void +test_radio_group (void) +{ + GtkWidget * window; + GtkWidget * buttons; + + + window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + + buttons = nautilus_radio_button_group_new (); + + nautilus_radio_button_group_insert (NAUTILUS_RADIO_BUTTON_GROUP (buttons), "Apples"); + nautilus_radio_button_group_insert (NAUTILUS_RADIO_BUTTON_GROUP (buttons), "Oranges"); + nautilus_radio_button_group_insert (NAUTILUS_RADIO_BUTTON_GROUP (buttons), "Strawberries"); + + gtk_signal_connect (GTK_OBJECT (buttons), + "changed", + GTK_SIGNAL_FUNC (test_radio_changed_signal), + (gpointer) NULL); + + gtk_container_add (GTK_CONTAINER (window), buttons); + + gtk_widget_show (buttons); + + gtk_widget_show (window); +} + +static void +test_preferences_item (void) +{ + GtkWidget * window; + GtkWidget * item; + + window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + + item = create_enum_item (); + + gtk_container_add (GTK_CONTAINER (window), item); + + gtk_widget_show (item); + + gtk_widget_show (window); +} + +static void +test_preferences_group (void) +{ + GtkWidget * window; + GtkWidget * group; + + GtkWidget * item; + + window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + + group = nautilus_preferences_group_new ("A group"); + + item = create_enum_item (); + + nautilus_preferences_group_add (NAUTILUS_PREFERENCES_GROUP (group), + item); + + gtk_widget_show (item); + + gtk_container_add (GTK_CONTAINER (window), group); + + gtk_widget_show (group); + + gtk_widget_show (window); +} + +static void +test_radio_changed_signal (GtkWidget *buttons, gpointer user_data) +{ + gint i; + + i = nautilus_radio_button_group_get_active_index (NAUTILUS_RADIO_BUTTON_GROUP (buttons)); + + printf ("test_radio_changed_signal (%d)\n", i); +} + +GtkWidget * +create_enum_item (void) +{ + GtkWidget * item; + + item = nautilus_preferences_item_new (dummy_prefs, + "user_level", + NAUTILUS_PREFERENCES_ITEM_ENUM); + + return item; +} + +GtkWidget * +create_bool_item (void) +{ + GtkWidget * item; + + item = nautilus_preferences_item_new (dummy_prefs, + "foo", + NAUTILUS_PREFERENCES_ITEM_BOOL); + + return item; +} + + +static const gchar * prefs_global_user_level_names[] = +{ + "novice", + "intermediate", + "hacker", + "ettore" +}; + +static const gchar * prefs_global_user_level_descriptions[] = +{ + "Novice", + "Intermediate", + "Hacker", + "Ettore" +}; + +static const gint prefs_global_user_level_values[] = +{ + 0, + 1, + 2, + 3 +}; + +static NautilusPrefEnumData prefs_global_user_level_data = +{ + prefs_global_user_level_names, + prefs_global_user_level_descriptions, + prefs_global_user_level_values, + 4 +}; + +static NautilusPrefInfo prefs_global_static_pref_info[] = +{ + { + "user_level", + "User Level", + GTK_TYPE_ENUM, + FALSE, + (gpointer) &prefs_global_user_level_data + }, + { + "foo", + "Create new window for each new page", + GTK_TYPE_BOOL, + FALSE, + NULL + }, + { + "bar", + "Do not open more than one window with the same page", + GTK_TYPE_BOOL, + FALSE, + NULL + }, +}; + +static GtkObject * +create_dummy_prefs (void) +{ + GtkObject * dummy_prefs; + guint i; + + dummy_prefs = nautilus_prefs_new ("dummy"); + + /* Register the static prefs */ + for (i = 0; i < 3; i++) + { + nautilus_prefs_register_from_info (NAUTILUS_PREFS (dummy_prefs), + &prefs_global_static_pref_info[i]); + } + + + nautilus_prefs_set_enum (NAUTILUS_PREFS (dummy_prefs), + "user_level", + 2); + + return dummy_prefs; +} |