summary refs log tree commit diff stats
path: root/src/fe-gtk/ignoregui.c
blob: a30b8cd156979cf671037dab782b3b1fea5fe702 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
/* 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include "fe-gtk.h"

#include "../common/hexchat.h"
#include "../common/ignore.h"
#include "../common/cfgfiles.h"
#include "../common/fe.h"
#include "gtkutil.h"
#include "maingui.h"

enum
{
	MASK_COLUMN,
	CHAN_COLUMN,
	PRIV_COLUMN,
	NOTICE_COLUMN,
	CTCP_COLUMN,
	DCC_COLUMN,
	INVITE_COLUMN,
	UNIGNORE_COLUMN,
	N_COLUMNS
};

static GtkWidget *ignorewin = 0;

static GtkWidget *num_ctcp;
static GtkWidget *num_priv;
static GtkWidget *num_chan;
static GtkWidget *num_noti;
static GtkWidget *num_invi;

static GtkTreeModel *
get_store (void)
{
	return gtk_tree_view_get_model (g_object_get_data (G_OBJECT (ignorewin), "view"));
}

static int
ignore_get_flags (GtkTreeModel *model, GtkTreeIter *iter)
{
	gboolean chan, priv, noti, ctcp, dcc, invi, unig;
	int flags = 0;

	gtk_tree_model_get (model, iter, 1, &chan, 2, &priv, 3, &noti,
	                    4, &ctcp, 5, &dcc, 6, &invi, 7, &unig, -1);
	if (chan)
		flags |= IG_CHAN;
	if (priv)
		flags |= IG_PRIV;
	if (noti)
		flags |= IG_NOTI;
	if (ctcp)
		flags |= IG_CTCP;
	if (dcc)
		flags |= IG_DCC;
	if (invi)
		flags |= IG_INVI;
	if (unig)
		flags |= IG_UNIG;
	return flags;
}

static void
mask_edited (GtkCellRendererText *render, gchar *path, gchar *new, gpointer dat)
{
	GtkListStore *store = GTK_LIST_STORE (get_store ());
	GtkTreeIter iter;
	char *old;
	int flags;

	gtkutil_treemodel_string_to_iter (GTK_TREE_MODEL (store), path, &iter);
	gtk_tree_model_get (GTK_TREE_MODEL (store), &iter, 0, &old, -1);
	
	if (!strcmp (old, new))	/* no change */
		;
	else if (ignore_exists (new))	/* duplicate, ignore */
		fe_message (_("That mask already exists."), FE_MSG_ERROR);
	else
	{
		/* delete old mask, and add new one with original flags */
		ignore_del (old, NULL);
		flags = ignore_get_flags (GTK_TREE_MODEL (store), &iter);
		ignore_add (new, flags, TRUE);

		/* update tree */
		gtk_list_store_set (store, &iter, MASK_COLUMN, new, -1);
	}
	g_free (old);
	
}

static void
option_toggled (GtkCellRendererToggle *render, gchar *path, gpointer data)
{
	GtkListStore *store = GTK_LIST_STORE (get_store ());
	GtkTreeIter iter;
	int col_id = GPOINTER_TO_INT (data);
	gboolean active;
	char *mask;
	int flags;

	gtkutil_treemodel_string_to_iter (GTK_TREE_MODEL (store), path, &iter);

	/* update model */
	gtk_tree_model_get (GTK_TREE_MODEL (store), &iter, col_id, &active, -1);
	gtk_list_store_set (store, &iter, col_id, !active, -1);

	/* update ignore list */
	gtk_tree_model_get (GTK_TREE_MODEL (store), &iter, 0, &mask, -1);
	flags = ignore_get_flags (GTK_TREE_MODEL (store), &iter);
	if (ignore_add (mask, flags, TRUE) != 2)
		g_warning ("ignore treeview is out of sync!\n");
	
	g_free (mask);
}

static GtkWidget *
ignore_treeview_new (GtkWidget *box)
{
	GtkListStore *store;
	GtkWidget *view;
	GtkTreeViewColumn *col;
	GtkCellRenderer *render;
	int col_id;

	store = gtk_list_store_new (N_COLUMNS, G_TYPE_STRING,
	                            G_TYPE_BOOLEAN, G_TYPE_BOOLEAN,
	                            G_TYPE_BOOLEAN, G_TYPE_BOOLEAN,
	                            G_TYPE_BOOLEAN, G_TYPE_BOOLEAN,
	                            G_TYPE_BOOLEAN, G_TYPE_BOOLEAN);
	g_return_val_if_fail (store != NULL, NULL);

	view = gtkutil_treeview_new (box, GTK_TREE_MODEL (store),
	                             NULL,
	                             MASK_COLUMN, _("Mask"),
	                             CHAN_COLUMN, _("Channel"),
	                             PRIV_COLUMN, _("Private"),
	                             NOTICE_COLUMN, _("Notice"),
	                             CTCP_COLUMN, _("CTCP"),
	                             DCC_COLUMN, _("DCC"),
	                             INVITE_COLUMN, _("Invite"),
	                             UNIGNORE_COLUMN, _("Unignore"),
	                             -1);

	gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (view), TRUE);
	gtk_tree_view_column_set_expand (gtk_tree_view_get_column (GTK_TREE_VIEW (view), 0), TRUE);

	/* attach to signals and customise columns */
	for (col_id=0; (col = gtk_tree_view_get_column (GTK_TREE_VIEW (view), col_id));
	     col_id++)
	{
		GList *list = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (col));
		GList *tmp;

		for (tmp = list; tmp; tmp = tmp->next)
		{
			render = tmp->data;
			if (col_id > 0)	/* it's a toggle button column */
			{
				g_signal_connect (render, "toggled", G_CALLBACK (option_toggled),
				                  GINT_TO_POINTER (col_id));
			} else	/* mask column */
			{
				g_object_set (G_OBJECT (render), "editable", TRUE, NULL);
				g_signal_connect (render, "edited", G_CALLBACK (mask_edited), NULL);
				/* make this column sortable */
				gtk_tree_view_column_set_sort_column_id (col, col_id);
				gtk_tree_view_column_set_min_width (col, 272);
			}
			/* centre titles */
			gtk_tree_view_column_set_alignment (col, 0.5);
		}

		g_list_free (list);
	}
	
	gtk_widget_show (view);
	return view;
}

static void
ignore_delete_entry_clicked (GtkWidget * wid, struct session *sess)
{
	GtkTreeView *view = g_object_get_data (G_OBJECT (ignorewin), "view");
	GtkListStore *store = GTK_LIST_STORE (gtk_tree_view_get_model (view));
	GtkTreeIter iter;
	GtkTreePath *path;
	char *mask = NULL;

	if (gtkutil_treeview_get_selected (view, &iter, 0, &mask, -1))
	{
		/* delete this row, select next one */
		if (gtk_list_store_remove (store, &iter))
		{
			path = gtk_tree_model_get_path (GTK_TREE_MODEL (store), &iter);
			gtk_tree_view_scroll_to_cell (view, path, NULL, TRUE, 1.0, 0.0);
			gtk_tree_view_set_cursor (view, path, NULL, FALSE);
			gtk_tree_path_free (path);
		}

		ignore_del (mask, NULL);
		g_free (mask);
	}
}

static void
ignore_store_new (int cancel, char *mask, gpointer data)
{
	GtkTreeView *view = g_object_get_data (G_OBJECT (ignorewin), "view");
	GtkListStore *store = GTK_LIST_STORE (get_store ());
	GtkTreeIter iter;
	GtkTreePath *path;
	int flags = IG_CHAN | IG_PRIV | IG_NOTI | IG_CTCP | IG_DCC | IG_INVI;

	if (cancel)
		return;
	/* check if it already exists */
	if (ignore_exists (mask))
	{
		fe_message (_("That mask already exists."), FE_MSG_ERROR);
		return;
	}

	ignore_add (mask, flags, TRUE);

	gtk_list_store_append (store, &iter);
	/* ignore everything by default */
	gtk_list_store_set (store, &iter, 0, mask, 1, TRUE, 2, TRUE, 3, TRUE,
	                    4, TRUE, 5, TRUE, 6, TRUE, 7, FALSE, -1);
	/* make sure the new row is visible and selected */
	path = gtk_tree_model_get_path (GTK_TREE_MODEL (store), &iter);
	gtk_tree_view_scroll_to_cell (view, path, NULL, TRUE, 1.0, 0.0);
	gtk_tree_view_set_cursor (view, path, NULL, FALSE);
	gtk_tree_path_free (path);
}

