From 623b971fad694cddcb4598452755028848940b22 Mon Sep 17 00:00:00 2001 From: Nicholas Little Date: Wed, 6 Aug 2014 20:40:26 +0100 Subject: [PATCH] Dap.Bluetooth: Rename file, add Popover Since the widget is now really just a button, we rename it as such while adding the Popover class. The popover consists of a single constructor; functions for setting position and changing the relative_to GtkWidget are not implemented, nor are signals. --- src/Bluetooth/Banshee.Dap.Bluetooth.fsproj | 3 +- .../Gui/MediaControlButton.fs | 78 +++++++++++++++++++++ .../Gui/MediaControlWidget.fs | 79 ---------------------- src/Bluetooth/Banshee.Dap.Bluetooth/Gui/Popover.fs | 41 +++++++++++ 4 files changed, 121 insertions(+), 80 deletions(-) create mode 100644 src/Bluetooth/Banshee.Dap.Bluetooth/Gui/MediaControlButton.fs delete mode 100644 src/Bluetooth/Banshee.Dap.Bluetooth/Gui/MediaControlWidget.fs create mode 100644 src/Bluetooth/Banshee.Dap.Bluetooth/Gui/Popover.fs diff --git a/src/Bluetooth/Banshee.Dap.Bluetooth.fsproj b/src/Bluetooth/Banshee.Dap.Bluetooth.fsproj index 8297b74..ee38b1b 100644 --- a/src/Bluetooth/Banshee.Dap.Bluetooth.fsproj +++ b/src/Bluetooth/Banshee.Dap.Bluetooth.fsproj @@ -109,9 +109,10 @@ + - + diff --git a/src/Bluetooth/Banshee.Dap.Bluetooth/Gui/MediaControlButton.fs b/src/Bluetooth/Banshee.Dap.Bluetooth/Gui/MediaControlButton.fs new file mode 100644 index 0000000..32f27e3 --- /dev/null +++ b/src/Bluetooth/Banshee.Dap.Bluetooth/Gui/MediaControlButton.fs @@ -0,0 +1,78 @@ +// +// MediaControlButton.fs +// +// Author: +// Nicholas J. Little +// +// Copyright (c) 2014 Nicholas J. Little +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +namespace Banshee.Dap.Bluetooth.Gui + +open Banshee.Dap.Bluetooth.Wrappers +open Gtk +open Gtk.Extensions +open Hyena.Log +open Hyena.ThreadAssist + +type MediaControlButton (img: Image, mc: INotifyMediaControl) as this = + inherit ToggleButton (Image = img) + let menu = new VBox (true, 1) + let pop = new Popover (this) + let item x = new Button (Image = x) + let button_icon x = new Image (IconName = x) |> item + let hboxof xs = + let box = new HBox (true, 1) + xs |> Seq.iter (fun x -> box.PackStart (x, true, true, 0u)) + box + let pack x = menu.PackStart (x, false, false, 0u) + let play = button_icon "media-playback-start" + let pause = button_icon "media-playback-pause" + let stop = button_icon "media-playback-stop" + let next = button_icon "media-skip-forward" + let prev = button_icon "media-skip-backward" + let fwd = button_icon "media-seek-forward" + let rwd = button_icon "media-seek-backward" + let vup = button_icon "audio-volume-high" + let vdn = button_icon "audio-volume-low" + let hidden _ = this.Active <- false + do + hboxof [prev;next] |> pack + hboxof [rwd;fwd] |> pack + hboxof [pause;stop;play] |> pack + hboxof [vup;vdn] |> pack + menu.ShowAll () + pop.Add menu + pop.Hidden.Add hidden + + play.Clicked.Add (fun o -> mc.Play ()) + pause.Clicked.Add (fun o -> mc.Pause ()) + stop.Clicked.Add (fun o -> mc.Stop ()) + next.Clicked.Add (fun o -> mc.Next ()) + prev.Clicked.Add (fun o -> mc.Previous ()) + rwd.Clicked.Add (fun o -> mc.Rewind ()) + fwd.Clicked.Add (fun o -> mc.FastForward ()) + vup.Clicked.Add (fun o -> mc.VolumeUp ()) + vdn.Clicked.Add (fun o -> mc.VolumeDown ()) + override x.OnToggled () = if x.Active then pop.Show () + new (mc) = + let icon = "applications-multimedia" + let size = int IconSize.LargeToolbar + let img = new Image (IconName = icon, IconSize = size) + new MediaControlButton (img, mc) diff --git a/src/Bluetooth/Banshee.Dap.Bluetooth/Gui/MediaControlWidget.fs b/src/Bluetooth/Banshee.Dap.Bluetooth/Gui/MediaControlWidget.fs deleted file mode 100644 index 269ab2e..0000000 --- a/src/Bluetooth/Banshee.Dap.Bluetooth/Gui/MediaControlWidget.fs +++ /dev/null @@ -1,79 +0,0 @@ -// -// MediaControlWidget.fs -// -// Author: -// Nicholas J. Little -// -// Copyright (c) 2014 Nicholas J. Little -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. -namespace Banshee.Dap.Bluetooth.Gui - -open Banshee.Dap.Bluetooth.Wrappers -open Gtk -open Hyena.Log -open Hyena.ThreadAssist - -type MediaControlButton(img: Image, mc: INotifyMediaControl) as this = - inherit ToggleButton(Image = img) - let menu = new Menu() - let button_icon x = - let img = new Image(IconName = x) - let item = new MenuItem (Child = img) - item - let play = button_icon "media-playback-start" - let pause = button_icon "media-playback-pause" - let stop = button_icon "media-playback-stop" - let next = button_icon "media-skip-forward" - let prev = button_icon "media-skip-backward" - let fwd = button_icon "media-seek-forward" - let rwd = button_icon "media-seek-backward" - let vup = button_icon "audio-volume-high" - let vdn = button_icon "audio-volume-low" - let hidden _ = this.Active <- false - do - menu.Append prev - menu.Append rwd - menu.Append stop - menu.Append pause - menu.Append play - menu.Append fwd - menu.Append next - menu.Append vup - menu.Append vdn - menu.ShowAll () - menu.Hidden.Add hidden - - play.Activated.Add (fun o -> mc.Play ()) - pause.Activated.Add (fun o -> mc.Pause ()) - stop.Activated.Add (fun o -> mc.Stop ()) - next.Activated.Add (fun o -> mc.Next ()) - prev.Activated.Add (fun o -> mc.Previous ()) - rwd.Activated.Add (fun o -> mc.Rewind ()) - fwd.Activated.Add (fun o -> mc.FastForward ()) - vup.Activated.Add (fun o -> mc.VolumeUp ()) - vdn.Activated.Add (fun o -> mc.VolumeDown ()) - override x.OnToggled () = - if x.Active then - menu.Popup () - else - menu.Popdown () - new (mc) = - let img = new Image(IconName = "media-playback-start", IconSize = int IconSize.LargeToolbar) - new MediaControlButton (img, mc) diff --git a/src/Bluetooth/Banshee.Dap.Bluetooth/Gui/Popover.fs b/src/Bluetooth/Banshee.Dap.Bluetooth/Gui/Popover.fs new file mode 100644 index 0000000..a77f604 --- /dev/null +++ b/src/Bluetooth/Banshee.Dap.Bluetooth/Gui/Popover.fs @@ -0,0 +1,41 @@ +// +// Popover.fs +// +// Author: +// Nicholas Little +// +// Copyright (c) 2014 Nicholas Little +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +module Gtk.Extensions + +open System +open System.Runtime.InteropServices +open Gtk + +module Global = + [] + let GtkNativeDll = "gtk-3.dll" + +[] +extern IntPtr gtk_popover_new (IntPtr relative) + +type Popover (relative_to: Widget) = + inherit Bin () + do base.Raw <- gtk_popover_new (relative_to.Handle) -- 2.1.4