[Rhythmbox-devel] patch for search entry



-
Hello,

Attached is a patch against CVS for the search entry that does two
things:

* Adds an icon that when pressed drops down a menu, allowing you to
select what to search (All, Artists, Albums, Songs).  The code that
would make the selection actually work has not been written yet, I
thought it better to get comments on this before I spend time doing
that.

* Adds and icon that when pressed clears the search entry ("clear
button")

You can see the new search entry here:
http://ishamael.inactivex.net/images/rb-new-search-entry.png

To get the effect of the icons in the entry, I've borrowed epiphany's
ephy-icon-entry widget.  

This is a request for comments & suggestions regarding this patch.  I
think these would be nice features, but I understand there has been some
debate in the past about a clear button, perhaps this new way (as
opposed to a large GtkButton) sovles it?

If there is a positive response, I'll go ahead and tie in the search
type so that your selection actually works, and commit it (with walters'
approval, of course).

Thanks,
-charlie

diff -x .deps -x .libs -x '*.o' -x '*.lo' -x '*.la' -x Makefile -x Makefile.in -x '.*swp' -ruN rhythmbox-cvs/widgets/ephy-icon-entry.c rhythmbox/widgets/ephy-icon-entry.c
--- rhythmbox-cvs/widgets/ephy-icon-entry.c	1969-12-31 19:00:00.000000000 -0500
+++ rhythmbox/widgets/ephy-icon-entry.c	2005-09-10 15:38:34.000000000 -0400
@@ -0,0 +1,352 @@
+/*
+ *  Copyright (C) 2003, 2004, 2005  Christian Persch
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2 of the License, or (at your option) any later version.
+ *
+ *  This library 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
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the
+ *  Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ *  Boston, MA 02111-1307, USA.
+ *
+ *  Adapted and modified from gtk+ code:
+ *
+ *  Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
+ *  Modified by the GTK+ Team and others 1997-2005.  See the AUTHORS
+ *  file in the gtk+ distribution for a list of people on the GTK+ Team.
+ *  See the ChangeLog in the gtk+ distribution files for a list of changes.
+ *  These files are distributed with GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
+ *
+ *  $Id: ephy-icon-entry.c,v 1.4 2005/08/07 20:31:32 chpe Exp $
+ */
+
+#include "config.h"
+
+#include "ephy-icon-entry.h"
+
+#include <gtk/gtkentry.h>
+#include <gtk/gtkbox.h>
+#include <gtk/gtkhbox.h>
+
+#define EPHY_ICON_ENTRY_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), EPHY_TYPE_ICON_ENTRY, EphyIconEntryPrivate))
+
+struct _EphyIconEntryPrivate
+{
+	GtkWidget *hbox;
+};
+
+static GtkWidgetClass *parent_class = NULL;
+
+/* private helper functions */
+
+static gboolean
+entry_focus_change_cb (GtkWidget *widget,
+		       GdkEventFocus *event,
+		       GtkWidget *entry)
+{
+	gtk_widget_queue_draw (entry);
+
+	return FALSE;
+}
+
+static void
+ephy_icon_entry_get_borders (GtkWidget *widget,
+			     GtkWidget *entry,
+			     int *xborder,
+			     int *yborder)
+{
+	int focus_width;
+	gboolean interior_focus;
+
+	g_return_if_fail (entry->style != NULL);
+
+	gtk_widget_style_get (entry,
+			      "focus-line-width", &focus_width,
+			      "interior-focus", &interior_focus,
+			      NULL);
+
+	*xborder = entry->style->xthickness;
+	*yborder = entry->style->ythickness;
+
+	if (!interior_focus)
+	{
+		*xborder += focus_width;
+		*yborder += focus_width;
+	}
+}
+
+static void
+ephy_icon_entry_paint (GtkWidget *widget,
+		       GdkEventExpose *event)
+{
+	EphyIconEntry *entry = EPHY_ICON_ENTRY (widget);
+	GtkWidget *entry_widget = entry->entry;
+	int x = 0, y = 0, width, height, focus_width;
+	gboolean interior_focus;
+
+	gtk_widget_style_get (entry_widget,
+			      "interior-focus", &interior_focus,
+			      "focus-line-width", &focus_width,
+			      NULL);
+
+	gdk_drawable_get_size (widget->window, &width, &height);
+
+	if (GTK_WIDGET_HAS_FOCUS (entry_widget) && !interior_focus)
+	{
+		x += focus_width;
+		y += focus_width;
+		width -= 2 * focus_width;
+		height -= 2 * focus_width;
+	}
+
+	gtk_paint_flat_box (entry_widget->style, widget->window, 
+			    GTK_WIDGET_STATE (entry_widget), GTK_SHADOW_NONE,
+			    NULL, entry_widget, "entry_bg", 
+			    /* FIXME: was 0, 0 in gtk_entry_expose, but I think this is correct: */
+			    x, y, width, height);
+     
+	gtk_paint_shadow (entry_widget->style, widget->window,
+			  GTK_STATE_NORMAL, GTK_SHADOW_IN,
+			  NULL, entry_widget, "entry",
+			  x, y, width, height);
+
+	if (GTK_WIDGET_HAS_FOCUS (entry_widget) && !interior_focus)
+	{
+		x -= focus_width;
+		y -= focus_width;
+		width += 2 * focus_width;
+		height += 2 * focus_width;
+
+		gtk_paint_focus (entry_widget->style, widget->window,
+				 GTK_WIDGET_STATE (entry_widget),
+				 NULL, entry_widget, "entry",
+				 /* FIXME: was 0, 0 in gtk_entry_draw_frame, but I think this is correct: */
+				 x, y, width, height);
+	}
+}
+
+/* Class implementation */
+
+static void
+ephy_icon_entry_init (EphyIconEntry *entry)
+{
+	EphyIconEntryPrivate *priv;
+	GtkWidget *widget = (GtkWidget *) entry;
+
+	priv = entry->priv = EPHY_ICON_ENTRY_GET_PRIVATE (entry);
+
+	GTK_WIDGET_UNSET_FLAGS (widget, GTK_NO_WINDOW);
+
+	priv->hbox = gtk_hbox_new (FALSE, /* FIXME */ 0);
+	gtk_container_add (GTK_CONTAINER (entry), priv->hbox);
+
+	entry->entry = gtk_entry_new ();
+	gtk_entry_set_has_frame (GTK_ENTRY (entry->entry), FALSE);
+	gtk_box_pack_start (GTK_BOX (priv->hbox), entry->entry, TRUE, TRUE, /* FIXME */ 0);
+
+	/* We need to queue a redraw when focus changes, to comply with themes
+	 * (like Clearlooks) which draw focused and unfocused entries differently.
+	 */
+	g_signal_connect_after (entry->entry, "focus-in-event",
+				G_CALLBACK (entry_focus_change_cb), entry);
+	g_signal_connect_after (entry->entry, "focus-out-event",
+				G_CALLBACK (entry_focus_change_cb), entry);
+}
+
+static void
+ephy_icon_entry_realize (GtkWidget *widget)
+{
+	GdkWindowAttr attributes;
+	gint attributes_mask;
+	gint border_width;
+
+	GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
+
+	border_width = GTK_CONTAINER (widget)->border_width;
+
+	attributes.x = widget->allocation.x + border_width;
+	attributes.y = widget->allocation.y + border_width;
+	attributes.width = widget->allocation.width - 2 * border_width;
+	attributes.height = widget->allocation.height - 2 * border_width;
+	attributes.window_type = GDK_WINDOW_CHILD;
+	attributes.event_mask = gtk_widget_get_events (widget)
+				| GDK_EXPOSURE_MASK;
+
+	attributes.visual = gtk_widget_get_visual (widget);
+	attributes.colormap = gtk_widget_get_colormap (widget);
+	attributes.wclass = GDK_INPUT_OUTPUT;
+	attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
+
+	widget->window = gdk_window_new (gtk_widget_get_parent_window (widget),
+					 &attributes, attributes_mask);
+	gdk_window_set_user_data (widget->window, widget);
+
+	widget->style = gtk_style_attach (widget->style, widget->window);
+
+	gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
+}
+
+static void
+ephy_icon_entry_size_request (GtkWidget *widget,
+			      GtkRequisition *requisition)
+{
+	EphyIconEntry *entry = EPHY_ICON_ENTRY (widget);
+	GtkContainer *container = GTK_CONTAINER (widget);
+	GtkBin *bin = GTK_BIN (widget);
+	int xborder, yborder;
+
+	requisition->width = requisition->height = container->border_width * 2;
+
+	gtk_widget_ensure_style (entry->entry);
+	ephy_icon_entry_get_borders (widget, entry->entry, &xborder, &yborder);
+
+	if (GTK_WIDGET_VISIBLE (bin->child))
+	{
+		GtkRequisition child_requisition;
+
+		gtk_widget_size_request (bin->child, &child_requisition);
+		requisition->width += child_requisition.width;
+		requisition->height += child_requisition.height;
+	}
+
+	requisition->width += 2 * xborder;
+	requisition->height += 2 * yborder;
+}
+
+static void
+ephy_icon_entry_size_allocate (GtkWidget *widget,
+			       GtkAllocation *allocation)
+{
+	EphyIconEntry *entry = EPHY_ICON_ENTRY (widget);
+	GtkContainer *container = GTK_CONTAINER (widget);
+	GtkBin *bin = GTK_BIN (widget);
+	GtkAllocation child_allocation;
+	int xborder, yborder;
+
+	widget->allocation = *allocation;
+
+	ephy_icon_entry_get_borders (widget, entry->entry, &xborder, &yborder);
+
+	if (GTK_WIDGET_REALIZED (widget))
+	{
+		child_allocation.x = container->border_width;
+		child_allocation.y = container->border_width;
+		child_allocation.width = MAX (allocation->width - container->border_width * 2, 0);
+		child_allocation.height = MAX (allocation->height - container->border_width * 2, 0);
+
+		gdk_window_move_resize (widget->window,
+					allocation->x + child_allocation.x,
+					allocation->y + child_allocation.y,
+					child_allocation.width,
+					child_allocation.height);
+	}
+  
+	child_allocation.x = container->border_width + xborder;
+	child_allocation.y = container->border_width + yborder;
+	child_allocation.width = MAX (allocation->width - (container->border_width + xborder) * 2, 0);
+	child_allocation.height = MAX (allocation->height - (container->border_width + yborder) * 2, 0);
+
+	gtk_widget_size_allocate (bin->child, &child_allocation);
+}
+
+static gboolean
+ephy_icon_entry_expose (GtkWidget *widget,
+			GdkEventExpose *event)
+{
+	if (GTK_WIDGET_DRAWABLE (widget) &&
+	    event->window == widget->window)
+	{
+		ephy_icon_entry_paint (widget, event);
+	}
+
+	return parent_class->expose_event (widget, event);
+}
+
+static void
+ephy_icon_entry_class_init (EphyIconEntryClass *klass)
+{
+	GObjectClass *object_class = G_OBJECT_CLASS (klass);
+	GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+	parent_class = GTK_WIDGET_CLASS (g_type_class_peek_parent (klass));
+
+	widget_class->realize = ephy_icon_entry_realize;
+	widget_class->size_request = ephy_icon_entry_size_request;
+	widget_class->size_allocate = ephy_icon_entry_size_allocate;
+	widget_class->expose_event = ephy_icon_entry_expose;
+
+	g_type_class_add_private (object_class, sizeof (EphyIconEntryPrivate));
+}
+
+GType
+ephy_icon_entry_get_type (void)
+{
+	static GType type = 0;
+
+	if (G_UNLIKELY (type == 0))
+	{
+		static const GTypeInfo our_info =
+		{
+			sizeof (EphyIconEntryClass),
+			NULL,
+			NULL,
+			(GClassInitFunc) ephy_icon_entry_class_init,
+			NULL,
+			NULL,
+			sizeof (EphyIconEntry),
+			0,
+			(GInstanceInitFunc) ephy_icon_entry_init
+		};
+
+		type = g_type_register_static (GTK_TYPE_BIN,
+					       "EphyIconEntry",
+					       &our_info, 0);
+	}
+
+	return type;
+}
+
+/* public functions */
+
+GtkWidget *
+ephy_icon_entry_new (void)
+{
+	return GTK_WIDGET (g_object_new (EPHY_TYPE_ICON_ENTRY, NULL));
+}
+
+void
+ephy_icon_entry_pack_widget (EphyIconEntry *entry,
+			     GtkWidget *widget,
+			     gboolean start)
+{
+	EphyIconEntryPrivate *priv;
+
+	g_return_if_fail (EPHY_IS_ICON_ENTRY (entry));
+
+	priv = entry->priv;
+
+	if (start)
+	{
+		gtk_box_pack_start (GTK_BOX (priv->hbox), widget, FALSE, FALSE, /* FIXME */ 2);
+		gtk_box_reorder_child (GTK_BOX (priv->hbox), widget, 0);
+	}
+	else
+	{
+		gtk_box_pack_end (GTK_BOX (priv->hbox), widget, FALSE, FALSE, /* FIXME */ 2);
+	}
+}
+
+GtkWidget *
+ephy_icon_entry_get_entry (EphyIconEntry *entry)
+{
+	g_return_val_if_fail (EPHY_IS_ICON_ENTRY (entry), NULL);
+
+	return entry->entry;
+}
diff -x .deps -x .libs -x '*.o' -x '*.lo' -x '*.la' -x Makefile -x Makefile.in -x '.*swp' -ruN rhythmbox-cvs/widgets/ephy-icon-entry.h rhythmbox/widgets/ephy-icon-entry.h
--- rhythmbox-cvs/widgets/ephy-icon-entry.h	1969-12-31 19:00:00.000000000 -0500
+++ rhythmbox/widgets/ephy-icon-entry.h	2005-09-10 15:38:34.000000000 -0400
@@ -0,0 +1,76 @@
+/*
+ *  Copyright (C) 2003, 2004, 2005  Christian Persch
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2 of the License, or (at your option) any later version.
+ *
+ *  This library 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
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the
+ *  Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ *  Boston, MA 02111-1307, USA.
+ *
+ *  Adapted and modified from gtk+ code:
+ *
+ *  Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
+ *  Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
+ *  file in the gtk+ distribution for a list of people on the GTK+ Team.
+ *  See the ChangeLog in the gtk+ distribution files for a list of changes.
+ *  These files are distributed with GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
+ *
+ *  $Id: ephy-icon-entry.h,v 1.2 2005/08/07 20:31:32 chpe Exp $
+ */
+
+#ifndef EPHY_ICON_ENTRY_H
+#define EPHY_ICON_ENTRY_H
+
+#include <gtk/gtkbin.h>
+
+G_BEGIN_DECLS
+
+#define EPHY_TYPE_ICON_ENTRY		(ephy_icon_entry_get_type())
+#define EPHY_ICON_ENTRY(object)		(G_TYPE_CHECK_INSTANCE_CAST((object), EPHY_TYPE_ICON_ENTRY, EphyIconEntry))
+#define EPHY_ICON_ENTRY_CLASS(klass)	(G_TYPE_CHECK_CLASS_CAST((klass), EPHY_TYPE_ICON_ENTRY, EphyIconEntryClass))
+#define EPHY_IS_ICON_ENTRY(object)	(G_TYPE_CHECK_INSTANCE_TYPE((object), EPHY_TYPE_ICON_ENTRY))
+#define EPHY_IS_ICON_ENTRY_CLASS(klass)	(G_TYPE_CHECK_CLASS_TYPE((klass), EPHY_TYPE_ICON_ENTRY))
+#define EPHY_ICON_ENTRY_GET_CLASS(obj)	(G_TYPE_INSTANCE_GET_CLASS((obj), EPHY_TYPE_ICON_ENTRY, EphyIconEntryClass))
+
+typedef struct _EphyIconEntryClass	EphyIconEntryClass;
+typedef struct _EphyIconEntry		EphyIconEntry;
+typedef struct _EphyIconEntryPrivate	EphyIconEntryPrivate;
+
+struct _EphyIconEntryClass
+{
+	GtkBinClass parent_class;
+};
+
+struct _EphyIconEntry
+{
+	GtkBin parent_object;
+
+	/*< public >*/
+	GtkWidget *entry;
+
+	/*< private >*/
+	EphyIconEntryPrivate *priv;
+};
+
+GType		ephy_icon_entry_get_type	(void);
+
+GtkWidget      *ephy_icon_entry_new		(void);
+
+void		ephy_icon_entry_pack_widget	(EphyIconEntry *entry,
+						 GtkWidget *widget,
+						 gboolean start);
+
+GtkWidget      *ephy_icon_entry_get_entry	(EphyIconEntry *entry);
+
+G_END_DECLS
+
+#endif
diff -x .deps -x .libs -x '*.o' -x '*.lo' -x '*.la' -x Makefile -x Makefile.in -x '.*swp' -ruN rhythmbox-cvs/widgets/Makefile.am rhythmbox/widgets/Makefile.am
--- rhythmbox-cvs/widgets/Makefile.am	2005-08-23 13:35:27.000000000 -0400
+++ rhythmbox/widgets/Makefile.am	2005-09-10 15:38:51.000000000 -0400
@@ -5,6 +5,8 @@
 librbwidgets_la_SOURCES =				\
 	eel-gconf-extensions.c				\
 	eel-gconf-extensions.h				\
+	ephy-icon-entry.c				\
+	ephy-icon-entry.h				\
 	rb-song-display-box.c				\
 	rb-song-display-box.h				\
 	rb-entry-view.c					\
diff -x .deps -x .libs -x '*.o' -x '*.lo' -x '*.la' -x Makefile -x Makefile.in -x '.*swp' -ruN rhythmbox-cvs/widgets/rb-search-entry.c rhythmbox/widgets/rb-search-entry.c
--- rhythmbox-cvs/widgets/rb-search-entry.c	2005-08-15 09:37:53.000000000 -0400
+++ rhythmbox/widgets/rb-search-entry.c	2005-09-10 17:06:18.000000000 -0400
@@ -23,15 +23,45 @@
 #include <gtk/gtklabel.h>
 #include <gtk/gtkhbox.h>
 #include <gtk/gtkentry.h>
+#include <gtk/gtkeventbox.h>
+#include <gtk/gtkstock.h>
+#include <gtk/gtkimage.h>
+#include <gtk/gtkmenu.h>
+#include <gtk/gtkradiomenuitem.h>
 #include <config.h>
 #include <libgnome/gnome-i18n.h>
 #include <string.h>
 
 #include "rb-search-entry.h"
+#include "ephy-icon-entry.h"
+
+#define ENUM_ENTRY(NAME, DESC) { NAME, "" #NAME "", DESC }
+
+GType
+rb_search_type_get_type (void)
+{
+	static GType etype = 0;
+
+	if (etype == 0) {
+		static const GEnumValue values[] = {
+			ENUM_ENTRY (RB_SEARCH_TYPE_ALL, "Search all metadata"),
+			ENUM_ENTRY (RB_SEARCH_TYPE_ARTISTS, "Search artist names"),
+			ENUM_ENTRY (RB_SEARCH_TYPE_ALBUMS, "Search album names"),
+			ENUM_ENTRY (RB_SEARCH_TYPE_TITLES, "Search song titles"),
+			{0, 0, 0}
+		};
+
+		etype = g_enum_register_static ("RBSearchType", values);
+	}
+
+	return etype;
+}
+
 
 static void rb_search_entry_class_init (RBSearchEntryClass *klass);
 static void rb_search_entry_init (RBSearchEntry *entry);
 static void rb_search_entry_finalize (GObject *object);
+static void rb_search_entry_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec);
 static gboolean rb_search_entry_timeout_cb (RBSearchEntry *entry);
 static void rb_search_entry_changed_cb (GtkEditable *editable,
 			                RBSearchEntry *entry);
