Commit 7d47f172 authored by Ramiro Estrugo's avatar Ramiro Estrugo

Add support for custom preferences items.

	* libnautilus-extensions/nautilus-preferences-group.c:
	* libnautilus-extensions/nautilus-preferences-group.h:
	Add support for custom preferences items.

	* libnautilus-extensions/nautilus-preferences-item.h:
	* libnautilus-extensions/nautilus-preferences-item.c:
	Add support for custom preferences items.  For now only the theme
	selector uses this powerful technology.

	Fix bug 8167 - Crash boinking on single-click mode.  It was a dumb
	mistake left over from a previous fix.  Wrong number of arguments
	to a signal.

	Fix bug where strings in enumeration menus would show up
	untranslated in the preferences dialog, even in locales where
	translations exist.

	* libnautilus-extensions/nautilus-theme.h:
	* libnautilus-extensions/nautilus-theme.c: (load_theme_document),
	(nautilus_pixmap_file_may_be_local),
	(nautilus_theme_get_image_path_from_theme),
	(nautilus_theme_make_preview_pixbuf): Rename this function from
	nautilus_theme_make_selector for greater clarity.
	(has_image_file), (theme_get_property), (theme_get_name_property),
	(theme_get_description_property), (theme_list_insert),
	(theme_get_themes_for_location): Replace some cut-n-paste code by
	a shared function.  Add some FIXMEs for the funky handling of the
	"default" theme.
	(theme_get_builtin_themes), (theme_get_user_themes),
	(theme_get_default_themes): Functions for reaping the
	different types of themes available to Nautilus.
	(nautilus_theme_for_each_theme), (theme_list_invoke_callback): New
	function to iterate all the themese available to Nautilus.  Makes
	Nautilus code that needs to operate on themes (like the theme
	selector) easier to write.
	(nautilus_theme_get_user_themes_directory),
	(nautilus_theme_remove_user_theme),
	(nautilus_theme_install_user_theme):  Functions for reaping the
	different types of themes available to Nautilus.

	* src/nautilus-preferences-dialog.c:
	(preferences_dialog_populate_sidebar_tabs_group),
	(theme_changed_callback),
	(update_theme_selector_displayed_value_callback),
	(preferences_dialog_populate_themes_group):
	Add a custom preference item for the theme chooser.

	* src/nautilus-theme-selector.h:
	* src/nautilus-theme-selector.c:
	Use regular Gtk widgets in the list so that all the things that
	are expect to work do indeed work.  This includes Gtk+ theme
	changes and custom tweaks made in the code to satisfy the design.
	Larger and bolder labels for example.

	Simplify this code alot by using iterators for the available
	themes.  Also maintain two lists instead of managing a remove_mode
	boolean.  Makes the code simpler.

	* src/nautilus-window-menus.c:
	(nautilus_window_initialize_menus_part_1):
	Remove the standalone theme selector handling code.

	* src/nautilus-shell-ui.xml:
	Remove the standalone theme selector ui.
