[Goodies-commits] r3343 - xfce4-notes-plugin/trunk/panel-plugin
Mike Massonnet
mmassonnet at xfce.org
Thu Oct 11 00:00:40 CEST 2007
Author: mmassonnet
Date: 2007-10-10 22:00:40 +0000 (Wed, 10 Oct 2007)
New Revision: 3343
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:
* Save NotesNote data on buffer changes.
Modified: xfce4-notes-plugin/trunk/panel-plugin/notes.c
===================================================================
--- xfce4-notes-plugin/trunk/panel-plugin/notes.c 2007-10-10 22:00:26 UTC (rev 3342)
+++ xfce4-notes-plugin/trunk/panel-plugin/notes.c 2007-10-10 22:00:40 UTC (rev 3343)
@@ -17,14 +17,8 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
#include <glib/gstdio.h>
#include <gdk/gdkkeysyms.h>
-#include <gtk/gtk.h>
-#include <libxfce4panel/xfce-panel-convenience.h>
#include <libxfce4util/libxfce4util.h>
#include "notes.h"
@@ -76,6 +70,8 @@
static void notes_window_delete_note (NotesWindow *notes_window);
+static gboolean notes_note_save_data (NotesNote *notes_note);
+
/*static inline void notes_note_sort_names (NotesNote *notes_note);*/
static gint notes_note_strcasecmp (NotesNote *notes_note0,
@@ -1242,6 +1238,34 @@
g_free (filename);
}
+static gboolean
+notes_note_save_data (NotesNote *notes_note)
+{
+ DBG ("Save note `%s'", notes_note->name);
+
+ GtkTextBuffer *buffer;
+ GtkTextIter start, end;
+ gchar *filename, *contents;
+
+ buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (notes_note->text_view));
+
+ gtk_text_buffer_get_bounds (buffer, &start, &end);
+
+ contents = gtk_text_buffer_get_text (GTK_TEXT_BUFFER (buffer), &start, &end, TRUE);
+
+ filename = g_build_path (G_DIR_SEPARATOR_S,
+ notes_note->notes_window->notes_plugin->notes_path,
+ notes_note->notes_window->name,
+ notes_note->name,
+ NULL);
+ g_file_set_contents (filename, contents, -1, NULL);
+
+ g_free (filename);
+ g_free (contents);
+
+ return FALSE;
+}
+
void
notes_note_destroy (NotesNote *notes_note)
{
@@ -1251,6 +1275,10 @@
gchar *note_path;
NotesWindow *notes_window = notes_note->notes_window;
+ /* Make sure we kill the timeout */
+ if (notes_note->timeout != 0)
+ g_source_remove (notes_note->timeout);
+
/* Remove notebook page */
id = gtk_notebook_get_current_page (GTK_NOTEBOOK (notes_window->notebook));
gtk_notebook_remove_page (GTK_NOTEBOOK (notes_window->notebook), id);
@@ -1365,6 +1393,12 @@
static void
notes_note_buffer_changed (NotesNote *notes_note)
{
+ if (notes_note->timeout > 0)
+ {
+ g_source_remove (notes_note->timeout);
+ notes_note->timeout = 0;
+ }
+ notes_note->timeout = g_timeout_add (60000, (GSourceFunc)notes_note_save_data, notes_note);
}
static gboolean
Modified: xfce4-notes-plugin/trunk/panel-plugin/notes.h
===================================================================
--- xfce4-notes-plugin/trunk/panel-plugin/notes.h 2007-10-10 22:00:26 UTC (rev 3342)
+++ xfce4-notes-plugin/trunk/panel-plugin/notes.h 2007-10-10 22:00:40 UTC (rev 3343)
@@ -20,15 +20,19 @@
#ifndef NOTES_H
#define NOTES_H
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <gtk/gtk.h>
#include <libxfce4panel/xfce-panel-plugin.h>
-/* #include <gdk/gdkkeysyms.h> FIXME */
+#include <libxfce4panel/xfce-panel-convenience.h>
typedef struct _NotesPlugin NotesPlugin;
struct _NotesPlugin
{
XfcePanelPlugin *panel_plugin;
GSList *windows;
- /* guint timeout_id; FIXME */
gchar *config_file;
gchar *notes_path;
@@ -87,6 +91,7 @@
NotesWindow *notes_window;
gchar *name;
+ guint timeout;
GtkWidget *title;
GtkWidget *scrolled_window;
Modified: xfce4-notes-plugin/trunk/panel-plugin/panel-plugin.c
===================================================================
--- xfce4-notes-plugin/trunk/panel-plugin/panel-plugin.c 2007-10-10 22:00:26 UTC (rev 3342)
+++ xfce4-notes-plugin/trunk/panel-plugin/panel-plugin.c 2007-10-10 22:00:40 UTC (rev 3343)
@@ -19,19 +19,9 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#ifdef HAVE_STRING_H
-#include <string.h>
-#endif
-
#include <stdlib.h>
-#include <gtk/gtk.h>
#include <libxfcegui4/libxfcegui4.h>
-#include <libxfce4panel/xfce-panel-plugin.h>
-#include <libxfce4panel/xfce-panel-convenience.h>
#include "notes.h"
@@ -62,14 +52,8 @@
gpointer user_data);
static void notes_plugin_menu_destroy (NotesPlugin *notes_plugin);
-/* TODO sort the next functions */
-/*static gboolean save_on_timeout_execute (NotesPlugin *notes_plugin);
-static void save_on_timeout (NotesPlugin *notes);*/
-
-
-
static void
notes_plugin_register (XfcePanelPlugin *panel_plugin)
{
@@ -329,23 +313,3 @@
XFCE_PANEL_PLUGIN_REGISTER_EXTERNAL (notes_plugin_register);
-/* TODO sort the next functions */
-
-/*static gboolean
-save_on_timeout_execute (NotesPlugin *notes)
-{
- notes_save (notes->plugin, notes);
- return FALSE;
-}
-
-static void
-save_on_timeout (NotesPlugin *notes)
-{
- if (notes->timeout_id > 0)
- {
- g_source_remove (notes->timeout_id);
- notes->timeout_id = 0;
- }
- notes->timeout_id = g_timeout_add (60000, (GSourceFunc) save_on_timeout_execute, notes);
-}*/
-
More information about the Goodies-commits
mailing list