changeset 666:71ea550c22ac

[gaim-migrate @ 676] la la la. i also modified how fonts work a bit to make the convo window smaller and the code more understandable. committer: Tailor Script <tailor@pidgin.im>
author Eric Warmenhoven <eric@warmenhoven.org>
date Fri, 11 Aug 2000 03:04:29 +0000
parents 0bbcdd94e5b0
children 45ed2ca0756e
files TODO src/buddy_chat.c src/conversation.c src/dialogs.c src/gaim.h src/gaimrc.c src/gtkhtml.c src/prefs.c
diffstat 8 files changed, 107 insertions(+), 132 deletions(-) [+]
line wrap: on
line diff
--- a/TODO	Fri Aug 11 02:24:34 2000 +0000
+++ b/TODO	Fri Aug 11 03:04:29 2000 +0000
@@ -4,7 +4,6 @@
 		sound events.  Make a PC Speaker Beep (^G / Char 7)
 	Save Buddy Pounces 
 	Save Buddy Chats
-	Default colors (foreground and background) in prefs
 	Execute Command on Buddy Pounce
 	Possibly make it so that you can create 'aliases' for buddies
 		on your buddy list.  This won't be too hard it'll just
--- a/src/buddy_chat.c	Fri Aug 11 02:24:34 2000 +0000
+++ b/src/buddy_chat.c	Fri Aug 11 03:04:29 2000 +0000
@@ -703,11 +703,6 @@
 
 	gtk_signal_connect(GTK_OBJECT(win), "destroy", GTK_SIGNAL_FUNC(close_callback),b);
 
-	if (fontface)
-		strncpy(b->current_fontface, fontface, sizeof(b->current_fontface));
-	if (fontname)
-		strncpy(b->current_fontname, fontname, sizeof(b->current_fontname));
-		
 	gtk_widget_realize(win);
 	aol_icon(win->window);
 
--- a/src/conversation.c	Fri Aug 11 02:24:34 2000 +0000
+++ b/src/conversation.c	Fri Aug 11 03:04:29 2000 +0000
@@ -81,10 +81,11 @@
 GdkPixmap *dark_icon_pm = NULL;
 GdkBitmap *dark_icon_bm = NULL;
 
-char *fontface;
+char fontface[64];
+int bgcolor = 0;
+int fgcolor = 0;
 
 void check_everything(GtkWidget *entry);
-char *get_tag_by_prefix(GtkWidget *entry, const char *prefix);
 gboolean keypress_callback(GtkWidget *entry, GdkEventKey *event,  struct conversation *c);
 
 /*------------------------------------------------------------------------*/
@@ -167,31 +168,6 @@
         return NULL;
 }
 
-/* given the first part of a tag, returns the length up to the final '>';
-   useful for 'remove_tags' calls on variable data, such as <font face>
-   tags */
-char *get_tag_by_prefix(GtkWidget *entry, const char *prefix)
-{
-	char *s, *t;
-	int i = 0;
-	
-	s = gtk_editable_get_chars(GTK_EDITABLE(entry), 0, -1);
-	t = s;
-		
-	if ((t = strstr(s, prefix)) != NULL)
-	{
-		for (i = 1; t[i] != '\0'; i++)
-		{
-	
-			if (t[i] == '>')
-				break;
-		}
-		
-		t = gtk_editable_get_chars(GTK_EDITABLE(entry), (t-s), (t-s) + i + 1);		
-	}
-	return t;
-}
-
 void make_direct(struct conversation *c, gboolean direct, struct aim_conn_t *conn, gint watcher)
 {
 	char buf[BUF_LONG];
@@ -415,18 +391,12 @@
         return TRUE;
 }
 