static void
ignore_clear_cb (GtkDialog *dialog, gint response)
{
	GtkListStore *store = GTK_LIST_STORE (get_store ());
	GtkTreeIter iter;
	char *mask;

	gtk_widget_destroy (GTK_WIDGET (dialog));

	if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &iter) && response == GTK_RESPONSE_OK)
	{
		/* remove from ignore_list */
		do
		{
			mask = NULL;
			gtk_tree_model_get (GTK_TREE_MODEL (store), &iter, MASK_COLUMN, &mask, -1);
			ignore_del (mask, NULL);
			g_free (mask);
		}
		while (gtk_tree_model_iter_next (GTK_TREE_MODEL (store), &iter));

		/* remove from GUI */
		gtk_list_store_clear (store);
	}
}

static void
ignore_clear_entry_clicked (GtkWidget * wid)
{
	GtkWidget *dialog;

	dialog = gtk_message_dialog_new (NULL, 0,
								GTK_MESSAGE_QUESTION, GTK_BUTTONS_OK_CANCEL,
					_("Are you sure you want to remove all ignores?"));
	g_signal_connect (G_OBJECT (dialog), "response",
							G_CALLBACK (ignore_clear_cb), NULL);
	gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_MOUSE);
	gtk_widget_show (dialog);
}

static void
ignore_new_entry_clicked (GtkWidget * wid, struct session *sess)
{
	fe_get_str (_("Enter mask to ignore:"), "nick!userid@host.com",
	            ignore_store_new, NULL);

}

static void
close_ignore_gui_callback ()
{
	ignore_save ();
	ignorewin = 0;
}

static GtkWidget *
ignore_stats_entry (GtkWidget * box, char *label, int value)
{
	GtkWidget *wid;
	char buf[16];

	sprintf (buf, "%d", value);
	gtkutil_label_new (label, box);
	wid = gtkutil_entry_new (16, box, 0, 0);
	gtk_widget_set_size_request (wid, 30, -1);
	gtk_editable_set_editable (GTK_EDITABLE (wid), FALSE);
	gtk_widget_set_sensitive (GTK_WIDGET (wid), FALSE);
	gtk_entry_set_text (GTK_ENTRY (wid), buf);

	return wid;
}

void
ignore_gui_open ()
{
	GtkWidget *vbox, *box, *stat_box, *frame;
	GtkWidget *view;
	GtkListStore *store;
	GtkTreeIter iter;
	GSList *temp = ignore_list;
	char *mask;
	gboolean private, chan, notice, ctcp, dcc, invite, unignore;

	if (ignorewin)
	{
		mg_bring_tofront (ignorewin);
		return;
	}

	ignorewin =
			  mg_create_generic_tab ("IgnoreList", _(DISPLAY_NAME": Ignore list"),
											FALSE, TRUE, close_ignore_gui_callback,
											NULL, 600, 256, &vbox, 0);
	gtkutil_destroy_on_esc (ignorewin);

	view = ignore_treeview_new (vbox);
	g_object_set_data (G_OBJECT (ignorewin), "view", view);
	
	frame = gtk_frame_new (_("Ignore Stats:"));
	gtk_widget_show (frame);

	stat_box = gtk_hbox_new (0, 2);
	gtk_container_set_border_width (GTK_CONTAINER (stat_box), 6);
	gtk_container_add (GTK_CONTAINER (frame), stat_box);
	gtk_widget_show (stat_box);

	num_chan = ignore_stats_entry (stat_box, _("Channel:"), ignored_chan);
	num_priv = ignore_stats_entry (stat_box, _("Private:"), ignored_priv);
	num_noti = ignore_stats_entry (stat_box, _("Notice:"), ignored_noti);
	num_ctcp = ignore_stats_entry (stat_box, _("CTCP:"), ignored_ctcp);
	num_invi = ignore_stats_entry (stat_box, _("Invite:"), ignored_invi);

	gtk_box_pack_start (GTK_BOX (vbox), frame, 0, 0, 5);

	box = gtk_hbutton_box_new ();
	gtk_button_box_set_layout (GTK_BUTTON_BOX (box), GTK_BUTTONBOX_SPREAD);
	gtk_box_pack_start (GTK_BOX (vbox), box, FALSE, FALSE, 2);
	gtk_container_set_border_width (GTK_CONTAINER (box), 5);
	gtk_widget_show (box);

	gtkutil_button (box, GTK_STOCK_NEW, 0, ignore_new_entry_clicked, 0,
						 _("Add..."));
	gtkutil_button (box, GTK_STOCK_DELETE, 0, ignore_delete_entry_clicked,
						 0, _("Delete"));
	gtkutil_button (box, GTK_STOCK_CLEAR, 0, ignore_clear_entry_clicked,
						 0, _("Clear"));

	store = GTK_LIST_STORE (gtk_tree_view_get_model (GTK_TREE_VIEW (view)));

	while (temp)
	{
		struct ignore *ignore = temp->data;

		mask = ignore->mask;
		chan = (ignore->type & IG_CHAN);
		private = (ignore->type & IG_PRIV);
		notice = (ignore->type & IG_NOTI);
		ctcp = (ignore->type & IG_CTCP);
		dcc = (ignore->type & IG_DCC);
		invite = (ignore->type & IG_INVI);
		unignore = (ignore->type & IG_UNIG);

		gtk_list_store_append (store, &iter);
		gtk_list_store_set (store, &iter,
		                    MASK_COLUMN, mask,
		                    CHAN_COLUMN, chan,
		                    PRIV_COLUMN, private,
		                    NOTICE_COLUMN, notice,
		                    CTCP_COLUMN, ctcp,
		                    DCC_COLUMN, dcc,
		                    INVITE_COLUMN, invite,
		                    UNIGNORE_COLUMN, unignore,
		                    -1);
		
		temp = temp->next;
	}
	gtk_widget_show (ignorewin);
}

