Update of /cvsroot/gaim/gaim/src
In directory sc8-pr-cvs1:/tmp/cvs-serv31695/src
Modified Files:
conversation.c gtkimhtml.c gtkimhtml.h
Log Message:
Smileys. These are just the default smileys--I'm adding the prpl-specific smileys right now.
If you want to help by creating some png's, IM me.
Index: conversation.c
===================================================================
RCS file: /cvsroot/gaim/gaim/src/conversation.c,v
retrieving revision 1.439
retrieving revision 1.440
diff -u -d -r1.439 -r1.440
--- conversation.c 1 Dec 2002 04:28:03 -0000 1.439
+++ conversation.c 3 Dec 2002 02:02:14 -0000 1.440
@@ -54,15 +54,6 @@
#include "win32dep.h"
#endif
-/*#include "pixmaps/save_small.xpm"*/
-
-#include "pixmaps/luke03.xpm"
-#include "pixmaps/oneeye.xpm"
-#include "pixmaps/crazy4.xpm"
-#include "pixmaps/mrt.xpm"
-#include "pixmaps/download.xpm"
-#include "pixmaps/farted.xpm"
-
int state_lock = 0;
GdkPixmap *dark_icon_pm = NULL;
@@ -98,15 +89,89 @@
void gaim_setup_imhtml_smileys(GtkWidget *imhtml)
{
- gtk_imhtml_associate_smiley(GTK_IMHTML(imhtml), "C:)", luke03_xpm);
- gtk_imhtml_associate_smiley(GTK_IMHTML(imhtml), "C:-)", luke03_xpm);
- gtk_imhtml_associate_smiley(GTK_IMHTML(imhtml), "O-)", oneeye_xpm);
- gtk_imhtml_associate_smiley(GTK_IMHTML(imhtml), ">:)", crazy4_xpm);
- gtk_imhtml_associate_smiley(GTK_IMHTML(imhtml), ">:-)", crazy4_xpm);
- gtk_imhtml_associate_smiley(GTK_IMHTML(imhtml), ":-o)))", mrt_xpm);
- gtk_imhtml_associate_smiley(GTK_IMHTML(imhtml), ":-O)))", mrt_xpm);
- gtk_imhtml_associate_smiley(GTK_IMHTML(imhtml), "8-|)", download_xpm);
- gtk_imhtml_associate_smiley(GTK_IMHTML(imhtml), ":-]", farted_xpm);
+ /* This is ugly right now--it will get better when the themable smileys come */
+
+
+ char *filename;
+ filename = g_build_filename(DATADIR, "pixmaps", "gaim", "smileys", "default", "smile.png", NULL);
+ gtk_imhtml_associate_smiley(GTK_IMHTML(imhtml), ":)", NULL, filename);
+ gtk_imhtml_associate_smiley(GTK_IMHTML(imhtml), ":-)", NULL, filename);
+
+ filename = g_build_filename(DATADIR, "pixmaps", "gaim", "smileys", "default", "sad.png", NULL);
+ gtk_imhtml_associate_smiley(GTK_IMHTML(imhtml), ":(", NULL, filename);
+ gtk_imhtml_associate_smiley(GTK_IMHTML(imhtml), ":-(", NULL, filename);
+
+ filename = g_build_filename(DATADIR, "pixmaps", "gaim", "smileys", "default", "wink.png", NULL);
+ gtk_imhtml_associate_smiley(GTK_IMHTML(imhtml), ";)", NULL, filename);
+ gtk_imhtml_associate_smiley(GTK_IMHTML(imhtml), ";-)", NULL, filename);
+
+ filename = g_build_filename(DATADIR, "pixmaps", "gaim", "smileys", "default", "tounge.png", NULL);
+ gtk_imhtml_associate_smiley(GTK_IMHTML(imhtml), ":-p", NULL, filename);
+ gtk_imhtml_associate_smiley(GTK_IMHTML(imhtml), ":-P", NULL, filename);
+
+ filename = g_build_filename(DATADIR, "pixmaps", "gaim", "smileys", "default", "scream.png", NULL);
+ gtk_imhtml_associate_smiley(GTK_IMHTML(imhtml), "=-O", NULL, filename);
+ gtk_imhtml_associate_smiley(GTK_IMHTML(imhtml), "=-o", NULL, filename);
+
+ filename = g_build_filename(DATADIR, "pixmaps", "gaim", "smileys", "default", "kiss.png", NULL);
+ gtk_imhtml_associate_smiley(GTK_IMHTML(imhtml), ":-*", NULL, filename);
+
+ filename = g_build_filename(DATADIR, "pixmaps", "gaim", "smileys", "default", "yell.png", NULL);
+ gtk_imhtml_associate_smiley(GTK_IMHTML(imhtml), ">:o", NULL, filename);
+ gtk_imhtml_associate_smiley(GTK_IMHTML(imhtml), ">:O", NULL, filename);
+
+ filename = g_build_filename(DATADIR, "pixmaps", "gaim", "smileys", "default", "cool.png", NULL);
+ gtk_imhtml_associate_smiley(GTK_IMHTML(imhtml), "8-)", NULL, filename);
+
+ filename = g_build_filename(DATADIR, "pixmaps", "gaim", "smileys", "default", "moneymouth.png", NULL);
+ gtk_imhtml_associate_smiley(GTK_IMHTML(imhtml), ":-$", NULL, filename);
+
+ filename = g_build_filename(DATADIR, "pixmaps", "gaim", "smileys", "default", "burp.png", NULL);
+ gtk_imhtml_associate_smiley(GTK_IMHTML(imhtml), ":-!", NULL, filename);
+
+ filename = g_build_filename(DATADIR, "pixmaps", "gaim", "smileys", "default", "embarrassed.png", NULL);
+ gtk_imhtml_associate_smiley(GTK_IMHTML(imhtml), ":-[", NULL, filename);
+
+ filename = g_build_filename(DATADIR, "pixmaps", "gaim", "smileys", "default", "cry.png", NULL);
+ gtk_imhtml_associate_smiley(GTK_IMHTML(imhtml), ":'(", NULL, filename);
+
+ filename = g_build_filename(DATADIR, "pixmaps", "gaim", "smileys", "default", "think.png", NULL);
+ gtk_imhtml_associate_smiley(GTK_IMHTML(imhtml), ":-/", NULL, filename);
+ gtk_imhtml_associate_smiley(GTK_IMHTML(imhtml), ":-\\", NULL, filename);
+
+ filename = g_build_filename(DATADIR, "pixmaps", "gaim", "smileys", "default", "crossedlips.png", NULL);
+ gtk_imhtml_associate_smiley(GTK_IMHTML(imhtml), ":-x", NULL, filename);
+ gtk_imhtml_associate_smiley(GTK_IMHTML(imhtml), ":-X", NULL, filename);
+
+ filename = g_build_filename(DATADIR, "pixmaps", "gaim", "smileys", "default", "bigsmile.png", NULL);
+ gtk_imhtml_associate_smiley(GTK_IMHTML(imhtml), ":-d", NULL, filename);
+ gtk_imhtml_associate_smiley(GTK_IMHTML(imhtml), ":-D", NULL, filename);
+
+ filename = g_build_filename(DATADIR, "pixmaps", "gaim", "smileys", "default", "angel.png", NULL);
+ gtk_imhtml_associate_smiley(GTK_IMHTML(imhtml), "O:-)", NULL, filename);
+
+
+ /* "Secret" smileys */
+ filename = g_build_filename(DATADIR, "pixmaps", "gaim", "smileys", "default", "luke.png", NULL);
+ gtk_imhtml_associate_smiley(GTK_IMHTML(imhtml), "C:)", NULL, filename);
+ gtk_imhtml_associate_smiley(GTK_IMHTML(imhtml), "C:-)", NULL, filename);
+
+ filename = g_build_filename(DATADIR, "pixmaps", "gaim", "smileys", "default", "oneeye.png", NULL);
+ gtk_imhtml_associate_smiley(GTK_IMHTML(imhtml), "O-)", NULL, filename);
+
+ filename = g_build_filename(DATADIR, "pixmaps", "gaim", "smileys", "default", "crazy.png", NULL);
+ gtk_imhtml_associate_smiley(GTK_IMHTML(imhtml), ">:)", NULL, filename);
+ gtk_imhtml_associate_smiley(GTK_IMHTML(imhtml), ">:-)", NULL, filename);
+
+ filename = g_build_filename(DATADIR, "pixmaps", "gaim", "smileys", "default", "mrt.png", NULL);
+ gtk_imhtml_associate_smiley(GTK_IMHTML(imhtml), ":-o)))", NULL, filename);
+ gtk_imhtml_associate_smiley(GTK_IMHTML(imhtml), ":-O)))", NULL, filename);
+
+ filename = g_build_filename(DATADIR, "pixmaps", "gaim", "smileys", "default", "download.png", NULL);
+ gtk_imhtml_associate_smiley(GTK_IMHTML(imhtml), "8-|)", NULL, filename);
+
+ filename = g_build_filename(DATADIR, "pixmaps", "gaim", "smileys", "default", "farted.png", NULL);
+ gtk_imhtml_associate_smiley(GTK_IMHTML(imhtml), ":-]", NULL, filename);
}
void gaim_setup_imhtml(GtkWidget *imhtml)
@@ -1797,6 +1862,7 @@
char buf2[BUF_LONG];
char mdate[64];
int unhighlight = 0;
+ char *withfonttag;
if (c->is_chat && (!c->gc || !g_slist_find(c->gc->buddy_chats, c)))
return;
@@ -1959,8 +2025,9 @@
g_free(str);
gtk_imhtml_append_text(GTK_IMHTML(c->text), buf2, -1, 0);
-
- logstr = gtk_imhtml_append_text(GTK_IMHTML(c->text), what, length, gtk_font_options);
+
+ withfonttag = g_strdup_printf("<font sml=\"%s\">%s</font>", c->gc->prpl->name, what);
+ logstr = gtk_imhtml_append_text(GTK_IMHTML(c->text), withfonttag, length, gtk_font_options);
gtk_imhtml_append_text(GTK_IMHTML(c->text), "<BR>", -1, 0);
@@ -1999,10 +2066,10 @@
if (logging_options & OPT_LOG_STRIP_HTML) {
t1 = strip_html(buf);
- t2 = strip_html(what);
+ t2 = strip_html(withfonttag);
} else {
t1 = html_logize(buf);
- t2 = html_logize(what);
+ t2 = html_logize(withfonttag);
}
fd = open_log_file(nm, c->is_chat);
if (fd) {
@@ -2018,8 +2085,11 @@
g_free(t2);
g_free(nm);
}
+
+ g_free(withfonttag);
}
+
if (!(flags & WFLAG_NOLOG) && ((c->is_chat && (chat_options & OPT_CHAT_POPUP)) ||
(!c->is_chat && (im_options & OPT_IM_POPUP))))
gdk_window_show(c->window->window);
@@ -3594,7 +3664,7 @@
struct _prpl_smiley *smile =
(struct _prpl_smiley *)smilies->data;
- gtk_imhtml_associate_smiley(GTK_IMHTML(c->text), smile->key, smile->xpm);
+ //gtk_imhtml_associate_smiley(GTK_IMHTML(c->text), smile->key, smile->xpm);
smilies = g_slist_next(smilies);
}
} else {
Index: gtkimhtml.c
===================================================================
RCS file: /cvsroot/gaim/gaim/src/gtkimhtml.c,v
retrieving revision 1.129
retrieving revision 1.130
diff -u -d -r1.129 -r1.130
--- gtkimhtml.c 11 Nov 2002 04:17:25 -0000 1.129
+++ gtkimhtml.c 3 Dec 2002 02:02:15 -0000 1.130
@@ -47,8 +47,76 @@
gchar *face;
gchar *fore;
gchar *back;
+ gchar *sml;
};
+struct _GtkSmileyTree {
+ GString *values;
+ GtkSmileyTree **children;
+ gchar *image;
+};
+
+static GtkSmileyTree*
+gtk_smiley_tree_new ()
+{
+ return g_new0 (GtkSmileyTree, 1);
+}
+
+static void
+gtk_smiley_tree_insert (GtkSmileyTree *tree,
+ const gchar *text,
+ const gchar *path)
+{
+ GtkSmileyTree *t = tree;
+ const gchar *x = text;
+
+ if (!strlen (x))
+ return;
+
+ while (*x) {
+ gchar *pos;
+ gint index;
+
+ if (!t->values)
+ t->values = g_string_new ("");
+
+ pos = strchr (t->values->str, *x);
+ if (!pos) {
+ t->values = g_string_append_c (t->values, *x);
+ index = t->values->len - 1;
+ t->children = g_realloc (t->children, t->values->len * sizeof (GtkSmileyTree *));
+ t->children [index] = g_new0 (GtkSmileyTree, 1);
+ } else
+ index = (int) pos - (int) t->values->str;
+
+ t = t->children [index];
+
+ x++;
+ }
+
+ t->image = path;
+}
+gtk_smiley_tree_destroy (GtkSmileyTree *tree)
+{
+ GSList *list = g_slist_append (NULL, tree);
+
+ while (list) {
+ GtkSmileyTree *t = list->data;
+ gint i;
+ list = g_slist_remove(list, t);
+ if (t->values) {
+ for (i = 0; i < t->values->len; i++)
+ list = g_slist_append (list, t->children [i]);
+ g_string_free (t->values, TRUE);
+ g_free (t->children);
+ }
+ g_free (t);
+ }
+}
+
+static GtkTextViewClass *parent_class = NULL;
+
+
/* GtkIMHtml has one signal--URL_CLICKED */
enum {
URL_CLICKED,
@@ -56,12 +124,24 @@
};
static guint signals [LAST_SIGNAL] = { 0 };
+static void
+gtk_imhtml_finalize (GObject *object)
+{
+ GtkIMHtml *imhtml = GTK_IMHTML(object);
+
+ g_hash_table_foreach_remove(imhtml->smiley_data, gtk_smiley_tree_destroy, NULL);
+ gtk_smiley_tree_destroy(imhtml->default_smilies);
+ G_OBJECT_CLASS(parent_class)->finalize (object);
+}
/* Boring GTK stuff */
static void gtk_imhtml_class_init (GtkIMHtmlClass *class)
{
GtkObjectClass *object_class;
+ GObjectClass *gobject_class;
object_class = (GtkObjectClass*) class;
+ gobject_class = (GObjectClass*) class;
+ parent_class = gtk_type_class(GTK_TYPE_TEXT_VIEW);
signals[URL_CLICKED] = gtk_signal_new("url_clicked",
GTK_RUN_FIRST,
GTK_CLASS_TYPE(object_class),
@@ -69,6 +149,7 @@
gtk_marshal_NONE__POINTER,
GTK_TYPE_NONE, 1,
GTK_TYPE_POINTER);
+ gobject_class->finalize = gtk_imhtml_finalize;
}
static void gtk_imhtml_init (GtkIMHtml *imhtml)
@@ -98,6 +179,8 @@
imhtml->hand_cursor = gdk_cursor_new (GDK_HAND2);
imhtml->arrow_cursor = gdk_cursor_new (GDK_LEFT_PTR);
+ imhtml->smiley_data = g_hash_table_new (g_str_hash, g_str_equal);
+ imhtml->default_smilies = gtk_smiley_tree_new();
}
GtkWidget *gtk_imhtml_new(void *a, void *b)
@@ -139,6 +222,149 @@
}
}
+static void
+gtk_smiley_tree_remove (GtkSmileyTree *tree,
+ const gchar *text)
+{
+ GtkSmileyTree *t = tree;
+ const gchar *x = text;
+ gint len = 0;
+
+ while (*x) {
+ gchar *pos;
+
+ if (!t->values)
+ return;
+
+ pos = strchr (t->values->str, *x);
+ if (pos)
+ t = t->children [(int) pos - (int) t->values->str];
+ else
+ return;
+
+ x++; len++;
+ }
+
+ if (t->image)
+ t->image = NULL;
+}
+
+static gint
+gtk_smiley_tree_lookup (GtkSmileyTree *tree,
+ const gchar *text)
+{
+ GtkSmileyTree *t = tree;
+ const gchar *x = text;
+ gint len = 0;
+
+ while (*x) {
+ gchar *pos;
+
+ if (!t->values)
+ break;
+
+ pos = strchr (t->values->str, *x);
+ if (pos)
+ t = t->children [(int) pos - (int) t->values->str];
+ else
+ break;
+
+ x++; len++;
+ }
+
+ if (t->image)
+ return len;
+
+ return 0;
+}
+
+void
+gtk_imhtml_associate_smiley (GtkIMHtml *imhtml,
+ gchar *text,
+ gchar *sml,
+ gchar *path)
+{
+ GtkSmileyTree *tree;
+ g_return_if_fail (imhtml != NULL);
+ g_return_if_fail (GTK_IS_IMHTML (imhtml));
+ g_return_if_fail (text != NULL);
+
+ if (sml == NULL)
+ tree = imhtml->default_smilies;
+ else if ((tree = g_hash_table_lookup(imhtml->smiley_data, sml))) {
+ } else {
+ tree = gtk_smiley_tree_new();
+ g_hash_table_insert(imhtml->smiley_data, sml, tree);
+ }
+
+ if (path == NULL)
+ gtk_smiley_tree_remove (tree, text);
+ else
+ gtk_smiley_tree_insert (tree, text, path);
+}
+
+static gboolean
+gtk_imhtml_is_smiley (GtkIMHtml *imhtml,
+ GSList *fonts,
+ const gchar *text,
+ gint *len)
+{
+ GtkSmileyTree *tree;
+ FontDetail *font;
+ char *sml = NULL;
+
+ if (fonts) {
+ font = fonts->data;
+ sml = font->sml;
+ }
+
+ if (sml == NULL)
+ tree = imhtml->default_smilies;
+ else {
+ tree = g_hash_table_lookup(imhtml->smiley_data, sml);
+ }
+ if (tree == NULL)
+ return FALSE;
+
+ *len = gtk_smiley_tree_lookup (tree, text);
+ return (*len > 0);
+}
+
+static gchar*
+gtk_smiley_tree_image (GtkIMHtml *imhtml,
+ const gchar *sml,
+ const gchar *text)
+{
+ GtkSmileyTree *t;
+ const gchar *x = text;
+
+ if (sml == NULL)
+ t = imhtml->default_smilies;
+ else
+ t = g_hash_table_lookup(imhtml->smiley_data, sml);
+
+
+ if (t == NULL)
+ return sml ? gtk_smiley_tree_image(imhtml, NULL, text) : NULL;
+
+ while (*x) {
+ gchar *pos;
+
+ if (!t->values) {
+ return sml ? gtk_smiley_tree_image(imhtml, NULL, text) : NULL;
+ }
+
+ pos = strchr (t->values->str, *x);
+ if (pos) {
+ t = t->children [(int) pos - (int) t->values->str];
+ } else {
+ return sml ? gtk_smiley_tree_image(imhtml, NULL, text) : NULL;
+ }
+ x++;
+ }
+
+ return t->image;
+}
#define VALID_TAG(x) if (!g_strncasecmp (string, x ">", strlen (x ">"))) { \
*tag = g_strndup (string, strlen (x)); \
*len = strlen (x) + 1; \
@@ -414,7 +640,7 @@
gchar *tag;
gchar *url = NULL;
gchar *bg = NULL;
- gint tlen, wpos=0;
+ gint tlen, smilelen, wpos=0;
gint type;
const gchar *c;
gchar amp;
@@ -557,6 +783,8 @@
g_free (font->fore);
if (font->back)
g_free (font->back);
+ if (font->sml)
+ g_free (font->sml);
g_free (font);
}
break;
@@ -584,14 +812,14 @@
break;
case 43: /* FONT (opt) */
{
- gchar *color, *back, *face, *size;
+ gchar *color, *back, *face, *size, *sml;
FontDetail *font, *oldfont = NULL;
color = gtk_imhtml_get_html_opt (tag, "COLOR=");
back = gtk_imhtml_get_html_opt (tag, "BACK=");
face = gtk_imhtml_get_html_opt (tag, "FACE=");
size = gtk_imhtml_get_html_opt (tag, "SIZE=");
-
- if (!(color || back || face || size))
+ sml = gtk_imhtml_get_html_opt (tag, "SML=");
+ if (!(color || back || face || size || sml))
break;
NEW_BIT (NEW_TEXT_BIT);
@@ -614,7 +842,12 @@
font->face = face;
else if (oldfont && oldfont->face)
font->face = g_strdup(oldfont->face);
-
+
+ if (sml)
+ font->sml = sml;
+ else if (oldfont && oldfont->sml)
+ font->sml = g_strdup(oldfont->sml);
+
if (size && !(options & GTK_IMHTML_NO_SIZES)) {
if (*size == '+') {
sscanf (size + 1, "%hd", &font->size);
@@ -678,7 +911,21 @@
}
c++;
pos++;
- } else if (*c) {
+ } else if (gtk_imhtml_is_smiley (imhtml, fonts, c, &smilelen) || gtk_imhtml_is_smiley(imhtml, NULL, c, &smilelen)) {
+ FontDetail *fd;
+ gchar *sml = NULL;
+ if (fonts) {
+ fd = fonts->data;
+ sml = fd->sml;
+ }
+ NEW_BIT (NEW_TEXT_BIT);
+ wpos = g_snprintf (ws, smilelen + 1, "%s", c);
+ gtk_text_buffer_insert_pixbuf(imhtml->text_buffer, &iter, gdk_pixbuf_new_from_file(gtk_smiley_tree_image (imhtml, sml, ws), NULL));
+ c += smilelen;
+ pos += smilelen;
+ wpos = 0;
+ ws[0] = 0;
+ } else if (*c) {
ws [wpos++] = *c++;
pos++;
} else {
@@ -693,6 +940,22 @@
str = g_string_append (str, "</A>");
}
+ while (fonts) {
+ FontDetail *font = fonts->data;
+ fonts = g_slist_remove (fonts, font);
+ if (font->face)
+ g_free (font->face);
+ if (font->fore)
+ g_free (font->fore);
+ if (font->back)
+ g_free (font->back);
+ if (font->sml)
+ g_free (font->sml);
+ g_free (font);
+ if (str)
+ str = g_string_append (str, "</FONT>");
+ }
+
if (str) {
while (bold) {
str = g_string_append (str, "</B>");
@@ -727,9 +990,10 @@
pre--;
}
}
- g_free(ws);
- gtk_text_view_scroll_to_mark (GTK_TEXT_VIEW (imhtml), mark,
- 0, TRUE, 0.0, 1.0);
+ g_free (ws);
+ if (!(options & GTK_IMHTML_NO_SCROLL))
+ gtk_text_view_scroll_to_mark (GTK_TEXT_VIEW (imhtml), mark,
+ 0, TRUE, 0.0, 1.0);
gtk_text_buffer_delete_mark (imhtml->text_buffer, mark);
return str;
}
@@ -746,9 +1010,6 @@
void gtk_imhtml_set_img_handler (GtkIMHtml *imhtml,
GtkIMHtmlImage handler){}
-void gtk_imhtml_associate_smiley (GtkIMHtml *imhtml,
- gchar *text,
- gchar **xpm){}
void gtk_imhtml_init_smileys (GtkIMHtml *imhtml){}
void gtk_imhtml_remove_smileys (GtkIMHtml *imhtml){}
void gtk_imhtml_reset_smileys (GtkIMHtml *imhtml){}
Index: gtkimhtml.h
===================================================================
RCS file: /cvsroot/gaim/gaim/src/gtkimhtml.h,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -d -r1.20 -r1.21
--- gtkimhtml.h 8 Nov 2002 06:10:34 -0000 1.20
+++ gtkimhtml.h 3 Dec 2002 02:02:16 -0000 1.21
@@ -49,6 +49,8 @@
gboolean comments, smileys;
GdkCursor *hand_cursor;
GdkCursor *arrow_cursor;
+ GHashTable *smiley_data;
+ GtkSmileyTree *default_smilies;
};
struct _GtkIMHtmlClass {
@@ -85,8 +87,9 @@
GtkIMHtmlImage handler);
void gtk_imhtml_associate_smiley (GtkIMHtml *imhtml,
+ gchar *sml,
gchar *text,
- gchar **xpm);
+ gchar *path);
void gtk_imhtml_init_smileys (GtkIMHtml *imhtml);
|