comparison pidgin/gtkwebview.c @ 32527:2af29d62cfde

more cleanup.
author tdrhq@soc.pidgin.im
date Fri, 07 Aug 2009 18:44:27 +0000
parents a2fd5f08ed49
children b89351c7580b
comparison
equal deleted inserted replaced
32526:a2fd5f08ed49 32527:2af29d62cfde
107 107
108 cur = strstr (img, "/>"); 108 cur = strstr (img, "/>");
109 if (!cur) 109 if (!cur)
110 cur = strstr (img, ">"); 110 cur = strstr (img, ">");
111 111
112 if (!cur) { /*oops, invalid html */ 112 if (!cur) { /* invalid html? */
113 g_string_printf (buffer, "%s", html); 113 g_string_printf (buffer, "%s", html);
114 break; 114 break;
115 } 115 }
116 116
117 if (strstr (img, "src=") || !strstr (img, "id=")) { 117 if (strstr (img, "src=") || !strstr (img, "id=")) {
118 g_string_printf (buffer, "%s", html); 118 g_string_printf (buffer, "%s", html);
119 break; 119 break;
120 } 120 }
121 121
122 /* now I _kinda_ know that it has an id=, and does not have a src= */ 122 /*
123 /* todo: take care of src= and id= appearing in strings? */ 123 * if this is valid HTML, then I can be sure that it
124 * has an id= and does not have an src=, since
125 * '=' cannot appear in parameters.
126 */
127
124 id = strstr (img, "id=") + 3; 128 id = strstr (img, "id=") + 3;
125 129
126 /* *id can't be \0, since a ">" appears after this */ 130 /* *id can't be \0, since a ">" appears after this */
127 if (isdigit (*id)) 131 if (isdigit (*id))
128 nid = atoi (id); 132 nid = atoi (id);
132 /* let's dump this, tag and then dump the src information */ 136 /* let's dump this, tag and then dump the src information */
133 g_string_append_len (buffer, img, cur - img); 137 g_string_append_len (buffer, img, cur - img);
134 138
135 g_string_append_printf (buffer, " src='file://%s' ", get_image_filename_from_id (view, nid)); 139 g_string_append_printf (buffer, " src='file://%s' ", get_image_filename_from_id (view, nid));
136 } 140 }
141
137 return g_string_free (buffer, FALSE); 142 return g_string_free (buffer, FALSE);
138 } 143 }
139 144
140 static void 145 static void
141 gtk_webview_finalize (GObject *view) 146 gtk_webview_finalize (GObject *view)
151 G_OBJECT_CLASS (klass)->finalize = gtk_webview_finalize; 156 G_OBJECT_CLASS (klass)->finalize = gtk_webview_finalize;
152 } 157 }
153 158
154 static gboolean 159 static gboolean
155 webview_link_clicked (WebKitWebView *view, 160 webview_link_clicked (WebKitWebView *view,
156 WebKitWebFrame *frame, 161 WebKitWebFrame *frame,
157 WebKitNetworkRequest *request, 162 WebKitNetworkRequest *request,
158 WebKitWebNavigationAction *navigation_action, 163 WebKitWebNavigationAction *navigation_action,
159 WebKitWebPolicyDecision *policy_decision) 164 WebKitWebPolicyDecision *policy_decision)
160 { 165 {
161 const gchar *uri; 166 const gchar *uri;
162 167
163 uri = webkit_network_request_get_uri (request); 168 uri = webkit_network_request_get_uri (request);
207 printf ("%s\n", html_imged); 212 printf ("%s\n", html_imged);
208 webkit_web_view_load_html_string (WEBKIT_WEB_VIEW (view), html_imged, "file:///"); 213 webkit_web_view_load_html_string (WEBKIT_WEB_VIEW (view), html_imged, "file:///");
209 g_free (html_imged); 214 g_free (html_imged);
210 } 215 }
211 216
212 /* taken from sean's webkit plugin */
213 char *gtk_webview_quote_js_string(const char *text) 217 char *gtk_webview_quote_js_string(const char *text)
214 { 218 {
215 GString *str = g_string_new("\""); 219 GString *str = g_string_new("\"");
216 const char *cur = text; 220 const char *cur = text;
217 221
273 } 277 }
274 278
275 GType gtk_webview_get_type () 279 GType gtk_webview_get_type ()
276 { 280 {
277 static GType mview_type = 0; 281 static GType mview_type = 0;
278 if (!mview_type) { 282 if (G_UNLIKELY (mview_type == 0)) {
279 static const GTypeInfo mview_info = { 283 static const GTypeInfo mview_info = {
280 sizeof (GtkWebViewClass), 284 sizeof (GtkWebViewClass),
281 NULL, 285 NULL,
282 NULL, 286 NULL,
283 (GClassInitFunc) gtk_webview_class_init, 287 (GClassInitFunc) gtk_webview_class_init,