#include <gtk/gtk.h>

static gboolean
rock (GtkProgressBar *progress)
{
  static gdouble fraction = 0.0;

  if (fraction <= 1.0)
    {
      gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (progress), fraction);
      fraction += 0.1;
    }

  gtk_widget_queue_draw (GTK_WIDGET (progress));

  return TRUE;
}

static void
button_clicked (GtkButton *button, GtkWidget *progress)
{
  static gboolean rocking = FALSE;
  static guint timeout_id = 0;

  rocking = !rocking;

  if (rocking)
    timeout_id = g_timeout_add (100, (GSourceFunc)rock, progress);
  else
    g_source_remove (timeout_id);
}

int main (int argc, char **argv)
{
  GtkWidget *window, *vbox, *button, *status, *progress, *hbox, *vboxp;
  guint context_id;

  gtk_init (&argc, &argv);

  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  g_signal_connect (G_OBJECT (window), "delete-event",
                    G_CALLBACK (gtk_main_quit), NULL);

  vbox = gtk_vbox_new (FALSE, 10);
  gtk_container_add (GTK_CONTAINER (window), vbox);

  button = gtk_button_new_with_label ("Rock and Roll!");
  gtk_container_add (GTK_CONTAINER (vbox), button);

  status = gtk_statusbar_new ();
  context_id = gtk_statusbar_get_context_id (GTK_STATUSBAR (status),
                                             "Test");
  gtk_statusbar_push (GTK_STATUSBAR (status), context_id, "Rock and Roll!");
  hbox = gtk_hbox_new (FALSE, 4);
  g_object_ref (GTK_STATUSBAR (status)->label);
  gtk_container_remove (GTK_CONTAINER (GTK_STATUSBAR (status)->frame),
                        GTK_STATUSBAR (status)->label);
  gtk_box_pack_start (GTK_BOX (hbox), GTK_STATUSBAR (status)->label,
                      TRUE, TRUE, 0);
  g_object_unref (GTK_STATUSBAR (status)->label);

  gtk_container_add (GTK_CONTAINER (GTK_STATUSBAR (status)->frame),
                     hbox);

  vboxp = gtk_vbox_new (FALSE, 0);
  gtk_box_pack_end (GTK_BOX (hbox), vboxp, FALSE, FALSE, 0);
  
  progress = gtk_progress_bar_new ();
  gtk_box_pack_end (GTK_BOX (vboxp), progress,
                    TRUE, TRUE, 1);

  gtk_widget_set_size_request (progress, -1, 10);

  gtk_container_add (GTK_CONTAINER (vbox), status);

  g_signal_connect (G_OBJECT (button), "clicked",
                    G_CALLBACK (button_clicked), progress);

  gtk_widget_show_all (window);

  gtk_main ();

  return 0;
}
