Commit e4d81832 authored by Darin Adler's avatar Darin Adler

Improved the background handling code so more is shared.

	There's even more we could do in this direction.

	* components/music/nautilus-music-view.c:
	(nautilus_music_view_initialize): Got rid of redundant background
	color initialization.
	(nautilus_music_view_realize): Got rid of background color
	initialization.
	(nautilus_music_view_update_from_uri): Changed background color
	handling to use new nautilus_directory_background calls.
	(nautilus_music_view_background_changed): Not needed any more.

	* components/notes/ntl-notes.c:
	Did some cleanup and reformatting.

	* libnautilus/Makefile.am:
	* libnautilus/nautilus-directory-background.c:
	* libnautilus/nautilus-directory-background.h:
	Created a new file with functions that manage the background for
	a window connected with a particular directory. Later we might
	generalize it further to work for windows that are connected to
	any URI, not just a directory.

	* libnautilus/nautilus-directory.c:
	* libnautilus/nautilus-directory.h:
	Added a new "metdata_changed" signal so that the background can
	be updated if the underlying data changes.
	(nautilus_directory_initialize_class): Create the new signal.
	(nautilus_directory_ref), (nautilus_directory_unref): Made these
	functions quietly do nothing for NULL. This simplifies life for
	callers.
	(nautilus_directory_set_metadata): Emit the "metadata_changed"
	signal.

	* libnautilus/nautilus-file.c:
	(nautilus_file_ref), (nautilus_file_unref): Made these
	functions quietly do nothing for NULL. This simplifies life for
	callers.

	* libnautilus/nautilus-metadata.h:
	Renamed all the constants to be consistent. Got rid of separate
	constants for the icon view and list view backgrounds. Changed
	some of the underlying XML tags as well.

	* libnautilus/nautilus-icon-factory.c:
	(nautilus_icon_factory_get_icon_for_file):
	* src/nautilus-index-title.c: (nautilus_index_title_update_info):
	* src/ntl-index-panel: (nautilus_index_panel_update_info),
	(receive_dropped_uri_list),
	(nautilus_index_panel_background_changed):
	* src/ntl-uri-map.c: (set_initial_content_iid),
	(add_components_from_metadata):
	* src/ntl-window-msgs.c: (view_menu_switch_views_cb):
	* src/file-manager/fm-icon-view.c: (add_icon_if_already_positioned),
	(fm_icon_view_begin_loading), (fm_icon_view_set_zoom_level),
	(fm_icon_view_icon_changed_callback):
	* src/file-manager/fm-list-view.c: (fm_list_view_begin_loading),
	(fm_list_view_set_zoom_level), (fm_list_view_sort_items):
	Updated uses of metadata constants to use the new names.

	* src/ntl-index-panel: (nautilus_index_panel_destroy),
	(nautilus_index_panel_update_info):
	* src/ntl-uri-map.c: (add_components_from_metadata):
	* src/file-manager/fm-directory-view.c:
	(fm_directory_view_destroy), (fm_directory_view_load_uri):
	Used new nautilus_directory_unref to simplify code.

	* src/ntl-uri-map.c: (set_initial_content_iid):
	* src/ntl-window-msgs.c: (view_menu_switch_views_cb):
	Added missing nautilus_directory_unref (storage leak).

	* src/file-manager/fm-icon-view.c: (create_icon_container),
	(fm_icon_view_background_changed_callback): Removed "changed"
	signal handler on NautilusBackground since that's now handled
	by the new nautilus_directory_background calls instead.
	(fm_icon_view_begin_loading): Used nautilus_directory_background
	to replace background customization code.

	* src/file-manager/fm-icon-view.c: (fm_icon_view_get_zoom_level):
	Fixed a bug where it would try to use view as an FMIconView after
	the FM_IS_ICON_VIEW check failed.

	* src/file-manager/fm-list-view.c: (create_list),
	(fm_list_view_background_changed_callback): Removed "changed"
	signal handler on NautilusBackground since that's now handled
	by the new nautilus_directory_background calls instead.
	(fm_list_view_begin_loading): Used nautilus_directory_background
	to replace background customization code.
