diff --git a/capplets/appearance/ChangeLog b/capplets/appearance/ChangeLog index ae5ba8c8a..48424ab0b 100644 --- a/capplets/appearance/ChangeLog +++ b/capplets/appearance/ChangeLog @@ -1,3 +1,9 @@ +2008-05-06 Jens Granseuer + + * Makefile.am: + * appearance-themes.c: (theme_message_area_update): move metatheme + validation code to common/gnome-theme-info.c + 2008-05-04 Jens Granseuer * appearance-desktop.c: (desktop_init): diff --git a/capplets/appearance/Makefile.am b/capplets/appearance/Makefile.am index 3fd9f74d8..6f2d80415 100644 --- a/capplets/appearance/Makefile.am +++ b/capplets/appearance/Makefile.am @@ -57,7 +57,6 @@ INCLUDES = \ -DGNOMECC_DATA_DIR="\"$(pkgdatadir)\"" \ -DGNOMECC_GLADE_DIR="\"$(gladedir)\"" \ -DGNOMECC_PIXMAP_DIR="\"$(pixmapdir)\"" \ - -DGTK_ENGINE_DIR="\"$(GTK_ENGINE_DIR)\"" \ -DWALLPAPER_DATADIR="\"$(wallpaperdir)\"" CLEANFILES = $(GNOMECC_CAPPLETS_CLEANFILES) diff --git a/capplets/appearance/appearance-themes.c b/capplets/appearance/appearance-themes.c index 22678480b..c245b7ade 100644 --- a/capplets/appearance/appearance-themes.c +++ b/capplets/appearance/appearance-themes.c @@ -352,67 +352,6 @@ theme_is_equal (const GnomeThemeMetaInfo *a, const GnomeThemeMetaInfo *b) return TRUE; } -static gchar * -theme_validate (const GnomeThemeMetaInfo *info) -{ - GnomeThemeInfo *theme; - gchar *gtkrc; - - theme = gnome_theme_info_find (info->gtk_theme_name); - if (!theme || !theme->has_gtk) { - return g_strdup_printf ( - _("This theme will not look as intended because the required GTK+ theme '%s' is not installed."), - info->gtk_theme_name); - } - - theme = gnome_theme_info_find (info->metacity_theme_name); - if (!theme || !theme->has_metacity) { - return g_strdup_printf ( - _("This theme will not look as intended because the required window manager theme '%s' is not installed."), - info->metacity_theme_name); - } - - if (!gnome_theme_icon_info_find (info->icon_theme_name)) { - return g_strdup_printf ( - _("This theme will not look as intended because the required icon theme '%s' is not installed."), - info->gtk_theme_name); - } - - /* check for gtk theme engines */ - gtkrc = gtkrc_find_named (info->gtk_theme_name); - if (gtkrc) { - GSList *engines = NULL, *l; - gchar *msg = NULL; - gboolean found; - - gtkrc_get_details (gtkrc, &engines, NULL); - g_free (gtkrc); - - for (l = engines; l; l = l->next) { - gchar *lib = g_strconcat ("lib", l->data, ".so", NULL); - gchar *full = g_build_filename (GTK_ENGINE_DIR, lib, NULL); - - g_free (lib); - found = g_file_test (full, G_FILE_TEST_EXISTS); - g_free (full); - - if (!found) { - msg = g_strdup_printf ( - _("This theme will not look as intended because the required GTK+ theme engine '%s' is not installed."), - (gchar *) l->data); - break; - } - } - - g_slist_foreach (engines, (GFunc) g_free, NULL); - g_slist_free (engines); - - return msg; - } - - return NULL; -} - static void theme_set_custom_from_theme (const GnomeThemeMetaInfo *info, AppearanceData *data) { @@ -639,16 +578,15 @@ theme_message_area_update (AppearanceData *data) gboolean show_revert_font = FALSE; gboolean show_error; const gchar *message; - gchar *error_message; gchar *font; + GError *error = NULL; theme = theme_get_selected (GTK_ICON_VIEW (glade_xml_get_widget (data->xml, "theme_list")), data); if (!theme) return; - error_message = theme_validate (theme); - show_error = (error_message != NULL); + show_error = !gnome_theme_meta_info_validate (theme, &error); if (!show_error) { if (theme->background_image != NULL) { @@ -747,7 +685,7 @@ theme_message_area_update (AppearanceData *data) } if (show_error) - message = error_message; + message = error->message; else if (show_apply_background && show_apply_font && show_revert_font) message = _("The current theme suggests a background and a font. Also, the last applied font suggestion can be reverted."); else if (show_apply_background && show_revert_font) @@ -796,7 +734,7 @@ theme_message_area_update (AppearanceData *data) } gtk_label_set_text (GTK_LABEL (data->theme_message_label), message); - g_free (error_message); + g_clear_error (&error); } static void diff --git a/capplets/common/ChangeLog b/capplets/common/ChangeLog index 5e09485b8..f09fb9308 100644 --- a/capplets/common/ChangeLog +++ b/capplets/common/ChangeLog @@ -1,3 +1,11 @@ +2008-05-06 Jens Granseuer + + * Makefile.am: + * gnome-theme-info.c: (gnome_theme_info_error_quark), + (gnome_theme_meta_info_free), (gnome_theme_meta_info_validate): + * gnome-theme-info.h: move metatheme validation code here from the + appearance capplet and add proper error codes + 2008-05-04 Jens Granseuer * gnome-theme-test.c: (main): doesn't need gnome-vfs any longer diff --git a/capplets/common/Makefile.am b/capplets/common/Makefile.am index 444c4d089..ac0fbca3f 100644 --- a/capplets/common/Makefile.am +++ b/capplets/common/Makefile.am @@ -3,13 +3,13 @@ EXTRA_DIST = ChangeLog INCLUDES = \ -DGNOMECC_DATA_DIR="\"$(pkgdatadir)\"" \ -DGNOMELOCALEDIR="\"$(datadir)/locale\"" \ + -DGTK_ENGINE_DIR="\"$(GTK_ENGINE_DIR)\"" \ -DG_LOG_DOMAIN=\"capplet-common\" \ -DINSTALL_PREFIX=\"$(prefix)\" \ -I$(top_srcdir) \ -I$(top_srcdir)/libbackground \ -I$(top_srcdir)/libwindow-settings \ $(DBUS_CFLAGS) \ - $(VFS_CAPPLET_CFLAGS) \ $(GNOME_DESKTOP_CFLAGS) \ $(METACITY_CFLAGS) \ $(GSD_DBUS_CFLAGS) diff --git a/capplets/common/gnome-theme-info.c b/capplets/common/gnome-theme-info.c index 51016089f..780854721 100644 --- a/capplets/common/gnome-theme-info.c +++ b/capplets/common/gnome-theme-info.c @@ -251,6 +251,12 @@ theme_free (GnomeThemeCommonInfo *info) } } +GQuark +gnome_theme_info_error_quark (void) +{ + return g_quark_from_static_string ("gnome-theme-info-error-quark"); +} + GnomeThemeMetaInfo * gnome_theme_read_meta_theme (GFile *meta_theme_uri) { @@ -1554,6 +1560,71 @@ gnome_theme_meta_info_free (GnomeThemeMetaInfo *meta_theme_info) g_free (meta_theme_info); } +gboolean +gnome_theme_meta_info_validate (GnomeThemeMetaInfo *info, GError **error) +{ + GnomeThemeInfo *theme; + gchar *gtkrc; + + g_assert (error == NULL || *error == NULL); + + theme = gnome_theme_info_find (info->gtk_theme_name); + if (!theme || !theme->has_gtk) { + g_set_error (error, GNOME_THEME_ERROR, GNOME_THEME_ERROR_GTK_THEME_NOT_AVAILABLE, + _("This theme will not look as intended because the required GTK+ theme '%s' is not installed."), + info->gtk_theme_name); + return FALSE; + } + + theme = gnome_theme_info_find (info->metacity_theme_name); + if (!theme || !theme->has_metacity) { + g_set_error (error, GNOME_THEME_ERROR, GNOME_THEME_ERROR_WM_THEME_NOT_AVAILABLE, + _("This theme will not look as intended because the required window manager theme '%s' is not installed."), + info->metacity_theme_name); + return FALSE; + } + + if (!gnome_theme_icon_info_find (info->icon_theme_name)) { + g_set_error (error, GNOME_THEME_ERROR, GNOME_THEME_ERROR_ICON_THEME_NOT_AVAILABLE, + _("This theme will not look as intended because the required icon theme '%s' is not installed."), + info->icon_theme_name); + return FALSE; + } + + /* check for gtk theme engines */ + gtkrc = gtkrc_find_named (info->gtk_theme_name); + if (gtkrc) { + GSList *engines = NULL, *l; + gboolean found; + + gtkrc_get_details (gtkrc, &engines, NULL); + g_free (gtkrc); + + for (l = engines; l; l = l->next) { + gchar *lib = g_strconcat ("lib", l->data, ".so", NULL); + gchar *full = g_build_filename (GTK_ENGINE_DIR, lib, NULL); + + g_free (lib); + found = g_file_test (full, G_FILE_TEST_EXISTS); + g_free (full); + + if (!found) { + g_set_error (error, GNOME_THEME_ERROR, GNOME_THEME_ERROR_GTK_THEME_NOT_AVAILABLE, + _("This theme will not look as intended because the required GTK+ theme engine '%s' is not installed."), + (gchar *) l->data); + break; + } + } + + g_slist_foreach (engines, (GFunc) g_free, NULL); + g_slist_free (engines); + + return found; + } + + return TRUE; +} + GnomeThemeMetaInfo * gnome_theme_meta_info_find (const char *meta_theme_name) { diff --git a/capplets/common/gnome-theme-info.h b/capplets/common/gnome-theme-info.h index f90c6c48a..259bfde8e 100644 --- a/capplets/common/gnome-theme-info.h +++ b/capplets/common/gnome-theme-info.h @@ -128,13 +128,23 @@ typedef void (* ThemeChangedCallback) (GnomeThemeCommonInfo *theme, GnomeThemeChangeType change_type, gpointer user_data); +#define GNOME_THEME_ERROR gnome_theme_info_error_quark () + +enum { + GNOME_THEME_ERROR_GTK_THEME_NOT_AVAILABLE = 1, + GNOME_THEME_ERROR_WM_THEME_NOT_AVAILABLE, + GNOME_THEME_ERROR_ICON_THEME_NOT_AVAILABLE, + GNOME_THEME_ERROR_GTK_ENGINE_NOT_AVAILABLE, + GNOME_THEME_ERROR_UNKNOWN +}; + /* GTK/Metacity/keybinding Themes */ GnomeThemeInfo *gnome_theme_info_new (void); void gnome_theme_info_free (GnomeThemeInfo *theme_info); GnomeThemeInfo *gnome_theme_info_find (const gchar *theme_name); GList *gnome_theme_info_find_by_type (guint elements); - +GQuark gnome_theme_info_error_quark (void); /* Icon Themes */ GnomeThemeIconInfo *gnome_theme_icon_info_new (void); @@ -159,6 +169,8 @@ GnomeThemeMetaInfo *gnome_theme_meta_info_find (const gchar * GList *gnome_theme_meta_info_find_all (void); gint gnome_theme_meta_info_compare (GnomeThemeMetaInfo *a, GnomeThemeMetaInfo *b); +gboolean gnome_theme_meta_info_validate (const GnomeThemeMetaInfo *info, + GError **error); GnomeThemeMetaInfo *gnome_theme_read_meta_theme (GFile *meta_theme_uri); /* Other */