move metatheme validation code here from the appearance capplet and add

2008-05-06  Jens Granseuer  <jensgr@gmx.net>

	* 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-06  Jens Granseuer  <jensgr@gmx.net>

	* Makefile.am:
	* appearance-themes.c: (theme_message_area_update): move metatheme
	validation code to common/gnome-theme-info.c

svn path=/trunk/; revision=8692
This commit is contained in:
Jens Granseuer 2008-05-06 17:41:57 +00:00 committed by Jens Granseuer
parent b6b9845852
commit 3c71eb6319
7 changed files with 103 additions and 69 deletions

View file

@ -1,3 +1,9 @@
2008-05-06 Jens Granseuer <jensgr@gmx.net>
* Makefile.am:
* appearance-themes.c: (theme_message_area_update): move metatheme
validation code to common/gnome-theme-info.c
2008-05-04 Jens Granseuer <jensgr@gmx.net> 2008-05-04 Jens Granseuer <jensgr@gmx.net>
* appearance-desktop.c: (desktop_init): * appearance-desktop.c: (desktop_init):

View file

@ -57,7 +57,6 @@ INCLUDES = \
-DGNOMECC_DATA_DIR="\"$(pkgdatadir)\"" \ -DGNOMECC_DATA_DIR="\"$(pkgdatadir)\"" \
-DGNOMECC_GLADE_DIR="\"$(gladedir)\"" \ -DGNOMECC_GLADE_DIR="\"$(gladedir)\"" \
-DGNOMECC_PIXMAP_DIR="\"$(pixmapdir)\"" \ -DGNOMECC_PIXMAP_DIR="\"$(pixmapdir)\"" \
-DGTK_ENGINE_DIR="\"$(GTK_ENGINE_DIR)\"" \
-DWALLPAPER_DATADIR="\"$(wallpaperdir)\"" -DWALLPAPER_DATADIR="\"$(wallpaperdir)\""
CLEANFILES = $(GNOMECC_CAPPLETS_CLEANFILES) CLEANFILES = $(GNOMECC_CAPPLETS_CLEANFILES)

View file

@ -352,67 +352,6 @@ theme_is_equal (const GnomeThemeMetaInfo *a, const GnomeThemeMetaInfo *b)
return TRUE; 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 static void
theme_set_custom_from_theme (const GnomeThemeMetaInfo *info, AppearanceData *data) 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_revert_font = FALSE;
gboolean show_error; gboolean show_error;
const gchar *message; const gchar *message;
gchar *error_message;
gchar *font; gchar *font;
GError *error = NULL;
theme = theme_get_selected (GTK_ICON_VIEW (glade_xml_get_widget (data->xml, "theme_list")), data); theme = theme_get_selected (GTK_ICON_VIEW (glade_xml_get_widget (data->xml, "theme_list")), data);
if (!theme) if (!theme)
return; return;
error_message = theme_validate (theme); show_error = !gnome_theme_meta_info_validate (theme, &error);
show_error = (error_message != NULL);
if (!show_error) { if (!show_error) {
if (theme->background_image != NULL) { if (theme->background_image != NULL) {
@ -747,7 +685,7 @@ theme_message_area_update (AppearanceData *data)
} }
if (show_error) if (show_error)
message = error_message; message = error->message;
else if (show_apply_background && show_apply_font && show_revert_font) 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."); 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) 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); gtk_label_set_text (GTK_LABEL (data->theme_message_label), message);
g_free (error_message); g_clear_error (&error);
} }
static void static void

View file

@ -1,3 +1,11 @@
2008-05-06 Jens Granseuer <jensgr@gmx.net>
* 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 <jensgr@gmx.net> 2008-05-04 Jens Granseuer <jensgr@gmx.net>
* gnome-theme-test.c: (main): doesn't need gnome-vfs any longer * gnome-theme-test.c: (main): doesn't need gnome-vfs any longer

View file

@ -3,13 +3,13 @@ EXTRA_DIST = ChangeLog
INCLUDES = \ INCLUDES = \
-DGNOMECC_DATA_DIR="\"$(pkgdatadir)\"" \ -DGNOMECC_DATA_DIR="\"$(pkgdatadir)\"" \
-DGNOMELOCALEDIR="\"$(datadir)/locale\"" \ -DGNOMELOCALEDIR="\"$(datadir)/locale\"" \
-DGTK_ENGINE_DIR="\"$(GTK_ENGINE_DIR)\"" \
-DG_LOG_DOMAIN=\"capplet-common\" \ -DG_LOG_DOMAIN=\"capplet-common\" \
-DINSTALL_PREFIX=\"$(prefix)\" \ -DINSTALL_PREFIX=\"$(prefix)\" \
-I$(top_srcdir) \ -I$(top_srcdir) \
-I$(top_srcdir)/libbackground \ -I$(top_srcdir)/libbackground \
-I$(top_srcdir)/libwindow-settings \ -I$(top_srcdir)/libwindow-settings \
$(DBUS_CFLAGS) \ $(DBUS_CFLAGS) \
$(VFS_CAPPLET_CFLAGS) \
$(GNOME_DESKTOP_CFLAGS) \ $(GNOME_DESKTOP_CFLAGS) \
$(METACITY_CFLAGS) \ $(METACITY_CFLAGS) \
$(GSD_DBUS_CFLAGS) $(GSD_DBUS_CFLAGS)

View file

@ -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 * GnomeThemeMetaInfo *
gnome_theme_read_meta_theme (GFile *meta_theme_uri) 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); 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 * GnomeThemeMetaInfo *
gnome_theme_meta_info_find (const char *meta_theme_name) gnome_theme_meta_info_find (const char *meta_theme_name)
{ {

View file

@ -128,13 +128,23 @@ typedef void (* ThemeChangedCallback) (GnomeThemeCommonInfo *theme,
GnomeThemeChangeType change_type, GnomeThemeChangeType change_type,
gpointer user_data); 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 */ /* GTK/Metacity/keybinding Themes */
GnomeThemeInfo *gnome_theme_info_new (void); GnomeThemeInfo *gnome_theme_info_new (void);
void gnome_theme_info_free (GnomeThemeInfo *theme_info); void gnome_theme_info_free (GnomeThemeInfo *theme_info);
GnomeThemeInfo *gnome_theme_info_find (const gchar *theme_name); GnomeThemeInfo *gnome_theme_info_find (const gchar *theme_name);
GList *gnome_theme_info_find_by_type (guint elements); GList *gnome_theme_info_find_by_type (guint elements);
GQuark gnome_theme_info_error_quark (void);
/* Icon Themes */ /* Icon Themes */
GnomeThemeIconInfo *gnome_theme_icon_info_new (void); 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); GList *gnome_theme_meta_info_find_all (void);
gint gnome_theme_meta_info_compare (GnomeThemeMetaInfo *a, gint gnome_theme_meta_info_compare (GnomeThemeMetaInfo *a,
GnomeThemeMetaInfo *b); GnomeThemeMetaInfo *b);
gboolean gnome_theme_meta_info_validate (const GnomeThemeMetaInfo *info,
GError **error);
GnomeThemeMetaInfo *gnome_theme_read_meta_theme (GFile *meta_theme_uri); GnomeThemeMetaInfo *gnome_theme_read_meta_theme (GFile *meta_theme_uri);
/* Other */ /* Other */