nautilus/test/test.c
Ramiro Estrugo 24faaf9219 reviewed by: Pavel Cisler <pavel@eazel.com>
Maciej Stachowiak  <mjs@eazel.com>

		      Bugs:

		      6368 - Multibyte font handling in non smooth mode.
		      2673 - Need to hook up the new font picker to nautilus
		      1274 - Add support for picking a custom font

		      * components/history/Makefile.am:
		      * components/history/nautilus-history-view.c: (main):
		      Initialize gettext for the history component so it can display
		      localized strings.

		      * components/notes/nautilus-notes.c: (make_notes_view):
		      Set the notes widget font from preferences so it can be properly
		      localized.

		      * components/text/nautilus-text-view.c:
		      (nautilus_text_view_set_font):
		      Use the localized font name to make this work in locales other
		      than the default.

		      * libnautilus-extensions/Makefile.am:
		      Add a macro for finding data on the source tree for the situation
		      when 'make install' has not be run.

		      * libnautilus-extensions/nautilus-font-factory.c:
		      (nautilus_font_factory_get_font_by_family): Workaround the problem
		      that fully qualified localized fonts were being processed
		      incorrectly.  We simply leave them alone now.
		      (nautilus_font_factory_get_font_from_preferences): Use the
		      localized font string to make this work on more locales.

		      * libnautilus-extensions/nautilus-font-manager.h:
		      * libnautilus-extensions/nautilus-font-manager.c:
		      (font_description_table_find): New function to find a description
		      in a table.
		      (font_description_table_for_each): Change the return value to a
		      boolean to indicate whether to stop the iteration or not.  Switch
		      the order of an assert and assigned.
		      (collect_fonts_from_directory): Use macros for the mime type
		      strings.
		      (font_ignore_directory): Add more directories to ignore.
		      (font_manager_collect_font_tables): Change prepend to append to
		      get fonts in a better order (fallback and user fonts first)
		      , (font_table_list_find),
		      (free_font_tables), (ensure_global_font_table),
		      (nautilus_font_manager_for_each_font): Use just one global table
		      for all fonts instead of 3.
		      (nautilus_font_manager_get_default_font): Compute the default
		      dynamically to take user choices into account.  Make it work on
		      non installed nautilus builds.
		      (nautilus_font_manager_get_default_bold_font): Same as above for a
		      bold font.
		      (nautilus_font_manager_file_is_scalable_font): New function to
		      check that a file is really a scalable font:
		      (font_list_find_bold_callback), (nautilus_font_manager_get_bold),
		      (nautilus_font_manager_weight_is_bold): New functions to find a
		      bold font in the global tables.
		      (nautilus_self_check_font_manager): Make it work on not installed
		      nautilus builds and remove the hack where checks would on run for
		      the "ramiro" user.

		      * libnautilus-extensions/nautilus-font-picker.c:
		      (nautilus_font_picker_initialize), (font_list_find),
		      (font_picker_update_styles), (font_picker_populate),
		      (font_picker_font_changed_callback),
		      (font_picker_style_changed_callback), (font_find_style),
		      (ignore_font), (font_make_name), (font_make_style),
		      (global_font_list_free), (font_list_count_families),
		      (global_font_list_get), (global_font_list_populate_callback),
		      (nautilus_font_picker_get_selected_font),
		      (nautilus_font_picker_set_selected_font):
		      Make the font list global and not per widget instance.  Use better
		      labels for the font styles.  Use better labels for font names
		      (foundry and family vs just family depending on how many families
		      of the same font are found)

		      * libnautilus-extensions/nautilus-global-preferences.h:
		      * libnautilus-extensions/nautilus-global-preferences.c:
		      (global_preferences_install_font_defaults): Add new smooth font
		      preference for the icon container.
		      (nautilus_global_preferences_get_smooth_font): New function to
		      safely get a smooth font out of preferences.

		      * libnautilus-extensions/nautilus-icon-container.c:
		      (nautilus_icon_container_initialize): Use the localized version of
		      the font strings and add a FIXME for the problem of checking these
		      in many disparate places in nautilus.

		      * libnautilus-extensions/nautilus-program-chooser.c:
		      (program_file_pair_get_program_name_for_display): Use the
		      localized version of the application name strings.

		      * libnautilus-extensions/nautilus-scalable-font.h:
		      * libnautilus-extensions/nautilus-scalable-font.c:
		      (nautilus_scalable_font_initialize_class),
		      (nautilus_scalable_font_initialize),
		      (nautilus_scalable_font_destroy), (nautilus_scalable_font_new),
		      (nautilus_scalable_font_make_bold),
		      (nautilus_scalable_font_get_default_font),
		      (nautilus_scalable_font_get_default_bold_font),
		      (free_global_font_handle_table),
		      (initialize_global_stuff_if_needed),
		      (nautilus_scalable_font_get_rsvg_handle):
		      Simplify this class a lot by using the font manager.  No longer
		      need to manage font lookup and queries.

		      * libnautilus-extensions/nautilus-smooth-text-layout-cache.c:
		      (nautilus_self_check_smooth_text_layout_cache): Fix a comment.
		      Dont hardcode the font family.  Use the default font.  Remove the
		      #ifdef hacker for "before make install fonts broken" problem which
		      is now fixed.

		      * src/file-manager/fm-directory-view.h:
		      * src/file-manager/fm-directory-view.c:
		      (directory_view_smooth_font_changed_callback),
		      (fm_directory_view_initialize), (fm_directory_view_destroy):
		      Add method for responding to changes in the smooth font for AA
		      mode of the icon container.

		      * src/file-manager/fm-icon-view.c:
		      (fm_icon_view_smooth_font_changed),
		      (fm_icon_view_initialize_class),
		      (fm_icon_view_update_icon_container_smooth_font),
		      (create_icon_container):
		      Add support for responding to change in the smooth font.  Update
		      the icon container's smooth font on such changes.

		      * src/nautilus-about.c: (nautilus_about_draw_info):
		      Change the offset of the "Nautilus" title which broken when jsh
		      make glyphs render properly taking the baseline into account.

		      * src/nautilus-sidebar-title.c: (update_font):
		      Use the localized font name.

		      * src/nautilus-sidebar.c: (nautilus_sidebar_add_panel),
		      (nautilus_sidebar_remove_panel):
		      Use the localized sidebar tabs descriptions.

		      * src/nautilus-window.c: (create_view_as_menu_item):
		      Use the localized "View as" labels.

		      * test/test-nautilus-font-manager.c: (font_iterator_callback):
		      * test/test-nautilus-font-picker.c: (update_font),
		      (font_changed_update_label_callback),
		      (font_changed_update_file_name_callback),
		      (use_defalt_font_callback), (use_defalt_bold_font_callback),
		      (use_defalt_font_update_picker_callback),
		      (use_defalt_bold_font_update_picker_callback), (main):
		      * test/test.c: (test_quit):
		      Updates for changes in font manager and font picker.
