summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDarin Adler <darin@src.gnome.org>2000-01-07 00:07:34 +0000
committerDarin Adler <darin@src.gnome.org>2000-01-07 00:07:34 +0000
commit313469f41318c61679368f9fa5973151f5f6500b (patch)
tree3ef5110ac2fadd29561c2ad4203a48b06b2e2ca8
parent5abab532aa672b3febfbb97017fc42da767d9b97 (diff)
downloadnautilus-313469f41318c61679368f9fa5973151f5f6500b.tar.gz
Moved self-check framework into libnautilus. Added functions so each
check will report if it fails instead of just aborting. Added new functions to manage a string that specifies a color or gradient, and added tests for the new functions.
-rw-r--r--ChangeLog-2000041427
-rw-r--r--libnautilus-extensions/Makefile.am4
-rw-r--r--libnautilus-extensions/gdk-extensions.c335
-rw-r--r--libnautilus-extensions/gdk-extensions.h62
-rw-r--r--libnautilus-extensions/nautilus-lib-self-check-functions.c (renamed from src/nautilus-self-checks.h)21
-rw-r--r--libnautilus-extensions/nautilus-lib-self-check-functions.h38
-rw-r--r--libnautilus-extensions/nautilus-self-checks.c120
-rw-r--r--libnautilus-extensions/nautilus-self-checks.h54
-rw-r--r--libnautilus-private/Makefile.am4
-rw-r--r--libnautilus-private/gdk-extensions.c335
-rw-r--r--libnautilus-private/gdk-extensions.h62
-rw-r--r--libnautilus-private/nautilus-lib-self-check-functions.c39
-rw-r--r--libnautilus-private/nautilus-lib-self-check-functions.h38
-rw-r--r--libnautilus-private/nautilus-self-checks.c120
-rw-r--r--libnautilus-private/nautilus-self-checks.h54
-rw-r--r--libnautilus/Makefile.am4
-rw-r--r--libnautilus/gdk-extensions.c335
-rw-r--r--libnautilus/gdk-extensions.h62
-rw-r--r--libnautilus/nautilus-lib-self-check-functions.c39
-rw-r--r--libnautilus/nautilus-lib-self-check-functions.h38
-rw-r--r--libnautilus/nautilus-self-checks.c120
-rw-r--r--libnautilus/nautilus-self-checks.h54
-rw-r--r--src/Makefile.am36
-rw-r--r--src/file-manager/fm-directory.c60
-rw-r--r--src/file-manager/fm-vfs-directory.c71
-rw-r--r--src/nautilus-main.c29
-rw-r--r--src/nautilus-self-check-functions.c (renamed from src/nautilus-self-checks.c)12
-rw-r--r--src/nautilus-self-check-functions.h11
-rw-r--r--src/ntl-main.c29
29 files changed, 2044 insertions, 169 deletions
diff --git a/ChangeLog-20000414 b/ChangeLog-20000414
index 96c43bab1..121c3a000 100644
--- a/ChangeLog-20000414
+++ b/ChangeLog-20000414
@@ -1,3 +1,30 @@
+2000-01-06 Darin Adler <darin@eazel.com>
+
+ * libnautilus/Makefile.am,
+ libnautilus/nautilus-lib-self-check-functions.c,
+ libnautilus/nautilus-lib-self-check-functions.h,
+ libnautilus/nautilus-self-checks.c,
+ libnautilus/nautilus-self-checks.h, src/Makefile.am,
+ src/nautilus-self-check-functions.c,
+ src/nautilus-self-check-functions.h, src/nautilus-self-checks.c,
+ src/nautilus-self-checks.h, src/ntl-main.c (main),
+ src/file-manager/fm-directory.c,
+ src/file-manager/fm-vfs-directory.c: Moved self-check framework
+ into libnautilus. Added functions so each check will report if it
+ fails instead of just aborting.
+
+ * src/gdk-extensions.c, src/gdk-extensions.h
+ (nautilus_gradient_new, nautilus_gradient_is_gradient,
+ nautilus_gradient_get_start_color_spec,
+ nautilus_gradient_get_end_color_spec,
+ nautilus_gradient_is_horizontal,
+ nautilus_gradient_set_left_color_spec,
+ nautilus_gradient_set_top_color_spec,
+ nautilus_gradient_set_right_color_spec,
+ nautilus_gradient_set_bottom_color_spec): Added new functions to
+ manage a string that specifies a color or gradient, and added
+ tests for the new functions.
+
2000-01-06 John Sullivan <sullivan@eazel.com>
* src/ntl-app.h: src/ntl-app.c: (nautilus_app_exiting):
diff --git a/libnautilus-extensions/Makefile.am b/libnautilus-extensions/Makefile.am
index 719d7d76d..dc583e7f4 100644
--- a/libnautilus-extensions/Makefile.am
+++ b/libnautilus-extensions/Makefile.am
@@ -23,6 +23,8 @@ libnautilusinclude_HEADERS= \
gtkscrollframe.h \
nautilus.h \
nautilus-file-utilities.h \
+ nautilus-lib-self-check-functions.c \
+ nautilus-self-checks.c \
ntl-content-view-client.h \
ntl-meta-view-client.h \
ntl-view-client.h
@@ -35,6 +37,8 @@ libnautilus_la_SOURCES=$(nautilus_idl_sources) \
gtkflist.c \
gtkscrollframe.c \
nautilus-file-utilities.c \
+ nautilus-lib-self-check-functions.c \
+ nautilus-self-checks.c \
ntl-content-view-client.c \
ntl-meta-view-client.c \
ntl-view-client.c \
diff --git a/libnautilus-extensions/gdk-extensions.c b/libnautilus-extensions/gdk-extensions.c
index 0f3184f3e..8f145b5b6 100644
--- a/libnautilus-extensions/gdk-extensions.c
+++ b/libnautilus-extensions/gdk-extensions.c
@@ -28,7 +28,9 @@
#include "gdk-extensions.h"
-#include "../src/nautilus-self-check-functions.h"
+#include "nautilus-lib-self-check-functions.h"
+
+#include <string.h>
#define GRADIENT_BAND_SIZE 4
@@ -178,30 +180,329 @@ nautilus_interpolate_color (gdouble ratio,
interpolated_color->blue = start_color->blue * (1.0 - ratio) + end_color->blue * ratio;
}
+/**
+ * nautilus_gradient_new
+ * @start_color: Color for the top or left.
+ * @end_color: Color for the bottom or right.
+ * @is_horizontal: Direction of the gradient.
+ *
+ * Create a string that combines the start and end colors along
+ * with the direction of the gradient in a standard format.
+ */
+char *
+nautilus_gradient_new (const char *start_color,
+ const char *end_color,
+ gboolean is_horizontal)
+{
+ g_return_val_if_fail (start_color != NULL, g_strdup (""));
+ g_return_val_if_fail (end_color != NULL, g_strdup (""));
+ g_return_val_if_fail (is_horizontal == FALSE || is_horizontal == TRUE, g_strdup (""));
+
+ /* Handle the special case where the start and end colors are identical.
+ Handle the special case where the end color is an empty string.
+ */
+ if (strcmp(start_color, end_color) == 0 || end_color[0] == '\0')
+ return g_strdup (start_color);
+
+ /* Handle the special case where the start color is an empty string. */
+ if (start_color[0] == '\0')
+ return g_strdup (end_color);
+
+ /* Handle the general case. */
+ return g_strconcat (start_color, "-", end_color, is_horizontal ? ":h" : NULL, NULL);
+}
+
+/**
+ * nautilus_gradient_is_gradient
+ * @gradient_spec: A gradient spec. string.
+ *
+ * Return true if the spec. specifies a gradient instead of a solid color.
+ */
+gboolean
+nautilus_gradient_is_gradient (const char *gradient_spec)
+{
+ g_return_val_if_fail (gradient_spec != NULL, FALSE);
+
+ return strchr (gradient_spec, '-') != NULL;
+}
+
+static char *
+nautilus_gradient_strip_trailing_direction_if_any (const char *gradient_spec)
+{
+ size_t length;
+
+ g_return_val_if_fail (gradient_spec != NULL, g_strdup (""));
+
+ length = strlen (gradient_spec);
+ if (length >= 2 && gradient_spec[length - 2] == ':'
+ && (gradient_spec[length - 1] == 'v' || gradient_spec[length - 1] == 'h'))
+ length -= 2;
+
+ return g_strndup (gradient_spec, length);
+}
+
+/**
+ * nautilus_gradient_get_start_color_spec
+ * @gradient_spec: A gradient spec. string.
+ *
+ * Return the start color.
+ * This may be the entire gradient_spec if it's a solid color.
+ */
+char *
+nautilus_gradient_get_start_color_spec (const char *gradient_spec)
+{
+ const char *separator;
+
+ g_return_val_if_fail (gradient_spec != NULL, g_strdup (""));
+
+ separator = strchr (gradient_spec, '-');
+ if (separator == NULL)
+ return nautilus_gradient_strip_trailing_direction_if_any (gradient_spec);
+
+ return g_strndup (gradient_spec, separator - gradient_spec);
+}
+
+/**
+ * nautilus_gradient_get_end_color_spec
+ * @gradient_spec: A gradient spec. string.
+ *
+ * Return the end color.
+ * This may be the entire gradient_spec if it's a solid color.
+ */
+char *
+nautilus_gradient_get_end_color_spec (const char *gradient_spec)
+{
+ const char *separator;
+
+ g_return_val_if_fail (gradient_spec != NULL, g_strdup (""));
+
+ separator = strchr (gradient_spec, '-');
+ return nautilus_gradient_strip_trailing_direction_if_any
+ (separator != NULL ? separator + 1 : gradient_spec);
+}
+
+/* Do the work shared by all the set_color_spec functions below. */
+static char *
+nautilus_gradient_set_edge_color (const char *gradient_spec,
+ const char *edge_color,
+ gboolean is_horizontal,
+ gboolean change_end)
+{
+ char *opposite_color;
+ char *result;
+
+ g_return_val_if_fail (gradient_spec != NULL, g_strdup (""));
+ g_return_val_if_fail (edge_color != NULL, g_strdup (gradient_spec));
+
+ /* Get the color from the existing gradient spec. for the opposite
+ edge. This will parse away all the stuff we don't want from the
+ old gradient spec.
+ */
+ opposite_color = change_end
+ ? nautilus_gradient_get_start_color_spec (gradient_spec)
+ : nautilus_gradient_get_end_color_spec (gradient_spec);
+
+ /* Create a new gradient spec. The nautilus_gradient_new function handles
+ some special cases, so we don't have to bother with them here.
+ */
+ result = nautilus_gradient_new (change_end ? opposite_color : edge_color,
+ change_end ? edge_color : opposite_color,
+ is_horizontal);
+
+ g_free (opposite_color);
+
+ return result;
+}
+
+/**
+ * nautilus_gradient_set_left_color_spec
+ * @gradient_spec: A gradient spec. string.
+ * @left_color: Color spec. to replace left color with.
+ *
+ * Changes the left color to what's passed in.
+ * This creates a horizontal gradient.
+ */
+char *
+nautilus_gradient_set_left_color_spec (const char *gradient_spec,
+ const char *left_color)
+{
+ return nautilus_gradient_set_edge_color (gradient_spec, left_color, TRUE, FALSE);
+}
+
+/**
+ * nautilus_gradient_set_top_color_spec
+ * @gradient_spec: A gradient spec. string.
+ * @top_color: Color spec. to replace top color with.
+ *
+ * Changes the top color to what's passed in.
+ * This creates a vertical gradient.
+ */
+char *
+nautilus_gradient_set_top_color_spec (const char *gradient_spec,
+ const char *top_color)
+{
+ return nautilus_gradient_set_edge_color (gradient_spec, top_color, FALSE, FALSE);
+}
+
+/**
+ * nautilus_gradient_set_right_color_spec
+ * @gradient_spec: A gradient spec. string.
+ * @right_color: Color spec. to replace right color with.
+ *
+ * Changes the right color to what's passed in.
+ * This creates a horizontal gradient.
+ */
+char *
+nautilus_gradient_set_right_color_spec (const char *gradient_spec,
+ const char *right_color)
+{
+ return nautilus_gradient_set_edge_color (gradient_spec, right_color, TRUE, TRUE);
+}
+
+/**
+ * nautilus_gradient_set_bottom_color_spec
+ * @gradient_spec: A gradient spec. string.
+ * @bottom_color: Color spec. to replace bottom color with.
+ *
+ * Changes the bottom color to what's passed in.
+ * This creates a vertical gradient.
+ */
+char *
+nautilus_gradient_set_bottom_color_spec (const char *gradient_spec,
+ const char *bottom_color)
+{
+ return nautilus_gradient_set_edge_color (gradient_spec, bottom_color, FALSE, TRUE);
+}
+
#if ! defined (NAUTILUS_OMIT_SELF_CHECK)
-static void
-self_check_interpolate(gdouble ratio,
- gushort r1, gushort g1, gushort b1,
- gushort r2, gushort g2, gushort b2,
- gushort r3, gushort g3, gushort b3)
+#include <stdio.h>
+
+static GdkColor
+nautilus_self_check_interpolate (gdouble ratio,
+ gushort r1, gushort g1, gushort b1,
+ gushort r2, gushort g2, gushort b2)
{
- GdkColor start_color = { 0, r1, g1, b1 };
- GdkColor end_color = { 0, r2, g2, b2 };
+ GdkColor start_color;
+ GdkColor end_color;
GdkColor interpolated_color;
- nautilus_interpolate_color(ratio, &start_color, &end_color, &interpolated_color);
- g_assert(interpolated_color.red == r3);
- g_assert(interpolated_color.red == g3);
- g_assert(interpolated_color.red == b3);
+
+ start_color.red = r1;
+ start_color.green = g1;
+ start_color.blue = b1;
+
+ end_color.red = r2;
+ end_color.green = g2;
+ end_color.blue = b2;
+
+ nautilus_interpolate_color (ratio, &start_color, &end_color, &interpolated_color);
+
+ return interpolated_color;
}
void
-self_check_gdk_extensions (void)
+nautilus_self_check_gdk_extensions (void)
{
- self_check_interpolate(0.0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
- self_check_interpolate(0.0, 0, 0, 0, 0xFFFF, 0xFFFF, 0xFFFF, 0, 0, 0);
- self_check_interpolate(0.5, 0, 0, 0, 0xFFFF, 0xFFFF, 0xFFFF, 0x7FFF, 0x7FFF, 0x7FFF);
- self_check_interpolate(1.0, 0, 0, 0, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF);
+ /* nautilus_interpolate_color */
+ NAUTILUS_CHECK_INTEGER_RESULT (nautilus_self_check_interpolate (0.0, 0, 0, 0, 0, 0, 0).red, 0);
+ NAUTILUS_CHECK_INTEGER_RESULT (nautilus_self_check_interpolate (0.0, 0, 0, 0, 0, 0, 0).green, 0);
+ NAUTILUS_CHECK_INTEGER_RESULT (nautilus_self_check_interpolate (0.0, 0, 0, 0, 0, 0, 0).blue, 0);
+ NAUTILUS_CHECK_INTEGER_RESULT (nautilus_self_check_interpolate (0.0, 0, 0, 0, 0xFFFF, 0xFFFF, 0xFFFF).red, 0);
+ NAUTILUS_CHECK_INTEGER_RESULT (nautilus_self_check_interpolate (0.0, 0, 0, 0, 0xFFFF, 0xFFFF, 0xFFFF).green, 0);
+ NAUTILUS_CHECK_INTEGER_RESULT (nautilus_self_check_interpolate (0.0, 0, 0, 0, 0xFFFF, 0xFFFF, 0xFFFF).blue, 0);
+ NAUTILUS_CHECK_INTEGER_RESULT (nautilus_self_check_interpolate (0.5, 0, 0, 0, 0xFFFF, 0xFFFF, 0xFFFF).red, 0x7FFF);
+ NAUTILUS_CHECK_INTEGER_RESULT (nautilus_self_check_interpolate (0.5, 0, 0, 0, 0xFFFF, 0xFFFF, 0xFFFF).green, 0x7FFF);
+ NAUTILUS_CHECK_INTEGER_RESULT (nautilus_self_check_interpolate (0.5, 0, 0, 0, 0xFFFF, 0xFFFF, 0xFFFF).blue, 0x7FFF);
+ NAUTILUS_CHECK_INTEGER_RESULT (nautilus_self_check_interpolate (1.0, 0, 0, 0, 0xFFFF, 0xFFFF, 0xFFFF).red, 0xFFFF);
+ NAUTILUS_CHECK_INTEGER_RESULT (nautilus_self_check_interpolate (1.0, 0, 0, 0, 0xFFFF, 0xFFFF, 0xFFFF).green, 0xFFFF);
+ NAUTILUS_CHECK_INTEGER_RESULT (nautilus_self_check_interpolate (1.0, 0, 0, 0, 0xFFFF, 0xFFFF, 0xFFFF).blue, 0xFFFF);
+
+ /* nautilus_fill_rectangle */
+ /* Make a GdkImage and fill it, maybe? */
+
+ /* nautilus_fill_rectangle_with_color */
+
+ /* nautilus_fill_rectangle_with_gradient */
+
+ /* nautilus_gradient_new */
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_new ("", "", FALSE), "");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_new ("a", "b", FALSE), "a-b");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_new ("a", "b", TRUE), "a-b:h");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_new ("a", "a", FALSE), "a");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_new ("a", "a", TRUE), "a");
+
+ /* nautilus_gradient_is_gradient */
+ NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_gradient_is_gradient (""), FALSE);
+ NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_gradient_is_gradient ("-"), TRUE);
+ NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_gradient_is_gradient ("a"), FALSE);
+ NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_gradient_is_gradient ("a-b"), TRUE);
+ NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_gradient_is_gradient ("a-b:h"), TRUE);
+
+ /* nautilus_gradient_get_start_color_spec */
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_get_start_color_spec (""), "");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_get_start_color_spec ("-"), "");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_get_start_color_spec ("a"), "a");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_get_start_color_spec ("a-b"), "a");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_get_start_color_spec ("a-"), "a");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_get_start_color_spec ("-b"), "");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_get_start_color_spec ("a:h"), "a");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_get_start_color_spec ("a:v"), "a");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_get_start_color_spec ("a:c"), "a:c");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_get_start_color_spec ("a:-b"), "a:");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_get_start_color_spec ("a:-b:v"), "a:");
+
+ /* nautilus_gradient_get_end_color_spec */
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_get_end_color_spec (""), "");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_get_end_color_spec ("-"), "");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_get_end_color_spec ("a"), "a");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_get_end_color_spec ("a-b"), "b");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_get_end_color_spec ("a-"), "");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_get_end_color_spec ("-b"), "b");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_get_end_color_spec ("a:h"), "a");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_get_end_color_spec ("a:v"), "a");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_get_end_color_spec ("a:c"), "a:c");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_get_end_color_spec ("a:-b"), "b");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_get_end_color_spec ("a:-b:v"), "b");
+
+ /* nautilus_gradient_set_left_color_spec */
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_set_left_color_spec ("", ""), "");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_set_left_color_spec ("", "a"), "a");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_set_left_color_spec ("a", ""), "a");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_set_left_color_spec ("a", "a"), "a");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_set_left_color_spec ("a", "b"), "b-a:h");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_set_left_color_spec ("a-c:v", "b"), "b-c:h");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_set_left_color_spec ("a-c:v", "c"), "c");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_set_left_color_spec ("a:-b:v", "d"), "d-b:h");
+
+ /* nautilus_gradient_set_top_color_spec */
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_set_top_color_spec ("", ""), "");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_set_top_color_spec ("", "a"), "a");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_set_top_color_spec ("a", ""), "a");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_set_top_color_spec ("a", "a"), "a");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_set_top_color_spec ("a", "b"), "b-a");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_set_top_color_spec ("a-c:v", "b"), "b-c");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_set_top_color_spec ("a-c:v", "c"), "c");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_set_top_color_spec ("a:-b:h", "d"), "d-b");
+
+ /* nautilus_gradient_set_right_color_spec */
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_set_right_color_spec ("", ""), "");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_set_right_color_spec ("", "a"), "a");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_set_right_color_spec ("a", ""), "a");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_set_right_color_spec ("a", "a"), "a");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_set_right_color_spec ("a", "b"), "a-b:h");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_set_right_color_spec ("a-c:v", "b"), "a-b:h");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_set_right_color_spec ("a-c:v", "c"), "a-c:h");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_set_right_color_spec ("a:-b:v", "d"), "a:-d:h");
+
+ /* nautilus_gradient_set_bottom_color_spec */
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_set_bottom_color_spec ("", ""), "");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_set_bottom_color_spec ("", "a"), "a");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_set_bottom_color_spec ("a", ""), "a");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_set_bottom_color_spec ("a", "a"), "a");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_set_bottom_color_spec ("a", "b"), "a-b");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_set_bottom_color_spec ("a-c:v", "b"), "a-b");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_set_bottom_color_spec ("a-c:v", "c"), "a-c");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_set_bottom_color_spec ("a:-b:h", "d"), "a:-d");
}
#endif /* ! NAUTILUS_OMIT_SELF_CHECK */
diff --git a/libnautilus-extensions/gdk-extensions.h b/libnautilus-extensions/gdk-extensions.h
index 57294ec43..8ecadf853 100644
--- a/libnautilus-extensions/gdk-extensions.h
+++ b/libnautilus-extensions/gdk-extensions.h
@@ -27,23 +27,49 @@
#include <gdk/gdk.h>
-void nautilus_fill_rectangle (GdkDrawable *drawable,
- GdkGC *gc,
- const GdkRectangle *rectangle);
-void nautilus_fill_rectangle_with_color (GdkDrawable *drawable,
- GdkGC *gc,
- const GdkRectangle *rectangle,
- const GdkColor *color);
-void nautilus_fill_rectangle_with_gradient (GdkDrawable *drawable,
- GdkGC *gc,
- GdkColormap *colormap,
- const GdkRectangle *rectangle,
- const GdkColor *start_color,
- const GdkColor *end_color,
- gboolean horizontal_gradient);
-void nautilus_interpolate_color (gdouble ratio,
- const GdkColor *start_color,
- const GdkColor *end_color,
- GdkColor *interpolated_color);
+/* A gradient spec. is a string that contains a specifier for either a
+ color or a gradient. If the string has a "-" in it, then it's a gradient.
+ The gradient is vertical by default and the spec. can end with ":v" to indicate that.
+ If the gradient ends with ":h", the gradient is horizontal.
+*/
+char * nautilus_gradient_new (const char *start_color,
+ const char *end_color,
+ gboolean is_horizontal);
+
+gboolean nautilus_gradient_is_gradient (const char *gradient_spec);
+char * nautilus_gradient_get_start_color_spec (const char *gradient_spec);
+char * nautilus_gradient_get_end_color_spec (const char *gradient_spec);
+gboolean nautilus_gradient_is_horizontal (const char *gradient_spec);
+
+char * nautilus_gradient_set_left_color_spec (const char *gradient_spec,
+ const char *left_color);
+char * nautilus_gradient_set_top_color_spec (const char *gradient_spec,
+ const char *top_color);
+char * nautilus_gradient_set_right_color_spec (const char *gradient_spec,
+ const char *right_color);
+char * nautilus_gradient_set_bottom_color_spec (const char *gradient_spec,
+ const char *bottom_color);
+
+/* Fill routines that take GdkRectangle parameters instead of four coordinates. */
+void nautilus_fill_rectangle (GdkDrawable *drawable,
+ GdkGC *gc,
+ const GdkRectangle *rectangle);
+void nautilus_fill_rectangle_with_color (GdkDrawable *drawable,
+ GdkGC *gc,
+ const GdkRectangle *rectangle,
+ const GdkColor *color);
+void nautilus_fill_rectangle_with_gradient (GdkDrawable *drawable,
+ GdkGC *gc,
+ GdkColormap *colormap,
+ const GdkRectangle *rectangle,
+ const GdkColor *start_color,
+ const GdkColor *end_color,
+ gboolean horizontal_gradient);
+
+/* A basic operation needed for drawing gradients is interpolating two colors.*/
+void nautilus_interpolate_color (gdouble ratio,
+ const GdkColor *start_color,
+ const GdkColor *end_color,
+ GdkColor *interpolated_color);
#endif /* GDK_EXTENSIONS_H */
diff --git a/src/nautilus-self-checks.h b/libnautilus-extensions/nautilus-lib-self-check-functions.c
index a8c46e68f..3e8d2e21e 100644
--- a/src/nautilus-self-checks.h
+++ b/libnautilus-extensions/nautilus-lib-self-check-functions.c
@@ -1,8 +1,9 @@
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*-
- nautilus-self-checks.h: The self-check framework.
+ nautilus-lib-self-check-functions.c: Wrapper for all self check functions
+ in Nautilus proper.
- Copyright (C) 1999 Eazel, Inc.
+ Copyright (C) 2000 Eazel, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
@@ -22,9 +23,17 @@
Author: Darin Adler <darin@eazel.com>
*/
-#ifndef NAUTILUS_SELF_CHECKS_H
-#define NAUTILUS_SELF_CHECKS_H
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
-void nautilus_run_all_self_checks(void);
+#if ! defined (NAUTILUS_OMIT_SELF_CHECK)
-#endif /* NAUTILUS_SELF_CHECKS_H */
+#include "nautilus-lib-self-check-functions.h"
+
+void nautilus_run_lib_self_checks ()
+{
+ nautilus_self_check_gdk_extensions ();
+}
+
+#endif /* ! NAUTILUS_OMIT_SELF_CHECK */
diff --git a/libnautilus-extensions/nautilus-lib-self-check-functions.h b/libnautilus-extensions/nautilus-lib-self-check-functions.h
new file mode 100644
index 000000000..dc9ada13a
--- /dev/null
+++ b/libnautilus-extensions/nautilus-lib-self-check-functions.h
@@ -0,0 +1,38 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*-
+
+ nautilus-lib-self-check-functions.h: Wrapper and prototypes for all
+ self-check functions in libnautilus.
+
+ Copyright (C) 2000 Eazel, Inc.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ This program 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
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with this program; if not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+
+ Author: Darin Adler <darin@eazel.com>
+*/
+
+#include "nautilus-self-checks.h"
+
+void nautilus_run_lib_self_checks (void);
+
+/* Putting the prototypes for these self-check functions in each
+ header file for the files they are defined in would make compiling
+ the self-check framework take way too long (since one file would
+ have to include everything).
+
+ So we put the prototypes here instead.
+*/
+
+void nautilus_self_check_gdk_extensions (void);
diff --git a/libnautilus-extensions/nautilus-self-checks.c b/libnautilus-extensions/nautilus-self-checks.c
new file mode 100644
index 000000000..a41df1f9d
--- /dev/null
+++ b/libnautilus-extensions/nautilus-self-checks.c
@@ -0,0 +1,120 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*-
+
+ nautilus-self-checks.c: The self-check framework.
+
+ Copyright (C) 1999 Eazel, Inc.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ This program 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
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with this program; if not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+
+ Author: Darin Adler <darin@eazel.com>
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#if ! defined (NAUTILUS_OMIT_SELF_CHECK)
+
+#include "nautilus-self-checks.h"
+#include <stdio.h>
+
+static gboolean failed;
+
+static const char *current_expression;
+static const char *current_file_name;
+static int current_line_number;
+
+gboolean nautilus_self_checks_failed (void)
+{
+ return failed;
+}
+
+static void
+nautilus_report_check_failure (char *result, char *expected)
+{
+ printf ("FAIL: check failed in %s, line %d\n", current_file_name, current_line_number);
+ printf (" evaluated: %s\n", current_expression);
+ printf (" expected: %s\n", expected == NULL ? "NULL" : expected);
+ printf (" got: %s\n", result == NULL ? "NULL" : result);
+
+ failed = TRUE;
+
+ g_free (result);
+ g_free (expected);
+}
+
+static char *
+nautilus_strdup_boolean (gboolean boolean)
+{
+ if (boolean == FALSE)
+ return g_strdup ("FALSE");
+ if (boolean == TRUE)
+ return g_strdup ("TRUE");
+ return g_strdup_printf ("gboolean(%d)", boolean);
+}
+
+void
+nautilus_before_check (const char *expression,
+ const char *file_name,
+ int line_number)
+{
+ current_expression = expression;
+ current_file_name = file_name;
+ current_line_number = line_number;
+}
+
+static void
+nautilus_after_check ()
+{
+ /* It would be good to check here if there was a memory leak. */
+}
+
+void
+nautilus_check_boolean_result (gboolean result, gboolean expected)
+{
+ if (result != expected)
+ nautilus_report_check_failure (nautilus_strdup_boolean(result),
+ nautilus_strdup_boolean(expected));
+ nautilus_after_check ();
+}
+
+void
+nautilus_check_integer_result (long result, long expected)
+{
+ if (result != expected)
+ nautilus_report_check_failure (g_strdup_printf("%ld", result),
+ g_strdup_printf("%ld", expected));
+
+ nautilus_after_check ();
+}
+
+void
+nautilus_check_string_result (char *result, const char *expected)
+{
+ gboolean match;
+
+ if (expected == NULL)
+ match = result == NULL;
+ else
+ match = result != NULL && strcmp (result, expected) == 0;
+
+ if (!match)
+ nautilus_report_check_failure (result, g_strdup(expected));
+
+ nautilus_after_check ();
+}
+
+#endif /* ! NAUTILUS_OMIT_SELF_CHECK */
diff --git a/libnautilus-extensions/nautilus-self-checks.h b/libnautilus-extensions/nautilus-self-checks.h
new file mode 100644
index 000000000..bfbdd40c0
--- /dev/null
+++ b/libnautilus-extensions/nautilus-self-checks.h
@@ -0,0 +1,54 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*-
+
+ nautilus-self-checks.h: The self-check framework.
+
+ Copyright (C) 1999 Eazel, Inc.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ This program 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
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with this program; if not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+
+ Author: Darin Adler <darin@eazel.com>
+*/
+
+#ifndef NAUTILUS_SELF_CHECKS_H
+#define NAUTILUS_SELF_CHECKS_H
+
+#include <glib.h>
+
+gboolean nautilus_self_checks_failed (void);
+void nautilus_before_check (const char *expression,
+ const char *file_name,
+ int line_number);
+void nautilus_check_boolean_result (gboolean result,
+ gboolean expected_value);
+void nautilus_check_integer_result (long result,
+ long expected_value);
+void nautilus_check_string_result (char *result,
+ const char *expected_value);
+
+#define NAUTILUS_CHECK_RESULT(type, expression, expected_value) \
+G_STMT_START { \
+ nautilus_before_check (#expression, __FILE__, __LINE__); \
+ nautilus_check_##type##_result (expression, expected_value); \
+} G_STMT_END
+
+#define NAUTILUS_CHECK_BOOLEAN_RESULT(expression, expected_value) \
+ NAUTILUS_CHECK_RESULT(boolean, expression, expected_value)
+#define NAUTILUS_CHECK_INTEGER_RESULT(expression, expected_value) \
+ NAUTILUS_CHECK_RESULT(integer, expression, expected_value)
+#define NAUTILUS_CHECK_STRING_RESULT(expression, expected_value) \
+ NAUTILUS_CHECK_RESULT(string, expression, expected_value)
+
+#endif /* NAUTILUS_SELF_CHECKS_H */
diff --git a/libnautilus-private/Makefile.am b/libnautilus-private/Makefile.am
index 719d7d76d..dc583e7f4 100644
--- a/libnautilus-private/Makefile.am
+++ b/libnautilus-private/Makefile.am
@@ -23,6 +23,8 @@ libnautilusinclude_HEADERS= \
gtkscrollframe.h \
nautilus.h \
nautilus-file-utilities.h \
+ nautilus-lib-self-check-functions.c \
+ nautilus-self-checks.c \
ntl-content-view-client.h \
ntl-meta-view-client.h \
ntl-view-client.h
@@ -35,6 +37,8 @@ libnautilus_la_SOURCES=$(nautilus_idl_sources) \
gtkflist.c \
gtkscrollframe.c \
nautilus-file-utilities.c \
+ nautilus-lib-self-check-functions.c \
+ nautilus-self-checks.c \
ntl-content-view-client.c \
ntl-meta-view-client.c \
ntl-view-client.c \
diff --git a/libnautilus-private/gdk-extensions.c b/libnautilus-private/gdk-extensions.c
index 0f3184f3e..8f145b5b6 100644
--- a/libnautilus-private/gdk-extensions.c
+++ b/libnautilus-private/gdk-extensions.c
@@ -28,7 +28,9 @@
#include "gdk-extensions.h"
-#include "../src/nautilus-self-check-functions.h"
+#include "nautilus-lib-self-check-functions.h"
+
+#include <string.h>
#define GRADIENT_BAND_SIZE 4
@@ -178,30 +180,329 @@ nautilus_interpolate_color (gdouble ratio,
interpolated_color->blue = start_color->blue * (1.0 - ratio) + end_color->blue * ratio;
}
+/**
+ * nautilus_gradient_new
+ * @start_color: Color for the top or left.
+ * @end_color: Color for the bottom or right.
+ * @is_horizontal: Direction of the gradient.
+ *
+ * Create a string that combines the start and end colors along
+ * with the direction of the gradient in a standard format.
+ */
+char *
+nautilus_gradient_new (const char *start_color,
+ const char *end_color,
+ gboolean is_horizontal)
+{
+ g_return_val_if_fail (start_color != NULL, g_strdup (""));
+ g_return_val_if_fail (end_color != NULL, g_strdup (""));
+ g_return_val_if_fail (is_horizontal == FALSE || is_horizontal == TRUE, g_strdup (""));
+
+ /* Handle the special case where the start and end colors are identical.
+ Handle the special case where the end color is an empty string.
+ */
+ if (strcmp(start_color, end_color) == 0 || end_color[0] == '\0')
+ return g_strdup (start_color);
+
+ /* Handle the special case where the start color is an empty string. */
+ if (start_color[0] == '\0')
+ return g_strdup (end_color);
+
+ /* Handle the general case. */
+ return g_strconcat (start_color, "-", end_color, is_horizontal ? ":h" : NULL, NULL);
+}
+
+/**
+ * nautilus_gradient_is_gradient
+ * @gradient_spec: A gradient spec. string.
+ *
+ * Return true if the spec. specifies a gradient instead of a solid color.
+ */
+gboolean
+nautilus_gradient_is_gradient (const char *gradient_spec)
+{
+ g_return_val_if_fail (gradient_spec != NULL, FALSE);
+
+ return strchr (gradient_spec, '-') != NULL;
+}
+
+static char *
+nautilus_gradient_strip_trailing_direction_if_any (const char *gradient_spec)
+{
+ size_t length;
+
+ g_return_val_if_fail (gradient_spec != NULL, g_strdup (""));
+
+ length = strlen (gradient_spec);
+ if (length >= 2 && gradient_spec[length - 2] == ':'
+ && (gradient_spec[length - 1] == 'v' || gradient_spec[length - 1] == 'h'))
+ length -= 2;
+
+ return g_strndup (gradient_spec, length);
+}
+
+/**
+ * nautilus_gradient_get_start_color_spec
+ * @gradient_spec: A gradient spec. string.
+ *
+ * Return the start color.
+ * This may be the entire gradient_spec if it's a solid color.
+ */
+char *
+nautilus_gradient_get_start_color_spec (const char *gradient_spec)
+{
+ const char *separator;
+
+ g_return_val_if_fail (gradient_spec != NULL, g_strdup (""));
+
+ separator = strchr (gradient_spec, '-');
+ if (separator == NULL)
+ return nautilus_gradient_strip_trailing_direction_if_any (gradient_spec);
+
+ return g_strndup (gradient_spec, separator - gradient_spec);
+}
+
+/**
+ * nautilus_gradient_get_end_color_spec
+ * @gradient_spec: A gradient spec. string.
+ *
+ * Return the end color.
+ * This may be the entire gradient_spec if it's a solid color.
+ */
+char *
+nautilus_gradient_get_end_color_spec (const char *gradient_spec)
+{
+ const char *separator;
+
+ g_return_val_if_fail (gradient_spec != NULL, g_strdup (""));
+
+ separator = strchr (gradient_spec, '-');
+ return nautilus_gradient_strip_trailing_direction_if_any
+ (separator != NULL ? separator + 1 : gradient_spec);
+}
+
+/* Do the work shared by all the set_color_spec functions below. */
+static char *
+nautilus_gradient_set_edge_color (const char *gradient_spec,
+ const char *edge_color,
+ gboolean is_horizontal,
+ gboolean change_end)
+{
+ char *opposite_color;
+ char *result;
+
+ g_return_val_if_fail (gradient_spec != NULL, g_strdup (""));
+ g_return_val_if_fail (edge_color != NULL, g_strdup (gradient_spec));
+
+ /* Get the color from the existing gradient spec. for the opposite
+ edge. This will parse away all the stuff we don't want from the
+ old gradient spec.
+ */
+ opposite_color = change_end
+ ? nautilus_gradient_get_start_color_spec (gradient_spec)
+ : nautilus_gradient_get_end_color_spec (gradient_spec);
+
+ /* Create a new gradient spec. The nautilus_gradient_new function handles
+ some special cases, so we don't have to bother with them here.
+ */
+ result = nautilus_gradient_new (change_end ? opposite_color : edge_color,
+ change_end ? edge_color : opposite_color,
+ is_horizontal);
+
+ g_free (opposite_color);
+
+ return result;
+}
+
+/**
+ * nautilus_gradient_set_left_color_spec
+ * @gradient_spec: A gradient spec. string.
+ * @left_color: Color spec. to replace left color with.
+ *
+ * Changes the left color to what's passed in.
+ * This creates a horizontal gradient.
+ */
+char *
+nautilus_gradient_set_left_color_spec (const char *gradient_spec,
+ const char *left_color)
+{
+ return nautilus_gradient_set_edge_color (gradient_spec, left_color, TRUE, FALSE);
+}
+
+/**
+ * nautilus_gradient_set_top_color_spec
+ * @gradient_spec: A gradient spec. string.
+ * @top_color: Color spec. to replace top color with.
+ *
+ * Changes the top color to what's passed in.
+ * This creates a vertical gradient.
+ */
+char *
+nautilus_gradient_set_top_color_spec (const char *gradient_spec,
+ const char *top_color)
+{
+ return nautilus_gradient_set_edge_color (gradient_spec, top_color, FALSE, FALSE);
+}
+
+/**
+ * nautilus_gradient_set_right_color_spec
+ * @gradient_spec: A gradient spec. string.
+ * @right_color: Color spec. to replace right color with.
+ *
+ * Changes the right color to what's passed in.
+ * This creates a horizontal gradient.
+ */
+char *
+nautilus_gradient_set_right_color_spec (const char *gradient_spec,
+ const char *right_color)
+{
+ return nautilus_gradient_set_edge_color (gradient_spec, right_color, TRUE, TRUE);
+}
+
+/**
+ * nautilus_gradient_set_bottom_color_spec
+ * @gradient_spec: A gradient spec. string.
+ * @bottom_color: Color spec. to replace bottom color with.
+ *
+ * Changes the bottom color to what's passed in.
+ * This creates a vertical gradient.
+ */
+char *
+nautilus_gradient_set_bottom_color_spec (const char *gradient_spec,
+ const char *bottom_color)
+{
+ return nautilus_gradient_set_edge_color (gradient_spec, bottom_color, FALSE, TRUE);
+}
+
#if ! defined (NAUTILUS_OMIT_SELF_CHECK)
-static void
-self_check_interpolate(gdouble ratio,
- gushort r1, gushort g1, gushort b1,
- gushort r2, gushort g2, gushort b2,
- gushort r3, gushort g3, gushort b3)
+#include <stdio.h>
+
+static GdkColor
+nautilus_self_check_interpolate (gdouble ratio,
+ gushort r1, gushort g1, gushort b1,
+ gushort r2, gushort g2, gushort b2)
{
- GdkColor start_color = { 0, r1, g1, b1 };
- GdkColor end_color = { 0, r2, g2, b2 };
+ GdkColor start_color;
+ GdkColor end_color;
GdkColor interpolated_color;
- nautilus_interpolate_color(ratio, &start_color, &end_color, &interpolated_color);
- g_assert(interpolated_color.red == r3);
- g_assert(interpolated_color.red == g3);
- g_assert(interpolated_color.red == b3);
+
+ start_color.red = r1;
+ start_color.green = g1;
+ start_color.blue = b1;
+
+ end_color.red = r2;
+ end_color.green = g2;
+ end_color.blue = b2;
+
+ nautilus_interpolate_color (ratio, &start_color, &end_color, &interpolated_color);
+
+ return interpolated_color;
}
void
-self_check_gdk_extensions (void)
+nautilus_self_check_gdk_extensions (void)
{
- self_check_interpolate(0.0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
- self_check_interpolate(0.0, 0, 0, 0, 0xFFFF, 0xFFFF, 0xFFFF, 0, 0, 0);
- self_check_interpolate(0.5, 0, 0, 0, 0xFFFF, 0xFFFF, 0xFFFF, 0x7FFF, 0x7FFF, 0x7FFF);
- self_check_interpolate(1.0, 0, 0, 0, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF);
+ /* nautilus_interpolate_color */
+ NAUTILUS_CHECK_INTEGER_RESULT (nautilus_self_check_interpolate (0.0, 0, 0, 0, 0, 0, 0).red, 0);
+ NAUTILUS_CHECK_INTEGER_RESULT (nautilus_self_check_interpolate (0.0, 0, 0, 0, 0, 0, 0).green, 0);
+ NAUTILUS_CHECK_INTEGER_RESULT (nautilus_self_check_interpolate (0.0, 0, 0, 0, 0, 0, 0).blue, 0);
+ NAUTILUS_CHECK_INTEGER_RESULT (nautilus_self_check_interpolate (0.0, 0, 0, 0, 0xFFFF, 0xFFFF, 0xFFFF).red, 0);
+ NAUTILUS_CHECK_INTEGER_RESULT (nautilus_self_check_interpolate (0.0, 0, 0, 0, 0xFFFF, 0xFFFF, 0xFFFF).green, 0);
+ NAUTILUS_CHECK_INTEGER_RESULT (nautilus_self_check_interpolate (0.0, 0, 0, 0, 0xFFFF, 0xFFFF, 0xFFFF).blue, 0);
+ NAUTILUS_CHECK_INTEGER_RESULT (nautilus_self_check_interpolate (0.5, 0, 0, 0, 0xFFFF, 0xFFFF, 0xFFFF).red, 0x7FFF);
+ NAUTILUS_CHECK_INTEGER_RESULT (nautilus_self_check_interpolate (0.5, 0, 0, 0, 0xFFFF, 0xFFFF, 0xFFFF).green, 0x7FFF);
+ NAUTILUS_CHECK_INTEGER_RESULT (nautilus_self_check_interpolate (0.5, 0, 0, 0, 0xFFFF, 0xFFFF, 0xFFFF).blue, 0x7FFF);
+ NAUTILUS_CHECK_INTEGER_RESULT (nautilus_self_check_interpolate (1.0, 0, 0, 0, 0xFFFF, 0xFFFF, 0xFFFF).red, 0xFFFF);
+ NAUTILUS_CHECK_INTEGER_RESULT (nautilus_self_check_interpolate (1.0, 0, 0, 0, 0xFFFF, 0xFFFF, 0xFFFF).green, 0xFFFF);
+ NAUTILUS_CHECK_INTEGER_RESULT (nautilus_self_check_interpolate (1.0, 0, 0, 0, 0xFFFF, 0xFFFF, 0xFFFF).blue, 0xFFFF);
+
+ /* nautilus_fill_rectangle */
+ /* Make a GdkImage and fill it, maybe? */
+
+ /* nautilus_fill_rectangle_with_color */
+
+ /* nautilus_fill_rectangle_with_gradient */
+
+ /* nautilus_gradient_new */
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_new ("", "", FALSE), "");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_new ("a", "b", FALSE), "a-b");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_new ("a", "b", TRUE), "a-b:h");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_new ("a", "a", FALSE), "a");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_new ("a", "a", TRUE), "a");
+
+ /* nautilus_gradient_is_gradient */
+ NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_gradient_is_gradient (""), FALSE);
+ NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_gradient_is_gradient ("-"), TRUE);
+ NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_gradient_is_gradient ("a"), FALSE);
+ NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_gradient_is_gradient ("a-b"), TRUE);
+ NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_gradient_is_gradient ("a-b:h"), TRUE);
+
+ /* nautilus_gradient_get_start_color_spec */
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_get_start_color_spec (""), "");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_get_start_color_spec ("-"), "");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_get_start_color_spec ("a"), "a");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_get_start_color_spec ("a-b"), "a");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_get_start_color_spec ("a-"), "a");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_get_start_color_spec ("-b"), "");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_get_start_color_spec ("a:h"), "a");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_get_start_color_spec ("a:v"), "a");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_get_start_color_spec ("a:c"), "a:c");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_get_start_color_spec ("a:-b"), "a:");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_get_start_color_spec ("a:-b:v"), "a:");
+
+ /* nautilus_gradient_get_end_color_spec */
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_get_end_color_spec (""), "");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_get_end_color_spec ("-"), "");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_get_end_color_spec ("a"), "a");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_get_end_color_spec ("a-b"), "b");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_get_end_color_spec ("a-"), "");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_get_end_color_spec ("-b"), "b");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_get_end_color_spec ("a:h"), "a");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_get_end_color_spec ("a:v"), "a");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_get_end_color_spec ("a:c"), "a:c");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_get_end_color_spec ("a:-b"), "b");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_get_end_color_spec ("a:-b:v"), "b");
+
+ /* nautilus_gradient_set_left_color_spec */
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_set_left_color_spec ("", ""), "");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_set_left_color_spec ("", "a"), "a");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_set_left_color_spec ("a", ""), "a");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_set_left_color_spec ("a", "a"), "a");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_set_left_color_spec ("a", "b"), "b-a:h");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_set_left_color_spec ("a-c:v", "b"), "b-c:h");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_set_left_color_spec ("a-c:v", "c"), "c");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_set_left_color_spec ("a:-b:v", "d"), "d-b:h");
+
+ /* nautilus_gradient_set_top_color_spec */
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_set_top_color_spec ("", ""), "");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_set_top_color_spec ("", "a"), "a");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_set_top_color_spec ("a", ""), "a");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_set_top_color_spec ("a", "a"), "a");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_set_top_color_spec ("a", "b"), "b-a");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_set_top_color_spec ("a-c:v", "b"), "b-c");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_set_top_color_spec ("a-c:v", "c"), "c");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_set_top_color_spec ("a:-b:h", "d"), "d-b");
+
+ /* nautilus_gradient_set_right_color_spec */
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_set_right_color_spec ("", ""), "");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_set_right_color_spec ("", "a"), "a");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_set_right_color_spec ("a", ""), "a");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_set_right_color_spec ("a", "a"), "a");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_set_right_color_spec ("a", "b"), "a-b:h");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_set_right_color_spec ("a-c:v", "b"), "a-b:h");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_set_right_color_spec ("a-c:v", "c"), "a-c:h");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_set_right_color_spec ("a:-b:v", "d"), "a:-d:h");
+
+ /* nautilus_gradient_set_bottom_color_spec */
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_set_bottom_color_spec ("", ""), "");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_set_bottom_color_spec ("", "a"), "a");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_set_bottom_color_spec ("a", ""), "a");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_set_bottom_color_spec ("a", "a"), "a");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_set_bottom_color_spec ("a", "b"), "a-b");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_set_bottom_color_spec ("a-c:v", "b"), "a-b");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_set_bottom_color_spec ("a-c:v", "c"), "a-c");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_set_bottom_color_spec ("a:-b:h", "d"), "a:-d");
}
#endif /* ! NAUTILUS_OMIT_SELF_CHECK */
diff --git a/libnautilus-private/gdk-extensions.h b/libnautilus-private/gdk-extensions.h
index 57294ec43..8ecadf853 100644
--- a/libnautilus-private/gdk-extensions.h
+++ b/libnautilus-private/gdk-extensions.h
@@ -27,23 +27,49 @@
#include <gdk/gdk.h>
-void nautilus_fill_rectangle (GdkDrawable *drawable,
- GdkGC *gc,
- const GdkRectangle *rectangle);
-void nautilus_fill_rectangle_with_color (GdkDrawable *drawable,
- GdkGC *gc,
- const GdkRectangle *rectangle,
- const GdkColor *color);
-void nautilus_fill_rectangle_with_gradient (GdkDrawable *drawable,
- GdkGC *gc,
- GdkColormap *colormap,
- const GdkRectangle *rectangle,
- const GdkColor *start_color,
- const GdkColor *end_color,
- gboolean horizontal_gradient);
-void nautilus_interpolate_color (gdouble ratio,
- const GdkColor *start_color,
- const GdkColor *end_color,
- GdkColor *interpolated_color);
+/* A gradient spec. is a string that contains a specifier for either a
+ color or a gradient. If the string has a "-" in it, then it's a gradient.
+ The gradient is vertical by default and the spec. can end with ":v" to indicate that.
+ If the gradient ends with ":h", the gradient is horizontal.
+*/
+char * nautilus_gradient_new (const char *start_color,
+ const char *end_color,
+ gboolean is_horizontal);
+
+gboolean nautilus_gradient_is_gradient (const char *gradient_spec);
+char * nautilus_gradient_get_start_color_spec (const char *gradient_spec);
+char * nautilus_gradient_get_end_color_spec (const char *gradient_spec);
+gboolean nautilus_gradient_is_horizontal (const char *gradient_spec);
+
+char * nautilus_gradient_set_left_color_spec (const char *gradient_spec,
+ const char *left_color);
+char * nautilus_gradient_set_top_color_spec (const char *gradient_spec,
+ const char *top_color);
+char * nautilus_gradient_set_right_color_spec (const char *gradient_spec,
+ const char *right_color);
+char * nautilus_gradient_set_bottom_color_spec (const char *gradient_spec,
+ const char *bottom_color);
+
+/* Fill routines that take GdkRectangle parameters instead of four coordinates. */
+void nautilus_fill_rectangle (GdkDrawable *drawable,
+ GdkGC *gc,
+ const GdkRectangle *rectangle);
+void nautilus_fill_rectangle_with_color (GdkDrawable *drawable,
+ GdkGC *gc,
+ const GdkRectangle *rectangle,
+ const GdkColor *color);
+void nautilus_fill_rectangle_with_gradient (GdkDrawable *drawable,
+ GdkGC *gc,
+ GdkColormap *colormap,
+ const GdkRectangle *rectangle,
+ const GdkColor *start_color,
+ const GdkColor *end_color,
+ gboolean horizontal_gradient);
+
+/* A basic operation needed for drawing gradients is interpolating two colors.*/
+void nautilus_interpolate_color (gdouble ratio,
+ const GdkColor *start_color,
+ const GdkColor *end_color,
+ GdkColor *interpolated_color);
#endif /* GDK_EXTENSIONS_H */
diff --git a/libnautilus-private/nautilus-lib-self-check-functions.c b/libnautilus-private/nautilus-lib-self-check-functions.c
new file mode 100644
index 000000000..3e8d2e21e
--- /dev/null
+++ b/libnautilus-private/nautilus-lib-self-check-functions.c
@@ -0,0 +1,39 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*-
+
+ nautilus-lib-self-check-functions.c: Wrapper for all self check functions
+ in Nautilus proper.
+
+ Copyright (C) 2000 Eazel, Inc.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ This program 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
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with this program; if not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+
+ Author: Darin Adler <darin@eazel.com>
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#if ! defined (NAUTILUS_OMIT_SELF_CHECK)
+
+#include "nautilus-lib-self-check-functions.h"
+
+void nautilus_run_lib_self_checks ()
+{
+ nautilus_self_check_gdk_extensions ();
+}
+
+#endif /* ! NAUTILUS_OMIT_SELF_CHECK */
diff --git a/libnautilus-private/nautilus-lib-self-check-functions.h b/libnautilus-private/nautilus-lib-self-check-functions.h
new file mode 100644
index 000000000..dc9ada13a
--- /dev/null
+++ b/libnautilus-private/nautilus-lib-self-check-functions.h
@@ -0,0 +1,38 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*-
+
+ nautilus-lib-self-check-functions.h: Wrapper and prototypes for all
+ self-check functions in libnautilus.
+
+ Copyright (C) 2000 Eazel, Inc.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ This program 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
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with this program; if not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+
+ Author: Darin Adler <darin@eazel.com>
+*/
+
+#include "nautilus-self-checks.h"
+
+void nautilus_run_lib_self_checks (void);
+
+/* Putting the prototypes for these self-check functions in each
+ header file for the files they are defined in would make compiling
+ the self-check framework take way too long (since one file would
+ have to include everything).
+
+ So we put the prototypes here instead.
+*/
+
+void nautilus_self_check_gdk_extensions (void);
diff --git a/libnautilus-private/nautilus-self-checks.c b/libnautilus-private/nautilus-self-checks.c
new file mode 100644
index 000000000..a41df1f9d
--- /dev/null
+++ b/libnautilus-private/nautilus-self-checks.c
@@ -0,0 +1,120 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*-
+
+ nautilus-self-checks.c: The self-check framework.
+
+ Copyright (C) 1999 Eazel, Inc.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ This program 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
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with this program; if not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+
+ Author: Darin Adler <darin@eazel.com>
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#if ! defined (NAUTILUS_OMIT_SELF_CHECK)
+
+#include "nautilus-self-checks.h"
+#include <stdio.h>
+
+static gboolean failed;
+
+static const char *current_expression;
+static const char *current_file_name;
+static int current_line_number;
+
+gboolean nautilus_self_checks_failed (void)
+{
+ return failed;
+}
+
+static void
+nautilus_report_check_failure (char *result, char *expected)
+{
+ printf ("FAIL: check failed in %s, line %d\n", current_file_name, current_line_number);
+ printf (" evaluated: %s\n", current_expression);
+ printf (" expected: %s\n", expected == NULL ? "NULL" : expected);
+ printf (" got: %s\n", result == NULL ? "NULL" : result);
+
+ failed = TRUE;
+
+ g_free (result);
+ g_free (expected);
+}
+
+static char *
+nautilus_strdup_boolean (gboolean boolean)
+{
+ if (boolean == FALSE)
+ return g_strdup ("FALSE");
+ if (boolean == TRUE)
+ return g_strdup ("TRUE");
+ return g_strdup_printf ("gboolean(%d)", boolean);
+}
+
+void
+nautilus_before_check (const char *expression,
+ const char *file_name,
+ int line_number)
+{
+ current_expression = expression;
+ current_file_name = file_name;
+ current_line_number = line_number;
+}
+
+static void
+nautilus_after_check ()
+{
+ /* It would be good to check here if there was a memory leak. */
+}
+
+void
+nautilus_check_boolean_result (gboolean result, gboolean expected)
+{
+ if (result != expected)
+ nautilus_report_check_failure (nautilus_strdup_boolean(result),
+ nautilus_strdup_boolean(expected));
+ nautilus_after_check ();
+}
+
+void
+nautilus_check_integer_result (long result, long expected)
+{
+ if (result != expected)
+ nautilus_report_check_failure (g_strdup_printf("%ld", result),
+ g_strdup_printf("%ld", expected));
+
+ nautilus_after_check ();
+}
+
+void
+nautilus_check_string_result (char *result, const char *expected)
+{
+ gboolean match;
+
+ if (expected == NULL)
+ match = result == NULL;
+ else
+ match = result != NULL && strcmp (result, expected) == 0;
+
+ if (!match)
+ nautilus_report_check_failure (result, g_strdup(expected));
+
+ nautilus_after_check ();
+}
+
+#endif /* ! NAUTILUS_OMIT_SELF_CHECK */
diff --git a/libnautilus-private/nautilus-self-checks.h b/libnautilus-private/nautilus-self-checks.h
new file mode 100644
index 000000000..bfbdd40c0
--- /dev/null
+++ b/libnautilus-private/nautilus-self-checks.h
@@ -0,0 +1,54 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*-
+
+ nautilus-self-checks.h: The self-check framework.
+
+ Copyright (C) 1999 Eazel, Inc.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ This program 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
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with this program; if not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+
+ Author: Darin Adler <darin@eazel.com>
+*/
+
+#ifndef NAUTILUS_SELF_CHECKS_H
+#define NAUTILUS_SELF_CHECKS_H
+
+#include <glib.h>
+
+gboolean nautilus_self_checks_failed (void);
+void nautilus_before_check (const char *expression,
+ const char *file_name,
+ int line_number);
+void nautilus_check_boolean_result (gboolean result,
+ gboolean expected_value);
+void nautilus_check_integer_result (long result,
+ long expected_value);
+void nautilus_check_string_result (char *result,
+ const char *expected_value);
+
+#define NAUTILUS_CHECK_RESULT(type, expression, expected_value) \
+G_STMT_START { \
+ nautilus_before_check (#expression, __FILE__, __LINE__); \
+ nautilus_check_##type##_result (expression, expected_value); \
+} G_STMT_END
+
+#define NAUTILUS_CHECK_BOOLEAN_RESULT(expression, expected_value) \
+ NAUTILUS_CHECK_RESULT(boolean, expression, expected_value)
+#define NAUTILUS_CHECK_INTEGER_RESULT(expression, expected_value) \
+ NAUTILUS_CHECK_RESULT(integer, expression, expected_value)
+#define NAUTILUS_CHECK_STRING_RESULT(expression, expected_value) \
+ NAUTILUS_CHECK_RESULT(string, expression, expected_value)
+
+#endif /* NAUTILUS_SELF_CHECKS_H */
diff --git a/libnautilus/Makefile.am b/libnautilus/Makefile.am
index 719d7d76d..dc583e7f4 100644
--- a/libnautilus/Makefile.am
+++ b/libnautilus/Makefile.am
@@ -23,6 +23,8 @@ libnautilusinclude_HEADERS= \
gtkscrollframe.h \
nautilus.h \
nautilus-file-utilities.h \
+ nautilus-lib-self-check-functions.c \
+ nautilus-self-checks.c \
ntl-content-view-client.h \
ntl-meta-view-client.h \
ntl-view-client.h
@@ -35,6 +37,8 @@ libnautilus_la_SOURCES=$(nautilus_idl_sources) \
gtkflist.c \
gtkscrollframe.c \
nautilus-file-utilities.c \
+ nautilus-lib-self-check-functions.c \
+ nautilus-self-checks.c \
ntl-content-view-client.c \
ntl-meta-view-client.c \
ntl-view-client.c \
diff --git a/libnautilus/gdk-extensions.c b/libnautilus/gdk-extensions.c
index 0f3184f3e..8f145b5b6 100644
--- a/libnautilus/gdk-extensions.c
+++ b/libnautilus/gdk-extensions.c
@@ -28,7 +28,9 @@
#include "gdk-extensions.h"
-#include "../src/nautilus-self-check-functions.h"
+#include "nautilus-lib-self-check-functions.h"
+
+#include <string.h>
#define GRADIENT_BAND_SIZE 4
@@ -178,30 +180,329 @@ nautilus_interpolate_color (gdouble ratio,
interpolated_color->blue = start_color->blue * (1.0 - ratio) + end_color->blue * ratio;
}
+/**
+ * nautilus_gradient_new
+ * @start_color: Color for the top or left.
+ * @end_color: Color for the bottom or right.
+ * @is_horizontal: Direction of the gradient.
+ *
+ * Create a string that combines the start and end colors along
+ * with the direction of the gradient in a standard format.
+ */
+char *
+nautilus_gradient_new (const char *start_color,
+ const char *end_color,
+ gboolean is_horizontal)
+{
+ g_return_val_if_fail (start_color != NULL, g_strdup (""));
+ g_return_val_if_fail (end_color != NULL, g_strdup (""));
+ g_return_val_if_fail (is_horizontal == FALSE || is_horizontal == TRUE, g_strdup (""));
+
+ /* Handle the special case where the start and end colors are identical.
+ Handle the special case where the end color is an empty string.
+ */
+ if (strcmp(start_color, end_color) == 0 || end_color[0] == '\0')
+ return g_strdup (start_color);
+
+ /* Handle the special case where the start color is an empty string. */
+ if (start_color[0] == '\0')
+ return g_strdup (end_color);
+
+ /* Handle the general case. */
+ return g_strconcat (start_color, "-", end_color, is_horizontal ? ":h" : NULL, NULL);
+}
+
+/**
+ * nautilus_gradient_is_gradient
+ * @gradient_spec: A gradient spec. string.
+ *
+ * Return true if the spec. specifies a gradient instead of a solid color.
+ */
+gboolean
+nautilus_gradient_is_gradient (const char *gradient_spec)
+{
+ g_return_val_if_fail (gradient_spec != NULL, FALSE);
+
+ return strchr (gradient_spec, '-') != NULL;
+}
+
+static char *
+nautilus_gradient_strip_trailing_direction_if_any (const char *gradient_spec)
+{
+ size_t length;
+
+ g_return_val_if_fail (gradient_spec != NULL, g_strdup (""));
+
+ length = strlen (gradient_spec);
+ if (length >= 2 && gradient_spec[length - 2] == ':'
+ && (gradient_spec[length - 1] == 'v' || gradient_spec[length - 1] == 'h'))
+ length -= 2;
+
+ return g_strndup (gradient_spec, length);
+}
+
+/**
+ * nautilus_gradient_get_start_color_spec
+ * @gradient_spec: A gradient spec. string.
+ *
+ * Return the start color.
+ * This may be the entire gradient_spec if it's a solid color.
+ */
+char *
+nautilus_gradient_get_start_color_spec (const char *gradient_spec)
+{
+ const char *separator;
+
+ g_return_val_if_fail (gradient_spec != NULL, g_strdup (""));
+
+ separator = strchr (gradient_spec, '-');
+ if (separator == NULL)
+ return nautilus_gradient_strip_trailing_direction_if_any (gradient_spec);
+
+ return g_strndup (gradient_spec, separator - gradient_spec);
+}
+
+/**
+ * nautilus_gradient_get_end_color_spec
+ * @gradient_spec: A gradient spec. string.
+ *
+ * Return the end color.
+ * This may be the entire gradient_spec if it's a solid color.
+ */
+char *
+nautilus_gradient_get_end_color_spec (const char *gradient_spec)
+{
+ const char *separator;
+
+ g_return_val_if_fail (gradient_spec != NULL, g_strdup (""));
+
+ separator = strchr (gradient_spec, '-');
+ return nautilus_gradient_strip_trailing_direction_if_any
+ (separator != NULL ? separator + 1 : gradient_spec);
+}
+
+/* Do the work shared by all the set_color_spec functions below. */
+static char *
+nautilus_gradient_set_edge_color (const char *gradient_spec,
+ const char *edge_color,
+ gboolean is_horizontal,
+ gboolean change_end)
+{
+ char *opposite_color;
+ char *result;
+
+ g_return_val_if_fail (gradient_spec != NULL, g_strdup (""));
+ g_return_val_if_fail (edge_color != NULL, g_strdup (gradient_spec));
+
+ /* Get the color from the existing gradient spec. for the opposite
+ edge. This will parse away all the stuff we don't want from the
+ old gradient spec.
+ */
+ opposite_color = change_end
+ ? nautilus_gradient_get_start_color_spec (gradient_spec)
+ : nautilus_gradient_get_end_color_spec (gradient_spec);
+
+ /* Create a new gradient spec. The nautilus_gradient_new function handles
+ some special cases, so we don't have to bother with them here.
+ */
+ result = nautilus_gradient_new (change_end ? opposite_color : edge_color,
+ change_end ? edge_color : opposite_color,
+ is_horizontal);
+
+ g_free (opposite_color);
+
+ return result;
+}
+
+/**
+ * nautilus_gradient_set_left_color_spec
+ * @gradient_spec: A gradient spec. string.
+ * @left_color: Color spec. to replace left color with.
+ *
+ * Changes the left color to what's passed in.
+ * This creates a horizontal gradient.
+ */
+char *
+nautilus_gradient_set_left_color_spec (const char *gradient_spec,
+ const char *left_color)
+{
+ return nautilus_gradient_set_edge_color (gradient_spec, left_color, TRUE, FALSE);
+}
+
+/**
+ * nautilus_gradient_set_top_color_spec
+ * @gradient_spec: A gradient spec. string.
+ * @top_color: Color spec. to replace top color with.
+ *
+ * Changes the top color to what's passed in.
+ * This creates a vertical gradient.
+ */
+char *
+nautilus_gradient_set_top_color_spec (const char *gradient_spec,
+ const char *top_color)
+{
+ return nautilus_gradient_set_edge_color (gradient_spec, top_color, FALSE, FALSE);
+}
+
+/**
+ * nautilus_gradient_set_right_color_spec
+ * @gradient_spec: A gradient spec. string.
+ * @right_color: Color spec. to replace right color with.
+ *
+ * Changes the right color to what's passed in.
+ * This creates a horizontal gradient.
+ */
+char *
+nautilus_gradient_set_right_color_spec (const char *gradient_spec,
+ const char *right_color)
+{
+ return nautilus_gradient_set_edge_color (gradient_spec, right_color, TRUE, TRUE);
+}
+
+/**
+ * nautilus_gradient_set_bottom_color_spec
+ * @gradient_spec: A gradient spec. string.
+ * @bottom_color: Color spec. to replace bottom color with.
+ *
+ * Changes the bottom color to what's passed in.
+ * This creates a vertical gradient.
+ */
+char *
+nautilus_gradient_set_bottom_color_spec (const char *gradient_spec,
+ const char *bottom_color)
+{
+ return nautilus_gradient_set_edge_color (gradient_spec, bottom_color, FALSE, TRUE);
+}
+
#if ! defined (NAUTILUS_OMIT_SELF_CHECK)
-static void
-self_check_interpolate(gdouble ratio,
- gushort r1, gushort g1, gushort b1,
- gushort r2, gushort g2, gushort b2,
- gushort r3, gushort g3, gushort b3)
+#include <stdio.h>
+
+static GdkColor
+nautilus_self_check_interpolate (gdouble ratio,
+ gushort r1, gushort g1, gushort b1,
+ gushort r2, gushort g2, gushort b2)
{
- GdkColor start_color = { 0, r1, g1, b1 };
- GdkColor end_color = { 0, r2, g2, b2 };
+ GdkColor start_color;
+ GdkColor end_color;
GdkColor interpolated_color;
- nautilus_interpolate_color(ratio, &start_color, &end_color, &interpolated_color);
- g_assert(interpolated_color.red == r3);
- g_assert(interpolated_color.red == g3);
- g_assert(interpolated_color.red == b3);
+
+ start_color.red = r1;
+ start_color.green = g1;
+ start_color.blue = b1;
+
+ end_color.red = r2;
+ end_color.green = g2;
+ end_color.blue = b2;
+
+ nautilus_interpolate_color (ratio, &start_color, &end_color, &interpolated_color);
+
+ return interpolated_color;
}
void
-self_check_gdk_extensions (void)
+nautilus_self_check_gdk_extensions (void)
{
- self_check_interpolate(0.0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
- self_check_interpolate(0.0, 0, 0, 0, 0xFFFF, 0xFFFF, 0xFFFF, 0, 0, 0);
- self_check_interpolate(0.5, 0, 0, 0, 0xFFFF, 0xFFFF, 0xFFFF, 0x7FFF, 0x7FFF, 0x7FFF);
- self_check_interpolate(1.0, 0, 0, 0, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF);
+ /* nautilus_interpolate_color */
+ NAUTILUS_CHECK_INTEGER_RESULT (nautilus_self_check_interpolate (0.0, 0, 0, 0, 0, 0, 0).red, 0);
+ NAUTILUS_CHECK_INTEGER_RESULT (nautilus_self_check_interpolate (0.0, 0, 0, 0, 0, 0, 0).green, 0);
+ NAUTILUS_CHECK_INTEGER_RESULT (nautilus_self_check_interpolate (0.0, 0, 0, 0, 0, 0, 0).blue, 0);
+ NAUTILUS_CHECK_INTEGER_RESULT (nautilus_self_check_interpolate (0.0, 0, 0, 0, 0xFFFF, 0xFFFF, 0xFFFF).red, 0);
+ NAUTILUS_CHECK_INTEGER_RESULT (nautilus_self_check_interpolate (0.0, 0, 0, 0, 0xFFFF, 0xFFFF, 0xFFFF).green, 0);
+ NAUTILUS_CHECK_INTEGER_RESULT (nautilus_self_check_interpolate (0.0, 0, 0, 0, 0xFFFF, 0xFFFF, 0xFFFF).blue, 0);
+ NAUTILUS_CHECK_INTEGER_RESULT (nautilus_self_check_interpolate (0.5, 0, 0, 0, 0xFFFF, 0xFFFF, 0xFFFF).red, 0x7FFF);
+ NAUTILUS_CHECK_INTEGER_RESULT (nautilus_self_check_interpolate (0.5, 0, 0, 0, 0xFFFF, 0xFFFF, 0xFFFF).green, 0x7FFF);
+ NAUTILUS_CHECK_INTEGER_RESULT (nautilus_self_check_interpolate (0.5, 0, 0, 0, 0xFFFF, 0xFFFF, 0xFFFF).blue, 0x7FFF);
+ NAUTILUS_CHECK_INTEGER_RESULT (nautilus_self_check_interpolate (1.0, 0, 0, 0, 0xFFFF, 0xFFFF, 0xFFFF).red, 0xFFFF);
+ NAUTILUS_CHECK_INTEGER_RESULT (nautilus_self_check_interpolate (1.0, 0, 0, 0, 0xFFFF, 0xFFFF, 0xFFFF).green, 0xFFFF);
+ NAUTILUS_CHECK_INTEGER_RESULT (nautilus_self_check_interpolate (1.0, 0, 0, 0, 0xFFFF, 0xFFFF, 0xFFFF).blue, 0xFFFF);
+
+ /* nautilus_fill_rectangle */
+ /* Make a GdkImage and fill it, maybe? */
+
+ /* nautilus_fill_rectangle_with_color */
+
+ /* nautilus_fill_rectangle_with_gradient */
+
+ /* nautilus_gradient_new */
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_new ("", "", FALSE), "");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_new ("a", "b", FALSE), "a-b");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_new ("a", "b", TRUE), "a-b:h");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_new ("a", "a", FALSE), "a");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_new ("a", "a", TRUE), "a");
+
+ /* nautilus_gradient_is_gradient */
+ NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_gradient_is_gradient (""), FALSE);
+ NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_gradient_is_gradient ("-"), TRUE);
+ NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_gradient_is_gradient ("a"), FALSE);
+ NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_gradient_is_gradient ("a-b"), TRUE);
+ NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_gradient_is_gradient ("a-b:h"), TRUE);
+
+ /* nautilus_gradient_get_start_color_spec */
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_get_start_color_spec (""), "");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_get_start_color_spec ("-"), "");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_get_start_color_spec ("a"), "a");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_get_start_color_spec ("a-b"), "a");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_get_start_color_spec ("a-"), "a");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_get_start_color_spec ("-b"), "");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_get_start_color_spec ("a:h"), "a");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_get_start_color_spec ("a:v"), "a");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_get_start_color_spec ("a:c"), "a:c");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_get_start_color_spec ("a:-b"), "a:");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_get_start_color_spec ("a:-b:v"), "a:");
+
+ /* nautilus_gradient_get_end_color_spec */
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_get_end_color_spec (""), "");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_get_end_color_spec ("-"), "");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_get_end_color_spec ("a"), "a");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_get_end_color_spec ("a-b"), "b");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_get_end_color_spec ("a-"), "");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_get_end_color_spec ("-b"), "b");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_get_end_color_spec ("a:h"), "a");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_get_end_color_spec ("a:v"), "a");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_get_end_color_spec ("a:c"), "a:c");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_get_end_color_spec ("a:-b"), "b");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_get_end_color_spec ("a:-b:v"), "b");
+
+ /* nautilus_gradient_set_left_color_spec */
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_set_left_color_spec ("", ""), "");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_set_left_color_spec ("", "a"), "a");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_set_left_color_spec ("a", ""), "a");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_set_left_color_spec ("a", "a"), "a");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_set_left_color_spec ("a", "b"), "b-a:h");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_set_left_color_spec ("a-c:v", "b"), "b-c:h");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_set_left_color_spec ("a-c:v", "c"), "c");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_set_left_color_spec ("a:-b:v", "d"), "d-b:h");
+
+ /* nautilus_gradient_set_top_color_spec */
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_set_top_color_spec ("", ""), "");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_set_top_color_spec ("", "a"), "a");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_set_top_color_spec ("a", ""), "a");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_set_top_color_spec ("a", "a"), "a");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_set_top_color_spec ("a", "b"), "b-a");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_set_top_color_spec ("a-c:v", "b"), "b-c");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_set_top_color_spec ("a-c:v", "c"), "c");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_set_top_color_spec ("a:-b:h", "d"), "d-b");
+
+ /* nautilus_gradient_set_right_color_spec */
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_set_right_color_spec ("", ""), "");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_set_right_color_spec ("", "a"), "a");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_set_right_color_spec ("a", ""), "a");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_set_right_color_spec ("a", "a"), "a");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_set_right_color_spec ("a", "b"), "a-b:h");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_set_right_color_spec ("a-c:v", "b"), "a-b:h");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_set_right_color_spec ("a-c:v", "c"), "a-c:h");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_set_right_color_spec ("a:-b:v", "d"), "a:-d:h");
+
+ /* nautilus_gradient_set_bottom_color_spec */
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_set_bottom_color_spec ("", ""), "");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_set_bottom_color_spec ("", "a"), "a");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_set_bottom_color_spec ("a", ""), "a");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_set_bottom_color_spec ("a", "a"), "a");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_set_bottom_color_spec ("a", "b"), "a-b");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_set_bottom_color_spec ("a-c:v", "b"), "a-b");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_set_bottom_color_spec ("a-c:v", "c"), "a-c");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_gradient_set_bottom_color_spec ("a:-b:h", "d"), "a:-d");
}
#endif /* ! NAUTILUS_OMIT_SELF_CHECK */
diff --git a/libnautilus/gdk-extensions.h b/libnautilus/gdk-extensions.h
index 57294ec43..8ecadf853 100644
--- a/libnautilus/gdk-extensions.h
+++ b/libnautilus/gdk-extensions.h
@@ -27,23 +27,49 @@
#include <gdk/gdk.h>
-void nautilus_fill_rectangle (GdkDrawable *drawable,
- GdkGC *gc,
- const GdkRectangle *rectangle);
-void nautilus_fill_rectangle_with_color (GdkDrawable *drawable,
- GdkGC *gc,
- const GdkRectangle *rectangle,
- const GdkColor *color);
-void nautilus_fill_rectangle_with_gradient (GdkDrawable *drawable,
- GdkGC *gc,
- GdkColormap *colormap,
- const GdkRectangle *rectangle,
- const GdkColor *start_color,
- const GdkColor *end_color,
- gboolean horizontal_gradient);
-void nautilus_interpolate_color (gdouble ratio,
- const GdkColor *start_color,
- const GdkColor *end_color,
- GdkColor *interpolated_color);
+/* A gradient spec. is a string that contains a specifier for either a
+ color or a gradient. If the string has a "-" in it, then it's a gradient.
+ The gradient is vertical by default and the spec. can end with ":v" to indicate that.
+ If the gradient ends with ":h", the gradient is horizontal.
+*/
+char * nautilus_gradient_new (const char *start_color,
+ const char *end_color,
+ gboolean is_horizontal);
+
+gboolean nautilus_gradient_is_gradient (const char *gradient_spec);
+char * nautilus_gradient_get_start_color_spec (const char *gradient_spec);
+char * nautilus_gradient_get_end_color_spec (const char *gradient_spec);
+gboolean nautilus_gradient_is_horizontal (const char *gradient_spec);
+
+char * nautilus_gradient_set_left_color_spec (const char *gradient_spec,
+ const char *left_color);
+char * nautilus_gradient_set_top_color_spec (const char *gradient_spec,
+ const char *top_color);
+char * nautilus_gradient_set_right_color_spec (const char *gradient_spec,
+ const char *right_color);
+char * nautilus_gradient_set_bottom_color_spec (const char *gradient_spec,
+ const char *bottom_color);
+
+/* Fill routines that take GdkRectangle parameters instead of four coordinates. */
+void nautilus_fill_rectangle (GdkDrawable *drawable,
+ GdkGC *gc,
+ const GdkRectangle *rectangle);
+void nautilus_fill_rectangle_with_color (GdkDrawable *drawable,
+ GdkGC *gc,
+ const GdkRectangle *rectangle,
+ const GdkColor *color);
+void nautilus_fill_rectangle_with_gradient (GdkDrawable *drawable,
+ GdkGC *gc,
+ GdkColormap *colormap,
+ const GdkRectangle *rectangle,
+ const GdkColor *start_color,
+ const GdkColor *end_color,
+ gboolean horizontal_gradient);
+
+/* A basic operation needed for drawing gradients is interpolating two colors.*/
+void nautilus_interpolate_color (gdouble ratio,
+ const GdkColor *start_color,
+ const GdkColor *end_color,
+ GdkColor *interpolated_color);
#endif /* GDK_EXTENSIONS_H */
diff --git a/libnautilus/nautilus-lib-self-check-functions.c b/libnautilus/nautilus-lib-self-check-functions.c
new file mode 100644
index 000000000..3e8d2e21e
--- /dev/null
+++ b/libnautilus/nautilus-lib-self-check-functions.c
@@ -0,0 +1,39 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*-
+
+ nautilus-lib-self-check-functions.c: Wrapper for all self check functions
+ in Nautilus proper.
+
+ Copyright (C) 2000 Eazel, Inc.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ This program 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
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with this program; if not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+
+ Author: Darin Adler <darin@eazel.com>
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#if ! defined (NAUTILUS_OMIT_SELF_CHECK)
+
+#include "nautilus-lib-self-check-functions.h"
+
+void nautilus_run_lib_self_checks ()
+{
+ nautilus_self_check_gdk_extensions ();
+}
+
+#endif /* ! NAUTILUS_OMIT_SELF_CHECK */
diff --git a/libnautilus/nautilus-lib-self-check-functions.h b/libnautilus/nautilus-lib-self-check-functions.h
new file mode 100644
index 000000000..dc9ada13a
--- /dev/null
+++ b/libnautilus/nautilus-lib-self-check-functions.h
@@ -0,0 +1,38 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*-
+
+ nautilus-lib-self-check-functions.h: Wrapper and prototypes for all
+ self-check functions in libnautilus.
+
+ Copyright (C) 2000 Eazel, Inc.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ This program 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
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with this program; if not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+
+ Author: Darin Adler <darin@eazel.com>
+*/
+
+#include "nautilus-self-checks.h"
+
+void nautilus_run_lib_self_checks (void);
+
+/* Putting the prototypes for these self-check functions in each
+ header file for the files they are defined in would make compiling
+ the self-check framework take way too long (since one file would
+ have to include everything).
+
+ So we put the prototypes here instead.
+*/
+
+void nautilus_self_check_gdk_extensions (void);
diff --git a/libnautilus/nautilus-self-checks.c b/libnautilus/nautilus-self-checks.c
new file mode 100644
index 000000000..a41df1f9d
--- /dev/null
+++ b/libnautilus/nautilus-self-checks.c
@@ -0,0 +1,120 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*-
+
+ nautilus-self-checks.c: The self-check framework.
+
+ Copyright (C) 1999 Eazel, Inc.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ This program 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
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with this program; if not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+
+ Author: Darin Adler <darin@eazel.com>
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#if ! defined (NAUTILUS_OMIT_SELF_CHECK)
+
+#include "nautilus-self-checks.h"
+#include <stdio.h>
+
+static gboolean failed;
+
+static const char *current_expression;
+static const char *current_file_name;
+static int current_line_number;
+
+gboolean nautilus_self_checks_failed (void)
+{
+ return failed;
+}
+
+static void
+nautilus_report_check_failure (char *result, char *expected)
+{
+ printf ("FAIL: check failed in %s, line %d\n", current_file_name, current_line_number);
+ printf (" evaluated: %s\n", current_expression);
+ printf (" expected: %s\n", expected == NULL ? "NULL" : expected);
+ printf (" got: %s\n", result == NULL ? "NULL" : result);
+
+ failed = TRUE;
+
+ g_free (result);
+ g_free (expected);
+}
+
+static char *
+nautilus_strdup_boolean (gboolean boolean)
+{
+ if (boolean == FALSE)
+ return g_strdup ("FALSE");
+ if (boolean == TRUE)
+ return g_strdup ("TRUE");
+ return g_strdup_printf ("gboolean(%d)", boolean);
+}
+
+void
+nautilus_before_check (const char *expression,
+ const char *file_name,
+ int line_number)
+{
+ current_expression = expression;
+ current_file_name = file_name;
+ current_line_number = line_number;
+}
+
+static void
+nautilus_after_check ()
+{
+ /* It would be good to check here if there was a memory leak. */
+}
+
+void
+nautilus_check_boolean_result (gboolean result, gboolean expected)
+{
+ if (result != expected)
+ nautilus_report_check_failure (nautilus_strdup_boolean(result),
+ nautilus_strdup_boolean(expected));
+ nautilus_after_check ();
+}
+
+void
+nautilus_check_integer_result (long result, long expected)
+{
+ if (result != expected)
+ nautilus_report_check_failure (g_strdup_printf("%ld", result),
+ g_strdup_printf("%ld", expected));
+
+ nautilus_after_check ();
+}
+
+void
+nautilus_check_string_result (char *result, const char *expected)
+{
+ gboolean match;
+
+ if (expected == NULL)
+ match = result == NULL;
+ else
+ match = result != NULL && strcmp (result, expected) == 0;
+
+ if (!match)
+ nautilus_report_check_failure (result, g_strdup(expected));
+
+ nautilus_after_check ();
+}
+
+#endif /* ! NAUTILUS_OMIT_SELF_CHECK */
diff --git a/libnautilus/nautilus-self-checks.h b/libnautilus/nautilus-self-checks.h
new file mode 100644
index 000000000..bfbdd40c0
--- /dev/null
+++ b/libnautilus/nautilus-self-checks.h
@@ -0,0 +1,54 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*-
+
+ nautilus-self-checks.h: The self-check framework.
+
+ Copyright (C) 1999 Eazel, Inc.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ This program 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
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with this program; if not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+
+ Author: Darin Adler <darin@eazel.com>
+*/
+
+#ifndef NAUTILUS_SELF_CHECKS_H
+#define NAUTILUS_SELF_CHECKS_H
+
+#include <glib.h>
+
+gboolean nautilus_self_checks_failed (void);
+void nautilus_before_check (const char *expression,
+ const char *file_name,
+ int line_number);
+void nautilus_check_boolean_result (gboolean result,
+ gboolean expected_value);
+void nautilus_check_integer_result (long result,
+ long expected_value);
+void nautilus_check_string_result (char *result,
+ const char *expected_value);
+
+#define NAUTILUS_CHECK_RESULT(type, expression, expected_value) \
+G_STMT_START { \
+ nautilus_before_check (#expression, __FILE__, __LINE__); \
+ nautilus_check_##type##_result (expression, expected_value); \
+} G_STMT_END
+
+#define NAUTILUS_CHECK_BOOLEAN_RESULT(expression, expected_value) \
+ NAUTILUS_CHECK_RESULT(boolean, expression, expected_value)
+#define NAUTILUS_CHECK_INTEGER_RESULT(expression, expected_value) \
+ NAUTILUS_CHECK_RESULT(integer, expression, expected_value)
+#define NAUTILUS_CHECK_STRING_RESULT(expression, expected_value) \
+ NAUTILUS_CHECK_RESULT(string, expression, expected_value)
+
+#endif /* NAUTILUS_SELF_CHECKS_H */
diff --git a/src/Makefile.am b/src/Makefile.am
index 3c46b917f..996c15cc8 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -20,46 +20,46 @@ LDADD= file-manager/libntl-file-manager.la \
$(XML_LIBS)
nautilus_SOURCES= \
- nautilus-bookmark.h \
+ explorer-location-bar.c \
+ explorer-location-bar.h \
nautilus-bookmark.c \
- nautilus-bookmarklist.h \
+ nautilus-bookmark.h \
nautilus-bookmarklist.c \
- nautilus-bookmarks-menu.h \
+ nautilus-bookmarklist.h \
nautilus-bookmarks-menu.c \
- nautilus-bookmarks-window.h \
+ nautilus-bookmarks-menu.h \
nautilus-bookmarks-window.c \
- nautilus-self-checks.c \
- nautilus-self-checks.h \
- ntl-app.h \
+ nautilus-bookmarks-window.h \
+ nautilus-self-check-functions.c \
+ nautilus-self-check-functions.h \
ntl-app.c \
- ntl-content-view.h \
+ ntl-app.h \
ntl-content-view.c \
+ ntl-content-view.h \
ntl-main.c \
- ntl-meta-view.h \
ntl-meta-view.c \
- ntl-miniicon.h \
+ ntl-meta-view.h \
ntl-miniicon.c \
- ntl-prefs.h \
+ ntl-miniicon.h \
ntl-prefs.c \
+ ntl-prefs.h \
ntl-types.h \
- ntl-uri-map.h \
ntl-uri-map.c \
- ntl-view.h \
- ntl-view.c \
+ ntl-uri-map.h \
ntl-view-bonobo-control.c \
ntl-view-bonobo-subdoc.c \
+ ntl-view.c \
ntl-view-frame-svr.c \
+ ntl-view.h \
ntl-view-nautilus.c \
ntl-view-private.h \
- ntl-window.h \
ntl-window.c \
+ ntl-window.h \
ntl-window-msgs.c \
ntl-window-msgs.h \
ntl-window-private.h \
- ntl-window-state.h \
ntl-window-state.c \
- explorer-location-bar.h \
- explorer-location-bar.c
+ ntl-window-state.h
goaddir=$(sysconfdir)/CORBA/servers
goad_DATA=nautilus.goad
diff --git a/src/file-manager/fm-directory.c b/src/file-manager/fm-directory.c
index de80547bf..cb662338d 100644
--- a/src/file-manager/fm-directory.c
+++ b/src/file-manager/fm-directory.c
@@ -2,7 +2,7 @@
fm-directory.c: GNOME file manager directory model.
- Copyright (C) 1999 Eazel, Inc.
+ Copyright (C) 1999, 2000 Eazel, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
@@ -30,13 +30,21 @@
#include "fm-directory-protected.h"
#include "fm-vfs-directory.h"
+#include <gtk/gtksignal.h>
#include <libnautilus/nautilus-gtk-macros.h>
#include "../nautilus-self-check-functions.h"
static void fm_directory_destroy (GtkObject *object);
static void fm_directory_finalize (GtkObject *object);
+enum {
+ GET_FILES,
+ LAST_SIGNAL
+};
+
static GtkObjectClass *parent_class;
+static guint signals[LAST_SIGNAL];
+
static GHashTable* directory_objects;
static void
@@ -46,6 +54,17 @@ fm_directory_initialize_class (gpointer klass)
object_class = GTK_OBJECT_CLASS (klass);
parent_class = gtk_type_class (GTK_TYPE_OBJECT);
+
+ signals[GET_FILES] =
+ gtk_signal_new ("get_files",
+ GTK_RUN_FIRST,
+ object_class->type,
+ GTK_SIGNAL_OFFSET (FMDirectoryClass, get_files),
+ gtk_marshal_NONE__POINTER_POINTER,
+ GTK_TYPE_NONE,
+ 2, GTK_TYPE_POINTER, GTK_TYPE_POINTER);
+
+ gtk_object_class_add_signals (object_class, signals, LAST_SIGNAL);
object_class->destroy = fm_directory_destroy;
object_class->finalize = fm_directory_finalize;
@@ -95,7 +114,8 @@ NAUTILUS_DEFINE_GET_TYPE_FUNCTION(FMDirectory, fm_directory, GTK_TYPE_OBJECT)
* Returns a referenced object, not a floating one. Unref when finished.
* If two windows are viewing the same uri, the directory object is shared.
*/
-FMDirectory *fm_directory_get(const char *uri)
+FMDirectory *
+fm_directory_get(const char *uri)
{
FMDirectory *directory;
@@ -128,15 +148,49 @@ FMDirectory *fm_directory_get(const char *uri)
return directory;
}
+void
+fm_directory_get_files(FMDirectory *directory,
+ FMFileListCallback callback,
+ gpointer callback_data)
+{
+ g_return_if_fail(FM_IS_DIRECTORY(directory));
+ g_return_if_fail(callback);
+
+ gtk_signal_emit(GTK_OBJECT(directory), signals[GET_FILES], callback, callback_data);
+}
+
/* self check code */
#if !defined (NAUTILUS_OMIT_SELF_CHECK)
-void self_check_fm_directory(void)
+static int data_dummy;
+static guint file_count;
+
+static void
+get_files_cb(FMDirectory *directory, FMFileList *files, gpointer data)
+{
+ g_assert(FM_IS_DIRECTORY(directory));
+ g_assert(files);
+ g_assert(data == &data_dummy);
+
+ file_count += g_list_length(files);
+}
+
+void
+nautilus_self_check_fm_directory(void)
{
FMDirectory *directory;
directory = fm_directory_get("file:///etc");
+
+ g_assert(g_hash_table_size(directory_objects) == 1);
+
+ file_count = 0;
+ fm_directory_get_files(directory, get_files_cb, &data_dummy);
+
+ gtk_object_unref(GTK_OBJECT(directory));
+
+ g_assert(g_hash_table_size(directory_objects) == 0);
}
#endif /* !NAUTILUS_OMIT_SELF_CHECK */
diff --git a/src/file-manager/fm-vfs-directory.c b/src/file-manager/fm-vfs-directory.c
index 1dc003a48..8cfe3812b 100644
--- a/src/file-manager/fm-vfs-directory.c
+++ b/src/file-manager/fm-vfs-directory.c
@@ -2,7 +2,7 @@
fm-vfs-directory.c: GNOME file manager directory model, VFS implementation.
- Copyright (C) 1999 Eazel, Inc.
+ Copyright (C) 1999, 2000 Eazel, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
@@ -30,28 +30,44 @@
#include "fm-directory-protected.h"
#include <libnautilus/nautilus-gtk-macros.h>
+#include <libgnomevfs/gnome-vfs.h>
struct _FMVFSDirectoryDetails {
- GList *files;
+ GnomeVFSURI *uri;
- /* GnomeVFSAsyncHandle *async_handle; */
+ FMFileList *files;
};
static void fm_vfs_directory_destroy (GtkObject *object);
static void fm_vfs_directory_finalize (GtkObject *object);
+static void fm_vfs_directory_get_files (FMDirectory *directory,
+ FMFileListCallback callback,
+ gpointer callback_data);
static GtkObjectClass *parent_class;
+#define METAFILE_NAME ".gnomad.xml"
+
+/* The process of reading a directory:
+
+ 1) Read and parse the metafile.
+ 2) Read the directory to notice changes.
+*/
+
static void
fm_vfs_directory_initialize_class (gpointer klass)
{
GtkObjectClass *object_class;
+ FMDirectoryClass *abstract_directory_class;
object_class = GTK_OBJECT_CLASS (klass);
+ abstract_directory_class = FM_DIRECTORY_CLASS (klass);
parent_class = gtk_type_class (FM_TYPE_DIRECTORY);
object_class->destroy = fm_vfs_directory_destroy;
object_class->finalize = fm_vfs_directory_finalize;
+
+ abstract_directory_class->get_files = fm_vfs_directory_get_files;
}
static void
@@ -59,7 +75,7 @@ fm_vfs_directory_initialize (gpointer object, gpointer klass)
{
FMVFSDirectory *directory;
- directory = FM_VFS_DIRECTORY(object);
+ directory = FM_VFS_DIRECTORY (object);
directory->details = g_new0 (FMVFSDirectoryDetails, 1);
}
@@ -67,7 +83,7 @@ fm_vfs_directory_initialize (gpointer object, gpointer klass)
static void
fm_vfs_directory_destroy (GtkObject *object)
{
- NAUTILUS_CALL_PARENT_CLASS(GTK_OBJECT_CLASS, destroy, (object));
+ NAUTILUS_CALL_PARENT_CLASS (GTK_OBJECT_CLASS, destroy, (object));
}
static void
@@ -78,19 +94,60 @@ fm_vfs_directory_finalize (GtkObject *object)
directory = FM_VFS_DIRECTORY (object);
g_free (directory->details);
- NAUTILUS_CALL_PARENT_CLASS(GTK_OBJECT_CLASS, finalize, (object));
+ NAUTILUS_CALL_PARENT_CLASS (GTK_OBJECT_CLASS, finalize, (object));
}
NAUTILUS_DEFINE_GET_TYPE_FUNCTION(FMVFSDirectory, fm_vfs_directory, FM_TYPE_DIRECTORY)
+static void
+fm_vfs_opened_metafile (GnomeVFSAsyncHandle *handle,
+ GnomeVFSResult result,
+ gpointer callback_data)
+{
+}
+
FMVFSDirectory *
fm_vfs_directory_new (const char* uri)
{
FMVFSDirectory *directory;
+ GnomeVFSURI *vfs_uri;
+ GnomeVFSURI *metafile_uri;
+ GnomeVFSAsyncHandle *metafile_handle;
+ GnomeVFSResult result;
+
+ vfs_uri = gnome_vfs_uri_new (uri);
+ if (vfs_uri == NULL)
+ return NULL;
+
+ metafile_uri = gnome_vfs_uri_append_path (vfs_uri, METAFILE_NAME);
+ if (metafile_uri == NULL)
+ return NULL;
directory = gtk_type_new (FM_TYPE_VFS_DIRECTORY);
- FM_DIRECTORY(directory)->details->hash_table_key = g_strdup(uri);
+ FM_DIRECTORY (directory)->details->hash_table_key = g_strdup (uri);
+
+ directory->details->uri = vfs_uri;
+
+ result = gnome_vfs_async_open_uri (&metafile_handle, metafile_uri, GNOME_VFS_OPEN_READ,
+ fm_vfs_opened_metafile, directory);
return directory;
}
+
+static void
+fm_vfs_directory_get_files (FMDirectory *abstract_directory,
+ FMFileListCallback callback,
+ gpointer callback_data)
+{
+ FMVFSDirectory *directory;
+
+ g_return_if_fail (FM_IS_VFS_DIRECTORY (abstract_directory));
+ g_return_if_fail (callback != NULL);
+
+ directory = FM_VFS_DIRECTORY (abstract_directory);
+ if (directory->details->files != NULL)
+ (* callback) (abstract_directory,
+ directory->details->files,
+ callback_data);
+}
diff --git a/src/nautilus-main.c b/src/nautilus-main.c
index b558b8de1..fe6a23954 100644
--- a/src/nautilus-main.c
+++ b/src/nautilus-main.c
@@ -4,6 +4,7 @@
* Nautilus
*
* Copyright (C) 1999, 2000 Red Hat, Inc.
+ * Copyright (C) 1999, 2000 Eazel, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
@@ -19,14 +20,19 @@
* along with this library; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
- * Author: Elliot Lee <sopwith@redhat.com>
+ * Authors: Elliot Lee <sopwith@redhat.com>,
+ * Darin Adler <darin@eazel.com>,
+ * John Sullivan <sullivan@eazel.com>
*
*/
+
/* ntl-main.c: Implementation of the routines that drive program lifecycle and main window creation/destruction. */
#include "config.h"
#include "nautilus.h"
-#include "nautilus-self-checks.h"
+#include "nautilus-self-check-functions.h"
+#include <libnautilus/nautilus-lib-self-check-functions.h>
+#include <libnautilus/nautilus-self-checks.h>
int main(int argc, char *argv[])
{
@@ -34,7 +40,7 @@ int main(int argc, char *argv[])
CORBA_Environment ev;
CORBA_ORB orb;
#if !defined (NAUTILUS_OMIT_SELF_CHECK)
- int check = FALSE;
+ gboolean check = FALSE;
#endif
const char **args;
@@ -61,17 +67,22 @@ int main(int argc, char *argv[])
args = poptGetArgs (ctx);
#if !defined (NAUTILUS_OMIT_SELF_CHECK)
- if (check)
- nautilus_run_all_self_checks();
- else
+ if (check) {
+ /* Run the checks for nautilus and libnautilus. */
+ nautilus_run_self_checks ();
+ nautilus_run_lib_self_checks ();
+ if (nautilus_self_checks_failed ())
+ return 1;
+ } else
#endif
{
nautilus_app_init (args ? args[0] : NULL);
+
bonobo_main();
- }
- /* One last chance for cleanup before program finishes. */
- nautilus_app_exiting();
+ /* One last chance for cleanup before program finishes. */
+ nautilus_app_exiting();
+ }
return 0;
}
diff --git a/src/nautilus-self-checks.c b/src/nautilus-self-check-functions.c
index cfa84c565..04fe6bcd4 100644
--- a/src/nautilus-self-checks.c
+++ b/src/nautilus-self-check-functions.c
@@ -1,8 +1,9 @@
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*-
- nautilus-self-checks.c: The self-check framework.
+ nautilus-self-check-functions.c: Wrapper for all self check functions
+ in Nautilus proper.
- Copyright (C) 1999 Eazel, Inc.
+ Copyright (C) 1999, 2000 Eazel, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
@@ -28,14 +29,11 @@
#if ! defined (NAUTILUS_OMIT_SELF_CHECK)
-#include "nautilus-self-checks.h"
-
#include "nautilus-self-check-functions.h"
-void nautilus_run_all_self_checks()
+void nautilus_run_self_checks()
{
- self_check_fm_directory();
- self_check_gdk_extensions();
+ nautilus_self_check_fm_directory();
}
#endif /* ! NAUTILUS_OMIT_SELF_CHECK */
diff --git a/src/nautilus-self-check-functions.h b/src/nautilus-self-check-functions.h
index 33e872308..6c11cf9bc 100644
--- a/src/nautilus-self-check-functions.h
+++ b/src/nautilus-self-check-functions.h
@@ -1,9 +1,9 @@
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*-
- nautilus-self-check-functions.h: Prototypes for all the functions
- called by the self-check framework.
+ nautilus-self-check-functions.h: Wrapper and prototypes for all self
+ check functions in Nautilus proper.
- Copyright (C) 1999 Eazel, Inc.
+ Copyright (C) 1999, 2000 Eazel, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
@@ -23,6 +23,8 @@
Author: Darin Adler <darin@eazel.com>
*/
+void nautilus_run_self_checks (void);
+
/* Putting the prototypes for these self-check functions in each
header file for the files they are defined in would make compiling
the self-check framework take way too long (since one file would
@@ -31,5 +33,4 @@
So we put the prototypes here instead.
*/
-void self_check_fm_directory(void);
-void self_check_gdk_extensions(void);
+void nautilus_self_check_fm_directory (void);
diff --git a/src/ntl-main.c b/src/ntl-main.c
index b558b8de1..fe6a23954 100644
--- a/src/ntl-main.c
+++ b/src/ntl-main.c
@@ -4,6 +4,7 @@
* Nautilus
*
* Copyright (C) 1999, 2000 Red Hat, Inc.
+ * Copyright (C) 1999, 2000 Eazel, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
@@ -19,14 +20,19 @@
* along with this library; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
- * Author: Elliot Lee <sopwith@redhat.com>
+ * Authors: Elliot Lee <sopwith@redhat.com>,
+ * Darin Adler <darin@eazel.com>,
+ * John Sullivan <sullivan@eazel.com>
*
*/
+
/* ntl-main.c: Implementation of the routines that drive program lifecycle and main window creation/destruction. */
#include "config.h"
#include "nautilus.h"
-#include "nautilus-self-checks.h"
+#include "nautilus-self-check-functions.h"
+#include <libnautilus/nautilus-lib-self-check-functions.h>
+#include <libnautilus/nautilus-self-checks.h>
int main(int argc, char *argv[])
{
@@ -34,7 +40,7 @@ int main(int argc, char *argv[])
CORBA_Environment ev;
CORBA_ORB orb;
#if !defined (NAUTILUS_OMIT_SELF_CHECK)
- int check = FALSE;
+ gboolean check = FALSE;
#endif
const char **args;
@@ -61,17 +67,22 @@ int main(int argc, char *argv[])
args = poptGetArgs (ctx);
#if !defined (NAUTILUS_OMIT_SELF_CHECK)
- if (check)
- nautilus_run_all_self_checks();
- else
+ if (check) {
+ /* Run the checks for nautilus and libnautilus. */
+ nautilus_run_self_checks ();
+ nautilus_run_lib_self_checks ();
+ if (nautilus_self_checks_failed ())
+ return 1;
+ } else
#endif
{
nautilus_app_init (args ? args[0] : NULL);
+
bonobo_main();
- }
- /* One last chance for cleanup before program finishes. */
- nautilus_app_exiting();
+ /* One last chance for cleanup before program finishes. */
+ nautilus_app_exiting();
+ }
return 0;
}