[Goodies-commits] r3742 - xfce4-notes-plugin/trunk/panel-plugin

Mike Massonnet mmassonnet at xfce.org
Sun Dec 23 23:10:53 CET 2007


Author: mmassonnet
Date: 2007-12-23 22:10:53 +0000 (Sun, 23 Dec 2007)
New Revision: 3742

Modified:
   xfce4-notes-plugin/trunk/panel-plugin/notes.c
   xfce4-notes-plugin/trunk/panel-plugin/notes.h
   xfce4-notes-plugin/trunk/panel-plugin/panel-plugin.c
Log:
	* panel-plugin/notes.h: Add delete boolean on NotesNote.  Declare
	  notes_window_get_note_by_name outside.  Add interactive delete
	  function for a window.
	* panel-plugin/notes.c(notes_window_delete),
	  panel-plugin/notes.c(notes_window_destroy),
	  panel-plugin/notes.c(notes_window_menu_new): Separate interactive
	  delete out from _destroy.
	* panel-plugin/notes.c(notes_window_get_note_by_name): Return the
	  pointer of a NotesNote by comparing its name.
	* panel-plugin/notes.c(notes_window_fs_event),
	  panel-plugin/notes.c(notes_note_new): Set a boolean "delete" to
	  TRUE or FALSE.  It keeps the CPU cycles lower when it comes to
	  refresh the NotesNote.  The fs event on NotesPlugin takes care of
	  the refresh.
	* panel-plugin/notes.c(notes_note_destroy): Read the id from the
	  GSList or it breaks the delete process of the NotesNote if the Tab
	  doesn't have the focus.
	* panel-plugin/panel-plugin.c(notes_plugin_get_window_by_name):
	  Returns the NotesWindow po


Modified: xfce4-notes-plugin/trunk/panel-plugin/notes.c
===================================================================
--- xfce4-notes-plugin/trunk/panel-plugin/notes.c	2007-12-23 22:10:17 UTC (rev 3741)
+++ xfce4-notes-plugin/trunk/panel-plugin/notes.c	2007-12-23 22:10:53 UTC (rev 3742)
@@ -411,10 +411,8 @@
 }
 
 void
