[brasero] Code refactoring for future changes



commit a3731bb961b61265c46dd0f2a38b3efa73d062b6
Author: Philippe Rouquier <bonfire-app wanadoo fr>
Date:   Fri Nov 6 20:29:44 2009 +0100

    Code refactoring for future changes

 src/brasero-search-beagle.c | 1089 ++++++++++++++++++++-----------------------
 1 files changed, 511 insertions(+), 578 deletions(-)
---
diff --git a/src/brasero-search-beagle.c b/src/brasero-search-beagle.c
index 65ca02d..240ad96 100644
--- a/src/brasero-search-beagle.c
+++ b/src/brasero-search-beagle.c
@@ -55,12 +55,6 @@
 #include "brasero-uri-container.h"
 #include "brasero-layout-object.h"
 
-static void brasero_search_class_init (BraseroSearchClass *klass);
-static void brasero_search_init (BraseroSearch *sp);
-static void brasero_search_iface_uri_container_init (BraseroURIContainerIFace *iface);
-static void brasero_search_iface_layout_object_init (BraseroLayoutObjectIFace *iface);
-static void brasero_search_finalize (GObject *object);
-static void brasero_search_destroy (GtkObject *object);
 
 struct BraseroSearchPrivate {
 	BeagleClient *client;
@@ -105,457 +99,20 @@ enum {
 	BRASERO_SEARCH_TREE_NB_COL
 };
 
-
-static void brasero_search_entry_activated_cb (BraseroSearchEntry *entry,
-					       BraseroSearch *obj);
-static void brasero_search_tree_activated_cb (GtkTreeView *tree,
-					      GtkTreeIter *row,
-					      GtkTreeViewColumn *column,
-					      BraseroSearch *search);
-static void brasero_search_tree_selection_changed_cb (GtkTreeSelection *selection,
-						      BraseroSearch *search);
-static void brasero_search_drag_data_get_cb (GtkTreeView *tree,
-					     GdkDragContext *drag_context,
-					     GtkSelectionData *selection_data,
-					     guint info,
-					     guint time,
-					     BraseroSearch *search);
-static void brasero_search_mime_filter_changed (GtkComboBox *combo,
-						BraseroSearch *search);
-static gboolean brasero_search_is_visible_cb (GtkTreeModel *model,
-					      GtkTreeIter *iter,
-					      BraseroSearch *search);
-static void
-brasero_search_right_button_clicked_cb (GtkButton *button,
-					BraseroSearch *search);
-static void
-brasero_search_left_button_clicked_cb (GtkButton *button,
-				       BraseroSearch *search);
-
-static void
-brasero_search_max_results_num_changed_cb (GtkComboBox *combo,
-					   BraseroSearch *search);
-
-static void brasero_search_empty_tree (BraseroSearch *search);
-static gchar ** brasero_search_get_selected_rows (BraseroSearch *search);
-
-static gchar **
-brasero_search_get_selected_uris (BraseroURIContainer *container);
-static gchar *
-brasero_search_get_selected_uri (BraseroURIContainer *container);
-
 #define BRASERO_SEARCH_SPACING 6
 
-GType
-brasero_search_get_type ()
-{
-	static GType type = 0;
-
-	if (type == 0) {
-		static const GTypeInfo our_info = {
-			sizeof (BraseroSearchClass),
-			NULL,
-			NULL,
-			(GClassInitFunc) brasero_search_class_init,
-			NULL,
-			NULL,
-			sizeof (BraseroSearch),
-			0,
-			(GInstanceInitFunc) brasero_search_init,
-		};
-
-		static const GInterfaceInfo uri_container_info =
-		{
-			(GInterfaceInitFunc) brasero_search_iface_uri_container_init,
-			NULL,
-			NULL
-		};
-		static const GInterfaceInfo layout_object_info =
-		{
-			(GInterfaceInitFunc) brasero_search_iface_layout_object_init,
-			NULL,
-			NULL
-		};
-
-		type = g_type_register_static (GTK_TYPE_VBOX,
-					       "BraseroSearch",
-					       &our_info,
-					       0);
-
-		g_type_add_interface_static (type,
-					     BRASERO_TYPE_URI_CONTAINER,
-					     &uri_container_info);
-		g_type_add_interface_static (type,
-					     BRASERO_TYPE_LAYOUT_OBJECT,
-					     &layout_object_info);
-	}
-
-	return type;
-}
-
-static void
-brasero_search_class_init (BraseroSearchClass *klass)
-{
-	GObjectClass *object_class = G_OBJECT_CLASS (klass);
-	GtkObjectClass *gtkobject_class = GTK_OBJECT_CLASS (klass);
-
-	parent_class = g_type_class_peek_parent (klass);
-	object_class->finalize = brasero_search_finalize;
-	gtkobject_class->destroy = brasero_search_destroy;
-}
-
-static void
-brasero_search_iface_uri_container_init (BraseroURIContainerIFace *iface)
-{
-	iface->get_selected_uri = brasero_search_get_selected_uri;
-	iface->get_selected_uris = brasero_search_get_selected_uris;
-}
-
-static void
-brasero_search_get_proportion (BraseroLayoutObject *object,
-			       gint *header,
-			       gint *center,
-			       gint *footer) 
-{
-	GtkRequisition requisition;
-
-	gtk_widget_size_request (BRASERO_SEARCH (object)->priv->filters,
-				 &requisition);
-	*footer = requisition.height + BRASERO_SEARCH_SPACING;
-}
-
-static void
-brasero_search_set_context (BraseroLayoutObject *object,
-			    BraseroLayoutType type)
-{
-	BraseroSearch *self;
-
-	self = BRASERO_SEARCH (object);
-	brasero_search_entry_set_context (BRASERO_SEARCH_ENTRY (self->priv->entry), type);
-}
-
-static void
-brasero_search_iface_layout_object_init (BraseroLayoutObjectIFace *iface)
-{
-	iface->get_proportion = brasero_search_get_proportion;
-	iface->set_context = brasero_search_set_context;
-}
-
-static void
-brasero_search_column_clicked (GtkTreeViewColumn *column,
-			       BraseroSearch *search)
-{
-	gint model_id;
-	gint column_id;
-	GtkTreeModel *model;
-	GtkSortType model_order;
-
-	model = gtk_tree_view_get_model (GTK_TREE_VIEW (search->priv->tree));
-	model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model));
-
-	gtk_tree_sortable_get_sort_column_id (GTK_TREE_SORTABLE (model),
-					      &model_id,
-					      &model_order);
-	column_id = gtk_tree_view_column_get_sort_column_id (column);
-
-	if (column_id == model_id && model_order == GTK_SORT_DESCENDING) {
-		gtk_tree_view_column_set_sort_indicator (column, FALSE);
-		gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (model),
-						      BRASERO_SEARCH_TREE_SCORE_COL,
-						      GTK_SORT_DESCENDING);
-	}
-	else if (model_id == BRASERO_SEARCH_TREE_SCORE_COL) {
-		gtk_tree_view_column_set_sort_indicator (column, TRUE);
-		gtk_tree_view_column_set_sort_order (column, GTK_SORT_ASCENDING);
-		gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (model),
-						      column_id,
-						      GTK_SORT_ASCENDING);
-	}
-	else {
-		gtk_tree_view_column_set_sort_order (column, GTK_SORT_DESCENDING);
-		gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (model),
-						      column_id,
-						      GTK_SORT_DESCENDING);
-	}
-
-	g_signal_stop_emission_by_name (column, "clicked");
-}
-
-static void
-brasero_search_init (BraseroSearch *obj)
-{
-	gchar *string;
-	GtkWidget *box;
-	GtkWidget *box1;
-	GtkWidget *label;
-	GtkWidget *combo;
-	GtkWidget *button;
-	GtkWidget *scroll;
-	GtkListStore *store;
-	GtkTreeModel *model;
-	GtkWidget *separator;
-	GtkTreeViewColumn *column;
-	GtkCellRenderer *renderer;
-	GtkFileFilter *file_filter;
-	GtkTreeSelection *selection;
-
-	gtk_box_set_spacing (GTK_BOX (obj), BRASERO_SEARCH_SPACING);
-	obj->priv = g_new0 (BraseroSearchPrivate, 1);
-
-	/* separator */
-	separator = gtk_hseparator_new ();
-	gtk_box_pack_start (GTK_BOX (obj), separator, FALSE, FALSE, 0);
-
-	/* Entry */
-	obj->priv->entry = brasero_search_entry_new ();
-	g_signal_connect (G_OBJECT (obj->priv->entry), 
-			  "activated",
-			  G_CALLBACK (brasero_search_entry_activated_cb),
-			  obj);
-	gtk_box_pack_start (GTK_BOX (obj), obj->priv->entry, FALSE, FALSE, 0);
-
-	/* separator */
-	separator = gtk_hseparator_new ();
-	gtk_box_pack_start (GTK_BOX (obj), separator, FALSE, FALSE, 0);
-
-	/* results navigation */
-	box = gtk_hbox_new (FALSE, 6);
-	gtk_box_pack_start (GTK_BOX (obj), box, FALSE, FALSE, 0);
-
-	button = brasero_utils_make_button (_("Previous Results"),
-					    GTK_STOCK_GO_BACK,
-					    NULL,
-					    GTK_ICON_SIZE_BUTTON);
-	gtk_button_set_alignment (GTK_BUTTON (button), 0.0, 0.5);
-	gtk_widget_set_sensitive (button, FALSE);
-	g_signal_connect (G_OBJECT (button), 
-			  "clicked",
-			  G_CALLBACK (brasero_search_left_button_clicked_cb),
-			  obj);
-	gtk_box_pack_start (GTK_BOX (box), button, FALSE, TRUE, 0);
-	obj->priv->left = button;
-
-	string = g_strdup_printf ("<b>%s</b>", _("No results"));
-	label = gtk_label_new (string);
-	g_free (string);
-
-	gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
-	gtk_box_pack_start (GTK_BOX (box), label, TRUE, TRUE, 0);
-	obj->priv->results_label = label;
-
-	button = brasero_utils_make_button (_("Next Results"),
-					    GTK_STOCK_GO_FORWARD,
-					    NULL,
-					    GTK_ICON_SIZE_BUTTON);
-	gtk_button_set_alignment (GTK_BUTTON (button), 1.0, 0.5);
-	gtk_widget_set_sensitive (button, FALSE);
-	g_signal_connect (G_OBJECT (button), 
-			  "clicked",
-			  G_CALLBACK (brasero_search_right_button_clicked_cb),
-			  obj);
-	gtk_box_pack_start (GTK_BOX (box), button, FALSE, TRUE, 0);
-	obj->priv->right = button;
-
-	/* Tree */
-	obj->priv->tree = gtk_tree_view_new ();
-	gtk_tree_view_set_rubber_banding (GTK_TREE_VIEW (obj->priv->tree), TRUE);
-	egg_tree_multi_drag_add_drag_support (GTK_TREE_VIEW (obj->priv->tree));
-
-	selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (obj->priv->tree));
-	gtk_tree_selection_set_mode (selection, GTK_SELECTION_MULTIPLE);
-
-	gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (obj->priv->tree), TRUE);
-	g_signal_connect (G_OBJECT (obj->priv->tree), 
-			  "row-activated",
-			  G_CALLBACK (brasero_search_tree_activated_cb),
-			  obj);
-	g_signal_connect (G_OBJECT (gtk_tree_view_get_selection (GTK_TREE_VIEW (obj->priv->tree))),
-			  "changed",
-			  G_CALLBACK (brasero_search_tree_selection_changed_cb),
-			  obj);
-
-	gtk_tree_view_set_headers_clickable (GTK_TREE_VIEW (obj->priv->tree), TRUE);
-	store = gtk_list_store_new (BRASERO_SEARCH_TREE_NB_COL,
-				    G_TYPE_STRING,
-				    G_TYPE_STRING,
-				    G_TYPE_STRING,
-				    G_TYPE_INT,
-				    G_TYPE_STRING,
-				    G_TYPE_STRING);
-
-	gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
-					      BRASERO_SEARCH_TREE_SCORE_COL,
-					      GTK_SORT_DESCENDING);
-
-	model = gtk_tree_model_filter_new (GTK_TREE_MODEL (store), NULL);
-	g_object_unref (G_OBJECT (store));
-	gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (model),
-						(GtkTreeModelFilterVisibleFunc) brasero_search_is_visible_cb,
-						obj,
-						NULL);
-
-	gtk_tree_view_set_model (GTK_TREE_VIEW (obj->priv->tree), model);
-	g_object_unref (G_OBJECT (model));
-
-	column = gtk_tree_view_column_new ();
-	g_signal_connect (column,
-			  "clicked",
-			  G_CALLBACK (brasero_search_column_clicked),
-			  obj);
-
-	gtk_tree_view_column_set_resizable (column, TRUE);
-	gtk_tree_view_column_set_title (column, _("Files"));
-	gtk_tree_view_column_set_min_width (column, 128);
-	gtk_tree_view_column_set_sort_column_id (column,
-						 BRASERO_SEARCH_TREE_TITLE_COL);
-
-	renderer = gtk_cell_renderer_pixbuf_new ();
-	gtk_tree_view_column_pack_start (column, renderer, FALSE);
-	gtk_tree_view_column_add_attribute (column, renderer, "icon-name",
-					    BRASERO_SEARCH_TREE_ICON_COL);
-
-	renderer = gtk_cell_renderer_text_new ();
-	gtk_tree_view_column_pack_start (column, renderer, TRUE);
-	gtk_tree_view_column_add_attribute (column, renderer, "text",
-					    BRASERO_SEARCH_TREE_TITLE_COL);
-
-	gtk_tree_view_append_column (GTK_TREE_VIEW (obj->priv->tree),
-				     column);
-
-	renderer = gtk_cell_renderer_text_new ();
-	column =  gtk_tree_view_column_new_with_attributes (_("Description"),
-							    renderer, "text",
-						            BRASERO_SEARCH_TREE_DESCRIPTION_COL,
-						            NULL);
-	gtk_tree_view_column_set_resizable (column, TRUE);
-	gtk_tree_view_column_set_min_width (column, 128);
-	gtk_tree_view_column_set_sort_column_id (column,
-						 BRASERO_SEARCH_TREE_DESCRIPTION_COL);
-	gtk_tree_view_append_column (GTK_TREE_VIEW (obj->priv->tree),
-				     column);
-	g_signal_connect (column,
-			  "clicked",
-			  G_CALLBACK (brasero_search_column_clicked),
-			  obj);
-
-	/* dnd */
-	gtk_tree_view_enable_model_drag_source (GTK_TREE_VIEW (obj->priv->tree),
-						GDK_BUTTON1_MASK,
-						ntables_find,
-						nb_ntables_find,
-						GDK_ACTION_COPY);
-
-	g_signal_connect (G_OBJECT (obj->priv->tree), 
-			  "drag-data-get",
-			  G_CALLBACK (brasero_search_drag_data_get_cb),
-			  obj);
-
-	scroll = gtk_scrolled_window_new (NULL, NULL);
-	gtk_container_add (GTK_CONTAINER (scroll), obj->priv->tree);
-	gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scroll),
-					     GTK_SHADOW_IN);
-	gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll),
-					GTK_POLICY_AUTOMATIC,
-					GTK_POLICY_AUTOMATIC);
-	gtk_box_pack_start (GTK_BOX (obj), scroll, TRUE, TRUE, 0);
-
-	/* filter combo */
-	box = gtk_hbox_new (FALSE, 32);
-	obj->priv->filters = box;
-	gtk_box_pack_end (GTK_BOX (obj), box, FALSE, FALSE, 0);
-
-	obj->priv->filter = brasero_mime_filter_new ();
-	g_signal_connect (G_OBJECT (BRASERO_MIME_FILTER (obj->priv->filter)->combo),
-			  "changed",
-			  G_CALLBACK (brasero_search_mime_filter_changed),
-			  obj);
-
-	file_filter = gtk_file_filter_new ();
-	gtk_file_filter_set_name (file_filter, _("All files"));
-	gtk_file_filter_add_pattern (file_filter, "*");
-	brasero_mime_filter_add_filter (BRASERO_MIME_FILTER (obj->priv->filter),
-					file_filter);
-	g_object_unref (file_filter);
-
-	gtk_box_pack_end (GTK_BOX (box), obj->priv->filter, FALSE, FALSE, 0);
-
-	box1 = gtk_hbox_new (FALSE, 6);
-	gtk_box_pack_end (GTK_BOX (box), box1, FALSE, FALSE, 0);
-
-	label = gtk_label_new (_("Number of results displayed"));
-	gtk_box_pack_start (GTK_BOX (box1), label, FALSE, FALSE, 0);
-
-	combo = gtk_combo_box_new_text ();
-	g_signal_connect (combo,
-			  "changed",
-			  G_CALLBACK (brasero_search_max_results_num_changed_cb),
-			  obj);
-	gtk_combo_box_append_text (GTK_COMBO_BOX (combo), "20");
-	gtk_combo_box_append_text (GTK_COMBO_BOX (combo), "50");
-	gtk_combo_box_append_text (GTK_COMBO_BOX (combo), "100");
-
-	gtk_combo_box_set_active (GTK_COMBO_BOX (combo), 1);
-	obj->priv->max_results = 50;
-
-	gtk_box_pack_start (GTK_BOX (box1), combo, FALSE, FALSE, 0);
-
-}
-
-static void
-brasero_search_destroy (GtkObject *object)
-{
-	BraseroSearch *search;
-
-	search = BRASERO_SEARCH (object);
-	if (search->priv->query) {
-		g_object_unref (search->priv->query);
-		search->priv->query = NULL;
-	}
-
-	if (search->priv->client) {
-		g_object_unref (search->priv->client);
-		search->priv->client = NULL;
-	}
-
-	if (search->priv->tree) {
-		g_signal_handlers_disconnect_by_func (gtk_tree_view_get_selection (GTK_TREE_VIEW (search->priv->tree)),
-		                                      brasero_search_tree_selection_changed_cb,
-		                                      search);
-
-		g_signal_handlers_disconnect_by_func (search->priv->filter,
-						      brasero_search_mime_filter_changed,
-						      search);
-
-		brasero_search_empty_tree (search);
-		search->priv->filter = NULL;
-		search->priv->tree = NULL;
-	}
-
-	if (search->priv->id) {
-		g_source_remove (search->priv->id);
-		search->priv->id = 0;
-	}
-
-	if (search->priv->hits) {
-		g_slist_foreach (search->priv->hits, (GFunc) beagle_hit_unref, NULL);
-		g_slist_free (search->priv->hits);
-		search->priv->hits = NULL;
-	}
-
-	if (GTK_OBJECT_CLASS (parent_class)->destroy)
-		GTK_OBJECT_CLASS (parent_class)->destroy (object);
-}
+static void brasero_search_iface_uri_container_init (BraseroURIContainerIFace *iface);
+static void brasero_search_iface_layout_object_init (BraseroLayoutObjectIFace *iface);
 
