AppOutputStreamSlider: added stream name.
[AdvancedVolumeMixer.git] / widget.js
blobc42ff7ffa0558d8f76b192e98c102e3b64d4c70f
1 // vi: et sw=2 fileencoding=utf8
2 //
4 const Mainloop = imports.mainloop;
5 const St = imports.gi.St;
6 const PopupMenu = imports.ui.popupMenu;
7 const Slider = imports.ui.slider;
8 const Pango = imports.gi.Pango;
9 const GLib = imports.gi.GLib;
10 const Gio = imports.gi.Gio;
11 const Lang = imports.lang;
13 const Volume = imports.ui.status.volume;
16 const AppOutputStreamSlider = new Lang.Class({
17   Name: "AppOutputStreamSlider",
18   Extends: Volume.StreamSlider,
20   _init: function(control) {
21     log("AppOutputStreamSlider");
23     this._control = control;
24     this.item = new PopupMenu.PopupBaseMenuItem({ activate: false });
26     this._vbox = new St.BoxLayout({vertical: true});
27     //this._hbox = new St.BoxLayout({vertical: false});
29     this._slider = new Slider.Slider(0);
30     this._slider.connect('value-changed', Lang.bind(this, this._sliderChanged));
31     this._slider.connect('drag-end', Lang.bind(this, this._notifyVolumeChange));
33     this._icon = new St.Icon({ style_class: 'popup-menu-icon' });
34     this._label = new St.Label({text: ""});
35     this.item.actor.add(this._icon);
36     //this.item.actor.add(this._slider.actor, { expand: true });
37     //this._hbox.add(this._icon);
38     this._vbox.add(this._label);
39     this._vbox.add(this._slider.actor /*,{ expand: true }*/);
40     //this._vbox.add(this._hbox);
41     this.item.actor.add(this._vbox, {expand: true});
43     this.item.actor.connect('button-press-event', Lang.bind(this, function(actor, event) {
44         this._slider.startDragging(event);
45     }));
46     this.item.actor.connect('key-press-event', Lang.bind(this, function(actor, event) {
47         return this._slider.onKeyPressEvent(actor, event);
48     }));
49   },
51   _updateSliderIcon: function() {
52     if (this._stream) {
53       log("_updateSliderIcon:");
54       log(this._stream.get_gicon());
55       this._icon.gicon = this._stream.get_gicon();
56     } else {
57       this._icon.icon_name = (this._hasHeadphones ?
58                               'audio-headphones-symbolic' :
59                               'audio-speakers-symbolic');
60     }
61   },
63   _connectStream: function(stream) {
64     this._mutedChangedId = stream.connect('notify::is-muted', Lang.bind(this, this._updateVolume));
65     this._volumeChangedId = stream.connect('notify::volume', Lang.bind(this, this._updateVolume));
66     this._label.text = stream.get_name();
67     this._icon.gicon = stream.get_gicon();
68   },
70 });