changeset 230:83dd297aa363

[gaim-migrate @ 240] Added a few patches from fflewddur to add default away messages, save prefs after deleting an away message, and *duh* *duh* *duh* *duh* presenting..... font face selection dialog! Thanks fflewddur. I also added a pixmap for font face to eventually go on the conversation windows, but I didn't implement it yet. committer: Tailor Script <tailor@pidgin.im>
author Eric Warmenhoven <eric@warmenhoven.org>
date Wed, 10 May 2000 10:56:25 +0000
parents e8ea7f37e28f
children 4a638177f917
files doc/CREDITS pixmaps/fontface.xpm src/away.c src/conversation.c src/dialogs.c src/gaim.h src/gaimrc.c src/prefs.c
diffstat 8 files changed, 215 insertions(+), 37 deletions(-) [+]
line wrap: on
line diff
--- a/doc/CREDITS	Wed May 10 08:29:02 2000 +0000
+++ b/doc/CREDITS	Wed May 10 10:56:25 2000 +0000
@@ -38,3 +38,4 @@
 
 G. Sumner Hayes <IM: SumnerFool> Security Patches
 Brian Ryner for a little make file patch :)
+fflewddur for the font dialog, default away messages, and other neat patches
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pixmaps/fontface.xpm	Wed May 10 10:56:25 2000 +0000
@@ -0,0 +1,22 @@
+/* XPM */
+static char * fontface_xpm[] = {
+"22 17 2 1",
+" 	c None",
+".	c #000000",
+"                      ",
+"                      ",
+"                      ",
+"            ..        ",
+"            ..        ",
+"           ...        ",
+"          . ..        ",
+"          . ..        ",
+"         .  ...       ",
+"         ......       ",
+"        .   ...       ",
+"        .    ..       ",
+"       .     ..       ",
+"      ...   ....      ",
+"                      ",
+"                      ",
+"                      "};
--- a/src/away.c	Wed May 10 08:29:02 2000 +0000
+++ b/src/away.c	Wed May 10 10:56:25 2000 +0000
@@ -210,6 +210,7 @@
         away_messages = g_list_remove(away_messages, a);
         g_free(a);
         do_away_menu();
+        save_prefs();
 }
 
 
--- a/src/conversation.c	Wed May 10 08:29:02 2000 +0000
+++ b/src/conversation.c	Wed May 10 10:56:25 2000 +0000
@@ -37,6 +37,7 @@
 #include "pixmaps/small.xpm"
 #include "pixmaps/normal.xpm"
 #include "pixmaps/big.xpm"
+/* #include "pixmaps/fontface.xpm" */
 #include "pixmaps/speaker.xpm"
 /* #include "pixmaps/aimicon2.xpm" */
 #include "pixmaps/wood.xpm"
@@ -49,10 +50,11 @@
 GdkPixmap *dark_icon_pm = NULL;
 GdkBitmap *dark_icon_bm = NULL;
 
+char *fontface;
 
 void check_everything(GtkWidget *entry);
 gboolean user_keypress_callback(GtkWidget *entry, GdkEventKey *event,  struct conversation *c);
-
+void set_font_face(GtkWidget *widget, struct conversation *c);
 
 /*------------------------------------------------------------------------*/
 /*  Helpers                                                               */
@@ -247,7 +249,6 @@
 		show_log_dialog(p->name);
 }
 
-
 static int close_callback(GtkWidget *widget, struct conversation *c)
 {
         gtk_widget_destroy(c->window);
@@ -255,6 +256,30 @@
         return TRUE;
 }
 
+void set_font_face(GtkWidget *widget, struct conversation *c)
+{
+	char *pre_fontface;
+	int alloc = 0;
+
+	if (!(font_options & OPT_FONT_FACE))
+		return;
+
+	if (fontface)
+	{
+		pre_fontface = g_strconcat("<FONT FACE=\"", fontface, "\">", '\0');
+		alloc++;
+	}
+	else
+		pre_fontface = "<FONT FACE=\"Helvetica\">";
+		
+	surround(c->entry, pre_fontface, "</FONT>");
+	gtk_widget_grab_focus(c->entry);
+	
+	if (alloc)
+		g_free(pre_fontface);
+	return;
+}
+
 static gint delete_event_convo(GtkWidget *w, GdkEventAny *e, struct conversation *c)
 {
 	delete_conversation(c);
@@ -419,7 +444,8 @@
 		do_im_back();
 	}
 
-
+    set_font_face(NULL, c);
+	
 	gtk_widget_grab_focus(c->entry);
 
         g_free(buf2);
@@ -502,12 +528,27 @@
 	int finish = GTK_EDITABLE(entry)->selection_end_pos;
 	s = gtk_editable_get_chars(GTK_EDITABLE(entry), 0, -1); 
 	t = s;
-	while((t = strstr(t, tag))) {
-		if (((t-s) < finish) && ((t-s) >= start)) { 
-			gtk_editable_delete_text(GTK_EDITABLE(entry), (t-s), (t-s) + strlen(tag));
-			t = gtk_editable_get_chars(GTK_EDITABLE(entry), 0, -1);
+	if (strstr(tag, "<FONT SIZE="))
+	{
+		while((t = strstr(t, "<FONT SIZE="))) {
+			if (((t-s) < finish) && ((t-s) >= start)) {
+				gtk_editable_delete_text(GTK_EDITABLE(entry), (t-s), (t-s) + strlen(tag));
+				s = gtk_editable_get_chars(GTK_EDITABLE(entry), 0, -1);
+				t = s;
+			}
+			else t++;
 		}
-		else t++;
+	}
+	else
+	{
+		while((t = strstr(t, tag))) {
+			if (((t-s) < finish) && ((t-s) >= start)) {
+				gtk_editable_delete_text(GTK_EDITABLE(entry), (t-s), (t-s) + strlen(tag));
+				s = gtk_editable_get_chars(GTK_EDITABLE(entry), 0, -1);
+				t = s;
+			}
+			else t++;
+		}
 	}
 	g_free(s);
 }
@@ -622,11 +663,14 @@
 		advance_past(entry, "<I>", "</I>");
 }
 
+/* html code to modify font sizes must all be the same length, */
+/* currently set to 15 chars */
+
 static void do_small(GtkWidget *small, GtkWidget *entry)
 {
 	if (state_lock)
 		return;
-	surround(entry, "<FONT SIZE=\"-2\">","</FONT>");
+	surround(entry, "<FONT SIZE=\"1\">","</FONT>");
 }
 
 static void do_normal(GtkWidget *normal, GtkWidget *entry)
@@ -640,7 +684,7 @@
 {
 	if (state_lock)
 		return;
-	surround(entry, "<FONT SIZE=\"+5\">","</FONT>");
+	surround(entry, "<FONT SIZE=\"5\">","</FONT>");
 }
 
 void check_everything(GtkWidget *entry)
@@ -884,7 +928,7 @@
 	entry = gtk_text_new(NULL, NULL);
 	gtk_text_set_editable(GTK_TEXT(entry), TRUE);
 	gtk_text_set_word_wrap(GTK_TEXT(entry), TRUE);
-        
+
 	/* Toolbar */
 	toolbar = gtk_toolbar_new(GTK_ORIENTATION_HORIZONTAL, GTK_TOOLBAR_ICONS);
 
@@ -1093,8 +1137,9 @@
 	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);
 
+	set_font_face(NULL, c);
+	
 	gtk_widget_show(win);
-	
 }
 
 
--- a/src/dialogs.c	Wed May 10 08:29:02 2000 +0000
+++ b/src/dialogs.c	Wed May 10 10:56:25 2000 +0000
@@ -37,9 +37,16 @@
 #include "gaim.h"
 #include "gtkhtml.h"
 
+#define DEFAULT_FONT_NAME "-adobe-helvetica-medium-r-normal--12-120-75-75-p-67-iso8859-1"
+
+char *fontface;
+char *fontname;
+
 static GtkWidget *imdialog = NULL; /*I only want ONE of these :) */
 static GList *dialogwindows = NULL;
-static GtkWidget *linkdialog, *colordialog, *exportdialog, *importdialog, *logdialog;
+static GtkWidget *linkdialog, *colordialog, *exportdialog, *importdialog, *logdialog, *fontdialog;
+
+static void accept_callback(GtkWidget *widget, struct file_transfer *t);
 
 struct create_away {
         GtkWidget *window;
@@ -1933,6 +1940,74 @@
 }
 
 /*------------------------------------------------------------------------*/
+/*  Font Selection Dialog                                                 */
+/*------------------------------------------------------------------------*/
+
+void cancel_font(GtkWidget *widget, GtkWidget *font)
+{
+	if (font)
+    {
+		set_state_lock(1);
+        gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(font), FALSE);
+        set_state_lock(0);
+	}
+	
+	destroy_dialog(NULL, fontdialog);
+}
+
+void apply_font(GtkWidget *widget, GtkFontSelection *fontsel)
+{
+	/* this could be expanded to include font size, weight, etc.
+	   but for now only works with font face */
+	int i, j = 0, k = 0;
+
+	fontface = g_malloc(64);
+	fontname = gtk_font_selection_get_font_name(fontsel);
+	
+	for (i = 0; i < strlen(fontname); i++)
+	{
+		if (fontname[i] == '-')
+		{
+			if (++j > 2)
+				break;	
+		}		
+		else if (j == 2)
+			fontface[k++] = fontname[i];
+	}
+	fontface[k] = '\0';
+	
+	save_prefs();
+	
+	cancel_font(widget, NULL);	
+}
+
+void show_font_dialog(GtkWidget *widget, GtkWidget *font)
+{
+	GtkWidget *fontsel;
+
+	fontdialog = gtk_font_selection_dialog_new("Select Font");
+	fontsel = GTK_FONT_SELECTION_DIALOG(fontdialog)->fontsel;
+	
+	gtk_font_selection_dialog_set_font_name((GtkFontSelectionDialog *)fontdialog, DEFAULT_FONT_NAME);	
+	gtk_window_set_modal(GTK_WINDOW(fontdialog), TRUE);
+	gtk_signal_connect(GTK_OBJECT(fontdialog), "delete_event", GTK_SIGNAL_FUNC(cancel_font), font);
+	gtk_signal_connect(GTK_OBJECT(GTK_FONT_SELECTION_DIALOG(fontdialog)->ok_button), "clicked", GTK_SIGNAL_FUNC(apply_font), fontsel);
+	gtk_signal_connect(GTK_OBJECT(GTK_FONT_SELECTION_DIALOG(fontdialog)->cancel_button), "clicked", GTK_SIGNAL_FUNC(cancel_font), font);
+	
+	if (fontname)
+		gtk_font_selection_dialog_set_font_name((GtkFontSelectionDialog *)fontdialog, fontname);
+	else
+		gtk_font_selection_dialog_set_font_name((GtkFontSelectionDialog *)fontdialog, DEFAULT_FONT_NAME);		
+		
+	gtk_widget_realize(fontdialog);
+	
+	aol_icon(fontdialog->window);
+		
+	gtk_widget_show(fontdialog);
+	gdk_window_raise(fontdialog->window);
+}
+
+/*------------------------------------------------------------------------*/
 /*  The dialog for import/export                                          */
 /*------------------------------------------------------------------------*/
 
@@ -2014,7 +2089,7 @@
                                    GTK_SIGNAL_FUNC(destroy_dialog), exportdialog);
                 
                 gtk_signal_connect(GTK_OBJECT(GTK_FILE_SELECTION(exportdialog)->ok_button),
-                                   "clicked", GTK_SIGNAL_FUNC(do_export), 1);
+                                   "clicked", GTK_SIGNAL_FUNC(do_export), (void*)1);
                 gtk_signal_connect(GTK_OBJECT(GTK_FILE_SELECTION(exportdialog)->cancel_button),
                                    "clicked", GTK_SIGNAL_FUNC(destroy_dialog), exportdialog);
                 
@@ -2134,7 +2209,7 @@
                                    GTK_SIGNAL_FUNC(destroy_dialog), importdialog);
                 
                 gtk_signal_connect(GTK_OBJECT(GTK_FILE_SELECTION(importdialog)->ok_button),
-                                   "clicked", GTK_SIGNAL_FUNC(do_import), 1);
+                                   "clicked", GTK_SIGNAL_FUNC(do_import), (void*)1);
                 gtk_signal_connect(GTK_OBJECT(GTK_FILE_SELECTION(importdialog)->cancel_button),
                                    "clicked", GTK_SIGNAL_FUNC(destroy_dialog), importdialog);
                 
--- a/src/gaim.h	Wed May 10 08:29:02 2000 +0000
+++ b/src/gaim.h	Wed May 10 10:56:25 2000 +0000
@@ -334,7 +334,7 @@
 #define TYPE_SIGNOFF   4
 #define TYPE_KEEPALIVE 5
 
-#define REVISION "gaim:$Revision: 220 $"
+#define REVISION "gaim:$Revision: 240 $"
 #define FLAPON "FLAPON\r\n\r\n"
 
 #define ROAST "Tic/Toc"
@@ -359,6 +359,14 @@
 /* Globals in server.c */
 extern int correction_time;
 
+/* Globals in dialog.c */
+extern char *fontface;
+extern char *fontname;
+
+/* Globals in dialog.c */
+extern char *fontface;
+extern char *fontname;
+
 /* Globals in network.c */
 
 /* Globals in toc.c */
@@ -430,6 +438,7 @@
 #define OPT_FONT_ITALIC          0x00000002
 #define OPT_FONT_UNDERLINE       0x00000008
 #define OPT_FONT_STRIKE          0x00000010
+#define OPT_FONT_FACE            0x00000020
 
 #define DEFAULT_INFO "Visit the GAIM website at <A HREF=\"http://www.marko.net/gaim\">http://www.marko.net/gaim</A>."
 
@@ -631,6 +640,7 @@
 
 
 /* Functions in dialogs.c */
+extern void do_export(GtkWidget *, void *);
 extern void show_warn_dialog(char *);
 extern void do_error_dialog(char *, char *);
 extern void show_error_dialog(char *);
