Committed new schemas patch.
2002-03-14 Richard Hestilow <hestilow@ximian.com> * Committed new schemas patch.
This commit is contained in:
parent
e89410ab87
commit
c10c6c06ce
7 changed files with 629 additions and 110 deletions
|
@ -25,7 +25,6 @@
|
|||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <gnome.h>
|
||||
|
@ -42,6 +41,53 @@ static void bg_preferences_class_init (BGPreferencesClass *class);
|
|||
static void bg_preferences_finalize (GObject *object);
|
||||
|
||||
static GdkColor *read_color_from_string (const gchar *string);
|
||||
static orientation_t read_orientation_from_string (gchar *string);
|
||||
static wallpaper_type_t read_wptype_from_string (gchar *string);
|
||||
|
||||
static GEnumValue _bg_wptype_values[] = {
|
||||
{ WPTYPE_TILED, "wallpaper", N_("Tiled") },
|
||||
{ WPTYPE_CENTERED, "centered", N_("Centered") },
|
||||
{ WPTYPE_SCALED, "scaled", N_("Scaled") },
|
||||
{ WPTYPE_STRETCHED, "stretched", N_("Stretched") },
|
||||
{ WPTYPE_EMBOSSED, "embossed", N_("Embossed") },
|
||||
{ WPTYPE_NONE, "none", N_("None") },
|
||||
{ 0, NULL, NULL }
|
||||
};
|
||||
|
||||
static GEnumValue _bg_orientation_values[] = {
|
||||
{ ORIENTATION_SOLID, "solid", N_("Solid") },
|
||||
{ ORIENTATION_HORIZ, "horizontal-gradient", N_("Horizontal Gradient") },
|
||||
{ ORIENTATION_VERT, "vertical-gradient", N_("Vertical Gradient") },
|
||||
{ 0, NULL, NULL }
|
||||
};
|
||||
|
||||
GType
|
||||
bg_preferences_wptype_get_type (void)
|
||||
{
|
||||
static GType type = 0;
|
||||
|
||||
if (!type)
|
||||
{
|
||||
type = g_enum_register_static ("BgPreferencesWptype",
|
||||
_bg_wptype_values);
|
||||
}
|
||||
|
||||
return type;
|
||||
}
|
||||
|
||||
GType
|
||||
bg_preferences_orientation_get_type (void)
|
||||
{
|
||||
static GType type = 0;
|
||||
|
||||
if (!type)
|
||||
{
|
||||
type = g_enum_register_static ("BgPreferencesOrientation",
|
||||
_bg_orientation_values);
|
||||
}
|
||||
|
||||
return type;
|
||||
}
|
||||
|
||||
GType
|
||||
bg_preferences_get_type (void)
|
||||
|
@ -86,7 +132,7 @@ bg_preferences_init (BGPreferences *prefs,
|
|||
prefs->wallpaper_sel_path = g_strdup (g_get_home_dir ());
|
||||
prefs->auto_apply = TRUE;
|
||||
prefs->wallpapers = NULL;
|
||||
prefs->adjust_opacity = FALSE;
|
||||
prefs->adjust_opacity = TRUE;
|
||||
prefs->opacity = 255;
|
||||
}
|
||||
|
||||
|
@ -174,22 +220,30 @@ bg_preferences_load (BGPreferences *prefs)
|
|||
|
||||
client = gconf_client_get_default ();
|
||||
|
||||
prefs->enabled = gconf_client_get_bool (client, "/desktop/gnome/background/enabled", &error);
|
||||
prefs->wallpaper_type = gconf_client_get_int (client, "/desktop/gnome/background/wallpaper-type", &error);
|
||||
prefs->wallpaper_filename = gconf_client_get_string (client, "/desktop/gnome/background/wallpaper-filename", &error);
|
||||
prefs->wallpaper_enabled = gconf_client_get_bool (client, "/desktop/gnome/background/wallpaper-enabled", &error);
|
||||
prefs->color1 = read_color_from_string (gconf_client_get_string (client, "/desktop/gnome/background/color1", &error));
|
||||
prefs->color2 = read_color_from_string (gconf_client_get_string (client, "/desktop/gnome/background/color2", &error));
|
||||
prefs->opacity = gconf_client_get_int (client, "/desktop/gnome/background/opacity", &error);
|
||||
prefs->enabled = gconf_client_get_bool (client, BG_PREFERENCES_DRAW_BACKGROUND, &error);
|
||||
prefs->wallpaper_filename = gconf_client_get_string (client, BG_PREFERENCES_PICTURE_FILENAME, &error);
|
||||
|
||||
prefs->color1 = read_color_from_string (gconf_client_get_string (client, BG_PREFERENCES_PRIMARY_COLOR, &error));
|
||||
prefs->color2 = read_color_from_string (gconf_client_get_string (client, BG_PREFERENCES_SECONDARY_COLOR, &error));
|
||||
|
||||
prefs->opacity = gconf_client_get_int (client, BG_PREFERENCES_PICTURE_OPACITY, &error);
|
||||
if (prefs->opacity >= 100 || prefs->opacity < 0)
|
||||
prefs->adjust_opacity = FALSE;
|
||||
|
||||
prefs->orientation = gconf_client_get_int (client, "/desktop/gnome/background/orientation", &error);
|
||||
|
||||
prefs->orientation = read_orientation_from_string (gconf_client_get_string (client, BG_PREFERENCES_COLOR_SHADING_TYPE, &error));
|
||||
if (prefs->orientation == ORIENTATION_SOLID)
|
||||
prefs->gradient_enabled = FALSE;
|
||||
else
|
||||
prefs->gradient_enabled = TRUE;
|
||||
|
||||
prefs->wallpaper_type = read_wptype_from_string (gconf_client_get_string (client, BG_PREFERENCES_PICTURE_OPTIONS, &error));
|
||||
|
||||
if (prefs->wallpaper_type == -1) {
|
||||
prefs->wallpaper_enabled = FALSE;
|
||||
prefs->wallpaper_type = WPTYPE_CENTERED;
|
||||
} else {
|
||||
prefs->wallpaper_enabled = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
/* Parse the event name given (the event being notification of a property having
|
||||
|
@ -206,10 +260,17 @@ bg_preferences_merge_entry (BGPreferences *prefs,
|
|||
g_return_if_fail (prefs != NULL);
|
||||
g_return_if_fail (IS_BG_PREFERENCES (prefs));
|
||||
|
||||
if (!strcmp (entry->key, "/desktop/gnome/background/wallpaper_type")) {
|
||||
prefs->wallpaper_type = gconf_value_get_int (value);
|
||||
if (!strcmp (entry->key, BG_PREFERENCES_PICTURE_OPTIONS)) {
|
||||
wallpaper_type_t wallpaper_type = read_wptype_from_string (g_strdup (gconf_value_get_string (value)));
|
||||
if (wallpaper_type == -1) {
|
||||
prefs->wallpaper_enabled = FALSE;
|
||||
} else {
|
||||
prefs->wallpaper_type = wallpaper_type;
|
||||
prefs->wallpaper_enabled = TRUE;
|
||||
}
|
||||
|
||||
}
|
||||
else if (!strcmp (entry->key, "/desktop/gnome/background/wallpaper-filename")) {
|
||||
else if (!strcmp (entry->key, BG_PREFERENCES_PICTURE_FILENAME)) {
|
||||
prefs->wallpaper_filename = g_strdup (gconf_value_get_string (value));
|
||||
|
||||
if (prefs->wallpaper_filename != NULL &&
|
||||
|
@ -219,42 +280,76 @@ bg_preferences_merge_entry (BGPreferences *prefs,
|
|||
else
|
||||
prefs->wallpaper_enabled = FALSE;
|
||||
}
|
||||
else if (!strcmp (entry->key, "/desktop/gnome/background/color1")) {
|
||||
else if (!strcmp (entry->key, BG_PREFERENCES_PRIMARY_COLOR)) {
|
||||
prefs->color1 = read_color_from_string (gconf_value_get_string (value));
|
||||
}
|
||||
else if (!strcmp (entry->key, "/desktop/gnome/background/color2")) {
|
||||
else if (!strcmp (entry->key, BG_PREFERENCES_SECONDARY_COLOR)) {
|
||||
prefs->color2 = read_color_from_string (gconf_value_get_string (value));
|
||||
}
|
||||
else if (!strcmp (entry->key, "/desktop/gnome/background/opacity")) {
|
||||
else if (!strcmp (entry->key, BG_PREFERENCES_PICTURE_OPACITY)) {
|
||||
prefs->opacity = gconf_value_get_int (value);
|
||||
|
||||
if (prefs->opacity >= 100)
|
||||
prefs->adjust_opacity = FALSE;
|
||||
}
|
||||
else if (!strcmp (entry->key, "/desktop/gnome/background/orientation")) {
|
||||
prefs->orientation = gconf_value_get_int (value);
|
||||
else if (!strcmp (entry->key, BG_PREFERENCES_COLOR_SHADING_TYPE)) {
|
||||
prefs->orientation = read_orientation_from_string (g_strdup (gconf_value_get_string (value)));
|
||||
|
||||
if (prefs->orientation == ORIENTATION_SOLID)
|
||||
prefs->gradient_enabled = FALSE;
|
||||
else
|
||||
prefs->gradient_enabled = TRUE;
|
||||
}
|
||||
else if (!strcmp (entry->key, "/desktop/gnome/background/wallpaper-enabled")) {
|
||||
if (gconf_value_get_bool (value) &&
|
||||
(prefs->wallpaper_filename != NULL) &&
|
||||
strcmp (prefs->wallpaper_filename, "") != 0 &&
|
||||
strcmp (prefs->wallpaper_filename, "(none)") != 0)
|
||||
prefs->wallpaper_enabled = TRUE;
|
||||
else if (!strcmp (entry->key, BG_PREFERENCES_DRAW_BACKGROUND)) {
|
||||
if (gconf_value_get_bool (value))
|
||||
prefs->enabled = TRUE;
|
||||
else
|
||||
prefs->wallpaper_enabled = FALSE;
|
||||
}
|
||||
else if (!strcmp (entry->key, "/desktop/gnome/background/wallpaper-type")) {
|
||||
prefs->wallpaper_type = gconf_value_get_int (value);
|
||||
prefs->enabled = FALSE;
|
||||
} else {
|
||||
g_warning ("%s: Unknown property: %s", G_GNUC_FUNCTION, entry->key);
|
||||
g_warning ("%s: Unknown property: %s", __FUNCTION__, entry->key);
|
||||
}
|
||||
}
|
||||
|
||||
static wallpaper_type_t
|
||||
read_wptype_from_string (gchar *string)
|
||||
{
|
||||
wallpaper_type_t type = -1;
|
||||
|
||||
if (string) {
|
||||
if (!strncmp (string, "wallpaper", sizeof ("wallpaper"))) {
|
||||
type = WPTYPE_TILED;
|
||||
} else if (!strncmp (string, "centered", sizeof ("centered"))) {
|
||||
type = WPTYPE_CENTERED;
|
||||
} else if (!strncmp (string, "scaled", sizeof ("scaled"))) {
|
||||
type = WPTYPE_SCALED;
|
||||
} else if (!strncmp (string, "stretched", sizeof ("stretched"))) {
|
||||
type = WPTYPE_STRETCHED;
|
||||
} else if (!strncmp (string, "embossed", sizeof ("embossed"))) {
|
||||
type = WPTYPE_EMBOSSED;
|
||||
}
|
||||
g_free (string);
|
||||
}
|
||||
|
||||
return type;
|
||||
}
|
||||
|
||||
static orientation_t
|
||||
read_orientation_from_string (gchar *string)
|
||||
{
|
||||
orientation_t type = ORIENTATION_SOLID;
|
||||
|
||||
if (string) {
|
||||
if (!strncmp (string, "vertical-gradient", sizeof ("vertical-gradient"))) {
|
||||
type = ORIENTATION_VERT;
|
||||
} else if (!strncmp (string, "horizontal-gradient", sizeof ("horizontal-gradient"))) {
|
||||
type = ORIENTATION_HORIZ;
|
||||
}
|
||||
g_free (string);
|
||||
}
|
||||
|
||||
return type;
|
||||
}
|
||||
|
||||
static GdkColor *
|
||||
read_color_from_string (const gchar *string)
|
||||
{
|
||||
|
@ -269,16 +364,51 @@ read_color_from_string (const gchar *string)
|
|||
((color->green >> 8) << 8) ||
|
||||
(color->blue >> 8);
|
||||
#if 0
|
||||
/* fixme: I am not sure, but this can be accomplished otherwise */
|
||||
color->pixel = gdk_rgb_xpixel_from_rgb (rgb);
|
||||
#else
|
||||
gdk_rgb_find_color (gdk_rgb_get_colormap (), color);
|
||||
#endif
|
||||
}
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
#define DGB "/desktop/gnome/background/"
|
||||
const gchar*
|
||||
bg_preferences_get_wptype_as_string (wallpaper_type_t wp)
|
||||
{
|
||||
switch (wp)
|
||||
{
|
||||
case WPTYPE_TILED:
|
||||
return "wallpaper";
|
||||
case WPTYPE_CENTERED:
|
||||
return "centered";
|
||||
case WPTYPE_SCALED:
|
||||
return "scaled";
|
||||
case WPTYPE_STRETCHED:
|
||||
return "stretched";
|
||||
case WPTYPE_EMBOSSED:
|
||||
return "embossed";
|
||||
case WPTYPE_NONE:
|
||||
return "none";
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const gchar*
|
||||
bg_preferences_get_orientation_as_string (orientation_t o)
|
||||
{
|
||||
switch (o)
|
||||
{
|
||||
case ORIENTATION_SOLID:
|
||||
return "solid";
|
||||
case ORIENTATION_HORIZ:
|
||||
return "horizontal-gradient";
|
||||
case ORIENTATION_VERT:
|
||||
return "vertical-gradient";
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void
|
||||
bg_preferences_save (BGPreferences *prefs)
|
||||
|
@ -290,29 +420,32 @@ bg_preferences_save (BGPreferences *prefs)
|
|||
g_return_if_fail (IS_BG_PREFERENCES (prefs));
|
||||
|
||||
cs = gconf_change_set_new ();
|
||||
gconf_change_set_set_bool (cs, DGB "enabled", prefs->enabled);
|
||||
gconf_change_set_set_bool (cs, DGB "wallpaper-enabled", prefs->wallpaper_enabled);
|
||||
gconf_change_set_set_int (cs, DGB "wallpaper-type", prefs->wallpaper_type);
|
||||
gconf_change_set_set_string (cs, DGB "wallpaper-filename", prefs->wallpaper_filename);
|
||||
gconf_change_set_set_bool (cs, BG_PREFERENCES_DRAW_BACKGROUND, prefs->enabled);
|
||||
if (prefs->wallpaper_enabled)
|
||||
gconf_change_set_set_string (cs, BG_PREFERENCES_PICTURE_OPTIONS, bg_preferences_get_wptype_as_string (prefs->wallpaper_type));
|
||||
else
|
||||
gconf_change_set_set_string (cs, BG_PREFERENCES_PICTURE_OPTIONS, "none");
|
||||
|
||||
gconf_change_set_set_string (cs, BG_PREFERENCES_PICTURE_FILENAME, prefs->wallpaper_filename);
|
||||
|
||||
tmp = g_strdup_printf ("#%02x%02x%02x",
|
||||
prefs->color1->red >> 8,
|
||||
prefs->color1->green >> 8,
|
||||
prefs->color1->blue >> 8);
|
||||
gconf_change_set_set_string (cs, DGB "color1", tmp);
|
||||
gconf_change_set_set_string (cs, BG_PREFERENCES_PRIMARY_COLOR, tmp);
|
||||
g_free (tmp);
|
||||
|
||||
tmp = g_strdup_printf ("#%02x%02x%02x",
|
||||
prefs->color2->red >> 8,
|
||||
prefs->color2->green >> 8,
|
||||
prefs->color2->blue >> 8);
|
||||
gconf_change_set_set_string (cs, DGB "color2", tmp);
|
||||
gconf_change_set_set_string (cs, BG_PREFERENCES_SECONDARY_COLOR, tmp);
|
||||
g_free (tmp);
|
||||
|
||||
gconf_change_set_set_int (cs, DGB "orientation", prefs->orientation);
|
||||
gconf_change_set_set_string (cs, BG_PREFERENCES_COLOR_SHADING_TYPE, bg_preferences_get_orientation_as_string (prefs->orientation));
|
||||
|
||||
gconf_client_commit_change_set (gconf_client_get_default (), cs, TRUE, NULL);
|
||||
gconf_change_set_unref (cs);
|
||||
}
|
||||
|
||||
#undef DGB
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue