[patch] emblem sidebar



Hi,

I've made a little sidebar thing that lets you drag emblem icons to
files to set/unset the chosen emblem.  I'm not sure if it's the correct
use of the sidebar, but I like it.  What do you guys think?  Here's a
screenshot:

http://www.cs.indiana.edu/~jwillcox/files/screenshots/nautilus-emblem-sidebar.png

(it's a little inaccurate...the "erase" icon is actually at the end)

Thanks,
James

BTW, nautilus-emblem-panel.[ch] should go in src/
? components/adapter/Nautilus_ComponentAdapterFactory_std.server.in
? components/history/Nautilus_View_history.server.in
? components/loser/content/Nautilus_View_content-loser.server.in
? components/loser/sidebar/Nautilus_View_sidebar-loser.server.in
? components/music/Nautilus_View_music.server.in
? components/notes/Nautilus_View_notes.server.in
? components/sample/Nautilus_View_sample.server.in
? components/text/Nautilus_View_text.server.in
? components/throbber/Nautilus_Control_throbber.server.in
? components/tree/Nautilus_View_tree.server.in
? src/.nautilus-emblem-panel.c.swp
? src/emblem_panel_patch.diff
? src/nautilus-emblem-panel.c
? src/nautilus-emblem-panel.h
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/nautilus/ChangeLog,v
retrieving revision 1.5524
diff -u -5 -r1.5524 ChangeLog
--- ChangeLog	26 Sep 2002 11:37:46 -0000	1.5524
+++ ChangeLog	26 Sep 2002 23:09:01 -0000
@@ -1,5 +1,12 @@
+2002-09-26  James Willcox  <jwillcox gnome org>
+
+	* src/Makefile.am:  Added nautilus-emblem-panel.[ch]
+	* src/nautilus-window.c: (nautilus_window_set_up_sidebar):  Add the
+	emblem sidebar.
+	* src/nautilus-window.h:
+
 2002-09-26  Alexander Larsson  <alexl redhat com>
 
 	* libnautilus-private/Makefile.am:
 	* libnautilus-private/nautilus-find-icon-image.c:
 	* libnautilus-private/nautilus-find-icon-image.h:
Index: src/Makefile.am
===================================================================
RCS file: /cvs/gnome/nautilus/src/Makefile.am,v
retrieving revision 1.140
diff -u -5 -r1.140 Makefile.am
--- src/Makefile.am	21 Sep 2002 16:31:23 -0000	1.140
+++ src/Makefile.am	26 Sep 2002 23:09:01 -0000
@@ -49,10 +49,11 @@
 	nautilus-complex-search-bar.c		\
 	nautilus-component-adapter-factory.c	\
 	nautilus-desktop-window.c		\
 	nautilus-first-time-druid.c		\
 	nautilus-information-panel.c            \
+	nautilus-emblem-panel.c                 \
 	nautilus-location-bar.c         	\
 	nautilus-main.c 			\
 	nautilus-navigation-bar.c         	\
 	nautilus-preferences-dialog.c		\
 	nautilus-profiler.c			\
@@ -83,10 +84,11 @@
 	nautilus-complex-search-bar.h		\
 	nautilus-component-adapter-factory.h	\
 	nautilus-desktop-window.h		\
 	nautilus-first-time-druid.h		\
 	nautilus-information-panel.h            \
+	nautilus-emblem-panel.h                 \
 	nautilus-location-bar.h			\
 	nautilus-main.h				\
 	nautilus-navigation-bar.h		\
 	nautilus-preferences-dialog.h		\
 	nautilus-profiler.h			\
Index: src/nautilus-window.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/nautilus-window.c,v
retrieving revision 1.396
diff -u -5 -r1.396 nautilus-window.c
--- src/nautilus-window.c	22 Sep 2002 17:18:44 -0000	1.396
+++ src/nautilus-window.c	26 Sep 2002 23:09:02 -0000
@@ -31,10 +31,11 @@
 #include "nautilus-window-private.h"
 
 #include "nautilus-application.h"
 #include "nautilus-bookmarks-window.h"
 #include "nautilus-information-panel.h"
+#include "nautilus-emblem-panel.h"
 #include "nautilus-main.h"
 #include "nautilus-signaller.h"
 #include "nautilus-switchable-navigation-bar.h"
 #include "nautilus-window-manage-views.h"
 #include "nautilus-zoom-control.h"
@@ -653,10 +654,11 @@
 			  "size_allocate",
 			  G_CALLBACK (side_pane_size_allocate_callback),
 			  window);
 	
 	window->information_panel = nautilus_information_panel_new ();