-static void
-brasero_search_finalize (GObject *object)
-{
-	BraseroSearch *cobj;
+G_DEFINE_TYPE_WITH_CODE (BraseroSearch,
+			 brasero_search,
+			 GTK_TYPE_VBOX,
+			 G_IMPLEMENT_INTERFACE (BRASERO_TYPE_URI_CONTAINER,
+					        brasero_search_iface_uri_container_init)
+			 G_IMPLEMENT_INTERFACE (BRASERO_TYPE_LAYOUT_OBJECT,
+					        brasero_search_iface_layout_object_init));
 
-	cobj = BRASERO_SEARCH (object);
 
-	g_free (cobj->priv);
-	G_OBJECT_CLASS (parent_class)->finalize (object);
-}
 
 static gboolean
 brasero_search_try_again (BraseroSearch *search)
@@ -569,28 +126,6 @@ brasero_search_try_again (BraseroSearch *search)
 	return FALSE;
 }
 
-GtkWidget *
-brasero_search_new ()
-{
-	BraseroSearch *obj;
-
-	obj = BRASERO_SEARCH (g_object_new (BRASERO_TYPE_SEARCH, NULL));
-
-	/* FIXME : there are better ways to do the following with the new API
-	 * see beagle_util_daemon_is_running (void) */
-	obj->priv->client = beagle_client_new (NULL);
-	if (!obj->priv->client) {
-		gtk_widget_set_sensitive (GTK_WIDGET (obj), FALSE);
-
-		/* we will retry in 10 seconds */
-		obj->priv->id = g_timeout_add_seconds (10,
-						       (GSourceFunc) brasero_search_try_again,
-						       obj);
-	}
-
-	return GTK_WIDGET (obj);
-}
-
 static void
 brasero_search_increase_activity (BraseroSearch *search)
 {
@@ -615,32 +150,39 @@ brasero_search_decrease_activity (BraseroSearch *search)
 		gdk_window_set_cursor (GTK_WIDGET (search)->window, NULL);
 }
 
