2000-09-09 23:21:28 +00:00
|
|
|
/* -*- mode: c; style: linux -*- */
|
|
|
|
|
|
|
|
/* main.c
|
2001-07-19 21:05:43 +00:00
|
|
|
* Copyright (C) 2000-2001 Ximian, Inc.
|
2000-09-09 23:21:28 +00:00
|
|
|
*
|
2001-07-19 21:05:43 +00:00
|
|
|
* Written by: Bradford Hovinen <hovinen@ximian.com>
|
|
|
|
* Richard Hestilow <hestilow@ximian.com>
|
2000-09-09 23:21:28 +00:00
|
|
|
* 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, 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include <config.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <gnome.h>
|
2001-07-19 21:05:43 +00:00
|
|
|
#include <bonobo.h>
|
2000-09-09 23:21:28 +00:00
|
|
|
|
|
|
|
#include <glade/glade.h>
|
2001-07-19 21:05:43 +00:00
|
|
|
#include <gtk/gtksignal.h>
|
|
|
|
#include "capplet-util.h"
|
|
|
|
#include "applier.h"
|
2000-09-09 23:21:28 +00:00
|
|
|
|
2001-07-19 21:05:43 +00:00
|
|
|
static Applier *applier;
|
2001-04-25 01:00:46 +00:00
|
|
|
|
2001-01-25 18:10:16 +00:00
|
|
|
static void
|
2001-07-19 21:05:43 +00:00
|
|
|
apply_settings (Bonobo_ConfigDatabase db)
|
2001-01-25 18:10:16 +00:00
|
|
|
{
|
2001-07-19 21:05:43 +00:00
|
|
|
CORBA_Environment ev;
|
|
|
|
|
|
|
|
CORBA_exception_init (&ev);
|
|
|
|
applier_apply_prefs (applier, CORBA_OBJECT_NIL, db, &ev, TRUE, FALSE);
|
|
|
|
CORBA_exception_free (&ev);
|
2001-01-25 18:10:16 +00:00
|
|
|
}
|
|
|
|
|
2001-07-19 21:05:43 +00:00
|
|
|
static CORBA_any*
|
|
|
|
gdk_color_to_bonobo (const gchar *colorstr)
|
|
|
|
{
|
|
|
|
GdkColor tmp;
|
|
|
|
CORBA_Environment ev;
|
|
|
|
DynamicAny_DynAny dyn;
|
|
|
|
CORBA_any *any;
|
|
|
|
|
|
|
|
g_return_val_if_fail (colorstr != NULL, NULL);
|
|
|
|
|
|
|
|
CORBA_exception_init (&ev);
|
|
|
|
|
|
|
|
gdk_color_parse (colorstr, &tmp);
|
|
|
|
|
|
|
|
dyn = CORBA_ORB_create_dyn_struct (bonobo_orb (),
|
|
|
|
TC_Bonobo_Config_Color, &ev);
|
|
|
|
|
|
|
|
DynamicAny_DynAny_insert_double (dyn, ((double)tmp.red)/65535, &ev);
|
|
|
|
DynamicAny_DynAny_next (dyn, &ev);
|
|
|
|
DynamicAny_DynAny_insert_double (dyn, ((double)tmp.green)/65535, &ev);
|
|
|
|
DynamicAny_DynAny_next (dyn, &ev);
|
|
|
|
DynamicAny_DynAny_insert_double (dyn, ((double)tmp.blue)/65535, &ev);
|
|
|
|
DynamicAny_DynAny_next (dyn, &ev);
|
|
|
|
DynamicAny_DynAny_insert_double (dyn, 0, &ev);
|
|
|
|
|
|
|
|
any = DynamicAny_DynAny_to_any (dyn, &ev);
|
|
|
|
|
|
|
|
CORBA_Object_release ((CORBA_Object) dyn, &ev);
|
|
|
|
CORBA_exception_free (&ev);
|
|
|
|
|
|
|
|
return any;
|
|
|
|
}
|
2001-05-05 14:19:03 +00:00
|
|
|
|
2000-09-09 23:21:28 +00:00
|
|
|
static void
|
2001-07-19 21:05:43 +00:00
|
|
|
copy_color_from_legacy (Bonobo_ConfigDatabase db,
|
|
|
|
const gchar *key, const gchar *legacy_key)
|
2000-09-09 23:21:28 +00:00
|
|
|
{
|
2001-07-19 21:05:43 +00:00
|
|
|
gboolean def;
|
|
|
|
gchar *val_string;
|
|
|
|
|
|
|
|
g_return_if_fail (key != NULL);
|
|
|
|
g_return_if_fail (legacy_key != NULL);
|
|
|
|
|
|
|
|
val_string = gnome_config_get_string_with_default (legacy_key, &def);
|
|
|
|
|
|
|
|
if (!def)
|
|
|
|
{
|
|
|
|
CORBA_any *color = gdk_color_to_bonobo (val_string);
|
|
|
|
bonobo_config_set_value (db, key, color, NULL);
|
|
|
|
bonobo_arg_release (color);
|
2001-04-25 01:00:46 +00:00
|
|
|
}
|
2001-07-19 21:05:43 +00:00
|
|
|
|
|
|
|
g_free (val_string);
|
2000-09-09 23:21:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-07-19 21:05:43 +00:00
|
|
|
get_legacy_settings (Bonobo_ConfigDatabase db)
|
2000-09-09 23:21:28 +00:00
|
|
|
{
|
2001-07-19 21:05:43 +00:00
|
|
|
gboolean val_boolean, def;
|
|
|
|
gchar *val_string;
|
|
|
|
int val_ulong, val_long;
|
|
|
|
|
|
|
|
COPY_FROM_LEGACY (string, "/main/wallpaper_filename", string, "/Background/Default/wallpaper=none");
|
|
|
|
COPY_FROM_LEGACY (ulong, "/main/wallpaper_type", int, "/Background/Default/wallpaperAlign=0");
|
|
|
|
copy_color_from_legacy (db, "/main/color1", "/Background/Default/color1");
|
|
|
|
copy_color_from_legacy (db, "/main/color2", "/Background/Default/color2");
|
|
|
|
|
|
|
|
/* Code to deal with new enum - messy */
|
|
|
|
val_ulong = -1;
|
|
|
|
val_string = gnome_config_get_string_with_default ("/Background/Default/simple=solid", &def);
|
|
|
|
if (!def)
|
|
|
|
{
|
|
|
|
if (!strcmp (val_string, "solid"))
|
|
|
|
val_ulong = 0;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_free (val_string);
|
|
|
|
val_string = gnome_config_get_string_with_default ("/Background/Default/gradient=vertical", &def);
|
|
|
|
if (!def)
|
|
|
|
val_ulong = !strcmp (val_string, "vertical");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (val_string);
|
|
|
|
|
|
|
|
if (val_ulong != -1)
|
|
|
|
bonobo_config_set_ulong (db, "/main/orientation", val_ulong, NULL);
|
|
|
|
|
|
|
|
val_boolean = gnome_config_get_bool_with_default ("/Background/Default/adjustOpacity=true", &def);
|
|
|
|
if (!def && val_boolean)
|
|
|
|
{
|
|
|
|
COPY_FROM_LEGACY (long, "/main/opacity", int, "/Background/Default/opacity=100");
|
2001-04-25 01:00:46 +00:00
|
|
|
}
|
2000-09-09 23:21:28 +00:00
|
|
|
}
|
|
|
|
|
2001-07-19 21:05:43 +00:00
|
|
|
static void
|
|
|
|
property_change_cb (BonoboListener *listener,
|
|
|
|
char *event_name,
|
|
|
|
CORBA_any *any,
|
|
|
|
CORBA_Environment *ev,
|
|
|
|
Bonobo_PropertyBag pb)
|
2000-09-09 23:21:28 +00:00
|
|
|
{
|
2001-07-19 21:05:43 +00:00
|
|
|
applier_apply_prefs (applier, pb, CORBA_OBJECT_NIL, ev, FALSE, TRUE);
|
2000-09-09 23:21:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-07-19 21:05:43 +00:00
|
|
|
realize_cb (GtkWidget *widget, Bonobo_PropertyBag bag)
|
2000-09-09 23:21:28 +00:00
|
|
|
{
|
2001-07-19 21:05:43 +00:00
|
|
|
CORBA_Environment ev;
|
|
|
|
|
|
|
|
CORBA_exception_init (&ev);
|
|
|
|
applier_apply_prefs (applier, bag, CORBA_OBJECT_NIL, &ev, FALSE, TRUE);
|
|
|
|
CORBA_exception_free (&ev);
|
2000-09-09 23:21:28 +00:00
|
|
|
}
|
|
|
|
|
2001-07-19 21:05:43 +00:00
|
|
|
#define CUSTOM_CREATE_PEDITOR(type, corba_type, key, widget) \
|
|
|
|
{ \
|
|
|
|
BonoboPEditor *ed = BONOBO_PEDITOR \
|
|
|
|
(bonobo_peditor_##type##_construct (WID (widget))); \
|
|
|
|
bonobo_peditor_set_property (ed, bag, key, TC_##corba_type, NULL); \
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-09-09 23:21:28 +00:00
|
|
|
static void
|
2001-07-19 21:05:43 +00:00
|
|
|
setup_dialog (GtkWidget *widget, Bonobo_PropertyBag bag)
|
2000-09-09 23:21:28 +00:00
|
|
|
{
|
2001-07-19 21:05:43 +00:00
|
|
|
BonoboPEditor *ed;
|
|
|
|
GladeXML *dialog;
|
2000-09-09 23:21:28 +00:00
|
|
|
|
2001-07-19 21:05:43 +00:00
|
|
|
dialog = gtk_object_get_data (GTK_OBJECT (widget), "glade-data");
|
|
|
|
ed = BONOBO_PEDITOR (bonobo_peditor_option_construct (0, WID ("color_option")));
|
|
|
|
bonobo_peditor_set_property (ed, bag, "orientation", TC_ulong, NULL);
|
2001-06-18 16:44:33 +00:00
|
|
|
|
2001-07-19 21:05:43 +00:00
|
|
|
CUSTOM_CREATE_PEDITOR (color, Bonobo_Config_Color, "color1", "colorpicker1");
|
|
|
|
CUSTOM_CREATE_PEDITOR (color, Bonobo_Config_Color, "color2", "colorpicker2");
|
|
|
|
CUSTOM_CREATE_PEDITOR (filename, Bonobo_Config_FileName, "wallpaper_filename", "image_fileentry");
|
2001-06-21 14:28:48 +00:00
|
|
|
|
2001-07-19 21:05:43 +00:00
|
|
|
ed = BONOBO_PEDITOR (bonobo_peditor_option_construct (0, WID ("image_option")));
|
|
|
|
bonobo_peditor_set_property (ed, bag, "wallpaper_type", TC_ulong, NULL);
|
2001-06-21 14:28:48 +00:00
|
|
|
|
2001-07-19 21:05:43 +00:00
|
|
|
CUSTOM_CREATE_PEDITOR (int_range, long, "opacity", "opacity_spin");
|
2001-06-21 14:28:48 +00:00
|
|
|
|
2001-07-19 21:05:43 +00:00
|
|
|
bonobo_event_source_client_add_listener (bag, property_change_cb,
|
|
|
|
NULL, NULL, bag);
|
2001-06-18 16:44:33 +00:00
|
|
|
|
2001-07-19 21:05:43 +00:00
|
|
|
gtk_signal_connect_after (GTK_OBJECT (applier_class_get_preview_widget ()), "realize", realize_cb, bag);
|
|
|
|
}
|
2001-06-18 16:44:33 +00:00
|
|
|
|
2001-07-19 21:05:43 +00:00
|
|
|
static GtkWidget*
|
|
|
|
create_dialog (void)
|
|
|
|
{
|
|
|
|
GtkWidget *holder;
|
|
|
|
GtkWidget *widget;
|
|
|
|
GladeXML *dialog;
|
2000-09-09 23:21:28 +00:00
|
|
|
|
2001-07-19 21:05:43 +00:00
|
|
|
dialog = glade_xml_new (GNOMECC_GLADE_DIR "/background-properties.glade", "prefs_widget");
|
|
|
|
widget = glade_xml_get_widget (dialog, "prefs_widget");
|
|
|
|
gtk_object_set_data (GTK_OBJECT (widget), "glade-data", dialog);
|
2000-09-09 23:21:28 +00:00
|
|
|
|
2001-07-19 21:05:43 +00:00
|
|
|
applier = APPLIER (applier_new ());
|
2001-04-29 16:22:27 +00:00
|
|
|
|
2001-07-19 21:05:43 +00:00
|
|
|
/* Minor GUI addition */
|
|
|
|
holder = WID ("preview_holder");
|
|
|
|
gtk_box_pack_start (GTK_BOX (holder),
|
|
|
|
applier_class_get_preview_widget (),
|
|
|
|
TRUE, TRUE, 0);
|
|
|
|
gtk_widget_show_all (holder);
|
2000-09-09 23:21:28 +00:00
|
|
|
|
2001-07-19 21:05:43 +00:00
|
|
|
gtk_signal_connect_object (GTK_OBJECT (widget), "destroy",
|
|
|
|
GTK_SIGNAL_FUNC (gtk_object_destroy),
|
|
|
|
GTK_OBJECT (dialog));
|
2001-05-05 14:19:03 +00:00
|
|
|
|
2001-07-19 21:05:43 +00:00
|
|
|
return widget;
|
2001-01-27 17:14:59 +00:00
|
|
|
}
|
|
|
|
|
2000-09-09 23:21:28 +00:00
|
|
|
int
|
2001-07-19 21:05:43 +00:00
|
|
|
main (int argc, char **argv)
|
2000-09-09 23:21:28 +00:00
|
|
|
{
|
|
|
|
glade_gnome_init ();
|
2001-07-19 21:05:43 +00:00
|
|
|
capplet_init (argc, argv, apply_settings, create_dialog, setup_dialog, get_legacy_settings);
|
2000-09-09 23:21:28 +00:00
|
|
|
|
|
|
|
gnome_window_icon_set_default_from_file
|
2001-07-18 03:21:07 +00:00
|
|
|
(GNOMECC_ICONS_DIR"/gnome-ccbackground.png");
|
2000-09-09 23:21:28 +00:00
|
|
|
return 0;
|
|
|
|
}
|