@@ -40,10 +70,18 @@
 static gboolean rb_search_entry_focus_out_event_cb (GtkWidget *widget,
 				                    GdkEventFocus *event,
 				                    RBSearchEntry *entry);
-
+static gboolean rb_search_entry_clear_button_press (GtkWidget *widget,
+						    GdkEventButton *event,
+						    RBSearchEntry *entry);
+static gboolean rb_search_entry_type_button_press (GtkWidget *widget,
+						   GdkEventButton *event,
+						   RBSearchEntry *entry);
 struct RBSearchEntryPrivate
 {
 	GtkWidget *entry;
+	
+	GtkWidget *type_menu;
+	RBSearchType search_type;
 
 	gboolean clearing;
 
@@ -57,6 +95,11 @@
 	LAST_SIGNAL
 };
 
+enum {
+	PROP_0,
+	PROP_SEARCH_TYPE
+};
+
 static GObjectClass *parent_class = NULL;
 
 static guint rb_search_entry_signals[LAST_SIGNAL] = { 0 };
@@ -97,7 +140,17 @@
 	parent_class = g_type_class_peek_parent (klass);
 
 	object_class->finalize = rb_search_entry_finalize;
-
+	object_class->get_property = rb_search_entry_get_property;
+	
+	g_object_class_install_property (object_class, 
+					 PROP_SEARCH_TYPE,
+					 g_param_spec_enum ("search-type",
+						 	    "Search Type",
+							    "Type of search to perform",
+							    RB_TYPE_SEARCH_TYPE,
+							    RB_SEARCH_TYPE_ALL,
+							    G_PARAM_READABLE));
+	
 	rb_search_entry_signals[SEARCH] =
 		g_signal_new ("search",
 			      G_OBJECT_CLASS_TYPE (object_class),
@@ -120,10 +173,28 @@
 }
 
 static void
+menu_item_toggled_cb (GtkWidget *menu_item,
+		      RBSearchEntry *entry)
+{
+	gint val = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (menu_item), "search-type"));
+
+	entry->priv->search_type = val;
+	g_object_notify (G_OBJECT (entry), "search-type");
+
+	return;
+}
+
+static void
 rb_search_entry_init (RBSearchEntry *entry)
 {
 	GtkWidget *label;
-
+	GtkWidget *gtkentry;
+	GtkWidget *eventbox;
+	GtkWidget *image;
+	GSList *menu_items = NULL;
+	gchar *names[] = {_("A_ll"), _("_Artists"), _("Al_bums"), _("_Songs")};
+	gint i;
+	
 	entry->priv = g_new0 (RBSearchEntryPrivate, 1);
 
 	/* this string can only be so long, or there wont be a search entry :) */
@@ -131,14 +202,53 @@
 	gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_RIGHT);
 	gtk_box_pack_start (GTK_BOX (entry), label, FALSE, TRUE, 0);
 
-	entry->priv->entry = gtk_entry_new ();
+	entry->priv->entry = ephy_icon_entry_new ();
+	gtkentry = ephy_icon_entry_get_entry (EPHY_ICON_ENTRY (entry->priv->entry));
+
+	entry->priv->type_menu = gtk_menu_new ();
+	
+	for (i = 0; i <= RB_SEARCH_TYPE_TITLES; i++) {
+		GtkWidget *menu_item;
 
+		menu_item = gtk_radio_menu_item_new_with_mnemonic (menu_items, names[i]);
+		menu_items = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (menu_item));
+		g_object_set_data (G_OBJECT (menu_item), "search-type", GINT_TO_POINTER (i));
+		gtk_menu_shell_append (GTK_MENU_SHELL (entry->priv->type_menu), menu_item);
+		g_signal_connect_object (G_OBJECT (menu_item), 
+					 "toggled", 
+					 G_CALLBACK (menu_item_toggled_cb),
+					 entry, 0);
+	}
+	gtk_widget_show_all (entry->priv->type_menu);
+		
+	eventbox = gtk_event_box_new ();
+	gtk_container_set_border_width (GTK_CONTAINER (eventbox), 2);
+	gtk_event_box_set_visible_window (GTK_EVENT_BOX (eventbox), FALSE);
+	g_signal_connect_object (G_OBJECT (eventbox),
+				 "button-press-event",
+				 G_CALLBACK (rb_search_entry_type_button_press),
+				 entry, 0);
+	image = gtk_image_new_from_stock (GTK_STOCK_FIND, GTK_ICON_SIZE_MENU);
+	gtk_container_add (GTK_CONTAINER (eventbox), image);
+	ephy_icon_entry_pack_widget (EPHY_ICON_ENTRY (entry->priv->entry), eventbox, TRUE);
+	
+	eventbox = gtk_event_box_new ();
+	gtk_container_set_border_width (GTK_CONTAINER (eventbox), 2);
+	gtk_event_box_set_visible_window (GTK_EVENT_BOX (eventbox), FALSE);
+	g_signal_connect_object (G_OBJECT (eventbox),
+				 "button-press-event",
+				 G_CALLBACK (rb_search_entry_clear_button_press),
+				 entry, 0);
+	image = gtk_image_new_from_stock (GTK_STOCK_CLEAR, GTK_ICON_SIZE_MENU);
+	gtk_container_add (GTK_CONTAINER (eventbox), image);
+	ephy_icon_entry_pack_widget (EPHY_ICON_ENTRY (entry->priv->entry), eventbox, FALSE);
+	
 	gtk_label_set_mnemonic_widget (GTK_LABEL (label),
 				       entry->priv->entry);
 
 	gtk_box_pack_start (GTK_BOX (entry), entry->priv->entry, TRUE, TRUE, 0);
 
