changeset 8456:5f8d4ab6d375

[gaim-migrate @ 9186] "his patch fixes an issue where the gtkimhtml and the gtkimtoolbar did not know what protocol the conversation was for so they we're either displaying core smileys or white boxes with an x through them. this also make gtkimthml honor the ctrl-{b/u/i} and ctrl-number prefs." --Gary Kramlich who continues: "in the first patch i forgot to adjust the protocol name in the conversation when an item in the send as menu was selected. This fixes that." committer: Tailor Script <tailor@pidgin.im>
author Luke Schierer <lschiere@pidgin.im>
date Tue, 16 Mar 2004 19:35:17 +0000
parents 622fd4e800b4
children daeeb96cdf8f
files src/gtkconv.c src/gtkimhtml.c src/gtkimhtml.h src/gtkimhtmltoolbar.c
diffstat 4 files changed, 115 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/src/gtkconv.c	Tue Mar 16 19:19:36 2004 +0000
+++ b/src/gtkconv.c	Tue Mar 16 19:35:17 2004 +0000
@@ -1494,10 +1494,17 @@
 	GaimConvWindow *win = g_object_get_data(m, "user_data");
 	GaimAccount *account = g_object_get_data(m, "gaim_account");
 	GaimConversation *conv;
+	GaimGtkConversation *gtkconv;
+	GaimPlugin *protocol;
 
 	conv = gaim_conv_window_get_active_conversation(win);
 
 	gaim_conversation_set_account(conv, account);
+
+	gtkconv = GAIM_GTK_CONVERSATION(conv);
+	protocol = gaim_find_prpl(conv->account->protocol_id);
+	gtk_imhtml_set_protocol_name(GTK_IMHTML(gtkconv->entry),
+								 protocol->info->name);
 }
 
 static void
@@ -3453,6 +3460,7 @@
 	GaimGtkConversation *gtkconv;
 	GaimGtkChatPane *gtkchat;
 	GaimConnection *gc;
+	GaimPlugin *protocol;
 	GtkWidget *vpaned, *hpaned;
 	GtkWidget *vbox, *hbox;
 	GtkWidget *lbox, *bbox;
@@ -3655,6 +3663,14 @@
 	gtk_widget_show(sw);
 
 	gtkconv->entry = gtk_imhtml_new(NULL, NULL);
+	gtk_imhtml_smiley_shortcuts(GTK_IMHTML(gtkconv->entry),
+			gaim_prefs_get_bool("/gaim/gtk/conversations/smiley_shortcuts"));
+	gtk_imhtml_html_shortcuts(GTK_IMHTML(gtkconv->entry),
+			gaim_prefs_get_bool("/gaim/gtk/conversations/html_shortcuts"));
+
+	protocol = gaim_find_prpl(conv->account->protocol_id);
+	gtk_imhtml_set_protocol_name(GTK_IMHTML(gtkconv->entry),
+								 protocol->info->name);
 	gtkconv->entry_buffer =
 		gtk_text_view_get_buffer(GTK_TEXT_VIEW(gtkconv->entry));
 	gaim_setup_imhtml(gtkconv->entry);
@@ -3696,6 +3712,7 @@
 {
 	GaimGtkConversation *gtkconv;
 	GaimGtkImPane *gtkim;
+	GaimPlugin *protocol;
 	GtkWidget *paned;
 	GtkWidget *vbox;
 	GtkWidget *vbox2;
@@ -3765,6 +3782,15 @@
 	gtk_widget_show(sw);
 
 	gtkconv->entry = gtk_imhtml_new(NULL, NULL);
+
+	gtk_imhtml_smiley_shortcuts(GTK_IMHTML(gtkconv->entry),
+			gaim_prefs_get_bool("/gaim/gtk/conversations/smiley_shortcuts"));
+	gtk_imhtml_html_shortcuts(GTK_IMHTML(gtkconv->entry),
+			gaim_prefs_get_bool("/gaim/gtk/conversations/html_shortcuts"));
+
+	protocol = gaim_find_prpl(conv->account->protocol_id);
+	gtk_imhtml_set_protocol_name(GTK_IMHTML(gtkconv->entry),
+								 protocol->info->name);
 	gtkconv->entry_buffer =
 		gtk_text_view_get_buffer(GTK_TEXT_VIEW(gtkconv->entry));
 	gaim_setup_imhtml(gtkconv->entry);
@@ -5534,6 +5560,48 @@
 }
 
 static void
