diff --git a/ChangeLog b/ChangeLog index 622203e7ac71d34925f448a1551b341a1b4a5558..0ea1c4404c6ff3f9fe339fbd767fc92a03a2a94a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2006-03-21 Benedikt Meurer <benny@xfce.org> + + * thunar/thunar-gobject-extensions.c + (thunar_g_initialize_transformations): Register one string->enum + transformation function that is used by all GEnum derived types. + * thunar/thunar-enum-types.{c,h}: Import ThunarRenamerMode enum. Don't + need to register a transformation for each and every enum type. + * thunar/thunar-preferences.c(thunar_preferences_class_init), + thunar/main.c(main): Initialize the additional GType transformations + on startup, rather than in the ThunarPreferences class constructor. + 2006-03-20 Benedikt Meurer <benny@xfce.org> * Makefile.am, acinclude.m4, configure.in.in, po/POTFILES.in, diff --git a/thunar/main.c b/thunar/main.c index e80e0189a6919ae1d01c5c3c490e9bea0128a420..756f0fde555513bf17d16f800e4b2fa3e28fbc73 100644 --- a/thunar/main.c +++ b/thunar/main.c @@ -33,6 +33,7 @@ #include <thunar/thunar-application.h> #include <thunar/thunar-dbus-client.h> #include <thunar/thunar-dbus-service.h> +#include <thunar/thunar-gobject-extensions.h> #include <thunar/thunar-stock.h> @@ -103,6 +104,9 @@ main (int argc, char **argv) return EXIT_FAILURE; } + /* register additional transformation functions */ + thunar_g_initialize_transformations (); + #ifdef HAVE_DBUS /* check if we should terminate a running Thunar instance */ if (G_UNLIKELY (opt_quit)) diff --git a/thunar/thunar-enum-types.c b/thunar/thunar-enum-types.c index d6f61bad966e356f76c43bb1edbab60e93aa5782..7f4626720c7756b2cac9b38e18a9d297cfc8fda6 100644 --- a/thunar/thunar-enum-types.c +++ b/thunar/thunar-enum-types.c @@ -27,27 +27,53 @@ -static void thunar_enum_from_string (const GValue *src_value, - GValue *dst_value); -static GType thunar_enum_register_type (const gchar *enum_name, - const GEnumValue *enum_values); -static void thunar_icon_size_from_zoom_level (const GValue *src_value, - GValue *dst_value); +static void thunar_icon_size_from_zoom_level (const GValue *src_value, + GValue *dst_value); + + + +GType +thunar_renamer_mode_get_type (void) +{ + static GType type = G_TYPE_INVALID; + + if (G_UNLIKELY (type == G_TYPE_INVALID)) + { + static const GEnumValue values[] = + { + { THUNAR_RENAMER_MODE_NAME, "THUNAR_RENAMER_MODE_NAME", N_ ("Name only"), }, + { THUNAR_RENAMER_MODE_SUFFIX, "THUNAR_RENAMER_MODE_SUFFIX", N_ ("Suffix only"), }, + { THUNAR_RENAMER_MODE_BOTH, "THUNAR_RENAMER_MODE_BOTH", N_ ("Name and Suffix"), }, + { 0, NULL, NULL, }, + }; + + type = g_enum_register_static (I_("ThunarRenamerMode"), values); + } + + return type; +} GType thunar_color_style_get_type (void) { - static const GEnumValue values[] = - { - { THUNAR_COLOR_STYLE_SOLID, "THUNAR_COLOR_STYLE_SOLID", "solid", }, - { THUNAR_COLOR_STYLE_HGRADIENT, "THUNAR_COLOR_STYLE_HGRADIENT", "hgradient", }, - { THUNAR_COLOR_STYLE_VGRADIENT, "THUNAR_COLOR_STYLE_VGRADIENT", "vgradient", }, - { 0, NULL, NULL, }, - }; - - return thunar_enum_register_type ("ThunarColorStyle", values); + static GType type = G_TYPE_INVALID; + + if (G_UNLIKELY (type == G_TYPE_INVALID)) + { + static const GEnumValue values[] = + { + { THUNAR_COLOR_STYLE_SOLID, "THUNAR_COLOR_STYLE_SOLID", "solid", }, + { THUNAR_COLOR_STYLE_HGRADIENT, "THUNAR_COLOR_STYLE_HGRADIENT", "hgradient", }, + { THUNAR_COLOR_STYLE_VGRADIENT, "THUNAR_COLOR_STYLE_VGRADIENT", "vgradient", }, + { 0, NULL, NULL, }, + }; + + type = g_enum_register_static (I_("ThunarColorStyle"), values); + } + + return type; } @@ -55,23 +81,30 @@ thunar_color_style_get_type (void) GType thunar_column_get_type (void) { - static const GEnumValue values[] = - { - { THUNAR_COLUMN_DATE_ACCESSED, "THUNAR_COLUMN_DATE_ACCESSED", N_ ("Date Accessed"), }, - { THUNAR_COLUMN_DATE_MODIFIED, "THUNAR_COLUMN_DATE_MODIFIED", N_ ("Date Modified"), }, - { THUNAR_COLUMN_GROUP, "THUNAR_COLUMN_GROUP", N_ ("Group"), }, - { THUNAR_COLUMN_MIME_TYPE, "THUNAR_COLUMN_MIME_TYPE", N_ ("MIME Type"), }, - { THUNAR_COLUMN_NAME, "THUNAR_COLUMN_NAME", N_ ("Name"), }, - { THUNAR_COLUMN_OWNER, "THUNAR_COLUMN_OWNER", N_ ("Owner"), }, - { THUNAR_COLUMN_PERMISSIONS, "THUNAR_COLUMN_PERMISSIONS", N_ ("Permissions"), }, - { THUNAR_COLUMN_SIZE, "THUNAR_COLUMN_SIZE", N_ ("Size"), }, - { THUNAR_COLUMN_TYPE, "THUNAR_COLUMN_TYPE", N_ ("Type"), }, - { THUNAR_COLUMN_FILE, "THUNAR_COLUMN_FILE", N_ ("File"), }, - { THUNAR_COLUMN_FILE_NAME, "THUNAR_COLUMN_FILE_NAME", N_ ("File Name"), }, - { 0, NULL, NULL, }, - }; - - return thunar_enum_register_type ("ThunarColumn", values); + static GType type = G_TYPE_INVALID; + + if (G_UNLIKELY (type == G_TYPE_INVALID)) + { + static const GEnumValue values[] = + { + { THUNAR_COLUMN_DATE_ACCESSED, "THUNAR_COLUMN_DATE_ACCESSED", N_ ("Date Accessed"), }, + { THUNAR_COLUMN_DATE_MODIFIED, "THUNAR_COLUMN_DATE_MODIFIED", N_ ("Date Modified"), }, + { THUNAR_COLUMN_GROUP, "THUNAR_COLUMN_GROUP", N_ ("Group"), }, + { THUNAR_COLUMN_MIME_TYPE, "THUNAR_COLUMN_MIME_TYPE", N_ ("MIME Type"), }, + { THUNAR_COLUMN_NAME, "THUNAR_COLUMN_NAME", N_ ("Name"), }, + { THUNAR_COLUMN_OWNER, "THUNAR_COLUMN_OWNER", N_ ("Owner"), }, + { THUNAR_COLUMN_PERMISSIONS, "THUNAR_COLUMN_PERMISSIONS", N_ ("Permissions"), }, + { THUNAR_COLUMN_SIZE, "THUNAR_COLUMN_SIZE", N_ ("Size"), }, + { THUNAR_COLUMN_TYPE, "THUNAR_COLUMN_TYPE", N_ ("Type"), }, + { THUNAR_COLUMN_FILE, "THUNAR_COLUMN_FILE", N_ ("File"), }, + { THUNAR_COLUMN_FILE_NAME, "THUNAR_COLUMN_FILE_NAME", N_ ("File Name"), }, + { 0, NULL, NULL, }, + }; + + type = g_enum_register_static (I_("ThunarColumn"), values); + } + + return type; } @@ -79,19 +112,26 @@ thunar_column_get_type (void) GType thunar_icon_size_get_type (void) { - static const GEnumValue values[] = - { - { THUNAR_ICON_SIZE_SMALLEST, "THUNAR_ICON_SIZE_SMALLEST", "smallest", }, - { THUNAR_ICON_SIZE_SMALLER, "THUNAR_ICON_SIZE_SMALLER", "smaller", }, - { THUNAR_ICON_SIZE_SMALL, "THUNAR_ICON_SIZE_SMALL", "small", }, - { THUNAR_ICON_SIZE_NORMAL, "THUNAR_ICON_SIZE_NORMAL", "normal", }, - { THUNAR_ICON_SIZE_LARGE, "THUNAR_ICON_SIZE_LARGE", "large", }, - { THUNAR_ICON_SIZE_LARGER, "THUNAR_ICON_SIZE_LARGER", "larger", }, - { THUNAR_ICON_SIZE_LARGEST, "THUNAR_ICON_SIZE_LARGEST", "largest", }, - { 0, NULL, NULL, }, - }; - - return thunar_enum_register_type ("ThunarIconSize", values); + static GType type = G_TYPE_INVALID; + + if (G_UNLIKELY (type == G_TYPE_INVALID)) + { + static const GEnumValue values[] = + { + { THUNAR_ICON_SIZE_SMALLEST, "THUNAR_ICON_SIZE_SMALLEST", "smallest", }, + { THUNAR_ICON_SIZE_SMALLER, "THUNAR_ICON_SIZE_SMALLER", "smaller", }, + { THUNAR_ICON_SIZE_SMALL, "THUNAR_ICON_SIZE_SMALL", "small", }, + { THUNAR_ICON_SIZE_NORMAL, "THUNAR_ICON_SIZE_NORMAL", "normal", }, + { THUNAR_ICON_SIZE_LARGE, "THUNAR_ICON_SIZE_LARGE", "large", }, + { THUNAR_ICON_SIZE_LARGER, "THUNAR_ICON_SIZE_LARGER", "larger", }, + { THUNAR_ICON_SIZE_LARGEST, "THUNAR_ICON_SIZE_LARGEST", "largest", }, + { 0, NULL, NULL, }, + }; + + type = g_enum_register_static (I_("ThunarIconSize"), values); + } + + return type; } @@ -99,15 +139,22 @@ thunar_icon_size_get_type (void) GType thunar_recursive_permissions_get_type (void) { - static const GEnumValue values[] = - { - { THUNAR_RECURSIVE_PERMISSIONS_ASK, "THUNAR_RECURSIVE_PERMISSIONS_ASK", "ask", }, - { THUNAR_RECURSIVE_PERMISSIONS_ALWAYS, "THUNAR_RECURSIVE_PERMISSIONS_ALWAYS", "always", }, - { THUNAR_RECURSIVE_PERMISSIONS_NEVER, "THUNAR_RECURSIVE_PERMISSIONS_NEVER", "never", }, - { 0, NULL, NULL, }, - }; - - return thunar_enum_register_type ("ThunarRecursivePermissions", values); + static GType type = G_TYPE_INVALID; + + if (G_UNLIKELY (type == G_TYPE_INVALID)) + { + static const GEnumValue values[] = + { + { THUNAR_RECURSIVE_PERMISSIONS_ASK, "THUNAR_RECURSIVE_PERMISSIONS_ASK", "ask", }, + { THUNAR_RECURSIVE_PERMISSIONS_ALWAYS, "THUNAR_RECURSIVE_PERMISSIONS_ALWAYS", "always", }, + { THUNAR_RECURSIVE_PERMISSIONS_NEVER, "THUNAR_RECURSIVE_PERMISSIONS_NEVER", "never", }, + { 0, NULL, NULL, }, + }; + + type = g_enum_register_static (I_("ThunarRecursivePermissions"), values); + } + + return type; } @@ -115,16 +162,23 @@ thunar_recursive_permissions_get_type (void) GType thunar_wallpaper_style_get_type (void) { - static const GEnumValue values[] = - { - { THUNAR_WALLPAPER_STYLE_CENTERED, "THUNAR_WALLPAPER_STYLE_CENTERED", "centered", }, - { THUNAR_WALLPAPER_STYLE_SCALED, "THUNAR_WALLPAPER_STYLE_SCALED", "scaled", }, - { THUNAR_WALLPAPER_STYLE_STRETCHED, "THUNAR_WALLPAPER_STYLE_STRETCHED", "stretched", }, - { THUNAR_WALLPAPER_STYLE_TILED, "THUNAR_WALLPAPER_STYLE_TILED", "tiled", }, - { 0, NULL, NULL, }, - }; - - return thunar_enum_register_type ("ThunarWallpaperStyle", values); + static GType type = G_TYPE_INVALID; + + if (G_UNLIKELY (type == G_TYPE_INVALID)) + { + static const GEnumValue values[] = + { + { THUNAR_WALLPAPER_STYLE_CENTERED, "THUNAR_WALLPAPER_STYLE_CENTERED", "centered", }, + { THUNAR_WALLPAPER_STYLE_SCALED, "THUNAR_WALLPAPER_STYLE_SCALED", "scaled", }, + { THUNAR_WALLPAPER_STYLE_STRETCHED, "THUNAR_WALLPAPER_STYLE_STRETCHED", "stretched", }, + { THUNAR_WALLPAPER_STYLE_TILED, "THUNAR_WALLPAPER_STYLE_TILED", "tiled", }, + { 0, NULL, NULL, }, + }; + + type = g_enum_register_static (I_("ThunarWallpaperStyle"), values); + } + + return type; } @@ -152,9 +206,6 @@ thunar_zoom_level_get_type (void) /* register transformation function for ThunarZoomLevel->ThunarIconSize */ g_value_register_transform_func (type, THUNAR_TYPE_ICON_SIZE, thunar_icon_size_from_zoom_level); - - /* register transformation function for string->ThunarZoomLevel */ - g_value_register_transform_func (G_TYPE_STRING, type, thunar_enum_from_string); } return type; @@ -187,52 +238,6 @@ thunar_zoom_level_to_icon_size (ThunarZoomLevel zoom_level) -static void -thunar_enum_from_string (const GValue *src_value, - GValue *dst_value) -{ - GEnumClass *klass; - gint value = 0; - gint n; - - /* determine the enum value matching the src_value... */ - klass = g_type_class_ref (G_VALUE_TYPE (dst_value)); - for (n = 0; n < klass->n_values; ++n) - { - value = klass->values[n].value; - if (exo_str_is_equal (klass->values[n].value_name, g_value_get_string (src_value))) - break; - } - g_type_class_unref (klass); - - /* ...and return that value */ - g_value_set_enum (dst_value, value); -} - - - -static GType -thunar_enum_register_type (const gchar *enum_name, - const GEnumValue *enum_values) -{ - GType type; - - /* check if we already have the type */ - type = g_type_from_name (enum_name); - if (G_UNLIKELY (type == G_TYPE_INVALID)) - { - /* register the type using the specified enum values */ - type = g_enum_register_static (I_(enum_name), enum_values); - - /* register transformation function, that transforms strings to the enum type */ - g_value_register_transform_func (G_TYPE_STRING, type, thunar_enum_from_string); - } - - return type; -} - - - static void thunar_icon_size_from_zoom_level (const GValue *src_value, GValue *dst_value) diff --git a/thunar/thunar-enum-types.h b/thunar/thunar-enum-types.h index 080ef12bf472546b5185b0dbda32b27e3067a46a..653662395c5714efe2f9655754def38f376808df 100644 --- a/thunar/thunar-enum-types.h +++ b/thunar/thunar-enum-types.h @@ -24,6 +24,26 @@ G_BEGIN_DECLS; +#define THUNAR_TYPE_RENAMER_MODE (thunar_renamer_mode_get_type ()) + +/** + * ThunarRenamerMode: + * @THUNAR_RENAMER_MODE_NAME : only the name should be renamed. + * @THUNAR_RENAMER_MODE_SUFFIX : only the suffix should be renamed. + * @THUNAR_RENAMER_MODE_BOTH : the name and the suffix should be renamed. + * + * The rename mode for a #ThunarRenamerModel instance. + **/ +typedef enum +{ + THUNAR_RENAMER_MODE_NAME, + THUNAR_RENAMER_MODE_SUFFIX, + THUNAR_RENAMER_MODE_BOTH, +} ThunarRenamerMode; + +GType thunar_renamer_mode_get_type (void) G_GNUC_CONST G_GNUC_INTERNAL; + + #define THUNAR_TYPE_COLOR_STYLE (thunar_color_style_get_type ()) /** diff --git a/thunar/thunar-gobject-extensions.c b/thunar/thunar-gobject-extensions.c index 345bbc58af9b760e1d4a6d8c1e10de6695311e02..54d6a7ace6d680090e85cb90f3be8c8cfbb8e446 100644 --- a/thunar/thunar-gobject-extensions.c +++ b/thunar/thunar-gobject-extensions.c @@ -101,6 +101,7 @@ thunar_g_initialize_transformations (void) g_value_register_transform_func (G_TYPE_STRING, G_TYPE_BOOLEAN, transform_string_to_boolean); if (!g_value_type_transformable (G_TYPE_STRING, G_TYPE_INT)) g_value_register_transform_func (G_TYPE_STRING, G_TYPE_INT, transform_string_to_int); - if (!g_value_type_transformable (G_TYPE_STRING, GTK_TYPE_SORT_TYPE)) - g_value_register_transform_func (G_TYPE_STRING, GTK_TYPE_SORT_TYPE, transform_string_to_enum); + + /* register a transformation function string->enum unconditionally */ + g_value_register_transform_func (G_TYPE_STRING, G_TYPE_ENUM, transform_string_to_enum); } diff --git a/thunar/thunar-preferences.c b/thunar/thunar-preferences.c index 5ea781d68ef39d16d75cef1c55c8ce6b07834d9c..815549b6c1b5017fa2fb763cad4c95d1f9c3a16c 100644 --- a/thunar/thunar-preferences.c +++ b/thunar/thunar-preferences.c @@ -178,9 +178,6 @@ thunar_preferences_class_init (ThunarPreferencesClass *klass) gobject_class->get_property = thunar_preferences_get_property; gobject_class->set_property = thunar_preferences_set_property; - /* register additional transformation functions */ - thunar_g_initialize_transformations (); - /** * ThunarPreferences:default-view: *