-	g_signal_connect_object (G_OBJECT (entry->priv->entry),
+	g_signal_connect_object (G_OBJECT (gtkentry),
 				 "changed",
 				 G_CALLBACK (rb_search_entry_changed_cb),
 				 entry, 0);
@@ -146,7 +256,7 @@
 				 "focus_out_event",
 				 G_CALLBACK (rb_search_entry_focus_out_event_cb),
 				 entry, 0);
-	g_signal_connect_object (G_OBJECT (entry->priv->entry),
+	g_signal_connect_object (G_OBJECT (gtkentry),
 				 "activate",
 				 G_CALLBACK (rb_search_entry_activate_cb),
 				 entry, 0);
@@ -169,13 +279,30 @@
 	G_OBJECT_CLASS (parent_class)->finalize (object);
 }
 
+static void 
+rb_search_entry_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
+{
+	RBSearchEntry *entry = RB_SEARCH_ENTRY (object);
+	
+	switch (prop_id) {
+		case PROP_SEARCH_TYPE:
+			g_value_set_enum (value, entry->priv->search_type);
+			break;
+		default:
+			G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+			break;
+	}
+
+	return;
+}
+
 RBSearchEntry *
 rb_search_entry_new (void)
 {
 	RBSearchEntry *entry;
 
 	entry = RB_SEARCH_ENTRY (g_object_new (RB_TYPE_SEARCH_ENTRY,
-					       "spacing", 5,
+					       "spacing", 6,
 					       NULL));
 
 	g_return_val_if_fail (entry->priv != NULL, NULL);
@@ -193,7 +320,7 @@
 		
 	entry->priv->clearing = TRUE;
 	
-	gtk_entry_set_text (GTK_ENTRY (entry->priv->entry), "");
+	gtk_entry_set_text (GTK_ENTRY (ephy_icon_entry_get_entry (EPHY_ICON_ENTRY (entry->priv->entry))), "");
 
 	entry->priv->clearing = FALSE;
 }
