generalized toolbar icon themes to support any number, and reorganized

generalized toolbar icon themes to support any number, and
	reorganized appearance preference panel to group the icon theme
	selectors together.  Also, added a cleaner version of the zoom icon.
This commit is contained in:
Andy Hertzfeld 2000-06-05 04:33:56 +00:00
parent a01189b6c5
commit 68eeed5cdd
15 changed files with 518 additions and 103 deletions

View file

@ -1,3 +1,35 @@
2000-06-04 Andy Hertzfeld <andy@eazel.com>
* libnautilus-extensions/nautilus-global-preferences.c:
(global_preferences_create_dialog),
(global_preferences_register_for_ui):
reorganized the icon theming in the preferences dialog, combining toolbar and
icon themes into one section, and generalizing toolbar themes to support any
number of themes.
* libnautilus-extensions/nautilus-global-preferences.h:
generalized the toolbar icon theme preference from a boolean to a string,
changing its name to avoid confusion
* nautilus-widgets/nautilus-preferences-item.c:
(preferences_item_construct), (has_image_file), (add_icon_themes),
(preferences_item_create_icon_theme),
(preferences_item_create_toolbar_icon_theme):
added support for toolbar icon themes and made it more robust for icon themes
in general, by adding code to check that a candidate directory actually has
the required icons.
* nautilus-widgets/nautilus-preferences-item.h:
added a new item type for toolbar themes
* src/nautilus-window-toolbars.c: (setup_button),
(setup_toolbar_images), (nautilus_window_initialize_toolbars),
(nautilus_window_toolbar_remove_theme_callback):
generalized the toolbar icon switching code to support arbitrary themes instead
of just two.
* libnautilus-extensions/nautilus-link-set.c:
(get_link_set_document), (expand_uri), (nautilus_link_set_install),
(nautilus_link_set_remove):
added link set remove code, which hasn't been tested yet, but will be soon.
* icons/zoom.png:
cleaner version of magnifier icon
2000-06-04 Ian McKellar <yakk@yakk.net>
* nautilus-widgets/nautilus-preferences.c:

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 898 B

View file

@ -185,24 +185,23 @@ global_preferences_create_dialog (void)
NAUTILUS_PREFERENCES_ANTI_ALIASED_CANVAS,
NAUTILUS_PREFERENCE_ITEM_BOOLEAN);
nautilus_preferences_pane_add_group (NAUTILUS_PREFERENCES_PANE (appearance_pane), "Toolbar Icons");
nautilus_preferences_pane_add_group (NAUTILUS_PREFERENCES_PANE (appearance_pane), "Icon Themes");
nautilus_preferences_pane_add_item_to_nth_group (NAUTILUS_PREFERENCES_PANE (appearance_pane),
1,
NAUTILUS_PREFERENCES_EAZEL_TOOLBAR_ICONS,
NAUTILUS_PREFERENCE_ITEM_BOOLEAN);
NAUTILUS_PREFERENCES_TOOLBAR_ICON_THEME,
NAUTILUS_PREFERENCE_ITEM_TOOLBAR_ICON_THEME);
nautilus_preferences_pane_add_item_to_nth_group (NAUTILUS_PREFERENCES_PANE (appearance_pane),
1,
NAUTILUS_PREFERENCES_ICON_THEME,
NAUTILUS_PREFERENCE_ITEM_ICON_THEME);
nautilus_preferences_pane_add_group (NAUTILUS_PREFERENCES_PANE (appearance_pane), "Fonts");
nautilus_preferences_pane_add_item_to_nth_group (NAUTILUS_PREFERENCES_PANE (appearance_pane),
2,
NAUTILUS_PREFERENCES_DIRECTORY_VIEW_FONT_FAMILY,
NAUTILUS_PREFERENCE_ITEM_FONT_FAMILY);
nautilus_preferences_pane_add_group (NAUTILUS_PREFERENCES_PANE (appearance_pane), "Icons");
nautilus_preferences_pane_add_item_to_nth_group (NAUTILUS_PREFERENCES_PANE (appearance_pane),
3,
NAUTILUS_PREFERENCES_ICON_THEME,
NAUTILUS_PREFERENCE_ITEM_ICON_THEME);
/*
* Tradeoffs
*/
@ -500,7 +499,7 @@ global_preferences_register_for_ui (void)
FALSE);
global_preferences_register_string_with_defaults (NAUTILUS_PREFERENCES_ICON_THEME,
"Select theme for icons",
"theme for file icons: ",
"default",
"default",
"default");
@ -512,11 +511,11 @@ global_preferences_register_for_ui (void)
"helvetica");
/* toolbar icons */
global_preferences_register_boolean_with_defaults (NAUTILUS_PREFERENCES_EAZEL_TOOLBAR_ICONS,
"Use Eazel's toolbar icons",
FALSE,
FALSE,
FALSE);
global_preferences_register_string_with_defaults (NAUTILUS_PREFERENCES_TOOLBAR_ICON_THEME,
"theme for toolbar icons:",
"standard",
"standard",
"standard");
/*
* These dont have a UI (yet ? maybe in the advanced settings ?).

View file

@ -62,7 +62,7 @@ BEGIN_GNOME_DECLS
#define NAUTILUS_PREFERENCES_DIRECTORY_VIEW_FONT_FAMILY "directory-view/font_family"
/* themes */
#define NAUTILUS_PREFERENCES_EAZEL_TOOLBAR_ICONS "preferences/eazel_toolbar_icons"
#define NAUTILUS_PREFERENCES_TOOLBAR_ICON_THEME "preferences/toolbar_icon_theme"
#define NAUTILUS_PREFERENCES_ICON_THEME "preferences/icon_theme"
enum

