Ejemplo n.º 1
0
static GtkCMCTreeNode *grouplist_create_parent(const gchar *name,
					     const gchar *pattern)
{
	GtkCMCTreeNode *parent;
	GtkCMCTreeNode *node;
	gchar *cols[3];
	gchar *parent_name;

	if (*name == '\0') return NULL;
	node = grouplist_hash_get_branch_node(name);
	if (node != NULL) return node;

	cols[0] = (gchar *)name;
	cols[1] = cols[2] = "";

	parent_name = grouplist_get_parent_name(name);
	parent = grouplist_create_parent(parent_name, pattern);

	node = parent ? GTK_CMCTREE_ROW(parent)->children
		: GTK_CMCTREE_NODE(GTK_CMCLIST(ctree)->row_list);
	node = gtk_sctree_insert_node(GTK_CMCTREE(ctree), parent, node,
				     cols, 0, NULL, NULL,
				     FALSE, FALSE);
	if (parent && g_pattern_match_simple(pattern, parent_name) == FALSE)
		gtk_cmctree_expand(GTK_CMCTREE(ctree), parent);
	gtk_cmctree_node_set_selectable(GTK_CMCTREE(ctree), node, FALSE);

	grouplist_hash_set_branch_node(name, node);

	g_free(parent_name);

	return node;
}
Ejemplo n.º 2
0
static GtkCMCTreeNode *grouplist_create_branch(NewsGroupInfo *ginfo,
					     const gchar *pattern)
{
	GtkCMCTreeNode *node;
	GtkCMCTreeNode *parent;
	gchar *name = (gchar *)ginfo->name;
	gchar *parent_name;
	gchar *count_str;
	gchar *cols[3];
	gint count;

	count = ginfo->last - ginfo->first;
	if (count < 0)
		count = 0;
	count_str = itos(count);

	cols[0] = ginfo->name;
	cols[1] = count_str;
	if (ginfo->type == 'y')
		cols[2] = "";
	else if (ginfo->type == 'm')
		cols[2] = _("moderated");
	else if (ginfo->type == 'n')
		cols[2] = _("readonly");
	else
		cols[2] = _("unknown");

	parent_name = grouplist_get_parent_name(name);
	parent = grouplist_create_parent(parent_name, pattern);
	node = grouplist_hash_get_branch_node(name);
	if (node) {
		gtk_cmctree_set_node_info(GTK_CMCTREE(ctree), node, cols[0], 0,
					NULL, NULL, FALSE, FALSE);
		gtk_cmctree_node_set_text(GTK_CMCTREE(ctree), node, 1, cols[1]);
		gtk_cmctree_node_set_text(GTK_CMCTREE(ctree), node, 2, cols[2]);
	} else {
		node = parent ? GTK_CMCTREE_ROW(parent)->children
			: GTK_CMCTREE_NODE(GTK_CMCLIST(ctree)->row_list);
		node = gtk_sctree_insert_node(GTK_CMCTREE(ctree), parent, node,
					     cols, 0, NULL, NULL,
					     TRUE, FALSE);
		if (parent &&
		    g_pattern_match_simple(pattern, parent_name) == FALSE)
			gtk_cmctree_expand(GTK_CMCTREE(ctree), parent);
	}
	gtk_cmctree_node_set_selectable(GTK_CMCTREE(ctree), node, TRUE);
	if (node)
		gtk_cmctree_node_set_row_data(GTK_CMCTREE(ctree), node, ginfo);

	g_free(parent_name);

	return node;
}
Ejemplo n.º 3
0
gboolean addressbook_foldersel_selection( AddressIndex *addrIndex,
					AddressBookFile **book, ItemFolder **folder, 
					const gchar* path)
{
	FolderPathMatch folder_path_match = { NULL, FALSE, 0, NULL };
	gboolean retVal = FALSE;
	addressbook_foldersel_cancelled = FALSE;

	if ( ! addressbook_foldersel_dlg.window )
		addressbook_foldersel_create();
	gtk_widget_grab_focus(addressbook_foldersel_dlg.ok_btn);
	gtk_widget_show(addressbook_foldersel_dlg.window);
	manage_window_set_transient(GTK_WINDOW(addressbook_foldersel_dlg.window));
	gtk_window_set_modal(GTK_WINDOW(addressbook_foldersel_dlg.window), TRUE);
	
	addressbook_foldersel_dlg.fiSelected = NULL;

	/* split the folder path we've received, we'll try to match this path, subpath by
	   subpath against the book/folder structure in order to select the folder that
       corresponds to what we received */

	if ( path != NULL ) {
		if ( g_utf8_collate(path, _("Any")) == 0 || strcasecmp(path, "Any") ==0 || *path == '\0' )
			/* consider "Any" (both translated or untranslated forms) and ""
			   as valid addressbook roots */
			folder_path_match.matched = TRUE;
		else
			folder_path_match.folder_path = g_strsplit( path, "/", 256 );
	}

	addressbook_foldersel_load_data( addrIndex, &folder_path_match );

	if ( folder_path_match.folder_path != NULL && folder_path_match.matched == FALSE)
		g_warning("addressbook_foldersel_load_data: couldn't match book/folder path '%s'", path);

	g_strfreev( folder_path_match.folder_path );

	if ( folder_path_match.node != NULL)
		gtk_cmctree_select( GTK_CMCTREE( addressbook_foldersel_dlg.tree_folder ),
							GTK_CMCTREE_NODE( folder_path_match.node ) );
	else
		gtk_cmclist_select_row( GTK_CMCLIST( addressbook_foldersel_dlg.tree_folder ), 0, 0 );
	gtk_widget_show(addressbook_foldersel_dlg.window);

	gtk_main();
	gtk_widget_hide( addressbook_foldersel_dlg.window );
	gtk_window_set_modal(GTK_WINDOW(addressbook_foldersel_dlg.window), FALSE);
	if ( ! addressbook_foldersel_cancelled ) {

		*book = NULL;
		*folder = NULL;

		if ( addressbook_foldersel_dlg.fiSelected ) {
			*book = addressbook_foldersel_dlg.fiSelected->book;
			*folder = addressbook_foldersel_dlg.fiSelected->folder;
			retVal = TRUE;
		}
	}

	gtk_cmclist_clear( GTK_CMCLIST( addressbook_foldersel_dlg.tree_folder ) );

	return retVal;
}