-notes_window_destroy (NotesWindow *notes_window)
+notes_window_delete (NotesWindow *notes_window)
 {
-  DBG ("Destroy window `%s' (%p)", notes_window->name, notes_window);
-
   GtkWidget *dialog =
     gtk_message_dialog_new (GTK_WINDOW (notes_window->window),
                             GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT,
@@ -426,10 +424,18 @@
   if (G_UNLIKELY (result != GTK_RESPONSE_YES))
     return;
 
+  notes_window_destroy (notes_window);
+}
+
+void
+notes_window_destroy (NotesWindow *notes_window)
+{
+  DBG ("Destroy window `%s' (%p)", notes_window->name, notes_window);
+
   NotesPlugin *notes_plugin = notes_window->notes_plugin;
 
   /* Drop configuration data */
-  XfceRc *rc = xfce_rc_simple_open (notes_window->notes_plugin->config_file, FALSE);
+  XfceRc *rc = xfce_rc_simple_open (notes_plugin->config_file, FALSE);
   g_return_if_fail (G_LIKELY (rc != NULL));
   xfce_rc_delete_group (rc, notes_window->name, FALSE);
   xfce_rc_close (rc);
@@ -438,22 +444,24 @@
   g_slist_foreach (notes_window->notes, (GFunc)notes_note_destroy, NULL);
   g_slist_free (notes_window->notes);
 
+  /* Remove GSList entry */
+  notes_plugin->windows = g_slist_remove (notes_plugin->windows, notes_window);
+
+#ifdef HAVE_THUNAR_VFS
+  /* Monitor handle */
+  thunar_vfs_monitor_remove (notes_plugin->monitor,
+                             notes_window->monitor_handle);
+  thunar_vfs_path_unref (notes_window->thunar_vfs_path);
+#endif
+
   /* Remove directory */
   gchar *window_path = g_build_path (G_DIR_SEPARATOR_S,
-                                     notes_window->notes_plugin->notes_path,
+                                     notes_plugin->notes_path,
                                      notes_window->name,
                                      NULL);
   g_rmdir (window_path);
   g_free (window_path);
 
-  /* Remove GSList entry */
-  notes_plugin->windows = g_slist_remove (notes_plugin->windows, notes_window);
-
-  /* Monitor handle */
-  thunar_vfs_monitor_remove (notes_window->notes_plugin->monitor,
-                             notes_window->monitor_handle);
-  thunar_vfs_path_unref (notes_window->thunar_vfs_path);
-
   /* Free data */
   g_free (notes_window->name);
   gtk_widget_destroy (notes_window->window);
@@ -611,6 +619,22 @@
 }
 
 #ifdef HAVE_THUNAR_VFS
+NotesNote *
+notes_window_get_note_by_name (NotesWindow *notes_window,
+                               const gchar *name)
+{
+  NotesNote            *notes_note = NULL;
+  gint                  i = 0;
+
+  while (NULL != (notes_note = (NotesNote *)g_slist_nth_data (notes_window->notes, i++)))
+    {
+      if (0 == g_ascii_strcasecmp (name, notes_note->name))
+        return notes_note;
+    }
+
+  return NULL;
+}
+
 /**
  * Fs event
  */
@@ -622,10 +646,44 @@
                        ThunarVfsPath *event_path,
                        NotesWindow *notes_window)
 {
+  /* XXX VIM plays fool with delete/create so this is not the right place to
+   * XXX create new notes as they are created in the user data directory. */
+  /* notes changed > OK */
+  /* notes created > is it a regular file or a .swp/… file? */
+  /* notes deleted > VIM deletes the file during the saving */
   TRACE ("event: `%d'\nhandle_path: `%s'\nevent_path: `%s'",
          event,
          thunar_vfs_path_get_name (handle_path),
          thunar_vfs_path_get_name (event_path));
+
+  const gchar          *name = thunar_vfs_path_get_name (event_path);
+  NotesNote            *notes_note = notes_window_get_note_by_name (notes_window, name);
+  GtkTextBuffer        *buffer = NULL;
+
+  TRACE ("NotesNote (0x%p) `%s'", notes_note, name);
+
+  if (G_LIKELY (NULL != notes_note))
+    {
+      switch (event)
+        {
+        case THUNAR_VFS_MONITOR_EVENT_CHANGED:
+          /* Reload the NotesNote */
+          buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (notes_note->text_view));
+          notes_note_load_data (notes_note, buffer);
+          break;
+
+        case THUNAR_VFS_MONITOR_EVENT_CREATED:
+          notes_note->delete = FALSE;
+          break;
+
+        case THUNAR_VFS_MONITOR_EVENT_DELETED:
+          notes_note->delete = TRUE;
+          break;
+
+        default:
+          break;
+        }
+    }
 }
 #endif
 
@@ -721,7 +779,7 @@
                             notes_window->notes_plugin);
   g_signal_connect_swapped (mi_destroy_window,
                             "activate",
-                            G_CALLBACK (notes_window_destroy),
+                            G_CALLBACK (notes_window_delete),
                             notes_window);
   g_signal_connect_swapped (mi_rename_window,
                             "activate",
@@ -1436,6 +1494,9 @@
   notes_note = g_slice_new0 (NotesNote);
   notes_note->notes_window = notes_window;
   notes_note->name = g_strdup (note_name);
+#ifdef HAVE_THUNAR_VFS
+  notes_note->delete = FALSE;
+#endif
 
   /* Label */
   GtkWidget *eb_border = gtk_event_box_new ();
@@ -1507,7 +1568,7 @@
     g_source_remove (notes_note->timeout);
 
   /* Remove notebook page */
-  id = gtk_notebook_get_current_page (GTK_NOTEBOOK (notes_window->notebook));
+  id = g_slist_index (notes_window->notes, notes_note);
   gtk_notebook_remove_page (GTK_NOTEBOOK (notes_window->notebook), id);
   gtk_notebook_set_show_tabs (GTK_NOTEBOOK (notes_window->notebook),
                               ((g_slist_length (notes_window->notes) - 1) > 1));

Modified: xfce4-notes-plugin/trunk/panel-plugin/notes.h
===================================================================
--- xfce4-notes-plugin/trunk/panel-plugin/notes.h	2007-12-23 22:10:17 UTC (rev 3741)
+++ xfce4-notes-plugin/trunk/panel-plugin/notes.h	2007-12-23 22:10:53 UTC (rev 3742)
@@ -111,6 +111,10 @@
   GtkWidget            *title;
   GtkWidget            *scrolled_window;
   GtkWidget            *text_view;
+
+#ifdef HAVE_THUNAR_VFS
+  gboolean				delete;
+#endif
 };
 
 typedef struct _NotesOptions    NotesOptions;
