⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 chanlist.c

📁 The major functionality added in this release includes: - Rootless mode in X11 - Widget Templt
💻 C
📖 第 1 页 / 共 2 页
字号:
/* 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 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */#include <stdio.h>#include <stdlib.h>#include <string.h>#include "../../config.h"#ifdef HAVE_STRINGS_H#include <strings.h>#endif#include <unistd.h>#include <fcntl.h>#include <time.h>#include "fe-gtk.h"#include "../common/xchat.h"#include "../common/xchatc.h"#include "../common/outbound.h"#include "../common/util.h"#include <gdk/gdkkeysyms.h>#include "gtkutil.h"#include "wins.h"/** * Accepts a regex_t pointer and string to test it with  * Returns 0 if no match, 1 if a match. */#ifndef WIN32static intreg_match (regex_t * regexptr, const char *str){	int m;	m = regexec (regexptr, str, 1, NULL, REG_NOTBOL);	/* regex returns 0 if it's a match: */	return m == 0 ? 1 : 0;}#elsestatic intreg_match (char ** regexptr, const char *str){	return match (*regexptr, str);}#endif/** * Sorts the channel list based upon the user field. */static gintchanlist_compare_user (GtkCList * clist,							  gconstpointer ptr1, gconstpointer ptr2){	int int1;	int int2;	GtkCListRow *row1 = (GtkCListRow *) ptr1;	GtkCListRow *row2 = (GtkCListRow *) ptr2;	int1 = atoi (GTK_CELL_TEXT (row1->cell[clist->sort_column])->text);	int2 = atoi (GTK_CELL_TEXT (row2->cell[clist->sort_column])->text);	return int1 > int2 ? 1 : -1;}/** * Provides the default case-insensitive sorting for the channel  * list. */static gintchanlist_compare_text_ignore_case (GtkCList * clist,											  gconstpointer ptr1, gconstpointer ptr2){	GtkCListRow *row1 = (GtkCListRow *) ptr1;	GtkCListRow *row2 = (GtkCListRow *) ptr2;	return strcasecmp (GTK_CELL_TEXT (row1->cell[clist->sort_column])->text,							 GTK_CELL_TEXT (row2->cell[clist->sort_column])->text);}/** * Updates the caption to reflect the number of users and channels */static voidchanlist_update_caption (struct server *serv){	static gchar *title =		N_("User and Channel Statistics: %d/%d Users on %d/%d Channels");	gchar tbuf[256];	snprintf (tbuf, sizeof tbuf, _(title),				 serv->gui->chanlist_users_shown_count,				 serv->gui->chanlist_users_found_count,				 serv->gui->chanlist_channels_shown_count,				 serv->gui->chanlist_channels_found_count);	gtk_label_set_text (GTK_LABEL (serv->gui->chanlist_label), tbuf);}/** * Resets the various integer counters  */static voidchanlist_reset_counters (struct server *serv){	serv->gui->chanlist_users_found_count = 0;	serv->gui->chanlist_users_shown_count = 0;	serv->gui->chanlist_channels_found_count = 0;	serv->gui->chanlist_channels_shown_count = 0;	chanlist_update_caption (serv);}/** * Resets the vars that keep track of sort options. */static voidchanlist_reset_sort_vars (struct server *serv){	serv->gui->chanlist_sort_type = GTK_SORT_ASCENDING;	serv->gui->chanlist_last_column = 0;}/** * Frees up the dynamic memory needed to store the channel information. */static voidchanlist_data_free (struct server *serv){	GSList *rows;	gchar **data;	if (serv->gui->chanlist_data_stored_rows)	{		for (rows = serv->gui->chanlist_data_stored_rows; rows != NULL;			  rows = rows->next)		{			data = (gchar **) rows->data;			free (data[0]);			free (data[1]);			free (data[2]);			free (data);		}		g_slist_free (serv->gui->chanlist_data_stored_rows);		serv->gui->chanlist_data_stored_rows = NULL;	}}/** * Prepends a row of channel information to the chanlist_data_stored_rows  * GSList. */static voidchanlist_data_prepend_row (struct server *serv, gchar ** next_row){	serv->gui->chanlist_data_stored_rows =		g_slist_prepend (serv->gui->chanlist_data_stored_rows, next_row);}/** * Places a data row into the gui GtkCList, if and only if the row matches * the user and regex requirements. */static voidchanlist_place_row_in_gui (struct server *serv, gchar ** next_row){	int num_users = atoi (next_row[1]);	/* First, update the 'found' counter values */	serv->gui->chanlist_users_found_count += num_users;	serv->gui->chanlist_channels_found_count++;	if (num_users < serv->gui->chanlist_minusers)	{		chanlist_update_caption (serv);		return;	}	if (num_users > serv->gui->chanlist_maxusers		 && serv->gui->chanlist_maxusers > 0)	{		chanlist_update_caption (serv);		return;	}	if (serv->gui->chanlist_wild_text && serv->gui->chanlist_wild_text[0])	{		/* Check what the user wants to match. If both buttons or _neither_		 * button is checked, look for match in both by default. 		 */		if ((serv->gui->chanlist_match_wants_channel			  && serv->gui->chanlist_match_wants_topic)			 ||			 (!serv->gui->chanlist_match_wants_channel			  && !serv->gui->chanlist_match_wants_topic))		{			if (!reg_match (&serv->gui->chanlist_match_regex, next_row[0])				 && !reg_match (&serv->gui->chanlist_match_regex, next_row[2]))			{				chanlist_update_caption (serv);				return;			}		}		else if (serv->gui->chanlist_match_wants_channel)		{			if (!reg_match (&serv->gui->chanlist_match_regex, next_row[0]))			{				chanlist_update_caption (serv);				return;			}		}		else if (serv->gui->chanlist_match_wants_topic)		{			if (!reg_match (&serv->gui->chanlist_match_regex, next_row[2]))			{				chanlist_update_caption (serv);				return;			}		}	}	/*	 * If all the above above tests passed or if no text was in the 	 * chanlist_wild_text, add this entry to the GUI	 */	gtk_clist_prepend (GTK_CLIST (serv->gui->chanlist_list), next_row);	/* Update the 'shown' counter values */	serv->gui->chanlist_users_shown_count += num_users;	serv->gui->chanlist_channels_shown_count++;	chanlist_update_caption (serv);}/** * Performs the actual refresh operations. */static voidchanlist_do_refresh (struct server *serv){	if (serv->connected)	{		chanlist_data_free (serv);		chanlist_reset_counters (serv);		chanlist_update_caption (serv);		gtk_clist_clear (GTK_CLIST (serv->gui->chanlist_list));		gtk_widget_set_sensitive (serv->gui->chanlist_refresh, FALSE);		handle_command ("/LIST", serv->front_session, FALSE, FALSE);	} else		gtkutil_simpledialog ("Not connected.");}static voidchanlist_refresh (GtkWidget * wid, struct server *serv){	/* JG NOTE: Didn't see actual use of wid here, so just forwarding	 * this to chanlist_do_refresh because I use it without any widget	 * param in chanlist_build_gui_list when the user presses enter	 * or apply for the first time if the list has not yet been 	 * received.	 */	chanlist_do_refresh (serv);}/** * Fills the gui GtkCList with stored items from the GSList. */static voidchanlist_build_gui_list (struct server *serv){	GSList *rows;	GtkCList *clist;	/* first check if the list is present */	if (serv->gui->chanlist_data_stored_rows == NULL)	{		chanlist_do_refresh (serv);		return;	}	clist = GTK_CLIST (serv->gui->chanlist_list);	/* turn off sorting because this _greatly_ quickens the reinsertion */	gtk_clist_set_auto_sort (clist, FALSE);	/* freeze that GtkCList to make it go fasssster as well */	gtk_clist_freeze (clist);	gtk_clist_clear (clist);	/* Reset the counters */	chanlist_reset_counters (serv);	/* Refill the list */	for (rows = serv->gui->chanlist_data_stored_rows; rows != NULL;		  rows = rows->next)	{		chanlist_place_row_in_gui (serv, (gchar **) rows->data);	}	gtk_clist_thaw (clist);	gtk_clist_set_auto_sort (clist, TRUE);	gtk_clist_sort (clist);}/** * Accepts incoming channel data from inbound.c, allocates new space for a * gchar**, forwards newly allocated row to chanlist_data_prepend_row * and chanlist_place_row_in_gui. */voidfe_add_chan_list (struct server *serv, char *chan, char *users, char *topic){	gchar **next_row;	next_row = (gchar **) malloc (sizeof (gchar *) * 3);	next_row[0] = strdup (chan);	next_row[1] = strdup (users);	next_row[2] = strip_color (topic);	/* add this row to the data */	chanlist_data_prepend_row (serv, next_row);	/* _possibly_ add the row to the gui */	chanlist_place_row_in_gui (serv, next_row);}/** * The next several functions simply handle signals from widgets to update  * the list and state variables.  */static voidchanlist_editable_keypress (GtkWidget * widget, GdkEventKey * event,									 struct server *serv){	if (event->keyval == GDK_Return)		chanlist_build_gui_list (serv);}static voidchanlist_apply_pressed (GtkButton * button, struct server *serv){	chanlist_build_gui_list (serv);}static voidchanlist_wild (GtkWidget * wid, struct server *serv){	/* Store the pattern text in the wild_text var so next time the window is 	 * opened it is remembered. 	 */	strncpy (serv->gui->chanlist_wild_text,				gtk_entry_get_text (GTK_ENTRY (wid)), 255);#ifdef WIN32	serv->gui->chanlist_match_regex =		strdup (gtk_entry_get_text (GTK_ENTRY (wid)));

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -