static void 
on_remote_find (GtkAction* action, SeahorseKeyserverResults* self) 
{
	g_return_if_fail (SEAHORSE_IS_KEYSERVER_RESULTS (self));
	g_return_if_fail (GTK_IS_ACTION (action));
	seahorse_keyserver_search_show (seahorse_viewer_get_window (SEAHORSE_VIEWER (self)));
}
static void 
on_view_collapse_all (GtkAction* action, SeahorseKeyserverResults* self) 
{
	g_return_if_fail (SEAHORSE_IS_KEYSERVER_RESULTS (self));
	g_return_if_fail (GTK_IS_ACTION (action));
	gtk_tree_view_collapse_all (self->pv->view);
}
static void 
on_app_close (GtkAction* action, SeahorseKeyserverResults* self) 
{
	g_return_if_fail (SEAHORSE_IS_KEYSERVER_RESULTS (self));
	g_return_if_fail (action == NULL || GTK_IS_ACTION (action));
	seahorse_widget_destroy (SEAHORSE_WIDGET (self));
}
static void 
on_view_selection_changed (GtkTreeSelection *selection, SeahorseKeyserverResults *self) 
{
	g_return_if_fail (SEAHORSE_IS_KEYSERVER_RESULTS (self));
	g_return_if_fail (GTK_IS_TREE_SELECTION (selection));
	g_idle_add ((GSourceFunc)fire_selection_changed, self);
}
/* When this window closes we quit seahorse */
static gboolean 
on_delete_event (GtkWidget* widget, GdkEvent* event, SeahorseKeyserverResults* self) 
{
	g_return_val_if_fail (SEAHORSE_IS_KEYSERVER_RESULTS (self), FALSE);
	g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
	on_app_close (NULL, self);
	return TRUE;
}
G_MODULE_EXPORT gboolean 
on_key_list_button_pressed (GtkTreeView* view, GdkEventButton* event, SeahorseKeyserverResults* self) 
{
	g_return_val_if_fail (SEAHORSE_IS_KEYSERVER_RESULTS (self), FALSE);
	g_return_val_if_fail (GTK_IS_TREE_VIEW (view), FALSE);
	if (event->button == 3)
		seahorse_viewer_show_context_menu (SEAHORSE_VIEWER (self), event->button, event->time);
	return FALSE;
}
static gboolean
on_key_list_button_pressed (GtkTreeView* view, GdkEventButton* event, SeahorseKeyserverResults* self)
{
	g_return_val_if_fail (SEAHORSE_IS_KEYSERVER_RESULTS (self), FALSE);
	g_return_val_if_fail (GTK_IS_TREE_VIEW (view), FALSE);
	if (event->button == 3)
		seahorse_catalog_show_context_menu (SEAHORSE_CATALOG (self),
		                                   SEAHORSE_CATALOG_MENU_OBJECT,
		                                   event->button, event->time);
	return FALSE;
}
static gboolean 
fire_selection_changed (SeahorseKeyserverResults* self) 
{
	gint rows;
	GtkTreeSelection* selection;
	g_return_val_if_fail (SEAHORSE_IS_KEYSERVER_RESULTS (self), FALSE);

	selection = gtk_tree_view_get_selection (self->pv->view);
	rows = gtk_tree_selection_count_selected_rows (selection);
	seahorse_viewer_set_numbered_status (SEAHORSE_VIEWER (self), ngettext ("Selected %d key", "Selected %d keys", rows), rows);
	gtk_action_group_set_sensitive (self->pv->object_actions, rows > 0);
	g_signal_emit_by_name (G_OBJECT (SEAHORSE_VIEW (self)), "selection-changed");
	return FALSE;
}
G_MODULE_EXPORT gboolean 
on_key_list_popup_menu (GtkTreeView* view, SeahorseKeyserverResults* self) 
{
	SeahorseObject* key;

	g_return_val_if_fail (SEAHORSE_IS_KEYSERVER_RESULTS (self), FALSE);
	g_return_val_if_fail (GTK_IS_TREE_VIEW (view), FALSE);

	key = seahorse_viewer_get_selected (SEAHORSE_VIEWER (self));
	if (key == NULL)
		return FALSE;
	seahorse_viewer_show_context_menu (SEAHORSE_VIEWER (self), 0, gtk_get_current_event_time ());
	return TRUE;
}
static void 
on_row_activated (GtkTreeView *view, GtkTreePath *path, GtkTreeViewColumn *column, SeahorseKeyserverResults *self) 
{
	SeahorseObject *obj;

	g_return_if_fail (SEAHORSE_IS_KEYSERVER_RESULTS (self));
	g_return_if_fail (GTK_IS_TREE_VIEW (view));
	g_return_if_fail (path != NULL);
	g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (column));

	obj = seahorse_key_manager_store_get_object_from_path (view, path);
	if (obj != NULL) 
		seahorse_viewer_show_properties (SEAHORSE_VIEWER (self), obj);
}
static gboolean
fire_selection_changed (SeahorseKeyserverResults* self)
{
	gint rows;
	GtkTreeSelection* selection;
	g_return_val_if_fail (SEAHORSE_IS_KEYSERVER_RESULTS (self), FALSE);

	selection = gtk_tree_view_get_selection (self->pv->view);
	rows = gtk_tree_selection_count_selected_rows (selection);
	if (self->pv->import_actions)
		gtk_action_group_set_sensitive (self->pv->import_actions, rows > 0);
	g_signal_emit_by_name (self, "selection-changed");
	return FALSE;
}
static gboolean
on_key_list_popup_menu (GtkTreeView* view, SeahorseKeyserverResults* self)
{
	GList *objects;

	g_return_val_if_fail (SEAHORSE_IS_KEYSERVER_RESULTS (self), FALSE);
	g_return_val_if_fail (GTK_IS_TREE_VIEW (view), FALSE);

	objects = seahorse_catalog_get_selected_objects (SEAHORSE_CATALOG (self));
	if (objects != NULL)
		seahorse_catalog_show_context_menu (SEAHORSE_CATALOG (self),
		                                   SEAHORSE_CATALOG_MENU_OBJECT,
		                                   0, gtk_get_current_event_time ());
	g_list_free (objects);
	return TRUE;
}
static gboolean 
on_filter_objects (SeahorseObject *obj, SeahorseKeyserverResults *self) 
{
	const gchar *match;
	gboolean ret = FALSE;
	gchar* value;
	gsize n_value, n_match;

	g_return_val_if_fail (SEAHORSE_IS_KEYSERVER_RESULTS (self), FALSE);
	g_return_val_if_fail (SEAHORSE_IS_OBJECT (obj), FALSE);

	match = self->pv->search_string;
	if (g_utf8_strlen (match, -1) == 0)
		ret = TRUE;

	/* Match against the label */
	if (ret != TRUE) {
		value = g_utf8_casefold (seahorse_object_get_label (obj), -1);
		ret = strstr (value, match) != NULL;
		g_free (value);
	}
	
	/* Match against the key identifier */
	if (ret != TRUE) {
		if (strncmp (match, "0x", 2) == 0)
			match += 2;
		value = g_utf8_casefold (seahorse_object_get_identifier (obj), -1);
		
		/* Only compare as many bytes as exist in the key id */
		n_value = strlen (value);
		n_match = strlen (match);
		if (n_value > n_match)
			match += (n_value - n_match);
		ret = strstr (value, match) != NULL;
		
		g_free (value);
	}
	
	return ret;
}
const gchar* 
seahorse_keyserver_results_get_search (SeahorseKeyserverResults* self) 
{
	g_return_val_if_fail (SEAHORSE_IS_KEYSERVER_RESULTS (self), NULL);
	return self->pv->search_string;
}