1 module webkit2.GeolocationManager;
2 
3 private import glib.Str;
4 private import gobject.ObjectG;
5 private import gobject.Signals;
6 private import std.algorithm;
7 private import webkit2.GeolocationPosition;
8 private import webkit2.c.functions;
9 public  import webkit2.c.types;
10 
11 
12 /**
13  * WebKitGeolocationManager provides API to get the geographical position of the user.
14  * Once a #WebKitGeolocationPermissionRequest is allowed, when WebKit needs to know the
15  * user location #WebKitGeolocationManager::start signal is emitted. If the signal is handled
16  * and returns %TRUE, the application is responsible for providing the position every time it's
17  * updated by calling webkit_geolocation_manager_update_position(). The signal #WebKitGeolocationManager::stop
18  * will be emitted when location updates are no longer needed.
19  *
20  * Since: 2.26
21  */
22 public class GeolocationManager : ObjectG
23 {
24 	/** the main Gtk struct */
25 	protected WebKitGeolocationManager* webKitGeolocationManager;
26 
27 	/** Get the main Gtk struct */
28 	public WebKitGeolocationManager* getGeolocationManagerStruct(bool transferOwnership = false)
29 	{
30 		if (transferOwnership)
31 			ownedRef = false;
32 		return webKitGeolocationManager;
33 	}
34 
35 	/** the main Gtk struct as a void* */
36 	protected override void* getStruct()
37 	{
38 		return cast(void*)webKitGeolocationManager;
39 	}
40 
41 	/**
42 	 * Sets our main struct and passes it to the parent class.
43 	 */
44 	public this (WebKitGeolocationManager* webKitGeolocationManager, bool ownedRef = false)
45 	{
46 		this.webKitGeolocationManager = webKitGeolocationManager;
47 		super(cast(GObject*)webKitGeolocationManager, ownedRef);
48 	}
49 
50 
51 	/** */
52 	public static GType getType()
53 	{
54 		return webkit_geolocation_manager_get_type();
55 	}
56 
57 	/**
58 	 * Notify @manager that determining the position failed.
59 	 *
60 	 * Params:
61 	 *     errorMessage = the error message
62 	 *
63 	 * Since: 2.26
64 	 */
65 	public void failed(string errorMessage)
66 	{
67 		webkit_geolocation_manager_failed(webKitGeolocationManager, Str.toStringz(errorMessage));
68 	}
69 
70 	/**
71 	 * Get whether high accuracy is enabled.
72 	 *
73 	 * Since: 2.26
74 	 */
75 	public bool getEnableHighAccuracy()
76 	{
77 		return webkit_geolocation_manager_get_enable_high_accuracy(webKitGeolocationManager) != 0;
78 	}
79 
80 	/**
81 	 * Notify @manager that position has been updated to @position.
82 	 *
83 	 * Params:
84 	 *     position = a #WebKitGeolocationPosition
85 	 *
86 	 * Since: 2.26
87 	 */
88 	public void updatePosition(GeolocationPosition position)
89 	{
90 		webkit_geolocation_manager_update_position(webKitGeolocationManager, (position is null) ? null : position.getGeolocationPositionStruct());
91 	}
92 
93 	/**
94 	 * The signal is emitted to notify that @manager needs to start receiving
95 	 * position updates. After this signal is emitted the user should provide
96 	 * the updates using webkit_geolocation_manager_update_position() every time
97 	 * the position changes, or use webkit_geolocation_manager_failed() in case
98 	 * it isn't possible to determine the current position.
99 	 *
100 	 * If the signal is not handled, WebKit will try to determine the position
101 	 * using GeoClue if available.
102 	 *
103 	 * Returns: %TRUE to stop other handlers from being invoked for the event.
104 	 *     %FALSE to propagate the event further.
105 	 *
106 	 * Since: 2.26
107 	 */
108 	gulong addOnStart(bool delegate(GeolocationManager) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
109 	{
110 		return Signals.connect(this, "start", dlg, connectFlags ^ ConnectFlags.SWAPPED);
111 	}
112 
113 	/**
114 	 * The signal is emitted to notify that @manager doesn't need to receive
115 	 * position updates anymore.
116 	 *
117 	 * Since: 2.26
118 	 */
119 	gulong addOnStop(void delegate(GeolocationManager) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
120 	{
121 		return Signals.connect(this, "stop", dlg, connectFlags ^ ConnectFlags.SWAPPED);
122 	}
123 }