Version 14
[AdvancedVolumeMixer.git] / panel.js
blob62bcf4f0f1c75f4eec95914eb672266bc8fe249b
1 // vi: et sw=2 fileencoding=utf8
2 //
5 const Lang = imports.lang;
6 const Clutter = imports.gi.Clutter;
7 const St = imports.gi.St;
8 const PanelMenu = imports.ui.panelMenu;
9 const GLib = imports.gi.GLib;
11 const AVM = imports.misc.extensionUtils.getCurrentExtension();
12 const Settings = AVM.imports.settings;
14 const AdvancedVolumeMixerStatusButton = new Lang.Class({
15   Name: 'AdvancedVolumeMixerStatusButton',
16   Extends: PanelMenu.Button,
18   _init: function(mixer) {
19     this.parent(0.0, "AdvancedVolumeMixer");
21     this.mixer = mixer;
23     this._box = new St.BoxLayout();
25     this._icon = new St.Icon({style_class: 'system-status-icon'});
26     this._bin = new St.Bin({child: this._icon});
28     this._stateIcon = new St.Icon({icon_name: 'audio-headphones-symbolic',
29                                    style_class: 'system-status-icon'});
30     this._stateIconBin = new St.Bin({child: this._stateIcon});
32     this._box.add(this._bin);
33     this._box.add(this._stateIconBin);
35     this._stateIconBin.hide();
37     this.actor.add_actor(this._box);
38     this.actor.add_style_class_name('panel-status-button');
39     this.actor.connect('scroll-event', Lang.bind(this, this._onScrollEvent));
41     this.mixer.connect("icon-changed", Lang.bind(this, this._onIconChanged));
43     this.menu.actor.add_style_class_name("AdvancedVolumeMixer");
44     this.menu.addMenuItem(this.mixer);
46     this._onIconChanged();
47   },
49   _onScrollEvent: function (actor, event) {
50     this.mixer.scroll(event);
51   },
53   _onIconChanged: function () {
54     this.setIcon(this.mixer.getIcon());
56     if (this.mixer.outputHasHeadphones()) {
57       this._stateIconBin.show();
58     } else {
59       this._stateIconBin.hide();
60     }
61   },
63   setIcon: function (icon_name) {
64     this._icon.icon_name = icon_name;
65   }
66 });