~ubuntu-branches/ubuntu/oneiric/midori/oneiric-updates

« back to all changes in this revision

Viewing changes to midori/midori-viewable.c

  • Committer: Bazaar Package Importer
  • Author(s): Artur Rona
  • Date: 2011-02-01 20:27:20 UTC
  • mfrom: (1.1.14 upstream) (3.3.3 sid)
  • Revision ID: james.westby@ubuntu.com-20110201202720-xobt459otz1m6sas
Tags: 0.3.0-1.1ubuntu1
* Merge from debian unstable.  Remaining changes:
  - debian/control, debian/rules:
    + Change build-depends from libwebkit-dev to libwebkitgtk-dev.
* debian/patches/desktop-scheme-handler-types:
  - Dropped, fixed upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
97
97
        G_TYPE_NONE, 1,
98
98
        GTK_TYPE_MENU);
99
99
 
100
 
    iface->p = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
101
 
 
102
100
    iface->get_stock_id = midori_viewable_default_get_stock_id;
103
101
    iface->get_label = midori_viewable_default_get_label;
104
102
    iface->get_toolbar = midori_viewable_default_get_toolbar;
109
107
static void
110
108
midori_viewable_base_finalize (MidoriViewableIface* iface)
111
109
{
112
 
    g_hash_table_destroy (iface->p);
113
 
}
114
 
 
115
 
/**
116
 
 * midori_viewable_new_from_uri:
117
 
 * @uri: an URI
118
 
 *
119
 
 * Attempts to create a new #MidoriViewable from the specified URI.
120
 
 *
121
 
 * The protocol of @uri must previously have been registered by
122
 
 * the #MidoriViewable via midori_viewable_register_protocol().
123
 
 *
124
 
 * Return value: a new #MidoriViewable, or %NULL
125
 
 *
126
 
 * Deprecated: 0.2.6
127
 
 **/
128
 
GtkWidget*
129
 
midori_viewable_new_from_uri (const gchar* uri)
130
 
{
131
 
    MidoriViewableIface* iface;
132
 
    gchar** parts;
133
 
    gchar* type_name;
134
 
    GType type;
135
 
 
136
 
    if (!(iface = g_type_default_interface_peek (MIDORI_TYPE_VIEWABLE)))
137
 
    {
138
 
        g_warning ("No viewable interface available");
139
 
        return NULL;
140
 
    }
141
 
 
142
 
    g_return_val_if_fail (uri != NULL, NULL);
143
 
 
144
 
    if (!g_hash_table_size (iface->p))
145
 
        return NULL;
146
 
 
147
 
    if ((parts = g_strsplit (uri, "://", 2)))
148
 
    {
149
 
        if (!(type_name = g_hash_table_lookup (iface->p, parts[0])))
150
 
        {
151
 
            /* FIXME: Support midori://dummy/foo */
152
 
 
153
 
            type_name = g_hash_table_lookup (iface->p, uri);
154
 
        }
155
 
        g_strfreev (parts);
156
 
        if (type_name)
157
 
        {
158
 
            type = g_type_from_name (type_name);
159
 
            g_free (type_name);
160
 
            if (type)
161
 
                return g_object_new (type, "uri", uri, NULL);
162
 
        }
163
 
    }
164
 
    else if ((parts = g_strsplit_set (uri, ":", 2)))
165
 
    {
166
 
        type_name = g_hash_table_lookup (iface->p, parts[0]);
167
 
        g_strfreev (parts);
168
 
        if (type_name)
169
 
        {
170
 
            type = g_type_from_name (type_name);
171
 
            g_free (type_name);
172
 
            if (type)
173
 
                return g_object_new (type, "uri", uri, NULL);
174
 
        }
175
 
    }
176
 
    return NULL;
177
 
}
178
 
 
179
 
static gboolean
180
 
viewable_type_implements (GType type,
181
 
                          GType interface)
182
 
{
183
 
    GType *interfaces;
184
 
    guint i;
185
 
 
186
 
    if (!(interfaces = g_type_interfaces (type, NULL)))
187
 
        return FALSE;
188
 
    for (i = 0; interfaces[i]; i++)
189
 
    {
190
 
        if (interfaces[i] == interface)
191
 
        {
192
 
            g_free (interfaces);
193
 
            return TRUE;
194
 
        }
195
 
    }
196
 
    g_free (interfaces);
197
 
    return FALSE;
198
 
}
199
 
 
200
 
/**
201
 
 * midori_viewable_register_protocol:
202
 
 * @type: a type that implements #MidoriViewable
203
 
 * @protocol: a protocol
204
 
 *
205
 
 * Registers the specified protocol as supported by @type.
206
 
 *
207
 
 * The following kinds of protocols are supported:
208
 
 *
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"
213
 
 *
214
 
 * Return value: a new #MidoriViewable, or %NULL
215
 
 *
216
 
 * Deprecated: 0.2.6
217
 
 **/
218
 
void
219
 
midori_viewable_register_protocol (GType        type,
220
 
                                   const gchar* protocol)
221
 
{
222
 
    MidoriViewableIface* iface;
223
 
    GObjectClass* class;
224
 
 
225
 
    if (!(iface = g_type_default_interface_peek (MIDORI_TYPE_VIEWABLE)))
226
 
    {
227
 
        g_warning ("No viewable interface available");
228
 
        return;
229
 
    }
230
 
 
231
 
    g_return_if_fail (viewable_type_implements (type, MIDORI_TYPE_VIEWABLE));
232
 
 
233
 
    if (!(class = g_type_class_peek (type)))
234
 
    {
235
 
        g_warning ("No class for %s available", g_type_name (type));
236
 
        return;
237
 
    }
238
 
    g_return_if_fail (g_object_class_find_property (class, "uri"));
239
 
    /* FIXME: Verify the syntax of protocol */
240
 
 
241
 
    g_hash_table_insert (iface->p, g_strdup (protocol),
242
 
                         g_strdup (g_type_name (type)));
243
110
}
244
111
 
245
112
/**