#include <gtk/gtk.h>
#include <gnome-keyring.h>
#include <gnome-keyring-memory.h>

void
password_stored_cb (GnomeKeyringResult result, gpointer user_data)
{
    if (result != GNOME_KEYRING_RESULT_OK) {
        g_message ("An Error has occured: %s",
                   gnome_keyring_result_to_message (result));
        return;
    }
    g_message ("Password stored successfully"); 
}

void
button_clicked_cb (GtkWidget *widget, gpointer user_data)
{
    gchar *password;
    g_message ("Button clicked");
    password = gnome_keyring_memory_strdup ("password");

    gnome_keyring_store_password (GNOME_KEYRING_NETWORK_PASSWORD,
                                    GNOME_KEYRING_DEFAULT,
                                    "Rhythmbox Audioscrobbler Password",
                                    password,
                                    password_stored_cb,
                                    NULL, NULL,
                                    "server", "post.audioscrobbler.com",
                                    NULL);

    gnome_keyring_memory_free (password);

}

int main (int argc, char ** argv)
{
    GtkWidget *window, *button;

    gtk_init (&argc, &argv);
    button = gtk_button_new ();
    window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
    gtk_button_set_label (GTK_BUTTON (button), "enable");
    g_signal_connect (G_OBJECT (button), "clicked",
                      G_CALLBACK (button_clicked_cb), NULL);
    g_signal_connect (G_OBJECT (window), "destroy",
                      G_CALLBACK (gtk_main_quit), NULL);
    gtk_container_add (GTK_CONTAINER (window), button);
    gtk_widget_show_all (window);

    gtk_main ();     

    return 0;                    
}
