1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
|
#include <config.h>
#include <gtk/gtk.h>
#include <string.h>
#include "libgnome/gnome-defs.h"
#include "gnome-properties.h"
#include "gnome-propertybox.h"
#include "libgnome/gnome-config.h"
GnomePropertyConfigurator *
gnome_property_configurator_new (void)
{
GnomePropertyConfigurator *this = g_malloc (sizeof (GnomePropertyConfigurator));
this->props = NULL;
this->property_box = NULL;
return this;
}
void
gnome_property_configurator_destroy (GnomePropertyConfigurator *this)
{
g_return_if_fail ( this != NULL );
/* The property box should have closed itself. */
g_list_free (this->props);
}
void
gnome_property_configurator_register (GnomePropertyConfigurator *this,
int (*callback)(GnomePropertyRequest))
{
g_return_if_fail ( this != NULL );
g_return_if_fail ( callback != NULL );
this->props = g_list_append (this->props, callback);
}
/* This is run when the user applies a change in the property box. */
static void
apply_page (GtkObject *object, gint page, gpointer data)
{
GnomePropertyConfigurator *this = (GnomePropertyConfigurator *) data;
int (*cb)(GnomePropertyRequest);
if (page == -1) {
/* Applied all pages. Now write and sync. */
gnome_property_configurator_request_foreach (this, GNOME_PROPERTY_WRITE);
gnome_config_sync ();
return;
}
cb = (int (*)(GnomePropertyRequest))
(g_list_nth (this->props, page)->data);
if (cb)
(*cb) (GNOME_PROPERTY_APPLY);
}
void
gnome_property_configurator_setup (GnomePropertyConfigurator *this)
{
g_return_if_fail ( this != NULL );
this->property_box = gnome_property_box_new ();
gtk_signal_connect (GTK_OBJECT (this->property_box), "apply",
(GtkSignalFunc) apply_page, (gpointer) this);
}
static void
request (int (*cb)(GnomePropertyRequest), GnomePropertyRequest r)
{
(*cb) (r);
}
void
gnome_property_configurator_request_foreach (GnomePropertyConfigurator *this,
GnomePropertyRequest r)
{
g_return_if_fail ( this != NULL );
/* Range check */
g_return_if_fail ( ( r >= 0 ) && ( r <= GNOME_PROPERTY_SETUP ) );
g_list_foreach (this->props, (GFunc)request, (gpointer)r);
}
|