Commit b9488278 authored by Ramiro Estrugo's avatar Ramiro Estrugo

Moved all the preference widetry to nautilus-widgets.

Added a test program for preferences (not built).
Renamed files to user "preference" instead of "prefs".
parent bddcc07d
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
......
/* -*- 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;
}
/* -*- 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 */
/* -*- 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",