summaryrefslogtreecommitdiff
path: root/dock.c
diff options
context:
space:
mode:
Diffstat (limited to 'dock.c')
-rw-r--r--dock.c102
1 files changed, 71 insertions, 31 deletions
diff --git a/dock.c b/dock.c
index e4321f8..5676f63 100644
--- a/dock.c
+++ b/dock.c
@@ -860,28 +860,48 @@ set_position_from_string (KibaDock *dock, const char *string)
}
static void
+set_option (KibaDock *dock, GConfEntry *entry)
+{
+ const char *value;
+ char *key;
+ int i;
+ struct { const char *name; size_t offset; } options[] = {
+ { "elasticity", G_STRUCT_OFFSET (Model, elasticity) },
+ { "friction", G_STRUCT_OFFSET (Model, friction) },
+ { "k", G_STRUCT_OFFSET (Model, k) }
+ };
+
+ if (strcmp (entry->key, KIBA_GCONF_PATH "/options/position") == 0 &&
+ entry->value != NULL &&
+ entry->value->type == GCONF_VALUE_STRING)
+ {
+ value = gconf_value_get_string (entry->value);
+ set_position_from_string (dock, value);
+ }
+ else for (i = 0; i < G_N_ELEMENTS (options); i++) {
+ key = g_strdup_printf (KIBA_GCONF_PATH "/options/%s", options[i].name);
+ if (strcmp (entry->key, key) == 0 &&
+ entry->value != NULL &&
+ entry->value->type == GCONF_VALUE_FLOAT)
+ {
+ G_STRUCT_MEMBER (double, &dock->model, options[i].offset) =
+ gconf_value_get_float (entry->value);
+ }
+ g_free (key);
+ }
+}
+
+static void
options_changed_callback(GConfClient *client,
guint cnxn_id,
GConfEntry *entry,
gpointer user_data)
{
KibaDock *dock;
- const char *value;
dock = KIBA_DOCK (user_data);
- if (strcmp (entry->key, KIBA_GCONF_PATH "/options/position") == 0)
- {
- if (entry->value == NULL || entry->value->type != GCONF_VALUE_STRING)
- {
- printf ("unset or wrong type\n");
- }
- else
- {
- value = gconf_value_get_string (entry->value);
- set_position_from_string (dock, value);
- }
- }
+ set_option (dock, entry);
}
static void
@@ -911,7 +931,6 @@ launchers_changed_callback(GConfClient *client,
path = g_strdup (entry->key);
last_slash = strrchr (path, '/');
*last_slash = '\0';
- printf ("entry: key = %s, path = %s\n", entry->key, path);
launcher = kiba_launcher_new (dock, path);
g_free (path);
@@ -925,10 +944,9 @@ launchers_changed_callback(GConfClient *client,
}
static void
-add_launchers (KibaDock *dock, GConfClient *gconf_client)
+init_from_gconf (KibaDock *dock, GConfClient *gconf_client, GError **error)
{
- GSList *launchers, *l;
- GError *error = NULL;
+ GSList *launchers, *options, *l;
KibaLauncher *launcher;
GdkScreen *screen;
int width, height;
@@ -939,12 +957,9 @@ add_launchers (KibaDock *dock, GConfClient *gconf_client)
launchers = gconf_client_all_dirs (gconf_client,
KIBA_GCONF_PATH "/launchers",
- &error);
- if (error != NULL)
- {
- printf ("error getting launchers: %s\n", error->message);
- g_free (error->message);
- }
+ error);
+ if (*error != NULL)
+ return;
for (l = launchers; l != NULL; l = l->next)
{
@@ -957,6 +972,19 @@ add_launchers (KibaDock *dock, GConfClient *gconf_client)
g_random_int_range (0, width),
g_random_int_range (0, height));
}
+
+ options = gconf_client_all_entries (gconf_client,
+ KIBA_GCONF_PATH "/options",
+ error);
+ if (*error != NULL)
+ return;
+
+ for (l = options; l != NULL; l = l->next)
+ {
+ GConfEntry *entry = l->data;
+
+ set_option (dock, entry);
+ }
}
int main (int argc, char *argv[])
@@ -964,7 +992,6 @@ int main (int argc, char *argv[])
GtkWidget *dock;
GConfClient *gconf_client;
GError *error = NULL;
- char *position;
gtk_init (&argc, &argv);
@@ -975,23 +1002,36 @@ int main (int argc, char *argv[])
gconf_client_add_dir (gconf_client, KIBA_GCONF_PATH,
GCONF_CLIENT_PRELOAD_NONE, &error);
- position = gconf_client_get_string (gconf_client,
- KIBA_GCONF_PATH "/options/position",
- &error);
- set_position_from_string (KIBA_DOCK (dock), position);
- g_free (position);
-
gconf_client_notify_add(gconf_client, KIBA_GCONF_PATH "/options",
options_changed_callback,
dock,
NULL, &error);
+ if (error != NULL)
+ {
+ g_error ("Failed to listen for "
+ KIBA_GCONF_PATH "/options notifications: %s",
+ error->message);
+ exit (1);
+ }
gconf_client_notify_add(gconf_client, KIBA_GCONF_PATH "/launchers",
launchers_changed_callback,
dock,
NULL, &error);
+ if (error != NULL)
+ {
+ g_error ("Failed to listen for "
+ KIBA_GCONF_PATH "/launchers notifications: %s",
+ error->message);
+ exit (1);
+ }
- add_launchers (KIBA_DOCK (dock), gconf_client);
+ init_from_gconf (KIBA_DOCK (dock), gconf_client, &error);
+ if (error != NULL)
+ {
+ g_error ("Failed to read config from gconf: %s", error->message);
+ exit (1);
+ }
gtk_widget_show (dock);