| 101 * Prototypes |
101 * Prototypes |
| 102 *****************************************************************************/ |
102 *****************************************************************************/ |
| 103 |
103 |
| 104 static void |
104 static void |
| 105 toggle_action_set_active_block(GtkToggleAction *action, gboolean is_active, |
105 toggle_action_set_active_block(GtkToggleAction *action, gboolean is_active, |
| 106 GtkWebViewToolbar *toolbar); |
106 PidginWebViewToolbar *toolbar); |
| 107 |
107 |
| 108 /****************************************************************************** |
108 /****************************************************************************** |
| 109 * Helpers |
109 * Helpers |
| 110 *****************************************************************************/ |
110 *****************************************************************************/ |
| 111 |
111 |
| 112 static void |
112 static void |
| 113 do_bold(GtkAction *bold, GtkWebViewToolbar *toolbar) |
113 do_bold(GtkAction *bold, PidginWebViewToolbar *toolbar) |
| 114 { |
114 { |
| 115 g_return_if_fail(toolbar != NULL); |
115 g_return_if_fail(toolbar != NULL); |
| 116 gtk_webview_toggle_bold(GTK_WEBVIEW(toolbar->webview)); |
116 pidgin_webview_toggle_bold(PIDGIN_WEBVIEW(toolbar->webview)); |
| 117 gtk_widget_grab_focus(toolbar->webview); |
117 gtk_widget_grab_focus(toolbar->webview); |
| 118 } |
118 } |
| 119 |
119 |
| 120 static void |
120 static void |
| 121 do_italic(GtkAction *italic, GtkWebViewToolbar *toolbar) |
121 do_italic(GtkAction *italic, PidginWebViewToolbar *toolbar) |
| 122 { |
122 { |
| 123 g_return_if_fail(toolbar != NULL); |
123 g_return_if_fail(toolbar != NULL); |
| 124 gtk_webview_toggle_italic(GTK_WEBVIEW(toolbar->webview)); |
124 pidgin_webview_toggle_italic(PIDGIN_WEBVIEW(toolbar->webview)); |
| 125 gtk_widget_grab_focus(toolbar->webview); |
125 gtk_widget_grab_focus(toolbar->webview); |
| 126 } |
126 } |
| 127 |
127 |
| 128 static void |
128 static void |
| 129 do_underline(GtkAction *underline, GtkWebViewToolbar *toolbar) |
129 do_underline(GtkAction *underline, PidginWebViewToolbar *toolbar) |
| 130 { |
130 { |
| 131 g_return_if_fail(toolbar != NULL); |
131 g_return_if_fail(toolbar != NULL); |
| 132 gtk_webview_toggle_underline(GTK_WEBVIEW(toolbar->webview)); |
132 pidgin_webview_toggle_underline(PIDGIN_WEBVIEW(toolbar->webview)); |
| 133 gtk_widget_grab_focus(toolbar->webview); |
133 gtk_widget_grab_focus(toolbar->webview); |
| 134 } |
134 } |
| 135 |
135 |
| 136 static void |
136 static void |
| 137 do_strikethrough(GtkAction *strikethrough, GtkWebViewToolbar *toolbar) |
137 do_strikethrough(GtkAction *strikethrough, PidginWebViewToolbar *toolbar) |
| 138 { |
138 { |
| 139 g_return_if_fail(toolbar != NULL); |
139 g_return_if_fail(toolbar != NULL); |
| 140 gtk_webview_toggle_strike(GTK_WEBVIEW(toolbar->webview)); |
140 pidgin_webview_toggle_strike(PIDGIN_WEBVIEW(toolbar->webview)); |
| 141 gtk_widget_grab_focus(toolbar->webview); |
141 gtk_widget_grab_focus(toolbar->webview); |
| 142 } |
142 } |
| 143 |
143 |
| 144 static void |
144 static void |
| 145 do_small(GtkAction *small, GtkWebViewToolbar *toolbar) |
145 do_small(GtkAction *small, PidginWebViewToolbar *toolbar) |
| 146 { |
146 { |
| 147 g_return_if_fail(toolbar != NULL); |
147 g_return_if_fail(toolbar != NULL); |
| 148 gtk_webview_font_shrink(GTK_WEBVIEW(toolbar->webview)); |
148 pidgin_webview_font_shrink(PIDGIN_WEBVIEW(toolbar->webview)); |
| 149 gtk_widget_grab_focus(toolbar->webview); |
149 gtk_widget_grab_focus(toolbar->webview); |
| 150 } |
150 } |
| 151 |
151 |
| 152 static void |
152 static void |
| 153 do_big(GtkAction *large, GtkWebViewToolbar *toolbar) |
153 do_big(GtkAction *large, PidginWebViewToolbar *toolbar) |
| 154 { |
154 { |
| 155 g_return_if_fail(toolbar); |
155 g_return_if_fail(toolbar); |
| 156 gtk_webview_font_grow(GTK_WEBVIEW(toolbar->webview)); |
156 pidgin_webview_font_grow(PIDGIN_WEBVIEW(toolbar->webview)); |
| 157 gtk_widget_grab_focus(toolbar->webview); |
157 gtk_widget_grab_focus(toolbar->webview); |
| 158 } |
158 } |
| 159 |
159 |
| 160 static void |
160 static void |
| 161 destroy_toolbar_font(GtkWebViewToolbar *toolbar) |
161 destroy_toolbar_font(PidginWebViewToolbar *toolbar) |
| 162 { |
162 { |
| 163 GtkWebViewToolbarPriv *priv = GTK_WEBVIEWTOOLBAR_GET_PRIVATE(toolbar); |
163 PidginWebViewToolbarPriv *priv = PIDGIN_WEBVIEWTOOLBAR_GET_PRIVATE(toolbar); |
| 164 |
164 |
| 165 if (priv->font_dialog != NULL) |
165 if (priv->font_dialog != NULL) |
| 166 { |
166 { |
| 167 gtk_widget_destroy(priv->font_dialog); |
167 gtk_widget_destroy(priv->font_dialog); |
| 168 priv->font_dialog = NULL; |
168 priv->font_dialog = NULL; |
| 169 } |
169 } |
| 170 } |
170 } |
| 171 |
171 |
| 172 static void |
172 static void |
| 173 realize_toolbar_font(GtkWidget *widget, GtkWebViewToolbar *toolbar) |
173 realize_toolbar_font(GtkWidget *widget, PidginWebViewToolbar *toolbar) |
| 174 { |
174 { |
| 175 #if !GTK_CHECK_VERSION(3,2,0) |
175 #if !GTK_CHECK_VERSION(3,2,0) |
| 176 GtkWebViewToolbarPriv *priv = GTK_WEBVIEWTOOLBAR_GET_PRIVATE(toolbar); |
176 PidginWebViewToolbarPriv *priv = PIDGIN_WEBVIEWTOOLBAR_GET_PRIVATE(toolbar); |
| 177 GtkFontSelection *sel; |
177 GtkFontSelection *sel; |
| 178 |
178 |
| 179 sel = GTK_FONT_SELECTION( |
179 sel = GTK_FONT_SELECTION( |
| 180 gtk_font_selection_dialog_get_font_selection(GTK_FONT_SELECTION_DIALOG(priv->font_dialog))); |
180 gtk_font_selection_dialog_get_font_selection(GTK_FONT_SELECTION_DIALOG(priv->font_dialog))); |
| 181 gtk_widget_hide(gtk_widget_get_parent( |
181 gtk_widget_hide(gtk_widget_get_parent( |
| 204 |
204 |
| 205 desc = pango_font_description_from_string(fontname); |
205 desc = pango_font_description_from_string(fontname); |
| 206 family_name = pango_font_description_get_family(desc); |
206 family_name = pango_font_description_get_family(desc); |
| 207 |
207 |
| 208 if (family_name) { |
208 if (family_name) { |
| 209 gtk_webview_toggle_fontface(GTK_WEBVIEW(toolbar->webview), |
209 pidgin_webview_toggle_fontface(PIDGIN_WEBVIEW(toolbar->webview), |
| 210 family_name); |
210 family_name); |
| 211 } |
211 } |
| 212 |
212 |
| 213 pango_font_description_free(desc); |
213 pango_font_description_free(desc); |
| 214 g_free(fontname); |
214 g_free(fontname); |
| 215 } else { |
215 } else { |
| 216 gtk_webview_toggle_fontface(GTK_WEBVIEW(toolbar->webview), ""); |
216 pidgin_webview_toggle_fontface(PIDGIN_WEBVIEW(toolbar->webview), ""); |
| 217 } |
217 } |
| 218 |
218 |
| 219 destroy_toolbar_font(toolbar); |
219 destroy_toolbar_font(toolbar); |
| 220 } |
220 } |
| 221 |
221 |
| 222 static void |
222 static void |
| 223 toggle_font(GtkAction *font, GtkWebViewToolbar *toolbar) |
223 toggle_font(GtkAction *font, PidginWebViewToolbar *toolbar) |
| 224 { |
224 { |
| 225 GtkWebViewToolbarPriv *priv = GTK_WEBVIEWTOOLBAR_GET_PRIVATE(toolbar); |
225 PidginWebViewToolbarPriv *priv = PIDGIN_WEBVIEWTOOLBAR_GET_PRIVATE(toolbar); |
| 226 |
226 |
| 227 if (gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(font))) { |
227 if (gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(font))) { |
| 228 char *fontname = gtk_webview_get_current_fontface(GTK_WEBVIEW(toolbar->webview)); |
228 char *fontname = pidgin_webview_get_current_fontface(PIDGIN_WEBVIEW(toolbar->webview)); |
| 229 |
229 |
| 230 if (!priv->font_dialog) { |
230 if (!priv->font_dialog) { |
| 231 GtkWindow *window; |
231 GtkWindow *window; |
| 232 window = GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(toolbar))); |
232 window = GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(toolbar))); |
| 233 priv->font_dialog = gtk_font_chooser_dialog_new(_("Select Font"), window); |
233 priv->font_dialog = gtk_font_chooser_dialog_new(_("Select Font"), window); |
| 298 gtk_color_selection_get_current_color(colorsel, &text_color); |
298 gtk_color_selection_get_current_color(colorsel, &text_color); |
| 299 g_snprintf(open_tag, 23, "#%02X%02X%02X", |
299 g_snprintf(open_tag, 23, "#%02X%02X%02X", |
| 300 text_color.red / 256, |
300 text_color.red / 256, |
| 301 text_color.green / 256, |
301 text_color.green / 256, |
| 302 text_color.blue / 256); |
302 text_color.blue / 256); |
| 303 gtk_webview_toggle_forecolor(GTK_WEBVIEW(toolbar->webview), open_tag); |
303 pidgin_webview_toggle_forecolor(PIDGIN_WEBVIEW(toolbar->webview), open_tag); |
| 304 g_free(open_tag); |
304 g_free(open_tag); |
| 305 |
305 |
| 306 cancel_toolbar_fgcolor(NULL, toolbar); |
306 cancel_toolbar_fgcolor(NULL, toolbar); |
| 307 } |
307 } |
| 308 |
308 |
| 309 static void |
309 static void |
| 310 toggle_fg_color(GtkAction *color, GtkWebViewToolbar *toolbar) |
310 toggle_fg_color(GtkAction *color, PidginWebViewToolbar *toolbar) |
| 311 { |
311 { |
| 312 GtkWebViewToolbarPriv *priv = GTK_WEBVIEWTOOLBAR_GET_PRIVATE(toolbar); |
312 PidginWebViewToolbarPriv *priv = PIDGIN_WEBVIEWTOOLBAR_GET_PRIVATE(toolbar); |
| 313 |
313 |
| 314 if (gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(color))) { |
314 if (gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(color))) { |
| 315 GtkWidget *colorsel; |
315 GtkWidget *colorsel; |
| 316 GdkColor fgcolor; |
316 GdkColor fgcolor; |
| 317 char *color = gtk_webview_get_current_forecolor(GTK_WEBVIEW(toolbar->webview)); |
317 char *color = pidgin_webview_get_current_forecolor(PIDGIN_WEBVIEW(toolbar->webview)); |
| 318 |
318 |
| 319 if (!priv->fgcolor_dialog) { |
319 if (!priv->fgcolor_dialog) { |
| 320 GtkWidget *ok_button; |
320 GtkWidget *ok_button; |
| 321 GtkWidget *cancel_button; |
321 GtkWidget *cancel_button; |
| 322 |
322 |
| 388 gtk_color_selection_get_current_color(colorsel, &text_color); |
388 gtk_color_selection_get_current_color(colorsel, &text_color); |
| 389 g_snprintf(open_tag, 23, "#%02X%02X%02X", |
389 g_snprintf(open_tag, 23, "#%02X%02X%02X", |
| 390 text_color.red / 256, |
390 text_color.red / 256, |
| 391 text_color.green / 256, |
391 text_color.green / 256, |
| 392 text_color.blue / 256); |
392 text_color.blue / 256); |
| 393 gtk_webview_toggle_backcolor(GTK_WEBVIEW(toolbar->webview), open_tag); |
393 pidgin_webview_toggle_backcolor(PIDGIN_WEBVIEW(toolbar->webview), open_tag); |
| 394 g_free(open_tag); |
394 g_free(open_tag); |
| 395 |
395 |
| 396 cancel_toolbar_bgcolor(NULL, toolbar); |
396 cancel_toolbar_bgcolor(NULL, toolbar); |
| 397 } |
397 } |
| 398 |
398 |
| 399 static void |
399 static void |
| 400 toggle_bg_color(GtkAction *color, GtkWebViewToolbar *toolbar) |
400 toggle_bg_color(GtkAction *color, PidginWebViewToolbar *toolbar) |
| 401 { |
401 { |
| 402 GtkWebViewToolbarPriv *priv = GTK_WEBVIEWTOOLBAR_GET_PRIVATE(toolbar); |
402 PidginWebViewToolbarPriv *priv = PIDGIN_WEBVIEWTOOLBAR_GET_PRIVATE(toolbar); |
| 403 |
403 |
| 404 if (gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(color))) { |
404 if (gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(color))) { |
| 405 GtkWidget *colorsel; |
405 GtkWidget *colorsel; |
| 406 GdkColor bgcolor; |
406 GdkColor bgcolor; |
| 407 char *color = gtk_webview_get_current_backcolor(GTK_WEBVIEW(toolbar->webview)); |
407 char *color = pidgin_webview_get_current_backcolor(PIDGIN_WEBVIEW(toolbar->webview)); |
| 408 |
408 |
| 409 if (!priv->bgcolor_dialog) { |
409 if (!priv->bgcolor_dialog) { |
| 410 GtkWidget *ok_button; |
410 GtkWidget *ok_button; |
| 411 GtkWidget *cancel_button; |
411 GtkWidget *cancel_button; |
| 412 |
412 |
| 439 |
439 |
| 440 gtk_widget_grab_focus(toolbar->webview); |
440 gtk_widget_grab_focus(toolbar->webview); |
| 441 } |
441 } |
| 442 |
442 |
| 443 static void |
443 static void |
| 444 clear_formatting_cb(GtkAction *clear, GtkWebViewToolbar *toolbar) |
444 clear_formatting_cb(GtkAction *clear, PidginWebViewToolbar *toolbar) |
| 445 { |
445 { |
| 446 gtk_webview_clear_formatting(GTK_WEBVIEW(toolbar->webview)); |
446 pidgin_webview_clear_formatting(PIDGIN_WEBVIEW(toolbar->webview)); |
| 447 gtk_widget_grab_focus(toolbar->webview); |
447 gtk_widget_grab_focus(toolbar->webview); |
| 448 } |
448 } |
| 449 |
449 |
| 450 static void |
450 static void |
| 451 cancel_link_cb(GtkWebViewToolbar *toolbar, PurpleRequestFields *fields) |
451 cancel_link_cb(PidginWebViewToolbar *toolbar, PurpleRequestFields *fields) |
| 452 { |
452 { |
| 453 GtkWebViewToolbarPriv *priv = GTK_WEBVIEWTOOLBAR_GET_PRIVATE(toolbar); |
453 PidginWebViewToolbarPriv *priv = PIDGIN_WEBVIEWTOOLBAR_GET_PRIVATE(toolbar); |
| 454 gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(priv->link), FALSE); |
454 gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(priv->link), FALSE); |
| 455 |
455 |
| 456 priv->link_dialog = NULL; |
456 priv->link_dialog = NULL; |
| 457 } |
457 } |
| 458 |
458 |
| 459 static void |
459 static void |
| 460 close_link_dialog(GtkWebViewToolbar *toolbar) |
460 close_link_dialog(PidginWebViewToolbar *toolbar) |
| 461 { |
461 { |
| 462 GtkWebViewToolbarPriv *priv = GTK_WEBVIEWTOOLBAR_GET_PRIVATE(toolbar); |
462 PidginWebViewToolbarPriv *priv = PIDGIN_WEBVIEWTOOLBAR_GET_PRIVATE(toolbar); |
| 463 if (priv->link_dialog != NULL) |
463 if (priv->link_dialog != NULL) |
| 464 { |
464 { |
| 465 purple_request_close(PURPLE_REQUEST_FIELDS, priv->link_dialog); |
465 purple_request_close(PURPLE_REQUEST_FIELDS, priv->link_dialog); |
| 466 priv->link_dialog = NULL; |
466 priv->link_dialog = NULL; |
| 467 } |
467 } |
| 468 } |
468 } |
| 469 |
469 |
| 470 static void |
470 static void |
| 471 do_insert_link_cb(GtkWebViewToolbar *toolbar, PurpleRequestFields *fields) |
471 do_insert_link_cb(PidginWebViewToolbar *toolbar, PurpleRequestFields *fields) |
| 472 { |
472 { |
| 473 GtkWebViewToolbarPriv *priv = GTK_WEBVIEWTOOLBAR_GET_PRIVATE(toolbar); |
473 PidginWebViewToolbarPriv *priv = PIDGIN_WEBVIEWTOOLBAR_GET_PRIVATE(toolbar); |
| 474 const char *url, *description; |
474 const char *url, *description; |
| 475 |
475 |
| 476 url = purple_request_fields_get_string(fields, "url"); |
476 url = purple_request_fields_get_string(fields, "url"); |
| 477 if (gtk_webview_get_format_functions(GTK_WEBVIEW(toolbar->webview)) & GTK_WEBVIEW_LINKDESC) |
477 if (pidgin_webview_get_format_functions(PIDGIN_WEBVIEW(toolbar->webview)) & PIDGIN_WEBVIEW_LINKDESC) |
| 478 description = purple_request_fields_get_string(fields, "description"); |
478 description = purple_request_fields_get_string(fields, "description"); |
| 479 else |
479 else |
| 480 description = NULL; |
480 description = NULL; |
| 481 |
481 |
| 482 gtk_webview_insert_link(GTK_WEBVIEW(toolbar->webview), url, description); |
482 pidgin_webview_insert_link(PIDGIN_WEBVIEW(toolbar->webview), url, description); |
| 483 |
483 |
| 484 gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(priv->link), FALSE); |
484 gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(priv->link), FALSE); |
| 485 |
485 |
| 486 priv->link_dialog = NULL; |
486 priv->link_dialog = NULL; |
| 487 } |
487 } |
| 488 |
488 |
| 489 static void |
489 static void |
| 490 insert_link_cb(GtkAction *action, GtkWebViewToolbar *toolbar) |
490 insert_link_cb(GtkAction *action, PidginWebViewToolbar *toolbar) |
| 491 { |
491 { |
| 492 GtkWebViewToolbarPriv *priv = GTK_WEBVIEWTOOLBAR_GET_PRIVATE(toolbar); |
492 PidginWebViewToolbarPriv *priv = PIDGIN_WEBVIEWTOOLBAR_GET_PRIVATE(toolbar); |
| 493 |
493 |
| 494 if (gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(priv->link))) { |
494 if (gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(priv->link))) { |
| 495 PurpleRequestFields *fields; |
495 PurpleRequestFields *fields; |
| 496 PurpleRequestFieldGroup *group; |
496 PurpleRequestFieldGroup *group; |
| 497 PurpleRequestField *field; |
497 PurpleRequestField *field; |
| 505 |
505 |
| 506 field = purple_request_field_string_new("url", _("_URL"), NULL, FALSE); |
506 field = purple_request_field_string_new("url", _("_URL"), NULL, FALSE); |
| 507 purple_request_field_set_required(field, TRUE); |
507 purple_request_field_set_required(field, TRUE); |
| 508 purple_request_field_group_add_field(group, field); |
508 purple_request_field_group_add_field(group, field); |
| 509 |
509 |
| 510 if (gtk_webview_get_format_functions(GTK_WEBVIEW(toolbar->webview)) & GTK_WEBVIEW_LINKDESC) { |
510 if (pidgin_webview_get_format_functions(PIDGIN_WEBVIEW(toolbar->webview)) & PIDGIN_WEBVIEW_LINKDESC) { |
| 511 desc = gtk_webview_get_selected_text(GTK_WEBVIEW(toolbar->webview)); |
511 desc = pidgin_webview_get_selected_text(PIDGIN_WEBVIEW(toolbar->webview)); |
| 512 field = purple_request_field_string_new("description", _("_Description"), |
512 field = purple_request_field_string_new("description", _("_Description"), |
| 513 desc, FALSE); |
513 desc, FALSE); |
| 514 purple_request_field_group_add_field(group, field); |
514 purple_request_field_group_add_field(group, field); |
| 515 msg = g_strdup(_("Please enter the URL and description of the " |
515 msg = g_strdup(_("Please enter the URL and description of the " |
| 516 "link that you want to insert. The description " |
516 "link that you want to insert. The description " |
| 582 return; |
582 return; |
| 583 } |
583 } |
| 584 |
584 |
| 585 g_free(filename); |
585 g_free(filename); |
| 586 |
586 |
| 587 gtk_webview_insert_image(GTK_WEBVIEW(toolbar->webview), id); |
587 pidgin_webview_insert_image(PIDGIN_WEBVIEW(toolbar->webview), id); |
| 588 /* TODO: do it after passing an image to protocol, not before |
588 /* TODO: do it after passing an image to protocol, not before |
| 589 * purple_imgstore_unref_by_id(id); |
589 * purple_imgstore_unref_by_id(id); |
| 590 */ |
590 */ |
| 591 } |
591 } |
| 592 |
592 |
| 593 static void |
593 static void |
| 594 insert_image_cb(GtkAction *action, GtkWebViewToolbar *toolbar) |
594 insert_image_cb(GtkAction *action, PidginWebViewToolbar *toolbar) |
| 595 { |
595 { |
| 596 GtkWebViewToolbarPriv *priv = GTK_WEBVIEWTOOLBAR_GET_PRIVATE(toolbar); |
596 PidginWebViewToolbarPriv *priv = PIDGIN_WEBVIEWTOOLBAR_GET_PRIVATE(toolbar); |
| 597 GtkWidget *window; |
597 GtkWidget *window; |
| 598 |
598 |
| 599 if (!priv->image_dialog) { |
599 if (!priv->image_dialog) { |
| 600 window = gtk_file_chooser_dialog_new(_("Insert Image"), NULL, |
600 window = gtk_file_chooser_dialog_new(_("Insert Image"), NULL, |
| 601 GTK_FILE_CHOOSER_ACTION_OPEN, |
601 GTK_FILE_CHOOSER_ACTION_OPEN, |
| 615 |
615 |
| 616 gtk_widget_grab_focus(toolbar->webview); |
616 gtk_widget_grab_focus(toolbar->webview); |
| 617 } |
617 } |
| 618 |
618 |
| 619 static void |
619 static void |
| 620 destroy_smiley_dialog(GtkWebViewToolbar *toolbar) |
620 destroy_smiley_dialog(PidginWebViewToolbar *toolbar) |
| 621 { |
621 { |
| 622 GtkWebViewToolbarPriv *priv = GTK_WEBVIEWTOOLBAR_GET_PRIVATE(toolbar); |
622 PidginWebViewToolbarPriv *priv = PIDGIN_WEBVIEWTOOLBAR_GET_PRIVATE(toolbar); |
| 623 if (priv->smiley_dialog != NULL) |
623 if (priv->smiley_dialog != NULL) |
| 624 { |
624 { |
| 625 gtk_widget_destroy(priv->smiley_dialog); |
625 gtk_widget_destroy(priv->smiley_dialog); |
| 626 priv->smiley_dialog = NULL; |
626 priv->smiley_dialog = NULL; |
| 627 } |
627 } |
| 628 } |
628 } |
| 629 |
629 |
| 630 static gboolean |
630 static gboolean |
| 631 close_smiley_dialog(GtkWebViewToolbar *toolbar) |
631 close_smiley_dialog(PidginWebViewToolbar *toolbar) |
| 632 { |
632 { |
| 633 GtkWebViewToolbarPriv *priv = GTK_WEBVIEWTOOLBAR_GET_PRIVATE(toolbar); |
633 PidginWebViewToolbarPriv *priv = PIDGIN_WEBVIEWTOOLBAR_GET_PRIVATE(toolbar); |
| 634 gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(priv->smiley), FALSE); |
634 gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(priv->smiley), FALSE); |
| 635 return FALSE; |
635 return FALSE; |
| 636 } |
636 } |
| 637 |
637 |
| 638 static void |
638 static void |
| 639 insert_smiley_text(GtkWidget *widget, GtkWebViewToolbar *toolbar) |
639 insert_smiley_text(GtkWidget *widget, PidginWebViewToolbar *toolbar) |
| 640 { |
640 { |
| 641 char *smiley_text, *escaped_smiley; |
641 char *smiley_text, *escaped_smiley; |
| 642 |
642 |
| 643 smiley_text = g_object_get_data(G_OBJECT(widget), "smiley_text"); |
643 smiley_text = g_object_get_data(G_OBJECT(widget), "smiley_text"); |
| 644 escaped_smiley = g_markup_escape_text(smiley_text, -1); |
644 escaped_smiley = g_markup_escape_text(smiley_text, -1); |
| 645 |
645 |
| 646 gtk_webview_insert_smiley(GTK_WEBVIEW(toolbar->webview), |
646 pidgin_webview_insert_smiley(PIDGIN_WEBVIEW(toolbar->webview), |
| 647 gtk_webview_get_protocol_name(GTK_WEBVIEW(toolbar->webview)), |
647 pidgin_webview_get_protocol_name(PIDGIN_WEBVIEW(toolbar->webview)), |
| 648 escaped_smiley); |
648 escaped_smiley); |
| 649 |
649 |
| 650 g_free(escaped_smiley); |
650 g_free(escaped_smiley); |
| 651 |
651 |
| 652 close_smiley_dialog(toolbar); |
652 close_smiley_dialog(toolbar); |
| 654 |
654 |
| 655 /* smiley buttons list */ |
655 /* smiley buttons list */ |
| 656 struct smiley_button_list { |
656 struct smiley_button_list { |
| 657 int width, height; |
657 int width, height; |
| 658 GtkWidget *button; |
658 GtkWidget *button; |
| 659 const GtkWebViewSmiley *smiley; |
659 const PidginWebViewSmiley *smiley; |
| 660 struct smiley_button_list *next; |
660 struct smiley_button_list *next; |
| 661 }; |
661 }; |
| 662 |
662 |
| 663 static struct smiley_button_list * |
663 static struct smiley_button_list * |
| 664 sort_smileys(struct smiley_button_list *ls, GtkWebViewToolbar *toolbar, |
664 sort_smileys(struct smiley_button_list *ls, PidginWebViewToolbar *toolbar, |
| 665 int *width, const GtkWebViewSmiley *smiley) |
665 int *width, const PidginWebViewSmiley *smiley) |
| 666 { |
666 { |
| 667 GtkWidget *image; |
667 GtkWidget *image; |
| 668 GtkWidget *button; |
668 GtkWidget *button; |
| 669 GtkRequisition size; |
669 GtkRequisition size; |
| 670 struct smiley_button_list *cur; |
670 struct smiley_button_list *cur; |
| 671 struct smiley_button_list *it, *it_last; |
671 struct smiley_button_list *it, *it_last; |
| 672 const gchar *filename = gtk_webview_smiley_get_file(smiley); |
672 const gchar *filename = pidgin_webview_smiley_get_file(smiley); |
| 673 const gchar *face = gtk_webview_smiley_get_smile(smiley); |
673 const gchar *face = pidgin_webview_smiley_get_smile(smiley); |
| 674 PurpleSmiley *psmiley = NULL; |
674 PurpleSmiley *psmiley = NULL; |
| 675 gboolean supports_custom = (gtk_webview_get_format_functions(GTK_WEBVIEW(toolbar->webview)) & GTK_WEBVIEW_CUSTOM_SMILEY); |
675 gboolean supports_custom = (pidgin_webview_get_format_functions(PIDGIN_WEBVIEW(toolbar->webview)) & PIDGIN_WEBVIEW_CUSTOM_SMILEY); |
| 676 |
676 |
| 677 cur = g_new0(struct smiley_button_list, 1); |
677 cur = g_new0(struct smiley_button_list, 1); |
| 678 it = ls; |
678 it = ls; |
| 679 it_last = ls; /* list iterators */ |
679 it_last = ls; /* list iterators */ |
| 680 image = gtk_image_new_from_file(filename); |
680 image = gtk_image_new_from_file(filename); |
| 681 |
681 |
| 682 gtk_widget_get_preferred_size(image, NULL, &size); |
682 gtk_widget_get_preferred_size(image, NULL, &size); |
| 683 |
683 |
| 684 if ((size.width > 24) |
684 if ((size.width > 24) |
| 685 && (gtk_webview_smiley_get_flags(smiley) & GTK_WEBVIEW_SMILEY_CUSTOM)) { |
685 && (pidgin_webview_smiley_get_flags(smiley) & PIDGIN_WEBVIEW_SMILEY_CUSTOM)) { |
| 686 /* This is a custom smiley, let's scale it */ |
686 /* This is a custom smiley, let's scale it */ |
| 687 GdkPixbuf *pixbuf = NULL; |
687 GdkPixbuf *pixbuf = NULL; |
| 688 GtkImageType type; |
688 GtkImageType type; |
| 689 |
689 |
| 690 type = gtk_image_get_storage_type(GTK_IMAGE(image)); |
690 type = gtk_image_get_storage_type(GTK_IMAGE(image)); |
| 726 psmiley = purple_smileys_find_by_shortcut(face); |
726 psmiley = purple_smileys_find_by_shortcut(face); |
| 727 /* If this is a "non-custom" smiley, check to see if its shortcut is |
727 /* If this is a "non-custom" smiley, check to see if its shortcut is |
| 728 "shadowed" by any custom smiley. This can only happen if the connection |
728 "shadowed" by any custom smiley. This can only happen if the connection |
| 729 is custom smiley-enabled */ |
729 is custom smiley-enabled */ |
| 730 if (supports_custom && psmiley |
730 if (supports_custom && psmiley |
| 731 && !(gtk_webview_smiley_get_flags(smiley) & GTK_WEBVIEW_SMILEY_CUSTOM)) { |
731 && !(pidgin_webview_smiley_get_flags(smiley) & PIDGIN_WEBVIEW_SMILEY_CUSTOM)) { |
| 732 gchar tip[128]; |
732 gchar tip[128]; |
| 733 g_snprintf(tip, sizeof(tip), |
733 g_snprintf(tip, sizeof(tip), |
| 734 _("This smiley is disabled because a custom smiley exists for this shortcut:\n %s"), |
734 _("This smiley is disabled because a custom smiley exists for this shortcut:\n %s"), |
| 735 face); |
735 face); |
| 736 gtk_widget_set_tooltip_text(button, tip); |
736 gtk_widget_set_tooltip_text(button, tip); |
| 759 it_last->next = cur; |
759 it_last->next = cur; |
| 760 return ls; |
760 return ls; |
| 761 } |
761 } |
| 762 |
762 |
| 763 static gboolean |
763 static gboolean |
| 764 smiley_is_unique(GSList *list, GtkWebViewSmiley *smiley) |
764 smiley_is_unique(GSList *list, PidginWebViewSmiley *smiley) |
| 765 { |
765 { |
| 766 const char *file = gtk_webview_smiley_get_file(smiley); |
766 const char *file = pidgin_webview_smiley_get_file(smiley); |
| 767 while (list) { |
767 while (list) { |
| 768 GtkWebViewSmiley *cur = (GtkWebViewSmiley *)list->data; |
768 PidginWebViewSmiley *cur = (PidginWebViewSmiley *)list->data; |
| 769 if (!strcmp(gtk_webview_smiley_get_file(cur), file)) |
769 if (!strcmp(pidgin_webview_smiley_get_file(cur), file)) |
| 770 return FALSE; |
770 return FALSE; |
| 771 list = list->next; |
771 list = list->next; |
| 772 } |
772 } |
| 773 return TRUE; |
773 return TRUE; |
| 774 } |
774 } |
| 775 |
775 |
| 776 static gboolean |
776 static gboolean |
| 777 smiley_dialog_input_cb(GtkWidget *dialog, GdkEvent *event, |
777 smiley_dialog_input_cb(GtkWidget *dialog, GdkEvent *event, |
| 778 GtkWebViewToolbar *toolbar) |
778 PidginWebViewToolbar *toolbar) |
| 779 { |
779 { |
| 780 if ((event->type == GDK_KEY_PRESS && event->key.keyval == GDK_KEY_Escape) || |
780 if ((event->type == GDK_KEY_PRESS && event->key.keyval == GDK_KEY_Escape) || |
| 781 (event->type == GDK_BUTTON_PRESS && event->button.button == 1)) |
781 (event->type == GDK_BUTTON_PRESS && event->button.button == 1)) |
| 782 { |
782 { |
| 783 close_smiley_dialog(toolbar); |
783 close_smiley_dialog(toolbar); |
| 798 return; |
798 return; |
| 799 |
799 |
| 800 line = gtk_hbox_new(FALSE, 0); |
800 line = gtk_hbox_new(FALSE, 0); |
| 801 gtk_box_pack_start(GTK_BOX(container), line, FALSE, FALSE, 0); |
801 gtk_box_pack_start(GTK_BOX(container), line, FALSE, FALSE, 0); |
| 802 for (; list; list = list->next) { |
802 for (; list; list = list->next) { |
| 803 if (custom != !!(gtk_webview_smiley_get_flags(list->smiley) & GTK_WEBVIEW_SMILEY_CUSTOM)) |
803 if (custom != !!(pidgin_webview_smiley_get_flags(list->smiley) & PIDGIN_WEBVIEW_SMILEY_CUSTOM)) |
| 804 continue; |
804 continue; |
| 805 gtk_box_pack_start(GTK_BOX(line), list->button, FALSE, FALSE, 0); |
805 gtk_box_pack_start(GTK_BOX(line), list->button, FALSE, FALSE, 0); |
| 806 gtk_widget_show(list->button); |
806 gtk_widget_show(list->button); |
| 807 line_width += list->width; |
807 line_width += list->width; |
| 808 if (line_width >= max_width) { |
808 if (line_width >= max_width) { |
| 840 |
840 |
| 841 /* Note: prepend smileys to list to avoid O(n^2) overhead when there is a |
841 /* Note: prepend smileys to list to avoid O(n^2) overhead when there is a |
| 842 large number of smileys... need to reverse the list after for the dialog |
842 large number of smileys... need to reverse the list after for the dialog |
| 843 to work... */ |
843 to work... */ |
| 844 while (smileys) { |
844 while (smileys) { |
| 845 GtkWebViewSmiley *smiley = (GtkWebViewSmiley *)smileys->data; |
845 PidginWebViewSmiley *smiley = (PidginWebViewSmiley *)smileys->data; |
| 846 if (!gtk_webview_smiley_get_hidden(smiley)) { |
846 if (!pidgin_webview_smiley_get_hidden(smiley)) { |
| 847 if (smiley_is_unique(unique_smileys, smiley)) { |
847 if (smiley_is_unique(unique_smileys, smiley)) { |
| 848 unique_smileys = g_slist_prepend(unique_smileys, smiley); |
848 unique_smileys = g_slist_prepend(unique_smileys, smiley); |
| 849 } |
849 } |
| 850 } |
850 } |
| 851 smileys = smileys->next; |
851 smileys = smileys->next; |
| 852 } |
852 } |
| 853 supports_custom = (gtk_webview_get_format_functions(GTK_WEBVIEW(toolbar->webview)) & GTK_WEBVIEW_CUSTOM_SMILEY); |
853 supports_custom = (pidgin_webview_get_format_functions(PIDGIN_WEBVIEW(toolbar->webview)) & PIDGIN_WEBVIEW_CUSTOM_SMILEY); |
| 854 if (toolbar->webview && supports_custom) { |
854 if (toolbar->webview && supports_custom) { |
| 855 const GSList *iterator = NULL; |
855 const GSList *iterator = NULL; |
| 856 custom_smileys = pidgin_smileys_get_all(); |
856 custom_smileys = pidgin_smileys_get_all(); |
| 857 |
857 |
| 858 for (iterator = custom_smileys ; iterator ; |
858 for (iterator = custom_smileys ; iterator ; |
| 859 iterator = g_slist_next(iterator)) { |
859 iterator = g_slist_next(iterator)) { |
| 860 GtkWebViewSmiley *smiley = (GtkWebViewSmiley *)iterator->data; |
860 PidginWebViewSmiley *smiley = (PidginWebViewSmiley *)iterator->data; |
| 861 unique_smileys = g_slist_prepend(unique_smileys, smiley); |
861 unique_smileys = g_slist_prepend(unique_smileys, smiley); |
| 862 } |
862 } |
| 863 } |
863 } |
| 864 |
864 |
| 865 /* we need to reverse the list to get the smileys in the correct order */ |
865 /* we need to reverse the list to get the smileys in the correct order */ |
| 961 |
961 |
| 962 gtk_widget_grab_focus(toolbar->webview); |
962 gtk_widget_grab_focus(toolbar->webview); |
| 963 } |
963 } |
| 964 |
964 |
| 965 static void |
965 static void |
| 966 send_attention_cb(GtkAction *attention, GtkWebViewToolbar *toolbar) |
966 send_attention_cb(GtkAction *attention, PidginWebViewToolbar *toolbar) |
| 967 { |
967 { |
| 968 GtkWebViewToolbarPriv *priv = GTK_WEBVIEWTOOLBAR_GET_PRIVATE(toolbar); |
968 PidginWebViewToolbarPriv *priv = PIDGIN_WEBVIEWTOOLBAR_GET_PRIVATE(toolbar); |
| 969 PurpleConversation *conv = priv->active_conv; |
969 PurpleConversation *conv = priv->active_conv; |
| 970 const gchar *who = purple_conversation_get_name(conv); |
970 const gchar *who = purple_conversation_get_name(conv); |
| 971 PurpleConnection *gc = purple_conversation_get_connection(conv); |
971 PurpleConnection *gc = purple_conversation_get_connection(conv); |
| 972 |
972 |
| 973 purple_protocol_send_attention(gc, who, 0); |
973 purple_protocol_send_attention(gc, who, 0); |
| 974 gtk_widget_grab_focus(toolbar->webview); |
974 gtk_widget_grab_focus(toolbar->webview); |
| 975 } |
975 } |
| 976 |
976 |
| 977 static void |
977 static void |
| 978 update_buttons_cb(GtkWebView *webview, GtkWebViewButtons buttons, |
978 update_buttons_cb(PidginWebView *webview, PidginWebViewButtons buttons, |
| 979 GtkWebViewToolbar *toolbar) |
979 PidginWebViewToolbar *toolbar) |
| 980 { |
980 { |
| 981 GtkWebViewToolbarPriv *priv = GTK_WEBVIEWTOOLBAR_GET_PRIVATE(toolbar); |
981 PidginWebViewToolbarPriv *priv = PIDGIN_WEBVIEWTOOLBAR_GET_PRIVATE(toolbar); |
| 982 |
982 |
| 983 gtk_action_set_sensitive(priv->bold, buttons & GTK_WEBVIEW_BOLD); |
983 gtk_action_set_sensitive(priv->bold, buttons & PIDGIN_WEBVIEW_BOLD); |
| 984 gtk_action_set_sensitive(priv->italic, buttons & GTK_WEBVIEW_ITALIC); |
984 gtk_action_set_sensitive(priv->italic, buttons & PIDGIN_WEBVIEW_ITALIC); |
| 985 gtk_action_set_sensitive(priv->underline, buttons & GTK_WEBVIEW_UNDERLINE); |
985 gtk_action_set_sensitive(priv->underline, buttons & PIDGIN_WEBVIEW_UNDERLINE); |
| 986 gtk_action_set_sensitive(priv->strike, buttons & GTK_WEBVIEW_STRIKE); |
986 gtk_action_set_sensitive(priv->strike, buttons & PIDGIN_WEBVIEW_STRIKE); |
| 987 |
987 |
| 988 gtk_action_set_sensitive(priv->larger_size, buttons & GTK_WEBVIEW_GROW); |
988 gtk_action_set_sensitive(priv->larger_size, buttons & PIDGIN_WEBVIEW_GROW); |
| 989 gtk_action_set_sensitive(priv->smaller_size, buttons & GTK_WEBVIEW_SHRINK); |
989 gtk_action_set_sensitive(priv->smaller_size, buttons & PIDGIN_WEBVIEW_SHRINK); |
| 990 |
990 |
| 991 gtk_action_set_sensitive(priv->font, buttons & GTK_WEBVIEW_FACE); |
991 gtk_action_set_sensitive(priv->font, buttons & PIDGIN_WEBVIEW_FACE); |
| 992 gtk_action_set_sensitive(priv->fgcolor, buttons & GTK_WEBVIEW_FORECOLOR); |
992 gtk_action_set_sensitive(priv->fgcolor, buttons & PIDGIN_WEBVIEW_FORECOLOR); |
| 993 gtk_action_set_sensitive(priv->bgcolor, buttons & GTK_WEBVIEW_BACKCOLOR); |
993 gtk_action_set_sensitive(priv->bgcolor, buttons & PIDGIN_WEBVIEW_BACKCOLOR); |
| 994 |
994 |
| 995 gtk_action_set_sensitive(priv->clear, |
995 gtk_action_set_sensitive(priv->clear, |
| 996 (buttons & GTK_WEBVIEW_BOLD || |
996 (buttons & PIDGIN_WEBVIEW_BOLD || |
| 997 buttons & GTK_WEBVIEW_ITALIC || |
997 buttons & PIDGIN_WEBVIEW_ITALIC || |
| 998 buttons & GTK_WEBVIEW_UNDERLINE || |
998 buttons & PIDGIN_WEBVIEW_UNDERLINE || |
| 999 buttons & GTK_WEBVIEW_STRIKE || |
999 buttons & PIDGIN_WEBVIEW_STRIKE || |
| 1000 buttons & GTK_WEBVIEW_GROW || |
1000 buttons & PIDGIN_WEBVIEW_GROW || |
| 1001 buttons & GTK_WEBVIEW_SHRINK || |
1001 buttons & PIDGIN_WEBVIEW_SHRINK || |
| 1002 buttons & GTK_WEBVIEW_FACE || |
1002 buttons & PIDGIN_WEBVIEW_FACE || |
| 1003 buttons & GTK_WEBVIEW_FORECOLOR || |
1003 buttons & PIDGIN_WEBVIEW_FORECOLOR || |
| 1004 buttons & GTK_WEBVIEW_BACKCOLOR)); |
1004 buttons & PIDGIN_WEBVIEW_BACKCOLOR)); |
| 1005 |
1005 |
| 1006 gtk_action_set_sensitive(priv->image, buttons & GTK_WEBVIEW_IMAGE); |
1006 gtk_action_set_sensitive(priv->image, buttons & PIDGIN_WEBVIEW_IMAGE); |
| 1007 gtk_action_set_sensitive(priv->link, buttons & GTK_WEBVIEW_LINK); |
1007 gtk_action_set_sensitive(priv->link, buttons & PIDGIN_WEBVIEW_LINK); |
| 1008 gtk_action_set_sensitive(priv->smiley, (buttons & GTK_WEBVIEW_SMILEY) && |
1008 gtk_action_set_sensitive(priv->smiley, (buttons & PIDGIN_WEBVIEW_SMILEY) && |
| 1009 pidgin_themes_get_proto_smileys(priv->sml)); |
1009 pidgin_themes_get_proto_smileys(priv->sml)); |
| 1010 } |
1010 } |
| 1011 |
1011 |
| 1012 /* we call this when we want to _set_active the toggle button, it'll |
1012 /* we call this when we want to _set_active the toggle button, it'll |
| 1013 * block the callback that's connected to the button so we don't have to |
1013 * block the callback that's connected to the button so we don't have to |
| 1014 * do the double toggling hack |
1014 * do the double toggling hack |
| 1015 */ |
1015 */ |
| 1016 static void |
1016 static void |
| 1017 toggle_action_set_active_block(GtkToggleAction *action, gboolean is_active, |
1017 toggle_action_set_active_block(GtkToggleAction *action, gboolean is_active, |
| 1018 GtkWebViewToolbar *toolbar) |
1018 PidginWebViewToolbar *toolbar) |
| 1019 { |
1019 { |
| 1020 GObject *object; |
1020 GObject *object; |
| 1021 g_return_if_fail(toolbar); |
1021 g_return_if_fail(toolbar); |
| 1022 |
1022 |
| 1023 object = g_object_ref(action); |
1023 object = g_object_ref(action); |
| 1028 0, 0, NULL, NULL, toolbar); |
1028 0, 0, NULL, NULL, toolbar); |
| 1029 g_object_unref(object); |
1029 g_object_unref(object); |
| 1030 } |
1030 } |
| 1031 |
1031 |
| 1032 static void |
1032 static void |
| 1033 update_buttons(GtkWebViewToolbar *toolbar) |
1033 update_buttons(PidginWebViewToolbar *toolbar) |
| 1034 { |
1034 { |
| 1035 GtkWebViewToolbarPriv *priv = GTK_WEBVIEWTOOLBAR_GET_PRIVATE(toolbar); |
1035 PidginWebViewToolbarPriv *priv = PIDGIN_WEBVIEWTOOLBAR_GET_PRIVATE(toolbar); |
| 1036 gboolean bold, italic, underline, strike; |
1036 gboolean bold, italic, underline, strike; |
| 1037 char *tmp; |
1037 char *tmp; |
| 1038 char *label; |
1038 char *label; |
| 1039 |
1039 |
| 1040 label = g_strdup(_("_Font")); |
1040 label = g_strdup(_("_Font")); |
| 1041 |
1041 |
| 1042 gtk_webview_get_current_format(GTK_WEBVIEW(toolbar->webview), |
1042 pidgin_webview_get_current_format(PIDGIN_WEBVIEW(toolbar->webview), |
| 1043 &bold, &italic, &underline, &strike); |
1043 &bold, &italic, &underline, &strike); |
| 1044 |
1044 |
| 1045 if (gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(priv->bold)) != bold) |
1045 if (gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(priv->bold)) != bold) |
| 1046 toggle_action_set_active_block(GTK_TOGGLE_ACTION(priv->bold), bold, |
1046 toggle_action_set_active_block(GTK_TOGGLE_ACTION(priv->bold), bold, |
| 1047 toolbar); |
1047 toolbar); |
| 1074 gchar *markup = g_strdup_printf("<s>%s</s>", label); |
1074 gchar *markup = g_strdup_printf("<s>%s</s>", label); |
| 1075 g_free(label); |
1075 g_free(label); |
| 1076 label = markup; |
1076 label = markup; |
| 1077 } |
1077 } |
| 1078 |
1078 |
| 1079 tmp = gtk_webview_get_current_fontface(GTK_WEBVIEW(toolbar->webview)); |
1079 tmp = pidgin_webview_get_current_fontface(PIDGIN_WEBVIEW(toolbar->webview)); |
| 1080 toggle_action_set_active_block(GTK_TOGGLE_ACTION(priv->font), |
1080 toggle_action_set_active_block(GTK_TOGGLE_ACTION(priv->font), |
| 1081 (tmp && *tmp), toolbar); |
1081 (tmp && *tmp), toolbar); |
| 1082 if (tmp && *tmp) { |
1082 if (tmp && *tmp) { |
| 1083 gchar *markup = g_strdup_printf("<span face=\"%s\">%s</span>", |
1083 gchar *markup = g_strdup_printf("<span face=\"%s\">%s</span>", |
| 1084 tmp, label); |
1084 tmp, label); |
| 1085 g_free(label); |
1085 g_free(label); |
| 1086 label = markup; |
1086 label = markup; |
| 1087 } |
1087 } |
| 1088 g_free(tmp); |
1088 g_free(tmp); |
| 1089 |
1089 |
| 1090 tmp = gtk_webview_get_current_forecolor(GTK_WEBVIEW(toolbar->webview)); |
1090 tmp = pidgin_webview_get_current_forecolor(PIDGIN_WEBVIEW(toolbar->webview)); |
| 1091 /* TODO: rgb()/rgba() colors are not supported by GTK, so let's get rid |
1091 /* TODO: rgb()/rgba() colors are not supported by GTK, so let's get rid |
| 1092 * of such warnings for now. There are two solutions: rewrite those |
1092 * of such warnings for now. There are two solutions: rewrite those |
| 1093 * colors to #aabbcc or implement the toolbar in javascript. |
1093 * colors to #aabbcc or implement the toolbar in javascript. |
| 1094 */ |
1094 */ |
| 1095 if (tmp && strncmp(tmp, "rgb", 3) == 0) |
1095 if (tmp && strncmp(tmp, "rgb", 3) == 0) |
| 1120 |
1120 |
| 1121 gtk_label_set_markup_with_mnemonic(GTK_LABEL(priv->font_label), label); |
1121 gtk_label_set_markup_with_mnemonic(GTK_LABEL(priv->font_label), label); |
| 1122 } |
1122 } |
| 1123 |
1123 |
| 1124 static void |
1124 static void |
| 1125 toggle_button_cb(GtkWebView *webview, GtkWebViewButtons buttons, |
1125 toggle_button_cb(PidginWebView *webview, PidginWebViewButtons buttons, |
| 1126 GtkWebViewToolbar *toolbar) |
1126 PidginWebViewToolbar *toolbar) |
| 1127 { |
1127 { |
| 1128 update_buttons(toolbar); |
1128 update_buttons(toolbar); |
| 1129 } |
1129 } |
| 1130 |
1130 |
| 1131 static void |
1131 static void |
| 1132 update_format_cb(GtkWebView *webview, GtkWebViewToolbar *toolbar) |
1132 update_format_cb(PidginWebView *webview, PidginWebViewToolbar *toolbar) |
| 1133 { |
1133 { |
| 1134 update_buttons(toolbar); |
1134 update_buttons(toolbar); |
| 1135 } |
1135 } |
| 1136 |
1136 |
| 1137 static void |
1137 static void |
| 1138 mark_set_cb(GtkWebView *webview, GtkWebViewToolbar *toolbar) |
1138 mark_set_cb(PidginWebView *webview, PidginWebViewToolbar *toolbar) |
| 1139 { |
1139 { |
| 1140 update_buttons(toolbar); |
1140 update_buttons(toolbar); |
| 1141 } |
1141 } |
| 1142 |
1142 |
| 1143 /* This comes from gtkmenutoolbutton.c from gtk+ |
1143 /* This comes from gtkmenutoolbutton.c from gtk+ |
| 1287 |
1287 |
| 1288 G_OBJECT_CLASS(parent_class)->finalize(object); |
1288 G_OBJECT_CLASS(parent_class)->finalize(object); |
| 1289 } |
1289 } |
| 1290 |
1290 |
| 1291 static void |
1291 static void |
| 1292 gtk_webviewtoolbar_class_init(GtkWebViewToolbarClass *class) |
1292 pidgin_webviewtoolbar_class_init(PidginWebViewToolbarClass *class) |
| 1293 { |
1293 { |
| 1294 GObjectClass *gobject_class; |
1294 GObjectClass *gobject_class; |
| 1295 gobject_class = (GObjectClass *)class; |
1295 gobject_class = (GObjectClass *)class; |
| 1296 parent_class = g_type_class_ref(GTK_TYPE_HBOX); |
1296 parent_class = g_type_class_ref(GTK_TYPE_HBOX); |
| 1297 gobject_class->finalize = gtk_webviewtoolbar_finalize; |
1297 gobject_class->finalize = pidgin_webviewtoolbar_finalize; |
| 1298 |
1298 |
| 1299 g_type_class_add_private(class, sizeof(GtkWebViewToolbarPriv)); |
1299 g_type_class_add_private(class, sizeof(PidginWebViewToolbarPriv)); |
| 1300 |
1300 |
| 1301 purple_prefs_add_none(PIDGIN_PREFS_ROOT "/conversations/toolbar"); |
1301 purple_prefs_add_none(PIDGIN_PREFS_ROOT "/conversations/toolbar"); |
| 1302 purple_prefs_add_bool(PIDGIN_PREFS_ROOT "/conversations/toolbar/wide", FALSE); |
1302 purple_prefs_add_bool(PIDGIN_PREFS_ROOT "/conversations/toolbar/wide", FALSE); |
| 1303 } |
1303 } |
| 1304 |
1304 |
| 1305 static void |
1305 static void |
| 1306 gtk_webviewtoolbar_create_actions(GtkWebViewToolbar *toolbar) |
1306 pidgin_webviewtoolbar_create_actions(PidginWebViewToolbar *toolbar) |
| 1307 { |
1307 { |
| 1308 GtkWebViewToolbarPriv *priv = GTK_WEBVIEWTOOLBAR_GET_PRIVATE(toolbar); |
1308 PidginWebViewToolbarPriv *priv = PIDGIN_WEBVIEWTOOLBAR_GET_PRIVATE(toolbar); |
| 1309 GtkActionGroup *action_group; |
1309 GtkActionGroup *action_group; |
| 1310 gsize i; |
1310 gsize i; |
| 1311 struct { |
1311 struct { |
| 1312 GtkAction **action; |
1312 GtkAction **action; |
| 1313 char *name; |
1313 char *name; |
| 1335 {&priv->hr, "InsertHR", NULL, N_("_Horizontal rule"), N_("Insert Horizontal rule"), insert_hr_cb, FALSE}, |
1335 {&priv->hr, "InsertHR", NULL, N_("_Horizontal rule"), N_("Insert Horizontal rule"), insert_hr_cb, FALSE}, |
| 1336 {&priv->smiley, "InsertSmiley", PIDGIN_STOCK_TOOLBAR_SMILEY, N_("_Smile!"), N_("Insert Smiley"), insert_smiley_cb, TRUE}, |
1336 {&priv->smiley, "InsertSmiley", PIDGIN_STOCK_TOOLBAR_SMILEY, N_("_Smile!"), N_("Insert Smiley"), insert_smiley_cb, TRUE}, |
| 1337 {&priv->attention, "SendAttention", PIDGIN_STOCK_TOOLBAR_SEND_ATTENTION, N_("_Attention!"), N_("Get Attention"), send_attention_cb, FALSE}, |
1337 {&priv->attention, "SendAttention", PIDGIN_STOCK_TOOLBAR_SEND_ATTENTION, N_("_Attention!"), N_("Get Attention"), send_attention_cb, FALSE}, |
| 1338 }; |
1338 }; |
| 1339 |
1339 |
| 1340 action_group = gtk_action_group_new("GtkWebViewToolbar"); |
1340 action_group = gtk_action_group_new("PidginWebViewToolbar"); |
| 1341 #ifdef ENABLE_NLS |
1341 #ifdef ENABLE_NLS |
| 1342 gtk_action_group_set_translation_domain(action_group, PACKAGE); |
1342 gtk_action_group_set_translation_domain(action_group, PACKAGE); |
| 1343 #endif |
1343 #endif |
| 1344 |
1344 |
| 1345 for (i = 0; i < G_N_ELEMENTS(actions); i++) { |
1345 for (i = 0; i < G_N_ELEMENTS(actions); i++) { |
| 1504 |
1504 |
| 1505 #undef ADD_MENU_ITEM |
1505 #undef ADD_MENU_ITEM |
| 1506 } |
1506 } |
| 1507 |
1507 |
| 1508 static void |
1508 static void |
| 1509 gtk_webviewtoolbar_init(GtkWebViewToolbar *toolbar) |
1509 pidgin_webviewtoolbar_init(PidginWebViewToolbar *toolbar) |
| 1510 { |
1510 { |
| 1511 GtkWebViewToolbarPriv *priv = GTK_WEBVIEWTOOLBAR_GET_PRIVATE(toolbar); |
1511 PidginWebViewToolbarPriv *priv = PIDGIN_WEBVIEWTOOLBAR_GET_PRIVATE(toolbar); |
| 1512 GtkWidget *hbox = GTK_WIDGET(toolbar); |
1512 GtkWidget *hbox = GTK_WIDGET(toolbar); |
| 1513 |
1513 |
| 1514 gtk_webviewtoolbar_create_actions(toolbar); |
1514 pidgin_webviewtoolbar_create_actions(toolbar); |
| 1515 gtk_webviewtoolbar_create_wide_view(toolbar); |
1515 pidgin_webviewtoolbar_create_wide_view(toolbar); |
| 1516 gtk_webviewtoolbar_create_lean_view(toolbar); |
1516 pidgin_webviewtoolbar_create_lean_view(toolbar); |
| 1517 |
1517 |
| 1518 gtk_box_pack_start(GTK_BOX(hbox), priv->wide_view, TRUE, TRUE, 0); |
1518 gtk_box_pack_start(GTK_BOX(hbox), priv->wide_view, TRUE, TRUE, 0); |
| 1519 gtk_box_pack_start(GTK_BOX(hbox), priv->lean_view, TRUE, TRUE, 0); |
1519 gtk_box_pack_start(GTK_BOX(hbox), priv->lean_view, TRUE, TRUE, 0); |
| 1520 |
1520 |
| 1521 priv->sml = NULL; |
1521 priv->sml = NULL; |
| 1533 G_CALLBACK(purple_prefs_trigger_callback), |
1533 G_CALLBACK(purple_prefs_trigger_callback), |
| 1534 PIDGIN_PREFS_ROOT "/conversations/toolbar/wide", |
1534 PIDGIN_PREFS_ROOT "/conversations/toolbar/wide", |
| 1535 NULL, G_CONNECT_AFTER | G_CONNECT_SWAPPED); |
1535 NULL, G_CONNECT_AFTER | G_CONNECT_SWAPPED); |
| 1536 |
1536 |
| 1537 g_signal_connect(G_OBJECT(hbox), "button-press-event", |
1537 g_signal_connect(G_OBJECT(hbox), "button-press-event", |
| 1538 G_CALLBACK(gtk_webviewtoolbar_popup_menu), toolbar); |
1538 G_CALLBACK(pidgin_webviewtoolbar_popup_menu), toolbar); |
| 1539 } |
1539 } |
| 1540 |
1540 |
| 1541 /****************************************************************************** |
1541 /****************************************************************************** |
| 1542 * Public API |
1542 * Public API |
| 1543 *****************************************************************************/ |
1543 *****************************************************************************/ |
| 1544 |
1544 |
| 1545 GtkWidget * |
1545 GtkWidget * |
| 1546 gtk_webviewtoolbar_new(void) |
1546 pidgin_webviewtoolbar_new(void) |
| 1547 { |
1547 { |
| 1548 return GTK_WIDGET(g_object_new(gtk_webviewtoolbar_get_type(), NULL)); |
1548 return GTK_WIDGET(g_object_new(pidgin_webviewtoolbar_get_type(), NULL)); |
| 1549 } |
1549 } |
| 1550 |
1550 |
| 1551 GType |
1551 GType |
| 1552 gtk_webviewtoolbar_get_type(void) |
1552 pidgin_webviewtoolbar_get_type(void) |
| 1553 { |
1553 { |
| 1554 static GType webviewtoolbar_type = 0; |
1554 static GType webviewtoolbar_type = 0; |
| 1555 |
1555 |
| 1556 if (!webviewtoolbar_type) { |
1556 if (!webviewtoolbar_type) { |
| 1557 static const GTypeInfo webviewtoolbar_info = { |
1557 static const GTypeInfo webviewtoolbar_info = { |
| 1558 sizeof(GtkWebViewToolbarClass), |
1558 sizeof(PidginWebViewToolbarClass), |
| 1559 NULL, |
1559 NULL, |
| 1560 NULL, |
1560 NULL, |
| 1561 (GClassInitFunc)gtk_webviewtoolbar_class_init, |
1561 (GClassInitFunc)pidgin_webviewtoolbar_class_init, |
| 1562 NULL, |
1562 NULL, |
| 1563 NULL, |
1563 NULL, |
| 1564 sizeof(GtkWebViewToolbar), |
1564 sizeof(PidginWebViewToolbar), |
| 1565 0, |
1565 0, |
| 1566 (GInstanceInitFunc)gtk_webviewtoolbar_init, |
1566 (GInstanceInitFunc)pidgin_webviewtoolbar_init, |
| 1567 NULL |
1567 NULL |
| 1568 }; |
1568 }; |
| 1569 |
1569 |
| 1570 webviewtoolbar_type = g_type_register_static(GTK_TYPE_HBOX, |
1570 webviewtoolbar_type = g_type_register_static(GTK_TYPE_HBOX, |
| 1571 "GtkWebViewToolbar", &webviewtoolbar_info, 0); |
1571 "PidginWebViewToolbar", &webviewtoolbar_info, 0); |
| 1572 } |
1572 } |
| 1573 |
1573 |
| 1574 return webviewtoolbar_type; |
1574 return webviewtoolbar_type; |
| 1575 } |
1575 } |
| 1576 |
1576 |
| 1577 void |
1577 void |
| 1578 gtk_webviewtoolbar_attach(GtkWebViewToolbar *toolbar, GtkWidget *webview) |
1578 pidgin_webviewtoolbar_attach(PidginWebViewToolbar *toolbar, GtkWidget *webview) |
| 1579 { |
1579 { |
| 1580 GtkWebViewButtons buttons; |
1580 PidginWebViewButtons buttons; |
| 1581 |
1581 |
| 1582 g_return_if_fail(toolbar != NULL); |
1582 g_return_if_fail(toolbar != NULL); |
| 1583 g_return_if_fail(GTK_IS_WEBVIEWTOOLBAR(toolbar)); |
1583 g_return_if_fail(GTK_IS_WEBVIEWTOOLBAR(toolbar)); |
| 1584 g_return_if_fail(webview != NULL); |
1584 g_return_if_fail(webview != NULL); |
| 1585 g_return_if_fail(GTK_IS_WEBVIEW(webview)); |
1585 g_return_if_fail(GTK_IS_WEBVIEW(webview)); |
| 1594 g_signal_connect(G_OBJECT(webview), "format-updated", |
1594 g_signal_connect(G_OBJECT(webview), "format-updated", |
| 1595 G_CALLBACK(update_format_cb), toolbar); |
1595 G_CALLBACK(update_format_cb), toolbar); |
| 1596 g_signal_connect_after(G_OBJECT(webview), "selection-changed", |
1596 g_signal_connect_after(G_OBJECT(webview), "selection-changed", |
| 1597 G_CALLBACK(mark_set_cb), toolbar); |
1597 G_CALLBACK(mark_set_cb), toolbar); |
| 1598 |
1598 |
| 1599 buttons = gtk_webview_get_format_functions(GTK_WEBVIEW(webview)); |
1599 buttons = pidgin_webview_get_format_functions(PIDGIN_WEBVIEW(webview)); |
| 1600 update_buttons_cb(GTK_WEBVIEW(webview), buttons, toolbar); |
1600 update_buttons_cb(PIDGIN_WEBVIEW(webview), buttons, toolbar); |
| 1601 update_buttons(toolbar); |
1601 update_buttons(toolbar); |
| 1602 } |
1602 } |
| 1603 |
1603 |
| 1604 void |
1604 void |
| 1605 gtk_webviewtoolbar_associate_smileys(GtkWebViewToolbar *toolbar, |
1605 pidgin_webviewtoolbar_associate_smileys(PidginWebViewToolbar *toolbar, |
| 1606 const char *proto_id) |
1606 const char *proto_id) |
| 1607 { |
1607 { |
| 1608 GtkWebViewToolbarPriv *priv = GTK_WEBVIEWTOOLBAR_GET_PRIVATE(toolbar); |
1608 PidginWebViewToolbarPriv *priv = PIDGIN_WEBVIEWTOOLBAR_GET_PRIVATE(toolbar); |
| 1609 g_free(priv->sml); |
1609 g_free(priv->sml); |
| 1610 priv->sml = g_strdup(proto_id); |
1610 priv->sml = g_strdup(proto_id); |
| 1611 } |
1611 } |
| 1612 |
1612 |
| 1613 void |
1613 void |
| 1614 gtk_webviewtoolbar_switch_active_conversation(GtkWebViewToolbar *toolbar, |
1614 pidgin_webviewtoolbar_switch_active_conversation(PidginWebViewToolbar *toolbar, |
| 1615 PurpleConversation *conv) |
1615 PurpleConversation *conv) |
| 1616 { |
1616 { |
| 1617 GtkWebViewToolbarPriv *priv = GTK_WEBVIEWTOOLBAR_GET_PRIVATE(toolbar); |
1617 PidginWebViewToolbarPriv *priv = PIDGIN_WEBVIEWTOOLBAR_GET_PRIVATE(toolbar); |
| 1618 PurpleConnection *gc = purple_conversation_get_connection(conv); |
1618 PurpleConnection *gc = purple_conversation_get_connection(conv); |
| 1619 PurpleProtocol *protocol = purple_connection_get_protocol(gc); |
1619 PurpleProtocol *protocol = purple_connection_get_protocol(gc); |
| 1620 |
1620 |
| 1621 priv->active_conv = conv; |
1621 priv->active_conv = conv; |
| 1622 |
1622 |
| 1629 gtk_action_set_sensitive(priv->smiley, |
1629 gtk_action_set_sensitive(priv->smiley, |
| 1630 pidgin_themes_get_proto_smileys(priv->sml) != NULL); |
1630 pidgin_themes_get_proto_smileys(priv->sml) != NULL); |
| 1631 } |
1631 } |
| 1632 |
1632 |
| 1633 void |
1633 void |
| 1634 gtk_webviewtoolbar_activate(GtkWebViewToolbar *toolbar, |
1634 pidgin_webviewtoolbar_activate(PidginWebViewToolbar *toolbar, |
| 1635 GtkWebViewAction action) |
1635 PidginWebViewAction action) |
| 1636 { |
1636 { |
| 1637 GtkWebViewToolbarPriv *priv; |
1637 PidginWebViewToolbarPriv *priv; |
| 1638 GtkAction *act; |
1638 GtkAction *act; |
| 1639 |
1639 |
| 1640 g_return_if_fail(toolbar != NULL); |
1640 g_return_if_fail(toolbar != NULL); |
| 1641 |
1641 |
| 1642 priv = GTK_WEBVIEWTOOLBAR_GET_PRIVATE(toolbar); |
1642 priv = PIDGIN_WEBVIEWTOOLBAR_GET_PRIVATE(toolbar); |
| 1643 switch (action) { |
1643 switch (action) { |
| 1644 case GTK_WEBVIEW_ACTION_BOLD: |
1644 case PIDGIN_WEBVIEW_ACTION_BOLD: |
| 1645 act = priv->bold; |
1645 act = priv->bold; |
| 1646 break; |
1646 break; |
| 1647 |
1647 |
| 1648 case GTK_WEBVIEW_ACTION_ITALIC: |
1648 case PIDGIN_WEBVIEW_ACTION_ITALIC: |
| 1649 act = priv->italic; |
1649 act = priv->italic; |
| 1650 break; |
1650 break; |
| 1651 |
1651 |
| 1652 case GTK_WEBVIEW_ACTION_UNDERLINE: |
1652 case PIDGIN_WEBVIEW_ACTION_UNDERLINE: |
| 1653 act = priv->underline; |
1653 act = priv->underline; |
| 1654 break; |
1654 break; |
| 1655 |
1655 |
| 1656 case GTK_WEBVIEW_ACTION_STRIKE: |
1656 case PIDGIN_WEBVIEW_ACTION_STRIKE: |
| 1657 act = priv->strike; |
1657 act = priv->strike; |
| 1658 break; |
1658 break; |
| 1659 |
1659 |
| 1660 case GTK_WEBVIEW_ACTION_LARGER: |
1660 case PIDGIN_WEBVIEW_ACTION_LARGER: |
| 1661 act = priv->larger_size; |
1661 act = priv->larger_size; |
| 1662 break; |
1662 break; |
| 1663 |
1663 |
| 1664 #if 0 |
1664 #if 0 |
| 1665 case GTK_WEBVIEW_ACTION_NORMAL: |
1665 case PIDGIN_WEBVIEW_ACTION_NORMAL: |
| 1666 act = priv->normal_size; |
1666 act = priv->normal_size; |
| 1667 break; |
1667 break; |
| 1668 #endif |
1668 #endif |
| 1669 |
1669 |
| 1670 case GTK_WEBVIEW_ACTION_SMALLER: |
1670 case PIDGIN_WEBVIEW_ACTION_SMALLER: |
| 1671 act = priv->smaller_size; |
1671 act = priv->smaller_size; |
| 1672 break; |
1672 break; |
| 1673 |
1673 |
| 1674 case GTK_WEBVIEW_ACTION_FONTFACE: |
1674 case PIDGIN_WEBVIEW_ACTION_FONTFACE: |
| 1675 act = priv->font; |
1675 act = priv->font; |
| 1676 break; |
1676 break; |
| 1677 |
1677 |
| 1678 case GTK_WEBVIEW_ACTION_FGCOLOR: |
1678 case PIDGIN_WEBVIEW_ACTION_FGCOLOR: |
| 1679 act = priv->fgcolor; |
1679 act = priv->fgcolor; |
| 1680 break; |
1680 break; |
| 1681 |
1681 |
| 1682 case GTK_WEBVIEW_ACTION_BGCOLOR: |
1682 case PIDGIN_WEBVIEW_ACTION_BGCOLOR: |
| 1683 act = priv->bgcolor; |
1683 act = priv->bgcolor; |
| 1684 break; |
1684 break; |
| 1685 |
1685 |
| 1686 case GTK_WEBVIEW_ACTION_CLEAR: |
1686 case PIDGIN_WEBVIEW_ACTION_CLEAR: |
| 1687 act = priv->clear; |
1687 act = priv->clear; |
| 1688 break; |
1688 break; |
| 1689 |
1689 |
| 1690 case GTK_WEBVIEW_ACTION_IMAGE: |
1690 case PIDGIN_WEBVIEW_ACTION_IMAGE: |
| 1691 act = priv->image; |
1691 act = priv->image; |
| 1692 break; |
1692 break; |
| 1693 |
1693 |
| 1694 case GTK_WEBVIEW_ACTION_LINK: |
1694 case PIDGIN_WEBVIEW_ACTION_LINK: |
| 1695 act = priv->link; |
1695 act = priv->link; |
| 1696 break; |
1696 break; |
| 1697 |
1697 |
| 1698 case GTK_WEBVIEW_ACTION_HR: |
1698 case PIDGIN_WEBVIEW_ACTION_HR: |
| 1699 act = priv->hr; |
1699 act = priv->hr; |
| 1700 break; |
1700 break; |
| 1701 |
1701 |
| 1702 case GTK_WEBVIEW_ACTION_SMILEY: |
1702 case PIDGIN_WEBVIEW_ACTION_SMILEY: |
| 1703 act = priv->smiley; |
1703 act = priv->smiley; |
| 1704 break; |
1704 break; |
| 1705 |
1705 |
| 1706 case GTK_WEBVIEW_ACTION_ATTENTION: |
1706 case PIDGIN_WEBVIEW_ACTION_ATTENTION: |
| 1707 act = priv->attention; |
1707 act = priv->attention; |
| 1708 break; |
1708 break; |
| 1709 |
1709 |
| 1710 default: |
1710 default: |
| 1711 g_return_if_reached(); |
1711 g_return_if_reached(); |