1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2012 Hiroyuki Yamamoto and the Claws Mail team
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  */
19 
20 #ifdef HAVE_CONFIG_H
21 #  include "config.h"
22 #include "claws-features.h"
23 #endif
24 
25 #include "defs.h"
26 
27 #include <glib.h>
28 #include <glib/gi18n.h>
29 #include <gdk/gdkkeysyms.h>
30 #include <gtk/gtk.h>
31 #include <string.h>
32 
33 #include "grouplistdialog.h"
34 #include "mainwindow.h"
35 #include "manage_window.h"
36 #include "gtkutils.h"
37 #include "utils.h"
38 #include "news.h"
39 #include "folder.h"
40 #include "alertpanel.h"
41 #include "recv.h"
42 #include "socket.h"
43 #include "prefs_common.h"
44 
45 #define GROUPLIST_DIALOG_WIDTH		450
46 #define GROUPLIST_DIALOG_HEIGHT		400
47 #define GROUPLIST_COL_NAME_WIDTH	250
48 
49 static gboolean ack;
50 static gboolean locked;
51 
52 static GtkWidget *dialog;
53 static GtkWidget *entry;
54 static GtkWidget *ctree;
55 static GtkWidget *status_label;
56 static GtkWidget *ok_button;
57 static GSList *group_list;
58 static Folder *news_folder;
59 
60 static GSList *subscribed;
61 
62 static void grouplist_dialog_create	(void);
63 static void grouplist_dialog_set_list	(const gchar	*pattern,
64 					 gboolean	 refresh);
65 static void grouplist_search		(void);
66 static void grouplist_clear		(void);
67 static gboolean grouplist_recv_func	(SockInfo	*sock,
68 					 gint		 count,
69 					 gint		 read_bytes,
70 					 gpointer	 data);
71 static void grouplist_size_allocate	(GtkWidget *widget,
72 					 GtkAllocation *allocation);
73 
74 static gint window_deleted	(GtkWidget	*widget,
75 				 GdkEventAny	*event,
76 				 gpointer	 data);
77 static void ok_clicked		(GtkWidget	*widget,
78 				 gpointer	 data);
79 static void cancel_clicked	(GtkWidget	*widget,
80 				 gpointer	 data);
81 static void refresh_clicked	(GtkWidget	*widget,
82 				 gpointer	 data);
83 static gboolean key_pressed	(GtkWidget	*widget,
84 				 GdkEventKey	*event,
85 				 gpointer	 data);
86 static gboolean button_press_cb (GtkCMCTree	*ctree,
87 				 GdkEventButton	*button,
88 				 gpointer	 data);
89 static void entry_activated	(GtkEditable	*editable);
90 static void search_clicked	(GtkWidget	*widget,
91 				 gpointer	 data);
92 
grouplist_dialog(Folder * folder)93 GSList *grouplist_dialog(Folder *folder)
94 {
95 	GNode *node;
96 	FolderItem *item;
97 
98 	if (dialog && gtk_widget_get_visible(dialog)) return NULL;
99 
100 	if (!dialog)
101 		grouplist_dialog_create();
102 
103 	news_folder = folder;
104 
105 	gtk_widget_show(dialog);
106 	gtk_window_set_modal(GTK_WINDOW(dialog), TRUE);
107 	manage_window_set_transient(GTK_WINDOW(dialog));
108 	gtk_widget_grab_focus(ok_button);
109 	gtk_widget_grab_focus(ctree);
110 	GTK_EVENTS_FLUSH();
111 
112 	subscribed = NULL;
113 	for (node = folder->node->children; node != NULL; node = node->next) {
114 		item = FOLDER_ITEM(node->data);
115 		subscribed = g_slist_append(subscribed, g_strdup(item->path));
116 	}
117 
118 	grouplist_dialog_set_list(NULL, TRUE);
119 
120 	if (ack) gtk_main();
121 
122 	manage_window_focus_out(dialog, NULL, NULL);
123 	gtk_widget_hide(dialog);
124 
125 	if (!ack) {
126 		slist_free_strings_full(subscribed);
127 		subscribed = NULL;
128 
129 		for (node = folder->node->children; node != NULL;
130 		     node = node->next) {
131 			item = FOLDER_ITEM(node->data);
132 			subscribed = g_slist_append(subscribed,
133 						    g_strdup(item->path));
134 		}
135 	}
136 
137 	grouplist_clear();
138 
139 	return subscribed;
140 }
141 
grouplist_dialog_create(void)142 static void grouplist_dialog_create(void)
143 {
144 	GtkWidget *vbox;
145 	GtkWidget *hbox;
146 	GtkWidget *msg_label;
147 	GtkWidget *search_button;
148 	GtkWidget *confirm_area;
149 	GtkWidget *cancel_button;
150 	GtkWidget *refresh_button;
151 	GtkWidget *scrolledwin;
152 	static GdkGeometry geometry;
153 	gchar *titles[3];
154 	gint i;
155 
156 	dialog = gtk_dialog_new();
157 	gtk_window_set_resizable(GTK_WINDOW(dialog), TRUE);
158 	gtk_container_set_border_width
159 		(GTK_CONTAINER(gtk_dialog_get_action_area(GTK_DIALOG(dialog))), 5);
160 	gtk_window_set_position(GTK_WINDOW(dialog), GTK_WIN_POS_CENTER);
161 	gtk_window_set_title(GTK_WINDOW(dialog), _("Newsgroup subscription"));
162 	g_signal_connect(G_OBJECT(dialog), "delete_event",
163 			 G_CALLBACK(window_deleted), NULL);
164 	g_signal_connect(G_OBJECT(dialog), "key_press_event",
165 			 G_CALLBACK(key_pressed), NULL);
166 	g_signal_connect(G_OBJECT(dialog), "size_allocate",
167 			 G_CALLBACK(grouplist_size_allocate), NULL);
168 	MANAGE_WINDOW_SIGNALS_CONNECT(dialog);
169 
170 	vbox = gtk_vbox_new(FALSE, 8);
171 	gtk_container_add(GTK_CONTAINER(
172 				gtk_dialog_get_content_area(GTK_DIALOG(dialog))), vbox);
173 	gtk_container_set_border_width(GTK_CONTAINER(vbox), 8);
174 
175 	hbox = gtk_hbox_new(FALSE, 0);
176 	gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
177 
178 	msg_label = gtk_label_new(_("Select newsgroups for subscription:"));
179 	gtk_box_pack_start(GTK_BOX(hbox), msg_label, FALSE, FALSE, 0);
180 
181 	hbox = gtk_hbox_new(FALSE, 8);
182 	gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
183 
184 	msg_label = gtk_label_new(_("Find groups:"));
185 	gtk_box_pack_start(GTK_BOX(hbox), msg_label, FALSE, FALSE, 0);
186 
187 	entry = gtk_entry_new();
188 	gtk_box_pack_start(GTK_BOX(hbox), entry, TRUE, TRUE, 0);
189 	g_signal_connect(G_OBJECT(entry), "activate",
190 			 G_CALLBACK(entry_activated), NULL);
191 
192 	search_button = gtk_button_new_with_label(_(" Search "));
193 	gtk_box_pack_start(GTK_BOX(hbox), search_button, FALSE, FALSE, 0);
194 
195 	g_signal_connect(G_OBJECT(search_button), "clicked",
196 			 G_CALLBACK(search_clicked), NULL);
197 
198 	scrolledwin = gtk_scrolled_window_new(NULL, NULL);
199 	gtk_box_pack_start(GTK_BOX (vbox), scrolledwin, TRUE, TRUE, 0);
200 	gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW (scrolledwin),
201 				       GTK_POLICY_AUTOMATIC,
202 				       GTK_POLICY_AUTOMATIC);
203 
204 	titles[0] = _("Newsgroup name");
205 	titles[1] = _("Messages");
206 	titles[2] = _("Type");
207 	ctree = gtk_sctree_new_with_titles(3, 0, titles);
208 	gtk_container_add(GTK_CONTAINER(scrolledwin), ctree);
209 	gtk_cmclist_set_column_width
210 		(GTK_CMCLIST(ctree), 0, GROUPLIST_COL_NAME_WIDTH);
211 	gtk_cmclist_set_column_auto_resize(GTK_CMCLIST(ctree), 0, TRUE);
212 	gtk_cmclist_set_selection_mode(GTK_CMCLIST(ctree), GTK_SELECTION_MULTIPLE);
213 
214 	gtk_cmctree_set_expander_style(GTK_CMCTREE(ctree),
215 				GTK_CMCTREE_EXPANDER_TRIANGLE);
216 
217 	for (i = 0; i < 3; i++)
218 		gtk_widget_set_can_focus(GTK_CMCLIST(ctree)->column[i].button, FALSE);
219 	g_signal_connect(G_OBJECT(ctree), "button-press-event",
220 			 G_CALLBACK(button_press_cb), NULL);
221 
222 	hbox = gtk_hbox_new(FALSE, 0);
223 	gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
224 
225 	status_label = gtk_label_new("");
226 	gtk_box_pack_start(GTK_BOX(hbox), status_label, FALSE, FALSE, 0);
227 
228 	gtkut_stock_button_set_create(&confirm_area,
229 				      &refresh_button, GTK_STOCK_REFRESH,
230 				      &cancel_button, GTK_STOCK_CANCEL,
231 				      &ok_button, GTK_STOCK_OK);
232 	gtk_container_add(GTK_CONTAINER(gtk_dialog_get_action_area(GTK_DIALOG(dialog))),
233 			  confirm_area);
234 	gtk_widget_grab_default(ok_button);
235 
236 	g_signal_connect(G_OBJECT(ok_button), "clicked",
237 			 G_CALLBACK(ok_clicked), NULL);
238 	g_signal_connect(G_OBJECT(cancel_button), "clicked",
239 			 G_CALLBACK(cancel_clicked), NULL);
240 	g_signal_connect(G_OBJECT(refresh_button), "clicked",
241 			 G_CALLBACK(refresh_clicked), NULL);
242 
243 	if (!geometry.min_width) {
244 		geometry.min_width = GROUPLIST_DIALOG_WIDTH;
245 		geometry.min_height = GROUPLIST_DIALOG_HEIGHT;
246 	}
247 
248 	gtk_window_set_geometry_hints(GTK_WINDOW(dialog), NULL, &geometry,
249 				      GDK_HINT_MIN_SIZE);
250 	gtk_window_set_default_size(GTK_WINDOW(dialog),
251 					prefs_common.news_subscribe_width,
252 					prefs_common.news_subscribe_height);
253 
254 	gtk_widget_show_all(gtk_dialog_get_content_area(GTK_DIALOG(dialog)));
255 }
256 
257 static GHashTable *branch_node_table;
258 
grouplist_hash_init(void)259 static void grouplist_hash_init(void)
260 {
261 	branch_node_table = g_hash_table_new(g_str_hash, g_str_equal);
262 }
263 
grouplist_hash_done(void)264 static void grouplist_hash_done(void)
265 {
266 	hash_free_strings(branch_node_table);
267 	g_hash_table_destroy(branch_node_table);
268 }
269 
grouplist_hash_get_branch_node(const gchar * name)270 static GtkCMCTreeNode *grouplist_hash_get_branch_node(const gchar *name)
271 {
272 	return g_hash_table_lookup(branch_node_table, name);
273 }
274 
grouplist_hash_set_branch_node(const gchar * name,GtkCMCTreeNode * node)275 static void grouplist_hash_set_branch_node(const gchar *name,
276 					   GtkCMCTreeNode *node)
277 {
278 	g_hash_table_insert(branch_node_table, g_strdup(name), node);
279 }
280 
grouplist_get_parent_name(const gchar * name)281 static gchar *grouplist_get_parent_name(const gchar *name)
282 {
283 	gchar *p;
284 
285 	p = strrchr(name, '.');
286 	if (!p)
287 		return g_strdup("");
288 	return g_strndup(name, p - name);
289 }
290 
grouplist_create_parent(const gchar * name,const gchar * pattern)291 static GtkCMCTreeNode *grouplist_create_parent(const gchar *name,
292 					     const gchar *pattern)
293 {
294 	GtkCMCTreeNode *parent;
295 	GtkCMCTreeNode *node;
296 	gchar *cols[3];
297 	gchar *parent_name;
298 
299 	if (*name == '\0') return NULL;
300 	node = grouplist_hash_get_branch_node(name);
301 	if (node != NULL) return node;
302 
303 	cols[0] = (gchar *)name;
304 	cols[1] = cols[2] = "";
305 
306 	parent_name = grouplist_get_parent_name(name);
307 	parent = grouplist_create_parent(parent_name, pattern);
308 
309 	node = parent ? GTK_CMCTREE_ROW(parent)->children
310 		: GTK_CMCTREE_NODE(GTK_CMCLIST(ctree)->row_list);
311 	node = gtk_sctree_insert_node(GTK_CMCTREE(ctree), parent, node,
312 				     cols, 0, NULL, NULL,
313 				     FALSE, FALSE);
314 	if (parent && g_pattern_match_simple(pattern, parent_name) == FALSE)
315 		gtk_cmctree_expand(GTK_CMCTREE(ctree), parent);
316 	gtk_cmctree_node_set_selectable(GTK_CMCTREE(ctree), node, FALSE);
317 
318 	grouplist_hash_set_branch_node(name, node);
319 
320 	g_free(parent_name);
321 
322 	return node;
323 }
324 
grouplist_create_branch(NewsGroupInfo * ginfo,const gchar * pattern)325 static GtkCMCTreeNode *grouplist_create_branch(NewsGroupInfo *ginfo,
326 					     const gchar *pattern)
327 {
328 	GtkCMCTreeNode *node;
329 	GtkCMCTreeNode *parent;
330 	gchar *name = (gchar *)ginfo->name;
331 	gchar *parent_name;
332 	gchar *count_str;
333 	gchar *cols[3];
334 	gint count;
335 
336 	count = ginfo->last - ginfo->first;
337 	if (count < 0)
338 		count = 0;
339 	count_str = itos(count);
340 
341 	cols[0] = ginfo->name;
342 	cols[1] = count_str;
343 	if (ginfo->type == 'y')
344 		cols[2] = "";
345 	else if (ginfo->type == 'm')
346 		cols[2] = _("moderated");
347 	else if (ginfo->type == 'n')
348 		cols[2] = _("readonly");
349 	else
350 		cols[2] = _("unknown");
351 
352 	parent_name = grouplist_get_parent_name(name);
353 	parent = grouplist_create_parent(parent_name, pattern);
354 	node = grouplist_hash_get_branch_node(name);
355 	if (node) {
356 		gtk_cmctree_set_node_info(GTK_CMCTREE(ctree), node, cols[0], 0,
357 					NULL, NULL, FALSE, FALSE);
358 		gtk_cmctree_node_set_text(GTK_CMCTREE(ctree), node, 1, cols[1]);
359 		gtk_cmctree_node_set_text(GTK_CMCTREE(ctree), node, 2, cols[2]);
360 	} else {
361 		node = parent ? GTK_CMCTREE_ROW(parent)->children
362 			: GTK_CMCTREE_NODE(GTK_CMCLIST(ctree)->row_list);
363 		node = gtk_sctree_insert_node(GTK_CMCTREE(ctree), parent, node,
364 					     cols, 0, NULL, NULL,
365 					     TRUE, FALSE);
366 		if (parent &&
367 		    g_pattern_match_simple(pattern, parent_name) == FALSE)
368 			gtk_cmctree_expand(GTK_CMCTREE(ctree), parent);
369 	}
370 	gtk_cmctree_node_set_selectable(GTK_CMCTREE(ctree), node, TRUE);
371 	if (node)
372 		gtk_cmctree_node_set_row_data(GTK_CMCTREE(ctree), node, ginfo);
373 
374 	g_free(parent_name);
375 
376 	return node;
377 }
378 
grouplist_expand_upwards(GtkCMCTree * ctree,const gchar * name)379 static void grouplist_expand_upwards(GtkCMCTree *ctree, const gchar *name) {
380 	const gchar *ptr;
381 	gchar *newname=g_malloc0(strlen(name));
382 	GtkCMCTreeNode *node;
383 
384 	for (ptr=name; *ptr; ptr++) {
385 		if (*ptr == '.') {
386 			node = grouplist_hash_get_branch_node(newname);
387 			if (node != NULL)
388 				gtk_cmctree_expand(ctree, node);
389 		}
390 		newname[ptr-name] = *ptr;
391 	}
392 	g_free(newname);
393 }
394 
grouplist_dialog_set_list(const gchar * pattern,gboolean refresh)395 static void grouplist_dialog_set_list(const gchar *pattern, gboolean refresh)
396 {
397 	static GdkCursor *watch_cursor = NULL;
398 	GSList *cur;
399 	GtkCMCTreeNode *node;
400 	GPatternSpec *pspec;
401 	GdkWindow *window;
402 
403 	if (locked) return;
404 	locked = TRUE;
405 
406 	if (!pattern || *pattern == '\0')
407 		pattern = "*";
408 
409 	if (!watch_cursor)
410 		watch_cursor = gdk_cursor_new(GDK_WATCH);
411 	window = gtk_widget_get_window(dialog);
412 	gdk_window_set_cursor(window, watch_cursor);
413 	main_window_cursor_wait(mainwindow_get_mainwindow());
414 	GTK_EVENTS_FLUSH();
415 
416 	if (refresh) {
417 		ack = TRUE;
418 		grouplist_clear();
419 		recv_set_ui_func(grouplist_recv_func, NULL);
420 		group_list = news_get_group_list(news_folder);
421 		group_list = g_slist_reverse(group_list);
422 		recv_set_ui_func(NULL, NULL);
423 		if (group_list == NULL && ack == TRUE) {
424 			alertpanel_error(_("Can't retrieve newsgroup list."));
425 			locked = FALSE;
426 			gdk_window_set_cursor(window, NULL);
427 			main_window_cursor_normal(mainwindow_get_mainwindow());
428 			return;
429 		}
430 	} else
431 		gtk_cmclist_clear(GTK_CMCLIST(ctree));
432 
433 	gtk_entry_set_text(GTK_ENTRY(entry), pattern);
434 
435 	grouplist_hash_init();
436 
437 	gtk_cmclist_freeze(GTK_CMCLIST(ctree));
438 
439 	pspec = g_pattern_spec_new(pattern);
440 
441 	for (cur = group_list; cur != NULL ; cur = cur->next) {
442 		NewsGroupInfo *ginfo = (NewsGroupInfo *)cur->data;
443 
444 		if (g_pattern_match_string(pspec, ginfo->name)) {
445 			node = grouplist_create_branch(ginfo, pattern);
446 			if (g_slist_find_custom(subscribed, ginfo->name,
447 						(GCompareFunc)g_ascii_strcasecmp)
448 			    != NULL)
449 				gtk_cmctree_select(GTK_CMCTREE(ctree), node);
450 		}
451 	}
452 	for (cur = subscribed; cur; cur = g_slist_next(cur))
453 		grouplist_expand_upwards(GTK_CMCTREE(ctree), (gchar *)cur->data);
454 
455 	g_pattern_spec_free(pspec);
456 
457 	gtk_cmclist_thaw(GTK_CMCLIST(ctree));
458 
459 	grouplist_hash_done();
460 
461 	gtk_label_set_text(GTK_LABEL(status_label), _("Done."));
462 
463 	gdk_window_set_cursor(window, NULL);
464 	main_window_cursor_normal(mainwindow_get_mainwindow());
465 
466 	locked = FALSE;
467 }
468 
grouplist_search(void)469 static void grouplist_search(void)
470 {
471 	gchar *str;
472 
473 	if (locked) return;
474 
475 	str = gtk_editable_get_chars(GTK_EDITABLE(entry), 0, -1);
476 	grouplist_dialog_set_list(str, FALSE);
477 	g_free(str);
478 }
479 
grouplist_clear(void)480 static void grouplist_clear(void)
481 {
482 	gtk_cmclist_clear(GTK_CMCLIST(ctree));
483 	gtk_entry_set_text(GTK_ENTRY(entry), "");
484 	news_group_list_free(group_list);
485 	group_list = NULL;
486 }
487 
grouplist_recv_func(SockInfo * sock,gint count,gint read_bytes,gpointer data)488 static gboolean grouplist_recv_func(SockInfo *sock, gint count, gint read_bytes,
489 				    gpointer data)
490 {
491 	gchar buf[BUFFSIZE];
492 
493 	g_snprintf(buf, sizeof(buf),
494 		   _("%d newsgroups received (%s read)"),
495 		   count, to_human_readable((goffset)read_bytes));
496 	gtk_label_set_text(GTK_LABEL(status_label), buf);
497 	GTK_EVENTS_FLUSH();
498 	if (ack == FALSE)
499 		return FALSE;
500 	else
501 		return TRUE;
502 }
503 
grouplist_size_allocate(GtkWidget * widget,GtkAllocation * allocation)504 static void grouplist_size_allocate(GtkWidget *widget, GtkAllocation *allocation)
505 {
506 	cm_return_if_fail( allocation != NULL );
507 
508 	prefs_common.news_subscribe_width	= allocation->width;
509 	prefs_common.news_subscribe_height	= allocation->height;
510 }
511 
window_deleted(GtkWidget * widget,GdkEventAny * event,gpointer data)512 static gint window_deleted(GtkWidget *widget, GdkEventAny *event, gpointer data)
513 {
514 	ack = FALSE;
515 	if (gtk_main_level() > 1)
516 		gtk_main_quit();
517 
518 	return TRUE;
519 }
520 
ok_clicked(GtkWidget * widget,gpointer data)521 static void ok_clicked(GtkWidget *widget, gpointer data)
522 {
523 	ack = TRUE;
524 	if (gtk_main_level() > 1)
525 		gtk_main_quit();
526 }
527 
cancel_clicked(GtkWidget * widget,gpointer data)528 static void cancel_clicked(GtkWidget *widget, gpointer data)
529 {
530 	ack = FALSE;
531 	if (gtk_main_level() > 1)
532 		gtk_main_quit();
533 }
534 
refresh_clicked(GtkWidget * widget,gpointer data)535 static void refresh_clicked(GtkWidget *widget, gpointer data)
536 {
537 	gchar *str;
538 
539 	if (locked) return;
540 
541 	news_remove_group_list_cache(news_folder);
542 
543 	str = gtk_editable_get_chars(GTK_EDITABLE(entry), 0, -1);
544 	grouplist_dialog_set_list(str, TRUE);
545 	g_free(str);
546 }
547 
key_pressed(GtkWidget * widget,GdkEventKey * event,gpointer data)548 static gboolean key_pressed(GtkWidget *widget, GdkEventKey *event, gpointer data)
549 {
550 	if (event && event->keyval == GDK_KEY_Escape)
551 		cancel_clicked(NULL, NULL);
552 	return FALSE;
553 }
554 
555 /* clist/ctree clear old selection on click (gtk2 only)
556  * - intercept all button clicks (always return TRUE)
557  * - only allow left button single click
558  * - handle click on expander
559  * - update "subscribed" list and un-/select row
560  */
button_press_cb(GtkCMCTree * ctree,GdkEventButton * button,gpointer data)561 static gboolean button_press_cb(GtkCMCTree *ctree, GdkEventButton *button,
562 				gpointer data)
563 {
564 	gint row, col;
565 	GtkCMCTreeNode *node;
566 	NewsGroupInfo *ginfo;
567 	GSList *list;
568 
569 	if (button->type != GDK_BUTTON_PRESS) return TRUE;
570 	if (button->button != 1) return TRUE;
571 	if (button->window != GTK_CMCLIST(ctree)->clist_window) return TRUE;
572 
573 	if (!gtk_cmclist_get_selection_info(GTK_CMCLIST(ctree),
574 				     button->x, button->y, &row, &col))
575 		return TRUE;
576 	node = gtk_cmctree_node_nth(ctree, row);
577 	if (!node) return TRUE;
578 
579 	if (gtk_cmctree_is_hot_spot(ctree, button->x, button->y)) {
580 		gtk_cmctree_toggle_expansion(ctree, node);
581 		return TRUE;
582 	}
583 
584 	ginfo = gtk_cmctree_node_get_row_data(ctree, node);
585 	if (!ginfo) return TRUE;
586 
587 	list = g_slist_find_custom(subscribed, ginfo->name,
588 				   (GCompareFunc)g_ascii_strcasecmp);
589 	if (list) {
590 		g_free(list->data);
591 		subscribed = g_slist_remove(subscribed, list->data);
592 		gtk_cmclist_unselect_row(GTK_CMCLIST(ctree), row, 0);
593 	} else {
594 		subscribed = g_slist_append(subscribed, g_strdup(ginfo->name));
595 		gtk_cmclist_select_row(GTK_CMCLIST(ctree), row, 0);
596 	}
597 
598 	return TRUE;
599 }
600 
entry_activated(GtkEditable * editable)601 static void entry_activated(GtkEditable *editable)
602 {
603 	grouplist_search();
604 }
605 
search_clicked(GtkWidget * widget,gpointer data)606 static void search_clicked(GtkWidget *widget, gpointer data)
607 {
608 	grouplist_search();
609 }
610