X-Git-Url: https://vcs.maemo.org/git/?a=blobdiff_plain;f=modules%2Ftweakr-profile-status-menu-widget.c;h=75e263483a1e8e23ecc9423d77e12a3cb82c9c64;hb=31684bed7834ef2b8271a695616ebe2b1e32354a;hp=7d2e7a85276148109788af29c2e228ed7c457d8c;hpb=1cf6d3f69c9a1b9b1164786d9a7a315e9a98d5ee;p=tweakr diff --git a/modules/tweakr-profile-status-menu-widget.c b/modules/tweakr-profile-status-menu-widget.c index 7d2e7a8..75e2634 100644 --- a/modules/tweakr-profile-status-menu-widget.c +++ b/modules/tweakr-profile-status-menu-widget.c @@ -70,6 +70,7 @@ struct _TweakrProfileStatusPluginPrivate GtkWidget *dialog; GtkWidget *box; GConfClient *gconf; + guint notify_id; }; HD_DEFINE_PLUGIN_MODULE (TweakrProfileStatusPlugin, @@ -107,7 +108,7 @@ _preset_clicked (HildonButton *button, TweakrProfileStatusPlugin *plugin) basename = g_path_get_basename (path); hildon_button_set_value (HILDON_BUTTON (plugin->priv->button), basename); gconf_client_set_string (plugin->priv->gconf, - "/system/tweakr/current-preset", basename, NULL); + GCONF_PATH "/current-preset", basename, NULL); g_free (basename); gtk_dialog_response (GTK_DIALOG (plugin->priv->dialog), GTK_RESPONSE_OK); @@ -172,6 +173,55 @@ _button_clicked (HildonButton *b, TweakrProfileStatusPlugin *plugin) } static void +_create_main_button (TweakrProfileStatusPlugin *plugin) +{ + gchar *current; + GtkWidget *image; + + plugin->priv->button = hildon_button_new + (HILDON_SIZE_AUTO | HILDON_SIZE_FINGER_HEIGHT, + HILDON_BUTTON_ARRANGEMENT_VERTICAL); + hildon_button_set_title (HILDON_BUTTON (plugin->priv->button), + _("Profile preset")); + + current = gconf_client_get_string (plugin->priv->gconf, + GCONF_PATH "/current-preset", + NULL); + + hildon_button_set_value (HILDON_BUTTON (plugin->priv->button), current); + g_free (current); + gtk_button_set_alignment (GTK_BUTTON (plugin->priv->button), 0.0f, 0.5f); + + image = gtk_image_new_from_icon_name ("control_tweakr", + GTK_ICON_SIZE_BUTTON); + hildon_button_set_image (HILDON_BUTTON (plugin->priv->button), image); + + g_signal_connect (G_OBJECT (plugin->priv->button), "clicked", + G_CALLBACK (_button_clicked), plugin); + + gtk_container_add (GTK_CONTAINER (plugin), plugin->priv->button); + gtk_widget_show_all (plugin->priv->button); +} + +static void +_current_preset_changed_cb (GConfClient *client, guint notify_id, + GConfEntry *entry, + TweakrProfileStatusPlugin *plugin) +{ + if (plugin->priv->button == NULL) + { + _create_main_button (plugin); + gtk_widget_show (GTK_WIDGET (plugin)); + } + else + { + hildon_button_set_value (HILDON_BUTTON (plugin->priv->button), + gconf_value_get_string (entry->value)); + } +} + + +static void tweakr_profile_status_plugin_class_finalize (TweakrProfileStatusPluginClass *klass) { @@ -184,6 +234,14 @@ tweakr_profile_status_plugin_dispose (GObject *obj) if (plugin->priv->gconf != NULL) { + if (plugin->priv->notify_id) + { + gconf_client_notify_remove (plugin->priv->gconf, + plugin->priv->notify_id); + plugin->priv->notify_id = 0; + } + + gconf_client_remove_dir (plugin->priv->gconf, GCONF_PATH, NULL); g_object_unref (plugin->priv->gconf); plugin->priv->gconf = NULL; } @@ -207,34 +265,26 @@ static void tweakr_profile_status_plugin_init (TweakrProfileStatusPlugin *plugin) { gchar *current; - GtkWidget *image; plugin->priv = TWEAKR_PROFILE_STATUS_PLUGIN_GET_PRIVATE (plugin); plugin->priv->gconf = gconf_client_get_default (); - plugin->priv->button = hildon_button_new - (HILDON_SIZE_AUTO | HILDON_SIZE_FINGER_HEIGHT, - HILDON_BUTTON_ARRANGEMENT_VERTICAL); - hildon_button_set_title (HILDON_BUTTON (plugin->priv->button), - _("Tweakr profile preset")); + gconf_client_add_dir (plugin->priv->gconf, GCONF_PATH, + GCONF_CLIENT_PRELOAD_NONE, NULL); + plugin->priv->notify_id = gconf_client_notify_add + (plugin->priv->gconf, GCONF_PATH "/current-preset", + (GConfClientNotifyFunc) _current_preset_changed_cb, plugin, + NULL, NULL); current = gconf_client_get_string (plugin->priv->gconf, - "/system/tweakr/current-preset", + GCONF_PATH "/current-preset", NULL); - hildon_button_set_value (HILDON_BUTTON (plugin->priv->button), current); - g_free (current); - gtk_button_set_alignment (GTK_BUTTON (plugin->priv->button), 0.0f, 0.5f); - image = gtk_image_new_from_icon_name ("control_tweakr", - GTK_ICON_SIZE_BUTTON); - hildon_button_set_image (HILDON_BUTTON (plugin->priv->button), image); - - g_signal_connect (G_OBJECT (plugin->priv->button), "clicked", - G_CALLBACK (_button_clicked), plugin); - - gtk_container_add (GTK_CONTAINER (plugin), plugin->priv->button); - gtk_widget_show_all (plugin->priv->button); + if (current == NULL) + return; + _create_main_button (plugin); gtk_widget_show (GTK_WIDGET (plugin)); + g_free (current); }