-static gchar **
-brasero_search_get_selected_uris (BraseroURIContainer *container)
+static void
+brasero_search_update_header (BraseroSearch *search)
 {
-	BraseroSearch *search;
+	gchar *string;
 
-	search = BRASERO_SEARCH (container);
-	return brasero_search_get_selected_rows (search);
-}
+	if (search->priv->hits_num) {
+		gint last;
+		gchar *tmp;
 
-static gchar *
-brasero_search_get_selected_uri (BraseroURIContainer *container)
-{
-	BraseroSearch *search;
-	gchar **uris = NULL;
-	gchar *uri;
+		last = search->priv->first_hit + search->priv->max_results;
+		last = last <= search->priv->hits_num ? last : search->priv->hits_num;
+		tmp = g_strdup_printf (_("Results %iâ??%i (out of %i)"),
+				       search->priv->first_hit + 1,
+				       last,
+				       search->priv->hits_num);
+		string = g_strdup_printf ("<b>%s</b>", tmp);
+		g_free (tmp);
+	}
+	else
+		string = g_strdup_printf ("<b>%s</b>", _("No results"));
 
-	search = BRASERO_SEARCH (container);
-	uris = brasero_search_get_selected_rows (search);
+	gtk_label_set_markup (GTK_LABEL (search->priv->results_label), string);
+	g_free (string);
 
-	if (uris) {
-		uri = g_strdup (uris [0]);
-		g_strfreev (uris);
-		return uri;
-	}
+	if (search->priv->first_hit + search->priv->max_results < search->priv->hits_num)
+		gtk_widget_set_sensitive (search->priv->right, TRUE);
+	else
+		gtk_widget_set_sensitive (search->priv->right, FALSE);
 
-	return NULL;
+	if (search->priv->first_hit > 0)
+		gtk_widget_set_sensitive (search->priv->left, TRUE);
+	else
+		gtk_widget_set_sensitive (search->priv->left, FALSE);
 }
 
 static void
