summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRamiro Estrugo <ramiro@src.gnome.org>2001-03-02 09:48:29 +0000
committerRamiro Estrugo <ramiro@src.gnome.org>2001-03-02 09:48:29 +0000
commitc82b82179b758fbf10fcf8db520d633236c31398 (patch)
treede405d2c5e283589b59eef3aa5538e3b495f0f99
parent9ea01db6fb26e2baabc9a56a8bfc0ad821ca3d61 (diff)
downloadnautilus-c82b82179b758fbf10fcf8db520d633236c31398.tar.gz
reviewed by: Eskil Heinous Olsen <eskil@eazel.com>
* libnautilus-extensions/nautilus-string-list.h: * libnautilus-extensions/nautilus-string-list.c: (nautilus_string_list_nth_as_integer), (nautilus_self_check_string_list): New function to get the nth string as an integer - and checks. * libnautilus-extensions/Makefile.am: * libnautilus-extensions/nautilus-font-manager.h: * libnautilus-extensions/nautilus-font-manager.c: * libnautilus-extensions/nautilus-lib-self-check-functions.h: New files. Support for collecting information about the scalable fonts installed on the system. Parts written by Pavel Cisler. * components/text/nautilus-text-view.c: (nautilus_text_view_initialize): Mark a string for translation. * libnautilus-extensions/nautilus-font-factory.c: (nautilus_font_factory_get_font_by_family): Take fontsets into account. Patch submitted by eungkyu@sparcs.kaist.ac.kr. * libnautilus-extensions/nautilus-preferences-item.h: * libnautilus-extensions/nautilus-preferences-item.c: (nautilus_preferences_item_initialize_class), (nautilus_preferences_item_initialize), (preferences_item_destroy), (preferences_item_construct), (preferences_item_update_enum), (preferences_item_create_enum), (preferences_item_update_short_enum), (preferences_item_create_short_enum), (preferences_item_update_boolean), (preferences_item_create_boolean), (preferences_item_update_editable_string), (preferences_item_create_editable_string), (preferences_item_update_integer), (preferences_item_create_integer), (preferences_item_update_font_family), (preferences_item_create_font_family), (nautilus_preferences_item_new), (enum_radio_group_changed_callback), (nautilus_preferences_item_update_displayed_value), (update_text_settings_at_idle): Clean this up a bit. Follow nautilus coding conventions more. Remove long unused theme picker. Remove unused GtkArg stuff. * libnautilus-extensions/nautilus-preferences-pane.c: (nautilus_preferences_pane_new): * libnautilus-extensions/nautilus-preferences-pane.h: Remove unused pane description. * libnautilus-extensions/nautilus-preferences-box.c: (nautilus_preferences_box_add_pane): * libnautilus-extensions/nautilus-preferences-box.h: Remove unused pane description. * libnautilus-extensions/nautilus-global-preferences.c: (global_preferences_install_defaults): Mark font name for translation. (global_preferences_create_dialog), (global_preferences_create_search_pane): Remove unused pane description. * test/.cvsignore: * test/Makefile.am: * test/test-nautilus-glyph-simple.c: (main): * test/test-nautilus-glyph.c: (main): * test/test-nautilus-labeled-image.c: (main): * test/test-nautilus-smooth-text-layout.c: (main): * test/test-nautilus-font-manager.c: (main): * test/test.c: (test_quit): * test/test.h: Some minor changes. New test for font manager.
-rw-r--r--ChangeLog79
-rw-r--r--components/text/nautilus-text-view.c3
-rw-r--r--libnautilus-extensions/Makefile.am2
-rw-r--r--libnautilus-extensions/nautilus-font-factory.c28
-rw-r--r--libnautilus-extensions/nautilus-font-manager.c996
-rw-r--r--libnautilus-extensions/nautilus-font-manager.h52
-rw-r--r--libnautilus-extensions/nautilus-global-preferences.c23
-rw-r--r--libnautilus-extensions/nautilus-lib-self-check-functions.h1
-rw-r--r--libnautilus-extensions/nautilus-preferences-box.c6
-rw-r--r--libnautilus-extensions/nautilus-preferences-box.h3
-rw-r--r--libnautilus-extensions/nautilus-preferences-item.c435
-rw-r--r--libnautilus-extensions/nautilus-preferences-item.h11
-rw-r--r--libnautilus-extensions/nautilus-preferences-pane.c6
-rw-r--r--libnautilus-extensions/nautilus-preferences-pane.h3
-rw-r--r--libnautilus-extensions/nautilus-string-list.c78
-rw-r--r--libnautilus-extensions/nautilus-string-list.h4
-rw-r--r--libnautilus-private/Makefile.am2
-rw-r--r--libnautilus-private/nautilus-font-factory.c28
-rw-r--r--libnautilus-private/nautilus-font-manager.c996
-rw-r--r--libnautilus-private/nautilus-font-manager.h52
-rw-r--r--libnautilus-private/nautilus-global-preferences.c23
-rw-r--r--libnautilus-private/nautilus-lib-self-check-functions.h1
-rw-r--r--libnautilus-private/nautilus-preferences-box.c6
-rw-r--r--libnautilus-private/nautilus-preferences-box.h3
-rw-r--r--libnautilus-private/nautilus-preferences-item.c435
-rw-r--r--libnautilus-private/nautilus-preferences-item.h11
-rw-r--r--libnautilus-private/nautilus-preferences-pane.c6
-rw-r--r--libnautilus-private/nautilus-preferences-pane.h3
-rw-r--r--libnautilus-private/nautilus-string-list.c78
-rw-r--r--libnautilus-private/nautilus-string-list.h4
-rw-r--r--test/.cvsignore1
-rw-r--r--test/Makefile.am2
-rw-r--r--test/test-nautilus-font-manager.c37
-rw-r--r--test/test-nautilus-glyph-simple.c4
-rw-r--r--test/test-nautilus-glyph.c2
-rw-r--r--test/test-nautilus-labeled-image.c2
-rw-r--r--test/test-nautilus-smooth-text-layout.c3
-rw-r--r--test/test.c9
-rw-r--r--test/test.h2
39 files changed, 2654 insertions, 786 deletions
diff --git a/ChangeLog b/ChangeLog
index 53043ad06..9bdb7b346 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,81 @@
+2001-03-01 Ramiro Estrugo <ramiro@eazel.com>
+
+ reviewed by: Eskil Heinous Olsen <eskil@eazel.com>
+
+ * libnautilus-extensions/nautilus-string-list.h:
+ * libnautilus-extensions/nautilus-string-list.c:
+ (nautilus_string_list_nth_as_integer),
+ (nautilus_self_check_string_list):
+ New function to get the nth string as an integer - and checks.
+
+ * libnautilus-extensions/Makefile.am:
+ * libnautilus-extensions/nautilus-font-manager.h:
+ * libnautilus-extensions/nautilus-font-manager.c:
+ * libnautilus-extensions/nautilus-lib-self-check-functions.h:
+ New files. Support for collecting information about the scalable
+ fonts installed on the system. Parts written by Pavel Cisler.
+
+ * components/text/nautilus-text-view.c:
+ (nautilus_text_view_initialize):
+ Mark a string for translation.
+
+ * libnautilus-extensions/nautilus-font-factory.c:
+ (nautilus_font_factory_get_font_by_family):
+ Take fontsets into account. Patch submitted by
+ eungkyu@sparcs.kaist.ac.kr.
+
+ * libnautilus-extensions/nautilus-preferences-item.h:
+ * libnautilus-extensions/nautilus-preferences-item.c:
+ (nautilus_preferences_item_initialize_class),
+ (nautilus_preferences_item_initialize), (preferences_item_destroy),
+ (preferences_item_construct), (preferences_item_update_enum),
+ (preferences_item_create_enum),
+ (preferences_item_update_short_enum),
+ (preferences_item_create_short_enum),
+ (preferences_item_update_boolean),
+ (preferences_item_create_boolean),
+ (preferences_item_update_editable_string),
+ (preferences_item_create_editable_string),
+ (preferences_item_update_integer),
+ (preferences_item_create_integer),
+ (preferences_item_update_font_family),
+ (preferences_item_create_font_family),
+ (nautilus_preferences_item_new),
+ (enum_radio_group_changed_callback),
+ (nautilus_preferences_item_update_displayed_value),
+ (update_text_settings_at_idle):
+ Clean this up a bit. Follow nautilus coding conventions more.
+ Remove long unused theme picker.
+ Remove unused GtkArg stuff.
+
+ * libnautilus-extensions/nautilus-preferences-pane.c:
+ (nautilus_preferences_pane_new):
+ * libnautilus-extensions/nautilus-preferences-pane.h:
+ Remove unused pane description.
+
+ * libnautilus-extensions/nautilus-preferences-box.c:
+ (nautilus_preferences_box_add_pane):
+ * libnautilus-extensions/nautilus-preferences-box.h:
+ Remove unused pane description.
+
+ * libnautilus-extensions/nautilus-global-preferences.c:
+ (global_preferences_install_defaults): Mark font name for
+ translation.
+ (global_preferences_create_dialog),
+ (global_preferences_create_search_pane): Remove unused pane
+ description.
+
+ * test/.cvsignore:
+ * test/Makefile.am:
+ * test/test-nautilus-glyph-simple.c: (main):
+ * test/test-nautilus-glyph.c: (main):
+ * test/test-nautilus-labeled-image.c: (main):
+ * test/test-nautilus-smooth-text-layout.c: (main):
+ * test/test-nautilus-font-manager.c: (main):
+ * test/test.c: (test_quit):
+ * test/test.h:
+ Some minor changes. New test for font manager.
+
2001-03-02 Arlo Rose <arlo@eazel.com>
reviewed by: Josh Barrow <josh@eazel.com>
@@ -95,7 +173,6 @@
Yee Ha! New throbbers for everyone!
Added new throbbers for Crux Teal and Eggplant.
-
2001-03-01 Ian McKellar <ian@eazel.com>
reviewed by: John "I'll review that" Harper.
diff --git a/components/text/nautilus-text-view.c b/components/text/nautilus-text-view.c
index 56453db43..e5c10cf6a 100644
--- a/components/text/nautilus-text-view.c
+++ b/components/text/nautilus-text-view.c
@@ -50,6 +50,7 @@
#include <gnome.h>
#include <gtk/gtkeventbox.h>
+#include <libgnome/gnome-i18n.h>
#include <libgnomevfs/gnome-vfs.h>
#include <ghttp.h>
@@ -184,7 +185,7 @@ nautilus_text_view_initialize (NautilusTextView *text_view)
/* FIXME: eventually, get this from preferences */
/* set up the default font */
- text_view->details->font_name = g_strdup ("helvetica");
+ text_view->details->font_name = g_strdup (_("helvetica"));
/* allocate a vbox to contain the text widget */
diff --git a/libnautilus-extensions/Makefile.am b/libnautilus-extensions/Makefile.am
index 8a828fa60..a7e22caa8 100644
--- a/libnautilus-extensions/Makefile.am
+++ b/libnautilus-extensions/Makefile.am
@@ -91,6 +91,7 @@ libnautilus_extensions_la_SOURCES = \
nautilus-file-utilities.c \
nautilus-file.c \
nautilus-font-factory.c \
+ nautilus-font-manager.c \
nautilus-font-picker.c \
nautilus-gconf-extensions.c \
nautilus-gdk-extensions.c \
@@ -206,6 +207,7 @@ noinst_HEADERS = \
nautilus-file-utilities.h \
nautilus-file.h \
nautilus-font-factory.h \
+ nautilus-font-manager.h \
nautilus-font-picker.h \
nautilus-gconf-extensions.h \
nautilus-gdk-extensions.h \
diff --git a/libnautilus-extensions/nautilus-font-factory.c b/libnautilus-extensions/nautilus-font-factory.c
index 9c1bbb637..2715ae16d 100644
--- a/libnautilus-extensions/nautilus-font-factory.c
+++ b/libnautilus-extensions/nautilus-font-factory.c
@@ -212,19 +212,33 @@ nautilus_font_factory_get_font_by_family (const char *family,
GdkFont *font;
FontHashNode *node;
char *font_name;
+ char **fontset;
+ char **iter;
g_return_val_if_fail (family != NULL, NULL);
g_return_val_if_fail (size_in_pixels > 0, NULL);
+ fontset = g_strsplit (family, ",", 5);
+ iter = fontset;
+
factory = nautilus_get_current_font_factory ();
- font_name = nautilus_gdk_font_xlfd_string_new ("*",
- family,
- "medium",
- "r",
- "normal",
- "*",
- size_in_pixels);
+ while (*iter) {
+ font_name = nautilus_gdk_font_xlfd_string_new ("*",
+ *iter,
+ "medium",
+ "r",
+ "normal",
+ "*",
+ size_in_pixels);
+ g_free (*iter);
+ *iter = font_name;
+ iter++;
+ }
+
+ font_name = g_strjoinv (",", fontset);
+ g_strfreev (fontset);
+
node = font_hash_node_lookup_with_insertion (font_name);
if (node != NULL) {
diff --git a/libnautilus-extensions/nautilus-font-manager.c b/libnautilus-extensions/nautilus-font-manager.c
new file mode 100644
index 000000000..331f58190
--- /dev/null
+++ b/libnautilus-extensions/nautilus-font-manager.c
@@ -0,0 +1,996 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+
+/* nautilus-font-manager.c - Functions for managing fonts.
+
+ Copyright (C) 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 <config.h>
+#include "nautilus-font-manager.h"
+#include "nautilus-string.h"
+#include "nautilus-string-list.h"
+#include "nautilus-lib-self-check-functions.h"
+#include "nautilus-file-utilities.h"
+
+#include <libgnome/gnome-util.h>
+#include <ctype.h>
+#include <stdio.h>
+#include <sys/stat.h>
+#include <libgnomevfs/gnome-vfs.h>
+
+#define XLFD_INDEX_FOUNDRY 1
+#define XLFD_INDEX_FAMILY 2
+#define XLFD_INDEX_WEIGHT 3
+#define XLFD_INDEX_SLANT 4
+#define XLFD_INDEX_SET_WIDTH 5
+#define XLFD_INDEX_CHAR_SET_REGISTRY 13
+#define XLFD_INDEX_CHAR_SET_ENCODING 14
+#define XLFD_INDEX_MAX XLFD_INDEX_CHAR_SET_ENCODING
+
+#define FONTS_DIR_FILE_NAME "fonts.dir"
+#define FONTS_ALIAS_FILE_NAME "fonts.alias"
+#define FONTS_SCALE_FILE_NAME "fonts.scale"
+
+typedef struct {
+ char *file_name;
+ char *foundry;
+ char *family;
+ char *weight;
+ char *slant;
+ char *set_width;
+ char *char_set_registry;
+ char *char_set_encoding;
+} FontDescription;
+
+typedef struct {
+ char *directory;
+ char *fonts_dir_file;
+ char *fonts_alias_file;
+ char *fonts_scale_file;
+ GList *descriptions;
+ GList *postscript_font_list;
+ GList *true_type_font_list;
+} FontDescriptionTable;
+
+static gboolean string_is_valid (const char *string);
+static char * file_as_string (const char *file_name);
+static gboolean directory_contains_file (const char *directory,
+ const char *file_name);
+static FontDescription * font_description_new (const char *font_file_name,
+ const char *xlfd_string);
+static void font_description_free (FontDescription *description);
+static void font_description_table_for_each (const FontDescriptionTable *description_table,
+ NautilusFontManagerIterationCallback callback,
+ gpointer callback_data);
+static char *font_description_get_file_name (const FontDescription *description);
+static char *font_description_get_foundry (const FontDescription *description);
+static char *font_description_get_family (const FontDescription *description);
+static char *font_description_get_weight (const FontDescription *description);
+static char *font_description_get_slant (const FontDescription *description);
+static char *font_description_get_set_width (const FontDescription *description);
+static char *font_description_get_char_set_registry (const FontDescription *description);
+static char *font_description_get_char_set_encoding (const FontDescription *description);
+static FontDescriptionTable * font_description_table_new (const char *font_directory);
+static void font_description_table_install_font_lists (FontDescriptionTable *table,
+ GList *postscript_font_list,
+ GList *true_type_font_list);
+static void font_description_table_add (FontDescriptionTable *description_table,
+ const char *line);
+static guint font_description_table_get_length (const FontDescriptionTable *description_table);
+static const FontDescription * font_description_table_peek_nth (const FontDescriptionTable *description_table,
+ guint n);
+static char * font_description_table_get_nth_file_name (const FontDescriptionTable *description_table,
+ guint n);
+static void font_description_table_free (FontDescriptionTable *table);
+static void font_description_table_clear (FontDescriptionTable *table);
+
+static gboolean
+string_is_valid (const char *string)
+{
+ return string && string[0] != '\0';
+}
+
+static char *
+file_as_string (const char *file_name)
+{
+ struct stat stat_info;
+ FILE *stream;
+ char *result;
+ size_t num_read;
+
+ g_return_val_if_fail (file_name != NULL, NULL);
+ g_return_val_if_fail (g_file_exists (file_name), NULL);
+
+ if (stat (file_name, &stat_info) != 0) {
+ return NULL;
+ }
+
+ if (stat_info.st_size == 0) {
+ return NULL;
+ }
+
+ stream = fopen (file_name, "r");
+
+ if (!stream) {
+ return NULL;
+ }
+
+ result = g_malloc (sizeof (char) * stat_info.st_size + 1);
+
+ num_read = fread (result, sizeof (char), stat_info.st_size, stream);
+
+ fclose (stream);
+
+ if ((ssize_t)num_read != stat_info.st_size) {
+ g_free (result);
+ return NULL;
+ }
+
+ result[stat_info.st_size] = '\0';
+
+ return result;
+}
+
+static FontDescription *
+font_description_new (const char *font_file_name,
+ const char *xlfd_string)
+{
+ FontDescription *font_description = NULL;
+ NautilusStringList *tokenized_xlfd;
+
+ g_return_val_if_fail (string_is_valid (font_file_name), NULL);
+ g_return_val_if_fail (string_is_valid (xlfd_string), NULL);
+
+ tokenized_xlfd = nautilus_string_list_new_from_tokens (xlfd_string, "-", FALSE);
+
+ if (nautilus_string_list_get_length (tokenized_xlfd) == (XLFD_INDEX_MAX + 1)) {
+ font_description = g_new0 (FontDescription, 1);
+ font_description->file_name = g_strdup (font_file_name);
+ font_description->foundry = nautilus_string_list_nth (tokenized_xlfd, XLFD_INDEX_FOUNDRY);
+ font_description->family = nautilus_string_list_nth (tokenized_xlfd, XLFD_INDEX_FAMILY);
+ font_description->weight = nautilus_string_list_nth (tokenized_xlfd, XLFD_INDEX_WEIGHT);
+ font_description->slant = nautilus_string_list_nth (tokenized_xlfd, XLFD_INDEX_SLANT);
+ font_description->set_width = nautilus_string_list_nth (tokenized_xlfd, XLFD_INDEX_SET_WIDTH);
+ font_description->char_set_registry = nautilus_string_list_nth (tokenized_xlfd, XLFD_INDEX_CHAR_SET_REGISTRY);
+ font_description->char_set_encoding = nautilus_string_list_nth (tokenized_xlfd, XLFD_INDEX_CHAR_SET_ENCODING);
+ } else {
+ g_warning ("'%s' is not a valid XLFD string", xlfd_string);
+ }
+
+ nautilus_string_list_free (tokenized_xlfd);
+
+ return font_description;
+}
+
+static void
+font_description_free (FontDescription *font_description)
+{
+ g_return_if_fail (font_description != NULL);
+
+ g_free (font_description->file_name);
+ g_free (font_description->foundry);
+ g_free (font_description->family);
+ g_free (font_description->weight);
+ g_free (font_description->slant);
+ g_free (font_description->set_width);
+ g_free (font_description->char_set_registry);
+ g_free (font_description->char_set_encoding);
+ g_free (font_description);
+}
+
+static char *
+font_description_get_file_name (const FontDescription *description)
+{
+ g_return_val_if_fail (description != NULL, NULL);
+
+ return g_strdup (description->file_name);
+}
+
+static char *
+font_description_get_foundry (const FontDescription *description)
+{
+ g_return_val_if_fail (description != NULL, NULL);
+
+ return g_strdup (description->foundry);
+}
+
+static char *
+font_description_get_family (const FontDescription *description)
+{
+ g_return_val_if_fail (description != NULL, NULL);
+
+ return g_strdup (description->family);
+}
+
+static char *
+font_description_get_weight (const FontDescription *description)
+{
+ g_return_val_if_fail (description != NULL, NULL);
+
+ return g_strdup (description->weight);
+}
+
+static char *
+font_description_get_slant (const FontDescription *description)
+{
+ g_return_val_if_fail (description != NULL, NULL);
+
+ return g_strdup (description->slant);
+}
+
+static char *
+font_description_get_set_width (const FontDescription *description)
+{
+ g_return_val_if_fail (description != NULL, NULL);
+
+ return g_strdup (description->set_width);
+}
+
+static char *
+font_description_get_char_set_registry (const FontDescription *description)
+{
+ g_return_val_if_fail (description != NULL, NULL);
+
+ return g_strdup (description->char_set_registry);
+}
+
+static char *
+font_description_get_char_set_encoding (const FontDescription *description)
+{
+ g_return_val_if_fail (description != NULL, NULL);
+
+ return g_strdup (description->char_set_encoding);
+}
+
+static void
+font_description_table_add (FontDescriptionTable *description_table,
+ const char *line)
+{
+ char *font_file_name = NULL;
+ FontDescription *description;
+ char *xlfd_delimeter;
+
+ g_return_if_fail (description_table != NULL);
+ g_return_if_fail (string_is_valid (line));
+
+ xlfd_delimeter = strstr (line, " ");
+
+ if (xlfd_delimeter == NULL) {
+ g_warning ("'%s' is not a valid font description line", line);
+ return;
+ }
+
+ font_file_name = g_strndup (line, xlfd_delimeter - line);
+
+ while (isspace ((guchar) *xlfd_delimeter)) {
+ xlfd_delimeter++;
+ }
+
+ description = font_description_new (font_file_name, xlfd_delimeter);
+
+ if (description != NULL) {
+ description_table->descriptions = g_list_append (description_table->descriptions,
+ description);
+ }
+
+ g_free (font_file_name);
+}
+
+static guint
+font_description_table_get_length (const FontDescriptionTable *description_table)
+{
+ g_return_val_if_fail (description_table != NULL, 0);
+
+ return g_list_length (description_table->descriptions);
+}
+
+static const FontDescription *
+font_description_table_peek_nth (const FontDescriptionTable *description_table,
+ guint n)
+{
+ g_return_val_if_fail (description_table != NULL, NULL);
+ g_return_val_if_fail (n < font_description_table_get_length (description_table), NULL);
+
+ return g_list_nth_data (description_table->descriptions, n);
+}
+
+static char *
+font_description_table_get_nth_file_name (const FontDescriptionTable *description_table,
+ guint n)
+{
+ const FontDescription *description;
+
+ g_return_val_if_fail (description_table != NULL, NULL);
+ g_return_val_if_fail (n < font_description_table_get_length (description_table), NULL);
+
+ description = font_description_table_peek_nth (description_table, n);
+
+ return g_strdup (description->file_name);
+}
+
+static void
+font_description_table_free (FontDescriptionTable *table)
+{
+ g_return_if_fail (table != NULL);
+
+ font_description_table_clear (table);
+ g_free (table);
+}
+
+static void
+font_description_table_clear (FontDescriptionTable *table)
+{
+ GList *node;
+
+ g_return_if_fail (table != NULL);
+
+ node = table->descriptions;
+ while (node != NULL) {
+ font_description_free (node->data);
+ node = node->next;
+ }
+
+ g_list_free (table->descriptions);
+ table->descriptions = NULL;
+
+ g_free (table->directory);
+ table->directory = NULL;
+
+ g_free (table->fonts_dir_file);
+ table->fonts_dir_file = NULL;
+
+ g_free (table->fonts_alias_file);
+ table->fonts_alias_file = NULL;
+
+ g_free (table->fonts_scale_file);
+ table->fonts_scale_file = NULL;
+}
+
+static void
+font_description_table_for_each (const FontDescriptionTable *description_table,
+ NautilusFontManagerIterationCallback callback,
+ gpointer callback_data)
+{
+ GList *node;
+ const FontDescription *description;
+
+ g_return_if_fail (description_table != NULL);
+ g_return_if_fail (callback != NULL);
+
+ node = description_table->descriptions;
+ while (node != NULL) {
+ description = node->data;
+ g_assert (node->data != NULL);
+
+ (* callback) (description->foundry,
+ description->family,
+ description->weight,
+ description->slant,
+ description->set_width,
+ description->char_set_registry,
+ description->char_set_encoding,
+ callback_data);
+
+ node = node->next;
+ }
+}
+
+static FontDescriptionTable *
+table_new_from_contents (const char *contents)
+{
+ FontDescriptionTable *description_table;
+ NautilusStringList *tokenized_contents;
+ int i;
+ int count;
+ char *line;
+
+ g_return_val_if_fail (string_is_valid (contents), NULL);
+
+ tokenized_contents = nautilus_string_list_new_from_tokens (contents, "\n", FALSE);
+
+ /* Make sure there is at least one description. Item 0 is the count */
+ if (nautilus_string_list_get_length (tokenized_contents) <= 1) {
+ nautilus_string_list_free (tokenized_contents);
+ return NULL;
+ }
+
+ /* Find out how many font entries are described in this file */
+ if (!nautilus_string_list_nth_as_integer (tokenized_contents, 0, &count)) {
+ nautilus_string_list_free (tokenized_contents);
+ return NULL;
+ }
+
+ description_table = g_new0 (FontDescriptionTable, 1);
+
+ for (i = 0; i < count; i++) {
+ line = nautilus_string_list_nth (tokenized_contents, i + 1);
+
+ if (line != NULL) {
+ font_description_table_add (description_table, line);
+ }
+
+ g_free (line);
+ }
+
+ nautilus_string_list_free (tokenized_contents);
+
+ return description_table;
+}
+
+static FontDescriptionTable *
+font_description_table_new (const char *font_directory)
+{
+ FontDescriptionTable *table;
+ char *description_file;
+ char *description_contents;
+
+ g_return_val_if_fail (string_is_valid (font_directory), NULL);
+ g_return_val_if_fail (g_file_test (font_directory, G_FILE_TEST_ISDIR), NULL);
+
+ description_file = nautilus_make_path (font_directory, FONTS_DIR_FILE_NAME);
+ description_contents = file_as_string (description_file);
+
+ if (description_contents == NULL) {
+ g_free (description_file);
+ return NULL;
+ }
+
+ table = table_new_from_contents (description_contents);
+
+ if (table != NULL) {
+ table->fonts_dir_file = nautilus_make_path (font_directory, FONTS_DIR_FILE_NAME);
+
+ /* Assign the alias file if found */
+ if (directory_contains_file (font_directory, FONTS_ALIAS_FILE_NAME)) {
+ table->fonts_alias_file = nautilus_make_path (font_directory, FONTS_ALIAS_FILE_NAME);
+ }
+
+ /* Assign the alias scale if found */
+ if (directory_contains_file (font_directory, FONTS_SCALE_FILE_NAME)) {
+ table->fonts_scale_file = nautilus_make_path (font_directory, FONTS_SCALE_FILE_NAME);
+ }
+ }
+
+ return table;
+}
+
+static void
+font_description_table_install_font_lists (FontDescriptionTable *table,
+ GList *postscript_font_list,
+ GList *true_type_font_list)
+{
+ g_return_if_fail (table != NULL);
+ g_return_if_fail (table->postscript_font_list == NULL);
+ g_return_if_fail (table->true_type_font_list == NULL);
+
+ table->postscript_font_list = postscript_font_list;
+ table->true_type_font_list = true_type_font_list;
+}
+
+static GnomeVFSResult
+collect_fonts_from_directory (const char *font_directory,
+ GList **postscript_font_list,
+ GList **true_type_font_list)
+{
+ GnomeVFSDirectoryHandle *directory;
+ GnomeVFSResult result;
+ GnomeVFSFileInfo *info;
+ char *directory_uri;
+
+ g_return_val_if_fail (string_is_valid (font_directory), GNOME_VFS_ERROR_BAD_PARAMETERS);
+ g_return_val_if_fail (postscript_font_list != NULL, GNOME_VFS_ERROR_BAD_PARAMETERS);
+ g_return_val_if_fail (true_type_font_list != NULL, GNOME_VFS_ERROR_BAD_PARAMETERS);
+
+ directory_uri = g_strconcat ("file://", font_directory, NULL);
+
+ *postscript_font_list = NULL;
+ *true_type_font_list = NULL;
+
+ result = gnome_vfs_directory_open (&directory,
+ directory_uri, GNOME_VFS_FILE_INFO_GET_MIME_TYPE, NULL);
+ g_free (directory_uri);
+
+ if (result != GNOME_VFS_OK) {
+ return result;
+ }
+
+
+ while (TRUE) {
+ info = gnome_vfs_file_info_new ();
+ result = gnome_vfs_directory_read_next (directory, info);
+ if (result == GNOME_VFS_OK) {
+ if (strcasecmp (info->mime_type, "application/x-font-type1") == 0) {
+ *postscript_font_list = g_list_prepend (*postscript_font_list,
+ g_strconcat (font_directory,
+ "/", info->name, NULL));
+ } else if (strcasecmp (info->mime_type, "application/x-font-ttf") == 0) {
+ *true_type_font_list = g_list_prepend (*true_type_font_list,
+ g_strconcat (font_directory,
+ "/", info->name, NULL));
+ }
+ }
+ gnome_vfs_file_info_unref (info);
+
+ if (result == GNOME_VFS_ERROR_EOF) {
+ break;
+ }
+ }
+
+ gnome_vfs_directory_close (directory);
+
+ return GNOME_VFS_OK;
+}
+
+
+static void
+chop_off_comments (char *line)
+{
+
+ /* Terminates a string right at the start of a comment, stripping it from the
+ * string.
+ */
+ gboolean saw_escape;
+ char *scanner;
+
+ saw_escape = FALSE;
+ for (scanner = line; *scanner != '\0'; scanner++) {
+ if (saw_escape) {
+ saw_escape = FALSE;
+ continue;
+ }
+ if (*scanner == '\\') {
+
+
+ saw_escape = TRUE;
+ continue;
+ }
+ if (*scanner == '#') {
+ *scanner = '\0';
+ break;
+ }
+ }
+}
+
+static void
+next_token (const char *buffer, int from, int *token_start, int *token_end)
+{
+ gboolean saw_escape;
+ const char *scanner;
+
+ g_assert ((int) strlen (buffer) >= from);
+
+ *token_start = -1;
+ *token_end = -1;
+
+ /* strip white space */
+ saw_escape = FALSE;
+ for (scanner = buffer + from; *scanner != '\0'; scanner++) {
+ if (saw_escape) {
+ saw_escape = FALSE;
+ continue;
+ }
+ if (*scanner == '\\') {
+ saw_escape = TRUE;
+ continue;
+ }
+ if (!isspace ((guchar) *scanner) && *scanner != '\n') {
+ *token_start = scanner - buffer;
+ break;
+ }
+ }
+
+ if (*scanner == ',') {
+ *token_end = *token_start + 1;
+ return;
+ }
+
+ /* go until token end */
+ saw_escape = FALSE;
+ for (; *scanner != '\0'; scanner++) {
+ if (saw_escape) {
+ saw_escape = FALSE;
+ continue;
+ }
+ if (*scanner == '\\') {
+ saw_escape = TRUE;
+ continue;
+ }
+ if (isspace ((guchar) *scanner) || *scanner == ',') {
+ break;
+ }
+ }
+
+ if (*token_start >= 0) {
+ *token_end = scanner - buffer;
+ }
+}
+
+#define READ_BUFFER_SIZE 2048
+
+static gboolean
+token_matches (const char *buffer, int start, int end, const char *pattern)
+{
+ if (start < 0) {
+ return FALSE;
+ }
+
+ return strncmp (buffer + start, pattern, end - start) == 0;
+}
+
+typedef enum {
+ EXPECT_CATALOGUE,
+ EXPECT_ASSIGNMENT,
+ EXPECT_DIRECTORY,
+ EXPECT_COMMA
+} FontConfigParseState;
+
+static void
+font_server_for_each_font_directory_internal (void (* callback) (const char *font_directory, gpointer callback_data),
+ gpointer callback_data,
+ char *buffer,
+ FILE *file)
+{
+ FontConfigParseState state;
+ int token_start, token_end;
+ char *font_directory;
+
+ g_return_if_fail (callback != NULL);
+ g_return_if_fail (buffer != NULL);
+ g_return_if_fail (file != NULL);
+
+ state = EXPECT_CATALOGUE;
+ while (TRUE) {
+ fgets (buffer, READ_BUFFER_SIZE, file);
+ if (strlen (buffer) == 0) {
+ if (state != EXPECT_COMMA) {
+ g_print ("unexpected file end\n");
+ }
+ break;
+ }
+
+ chop_off_comments (buffer);
+
+ token_start = 0;
+ while (TRUE) {
+ next_token (buffer, token_start, &token_start, &token_end);
+
+ if (token_start < 0) {
+ break;
+ }
+
+ switch (state) {
+ case EXPECT_CATALOGUE:
+ if (token_matches(buffer, token_start, token_end, "catalogue")) {
+ state = EXPECT_ASSIGNMENT;
+ }
+ break;
+
+ case EXPECT_ASSIGNMENT:
+ if (!token_matches(buffer, token_start, token_end, "=")) {
+ g_print (" expected token \"=\" \n");
+ return;
+ }
+ state = EXPECT_DIRECTORY;
+ break;
+
+ case EXPECT_DIRECTORY:
+ if (token_matches(buffer, token_start, token_end, ",")) {
+ g_print (" expected directory name \n");
+ return;
+ }
+ /* found a directory, call an each function on it */
+ font_directory = g_strndup (buffer + token_start, token_end - token_start);
+ (* callback) (font_directory, callback_data);
+ g_free (font_directory);
+ state = EXPECT_COMMA;
+ break;
+
+ case EXPECT_COMMA:
+ if (!token_matches(buffer, token_start, token_end, ",")) {
+ /* we are done, no more directories */
+ return;
+ }
+ state = EXPECT_DIRECTORY;
+ break;
+ }
+
+ token_start = token_end;
+ }
+ }
+}
+
+static void
+font_server_for_each_font_directory (const char *font_config_file_path,
+ void (* callback) (const char *font_directory, gpointer callback_data),
+ gpointer callback_data)
+{
+ /* scan the font config file, finding all the font directory paths */
+ FILE *font_config_file;
+ char *buffer;
+
+ g_return_if_fail (string_is_valid (font_config_file_path));
+ g_return_if_fail (callback != NULL);
+ g_return_if_fail (callback_data != NULL);
+
+ font_config_file = fopen (font_config_file_path, "r");
+
+ if (font_config_file == NULL) {
+ return;
+ }
+
+ buffer = g_malloc (READ_BUFFER_SIZE);
+ font_server_for_each_font_directory_internal (callback,
+ callback_data,
+ buffer,
+ font_config_file);
+
+ g_free (buffer);
+ fclose (font_config_file);
+}
+
+static gboolean
+directory_contains_file (const char *directory,
+ const char *file_name)
+{
+ gboolean result;
+ char *path;
+
+ g_return_val_if_fail (string_is_valid (directory), FALSE);
+ g_return_val_if_fail (string_is_valid (file_name), FALSE);
+
+ path = nautilus_make_path (directory, file_name);
+ result = g_file_exists (path);
+ g_free (path);
+
+ return result;
+}
+
+static void
+font_server_for_each_callback (const char *font_directory,
+ gpointer callback_data)
+{
+ FontDescriptionTable *table;
+
+ GList *postscript_font_list = NULL;
+ GList *true_type_font_list = NULL;
+
+ GList **collected_font_tables;
+
+ g_return_if_fail (font_directory != NULL);
+ g_return_if_fail (callback_data != NULL);
+
+ collected_font_tables = callback_data;
+
+ /* Collect postscript and true type font in this directory */
+ collect_fonts_from_directory (font_directory, &postscript_font_list, &true_type_font_list);
+
+ /* No scalable fonts found; we're done */
+ if (g_list_length (postscript_font_list) == 0
+ && g_list_length (true_type_font_list) == 0) {
+ return;
+ }
+
+ /* If no "fonts.dir" exists, then the user has a missing description file (broken setup) */
+ if (!directory_contains_file (font_directory, FONTS_DIR_FILE_NAME)) {
+ g_free (postscript_font_list);
+ g_free (true_type_font_list);
+ g_warning ("Direcotry '%s' contains scalable fonts but no '%s' description file.",
+ font_directory,
+ FONTS_DIR_FILE_NAME);
+ return;
+ }
+
+ table = font_description_table_new (font_directory);
+ g_assert (table != NULL);
+
+ font_description_table_install_font_lists (table, postscript_font_list, true_type_font_list);
+
+ *collected_font_tables = g_list_prepend (*collected_font_tables, table);
+}
+
+/* Public */
+void
+nautilus_font_manager_for_each_font (NautilusFontManagerIterationCallback callback,
+ gpointer callback_data)
+{
+ GList *collected_font_tables = NULL;
+ GList *node;
+ FontDescriptionTable *table;
+
+ g_return_if_fail (callback != NULL);
+
+ font_server_for_each_font_directory ("/etc/X11/fs/config",
+ font_server_for_each_callback,
+ &collected_font_tables);
+
+ node = collected_font_tables;
+ while (node) {
+ g_assert (node->data != NULL);
+ table = node->data;
+
+ font_description_table_for_each (table, callback, callback_data);
+ font_description_table_free (table);
+
+ node = node->next;
+ }
+
+ g_list_free (collected_font_tables);
+}
+
+
+#if !defined (NAUTILUS_OMIT_SELF_CHECK)
+
+/*
+ * The check strategy here is to create a temporary directory
+ * with a single fonts.dir inside it. We then use that to
+ * exercise the font manager.
+ */
+static const char *test_fonts_dir_content =
+"4\n"
+"n019003l.pfb -URW-Helvetica-medium-r-normal--0-0-0-0-p-0-iso8859-1\n"
+"n019004l.pfb -URW-Helvetica-bold-r-normal--0-0-0-0-p-0-iso8859-1\n"
+"n019023l.pfb -URW-Helvetica-medium-o-normal--0-0-0-0-p-0-iso8859-1\n"
+"n019024l.pfb -URW-Helvetica-bold-o-normal--0-0-0-0-p-0-iso8859-1\n"
+;
+
+static char *
+call_chop_off_comments (const char *input)
+{
+ char *test_copy;
+ test_copy = g_strdup (input);
+ chop_off_comments (test_copy);
+ return test_copy;
+}
+
+static gboolean
+write_temp_font_dot_dir_file (const char *temp_font_dir_file_name)
+{
+ FILE *stream;
+ size_t num;
+ size_t num_written;
+
+ g_return_val_if_fail (string_is_valid (temp_font_dir_file_name), FALSE);
+ g_return_val_if_fail (!g_file_exists (temp_font_dir_file_name), FALSE);
+
+ stream = fopen (temp_font_dir_file_name, "w");
+ g_return_val_if_fail (stream != NULL, FALSE);
+
+ num = strlen (test_fonts_dir_content);
+ num_written = fwrite (test_fonts_dir_content, sizeof (char), num, stream);
+ fclose (stream);
+
+ g_return_val_if_fail (num == num_written, FALSE);
+
+ return TRUE;
+}
+
+static char *
+get_unique_temp_directory (void)
+{
+ char *temp_font_directory;
+
+ temp_font_directory = nautilus_unique_temporary_file_name ();
+
+ if (temp_font_directory == NULL) {
+ return NULL;
+ }
+
+ if (g_file_test (temp_font_directory, G_FILE_TEST_ISDIR)) {
+ g_free (temp_font_directory);
+ return NULL;
+ }
+
+ mkdir (temp_font_directory, 0755);
+
+ if (!g_file_test (temp_font_directory, G_FILE_TEST_ISDIR)) {
+ g_free (temp_font_directory);
+ return NULL;
+ }
+
+ return temp_font_directory;
+}
+
+void
+nautilus_self_check_font_manager (void)
+{
+ FontDescriptionTable *table;
+ const FontDescription *description;
+
+ char *temp_font_directory;
+ char *temp_fonts_dot_dir_file;
+ char *cleanup_command;
+ gboolean temp_font_directory_ok;
+
+ temp_font_directory = get_unique_temp_directory ();
+ g_return_if_fail (string_is_valid (temp_font_directory));
+
+ temp_fonts_dot_dir_file = nautilus_make_path (temp_font_directory, FONTS_DIR_FILE_NAME);
+ temp_font_directory_ok = write_temp_font_dot_dir_file (temp_fonts_dot_dir_file);
+ g_return_if_fail (temp_font_directory_ok == TRUE);
+
+ cleanup_command = g_strdup_printf ("/bin/rm -rf %s", temp_font_directory);
+
+ table = font_description_table_new (temp_font_directory);
+
+ NAUTILUS_CHECK_INTEGER_RESULT (font_description_table_get_length (table), 4);
+ NAUTILUS_CHECK_STRING_RESULT (font_description_table_get_nth_file_name (table, 0), "n019003l.pfb");
+ NAUTILUS_CHECK_STRING_RESULT (font_description_table_get_nth_file_name (table, 1), "n019004l.pfb");
+ NAUTILUS_CHECK_STRING_RESULT (font_description_table_get_nth_file_name (table, 2), "n019023l.pfb");
+ NAUTILUS_CHECK_STRING_RESULT (font_description_table_get_nth_file_name (table, 3), "n019024l.pfb");
+
+ description = font_description_table_peek_nth (table, 0);
+ NAUTILUS_CHECK_STRING_RESULT (font_description_get_file_name (description), "n019003l.pfb");
+ NAUTILUS_CHECK_STRING_RESULT (font_description_get_foundry (description), "URW");
+ NAUTILUS_CHECK_STRING_RESULT (font_description_get_family (description), "Helvetica");
+ NAUTILUS_CHECK_STRING_RESULT (font_description_get_weight (description), "medium");
+ NAUTILUS_CHECK_STRING_RESULT (font_description_get_slant (description), "r");
+ NAUTILUS_CHECK_STRING_RESULT (font_description_get_set_width (description), "normal");
+ NAUTILUS_CHECK_STRING_RESULT (font_description_get_char_set_encoding (description), "1");
+ NAUTILUS_CHECK_STRING_RESULT (font_description_get_char_set_registry (description), "iso8859");
+
+ description = font_description_table_peek_nth (table, 1);
+ NAUTILUS_CHECK_STRING_RESULT (font_description_get_file_name (description), "n019004l.pfb");
+ NAUTILUS_CHECK_STRING_RESULT (font_description_get_foundry (description), "URW");
+ NAUTILUS_CHECK_STRING_RESULT (font_description_get_family (description), "Helvetica");
+ NAUTILUS_CHECK_STRING_RESULT (font_description_get_weight (description), "bold");
+ NAUTILUS_CHECK_STRING_RESULT (font_description_get_slant (description), "r");
+ NAUTILUS_CHECK_STRING_RESULT (font_description_get_set_width (description), "normal");
+ NAUTILUS_CHECK_STRING_RESULT (font_description_get_char_set_encoding (description), "1");
+ NAUTILUS_CHECK_STRING_RESULT (font_description_get_char_set_registry (description), "iso8859");
+
+ description = font_description_table_peek_nth (table, 2);
+ NAUTILUS_CHECK_STRING_RESULT (font_description_get_file_name (description), "n019023l.pfb");
+ NAUTILUS_CHECK_STRING_RESULT (font_description_get_foundry (description), "URW");
+ NAUTILUS_CHECK_STRING_RESULT (font_description_get_family (description), "Helvetica");
+ NAUTILUS_CHECK_STRING_RESULT (font_description_get_weight (description), "medium");
+ NAUTILUS_CHECK_STRING_RESULT (font_description_get_slant (description), "o");
+ NAUTILUS_CHECK_STRING_RESULT (font_description_get_set_width (description), "normal");
+ NAUTILUS_CHECK_STRING_RESULT (font_description_get_char_set_encoding (description), "1");
+ NAUTILUS_CHECK_STRING_RESULT (font_description_get_char_set_registry (description), "iso8859");
+
+ description = font_description_table_peek_nth (table, 3);
+ NAUTILUS_CHECK_STRING_RESULT (font_description_get_file_name (description), "n019024l.pfb");
+ NAUTILUS_CHECK_STRING_RESULT (font_description_get_foundry (description), "URW");
+ NAUTILUS_CHECK_STRING_RESULT (font_description_get_family (description), "Helvetica");
+ NAUTILUS_CHECK_STRING_RESULT (font_description_get_weight (description), "bold");
+ NAUTILUS_CHECK_STRING_RESULT (font_description_get_slant (description), "o");
+ NAUTILUS_CHECK_STRING_RESULT (font_description_get_set_width (description), "normal");
+ NAUTILUS_CHECK_STRING_RESULT (font_description_get_char_set_encoding (description), "1");
+ NAUTILUS_CHECK_STRING_RESULT (font_description_get_char_set_registry (description), "iso8859");
+
+ font_description_table_free (table);
+
+ /* chop_off_comments() */
+ NAUTILUS_CHECK_STRING_RESULT (call_chop_off_comments ("foo bar"), "foo bar");
+ NAUTILUS_CHECK_STRING_RESULT (call_chop_off_comments ("foo bar\n"), "foo bar\n");
+ NAUTILUS_CHECK_STRING_RESULT (call_chop_off_comments ("#foo bar"), "");
+ NAUTILUS_CHECK_STRING_RESULT (call_chop_off_comments ("foo bar#"), "foo bar");
+ NAUTILUS_CHECK_STRING_RESULT (call_chop_off_comments ("\\foo bar"), "\\foo bar");
+ NAUTILUS_CHECK_STRING_RESULT (call_chop_off_comments ("\\#foo bar"), "\\#foo bar");
+ NAUTILUS_CHECK_STRING_RESULT (call_chop_off_comments ("\\##foo bar"), "\\#");
+
+ system (cleanup_command);
+
+ g_free (cleanup_command);
+ g_free (temp_font_directory);
+ g_free (temp_fonts_dot_dir_file);
+}
+
+#endif /* !NAUTILUS_OMIT_SELF_CHECK */
diff --git a/libnautilus-extensions/nautilus-font-manager.h b/libnautilus-extensions/nautilus-font-manager.h
new file mode 100644
index 000000000..3204ce0fa
--- /dev/null
+++ b/libnautilus-extensions/nautilus-font-manager.h
@@ -0,0 +1,52 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+
+/* nautilus-font-manager.h - Functions for managing fonts.
+
+ Copyright (C) 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_FONT_MANAGER_H
+#define NAUTILUS_FONT_MANAGER_H
+
+#include <libgnome/gnome-defs.h>
+#include <glib.h>
+
+BEGIN_GNOME_DECLS
+
+/*
+ * A callback which can be invoked for each font available in the system.
+ */
+typedef void (*NautilusFontManagerIterationCallback) (const char *foundry,
+ const char *family,
+ const char *weight,
+ const char *slant,
+ const char *set_width,
+ const char *char_set_registry,
+ const char *char_set_encoding,
+ gpointer callback_data);
+
+void nautilus_font_manager_for_each_font (NautilusFontManagerIterationCallback callback,
+ gpointer callback_data);
+
+END_GNOME_DECLS
+
+#endif /* NAUTILUS_FONT_MANAGER_H */
+
+
diff --git a/libnautilus-extensions/nautilus-global-preferences.c b/libnautilus-extensions/nautilus-global-preferences.c
index 414e39f94..aeee8d2eb 100644
--- a/libnautilus-extensions/nautilus-global-preferences.c
+++ b/libnautilus-extensions/nautilus-global-preferences.c
@@ -264,7 +264,7 @@ global_preferences_install_defaults (void)
nautilus_preferences_default_set_string (NAUTILUS_PREFERENCES_DIRECTORY_VIEW_FONT_FAMILY,
NAUTILUS_USER_LEVEL_NOVICE,
- "helvetica");
+ _("helvetica"));
nautilus_preferences_default_set_integer (NAUTILUS_PREFERENCES_CLICK_POLICY,
NAUTILUS_USER_LEVEL_NOVICE,
@@ -522,8 +522,7 @@ global_preferences_create_dialog (void)
* Appearance
*/
appearance_pane = nautilus_preferences_box_add_pane (preference_box,
- _("Appearance"),
- _("Appearance Settings"));
+ _("Appearance"));
nautilus_preferences_pane_add_group (NAUTILUS_PREFERENCES_PANE (appearance_pane), _("Smoother Graphics"));
@@ -543,8 +542,7 @@ global_preferences_create_dialog (void)
* Windows & Desktop pane
*/
windows_and_desktop_pane = nautilus_preferences_box_add_pane (preference_box,
- _("Windows & Desktop"),
- _("Windows & Desktop Settings"));
+ _("Windows & Desktop"));
nautilus_preferences_pane_add_group (NAUTILUS_PREFERENCES_PANE (windows_and_desktop_pane), _("Desktop"));
nautilus_preferences_pane_add_item_to_nth_group (NAUTILUS_PREFERENCES_PANE (windows_and_desktop_pane),
@@ -587,8 +585,7 @@ global_preferences_create_dialog (void)
* Folder Views pane
*/
directory_views_pane = nautilus_preferences_box_add_pane (preference_box,
- _("Icon & List Views"),
- _("Icon & List Views Settings"));
+ _("Icon & List Views"));
nautilus_preferences_pane_add_group (NAUTILUS_PREFERENCES_PANE (directory_views_pane), _("Click Behavior"));
@@ -625,8 +622,7 @@ global_preferences_create_dialog (void)
* Sidebar panels pane
*/
sidebar_panels_pane = nautilus_preferences_box_add_pane (preference_box,
- _("Sidebar Panels"),
- _("Sidebar Panels Settings"));
+ _("Sidebar Panels"));
nautilus_preferences_pane_add_group (NAUTILUS_PREFERENCES_PANE (sidebar_panels_pane),
_("Tabs"));
@@ -678,8 +674,7 @@ global_preferences_create_dialog (void)
* Navigation
*/
navigation_pane = nautilus_preferences_box_add_pane (preference_box,
- _("Navigation"),
- _("Navigation Settings"));
+ _("Navigation"));
nautilus_preferences_pane_add_group (NAUTILUS_PREFERENCES_PANE (navigation_pane), _("Home"));
@@ -718,8 +713,7 @@ global_preferences_create_dialog (void)
* Tradeoffs
*/
tradeoffs_pane = nautilus_preferences_box_add_pane (preference_box,
- _("Speed Tradeoffs"),
- _("Speed Tradeoffs Settings"));
+ _("Speed Tradeoffs"));
nautilus_preferences_pane_add_group (NAUTILUS_PREFERENCES_PANE (tradeoffs_pane), _("Show Text in Icons"));
@@ -790,8 +784,7 @@ global_preferences_create_search_pane (NautilusPreferencesBox *preference_box)
* Search Settings
*/
search_pane = nautilus_preferences_box_add_pane (preference_box,
- _("Search"),
- _("Search Settings"));
+ _("Search"));
nautilus_preferences_pane_add_group (NAUTILUS_PREFERENCES_PANE (search_pane),
_("Search Complexity Options"));
nautilus_preferences_pane_add_item_to_nth_group (NAUTILUS_PREFERENCES_PANE (search_pane),
diff --git a/libnautilus-extensions/nautilus-lib-self-check-functions.h b/libnautilus-extensions/nautilus-lib-self-check-functions.h
index f1bdf9ea1..24288cbca 100644
--- a/libnautilus-extensions/nautilus-lib-self-check-functions.h
+++ b/libnautilus-extensions/nautilus-lib-self-check-functions.h
@@ -44,6 +44,7 @@ void nautilus_run_lib_self_checks (void);
macro (nautilus_self_check_enumeration) \
macro (nautilus_self_check_preferences) \
macro (nautilus_self_check_scalable_font) \
+ macro (nautilus_self_check_font_manager) \
macro (nautilus_self_check_string_map) \
macro (nautilus_self_check_art_extensions) \
macro (nautilus_self_check_gdk_pixbuf_extensions) \
diff --git a/libnautilus-extensions/nautilus-preferences-box.c b/libnautilus-extensions/nautilus-preferences-box.c
index 0bf886a03..3e5f254e8 100644
--- a/libnautilus-extensions/nautilus-preferences-box.c
+++ b/libnautilus-extensions/nautilus-preferences-box.c
@@ -336,20 +336,18 @@ nautilus_preferences_box_new (const char *box_title)
GtkWidget *
nautilus_preferences_box_add_pane (NautilusPreferencesBox *preferences_box,
- const char *pane_title,
- const char *pane_description)
+ const char *pane_title)
{
PaneInfo *info;
g_return_val_if_fail (NAUTILUS_IS_PREFERENCES_BOX (preferences_box), NULL);
g_return_val_if_fail (pane_title != NULL, NULL);
- g_return_val_if_fail (pane_description != NULL, NULL);
info = pane_info_new (pane_title);
preferences_box->details->panes = g_list_append (preferences_box->details->panes, info);
- info->pane_widget = nautilus_preferences_pane_new (pane_title, pane_description);
+ info->pane_widget = nautilus_preferences_pane_new ();
gtk_notebook_append_page (GTK_NOTEBOOK (preferences_box->details->pane_notebook),
info->pane_widget,
diff --git a/libnautilus-extensions/nautilus-preferences-box.h b/libnautilus-extensions/nautilus-preferences-box.h
index e688f1ee3..225274a57 100644
--- a/libnautilus-extensions/nautilus-preferences-box.h
+++ b/libnautilus-extensions/nautilus-preferences-box.h
@@ -60,8 +60,7 @@ struct _NautilusPreferencesBoxClass
GtkType nautilus_preferences_box_get_type (void);
GtkWidget* nautilus_preferences_box_new (const char *box_title);
GtkWidget* nautilus_preferences_box_add_pane (NautilusPreferencesBox *prefs_box,
- const char *pane_title,
- const char *pane_description);
+ const char *pane_title);
void nautilus_preferences_box_update (NautilusPreferencesBox *prefs_box);
END_GNOME_DECLS
diff --git a/libnautilus-extensions/nautilus-preferences-item.c b/libnautilus-extensions/nautilus-preferences-item.c
index df6b0a764..fad424973 100644
--- a/libnautilus-extensions/nautilus-preferences-item.c
+++ b/libnautilus-extensions/nautilus-preferences-item.c
@@ -31,6 +31,7 @@
#include "nautilus-string.h"
#include <libgnomevfs/gnome-vfs.h>
+#include <libgnome/gnome-i18n.h>
#include <gtk/gtkcheckbutton.h>
#include <gtk/gtksignal.h>
#include <gtk/gtklabel.h>
@@ -42,15 +43,6 @@
#include "nautilus-global-preferences.h"
-/* Arguments */
-enum
-{
- ARG_0,
- ARG_SHOW_DESCRIPTION,
- ARG_DESCRIPTION_STRING,
- ARG_TITLE_STRING
-};
-
static const guint PREFERENCES_ITEM_TITLE_SPACING = 4;
static const guint PREFERENCES_ITEM_FRAME_BORDER_WIDTH = 6;
static const NautilusPreferencesItemType PREFERENCES_ITEM_UNDEFINED_ITEM = -1U;
@@ -59,57 +51,46 @@ static gboolean integer_idle_handler = FALSE;
struct _NautilusPreferencesItemDetails
{
- gchar *preference_name;
- NautilusPreferencesItemType item_type;
- GtkWidget *child;
- guint change_signal_ID;
+ char *preference_name;
+ NautilusPreferencesItemType item_type;
+ GtkWidget *child;
+ guint change_signal_ID;
};
-/* 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);
+static void nautilus_preferences_item_initialize_class (NautilusPreferencesItemClass *preferences_item_class);
+static void nautilus_preferences_item_initialize (NautilusPreferencesItem *preferences_item);
+static void preferences_item_destroy (GtkObject *object);
/* Private stuff */
-static void preferences_item_construct (NautilusPreferencesItem *item,
- const gchar *preference_name,
- NautilusPreferencesItemType item_type);
-static void preferences_item_create_enum (NautilusPreferencesItem *item,
- const char *preference_name);
-static void preferences_item_create_short_enum (NautilusPreferencesItem *item,
- const char *preference_name);
-static void preferences_item_create_boolean (NautilusPreferencesItem *item,
- const char *preference_name);
-static void preferences_item_create_editable_string (NautilusPreferencesItem *item,
- const char *preference_name);
-static void preferences_item_create_integer (NautilusPreferencesItem *item,
- const char *preference_name);
-static void preferences_item_create_font_family (NautilusPreferencesItem *item,
- const char *preference_name);
-static void preferences_item_create_theme (NautilusPreferencesItem *item,
- const char *preference_name);
-static void preferences_item_update_text_settings_at_idle (NautilusPreferencesItem *preferences_item);
-static void preferences_item_update_integer_settings_at_idle (NautilusPreferencesItem *preferences_item);
-static void enum_radio_group_changed_callback (GtkWidget *button_group,
- GtkWidget *button,
- gpointer user_data);
-static void boolean_button_toggled_callback (GtkWidget *button_group,
- gpointer user_data);
-static void text_item_changed_callback (GtkWidget *string_picker,
- gpointer user_data);
-static void editable_string_changed_callback (GtkWidget *caption,
- gpointer user_data);
-static void integer_changed_callback (GtkWidget *caption,
- gpointer user_data);
+static void preferences_item_construct (NautilusPreferencesItem *item,
+ const char *preference_name,
+ NautilusPreferencesItemType item_type);
+static void preferences_item_create_enum (NautilusPreferencesItem *item,
+ const char *preference_name);
+static void preferences_item_create_short_enum (NautilusPreferencesItem *item,
+ const char *preference_name);
+static void preferences_item_create_boolean (NautilusPreferencesItem *item,
+ const char *preference_name);
+static void preferences_item_create_editable_string (NautilusPreferencesItem *item,
+ const char *preference_name);
+static void preferences_item_create_integer (NautilusPreferencesItem *item,
+ const char *preference_name);
+static void preferences_item_create_font_family (NautilusPreferencesItem *item,
+ const char *preference_name);
+static void preferences_item_update_text_settings_at_idle (NautilusPreferencesItem *preferences_item);
+static void preferences_item_update_integer_settings_at_idle (NautilusPreferencesItem *preferences_item);
+static void enum_radio_group_changed_callback (GtkWidget *button_group,
+ GtkWidget *button,
+ gpointer user_data);
+static void boolean_button_toggled_callback (GtkWidget *button_group,
+ gpointer user_data);
+static void text_item_changed_callback (GtkWidget *string_picker,
+ gpointer user_data);
+static void editable_string_changed_callback (GtkWidget *caption,
+ gpointer user_data);
+static void integer_changed_callback (GtkWidget *caption,
+ gpointer user_data);
NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusPreferencesItem, nautilus_preferences_item, GTK_TYPE_VBOX)
@@ -125,36 +106,15 @@ nautilus_preferences_item_initialize_class (NautilusPreferencesItemClass *prefer
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;
}
static void
nautilus_preferences_item_initialize (NautilusPreferencesItem *item)
{
- item->details = g_new (NautilusPreferencesItemDetails, 1);
-
- item->details->preference_name = NULL;
+ item->details = g_new0 (NautilusPreferencesItemDetails, 1);
item->details->item_type = PREFERENCES_ITEM_UNDEFINED_ITEM;
- item->details->child = NULL;
}
/* GtkObjectClass methods */
@@ -163,89 +123,15 @@ 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->preference_name)
- {
- g_free (item->details->preference_name);
- }
-
+ g_free (item->details->preference_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
+ /* Chain destroy */
+ NAUTILUS_CALL_PARENT (GTK_OBJECT_CLASS, destroy, (object));
}
/*
@@ -253,12 +139,12 @@ preferences_item_get_arg (GtkObject *object,
*/
static void
preferences_item_construct (NautilusPreferencesItem *item,
- const gchar *preference_name,
+ const char *preference_name,
NautilusPreferencesItemType item_type)
{
- g_assert (item != NULL);
+ g_return_if_fail (NAUTILUS_IS_PREFERENCES_ITEM (item));
- g_assert (preference_name != NULL);
+ g_return_if_fail (nautilus_strlen (preference_name) > 0);
g_assert (item_type != PREFERENCES_ITEM_UNDEFINED_ITEM);
g_assert (item->details->child == NULL);
@@ -287,12 +173,10 @@ preferences_item_construct (NautilusPreferencesItem *item,
preferences_item_create_font_family (item, preference_name);
break;
- case NAUTILUS_PREFERENCE_ITEM_THEME:
- preferences_item_create_theme (item, preference_name);
- break;
case NAUTILUS_PREFERENCE_ITEM_EDITABLE_STRING:
preferences_item_create_editable_string (item, preference_name);
break;
+
case NAUTILUS_PREFERENCE_ITEM_INTEGER:
preferences_item_create_integer (item, preference_name);
break;
@@ -315,12 +199,12 @@ preferences_item_construct (NautilusPreferencesItem *item,
static void
preferences_item_update_enum (const NautilusPreferencesItem *item)
{
- gint value;
+ int value;
char *preference_name;
guint i;
- g_assert (NAUTILUS_IS_PREFERENCES_ITEM (item));
- g_assert (item->details->item_type == NAUTILUS_PREFERENCE_ITEM_ENUM);
+ g_return_if_fail (NAUTILUS_IS_PREFERENCES_ITEM (item));
+ g_return_if_fail (item->details->item_type == NAUTILUS_PREFERENCE_ITEM_ENUM);
preference_name = item->details->preference_name;
value = nautilus_preferences_get_integer (preference_name);
@@ -338,8 +222,8 @@ preferences_item_create_enum (NautilusPreferencesItem *item,
{
guint i;
- g_assert (item != NULL);
- g_assert (preference_name != NULL);
+ g_return_if_fail (NAUTILUS_IS_PREFERENCES_ITEM (item));
+ g_return_if_fail (nautilus_strlen (preference_name) > 0);
g_assert (item->details->preference_name != NULL);
@@ -368,12 +252,12 @@ preferences_item_create_enum (NautilusPreferencesItem *item,
static void
preferences_item_update_short_enum (const NautilusPreferencesItem *item)
{
- gint value;
+ int value;
char *preference_name;
guint i;
- g_assert (NAUTILUS_IS_PREFERENCES_ITEM (item));
- g_assert (item->details->item_type == NAUTILUS_PREFERENCE_ITEM_SHORT_ENUM);
+ g_return_if_fail (NAUTILUS_IS_PREFERENCES_ITEM (item));
+ g_return_if_fail (item->details->item_type == NAUTILUS_PREFERENCE_ITEM_SHORT_ENUM);
preference_name = item->details->preference_name;
value = nautilus_preferences_get_integer (preference_name);
@@ -395,8 +279,8 @@ preferences_item_create_short_enum (NautilusPreferencesItem *item,
{
guint i;
- g_assert (item != NULL);
- g_assert (preference_name != NULL);
+ g_return_if_fail (NAUTILUS_IS_PREFERENCES_ITEM (item));
+ g_return_if_fail (nautilus_strlen (preference_name) > 0);
g_assert (item->details->preference_name != NULL);
@@ -427,8 +311,8 @@ preferences_item_update_boolean (const NautilusPreferencesItem *item)
{
gboolean value;
- g_assert (NAUTILUS_IS_PREFERENCES_ITEM (item));
- g_assert (item->details->item_type == NAUTILUS_PREFERENCE_ITEM_BOOLEAN);
+ g_return_if_fail (NAUTILUS_IS_PREFERENCES_ITEM (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);
@@ -440,8 +324,8 @@ preferences_item_create_boolean (NautilusPreferencesItem *item,
{
char *description;
- g_assert (NAUTILUS_IS_PREFERENCES_ITEM (item));
- g_assert (preference_name != NULL);
+ g_return_if_fail (NAUTILUS_IS_PREFERENCES_ITEM (item));
+ g_return_if_fail (nautilus_strlen (preference_name) > 0);
g_assert (item->details->preference_name != NULL);
description = nautilus_preferences_get_description (preference_name);
@@ -465,8 +349,8 @@ preferences_item_update_editable_string (const NautilusPreferencesItem *item)
{
char *current_value;
- g_assert (NAUTILUS_IS_PREFERENCES_ITEM (item));
- g_assert (item->details->item_type == NAUTILUS_PREFERENCE_ITEM_EDITABLE_STRING);
+ g_return_if_fail (NAUTILUS_IS_PREFERENCES_ITEM (item));
+ g_return_if_fail (item->details->item_type == NAUTILUS_PREFERENCE_ITEM_EDITABLE_STRING);
current_value = nautilus_preferences_get (item->details->preference_name);
@@ -481,12 +365,10 @@ preferences_item_create_editable_string (NautilusPreferencesItem *item,
{
char *description;
- g_assert (item != NULL);
- g_assert (preference_name != NULL);
+ g_return_if_fail (NAUTILUS_IS_PREFERENCES_ITEM (item));
+ g_return_if_fail (nautilus_strlen (preference_name) > 0);
- g_assert (item->details->preference_name != NULL);
description = nautilus_preferences_get_description (preference_name);
-
g_assert (description != NULL);
item->details->child = nautilus_text_caption_new ();
@@ -514,8 +396,8 @@ preferences_item_update_integer (const NautilusPreferencesItem *item)
{
char *current_value;
- g_assert (NAUTILUS_IS_PREFERENCES_ITEM (item));
- g_assert (item->details->item_type == NAUTILUS_PREFERENCE_ITEM_INTEGER);
+ g_return_if_fail (NAUTILUS_IS_PREFERENCES_ITEM (item));
+ g_return_if_fail (item->details->item_type == NAUTILUS_PREFERENCE_ITEM_INTEGER);
current_value = g_strdup_printf ("%d", nautilus_preferences_get_integer (item->details->preference_name));
@@ -530,10 +412,9 @@ preferences_item_create_integer (NautilusPreferencesItem *item,
{
char *description;
- g_assert (item != NULL);
- g_assert (preference_name != NULL);
+ g_return_if_fail (NAUTILUS_IS_PREFERENCES_ITEM (item));
+ g_return_if_fail (nautilus_strlen (preference_name) > 0);
- g_assert (item->details->preference_name != NULL);
description = nautilus_preferences_get_description (preference_name);
g_assert (description != NULL);
@@ -556,11 +437,10 @@ preferences_item_update_font_family (const NautilusPreferencesItem *item)
{
char *current_value;
- g_assert (NAUTILUS_IS_PREFERENCES_ITEM (item));
- g_assert (item->details->item_type == NAUTILUS_PREFERENCE_ITEM_FONT_FAMILY);
+ g_return_if_fail (NAUTILUS_IS_PREFERENCES_ITEM (item));
+ g_return_if_fail (item->details->item_type == NAUTILUS_PREFERENCE_ITEM_FONT_FAMILY);
current_value = nautilus_preferences_get (item->details->preference_name);
-
g_assert (current_value != NULL);
nautilus_string_picker_set_selected_string (NAUTILUS_STRING_PICKER (item->details->child), current_value);
@@ -569,22 +449,19 @@ preferences_item_update_font_family (const NautilusPreferencesItem *item)
}
static void
-preferences_item_create_font_family (NautilusPreferencesItem *item,
- const char *preference_name)
+preferences_item_create_font_family (NautilusPreferencesItem *item,
+ const char *preference_name)
{
- char *description;
- NautilusStringList *font_list;
+ char *description;
+ NautilusStringList *font_list;
- g_assert (item != NULL);
- g_assert (preference_name != NULL);
+ g_return_if_fail (NAUTILUS_IS_PREFERENCES_ITEM (item));
+ g_return_if_fail (nautilus_strlen (preference_name) > 0);
- g_assert (item->details->preference_name != NULL);
description = nautilus_preferences_get_description (preference_name);
-
- g_assert (description != NULL);
-
+ g_return_if_fail (description != NULL);
+
item->details->child = nautilus_string_picker_new ();
-
nautilus_caption_set_title_label (NAUTILUS_CAPTION (item->details->child), description);
g_free (description);
@@ -592,153 +469,23 @@ preferences_item_create_font_family (NautilusPreferencesItem *item,
/* FIXME bugzilla.eazel.com 1274: Need to query system for available fonts */
font_list = nautilus_string_list_new (TRUE);
- nautilus_string_list_insert (font_list, "helvetica");
- nautilus_string_list_insert (font_list, "times");
- nautilus_string_list_insert (font_list, "courier");
- nautilus_string_list_insert (font_list, "lucida");
+ nautilus_string_list_insert (font_list, _("helvetica"));
+ nautilus_string_list_insert (font_list, _("times"));
+ nautilus_string_list_insert (font_list, _("courier"));
+ nautilus_string_list_insert (font_list, _("lucida"));
nautilus_string_picker_set_string_list (NAUTILUS_STRING_PICKER (item->details->child), font_list);
nautilus_string_list_free (font_list);
- item->details->change_signal_ID =
- gtk_signal_connect (GTK_OBJECT (item->details->child),
- "changed",
- GTK_SIGNAL_FUNC (text_item_changed_callback),
- (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_string;
- guint index;
- gboolean result;
- GnomeVFSURI *base_uri, *uri;
-
- temp_str = nautilus_make_path (directory_uri, dir_name);
- base_uri_string = nautilus_make_path (temp_str, required_file);
- base_uri = gnome_vfs_uri_new (base_uri_string);
- g_free (temp_str);
- g_free (base_uri_string);
-
- result = FALSE;
- for (index = 0; index < NAUTILUS_N_ELEMENTS (icon_file_name_suffixes); index++) {
- uri = gnome_vfs_uri_append_string (base_uri, icon_file_name_suffixes[index]);
- result = gnome_vfs_uri_exists (uri);
- gnome_vfs_uri_unref (uri);
- if (result) {
- break;
- }
- }
-
- gnome_vfs_uri_unref (base_uri);
- g_free (base_uri);
- return result;
-}
-
-/* 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, char *required_file)
-{
- char *directory_uri;
- GnomeVFSResult result;
- GnomeVFSFileInfo *current_file_info;
- GList *list, *element;
- char *pixmap_directory;
-
- pixmap_directory = nautilus_get_pixmap_directory ();
-
- /* get the uri for the images directory */
- directory_uri = gnome_vfs_get_uri_from_local_path (pixmap_directory);
- g_free (pixmap_directory);
-
- result = gnome_vfs_directory_list_load (&list, directory_uri,
- GNOME_VFS_FILE_INFO_DEFAULT, NULL);
- if (result != GNOME_VFS_OK) {
- g_free(directory_uri);
- return;
- }
-
- /* interate through the directory for each file */
- for (element = list; element != NULL; element = element->next) {
- current_file_info = element->data;
- if ((current_file_info->type == GNOME_VFS_FILE_TYPE_DIRECTORY) &&
- (current_file_info->name[0] != '.')) {
- if (has_image_file(directory_uri, current_file_info->name, required_file))
- nautilus_string_list_insert (theme_list, current_file_info->name);
- }
- }
-
- g_free(directory_uri);
- gnome_vfs_file_info_list_free (list);
-}
-
-static void
-preferences_item_update_theme (const NautilusPreferencesItem *item)
-{
- char *current_value;
-
- g_assert (NAUTILUS_IS_PREFERENCES_ITEM (item));
- g_assert (item->details->item_type == NAUTILUS_PREFERENCE_ITEM_THEME);
-
- current_value = nautilus_preferences_get (item->details->preference_name);
-
- g_assert (current_value != NULL);
-
- nautilus_string_picker_set_selected_string (NAUTILUS_STRING_PICKER (item->details->child), current_value);
-
- g_free (current_value);
-}
-
-static void
-preferences_item_create_theme (NautilusPreferencesItem *item,
- const char *preference_name)
-{
- char *description;
- NautilusStringList *theme_list;
-
- g_assert (item != NULL);
- g_assert (preference_name != NULL);
-
- g_assert (item->details->preference_name != NULL);
- description = nautilus_preferences_get_description (preference_name);
-
- g_assert (description != NULL);
-
- item->details->child = nautilus_string_picker_new ();
-
- nautilus_caption_set_title_label (NAUTILUS_CAPTION (item->details->child), description);
-
- g_free (description);
-
- theme_list = nautilus_string_list_new (TRUE);
- nautilus_string_list_insert (theme_list, "default");
- add_icon_themes(theme_list, "i-directory");
-
- nautilus_string_picker_set_string_list (NAUTILUS_STRING_PICKER (item->details->child), theme_list);
- nautilus_string_list_free (theme_list);
-
- item->details->change_signal_ID =
- gtk_signal_connect (GTK_OBJECT (item->details->child),
- "changed",
- GTK_SIGNAL_FUNC (text_item_changed_callback),
- (gpointer) item);
+ item->details->change_signal_ID = 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,
+nautilus_preferences_item_new (const char *preference_name,
NautilusPreferencesItemType item_type)
{
NautilusPreferencesItem * item;
@@ -759,7 +506,7 @@ static void
enum_radio_group_changed_callback (GtkWidget *buttons, GtkWidget * button, gpointer user_data)
{
NautilusPreferencesItem *item;
- gint i;
+ int i;
g_assert (user_data != NULL);
g_assert (NAUTILUS_IS_PREFERENCES_ITEM (user_data));
@@ -771,7 +518,7 @@ enum_radio_group_changed_callback (GtkWidget *buttons, GtkWidget * button, gpoin
i = nautilus_radio_button_group_get_active_index (NAUTILUS_RADIO_BUTTON_GROUP (buttons));
nautilus_preferences_set_integer (item->details->preference_name,
- nautilus_preferences_enumeration_get_nth_value (item->details->preference_name, i));
+ nautilus_preferences_enumeration_get_nth_value (item->details->preference_name, i));
}
static void
@@ -882,12 +629,10 @@ nautilus_preferences_item_update_displayed_value (const NautilusPreferencesItem
preferences_item_update_font_family (item);
break;
- case NAUTILUS_PREFERENCE_ITEM_THEME:
- preferences_item_update_theme (item);
- break;
case NAUTILUS_PREFERENCE_ITEM_EDITABLE_STRING:
preferences_item_update_editable_string (item);
break;
+
case NAUTILUS_PREFERENCE_ITEM_INTEGER:
preferences_item_update_integer (item);
break;
@@ -906,10 +651,8 @@ update_text_settings_at_idle (NautilusPreferencesItem *preferences_item)
text = nautilus_text_caption_get_text (NAUTILUS_TEXT_CAPTION (preferences_item->details->child));
- if (text != NULL)
- {
+ if (text != NULL) {
nautilus_preferences_set (preferences_item->details->preference_name, text);
-
g_free (text);
}
diff --git a/libnautilus-extensions/nautilus-preferences-item.h b/libnautilus-extensions/nautilus-preferences-item.h
index c9c950371..11fba2436 100644
--- a/libnautilus-extensions/nautilus-preferences-item.h
+++ b/libnautilus-extensions/nautilus-preferences-item.h
@@ -67,16 +67,15 @@ typedef enum
NAUTILUS_PREFERENCE_ITEM_ENUM,
NAUTILUS_PREFERENCE_ITEM_SHORT_ENUM,
NAUTILUS_PREFERENCE_ITEM_FONT_FAMILY,
- NAUTILUS_PREFERENCE_ITEM_THEME,
NAUTILUS_PREFERENCE_ITEM_EDITABLE_STRING,
NAUTILUS_PREFERENCE_ITEM_INTEGER
} NautilusPreferencesItemType;
-GtkType nautilus_preferences_item_get_type (void);
-GtkWidget* nautilus_preferences_item_new (const gchar *preference_name,
- NautilusPreferencesItemType item_type);
-char * nautilus_preferences_item_get_name (const NautilusPreferencesItem *preferences_item);
-void nautilus_preferences_item_update_displayed_value (const NautilusPreferencesItem *preferences_item);
+GtkType nautilus_preferences_item_get_type (void);
+GtkWidget* nautilus_preferences_item_new (const char *preference_name,
+ NautilusPreferencesItemType item_type);
+char * nautilus_preferences_item_get_name (const NautilusPreferencesItem *preferences_item);
+void nautilus_preferences_item_update_displayed_value (const NautilusPreferencesItem *preferences_item);
END_GNOME_DECLS
diff --git a/libnautilus-extensions/nautilus-preferences-pane.c b/libnautilus-extensions/nautilus-preferences-pane.c
index 8d76cef98..f425e0194 100644
--- a/libnautilus-extensions/nautilus-preferences-pane.c
+++ b/libnautilus-extensions/nautilus-preferences-pane.c
@@ -90,14 +90,10 @@ nautilus_preferences_pane_destroy (GtkObject* object)
* NautilusPreferencesPane public methods
*/
GtkWidget *
-nautilus_preferences_pane_new (const gchar *pane_title,
- const gchar *pane_description)
+nautilus_preferences_pane_new (void)
{
NautilusPreferencesPane *preferences_pane;
- g_return_val_if_fail (pane_title != NULL, NULL);
- g_return_val_if_fail (pane_description != NULL, NULL);
-
preferences_pane = NAUTILUS_PREFERENCES_PANE
(gtk_widget_new (nautilus_preferences_pane_get_type (), NULL));
diff --git a/libnautilus-extensions/nautilus-preferences-pane.h b/libnautilus-extensions/nautilus-preferences-pane.h
index c1071a470..0b0fc3702 100644
--- a/libnautilus-extensions/nautilus-preferences-pane.h
+++ b/libnautilus-extensions/nautilus-preferences-pane.h
@@ -56,8 +56,7 @@ struct _NautilusPreferencesPaneClass
};
GtkType nautilus_preferences_pane_get_type (void);
-GtkWidget* nautilus_preferences_pane_new (const gchar *pane_title,
- const gchar *pane_description);
+GtkWidget* nautilus_preferences_pane_new (void);
GtkWidget *nautilus_preferences_pane_add_group (NautilusPreferencesPane *preferences_pane,
const char *group_title);
GtkWidget *nautilus_preferences_pane_add_item_to_nth_group (NautilusPreferencesPane *preferences_pane,
diff --git a/libnautilus-extensions/nautilus-string-list.c b/libnautilus-extensions/nautilus-string-list.c
index 9a2fd5f92..084d84085 100644
--- a/libnautilus-extensions/nautilus-string-list.c
+++ b/libnautilus-extensions/nautilus-string-list.c
@@ -212,6 +212,39 @@ nautilus_string_list_nth (const NautilusStringList *string_list, guint n)
}
/**
+ * nautilus_string_list_nth_as_integer
+ *
+ * @string_list: A NautilusStringList
+ * @n: Index of string to convert.
+ * @integer_result: Where to store the conversion result.
+ *
+ * Convert the nth string to an integer and store the result in &integer_result.
+ *
+ * Return value: Returns TRUE if the string to integer conversion was successful,
+ * FALSE otherwise.
+ */
+gboolean
+nautilus_string_list_nth_as_integer (const NautilusStringList *string_list,
+ guint n,
+ int *integer_result)
+{
+ const char *string;
+
+ g_return_val_if_fail (string_list != NULL, FALSE);
+ g_return_val_if_fail (integer_result != NULL, FALSE);
+
+ if (n >= g_list_length (string_list->strings)) {
+ if (!supress_out_of_bounds_warning) {
+ g_warning ("(n = %d) is out of bounds.", n);
+ }
+ return FALSE;
+ }
+
+ string = g_list_nth_data (string_list->strings, n);
+ return nautilus_str_to_int (string, integer_result);
+}
+
+/**
* nautilus_string_list_modify_nth
*
* @string_list: A NautilusStringList
@@ -1140,6 +1173,51 @@ nautilus_self_check_string_list (void)
nautilus_string_list_free (list);
nautilus_string_list_free (sorted_list);
}
+
+ /*
+ * nautilus_string_list_nth_as_integer
+ */
+ {
+ NautilusStringList *list;
+ const int untouched = 666;
+ int result;
+
+ list = nautilus_string_list_new_from_tokens ("word,c,0,1,20,xxx,foo,bar,-1", ",", TRUE);
+
+ result = untouched;
+ NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_string_list_nth_as_integer (list, 0, &result), FALSE);
+ NAUTILUS_CHECK_INTEGER_RESULT (result, untouched);
+
+ result = untouched;
+ NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_string_list_nth_as_integer (list, 1, &result), FALSE);
+ NAUTILUS_CHECK_INTEGER_RESULT (result, untouched);
+
+ result = untouched;
+ NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_string_list_nth_as_integer (list, 5, &result), FALSE);
+ NAUTILUS_CHECK_INTEGER_RESULT (result, untouched);
+
+ result = untouched;
+ NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_string_list_nth_as_integer (list, 6, &result), FALSE);
+ NAUTILUS_CHECK_INTEGER_RESULT (result, untouched);
+
+ result = untouched;
+ NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_string_list_nth_as_integer (list, 7, &result), FALSE);
+ NAUTILUS_CHECK_INTEGER_RESULT (result, untouched);
+
+ NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_string_list_nth_as_integer (list, 2, &result), TRUE);
+ NAUTILUS_CHECK_INTEGER_RESULT (result, 0);
+
+ NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_string_list_nth_as_integer (list, 3, &result), TRUE);
+ NAUTILUS_CHECK_INTEGER_RESULT (result, 1);
+
+ NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_string_list_nth_as_integer (list, 4, &result), TRUE);
+ NAUTILUS_CHECK_INTEGER_RESULT (result, 20);
+
+ NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_string_list_nth_as_integer (list, 8, &result), TRUE);
+ NAUTILUS_CHECK_INTEGER_RESULT (result, -1);
+
+ nautilus_string_list_free (list);
+ }
}
#endif /* !NAUTILUS_OMIT_SELF_CHECK */
diff --git a/libnautilus-extensions/nautilus-string-list.h b/libnautilus-extensions/nautilus-string-list.h
index 9c3816787..3bfd14a8c 100644
--- a/libnautilus-extensions/nautilus-string-list.h
+++ b/libnautilus-extensions/nautilus-string-list.h
@@ -68,6 +68,10 @@ void nautilus_string_list_clear (NautilusStri
/* Access the nth string in the collection. Returns an strduped string. */
char * nautilus_string_list_nth (const NautilusStringList *string_list,
guint n);
+/* Access the nth string as an integer. Return TRUE if the conversion was successful. */
+gboolean nautilus_string_list_nth_as_integer (const NautilusStringList *string_list,
+ guint n,
+ int *integer_result);
/* Modify the nth string in the collection. */
void nautilus_string_list_modify_nth (NautilusStringList *string_list,
guint n,
diff --git a/libnautilus-private/Makefile.am b/libnautilus-private/Makefile.am
index 8a828fa60..a7e22caa8 100644
--- a/libnautilus-private/Makefile.am
+++ b/libnautilus-private/Makefile.am
@@ -91,6 +91,7 @@ libnautilus_extensions_la_SOURCES = \
nautilus-file-utilities.c \
nautilus-file.c \
nautilus-font-factory.c \
+ nautilus-font-manager.c \
nautilus-font-picker.c \
nautilus-gconf-extensions.c \
nautilus-gdk-extensions.c \
@@ -206,6 +207,7 @@ noinst_HEADERS = \
nautilus-file-utilities.h \
nautilus-file.h \
nautilus-font-factory.h \
+ nautilus-font-manager.h \
nautilus-font-picker.h \
nautilus-gconf-extensions.h \
nautilus-gdk-extensions.h \
diff --git a/libnautilus-private/nautilus-font-factory.c b/libnautilus-private/nautilus-font-factory.c
index 9c1bbb637..2715ae16d 100644
--- a/libnautilus-private/nautilus-font-factory.c
+++ b/libnautilus-private/nautilus-font-factory.c
@@ -212,19 +212,33 @@ nautilus_font_factory_get_font_by_family (const char *family,
GdkFont *font;
FontHashNode *node;
char *font_name;
+ char **fontset;
+ char **iter;
g_return_val_if_fail (family != NULL, NULL);
g_return_val_if_fail (size_in_pixels > 0, NULL);
+ fontset = g_strsplit (family, ",", 5);
+ iter = fontset;
+
factory = nautilus_get_current_font_factory ();
- font_name = nautilus_gdk_font_xlfd_string_new ("*",
- family,
- "medium",
- "r",
- "normal",
- "*",
- size_in_pixels);
+ while (*iter) {
+ font_name = nautilus_gdk_font_xlfd_string_new ("*",
+ *iter,
+ "medium",
+ "r",
+ "normal",
+ "*",
+ size_in_pixels);
+ g_free (*iter);
+ *iter = font_name;
+ iter++;
+ }
+
+ font_name = g_strjoinv (",", fontset);
+ g_strfreev (fontset);
+
node = font_hash_node_lookup_with_insertion (font_name);
if (node != NULL) {
diff --git a/libnautilus-private/nautilus-font-manager.c b/libnautilus-private/nautilus-font-manager.c
new file mode 100644
index 000000000..331f58190
--- /dev/null
+++ b/libnautilus-private/nautilus-font-manager.c
@@ -0,0 +1,996 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+
+/* nautilus-font-manager.c - Functions for managing fonts.
+
+ Copyright (C) 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 <config.h>
+#include "nautilus-font-manager.h"
+#include "nautilus-string.h"
+#include "nautilus-string-list.h"
+#include "nautilus-lib-self-check-functions.h"
+#include "nautilus-file-utilities.h"
+
+#include <libgnome/gnome-util.h>
+#include <ctype.h>
+#include <stdio.h>
+#include <sys/stat.h>
+#include <libgnomevfs/gnome-vfs.h>
+
+#define XLFD_INDEX_FOUNDRY 1
+#define XLFD_INDEX_FAMILY 2
+#define XLFD_INDEX_WEIGHT 3
+#define XLFD_INDEX_SLANT 4
+#define XLFD_INDEX_SET_WIDTH 5
+#define XLFD_INDEX_CHAR_SET_REGISTRY 13
+#define XLFD_INDEX_CHAR_SET_ENCODING 14
+#define XLFD_INDEX_MAX XLFD_INDEX_CHAR_SET_ENCODING
+
+#define FONTS_DIR_FILE_NAME "fonts.dir"
+#define FONTS_ALIAS_FILE_NAME "fonts.alias"
+#define FONTS_SCALE_FILE_NAME "fonts.scale"
+
+typedef struct {
+ char *file_name;
+ char *foundry;
+ char *family;
+ char *weight;
+ char *slant;
+ char *set_width;
+ char *char_set_registry;
+ char *char_set_encoding;
+} FontDescription;
+
+typedef struct {
+ char *directory;
+ char *fonts_dir_file;
+ char *fonts_alias_file;
+ char *fonts_scale_file;
+ GList *descriptions;
+ GList *postscript_font_list;
+ GList *true_type_font_list;
+} FontDescriptionTable;
+
+static gboolean string_is_valid (const char *string);
+static char * file_as_string (const char *file_name);
+static gboolean directory_contains_file (const char *directory,
+ const char *file_name);
+static FontDescription * font_description_new (const char *font_file_name,
+ const char *xlfd_string);
+static void font_description_free (FontDescription *description);
+static void font_description_table_for_each (const FontDescriptionTable *description_table,
+ NautilusFontManagerIterationCallback callback,
+ gpointer callback_data);
+static char *font_description_get_file_name (const FontDescription *description);
+static char *font_description_get_foundry (const FontDescription *description);
+static char *font_description_get_family (const FontDescription *description);
+static char *font_description_get_weight (const FontDescription *description);
+static char *font_description_get_slant (const FontDescription *description);
+static char *font_description_get_set_width (const FontDescription *description);
+static char *font_description_get_char_set_registry (const FontDescription *description);
+static char *font_description_get_char_set_encoding (const FontDescription *description);
+static FontDescriptionTable * font_description_table_new (const char *font_directory);
+static void font_description_table_install_font_lists (FontDescriptionTable *table,
+ GList *postscript_font_list,
+ GList *true_type_font_list);
+static void font_description_table_add (FontDescriptionTable *description_table,
+ const char *line);
+static guint font_description_table_get_length (const FontDescriptionTable *description_table);
+static const FontDescription * font_description_table_peek_nth (const FontDescriptionTable *description_table,
+ guint n);
+static char * font_description_table_get_nth_file_name (const FontDescriptionTable *description_table,
+ guint n);
+static void font_description_table_free (FontDescriptionTable *table);
+static void font_description_table_clear (FontDescriptionTable *table);
+
+static gboolean
+string_is_valid (const char *string)
+{
+ return string && string[0] != '\0';
+}
+
+static char *
+file_as_string (const char *file_name)
+{
+ struct stat stat_info;
+ FILE *stream;
+ char *result;
+ size_t num_read;
+
+ g_return_val_if_fail (file_name != NULL, NULL);
+ g_return_val_if_fail (g_file_exists (file_name), NULL);
+
+ if (stat (file_name, &stat_info) != 0) {
+ return NULL;
+ }
+
+ if (stat_info.st_size == 0) {
+ return NULL;
+ }
+
+ stream = fopen (file_name, "r");
+
+ if (!stream) {
+ return NULL;
+ }
+
+ result = g_malloc (sizeof (char) * stat_info.st_size + 1);
+
+ num_read = fread (result, sizeof (char), stat_info.st_size, stream);
+
+ fclose (stream);
+
+ if ((ssize_t)num_read != stat_info.st_size) {
+ g_free (result);
+ return NULL;
+ }
+
+ result[stat_info.st_size] = '\0';
+
+ return result;
+}
+
+static FontDescription *
+font_description_new (const char *font_file_name,
+ const char *xlfd_string)
+{
+ FontDescription *font_description = NULL;
+ NautilusStringList *tokenized_xlfd;
+
+ g_return_val_if_fail (string_is_valid (font_file_name), NULL);
+ g_return_val_if_fail (string_is_valid (xlfd_string), NULL);
+
+ tokenized_xlfd = nautilus_string_list_new_from_tokens (xlfd_string, "-", FALSE);
+
+ if (nautilus_string_list_get_length (tokenized_xlfd) == (XLFD_INDEX_MAX + 1)) {
+ font_description = g_new0 (FontDescription, 1);
+ font_description->file_name = g_strdup (font_file_name);
+ font_description->foundry = nautilus_string_list_nth (tokenized_xlfd, XLFD_INDEX_FOUNDRY);
+ font_description->family = nautilus_string_list_nth (tokenized_xlfd, XLFD_INDEX_FAMILY);
+ font_description->weight = nautilus_string_list_nth (tokenized_xlfd, XLFD_INDEX_WEIGHT);
+ font_description->slant = nautilus_string_list_nth (tokenized_xlfd, XLFD_INDEX_SLANT);
+ font_description->set_width = nautilus_string_list_nth (tokenized_xlfd, XLFD_INDEX_SET_WIDTH);
+ font_description->char_set_registry = nautilus_string_list_nth (tokenized_xlfd, XLFD_INDEX_CHAR_SET_REGISTRY);
+ font_description->char_set_encoding = nautilus_string_list_nth (tokenized_xlfd, XLFD_INDEX_CHAR_SET_ENCODING);
+ } else {
+ g_warning ("'%s' is not a valid XLFD string", xlfd_string);
+ }
+
+ nautilus_string_list_free (tokenized_xlfd);
+
+ return font_description;
+}
+
+static void
+font_description_free (FontDescription *font_description)
+{
+ g_return_if_fail (font_description != NULL);
+
+ g_free (font_description->file_name);
+ g_free (font_description->foundry);
+ g_free (font_description->family);
+ g_free (font_description->weight);
+ g_free (font_description->slant);
+ g_free (font_description->set_width);
+ g_free (font_description->char_set_registry);
+ g_free (font_description->char_set_encoding);
+ g_free (font_description);
+}
+
+static char *
+font_description_get_file_name (const FontDescription *description)
+{
+ g_return_val_if_fail (description != NULL, NULL);
+
+ return g_strdup (description->file_name);
+}
+
+static char *
+font_description_get_foundry (const FontDescription *description)
+{
+ g_return_val_if_fail (description != NULL, NULL);
+
+ return g_strdup (description->foundry);
+}
+
+static char *
+font_description_get_family (const FontDescription *description)
+{
+ g_return_val_if_fail (description != NULL, NULL);
+
+ return g_strdup (description->family);
+}
+
+static char *
+font_description_get_weight (const FontDescription *description)
+{
+ g_return_val_if_fail (description != NULL, NULL);
+
+ return g_strdup (description->weight);
+}
+
+static char *
+font_description_get_slant (const FontDescription *description)
+{
+ g_return_val_if_fail (description != NULL, NULL);
+
+ return g_strdup (description->slant);
+}
+
+static char *
+font_description_get_set_width (const FontDescription *description)
+{
+ g_return_val_if_fail (description != NULL, NULL);
+
+ return g_strdup (description->set_width);
+}
+
+static char *
+font_description_get_char_set_registry (const FontDescription *description)
+{
+ g_return_val_if_fail (description != NULL, NULL);
+
+ return g_strdup (description->char_set_registry);
+}
+
+static char *
+font_description_get_char_set_encoding (const FontDescription *description)
+{
+ g_return_val_if_fail (description != NULL, NULL);
+
+ return g_strdup (description->char_set_encoding);
+}
+
+static void
+font_description_table_add (FontDescriptionTable *description_table,
+ const char *line)
+{
+ char *font_file_name = NULL;
+ FontDescription *description;
+ char *xlfd_delimeter;
+
+ g_return_if_fail (description_table != NULL);
+ g_return_if_fail (string_is_valid (line));
+
+ xlfd_delimeter = strstr (line, " ");
+
+ if (xlfd_delimeter == NULL) {
+ g_warning ("'%s' is not a valid font description line", line);
+ return;
+ }
+
+ font_file_name = g_strndup (line, xlfd_delimeter - line);
+
+ while (isspace ((guchar) *xlfd_delimeter)) {
+ xlfd_delimeter++;
+ }
+
+ description = font_description_new (font_file_name, xlfd_delimeter);
+
+ if (description != NULL) {
+ description_table->descriptions = g_list_append (description_table->descriptions,
+ description);
+ }
+
+ g_free (font_file_name);
+}
+
+static guint
+font_description_table_get_length (const FontDescriptionTable *description_table)
+{
+ g_return_val_if_fail (description_table != NULL, 0);
+
+ return g_list_length (description_table->descriptions);
+}
+
+static const FontDescription *
+font_description_table_peek_nth (const FontDescriptionTable *description_table,
+ guint n)
+{
+ g_return_val_if_fail (description_table != NULL, NULL);
+ g_return_val_if_fail (n < font_description_table_get_length (description_table), NULL);
+
+ return g_list_nth_data (description_table->descriptions, n);
+}
+
+static char *
+font_description_table_get_nth_file_name (const FontDescriptionTable *description_table,
+ guint n)
+{
+ const FontDescription *description;
+
+ g_return_val_if_fail (description_table != NULL, NULL);
+ g_return_val_if_fail (n < font_description_table_get_length (description_table), NULL);
+
+ description = font_description_table_peek_nth (description_table, n);
+
+ return g_strdup (description->file_name);
+}
+
+static void
+font_description_table_free (FontDescriptionTable *table)
+{
+ g_return_if_fail (table != NULL);
+
+ font_description_table_clear (table);
+ g_free (table);
+}
+
+static void
+font_description_table_clear (FontDescriptionTable *table)
+{
+ GList *node;
+
+ g_return_if_fail (table != NULL);
+
+ node = table->descriptions;
+ while (node != NULL) {
+ font_description_free (node->data);
+ node = node->next;
+ }
+
+ g_list_free (table->descriptions);
+ table->descriptions = NULL;
+
+ g_free (table->directory);
+ table->directory = NULL;
+
+ g_free (table->fonts_dir_file);
+ table->fonts_dir_file = NULL;
+
+ g_free (table->fonts_alias_file);
+ table->fonts_alias_file = NULL;
+
+ g_free (table->fonts_scale_file);
+ table->fonts_scale_file = NULL;
+}
+
+static void
+font_description_table_for_each (const FontDescriptionTable *description_table,
+ NautilusFontManagerIterationCallback callback,
+ gpointer callback_data)
+{
+ GList *node;
+ const FontDescription *description;
+
+ g_return_if_fail (description_table != NULL);
+ g_return_if_fail (callback != NULL);
+
+ node = description_table->descriptions;
+ while (node != NULL) {
+ description = node->data;
+ g_assert (node->data != NULL);
+
+ (* callback) (description->foundry,
+ description->family,
+ description->weight,
+ description->slant,
+ description->set_width,
+ description->char_set_registry,
+ description->char_set_encoding,
+ callback_data);
+
+ node = node->next;
+ }
+}
+
+static FontDescriptionTable *
+table_new_from_contents (const char *contents)
+{
+ FontDescriptionTable *description_table;
+ NautilusStringList *tokenized_contents;
+ int i;
+ int count;
+ char *line;
+
+ g_return_val_if_fail (string_is_valid (contents), NULL);
+
+ tokenized_contents = nautilus_string_list_new_from_tokens (contents, "\n", FALSE);
+
+ /* Make sure there is at least one description. Item 0 is the count */
+ if (nautilus_string_list_get_length (tokenized_contents) <= 1) {
+ nautilus_string_list_free (tokenized_contents);
+ return NULL;
+ }
+
+ /* Find out how many font entries are described in this file */
+ if (!nautilus_string_list_nth_as_integer (tokenized_contents, 0, &count)) {
+ nautilus_string_list_free (tokenized_contents);
+ return NULL;
+ }
+
+ description_table = g_new0 (FontDescriptionTable, 1);
+
+ for (i = 0; i < count; i++) {
+ line = nautilus_string_list_nth (tokenized_contents, i + 1);
+
+ if (line != NULL) {
+ font_description_table_add (description_table, line);
+ }
+
+ g_free (line);
+ }
+
+ nautilus_string_list_free (tokenized_contents);
+
+ return description_table;
+}
+
+static FontDescriptionTable *
+font_description_table_new (const char *font_directory)
+{
+ FontDescriptionTable *table;
+ char *description_file;
+ char *description_contents;
+
+ g_return_val_if_fail (string_is_valid (font_directory), NULL);
+ g_return_val_if_fail (g_file_test (font_directory, G_FILE_TEST_ISDIR), NULL);
+
+ description_file = nautilus_make_path (font_directory, FONTS_DIR_FILE_NAME);
+ description_contents = file_as_string (description_file);
+
+ if (description_contents == NULL) {
+ g_free (description_file);
+ return NULL;
+ }
+
+ table = table_new_from_contents (description_contents);
+
+ if (table != NULL) {
+ table->fonts_dir_file = nautilus_make_path (font_directory, FONTS_DIR_FILE_NAME);
+
+ /* Assign the alias file if found */
+ if (directory_contains_file (font_directory, FONTS_ALIAS_FILE_NAME)) {
+ table->fonts_alias_file = nautilus_make_path (font_directory, FONTS_ALIAS_FILE_NAME);
+ }
+
+ /* Assign the alias scale if found */
+ if (directory_contains_file (font_directory, FONTS_SCALE_FILE_NAME)) {
+ table->fonts_scale_file = nautilus_make_path (font_directory, FONTS_SCALE_FILE_NAME);
+ }
+ }
+
+ return table;
+}
+
+static void
+font_description_table_install_font_lists (FontDescriptionTable *table,
+ GList *postscript_font_list,
+ GList *true_type_font_list)
+{
+ g_return_if_fail (table != NULL);
+ g_return_if_fail (table->postscript_font_list == NULL);
+ g_return_if_fail (table->true_type_font_list == NULL);
+
+ table->postscript_font_list = postscript_font_list;
+ table->true_type_font_list = true_type_font_list;
+}
+
+static GnomeVFSResult
+collect_fonts_from_directory (const char *font_directory,
+ GList **postscript_font_list,
+ GList **true_type_font_list)
+{
+ GnomeVFSDirectoryHandle *directory;
+ GnomeVFSResult result;
+ GnomeVFSFileInfo *info;
+ char *directory_uri;
+
+ g_return_val_if_fail (string_is_valid (font_directory), GNOME_VFS_ERROR_BAD_PARAMETERS);
+ g_return_val_if_fail (postscript_font_list != NULL, GNOME_VFS_ERROR_BAD_PARAMETERS);
+ g_return_val_if_fail (true_type_font_list != NULL, GNOME_VFS_ERROR_BAD_PARAMETERS);
+
+ directory_uri = g_strconcat ("file://", font_directory, NULL);
+
+ *postscript_font_list = NULL;
+ *true_type_font_list = NULL;
+
+ result = gnome_vfs_directory_open (&directory,
+ directory_uri, GNOME_VFS_FILE_INFO_GET_MIME_TYPE, NULL);
+ g_free (directory_uri);
+
+ if (result != GNOME_VFS_OK) {
+ return result;
+ }
+
+
+ while (TRUE) {
+ info = gnome_vfs_file_info_new ();
+ result = gnome_vfs_directory_read_next (directory, info);
+ if (result == GNOME_VFS_OK) {
+ if (strcasecmp (info->mime_type, "application/x-font-type1") == 0) {
+ *postscript_font_list = g_list_prepend (*postscript_font_list,
+ g_strconcat (font_directory,
+ "/", info->name, NULL));
+ } else if (strcasecmp (info->mime_type, "application/x-font-ttf") == 0) {
+ *true_type_font_list = g_list_prepend (*true_type_font_list,
+ g_strconcat (font_directory,
+ "/", info->name, NULL));
+ }
+ }
+ gnome_vfs_file_info_unref (info);
+
+ if (result == GNOME_VFS_ERROR_EOF) {
+ break;
+ }
+ }
+
+ gnome_vfs_directory_close (directory);
+
+ return GNOME_VFS_OK;
+}
+
+
+static void
+chop_off_comments (char *line)
+{
+
+ /* Terminates a string right at the start of a comment, stripping it from the
+ * string.
+ */
+ gboolean saw_escape;
+ char *scanner;
+
+ saw_escape = FALSE;
+ for (scanner = line; *scanner != '\0'; scanner++) {
+ if (saw_escape) {
+ saw_escape = FALSE;
+ continue;
+ }
+ if (*scanner == '\\') {
+
+
+ saw_escape = TRUE;
+ continue;
+ }
+ if (*scanner == '#') {
+ *scanner = '\0';
+ break;
+ }
+ }
+}
+
+static void
+next_token (const char *buffer, int from, int *token_start, int *token_end)
+{
+ gboolean saw_escape;
+ const char *scanner;
+
+ g_assert ((int) strlen (buffer) >= from);
+
+ *token_start = -1;
+ *token_end = -1;
+
+ /* strip white space */
+ saw_escape = FALSE;
+ for (scanner = buffer + from; *scanner != '\0'; scanner++) {
+ if (saw_escape) {
+ saw_escape = FALSE;
+ continue;
+ }
+ if (*scanner == '\\') {
+ saw_escape = TRUE;
+ continue;
+ }
+ if (!isspace ((guchar) *scanner) && *scanner != '\n') {
+ *token_start = scanner - buffer;
+ break;
+ }
+ }
+
+ if (*scanner == ',') {
+ *token_end = *token_start + 1;
+ return;
+ }
+
+ /* go until token end */
+ saw_escape = FALSE;
+ for (; *scanner != '\0'; scanner++) {
+ if (saw_escape) {
+ saw_escape = FALSE;
+ continue;
+ }
+ if (*scanner == '\\') {
+ saw_escape = TRUE;
+ continue;
+ }
+ if (isspace ((guchar) *scanner) || *scanner == ',') {
+ break;
+ }
+ }
+
+ if (*token_start >= 0) {
+ *token_end = scanner - buffer;
+ }
+}
+
+#define READ_BUFFER_SIZE 2048
+
+static gboolean
+token_matches (const char *buffer, int start, int end, const char *pattern)
+{
+ if (start < 0) {
+ return FALSE;
+ }
+
+ return strncmp (buffer + start, pattern, end - start) == 0;
+}
+
+typedef enum {
+ EXPECT_CATALOGUE,
+ EXPECT_ASSIGNMENT,
+ EXPECT_DIRECTORY,
+ EXPECT_COMMA
+} FontConfigParseState;
+
+static void
+font_server_for_each_font_directory_internal (void (* callback) (const char *font_directory, gpointer callback_data),
+ gpointer callback_data,
+ char *buffer,
+ FILE *file)
+{
+ FontConfigParseState state;
+ int token_start, token_end;
+ char *font_directory;
+
+ g_return_if_fail (callback != NULL);
+ g_return_if_fail (buffer != NULL);
+ g_return_if_fail (file != NULL);
+
+ state = EXPECT_CATALOGUE;
+ while (TRUE) {
+ fgets (buffer, READ_BUFFER_SIZE, file);
+ if (strlen (buffer) == 0) {
+ if (state != EXPECT_COMMA) {
+ g_print ("unexpected file end\n");
+ }
+ break;
+ }
+
+ chop_off_comments (buffer);
+
+ token_start = 0;
+ while (TRUE) {
+ next_token (buffer, token_start, &token_start, &token_end);
+
+ if (token_start < 0) {
+ break;
+ }
+
+ switch (state) {
+ case EXPECT_CATALOGUE:
+ if (token_matches(buffer, token_start, token_end, "catalogue")) {
+ state = EXPECT_ASSIGNMENT;
+ }
+ break;
+
+ case EXPECT_ASSIGNMENT:
+ if (!token_matches(buffer, token_start, token_end, "=")) {
+ g_print (" expected token \"=\" \n");
+ return;
+ }
+ state = EXPECT_DIRECTORY;
+ break;
+
+ case EXPECT_DIRECTORY:
+ if (token_matches(buffer, token_start, token_end, ",")) {
+ g_print (" expected directory name \n");
+ return;
+ }
+ /* found a directory, call an each function on it */
+ font_directory = g_strndup (buffer + token_start, token_end - token_start);
+ (* callback) (font_directory, callback_data);
+ g_free (font_directory);
+ state = EXPECT_COMMA;
+ break;
+
+ case EXPECT_COMMA:
+ if (!token_matches(buffer, token_start, token_end, ",")) {
+ /* we are done, no more directories */
+ return;
+ }
+ state = EXPECT_DIRECTORY;
+ break;
+ }
+
+ token_start = token_end;
+ }
+ }
+}
+
+static void
+font_server_for_each_font_directory (const char *font_config_file_path,
+ void (* callback) (const char *font_directory, gpointer callback_data),
+ gpointer callback_data)
+{
+ /* scan the font config file, finding all the font directory paths */
+ FILE *font_config_file;
+ char *buffer;
+
+ g_return_if_fail (string_is_valid (font_config_file_path));
+ g_return_if_fail (callback != NULL);
+ g_return_if_fail (callback_data != NULL);
+
+ font_config_file = fopen (font_config_file_path, "r");
+
+ if (font_config_file == NULL) {
+ return;
+ }
+
+ buffer = g_malloc (READ_BUFFER_SIZE);
+ font_server_for_each_font_directory_internal (callback,
+ callback_data,
+ buffer,
+ font_config_file);
+
+ g_free (buffer);
+ fclose (font_config_file);
+}
+
+static gboolean
+directory_contains_file (const char *directory,
+ const char *file_name)
+{
+ gboolean result;
+ char *path;
+
+ g_return_val_if_fail (string_is_valid (directory), FALSE);
+ g_return_val_if_fail (string_is_valid (file_name), FALSE);
+
+ path = nautilus_make_path (directory, file_name);
+ result = g_file_exists (path);
+ g_free (path);
+
+ return result;
+}
+
+static void
+font_server_for_each_callback (const char *font_directory,
+ gpointer callback_data)
+{
+ FontDescriptionTable *table;
+
+ GList *postscript_font_list = NULL;
+ GList *true_type_font_list = NULL;
+
+ GList **collected_font_tables;
+
+ g_return_if_fail (font_directory != NULL);
+ g_return_if_fail (callback_data != NULL);
+
+ collected_font_tables = callback_data;
+
+ /* Collect postscript and true type font in this directory */
+ collect_fonts_from_directory (font_directory, &postscript_font_list, &true_type_font_list);
+
+ /* No scalable fonts found; we're done */
+ if (g_list_length (postscript_font_list) == 0
+ && g_list_length (true_type_font_list) == 0) {
+ return;
+ }
+
+ /* If no "fonts.dir" exists, then the user has a missing description file (broken setup) */
+ if (!directory_contains_file (font_directory, FONTS_DIR_FILE_NAME)) {
+ g_free (postscript_font_list);
+ g_free (true_type_font_list);
+ g_warning ("Direcotry '%s' contains scalable fonts but no '%s' description file.",
+ font_directory,
+ FONTS_DIR_FILE_NAME);
+ return;
+ }
+
+ table = font_description_table_new (font_directory);
+ g_assert (table != NULL);
+
+ font_description_table_install_font_lists (table, postscript_font_list, true_type_font_list);
+
+ *collected_font_tables = g_list_prepend (*collected_font_tables, table);
+}
+
+/* Public */
+void
+nautilus_font_manager_for_each_font (NautilusFontManagerIterationCallback callback,
+ gpointer callback_data)
+{
+ GList *collected_font_tables = NULL;
+ GList *node;
+ FontDescriptionTable *table;
+
+ g_return_if_fail (callback != NULL);
+
+ font_server_for_each_font_directory ("/etc/X11/fs/config",
+ font_server_for_each_callback,
+ &collected_font_tables);
+
+ node = collected_font_tables;
+ while (node) {
+ g_assert (node->data != NULL);
+ table = node->data;
+
+ font_description_table_for_each (table, callback, callback_data);
+ font_description_table_free (table);
+
+ node = node->next;
+ }
+
+ g_list_free (collected_font_tables);
+}
+
+
+#if !defined (NAUTILUS_OMIT_SELF_CHECK)
+
+/*
+ * The check strategy here is to create a temporary directory
+ * with a single fonts.dir inside it. We then use that to
+ * exercise the font manager.
+ */
+static const char *test_fonts_dir_content =
+"4\n"
+"n019003l.pfb -URW-Helvetica-medium-r-normal--0-0-0-0-p-0-iso8859-1\n"
+"n019004l.pfb -URW-Helvetica-bold-r-normal--0-0-0-0-p-0-iso8859-1\n"
+"n019023l.pfb -URW-Helvetica-medium-o-normal--0-0-0-0-p-0-iso8859-1\n"
+"n019024l.pfb -URW-Helvetica-bold-o-normal--0-0-0-0-p-0-iso8859-1\n"
+;
+
+static char *
+call_chop_off_comments (const char *input)
+{
+ char *test_copy;
+ test_copy = g_strdup (input);
+ chop_off_comments (test_copy);
+ return test_copy;
+}
+
+static gboolean
+write_temp_font_dot_dir_file (const char *temp_font_dir_file_name)
+{
+ FILE *stream;
+ size_t num;
+ size_t num_written;
+
+ g_return_val_if_fail (string_is_valid (temp_font_dir_file_name), FALSE);
+ g_return_val_if_fail (!g_file_exists (temp_font_dir_file_name), FALSE);
+
+ stream = fopen (temp_font_dir_file_name, "w");
+ g_return_val_if_fail (stream != NULL, FALSE);
+
+ num = strlen (test_fonts_dir_content);
+ num_written = fwrite (test_fonts_dir_content, sizeof (char), num, stream);
+ fclose (stream);
+
+ g_return_val_if_fail (num == num_written, FALSE);
+
+ return TRUE;
+}
+
+static char *
+get_unique_temp_directory (void)
+{
+ char *temp_font_directory;
+
+ temp_font_directory = nautilus_unique_temporary_file_name ();
+
+ if (temp_font_directory == NULL) {
+ return NULL;
+ }
+
+ if (g_file_test (temp_font_directory, G_FILE_TEST_ISDIR)) {
+ g_free (temp_font_directory);
+ return NULL;
+ }
+
+ mkdir (temp_font_directory, 0755);
+
+ if (!g_file_test (temp_font_directory, G_FILE_TEST_ISDIR)) {
+ g_free (temp_font_directory);
+ return NULL;
+ }
+
+ return temp_font_directory;
+}
+
+void
+nautilus_self_check_font_manager (void)
+{
+ FontDescriptionTable *table;
+ const FontDescription *description;
+
+ char *temp_font_directory;
+ char *temp_fonts_dot_dir_file;
+ char *cleanup_command;
+ gboolean temp_font_directory_ok;
+
+ temp_font_directory = get_unique_temp_directory ();
+ g_return_if_fail (string_is_valid (temp_font_directory));
+
+ temp_fonts_dot_dir_file = nautilus_make_path (temp_font_directory, FONTS_DIR_FILE_NAME);
+ temp_font_directory_ok = write_temp_font_dot_dir_file (temp_fonts_dot_dir_file);
+ g_return_if_fail (temp_font_directory_ok == TRUE);
+
+ cleanup_command = g_strdup_printf ("/bin/rm -rf %s", temp_font_directory);
+
+ table = font_description_table_new (temp_font_directory);
+
+ NAUTILUS_CHECK_INTEGER_RESULT (font_description_table_get_length (table), 4);
+ NAUTILUS_CHECK_STRING_RESULT (font_description_table_get_nth_file_name (table, 0), "n019003l.pfb");
+ NAUTILUS_CHECK_STRING_RESULT (font_description_table_get_nth_file_name (table, 1), "n019004l.pfb");
+ NAUTILUS_CHECK_STRING_RESULT (font_description_table_get_nth_file_name (table, 2), "n019023l.pfb");
+ NAUTILUS_CHECK_STRING_RESULT (font_description_table_get_nth_file_name (table, 3), "n019024l.pfb");
+
+ description = font_description_table_peek_nth (table, 0);
+ NAUTILUS_CHECK_STRING_RESULT (font_description_get_file_name (description), "n019003l.pfb");
+ NAUTILUS_CHECK_STRING_RESULT (font_description_get_foundry (description), "URW");
+ NAUTILUS_CHECK_STRING_RESULT (font_description_get_family (description), "Helvetica");
+ NAUTILUS_CHECK_STRING_RESULT (font_description_get_weight (description), "medium");
+ NAUTILUS_CHECK_STRING_RESULT (font_description_get_slant (description), "r");
+ NAUTILUS_CHECK_STRING_RESULT (font_description_get_set_width (description), "normal");
+ NAUTILUS_CHECK_STRING_RESULT (font_description_get_char_set_encoding (description), "1");
+ NAUTILUS_CHECK_STRING_RESULT (font_description_get_char_set_registry (description), "iso8859");
+
+ description = font_description_table_peek_nth (table, 1);
+ NAUTILUS_CHECK_STRING_RESULT (font_description_get_file_name (description), "n019004l.pfb");
+ NAUTILUS_CHECK_STRING_RESULT (font_description_get_foundry (description), "URW");
+ NAUTILUS_CHECK_STRING_RESULT (font_description_get_family (description), "Helvetica");
+ NAUTILUS_CHECK_STRING_RESULT (font_description_get_weight (description), "bold");
+ NAUTILUS_CHECK_STRING_RESULT (font_description_get_slant (description), "r");
+ NAUTILUS_CHECK_STRING_RESULT (font_description_get_set_width (description), "normal");
+ NAUTILUS_CHECK_STRING_RESULT (font_description_get_char_set_encoding (description), "1");
+ NAUTILUS_CHECK_STRING_RESULT (font_description_get_char_set_registry (description), "iso8859");
+
+ description = font_description_table_peek_nth (table, 2);
+ NAUTILUS_CHECK_STRING_RESULT (font_description_get_file_name (description), "n019023l.pfb");
+ NAUTILUS_CHECK_STRING_RESULT (font_description_get_foundry (description), "URW");
+ NAUTILUS_CHECK_STRING_RESULT (font_description_get_family (description), "Helvetica");
+ NAUTILUS_CHECK_STRING_RESULT (font_description_get_weight (description), "medium");
+ NAUTILUS_CHECK_STRING_RESULT (font_description_get_slant (description), "o");
+ NAUTILUS_CHECK_STRING_RESULT (font_description_get_set_width (description), "normal");
+ NAUTILUS_CHECK_STRING_RESULT (font_description_get_char_set_encoding (description), "1");
+ NAUTILUS_CHECK_STRING_RESULT (font_description_get_char_set_registry (description), "iso8859");
+
+ description = font_description_table_peek_nth (table, 3);
+ NAUTILUS_CHECK_STRING_RESULT (font_description_get_file_name (description), "n019024l.pfb");
+ NAUTILUS_CHECK_STRING_RESULT (font_description_get_foundry (description), "URW");
+ NAUTILUS_CHECK_STRING_RESULT (font_description_get_family (description), "Helvetica");
+ NAUTILUS_CHECK_STRING_RESULT (font_description_get_weight (description), "bold");
+ NAUTILUS_CHECK_STRING_RESULT (font_description_get_slant (description), "o");
+ NAUTILUS_CHECK_STRING_RESULT (font_description_get_set_width (description), "normal");
+ NAUTILUS_CHECK_STRING_RESULT (font_description_get_char_set_encoding (description), "1");
+ NAUTILUS_CHECK_STRING_RESULT (font_description_get_char_set_registry (description), "iso8859");
+
+ font_description_table_free (table);
+
+ /* chop_off_comments() */
+ NAUTILUS_CHECK_STRING_RESULT (call_chop_off_comments ("foo bar"), "foo bar");
+ NAUTILUS_CHECK_STRING_RESULT (call_chop_off_comments ("foo bar\n"), "foo bar\n");
+ NAUTILUS_CHECK_STRING_RESULT (call_chop_off_comments ("#foo bar"), "");
+ NAUTILUS_CHECK_STRING_RESULT (call_chop_off_comments ("foo bar#"), "foo bar");
+ NAUTILUS_CHECK_STRING_RESULT (call_chop_off_comments ("\\foo bar"), "\\foo bar");
+ NAUTILUS_CHECK_STRING_RESULT (call_chop_off_comments ("\\#foo bar"), "\\#foo bar");
+ NAUTILUS_CHECK_STRING_RESULT (call_chop_off_comments ("\\##foo bar"), "\\#");
+
+ system (cleanup_command);
+
+ g_free (cleanup_command);
+ g_free (temp_font_directory);
+ g_free (temp_fonts_dot_dir_file);
+}
+
+#endif /* !NAUTILUS_OMIT_SELF_CHECK */
diff --git a/libnautilus-private/nautilus-font-manager.h b/libnautilus-private/nautilus-font-manager.h
new file mode 100644
index 000000000..3204ce0fa
--- /dev/null
+++ b/libnautilus-private/nautilus-font-manager.h
@@ -0,0 +1,52 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+
+/* nautilus-font-manager.h - Functions for managing fonts.
+
+ Copyright (C) 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_FONT_MANAGER_H
+#define NAUTILUS_FONT_MANAGER_H
+
+#include <libgnome/gnome-defs.h>
+#include <glib.h>
+
+BEGIN_GNOME_DECLS
+
+/*
+ * A callback which can be invoked for each font available in the system.
+ */
+typedef void (*NautilusFontManagerIterationCallback) (const char *foundry,
+ const char *family,
+ const char *weight,
+ const char *slant,
+ const char *set_width,
+ const char *char_set_registry,
+ const char *char_set_encoding,
+ gpointer callback_data);
+
+void nautilus_font_manager_for_each_font (NautilusFontManagerIterationCallback callback,
+ gpointer callback_data);
+
+END_GNOME_DECLS
+
+#endif /* NAUTILUS_FONT_MANAGER_H */
+
+
diff --git a/libnautilus-private/nautilus-global-preferences.c b/libnautilus-private/nautilus-global-preferences.c
index 414e39f94..aeee8d2eb 100644
--- a/libnautilus-private/nautilus-global-preferences.c
+++ b/libnautilus-private/nautilus-global-preferences.c
@@ -264,7 +264,7 @@ global_preferences_install_defaults (void)
nautilus_preferences_default_set_string (NAUTILUS_PREFERENCES_DIRECTORY_VIEW_FONT_FAMILY,
NAUTILUS_USER_LEVEL_NOVICE,
- "helvetica");
+ _("helvetica"));
nautilus_preferences_default_set_integer (NAUTILUS_PREFERENCES_CLICK_POLICY,
NAUTILUS_USER_LEVEL_NOVICE,
@@ -522,8 +522,7 @@ global_preferences_create_dialog (void)
* Appearance
*/
appearance_pane = nautilus_preferences_box_add_pane (preference_box,
- _("Appearance"),
- _("Appearance Settings"));
+ _("Appearance"));
nautilus_preferences_pane_add_group (NAUTILUS_PREFERENCES_PANE (appearance_pane), _("Smoother Graphics"));
@@ -543,8 +542,7 @@ global_preferences_create_dialog (void)
* Windows & Desktop pane
*/
windows_and_desktop_pane = nautilus_preferences_box_add_pane (preference_box,
- _("Windows & Desktop"),
- _("Windows & Desktop Settings"));
+ _("Windows & Desktop"));
nautilus_preferences_pane_add_group (NAUTILUS_PREFERENCES_PANE (windows_and_desktop_pane), _("Desktop"));
nautilus_preferences_pane_add_item_to_nth_group (NAUTILUS_PREFERENCES_PANE (windows_and_desktop_pane),
@@ -587,8 +585,7 @@ global_preferences_create_dialog (void)
* Folder Views pane
*/
directory_views_pane = nautilus_preferences_box_add_pane (preference_box,
- _("Icon & List Views"),
- _("Icon & List Views Settings"));
+ _("Icon & List Views"));
nautilus_preferences_pane_add_group (NAUTILUS_PREFERENCES_PANE (directory_views_pane), _("Click Behavior"));
@@ -625,8 +622,7 @@ global_preferences_create_dialog (void)
* Sidebar panels pane
*/
sidebar_panels_pane = nautilus_preferences_box_add_pane (preference_box,
- _("Sidebar Panels"),
- _("Sidebar Panels Settings"));
+ _("Sidebar Panels"));
nautilus_preferences_pane_add_group (NAUTILUS_PREFERENCES_PANE (sidebar_panels_pane),
_("Tabs"));
@@ -678,8 +674,7 @@ global_preferences_create_dialog (void)
* Navigation
*/
navigation_pane = nautilus_preferences_box_add_pane (preference_box,
- _("Navigation"),
- _("Navigation Settings"));
+ _("Navigation"));
nautilus_preferences_pane_add_group (NAUTILUS_PREFERENCES_PANE (navigation_pane), _("Home"));
@@ -718,8 +713,7 @@ global_preferences_create_dialog (void)
* Tradeoffs
*/
tradeoffs_pane = nautilus_preferences_box_add_pane (preference_box,
- _("Speed Tradeoffs"),
- _("Speed Tradeoffs Settings"));
+ _("Speed Tradeoffs"));
nautilus_preferences_pane_add_group (NAUTILUS_PREFERENCES_PANE (tradeoffs_pane), _("Show Text in Icons"));
@@ -790,8 +784,7 @@ global_preferences_create_search_pane (NautilusPreferencesBox *preference_box)
* Search Settings
*/
search_pane = nautilus_preferences_box_add_pane (preference_box,
- _("Search"),
- _("Search Settings"));
+ _("Search"));
nautilus_preferences_pane_add_group (NAUTILUS_PREFERENCES_PANE (search_pane),
_("Search Complexity Options"));
nautilus_preferences_pane_add_item_to_nth_group (NAUTILUS_PREFERENCES_PANE (search_pane),
diff --git a/libnautilus-private/nautilus-lib-self-check-functions.h b/libnautilus-private/nautilus-lib-self-check-functions.h
index f1bdf9ea1..24288cbca 100644
--- a/libnautilus-private/nautilus-lib-self-check-functions.h
+++ b/libnautilus-private/nautilus-lib-self-check-functions.h
@@ -44,6 +44,7 @@ void nautilus_run_lib_self_checks (void);
macro (nautilus_self_check_enumeration) \
macro (nautilus_self_check_preferences) \
macro (nautilus_self_check_scalable_font) \
+ macro (nautilus_self_check_font_manager) \
macro (nautilus_self_check_string_map) \
macro (nautilus_self_check_art_extensions) \
macro (nautilus_self_check_gdk_pixbuf_extensions) \
diff --git a/libnautilus-private/nautilus-preferences-box.c b/libnautilus-private/nautilus-preferences-box.c
index 0bf886a03..3e5f254e8 100644
--- a/libnautilus-private/nautilus-preferences-box.c
+++ b/libnautilus-private/nautilus-preferences-box.c
@@ -336,20 +336,18 @@ nautilus_preferences_box_new (const char *box_title)
GtkWidget *
nautilus_preferences_box_add_pane (NautilusPreferencesBox *preferences_box,
- const char *pane_title,
- const char *pane_description)
+ const char *pane_title)
{
PaneInfo *info;
g_return_val_if_fail (NAUTILUS_IS_PREFERENCES_BOX (preferences_box), NULL);
g_return_val_if_fail (pane_title != NULL, NULL);
- g_return_val_if_fail (pane_description != NULL, NULL);
info = pane_info_new (pane_title);
preferences_box->details->panes = g_list_append (preferences_box->details->panes, info);
- info->pane_widget = nautilus_preferences_pane_new (pane_title, pane_description);
+ info->pane_widget = nautilus_preferences_pane_new ();
gtk_notebook_append_page (GTK_NOTEBOOK (preferences_box->details->pane_notebook),
info->pane_widget,
diff --git a/libnautilus-private/nautilus-preferences-box.h b/libnautilus-private/nautilus-preferences-box.h
index e688f1ee3..225274a57 100644
--- a/libnautilus-private/nautilus-preferences-box.h
+++ b/libnautilus-private/nautilus-preferences-box.h
@@ -60,8 +60,7 @@ struct _NautilusPreferencesBoxClass
GtkType nautilus_preferences_box_get_type (void);
GtkWidget* nautilus_preferences_box_new (const char *box_title);
GtkWidget* nautilus_preferences_box_add_pane (NautilusPreferencesBox *prefs_box,
- const char *pane_title,
- const char *pane_description);
+ const char *pane_title);
void nautilus_preferences_box_update (NautilusPreferencesBox *prefs_box);
END_GNOME_DECLS
diff --git a/libnautilus-private/nautilus-preferences-item.c b/libnautilus-private/nautilus-preferences-item.c
index df6b0a764..fad424973 100644
--- a/libnautilus-private/nautilus-preferences-item.c
+++ b/libnautilus-private/nautilus-preferences-item.c
@@ -31,6 +31,7 @@
#include "nautilus-string.h"
#include <libgnomevfs/gnome-vfs.h>
+#include <libgnome/gnome-i18n.h>
#include <gtk/gtkcheckbutton.h>
#include <gtk/gtksignal.h>
#include <gtk/gtklabel.h>
@@ -42,15 +43,6 @@
#include "nautilus-global-preferences.h"
-/* Arguments */
-enum
-{
- ARG_0,
- ARG_SHOW_DESCRIPTION,
- ARG_DESCRIPTION_STRING,
- ARG_TITLE_STRING
-};
-
static const guint PREFERENCES_ITEM_TITLE_SPACING = 4;
static const guint PREFERENCES_ITEM_FRAME_BORDER_WIDTH = 6;
static const NautilusPreferencesItemType PREFERENCES_ITEM_UNDEFINED_ITEM = -1U;
@@ -59,57 +51,46 @@ static gboolean integer_idle_handler = FALSE;
struct _NautilusPreferencesItemDetails
{
- gchar *preference_name;
- NautilusPreferencesItemType item_type;
- GtkWidget *child;
- guint change_signal_ID;
+ char *preference_name;
+ NautilusPreferencesItemType item_type;
+ GtkWidget *child;
+ guint change_signal_ID;
};
-/* 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);
+static void nautilus_preferences_item_initialize_class (NautilusPreferencesItemClass *preferences_item_class);
+static void nautilus_preferences_item_initialize (NautilusPreferencesItem *preferences_item);
+static void preferences_item_destroy (GtkObject *object);
/* Private stuff */
-static void preferences_item_construct (NautilusPreferencesItem *item,
- const gchar *preference_name,
- NautilusPreferencesItemType item_type);
-static void preferences_item_create_enum (NautilusPreferencesItem *item,
- const char *preference_name);
-static void preferences_item_create_short_enum (NautilusPreferencesItem *item,
- const char *preference_name);
-static void preferences_item_create_boolean (NautilusPreferencesItem *item,
- const char *preference_name);
-static void preferences_item_create_editable_string (NautilusPreferencesItem *item,
- const char *preference_name);
-static void preferences_item_create_integer (NautilusPreferencesItem *item,
- const char *preference_name);
-static void preferences_item_create_font_family (NautilusPreferencesItem *item,
- const char *preference_name);
-static void preferences_item_create_theme (NautilusPreferencesItem *item,
- const char *preference_name);
-static void preferences_item_update_text_settings_at_idle (NautilusPreferencesItem *preferences_item);
-static void preferences_item_update_integer_settings_at_idle (NautilusPreferencesItem *preferences_item);
-static void enum_radio_group_changed_callback (GtkWidget *button_group,
- GtkWidget *button,
- gpointer user_data);
-static void boolean_button_toggled_callback (GtkWidget *button_group,
- gpointer user_data);
-static void text_item_changed_callback (GtkWidget *string_picker,
- gpointer user_data);
-static void editable_string_changed_callback (GtkWidget *caption,
- gpointer user_data);
-static void integer_changed_callback (GtkWidget *caption,
- gpointer user_data);
+static void preferences_item_construct (NautilusPreferencesItem *item,
+ const char *preference_name,
+ NautilusPreferencesItemType item_type);
+static void preferences_item_create_enum (NautilusPreferencesItem *item,
+ const char *preference_name);
+static void preferences_item_create_short_enum (NautilusPreferencesItem *item,
+ const char *preference_name);
+static void preferences_item_create_boolean (NautilusPreferencesItem *item,
+ const char *preference_name);
+static void preferences_item_create_editable_string (NautilusPreferencesItem *item,
+ const char *preference_name);
+static void preferences_item_create_integer (NautilusPreferencesItem *item,
+ const char *preference_name);
+static void preferences_item_create_font_family (NautilusPreferencesItem *item,
+ const char *preference_name);
+static void preferences_item_update_text_settings_at_idle (NautilusPreferencesItem *preferences_item);
+static void preferences_item_update_integer_settings_at_idle (NautilusPreferencesItem *preferences_item);
+static void enum_radio_group_changed_callback (GtkWidget *button_group,
+ GtkWidget *button,
+ gpointer user_data);
+static void boolean_button_toggled_callback (GtkWidget *button_group,
+ gpointer user_data);
+static void text_item_changed_callback (GtkWidget *string_picker,
+ gpointer user_data);
+static void editable_string_changed_callback (GtkWidget *caption,
+ gpointer user_data);
+static void integer_changed_callback (GtkWidget *caption,
+ gpointer user_data);
NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusPreferencesItem, nautilus_preferences_item, GTK_TYPE_VBOX)
@@ -125,36 +106,15 @@ nautilus_preferences_item_initialize_class (NautilusPreferencesItemClass *prefer
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;
}
static void
nautilus_preferences_item_initialize (NautilusPreferencesItem *item)
{
- item->details = g_new (NautilusPreferencesItemDetails, 1);
-
- item->details->preference_name = NULL;
+ item->details = g_new0 (NautilusPreferencesItemDetails, 1);
item->details->item_type = PREFERENCES_ITEM_UNDEFINED_ITEM;
- item->details->child = NULL;
}
/* GtkObjectClass methods */
@@ -163,89 +123,15 @@ 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->preference_name)
- {
- g_free (item->details->preference_name);
- }
-
+ g_free (item->details->preference_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
+ /* Chain destroy */
+ NAUTILUS_CALL_PARENT (GTK_OBJECT_CLASS, destroy, (object));
}
/*
@@ -253,12 +139,12 @@ preferences_item_get_arg (GtkObject *object,
*/
static void
preferences_item_construct (NautilusPreferencesItem *item,
- const gchar *preference_name,
+ const char *preference_name,
NautilusPreferencesItemType item_type)
{
- g_assert (item != NULL);
+ g_return_if_fail (NAUTILUS_IS_PREFERENCES_ITEM (item));
- g_assert (preference_name != NULL);
+ g_return_if_fail (nautilus_strlen (preference_name) > 0);
g_assert (item_type != PREFERENCES_ITEM_UNDEFINED_ITEM);
g_assert (item->details->child == NULL);
@@ -287,12 +173,10 @@ preferences_item_construct (NautilusPreferencesItem *item,
preferences_item_create_font_family (item, preference_name);
break;
- case NAUTILUS_PREFERENCE_ITEM_THEME:
- preferences_item_create_theme (item, preference_name);
- break;
case NAUTILUS_PREFERENCE_ITEM_EDITABLE_STRING:
preferences_item_create_editable_string (item, preference_name);
break;
+
case NAUTILUS_PREFERENCE_ITEM_INTEGER:
preferences_item_create_integer (item, preference_name);
break;
@@ -315,12 +199,12 @@ preferences_item_construct (NautilusPreferencesItem *item,
static void
preferences_item_update_enum (const NautilusPreferencesItem *item)
{
- gint value;
+ int value;
char *preference_name;
guint i;
- g_assert (NAUTILUS_IS_PREFERENCES_ITEM (item));
- g_assert (item->details->item_type == NAUTILUS_PREFERENCE_ITEM_ENUM);
+ g_return_if_fail (NAUTILUS_IS_PREFERENCES_ITEM (item));
+ g_return_if_fail (item->details->item_type == NAUTILUS_PREFERENCE_ITEM_ENUM);
preference_name = item->details->preference_name;
value = nautilus_preferences_get_integer (preference_name);
@@ -338,8 +222,8 @@ preferences_item_create_enum (NautilusPreferencesItem *item,
{
guint i;
- g_assert (item != NULL);
- g_assert (preference_name != NULL);
+ g_return_if_fail (NAUTILUS_IS_PREFERENCES_ITEM (item));
+ g_return_if_fail (nautilus_strlen (preference_name) > 0);
g_assert (item->details->preference_name != NULL);
@@ -368,12 +252,12 @@ preferences_item_create_enum (NautilusPreferencesItem *item,
static void
preferences_item_update_short_enum (const NautilusPreferencesItem *item)
{
- gint value;
+ int value;
char *preference_name;
guint i;
- g_assert (NAUTILUS_IS_PREFERENCES_ITEM (item));
- g_assert (item->details->item_type == NAUTILUS_PREFERENCE_ITEM_SHORT_ENUM);
+ g_return_if_fail (NAUTILUS_IS_PREFERENCES_ITEM (item));
+ g_return_if_fail (item->details->item_type == NAUTILUS_PREFERENCE_ITEM_SHORT_ENUM);
preference_name = item->details->preference_name;
value = nautilus_preferences_get_integer (preference_name);
@@ -395,8 +279,8 @@ preferences_item_create_short_enum (NautilusPreferencesItem *item,
{
guint i;
- g_assert (item != NULL);
- g_assert (preference_name != NULL);
+ g_return_if_fail (NAUTILUS_IS_PREFERENCES_ITEM (item));
+ g_return_if_fail (nautilus_strlen (preference_name) > 0);
g_assert (item->details->preference_name != NULL);
@@ -427,8 +311,8 @@ preferences_item_update_boolean (const NautilusPreferencesItem *item)
{
gboolean value;
- g_assert (NAUTILUS_IS_PREFERENCES_ITEM (item));
- g_assert (item->details->item_type == NAUTILUS_PREFERENCE_ITEM_BOOLEAN);
+ g_return_if_fail (NAUTILUS_IS_PREFERENCES_ITEM (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);
@@ -440,8 +324,8 @@ preferences_item_create_boolean (NautilusPreferencesItem *item,
{
char *description;
- g_assert (NAUTILUS_IS_PREFERENCES_ITEM (item));
- g_assert (preference_name != NULL);
+ g_return_if_fail (NAUTILUS_IS_PREFERENCES_ITEM (item));
+ g_return_if_fail (nautilus_strlen (preference_name) > 0);
g_assert (item->details->preference_name != NULL);
description = nautilus_preferences_get_description (preference_name);
@@ -465,8 +349,8 @@ preferences_item_update_editable_string (const NautilusPreferencesItem *item)
{
char *current_value;
- g_assert (NAUTILUS_IS_PREFERENCES_ITEM (item));
- g_assert (item->details->item_type == NAUTILUS_PREFERENCE_ITEM_EDITABLE_STRING);
+ g_return_if_fail (NAUTILUS_IS_PREFERENCES_ITEM (item));
+ g_return_if_fail (item->details->item_type == NAUTILUS_PREFERENCE_ITEM_EDITABLE_STRING);
current_value = nautilus_preferences_get (item->details->preference_name);
@@ -481,12 +365,10 @@ preferences_item_create_editable_string (NautilusPreferencesItem *item,
{
char *description;
- g_assert (item != NULL);
- g_assert (preference_name != NULL);
+ g_return_if_fail (NAUTILUS_IS_PREFERENCES_ITEM (item));
+ g_return_if_fail (nautilus_strlen (preference_name) > 0);
- g_assert (item->details->preference_name != NULL);
description = nautilus_preferences_get_description (preference_name);
-
g_assert (description != NULL);
item->details->child = nautilus_text_caption_new ();
@@ -514,8 +396,8 @@ preferences_item_update_integer (const NautilusPreferencesItem *item)
{
char *current_value;
- g_assert (NAUTILUS_IS_PREFERENCES_ITEM (item));
- g_assert (item->details->item_type == NAUTILUS_PREFERENCE_ITEM_INTEGER);
+ g_return_if_fail (NAUTILUS_IS_PREFERENCES_ITEM (item));
+ g_return_if_fail (item->details->item_type == NAUTILUS_PREFERENCE_ITEM_INTEGER);
current_value = g_strdup_printf ("%d", nautilus_preferences_get_integer (item->details->preference_name));
@@ -530,10 +412,9 @@ preferences_item_create_integer (NautilusPreferencesItem *item,
{
char *description;
- g_assert (item != NULL);
- g_assert (preference_name != NULL);
+ g_return_if_fail (NAUTILUS_IS_PREFERENCES_ITEM (item));
+ g_return_if_fail (nautilus_strlen (preference_name) > 0);
- g_assert (item->details->preference_name != NULL);
description = nautilus_preferences_get_description (preference_name);
g_assert (description != NULL);
@@ -556,11 +437,10 @@ preferences_item_update_font_family (const NautilusPreferencesItem *item)
{
char *current_value;
- g_assert (NAUTILUS_IS_PREFERENCES_ITEM (item));
- g_assert (item->details->item_type == NAUTILUS_PREFERENCE_ITEM_FONT_FAMILY);
+ g_return_if_fail (NAUTILUS_IS_PREFERENCES_ITEM (item));
+ g_return_if_fail (item->details->item_type == NAUTILUS_PREFERENCE_ITEM_FONT_FAMILY);
current_value = nautilus_preferences_get (item->details->preference_name);
-
g_assert (current_value != NULL);
nautilus_string_picker_set_selected_string (NAUTILUS_STRING_PICKER (item->details->child), current_value);
@@ -569,22 +449,19 @@ preferences_item_update_font_family (const NautilusPreferencesItem *item)
}
static void
-preferences_item_create_font_family (NautilusPreferencesItem *item,
- const char *preference_name)
+preferences_item_create_font_family (NautilusPreferencesItem *item,
+ const char *preference_name)
{
- char *description;
- NautilusStringList *font_list;
+ char *description;
+ NautilusStringList *font_list;
- g_assert (item != NULL);
- g_assert (preference_name != NULL);
+ g_return_if_fail (NAUTILUS_IS_PREFERENCES_ITEM (item));
+ g_return_if_fail (nautilus_strlen (preference_name) > 0);
- g_assert (item->details->preference_name != NULL);
description = nautilus_preferences_get_description (preference_name);
-
- g_assert (description != NULL);
-
+ g_return_if_fail (description != NULL);
+
item->details->child = nautilus_string_picker_new ();
-
nautilus_caption_set_title_label (NAUTILUS_CAPTION (item->details->child), description);
g_free (description);
@@ -592,153 +469,23 @@ preferences_item_create_font_family (NautilusPreferencesItem *item,
/* FIXME bugzilla.eazel.com 1274: Need to query system for available fonts */
font_list = nautilus_string_list_new (TRUE);
- nautilus_string_list_insert (font_list, "helvetica");
- nautilus_string_list_insert (font_list, "times");
- nautilus_string_list_insert (font_list, "courier");
- nautilus_string_list_insert (font_list, "lucida");
+ nautilus_string_list_insert (font_list, _("helvetica"));
+ nautilus_string_list_insert (font_list, _("times"));
+ nautilus_string_list_insert (font_list, _("courier"));
+ nautilus_string_list_insert (font_list, _("lucida"));
nautilus_string_picker_set_string_list (NAUTILUS_STRING_PICKER (item->details->child), font_list);
nautilus_string_list_free (font_list);
- item->details->change_signal_ID =
- gtk_signal_connect (GTK_OBJECT (item->details->child),
- "changed",
- GTK_SIGNAL_FUNC (text_item_changed_callback),
- (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_string;
- guint index;
- gboolean result;
- GnomeVFSURI *base_uri, *uri;
-
- temp_str = nautilus_make_path (directory_uri, dir_name);
- base_uri_string = nautilus_make_path (temp_str, required_file);
- base_uri = gnome_vfs_uri_new (base_uri_string);
- g_free (temp_str);
- g_free (base_uri_string);
-
- result = FALSE;
- for (index = 0; index < NAUTILUS_N_ELEMENTS (icon_file_name_suffixes); index++) {
- uri = gnome_vfs_uri_append_string (base_uri, icon_file_name_suffixes[index]);
- result = gnome_vfs_uri_exists (uri);
- gnome_vfs_uri_unref (uri);
- if (result) {
- break;
- }
- }
-
- gnome_vfs_uri_unref (base_uri);
- g_free (base_uri);
- return result;
-}
-
-/* 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, char *required_file)
-{
- char *directory_uri;
- GnomeVFSResult result;
- GnomeVFSFileInfo *current_file_info;
- GList *list, *element;
- char *pixmap_directory;
-
- pixmap_directory = nautilus_get_pixmap_directory ();
-
- /* get the uri for the images directory */
- directory_uri = gnome_vfs_get_uri_from_local_path (pixmap_directory);
- g_free (pixmap_directory);
-
- result = gnome_vfs_directory_list_load (&list, directory_uri,
- GNOME_VFS_FILE_INFO_DEFAULT, NULL);
- if (result != GNOME_VFS_OK) {
- g_free(directory_uri);
- return;
- }
-
- /* interate through the directory for each file */
- for (element = list; element != NULL; element = element->next) {
- current_file_info = element->data;
- if ((current_file_info->type == GNOME_VFS_FILE_TYPE_DIRECTORY) &&
- (current_file_info->name[0] != '.')) {
- if (has_image_file(directory_uri, current_file_info->name, required_file))
- nautilus_string_list_insert (theme_list, current_file_info->name);
- }
- }
-
- g_free(directory_uri);
- gnome_vfs_file_info_list_free (list);
-}
-
-static void
-preferences_item_update_theme (const NautilusPreferencesItem *item)
-{
- char *current_value;
-
- g_assert (NAUTILUS_IS_PREFERENCES_ITEM (item));
- g_assert (item->details->item_type == NAUTILUS_PREFERENCE_ITEM_THEME);
-
- current_value = nautilus_preferences_get (item->details->preference_name);
-
- g_assert (current_value != NULL);
-
- nautilus_string_picker_set_selected_string (NAUTILUS_STRING_PICKER (item->details->child), current_value);
-
- g_free (current_value);
-}
-
-static void
-preferences_item_create_theme (NautilusPreferencesItem *item,
- const char *preference_name)
-{
- char *description;
- NautilusStringList *theme_list;
-
- g_assert (item != NULL);
- g_assert (preference_name != NULL);
-
- g_assert (item->details->preference_name != NULL);
- description = nautilus_preferences_get_description (preference_name);
-
- g_assert (description != NULL);
-
- item->details->child = nautilus_string_picker_new ();
-
- nautilus_caption_set_title_label (NAUTILUS_CAPTION (item->details->child), description);
-
- g_free (description);
-
- theme_list = nautilus_string_list_new (TRUE);
- nautilus_string_list_insert (theme_list, "default");
- add_icon_themes(theme_list, "i-directory");
-
- nautilus_string_picker_set_string_list (NAUTILUS_STRING_PICKER (item->details->child), theme_list);
- nautilus_string_list_free (theme_list);
-
- item->details->change_signal_ID =
- gtk_signal_connect (GTK_OBJECT (item->details->child),
- "changed",
- GTK_SIGNAL_FUNC (text_item_changed_callback),
- (gpointer) item);
+ item->details->change_signal_ID = 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,
+nautilus_preferences_item_new (const char *preference_name,
NautilusPreferencesItemType item_type)
{
NautilusPreferencesItem * item;
@@ -759,7 +506,7 @@ static void
enum_radio_group_changed_callback (GtkWidget *buttons, GtkWidget * button, gpointer user_data)
{
NautilusPreferencesItem *item;
- gint i;
+ int i;
g_assert (user_data != NULL);
g_assert (NAUTILUS_IS_PREFERENCES_ITEM (user_data));
@@ -771,7 +518,7 @@ enum_radio_group_changed_callback (GtkWidget *buttons, GtkWidget * button, gpoin
i = nautilus_radio_button_group_get_active_index (NAUTILUS_RADIO_BUTTON_GROUP (buttons));
nautilus_preferences_set_integer (item->details->preference_name,
- nautilus_preferences_enumeration_get_nth_value (item->details->preference_name, i));
+ nautilus_preferences_enumeration_get_nth_value (item->details->preference_name, i));
}
static void
@@ -882,12 +629,10 @@ nautilus_preferences_item_update_displayed_value (const NautilusPreferencesItem
preferences_item_update_font_family (item);
break;
- case NAUTILUS_PREFERENCE_ITEM_THEME:
- preferences_item_update_theme (item);
- break;
case NAUTILUS_PREFERENCE_ITEM_EDITABLE_STRING:
preferences_item_update_editable_string (item);
break;
+
case NAUTILUS_PREFERENCE_ITEM_INTEGER:
preferences_item_update_integer (item);
break;
@@ -906,10 +651,8 @@ update_text_settings_at_idle (NautilusPreferencesItem *preferences_item)
text = nautilus_text_caption_get_text (NAUTILUS_TEXT_CAPTION (preferences_item->details->child));
- if (text != NULL)
- {
+ if (text != NULL) {
nautilus_preferences_set (preferences_item->details->preference_name, text);
-
g_free (text);
}
diff --git a/libnautilus-private/nautilus-preferences-item.h b/libnautilus-private/nautilus-preferences-item.h
index c9c950371..11fba2436 100644
--- a/libnautilus-private/nautilus-preferences-item.h
+++ b/libnautilus-private/nautilus-preferences-item.h
@@ -67,16 +67,15 @@ typedef enum
NAUTILUS_PREFERENCE_ITEM_ENUM,
NAUTILUS_PREFERENCE_ITEM_SHORT_ENUM,
NAUTILUS_PREFERENCE_ITEM_FONT_FAMILY,
- NAUTILUS_PREFERENCE_ITEM_THEME,
NAUTILUS_PREFERENCE_ITEM_EDITABLE_STRING,
NAUTILUS_PREFERENCE_ITEM_INTEGER
} NautilusPreferencesItemType;
-GtkType nautilus_preferences_item_get_type (void);
-GtkWidget* nautilus_preferences_item_new (const gchar *preference_name,
- NautilusPreferencesItemType item_type);
-char * nautilus_preferences_item_get_name (const NautilusPreferencesItem *preferences_item);
-void nautilus_preferences_item_update_displayed_value (const NautilusPreferencesItem *preferences_item);
+GtkType nautilus_preferences_item_get_type (void);
+GtkWidget* nautilus_preferences_item_new (const char *preference_name,
+ NautilusPreferencesItemType item_type);
+char * nautilus_preferences_item_get_name (const NautilusPreferencesItem *preferences_item);
+void nautilus_preferences_item_update_displayed_value (const NautilusPreferencesItem *preferences_item);
END_GNOME_DECLS
diff --git a/libnautilus-private/nautilus-preferences-pane.c b/libnautilus-private/nautilus-preferences-pane.c
index 8d76cef98..f425e0194 100644
--- a/libnautilus-private/nautilus-preferences-pane.c
+++ b/libnautilus-private/nautilus-preferences-pane.c
@@ -90,14 +90,10 @@ nautilus_preferences_pane_destroy (GtkObject* object)
* NautilusPreferencesPane public methods
*/
GtkWidget *
-nautilus_preferences_pane_new (const gchar *pane_title,
- const gchar *pane_description)
+nautilus_preferences_pane_new (void)
{
NautilusPreferencesPane *preferences_pane;
- g_return_val_if_fail (pane_title != NULL, NULL);
- g_return_val_if_fail (pane_description != NULL, NULL);
-
preferences_pane = NAUTILUS_PREFERENCES_PANE
(gtk_widget_new (nautilus_preferences_pane_get_type (), NULL));
diff --git a/libnautilus-private/nautilus-preferences-pane.h b/libnautilus-private/nautilus-preferences-pane.h
index c1071a470..0b0fc3702 100644
--- a/libnautilus-private/nautilus-preferences-pane.h
+++ b/libnautilus-private/nautilus-preferences-pane.h
@@ -56,8 +56,7 @@ struct _NautilusPreferencesPaneClass
};
GtkType nautilus_preferences_pane_get_type (void);
-GtkWidget* nautilus_preferences_pane_new (const gchar *pane_title,
- const gchar *pane_description);
+GtkWidget* nautilus_preferences_pane_new (void);
GtkWidget *nautilus_preferences_pane_add_group (NautilusPreferencesPane *preferences_pane,
const char *group_title);
GtkWidget *nautilus_preferences_pane_add_item_to_nth_group (NautilusPreferencesPane *preferences_pane,
diff --git a/libnautilus-private/nautilus-string-list.c b/libnautilus-private/nautilus-string-list.c
index 9a2fd5f92..084d84085 100644
--- a/libnautilus-private/nautilus-string-list.c
+++ b/libnautilus-private/nautilus-string-list.c
@@ -212,6 +212,39 @@ nautilus_string_list_nth (const NautilusStringList *string_list, guint n)
}
/**
+ * nautilus_string_list_nth_as_integer
+ *
+ * @string_list: A NautilusStringList
+ * @n: Index of string to convert.
+ * @integer_result: Where to store the conversion result.
+ *
+ * Convert the nth string to an integer and store the result in &integer_result.
+ *
+ * Return value: Returns TRUE if the string to integer conversion was successful,
+ * FALSE otherwise.
+ */
+gboolean
+nautilus_string_list_nth_as_integer (const NautilusStringList *string_list,
+ guint n,
+ int *integer_result)
+{
+ const char *string;
+
+ g_return_val_if_fail (string_list != NULL, FALSE);
+ g_return_val_if_fail (integer_result != NULL, FALSE);
+
+ if (n >= g_list_length (string_list->strings)) {
+ if (!supress_out_of_bounds_warning) {
+ g_warning ("(n = %d) is out of bounds.", n);
+ }
+ return FALSE;
+ }
+
+ string = g_list_nth_data (string_list->strings, n);
+ return nautilus_str_to_int (string, integer_result);
+}
+
+/**
* nautilus_string_list_modify_nth
*
* @string_list: A NautilusStringList
@@ -1140,6 +1173,51 @@ nautilus_self_check_string_list (void)
nautilus_string_list_free (list);
nautilus_string_list_free (sorted_list);
}
+
+ /*
+ * nautilus_string_list_nth_as_integer
+ */
+ {
+ NautilusStringList *list;
+ const int untouched = 666;
+ int result;
+
+ list = nautilus_string_list_new_from_tokens ("word,c,0,1,20,xxx,foo,bar,-1", ",", TRUE);
+
+ result = untouched;
+ NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_string_list_nth_as_integer (list, 0, &result), FALSE);
+ NAUTILUS_CHECK_INTEGER_RESULT (result, untouched);
+
+ result = untouched;
+ NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_string_list_nth_as_integer (list, 1, &result), FALSE);
+ NAUTILUS_CHECK_INTEGER_RESULT (result, untouched);
+
+ result = untouched;
+ NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_string_list_nth_as_integer (list, 5, &result), FALSE);
+ NAUTILUS_CHECK_INTEGER_RESULT (result, untouched);
+
+ result = untouched;
+ NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_string_list_nth_as_integer (list, 6, &result), FALSE);
+ NAUTILUS_CHECK_INTEGER_RESULT (result, untouched);
+
+ result = untouched;
+ NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_string_list_nth_as_integer (list, 7, &result), FALSE);
+ NAUTILUS_CHECK_INTEGER_RESULT (result, untouched);
+
+ NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_string_list_nth_as_integer (list, 2, &result), TRUE);
+ NAUTILUS_CHECK_INTEGER_RESULT (result, 0);
+
+ NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_string_list_nth_as_integer (list, 3, &result), TRUE);
+ NAUTILUS_CHECK_INTEGER_RESULT (result, 1);
+
+ NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_string_list_nth_as_integer (list, 4, &result), TRUE);
+ NAUTILUS_CHECK_INTEGER_RESULT (result, 20);
+
+ NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_string_list_nth_as_integer (list, 8, &result), TRUE);
+ NAUTILUS_CHECK_INTEGER_RESULT (result, -1);
+
+ nautilus_string_list_free (list);
+ }
}
#endif /* !NAUTILUS_OMIT_SELF_CHECK */
diff --git a/libnautilus-private/nautilus-string-list.h b/libnautilus-private/nautilus-string-list.h
index 9c3816787..3bfd14a8c 100644
--- a/libnautilus-private/nautilus-string-list.h
+++ b/libnautilus-private/nautilus-string-list.h
@@ -68,6 +68,10 @@ void nautilus_string_list_clear (NautilusStri
/* Access the nth string in the collection. Returns an strduped string. */
char * nautilus_string_list_nth (const NautilusStringList *string_list,
guint n);
+/* Access the nth string as an integer. Return TRUE if the conversion was successful. */
+gboolean nautilus_string_list_nth_as_integer (const NautilusStringList *string_list,
+ guint n,
+ int *integer_result);
/* Modify the nth string in the collection. */
void nautilus_string_list_modify_nth (NautilusStringList *string_list,
guint n,
diff --git a/test/.cvsignore b/test/.cvsignore
index 79ebe3034..fba47c9d1 100644
--- a/test/.cvsignore
+++ b/test/.cvsignore
@@ -10,6 +10,7 @@ test-nautilus-clickable-image
test-nautilus-font
test-nautilus-font-picker
test-nautilus-font-simple
+test-nautilus-font-manager
test-nautilus-glyph
test-nautilus-glyph-simple
test-nautilus-image
diff --git a/test/Makefile.am b/test/Makefile.am
index f6c357977..9cd60bccd 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -35,6 +35,7 @@ noinst_PROGRAMS =\
test-nautilus-font \
test-nautilus-font-picker \
test-nautilus-font-simple \
+ test-nautilus-font-manager \
test-nautilus-glyph \
test-nautilus-glyph-simple \
test-nautilus-image \
@@ -70,6 +71,7 @@ test_nautilus_clickable_image_SOURCES = test-nautilus-clickable-image.c test.c
test_nautilus_font_SOURCES = test-nautilus-font.c test.c
test_nautilus_font_picker_SOURCES = test-nautilus-font-picker.c
test_nautilus_font_simple_SOURCES = test-nautilus-font-simple.c test.c
+test_nautilus_font_manager_SOURCES = test-nautilus-font-manager.c test.c
test_nautilus_glyph_SOURCES = test-nautilus-glyph.c test.c
test_nautilus_glyph_simple_SOURCES = test-nautilus-glyph-simple.c test.c
test_nautilus_image_SOURCES = test-nautilus-image.c
diff --git a/test/test-nautilus-font-manager.c b/test/test-nautilus-font-manager.c
new file mode 100644
index 000000000..0b34bb3ce
--- /dev/null
+++ b/test/test-nautilus-font-manager.c
@@ -0,0 +1,37 @@
+
+#include <config.h>
+
+#include "test.h"
+
+#include <libnautilus-extensions/nautilus-font-manager.h>
+
+static void
+font_iterator_callback (const char *foundry,
+ const char *family,
+ const char *weight,
+ const char *slant,
+ const char *set_width,
+ const char *char_set_registry,
+ const char *char_set_encoding,
+ gpointer callback_data)
+{
+
+ g_print ("%s-%s-%s-%s-%s-%s-%s\n",
+ foundry,
+ family,
+ weight,
+ slant,
+ set_width,
+ char_set_registry,
+ char_set_encoding);
+}
+
+int
+main (int argc, char* argv[])
+{
+ test_init (&argc, &argv);
+
+ nautilus_font_manager_for_each_font (font_iterator_callback, NULL);
+
+ return test_quit (EXIT_SUCCESS);
+}
diff --git a/test/test-nautilus-glyph-simple.c b/test/test-nautilus-glyph-simple.c
index c69bf15d0..8eaa06e9f 100644
--- a/test/test-nautilus-glyph-simple.c
+++ b/test/test-nautilus-glyph-simple.c
@@ -150,7 +150,5 @@ main (int argc, char* argv[])
gdk_pixbuf_unref (pixbuf);
gtk_object_unref (GTK_OBJECT (font));
- test_quit (0);
-
- return 0;
+ return test_quit (EXIT_SUCCESS);
}
diff --git a/test/test-nautilus-glyph.c b/test/test-nautilus-glyph.c
index c8016b4a9..287fda878 100644
--- a/test/test-nautilus-glyph.c
+++ b/test/test-nautilus-glyph.c
@@ -35,7 +35,7 @@ main (int argc, char* argv[])
const guint pixbuf_height = 480;
const gboolean has_alpha = FALSE;
const guint32 background_color = NAUTILUS_RGB_COLOR_WHITE;
- const char text[] = "Something";
+ const char text[] = "ù È É Ê Ë Ì Í Î Ï Ð Ñ Ò Ó Ô Õ Ö Ø Ù Ú Û Ü Ý Þ";
const gboolean solid_background = FALSE;
const guint font_size = 100;
const int opacity = NAUTILUS_OPACITY_FULLY_OPAQUE;
diff --git a/test/test-nautilus-labeled-image.c b/test/test-nautilus-labeled-image.c
index 208f9fdb7..c7d9565f2 100644
--- a/test/test-nautilus-labeled-image.c
+++ b/test/test-nautilus-labeled-image.c
@@ -115,5 +115,5 @@ main (int argc, char* argv[])
gtk_main ();
- return 0;
+ return test_quit (EXIT_SUCCESS);
}
diff --git a/test/test-nautilus-smooth-text-layout.c b/test/test-nautilus-smooth-text-layout.c
index 8fdde2c6a..7fc7dc899 100644
--- a/test/test-nautilus-smooth-text-layout.c
+++ b/test/test-nautilus-smooth-text-layout.c
@@ -136,7 +136,6 @@ main (int argc, char* argv[])
gdk_pixbuf_unref (pixbuf);
gtk_object_unref (GTK_OBJECT (font));
gtk_object_unref (GTK_OBJECT (bold_font));
- test_quit (0);
- return 0;
+ return test_quit (EXIT_SUCCESS);
}
diff --git a/test/test.c b/test/test.c
index 8de4c1504..d596b87ab 100644
--- a/test/test.c
+++ b/test/test.c
@@ -27,11 +27,16 @@ test_init (int *argc,
NULL);
}
-void
+int
test_quit (int exit_code)
{
gnome_vfs_shutdown ();
- gtk_main_quit ();
+
+ if (gtk_main_level () > 0) {
+ gtk_main_quit ();
+ }
+
+ return exit_code;
}
void
diff --git a/test/test.h b/test/test.h
index 0e7aefc0b..0b3c5f001 100644
--- a/test/test.h
+++ b/test/test.h
@@ -30,7 +30,7 @@
void test_init (int *argc,
char ***argv);
-void test_quit (int exit_code);
+int test_quit (int exit_code);
void test_delete_event (GtkWidget *widget,
GdkEvent *event,
gpointer callback_data);