summaryrefslogtreecommitdiff
path: root/components
diff options
context:
space:
mode:
authorAndy Hertzfeld <andy@src.gnome.org>2001-04-01 23:44:46 +0000
committerAndy Hertzfeld <andy@src.gnome.org>2001-04-01 23:44:46 +0000
commit0f7c34dfb0a7a30cfce0820be2a6c80a9d0210f8 (patch)
tree309a25010f50ecd850590f20ad62e487b418d17c /components
parent9a61eb330ae70c247171629a7b402ce3ab4d3c00 (diff)
downloadnautilus-0f7c34dfb0a7a30cfce0820be2a6c80a9d0210f8.tar.gz
added a way for sidebar views to specify small images that are displayed
added a way for sidebar views to specify small images that are displayed in their tab for notification purposes. Used that to make the notes component indicate if a note is present or not. * components/notes/nautilus-notes.c: (get_bonobo_properties), (set_bonobo_properties), (load_note_text_from_metadata), (done_with_file), (notes_load_metainfo), (notify_listeners_if_changed), (notes_save_metainfo), (do_destroy), (notes_get_indicator_image), (make_notes_view): added a property bag to the notes component to provide a tab_image property, and made it notify the listeners when the note text changes. * icons/Makefile.am: * icons/note-indicator.png: new notes indicator image from Arlo. * src/nautilus-sidebar-tabs.c: (tab_item_destroy), (pixbuf_composite), (draw_one_tab_plain), (draw_one_tab_themed), (get_tab_width), (draw_or_layout_all_tabs), (nautilus_sidebar_tabs_expose), (nautilus_sidebar_tabs_update_tab_item), (get_tab_item_from_view), (nautilus_sidebar_tabs_update_all_indicators), (nautilus_sidebar_tabs_update_indicator), (tab_indicator_changed_callback), (nautilus_sidebar_tabs_connect_view): * src/nautilus-sidebar-tabs.h: made the sidebar tabs hook up to the nautilus_view's tab_image property and use it to display a notification image in the tab if necessary. * src/nautilus-sidebar.c: (view_loaded_callback), (nautilus_sidebar_add_panel): connect the sidebar tabs to a newly added view, once the view is loaded. * src/nautilus-view-frame.c: (nautilus_view_frame_get_control): * src/nautilus-view-frame.h: added nautilus_view_frame_get_control so view properties can be accessed by the sidebar.
Diffstat (limited to 'components')
-rw-r--r--components/notes/nautilus-notes.c123
1 files changed, 105 insertions, 18 deletions
diff --git a/components/notes/nautilus-notes.c b/components/notes/nautilus-notes.c
index b531e7ae0..da92d7852 100644
--- a/components/notes/nautilus-notes.c
+++ b/components/notes/nautilus-notes.c
@@ -54,22 +54,68 @@
#define NOTES_DEFAULT_BACKGROUND_COLOR "rgb:FFFF/FFFF/BBBB"
-
typedef struct {
- NautilusView *view;
- GtkWidget *note_text_field;
- char *uri;
- NautilusFile *file;
- guint save_timeout_id;
- char* previous_saved_text;
+ NautilusView *view;
+ BonoboPropertyBag *property_bag;
+ GtkWidget *note_text_field;
+ char *uri;
+ NautilusFile *file;
+ guint save_timeout_id;
+ char* previous_saved_text;
} Notes;
-static void notes_save_metainfo (Notes *notes);
+static void notes_save_metainfo (Notes *notes);
+static char* notes_get_indicator_image (const char *notes_text);
+static void notify_listeners_if_changed (Notes *notes, char *new_notes);
static int notes_object_count = 0;
#define SAVE_TIMEOUT (3 * 1000)
+/* property bag getting and setting routines */
+enum {
+ TAB_IMAGE,
+} MyArgs;
+
+static void
+get_bonobo_properties (BonoboPropertyBag *bag,
+ BonoboArg *arg,
+ guint arg_id,
+ CORBA_Environment *ev,
+ gpointer user_data)
+{
+ char *indicator_image;
+ Notes *notes;
+ notes = (Notes*) user_data;
+
+ switch (arg_id) {
+
+ case TAB_IMAGE:
+ {
+ /* if there is a note, return the name of the indicator image,
+ otherwise, return NULL */
+ indicator_image = notes_get_indicator_image (notes->previous_saved_text);
+ BONOBO_ARG_SET_STRING (arg, indicator_image);
+ g_free (indicator_image);
+ break;
+ }
+
+ default:
+ g_warning ("Unhandled arg %d", arg_id);
+ break;
+ }
+}
+
+static void
+set_bonobo_properties (BonoboPropertyBag *bag,
+ const BonoboArg *arg,
+ guint arg_id,
+ CORBA_Environment *ev,
+ gpointer user_data)
+{
+ g_warning ("Cant set note property %d", arg_id);
+}
+
static gboolean
schedule_save_callback (gpointer data)
{
@@ -119,6 +165,9 @@ load_note_text_from_metadata (NautilusFile *file,
* metadata has actually changed.
*/
if (nautilus_strcmp (saved_text, notes->previous_saved_text) != 0) {
+
+ notify_listeners_if_changed (notes, saved_text);
+
g_free (notes->previous_saved_text);
notes->previous_saved_text = saved_text;
cancel_pending_save (notes);
@@ -146,8 +195,6 @@ static void
done_with_file (Notes *notes)
{
cancel_pending_save (notes);
- g_free (notes->previous_saved_text);
- notes->previous_saved_text = NULL;
if (notes->file != NULL) {
nautilus_file_monitor_remove (notes->file, notes);
@@ -163,13 +210,13 @@ notes_load_metainfo (Notes *notes)
{
GList *attributes;
- gtk_editable_delete_text (GTK_EDITABLE (notes->note_text_field), 0, -1);
-
done_with_file (notes);
notes->file = nautilus_file_get (notes->uri);
+ gtk_editable_delete_text (GTK_EDITABLE (notes->note_text_field), 0, -1);
+
if (notes->file == NULL) {
- return;
+ return;
}
attributes = g_list_append (NULL, NAUTILUS_FILE_ATTRIBUTE_METADATA);
@@ -187,8 +234,28 @@ notes_load_metainfo (Notes *notes)
notes);
}
-/* save the metainfo corresponding to the current uri, if any, into the text field */
+/* utility to notify event listeners if the notes data actually changed */
+static void
+notify_listeners_if_changed (Notes *notes, char *new_notes)
+{
+ char *tab_image;
+ BonoboArg *tab_image_arg;
+
+ if (nautilus_strcmp (notes->previous_saved_text, new_notes) != 0) {
+ /* notify listeners that the notes text has changed */
+ tab_image = notes_get_indicator_image (new_notes);
+
+ tab_image_arg = bonobo_arg_new (BONOBO_ARG_STRING);
+ BONOBO_ARG_SET_STRING (tab_image_arg, tab_image);
+
+ bonobo_property_bag_notify_listeners (notes->property_bag, "tab_image", tab_image_arg, NULL);
+
+ bonobo_arg_release (tab_image_arg);
+ g_free (tab_image);
+ }
+}
+/* save the metainfo corresponding to the current uri, if any, into the text field */
static void
notes_save_metainfo (Notes *notes)
{
@@ -208,12 +275,15 @@ notes_save_metainfo (Notes *notes)
notes_text = gtk_editable_get_chars (GTK_EDITABLE (notes->note_text_field), 0 , -1);
nautilus_file_set_metadata (notes->file, NAUTILUS_METADATA_KEY_ANNOTATION, NULL, notes_text);
- g_free (notes->previous_saved_text);
- notes->previous_saved_text = notes_text;
-
+
gtk_signal_handler_unblock_by_func (GTK_OBJECT (notes->file),
load_note_text_from_metadata,
- notes);
+ notes);
+
+ notify_listeners_if_changed (notes, notes_text);
+
+ g_free (notes->previous_saved_text);
+ notes->previous_saved_text = notes_text;
}
static void
@@ -268,6 +338,7 @@ do_destroy (GtkObject *obj, Notes *notes)
done_with_file (notes);
g_free (notes->uri);
+ g_free (notes->previous_saved_text);
g_free (notes);
notes_object_count--;
@@ -276,6 +347,16 @@ do_destroy (GtkObject *obj, Notes *notes)
}
}
+static char*
+notes_get_indicator_image (const char *notes_text)
+{
+ if (notes_text != NULL && strlen (notes_text) > 0) {
+ return g_strdup ("note-indicator.png");
+ }
+
+ return NULL;
+}
+
static BonoboObject *
make_notes_view (BonoboGenericFactory *Factory, const char *goad_id, gpointer closure)
{
@@ -316,6 +397,12 @@ make_notes_view (BonoboGenericFactory *Factory, const char *goad_id, gpointer cl
notes->view = nautilus_view_new (vbox);
gtk_signal_connect (GTK_OBJECT (notes->view), "destroy", do_destroy, notes);
+ /* allocate a property bag to reflect the TAB_IMAGE property */
+ notes->property_bag = bonobo_property_bag_new (get_bonobo_properties, set_bonobo_properties, notes);
+ bonobo_control_set_properties (nautilus_view_get_bonobo_control (notes->view), notes->property_bag);
+
+ bonobo_property_bag_add (notes->property_bag, "tab_image", TAB_IMAGE, BONOBO_ARG_STRING, NULL,
+ "image indicating that a note is present", 0);
notes_object_count++;
/* handle events */