@@ -130,6 +134,12 @@
 
 void                    notes_window_save_data          (NotesWindow *notes_window);
 
+#ifdef HAVE_THUNAR_VFS
+NotesNote *      		notes_window_get_note_by_name   (NotesWindow *notes_window,
+                                                         const gchar *name);
+#endif
+void                    notes_window_delete             (NotesWindow *notes_window);
+
 void                    notes_window_destroy            (NotesWindow *notes_window);
 
 void                    notes_window_show               (NotesWindow *notes_window);

Modified: xfce4-notes-plugin/trunk/panel-plugin/panel-plugin.c
===================================================================
--- xfce4-notes-plugin/trunk/panel-plugin/panel-plugin.c	2007-12-23 22:10:17 UTC (rev 3741)
+++ xfce4-notes-plugin/trunk/panel-plugin/panel-plugin.c	2007-12-23 22:10:53 UTC (rev 3742)
@@ -48,6 +48,8 @@
 static void             notes_plugin_destroy_timeout    (NotesPlugin *notes_plugin);
 
 #ifdef HAVE_THUNAR_VFS
+static NotesWindow     *notes_plugin_get_window_by_name (NotesPlugin *notes_plugin,
+                                                         const gchar *name);
 static void             notes_plugin_fs_event           (ThunarVfsMonitor *monitor,
                                                          ThunarVfsMonitorHandle *handle,
                                                          ThunarVfsMonitorEvent event,
@@ -224,8 +226,11 @@
 notes_plugin_free (NotesPlugin *notes_plugin)
 {
   notes_plugin_save_data_all (notes_plugin);
+#ifdef HAVE_THUNAR_VFS
+  /* FIXME thunar_vfs_path_unref ... */
   g_object_unref (notes_plugin->monitor);
   thunar_vfs_shutdown ();
+#endif
   gtk_main_quit ();
 }
 
@@ -236,6 +241,22 @@
 }
 
 #ifdef HAVE_THUNAR_VFS
+static NotesWindow *
+notes_plugin_get_window_by_name (NotesPlugin *notes_plugin,
+                                 const gchar *name)
+{
+  NotesWindow          *notes_window = NULL;
+  gint                  i = 0;
+
+  while (NULL != (notes_window = (NotesWindow *)g_slist_nth_data (notes_plugin->windows, i++)))
+    {
+      if (0 == g_ascii_strcasecmp (name, notes_window->name))
+        return notes_window;
+    }
+
+  return NULL;
+}
+
 static void
 notes_plugin_fs_event (ThunarVfsMonitor *monitor,
                        ThunarVfsMonitorHandle *handle,
@@ -248,6 +269,51 @@
          event,
          thunar_vfs_path_get_name (handle_path),
          thunar_vfs_path_get_name (event_path));
+
+  const gchar  *window_name = thunar_vfs_path_get_name (event_path);
+  NotesWindow  *notes_window = notes_plugin_get_window_by_name (notes_plugin, window_name);
+  const gchar  *note_name = NULL;
+  NotesNote    *notes_note = NULL;
+
+  TRACE ("NotesWindow (0x%p) `%s'", notes_window, window_name);
+
+  switch (event)
+    {
+    case THUNAR_VFS_MONITOR_EVENT_CHANGED:
+      /* Add/Remove the missing NotesNote */
+      if (G_LIKELY (NULL != notes_window))
+        {
+          gint i = 0;
+          while (NULL != (notes_note = (NotesNote *)g_slist_nth_data (notes_window->notes, i++)))
+            {
+              if (G_UNLIKELY (notes_note->delete))
+                notes_note_destroy (notes_note);
+            }
+
+          while (NULL != (note_name = notes_note_read_name (notes_window)))
+            {
+              notes_note = notes_window_get_note_by_name (notes_window, note_name);
+              if (G_UNLIKELY (NULL == notes_note))
+                notes_note_new (notes_window, note_name);
+            }
+        }
+      break;
+
+    case THUNAR_VFS_MONITOR_EVENT_CREATED:
+      /* Add a NotesWindow */
+      if (G_UNLIKELY (NULL == notes_window))
+        notes_window_new_with_label (notes_plugin, window_name);
+      break;
+
+    case THUNAR_VFS_MONITOR_EVENT_DELETED:
+      /* Remove a NotesWindow */
+      if (G_UNLIKELY (NULL != notes_window))
+        notes_window_destroy (notes_window);
+      break;
+
+    default:
+      break;
+    }
 }
 #endif
 




More information about the Goodies-commits mailing list