Rewritten to use bonobo-conf.
2001-07-18 Richard Hestilow <hestilow@ximian.com> * Rewritten to use bonobo-conf.
This commit is contained in:
parent
574cfdef9d
commit
59a807f174
9 changed files with 747 additions and 519 deletions
|
@ -1,10 +1,10 @@
|
|||
/* -*- mode: c; style: linux -*- */
|
||||
|
||||
/* main.c
|
||||
* Copyright (C) 2000 Helix Code, Inc.
|
||||
*
|
||||
* Written by Bradford Hovinen (hovinen@helixcode.com)
|
||||
* Copyright (C) 2000-2001 Ximian, Inc.
|
||||
*
|
||||
* Written by: Bradford Hovinen <hovinen@ximian.com>
|
||||
* Richard Hestilow <hestilow@ximian.com>
|
||||
* 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)
|
||||
|
@ -25,276 +25,190 @@
|
|||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
#include <gnome.h>
|
||||
#include <libgnomeui/gnome-window-icon.h>
|
||||
#include <tree.h>
|
||||
#include <parser.h>
|
||||
#include <fcntl.h>
|
||||
#include "capplet-util.h"
|
||||
#include "bonobo-property-editor-range.h"
|
||||
|
||||
#include <glade/glade.h>
|
||||
#include <libgnomeui/gnome-window-icon.h>
|
||||
|
||||
#include <capplet-widget.h>
|
||||
#include <gdk/gdkx.h>
|
||||
#include <X11/X.h>
|
||||
|
||||
#ifdef HAVE_XIMIAN_ARCHIVER
|
||||
# include <ximian-archiver/archive.h>
|
||||
# include <ximian-archiver/location.h>
|
||||
#endif /* HAVE_XIMIAN_ARCHIVER */
|
||||
|
||||
#include "preferences.h"
|
||||
#include "prefs-widget.h"
|
||||
|
||||
static Preferences *prefs;
|
||||
static Preferences *old_prefs;
|
||||
static PrefsWidget *prefs_widget;
|
||||
|
||||
#ifdef HAVE_XIMIAN_ARCHIVER
|
||||
|
||||
static Archive *archive;
|
||||
static gboolean outside_location;
|
||||
#ifdef HAVE_X11_EXTENSIONS_XF86MISC_H
|
||||
#include <X11/extensions/xf86misc.h>
|
||||
#endif
|
||||
|
||||
static void
|
||||
store_archive_data (void)
|
||||
apply_settings (Bonobo_ConfigDatabase db)
|
||||
{
|
||||
Location *location;
|
||||
xmlDocPtr xml_doc;
|
||||
gboolean repeat, click;
|
||||
int rate, delay, volume;
|
||||
int bell_volume, bell_pitch, bell_duration;
|
||||
|
||||
if (capplet_get_location () == NULL)
|
||||
location = archive_get_current_location (archive);
|
||||
else
|
||||
location = archive_get_location (archive,
|
||||
capplet_get_location ());
|
||||
#ifdef HAVE_X11_EXTENSIONS_XF86MISC_H
|
||||
XF86MiscKbdSettings kbdsettings;
|
||||
#endif
|
||||
XKeyboardControl kbdcontrol;
|
||||
int event_base_return, error_base_return;
|
||||
|
||||
xml_doc = preferences_write_xml (prefs);
|
||||
location_store_xml (location, "keyboard-properties-capplet",
|
||||
xml_doc, STORE_MASK_PREVIOUS);
|
||||
xmlFreeDoc (xml_doc);
|
||||
archive_close (archive);
|
||||
}
|
||||
repeat = bonobo_config_get_boolean (db, "/main/repeat", NULL);
|
||||
click = bonobo_config_get_boolean (db, "/main/click", NULL);
|
||||
rate = bonobo_config_get_ulong (db, "/main/rate", NULL);
|
||||
delay = bonobo_config_get_ulong (db, "/main/delay", NULL);
|
||||
volume = bonobo_config_get_ulong (db, "/main/volume", NULL);
|
||||
bell_volume = bonobo_config_get_ulong (db, "/main/bell_volume", NULL);
|
||||
bell_pitch = bonobo_config_get_ulong (db, "/main/bell_pitch", NULL);
|
||||
bell_duration = bonobo_config_get_ulong (db, "/main/bell_duration", NULL);
|
||||
|
||||
#endif /* HAVE_XIMIAN_ARCHIVER */
|
||||
|
||||
static void
|
||||
ok_cb (GtkWidget *widget)
|
||||
{
|
||||
#ifdef HAVE_XIMIAN_ARCHIVER
|
||||
if (!outside_location) {
|
||||
preferences_save (prefs);
|
||||
preferences_apply_now (prefs);
|
||||
}
|
||||
#else /* !HAVE_XIMIAN_ARCHIVER */
|
||||
preferences_save (old_prefs);
|
||||
preferences_apply_now (old_prefs);
|
||||
#endif /* !HAVE_XIMIAN_ARCHIVER */
|
||||
|
||||
#ifdef HAVE_XIMIAN_ARCHIVER
|
||||
store_archive_data ();
|
||||
#endif /* HAVE_XIMIAN_ARCHIVER */
|
||||
}
|
||||
|
||||
static void
|
||||
cancel_cb (GtkWidget *widget)
|
||||
{
|
||||
#ifdef HAVE_XIMIAN_ARCHIVER
|
||||
if (!outside_location) {
|
||||
preferences_save (old_prefs);
|
||||
preferences_apply_now (old_prefs);
|
||||
}
|
||||
#else /* !HAVE_XIMIAN_ARCHIVER */
|
||||
preferences_save (old_prefs);
|
||||
preferences_apply_now (old_prefs);
|
||||
#endif /* !HAVE_XIMIAN_ARCHIVER */
|
||||
}
|
||||
|
||||
static void
|
||||
setup_capplet_widget (void)
|
||||
{
|
||||
preferences_freeze (prefs);
|
||||
|
||||
prefs_widget = PREFS_WIDGET (prefs_widget_new (prefs));
|
||||
|
||||
gtk_signal_connect (GTK_OBJECT (prefs_widget), "ok",
|
||||
GTK_SIGNAL_FUNC (ok_cb), NULL);
|
||||
gtk_signal_connect (GTK_OBJECT (prefs_widget), "cancel",
|
||||
GTK_SIGNAL_FUNC (cancel_cb), NULL);
|
||||
|
||||
gtk_widget_show_all (GTK_WIDGET (prefs_widget));
|
||||
|
||||
preferences_thaw (prefs);
|
||||
}
|
||||
|
||||
#ifdef HAVE_XIMIAN_ARCHIVER
|
||||
|
||||
static void
|
||||
do_get_xml (void)
|
||||
{
|
||||
Preferences *prefs;
|
||||
xmlDocPtr doc;
|
||||
|
||||
prefs = PREFERENCES (preferences_new ());
|
||||
preferences_load (prefs);
|
||||
doc = preferences_write_xml (prefs);
|
||||
xmlDocDump (stdout, doc);
|
||||
gtk_object_destroy (GTK_OBJECT (prefs));
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
do_set_xml (gboolean apply_settings)
|
||||
{
|
||||
xmlDocPtr doc;
|
||||
char buffer[16384];
|
||||
GString *doc_str;
|
||||
int t = 0;
|
||||
|
||||
fflush (stdin);
|
||||
|
||||
fcntl (fileno (stdin), F_SETFL, 0);
|
||||
|
||||
doc_str = g_string_new ("");
|
||||
|
||||
while ((t = read (fileno (stdin), buffer, sizeof (buffer) - 1)) != 0) {
|
||||
buffer[t] = '\0';
|
||||
g_string_append (doc_str, buffer);
|
||||
}
|
||||
|
||||
if (doc_str->len > 0) {
|
||||
doc = xmlParseDoc (doc_str->str);
|
||||
g_string_free (doc_str, TRUE);
|
||||
|
||||
if (doc != NULL) {
|
||||
prefs = preferences_read_xml (doc);
|
||||
|
||||
if (prefs != NULL) {
|
||||
if (apply_settings) {
|
||||
preferences_save (prefs);
|
||||
preferences_apply_now (prefs);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
else if (prefs != NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
xmlFreeDoc (doc);
|
||||
}
|
||||
if (repeat) {
|
||||
XAutoRepeatOn (GDK_DISPLAY ());
|
||||
#ifdef HAVE_X11_EXTENSIONS_XF86MISC_H
|
||||
if (XF86MiscQueryExtension (GDK_DISPLAY (),
|
||||
&event_base_return,
|
||||
&error_base_return) == True)
|
||||
{
|
||||
kbdsettings.rate = rate;
|
||||
kbdsettings.delay = delay;
|
||||
XF86MiscSetKbdSettings (GDK_DISPLAY (), &kbdsettings);
|
||||
} else {
|
||||
XAutoRepeatOff (GDK_DISPLAY ());
|
||||
}
|
||||
#endif
|
||||
} else {
|
||||
g_critical ("No data to apply");
|
||||
XAutoRepeatOff (GDK_DISPLAY ());
|
||||
}
|
||||
|
||||
return;
|
||||
kbdcontrol.key_click_percent =
|
||||
click ? volume : 0;
|
||||
kbdcontrol.bell_percent = bell_volume;
|
||||
kbdcontrol.bell_pitch = bell_pitch;
|
||||
kbdcontrol.bell_duration = bell_duration;
|
||||
XChangeKeyboardControl (GDK_DISPLAY (), KBKeyClickPercent,
|
||||
&kbdcontrol);
|
||||
}
|
||||
|
||||
#endif /* HAVE_XIMIAN_ARCHIVER */
|
||||
static gulong
|
||||
get_value_ulong (Bonobo_PropertyBag bag, const gchar *prop)
|
||||
{
|
||||
BonoboArg *arg;
|
||||
gulong val;
|
||||
|
||||
arg = bonobo_property_bag_client_get_value_any (bag, prop, NULL);
|
||||
val = BONOBO_ARG_GET_GENERAL (arg, TC_ulong, CORBA_unsigned_long, NULL);
|
||||
bonobo_arg_release (arg);
|
||||
return val;
|
||||
}
|
||||
|
||||
static void
|
||||
do_restore_from_defaults (void)
|
||||
bell_cb (GtkWidget *widget, Bonobo_PropertyBag bag)
|
||||
{
|
||||
prefs = PREFERENCES (preferences_new ());
|
||||
preferences_save (prefs);
|
||||
preferences_apply_now (prefs);
|
||||
XKeyboardState backup;
|
||||
XKeyboardControl kbdcontrol;
|
||||
|
||||
XGetKeyboardControl (GDK_DISPLAY (), &backup);
|
||||
|
||||
kbdcontrol.bell_percent = get_value_ulong (bag, "bell_volume");
|
||||
kbdcontrol.bell_pitch = get_value_ulong (bag, "bell_pitch");
|
||||
kbdcontrol.bell_duration = get_value_ulong (bag, "bell_duration");
|
||||
XChangeKeyboardControl (GDK_DISPLAY (),
|
||||
KBBellPercent | KBBellPitch | KBBellDuration,
|
||||
&kbdcontrol);
|
||||
XBell (GDK_DISPLAY (), 0);
|
||||
|
||||
kbdcontrol.bell_percent = backup.bell_percent;
|
||||
kbdcontrol.bell_pitch = backup.bell_pitch;
|
||||
kbdcontrol.bell_duration = backup.bell_duration;
|
||||
|
||||
XChangeKeyboardControl (GDK_DISPLAY (),
|
||||
KBBellPercent | KBBellPitch | KBBellDuration,
|
||||
&kbdcontrol);
|
||||
}
|
||||
|
||||
static GtkWidget*
|
||||
create_dialog (Bonobo_PropertyBag bag)
|
||||
{
|
||||
GladeXML *dialog;
|
||||
GtkWidget *widget, *pixmap;
|
||||
|
||||
dialog = glade_xml_new (GLADE_DATADIR "/keyboard-properties.glade", "prefs_widget");
|
||||
widget = glade_xml_get_widget (dialog, "prefs_widget");
|
||||
gtk_object_set_data (GTK_OBJECT (widget), "glade-data", dialog);
|
||||
|
||||
/* Minor GUI addition */
|
||||
pixmap = gnome_stock_pixmap_widget (WID ("bell_test_button"),
|
||||
GNOME_STOCK_PIXMAP_VOLUME);
|
||||
gtk_box_pack_start (GTK_BOX (WID ("bell_test_holder")), pixmap,
|
||||
TRUE, TRUE, 0);
|
||||
gtk_widget_show_all (WID ("bell_test_button"));
|
||||
|
||||
gtk_signal_connect (GTK_OBJECT (WID ("bell_test_button")),
|
||||
"clicked", bell_cb, bag);
|
||||
|
||||
gtk_signal_connect_object (GTK_OBJECT (widget), "destroy",
|
||||
GTK_SIGNAL_FUNC (gtk_object_destroy),
|
||||
GTK_OBJECT (dialog));
|
||||
|
||||
return widget;
|
||||
}
|
||||
|
||||
static void
|
||||
setup_dialog (GtkWidget *widget, Bonobo_PropertyBag bag)
|
||||
{
|
||||
GladeXML *dialog;
|
||||
BonoboPEditor *ed;
|
||||
|
||||
dialog = gtk_object_get_data (GTK_OBJECT (widget), "glade-data");
|
||||
|
||||
CREATE_PEDITOR (boolean, "repeat", "repeat_toggle");
|
||||
|
||||
ed = BONOBO_PEDITOR (bonobo_peditor_option_construct (0, WID ("delay_menu")));
|
||||
bonobo_peditor_set_property (ed, bag, "delay", TC_ulong, NULL);
|
||||
|
||||
ed = BONOBO_PEDITOR (bonobo_peditor_option_construct (0, WID ("repeat_menu")));
|
||||
bonobo_peditor_set_property (ed, bag, "rate", TC_ulong, NULL);
|
||||
bonobo_peditor_set_guard (WID ("repeat_table"), bag, "repeat");
|
||||
|
||||
CREATE_PEDITOR (boolean, "click", "click_toggle");
|
||||
|
||||
ed = BONOBO_PEDITOR (bonobo_peditor_range_construct (WID ("click_volume_entry")));
|
||||
bonobo_peditor_set_property (ed, bag, "volume", TC_ulong, NULL);
|
||||
bonobo_peditor_set_guard (WID ("click_hbox"), bag, "click");
|
||||
|
||||
/* Bell properties */
|
||||
ed = BONOBO_PEDITOR (bonobo_peditor_range_construct (WID ("bell_volume_range")));
|
||||
bonobo_peditor_set_property (ed, bag, "bell_volume", TC_ulong, NULL);
|
||||
|
||||
ed = BONOBO_PEDITOR (bonobo_peditor_range_construct (WID ("bell_pitch_range")));
|
||||
bonobo_peditor_set_property (ed, bag, "bell_pitch", TC_ulong, NULL);
|
||||
|
||||
ed = BONOBO_PEDITOR (bonobo_peditor_range_construct (WID ("bell_duration_range")));
|
||||
bonobo_peditor_set_property (ed, bag, "bell_duration", TC_ulong, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
get_legacy_settings (Bonobo_ConfigDatabase db)
|
||||
{
|
||||
gboolean val_boolean, def;
|
||||
gulong val_ulong;
|
||||
|
||||
COPY_FROM_LEGACY (boolean, "/main/repeat", bool, "/Desktop/Keyboard/repeat=true");
|
||||
COPY_FROM_LEGACY (boolean, "/main/click", bool, "/Desktop/Keyboard/click=true");
|
||||
COPY_FROM_LEGACY (ulong, "/main/rate", int, "/Desktop/Keyboard/rate=30");
|
||||
COPY_FROM_LEGACY (ulong, "/main/delay", int, "/Desktop/Keyboard/delay=500");
|
||||
COPY_FROM_LEGACY (ulong, "/main/volume", int, "/Desktop/Keyboard/clickvolume=0");
|
||||
COPY_FROM_LEGACY (ulong, "/main/bell_volume", int, "/Desktop/Bell/percent=50");
|
||||
COPY_FROM_LEGACY (ulong, "/main/bell_pitch", int, "/Desktop/Bell/pitch=50");
|
||||
COPY_FROM_LEGACY (ulong, "/main/bell_duration", int, "/Desktop/Bell/duration=100");
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
GnomeClient *client;
|
||||
GnomeClientFlags flags;
|
||||
gint token, res;
|
||||
gchar *restart_args[3];
|
||||
|
||||
bindtextdomain (PACKAGE, GNOMELOCALEDIR);
|
||||
textdomain (PACKAGE);
|
||||
|
||||
glade_gnome_init ();
|
||||
res = gnome_capplet_init ("keyboard-properties-capplet",
|
||||
VERSION, argc, argv, NULL,
|
||||
0, NULL);
|
||||
|
||||
if (res < 0) {
|
||||
g_error ("Could not initialize the capplet.");
|
||||
}
|
||||
else if (res == 3) {
|
||||
#ifdef HAVE_XIMIAN_ARCHIVER
|
||||
do_get_xml ();
|
||||
#endif /* HAVE_XIMIAN_ARCHIVER */
|
||||
return 0;
|
||||
}
|
||||
else if (res == 4) {
|
||||
#ifdef HAVE_XIMIAN_ARCHIVER
|
||||
do_set_xml (TRUE);
|
||||
#endif /* HAVE_XIMIAN_ARCHIVER */
|
||||
return 0;
|
||||
}
|
||||
else if (res == 5) {
|
||||
do_restore_from_defaults ();
|
||||
return 0;
|
||||
}
|
||||
|
||||
client = gnome_master_client ();
|
||||
flags = gnome_client_get_flags (client);
|
||||
|
||||
if (flags & GNOME_CLIENT_IS_CONNECTED) {
|
||||
token = gnome_startup_acquire_token
|
||||
("GNOME_KEYBOARD_PROPERTIES",
|
||||
gnome_client_get_id (client));
|
||||
|
||||
if (token) {
|
||||
gnome_client_set_priority (client, 20);
|
||||
gnome_client_set_restart_style (client,
|
||||
GNOME_RESTART_ANYWAY);
|
||||
restart_args[0] = argv[0];
|
||||
restart_args[1] = "--init-session-settings";
|
||||
restart_args[2] = NULL;
|
||||
gnome_client_set_restart_command (client, 2,
|
||||
restart_args);
|
||||
} else {
|
||||
gnome_client_set_restart_style (client,
|
||||
GNOME_RESTART_NEVER);
|
||||
}
|
||||
} else {
|
||||
token = 1;
|
||||
}
|
||||
capplet_init (argc, argv, apply_settings, create_dialog, setup_dialog, get_legacy_settings);
|
||||
|
||||
gnome_window_icon_set_default_from_file
|
||||
(GNOMECC_ICONS_DIR"keyboard-capplet.png.png");
|
||||
|
||||
#ifdef HAVE_XIMIAN_ARCHIVER
|
||||
archive = ARCHIVE (archive_load (FALSE));
|
||||
|
||||
if (capplet_get_location () != NULL &&
|
||||
strcmp (capplet_get_location (),
|
||||
archive_get_current_location_id (archive)))
|
||||
{
|
||||
outside_location = TRUE;
|
||||
do_set_xml (FALSE);
|
||||
if (prefs == NULL) return -1;
|
||||
preferences_freeze (prefs);
|
||||
} else {
|
||||
outside_location = FALSE;
|
||||
prefs = PREFERENCES (preferences_new ());
|
||||
preferences_load (prefs);
|
||||
}
|
||||
|
||||
if (!outside_location && token) {
|
||||
preferences_apply_now (prefs);
|
||||
}
|
||||
|
||||
#else /* !HAVE_XIMIAN_ARCHIVER */
|
||||
|
||||
prefs = PREFERENCES (preferences_new ());
|
||||
preferences_load (prefs);
|
||||
if (token) preferences_apply_now (prefs);
|
||||
|
||||
#endif /* HAVE_XIMIAN_ARCHIVER */
|
||||
|
||||
if (!res) {
|
||||
old_prefs = PREFERENCES (preferences_clone (prefs));
|
||||
setup_capplet_widget ();
|
||||
|
||||
capplet_gtk_main ();
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue