gnome-media r4080 - in trunk/gnome-volume-control: . src



Author: mccann
Date: Thu Dec 11 17:28:22 2008
New Revision: 4080
URL: http://svn.gnome.org/viewvc/gnome-media?rev=4080&view=rev

Log:
2008-12-11  William Jon McCann  <jmccann redhat com>

	* src/Makefile.am:
	* src/gvc-applet.c (gvc_applet_start), (gvc_applet_dispose),
	(update_default_source), (update_default_sink), (on_control_ready),
	(on_control_default_sink_changed),
	(on_control_default_source_changed), (gvc_applet_constructor),
	(gvc_applet_class_init), (gvc_applet_init), (gvc_applet_finalize):
	* src/gvc-stream-status-icon.c (on_adjustment_value_changed),
	(popup_dock), (on_status_icon_activate),
	(on_menu_activate_open_volume_control),
	(on_status_icon_popup_menu), (on_status_icon_scroll_event),
	(gvc_icon_release_grab), (on_dock_button_press), (popdown_dock),
	(gvc_icon_grab_notify), (on_dock_grab_notify),
	(on_dock_grab_broken_event), (on_dock_key_release),
	(maybe_show_status_icon), (update_icon),
	(gvc_stream_status_icon_set_icon_names), (on_stream_volume_notify),
	(on_stream_is_muted_notify),
	(gvc_stream_status_icon_set_display_name),
	(gvc_stream_status_icon_set_mixer_stream),
	(gvc_stream_status_icon_set_property),
	(gvc_stream_status_icon_get_property), (on_bar_is_muted_notify),
	(gvc_stream_status_icon_constructor),
	(gvc_stream_status_icon_dispose),
	(gvc_stream_status_icon_class_init), (gvc_stream_status_icon_init),
	(gvc_stream_status_icon_finalize), (gvc_stream_status_icon_new):
	* src/gvc-stream-status-icon.h:
	Create a stream-status-icon class.  Create a status icon
	for input stream.  Todo: only show input status icon
	when an application is recording, use microphone images.



Added:
   trunk/gnome-volume-control/src/gvc-stream-status-icon.c
   trunk/gnome-volume-control/src/gvc-stream-status-icon.h
Modified:
   trunk/gnome-volume-control/ChangeLog
   trunk/gnome-volume-control/src/Makefile.am
   trunk/gnome-volume-control/src/gvc-applet.c

Modified: trunk/gnome-volume-control/src/Makefile.am
==============================================================================
--- trunk/gnome-volume-control/src/Makefile.am	(original)
+++ trunk/gnome-volume-control/src/Makefile.am	Thu Dec 11 17:28:22 2008
@@ -35,6 +35,8 @@
 	gvc-mixer-control.c			\
 	gvc-channel-bar.h			\
 	gvc-channel-bar.c			\
+	gvc-stream-status-icon.h		\
+	gvc-stream-status-icon.c		\
 	gvc-applet.h				\
 	gvc-applet.c				\
 	applet-main.c				\

Modified: trunk/gnome-volume-control/src/gvc-applet.c
==============================================================================
--- trunk/gnome-volume-control/src/gvc-applet.c	(original)
+++ trunk/gnome-volume-control/src/gvc-applet.c	Thu Dec 11 17:28:22 2008
@@ -29,18 +29,25 @@
 
 #include <glib.h>
 #include <glib/gi18n.h>
-#include <gdk/gdkkeysyms.h>
 #include <gtk/gtk.h>
 
 #include "gvc-applet.h"
-#include "gvc-channel-bar.h"
 #include "gvc-mixer-control.h"
+#include "gvc-stream-status-icon.h"
 
 #define GVC_APPLET_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GVC_TYPE_APPLET, GvcAppletPrivate))
 
 #define SCALE_SIZE 128
 
-static const char *icon_names[] = {
+static const char *output_icon_names[] = {
+        "audio-volume-muted",
+        "audio-volume-low",
+        "audio-volume-medium",
+        "audio-volume-high",
+        NULL
+};
+
+static const char *input_icon_names[] = {
         "audio-volume-muted",
         "audio-volume-low",
         "audio-volume-medium",
@@ -50,12 +57,9 @@
 
 struct GvcAppletPrivate
 {
-        GtkStatusIcon   *status_icon;
-        GtkWidget       *dock;
-        GtkWidget       *bar;
-        GvcMixerControl *control;
-        GvcMixerStream  *sink_stream;
-        guint            current_icon;
+        GvcStreamStatusIcon *input_status_icon;
+        GvcStreamStatusIcon *output_status_icon;
+        GvcMixerControl     *control;
 };
 
 static void     gvc_applet_class_init (GvcAppletClass *klass);
@@ -64,30 +68,12 @@
 
 G_DEFINE_TYPE (GvcApplet, gvc_applet, G_TYPE_OBJECT)
 
-static void
-maybe_show_status_icon (GvcApplet *applet)
-{
-        gboolean show;
-
-        show = TRUE;
-
-        if (applet->priv->sink_stream == NULL) {
-                show = FALSE;
-        }
-
-        if (applet->priv->dock != NULL) {
-                gtk_widget_hide (applet->priv->dock);
-        }
-
-        gtk_status_icon_set_visible (applet->priv->status_icon, show);
-}
-
 void
 gvc_applet_start (GvcApplet *applet)
 {
         g_return_if_fail (GVC_IS_APPLET (applet));
 
-        maybe_show_status_icon (applet);
+        //maybe_show_status_icon (applet);
 }
 
 static void
@@ -95,547 +81,122 @@
 {
         GvcApplet *applet = GVC_APPLET (object);
 
-        if (applet->priv->dock != NULL) {
-                gtk_widget_destroy (applet->priv->dock);
-                applet->priv->dock = NULL;
-        }
-
         if (applet->priv->control != NULL) {
                 g_object_unref (applet->priv->control);
                 applet->priv->control = NULL;
         }
 
-        if (applet->priv->sink_stream != NULL) {
-                g_object_unref (applet->priv->sink_stream);
-                applet->priv->sink_stream = NULL;
-        }
-
         G_OBJECT_CLASS (gvc_applet_parent_class)->dispose (object);
 }
 
-static GObject *
-gvc_applet_constructor (GType                  type,
-                        guint                  n_construct_properties,
-                        GObjectConstructParam *construct_params)
-{
-        GObject   *object;
-        GvcApplet *self;
-
-        object = G_OBJECT_CLASS (gvc_applet_parent_class)->constructor (type, n_construct_properties, construct_params);
-
-        self = GVC_APPLET (object);
-
-        gvc_mixer_control_open (self->priv->control);
-
-        return object;
-}
-
 static void
-gvc_applet_class_init (GvcAppletClass *klass)
+update_default_source (GvcApplet *applet)
 {
-        GObjectClass   *object_class = G_OBJECT_CLASS (klass);
-
-        object_class->finalize = gvc_applet_finalize;
-        object_class->dispose = gvc_applet_dispose;
-        object_class->constructor = gvc_applet_constructor;
+        GvcMixerStream *stream;
 
-        g_type_class_add_private (klass, sizeof (GvcAppletPrivate));
-}
-
-static void
-on_adjustment_value_changed (GtkAdjustment *adjustment,
-                             GvcApplet     *applet)
-{
-        gdouble volume;
-
-        volume = gtk_adjustment_get_value (adjustment);
-        gvc_mixer_stream_change_volume (applet->priv->sink_stream,
-                                        (guint)volume);
-}
-
-static gboolean
-popup_dock (GvcApplet *applet,
-            guint      time)
-{
-        GtkAdjustment *adj;
-        GdkRectangle   area;
-        GtkOrientation orientation;
-        GdkDisplay    *display;
-        GdkScreen     *screen;
-        gboolean       is_muted;
-        gboolean       res;
-        int            x, y;
-
-        adj = GTK_ADJUSTMENT (gvc_channel_bar_get_adjustment (GVC_CHANNEL_BAR (applet->priv->bar)));
-        gtk_adjustment_set_value (adj,
-                                  gvc_mixer_stream_get_volume (applet->priv->sink_stream));
-        is_muted = gvc_mixer_stream_get_is_muted (applet->priv->sink_stream);
-        gvc_channel_bar_set_is_muted (GVC_CHANNEL_BAR (applet->priv->bar), is_muted);
-
-        screen = gtk_status_icon_get_screen (applet->priv->status_icon);
-        res = gtk_status_icon_get_geometry (applet->priv->status_icon,
-                                            &screen,
-                                            &area,
-                                            &orientation);
-        if (! res) {
-                g_warning ("Unable to determine geometry of status icon");
-                return FALSE;
-        }
-
-        /* position roughly */
-        gtk_window_set_screen (GTK_WINDOW (applet->priv->dock), screen);
-        x = area.x + area.width;
-        y = area.y + area.height;
-
-        if (orientation == GTK_ORIENTATION_VERTICAL) {
-                gtk_window_move (GTK_WINDOW (applet->priv->dock), x, area.y);
+        stream = gvc_mixer_control_get_default_source (applet->priv->control);
+        if (stream != NULL) {
+                gvc_stream_status_icon_set_mixer_stream (applet->priv->input_status_icon,
+                                                         stream);
         } else {
-                gtk_window_move (GTK_WINDOW (applet->priv->dock), area.x, y);
-        }
-
-        /* FIXME: without this, the popup window appears as a square
-         * after changing the orientation
-         */
-        gtk_window_resize (GTK_WINDOW (applet->priv->dock), 1, 1);
-
-        gtk_widget_show_all (applet->priv->dock);
-
-
-        /* grab focus */
-        gtk_grab_add (applet->priv->dock);
-
-        if (gdk_pointer_grab (applet->priv->dock->window, TRUE,
-                              GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
-                              GDK_POINTER_MOTION_MASK, NULL, NULL,
-                              time)
-            != GDK_GRAB_SUCCESS) {
-                gtk_grab_remove (applet->priv->dock);
-                gtk_widget_hide (applet->priv->dock);
-                return FALSE;
+                g_warning ("Unable to get default source");
         }
-
-        if (gdk_keyboard_grab (applet->priv->dock->window, TRUE, time) != GDK_GRAB_SUCCESS) {
-                display = gtk_widget_get_display (applet->priv->dock);
-                gdk_display_pointer_ungrab (display, time);
-                gtk_grab_remove (applet->priv->dock);
-                gtk_widget_hide (applet->priv->dock);
-                return FALSE;
-        }
-
-        gtk_widget_grab_focus (applet->priv->dock);
-
-        return TRUE;
 }
 
 static void
-on_status_icon_activate (GtkStatusIcon *status_icon,
-                         GvcApplet     *applet)
-{
-        popup_dock (applet, GDK_CURRENT_TIME);
-}
-
-static void
-on_menu_activate_open_volume_control (GtkMenuItem *item,
-                                      GvcApplet   *applet)
-{
-        GError *error;
-
-        error = NULL;
-        gdk_spawn_command_line_on_screen (gtk_widget_get_screen (applet->priv->dock),
-                                          "gnome-volume-control",
-                                          &error);
-
-        if (error != NULL) {
-                GtkWidget *dialog;
-
-                dialog = gtk_message_dialog_new (NULL,
-                                                 0,
-                                                 GTK_MESSAGE_ERROR,
-                                                 GTK_BUTTONS_CLOSE,
-                                                 _("Failed to start Sound Preferences: %s"),
-                                                 error->message);
-                g_signal_connect (dialog,
-                                  "response",
-                                  G_CALLBACK (gtk_widget_destroy),
-                                  NULL);
-                gtk_widget_show (dialog);
-                g_error_free (error);
-        }
-}
-
-static void
-on_status_icon_popup_menu (GtkStatusIcon *status_icon,
-                           guint          button,
-                           guint          activate_time,
-                           GvcApplet     *applet)
-{
-        GtkWidget *menu;
-        GtkWidget *item;
-        GtkWidget *image;
-
-        menu = gtk_menu_new ();
-        item = gtk_image_menu_item_new_with_mnemonic (_("_Sound Preferences"));
-        image = gtk_image_new_from_icon_name ("multimedia-volume-control",
-                                              GTK_ICON_SIZE_MENU);
-        gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
-        g_signal_connect (item,
-                          "activate",
-                          G_CALLBACK (on_menu_activate_open_volume_control),
-                          applet);
-        gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
-
-        gtk_widget_show_all (menu);
-        gtk_menu_popup (GTK_MENU (menu),
-                        NULL,
-                        NULL,
-                        gtk_status_icon_position_menu,
-                        status_icon,
-                        button,
-                        activate_time);
-}
-
-#if GTK_CHECK_VERSION(2,15,0)
-static gboolean
-on_status_icon_scroll_event (GtkStatusIcon  *status_icon,
-                             GdkEventScroll *event,
-                             GvcApplet      *applet)
-{
-        GtkAdjustment *adj;
-
-        adj = GTK_ADJUSTMENT (gvc_channel_bar_get_adjustment (GVC_CHANNEL_BAR (applet->priv->bar)));
-
-        switch (event->direction) {
-        case GDK_SCROLL_UP:
-        case GDK_SCROLL_DOWN: {
-                gdouble volume;
-
-                volume = gtk_adjustment_get_value (adj);
-
-                if (event->direction == GDK_SCROLL_UP) {
-                        volume += adj->step_increment;
-                        if (volume > adj->upper) {
-                                volume = adj->upper;
-                        }
-                } else {
-                        volume -= adj->step_increment;
-                        if (volume < adj->lower) {
-                                volume = adj->lower;
-                        }
-                }
-
-                gtk_adjustment_set_value (adj, volume);
-                return TRUE;
-        }
-        default:
-                break;
-        }
-
-        return FALSE;
-}
-#endif
-
-static void
-gvc_applet_release_grab (GvcApplet      *applet,
-                         GdkEventButton *event)
+update_default_sink (GvcApplet *applet)
 {
-        GdkDisplay     *display;
+        GvcMixerStream *stream;
 
-        /* ungrab focus */
-        display = gtk_widget_get_display (GTK_WIDGET (applet->priv->dock));
-        gdk_display_keyboard_ungrab (display, event->time);
-        gdk_display_pointer_ungrab (display, event->time);
-        gtk_grab_remove (applet->priv->dock);
-
-        /* hide again */
-        gtk_widget_hide (applet->priv->dock);
-}
-
-static gboolean
-on_dock_button_press (GtkWidget      *widget,
-                      GdkEventButton *event,
-                      GvcApplet      *applet)
-{
-        if (event->type == GDK_BUTTON_PRESS) {
-                gvc_applet_release_grab (applet, event);
-                return TRUE;
+        stream = gvc_mixer_control_get_default_sink (applet->priv->control);
+        if (stream != NULL) {
+                gvc_stream_status_icon_set_mixer_stream (applet->priv->output_status_icon,
+                                                         stream);
+        } else {
+                g_warning ("Unable to get default sink");
         }
-
-        return FALSE;
 }
 
 static void
-popdown_dock (GvcApplet *applet)
+on_control_ready (GvcMixerControl *control,
+                  GvcApplet       *applet)
 {
-        GdkDisplay *display;
-
-        /* ungrab focus */
-        display = gtk_widget_get_display (applet->priv->dock);
-        gdk_display_keyboard_ungrab (display, GDK_CURRENT_TIME);
-        gdk_display_pointer_ungrab (display, GDK_CURRENT_TIME);
-        gtk_grab_remove (applet->priv->dock);
-
-        /* hide again */
-        gtk_widget_hide (applet->priv->dock);
+        update_default_sink (applet);
+        update_default_source (applet);
 }
 
-/* This is called when the grab is broken for
- * either the dock, or the scale itself */
 static void
-gvc_applet_grab_notify (GvcApplet *applet,
-                        gboolean   was_grabbed)
+on_control_default_sink_changed (GvcMixerControl *control,
+                                 guint            id,
+                                 GvcApplet       *applet)
 {
-        if (was_grabbed != FALSE) {
-                return;
-        }
-
-        if (!GTK_WIDGET_HAS_GRAB (applet->priv->dock)) {
-                return;
-        }
-
-        if (gtk_widget_is_ancestor (gtk_grab_get_current (), applet->priv->dock)) {
-                return;
-        }
-
-        popdown_dock (applet);
+        update_default_sink (applet);
 }
 
 static void
-on_dock_grab_notify (GtkWidget *widget,
-                     gboolean   was_grabbed,
-                     GvcApplet *applet)
-{
-        gvc_applet_grab_notify (applet, was_grabbed);
-}
-
-static gboolean
-on_dock_grab_broken_event (GtkWidget *widget,
-                           gboolean   was_grabbed,
-                           GvcApplet *applet)
+on_control_default_source_changed (GvcMixerControl *control,
+                                   guint            id,
+                                   GvcApplet       *applet)
 {
-        gvc_applet_grab_notify (applet, FALSE);
-
-        return FALSE;
-}
-
-static gboolean
-on_dock_key_release (GtkWidget   *widget,
-                     GdkEventKey *event,
-                     GvcApplet   *applet)
-{
-        if (event->keyval == GDK_Escape) {
-                popdown_dock (applet);
-                return TRUE;
-        }
-
-#if 0
-        if (!gtk_bindings_activate_event (GTK_OBJECT (widget), event)) {
-                /* The popup hasn't managed the event, pass onto the button */
-                gtk_bindings_activate_event (GTK_OBJECT (user_data), event);
-        }
-#endif
-        return TRUE;
+        update_default_source (applet);
 }
 
-static void
-update_icon (GvcApplet *applet)
+static GObject *
+gvc_applet_constructor (GType                  type,
+                        guint                  n_construct_properties,
+                        GObjectConstructParam *construct_params)
 {
-        guint    volume;
-        gboolean is_muted;
-        guint    n;
-
-        maybe_show_status_icon (applet);
-
-        if (applet->priv->sink_stream == NULL) {
-                return;
-        }
-
-        volume = gvc_mixer_stream_get_volume (applet->priv->sink_stream);
-        is_muted = gvc_mixer_stream_get_is_muted (applet->priv->sink_stream);
-
-        /* select image */
-        if (volume <= 0 || is_muted) {
-                n = 0;
-        } else {
-                n = 3 * volume / PA_VOLUME_NORM + 1;
-                if (n < 1) {
-                        n = 1;
-                } else if (n > 3) {
-                        n = 3;
-                }
-        }
+        GObject   *object;
+        GvcApplet *self;
 
-        /* apparently status icon will reset icon even if
-         * if doesn't change */
-        if (applet->priv->current_icon != n) {
-                gtk_status_icon_set_from_icon_name (GTK_STATUS_ICON (applet->priv->status_icon), icon_names [n]);
-                applet->priv->current_icon = n;
-        }
-}
+        object = G_OBJECT_CLASS (gvc_applet_parent_class)->constructor (type, n_construct_properties, construct_params);
 
-static void
-on_stream_volume_notify (GObject    *object,
-                         GParamSpec *pspec,
-                         GvcApplet  *applet)
-{
-        update_icon (applet);
-        /* FIXME: update dock too */
-}
+        self = GVC_APPLET (object);
 
-static void
-on_stream_is_muted_notify (GObject    *object,
-                           GParamSpec *pspec,
-                           GvcApplet  *applet)
-{
-        update_icon (applet);
-        /* FIXME: update dock too */
-}
+        self->priv->control = gvc_mixer_control_new ();
+        g_signal_connect (self->priv->control,
+                          "ready",
+                          G_CALLBACK (on_control_ready),
+                          self);
+        g_signal_connect (self->priv->control,
+                          "default-sink-changed",
+                          G_CALLBACK (on_control_default_sink_changed),
+                          self);
+        g_signal_connect (self->priv->control,
+                          "default-source-changed",
+                          G_CALLBACK (on_control_default_source_changed),
+                          self);
 
-static void
-update_default_sink (GvcApplet *applet)
-{
-        if (applet->priv->sink_stream != NULL) {
-                g_signal_handlers_disconnect_by_func (applet->priv->sink_stream,
-                                                      G_CALLBACK (on_stream_volume_notify),
-                                                      applet);
-                g_signal_handlers_disconnect_by_func (applet->priv->sink_stream,
-                                                      G_CALLBACK (on_stream_is_muted_notify),
-                                                      applet);
-                g_object_unref (applet->priv->sink_stream);
-                applet->priv->sink_stream = NULL;
-        }
+        gvc_mixer_control_open (self->priv->control);
 
-        applet->priv->sink_stream = gvc_mixer_control_get_default_sink (applet->priv->control);
-        if (applet->priv->sink_stream != NULL) {
-                GtkAdjustment *adj;
-
-                g_object_ref (applet->priv->sink_stream);
-
-                adj = GTK_ADJUSTMENT (gvc_channel_bar_get_adjustment (GVC_CHANNEL_BAR (applet->priv->bar)));
-                gtk_adjustment_set_value (adj,
-                                          gvc_mixer_stream_get_volume (applet->priv->sink_stream));
-
-                g_signal_connect (applet->priv->sink_stream,
-                                  "notify::volume",
-                                  G_CALLBACK (on_stream_volume_notify),
-                                  applet);
-                g_signal_connect (applet->priv->sink_stream,
-                                  "notify::is-muted",
-                                  G_CALLBACK (on_stream_is_muted_notify),
-                                  applet);
-        } else {
-                g_warning ("Unable to get default sink");
-        }
-        update_icon (applet);
+        return object;
 }
 
 static void
-on_control_ready (GvcMixerControl *control,
-                  GvcApplet       *applet)
+gvc_applet_class_init (GvcAppletClass *klass)
 {
-        update_default_sink (applet);
-}
+        GObjectClass   *object_class = G_OBJECT_CLASS (klass);
 
-static void
-on_bar_is_muted_notify (GObject    *object,
-                        GParamSpec *pspec,
-                        GvcApplet  *applet)
-{
-        gboolean is_muted;
-
-        is_muted = gvc_channel_bar_get_is_muted (GVC_CHANNEL_BAR (object));
-        gvc_mixer_stream_change_is_muted (applet->priv->sink_stream,
-                                          is_muted);
-}
+        object_class->finalize = gvc_applet_finalize;
+        object_class->dispose = gvc_applet_dispose;
+        object_class->constructor = gvc_applet_constructor;
 
-static void
-on_control_default_sink_changed (GvcMixerControl *control,
-                                 guint            id,
-                                 GvcApplet       *applet)
-{
-        update_default_sink (applet);
+        g_type_class_add_private (klass, sizeof (GvcAppletPrivate));
 }
 
 static void
 gvc_applet_init (GvcApplet *applet)
 {
-        GtkWidget *frame;
-        GtkWidget *box;
-        GtkAdjustment *adj;
-
         applet->priv = GVC_APPLET_GET_PRIVATE (applet);
 
-        applet->priv->status_icon = gtk_status_icon_new_from_icon_name (icon_names[0]);
-        g_signal_connect (applet->priv->status_icon,
-                          "activate",
-                          G_CALLBACK (on_status_icon_activate),
-                          applet);
-        g_signal_connect (applet->priv->status_icon,
-                          "popup-menu",
-                          G_CALLBACK (on_status_icon_popup_menu),
-                          applet);
-#if GTK_CHECK_VERSION(2,15,0)
-        g_signal_connect (applet->priv->status_icon,
-                          "scroll-event",
-                          G_CALLBACK (on_status_icon_scroll_event),
-                          applet);
-#endif
-
-        /* window */
-        applet->priv->dock = gtk_window_new (GTK_WINDOW_POPUP);
-        gtk_widget_set_name (applet->priv->dock, "gvc-applet-popup-window");
-        g_signal_connect (applet->priv->dock,
-                          "button-press-event",
-                          G_CALLBACK (on_dock_button_press),
-                          applet);
-        g_signal_connect (applet->priv->dock,
-                          "key-release-event",
-                          G_CALLBACK (on_dock_key_release),
-                          applet);
-        g_signal_connect (applet->priv->dock,
-                          "grab-notify",
-                          G_CALLBACK (on_dock_grab_notify),
-                          applet);
-        g_signal_connect (applet->priv->dock,
-                          "grab-broken-event",
-                          G_CALLBACK (on_dock_grab_broken_event),
-                          applet);
-
-        gtk_window_set_decorated (GTK_WINDOW (applet->priv->dock), FALSE);
-
-        frame = gtk_frame_new (NULL);
-        gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_OUT);
-        gtk_container_add (GTK_CONTAINER (applet->priv->dock), frame);
-        gtk_widget_show (frame);
-
-        box = gtk_vbox_new (FALSE, 6);
-        gtk_container_set_border_width (GTK_CONTAINER (box), 6);
-        gtk_container_add (GTK_CONTAINER (frame), box);
-
-        applet->priv->bar = gvc_channel_bar_new ();
-        gvc_channel_bar_set_orientation (GVC_CHANNEL_BAR (applet->priv->bar),
-                                         GTK_ORIENTATION_VERTICAL);
-
-        gtk_box_pack_start (GTK_BOX (box), applet->priv->bar, TRUE, FALSE, 0);
-        g_signal_connect (applet->priv->bar,
-                          "notify::is-muted",
-                          G_CALLBACK (on_bar_is_muted_notify),
-                          applet);
-
-        applet->priv->control = gvc_mixer_control_new ();
-        g_signal_connect (applet->priv->control,
-                          "ready",
-                          G_CALLBACK (on_control_ready),
-                          applet);
-        g_signal_connect (applet->priv->control,
-                          "default-sink-changed",
-                          G_CALLBACK (on_control_default_sink_changed),
-                          applet);
-
-        adj = GTK_ADJUSTMENT (gvc_channel_bar_get_adjustment (GVC_CHANNEL_BAR (applet->priv->bar)));
-        g_signal_connect (adj,
-                          "value-changed",
-                          G_CALLBACK (on_adjustment_value_changed),
-                          applet);
+        applet->priv->output_status_icon = gvc_stream_status_icon_new (NULL,
+                                                                       output_icon_names);
+        gvc_stream_status_icon_set_display_name (applet->priv->output_status_icon,
+                                                 _("Output"));
+        applet->priv->input_status_icon = gvc_stream_status_icon_new (NULL,
+                                                                      input_icon_names);
+        gvc_stream_status_icon_set_display_name (applet->priv->input_status_icon,
+                                                 _("Input"));
 }
 
 static void
@@ -649,6 +210,8 @@
         applet = GVC_APPLET (object);
 
         g_return_if_fail (applet->priv != NULL);
+
+
         G_OBJECT_CLASS (gvc_applet_parent_class)->finalize (object);
 }
 

Added: trunk/gnome-volume-control/src/gvc-stream-status-icon.c
==============================================================================
--- (empty file)
+++ trunk/gnome-volume-control/src/gvc-stream-status-icon.c	Thu Dec 11 17:28:22 2008
@@ -0,0 +1,742 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2008 William Jon McCann
+ *
+ * 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
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ */
+
+#include "config.h"
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+
+#include <glib.h>
+#include <glib/gi18n.h>
+#include <gdk/gdkkeysyms.h>
+#include <gtk/gtk.h>
+
+#include "gvc-mixer-stream.h"
+#include "gvc-channel-bar.h"
+#include "gvc-stream-status-icon.h"
+
+#define GVC_STREAM_STATUS_ICON_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GVC_TYPE_STREAM_STATUS_ICON, GvcStreamStatusIconPrivate))
+
+struct GvcStreamStatusIconPrivate
+{
+        char          **icon_names;
+        GvcMixerStream *mixer_stream;
+        GtkWidget      *dock;
+        GtkWidget      *bar;
+        guint           current_icon;
+        char           *display_name;
+
+};
+
+enum
+{
+        PROP_0,
+        PROP_DISPLAY_NAME,
+        PROP_MIXER_STREAM,
+        PROP_ICON_NAMES,
+};
+
+static void     gvc_stream_status_icon_class_init (GvcStreamStatusIconClass *klass);
+static void     gvc_stream_status_icon_init       (GvcStreamStatusIcon      *stream_status_icon);
+static void     gvc_stream_status_icon_finalize   (GObject                  *object);
+
+G_DEFINE_TYPE (GvcStreamStatusIcon, gvc_stream_status_icon, GTK_TYPE_STATUS_ICON)
+
+static void
+on_adjustment_value_changed (GtkAdjustment *adjustment,
+                             GvcStreamStatusIcon     *icon)
+{
+        gdouble volume;
+
+        volume = gtk_adjustment_get_value (adjustment);
+        gvc_mixer_stream_change_volume (icon->priv->mixer_stream,
+                                        (guint)volume);
+}
+
+static gboolean
+popup_dock (GvcStreamStatusIcon *icon,
+            guint                time)
+{
+        GtkAdjustment *adj;
+        GdkRectangle   area;
+        GtkOrientation orientation;
+        GdkDisplay    *display;
+        GdkScreen     *screen;
+        gboolean       is_muted;
+        gboolean       res;
+        int            x, y;
+
+        adj = GTK_ADJUSTMENT (gvc_channel_bar_get_adjustment (GVC_CHANNEL_BAR (icon->priv->bar)));
+        gtk_adjustment_set_value (adj,
+                                  gvc_mixer_stream_get_volume (icon->priv->mixer_stream));
+        is_muted = gvc_mixer_stream_get_is_muted (icon->priv->mixer_stream);
+        gvc_channel_bar_set_is_muted (GVC_CHANNEL_BAR (icon->priv->bar), is_muted);
+
+        screen = gtk_status_icon_get_screen (GTK_STATUS_ICON (icon));
+        res = gtk_status_icon_get_geometry (GTK_STATUS_ICON (icon),
+                                            &screen,
+                                            &area,
+                                            &orientation);
+        if (! res) {
+                g_warning ("Unable to determine geometry of status icon");
+                return FALSE;
+        }
+
+        /* position roughly */
+        gtk_window_set_screen (GTK_WINDOW (icon->priv->dock), screen);
+        x = area.x + area.width;
+        y = area.y + area.height;
+
+        if (orientation == GTK_ORIENTATION_VERTICAL) {
+                gtk_window_move (GTK_WINDOW (icon->priv->dock), x, area.y);
+        } else {
+                gtk_window_move (GTK_WINDOW (icon->priv->dock), area.x, y);
+        }
+
+        /* FIXME: without this, the popup window appears as a square
+         * after changing the orientation
+         */
+        gtk_window_resize (GTK_WINDOW (icon->priv->dock), 1, 1);
+
+        gtk_widget_show_all (icon->priv->dock);
+
+
+        /* grab focus */
+        gtk_grab_add (icon->priv->dock);
+
+        if (gdk_pointer_grab (icon->priv->dock->window, TRUE,
+                              GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
+                              GDK_POINTER_MOTION_MASK, NULL, NULL,
+                              time)
+            != GDK_GRAB_SUCCESS) {
+                gtk_grab_remove (icon->priv->dock);
+                gtk_widget_hide (icon->priv->dock);
+                return FALSE;
+        }
+
+        if (gdk_keyboard_grab (icon->priv->dock->window, TRUE, time) != GDK_GRAB_SUCCESS) {
+                display = gtk_widget_get_display (icon->priv->dock);
+                gdk_display_pointer_ungrab (display, time);
+                gtk_grab_remove (icon->priv->dock);
+                gtk_widget_hide (icon->priv->dock);
+                return FALSE;
+        }
+
+        gtk_widget_grab_focus (icon->priv->dock);
+
+        return TRUE;
+}
+
+static void
+on_status_icon_activate (GtkStatusIcon *status_icon,
+                         GvcStreamStatusIcon     *icon)
+{
+        popup_dock (icon, GDK_CURRENT_TIME);
+}
+
+static void
+on_menu_activate_open_volume_control (GtkMenuItem *item,
+                                      GvcStreamStatusIcon   *icon)
+{
+        GError *error;
+
+        error = NULL;
+        gdk_spawn_command_line_on_screen (gtk_widget_get_screen (icon->priv->dock),
+                                          "gnome-volume-control",
+                                          &error);
+
+        if (error != NULL) {
+                GtkWidget *dialog;
+
+                dialog = gtk_message_dialog_new (NULL,
+                                                 0,
+                                                 GTK_MESSAGE_ERROR,
+                                                 GTK_BUTTONS_CLOSE,
+                                                 _("Failed to start Sound Preferences: %s"),
+                                                 error->message);
+                g_signal_connect (dialog,
+                                  "response",
+                                  G_CALLBACK (gtk_widget_destroy),
+                                  NULL);
+                gtk_widget_show (dialog);
+                g_error_free (error);
+        }
+}
+
+static void
+on_status_icon_popup_menu (GtkStatusIcon       *status_icon,
+                           guint                button,
+                           guint                activate_time,
+                           GvcStreamStatusIcon *icon)
+{
+        GtkWidget *menu;
+        GtkWidget *item;
+        GtkWidget *image;
+
+        menu = gtk_menu_new ();
+        item = gtk_image_menu_item_new_with_mnemonic (_("_Sound Preferences"));
+        image = gtk_image_new_from_icon_name ("multimedia-volume-control",
+                                              GTK_ICON_SIZE_MENU);
+        gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
+        g_signal_connect (item,
+                          "activate",
+                          G_CALLBACK (on_menu_activate_open_volume_control),
+                          icon);
+        gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
+
+        gtk_widget_show_all (menu);
+        gtk_menu_popup (GTK_MENU (menu),
+                        NULL,
+                        NULL,
+                        gtk_status_icon_position_menu,
+                        status_icon,
+                        button,
+                        activate_time);
+}
+
+#if GTK_CHECK_VERSION(2,15,0)
+static gboolean
+on_status_icon_scroll_event (GtkStatusIcon       *status_icon,
+                             GdkEventScroll      *event,
+                             GvcStreamStatusIcon *icon)
+{
+        GtkAdjustment *adj;
+
+        adj = GTK_ADJUSTMENT (gvc_channel_bar_get_adjustment (GVC_CHANNEL_BAR (icon->priv->bar)));
+
+        switch (event->direction) {
+        case GDK_SCROLL_UP:
+        case GDK_SCROLL_DOWN: {
+                gdouble volume;
+
+                volume = gtk_adjustment_get_value (adj);
+
+                if (event->direction == GDK_SCROLL_UP) {
+                        volume += adj->step_increment;
+                        if (volume > adj->upper) {
+                                volume = adj->upper;
+                        }
+                } else {
+                        volume -= adj->step_increment;
+                        if (volume < adj->lower) {
+                                volume = adj->lower;
+                        }
+                }
+
+                gtk_adjustment_set_value (adj, volume);
+                return TRUE;
+        }
+        default:
+                break;
+        }
+
+        return FALSE;
+}
+#endif
+
+static void
+gvc_icon_release_grab (GvcStreamStatusIcon *icon,
+                         GdkEventButton    *event)
+{
+        GdkDisplay     *display;
+
+        /* ungrab focus */
+        display = gtk_widget_get_display (GTK_WIDGET (icon->priv->dock));
+        gdk_display_keyboard_ungrab (display, event->time);
+        gdk_display_pointer_ungrab (display, event->time);
+        gtk_grab_remove (icon->priv->dock);
+
+        /* hide again */
+        gtk_widget_hide (icon->priv->dock);
+}
+
+static gboolean
+on_dock_button_press (GtkWidget      *widget,
+                      GdkEventButton *event,
+                      GvcStreamStatusIcon      *icon)
+{
+        if (event->type == GDK_BUTTON_PRESS) {
+                gvc_icon_release_grab (icon, event);
+                return TRUE;
+        }
+
+        return FALSE;
+}
+
+static void
+popdown_dock (GvcStreamStatusIcon *icon)
+{
+        GdkDisplay *display;
+
+        /* ungrab focus */
+        display = gtk_widget_get_display (icon->priv->dock);
+        gdk_display_keyboard_ungrab (display, GDK_CURRENT_TIME);
+        gdk_display_pointer_ungrab (display, GDK_CURRENT_TIME);
+        gtk_grab_remove (icon->priv->dock);
+
+        /* hide again */
+        gtk_widget_hide (icon->priv->dock);
+}
+
+/* This is called when the grab is broken for
+ * either the dock, or the scale itself */
+static void
+gvc_icon_grab_notify (GvcStreamStatusIcon *icon,
+                      gboolean             was_grabbed)
+{
+        if (was_grabbed != FALSE) {
+                return;
+        }
+
+        if (!GTK_WIDGET_HAS_GRAB (icon->priv->dock)) {
+                return;
+        }
+
+        if (gtk_widget_is_ancestor (gtk_grab_get_current (), icon->priv->dock)) {
+                return;
+        }
+
+        popdown_dock (icon);
+}
+
+static void
+on_dock_grab_notify (GtkWidget           *widget,
+                     gboolean             was_grabbed,
+                     GvcStreamStatusIcon *icon)
+{
+        gvc_icon_grab_notify (icon, was_grabbed);
+}
+
+static gboolean
+on_dock_grab_broken_event (GtkWidget           *widget,
+                           gboolean             was_grabbed,
+                           GvcStreamStatusIcon *icon)
+{
+        gvc_icon_grab_notify (icon, FALSE);
+
+        return FALSE;
+}
+
+static gboolean
+on_dock_key_release (GtkWidget           *widget,
+                     GdkEventKey         *event,
+                     GvcStreamStatusIcon *icon)
+{
+        if (event->keyval == GDK_Escape) {
+                popdown_dock (icon);
+                return TRUE;
+        }
+
+#if 0
+        if (!gtk_bindings_activate_event (GTK_OBJECT (widget), event)) {
+                /* The popup hasn't managed the event, pass onto the button */
+                gtk_bindings_activate_event (GTK_OBJECT (user_data), event);
+        }
+#endif
+        return TRUE;
+}
+
+static void
+maybe_show_status_icon (GvcStreamStatusIcon *icon)
+{
+        gboolean show;
+
+        show = TRUE;
+
+        if (icon->priv->mixer_stream == NULL) {
+                show = FALSE;
+        }
+
+        if (icon->priv->dock != NULL) {
+                gtk_widget_hide (icon->priv->dock);
+        }
+
+        gtk_status_icon_set_visible (GTK_STATUS_ICON (icon), show);
+}
+
+static void
+update_icon (GvcStreamStatusIcon *icon)
+{
+        guint    volume;
+        gboolean is_muted;
+        guint    n;
+        char    *markup;
+
+        maybe_show_status_icon (icon);
+
+        if (icon->priv->mixer_stream == NULL) {
+                return;
+        }
+
+        volume = gvc_mixer_stream_get_volume (icon->priv->mixer_stream);
+        is_muted = gvc_mixer_stream_get_is_muted (icon->priv->mixer_stream);
+
+        /* select image */
+        if (volume <= 0 || is_muted) {
+                n = 0;
+        } else {
+                n = 3 * volume / PA_VOLUME_NORM + 1;
+                if (n < 1) {
+                        n = 1;
+                } else if (n > 3) {
+                        n = 3;
+                }
+        }
+
+        /* apparently status icon will reset icon even if
+         * if doesn't change */
+        if (icon->priv->current_icon != n) {
+                gtk_status_icon_set_from_icon_name (GTK_STATUS_ICON (icon),
+                                                    icon->priv->icon_names [n]);
+                icon->priv->current_icon = n;
+        }
+
+        markup = g_strdup_printf ("<b>%s: %.0f%%</b>\n<small>%s</small>",
+                                  icon->priv->display_name,
+                                  100 * (float)volume / PA_VOLUME_NORM,
+                                  gvc_mixer_stream_get_description (icon->priv->mixer_stream));
+        gtk_status_icon_set_tooltip_markup (GTK_STATUS_ICON (icon),
+                                            markup);
+        g_free (markup);
+}
+
+void
+gvc_stream_status_icon_set_icon_names (GvcStreamStatusIcon  *icon,
+                                       const char          **names)
+{
+        g_return_if_fail (GVC_IS_STREAM_STATUS_ICON (icon));
+
+        g_strfreev (icon->priv->icon_names);
+        icon->priv->icon_names = g_strdupv ((char **)names);
+        update_icon (icon);
+        g_object_notify (G_OBJECT (icon), "icon-names");
+}
+
+static void
+on_stream_volume_notify (GObject             *object,
+                         GParamSpec          *pspec,
+                         GvcStreamStatusIcon *icon)
+{
+        update_icon (icon);
+        /* FIXME: update dock too */
+}
+
+static void
+on_stream_is_muted_notify (GObject             *object,
+                           GParamSpec          *pspec,
+                           GvcStreamStatusIcon *icon)
+{
+        update_icon (icon);
+        /* FIXME: update dock too */
+}
+
+void
+gvc_stream_status_icon_set_display_name (GvcStreamStatusIcon *icon,
+                                         const char          *name)
+{
+        g_return_if_fail (GVC_STREAM_STATUS_ICON (icon));
+
+        g_free (icon->priv->display_name);
+        icon->priv->display_name = g_strdup (name);
+        update_icon (icon);
+        g_object_notify (G_OBJECT (icon), "display-name");
+}
+
+void
+gvc_stream_status_icon_set_mixer_stream (GvcStreamStatusIcon *icon,
+                                         GvcMixerStream      *stream)
+{
+        g_return_if_fail (GVC_STREAM_STATUS_ICON (icon));
+
+        if (stream != NULL) {
+                g_object_ref (stream);
+        }
+
+        if (icon->priv->mixer_stream != NULL) {
+                g_signal_handlers_disconnect_by_func (icon->priv->mixer_stream,
+                                                      G_CALLBACK (on_stream_volume_notify),
+                                                      icon);
+                g_signal_handlers_disconnect_by_func (icon->priv->mixer_stream,
+                                                      G_CALLBACK (on_stream_is_muted_notify),
+                                                      icon);
+                g_object_unref (icon->priv->mixer_stream);
+                icon->priv->mixer_stream = NULL;
+        }
+
+        icon->priv->mixer_stream = stream;
+
+        if (icon->priv->mixer_stream != NULL) {
+                GtkAdjustment *adj;
+
+                g_object_ref (icon->priv->mixer_stream);
+
+                adj = GTK_ADJUSTMENT (gvc_channel_bar_get_adjustment (GVC_CHANNEL_BAR (icon->priv->bar)));
+                gtk_adjustment_set_value (adj,
+                                          gvc_mixer_stream_get_volume (icon->priv->mixer_stream));
+
+                g_signal_connect (icon->priv->mixer_stream,
+                                  "notify::volume",
+                                  G_CALLBACK (on_stream_volume_notify),
+                                  icon);
+                g_signal_connect (icon->priv->mixer_stream,
+                                  "notify::is-muted",
+                                  G_CALLBACK (on_stream_is_muted_notify),
+                                  icon);
+        }
+
+        update_icon (icon);
+
+        g_object_notify (G_OBJECT (icon), "mixer-stream");
+}
+
+static void
+gvc_stream_status_icon_set_property (GObject       *object,
+                                     guint          prop_id,
+                                     const GValue  *value,
+                                     GParamSpec    *pspec)
+{
+        GvcStreamStatusIcon *self = GVC_STREAM_STATUS_ICON (object);
+
+        switch (prop_id) {
+        case PROP_MIXER_STREAM:
+                gvc_stream_status_icon_set_mixer_stream (self, g_value_get_object (value));
+                break;
+        case PROP_DISPLAY_NAME:
+                gvc_stream_status_icon_set_display_name (self, g_value_get_string (value));
+                break;
+        case PROP_ICON_NAMES:
+                gvc_stream_status_icon_set_icon_names (self, g_value_get_boxed (value));
+                break;
+        default:
+                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+                break;
+        }
+}
+
+static void
+gvc_stream_status_icon_get_property (GObject     *object,
+                                     guint        prop_id,
+                                     GValue      *value,
+                                     GParamSpec  *pspec)
+{
+        GvcStreamStatusIcon *self = GVC_STREAM_STATUS_ICON (object);
+        GvcStreamStatusIconPrivate *priv = self->priv;
+
+        switch (prop_id) {
+        case PROP_MIXER_STREAM:
+                g_value_set_object (value, priv->mixer_stream);
+                break;
+        case PROP_DISPLAY_NAME:
+                g_value_set_string (value, priv->display_name);
+                break;
+        case PROP_ICON_NAMES:
+                g_value_set_boxed (value, priv->icon_names);
+                break;
+        default:
+                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+                break;
+        }
+}
+
+static void
+on_bar_is_muted_notify (GObject             *object,
+                        GParamSpec          *pspec,
+                        GvcStreamStatusIcon *icon)
+{
+        gboolean is_muted;
+
+        is_muted = gvc_channel_bar_get_is_muted (GVC_CHANNEL_BAR (object));
+        gvc_mixer_stream_change_is_muted (icon->priv->mixer_stream,
+                                          is_muted);
+}
+
+static GObject *
+gvc_stream_status_icon_constructor (GType                  type,
+                                    guint                  n_construct_properties,
+                                    GObjectConstructParam *construct_params)
+{
+        GObject             *object;
+        GvcStreamStatusIcon *icon;
+        GtkWidget           *frame;
+        GtkWidget           *box;
+        GtkAdjustment       *adj;
+
+        object = G_OBJECT_CLASS (gvc_stream_status_icon_parent_class)->constructor (type, n_construct_properties, construct_params);
+
+        icon = GVC_STREAM_STATUS_ICON (object);
+
+        gtk_status_icon_set_from_icon_name (GTK_STATUS_ICON (icon),
+                                            icon->priv->icon_names[0]);
+
+        /* window */
+        icon->priv->dock = gtk_window_new (GTK_WINDOW_POPUP);
+        gtk_widget_set_name (icon->priv->dock, "gvc-stream-status-icon-popup-window");
+        g_signal_connect (icon->priv->dock,
+                          "button-press-event",
+                          G_CALLBACK (on_dock_button_press),
+                          icon);
+        g_signal_connect (icon->priv->dock,
+                          "key-release-event",
+                          G_CALLBACK (on_dock_key_release),
+                          icon);
+        g_signal_connect (icon->priv->dock,
+                          "grab-notify",
+                          G_CALLBACK (on_dock_grab_notify),
+                          icon);
+        g_signal_connect (icon->priv->dock,
+                          "grab-broken-event",
+                          G_CALLBACK (on_dock_grab_broken_event),
+                          icon);
+
+        gtk_window_set_decorated (GTK_WINDOW (icon->priv->dock), FALSE);
+
+        frame = gtk_frame_new (NULL);
+        gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_OUT);
+        gtk_container_add (GTK_CONTAINER (icon->priv->dock), frame);
+        gtk_widget_show (frame);
+
+        box = gtk_vbox_new (FALSE, 6);
+        gtk_container_set_border_width (GTK_CONTAINER (box), 6);
+        gtk_container_add (GTK_CONTAINER (frame), box);
+
+        icon->priv->bar = gvc_channel_bar_new ();
+        gvc_channel_bar_set_orientation (GVC_CHANNEL_BAR (icon->priv->bar),
+                                         GTK_ORIENTATION_VERTICAL);
+
+        gtk_box_pack_start (GTK_BOX (box), icon->priv->bar, TRUE, FALSE, 0);
+        g_signal_connect (icon->priv->bar,
+                          "notify::is-muted",
+                          G_CALLBACK (on_bar_is_muted_notify),
+                          icon);
+
+        adj = GTK_ADJUSTMENT (gvc_channel_bar_get_adjustment (GVC_CHANNEL_BAR (icon->priv->bar)));
+        g_signal_connect (adj,
+                          "value-changed",
+                          G_CALLBACK (on_adjustment_value_changed),
+                          icon);
+
+        return object;
+}
+
+static void
+gvc_stream_status_icon_dispose (GObject *object)
+{
+        GvcStreamStatusIcon *icon = GVC_STREAM_STATUS_ICON (object);
+
+        if (icon->priv->dock != NULL) {
+                gtk_widget_destroy (icon->priv->dock);
+                icon->priv->dock = NULL;
+        }
+
+        if (icon->priv->mixer_stream != NULL) {
+                g_object_unref (icon->priv->mixer_stream);
+                icon->priv->mixer_stream = NULL;
+        }
+
+        G_OBJECT_CLASS (gvc_stream_status_icon_parent_class)->dispose (object);
+}
+
+static void
+gvc_stream_status_icon_class_init (GvcStreamStatusIconClass *klass)
+{
+        GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+        object_class->constructor = gvc_stream_status_icon_constructor;
+        object_class->finalize = gvc_stream_status_icon_finalize;
+        object_class->dispose = gvc_stream_status_icon_dispose;
+        object_class->set_property = gvc_stream_status_icon_set_property;
+        object_class->get_property = gvc_stream_status_icon_get_property;
+
+        g_object_class_install_property (object_class,
+                                         PROP_MIXER_STREAM,
+                                         g_param_spec_object ("mixer-stream",
+                                                              "mixer stream",
+                                                              "mixer stream",
+                                                              GVC_TYPE_MIXER_STREAM,
+                                                              G_PARAM_READWRITE|G_PARAM_CONSTRUCT));
+        g_object_class_install_property (object_class,
+                                         PROP_DISPLAY_NAME,
+                                         g_param_spec_string ("display-name",
+                                                              "Display Name",
+                                                              "Name to display for this stream",
+                                                              NULL,
+                                                              G_PARAM_READWRITE|G_PARAM_CONSTRUCT));
+        g_object_class_install_property (object_class,
+                                         PROP_ICON_NAMES,
+                                         g_param_spec_boxed ("icon-names",
+                                                             "Icon Names",
+                                                             "Name of icon to display for this stream",
+                                                              G_TYPE_STRV,
+                                                              G_PARAM_READWRITE|G_PARAM_CONSTRUCT));
+
+        g_type_class_add_private (klass, sizeof (GvcStreamStatusIconPrivate));
+}
+
+static void
+gvc_stream_status_icon_init (GvcStreamStatusIcon *icon)
+{
+        icon->priv = GVC_STREAM_STATUS_ICON_GET_PRIVATE (icon);
+
+        g_signal_connect (icon,
+                          "activate",
+                          G_CALLBACK (on_status_icon_activate),
+                          icon);
+        g_signal_connect (icon,
+                          "popup-menu",
+                          G_CALLBACK (on_status_icon_popup_menu),
+                          icon);
+#if GTK_CHECK_VERSION(2,15,0)
+        g_signal_connect (icon,
+                          "scroll-event",
+                          G_CALLBACK (on_status_icon_scroll_event),
+                          icon);
+#endif
+
+}
+
+static void
+gvc_stream_status_icon_finalize (GObject *object)
+{
+        GvcStreamStatusIcon *stream_status_icon;
+
+        g_return_if_fail (object != NULL);
+        g_return_if_fail (GVC_IS_STREAM_STATUS_ICON (object));
+
+        stream_status_icon = GVC_STREAM_STATUS_ICON (object);
+
+        g_return_if_fail (stream_status_icon->priv != NULL);
+
+        g_strfreev (stream_status_icon->priv->icon_names);
+
+        G_OBJECT_CLASS (gvc_stream_status_icon_parent_class)->finalize (object);
+}
+
+GvcStreamStatusIcon *
+gvc_stream_status_icon_new (GvcMixerStream *stream,
+                            const char    **icon_names)
+{
+        GObject *icon;
+        icon = g_object_new (GVC_TYPE_STREAM_STATUS_ICON,
+                             "mixer-stream", stream,
+                             "icon-names", icon_names,
+                             NULL);
+        return GVC_STREAM_STATUS_ICON (icon);
+}

Added: trunk/gnome-volume-control/src/gvc-stream-status-icon.h
==============================================================================
--- (empty file)
+++ trunk/gnome-volume-control/src/gvc-stream-status-icon.h	Thu Dec 11 17:28:22 2008
@@ -0,0 +1,63 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2008 Red Hat, Inc.
+ *
+ * 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
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ */
+
+#ifndef __GVC_STREAM_STATUS_ICON_H
+#define __GVC_STREAM_STATUS_ICON_H
+
+#include <glib-object.h>
+#include "gvc-mixer-stream.h"
+
+G_BEGIN_DECLS
+
+#define GVC_TYPE_STREAM_STATUS_ICON         (gvc_stream_status_icon_get_type ())
+#define GVC_STREAM_STATUS_ICON(o)           (G_TYPE_CHECK_INSTANCE_CAST ((o), GVC_TYPE_STREAM_STATUS_ICON, GvcStreamStatusIcon))
+#define GVC_STREAM_STATUS_ICON_CLASS(k)     (G_TYPE_CHECK_CLASS_CAST((k), GVC_TYPE_STREAM_STATUS_ICON, GvcStreamStatusIconClass))
+#define GVC_IS_STREAM_STATUS_ICON(o)        (G_TYPE_CHECK_INSTANCE_TYPE ((o), GVC_TYPE_STREAM_STATUS_ICON))
+#define GVC_IS_STREAM_STATUS_ICON_CLASS(k)  (G_TYPE_CHECK_CLASS_TYPE ((k), GVC_TYPE_STREAM_STATUS_ICON))
+#define GVC_STREAM_STATUS_ICON_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GVC_TYPE_STREAM_STATUS_ICON, GvcStreamStatusIconClass))
+
+typedef struct GvcStreamStatusIconPrivate GvcStreamStatusIconPrivate;
+
+typedef struct
+{
+        GtkStatusIcon               parent;
+        GvcStreamStatusIconPrivate *priv;
+} GvcStreamStatusIcon;
+
+typedef struct
+{
+        GtkStatusIconClass          parent_class;
+} GvcStreamStatusIconClass;
+
+GType                 gvc_stream_status_icon_get_type            (void);
+
+GvcStreamStatusIcon * gvc_stream_status_icon_new                 (GvcMixerStream      *stream,
+                                                                  const char         **icon_names);
+
+void                  gvc_stream_status_icon_set_icon_names      (GvcStreamStatusIcon *icon,
+                                                                  const char         **icon_names);
+void                  gvc_stream_status_icon_set_display_name    (GvcStreamStatusIcon *icon,
+                                                                  const char          *display_name);
+void                  gvc_stream_status_icon_set_mixer_stream    (GvcStreamStatusIcon *icon,
+                                                                  GvcMixerStream      *stream);
+
+G_END_DECLS
+
+#endif /* __GVC_STREAM_STATUS_ICON_H */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]