110
108
midori_viewable_base_finalize (MidoriViewableIface* iface)
112
g_hash_table_destroy (iface->p);
116
* midori_viewable_new_from_uri:
119
* Attempts to create a new #MidoriViewable from the specified URI.
121
* The protocol of @uri must previously have been registered by
122
* the #MidoriViewable via midori_viewable_register_protocol().
124
* Return value: a new #MidoriViewable, or %NULL
129
midori_viewable_new_from_uri (const gchar* uri)
131
MidoriViewableIface* iface;
136
if (!(iface = g_type_default_interface_peek (MIDORI_TYPE_VIEWABLE)))
138
g_warning ("No viewable interface available");
142
g_return_val_if_fail (uri != NULL, NULL);
144
if (!g_hash_table_size (iface->p))
147
if ((parts = g_strsplit (uri, "://", 2)))
149
if (!(type_name = g_hash_table_lookup (iface->p, parts[0])))
151
/* FIXME: Support midori://dummy/foo */
153
type_name = g_hash_table_lookup (iface->p, uri);
158
type = g_type_from_name (type_name);
161
return g_object_new (type, "uri", uri, NULL);
164
else if ((parts = g_strsplit_set (uri, ":", 2)))
166
type_name = g_hash_table_lookup (iface->p, parts[0]);
170
type = g_type_from_name (type_name);
173
return g_object_new (type, "uri", uri, NULL);
180
viewable_type_implements (GType type,
186
if (!(interfaces = g_type_interfaces (type, NULL)))
188
for (i = 0; interfaces[i]; i++)
190
if (interfaces[i] == interface)
201
* midori_viewable_register_protocol:
202
* @type: a type that implements #MidoriViewable
203
* @protocol: a protocol
205
* Registers the specified protocol as supported by @type.
207
* The following kinds of protocols are supported:
209
* "dummy": support URIs like "dummy://foo/bar"
210
* "about:dummy": support URIs like "about:dummy"
211
* FIXME: The following is not yet fully supported
212
* "midori://dummy": support URIs like "midori://dummy/foo"
214
* Return value: a new #MidoriViewable, or %NULL
219
midori_viewable_register_protocol (GType type,
220
const gchar* protocol)
222
MidoriViewableIface* iface;
225
if (!(iface = g_type_default_interface_peek (MIDORI_TYPE_VIEWABLE)))
227
g_warning ("No viewable interface available");
231
g_return_if_fail (viewable_type_implements (type, MIDORI_TYPE_VIEWABLE));
233
if (!(class = g_type_class_peek (type)))
235
g_warning ("No class for %s available", g_type_name (type));
238
g_return_if_fail (g_object_class_find_property (class, "uri"));
239
/* FIXME: Verify the syntax of protocol */
241
g_hash_table_insert (iface->p, g_strdup (protocol),
242
g_strdup (g_type_name (type)));