void
fe_ignore_update (int level)
{
	/* some ignores have changed via /ignore, we should update
	   the gui now */
	/* level 1 = the list only. */
	/* level 2 = the numbers only. */
	/* for now, ignore level 1, since the ignore GUI isn't realtime,
	   only saved when you click OK */
	char buf[16];

	if (level == 2 && ignorewin)
	{
		sprintf (buf, "%d", ignored_ctcp);
		gtk_entry_set_text (GTK_ENTRY (num_ctcp), buf);

		sprintf (buf, "%d", ignored_noti);
		gtk_entry_set_text (GTK_ENTRY (num_noti), buf);

		sprintf (buf, "%d", ignored_chan);
		gtk_entry_set_text (GTK_ENTRY (num_chan), buf);

		sprintf (buf, "%d", ignored_invi);
		gtk_entry_set_text (GTK_ENTRY (num_invi), buf);

		sprintf (buf, "%d", ignored_priv);
		gtk_entry_set_text (GTK_ENTRY (num_priv), buf);
	}
}
t;#!&amp;"<br><small>(Added in version 2.0.9. Older versions will return NULL)</small></td><td>string</td> <tr><td>context</td><td>(xchat_context *) pointer. Can be used with xchat_set_context</td><td>string</td></tr> <tr><td>flags</td><td>Server/Channel Bits:<br> <table> <tr><td>Bit #</td><td>Value</td><td>Description</td></tr> <tr><td>0</td><td>1</td><td>Connected</td></tr> <tr><td>1</td><td>2</td><td>Connecting in Progress</td></tr> <tr><td>2</td><td>4</td><td>You are away</td></tr> <tr><td>3</td><td>8</td><td>End of MOTD (Login complete)</td></tr> <tr><td>4</td><td>16</td><td>Has WHOX (ircu)</td></tr> <tr><td>5</td><td>32</td><td>Has IDMSG (FreeNode)</td></tr> <tr><td>6</td><td>64</td><td>Hide Join/Part Messages</td></tr> <tr><td>7</td><td>128</td><td>unused (was Color Paste in old versions)</td></tr> <tr><td>8</td><td>256</td><td>Beep on Message</td></tr> <tr><td>9</td><td>512</td><td>Blink Tray</td></tr> <tr><td>10</td><td>1024</td><td>Blink Task Bar</td></tr> </table> <br><small>(Bits 0-5 added in 2.0.9. Bits 6-8 added in 2.6.6. Bit 9 added in 2.8.0. Bit 10 in 2.8.6)</small></td><td>int</td></tr> <tr><td>id</td><td>Unique server ID<br><small>(Added in version 2.0.8. Older versions will return -1)</small></td><td>int</td></tr> <tr><td>lag</td><td>Lag in milliseconds<br><small>(Added in version 2.6.8. Older versions will return -1)</small></td><td>int</td> <tr><td>maxmodes</td><td>Maximum modes per line<br><small>(Added in version 2.0.9. Older versions will return -1)</small></td><td>int</td> <tr><td>network</td><td>Network name to which this channel belongs<br><small>(Added in version 2.0.2. Older versions will return NULL)</small></td><td>string</td></tr> <tr><td>nickprefixes</td><td>Nickname prefixes e.g. "@+"<br><small>(Added in version 2.0.9. Older versions will return NULL)</small></td><td>string</td> <tr><td>nickmodes</td><td>Nickname mode chars e.g. "ov"<br><small>(Added in version 2.0.9. Older versions will return NULL)</small></td><td>string</td> <tr><td>queue</td><td>Number of bytes in the send-queue<br><small>(Added in version 2.6.8. Older versions will return -1)</small></td><td>int</td> <tr><td>server</td><td>Server name to which this channel belongs</td><td>string</td></tr> <tr><td>type</td><td>Type of context this is: 1-Server 2-Channel 3-Dialog<br><small>(Added in version 2.0.2. Older versions will return -1)</small></td><td>int</td></tr> <tr><td>users</td><td>Number of users in this channel<br><small>(Added in version 2.0.8. Older versions will return -1)</small></td><td>int</td></tr> </table> </blockquote> "dcc" - list of DCC file transfers. Fields: <blockquote> <table border=1> <tr bgcolor="#dddddd"><td>Name</td><td>Description</td><td>Type</td></tr> <tr><td>address32</td><td>Address of the remote user (ipv4 address)</td><td>int</td></tr> <tr><td>cps</td><td>Bytes per second (speed)</td><td>int</td></tr> <tr><td>destfile</td><td>Destination full pathname</td><td>string</td></tr> <tr><td>file</td><td>File name</td><td>string</td></tr> <tr><td>nick</td><td>Nickname of person who the file is from/to</td><td>string</td></tr> <tr><td>port</td><td>TCP port number</td><td>int</td></tr> <tr><td>pos</td><td>Bytes sent/received</td><td>int</td></tr> <tr><td>poshigh</td><td>Bytes sent/received, high order 32 bits</td><td>int</td></tr> <tr><td>resume</td><td>Point at which this file was resumed (or zero if it was not resumed)</td><td>int</td></tr> <tr><td>resumehigh</td><td>Point at which this file was resumed, high order 32 bits</td><td>int</td></tr> <tr><td>size</td><td>File size in bytes, low order 32 bits (cast it to unsigned)</td><td>int</td></tr> <tr><td>sizehigh</td><td>File size in bytes, high order 32 bits</td><td>int</td></tr> <tr><td>status</td><td>DCC Status: 0-Queued 1-Active 2-Failed 3-Done 4-Connecting 5-Aborted</td><td>int</td></tr> <tr><td>type</td><td>DCC Type: 0-Send 1-Receive 2-ChatRecv 3-ChatSend</td><td>int</td></tr> </table> </blockquote> "ignore" - current ignore list. <blockquote> <table border=1> <tr bgcolor="#dddddd"><td>Name</td><td>Description</td><td>Type</td></tr> <tr><td>mask</td><td>Ignore mask. .e.g: *!*@*.aol.com</td><td>string</td></tr> <tr><td>flags</td><td>Bit field of flags. 0=Private 1=Notice 2=Channel 3=Ctcp<br> 4=Invite 5=UnIgnore 6=NoSave 7=DCC</td><td>int</td></tr> </table> </blockquote> "notify" - list of people on notify. <blockquote> <table border=1> <tr bgcolor="#dddddd"><td>Name</td><td>Description</td><td>Type</td></tr> <tr><td>networks</td><td>Networks to which this nick applies. Comma separated. May be NULL. <br><small>(Added in version 2.6.8)</small></td><td>string</td></tr> <tr><td>nick</td><td>Nickname</td><td>string</td></tr> <tr><td>flags</td><td>Bit field of flags. 0=Is online.</td><td>int</td></tr> <tr><td>on</td><td>Time when user came online.</td><td>time_t</td></tr> <tr><td>off</td><td>Time when user went offline.</td><td>time_t</td></tr> <tr><td>seen</td><td>Time when user the user was last verified still online.</td><td>time_t</td></tr> </table> <small>The entire "notify" list was added in xchat 2.0.8. Fields are only valid for the context when xchat_list_get() was called (i.e. you get information about the user ON THAT ONE SERVER ONLY). You may cycle through the "channels" list to find notify information for every server.</small> </blockquote> "users" - list of users in the current channel. <blockquote> <table border=1> <tr bgcolor="#dddddd"><td>Name</td><td>Description</td><td>Type</td></tr> <tr><td>away</td><td>Away status (boolean)<br><small>(Added in version 2.0.6. Older versions will return -1)</small></td><td>int</td></tr> <tr><td>lasttalk</td><td>Last time the user was seen talking<br><small>(Added in version 2.4.2. Older versions will return -1)</small></td><td>time_t</td></tr> <tr><td>nick</td><td>Nick name</td><td>string</td></tr> <tr><td>host</td><td>Host name in the form: user@host (or NULL if not known).</td><td>string</td></tr> <tr><td>prefix</td><td>Prefix character, .e.g: @ or +. Points to a single char.</td><td>string</td></tr> <tr><td>realname</td><td>Real name or NULL<br><small>(Added in version 2.8.6)</small></td><td>string</td></tr> <tr><td>selected</td><td>Selected status in the user list, only works for retrieving the user list of the focused tab<br><small>(Added in version 2.6.1. Older versions will return -1)</small></td><td>int</td></tr> </table> </blockquote> </blockquote> Example: <br> <pre> list = xchat_list_get(ph, <font color="#f800f8">&quot;dcc&quot;</font>); <font color="#a02828"><b>if</b></font>(list) { xchat_print(ph, <font color="#f800f8">&quot;--- DCC LIST ------------------</font><font color="#6858c8">\n</font><font color="#f800f8">&quot;</font> <font color="#f800f8">&quot;File To/From KB/s Position</font><font color="#6858c8">\n</font><font color="#f800f8">&quot;</font>); <font color="#a02828"><b>while</b></font>(xchat_list_next(ph, list)) { xchat_printf(ph, <font color="#f800f8">&quot;</font><font color="#6858c8">%6s</font><font color="#f800f8"> </font><font color="#6858c8">%10s</font><font color="#f800f8"> </font><font color="#6858c8">%.2f</font><font color="#f800f8"> </font><font color="#6858c8">%d</font><font color="#6858c8">\n</font><font color="#f800f8">&quot;</font>, xchat_list_str(ph, list, <font color="#f800f8">&quot;file&quot;</font>), xchat_list_str(ph, list, <font color="#f800f8">&quot;nick&quot;</font>), xchat_list_int(ph, list, <font color="#f800f8">&quot;cps&quot;</font>) / <font color="#f800f8">1024</font>, xchat_list_int(ph, list, <font color="#f800f8">&quot;pos&quot;</font>)); } xchat_list_free(ph, list); } </pre> <br> <h3><a name=win32>Plugins on Windows (Win32)</a></h3> Yes, it can be done. All you need is either <a href="http://msdn.microsoft.com/visualc/vctoolkit2003/">MSVC</a> (Visual Studio) or <a href="http://www.mingw.org">MINGW</a>, both these compilers are free to download. Simply compile your plugin as a DLL. You should have the following files: <ul> <li><a href="http://xchat.org/docs/xchat-plugin.h">xchat-plugin.h</a> - Main Plugin header</li> <li>plugin.c - Your plugin, you need to write this one :)</li> <li>plugin.def - A simple text file containing the following:</li> </ul> <div class=box> EXPORTS<br> &nbsp; xchat_plugin_init<br> &nbsp; xchat_plugin_deinit<br> &nbsp; xchat_plugin_get_info<br> </div> <br>Leave out <i>xchat_plugin_deinit</i> if you don't intend to define that function. Then, to compile, type this at your command prompt:<br><br> <div class=bbox> <font color="#00FF00">MSVC</font> <br>&nbsp;cl -O1 -MD -G5 -DWIN32 -c plugin.c<br> <br>&nbsp;link /DLL /out:plugin.dll /SUBSYSTEM:WINDOWS plugin.obj /def:plugin.def /base:0x00d40000 <br><br> <font color="#00FF00">GCC (MINGW)</font> <br>&nbsp;gcc -Wall -Os -DWIN32 -c plugin.c<br> <br>&nbsp;dllwrap --def plugin.def --dllname plugin.dll plugin.o<br><br> </div> <br>For a complete example, have a look at the source code of the <a href="http://xchat.org/win32/testing/xcdns-src.zip">DNS Plugin</a>, which also contains a Makefile. <br><br> <font color=red>Caveat:</font> Plugins compiled on Win32 MUST have a global variable called <b>ph</b>, which is the plugin_handle, much like in the <a href="#sample">sample plugin</a> above. <br><br> <h3><a name=gui>Controlling the GUI</a></h3> <p> A simple way to perform basic GUI functions is to use the /GUI command. You can execute this command through the input-box, or by calling xchat_command(ph, "GUI .....");. </p> <blockquote> <table border=0 cellpadding=4> <tr><td>GUI ATTACH</td><td>Same function as "Attach Window" in the XChat menu (new for 2.6.2).</td></tr> <tr><td>GUI DETACH</td><td>Same function as "Detach Tab" in the XChat menu (new for 2.6.2).</td></tr> <tr><td>GUI APPLY</td><td>Similar to clicking OK in the settings window. Execute this after /SET to activate GUI changes (new for 2.8.0)</td></tr> <tr><td>GUI COLOR <i>n</i></td><td>Change the tab color of the current context, where n is a number from 0 to 3.</td></tr> <tr><td>GUI FOCUS</td><td>Focus the current window or tab.</td></tr> <tr><td>GUI FLASH</td><td>Flash the taskbar button. It will flash only if the window isn't focused and will stop when it is focused by the user.</td></tr> <tr><td>GUI HIDE</td><td>Hide the main xchat window completely (this is used by the Systray plugin).</td></tr> <tr><td>GUI ICONIFY</td><td>Iconify (minimize to taskbar) the current xchat window.</td></tr> <tr><td>GUI MSGBOX <i>text</i></td><td>Displays a asynchronous message box with your text (new for 2.4.5).</td></tr> <tr><td>GUI SHOW</td><td>Show the main xchat window (if currently hidden).</td></tr> </table> </blockquote> <p> Note, the FLASH, ICONIFY and COLOR args were added in xchat 2.0.8, they will not work with previous versions. </p> <a name=menu>Starting from 2.4.5 you can add your own items to the menu bar. The menu command has this syntax</a>: <pre> MENU [-eX] [-i&lt;ICONFILE>] [-k&lt;mod>,&lt;key>] [-m] [-pX] [-rX,group] [-tX] {ADD|DEL} &lt;path> [command] [unselect command]</pre> For example: <pre> MENU -p5 ADD FServe MENU ADD "FServe/Show File List" "fs list" MENU ADD FServe/- MENU -k4,101 -t1 ADD "FServe/Enabled" "fs on" "fs off" MENU -e0 ADD "FServe/Do Something" "fs action" </pre> In the example above, it would be recommended to execute "MENU DEL FServe" inside your xchat_plugin_deinit function. The special item with name "-" will add a separator line. <br><br> Parameters and flags: <blockquote> <table border=1 cellpadding=4 rules=all> <tr><td>-eX</td><td>Set enable flag to X. -e0 for disable, -e1 for enable. This lets you create a disabled (shaded) item.</td></tr> <tr><td>-iFILE</td><td>Use an icon filename FILE (new for 2.8.0). Not supported for toggles or radio items.</td></tr> <tr><td>-k&lt;mod>,&lt;key></td><td>Specify a keyboard shortcut. "mod" is the modifier which is a bitwise OR of: 1-SHIFT 4-CTRL 8-ALT in decimal. "key" is the key value in decimal, e.g. -k5,101 would specify SHIFT-CTRL-E.</td></tr> <tr><td>-m</td><td>Specify that this label should be treated as <a href="http://developer.gnome.org/doc/API/2.0/pango/PangoMarkupFormat.html">Pango Markup</a> language. Since forward slash ("/") is already used in menu paths, you should replace closing tags with an ASCII 003 instead e.g.: xchat_command(ph, "MENU -m ADD \"&lt;b>Bold Menu&lt;\003b>\""); (new for 2.6.6).</td></tr> <tr><td>-pX</td><td>Specify a menu item's position number. e.g. -p5 will cause the item to be inserted in the 5th place. New for 2.8.0: If the position is a negative number, it will be used as an offset from the bottom/right-most item.</td></tr> <tr><td>-rX,group</td><td>Specify a radio menu item, with initial state X and a group name (new for 2.8.0). The group name should be the exact label of another menu item (without the path) that this item will be grouped with. For radio items, only a select command will be executed (no unselect command).</td></tr> <tr><td>-tX</td><td>Specify a toggle menu item with an initial state. -t0 for an "unticked" item and -t1 for a "ticked" item.</td></tr> </table> </blockquote> If you want to change an item's toggle state or enabled flag, just ADD an item with exactly the same name and command and specify the -tX -eX parameters you need. <br><br>It's also possible to add items to XChat's existing menus, for example:<br> <pre> MENU ADD "Settings/Sub Menu" MENU -t0 ADD "Settings/Sub Menu/My Setting" myseton mysetoff </pre> However, internal names and layouts of XChat's menu may change in the future, so use at own risk. <br><br> Here is an example of Radio items: <pre> MENU ADD "Language" MENU -r1,"English" ADD "Language/English" cmd1 MENU -r0,"English" ADD "Language/Spanish" cmd2 MENU -r0,"English" ADD "Language/German" cmd3</pre> <br> From 2.8.0, you can also change menus other than the main one (i.e popup menus). Currently they are: <blockquote> <table border=1 cellpadding=4 rules=all> <tr bgcolor="#999999"><td>Root Name</td><td>Menu</td></tr> <tr><td>$TAB</td><td>Tab menu (right click a channel/query tab or treeview row)</td></tr> <tr><td>$TRAY</td><td>System Tray menu</td></tr> <tr><td>$URL</td><td>URL link menu</td></tr> <tr><td>$NICK</td><td>Userlist nick-name popup menu</td></tr> <tr><td>$CHAN</td><td>Menu when clicking a channel in the text area (since 2.8.4)</td></tr> </table> </blockquote> <pre> Example: MENU -p0 ADD "$TAB/Cycle Channel" cycle </pre> <br> <a name=tray>Starting from 2.8.0 you can manipulate XChat's system tray icon using the /TRAY command</a>: <pre> Usage: TRAY -f &lt;timeout> &lt;file1> [&lt;file2>] Flash tray between two icons. Leave off file2 to use default xchat icon. TRAY -f &lt;filename> Set tray to a fixed icon. TRAY -i &lt;number> Flash tray with an internal icon. <small>2=Message 5=Highlight 8=Private 11=File</small> TRAY -t &lt;text> Set the tray tooltip. TRAY -b &lt;title> &lt;text> Set the tray balloon. <small>Supported on Windows from 2.8.1 and 2.8.2 on Linux (libnotify required on Linux).</small> </pre> Filenames can be ICO or PNG format. PNG format is supported on Linux/BSD and Windows XP (but requires installation of GDI+ on Windows 2000). Set a timeout of -1 to use XChat's default. <br><br> <h3><a name=unicode>Handling UTF-8/Unicode strings</a></h3> <p> The XChat plugin API specifies that strings passed to and from xchat must be encoded in UTF-8. <br><br> What does this mean for the plugin programmer? You just have to be a little careful when passing strings obtained from IRC to system calls. For example, if you're writing a file-server bot, someone might message you a filename. Can you pass this filename directly to open()? Maybe! If you're lazy... The correct thing to do is to convert the string to "system locale encoding", otherwise your plugin will fail on non-ascii characters. <br><br> Here are examples on how to do this conversion on Unix and Windows. In this example, someone will CTCP you the message "SHOWFILE &lt;filename&gt;". <br><br> </p> <pre> static int ctcp_cb(char *word[], char *word_eol[], void *userdata) { if(strcmp(word[1], "SHOWFILE") == 0) { get_file_name(nick, word[2]); } return XCHAT_EAT_XCHAT; } static void get_file_name(char *nick, char *fname) { char buf[256]; FILE *fp; <font color="#777777"> /* the fname is in UTF-8, because it came from the xchat API */</font> </pre><font color="#33aa44">#ifdef _WIN32</font><pre> wchar_t wide_name[MAX_PATH]; <font color="#777777"> /* convert UTF-8 to WIDECHARs (aka UTF-16LE) */</font> if (MultiByteToWideChar(CP_UTF8, 0, fname, -1, wide_name, MAX_PATH) < 1) return; <font color="#777777"> /* now we have WIDECHARs, so we can _wopen() or CreateFileW(). */ /* _wfopen actually requires NT4, Win2000, XP or newer. */</font> fp = _wfopen(wide_name, "r"); </pre><font color="#33aa44">#else</font><pre> char *loc_name; <font color="#777777"> /* convert UTF-8 to System Encoding */</font> loc_name = g_filename_from_utf8(fname, -1, 0, 0, 0); if(!loc_name) return; <font color="#777777"> /* now open using the system's encoding */</font> fp = fopen(loc_name, "r"); g_free(loc_name); </pre><font color="#33aa44">#endif</font><pre> if (fp) { while (fgets (buf, sizeof(buf), fp)) { <font color="#777777"> /* send every line to the user that requested it */</font> xchat_commandf (ph, "QUOTE NOTICE %s :%s", nick, buf); } fclose (fp); } } </pre> <br><br> <h1>Functions</h1> <h3><a class=cmd name="xchat_hook_command">&nbsp;xchat_hook_command()&nbsp;</a></h3> <b>Prototype:</b> xchat_hook *xchat_hook_command(xchat_plugin *ph, const char *name, int pri, xchat_cmd_cb *callb, const char *help_text, void *userdata); <br> <br><b>Description:</b> Adds a new /command. This allows your program to handle commands entered at the input box. To capture text without a "/" at the start (non-commands), you may hook a special name of "". i.e xchat_hook_command(ph, "", ...);. <br> Starting from version 2.6.8, commands hooked that begin with a period ('.') will be hidden in /HELP and /HELP -l. <br> <br><b>Arguments:</b> <blockquote><b>ph:</b> Plugin handle (as given to xchat_plugin_init). <br><b>name:</b> Name of the command (without the forward slash). <br><b>pri:</b> Priority of this command. Use XCHAT_PRI_NORM. <br><b>callb:</b> Callback function. This will be called when the user executes the given command name. <br><b>help_text:</b> String of text to display when the user executes /help for this command. May be NULL if you're lazy. <br><b>userdata:</b> Pointer passed to the callback function.</blockquote> <b>Returns:</b> Pointer to the hook. Can be passed to xchat_unhook. <br> <br><b>Example:</b> <blockquote> <pre> static int onotice_cb(char *word[], char *word_eol[], void *userdata) { if(word_eol[2][0] == 0) { xchat_printf(ph, "Second arg must be the message!\n"); return XCHAT_EAT_ALL; } xchat_commandf(ph, "NOTICE @%s :%s", xchat_get_info(ph, "channel"), word_eol[2]); return XCHAT_EAT_ALL; } xchat_hook_command(ph, "ONOTICE", XCHAT_PRI_NORM, onotice_cb, "Usage: ONOTICE &lt;message> Sends a notice to all ops", NULL); </pre> </blockquote> <br> <h3><a class=cmd name="xchat_hook_fd">&nbsp;xchat_hook_fd()&nbsp;</a></h3> <b>Prototype:</b> xchat_hook *xchat_hook_fd(xchat_plugin *ph, int fd, int flags, xchat_fd_cb *callb, void *userdata); <br> <br><b>Description:</b> Hooks a socket or file descriptor. WIN32: Passing a pipe from MSVCR71, MSVCR80 or other variations is not supported at this time. <br> <br><b>Arguments:</b> <blockquote><b>ph:</b> Plugin handle (as given to xchat_plugin_init). <br><b>fd:</b> The file descriptor or socket. <br><b>flags:</b> One or more of XCHAT_FD_READ, XCHAT_FD_WRITE, XCHAT_FD_EXCEPTION, XCHAT_FD_NOTSOCKET. Use bitwise OR to combine them. XCHAT_FD_NOTSOCKET tells xchat that the provided <b>fd</b> is not a socket, but a "MSVCRT.DLL" pipe. <br><b>callb:</b> Callback function. This will be called when the socket is available for reading/writing or exception (depending on your chosen <b>flags</b>) <br><b>userdata:</b> Pointer passed to the callback function.</blockquote> <b>Returns:</b> Pointer to the hook. Can be passed to xchat_unhook. <br><br><br> <h3><a class=cmd name="xchat_hook_print">&nbsp;xchat_hook_print()&nbsp;</a></h3> <b>Prototype:</b> <font color="#f8a400"><b>xchat_hook</b></font> *xchat_hook_print(<font color="#f8a400"><b>xchat_plugin</b></font> *ph, <font color="#f8a400"><b>const char</b></font> *name, <font color="#f8a400"><b>int</b></font> pri, <font color="#f8a400"><b>xchat_print_cb</b></font> *callb, <font color="#f8a400"><b>void</b></font> *userdata); <br> <br><b>Description:</b> Registers a function to trap any print events. The event names may be any available in the "Advanced > Text Events" window. There are also some extra "special" events you may hook using this function. Currently they are:<blockquote> "Open Context" - Called when a new xchat_context is created. <br>"Close Context" - Called when a xchat_context pointer is closed. <br>"Focus Tab" - Called when a tab is brought to front. <br>"Focus Window" - Called a toplevel window is focused, or the main tab-window is focused by the window manager. <br>"DCC Chat Text" - Called when some text from a DCC Chat arrives. It provides these elements in the word[] array:<blockquote>word[1] Address <br>word[2] Port <br>word[3] Nick <br>word[4] The Message </blockquote> "Key Press" - Called when some keys are pressed in the input-box (since 2.4.2). It provides these elements in the word[] array:<blockquote>word[1] Key Value <br>word[2] State Bitfield (shift, capslock, alt) <br>word[3] String version of the key <br>word[4] Length of the string (may be 0 for unprintable keys) </blockquote> </blockquote> <br><b>Arguments:</b> <blockquote><b>ph:</b> Plugin handle (as given to xchat_plugin_init). <br><b>name:</b> Name of the print event (as in Edit Event Texts Window). <br><b>pri:</b> Priority of this command. Use XCHAT_PRI_NORM. <br><b>callb:</b> Callback function. This will be called when this event name is printed. <br><b>userdata:</b> Pointer passed to the callback function.</blockquote> <b>Returns:</b> Pointer to the hook. Can be passed to xchat_unhook. <br> <br><b>Example:</b> <blockquote> <pre> static int youpart_cb(char *word[], void *userdata) { xchat_printf(ph, "You have left channel %s\n", word[3]); return XCHAT_EAT_XCHAT; /* dont let xchat do its normal printing */ } xchat_hook_print(ph, "You Part", XCHAT_PRI_NORM, youpart_cb, NULL); </pre> </blockquote> <br> <h3><a class=cmd name="xchat_hook_server">&nbsp;xchat_hook_server()&nbsp;</a></h3> <b>Prototype:</b> xchat_hook *xchat_hook_server(xchat_plugin *ph, const char *name, int pri, xchat_serv_cb *callb, void *userdata); <br> <br><b>Description:</b> Registers a function to be called when a certain server event occurs. You can use this to trap PRIVMSG, NOTICE, PART, a server numeric etc... If you want to hook every line that comes from the IRC server, you may use the special name of "RAW LINE". <br> <br><b>Arguments:</b> <blockquote><b>ph:</b> Plugin handle (as given to xchat_plugin_init). <br><b>name:</b> Name of the server event. <br><b>pri:</b> Priority of this command. Use XCHAT_PRI_NORM. <br><b>callb:</b> Callback function. This will be called when this event is received from the server. <br><b>userdata:</b> Pointer passed to the callback function.</blockquote> <b>Returns:</b> Pointer to the hook. Can be passed to xchat_unhook. <br> <br><b>Example:</b> <blockquote> <pre> static int kick_cb(char *word[], char *word_eol[], void *userdata) { xchat_printf(ph, "%s was kicked from %s (reason=%s)\n", word[4], word[3], word_eol[5]); return XCHAT_EAT_NONE; /* don't eat this event, let other plugins and xchat see it too */ } xchat_hook_server(ph, "KICK", XCHAT_PRI_NORM, kick_cb, NULL); </pre> </blockquote> <br> <h3><a class=cmd name="xchat_hook_timer">&nbsp;xchat_hook_timer()&nbsp;</a></h3> <b>Prototype:</b> xchat_hook *xchat_hook_timer(xchat_plugin *ph, int timeout, xchat_timer_cb *callb, void *userdata); <br> <br><b>Description:</b> Registers a function to be called every "timeout" milliseconds. <br> <br><b>Arguments:</b> <blockquote><b>ph:</b> Plugin handle (as given to xchat_plugin_init). <br><b>timeout:</b> Timeout in milliseconds (1000 is 1 second). <br><b>callb:</b> Callback function. This will be called every "timeout" milliseconds. <br><b>userdata:</b> Pointer passed to the callback function.</blockquote> <b>Returns:</b> Pointer to the hook. Can be passed to xchat_unhook. <br> <br><b>Example:</b> <blockquote> <pre> static xchat_hook *myhook; static int stop_cb(char *word[], char *word_eol[], void *userdata) { if(myhook != NULL) { xchat_unhook(ph, myhook); myhook = NULL; xchat_print(ph, "Timeout removed!\n"); } return XCHAT_EAT_ALL; } static int timeout_cb(void *userdata) { xchat_print(ph, "Annoying message every 5 seconds! Type /STOP to stop it.\n"); return 1; /* return 1 to keep the timeout going */ } myhook = xchat_hook_timer(ph, 5000, timeout_cb, NULL); xchat_hook_command(ph, "STOP", XCHAT_PRI_NORM, stop_cb, NULL, NULL); </pre><br> </blockquote> <h3><a class=cmd name="xchat_unhook">&nbsp;xchat_unhook()&nbsp;</a></h3> <b>Prototype:</b> void *xchat_unhook(xchat_plugin *ph, xchat_hook *hook); <br> <br><b>Description:</b> Unhooks any hook registered with xchat_hook_print/server/timer/command. When plugins are unloaded, all of its hooks are automatically removed, so you don't need to call this within your xchat_plugin_deinit() function. <br> <br><b>Arguments:</b> <blockquote><b>ph:</b> Plugin handle (as given to xchat_plugin_init). <br><b>hook:</b> Pointer to the hook, as returned by xchat_hook_*. <br></blockquote> <b>Returns:</b> The userdata you originally gave to xchat_hook_*. <br><br> <h3><a class=cmd name="xchat_command">&nbsp;xchat_command()&nbsp;</a></h3> <b>Prototype:</b> void xchat_command(xchat_plugin *ph, const char *command); <br> <br><b>Description:</b> Executes a command as if it were typed in xchat's input box. <br> <br><b>Arguments:</b> <blockquote><b>ph:</b> Plugin handle (as given to xchat_plugin_init). <br><b>command:</b> Command to execute, without the forward slash "/". <br><br> </blockquote> <h3><a class=cmd name="xchat_commandf">&nbsp;xchat_commandf()&nbsp;</a></h3> <b>Prototype:</b> void xchat_commandf(xchat_plugin *ph, const char *format, ...); <br> <br><b>Description:</b> Executes a command as if it were typed in xchat's input box and provides string formating like printf. <br> <br><b>Arguments:</b> <blockquote><b>ph:</b> Plugin handle (as given to xchat_plugin_init). <br><b>format:</b> The format string. <br><br> </blockquote> <h3><a class=cmd name="xchat_print">&nbsp;xchat_print()&nbsp;</a></h3> <b>Prototype:</b> void xchat_print(xchat_plugin *ph, const char *text); <br> <br><b>Description:</b> Prints some text to the current tab/window. <br> <br><b>Arguments:</b> <blockquote><b>ph:</b> Plugin handle (as given to xchat_plugin_init). <br><b>text:</b> Text to print. May contain mIRC color codes. <br><br> </blockquote> <h3><a class=cmd name="xchat_printf">&nbsp;xchat_printf()&nbsp;</a></h3> <b>Prototype:</b> void xchat_printf(xchat_plugin *ph, const char *format, ...); <br> <br><b>Description:</b> Prints some text to the current tab/window and provides formating like printf. <br> <br><b>Arguments:</b> <blockquote><b>ph:</b> Plugin handle (as given to xchat_plugin_init). <br><b>format:</b> The format string. <br><br> </blockquote> <h3><a class=cmd name="xchat_emit_print">&nbsp;xchat_emit_print()&nbsp;</a></h3> <b>Prototype:</b> int xchat_emit_print(xchat_plugin *ph, const char *event_name, ...); <br> <br><b>Description:</b> Generates a print event. This can be any event found in the Preferences > Advanced > Text Events window. The vararg parameter list MUST always be NULL terminated. Special care should be taken when calling this function inside a print callback (from xchat_hook_print), as not to cause endless recursion. <br> <br><b>Arguments:</b> <blockquote><b>ph:</b> Plugin handle (as given to xchat_plugin_init). <br><b>event_name:</b> Text event to print. <br><br> </blockquote> <b>Returns:</b> 1-Success 0-Failure. <br><br> <b>Example:</b> <pre> xchat_emit_print(ph, "Channel Message", "John", "Hi there", "@", NULL); </pre> <br><br> <h3><a class=cmd name="xchat_send_modes">&nbsp;xchat_send_modes()&nbsp;</a><small>(new for 2.0.9)</small></h3> <b>Prototype:</b> void xchat_send_modes (xchat_plugin *ph, const char *targets[], int ntargets, int modes_per_line, char sign, char mode) <br> <br><b>Description:</b> Sends a number of channel mode changes to the current channel. For example, you can Op a whole group of people in one go. It may send multiple MODE lines if the request doesn't fit on one. Pass 0 for <b>modes_per_line</b> to use the current server's maximum possible. This function should only be called while in a channel context. <br> <br><b>Arguments:</b> <blockquote><b>ph:</b> Plugin handle (as given to xchat_plugin_init). <br><b>targets:</b> Array of targets (strings). The names of people whom the action will be performed on. <br><b>ntargets:</b> Number of elements in the array given. <br><b>modes_per_line:</b> Maximum modes to send per line. <br><b>sign:</b> Mode sign, '-' or '+'. <br><b>mode:</b> Mode char, e.g. 'o' for Ops.<br> </blockquote> <b>Example:</b> (Ops the three names given) <pre> const char *names_to_Op[] = {"John", "Jack", "Jill"}; xchat_send_modes(ph, names_to_Op, 3, 0, '+', 'o'); </pre> <br><br> <h3><a class=cmd name="xchat_find_context">&nbsp;xchat_find_context()&nbsp;</a></h3> <b>Prototype:</b> xchat_context *xchat_find_context(xchat_plugin *ph, const char *servname, const char *channel); <br> <br><b>Description:</b> Finds a context based on a channel and servername. If servname is NULL, it finds any channel (or query) by the given name. If channel is NULL, it finds the front-most tab/window of the given servname. If NULL is given for both arguments, the currently focused tab/window will be returned.<br> Changed in 2.6.1. If servname is NULL, it finds the channel (or query) by the given name in the same server group as the current context. If that doesn't exists then find any by the given name. <br> <br><b>Arguments:</b> <blockquote><b>ph:</b> Plugin handle (as given to xchat_plugin_init). <br><b>servname:</b> Servername or NULL. <br><b>channel:</b> Channelname or NULL. <br> </blockquote> <b>Returns:</b> Context pointer (for use with xchat_set_context) or NULL. <br><br><br> <h3><a class=cmd name="xchat_get_context">&nbsp;xchat_get_context()&nbsp;</a></h3> <b>Prototype:</b> xchat_context *xchat_get_context(xchat_plugin *ph); <br> <br><b>Description:</b> Returns the current context for your plugin. You can use this later with xchat_set_context. <br> <br><b>Arguments:</b> <blockquote><b>ph:</b> Plugin handle (as given to xchat_plugin_init). <br> </blockquote> <b>Returns:</b> Context pointer (for use with xchat_set_context). <br><br><br> <h3><a class=cmd name="xchat_get_info">&nbsp;xchat_get_info()&nbsp;</a></h3> <b>Prototype:</b> const char *xchat_get_info(xchat_plugin *ph, const char *id); <br> <br><b>Description:</b> Returns information based on your current context. <br> <br><b>Arguments:</b> <blockquote><b>ph:</b> Plugin handle (as given to xchat_plugin_init). <br><b>id:</b> ID of the information you want. Currently supported IDs are (case sensitive): <blockquote> <table border=0> <tr><td width="18%">away</td><td>away reason or NULL if you are not away.</td></tr> <tr><td>channel</td><td>current channel name.</td></tr> <tr><td>charset</td><td>character-set used in the current context (since 2.4.2).</td></tr> <tr><td>event_text &lt;name></td><td>text event format string for <i>name</i> (since 2.8.2).</td></tr> <tr><td>gtkwin_ptr</td><td>(GtkWindow *) (since 2.8.9).</td></tr> <tr><td>host</td><td>real hostname of the server you connected to.</td></tr> <tr><td>inputbox</td><td>the input-box contents, what the user has typed (since 2.4.1).</td></tr> <tr><td>libdirfs</td><td>library directory. e.g. /usr/lib/xchat. The same directory used for auto-loading plugins (since 2.4.0).<small>This string isn't necessarily UTF-8, but local file system encoding.</small></td></tr> <tr><td>modes</td><td>channel modes, if known, or NULL (since 2.8.1).</td></tr> <tr><td>network</td><td>current network name or NULL.</td></tr> <tr><td>nick</td><td>your current nick name.</td></tr> <tr><td>nickserv</td><td>nickserv password for this network or NULL (since 2.4.3).</td></tr> <tr><td>server</td><td>current server name (what the server claims to be). NULL if you are not connected.</td></tr> <tr><td>topic</td><td>current channel topic.</td></tr> <tr><td>version</td><td>xchat version number.</td></tr> <tr><td>win_ptr</td><td>native window pointer. Unix: (GtkWindow *) Win32: HWND (since 2.6.0).</td></tr> <tr><td>win_status</td><td>window status: "active", "hidden" or "normal" (since 2.0.9).</td> <tr><td>xchatdir</td><td>xchat config directory, e.g.: /home/user/.xchat2 <small>This string is encoded in UTF-8, which means you _should_ convert it to "locale" encoding before using functions like open() or OpenFile(). For best <a href="#unicode">Unicode support</a> on Linux, convert this string using g_filename_from_utf8 and on Windows convert this string to UTF-16LE (wide) and use OpenFileW() etc.</small></td></tr> <tr><td>xchatdirfs</td><td>xchat config directory, e.g.: /home/user/.xchat2 (since 2.0.9).<small>This string is encoded in local file system encoding, making it ideal for direct use with functions like open() or OpenFile(). For real Unicode support on Windows, it's best not to use xchatdirfs, but xchatdir instead.</small></td></tr> </table> </blockquote> </blockquote> <b>Returns:</b> A string of the requested information, or NULL. This string must not be freed and must be copied if needed after the call to xchat_get_info. <br><br><br> <h3><a class=cmd name="xchat_get_prefs">&nbsp;xchat_get_prefs()&nbsp;</a></h3> <b>Prototype:</b> int xchat_get_prefs(xchat_plugin *ph, const char *name, const char **string, int *integer); <br> <br><b>Description:</b> Provides xchat's setting information (that which is available through the /set command). A few extra bits of information are available that don't appear in the /set list, currently they are: <br> <blockquote> <table border=0 cellpadding=5> <tr><td width="18%">state_cursor</td><td>Current input-box cursor position (characters, not bytes). Since 2.4.2.</td></tr> <tr><td width="18%">id</td><td>Unique server id. Since 2.6.1.</td></tr> </table> </blockquote> <br><b>Arguments:</b> <blockquote><b>ph:</b> Plugin handle (as given to xchat_plugin_init). <br><b>name:</b> Setting name required. <br><b>string:</b> Pointer-pointer which to set. <br><b>integer:</b> Pointer to an integer to set, if setting is a Boolean or Integer type. </blockquote> <b>Returns:</b> 0-Failed 1-Returned a string 2-Returned an Integer 3-Returned a Boolean. <br><br><b>Example:</b> <blockquote> <pre> { int i; const char *str; if (xchat_get_prefs (ph, "irc_nick1", &amp;str, &amp;i) == 1) { xchat_printf (ph, "Current nickname setting: %s\n", str); } }</pre> </blockquote> <br><br> <h3><a class=cmd name="xchat_set_context">&nbsp;xchat_set_context()&nbsp;</a></h3> <b>Prototype:</b> int xchat_set_context(xchat_plugin *ph, xchat_context *ctx); <br> <br><b>Description:</b> Changes your current context to the one given. <br> <br><b>Arguments:</b> <blockquote><b>ph:</b> Plugin handle (as given to xchat_plugin_init). <br><b>ctx:</b> Context to change to (obtained with xchat_get_context or xchat_find_context). <br> </blockquote> <b>Returns:</b> 1 for success, 0 for failure. <br><br><br> <h3><a class=cmd name="xchat_nickcmp">&nbsp;xchat_nickcmp()&nbsp;</a></h3> <b>Prototype:</b> int xchat_nickcmp(xchat_plugin *ph, const char *s1, const char *s2); <br> <br><b>Description:</b> Performs a nick name comparision, based on the current server connection. This might be a RFC1459 compliant string compare, or plain ascii (in the case of DALNet). Use this to compare channels and nicknames. The function works the same way as strcasecmp. <br> <br><b>Arguments:</b> <blockquote><b>ph:</b> Plugin handle (as given to xchat_plugin_init). <br><b>s1:</b> String to compare. <br><b>s2:</b> String to compare s1 to. <br> </blockquote> <b>Quote from RFC1459:</b> <blockquote> Because of IRC's scandanavian origin, the characters {}| are considered to be the lower case equivalents of the characters []\, respectively. This is a critical issue when determining the equivalence of two nicknames. </blockquote> <b>Returns:</b> An integer less than, equal to, or greater than zero if s1 is found, respectively, to be less than, to match, or be greater than s2. <br><br><br> <h3><a class=cmd name="xchat_strip">&nbsp;xchat_strip()&nbsp;</a><small>(new for 2.4.2)</small></h3> <b>Prototype:</b> char *xchat_strip(xchat_plugin *ph, const char *str, int len, int flags); <br> <br><b>Description:</b> Strips mIRC color codes and/or text attributes (bold, underlined etc) from the given string and returns a newly allocated string. <br> <br><b>Arguments:</b> <blockquote><b>ph:</b> Plugin handle (as given to xchat_plugin_init). <br><b>str:</b> String to strip. <br><b>len:</b> Length of the string (or -1 for NULL terminated). <br><b>flags:</b> Bit-field of flags: 0-Strip mIRC colors, 1-Strip text attributes. <br> </blockquote> <b>Returns:</b> A newly allocated string or NULL for failure. You must free this string with xchat_free. <br><br><b>Example:</b> <blockquote> <pre> { char *new_text; /* strip both colors and attributes by using the 0 and 1 bits (1 BITWISE-OR 2) */ new_text = xchat_strip(ph, "\00312Blue\003 \002Bold!\002", -1, 1 | 2); if(new_text) { /* new_text should now contain only "Blue Bold!" */ xchat_printf(ph, "%s\n", new_text); xchat_free(ph, new_text); } }</pre> </blockquote> <br><br> <h3><a class=cmd name="xchat_free">&nbsp;xchat_free()&nbsp;</a><small>(new for 2.4.2)</small></h3> <b>Prototype:</b> void xchat_free(xchat_plugin *ph, void *ptr); <br> <br><b>Description:</b> Frees a string returned by xchat_* functions. Currently only used to free strings from xchat_strip. <br> <br><b>Arguments:</b> <blockquote><b>ph:</b> Plugin handle (as given to xchat_plugin_init). <br><b>ptr:</b> Pointer to free. <br> </blockquote> <br><br> <h3><a class=cmd name="xchat_pluginpref_set_str">&nbsp;xchat_pluginpref_set_str()&nbsp;</a><small>(new for 2.9.0)</small></h3> <b>Prototype:</b> int xchat_pluginpref_set_str (xchat_plugin *ph, const char *var, const char *value); <br> <br><b>Description:</b> Saves a plugin-specific setting with string value to a plugin-specific config file. <br> <br><b>Arguments:</b> <blockquote><b>ph:</b> Plugin handle (as given to xchat_plugin_init). <br><b>var:</b> Name of the setting to save. <br><b>value:</b> String value of the the setting. <br> </blockquote> <b>Returns:</b> 1 for success, 0 for failure. <br><br><b>Example:</b> <blockquote> <pre>int xchat_plugin_init (xchat_plugin *plugin_handle, char **plugin_name, char **plugin_desc, char **plugin_version, char *arg) { ph = plugin_handle; *plugin_name = "Tester Thingie"; *plugin_desc = "Testing stuff"; *plugin_version = "1.0"; xchat_pluginpref_set_str (ph, "myvar1", "I want to save this string!"); xchat_pluginpref_set_str (ph, "myvar2", "This is important, too."); return 1; /* return 1 for success */ }</pre> </blockquote> In the example above, the settings will be saved to the plugin_tester_thingie.conf file, and its content will be: <blockquote> <pre>myvar1 = I want to save this string! myvar2 = This is important, too.</pre> </blockquote> You should never need to edit this file manually. <br><br><br> <h3><a class=cmd name="xchat_pluginpref_get_str">&nbsp;xchat_pluginpref_get_str()&nbsp;</a><small>(new for 2.9.0)</small></h3> <b>Prototype:</b> int xchat_pluginpref_get_str (xchat_plugin *ph, const char *var, char *dest); <br> <br><b>Description:</b> Loads a plugin-specific setting with string value from a plugin-specific config file. <br> <br><b>Arguments:</b> <blockquote><b>ph:</b> Plugin handle (as given to xchat_plugin_init). <br><b>var:</b> Name of the setting to load. <br><b>dest:</b> Array to save the loaded setting's string value to. <br> </blockquote> <b>Returns:</b> 1 for success, 0 for failure. <br><br><br> <h3><a class=cmd name="xchat_pluginpref_set_int">&nbsp;xchat_pluginpref_set_int()&nbsp;</a><small>(new for 2.9.0)</small></h3> <b>Prototype:</b> int xchat_pluginpref_set_int (xchat_plugin *ph, const char *var, int value); <br> <br><b>Description:</b> Saves a plugin-specific setting with decimal value to a plugin-specific config file. <br> <br><b>Arguments:</b> <blockquote><b>ph:</b> Plugin handle (as given to xchat_plugin_init). <br><b>var:</b> Name of the setting to save. <br><b>value:</b> Decimal value of the the setting. <br> </blockquote> <b>Returns:</b> 1 for success, 0 for failure. <br><br><b>Example:</b> <blockquote> <pre>static int saveint_cb (char *word[], char *word_eol[], void *user_data) { int buffer = atoi (word[2]); if (buffer > 0 && buffer < INT_MAX) { if (xchat_pluginpref_set_int (ph, "myint1", buffer)) { xchat_printf (ph, "Setting successfully saved!\n"); } else { xchat_printf (ph, "Error while saving!\n"); } } else { xchat_printf (ph, "Invalid input!\n"); } return XCHAT_EAT_XCHAT; }</pre> </blockquote> You only need these kind of complex checks if you're saving user input, which can be non-numeric. <br><br><br> <h3><a class=cmd name="xchat_pluginpref_get_int">&nbsp;xchat_pluginpref_get_int()&nbsp;</a><small>(new for 2.9.0)</small></h3> <b>Prototype:</b> int xchat_pluginpref_get_int (xchat_plugin *ph, const char *var); <br> <br><b>Description:</b> Loads a plugin-specific setting with decimal value from a plugin-specific config file. <br> <br><b>Arguments:</b> <blockquote><b>ph:</b> Plugin handle (as given to xchat_plugin_init). <br><b>var:</b> Name of the setting to load. <br> </blockquote> <b>Returns:</b> The decimal value of the requested setting upon success, -1 for failure. <br><br><br> <h3><a class=cmd name="xchat_pluginpref_delete">&nbsp;xchat_pluginpref_delete()&nbsp;</a><small>(new for 2.9.0)</small></h3> <b>Prototype:</b> int xchat_pluginpref_delete (xchat_plugin *ph, const char *var); <br> <br><b>Description:</b> Deletes a plugin-specific setting from a plugin-specific config file. <br> <br><b>Arguments:</b> <blockquote><b>ph:</b> Plugin handle (as given to xchat_plugin_init). <br><b>var:</b> Name of the setting to delete. <br> </blockquote> <b>Returns:</b> 1 for success, 0 for failure. If the given setting didn't exist, it also returns 1, so 1 only indicates that the setting won't exist after the call. <br><br><br> <h3><a class=cmd name="xchat_pluginpref_list">&nbsp;xchat_pluginpref_list()&nbsp;</a><small>(new for 2.9.0)</small></h3> <b>Prototype:</b> int xchat_pluginpref_list (xchat_plugin *ph, char *dest); <br> <br><b>Description:</b> Builds a comma-separated list of the currently saved settings from a plugin-specific config file. <br> <br><b>Arguments:</b> <blockquote><b>ph:</b> Plugin handle (as given to xchat_plugin_init). <br><b>dest:</b> Array to save the list to. <br> </blockquote> <b>Returns:</b> 1 for success, 0 for failure (nonexistent, empty or inaccessible config file). <br><br><br> </body> </html>