restructure configure so pkg-config derived SSL flags get used
[rofl0r-ixchat.git] / src / fe-gtk / rawlog.c
blob56ca05103b521db169b7c34776f29c068e0ac4c0
1 /* X-Chat
2 * Copyright (C) 1998 Peter Zelezny.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
19 #include <stdio.h>
20 #include <string.h>
21 #include <fcntl.h>
22 #include <unistd.h>
23 #include <stdlib.h>
25 #include "fe-gtk.h"
27 #include <gtk/gtkbutton.h>
28 #include <gtk/gtkhbbox.h>
29 #include <gtk/gtkhbox.h>
30 #include <gtk/gtkvscrollbar.h>
31 #include <gtk/gtkstock.h>
33 #include "../common/xchat.h"
34 #include "../common/xchatc.h"
35 #include "../common/cfgfiles.h"
36 #include "../common/server.h"
37 #include "gtkutil.h"
38 #include "palette.h"
39 #include "maingui.h"
40 #include "rawlog.h"
41 #include "xtext.h"
44 static void
45 close_rawlog (GtkWidget *wid, server *serv)
47 if (is_server (serv))
48 serv->gui->rawlog_window = 0;
51 static void
52 rawlog_save (server *serv, char *file)
54 int fh = -1;
56 if (file)
58 if (serv->gui->rawlog_window)
59 fh = xchat_open_file (file, O_TRUNC | O_WRONLY | O_CREAT,
60 0600, XOF_DOMODE | XOF_FULLPATH);
61 if (fh != -1)
63 gtk_xtext_save (GTK_XTEXT (serv->gui->rawlog_textlist), fh);
64 close (fh);
69 static int
70 rawlog_clearbutton (GtkWidget * wid, server *serv)
72 gtk_xtext_clear (GTK_XTEXT (serv->gui->rawlog_textlist)->buffer, 0);
73 return FALSE;
76 static int
77 rawlog_savebutton (GtkWidget * wid, server *serv)
79 gtkutil_file_req (_("Save As..."), rawlog_save, serv, NULL, FRF_WRITE);
80 return FALSE;
83 void
84 open_rawlog (struct server *serv)
86 GtkWidget *hbox, *vscrollbar, *vbox;
87 char tbuf[256];
89 if (serv->gui->rawlog_window)
91 mg_bring_tofront (serv->gui->rawlog_window);
92 return;
95 snprintf (tbuf, sizeof tbuf, _("XChat: Rawlog (%s)"), serv->servername);
96 serv->gui->rawlog_window =
97 mg_create_generic_tab ("RawLog", tbuf, FALSE, TRUE, close_rawlog, serv,
98 640, 320, &vbox, serv);
100 hbox = gtk_hbox_new (FALSE, 2);
101 gtk_container_add (GTK_CONTAINER (vbox), hbox);
102 gtk_container_set_border_width (GTK_CONTAINER (hbox), 4);
103 gtk_widget_show (hbox);
105 serv->gui->rawlog_textlist = gtk_xtext_new (colors, 0);
106 gtk_xtext_set_tint (GTK_XTEXT (serv->gui->rawlog_textlist), prefs.tint_red, prefs.tint_green, prefs.tint_blue);
107 gtk_xtext_set_background (GTK_XTEXT (serv->gui->rawlog_textlist),
108 channelwin_pix, prefs.transparent);
110 gtk_container_add (GTK_CONTAINER (hbox), serv->gui->rawlog_textlist);
111 gtk_xtext_set_font (GTK_XTEXT (serv->gui->rawlog_textlist), prefs.font_normal);
112 GTK_XTEXT (serv->gui->rawlog_textlist)->ignore_hidden = 1;
113 gtk_widget_show (serv->gui->rawlog_textlist);
115 vscrollbar = gtk_vscrollbar_new (GTK_XTEXT (serv->gui->rawlog_textlist)->adj);
116 gtk_box_pack_start (GTK_BOX (hbox), vscrollbar, FALSE, FALSE, 0);
117 show_and_unfocus (vscrollbar);
119 hbox = gtk_hbutton_box_new ();
120 gtk_button_box_set_layout (GTK_BUTTON_BOX (hbox), GTK_BUTTONBOX_SPREAD);
121 gtk_box_pack_end (GTK_BOX (vbox), hbox, 0, 0, 0);
122 gtk_widget_show (hbox);
124 gtkutil_button (hbox, GTK_STOCK_CLEAR, NULL, rawlog_clearbutton,
125 serv, _("Clear rawlog"));
127 gtkutil_button (hbox, GTK_STOCK_SAVE_AS, NULL, rawlog_savebutton,
128 serv, _("Save As..."));
130 gtk_widget_show (serv->gui->rawlog_window);
133 void
134 fe_add_rawlog (server *serv, char *text, int len, int outbound)
136 char *new_text;
138 if (!serv->gui->rawlog_window)
139 return;
141 new_text = malloc (len + 7);
143 len = sprintf (new_text, "\0033>>\017 %s", text);
144 if (outbound)
146 new_text[1] = '4';
147 new_text[2] = '<';
148 new_text[3] = '<';
150 gtk_xtext_append (GTK_XTEXT (serv->gui->rawlog_textlist)->buffer, new_text, len);
151 free (new_text);