+	window->emblem_panel = nautilus_emblem_panel_new ();
 	
 	if (window->details->location != NULL &&
 	    window->details->title != NULL) {
 		nautilus_information_panel_set_uri (window->information_panel,
 						    window->details->location,
@@ -665,14 +667,19 @@
 
 	g_signal_connect_object (window->information_panel, "location_changed",
 				 G_CALLBACK (go_to_callback), window, 0);
 
 	gtk_widget_show (GTK_WIDGET (window->information_panel));
+	gtk_widget_show (GTK_WIDGET (window->emblem_panel));
 
 	nautilus_side_pane_add_panel (NAUTILUS_SIDE_PANE (window->sidebar), 
 				      GTK_WIDGET (window->information_panel),
 				      _("Information"));
+
+	nautilus_side_pane_add_panel (NAUTILUS_SIDE_PANE (window->sidebar), 
+				      GTK_WIDGET (window->emblem_panel),
+				      _("Emblems"));
 
 	/* Set up the sidebar panels. */
 	update_sidebar_panels_from_preferences (window);
 	
 	gtk_widget_show (GTK_WIDGET (window->sidebar));
Index: src/nautilus-window.h
===================================================================
RCS file: /cvs/gnome/nautilus/src/nautilus-window.h,v
retrieving revision 1.104
diff -u -5 -r1.104 nautilus-window.h
--- src/nautilus-window.h	21 Sep 2002 16:31:23 -0000	1.104
+++ src/nautilus-window.h	26 Sep 2002 23:09:02 -0000
@@ -35,10 +35,11 @@
 #include <libnautilus-private/nautilus-view-identifier.h>
 #include "nautilus-applicable-views.h"
 #include "nautilus-view-frame.h"
 #include "nautilus-application.h"
 #include "nautilus-information-panel.h"
+#include "nautilus-emblem-panel.h"
 #include "nautilus-side-pane.h"
 
 #define NAUTILUS_TYPE_WINDOW              (nautilus_window_get_type())
 #define NAUTILUS_WINDOW(obj)	          (GTK_CHECK_CAST ((obj), NAUTILUS_TYPE_WINDOW, NautilusWindow))
 #define NAUTILUS_WINDOW_CLASS(klass)      (GTK_CHECK_CLASS_CAST ((klass), NAUTILUS_TYPE_WINDOW, NautilusWindowClass))
@@ -77,10 +78,11 @@
         NautilusWindowDetails *details;
         
         /** UI stuff **/
         NautilusSidePane *sidebar;
         NautilusInformationPanel *information_panel;
+        NautilusEmblemPanel      *emblem_panel;
         GtkWidget *content_hbox;
         GtkWidget *view_as_option_menu;
         GtkWidget *navigation_bar;
         
 	char *last_geometry;
 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */

/*
 * Nautilus
 *
 * Copyright (C) 1999, 2000, 2001 Eazel, Inc.
 *
 * Nautilus is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * Nautilus 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * Author:  James Willcox  <jwillcox gnome org>
 *
 * This is a sidebar displaying emblems which can be dragged onto files to
 * set/unset the chosen emblem for that particular file.
 *
 */

#include <config.h>
#include "nautilus-emblem-panel.h"

#include <eel/eel-gtk-macros.h>
#include <eel/eel-string.h>
#include <eel/eel-wrap-table.h>
#include <eel/eel-labeled-image.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <gtk/gtk.h>
#include <libgnomeui/gnome-uidefs.h>
#include <libgnomevfs/gnome-vfs-utils.h>
#include <libnautilus-private/nautilus-customization-data.h>
#include <libnautilus-private/nautilus-icon-factory.h>

struct NautilusEmblemPanelDetails {
	GtkVBox *container;

	gchar *drag_keyword;
};

#define ERASE_EMBLEM_KEYWORD			"erase"
#define STANDARD_EMBLEM_HEIGHT			52
#define EMBLEM_LABEL_SPACING			2

static void     nautilus_emblem_panel_class_init      (GObjectClass *object_klass);
static void     nautilus_emblem_panel_init            (GObject      *object);
static void     nautilus_emblem_panel_destroy         (GtkObject      *object);
static void     nautilus_emblem_panel_finalize        (GObject     *object);

static GtkTargetEntry drag_types[] = {
	{"property/keyword", 0, 0 }
};

EEL_CLASS_BOILERPLATE (NautilusEmblemPanel, nautilus_emblem_panel, EEL_TYPE_BACKGROUND_BOX)

static void
nautilus_emblem_panel_class_init (GObjectClass *object_klass)
{
	GtkWidgetClass *widget_class;
	GObjectClass *gobject_class;
	GtkObjectClass *gtk_object_class;
	
	NautilusEmblemPanelClass *klass;

	widget_class = GTK_WIDGET_CLASS (object_klass);
	klass = NAUTILUS_EMBLEM_PANEL_CLASS (object_klass);
	gobject_class = G_OBJECT_CLASS (object_klass);
	gtk_object_class = GTK_OBJECT_CLASS (object_klass);
	
	gobject_class->finalize = nautilus_emblem_panel_finalize;

	gtk_object_class->destroy = nautilus_emblem_panel_destroy;
}

/* utility routine to strip the extension from the passed in string */
static char*
strip_extension (const char* string_to_strip)
{
	char *result_str, *temp_str;
	if (string_to_strip == NULL)
		return NULL;
	
	result_str = g_strdup(string_to_strip);
	temp_str = strrchr(result_str, '.');
	if (temp_str)
		*temp_str = '\0';
	return result_str;
}

static void
nautilus_emblem_panel_drag_data_get_cb (GtkWidget *image,
					GdkDragContext *context,
					GtkSelectionData *data,
					guint info,
					guint time,
					NautilusEmblemPanel *emblem_panel)
{
	gtk_selection_data_set (data, data->target, 8,
				emblem_panel->details->drag_keyword,
				strlen (emblem_panel->details->drag_keyword));
}

static void
nautilus_emblem_panel_drag_begin_cb (GtkWidget *widget,
				     GdkDragContext *drag_context,
				     NautilusEmblemPanel *emblem_panel)
{
	gchar *keyword;

	keyword = g_object_get_data (G_OBJECT (widget), "emblem-keyword");

	emblem_panel->details->drag_keyword = keyword;
}

static GtkWidget *
nautilus_emblem_panel_get_content (NautilusEmblemPanel *emblem_panel)
{
	NautilusCustomizationData *customization_data;
	GtkWidget *emblems_table, *image, *scroller;
	GtkWidget *erase_widget = NULL;
	char *emblem_name;
	GdkPixbuf *pixbuf;
	GtkWidget *event_box;
	char *label;

	/* The emblems wrapped table */
	scroller = eel_scrolled_wrap_table_new (TRUE, &emblems_table);

	gtk_container_set_border_width (GTK_CONTAINER (emblems_table), GNOME_PAD);
	
	gtk_widget_show (scroller);

	/* Use nautilus_customization to make the emblem widgets */
	customization_data = nautilus_customization_data_new ("emblems", TRUE,
						TRUE,
						NAUTILUS_ICON_SIZE_SMALL,
						NAUTILUS_ICON_SIZE_SMALL);
	
	while (nautilus_customization_data_get_next_element_for_display (customization_data,
									 &emblem_name,
									 &pixbuf,
									 &label) == GNOME_VFS_OK) {	
		gboolean is_erase_widget = FALSE;
		gchar *keyword;

		keyword = strip_extension (emblem_name);
		g_free (emblem_name);


		image = eel_labeled_image_new (label, pixbuf);
		eel_labeled_image_set_fixed_image_height (EEL_LABELED_IMAGE (image), STANDARD_EMBLEM_HEIGHT);
		eel_labeled_image_set_spacing (EEL_LABELED_IMAGE (image), EMBLEM_LABEL_SPACING);
		event_box = gtk_event_box_new ();
		gtk_container_add (GTK_CONTAINER (event_box), image);

		

		gtk_drag_source_set (event_box, GDK_BUTTON1_MASK, drag_types,
				     G_N_ELEMENTS (drag_types),
				     GDK_ACTION_COPY|GDK_ACTION_MOVE);

		gtk_drag_source_set_icon_pixbuf (event_box, pixbuf);

		g_signal_connect (event_box, "drag-data-get",
			G_CALLBACK (nautilus_emblem_panel_drag_data_get_cb),
			emblem_panel);
		g_signal_connect (event_box, "drag-begin",
			G_CALLBACK (nautilus_emblem_panel_drag_begin_cb),
			emblem_panel);
		
		g_free (label);
		g_object_unref (pixbuf);

		g_object_set_data_full (G_OBJECT (event_box),
					"emblem-keyword",
					keyword, g_free);

		if (strcmp (ERASE_EMBLEM_KEYWORD, keyword) == 0) {
			is_erase_widget = TRUE;
			erase_widget = event_box;
		}

		if (!is_erase_widget)
			gtk_container_add (GTK_CONTAINER (emblems_table), event_box);
	}

	/* we want to put the erase icon at the end */
	if (erase_widget != NULL)
			gtk_container_add (GTK_CONTAINER (emblems_table),
					   erase_widget);

	gtk_widget_show_all (emblems_table);

	return scroller;
}

static void
nautilus_emblem_panel_init (GObject *object)
{
	NautilusEmblemPanel *emblem_panel;
	GtkWidget *widget;
	
	emblem_panel = NAUTILUS_EMBLEM_PANEL (object);

	emblem_panel->details = g_new0 (NautilusEmblemPanelDetails, 1);

	widget = nautilus_emblem_panel_get_content (emblem_panel);
	gtk_container_add (GTK_CONTAINER (emblem_panel), widget);
}

static void
nautilus_emblem_panel_destroy (GtkObject *object)
{
	NautilusEmblemPanel *emblem_panel;

	emblem_panel = NAUTILUS_EMBLEM_PANEL (object);

	if (emblem_panel->details) {
		g_free (emblem_panel->details);
		emblem_panel->details = NULL;
	}

	EEL_CALL_PARENT (GTK_OBJECT_CLASS, destroy, (object));
}

static void
nautilus_emblem_panel_finalize (GObject *object)
{
	EEL_CALL_PARENT (G_OBJECT_CLASS, finalize, (object));
}

/* create a new instance */
NautilusEmblemPanel *
nautilus_emblem_panel_new (void)
{
	return NAUTILUS_EMBLEM_PANEL (gtk_widget_new (nautilus_emblem_panel_get_type (), NULL));
}
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */

/*
 * Nautilus
 *
 * Copyright (C) 1999, 2000 Eazel, Inc.
 *
 * Nautilus is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * Nautilus 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 *
 *  This is the header file for the index panel widget, which displays overview information
 *  in a vertical panel and hosts the meta-views.
 */

#ifndef NAUTILUS_EMBLEM_PANEL_H
#define NAUTILUS_EMBLEM_PANEL_H

#include <eel/eel-background-box.h>

#include "nautilus-view-frame.h"

#define NAUTILUS_TYPE_EMBLEM_PANEL \
	(nautilus_emblem_panel_get_type ())
#define NAUTILUS_EMBLEM_PANEL(obj) \
	(GTK_CHECK_CAST ((obj), NAUTILUS_TYPE_EMBLEM_PANEL, NautilusEmblemPanel))
#define NAUTILUS_EMBLEM_PANEL_CLASS(klass) \
	(GTK_CHECK_CLASS_CAST ((klass), NAUTILUS_TYPE_EMBLEM_PANEL, NautilusEmblemPanelClass))
#define NAUTILUS_IS_EMBLEM_PANEL(obj) \
	(GTK_CHECK_TYPE ((obj), NAUTILUS_TYPE_EMBLEM_PANEL))
#define NAUTILUS_IS_EMBLEM_PANEL_CLASS(klass) \
	(GTK_CHECK_CLASS_TYPE ((klass), NAUTILUS_TYPE_EMBLEM_PANEL))

typedef struct NautilusEmblemPanelDetails NautilusEmblemPanelDetails;

typedef struct {
	EelBackgroundBox parent_slot;
	NautilusEmblemPanelDetails *details;
} NautilusEmblemPanel;

typedef struct {
	EelBackgroundBoxClass parent_slot;
	
} NautilusEmblemPanelClass;

GtkType              nautilus_emblem_panel_get_type     (void);
NautilusEmblemPanel *nautilus_emblem_panel_new          (void);

#endif /* NAUTILUS_EMBLEM_PANEL_H */


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