parent c7c50ad5
2000-04-05 Darin Adler <darin@eazel.com>
Improved the background handling code so more is shared.
There's even more we could do in this direction.
* components/music/nautilus-music-view.c:
(nautilus_music_view_initialize): Got rid of redundant background
color initialization.
(nautilus_music_view_realize): Got rid of background color
initialization.
(nautilus_music_view_update_from_uri): Changed background color
handling to use new nautilus_directory_background calls.
(nautilus_music_view_background_changed): Not needed any more.
* components/notes/ntl-notes.c:
Did some cleanup and reformatting.
* libnautilus/Makefile.am:
* libnautilus/nautilus-directory-background.c:
* libnautilus/nautilus-directory-background.h:
Created a new file with functions that manage the background for
a window connected with a particular directory. Later we might
generalize it further to work for windows that are connected to
any URI, not just a directory.
* libnautilus/nautilus-directory.c:
* libnautilus/nautilus-directory.h:
Added a new "metdata_changed" signal so that the background can
be updated if the underlying data changes.
(nautilus_directory_initialize_class): Create the new signal.
(nautilus_directory_ref), (nautilus_directory_unref): Made these
functions quietly do nothing for NULL. This simplifies life for
callers.
(nautilus_directory_set_metadata): Emit the "metadata_changed"
signal.
* libnautilus/nautilus-file.c:
(nautilus_file_ref), (nautilus_file_unref): Made these
functions quietly do nothing for NULL. This simplifies life for
callers.
* libnautilus/nautilus-metadata.h:
Renamed all the constants to be consistent. Got rid of separate
constants for the icon view and list view backgrounds. Changed
some of the underlying XML tags as well.
* libnautilus/nautilus-icon-factory.c:
(nautilus_icon_factory_get_icon_for_file):
* src/nautilus-index-title.c: (nautilus_index_title_update_info):
* src/ntl-index-panel: (nautilus_index_panel_update_info),
(receive_dropped_uri_list),
(nautilus_index_panel_background_changed):
* src/ntl-uri-map.c: (set_initial_content_iid),
(add_components_from_metadata):
* src/ntl-window-msgs.c: (view_menu_switch_views_cb):
* src/file-manager/fm-icon-view.c: (add_icon_if_already_positioned),
(fm_icon_view_begin_loading), (fm_icon_view_set_zoom_level),
(fm_icon_view_icon_changed_callback):
* src/file-manager/fm-list-view.c: (fm_list_view_begin_loading),
(fm_list_view_set_zoom_level), (fm_list_view_sort_items):
Updated uses of metadata constants to use the new names.
* src/ntl-index-panel: (nautilus_index_panel_destroy),
(nautilus_index_panel_update_info):
* src/ntl-uri-map.c: (add_components_from_metadata):
* src/file-manager/fm-directory-view.c:
(fm_directory_view_destroy), (fm_directory_view_load_uri):
Used new nautilus_directory_unref to simplify code.
* src/ntl-uri-map.c: (set_initial_content_iid):
* src/ntl-window-msgs.c: (view_menu_switch_views_cb):
Added missing nautilus_directory_unref (storage leak).
* src/file-manager/fm-icon-view.c: (create_icon_container),
(fm_icon_view_background_changed_callback): Removed "changed"
signal handler on NautilusBackground since that's now handled
by the new nautilus_directory_background calls instead.
(fm_icon_view_begin_loading): Used nautilus_directory_background
to replace background customization code.
* src/file-manager/fm-icon-view.c: (fm_icon_view_get_zoom_level):
Fixed a bug where it would try to use view as an FMIconView after
the FM_IS_ICON_VIEW check failed.
* src/file-manager/fm-list-view.c: (create_list),
(fm_list_view_background_changed_callback): Removed "changed"
signal handler on NautilusBackground since that's now handled
by the new nautilus_directory_background calls instead.
(fm_list_view_begin_loading): Used nautilus_directory_background
to replace background customization code.
2000-04-05 John Sullivan <sullivan@eazel.com>
Fixed bug in Ramiro's recent checkin that broke booting
......@@ -120,7 +211,6 @@
for this preference. If so, then the code that fetches the preference
would have to deal with either a NULL return value (or "").
2000-04-05 Andy Hertzfeld <andy@eazel.com>
* components/services/startup/nautilus-service-startup-view.c:
......
......@@ -33,6 +33,7 @@
#include <libnautilus/libnautilus.h>
#include <libnautilus/nautilus-background.h>
#include <libnautilus/nautilus-directory-background.h>
#include <libnautilus/nautilus-file.h>
#include <libnautilus/nautilus-file-utilities.h>
#include <libnautilus/nautilus-glib-extensions.h>
......@@ -47,14 +48,13 @@
#include <limits.h>
struct _NautilusMusicViewDetails {
char *current_uri;
char *uri;
NautilusContentViewFrame *view_frame;
GtkVBox *album_container;
GtkWidget *album_title;
GtkWidget *song_list;
GtkWidget *album_image;
int background_connection;
};
/* structure for holding song info */
......@@ -69,8 +69,6 @@ typedef struct {
char *path_name;
} SongInfo;
#define MUSIC_VIEW_DEFAULT_BACKGROUND_COLOR "rgb:BBBB/BBBB/FFFF"
enum {
TARGET_URI_LIST,
TARGET_COLOR,
......@@ -83,7 +81,6 @@ static GtkTargetEntry music_dnd_target_table[] = {
{ "special/x-gnome-icon-list", 0, TARGET_GNOME_URI_LIST }
};
static void nautilus_music_view_background_changed (NautilusMusicView *music_view);
static void nautilus_music_view_drag_data_received (GtkWidget *widget,
GdkDragContext *context,
int x,
......@@ -125,7 +122,6 @@ nautilus_music_view_initialize_class (NautilusMusicViewClass *klass)
static void
nautilus_music_view_initialize (NautilusMusicView *music_view)
{
NautilusBackground *background;
char *file_name;
GtkWidget *song_box, *scrollwindow;
char *titles[] = {"Track", "Title", "Artist", "Time"};
......@@ -139,13 +135,6 @@ nautilus_music_view_initialize (NautilusMusicView *music_view)
GTK_SIGNAL_FUNC (music_view_notify_location_change_callback),
music_view);
music_view->details->current_uri = NULL;
music_view->details->background_connection = 0;
/* set up the default background color */
background = nautilus_get_widget_background (GTK_WIDGET (music_view));
nautilus_background_set_color (background, MUSIC_VIEW_DEFAULT_BACKGROUND_COLOR);
/* allocate a vbox to contain all of the views */
music_view->details->album_container = GTK_VBOX (gtk_vbox_new (FALSE, 0));
......@@ -208,7 +197,7 @@ nautilus_music_view_destroy (GtkObject *object)
bonobo_object_unref (BONOBO_OBJECT (music_view->details->view_frame));
g_free (music_view->details->current_uri);
g_free (music_view->details->uri);
g_free (music_view->details);
NAUTILUS_CALL_PARENT_CLASS (GTK_OBJECT_CLASS, destroy, (object));
......@@ -258,19 +247,14 @@ setup_title_font(NautilusMusicView *music_view)
/* set up fonts, colors, etc after we're realized */
void
nautilus_music_view_realize(GtkWidget *widget)
nautilus_music_view_realize (GtkWidget *widget)
{
NautilusMusicView *music_view;
NautilusBackground *background;
NAUTILUS_CALL_PARENT_CLASS (GTK_WIDGET_CLASS, realize, (widget));
music_view = NAUTILUS_MUSIC_VIEW (widget);
setup_title_font (music_view);
background = nautilus_get_widget_background (widget);
nautilus_background_set_color (background, MUSIC_VIEW_DEFAULT_BACKGROUND_COLOR);
}
/* here are some utility routines for reading ID3 tags from mp3 files */
......@@ -446,9 +430,6 @@ nautilus_music_view_update_from_uri (NautilusMusicView *music_view, const char *
DIR *dir;
struct dirent *entry;
char* clist_entry[4];
char *background_color;
NautilusBackground *background;
NautilusDirectory *directory;
GList *p;
GList *song_list = NULL ;
SongInfo *info;
......@@ -533,34 +514,19 @@ nautilus_music_view_update_from_uri (NautilusMusicView *music_view, const char *
/* install the album cover */
if (image_path_name) {
gnome_pixmap_load_file(GNOME_PIXMAP(music_view->details->album_image), image_path_name);
/* show the pixmap widget */
gtk_widget_show(music_view->details->album_image);
g_free(image_path_name);
if (image_path_name != NULL) {
gnome_pixmap_load_file (GNOME_PIXMAP (music_view->details->album_image),
image_path_name);
gtk_widget_show (music_view->details->album_image);
g_free (image_path_name);
} else {
gtk_widget_hide(music_view->details->album_image);
gtk_widget_hide (music_view->details->album_image);
}
/* set up background color */
background = nautilus_get_widget_background (GTK_WIDGET (music_view));
if (music_view->details->background_connection == 0) {
music_view->details->background_connection =
gtk_signal_connect_object (GTK_OBJECT (background),
"changed",
nautilus_music_view_background_changed,
GTK_OBJECT (music_view));
}
/* Set up the background color from the metadata. */
directory = nautilus_directory_get(music_view->details->current_uri);
background_color = nautilus_directory_get_metadata (directory,
ICON_VIEW_BACKGROUND_COLOR_METADATA_KEY,
MUSIC_VIEW_DEFAULT_BACKGROUND_COLOR);
nautilus_background_set_color (background, background_color);
g_free (background_color);
gtk_object_unref(GTK_OBJECT(directory));
nautilus_connect_background_to_directory_metadata_by_uri (GTK_WIDGET (music_view),
music_view->details->uri);
/* determine the album title/artist line */
......@@ -598,10 +564,9 @@ nautilus_music_view_update_from_uri (NautilusMusicView *music_view, const char *
void
nautilus_music_view_load_uri (NautilusMusicView *music_view, const char *uri)
{
g_free(music_view->details->current_uri);
music_view->details->current_uri = g_strdup (uri);
nautilus_music_view_update_from_uri(music_view, uri);
g_free (music_view->details->uri);
music_view->details->uri = g_strdup (uri);
nautilus_music_view_update_from_uri (music_view, uri);
}
static void
......@@ -630,24 +595,6 @@ music_view_notify_location_change_callback (NautilusContentViewFrame *view,
/* handle drag and drop */
static void
nautilus_music_view_background_changed (NautilusMusicView *music_view)
{
NautilusBackground *background;
NautilusDirectory *directory;
char *color_spec;
background = nautilus_get_widget_background (GTK_WIDGET (music_view));
color_spec = nautilus_background_get_color (background);
directory = nautilus_directory_get (music_view->details->current_uri);
nautilus_directory_set_metadata (directory,
ICON_VIEW_BACKGROUND_COLOR_METADATA_KEY,
MUSIC_VIEW_DEFAULT_BACKGROUND_COLOR,
color_spec);
g_free (color_spec);
nautilus_directory_unref (directory);
}
static void
nautilus_music_view_drag_data_received (GtkWidget *widget, GdkDragContext *context,
int x, int y,
......
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
/*
* Nautilus
......@@ -39,153 +39,146 @@
#define NOTES_DEFAULT_BACKGROUND_COLOR "rgb:FFFF/FFFF/BBBB"
typedef struct {
NautilusViewFrame *view;
GtkWidget *note_text_field;
gchar* current_uri;
} NotesView;
NautilusViewFrame *view;
GtkWidget *note_text_field;
char* uri;
} NotesView;
static int notes_object_count = 0;
static void notes_load_metainfo (NotesView *hview)
static void
notes_load_metainfo (NotesView *hview)
{
NautilusFile *file_object;
gtk_editable_delete_text(GTK_EDITABLE(hview->note_text_field), 0, -1);
file_object = nautilus_file_get(hview->current_uri);
if (file_object != NULL)
{
gint position;
gchar *notes_text;
notes_text = nautilus_file_get_metadata(file_object, NAUTILUS_ANNOTATION_METADATA_KEY, "");
if (notes_text)
{
if (strlen(notes_text))
gtk_editable_insert_text(GTK_EDITABLE(hview->note_text_field), notes_text, strlen(notes_text), &position);
g_free(notes_text);
}
/* set up the label */
nautilus_file_unref (file_object);
}
NautilusFile *file;
int position;
char *notes_text;
gtk_editable_delete_text (GTK_EDITABLE (hview->note_text_field), 0, -1);
file = nautilus_file_get (hview->uri);
if (file == NULL) {
return;
}
notes_text = nautilus_file_get_metadata (file, NAUTILUS_METADATA_KEY_ANNOTATION, "");
gtk_editable_insert_text (GTK_EDITABLE (hview->note_text_field),
notes_text,
strlen (notes_text),
&position);
g_free (notes_text);
nautilus_file_unref (file);
}
/* save the metainfo corresponding to the current uri, if any, into the text field */
static void notes_save_metainfo(NotesView *hview)
static void
notes_save_metainfo(NotesView *hview)
{
NautilusFile *file_object;
if (strlen(hview->current_uri) == 0)
return;
file_object = nautilus_file_get(hview->current_uri);
if (file_object != NULL)
{
gchar *notes_text = gtk_editable_get_chars(GTK_EDITABLE(hview->note_text_field), 0 , -1);
if (notes_text == NULL)
notes_text = strdup("");
nautilus_file_set_metadata(file_object, NAUTILUS_ANNOTATION_METADATA_KEY, NULL, notes_text);
g_free(notes_text);
nautilus_file_unref (file_object);
}
NautilusFile *file;
char *notes_text;
file = nautilus_file_get (hview->uri);
if (file == NULL) {
return;
}
notes_text = gtk_editable_get_chars (GTK_EDITABLE (hview->note_text_field), 0 , -1);
nautilus_file_set_metadata (file, NAUTILUS_METADATA_KEY_ANNOTATION, NULL, notes_text);
g_free (notes_text);
nautilus_file_unref (file);
}
static void
notes_notify_location_change (NautilusViewFrame *view,
Nautilus_NavigationInfo *loci,
NotesView *hview)
Nautilus_NavigationInfo *loci,
NotesView *hview)
{
if (strcmp(hview->current_uri, loci->requested_uri))
{
notes_save_metainfo(hview);
g_free(hview->current_uri);
hview->current_uri = strdup(loci->requested_uri);
notes_load_metainfo(hview);
}
if (strcmp (hview->uri, loci->requested_uri) != 0) {
notes_save_metainfo (hview);
g_free (hview->uri);
hview->uri = g_strdup (loci->requested_uri);
notes_load_metainfo (hview);
}
}
static void
do_destroy(GtkObject *obj, NotesView *hview)
{
notes_object_count--;
if(notes_object_count <= 0)
gtk_main_quit();
do_destroy (GtkObject *obj, NotesView *hview)
{
notes_object_count--;
if (notes_object_count <= 0) {
gtk_main_quit();
}
}
static BonoboObject *
make_obj(BonoboGenericFactory *Factory, const char *goad_id, gpointer closure)
make_notes_view (BonoboGenericFactory *Factory, const char *goad_id, gpointer closure)
{
GtkWidget *vbox;
NotesView *hview;
NautilusBackground *background;
g_return_val_if_fail (!strcmp (goad_id, "ntl_notes_view"), NULL);
hview = g_new0 (NotesView, 1);
/* initialize the current uri */
hview->current_uri = strdup("");
/* allocate a vbox to hold all of the UI elements */
vbox = gtk_vbox_new(FALSE, 0);
/* create the text container */
hview->note_text_field = gtk_text_new(NULL, NULL);
gtk_text_set_editable(GTK_TEXT(hview->note_text_field), TRUE);
gtk_box_pack_start (GTK_BOX(vbox), hview->note_text_field, TRUE, TRUE, 0);
background = nautilus_get_widget_background (GTK_WIDGET (hview->note_text_field));
nautilus_background_set_color (background, NOTES_DEFAULT_BACKGROUND_COLOR);
gtk_widget_show_all (vbox);
/* Create CORBA object. */
hview->view = NAUTILUS_VIEW_FRAME (nautilus_meta_view_frame_new (vbox));
gtk_signal_connect (GTK_OBJECT (hview->view), "destroy", do_destroy, hview);
notes_object_count++;
/* handle events */
gtk_signal_connect (GTK_OBJECT (hview->view), "notify_location_change", notes_notify_location_change, hview);
/* set description */
nautilus_meta_view_frame_set_label(NAUTILUS_META_VIEW_FRAME(hview->view),
_("Notes"));
return BONOBO_OBJECT (hview->view);
GtkWidget *vbox;
NotesView *hview;
NautilusBackground *background;
g_return_val_if_fail (strcmp (goad_id, "ntl_notes_view") == 0, NULL);
hview = g_new0 (NotesView, 1);
hview->uri = g_strdup ("");
/* allocate a vbox to hold all of the UI elements */
vbox = gtk_vbox_new (FALSE, 0);
/* create the text container */
hview->note_text_field = gtk_text_new (NULL, NULL);
gtk_text_set_editable (GTK_TEXT (hview->note_text_field), TRUE);
gtk_box_pack_start (GTK_BOX (vbox), hview->note_text_field, TRUE, TRUE, 0);
background = nautilus_get_widget_background (GTK_WIDGET (hview->note_text_field));
nautilus_background_set_color (background, NOTES_DEFAULT_BACKGROUND_COLOR);
gtk_widget_show_all (vbox);
/* Create CORBA object. */
hview->view = NAUTILUS_VIEW_FRAME (nautilus_meta_view_frame_new (vbox));
gtk_signal_connect (GTK_OBJECT (hview->view), "destroy", do_destroy, hview);
notes_object_count++;
/* handle events */
gtk_signal_connect (GTK_OBJECT (hview->view), "notify_location_change",
notes_notify_location_change, hview);
/* set description */
nautilus_meta_view_frame_set_label (NAUTILUS_META_VIEW_FRAME (hview->view),
_("Notes"));
return BONOBO_OBJECT (hview->view);
}
int main(int argc, char *argv[])
int
main(int argc, char *argv[])
{
BonoboGenericFactory *factory;
CORBA_ORB orb;
CORBA_Environment ev;
/* initialize CORBA and Bonobo */
CORBA_exception_init(&ev);
orb = gnome_CORBA_init_with_popt_table("ntl-notes", VERSION, &argc, argv, NULL, 0, NULL,
GNORBA_INIT_SERVER_FUNC, &ev);
bonobo_init(orb, CORBA_OBJECT_NIL, CORBA_OBJECT_NIL);
/* initialize gnome-vfs, etc */
g_thread_init (NULL);
gnome_vfs_init ();
factory = bonobo_generic_factory_new_multi("ntl_notes_view_factory", make_obj, NULL);
do {
bonobo_main();
} while (notes_object_count > 0);
return 0;
BonoboGenericFactory *factory;
CORBA_ORB orb;
CORBA_Environment ev;
/* initialize CORBA and Bonobo */
CORBA_exception_init (&ev);
orb = gnome_CORBA_init_with_popt_table ("ntl-notes", VERSION, &argc, argv,
NULL, 0, NULL,
GNORBA_INIT_SERVER_FUNC, &ev);
bonobo_init (orb, CORBA_OBJECT_NIL, CORBA_OBJECT_NIL);
/* initialize gnome-vfs, etc */
g_thread_init (NULL);
gnome_vfs_init ();
factory = bonobo_generic_factory_new_multi ("ntl_notes_view_factory",
make_notes_view, NULL);
do {
bonobo_main();
} while (notes_object_count > 0);
return EXIT_SUCCESS;
}
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
/*
* Nautilus
......@@ -39,153 +39,146 @@
#define NOTES_DEFAULT_BACKGROUND_COLOR "rgb:FFFF/FFFF/BBBB"
typedef struct {
NautilusViewFrame *view;
GtkWidget *note_text_field;
gchar* current_uri;
} NotesView;
NautilusViewFrame *view;
GtkWidget *note_text_field;
char* uri;
} NotesView;
static int notes_object_count = 0;
static void notes_load_metainfo (NotesView *hview)
static void
notes_load_metainfo (NotesView *hview)
{
NautilusFile *file_object;
gtk_editable_delete_text(GTK_EDITABLE(hview->note_text_field), 0, -1);
file_object = nautilus_file_get(hview->current_uri);
if (file_object != NULL)
{
gint position;
gchar *notes_text;
notes_text = nautilus_file_get_metadata(file_object, NAUTILUS_ANNOTATION_METADATA_KEY, "");
if (notes_text)
{
if (strlen(notes_text))
gtk_editable_insert_text(GTK_EDITABLE(hview->note_text_field), notes_text, strlen(notes_text), &position);
g_free(notes_text);
}
/* set up the label */
nautilus_file_unref (file_object);
}
NautilusFile *file;
int position;
char *notes_text;
gtk_editable_delete_text (GTK_EDITABLE (hview->note_text_field), 0, -1);
file = nautilus_file_get (hview->uri);
if (file == NULL) {
return;
}
notes_text = nautilus_file_get_metadata (file, NAUTILUS_METADATA_KEY_ANNOTATION, "");
gtk_editable_insert_text (GTK_EDITABLE (hview->note_text_field),
notes_text,
strlen (notes_text),
&position);
g_free (notes_text);
nautilus_file_unref (file);
}
/* save the metainfo corresponding to the current uri, if any, into the text field */
static void notes_save_metainfo(NotesView *hview)
static void
notes_save_metainfo(NotesView *hview)
{
NautilusFile *file_object;
if (strlen(hview->current_uri) == 0)
return;
file_object = nautilus_file_get(hview->current_uri);
if (file_object != NULL)
{
gchar *notes_text = gtk_editable_get_chars(GTK_EDITABLE(hview->note_text_field), 0 , -1);
if (notes_text == NULL)
notes_text = strdup("");
nautilus_file_set_metadata(file_object, NAUTILUS_ANNOTATION_METADATA_KEY, NULL, notes_text);
g_free(notes_text);
nautilus_file_unref (file_object);
}
NautilusFile *file;
char *notes_text;
file = nautilus_file_get (hview->uri);
if (file == NULL) {
return;
}
notes_text = gtk_editable_get_chars (GTK_EDITABLE (hview->note_text_field), 0 , -1);
nautilus_file_set_metadata (file, NAUTILUS_METADATA_KEY_ANNOTATION, NULL, notes_text);
g_free (notes_text);
nautilus_file_unref (file);
}
static void
notes_notify_location_change (NautilusViewFrame *view,
Nautilus_NavigationInfo *loci,
NotesView *hview)
Nautilus_NavigationInfo *loci,
NotesView *hview)
{
if (strcmp(hview->current_uri, loci->requested_uri))
{
notes_save_metainfo(hview);
g_free(hview->current_uri);
hview->current_uri = strdup(loci->requested_uri);
notes_load_metainfo(hview);
}
if (strcmp (hview->uri, loci->requested_uri) != 0) {
notes_save_metainfo (hview);
g_free (hview->uri);
hview->uri = g_strdup (loci->requested_uri);
notes_load_metainfo (hview);
}
}
static void
do_destroy(GtkObject *obj, NotesView *hview)
{
notes_object_count--;
if(notes_object_count <= 0)
gtk_main_quit();
do_destroy (GtkObject *obj, NotesView *hview)
{
notes_object_count--;
if (notes_object_count <= 0) {
gtk_main_quit();
}
}
static BonoboObject *
make_obj(BonoboGenericFactory *Factory, const char *goad_id, gpointer closure)
make_notes_view (BonoboGenericFactory *Factory, const char *goad_id, gpointer closure)
{
GtkWidget *vbox;
NotesView *hview;
NautilusBackground *background;
g_return_val_if_fail (!strcmp (goad_id, "ntl_notes_view"), NULL);
hview = g_new0 (NotesView, 1);
/* initialize the current uri */
hview->current_uri = strdup("");
/* allocate a vbox to hold all of the UI elements */
vbox = gtk_vbox_new(FALSE, 0);