+html_shortcuts_pref_cb(const char *name, GaimPrefType type,
+					   gpointer value, gpointer data)
+{
+	GList *l;
+	GaimConversation *conv;
+	GaimGtkConversation *gtkconv;
+	
+	for(l = gaim_get_conversations(); l != NULL; l = l->next) {
+		conv = (GaimConversation *)l->data;
+		
+		if(!GAIM_IS_GTK_CONVERSATION(conv))
+			continue;
+		
+		gtkconv = GAIM_GTK_CONVERSATION(conv);
+		
+		gtk_imhtml_html_shortcuts(GTK_IMHTML(gtkconv->entry),
+								  (gboolean)GPOINTER_TO_INT(value));
+	}
+}
+
+static void
+smiley_shortcuts_pref_cb(const char *name, GaimPrefType type,
+						 gpointer value, gpointer data)
+{
+	GList *l;
+	GaimConversation *conv;
+	GaimGtkConversation *gtkconv;
+	
+	for(l = gaim_get_conversations(); l != NULL; l = l->next) {
+		conv = (GaimConversation *)l->data;
+		
+		if(!GAIM_IS_GTK_CONVERSATION(conv))
+			continue;
+		
+		gtkconv = GAIM_GTK_CONVERSATION(conv);
+		
+		gtk_imhtml_smiley_shortcuts(GTK_IMHTML(gtkconv->entry), 
+									(gboolean)GPOINTER_TO_INT(value));
+	}
+}
+
+static void
 show_formatting_toolbar_pref_cb(const char *name, GaimPrefType type,
 								gpointer value, gpointer data)
 {
@@ -5728,6 +5796,10 @@
 								show_smileys_pref_cb, NULL);
 	gaim_prefs_connect_callback("/gaim/gtk/conversations/show_timestamps",
 								show_timestamps_pref_cb, NULL);
+	gaim_prefs_connect_callback("/gaim/gtk/conversations/html_shortcuts",
+								html_shortcuts_pref_cb, NULL);
+	gaim_prefs_connect_callback("/gaim/gtk/conversations/smiley_shortcuts",
+								smiley_shortcuts_pref_cb, NULL);
 	gaim_prefs_connect_callback("/gaim/gtk/conversations/show_formatting_toolbar",
 								show_formatting_toolbar_pref_cb, NULL);
 	gaim_prefs_connect_callback("/gaim/gtk/conversations/spellcheck",
--- a/src/gtkimhtml.c	Tue Mar 16 19:19:36 2004 +0000
+++ b/src/gtkimhtml.c	Tue Mar 16 19:35:17 2004 +0000
@@ -388,10 +388,12 @@
 		case 'b':  /* ctrl-b is GDK_Left, which moves backwards. */
 		case 'B':
 			if (imhtml->format_functions & GTK_IMHTML_BOLD) {
-				gtk_imhtml_toggle_bold(imhtml);
-				object = g_object_ref(G_OBJECT(imhtml));
-				g_signal_emit(object, signals[TOGGLE_FORMAT], 0, GTK_IMHTML_BOLD);
-				g_object_unref(object);
+				if(imhtml->html_shortcuts) {
+					gtk_imhtml_toggle_bold(imhtml);
+					object = g_object_ref(G_OBJECT(imhtml));
+					g_signal_emit(object, signals[TOGGLE_FORMAT], 0, GTK_IMHTML_BOLD);
+					g_object_unref(object);
+				}
 			}
 			return TRUE;
 			break;
@@ -408,14 +410,16 @@
 		case 'i':
 		case 'I':
 			if (imhtml->format_functions & GTK_IMHTML_ITALIC)
-				gtk_imhtml_toggle_italic(imhtml);
+				if(imhtml->html_shortcuts)
+					gtk_imhtml_toggle_italic(imhtml);
 			return TRUE;
 			break;
 			
 		case 'u':  /* ctrl-u is GDK_Clear, which clears the line. */
 		case 'U':
 			if (imhtml->format_functions & GTK_IMHTML_UNDERLINE)
-				gtk_imhtml_toggle_underline(imhtml);
+				if(imhtml->html_shortcuts)
+					gtk_imhtml_toggle_underline(imhtml);
 			return TRUE;
 			break;
 			
@@ -449,8 +453,8 @@
 		case '&': strcpy(buf, ":-X");  break;
 		case '*': strcpy(buf, ":-D");  break;
 		}