parent 9b782868
2001-04-26 Ramiro Estrugo <ramiro@eazel.com>
* libnautilus-extensions/nautilus-preferences-group.c:
* libnautilus-extensions/nautilus-preferences-group.h:
Add support for custom preferences items.
* libnautilus-extensions/nautilus-preferences-item.h:
* libnautilus-extensions/nautilus-preferences-item.c:
Add support for custom preferences items. For now only the theme
selector uses this powerful technology.
Fix bug 8167 - Crash boinking on single-click mode. It was a dumb
mistake left over from a previous fix. Wrong number of arguments
to a signal.
Fix bug where strings in enumeration menus would show up
untranslated in the preferences dialog, even in locales where
translations exist.
* libnautilus-extensions/nautilus-theme.h:
* libnautilus-extensions/nautilus-theme.c: (load_theme_document),
(nautilus_pixmap_file_may_be_local),
(nautilus_theme_get_image_path_from_theme),
(nautilus_theme_make_preview_pixbuf): Rename this function from
nautilus_theme_make_selector for greater clarity.
(has_image_file), (theme_get_property), (theme_get_name_property),
(theme_get_description_property), (theme_list_insert),
(theme_get_themes_for_location): Replace some cut-n-paste code by
a shared function. Add some FIXMEs for the funky handling of the
"default" theme.
(theme_get_builtin_themes), (theme_get_user_themes),
(theme_get_default_themes): Functions for reaping the
different types of themes available to Nautilus.
(nautilus_theme_for_each_theme), (theme_list_invoke_callback): New
function to iterate all the themese available to Nautilus. Makes
Nautilus code that needs to operate on themes (like the theme
selector) easier to write.
(nautilus_theme_get_user_themes_directory),
(nautilus_theme_remove_user_theme),
(nautilus_theme_install_user_theme): Functions for reaping the
different types of themes available to Nautilus.
* src/nautilus-preferences-dialog.c:
(preferences_dialog_populate_sidebar_tabs_group),
(theme_changed_callback),
(update_theme_selector_displayed_value_callback),
(preferences_dialog_populate_themes_group):
Add a custom preference item for the theme chooser.
* src/nautilus-theme-selector.h:
* src/nautilus-theme-selector.c:
Use regular Gtk widgets in the list so that all the things that
are expect to work do indeed work. This includes Gtk+ theme
changes and custom tweaks made in the code to satisfy the design.
Larger and bolder labels for example.
Simplify this code alot by using iterators for the available
themes. Also maintain two lists instead of managing a remove_mode
boolean. Makes the code simpler.
* src/nautilus-window-menus.c:
(nautilus_window_initialize_menus_part_1):
Remove the standalone theme selector handling code.
* src/nautilus-shell-ui.xml:
Remove the standalone theme selector ui.
2001-04-26 John Sullivan <sullivan@eazel.com>
Made the emblems column wider to fit the title "Emblems" (in
......
......@@ -163,6 +163,40 @@ nautilus_preferences_group_add_item (NautilusPreferencesGroup *group,
return item;
}
GtkWidget *
nautilus_preferences_group_add_custom_item (NautilusPreferencesGroup *group,
const char *preference_name,
GtkWidget *child,
const char *signal_name,
int column)
{
GtkWidget *item;
g_return_val_if_fail (NAUTILUS_IS_PREFERENCES_GROUP (group), NULL);
g_return_val_if_fail (preference_name != NULL, NULL);
g_return_val_if_fail (GTK_IS_WIDGET (child), NULL);
g_return_val_if_fail (signal_name != NULL, NULL);
g_return_val_if_fail (column >= 0, NULL);
g_return_val_if_fail (column <= 1, NULL);
item = nautilus_preferences_item_new_custom (preference_name,
child,
signal_name);
group->details->items[column] = g_list_append (group->details->items[column],
item);
gtk_box_pack_start (GTK_BOX (group->details->columns[column]),
item,
FALSE,
FALSE,
0);
gtk_widget_show (item);
return item;
}
void
nautilus_preferences_group_update (NautilusPreferencesGroup *group)
{
......
......@@ -62,6 +62,11 @@ GtkWidget* nautilus_preferences_group_add_item (NautilusPreferences
const char *preference_name,
NautilusPreferencesItemType item_type,
int column);
GtkWidget* nautilus_preferences_group_add_custom_item (NautilusPreferencesGroup *group,
const char *preference_name,
GtkWidget *child,
const char *signal_name,
int column);
void nautilus_preferences_group_update (NautilusPreferencesGroup *group);
guint nautilus_preferences_group_get_num_visible_items (const NautilusPreferencesGroup *group);
char * nautilus_preferences_group_get_title_label (const NautilusPreferencesGroup *group);
......
......@@ -58,13 +58,22 @@ struct NautilusPreferencesItemDetails
{
char *preference_name;
NautilusPreferencesItemType item_type;
GtkWidget *child;
GtkWidget *main_child;
GSList *change_signal_connections;
char *control_preference_name;
NautilusPreferencesItemControlAction control_action;
EelStringList *enumeration_list_unique_exceptions;
};
/* Signals */
typedef enum
{
CUSTOM_UPDATE_DISPLAYED_VALUE,
LAST_SIGNAL
} EelStringListSignals;
static guint preferences_item_signals[LAST_SIGNAL];
/* GtkObjectClass methods */
static void nautilus_preferences_item_initialize_class (NautilusPreferencesItemClass *preferences_item_class);
static void nautilus_preferences_item_initialize (NautilusPreferencesItem *preferences_item);
......@@ -88,9 +97,8 @@ static void preferences_item_update_editable_integer_settings_at_idle (NautilusP
static void preferences_item_update_text_settings_at_idle (NautilusPreferencesItem *preferences_item);
/* User triggered item changed callbacks */
static void enumeration_radio_changed_callback (GtkWidget *button_group,
GtkWidget *button,
gpointer user_data);
static void enumeration_radio_changed_callback (EelRadioButtonGroup *radio_button_group,
gpointer callback_data);
static void boolean_button_toggled_callback (GtkWidget *button_group,
gpointer user_data);
static void editable_string_changed_callback (GtkWidget *caption,
......@@ -105,6 +113,8 @@ static void enumeration_list_changed_callback (EelString
NautilusPreferencesItem *item);
static void smooth_font_changed_callback (EelFontPicker *font_picker,
gpointer callback_data);
static void custom_changed_callback (GtkWidget *custom,
gpointer user_data);
EEL_DEFINE_CLASS_BOILERPLATE (NautilusPreferencesItem, nautilus_preferences_item, GTK_TYPE_VBOX)
......@@ -118,6 +128,18 @@ nautilus_preferences_item_initialize_class (NautilusPreferencesItemClass *prefer
/* GtkObjectClass */
object_class->destroy = preferences_item_destroy;
/* Signals */
preferences_item_signals[CUSTOM_UPDATE_DISPLAYED_VALUE] =
gtk_signal_new ("custom_update_displayed_value",
GTK_RUN_LAST,
object_class->type,
0,
gtk_marshal_NONE__NONE,
GTK_TYPE_NONE,
0);
gtk_object_class_add_signals (object_class, preferences_item_signals, LAST_SIGNAL);
}
static void
......@@ -171,7 +193,7 @@ preferences_item_update_enumeration_radio (NautilusPreferencesItem *item)
/* Set the active button */
for (i = 0; i < eel_enumeration_id_get_length (enumeration_id); i++) {
if (value == eel_enumeration_id_get_nth_value (enumeration_id, i)) {
eel_radio_button_group_set_active_index (EEL_RADIO_BUTTON_GROUP (item->details->child), i);
eel_radio_button_group_set_active_index (EEL_RADIO_BUTTON_GROUP (item->details->main_child), i);
}
}
......@@ -281,7 +303,7 @@ preferences_item_update_enumeration_list (NautilusPreferencesItem *item)
position = eel_enumeration_id_get_name_position (enumeration_id,
nth_value_name);
nth_value_description = eel_enumeration_id_get_nth_description (enumeration_id,
nth_value_description = eel_enumeration_id_get_nth_description_translated (enumeration_id,
position);
eel_string_picker_set_selected_string (EEL_STRING_PICKER (connection->widget),
......@@ -297,6 +319,16 @@ preferences_item_update_enumeration_list (NautilusPreferencesItem *item)
preferences_item_update_enumeration_list_uniqueness (item);
}
static void
preferences_item_update_custom (NautilusPreferencesItem *item)
{
g_return_if_fail (NAUTILUS_IS_PREFERENCES_ITEM (item));
gtk_signal_emit (GTK_OBJECT (item),
preferences_item_signals[CUSTOM_UPDATE_DISPLAYED_VALUE]);
}
/* This callback is called whenever the preference value changes, so that we can
* update the item widgets accordingly.
*/
......@@ -315,7 +347,7 @@ preferences_item_set_main_child (NautilusPreferencesItem *item,
g_return_if_fail (NAUTILUS_IS_PREFERENCES_ITEM (item));
g_return_if_fail (eel_strlen (item->details->preference_name) > 0);
g_return_if_fail (GTK_IS_WIDGET (child));
g_return_if_fail (item->details->child == NULL);
g_return_if_fail (item->details->main_child == NULL);
if (item->details->item_type != NAUTILUS_PREFERENCE_ITEM_PADDING) {
nautilus_preferences_add_callback_while_alive (item->details->preference_name,
......@@ -332,7 +364,7 @@ preferences_item_set_main_child (NautilusPreferencesItem *item,
gtk_widget_show (child);
item->details->child = child;
item->details->main_child = child;
}
static void
......@@ -379,7 +411,7 @@ preferences_item_create_enumeration_radio (NautilusPreferencesItem *item,
/* Populate the radio group */
for (i = 0; i < eel_enumeration_id_get_length (enumeration_id); i++) {
description = eel_enumeration_id_get_nth_description (enumeration_id, i);
description = eel_enumeration_id_get_nth_description_translated (enumeration_id, i);
g_assert (description != NULL);
eel_radio_button_group_insert (EEL_RADIO_BUTTON_GROUP (child),
......@@ -456,7 +488,7 @@ preferences_item_create_enumeration_list (NautilusPreferencesItem *item,
eel_caption_set_show_title (EEL_CAPTION (string_picker), FALSE);
for (i = 0; i < eel_enumeration_id_get_length (enumeration_id); i++) {
enum_description = eel_enumeration_id_get_nth_description (enumeration_id, i);
enum_description = eel_enumeration_id_get_nth_description_translated (enumeration_id, i);
g_assert (enum_description != NULL);
eel_string_picker_insert_string (EEL_STRING_PICKER (string_picker), enum_description);
......@@ -490,7 +522,7 @@ preferences_item_update_boolean (NautilusPreferencesItem *item)
g_return_if_fail (item->details->item_type == NAUTILUS_PREFERENCE_ITEM_BOOLEAN);
value = nautilus_preferences_get_boolean (item->details->preference_name);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (item->details->child), value);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (item->details->main_child), value);
}
static void
......@@ -528,7 +560,7 @@ preferences_item_update_editable_string (NautilusPreferencesItem *item)
current_value = nautilus_preferences_get (item->details->preference_name);
g_assert (current_value != NULL);
eel_text_caption_set_text (EEL_TEXT_CAPTION (item->details->child), current_value);
eel_text_caption_set_text (EEL_TEXT_CAPTION (item->details->main_child), current_value);
g_free (current_value);
}
......@@ -576,7 +608,7 @@ preferences_item_update_editable_integer (NautilusPreferencesItem *item)
current_value = g_strdup_printf ("%d", nautilus_preferences_get_integer (item->details->preference_name));
g_assert (current_value != NULL);
eel_text_caption_set_text (EEL_TEXT_CAPTION (item->details->child), current_value);
eel_text_caption_set_text (EEL_TEXT_CAPTION (item->details->main_child), current_value);
g_free (current_value);
}
......@@ -629,11 +661,11 @@ preferences_item_update_enumeration_menu (NautilusPreferencesItem *item)
current_value);
g_return_if_fail (position != EEL_STRING_LIST_NOT_FOUND);
current_label = eel_enumeration_id_get_nth_description (enumeration_id,
current_label = eel_enumeration_id_get_nth_description_translated (enumeration_id,
position);
if (eel_string_picker_contains (EEL_STRING_PICKER (item->details->child), current_label)) {
eel_string_picker_set_selected_string (EEL_STRING_PICKER (item->details->child),
if (eel_string_picker_contains (EEL_STRING_PICKER (item->details->main_child), current_label)) {
eel_string_picker_set_selected_string (EEL_STRING_PICKER (item->details->main_child),
current_label);
} else {
g_warning ("Value string for %s is %s, which isn't in the expected set of values",
......@@ -669,7 +701,7 @@ preferences_item_create_enumeration_menu (NautilusPreferencesItem *item)
/* Populate the string picker */
for (i = 0; i < eel_enumeration_id_get_length (enumeration_id); i++) {
description = eel_enumeration_id_get_nth_description (enumeration_id, i);
description = eel_enumeration_id_get_nth_description_translated (enumeration_id, i);
g_assert (description != NULL);
eel_string_picker_insert_string (EEL_STRING_PICKER (child), description);
......@@ -702,8 +734,8 @@ preferences_item_update_font (NautilusPreferencesItem *item)
* it is one of the choice before trying to select it, otherwise we would get
* assertions.
*/
if (eel_string_picker_contains (EEL_STRING_PICKER (item->details->child), current_value)) {
eel_string_picker_set_selected_string (EEL_STRING_PICKER (item->details->child),
if (eel_string_picker_contains (EEL_STRING_PICKER (item->details->main_child), current_value)) {
eel_string_picker_set_selected_string (EEL_STRING_PICKER (item->details->main_child),
current_value);
}
......@@ -782,7 +814,7 @@ preferences_item_update_smooth_font (NautilusPreferencesItem *item)
current_value = nautilus_preferences_get (item->details->preference_name);
g_assert (current_value != NULL);
eel_font_picker_set_selected_font (EEL_FONT_PICKER (item->details->child),
eel_font_picker_set_selected_font (EEL_FONT_PICKER (item->details->main_child),
current_value);
g_free (current_value);
}
......@@ -798,7 +830,7 @@ smooth_font_changed_callback (EelFontPicker *font_picker,
g_return_if_fail (NAUTILUS_IS_PREFERENCES_ITEM (callback_data));
item = NAUTILUS_PREFERENCES_ITEM (callback_data);
new_value = eel_font_picker_get_selected_font (EEL_FONT_PICKER (item->details->child));
new_value = eel_font_picker_get_selected_font (EEL_FONT_PICKER (item->details->main_child));
g_assert (new_value != NULL);
nautilus_preferences_set (item->details->preference_name, new_value);
g_free (new_value);
......@@ -828,6 +860,13 @@ preferences_item_create_smooth_font (NautilusPreferencesItem *item)
preferences_item_set_main_child (item, child);
}
static void
custom_changed_callback (GtkWidget *widget,
gpointer callback_data)
{
g_return_if_fail (GTK_IS_WIDGET (widget));
}
/* NautilusPreferencesItem public methods */
GtkWidget *
nautilus_preferences_item_new (const char *preference_name,
......@@ -891,30 +930,62 @@ nautilus_preferences_item_new (const char *preference_name,
case NAUTILUS_PREFERENCE_ITEM_PADDING:
preferences_item_create_padding (item);
break;
case NAUTILUS_PREFERENCE_ITEM_CUSTOM:
g_assert_not_reached ();
break;
}
g_return_val_if_fail (GTK_IS_WIDGET (item->details->child), NULL);
g_return_val_if_fail (GTK_IS_WIDGET (item->details->main_child), NULL);
preferences_item_update_displayed_value (item);
return GTK_WIDGET (item);
}
GtkWidget*
nautilus_preferences_item_new_custom (const char *preference_name,
GtkWidget *child,
const char *signal_name)
{
NautilusPreferencesItem *item;
g_return_val_if_fail (eel_strlen (preference_name) > 0, NULL);
g_return_val_if_fail (GTK_IS_WIDGET (child), NULL);
g_return_val_if_fail (eel_strlen (signal_name) > 0, NULL);
item = NAUTILUS_PREFERENCES_ITEM
(gtk_widget_new (nautilus_preferences_item_get_type (), NULL));
item->details->preference_name = g_strdup (preference_name);
item->details->item_type = NAUTILUS_PREFERENCE_ITEM_CUSTOM;
preferences_item_add_connection_child (item,
child,
signal_name,
GTK_SIGNAL_FUNC (custom_changed_callback));
preferences_item_set_main_child (item, child);
return GTK_WIDGET (item);
}
static void
enumeration_radio_changed_callback (GtkWidget *buttons, GtkWidget * button, gpointer user_data)
enumeration_radio_changed_callback (EelRadioButtonGroup *radio_button_group,
gpointer callback_data)
{
NautilusPreferencesItem *item;
int i;
char *enumeration_id;
g_assert (user_data != NULL);
g_assert (NAUTILUS_IS_PREFERENCES_ITEM (user_data));
g_return_if_fail (EEL_IS_RADIO_BUTTON_GROUP (radio_button_group));
g_return_if_fail (NAUTILUS_IS_PREFERENCES_ITEM (callback_data));
item = NAUTILUS_PREFERENCES_ITEM (user_data);
item = NAUTILUS_PREFERENCES_ITEM (callback_data);
g_assert (item->details->preference_name != NULL);
i = eel_radio_button_group_get_active_index (EEL_RADIO_BUTTON_GROUP (buttons));
i = eel_radio_button_group_get_active_index (radio_button_group);
enumeration_id = nautilus_preferences_get_enumeration_id (item->details->preference_name);
g_return_if_fail (eel_strlen (enumeration_id) > 0);
......@@ -972,8 +1043,8 @@ editable_string_changed_callback (GtkWidget *button, gpointer user_data)
item = NAUTILUS_PREFERENCES_ITEM (user_data);
g_assert (item->details->child != NULL);
g_assert (EEL_IS_TEXT_CAPTION (item->details->child));
g_assert (item->details->main_child != NULL);
g_assert (EEL_IS_TEXT_CAPTION (item->details->main_child));
preferences_item_update_text_settings_at_idle (item);
}
......@@ -988,8 +1059,8 @@ editable_integer_changed_callback (GtkWidget *button, gpointer user_data)
item = NAUTILUS_PREFERENCES_ITEM (user_data);
g_assert (item->details->child != NULL);
g_assert (EEL_IS_TEXT_CAPTION (item->details->child));
g_assert (item->details->main_child != NULL);
g_assert (EEL_IS_TEXT_CAPTION (item->details->main_child));
preferences_item_update_editable_integer_settings_at_idle (item);
}
......@@ -1150,6 +1221,10 @@ preferences_item_update_displayed_value (NautilusPreferencesItem *item)
case NAUTILUS_PREFERENCE_ITEM_PADDING:
break;
case NAUTILUS_PREFERENCE_ITEM_CUSTOM:
preferences_item_update_custom (item);
break;
default:
g_assert_not_reached ();
}
......@@ -1169,7 +1244,7 @@ update_text_settings_at_idle (NautilusPreferencesItem *preferences_item)
{
char *text;
text = eel_text_caption_get_text (EEL_TEXT_CAPTION (preferences_item->details->child));
text = eel_text_caption_get_text (EEL_TEXT_CAPTION (preferences_item->details->main_child));
if (text != NULL) {
nautilus_preferences_set (preferences_item->details->preference_name, text);
......@@ -1198,7 +1273,7 @@ update_integer_settings_at_idle (NautilusPreferencesItem *preferences_item)
int value = 0;
char *text;
text = eel_text_caption_get_text (EEL_TEXT_CAPTION (preferences_item->details->child));
text = eel_text_caption_get_text (EEL_TEXT_CAPTION (preferences_item->details->main_child));
if (text != NULL) {
eel_eat_str_to_int (text, &value);
......@@ -1281,7 +1356,7 @@ nautilus_preferences_item_child_is_caption (const NautilusPreferencesItem *item)
{
g_return_val_if_fail (NAUTILUS_IS_PREFERENCES_ITEM (item), FALSE);
return EEL_IS_CAPTION (item->details->child);
return EEL_IS_CAPTION (item->details->main_child);
}
int
......@@ -1291,11 +1366,11 @@ nautilus_preferences_item_get_child_width (const NautilusPreferencesItem *item)
g_return_val_if_fail (NAUTILUS_IS_PREFERENCES_ITEM (item), 0);
if (item->details->child == NULL) {
if (item->details->main_child == NULL) {
return 0;
}
child_dimensions = eel_gtk_widget_get_preferred_dimensions (item->details->child);
child_dimensions = eel_gtk_widget_get_preferred_dimensions (item->details->main_child);
return child_dimensions.width;
}
......@@ -1311,8 +1386,8 @@ nautilus_preferences_item_set_caption_extra_spacing (NautilusPreferencesItem *it
return;
}
eel_caption_set_extra_spacing (EEL_CAPTION (item->details->child),
extra_spacing);
eel_caption_set_extra_spacing (EEL_CAPTION (item->details->main_child),
extra_spacing);
}
gboolean
......@@ -1364,4 +1439,3 @@ nautilus_preferences_item_enumeration_list_set_unique_exceptions (NautilusPrefer
preferences_item_update_enumeration_list_uniqueness (item);
}
......@@ -65,6 +65,7 @@ struct NautilusPreferencesItemClass
typedef enum
{
NAUTILUS_PREFERENCE_ITEM_BOOLEAN,
NAUTILUS_PREFERENCE_ITEM_CUSTOM,
NAUTILUS_PREFERENCE_ITEM_EDITABLE_INTEGER,
NAUTILUS_PREFERENCE_ITEM_EDITABLE_STRING,
NAUTILUS_PREFERENCE_ITEM_ENUMERATION_HORIZONTAL_RADIO,
......@@ -86,6 +87,9 @@ typedef enum
GtkType nautilus_preferences_item_get_type (void);
GtkWidget* nautilus_preferences_item_new (const char *preference_name,
NautilusPreferencesItemType item_type);
GtkWidget* nautilus_preferences_item_new_custom (const char *preference_name,
GtkWidget *child,
const char *signal_name);
char * nautilus_preferences_item_get_name (const NautilusPreferencesItem *preferences_item);
void nautilus_preferences_item_set_control_preference (NautilusPreferencesItem *preferences_item,
const char *control_preference_name);
......
......@@ -30,19 +30,20 @@
#include "nautilus-global-preferences.h"
#include "nautilus-metadata.h"
#include "nautilus-preferences.h"
#include <eel/eel-glib-extensions.h>
#include <eel/eel-gdk-pixbuf-extensions.h>
#include <eel/eel-string-list.h>
#include <eel/eel-string.h>
#include <eel/eel-vfs-extensions.h>
#include <eel/eel-xml-extensions.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <gnome-xml/parser.h>
#include <gnome-xml/xmlmemory.h>
#include <libgnome/gnome-util.h>
#include <libgnomevfs/gnome-vfs.h>
#include <librsvg/rsvg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <libgnome/gnome-defs.h>
#include <libgnome/gnome-i18n.h>
#include <libgnome/gnome-util.h>
/* static globals to hold the last accessed and default theme files */
static char *last_theme_name = NULL;
......@@ -51,6 +52,9 @@ static xmlDocPtr default_theme_document = NULL;
static char *theme_from_preferences = NULL;
#define THEME_PREVIEW_ICON_WIDTH 70
#define THEME_PREVIEW_ICON_HEIGHT 48
static void
theme_changed_callback (gpointer callback_data)
{
......@@ -97,10 +101,10 @@ load_theme_document (const char *theme_name)
{
xmlDocPtr theme_document;
char *theme_path, *temp_str;
char *user_directory, *themes_directory;
char *user_themes_directory;
/* formulate the theme path name */
if (strcmp(theme_name, "default") == 0) {
if (eel_str_is_equal (theme_name, "default")) {
theme_path = nautilus_pixmap_file ("default.xml");
} else {
temp_str = g_strdup_printf("%s/%s.xml", theme_name, theme_name);
......@@ -110,13 +114,11 @@ load_theme_document (const char *theme_name)
/* if we can't find the theme document in the global area, try in the user's home */
if (theme_path == NULL) {
user_directory = nautilus_get_user_directory ();
themes_directory = nautilus_make_path (user_directory, "themes");
user_themes_directory = nautilus_theme_get_user_themes_directory ();
temp_str = g_strdup_printf("%s/%s.xml", theme_name, theme_name);
theme_path = nautilus_make_path (themes_directory, temp_str);
theme_path = nautilus_make_path (user_themes_directory, temp_str);
g_free (user_directory);
g_free (themes_directory);
g_free (user_themes_directory);
g_free (temp_str);
if (!g_file_exists (theme_path)) {
......@@ -232,21 +234,19 @@ nautilus_theme_get_theme_data (const char *resource_name, const char *property_n
static char *
nautilus_pixmap_file_may_be_local (const char *themed_image)
{
char *image_path, *user_directory, *themes_directory;
char *image_path, *user_themes_directory;
image_path = nautilus_pixmap_file (themed_image);
if (image_path == NULL) {
user_directory = nautilus_get_user_directory ();
themes_directory = nautilus_make_path (user_directory, "themes");
user_themes_directory = nautilus_theme_get_user_themes_directory ();
image_path = nautilus_make_path (themes_directory, themed_image);
image_path = nautilus_make_path (user_themes_directory, themed_image);
if (!g_file_exists (image_path)) {
g_free (image_path);
image_path = NULL;
}
g_free (user_directory);
g_free (themes_directory);
g_free (user_themes_directory);
}
return image_path;
}
......@@ -260,7 +260,7 @@ nautilus_theme_get_image_path_from_theme (const char *image_name, const char* th
{
char *image_path, *png_string, *temp_str;
if (eel_strcmp (theme_name, "default") != 0) {
if (!eel_str_is_equal (theme_name, "default")) {
temp_str = g_strdup_printf ("%s/%s", theme_name, image_name);
image_path = nautilus_pixmap_file_may_be_local (temp_str);
......@@ -321,16 +321,17 @@ nautilus_theme_get_image_path (const char *image_name)
}
/* create a pixbuf that represents the passed in theme name */
GdkPixbuf *
nautilus_theme_make_selector (const char *theme_name)
nautilus_theme_make_preview_pixbuf (const char *theme_name)
{
char *pixbuf_file, *theme_preview_name;
char *user_directory, *directory_uri;
char *user_themes_directory;
GdkPixbuf *pixbuf;
/* first, see if we can find an explicit preview */
if (!eel_strcmp (theme_name, "default")) {
/* FIXME: This special handling for "default" is a little weird */
if (eel_str_is_equal (theme_name, "default")) {
theme_preview_name = g_strdup ("theme_preview.png");
} else {
theme_preview_name = g_strdup_printf ("%s/%s", theme_name, "theme_preview.png");
......@@ -343,12 +344,9 @@ nautilus_theme_make_selector (const char *theme_name)
return pixbuf;
} else {
/* try the user directory */
user_directory = nautilus_get_user_directory ();
directory_uri = nautilus_make_path (user_directory, "themes");
pixbuf_file = nautilus_make_path (directory_uri, theme_preview_name);
g_free (user_directory);
g_free (directory_uri);
user_themes_directory = nautilus_theme_get_user_themes_directory ();
pixbuf_file = nautilus_make_path (user_themes_directory, theme_preview_name);
g_free (user_themes_directory);
if (g_file_exists (pixbuf_file)) {
pixbuf = gdk_pixbuf_new_from_file (pixbuf_file);
......@@ -373,16 +371,15 @@ nautilus_theme_make_selector (const char *theme_name)
/* try the user directory if necessary */
if (pixbuf_file == NULL) {
user_directory = nautilus_get_user_directory ();
directory_uri = nautilus_make_path (user_directory, "themes");
user_themes_directory = nautilus_theme_get_user_themes_directory ();
theme_preview_name = g_strdup_printf ("%s/i-directory.png", theme_name);
pixbuf_file = nautilus_make_path (directory_uri, theme_preview_name);
pixbuf_file = nautilus_make_path (user_themes_directory, theme_preview_name);
g_free (theme_preview_name);
if (!g_file_exists (pixbuf_file)) {
g_free (pixbuf_file);
theme_preview_name = g_strdup_printf ("%s/i-directory.svg", theme_name);
pixbuf_file = nautilus_make_path (directory_uri, theme_preview_name);
pixbuf_file = nautilus_make_path (user_themes_directory, theme_preview_name);
g_free (theme_preview_name);
if (!g_file_exists (pixbuf_file)) {
......@@ -391,8 +388,7 @@ nautilus_theme_make_selector (const char *theme_name)
}
}
g_free (user_directory);
g_free (directory_uri);
g_free (user_themes_directory);
}
/* if we can't find anything, return NULL */
......@@ -417,3 +413,444 @@ nautilus_theme_make_selector (const char *theme_name)
g_free (pixbuf_file);
return pixbuf;
}
typedef struct
{
char *name;
char *path;
char *display_name;
char *description;
GdkPixbuf *preview_pixbuf;
gboolean builtin;
} ThemeAttibutes;
/* Test for the presence of an icon file */
static gboolean
vfs_file_exists (const char *file_uri)
{
GnomeVFSResult result;
GnomeVFSFileInfo *file_info;
file_info = gnome_vfs_file_info_new ();
result = gnome_vfs_get_file_info (file_uri, file_info, 0);
gnome_vfs_file_info_unref (file_info);
return result == GNOME_VFS_OK;
}
static gboolean
has_image_file (const char *path_uri,
const char *dir_name,
const char *image_file)
{
char* image_uri;
gboolean exists;
/* FIXME: This special handling for "default" is a little weird */
if (eel_str_is_equal (dir_name, "default")) {