GtkWidget *dialog;
GtkWidget *box;
GConfClient *gconf;
+ guint notify_id;
};
HD_DEFINE_PLUGIN_MODULE (TweakrProfileStatusPlugin,
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);
}
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)
{
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;
}
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);
}