-void set_font_face(GtkWidget *widget, struct conversation *c)
+void set_font_face(char *newfont, struct conversation *c)
 {
-	char *pre_fontface, *old_font_face;
-	int alloc = 0;
+	char *pre_fontface;
+	int alloc = 1;
 
-	if (c->current_fontface[0] && strcmp(c->current_fontface, "(null)"))
-	{
-		pre_fontface = g_strconcat("<FONT FACE=\"", c->current_fontface, "\">", '\0');
-		alloc++;
-	}
-	else
-		pre_fontface = "<FONT FACE=\"Helvetica\">";
+	pre_fontface = g_strconcat("<FONT FACE=\"", newfont, "\">", '\0');
 	
 	if (!strcmp(pre_fontface, "<FONT FACE=\"\">"))
 	{
@@ -435,20 +405,11 @@
 		pre_fontface = "<FONT FACE=\"Helvetica\">";
 	}
 
-	if ((old_font_face = get_tag_by_prefix(c->entry, "<FONT FACE")) != NULL)
-	{	
-		remove_tags(c->entry, old_font_face);
-		remove_tags(c->entry, "</FONT>");
-	}
-
 	surround(c->entry, pre_fontface, "</FONT>");
 	gtk_widget_grab_focus(c->entry);
 	
 	if (alloc)
 		g_free(pre_fontface);
-		
-	g_free(old_font_face); /* mem allocated in get_tag_by_prefix() */
-	return;
 }
 
 static gint delete_event_convo(GtkWidget *w, GdkEventAny *e, struct conversation *c)
@@ -614,10 +575,20 @@
         }
 
         if (font_options & OPT_FONT_FACE) {
-                g_snprintf(buf2, BUF_LONG, "<FONT FACE=\"%s\">%s</FONT>", c->current_fontface, buf);
+                g_snprintf(buf2, BUF_LONG, "<FONT FACE=\"%s\">%s</FONT>", fontface, buf);
                 strcpy(buf, buf2);
         }
 
+	if (font_options & OPT_FONT_FGCOL) {
+		g_snprintf(buf2, BUF_LONG, "<FONT COLOR=\"#%x\">%s</FONT>", fgcolor, buf);
+		strcpy(buf, buf2);
+	}
+
+	if (font_options & OPT_FONT_BGCOL) {
+		g_snprintf(buf2, BUF_LONG, "<BODY BGCOLOR=\"#%x\">%s</BODY>", bgcolor, buf);
+		strcpy(buf, buf2);
+	}
+
 #ifdef GAIM_PLUGINS
 	{
 		GList *ca = callbacks;
@@ -1630,12 +1601,7 @@
 	gtk_signal_connect(GTK_OBJECT(win), "delete_event", GTK_SIGNAL_FUNC(delete_event_convo), c);
 	gtk_signal_connect(GTK_OBJECT(entry), "insert-text", GTK_SIGNAL_FUNC(check_spelling), entry);
 	gtk_signal_connect(GTK_OBJECT(entry), "key_press_event", GTK_SIGNAL_FUNC(entry_key_pressed), entry);
-	
-	if (fontface)
-		strncpy(c->current_fontface, fontface, sizeof(c->current_fontface));
-	if (fontname)
-		strncpy(c->current_fontname, fontname, sizeof(c->current_fontname));
-	
+
 	gtk_widget_show(win);
 }
 
--- a/src/dialogs.c	Fri Aug 11 02:24:34 2000 +0000
+++ b/src/dialogs.c	Fri Aug 11 03:04:29 2000 +0000
@@ -66,8 +66,6 @@
 
 #define DEFAULT_FONT_NAME "-adobe-helvetica-medium-r-normal--12-120-75-75-p-67-iso8859-1"
 
-char *fontface;
-char *fontname;
 int smiley_array[FACE_TOTAL];
 
 static GtkWidget *imdialog = NULL; /*I only want ONE of these :) */
