5 // Nicholas J. Little <arealityfarbetween@googlemail.com>
7 // Copyright (c) 2014 Nicholas J. Little
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:
16 // The above copyright notice and this permission notice shall be included in
17 // all copies or substantial portions of the Software.
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
26 namespace Banshee.Dap.Bluetooth.Gui
29 open Banshee.ServiceStack
30 open Banshee.Dap.Bluetooth
31 open Banshee.Dap.Bluetooth.Wrappers
32 open Banshee.Dap.Bluetooth.Devices
33 open Banshee.Dap.Bluetooth.Client
34 open Banshee.Dap.Bluetooth.DapGlue
35 open Banshee.Dap.Bluetooth.SupportApi
36 open Banshee.Dap.Bluetooth.Gui.SpinButtons
40 type DeviceWidget(dev: IBansheeDevice) =
41 inherit VBox(false, 5, MarginLeft = 10, MarginRight = 10)
42 static let ICON_SIZE = int IconSize.LargeToolbar
43 static let PIXBUF_PREFS = "gnome-settings"
44 static let PIXBUF_PAIR = Gdk.Pixbuf.LoadFromResource("paired-black.png")
45 static let PIXBUF_SYNC = Gdk.Pixbuf.LoadFromResource("21cc-sync.png")
46 static let PIXBUF_AI = "audio-input-microphone"
47 static let PIXBUF_AO = "audio-speakers"
48 static let PIXBUF_HS = "audio-headphones"
49 static let PIXBUF_TIME = "preferences-system-time"
50 static let toggle_icon x =
51 new ToggleButton(Image = new Image(IconName = x, IconSize = ICON_SIZE))
52 static let toggle_buffer (x: Gdk.Pixbuf) =
53 new ToggleButton(Image = new Image(x))
54 let dev_bt = dev.Device
55 let mutable mcw = Unchecked.defaultof<_>
56 let line1 = new HBox(false, 5)
57 let line2 = new HBox(false, 0)
58 let sbox = new HBox(false, 5)
59 let icon = new Image(IconName = IconOf dev_bt, IconSize = ICON_SIZE)
60 let label = new Label(UseMarkup = true)
61 let ai = toggle_icon PIXBUF_AI
62 let ao = toggle_icon PIXBUF_AO
63 let hs = toggle_icon PIXBUF_HS
64 let pair = toggle_buffer PIXBUF_PAIR
65 let conn = toggle_buffer PIXBUF_SYNC
66 let conf = toggle_icon PIXBUF_TIME
67 let time = new TimeSpinButton()
68 let has_ai () = dev.HasSupport Feature.AudioIn
69 let has_ao () = dev.HasSupport Feature.AudioOut
70 let has_hs () = dev.HasSupport Feature.Headset
71 let has_sy () = dev.HasSupport Feature.Sync
72 let act_ai () = dev.IsConnected Feature.AudioIn
73 let act_ao () = dev.IsConnected Feature.AudioOut
74 let act_hs () = dev.IsConnected Feature.Headset
75 let act_sy () = dev.IsConnected Feature.Sync
76 let act x y f = match (x, y()) with
77 | (true, false) -> dev.Connect f
78 | (false, true) -> dev.Disconnect f
80 let markup () = if dev_bt.Connected then
81 sprintf "<b>%s</b>" dev_bt.Alias
85 ThreadAssist.BlockingProxyToMain (fun () ->
86 pair.Visible <- not dev_bt.Paired
87 label.Markup <- markup()
91 conn.Active <- act_sy()
92 conf.Active <- dev.Config.Auto
93 ai.Visible <- has_ai()
94 ao.Visible <- has_ao()
95 hs.Visible <- has_hs()
96 sbox.Visible <- has_sy()
97 time.Visible <- dev.Config.Auto
98 time.Value <- float dev.Config.Time
99 match (dev.MediaControl, IsNull mcw) with
100 | (Some mc, true) -> mcw <- new MediaControlWidget(mc)
101 line2.PackStart (mcw, true, true, 0u)
102 | (None, false) -> line2.Remove mcw
104 mcw <- Unchecked.defaultof<_>
107 do sbox.PackStart (time, false, false, 0u)
108 sbox.PackStart (conf, false, false, 0u)
109 sbox.PackStart (conn, false, false, 0u)
110 line1.PackStart (pair, false, false, 0u)
111 line1.PackStart (icon, false, false, 0u)
112 line1.PackStart (label, false, false, 0u)
113 line1.PackEnd (ai, false, false, 0u)
114 line1.PackEnd (ao, false, false, 0u)
115 line1.PackEnd (hs, false, false, 0u)
116 line1.PackEnd (sbox, false, false, 0u)
117 base.PackStart (line1, false, false, 0u)
118 base.PackStart (line2, false, false, 0u)
121 conf.Toggled.Add(fun o ->
122 match (conf.Active, dev.Config.Auto) with
123 | (x, y) when x <> y -> dev.Config.Auto <- x
125 time.ValueChanged.Add(fun o -> dev.Config.Time <- time.ValueAsInt)
126 pair.Toggled.Add(fun o -> match (pair.Active, dev_bt.Paired) with
127 | (true, false) -> dev_bt.Pair ()
129 ai.Toggled.Add(fun o -> act ai.Active act_ai Feature.AudioIn)
130 ao.Toggled.Add(fun o -> act ao.Active act_ao Feature.AudioOut)
131 hs.Toggled.Add(fun o -> act hs.Active act_hs Feature.Headset)
132 conn.Toggled.Add(fun o -> act conn.Active act_sy Feature.Sync)
133 dev.Notify.Add(fun o -> fresh ())
134 member x.Refresh () = fresh ()