Mercurial > pidgin.yaz
comparison src/conversation.c @ 1428:00b3d02a2168
[gaim-migrate @ 1438]
gtkhtml has gotten replaced by gtkimhtml.
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Fri, 26 Jan 2001 02:02:36 +0000 |
parents | ebfde8fc7e73 |
children | 0137bacd63c8 |
comparison
equal
deleted
inserted
replaced
1427:28278bd61403 | 1428:00b3d02a2168 |
---|---|
29 #include <unistd.h> | 29 #include <unistd.h> |
30 #include <stdio.h> | 30 #include <stdio.h> |
31 #include <stdlib.h> | 31 #include <stdlib.h> |
32 #include <ctype.h> | 32 #include <ctype.h> |
33 #include <gtk/gtk.h> | 33 #include <gtk/gtk.h> |
34 #include "gtkhtml.h" | 34 #include "gtkimhtml.h" |
35 #include <gdk/gdkkeysyms.h> | 35 #include <gdk/gdkkeysyms.h> |
36 #include "convo.h" | 36 #include "convo.h" |
37 #include "gtkspell.h" | 37 #include "gtkspell.h" |
38 #include "prpl.h" | 38 #include "prpl.h" |
39 | 39 |
50 #include "pixmaps/link.xpm" | 50 #include "pixmaps/link.xpm" |
51 #include "pixmaps/strike.xpm" | 51 #include "pixmaps/strike.xpm" |
52 #include "pixmaps/fgcolor.xpm" | 52 #include "pixmaps/fgcolor.xpm" |
53 #include "pixmaps/bgcolor.xpm" | 53 #include "pixmaps/bgcolor.xpm" |
54 | 54 |
55 #include "pixmaps/angel.xpm" | |
56 #include "pixmaps/bigsmile.xpm" | |
57 #include "pixmaps/burp.xpm" | |
58 #include "pixmaps/crossedlips.xpm" | |
59 #include "pixmaps/cry.xpm" | |
60 #include "pixmaps/embarrassed.xpm" | |
61 #include "pixmaps/kiss.xpm" | |
62 #include "pixmaps/moneymouth.xpm" | |
63 #include "pixmaps/sad.xpm" | |
64 #include "pixmaps/scream.xpm" | |
65 #include "pixmaps/smile.xpm" | |
66 #include "pixmaps/smile8.xpm" | |
67 #include "pixmaps/think.xpm" | |
68 #include "pixmaps/tongue.xpm" | |
69 #include "pixmaps/wink.xpm" | |
70 #include "pixmaps/yell.xpm" | |
71 #include "pixmaps/luke03.xpm" | 55 #include "pixmaps/luke03.xpm" |
72 #include "pixmaps/oneeye.xpm" | 56 #include "pixmaps/oneeye.xpm" |
73 | 57 |
74 int state_lock = 0; | 58 int state_lock = 0; |
75 | 59 |
483 if (event->keyval == GDK_Escape) { | 467 if (event->keyval == GDK_Escape) { |
484 if (general_options & OPT_GEN_ESC_CAN_CLOSE) { | 468 if (general_options & OPT_GEN_ESC_CAN_CLOSE) { |
485 gtk_signal_emit_stop_by_name(GTK_OBJECT(entry), "key_press_event"); | 469 gtk_signal_emit_stop_by_name(GTK_OBJECT(entry), "key_press_event"); |
486 close_callback(c->window, c); | 470 close_callback(c->window, c); |
487 } | 471 } |
472 } else if (event->keyval == GDK_F2) { | |
473 gtk_imhtml_show_comments(GTK_IMHTML(c->text), !(GTK_IMHTML(c->text))->comments); | |
488 } else if (event->keyval == GDK_Return) { | 474 } else if (event->keyval == GDK_Return) { |
489 if (!(event->state & GDK_SHIFT_MASK) | 475 if (!(event->state & GDK_SHIFT_MASK) |
490 && (general_options & OPT_GEN_ENTER_SENDS)) { | 476 && (general_options & OPT_GEN_ENTER_SENDS)) { |
491 gtk_signal_emit_by_name(GTK_OBJECT(entry), "activate", c); | 477 gtk_signal_emit_by_name(GTK_OBJECT(entry), "activate", c); |
492 //to stop the putting in of the enter character | 478 //to stop the putting in of the enter character |
1118 /*------------------------------------------------------------------------*/ | 1104 /*------------------------------------------------------------------------*/ |
1119 /* Takin care of the window.. */ | 1105 /* Takin care of the window.. */ |
1120 /*------------------------------------------------------------------------*/ | 1106 /*------------------------------------------------------------------------*/ |
1121 | 1107 |
1122 | 1108 |
1123 static GdkPixmap *is_smiley(GtkWidget *window, char *m, int *len, GdkColor * trans) | |
1124 { | |
1125 GdkBitmap *mask; | |
1126 GdkPixmap *face = NULL; | |
1127 | |
1128 if (strlen(m) < 2) | |
1129 return face; | |
1130 *len = 2; | |
1131 if (!strncmp(m, ":)", 2)) { | |
1132 face = gdk_pixmap_create_from_xpm_d(window->window, &mask, trans, smile_xpm); | |
1133 } else if (!strncmp(m, ":(", 2)) { | |
1134 face = gdk_pixmap_create_from_xpm_d(window->window, &mask, trans, sad_xpm); | |
1135 } else if (!strncmp(m, ";)", 2)) { | |
1136 face = gdk_pixmap_create_from_xpm_d(window->window, &mask, trans, wink_xpm); | |
1137 } | |
1138 | |
1139 if (face || strlen(m) < 3) | |
1140 return face; | |
1141 *len = 3; | |
1142 if (!strncmp(m, ":-)", 3)) { | |
1143 face = gdk_pixmap_create_from_xpm_d(window->window, &mask, trans, smile_xpm); | |
1144 } else if (!strncmp(m, "O-)", 3)) { | |
1145 face = gdk_pixmap_create_from_xpm_d(window->window, &mask, trans, oneeye_xpm); | |
1146 } else if (!strncmp(m, "C:)", 3)) { | |
1147 face = gdk_pixmap_create_from_xpm_d(window->window, &mask, trans, luke03_xpm); | |
1148 } else if (!strncmp(m, ":-(", 3)) { | |
1149 face = gdk_pixmap_create_from_xpm_d(window->window, &mask, trans, sad_xpm); | |
1150 } else if (!strncmp(m, ";-)", 3)) { | |
1151 face = gdk_pixmap_create_from_xpm_d(window->window, &mask, trans, wink_xpm); | |
1152 } else if (!strncmp(m, ":-p", 3) || !strncmp(m, ":-P", 3)) { | |
1153 face = gdk_pixmap_create_from_xpm_d(window->window, &mask, trans, tongue_xpm); | |
1154 } else if (!strncmp(m, "=-O", 3)) { | |
1155 face = gdk_pixmap_create_from_xpm_d(window->window, &mask, trans, scream_xpm); | |
1156 } else if (!strncmp(m, ":-*", 3)) { | |
1157 face = gdk_pixmap_create_from_xpm_d(window->window, &mask, trans, kiss_xpm); | |
1158 } else if (!strncmp(m, ">:o", 3)) { | |
1159 face = gdk_pixmap_create_from_xpm_d(window->window, &mask, trans, yell_xpm); | |
1160 } else if (!strncmp(m, "8-)", 3)) { | |
1161 face = gdk_pixmap_create_from_xpm_d(window->window, &mask, trans, smile8_xpm); | |
1162 } else if (!strncmp(m, ":-$", 3)) { | |
1163 face = gdk_pixmap_create_from_xpm_d(window->window, &mask, trans, moneymouth_xpm); | |
1164 } else if (!strncmp(m, ":-!", 3)) { | |
1165 face = gdk_pixmap_create_from_xpm_d(window->window, &mask, trans, burp_xpm); | |
1166 } else if (!strncmp(m, ":-[", 3)) { | |
1167 face = gdk_pixmap_create_from_xpm_d(window->window, &mask, trans, embarrassed_xpm); | |
1168 } else if (!strncmp(m, ":'(", 3)) { | |
1169 face = gdk_pixmap_create_from_xpm_d(window->window, &mask, trans, cry_xpm); | |
1170 } else if (!strncmp(m, ":-\\", 3) || !strncmp(m, ":-/", 3)) { | |
1171 face = gdk_pixmap_create_from_xpm_d(window->window, &mask, trans, think_xpm); | |
1172 } else if (!strncmp(m, ":-X", 3)) { | |
1173 face = gdk_pixmap_create_from_xpm_d(window->window, &mask, trans, crossedlips_xpm); | |
1174 } else if (!strncmp(m, ":-D", 3)) { | |
1175 face = gdk_pixmap_create_from_xpm_d(window->window, &mask, trans, bigsmile_xpm); | |
1176 } | |
1177 | |
1178 if (face || strlen(m) < 4) | |
1179 return face; | |
1180 *len = 4; | |
1181 if (!strncmp(m, "O:-)", 4)) { | |
1182 face = gdk_pixmap_create_from_xpm_d(window->window, &mask, trans, angel_xpm); | |
1183 } else if (!strncmp(m, "C:-)", 4)) { | |
1184 face = gdk_pixmap_create_from_xpm_d(window->window, &mask, trans, luke03_xpm); | |
1185 } | |
1186 | |
1187 if (face || strlen(m) < 6) | |
1188 return face; | |
1189 *len = 6; | |
1190 if (!strncmp(m, ">:o", 6)) { | |
1191 face = gdk_pixmap_create_from_xpm_d(window->window, &mask, trans, yell_xpm); | |
1192 } | |
1193 | |
1194 return face; | |
1195 } | |
1196 | |
1197 void write_html_with_smileys(GtkWidget *window, GtkWidget *html, char *what) | |
1198 { | |
1199 int y = 0; | |
1200 char *buf2 = g_strdup(what); | |
1201 int i; | |
1202 GdkPixmap *face; | |
1203 /* hopefully we can later use this for bgcolors in smileys */ | |
1204 GdkColor *trans = &window->style->base[GTK_STATE_NORMAL]; | |
1205 gboolean in_tag = FALSE; | |
1206 int gtk_font_options = 0; | |
1207 | |
1208 if (display_options & OPT_DISP_IGNORE_COLOUR) | |
1209 gtk_font_options = gtk_font_options ^ HTML_OPTION_NO_COLOURS; | |
1210 | |
1211 if (display_options & OPT_DISP_IGNORE_FONTS) | |
1212 gtk_font_options = gtk_font_options ^ HTML_OPTION_NO_FONTS; | |
1213 | |
1214 for (i = 0; i < strlen(what); i++) { | |
1215 if (!in_tag) { | |
1216 int len; | |
1217 if (what[i] == '<') { | |
1218 buf2[y] = what[i]; | |
1219 y++; | |
1220 in_tag = TRUE; | |
1221 } else if ((face = is_smiley(window, &what[i], &len, trans)) != NULL) { | |
1222 | |
1223 buf2[y] = 0; | |
1224 gtk_html_append_text(GTK_HTML(html), buf2, gtk_font_options); | |
1225 gtk_html_add_pixmap(GTK_HTML(html), face, 0, 0); | |
1226 y = 0; | |
1227 i += len - 1; | |
1228 } else { | |
1229 buf2[y] = what[i]; | |
1230 y++; | |
1231 } | |
1232 } else { | |
1233 buf2[y] = what[i]; | |
1234 y++; | |
1235 if (what[i] == '>') | |
1236 in_tag = FALSE; | |
1237 } | |
1238 } | |
1239 | |
1240 if (y) { | |
1241 buf2[y] = 0; | |
1242 gtk_html_append_text(GTK_HTML(html), buf2, gtk_font_options); | |
1243 } | |
1244 g_free(buf2); | |
1245 } | |
1246 | |
1247 /* this is going to be interesting since the conversation could either be a | 1109 /* this is going to be interesting since the conversation could either be a |
1248 * normal IM conversation or a chat window. but hopefully it won't matter */ | 1110 * normal IM conversation or a chat window. but hopefully it won't matter */ |
1249 void write_to_conv(struct conversation *c, char *what, int flags, char *who) | 1111 void write_to_conv(struct conversation *c, char *what, int flags, char *who) |
1250 { | 1112 { |
1251 char *buf = g_malloc(BUF_LONG); | 1113 char *buf = g_malloc(BUF_LONG); |
1258 char *smiley = g_malloc(7); | 1120 char *smiley = g_malloc(7); |
1259 struct buddy *b; | 1121 struct buddy *b; |
1260 int gtk_font_options = 0; | 1122 int gtk_font_options = 0; |
1261 | 1123 |
1262 if (display_options & OPT_DISP_IGNORE_COLOUR) | 1124 if (display_options & OPT_DISP_IGNORE_COLOUR) |
1263 gtk_font_options = gtk_font_options ^ HTML_OPTION_NO_COLOURS; | 1125 gtk_font_options = gtk_font_options ^ GTK_IMHTML_NO_COLOURS; |
1264 | 1126 |
1265 if (display_options & OPT_DISP_IGNORE_FONTS) | 1127 if (display_options & OPT_DISP_IGNORE_FONTS) |
1266 gtk_font_options = gtk_font_options ^ HTML_OPTION_NO_FONTS; | 1128 gtk_font_options = gtk_font_options ^ GTK_IMHTML_NO_FONTS; |
1129 | |
1130 gtk_font_options = gtk_font_options ^ GTK_IMHTML_NO_COMMENTS; | |
1131 gtk_font_options = gtk_font_options ^ GTK_IMHTML_NO_TITLE; | |
1132 | |
1133 if (display_options & OPT_DISP_IGNORE_SIZES) | |
1134 gtk_font_options = gtk_font_options ^ GTK_IMHTML_NO_SIZES; | |
1267 | 1135 |
1268 | 1136 |
1269 if (!who) { | 1137 if (!who) { |
1270 if (flags & WFLAG_SEND) { | 1138 if (flags & WFLAG_SEND) { |
1271 b = find_buddy(c->gc, c->gc->username); | 1139 b = find_buddy(c->gc, c->gc->username); |
1286 who = b->show; | 1154 who = b->show; |
1287 } | 1155 } |
1288 | 1156 |
1289 if (flags & WFLAG_SYSTEM) { | 1157 if (flags & WFLAG_SYSTEM) { |
1290 | 1158 |
1291 gtk_html_freeze(GTK_HTML(c->text)); | 1159 gtk_imhtml_append_text(GTK_IMHTML(c->text), what, 0); |
1292 | 1160 |
1293 gtk_html_append_text(GTK_HTML(c->text), what, 0); | 1161 gtk_imhtml_append_text(GTK_IMHTML(c->text), "<BR>", 0); |
1294 | |
1295 gtk_html_append_text(GTK_HTML(c->text), "<BR>", 0); | |
1296 | 1162 |
1297 if ((general_options & OPT_GEN_LOG_ALL) || find_log_info(c->name)) { | 1163 if ((general_options & OPT_GEN_LOG_ALL) || find_log_info(c->name)) { |
1298 char *t1; | 1164 char *t1; |
1299 char nm[256]; | 1165 char nm[256]; |
1300 | 1166 |
1356 else if (flags & WFLAG_SEND) | 1222 else if (flags & WFLAG_SEND) |
1357 strcpy(colour, "#0000ff"); | 1223 strcpy(colour, "#0000ff"); |
1358 } | 1224 } |
1359 } | 1225 } |
1360 | 1226 |
1361 if (display_options & OPT_DISP_SHOW_TIME) | 1227 g_snprintf(buf, BUF_LONG, "<FONT COLOR=\"%s\"><FONT SIZE=\"2\"><!--(%s) --></FONT>" |
1362 g_snprintf(buf, BUF_LONG, "<FONT COLOR=\"%s\"><B>%s %s</B></FONT> ", colour, | 1228 "<B>%s</B></FONT> ", colour, date(), str); |
1363 date(), str); | |
1364 else | |
1365 g_snprintf(buf, BUF_LONG, "<FONT COLOR=\"%s\"><B>%s</B></FONT>", colour, str); | |
1366 | 1229 |
1367 g_free(str); | 1230 g_free(str); |
1368 | 1231 |
1369 gtk_html_freeze(GTK_HTML(c->text)); | 1232 gtk_imhtml_append_text(GTK_IMHTML(c->text), buf, 0); |
1370 | 1233 |
1371 if (colorv != -1) { | 1234 gtk_imhtml_append_text(GTK_IMHTML(c->text), what, gtk_font_options); |
1372 sprintf(buf2, "<BODY BGCOLOR=\"#%x\">", colorv); | 1235 |
1373 gtk_html_append_text(GTK_HTML(c->text), buf2, gtk_font_options); | 1236 gtk_imhtml_append_text(GTK_IMHTML(c->text), "<BR>", 0); |
1374 } | |
1375 | |
1376 gtk_html_append_text(GTK_HTML(c->text), buf, 0); | |
1377 | |
1378 if (display_options & OPT_DISP_SHOW_SMILEY) { | |
1379 write_html_with_smileys(c->window, c->text, what); | |
1380 } else { | |
1381 gtk_html_append_text(GTK_HTML(c->text), what, gtk_font_options); | |
1382 } | |
1383 | |
1384 if (colorv != -1) { | |
1385 gtk_html_append_text(GTK_HTML(c->text), "</BODY>", gtk_font_options); | |
1386 } | |
1387 gtk_html_append_text(GTK_HTML(c->text), "<BR>", gtk_font_options); | |
1388 | |
1389 | 1237 |
1390 if ((general_options & OPT_GEN_LOG_ALL) || find_log_info(c->name)) { | 1238 if ((general_options & OPT_GEN_LOG_ALL) || find_log_info(c->name)) { |
1391 char *t1, *t2; | 1239 char *t1, *t2; |
1392 char *nm = g_malloc(256); | 1240 char *nm = g_malloc(256); |
1393 if (c->is_chat) | 1241 if (c->is_chat) |
1427 */ | 1275 */ |
1428 | 1276 |
1429 if ((c->is_chat && (general_options & OPT_GEN_POPUP_CHAT)) || | 1277 if ((c->is_chat && (general_options & OPT_GEN_POPUP_CHAT)) || |
1430 (!c->is_chat && (general_options & OPT_GEN_POPUP_WINDOWS))) | 1278 (!c->is_chat && (general_options & OPT_GEN_POPUP_WINDOWS))) |
1431 gdk_window_show(c->window->window); | 1279 gdk_window_show(c->window->window); |
1432 | |
1433 gtk_html_thaw(GTK_HTML(c->text)); | |
1434 | 1280 |
1435 g_free(smiley); | 1281 g_free(smiley); |
1436 g_free(buf); | 1282 g_free(buf); |
1437 } | 1283 } |
1438 | 1284 |
1864 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS); | 1710 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS); |
1865 gtk_box_pack_start(GTK_BOX(vbox), sw, TRUE, TRUE, 0); | 1711 gtk_box_pack_start(GTK_BOX(vbox), sw, TRUE, TRUE, 0); |
1866 gtk_widget_set_usize(sw, 320, 175); | 1712 gtk_widget_set_usize(sw, 320, 175); |
1867 gtk_widget_show(sw); | 1713 gtk_widget_show(sw); |
1868 | 1714 |
1869 text = gtk_html_new(NULL, NULL); | 1715 text = gtk_imhtml_new(NULL, NULL); |
1870 c->text = text; | 1716 c->text = text; |
1871 gtk_html_set_editable(GTK_HTML(text), FALSE); | |
1872 gtk_container_add(GTK_CONTAINER(sw), text); | 1717 gtk_container_add(GTK_CONTAINER(sw), text); |
1873 GTK_HTML(text)->hadj->step_increment = 10.0; | 1718 GTK_LAYOUT(text)->hadjustment->step_increment = 10.0; |
1874 GTK_HTML(text)->vadj->step_increment = 10.0; | 1719 GTK_LAYOUT(text)->vadjustment->step_increment = 10.0; |
1720 if (!(display_options & OPT_DISP_SHOW_SMILEY)) | |
1721 gtk_imhtml_show_smileys(GTK_IMHTML(text), FALSE); | |
1722 if (display_options & OPT_DISP_SHOW_TIME) | |
1723 gtk_imhtml_show_comments(GTK_IMHTML(text), TRUE); | |
1724 gtk_signal_connect(GTK_OBJECT(text), "url_clicked", GTK_SIGNAL_FUNC(open_url_nw), NULL); | |
1725 gtk_imhtml_associate_smiley(GTK_IMHTML(text), "C:)", luke03_xpm); | |
1726 gtk_imhtml_associate_smiley(GTK_IMHTML(text), "C:-)", luke03_xpm); | |
1727 gtk_imhtml_associate_smiley(GTK_IMHTML(text), "O-)", oneeye_xpm); | |
1875 gtk_widget_show(text); | 1728 gtk_widget_show(text); |
1876 | 1729 |
1877 vbox2 = gtk_vbox_new(FALSE, 5); | 1730 vbox2 = gtk_vbox_new(FALSE, 5); |
1878 gtk_paned_pack2(GTK_PANED(paned), vbox2, FALSE, FALSE); | 1731 gtk_paned_pack2(GTK_PANED(paned), vbox2, FALSE, FALSE); |
1879 gtk_widget_show(vbox2); | 1732 gtk_widget_show(vbox2); |
2003 cht = cht->next; | 1856 cht = cht->next; |
2004 } | 1857 } |
2005 con = con->next; | 1858 con = con->next; |
2006 } | 1859 } |
2007 } | 1860 } |
1861 | |
1862 void toggle_timestamps() | |
1863 { | |
1864 GList *cnv = conversations; | |
1865 GSList *cht; | |
1866 struct conversation *c; | |
1867 GSList *con = connections; | |
1868 struct gaim_connection *gc; | |
1869 | |
1870 while (cnv) { | |
1871 c = (struct conversation *)cnv->data; | |
1872 if (display_options & OPT_DISP_SHOW_TIME) | |
1873 gtk_imhtml_show_comments(GTK_IMHTML(c->text), TRUE); | |
1874 else | |
1875 gtk_imhtml_show_comments(GTK_IMHTML(c->text), FALSE); | |
1876 cnv = cnv->next; | |
1877 } | |
1878 | |
1879 while (con) { | |
1880 gc = (struct gaim_connection *)con->data; | |
1881 cht = gc->buddy_chats; | |
1882 while (cht) { | |
1883 c = (struct conversation *)cht->data; | |
1884 if (display_options & OPT_DISP_SHOW_TIME) | |
1885 gtk_imhtml_show_comments(GTK_IMHTML(c->text), TRUE); | |
1886 else | |
1887 gtk_imhtml_show_comments(GTK_IMHTML(c->text), FALSE); | |
1888 cht = cht->next; | |
1889 } | |
1890 con = con->next; | |
1891 } | |
1892 } | |
1893 | |
1894 void toggle_smileys() | |
1895 { | |
1896 GList *cnv = conversations; | |
1897 GSList *cht; | |
1898 struct conversation *c; | |
1899 GSList *con = connections; | |
1900 struct gaim_connection *gc; | |
1901 | |
1902 while (cnv) { | |
1903 c = (struct conversation *)cnv->data; | |
1904 if (display_options & OPT_DISP_SHOW_SMILEY) | |
1905 gtk_imhtml_show_smileys(GTK_IMHTML(c->text), TRUE); | |
1906 else | |
1907 gtk_imhtml_show_smileys(GTK_IMHTML(c->text), FALSE); | |
1908 cnv = cnv->next; | |
1909 } | |
1910 | |
1911 while (con) { | |
1912 gc = (struct gaim_connection *)con->data; | |
1913 cht = gc->buddy_chats; | |
1914 while (cht) { | |
1915 c = (struct conversation *)cht->data; | |
1916 if (display_options & OPT_DISP_SHOW_SMILEY) | |
1917 gtk_imhtml_show_smileys(GTK_IMHTML(c->text), TRUE); | |
1918 else | |
1919 gtk_imhtml_show_smileys(GTK_IMHTML(c->text), FALSE); | |
1920 cht = cht->next; | |
1921 } | |
1922 con = con->next; | |
1923 } | |
1924 } |