-	if (*buf) {
-		gtk_imhtml_insert_smiley(imhtml, NULL, buf);//->account->protocol_id, buf);
+	if (*buf && imhtml->smiley_shortcuts) {
+		gtk_imhtml_insert_smiley(imhtml, imhtml->protocol_name, buf);
 		return TRUE;
 	}	
 	return FALSE;
@@ -584,6 +588,7 @@
 	gdk_cursor_unref(imhtml->hand_cursor);
 	gdk_cursor_unref(imhtml->arrow_cursor);
 	gdk_cursor_unref(imhtml->text_cursor);
+	
 	if(imhtml->tip_window){
 		gtk_widget_destroy(imhtml->tip_window);
 	}
@@ -2056,6 +2061,23 @@
 	imhtml->show_comments = show;
 }
 
+void       gtk_imhtml_html_shortcuts   (GtkIMHtml        *imhtml,
+                    gboolean allow)
+{
+	imhtml->html_shortcuts = allow;
+}
+
+void       gtk_imhtml_smiley_shortcuts (GtkIMHtml        *imhtml,
+                    gboolean allow)
+{
+	imhtml->smiley_shortcuts = allow;
+}
+
+void 
+gtk_imhtml_set_protocol_name(GtkIMHtml *imhtml, gchar *protocol_name) {
+	imhtml->protocol_name = protocol_name;
+}
+
 void
 gtk_imhtml_clear (GtkIMHtml *imhtml)
 {
@@ -3018,4 +3040,3 @@
 	return gtk_text_buffer_get_text(imhtml->text_buffer, &start_iter, &end_iter, FALSE);
 
 }
-
--- a/src/gtkimhtml.h	Tue Mar 16 19:19:36 2004 +0000
+++ b/src/gtkimhtml.h	Tue Mar 16 19:35:17 2004 +0000
@@ -82,10 +82,14 @@
 	GdkCursor *text_cursor;
 	GHashTable *smiley_data;
 	GtkSmileyTree *default_smilies;
+	char *protocol_name;
 
 	gboolean show_smileys;
 	gboolean show_comments;
 
+	gboolean html_shortcuts;
+	gboolean smiley_shortcuts;
+
 	GtkWidget *tip_window;
 	char *tip;
 	guint tip_timer;
@@ -191,6 +195,12 @@
 
 void       gtk_imhtml_show_comments    (GtkIMHtml *imhtml, gboolean show);
 
+void       gtk_imhtml_html_shortcuts(GtkIMHtml *imhtml, gboolean allow);
+
+void       gtk_imhtml_smiley_shortcuts (GtkIMHtml *imhtml, gboolean allow);
+
+void       gtk_imhtml_set_protocol_name(GtkIMHtml *imhtml, gchar *protocol_name);
+
 #define    gtk_imhtml_append_text(x, y, z) \
  gtk_imhtml_append_text_with_images(x, y, z, NULL)
 
--- a/src/gtkimhtmltoolbar.c	Tue Mar 16 19:19:36 2004 +0000
+++ b/src/gtkimhtmltoolbar.c	Tue Mar 16 19:35:17 2004 +0000
@@ -481,9 +481,10 @@
 insert_smiley_text(GtkWidget *widget, GtkIMHtmlToolbar *toolbar)
 {
 	char *smiley_text = g_object_get_data(G_OBJECT(widget), "smiley_text");
-	//GaimPlugin *proto = gaim_find_prpl(gaim_account_get_protocol_id(gaim_conversation_get_account(c)));
 
-	gtk_imhtml_insert_smiley(GTK_IMHTML(toolbar->imhtml), NULL, smiley_text); //proto->info->name, smiley_text);
+	gtk_imhtml_insert_smiley(GTK_IMHTML(toolbar->imhtml),
+							 GTK_IMHTML(toolbar->imhtml)->protocol_name,
+							 smiley_text);
 
 	close_smiley_dialog(NULL, NULL, toolbar);
 }