@@ -201,7 +328,7 @@
 void
 rb_search_entry_set_text (RBSearchEntry *entry, const char *text)
 {
-	gtk_entry_set_text (GTK_ENTRY (entry->priv->entry),
+	gtk_entry_set_text (GTK_ENTRY (ephy_icon_entry_get_entry (EPHY_ICON_ENTRY (entry->priv->entry))),
 			    text ? text : "");
 }
 
@@ -226,7 +353,7 @@
 	gdk_threads_enter ();
 	
 	g_signal_emit (G_OBJECT (entry), rb_search_entry_signals[SEARCH], 0,
-		       gtk_entry_get_text (GTK_ENTRY (entry->priv->entry)));
+		       gtk_entry_get_text (GTK_ENTRY (ephy_icon_entry_get_entry (EPHY_ICON_ENTRY (entry->priv->entry)))));
 	entry->priv->timeout = 0;
 
 	gdk_threads_leave ();
@@ -246,7 +373,7 @@
 	entry->priv->timeout = 0;
 
 	g_signal_emit (G_OBJECT (entry), rb_search_entry_signals[SEARCH], 0,
-		       gtk_entry_get_text (GTK_ENTRY (entry->priv->entry)));
+		       gtk_entry_get_text (GTK_ENTRY (ephy_icon_entry_get_entry (EPHY_ICON_ENTRY (entry->priv->entry)))));
 
 	return FALSE;
 }
