chiark / gitweb /
desensitive queue context menu options when disconnected
[disorder] / disobedience / control.c
index 776aff1232ea18c00244c96ab8cdc648574ccf3e..f65c78ca10bad6b1f2f51214ba4938feab0373ff 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * This file is part of DisOrder.
- * Copyright (C) 2006 Richard Kettlewell
+ * Copyright (C) 2006, 2007 Richard Kettlewell
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
 
 #include "disobedience.h"
 
-/* Forward declartions ----------------------------------------------------- */
+/* Forward declarations ---------------------------------------------------- */
+
+WT(adjustment);
+WT(hscale);
+WT(hbox);
+WT(tooltips);
+WT(button);
+WT(image);
+WT(label);
+WT(vbox);
 
 struct icon;
 
@@ -77,7 +86,7 @@ static struct icon {
 GtkAdjustment *volume_adj, *balance_adj;
 
 /* Create the control bar */
- GtkWidget *control_widget(void) {
+GtkWidget *control_widget(void) {
   GtkWidget *hbox = gtk_hbox_new(FALSE, 1), *vbox;
   GtkWidget *content;
   GdkPixbuf *pb;
@@ -85,31 +94,42 @@ GtkAdjustment *volume_adj, *balance_adj;
   GtkTooltips *tips = gtk_tooltips_new();
   int n;
 
+  NW(hbox);
+  NW(tooltips);
   D(("control_widget"));
   for(n = 0; n < NICONS; ++n) {
+    NW(button);
     icons[n].button = gtk_button_new();
-    if((pb = find_image(icons[n].icon)))
+    if((pb = find_image(icons[n].icon))) {
+      NW(image);
       content = gtk_image_new_from_pixbuf(pb);
-    else
+    } else {
+      NW(label);
       content = gtk_label_new(icons[n].icon);
+    }
     gtk_container_add(GTK_CONTAINER(icons[n].button), content);
     gtk_tooltips_set_tip(tips, icons[n].button, icons[n].tip, "");
     g_signal_connect(G_OBJECT(icons[n].button), "clicked",
                      G_CALLBACK(icons[n].clicked), &icons[n]);
     /* pop the icon in a vbox so it doesn't get vertically stretch if there are
      * taller things in the control bar */
+    NW(vbox);
     vbox = gtk_vbox_new(FALSE, 0);
     gtk_box_pack_start(GTK_BOX(vbox), icons[n].button, TRUE, FALSE, 0);
     gtk_box_pack_start(GTK_BOX(hbox), vbox, FALSE, FALSE, 0);
   }
   /* create the adjustments for the volume control */
+  NW(adjustment);
   volume_adj = GTK_ADJUSTMENT(gtk_adjustment_new(0, 0, goesupto,
                                                  goesupto / 20, goesupto / 20,
                                                  0));
+  NW(adjustment);
   balance_adj = GTK_ADJUSTMENT(gtk_adjustment_new(0, -1, 1,
                                                   0.2, 0.2, 0));
   /* the volume control */
+  NW(hscale);
   v = gtk_hscale_new(volume_adj);
+  NW(hscale);
   b = gtk_hscale_new(balance_adj);
   gtk_scale_set_digits(GTK_SCALE(v), 10);
   gtk_scale_set_digits(GTK_SCALE(b), 10);
@@ -135,7 +155,7 @@ GtkAdjustment *volume_adj, *balance_adj;
   return hbox;
 }
 
-/* Update the control bar after some kind of state change */
+/** @brief Update the control bar after some kind of state change */
 void control_update(void) {
   int n;
   double l, r;
@@ -151,10 +171,27 @@ void control_update(void) {
   --suppress_set_volume;
 }
 
+/** @brief Update the state of one of the control icons
+ * @param button Widget for button
+ * @param visible True if this version of the button should be visible
+ * @param usable True if the button is currently usable
+ *
+ * Several of the icons, rather bizarrely, come in pairs: for instance exactly
+ * one of the play and pause buttons is supposed to be visible at any given
+ * moment.
+ *
+ * @p usable need not take into account server availability, that is done
+ * automatically.
+ */
 static void update_icon(GtkWidget *button, 
-                        int visible, int attribute((unused)) usable) {
+                        int visible, int usable) {
+  /* If the connection is down nothing is ever usable */
+  if(!disorder_eclient_connected(client))
+    usable = 0;
   (visible ? gtk_widget_show : gtk_widget_hide)(button);
-  /* TODO: show usability */
+  /* Only both updating usability if the button is visible */
+  if(visible)
+    gtk_widget_set_sensitive(button, usable);
 }
 
 static void update_pause(const struct icon *icon) {
@@ -233,7 +270,7 @@ static gchar *format_volume(GtkScale attribute((unused)) *scale,
   char s[32];
 
   snprintf(s, sizeof s, "%.1f", (double)value);
-  return xstrdup(s);
+  return g_strdup(s);
 }
 
 /* Called to format the balance value. */
@@ -242,9 +279,9 @@ static gchar *format_balance(GtkScale attribute((unused)) *scale,
   char s[32];
 
   if(fabs(value) < 0.1)
-    return xstrdup("0");
+    return g_strdup("0");
   snprintf(s, sizeof s, "%+.1f", (double)value);
-  return xstrdup(s);
+  return g_strdup(s);
 }
 
 /* Volume mapping.  We consider left, right, volume to be in [0,1]