AppOutputStreamSlider: Fixed scrolling and added description if stream has no name.
[AdvancedVolumeMixer.git] / widget.js
blobe203f43bf7552eb9dd25d934ceb38fc45a76ca32
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: 'adv-volume-icon' });
34     this._label = new St.Label({text: ""});
35     this.item.actor.add(this._icon);
36     this._vbox.add(this._label);
37     this._vbox.add(this._slider.actor /*,{ expand: true }*/);
38     this.item.actor.add(this._vbox, {expand: true});
40     this.item.actor.connect('scroll-event', Lang.bind(this._slider, this._slider._onScrollEvent));
41     this.item.actor.connect('button-press-event', Lang.bind(this, function(actor, event) {
42       this._slider.startDragging(event);
43     }));
44     this.item.actor.connect('key-press-event', Lang.bind(this, function(actor, event) {
45       return this._slider.onKeyPressEvent(actor, event);
46     }));
47   },
49   _updateSliderIcon: function() {
50     if (this._stream) {
51       log("_updateSliderIcon:");
52       log(this._stream.get_gicon());
53       this._icon.gicon = this._stream.get_gicon();
54     } else {
55       this._icon.icon_name = (this._hasHeadphones ?
56                               'audio-headphones-symbolic' :
57                               'audio-speakers-symbolic');
58     }
59   },
61   _connectStream: function(stream) {
62     this._mutedChangedId = stream.connect('notify::is-muted', Lang.bind(this, this._updateVolume));
63     this._volumeChangedId = stream.connect('notify::volume', Lang.bind(this, this._updateVolume));
64     this._label.text = stream.get_name() || stream.get_description();
65     this._icon.gicon = stream.get_gicon();
66   },
68 });