View file

@ -69,6 +69,39 @@ create_new_link (const char *directory_path, const char *name, const char *image
return result > 0;
}
/* utility to return link set path */
static xmlDocPtr
get_link_set_document(const char* link_set_name)
{
char *link_set_path, *temp_str;
xmlDocPtr document;
temp_str = g_strdup_printf ("nautilus/linksets/%s.xml", link_set_name);
link_set_path = gnome_datadir_file (temp_str);
g_free (temp_str);
document = xmlParseFile (link_set_path);
g_free (link_set_path);
return document;
}
/* utility to expand the uri to deal with the home directory, etc. */
static char *
expand_uri(const char *uri)
{
char *full_uri, *home_in_uri_format;
if (uri[0] == '~') {
home_in_uri_format = gnome_vfs_escape_string (g_get_home_dir (), GNOME_VFS_URI_UNSAFE_PATH);
full_uri = g_strconcat ("file://", home_in_uri_format, uri + 1, NULL);
g_free (home_in_uri_format);
return full_uri;
}
return g_strdup(uri);
}
/* install a link set into the specified directory */
gboolean
@ -76,22 +109,18 @@ nautilus_link_set_install (const char *directory_path, const char *link_set_name
{
xmlDocPtr document;
xmlNodePtr node;
char *temp_str, *link_set_path;
char *link_name, *image_name, *uri, *full_uri, *home_in_uri_format;
char *link_name, *image_name, *uri, *full_uri;
/* compose the path of the link set file */
temp_str = g_strdup_printf ("nautilus/linksets/%s.xml", link_set_name);
link_set_path = gnome_datadir_file (temp_str);
g_free (temp_str);
/* load and parse the link set document */
document = get_link_set_document(link_set_name);
/* load and parse the linkset xml file */
document = xmlParseFile (link_set_path);
g_free (link_set_path);
if (document == NULL) {
return FALSE;
}
/* loop through the entries, generating .link files */
/* loop through the entries, generating .link files, or incrementing the
reference count if it's already there */
for (node = nautilus_xml_get_children (xmlDocGetRootElement (document));
node != NULL; node = node->next) {
if (strcmp (node->name, "link") == 0) {
@ -100,16 +129,10 @@ nautilus_link_set_install (const char *directory_path, const char *link_set_name
uri = xmlGetProp (node, "uri");
/* Expand special URIs */
full_uri = NULL;
if (uri[0] == '~') {
home_in_uri_format = gnome_vfs_escape_string
(g_get_home_dir (), GNOME_VFS_URI_UNSAFE_PATH);
full_uri = g_strconcat ("file://", home_in_uri_format, uri + 1, NULL);
g_free (home_in_uri_format);
uri = full_uri;
}
if (!create_new_link (directory_path, link_name, image_name, uri)) {
full_uri = expand_uri(uri);
/* create the link file */
if (!create_new_link (directory_path, link_name, image_name, full_uri)) {
g_free (full_uri);
xmlFreeDoc (document);
return FALSE;
@ -126,10 +149,31 @@ nautilus_link_set_install (const char *directory_path, const char *link_set_name
}
/* remove a link set from the specified directory */
/* FIXME: Not implemented. */
#if 0
void
nautilus_link_set_remove (const char *directory_uri, const char *link_set_name)
nautilus_link_set_remove (const char *directory_path, const char *link_set_name)
{
xmlDocPtr document;
xmlNodePtr node;
char *link_name, *file_name;
document = get_link_set_document(link_set_name);
if (document == NULL)
return;
/* loop through the entries in the xml file, formulating the names of the link files and
deleting them or decrementing their reference count */
for (node = nautilus_xml_get_children (xmlDocGetRootElement (document));
node != NULL; node = node->next) {
if (strcmp (node->name, "link") == 0) {
link_name = xmlGetProp (node, "name");
/* formulate the link file path name */
file_name = g_strdup_printf ("%s/%s.link", directory_path, link_name);
/* delete the file */
unlink(file_name);
g_free(link_name);
}
}
xmlFreeDoc (document);
}
#endif

View file

@ -25,6 +25,8 @@
#include <config.h>
#include "nautilus-preferences-item.h"
#include "nautilus-preferences.h"
#include <libnautilus-extensions/nautilus-file-utilities.h>
#include <libnautilus-extensions/nautilus-glib-extensions.h>
#include <libnautilus-extensions/nautilus-gtk-macros.h>
#include <libgnomevfs/gnome-vfs.h>
@ -85,6 +87,8 @@ static void preferences_item_create_font_family (NautilusPreferenc
const NautilusPreference *prefrence);
static void preferences_item_create_icon_theme (NautilusPreferencesItem *item,
const NautilusPreference *preference);
static void preferences_item_create_toolbar_icon_theme (NautilusPreferencesItem *item,
const NautilusPreference *preference);
static void enum_radio_group_changed_callback (GtkWidget *button_group,
GtkWidget *button,
gpointer user_data);
@ -274,6 +278,10 @@ preferences_item_construct (NautilusPreferencesItem *item,
preferences_item_create_icon_theme (item, preference);
break;
case NAUTILUS_PREFERENCE_ITEM_TOOLBAR_ICON_THEME:
preferences_item_create_toolbar_icon_theme (item, preference);
break;
}
gtk_object_unref (GTK_OBJECT (preference));
@ -408,10 +416,50 @@ preferences_item_create_font_family (NautilusPreferencesItem *item,
(gpointer) item);
}
/* utility to determine if an image file exists in the candidate directory */
static const char *icon_file_name_suffixes[] =
{
".svg",
".SVG",
".png",
".PNG"
};
static gboolean
has_image_file(const char *directory_uri, const char *dir_name, const char *required_file)
{
char *temp_str, *base_uri;
int index;
GnomeVFSResult result;
GnomeVFSFileInfo *file_info;
file_info = gnome_vfs_file_info_new ();
temp_str = nautilus_make_path(directory_uri, dir_name);
base_uri = nautilus_make_path(temp_str, required_file);
g_free(temp_str);
for (index = 0; index < NAUTILUS_N_ELEMENTS (icon_file_name_suffixes); index++) {
temp_str = g_strconcat (base_uri, icon_file_name_suffixes[index], NULL);
result = gnome_vfs_get_file_info (temp_str, file_info, 0, NULL);
g_free(temp_str);
if (result == GNOME_VFS_OK) {
g_free(base_uri);
gnome_vfs_file_info_unref (file_info);
return TRUE;
}
}
gnome_vfs_file_info_unref (file_info);
g_free(base_uri);
return FALSE;
}
/* add available icon themes to the theme list by iterating through the
nautilus icons directory, looking for sub-directories */
static void
add_icon_themes(NautilusStringList *theme_list)
add_icon_themes(NautilusStringList *theme_list, char *required_file)
{
char *directory_uri;
GnomeVFSResult result;
@ -433,7 +481,8 @@ add_icon_themes(NautilusStringList *theme_list)
while (current_file_info != NULL) {
if ((current_file_info->type == GNOME_VFS_FILE_TYPE_DIRECTORY) &&
(current_file_info->name[0] != '.'))
nautilus_string_list_insert (theme_list, current_file_info->name);
if (has_image_file(directory_uri, current_file_info->name, required_file))
nautilus_string_list_insert (theme_list, current_file_info->name);
current_file_info = gnome_vfs_directory_list_next(list);
}
@ -465,7 +514,7 @@ preferences_item_create_icon_theme (NautilusPreferencesItem *item,
theme_list = nautilus_string_list_new ();
nautilus_string_list_insert (theme_list, "default");
add_icon_themes(theme_list);
add_icon_themes(theme_list, "i-directory");
nautilus_string_picker_set_string_list (NAUTILUS_STRING_PICKER (item->details->child), theme_list);
@ -487,6 +536,52 @@ preferences_item_create_icon_theme (NautilusPreferencesItem *item,
}
static void
preferences_item_create_toolbar_icon_theme (NautilusPreferencesItem *item,
const NautilusPreference *preference)
{
char *description;
char *current_value;
NautilusStringList *theme_list;
g_assert (item != NULL);
g_assert (preference != NULL);
g_assert (item->details->preference_name != NULL);
description = nautilus_preference_get_description (preference);
g_assert (description != NULL);
item->details->child = nautilus_string_picker_new ();
nautilus_string_picker_set_title_label (NAUTILUS_STRING_PICKER (item->details->child), description);
g_free (description);
theme_list = nautilus_string_list_new ();
nautilus_string_list_insert (theme_list, "standard");
add_icon_themes(theme_list, "Up");
nautilus_string_picker_set_string_list (NAUTILUS_STRING_PICKER (item->details->child), theme_list);
current_value = nautilus_preferences_get (item->details->preference_name, "standard");
g_assert (current_value != NULL);
g_assert (nautilus_string_list_contains (theme_list, current_value));
nautilus_string_picker_set_text (NAUTILUS_STRING_PICKER (item->details->child), current_value);
g_free (current_value);
nautilus_string_list_free (theme_list);
gtk_signal_connect (GTK_OBJECT (item->details->child),
"changed",
GTK_SIGNAL_FUNC (text_item_changed_callback),
(gpointer) item);
}
/* NautilusPreferencesItem public methods */
GtkWidget *
nautilus_preferences_item_new (const gchar *preference_name,

View file

@ -67,6 +67,7 @@ typedef enum
NAUTILUS_PREFERENCE_ITEM_BOOLEAN,
NAUTILUS_PREFERENCE_ITEM_ENUM,
NAUTILUS_PREFERENCE_ITEM_FONT_FAMILY,
NAUTILUS_PREFERENCE_ITEM_TOOLBAR_ICON_THEME,
NAUTILUS_PREFERENCE_ITEM_ICON_THEME
} NautilusPreferencesItemType;

View file

@ -185,24 +185,23 @@ global_preferences_create_dialog (void)
NAUTILUS_PREFERENCES_ANTI_ALIASED_CANVAS,
NAUTILUS_PREFERENCE_ITEM_BOOLEAN);
nautilus_preferences_pane_add_group (NAUTILUS_PREFERENCES_PANE (appearance_pane), "Toolbar Icons");
nautilus_preferences_pane_add_group (NAUTILUS_PREFERENCES_PANE (appearance_pane), "Icon Themes");
nautilus_preferences_pane_add_item_to_nth_group (NAUTILUS_PREFERENCES_PANE (appearance_pane),
1,
NAUTILUS_PREFERENCES_EAZEL_TOOLBAR_ICONS,
NAUTILUS_PREFERENCE_ITEM_BOOLEAN);
NAUTILUS_PREFERENCES_TOOLBAR_ICON_THEME,
NAUTILUS_PREFERENCE_ITEM_TOOLBAR_ICON_THEME);
nautilus_preferences_pane_add_item_to_nth_group (NAUTILUS_PREFERENCES_PANE (appearance_pane),
1,
NAUTILUS_PREFERENCES_ICON_THEME,
NAUTILUS_PREFERENCE_ITEM_ICON_THEME);
nautilus_preferences_pane_add_group (NAUTILUS_PREFERENCES_PANE (appearance_pane), "Fonts");
nautilus_preferences_pane_add_item_to_nth_group (NAUTILUS_PREFERENCES_PANE (appearance_pane),
2,
NAUTILUS_PREFERENCES_DIRECTORY_VIEW_FONT_FAMILY,
NAUTILUS_PREFERENCE_ITEM_FONT_FAMILY);
nautilus_preferences_pane_add_group (NAUTILUS_PREFERENCES_PANE (appearance_pane), "Icons");
nautilus_preferences_pane_add_item_to_nth_group (NAUTILUS_PREFERENCES_PANE (appearance_pane),
3,
NAUTILUS_PREFERENCES_ICON_THEME,
NAUTILUS_PREFERENCE_ITEM_ICON_THEME);
/*
* Tradeoffs
*/
@ -500,7 +499,7 @@ global_preferences_register_for_ui (void)
FALSE);
global_preferences_register_string_with_defaults (NAUTILUS_PREFERENCES_ICON_THEME,
"Select theme for icons",
"theme for file icons: ",
"default",
"default",
"default");
@ -512,11 +511,11 @@ global_preferences_register_for_ui (void)
"helvetica");
/* toolbar icons */
global_preferences_register_boolean_with_defaults (NAUTILUS_PREFERENCES_EAZEL_TOOLBAR_ICONS,
"Use Eazel's toolbar icons",
FALSE,
FALSE,
FALSE);
global_preferences_register_string_with_defaults (NAUTILUS_PREFERENCES_TOOLBAR_ICON_THEME,
"theme for toolbar icons:",
"standard",
"standard",
"standard");
/*
* These dont have a UI (yet ? maybe in the advanced settings ?).

View file

@ -62,7 +62,7 @@ BEGIN_GNOME_DECLS
#define NAUTILUS_PREFERENCES_DIRECTORY_VIEW_FONT_FAMILY "directory-view/font_family"
/* themes */
#define NAUTILUS_PREFERENCES_EAZEL_TOOLBAR_ICONS "preferences/eazel_toolbar_icons"
#define NAUTILUS_PREFERENCES_TOOLBAR_ICON_THEME "preferences/toolbar_icon_theme"
#define NAUTILUS_PREFERENCES_ICON_THEME "preferences/icon_theme"
enum

View file

@ -69,6 +69,39 @@ create_new_link (const char *directory_path, const char *name, const char *image
return result > 0;
}
/* utility to return link set path */
static xmlDocPtr
get_link_set_document(const char* link_set_name)
{
char *link_set_path, *temp_str;
xmlDocPtr document;
temp_str = g_strdup_printf ("nautilus/linksets/%s.xml", link_set_name);
link_set_path = gnome_datadir_file (temp_str);
g_free (temp_str);
document = xmlParseFile (link_set_path);
g_free (link_set_path);
return document;
}
/* utility to expand the uri to deal with the home directory, etc. */
static char *
expand_uri(const char *uri)
{
char *full_uri, *home_in_uri_format;
if (uri[0] == '~') {
home_in_uri_format = gnome_vfs_escape_string (g_get_home_dir (), GNOME_VFS_URI_UNSAFE_PATH);
full_uri = g_strconcat ("file://", home_in_uri_format, uri + 1, NULL);
g_free (home_in_uri_format);
return full_uri;
}
return g_strdup(uri);
}
/* install a link set into the specified directory */
gboolean
@ -76,22 +109,18 @@ nautilus_link_set_install (const char *directory_path, const char *link_set_name
{
xmlDocPtr document;
xmlNodePtr node;
char *temp_str, *link_set_path;
char *link_name, *image_name, *uri, *full_uri, *home_in_uri_format;
char *link_name, *image_name, *uri, *full_uri;
/* compose the path of the link set file */
temp_str = g_strdup_printf ("nautilus/linksets/%s.xml", link_set_name);
link_set_path = gnome_datadir_file (temp_str);
g_free (temp_str);
/* load and parse the link set document */
document = get_link_set_document(link_set_name);
/* load and parse the linkset xml file */
document = xmlParseFile (link_set_path);
g_free (link_set_path);
if (document == NULL) {
return FALSE;
}
/* loop through the entries, generating .link files */
/* loop through the entries, generating .link files, or incrementing the
reference count if it's already there */
for (node = nautilus_xml_get_children (xmlDocGetRootElement (document));
node != NULL; node = node->next) {
if (strcmp (node->name, "link") == 0) {
@ -100,16 +129,10 @@ nautilus_link_set_install (const char *directory_path, const char *link_set_name
uri = xmlGetProp (node, "uri");
/* Expand special URIs */
full_uri = NULL;
if (uri[0] == '~') {
home_in_uri_format = gnome_vfs_escape_string
(g_get_home_dir (), GNOME_VFS_URI_UNSAFE_PATH);
full_uri = g_strconcat ("file://", home_in_uri_format, uri + 1, NULL);
g_free (home_in_uri_format);
uri = full_uri;
}
if (!create_new_link (directory_path, link_name, image_name, uri)) {
full_uri = expand_uri(uri);
/* create the link file */
if (!create_new_link (directory_path, link_name, image_name, full_uri)) {
g_free (full_uri);
xmlFreeDoc (document);
return FALSE;
@ -126,10 +149,31 @@ nautilus_link_set_install (const char *directory_path, const char *link_set_name
}
/* remove a link set from the specified directory */
/* FIXME: Not implemented. */
#if 0
void
nautilus_link_set_remove (const char *directory_uri, const char *link_set_name)
nautilus_link_set_remove (const char *directory_path, const char *link_set_name)
{
xmlDocPtr document;
xmlNodePtr node;
char *link_name, *file_name;
document = get_link_set_document(link_set_name);
if (document == NULL)
return;
/* loop through the entries in the xml file, formulating the names of the link files and
deleting them or decrementing their reference count */
for (node = nautilus_xml_get_children (xmlDocGetRootElement (document));
node != NULL; node = node->next) {
if (strcmp (node->name, "link") == 0) {
link_name = xmlGetProp (node, "name");
/* formulate the link file path name */
file_name = g_strdup_printf ("%s/%s.link", directory_path, link_name);
/* delete the file */
unlink(file_name);
g_free(link_name);
}
}
xmlFreeDoc (document);
}
#endif

View file

@ -25,6 +25,8 @@
#include <config.h>
#include "nautilus-preferences-item.h"
#include "nautilus-preferences.h"
#include <libnautilus-extensions/nautilus-file-utilities.h>
#include <libnautilus-extensions/nautilus-glib-extensions.h>
#include <libnautilus-extensions/nautilus-gtk-macros.h>
#include <libgnomevfs/gnome-vfs.h>
@ -85,6 +87,8 @@ static void preferences_item_create_font_family (NautilusPreferenc
const NautilusPreference *prefrence);
static void preferences_item_create_icon_theme (NautilusPreferencesItem *item,
const NautilusPreference *preference);
static void preferences_item_create_toolbar_icon_theme (NautilusPreferencesItem *item,
const NautilusPreference *preference);
static void enum_radio_group_changed_callback (GtkWidget *button_group,
GtkWidget *button,
gpointer user_data);
@ -274,6 +278,10 @@ preferences_item_construct (NautilusPreferencesItem *item,
preferences_item_create_icon_theme (item, preference);
break;
case NAUTILUS_PREFERENCE_ITEM_TOOLBAR_ICON_THEME:
preferences_item_create_toolbar_icon_theme (item, preference);
break;
}
gtk_object_unref (GTK_OBJECT (preference));
@ -408,10 +416,50 @@ preferences_item_create_font_family (NautilusPreferencesItem *item,
(gpointer) item);
}
/* utility to determine if an image file exists in the candidate directory */
static const char *icon_file_name_suffixes[] =
{
".svg",
".SVG",
".png",
".PNG"
};
static gboolean
has_image_file(const char *directory_uri, const char *dir_name, const char *required_file)
{
char *temp_str, *base_uri;
int index;
GnomeVFSResult result;
GnomeVFSFileInfo *file_info;
file_info = gnome_vfs_file_info_new ();
temp_str = nautilus_make_path(directory_uri, dir_name);
base_uri = nautilus_make_path(temp_str, required_file);
g_free(temp_str);
for (index = 0; index < NAUTILUS_N_ELEMENTS (icon_file_name_suffixes); index++) {
temp_str = g_strconcat (base_uri, icon_file_name_suffixes[index], NULL);
result = gnome_vfs_get_file_info (temp_str, file_info, 0, NULL);
g_free(temp_str);
if (result == GNOME_VFS_OK) {
g_free(base_uri);
gnome_vfs_file_info_unref (file_info);
return TRUE;
}
}
gnome_vfs_file_info_unref (file_info);
g_free(base_uri);
return FALSE;
}
/* add available icon themes to the theme list by iterating through the
nautilus icons directory, looking for sub-directories */
static void
add_icon_themes(NautilusStringList *theme_list)
add_icon_themes(NautilusStringList *theme_list, char *required_file)
{
char *directory_uri;
GnomeVFSResult result;
@ -433,7 +481,8 @@ add_icon_themes(NautilusStringList *theme_list)
while (current_file_info != NULL) {
if ((current_file_info->type == GNOME_VFS_FILE_TYPE_DIRECTORY) &&
(current_file_info->name[0] != '.'))
nautilus_string_list_insert (theme_list, current_file_info->name);
if (has_image_file(directory_uri, current_file_info->name, required_file))
nautilus_string_list_insert (theme_list, current_file_info->name);
current_file_info = gnome_vfs_directory_list_next(list);
}
@ -465,7 +514,7 @@ preferences_item_create_icon_theme (NautilusPreferencesItem *item,
theme_list = nautilus_string_list_new ();
nautilus_string_list_insert (theme_list, "default");
add_icon_themes(theme_list);
add_icon_themes(theme_list, "i-directory");
nautilus_string_picker_set_string_list (NAUTILUS_STRING_PICKER (item->details->child), theme_list);
@ -487,6 +536,52 @@ preferences_item_create_icon_theme (NautilusPreferencesItem *item,
}
static void
preferences_item_create_toolbar_icon_theme (NautilusPreferencesItem *item,
const NautilusPreference *preference)
{
char *description;
char *current_value;
NautilusStringList *theme_list;
g_assert (item != NULL);
g_assert (preference != NULL);
g_assert (item->details->preference_name != NULL);
description = nautilus_preference_get_description (preference);
g_assert (description != NULL);
item->details->child = nautilus_string_picker_new ();
nautilus_string_picker_set_title_label (NAUTILUS_STRING_PICKER (item->details->child), description);
g_free (description);
theme_list = nautilus_string_list_new ();
nautilus_string_list_insert (theme_list, "standard");
add_icon_themes(theme_list, "Up");
nautilus_string_picker_set_string_list (NAUTILUS_STRING_PICKER (item->details->child), theme_list);
current_value = nautilus_preferences_get (item->details->preference_name, "standard");
g_assert (current_value != NULL);
g_assert (nautilus_string_list_contains (theme_list, current_value));
nautilus_string_picker_set_text (NAUTILUS_STRING_PICKER (item->details->child), current_value);
g_free (current_value);
nautilus_string_list_free (theme_list);
gtk_signal_connect (GTK_OBJECT (item->details->child),
"changed",
GTK_SIGNAL_FUNC (text_item_changed_callback),
(gpointer) item);
}
/* NautilusPreferencesItem public methods */
GtkWidget *
nautilus_preferences_item_new (const gchar *preference_name,

View file

@ -67,6 +67,7 @@ typedef enum
NAUTILUS_PREFERENCE_ITEM_BOOLEAN,
NAUTILUS_PREFERENCE_ITEM_ENUM,
NAUTILUS_PREFERENCE_ITEM_FONT_FAMILY,
NAUTILUS_PREFERENCE_ITEM_TOOLBAR_ICON_THEME,
NAUTILUS_PREFERENCE_ITEM_ICON_THEME
} NautilusPreferencesItemType;

View file

@ -25,6 +25,8 @@
#include <config.h>
#include "nautilus-preferences-item.h"
#include "nautilus-preferences.h"
#include <libnautilus-extensions/nautilus-file-utilities.h>
#include <libnautilus-extensions/nautilus-glib-extensions.h>
#include <libnautilus-extensions/nautilus-gtk-macros.h>
#include <libgnomevfs/gnome-vfs.h>
@ -85,6 +87,8 @@ static void preferences_item_create_font_family (NautilusPreferenc
const NautilusPreference *prefrence);
static void preferences_item_create_icon_theme (NautilusPreferencesItem *item,
const NautilusPreference *preference);
static void preferences_item_create_toolbar_icon_theme (NautilusPreferencesItem *item,
const NautilusPreference *preference);
static void enum_radio_group_changed_callback (GtkWidget *button_group,
GtkWidget *button,
gpointer user_data);
@ -274,6 +278,10 @@ preferences_item_construct (NautilusPreferencesItem *item,
preferences_item_create_icon_theme (item, preference);
break;
case NAUTILUS_PREFERENCE_ITEM_TOOLBAR_ICON_THEME:
preferences_item_create_toolbar_icon_theme (item, preference);
break;
}
gtk_object_unref (GTK_OBJECT (preference));
@ -408,10 +416,50 @@ preferences_item_create_font_family (NautilusPreferencesItem *item,
(gpointer) item);
}
/* utility to determine if an image file exists in the candidate directory */
static const char *icon_file_name_suffixes[] =
{
".svg",
".SVG",
".png",
".PNG"
};
static gboolean
has_image_file(const char *directory_uri, const char *dir_name, const char *required_file)
{
char *temp_str, *base_uri;
int index;
GnomeVFSResult result;
GnomeVFSFileInfo *file_info;
file_info = gnome_vfs_file_info_new ();
temp_str = nautilus_make_path(directory_uri, dir_name);
base_uri = nautilus_make_path(temp_str, required_file);
g_free(temp_str);
for (index = 0; index < NAUTILUS_N_ELEMENTS (icon_file_name_suffixes); index++) {
temp_str = g_strconcat (base_uri, icon_file_name_suffixes[index], NULL);
result = gnome_vfs_get_file_info (temp_str, file_info, 0, NULL);
g_free(temp_str);
if (result == GNOME_VFS_OK) {
g_free(base_uri);
gnome_vfs_file_info_unref (file_info);
return TRUE;
}
}
gnome_vfs_file_info_unref (file_info);
g_free(base_uri);
return FALSE;
}
/* add available icon themes to the theme list by iterating through the
nautilus icons directory, looking for sub-directories */
static void
add_icon_themes(NautilusStringList *theme_list)
add_icon_themes(NautilusStringList *theme_list, char *required_file)
{
char *directory_uri;
GnomeVFSResult result;
@ -433,7 +481,8 @@ add_icon_themes(NautilusStringList *theme_list)
while (current_file_info != NULL) {
if ((current_file_info->type == GNOME_VFS_FILE_TYPE_DIRECTORY) &&
(current_file_info->name[0] != '.'))
nautilus_string_list_insert (theme_list, current_file_info->name);
if (has_image_file(directory_uri, current_file_info->name, required_file))
nautilus_string_list_insert (theme_list, current_file_info->name);
current_file_info = gnome_vfs_directory_list_next(list);
}
@ -465,7 +514,7 @@ preferences_item_create_icon_theme (NautilusPreferencesItem *item,
theme_list = nautilus_string_list_new ();
nautilus_string_list_insert (theme_list, "default");
add_icon_themes(theme_list);
add_icon_themes(theme_list, "i-directory");
nautilus_string_picker_set_string_list (NAUTILUS_STRING_PICKER (item->details->child), theme_list);
@ -487,6 +536,52 @@ preferences_item_create_icon_theme (NautilusPreferencesItem *item,
}
static void
preferences_item_create_toolbar_icon_theme (NautilusPreferencesItem *item,
const NautilusPreference *preference)
{
char *description;
char *current_value;
NautilusStringList *theme_list;
g_assert (item != NULL);
g_assert (preference != NULL);
g_assert (item->details->preference_name != NULL);
description = nautilus_preference_get_description (preference);
g_assert (description != NULL);
item->details->child = nautilus_string_picker_new ();
nautilus_string_picker_set_title_label (NAUTILUS_STRING_PICKER (item->details->child), description);
g_free (description);
theme_list = nautilus_string_list_new ();
nautilus_string_list_insert (theme_list, "standard");
add_icon_themes(theme_list, "Up");
nautilus_string_picker_set_string_list (NAUTILUS_STRING_PICKER (item->details->child), theme_list);
current_value = nautilus_preferences_get (item->details->preference_name, "standard");
g_assert (current_value != NULL);
g_assert (nautilus_string_list_contains (theme_list, current_value));
nautilus_string_picker_set_text (NAUTILUS_STRING_PICKER (item->details->child), current_value);
g_free (current_value);
nautilus_string_list_free (theme_list);
gtk_signal_connect (GTK_OBJECT (item->details->child),
"changed",
GTK_SIGNAL_FUNC (text_item_changed_callback),
(gpointer) item);
}
/* NautilusPreferencesItem public methods */
GtkWidget *
nautilus_preferences_item_new (const gchar *preference_name,

View file

@ -67,6 +67,7 @@ typedef enum
NAUTILUS_PREFERENCE_ITEM_BOOLEAN,
NAUTILUS_PREFERENCE_ITEM_ENUM,
NAUTILUS_PREFERENCE_ITEM_FONT_FAMILY,
NAUTILUS_PREFERENCE_ITEM_TOOLBAR_ICON_THEME,
NAUTILUS_PREFERENCE_ITEM_ICON_THEME
} NautilusPreferencesItemType;

View file

@ -200,16 +200,23 @@ remember_buttons(NautilusWindow *window, GnomeUIInfo current_toolbar_info[])
/* set up the toolbar info based on the current theme selection from preferences */
static void
setup_button(GtkWidget* button, const char *icon_name)
setup_button(GtkWidget* button, const char *theme_name, const char *icon_name)
{
GList *list;
GtkWidget *widget;
char *full_name;
if (!strcmp(theme_name, "standard"))
full_name = g_strdup(icon_name);
else
full_name = g_strdup_printf("nautilus/%s/%s.png", theme_name, icon_name);
list = gtk_container_children(GTK_CONTAINER(GTK_BIN(button)->child));
widget = GTK_WIDGET(list->data);
g_list_free(list);
gnome_stock_set_icon(GNOME_STOCK(widget), icon_name);
gnome_stock_set_icon(GNOME_STOCK(widget), full_name);
g_free(full_name);
gtk_widget_queue_resize(button);
}
@ -217,16 +224,18 @@ setup_button(GtkWidget* button, const char *icon_name)
static void
setup_toolbar_images(NautilusWindow *window)
{
gboolean use_eazel_theme;
char *theme_name;
use_eazel_theme = nautilus_preferences_get_boolean(NAUTILUS_PREFERENCES_EAZEL_TOOLBAR_ICONS, FALSE);
setup_button (window->back_button, use_eazel_theme ? "nautilus/eazel/Back.png" : GNOME_STOCK_PIXMAP_BACK);
setup_button (window->forward_button, use_eazel_theme ? "nautilus/eazel/Forward.png" : GNOME_STOCK_PIXMAP_FORWARD);
setup_button (window->up_button, use_eazel_theme ? "nautilus/eazel/Up.png" : GNOME_STOCK_PIXMAP_UP);
setup_button (window->home_button, use_eazel_theme ? "nautilus/eazel/Home.png" : GNOME_STOCK_PIXMAP_HOME);
setup_button (window->reload_button, use_eazel_theme ? "nautilus/eazel/Refresh.png" : GNOME_STOCK_PIXMAP_REFRESH);
setup_button (window->stop_button, use_eazel_theme ? "nautilus/eazel/Stop.png" : GNOME_STOCK_PIXMAP_STOP);
theme_name = nautilus_preferences_get (NAUTILUS_PREFERENCES_TOOLBAR_ICON_THEME, "standard");
setup_button (window->back_button, theme_name, GNOME_STOCK_PIXMAP_BACK);
setup_button (window->forward_button, theme_name, GNOME_STOCK_PIXMAP_FORWARD);
setup_button (window->up_button, theme_name, GNOME_STOCK_PIXMAP_UP);
setup_button (window->home_button, theme_name, GNOME_STOCK_PIXMAP_HOME);
setup_button (window->reload_button, theme_name, GNOME_STOCK_PIXMAP_REFRESH);
setup_button (window->stop_button, theme_name, GNOME_STOCK_PIXMAP_STOP);
g_free(theme_name);
}
/* allocate a new toolbar */
@ -258,7 +267,7 @@ nautilus_window_initialize_toolbars (NautilusWindow *window)
window);
/* add callback for preference changes */
nautilus_preferences_add_callback(NAUTILUS_PREFERENCES_EAZEL_TOOLBAR_ICONS,
nautilus_preferences_add_callback(NAUTILUS_PREFERENCES_TOOLBAR_ICON_THEME,
(NautilusPreferencesCallback) setup_toolbar_images,
window);
}
@ -266,7 +275,7 @@ nautilus_window_initialize_toolbars (NautilusWindow *window)
void
nautilus_window_toolbar_remove_theme_callback()
{
nautilus_preferences_remove_callback(NAUTILUS_PREFERENCES_EAZEL_TOOLBAR_ICONS,
nautilus_preferences_remove_callback(NAUTILUS_PREFERENCES_TOOLBAR_ICON_THEME,
(NautilusPreferencesCallback) setup_toolbar_images, NULL);
}