Version 14
[AdvancedVolumeMixer.git] / widget.js
blob4145c1ed49426a9543a7fd62310bbafbf8e00f94
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 Atk = imports.gi.Atk;
12 const Clutter = imports.gi.Clutter;
13 const Lang = imports.lang;
15 const BoxPointer = imports.ui.boxpointer;
17 const Volume = imports.ui.status.volume;
20 const AppOutputStreamSlider = new Lang.Class({
21   Name: "AppOutputStreamSlider",
22   Extends: Volume.OutputStreamSlider,
24   _init: function(control, oldStyle, stream_name_func) {
25     this.parent(control);
26     log("AppOutputStreamSlider");
28     this.item.destroy();
30     this.stream_name = stream_name_func || function (stream) { return stream.get_name() || stream.get_description(); };
32     this.oldStyle = oldStyle || false;
33     this.item = new PopupMenu.PopupBaseMenuItem({ activate: false });
35     this._vbox = new St.BoxLayout({vertical: true});
37     this._slider = new Slider.Slider(0);
38     this._slider.connect('value-changed', Lang.bind(this, this._sliderChanged));
39     this._slider.connect('drag-end', Lang.bind(this, this._notifyVolumeChange));
41     this._icon = new St.Icon({ style_class: 'adv-volume-icon' });
42     this._label = new St.Label({text: ""});
43     this.item.actor.add(this._icon);
44     this._vbox.add(this._label);
45     this._vbox.add(this._slider.actor);
46     this.item.actor.add(this._vbox, {expand: true});
48     this.item.actor.connect('scroll-event', Lang.bind(this._slider, this._slider._onScrollEvent));
49   },
51   setButtonPressEvent: function() {
52     this.item.actor.connect('button-press-event', Lang.bind(this, function(actor, event) {
53       // FIXME Middle click mute
54       this._slider.startDragging(event);
55     }));
56   },
58   setOnlyMiddleButtonPressEvent: function() {
59     this.item.actor.connect('button-press-event', Lang.bind(this, function(actor, event) {
60       // FIXME Middle click mute
61     }));
62   },
64   setKeyPressEvent: function() {
65     this.item.actor.connect('key-press-event', Lang.bind(this, function(actor, event) {
66       return this._slider.onKeyPressEvent(actor, event);
67     }));
68   },
70   _updateSliderIcon: function() {
71     if (this._stream && !this.oldStyle) {
72       this._icon.gicon = this._stream.get_gicon();
73     } else {
74       this.parent();
75     }
77     this.emit("stream-updated");
78   },
80   _connectStream: function(stream) {
81     this.parent(stream);
83     this._label.text = this.stream_name(stream);
84     this._updateSliderIcon();
85     this.item.actor.stream = stream;
86   }
87 });
89 const AdvSubMenuItem = new Lang.Class({
90   Name: "AdvSubMenuItem",
91   Extends: PopupMenu.PopupSubMenuMenuItem,
93   _init: function(oldStyle) {
94     this.parent("", true);
96     //this.icon.remove_style_class_name("popup-menu-icon");
97     this.icon.set_style_class_name("adv-volume-icon");
98     this.slider = new Slider.Slider(0);
100     // Remove actors except ornament
101     this.actor.get_children().map(Lang.bind(this, function(child) {
102       log(child);
103       if (!child.has_style_class_name("popup-menu-ornament")) {
104         this.actor.remove_actor(child);
105       }
106     }));
108     if (oldStyle) {
109       this.actor.add_child(this.icon);
110       this.actor.add(this.slider.actor, {expand: true});
111       this.actor.add_child(this._triangleBin);
112     } else {
113       this._vbox = new St.BoxLayout({vertical: true});
114       this._hbox = new St.BoxLayout({vertical: false});
116       this._hbox.add(this.label);
117       this._hbox.add(this._triangleBin);
118       this._vbox.add(this._hbox);
119       this._vbox.add(this.slider.actor);
121       this.actor.add_child(this.icon);
122       this.actor.add_child(this._vbox);
123     }
124   },
126   _onButtonReleaseEvent: function (actor, event) {
127     if (event.get_button() != 2) {
128       this._setOpenState(!this._getOpenState());
129     }
130   }
134 const AdvOutputStreamSlider = new Lang.Class({
135   Name: "AdvOutputStreamSlider",
136   Extends: AppOutputStreamSlider,
138   _init: function(control, oldStyle) {
139     this.parent(control, oldStyle);
140     log("AdvOutputStreamSlider");
142     this.item.destroy();
143     this.item = new AdvSubMenuItem(this.oldStyle);
145     this._slider.actor.destroy();
146     this._slider = this.item.slider;
147     this._slider.connect('value-changed', Lang.bind(this, this._sliderChanged));
148     this._slider.connect('drag-end', Lang.bind(this, this._notifyVolumeChange));
150     this._icon.destroy();
151     this._icon = this.item.icon;
152     this._label.destroy();
153     this._label = this.item.label;
155     this.item.actor.connect('scroll-event', Lang.bind(this._slider, this._slider._onScrollEvent));
157   }