1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 
25 module gstreamer.URIHandlerT;
26 
27 public  import glib.ErrorG;
28 public  import glib.GException;
29 public  import glib.Str;
30 public  import gstreamerc.gstreamer;
31 public  import gstreamerc.gstreamertypes;
32 
33 
34 /**
35  * The URIHandler is an interface that is implemented by Source and Sink
36  * #GstElement to simplify then handling of URI.
37  * 
38  * An application can use the following functions to quickly get an element
39  * that handles the given URI for reading or writing
40  * (gst_element_make_from_uri()).
41  * 
42  * Source and Sink plugins should implement this interface when possible.
43  */
44 public template URIHandlerT(TStruct)
45 {
46 	/** Get the main Gtk struct */
47 	public GstURIHandler* getURIHandlerStruct()
48 	{
49 		return cast(GstURIHandler*)getStruct();
50 	}
51 
52 	/**
53 	 */
54 
55 	/**
56 	 * Gets the list of protocols supported by @handler. This list may not be
57 	 * modified.
58 	 *
59 	 * Return: the
60 	 *     supported protocols.  Returns %NULL if the @handler isn't
61 	 *     implemented properly, or the @handler doesn't support any
62 	 *     protocols.
63 	 */
64 	public string[] getProtocols()
65 	{
66 		return Str.toStringArray(gst_uri_handler_get_protocols(getURIHandlerStruct()));
67 	}
68 
69 	/**
70 	 * Gets the currently handled URI.
71 	 *
72 	 * Return: the URI currently handled by
73 	 *     the @handler.  Returns %NULL if there are no URI currently
74 	 *     handled. The returned string must be freed with g_free() when no
75 	 *     longer needed.
76 	 */
77 	public string getUri()
78 	{
79 		return Str.toString(gst_uri_handler_get_uri(getURIHandlerStruct()));
80 	}
81 
82 	/**
83 	 * Gets the type of the given URI handler
84 	 *
85 	 * Return: the #GstURIType of the URI handler.
86 	 *     Returns #GST_URI_UNKNOWN if the @handler isn't implemented correctly.
87 	 */
88 	public GstURIType getUriType()
89 	{
90 		return gst_uri_handler_get_uri_type(getURIHandlerStruct());
91 	}
92 
93 	/**
94 	 * Tries to set the URI of the given handler.
95 	 *
96 	 * Params:
97 	 *     uri = URI to set
98 	 *
99 	 * Return: %TRUE if the URI was set successfully, else %FALSE.
100 	 *
101 	 * Throws: GException on failure.
102 	 */
103 	public bool setUri(string uri)
104 	{
105 		GError* err = null;
106 		
107 		auto p = gst_uri_handler_set_uri(getURIHandlerStruct(), Str.toStringz(uri), &err) != 0;
108 		
109 		if (err !is null)
110 		{
111 			throw new GException( new ErrorG(err) );
112 		}
113 		
114 		return p;
115 	}
116 
117 	/**
118 	 * Similar to g_filename_to_uri(), but attempts to handle relative file paths
119 	 * as well. Before converting @filename into an URI, it will be prefixed by
120 	 * the current working directory if it is a relative path, and then the path
121 	 * will be canonicalised so that it doesn't contain any './' or '../' segments.
122 	 *
123 	 * On Windows #filename should be in UTF-8 encoding.
124 	 *
125 	 * Params:
126 	 *     filename = absolute or relative file name path
127 	 *
128 	 * Throws: GException on failure.
129 	 */
130 	public static string filenameToUri(string filename)
131 	{
132 		GError* err = null;
133 		
134 		auto p = gst_filename_to_uri(Str.toStringz(filename), &err);
135 		
136 		if (err !is null)
137 		{
138 			throw new GException( new ErrorG(err) );
139 		}
140 		
141 		return Str.toString(p);
142 	}
143 
144 	/**
145 	 * Constructs a URI for a given valid protocol and location.
146 	 *
147 	 * Free-function: g_free
148 	 *
149 	 * Params:
150 	 *     protocol = Protocol for URI
151 	 *     location = Location for URI
152 	 *
153 	 * Return: a new string for this URI. Returns %NULL if the
154 	 *     given URI protocol is not valid, or the given location is %NULL.
155 	 */
156 	public static string uriConstruct(string protocol, string location)
157 	{
158 		return Str.toString(gst_uri_construct(Str.toStringz(protocol), Str.toStringz(location)));
159 	}
160 
161 	public static GQuark uriErrorQuark()
162 	{
163 		return gst_uri_error_quark();
164 	}
165 
166 	/**
167 	 * Extracts the location out of a given valid URI, ie. the protocol and "://"
168 	 * are stripped from the URI, which means that the location returned includes
169 	 * the hostname if one is specified. The returned string must be freed using
170 	 * g_free().
171 	 *
172 	 * Free-function: g_free
173 	 *
174 	 * Params:
175 	 *     uri = A URI string
176 	 *
177 	 * Return: the location for this URI. Returns %NULL if the
178 	 *     URI isn't valid. If the URI does not contain a location, an empty
179 	 *     string is returned.
180 	 */
181 	public static string uriGetLocation(string uri)
182 	{
183 		return Str.toString(gst_uri_get_location(Str.toStringz(uri)));
184 	}
185 
186 	/**
187 	 * Extracts the protocol out of a given valid URI. The returned string must be
188 	 * freed using g_free().
189 	 *
190 	 * Params:
191 	 *     uri = A URI string
192 	 *
193 	 * Return: The protocol for this URI.
194 	 */
195 	public static string uriGetProtocol(string uri)
196 	{
197 		return Str.toString(gst_uri_get_protocol(Str.toStringz(uri)));
198 	}
199 
200 	/**
201 	 * Checks if the protocol of a given valid URI matches @protocol.
202 	 *
203 	 * Params:
204 	 *     uri = a URI string
205 	 *     protocol = a protocol string (e.g. "http")
206 	 *
207 	 * Return: %TRUE if the protocol matches.
208 	 */
209 	public static bool uriHasProtocol(string uri, string protocol)
210 	{
211 		return gst_uri_has_protocol(Str.toStringz(uri), Str.toStringz(protocol)) != 0;
212 	}
213 
214 	/**
215 	 * Tests if the given string is a valid URI identifier. URIs start with a valid
216 	 * scheme followed by ":" and maybe a string identifying the location.
217 	 *
218 	 * Params:
219 	 *     uri = A URI string
220 	 *
221 	 * Return: %TRUE if the string is a valid URI
222 	 */
223 	public static bool uriIsValid(string uri)
224 	{
225 		return gst_uri_is_valid(Str.toStringz(uri)) != 0;
226 	}
227 
228 	/**
229 	 * Checks if an element exists that supports the given URI protocol. Note
230 	 * that a positive return value does not imply that a subsequent call to
231 	 * gst_element_make_from_uri() is guaranteed to work.
232 	 *
233 	 * Params:
234 	 *     type = Whether to check for a source or a sink
235 	 *     protocol = Protocol that should be checked for (e.g. "http" or "smb")
236 	 *
237 	 * Return: %TRUE
238 	 */
239 	public static bool uriProtocolIsSupported(GstURIType type, string protocol)
240 	{
241 		return gst_uri_protocol_is_supported(type, Str.toStringz(protocol)) != 0;
242 	}
243 
244 	/**
245 	 * Tests if the given string is a valid protocol identifier. Protocols
246 	 * must consist of alphanumeric characters, '+', '-' and '.' and must
247 	 * start with a alphabetic character. See RFC 3986 Section 3.1.
248 	 *
249 	 * Params:
250 	 *     protocol = A string
251 	 *
252 	 * Return: %TRUE if the string is a valid protocol identifier, %FALSE otherwise.
253 	 */
254 	public static bool uriProtocolIsValid(string protocol)
255 	{
256 		return gst_uri_protocol_is_valid(Str.toStringz(protocol)) != 0;
257 	}
258 }