Dap.Bluetooth: Retire MediaControlWidget
[banshee-community-extensions:banshee-community-extensions.git] / src / Bluetooth / Banshee.Dap.Bluetooth / Gui / MediaControlWidget.fs
1 //
2 // MediaControlWidget.fs
3 //
4 // Author:
5 //   Nicholas J. Little <arealityfarbetween@googlemail.com>
6 //
7 // Copyright (c) 2014 Nicholas J. Little
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining a copy
10 // of this software and associated documentation files (the "Software"), to deal
11 // in the Software without restriction, including without limitation the rights
12 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 // copies of the Software, and to permit persons to whom the Software is
14 // furnished to do so, subject to the following conditions:
15 //
16 // The above copyright notice and this permission notice shall be included in
17 // all copies or substantial portions of the Software.
18 //
19 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 // THE SOFTWARE.
26 namespace Banshee.Dap.Bluetooth.Gui
27
28 open Banshee.Dap.Bluetooth.Wrappers
29 open Gtk
30 open Hyena.Log
31 open Hyena.ThreadAssist
32
33 type MediaControlButton(img: Image, mc: INotifyMediaControl) as this =
34     inherit ToggleButton(Image = img)
35     let menu = new Menu()
36     let button_icon x =
37         let img = new Image(IconName = x)
38         let item = new MenuItem (Child = img)
39         item
40     let play = button_icon "media-playback-start"
41     let pause = button_icon "media-playback-pause"
42     let stop = button_icon "media-playback-stop"
43     let next = button_icon "media-skip-forward"
44     let prev = button_icon "media-skip-backward"
45     let fwd = button_icon "media-seek-forward"
46     let rwd = button_icon "media-seek-backward"
47     let vup = button_icon "audio-volume-high"
48     let vdn = button_icon "audio-volume-low"
49     let hidden _ = this.Active <- false
50     do
51        menu.Append prev
52        menu.Append rwd
53        menu.Append stop
54        menu.Append pause
55        menu.Append play
56        menu.Append fwd
57        menu.Append next
58        menu.Append vup
59        menu.Append vdn
60        menu.ShowAll ()
61        menu.Hidden.Add hidden
62
63        play.Activated.Add (fun o -> mc.Play ())
64        pause.Activated.Add (fun o -> mc.Pause ())
65        stop.Activated.Add (fun o -> mc.Stop ())
66        next.Activated.Add (fun o -> mc.Next ())
67        prev.Activated.Add (fun o -> mc.Previous ())
68        rwd.Activated.Add (fun o -> mc.Rewind ())
69        fwd.Activated.Add (fun o -> mc.FastForward ())
70        vup.Activated.Add (fun o -> mc.VolumeUp ())
71        vdn.Activated.Add (fun o -> mc.VolumeDown ())
72     override x.OnToggled () =
73         if x.Active then
74           menu.Popup ()
75         else
76           menu.Popdown ()
77     new (mc) =
78         let img = new Image(IconName = "media-playback-start", IconSize = int IconSize.LargeToolbar)
79         new MediaControlButton (img, mc)