2011-02-24 04:14:30 +01:00
|
|
|
/* X-Chat
|
|
|
|
|
* Copyright (C) 1998 Peter Zelezny.
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software
|
2012-12-23 11:36:54 -08:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2011-02-24 04:14:30 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
2012-07-21 14:26:19 +02:00
|
|
|
#ifdef WIN32
|
|
|
|
|
#include <io.h>
|
|
|
|
|
#else
|
2011-12-11 17:34:02 +01:00
|
|
|
#include <unistd.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
2011-02-24 04:14:30 +01:00
|
|
|
#include "fe-gtk.h"
|
|
|
|
|
|
2012-10-31 05:18:20 +01:00
|
|
|
#include <gdk/gdkkeysyms.h>
|
2011-02-24 04:14:30 +01:00
|
|
|
|
2026-01-05 23:12:38 -07:00
|
|
|
#include "../common/zoitechat.h"
|
|
|
|
|
#include "../common/zoitechatc.h"
|
2011-02-24 04:14:30 +01:00
|
|
|
#include "../common/cfgfiles.h"
|
|
|
|
|
#include "../common/server.h"
|
|
|
|
|
#include "gtkutil.h"
|
|
|
|
|
#include "palette.h"
|
|
|
|
|
#include "maingui.h"
|
|
|
|
|
#include "rawlog.h"
|
|
|
|
|
#include "xtext.h"
|
2012-10-31 05:18:20 +01:00
|
|
|
#include "fkeys.h"
|
2011-02-24 04:14:30 +01:00
|
|
|
|
Added per-file ICON_* macros with GTK3 icon-name mappings and GTK2 stock fallbacks across GTK UI modules like banlist, DCC, editlist, ignore, URL grabber, notify, text events, tray menu, chanview tabs, and join dialog UI.
Updated GTK helper usages to reference the new ICON_* (and label) macros so GTK3 builds no longer pass stock IDs to button/icon helpers or dialogs, including banlist buttons, DCC windows, rawlog actions, notify dialog/buttons, pevent dialog buttons, tray menu items, and join dialog image helper usage.
2026-01-30 09:23:52 -07:00
|
|
|
#if HAVE_GTK3
|
|
|
|
|
#define ICON_RAWLOG_CLEAR "edit-clear"
|
|
|
|
|
#define ICON_RAWLOG_SAVE_AS "document-save-as"
|
|
|
|
|
#endif
|
|
|
|
|
#if !HAVE_GTK3
|
|
|
|
|
#define ICON_RAWLOG_CLEAR GTK_STOCK_CLEAR
|
|
|
|
|
#define ICON_RAWLOG_SAVE_AS GTK_STOCK_SAVE_AS
|
|
|
|
|
#endif
|
|
|
|
|
|
2011-02-24 04:14:30 +01:00
|
|
|
static void
|
|
|
|
|
close_rawlog (GtkWidget *wid, server *serv)
|
|
|
|
|
{
|
|
|
|
|
if (is_server (serv))
|
|
|
|
|
serv->gui->rawlog_window = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
rawlog_save (server *serv, char *file)
|
|
|
|
|
{
|
|
|
|
|
int fh = -1;
|
|
|
|
|
|
|
|
|
|
if (file)
|
|
|
|
|
{
|
|
|
|
|
if (serv->gui->rawlog_window)
|
2026-01-05 23:12:38 -07:00
|
|
|
fh = zoitechat_open_file (file, O_TRUNC | O_WRONLY | O_CREAT,
|
2011-02-24 04:14:30 +01:00
|
|
|
0600, XOF_DOMODE | XOF_FULLPATH);
|
|
|
|
|
if (fh != -1)
|
|
|
|
|
{
|
|
|
|
|
gtk_xtext_save (GTK_XTEXT (serv->gui->rawlog_textlist), fh);
|
|
|
|
|
close (fh);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
rawlog_clearbutton (GtkWidget * wid, server *serv)
|
|
|
|
|
{
|
|
|
|
|
gtk_xtext_clear (GTK_XTEXT (serv->gui->rawlog_textlist)->buffer, 0);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
rawlog_savebutton (GtkWidget * wid, server *serv)
|
|
|
|
|
{
|
2022-04-16 18:41:34 -05:00
|
|
|
gtkutil_file_req (NULL, _("Save As..."), rawlog_save, serv, NULL, NULL, FRF_WRITE);
|
2011-02-24 04:14:30 +01:00
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-17 15:11:23 -07:00
|
|
|
static gboolean
|
2012-10-31 05:18:20 +01:00
|
|
|
rawlog_key_cb (GtkWidget * wid, GdkEventKey * key, gpointer userdata)
|
|
|
|
|
{
|
|
|
|
|
/* Copy rawlog selection to clipboard when Ctrl+Shift+C is pressed,
|
|
|
|
|
* but make sure not to copy twice, i.e. when auto-copy is enabled.
|
|
|
|
|
*/
|
|
|
|
|
if (!prefs.hex_text_autocopy_text &&
|
2013-09-15 03:21:56 -04:00
|
|
|
(key->keyval == GDK_KEY_c || key->keyval == GDK_KEY_C) &&
|
2012-10-31 05:18:20 +01:00
|
|
|
key->state & STATE_SHIFT &&
|
|
|
|
|
key->state & STATE_CTRL)
|
|
|
|
|
{
|
|
|
|
|
gtk_xtext_copy_selection (userdata);
|
|
|
|
|
}
|
2013-03-17 15:11:23 -07:00
|
|
|
return FALSE;
|
2012-10-31 05:18:20 +01:00
|
|
|
}
|
|
|
|
|
|
2011-02-24 04:14:30 +01:00
|
|
|
void
|
|
|
|
|
open_rawlog (struct server *serv)
|
|
|
|
|
{
|
2014-02-05 18:08:40 -05:00
|
|
|
GtkWidget *bbox, *scrolledwindow, *vbox;
|
2026-01-17 21:39:45 -07:00
|
|
|
XTextColor xtext_palette[XTEXT_COLS];
|
2011-02-24 04:14:30 +01:00
|
|
|
char tbuf[256];
|
|
|
|
|
|
|
|
|
|
if (serv->gui->rawlog_window)
|
|
|
|
|
{
|
|
|
|
|
mg_bring_tofront (serv->gui->rawlog_window);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-15 17:36:02 -04:00
|
|
|
g_snprintf (tbuf, sizeof tbuf, _("Raw Log (%s) - %s"), serv->servername, _(DISPLAY_NAME));
|
2011-02-24 04:14:30 +01:00
|
|
|
serv->gui->rawlog_window =
|
|
|
|
|
mg_create_generic_tab ("RawLog", tbuf, FALSE, TRUE, close_rawlog, serv,
|
|
|
|
|
640, 320, &vbox, serv);
|
2013-03-17 15:11:23 -07:00
|
|
|
gtkutil_destroy_on_esc (serv->gui->rawlog_window);
|
2011-02-24 04:14:30 +01:00
|
|
|
|
2014-02-05 18:08:40 -05:00
|
|
|
scrolledwindow = gtk_scrolled_window_new (NULL, NULL);
|
|
|
|
|
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
|
|
|
|
|
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolledwindow), GTK_SHADOW_IN);
|
|
|
|
|
gtk_container_add (GTK_CONTAINER (vbox), scrolledwindow);
|
2011-02-24 04:14:30 +01:00
|
|
|
|
2026-01-17 21:39:45 -07:00
|
|
|
palette_get_xtext_colors (xtext_palette, XTEXT_COLS);
|
|
|
|
|
serv->gui->rawlog_textlist = gtk_xtext_new (xtext_palette, 0);
|
2014-02-05 18:08:40 -05:00
|
|
|
gtk_container_add (GTK_CONTAINER (scrolledwindow), serv->gui->rawlog_textlist);
|
2012-10-22 15:55:43 +02:00
|
|
|
gtk_xtext_set_font (GTK_XTEXT (serv->gui->rawlog_textlist), prefs.hex_text_font);
|
2011-02-24 04:14:30 +01:00
|
|
|
GTK_XTEXT (serv->gui->rawlog_textlist)->ignore_hidden = 1;
|
|
|
|
|
|
2026-01-30 17:03:27 -07:00
|
|
|
#if HAVE_GTK3
|
|
|
|
|
bbox = gtk_button_box_new (GTK_ORIENTATION_HORIZONTAL);
|
|
|
|
|
gtk_button_box_set_layout (GTK_BUTTON_BOX (bbox), GTK_BUTTONBOX_SPREAD);
|
|
|
|
|
#elif !HAVE_GTK3
|
2014-02-05 18:08:40 -05:00
|
|
|
bbox = gtk_hbutton_box_new ();
|
|
|
|
|
gtk_button_box_set_layout (GTK_BUTTON_BOX (bbox), GTK_BUTTONBOX_SPREAD);
|
2026-01-30 17:03:27 -07:00
|
|
|
#endif
|
2014-02-05 18:08:40 -05:00
|
|
|
gtk_box_pack_end (GTK_BOX (vbox), bbox, 0, 0, 4);
|
2011-02-24 04:14:30 +01:00
|
|
|
|
Added per-file ICON_* macros with GTK3 icon-name mappings and GTK2 stock fallbacks across GTK UI modules like banlist, DCC, editlist, ignore, URL grabber, notify, text events, tray menu, chanview tabs, and join dialog UI.
Updated GTK helper usages to reference the new ICON_* (and label) macros so GTK3 builds no longer pass stock IDs to button/icon helpers or dialogs, including banlist buttons, DCC windows, rawlog actions, notify dialog/buttons, pevent dialog buttons, tray menu items, and join dialog image helper usage.
2026-01-30 09:23:52 -07:00
|
|
|
gtkutil_button (bbox, ICON_RAWLOG_CLEAR, NULL, rawlog_clearbutton,
|
2012-10-31 05:31:35 +01:00
|
|
|
serv, _("Clear Raw Log"));
|
2011-02-24 04:14:30 +01:00
|
|
|
|
Added per-file ICON_* macros with GTK3 icon-name mappings and GTK2 stock fallbacks across GTK UI modules like banlist, DCC, editlist, ignore, URL grabber, notify, text events, tray menu, chanview tabs, and join dialog UI.
Updated GTK helper usages to reference the new ICON_* (and label) macros so GTK3 builds no longer pass stock IDs to button/icon helpers or dialogs, including banlist buttons, DCC windows, rawlog actions, notify dialog/buttons, pevent dialog buttons, tray menu items, and join dialog image helper usage.
2026-01-30 09:23:52 -07:00
|
|
|
gtkutil_button (bbox, ICON_RAWLOG_SAVE_AS, NULL, rawlog_savebutton,
|
2011-02-24 04:14:30 +01:00
|
|
|
serv, _("Save As..."));
|
|
|
|
|
|
2012-10-31 05:18:20 +01:00
|
|
|
/* Copy selection to clipboard when Ctrl+Shift+C is pressed AND text auto-copy is disabled */
|
|
|
|
|
g_signal_connect (G_OBJECT (serv->gui->rawlog_window), "key_press_event", G_CALLBACK (rawlog_key_cb), serv->gui->rawlog_textlist);
|
|
|
|
|
|
2014-02-05 18:08:40 -05:00
|
|
|
gtk_widget_show_all (serv->gui->rawlog_window);
|
2011-02-24 04:14:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
fe_add_rawlog (server *serv, char *text, int len, int outbound)
|
|
|
|
|
{
|
2013-05-16 09:21:55 +00:00
|
|
|
char **split_text;
|
2011-02-24 04:14:30 +01:00
|
|
|
char *new_text;
|
2014-12-04 04:06:38 -08:00
|
|
|
size_t i;
|
2011-02-24 04:14:30 +01:00
|
|
|
|
|
|
|
|
if (!serv->gui->rawlog_window)
|
|
|
|
|
return;
|
|
|
|
|
|
2013-05-16 09:21:55 +00:00
|
|
|
split_text = g_strsplit (text, "\r\n", 0);
|
2011-02-24 04:14:30 +01:00
|
|
|
|
2013-05-16 09:21:55 +00:00
|
|
|
for (i = 0; i < g_strv_length (split_text); i++)
|
2011-02-24 04:14:30 +01:00
|
|
|
{
|
2013-05-16 09:21:55 +00:00
|
|
|
if (split_text[i][0] == 0)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
if (outbound)
|
|
|
|
|
new_text = g_strconcat ("\0034<<\017 ", split_text[i], NULL);
|
|
|
|
|
else
|
|
|
|
|
new_text = g_strconcat ("\0033>>\017 ", split_text[i], NULL);
|
|
|
|
|
|
2014-11-30 22:33:30 -05:00
|
|
|
gtk_xtext_append (GTK_XTEXT (serv->gui->rawlog_textlist)->buffer, new_text, strlen (new_text), 0);
|
2013-05-16 09:21:55 +00:00
|
|
|
|
|
|
|
|
g_free (new_text);
|
2011-02-24 04:14:30 +01:00
|
|
|
}
|
2013-05-16 09:21:55 +00:00
|
|
|
|
|
|
|
|
g_strfreev (split_text);
|
2011-02-24 04:14:30 +01:00
|
|
|
}
|