@@ -648,12 +658,16 @@
 extern void show_register_dialog();
 extern void show_set_info();
 extern void show_set_dir();
-extern void show_color_dialog(GtkWidget *entrye, GtkWidget *color);
+extern void show_color_dialog(GtkWidget *entry, GtkWidget *color);
 extern void create_away_mess(GtkWidget *, void *);
 extern void show_ee_dialog(int);
 extern void show_add_link(GtkWidget *, GtkWidget *);
 extern void show_change_passwd();
 
+extern void show_font_dialog(GtkWidget *widget, GtkWidget *font);
+extern void cancel_font(GtkWidget *widget, GtkWidget *font);
+extern void apply_font(GtkWidget *widget, GtkFontSelection *fontsel);
+
 /* Functions in rvous.c */
 extern void accept_file_dialog(struct file_transfer *);
 
--- a/src/gaimrc.c	Wed May 10 08:29:02 2000 +0000
+++ b/src/gaimrc.c	Wed May 10 10:56:25 2000 +0000
@@ -36,6 +36,8 @@
 #include "gnome_applet_mgr.h"
 #endif
 
+/* for people like myself, who are too lazy to add an away msg :) */
+#define BORING_DEFAULT_AWAY_MSG "sorry, i ran out for a while. bbl"
 
 struct aim_user *current_user = NULL;
 GList *aim_users = NULL;
@@ -43,6 +45,8 @@
 int display_options;
 int sound_options;
 int font_options;
+char *fontface;
+char *fontname;
 
 int report_idle, web_browser;
 struct save_pos blist_pos;
@@ -214,22 +218,27 @@
 
 	fprintf(f, "away {\n");
 
-	while (awy) {
-		char *str1, *str2;
+	if (awy)
+	{
+		while (awy) {
+			char *str1, *str2;
 
-		a = (struct away_message *)awy->data;
-
-		str1 = escape_text2(a->name);
-		str2 = escape_text2(a->message);
+			a = (struct away_message *)awy->data;
 
-		fprintf(f, "\tmessage { %s } { %s }\n", str1, str2);
+			str1 = escape_text2(a->name);
+			str2 = escape_text2(a->message);
+	
+			fprintf(f, "\tmessage { %s } { %s }\n", str1, str2);
 
-		/* escape_text2 uses malloc(), so we don't want to g_free these */
-		free(str1);
-		free(str2);
-
-		awy = awy->next;
+			/* escape_text2 uses malloc(), so we don't want to g_free these */
+			free(str1);
+			free(str2);
+	
+			awy = awy->next;
+		}
 	}
+	else
+		fprintf(f, "\tmessage { boring default } { %s }\n", BORING_DEFAULT_AWAY_MSG);
 
 	fprintf(f, "}\n");
 }
@@ -444,10 +453,14 @@
                         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, "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")) {
+						fontface = g_strconcat(p->value[0], '\0');
+				} else if (!strcmp(p->option, "font_name")) {
+						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, "report_idle")) {
                         report_idle = atoi(p->value[0]);
                 } else if (!strcmp(p->option, "web_browser")) {
@@ -488,7 +501,9 @@
         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);
+		fprintf(f, "\tfont_face { %s }\n", fontface);
+		fprintf(f, "\tfont_name { %s }\n", fontname);
         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/prefs.c	Wed May 10 08:29:02 2000 +0000
+++ b/src/prefs.c	Wed May 10 10:56:25 2000 +0000
@@ -94,7 +94,6 @@
 	save_prefs();
 }
 
-
 void set_option(GtkWidget *w, int *option)
 {
 	*option = !(*option);
@@ -334,12 +333,12 @@
         GtkWidget *sw;
 	GtkWidget *sw2;
 	GtkWidget *away_page;
-
+	GtkWidget *select_font;
+	
 	GtkWidget *list_item;
 
 	gchar buffer[64];
 
-
 	if (!pd)
                 pd = g_new0(struct prefs_data, 1);
 
@@ -729,6 +728,12 @@
 	gaim_button("Italics Text", &font_options, OPT_FONT_ITALIC, fontbox);
 	gaim_button("Underlined Text", &font_options, OPT_FONT_UNDERLINE, fontbox);
 	gaim_button("Strike Text", &font_options, OPT_FONT_STRIKE, fontbox);
+	gaim_button("Font Face for Text", &font_options, OPT_FONT_FACE, fontbox);
+	
+	select_font = gtk_button_new_with_label("Select Font");
+	gtk_box_pack_start(GTK_BOX(fontbox), select_font, FALSE, FALSE, 0);
+	gtk_signal_connect(GTK_OBJECT(select_font), "clicked", GTK_SIGNAL_FUNC(show_font_dialog), NULL);
+	gtk_widget_show(select_font);
 
 	gtk_widget_show(appearance_page);
 	gtk_widget_show(fontbox);