@@ -2361,14 +2359,26 @@
 static void apply_color_dlg(GtkWidget *w, gpointer d)
 {
 	gdouble color[3];
+	int red, green, blue;
 	if ((int)d == 1) {
-		gtk_color_selection_get_color(GTK_COLOR_SELECTION(fgcseld), color);
+		gtk_color_selection_get_color(GTK_COLOR_SELECTION(GTK_COLOR_SELECTION_DIALOG(fgcseld)->colorsel), color);
 		destroy_colorsel(NULL, (void *)1);
+
+		red = ((guint16)(color[0]*65535))>>8;
+		green = ((guint16)(color[1]*65535))>>8;
+		blue = ((guint16)(color[2]*65535))>>8;
+
+		fgcolor = ((red & 0xff) << 16) | ((green & 0xff) < 8) | (blue & 0xff);
 	} else {
 		gtk_color_selection_get_color(GTK_COLOR_SELECTION(bgcseld), color);
 		destroy_colorsel(NULL, (void *)2);
+
+		red = ((guint16)(color[0]*65535))>>8;
+		green = ((guint16)(color[1]*65535))>>8;
+		blue = ((guint16)(color[2]*65535))>>8;
+
+		bgcolor = ((red & 0xff) << 16) | ((green & 0xff) < 8) | (blue & 0xff);
 	}
-	/* FIXME ! here we need to set the preferences, etc */
 }
 
 void show_color_dialog(struct conversation *c, GtkWidget *color)
@@ -2440,36 +2450,33 @@
 	/* this could be expanded to include font size, weight, etc.
 	   but for now only works with font face */
 	int i, j = 0, k = 0;