@@ -664,19 +206,9 @@ brasero_search_empty_tree (BraseroSearch *search)
 	}
 }
 
-static void
-brasero_search_drag_data_get_cb (GtkTreeView *tree,
-				 GdkDragContext *drag_context,
-				 GtkSelectionData *selection_data,
-				 guint info,
-				 guint time, BraseroSearch *search)
-{
-	gchar **uris;
-
-	uris = brasero_search_get_selected_rows (search);
-	gtk_selection_data_set_uris (selection_data, uris);
-	g_strfreev (uris);
-}
+/**
+ * Start of beagle specific code
+ **/
 
 static GSList *
 brasero_search_add_hit_to_tree (BraseroSearch *search,
@@ -783,38 +315,40 @@ brasero_search_add_hit_to_tree (BraseroSearch *search,
 }
 
 static void
-brasero_search_update_header (BraseroSearch *search)
+brasero_search_left_button_clicked_cb (GtkButton *button,
+				       BraseroSearch *search)
 {
-	gchar *string;
+	GSList *first;
 
-	if (search->priv->hits_num) {
-		gint last;
-		gchar *tmp;
+	if (!search->priv->first_hit)
+		return;
 
-		last = search->priv->first_hit + search->priv->max_results;
-		last = last <= search->priv->hits_num ? last : search->priv->hits_num;
-		tmp = g_strdup_printf (_("Results %iâ??%i (out of %i)"),
-				       search->priv->first_hit + 1,
-				       last,
-				       search->priv->hits_num);
-		string = g_strdup_printf ("<b>%s</b>", tmp);
-		g_free (tmp);
-	}
-	else
-		string = g_strdup_printf ("<b>%s</b>", _("No results"));
+	search->priv->first_hit -= search->priv->max_results;
+	if (search->priv->first_hit < 0)
+		search->priv->first_hit = 0;
 
-	gtk_label_set_markup (GTK_LABEL (search->priv->results_label), string);
-	g_free (string);
+	first = g_slist_nth (search->priv->hits, search->priv->first_hit);
 
-	if (search->priv->first_hit + search->priv->max_results < search->priv->hits_num)
-		gtk_widget_set_sensitive (search->priv->right, TRUE);
-	else
-		gtk_widget_set_sensitive (search->priv->right, FALSE);
+	brasero_search_empty_tree (search);
+	brasero_search_add_hit_to_tree (search, first, search->priv->max_results);
+	brasero_search_update_header (search);
+}
 
-	if (search->priv->first_hit > 0)
-		gtk_widget_set_sensitive (search->priv->left, TRUE);
-	else
-		gtk_widget_set_sensitive (search->priv->left, FALSE);
+static void
+brasero_search_right_button_clicked_cb (GtkButton *button,
+					BraseroSearch *search)
+{
+	GSList *first;
+
+	if (search->priv->first_hit + search->priv->max_results > search->priv->hits_num)
+		return;
+
+	search->priv->first_hit += search->priv->max_results;
+	first = g_slist_nth (search->priv->hits, search->priv->first_hit);
+
+	brasero_search_empty_tree (search);
+	brasero_search_add_hit_to_tree (search, first, search->priv->max_results);
+	brasero_search_update_header (search);
 }
 
 static void
@@ -848,43 +382,6 @@ brasero_search_max_results_num_changed_cb (GtkComboBox *combo,
 }
 
 static void
-brasero_search_left_button_clicked_cb (GtkButton *button,
-				       BraseroSearch *search)
-{
-	GSList *first;
-
-	if (!search->priv->first_hit)
-		return;
-
-	search->priv->first_hit -= search->priv->max_results;
-	if (search->priv->first_hit < 0)
-		search->priv->first_hit = 0;
-
-	first = g_slist_nth (search->priv->hits, search->priv->first_hit);
-
-	brasero_search_empty_tree (search);
-	brasero_search_add_hit_to_tree (search, first, search->priv->max_results);
-	brasero_search_update_header (search);
-}
-
-static void
-brasero_search_right_button_clicked_cb (GtkButton *button,
-					BraseroSearch *search)
-{
-	GSList *first;
-
-	if (search->priv->first_hit + search->priv->max_results > search->priv->hits_num)
-		return;
-
-	search->priv->first_hit += search->priv->max_results;
-	first = g_slist_nth (search->priv->hits, search->priv->first_hit);
-
-	brasero_search_empty_tree (search);
-	brasero_search_add_hit_to_tree (search, first, search->priv->max_results);
-	brasero_search_update_header (search);
-}
-
-static void
 brasero_search_check_for_possible_missing (BraseroSearch *search)
 {
 	gint num_missing;
@@ -892,7 +389,7 @@ brasero_search_check_for_possible_missing (BraseroSearch *search)
 	gint num_remaining;
 	GtkTreeModel *model;
 
-	/* not let's see if we should append new results */
+	/* now let's see if we should append new results */
 	model = gtk_tree_view_get_model (GTK_TREE_VIEW (search->priv->tree));
 	model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model));
 