@@ -254,7 +381,7 @@
 gboolean
 rb_search_entry_searching(RBSearchEntry *entry)
 {
-	return strcmp ("", gtk_entry_get_text (GTK_ENTRY (entry->priv->entry))) != 0;
+	return strcmp ("", gtk_entry_get_text (GTK_ENTRY (ephy_icon_entry_get_entry (EPHY_ICON_ENTRY (entry->priv->entry))))) != 0;
 }
 
 static void
@@ -263,3 +390,28 @@
 {
 	g_signal_emit (G_OBJECT (entry), rb_search_entry_signals[ACTIVATE], 0);
 }
+
+static gboolean rb_search_entry_clear_button_press (GtkWidget *widget,
+						    GdkEventButton *event,
+						    RBSearchEntry *entry)
+{
+	gtk_entry_set_text (GTK_ENTRY (ephy_icon_entry_get_entry (EPHY_ICON_ENTRY (entry->priv->entry))), "");
+	
+	return FALSE;
+}
+	
+static gboolean rb_search_entry_type_button_press (GtkWidget *widget,
+						   GdkEventButton *event,
+						   RBSearchEntry *entry)
+{
+	gtk_menu_popup (GTK_MENU (entry->priv->type_menu),
+			NULL,
+			NULL,
+			NULL,
+			NULL,
+			event->button,
+			event->time);
+
+	return TRUE;
+}
+
diff -x .deps -x .libs -x '*.o' -x '*.lo' -x '*.la' -x Makefile -x Makefile.in -x '.*swp' -ruN rhythmbox-cvs/widgets/rb-search-entry.h rhythmbox/widgets/rb-search-entry.h
--- rhythmbox-cvs/widgets/rb-search-entry.h	2005-08-15 09:37:53.000000000 -0400
+++ rhythmbox/widgets/rb-search-entry.h	2005-09-10 16:44:10.000000000 -0400
@@ -33,6 +33,16 @@
 #define RB_IS_SEARCH_ENTRY_CLASS(k)  (G_TYPE_CHECK_CLASS_TYPE ((k), RB_TYPE_SEARCH_ENTRY))
 #define RB_SEARCH_ENTRY_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), RB_TYPE_SEARCH_ENTRY, RBSearchEntryClass))
 
+typedef enum {
+	RB_SEARCH_TYPE_ALL = 0,
+	RB_SEARCH_TYPE_ARTISTS,
+	RB_SEARCH_TYPE_ALBUMS,
+	RB_SEARCH_TYPE_TITLES
+} RBSearchType;
+
+GType rb_search_type_get_type (void);
+#define RB_TYPE_SEARCH_TYPE (rb_search_type_get_type ())
+
 typedef struct RBSearchEntryPrivate RBSearchEntryPrivate;
 
 typedef struct


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