~vikoadi/audience/volume-control

« back to all changes in this revision

Viewing changes to src/Volume/VolumeScale.vala

  • Committer: Viko Adi Rahmawan
  • Date: 2015-10-31 19:24:36 UTC
  • Revision ID: vikoadi@gmail.com-20151031192436-73qoc7z9s3lhmi7x
useĀ getterĀ setter

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
namespace Audience.Widgets {
2
 
    public class VolumeScale : Sound.Widgets.Scale, IController {
3
 
        public VolumeScale () {
 
2
    public class VolumeScale : Sound.Widgets.Scale {
 
3
        double volume {
 
4
            get {
 
5
                return get_scale().get_value();
 
6
            }
 
7
            set {
 
8
                get_scale ().set_value (value);
 
9
                update_volume_icon (value);
 
10
            }
 
11
        }
 
12
 
 
13
        bool mute {
 
14
            get {
 
15
                return !get_switch ().active;
 
16
            }
 
17
            set {
 
18
                get_switch ().active = !value;
 
19
                get_image ().set_sensitive (!value);
 
20
                get_scale ().set_sensitive (!value);
 
21
            }
 
22
        }
 
23
 
 
24
        public VolumeScale (VolumeController controller) {
4
25
            base("audio-volume-high-symbolic", true, 0.0, 1.0, 0.01);
5
26
 
 
27
            controller.notify.connect(on_controller_changed);
 
28
 
6
29
            get_scale ().value_changed.connect (() => {
7
 
                volume_changed (get_scale ().get_value ());
 
30
                controller.volume = get_scale ().get_value ();
8
31
            });
9
32
 
10
33
            get_switch ().notify["active"].connect (() => {
11
 
                mute_changed (get_mute());
 
34
                controller.mute = !get_switch().active;
12
35
            });
13
36
        }
14
37
 
15
 
        public void set_volume (double volume) {
16
 
            var max_volume = 1.0;
17
 
            get_scale ().set_value (volume);
18
 
            update_volume_icon (volume);
19
 
        }
20
 
 
21
 
        public double get_volume () {
22
 
            return get_scale ().get_value ();
23
 
        }
24
 
 
25
 
        public bool get_mute () {
26
 
            return !get_switch ().active;
27
 
        }
28
 
 
29
 
        public void set_mute (bool mute) {
30
 
            message("set_mute"+(mute?"true":"false"));
31
 
            get_switch ().active = !mute;
32
 
            get_image ().set_sensitive (!mute);
33
 
            get_scale ().set_sensitive (!mute);
34
 
        }
35
 
 
36
 
        private void update_volume_icon (double v) {
 
38
        void on_controller_changed (Object o, ParamSpec p) {
 
39
            switch (p.name) {
 
40
                case "mute":
 
41
                    mute=((VolumeController)o).mute;
 
42
                break;
 
43
                case "volume":
 
44
                    volume=((VolumeController)o).volume;
 
45
                break;
 
46
                default:
 
47
                break;
 
48
            }
 
49
        }
 
50
 
 
51
        void update_volume_icon (double v) {
37
52
            string icon;
38
53
            if (v <= 0.0) {
39
54
                icon = "audio-volume-muted-symbolic";