@@ -911,6 +408,10 @@ brasero_search_check_for_possible_missing (BraseroSearch *search)
 	}
 }
 
+/**
+ * Really Beagle specific code
+ **/
+
 static gint
 _sort_hits_by_score (BeagleHit *a, BeagleHit *b)
 {
@@ -1108,6 +609,10 @@ brasero_search_entry_activated_cb (BraseroSearchEntry *entry,
 	}
 }
 
+/**
+ * End of beagle specific code
+ **/
+
 static gboolean
 brasero_search_is_visible_cb (GtkTreeModel *model,
 			      GtkTreeIter *iter,
@@ -1151,13 +656,6 @@ brasero_search_tree_activated_cb (GtkTreeView *tree,
 	brasero_uri_container_uri_activated (BRASERO_URI_CONTAINER (search));
 }
 
-static void
-brasero_search_tree_selection_changed_cb (GtkTreeSelection *selection,
-					  BraseroSearch *search)
-{
-	brasero_uri_container_uri_selected (BRASERO_URI_CONTAINER (search));
-}
-
 static char **
 brasero_search_get_selected_rows (BraseroSearch *search)
 {
@@ -1189,4 +687,439 @@ brasero_search_get_selected_rows (BraseroSearch *search)
 	return uris;
 }
 
+static void
+brasero_search_drag_data_get_cb (GtkTreeView *tree,
+				 GdkDragContext *drag_context,
+				 GtkSelectionData *selection_data,
+				 guint info,
+				 guint time, BraseroSearch *search)
+{
+	gchar **uris;
+
+	uris = brasero_search_get_selected_rows (search);
+	gtk_selection_data_set_uris (selection_data, uris);
+	g_strfreev (uris);
+}
+
+static gchar *
+brasero_search_get_selected_uri (BraseroURIContainer *container)
+{
+	BraseroSearch *search;
+	gchar **uris = NULL;
+	gchar *uri;
+
+	search = BRASERO_SEARCH (container);
+	uris = brasero_search_get_selected_rows (search);
+
+	if (uris) {
+		uri = g_strdup (uris [0]);
+		g_strfreev (uris);
+		return uri;
+	}
+
+	return NULL;
+}
+
+static gchar **
+brasero_search_get_selected_uris (BraseroURIContainer *container)
+{
+	BraseroSearch *search;
+
+	search = BRASERO_SEARCH (container);
+	return brasero_search_get_selected_rows (search);
+}
+
+static void
+brasero_search_tree_selection_changed_cb (GtkTreeSelection *selection,
+					  BraseroSearch *search)
+{
+	brasero_uri_container_uri_selected (BRASERO_URI_CONTAINER (search));
+}
+
+static void
+brasero_search_get_proportion (BraseroLayoutObject *object,
+			       gint *header,
+			       gint *center,
+			       gint *footer) 
+{
+	GtkRequisition requisition;
+
+	gtk_widget_size_request (BRASERO_SEARCH (object)->priv->filters,
+				 &requisition);
+	*footer = requisition.height + BRASERO_SEARCH_SPACING;
+}
+
+static void
+brasero_search_set_context (BraseroLayoutObject *object,
+			    BraseroLayoutType type)
+{
+	BraseroSearch *self;
+
+	self = BRASERO_SEARCH (object);
+	brasero_search_entry_set_context (BRASERO_SEARCH_ENTRY (self->priv->entry), type);
+}
+
+static void
+brasero_search_column_clicked (GtkTreeViewColumn *column,
+			       BraseroSearch *search)
+{
+	gint model_id;
+	gint column_id;
+	GtkTreeModel *model;
+	GtkSortType model_order;
+
+	model = gtk_tree_view_get_model (GTK_TREE_VIEW (search->priv->tree));
+	model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model));
+
+	gtk_tree_sortable_get_sort_column_id (GTK_TREE_SORTABLE (model),
+					      &model_id,
+					      &model_order);
+	column_id = gtk_tree_view_column_get_sort_column_id (column);
+
+	if (column_id == model_id && model_order == GTK_SORT_DESCENDING) {
+		gtk_tree_view_column_set_sort_indicator (column, FALSE);
+		gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (model),
+						      BRASERO_SEARCH_TREE_SCORE_COL,
+						      GTK_SORT_DESCENDING);
+	}
+	else if (model_id == BRASERO_SEARCH_TREE_SCORE_COL) {
+		gtk_tree_view_column_set_sort_indicator (column, TRUE);
+		gtk_tree_view_column_set_sort_order (column, GTK_SORT_ASCENDING);
+		gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (model),
+						      column_id,
+						      GTK_SORT_ASCENDING);
+	}
+	else {
+		gtk_tree_view_column_set_sort_order (column, GTK_SORT_DESCENDING);
+		gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (model),
+						      column_id,
+						      GTK_SORT_DESCENDING);
+	}
+
+	g_signal_stop_emission_by_name (column, "clicked");
+}
+
+static void
+brasero_search_init (BraseroSearch *obj)
+{
+	gchar *string;
+	GtkWidget *box;
+	GtkWidget *box1;
+	GtkWidget *label;
+	GtkWidget *combo;
+	GtkWidget *button;
+	GtkWidget *scroll;
+	GtkListStore *store;
+	GtkTreeModel *model;
+	GtkWidget *separator;
+	GtkTreeViewColumn *column;
+	GtkCellRenderer *renderer;
+	GtkFileFilter *file_filter;
+	GtkTreeSelection *selection;
+
+	gtk_box_set_spacing (GTK_BOX (obj), BRASERO_SEARCH_SPACING);
+	obj->priv = g_new0 (BraseroSearchPrivate, 1);
+
+	/* separator */
+	separator = gtk_hseparator_new ();
+	gtk_box_pack_start (GTK_BOX (obj), separator, FALSE, FALSE, 0);
+
+	/* Entry */
+	obj->priv->entry = brasero_search_entry_new ();
+	g_signal_connect (G_OBJECT (obj->priv->entry), 
+			  "activated",
+			  G_CALLBACK (brasero_search_entry_activated_cb),
+			  obj);
+	gtk_box_pack_start (GTK_BOX (obj), obj->priv->entry, FALSE, FALSE, 0);
+
+	/* separator */
+	separator = gtk_hseparator_new ();
+	gtk_box_pack_start (GTK_BOX (obj), separator, FALSE, FALSE, 0);
+
+	/* results navigation */
+	box = gtk_hbox_new (FALSE, 6);
+	gtk_box_pack_start (GTK_BOX (obj), box, FALSE, FALSE, 0);
+
+	button = brasero_utils_make_button (_("Previous Results"),
+					    GTK_STOCK_GO_BACK,
+					    NULL,
+					    GTK_ICON_SIZE_BUTTON);
+	gtk_button_set_alignment (GTK_BUTTON (button), 0.0, 0.5);
+	gtk_widget_set_sensitive (button, FALSE);
+	g_signal_connect (G_OBJECT (button), 
+			  "clicked",
+			  G_CALLBACK (brasero_search_left_button_clicked_cb),
+			  obj);
+	gtk_box_pack_start (GTK_BOX (box), button, FALSE, TRUE, 0);
+	obj->priv->left = button;
+
+	string = g_strdup_printf ("<b>%s</b>", _("No results"));
+	label = gtk_label_new (string);
+	g_free (string);
+
+	gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
+	gtk_box_pack_start (GTK_BOX (box), label, TRUE, TRUE, 0);
+	obj->priv->results_label = label;
+
+	button = brasero_utils_make_button (_("Next Results"),
+					    GTK_STOCK_GO_FORWARD,
+					    NULL,
+					    GTK_ICON_SIZE_BUTTON);
+	gtk_button_set_alignment (GTK_BUTTON (button), 1.0, 0.5);
+	gtk_widget_set_sensitive (button, FALSE);
+	g_signal_connect (G_OBJECT (button), 
+			  "clicked",
+			  G_CALLBACK (brasero_search_right_button_clicked_cb),
+			  obj);
+	gtk_box_pack_start (GTK_BOX (box), button, FALSE, TRUE, 0);
+	obj->priv->right = button;
+
+	/* Tree */
+	obj->priv->tree = gtk_tree_view_new ();
+	gtk_tree_view_set_rubber_banding (GTK_TREE_VIEW (obj->priv->tree), TRUE);
+	egg_tree_multi_drag_add_drag_support (GTK_TREE_VIEW (obj->priv->tree));
+
+	selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (obj->priv->tree));
+	gtk_tree_selection_set_mode (selection, GTK_SELECTION_MULTIPLE);
+
+	gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (obj->priv->tree), TRUE);
+	g_signal_connect (G_OBJECT (obj->priv->tree), 
+			  "row-activated",
+			  G_CALLBACK (brasero_search_tree_activated_cb),
+			  obj);
+	g_signal_connect (G_OBJECT (gtk_tree_view_get_selection (GTK_TREE_VIEW (obj->priv->tree))),
+			  "changed",
+			  G_CALLBACK (brasero_search_tree_selection_changed_cb),
+			  obj);
+
+	gtk_tree_view_set_headers_clickable (GTK_TREE_VIEW (obj->priv->tree), TRUE);
+	store = gtk_list_store_new (BRASERO_SEARCH_TREE_NB_COL,
+				    G_TYPE_STRING,
+				    G_TYPE_STRING,
+				    G_TYPE_STRING,
+				    G_TYPE_INT,
+				    G_TYPE_STRING,
+				    G_TYPE_STRING);
+
+	gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
+					      BRASERO_SEARCH_TREE_SCORE_COL,
+					      GTK_SORT_DESCENDING);
+
+	model = gtk_tree_model_filter_new (GTK_TREE_MODEL (store), NULL);
+	g_object_unref (G_OBJECT (store));
+	gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (model),
+						(GtkTreeModelFilterVisibleFunc) brasero_search_is_visible_cb,
+						obj,
+						NULL);
+
+	gtk_tree_view_set_model (GTK_TREE_VIEW (obj->priv->tree), model);
+	g_object_unref (G_OBJECT (model));
+
+	column = gtk_tree_view_column_new ();
+	g_signal_connect (column,
+			  "clicked",
+			  G_CALLBACK (brasero_search_column_clicked),
+			  obj);
+
+	gtk_tree_view_column_set_resizable (column, TRUE);
+	gtk_tree_view_column_set_title (column, _("Files"));
+	gtk_tree_view_column_set_min_width (column, 128);
+	gtk_tree_view_column_set_sort_column_id (column,
+						 BRASERO_SEARCH_TREE_TITLE_COL);
+
+	renderer = gtk_cell_renderer_pixbuf_new ();
+	gtk_tree_view_column_pack_start (column, renderer, FALSE);
+	gtk_tree_view_column_add_attribute (column, renderer, "icon-name",
+					    BRASERO_SEARCH_TREE_ICON_COL);
+
+	renderer = gtk_cell_renderer_text_new ();
+	gtk_tree_view_column_pack_start (column, renderer, TRUE);
+	gtk_tree_view_column_add_attribute (column, renderer, "text",
+					    BRASERO_SEARCH_TREE_TITLE_COL);
+
+	gtk_tree_view_append_column (GTK_TREE_VIEW (obj->priv->tree),
+				     column);
+
+	renderer = gtk_cell_renderer_text_new ();
+	column =  gtk_tree_view_column_new_with_attributes (_("Description"),
+							    renderer, "text",
+						            BRASERO_SEARCH_TREE_DESCRIPTION_COL,
+						            NULL);
+	gtk_tree_view_column_set_resizable (column, TRUE);
+	gtk_tree_view_column_set_min_width (column, 128);
+	gtk_tree_view_column_set_sort_column_id (column,
+						 BRASERO_SEARCH_TREE_DESCRIPTION_COL);
+	gtk_tree_view_append_column (GTK_TREE_VIEW (obj->priv->tree),
+				     column);
+	g_signal_connect (column,
+			  "clicked",
+			  G_CALLBACK (brasero_search_column_clicked),
+			  obj);
+
+	/* dnd */
+	gtk_tree_view_enable_model_drag_source (GTK_TREE_VIEW (obj->priv->tree),
+						GDK_BUTTON1_MASK,
+						ntables_find,
+						nb_ntables_find,
+						GDK_ACTION_COPY);
+
+	g_signal_connect (G_OBJECT (obj->priv->tree), 
+			  "drag-data-get",
+			  G_CALLBACK (brasero_search_drag_data_get_cb),
+			  obj);
+
+	scroll = gtk_scrolled_window_new (NULL, NULL);
+	gtk_container_add (GTK_CONTAINER (scroll), obj->priv->tree);
+	gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scroll),
+					     GTK_SHADOW_IN);
+	gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll),
+					GTK_POLICY_AUTOMATIC,
+					GTK_POLICY_AUTOMATIC);
+	gtk_box_pack_start (GTK_BOX (obj), scroll, TRUE, TRUE, 0);
+
+	/* filter combo */
+	box = gtk_hbox_new (FALSE, 32);
+	obj->priv->filters = box;
+	gtk_box_pack_end (GTK_BOX (obj), box, FALSE, FALSE, 0);
+
+	obj->priv->filter = brasero_mime_filter_new ();
+	g_signal_connect (G_OBJECT (BRASERO_MIME_FILTER (obj->priv->filter)->combo),
+			  "changed",
+			  G_CALLBACK (brasero_search_mime_filter_changed),
+			  obj);
+
+	file_filter = gtk_file_filter_new ();
+	gtk_file_filter_set_name (file_filter, _("All files"));
+	gtk_file_filter_add_pattern (file_filter, "*");
+	brasero_mime_filter_add_filter (BRASERO_MIME_FILTER (obj->priv->filter),
+					file_filter);
+	g_object_unref (file_filter);
+
+	gtk_box_pack_end (GTK_BOX (box), obj->priv->filter, FALSE, FALSE, 0);
+
+	box1 = gtk_hbox_new (FALSE, 6);
+	gtk_box_pack_end (GTK_BOX (box), box1, FALSE, FALSE, 0);
+
+	label = gtk_label_new (_("Number of results displayed"));
+	gtk_box_pack_start (GTK_BOX (box1), label, FALSE, FALSE, 0);
+
+	combo = gtk_combo_box_new_text ();
+	g_signal_connect (combo,
+			  "changed",
+			  G_CALLBACK (brasero_search_max_results_num_changed_cb),
+			  obj);
+	gtk_combo_box_append_text (GTK_COMBO_BOX (combo), "20");
+	gtk_combo_box_append_text (GTK_COMBO_BOX (combo), "50");
+	gtk_combo_box_append_text (GTK_COMBO_BOX (combo), "100");
+
+	gtk_combo_box_set_active (GTK_COMBO_BOX (combo), 1);
+	obj->priv->max_results = 50;
+
+	gtk_box_pack_start (GTK_BOX (box1), combo, FALSE, FALSE, 0);
+
+}
+
+static void
+brasero_search_destroy (GtkObject *object)
+{
+	BraseroSearch *search;
+
+	search = BRASERO_SEARCH (object);
+	if (search->priv->query) {
+		g_object_unref (search->priv->query);
+		search->priv->query = NULL;
+	}
+
+	if (search->priv->client) {
+		g_object_unref (search->priv->client);
+		search->priv->client = NULL;
+	}
+
+	if (search->priv->tree) {
+		g_signal_handlers_disconnect_by_func (gtk_tree_view_get_selection (GTK_TREE_VIEW (search->priv->tree)),
+		                                      brasero_search_tree_selection_changed_cb,
+		                                      search);
+
+		g_signal_handlers_disconnect_by_func (search->priv->filter,
+						      brasero_search_mime_filter_changed,
+						      search);
+
+		brasero_search_empty_tree (search);
+		search->priv->filter = NULL;
+		search->priv->tree = NULL;
+	}
+
+	if (search->priv->id) {
+		g_source_remove (search->priv->id);
+		search->priv->id = 0;
+	}
+
+	if (search->priv->hits) {
+		g_slist_foreach (search->priv->hits, (GFunc) beagle_hit_unref, NULL);
+		g_slist_free (search->priv->hits);
+		search->priv->hits = NULL;
+	}
+
+	if (GTK_OBJECT_CLASS (parent_class)->destroy)
+		GTK_OBJECT_CLASS (parent_class)->destroy (object);
+}
+
+static void
+brasero_search_finalize (GObject *object)
+{
+	BraseroSearch *cobj;
+
+	cobj = BRASERO_SEARCH (object);
+
+	g_free (cobj->priv);
+	G_OBJECT_CLASS (parent_class)->finalize (object);
+}
+
+static void
+brasero_search_iface_layout_object_init (BraseroLayoutObjectIFace *iface)
+{
+	iface->get_proportion = brasero_search_get_proportion;
+	iface->set_context = brasero_search_set_context;
+}
+
+static void
+brasero_search_iface_uri_container_init (BraseroURIContainerIFace *iface)
+{
+	iface->get_selected_uri = brasero_search_get_selected_uri;
+	iface->get_selected_uris = brasero_search_get_selected_uris;
+}
+
+static void
+brasero_search_class_init (BraseroSearchClass *klass)
+{
+	GObjectClass *object_class = G_OBJECT_CLASS (klass);
+	GtkObjectClass *gtkobject_class = GTK_OBJECT_CLASS (klass);
+
+	parent_class = g_type_class_peek_parent (klass);
+	object_class->finalize = brasero_search_finalize;
+	gtkobject_class->destroy = brasero_search_destroy;
+}
+
+GtkWidget *
+brasero_search_new ()
+{
+	BraseroSearch *obj;
+
+	obj = BRASERO_SEARCH (g_object_new (BRASERO_TYPE_SEARCH, NULL));
+
+	/* FIXME : there are better ways to do the following with the new API
+	 * see beagle_util_daemon_is_running (void) */
+	obj->priv->client = beagle_client_new (NULL);
+	if (!obj->priv->client) {
+		gtk_widget_set_sensitive (GTK_WIDGET (obj), FALSE);
+
+		/* we will retry in 10 seconds */
+		obj->priv->id = g_timeout_add_seconds (10,
+						       (GSourceFunc) brasero_search_try_again,
+						       obj);
+	}
+
+	return GTK_WIDGET (obj);
+}
+
 #endif



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]