-    struct conversation *c = gtk_object_get_user_data(GTK_OBJECT(fontsel));
+	char *fontname;
+	char font[64];
+	struct conversation *c = gtk_object_get_user_data(GTK_OBJECT(fontsel));
 	
 	if (c)
 	{
-		char *tmp = gtk_font_selection_dialog_get_font_name(GTK_FONT_SELECTION_DIALOG(fontsel));
-		strncpy(c->current_fontname, tmp, sizeof(c->current_fontname));
-
-		for (i = 0; i < strlen(c->current_fontname); i++)
+		fontname = gtk_font_selection_dialog_get_font_name(GTK_FONT_SELECTION_DIALOG(fontsel));
+
+		for (i = 0; i < strlen(fontname); i++)
 		{
-			if (c->current_fontname[i] == '-')
+			if (fontname[i] == '-')
 			{
 				if (++j > 2)
 					break;	
 			}		
 			else if (j == 2)
-				c->current_fontface[k++] = c->current_fontname[i];
+				font[k++] = fontname[i];
 		}
-		c->current_fontface[k] = '\0';
-
-		sprintf(debug_buff, "Setting font face %s\n", c->current_fontface);
+		font[k] = '\0';
+
+		sprintf(debug_buff, "Setting font face %s\n", font);
 		debug_print(debug_buff);
 
-		set_font_face(NULL, c);
+		set_font_face(font, c);
 	}
 	else
 	{
-		if (fontface)
-			g_free(fontface);
-		
-		fontface = g_malloc(64);
 		fontname = gtk_font_selection_dialog_get_font_name(GTK_FONT_SELECTION_DIALOG(fontsel));
 	
 		for (i = 0; i < strlen(fontname); i++)
@@ -2497,10 +2504,8 @@
 
 void apply_font_dlg(GtkWidget *w, GtkWidget *f) {
 	int i, j = 0, k = 0;
-	if (fontface)
-		g_free(fontface);
-
-	fontface = g_malloc(64);
+	char *fontname;
+
 	fontname = gtk_font_selection_dialog_get_font_name(GTK_FONT_SELECTION_DIALOG(fontseld));
 	destroy_fontsel(0, 0);
 	for (i = 0; i < strlen(fontname); i++) {
@@ -2518,10 +2523,7 @@
 	if (!font) { /* we came from the prefs dialog */
 		if (fontseld) return;
 		fontseld = gtk_font_selection_dialog_new(_("Select Font"));
-		if (fontname)
-			gtk_font_selection_dialog_set_font_name(GTK_FONT_SELECTION_DIALOG(fontseld), fontname);
-		else
-			gtk_font_selection_dialog_set_font_name(GTK_FONT_SELECTION_DIALOG(fontseld), DEFAULT_FONT_NAME);
+		gtk_font_selection_dialog_set_font_name(GTK_FONT_SELECTION_DIALOG(fontseld), DEFAULT_FONT_NAME);
 
 		gtk_object_set_user_data(GTK_OBJECT(fontseld), NULL);
 		gtk_signal_connect(GTK_OBJECT(fontseld), "delete_event", GTK_SIGNAL_FUNC(destroy_fontsel), NULL);
@@ -2549,10 +2551,7 @@
 		gtk_signal_connect(GTK_OBJECT(GTK_FONT_SELECTION_DIALOG(c->font_dialog)->ok_button), "clicked", GTK_SIGNAL_FUNC(apply_font), c->font_dialog);
 		gtk_signal_connect(GTK_OBJECT(GTK_FONT_SELECTION_DIALOG(c->font_dialog)->cancel_button), "clicked", GTK_SIGNAL_FUNC(cancel_font), c);
 	
-		if (fontname)
-			gtk_font_selection_dialog_set_font_name((GtkFontSelectionDialog *)c->font_dialog, fontname);
-		else
-			gtk_font_selection_dialog_set_font_name((GtkFontSelectionDialog *)c->font_dialog, DEFAULT_FONT_NAME);		
+		gtk_font_selection_dialog_set_font_name((GtkFontSelectionDialog *)c->font_dialog, DEFAULT_FONT_NAME);		
 		
 		gtk_widget_realize(c->font_dialog);
 	
@@ -2972,7 +2971,7 @@
 		case (FACE_SMILE): smiley_text = g_strndup(":-)", strlen(":-)")); break;
 		case (FACE_SMILE8): smiley_text = g_strndup("8-)", strlen("8-)")); break;
 		case (FACE_THINK): smiley_text = g_strndup(":-/", strlen(":-/")); break;
-		case (FACE_TONGUE): smiley_text = g_strndup(":-p", strlen(":-p")); break;
+		case (FACE_TONGUE): smiley_text = g_strndup(":-P", strlen(":-p")); break;
 		case (FACE_WINK): smiley_text = g_strndup(";-)", strlen(";-)")); break;
 		case (FACE_YELL): smiley_text = g_strndup(">:o", strlen(">:o")); break;
 		default: smiley_text = g_strndup(":-)", strlen(":-)")); break;
--- a/src/gaim.h	Fri Aug 11 02:24:34 2000 +0000
+++ b/src/gaim.h	Fri Aug 11 03:04:29 2000 +0000
@@ -268,8 +268,6 @@
 	GtkWidget *link_dialog;
 	GtkWidget *log_dialog;
 	int makesound;
-	char current_fontface[64];
-	char current_fontname[64];
 
 	/* stuff used just for IM */
 	GtkWidget *add_button;
@@ -388,7 +386,7 @@
 #define TYPE_SIGNOFF   4
 #define TYPE_KEEPALIVE 5
 
-#define REVISION "gaim:$Revision: 670 $"
+#define REVISION "gaim:$Revision: 676 $"
 #define FLAPON "FLAPON\r\n\r\n"
 
 #define ROAST "Tic/Toc"
@@ -416,8 +414,9 @@
 extern int correction_time;
 
 /* Globals in dialog.c */
-extern char *fontface;
-extern char *fontname;
+extern char fontface[64];
+extern int bgcolor;
+extern int fgcolor;
 extern int smiley_array[FACE_TOTAL];
 
 /* Globals in network.c */
@@ -503,6 +502,8 @@
 #define OPT_FONT_UNDERLINE       0x00000008
 #define OPT_FONT_STRIKE          0x00000010
 #define OPT_FONT_FACE            0x00000020
+#define OPT_FONT_FGCOL           0x00000040
+#define OPT_FONT_BGCOL           0x00000080
 
 #define DEFAULT_INFO "Visit the GAIM website at <A HREF=\"http://www.marko.net/gaim\">http://www.marko.net/gaim</A>."
 
@@ -636,7 +637,7 @@
 extern int invert_tags(GtkWidget *, char *, char *, int);
 extern void quiet_set(GtkWidget *, int);
 extern int count_tag(GtkWidget *, char *, char *);
-extern void set_font_face(GtkWidget *, struct conversation *);
+extern void set_font_face(char *, struct conversation *);
 
 /* Functions in network.c */
 extern unsigned int *get_address(char *);
--- a/src/gaimrc.c	Fri Aug 11 02:24:34 2000 +0000
+++ b/src/gaimrc.c	Fri Aug 11 03:04:29 2000 +0000
@@ -44,8 +44,6 @@
 int display_options;
 int sound_options;
 int font_options;
-char *fontface;
-char *fontname;
 
 int report_idle, web_browser;
 struct save_pos blist_pos;
@@ -452,16 +450,15 @@
                         display_options = atoi(p->value[0]);
                 } else if (!strcmp(p->option, "sound_options")) {
                         sound_options = atoi(p->value[0]);
-				} else if (!strcmp(p->option, "font_options")) {
-						font_options = atoi(p->value[0]);
-				} else if (!strcmp(p->option, "font_face")) {
-						if (p->value[0] != NULL)
-							fontface = g_strconcat(p->value[0], '\0');
-				} else if (!strcmp(p->option, "font_name")) {
-						if (p->value[0] != NULL)
-							fontname = g_strconcat(p->value[0], '\0');
-				} else if (!strcmp(p->option, "latest_ver")) {
-						g_snprintf(latest_ver, BUF_LONG, "%s", p->value[0]);
+		} else if (!strcmp(p->option, "font_options")) {
+			font_options = atoi(p->value[0]);
+		} else if (!strcmp(p->option, "font_face")) {
+			if (p->value[0] != NULL)
+					g_snprintf(fontface, sizeof(fontface), "%s", p->value[0]);
+		} else if (!strcmp(p->option, "foreground")) {
+			fgcolor = atoi(p->value[0]);
+		} else if (!strcmp(p->option, "background")) {
+			bgcolor = atoi(p->value[0]);
                 } else if (!strcmp(p->option, "report_idle")) {
                         report_idle = atoi(p->value[0]);
                 } else if (!strcmp(p->option, "web_browser")) {
@@ -502,11 +499,11 @@
         fprintf(f, "\tgeneral_options { %d }\n", general_options);
         fprintf(f, "\tdisplay_options { %d }\n", display_options);
         fprintf(f, "\tsound_options { %d }\n", sound_options);
-		fprintf(f, "\tfont_options { %d }\n", font_options);
+	fprintf(f, "\tfont_options { %d }\n", font_options);
 	if (fontface)
 		fprintf(f, "\tfont_face { %s }\n", fontface);
-	if (fontname)
-		fprintf(f, "\tfont_name { %s }\n", fontname);
+	fprintf(f, "\tforeground { %d }\n", fgcolor);
+	fprintf(f, "\tbackground { %d }\n", bgcolor);
         fprintf(f, "\treport_idle { %d }\n", report_idle);
         fprintf(f, "\tweb_browser { %d }\n", web_browser);
         fprintf(f, "\tweb_command { %s }\n", web_command);
--- a/src/gtkhtml.c	Fri Aug 11 02:24:34 2000 +0000
+++ b/src/gtkhtml.c	Fri Aug 11 03:04:29 2000 +0000
@@ -548,20 +548,6 @@
 		size += 10;
 	}
 
-	/* whoops, couldn't do any of those. maybe they have a default outgoing
-	 * font? maybe we can use that. */
-	if (font_options & OPT_FONT_FACE) {
-		if (fontname != NULL) {
-			/* woohoo! */
-			size = 120;
-			while (size <= 720) {
-				if (load_font_with_cache(fontname, "medium", 'r', size, &my_font))
-					return my_font;
-				size += 10;
-			}
-		}
-	}
-
 	/* ok, now we're in a pickle. if we can't do any of the above, let's
 	 * try doing the most boring font we can find. */
 	size = 120;
--- a/src/prefs.c	Fri Aug 11 02:24:34 2000 +0000
+++ b/src/prefs.c	Fri Aug 11 03:04:29 2000 +0000
@@ -40,6 +40,7 @@
 #include "pixmaps/refresh.xpm"
 #include "pixmaps/gnome_add.xpm"
 #include "pixmaps/gnome_remove.xpm"
+#include "pixmaps/palette.xpm"
 
 struct debug_window *dw = NULL;
 static GtkWidget *prefs = NULL;
@@ -156,12 +157,18 @@
 	gtk_box_pack_start(GTK_BOX(box), opt, FALSE, FALSE, 0);
 	gtk_signal_connect(GTK_OBJECT(opt), "clicked", GTK_SIGNAL_FUNC(set_connect), (void *)which);
 	gtk_widget_show(opt);
-	if (web_browser == which)
+	if (proxy_type == which)
 		gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(opt), TRUE);
 
 	return opt;
 }
 
+static void connect_destroy(GtkWidget *n, gpointer d)
+{
+	proxy_host_entry = NULL;
+	proxy_port_entry = NULL;
+}
+
 static void connect_page()
 {
 	GtkWidget *parent;
@@ -179,6 +186,7 @@
 
 	prefdialog = gtk_frame_new(_("Connection Options"));
 	gtk_container_add(GTK_CONTAINER(parent), prefdialog);
+	gtk_signal_connect(GTK_OBJECT(prefdialog), "destroy", GTK_SIGNAL_FUNC(connect_destroy), 0);
 
 	box = gtk_vbox_new(FALSE, 5);
 	gtk_container_add(GTK_CONTAINER(prefdialog), box);
@@ -727,15 +735,39 @@
 	gtk_box_pack_start(GTK_BOX(box), sep, FALSE, FALSE, 5);
 	gtk_widget_show(sep);
 
-/*
-	label = gtk_label_new(_("FIXME : This is where bg/fg color should go"));
-	gtk_box_pack_start(GTK_BOX(box), label, FALSE, FALSE, 5);
-	gtk_widget_show(label);
+	hbox = gtk_hbox_new(FALSE, 5);
+	gtk_box_pack_start(GTK_BOX(box), hbox, FALSE, FALSE, 5);
+	gtk_widget_show(hbox);
+	
+	button = gaim_button(_("Text Color"), &font_options, OPT_FONT_FGCOL, hbox);
+
+	select = picture_button(prefs, _("Select"), palette_xpm);
+	gtk_box_pack_start(GTK_BOX(hbox), select, FALSE, FALSE, 5);
+	if (!(font_options & OPT_FONT_FGCOL))
+		gtk_widget_set_sensitive(GTK_WIDGET(select), FALSE);
+	gtk_signal_connect(GTK_OBJECT(select), "clicked", GTK_SIGNAL_FUNC(show_color_dialog), (void *)1);
+	gtk_widget_show(select);
+
+	gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(toggle_sensitive), select);
+
+	hbox = gtk_hbox_new(FALSE, 5);
+	gtk_box_pack_start(GTK_BOX(box), hbox, FALSE, FALSE, 5);
+	gtk_widget_show(hbox);
+	
+	button = gaim_button(_("Background Color"), &font_options, OPT_FONT_BGCOL, hbox);
+
+	select = picture_button(prefs, _("Select"), palette_xpm);
+	gtk_box_pack_start(GTK_BOX(hbox), select, FALSE, FALSE, 5);
+	if (!(font_options & OPT_FONT_BGCOL))
+		gtk_widget_set_sensitive(GTK_WIDGET(select), FALSE);
+	gtk_signal_connect(GTK_OBJECT(select), "clicked", GTK_SIGNAL_FUNC(show_color_dialog), (void *)2);
+	gtk_widget_show(select);
+
+	gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(toggle_sensitive), select);
 
 	sep = gtk_hseparator_new();
 	gtk_box_pack_start(GTK_BOX(box), sep, FALSE, FALSE, 5);
 	gtk_widget_show(sep);
-*/
 
 	hbox = gtk_hbox_new(FALSE, 5);
 	gtk_box_pack_start(GTK_BOX(box), hbox, FALSE, FALSE, 5);