2001-03-05 08:15:06 +00:00

367 lines
7.6 KiB
C

#include "test.h"
#include <libart_lgpl/art_rgb.h>
#include <libnautilus-extensions/nautilus-preferences.h>
void
test_init (int *argc,
char ***argv)
{
gtk_init (argc, argv);
gdk_rgb_init ();
gnome_vfs_init ();
nautilus_make_warnings_and_criticals_stop_in_debugger
(G_LOG_DOMAIN, g_log_domain_glib,
"Bonobo",
"Gdk",
"GnomeUI",
"GnomeVFS",
"GnomeVFS-CORBA",
"GnomeVFS-pthread",
"Gtk",
"Nautilus",
"Nautilus-Authenticate",
"Nautilus-Tree",
"ORBit",
NULL);
}
int
test_quit (int exit_code)
{
//gnome_vfs_shutdown ();
if (gtk_main_level () > 0) {
gtk_main_quit ();
}
return exit_code;
}
void
test_delete_event (GtkWidget *widget,
GdkEvent *event,
gpointer callback_data)
{
test_quit (0);
}
GtkWidget *
test_window_new (const char *title, guint border_width)
{
GtkWidget *window;
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
if (title != NULL) {
gtk_window_set_title (GTK_WINDOW (window), title);
}
gtk_signal_connect (GTK_OBJECT (window),
"delete_event",
GTK_SIGNAL_FUNC (test_delete_event),
NULL);
gtk_window_set_policy (GTK_WINDOW (window), TRUE, TRUE, FALSE);
gtk_container_set_border_width (GTK_CONTAINER (window), border_width);
return window;
}
void
test_gtk_widget_set_background_image (GtkWidget *widget,
const char *image_name)
{
NautilusBackground *background;
char *uri;
g_return_if_fail (GTK_IS_WIDGET (widget));
g_return_if_fail (image_name != NULL);
background = nautilus_get_widget_background (widget);
uri = g_strdup_printf ("file://%s/%s", NAUTILUS_DATADIR, image_name);
nautilus_background_set_image_uri (background, uri);
g_free (uri);
}
void
test_gtk_widget_set_background_color (GtkWidget *widget,
const char *color_spec)
{
NautilusBackground *background;
g_return_if_fail (GTK_IS_WIDGET (widget));
g_return_if_fail (color_spec != NULL);
background = nautilus_get_widget_background (widget);
nautilus_background_set_color (background, color_spec);
}
GdkPixbuf *
test_pixbuf_new_named (const char *name, float scale)
{
GdkPixbuf *pixbuf;
char *path;
g_return_val_if_fail (name != NULL, NULL);
g_return_val_if_fail (scale >= 0.0, NULL);
if (name[0] == '/') {
path = g_strdup (name);
} else {
path = g_strdup_printf ("%s/%s", NAUTILUS_DATADIR, name);
}
pixbuf = gdk_pixbuf_new_from_file (path);
g_free (path);
g_return_val_if_fail (pixbuf != NULL, NULL);
if (scale != 1.0) {
GdkPixbuf *scaled;
float width = gdk_pixbuf_get_width (pixbuf) * scale;
float height = gdk_pixbuf_get_width (pixbuf) * scale;
scaled = gdk_pixbuf_scale_simple (pixbuf, width, height, GDK_INTERP_BILINEAR);
gdk_pixbuf_unref (pixbuf);
g_return_val_if_fail (scaled != NULL, NULL);
pixbuf = scaled;
}
return pixbuf;
}
GtkWidget *
test_image_new (const char *pixbuf_name,
const char *tile_name,
float scale,
gboolean with_background)
{
GtkWidget *image;
if (with_background) {
image = nautilus_image_new_with_background (NULL);
} else {
image = nautilus_image_new (NULL);
}
if (pixbuf_name != NULL) {
GdkPixbuf *pixbuf;
pixbuf = test_pixbuf_new_named (pixbuf_name, scale);
if (pixbuf != NULL) {
nautilus_image_set_pixbuf (NAUTILUS_IMAGE (image), pixbuf);
gdk_pixbuf_unref (pixbuf);
}
}
if (tile_name != NULL) {
GdkPixbuf *tile_pixbuf;
tile_pixbuf = test_pixbuf_new_named (tile_name, 1.0);
if (tile_pixbuf != NULL) {
nautilus_image_set_tile_pixbuf (NAUTILUS_IMAGE (image), tile_pixbuf);
gdk_pixbuf_unref (tile_pixbuf);
}
}
return image;
}
GtkWidget *
test_label_new (const char *text,
const char *tile_name,
gboolean with_background,
int num_sizes_larger)
{
GtkWidget *label;
if (text == NULL) {
text = "Foo";
}
if (with_background) {
label = nautilus_label_new_with_background (text);
} else {
label = nautilus_label_new (text);
}
if (num_sizes_larger < 0) {
nautilus_label_make_smaller (NAUTILUS_LABEL (label), ABS (num_sizes_larger));
} else if (num_sizes_larger > 0) {
nautilus_label_make_larger (NAUTILUS_LABEL (label), num_sizes_larger);
}
if (tile_name != NULL) {
GdkPixbuf *tile_pixbuf;
tile_pixbuf = test_pixbuf_new_named (tile_name, 1.0);
if (tile_pixbuf != NULL) {
nautilus_label_set_tile_pixbuf (NAUTILUS_LABEL (label), tile_pixbuf);
gdk_pixbuf_unref (tile_pixbuf);
}
}
return label;
}
/* Preferences hacks */
void
test_text_caption_set_text_for_int_preferences (NautilusTextCaption *text_caption,
const char *name)
{
int int_value;
char *text;
g_return_if_fail (NAUTILUS_IS_TEXT_CAPTION (text_caption));
g_return_if_fail (name != NULL);
int_value = nautilus_preferences_get_integer (name);
text = g_strdup_printf ("%d", int_value);
nautilus_text_caption_set_text (NAUTILUS_TEXT_CAPTION (text_caption), text);
g_free (text);
}
void
test_text_caption_set_text_for_string_preferences (NautilusTextCaption *text_caption,
const char *name)
{
char *text;
g_return_if_fail (NAUTILUS_IS_TEXT_CAPTION (text_caption));
g_return_if_fail (name != NULL);
text = nautilus_preferences_get (name);
nautilus_text_caption_set_text (NAUTILUS_TEXT_CAPTION (text_caption), text);
g_free (text);
}
void
test_text_caption_set_text_for_default_int_preferences (NautilusTextCaption *text_caption,
const char *name)
{
int int_value;
char *text;
g_return_if_fail (NAUTILUS_IS_TEXT_CAPTION (text_caption));
g_return_if_fail (name != NULL);
int_value = 0;
text = g_strdup_printf ("%d", int_value);
nautilus_text_caption_set_text (NAUTILUS_TEXT_CAPTION (text_caption), text);
g_free (text);
}
void
test_text_caption_set_text_for_default_string_preferences (NautilusTextCaption *text_caption,
const char *name)
{
char *text;
g_return_if_fail (NAUTILUS_IS_TEXT_CAPTION (text_caption));
g_return_if_fail (name != NULL);
text = g_strdup ("");
nautilus_text_caption_set_text (NAUTILUS_TEXT_CAPTION (text_caption), text);
g_free (text);
}
int
test_text_caption_get_text_as_int (const NautilusTextCaption *text_caption)
{
int result = 0;
char *text;
g_return_val_if_fail (NAUTILUS_IS_TEXT_CAPTION (text_caption), 0);
text = nautilus_text_caption_get_text (text_caption);
nautilus_eat_str_to_int (text, &result);
return result;
}
void
test_window_set_title_with_pid (GtkWindow *window,
const char *title)
{
char *tmp;
g_return_if_fail (GTK_IS_WINDOW (window));
tmp = g_strdup_printf ("%d: %s", getpid (), title);
gtk_window_set_title (GTK_WINDOW (window), tmp);
g_free (tmp);
}
void
test_pixbuf_draw_rectangle_tiled (GdkPixbuf *pixbuf,
const char *tile_name,
int x0,
int y0,
int x1,
int y1,
int opacity)
{
ArtIRect area;
GdkPixbuf *tile_pixbuf;
g_return_if_fail (nautilus_gdk_pixbuf_is_valid (pixbuf));
g_return_if_fail (tile_name != NULL);
g_return_if_fail (opacity > NAUTILUS_OPACITY_FULLY_TRANSPARENT);
g_return_if_fail (opacity <= NAUTILUS_OPACITY_FULLY_OPAQUE);
tile_pixbuf = test_pixbuf_new_named (tile_name, 1.0);
g_return_if_fail (tile_pixbuf != NULL);
if (x0 == -1 && y0 == -1 && x1 == -1 && y1 == -1) {
NautilusDimensions dimensions;
dimensions = nautilus_gdk_pixbuf_get_dimensions (pixbuf);
area = nautilus_art_irect_assign_dimensions (0, 0, &dimensions);
} else {
g_return_if_fail (x0 >= 0);
g_return_if_fail (y0 >= 0);
g_return_if_fail (x1 > x0);
g_return_if_fail (y1 > y0);
area.x0 = x0;
area.y0 = y0;
area.x1 = x1;
area.y1 = y1;
}
nautilus_gdk_pixbuf_draw_to_pixbuf_tiled (tile_pixbuf,
pixbuf,
&area,
gdk_pixbuf_get_width (tile_pixbuf),
gdk_pixbuf_get_height (tile_pixbuf),
0,
0,
opacity,
GDK_INTERP_NEAREST);
gdk_pixbuf_unref (tile_pixbuf);
}