[Goodies-commits] r3321 - xfce4-notes-plugin/trunk/panel-plugin
Mike Massonnet
mmassonnet at xfce.org
Wed Oct 10 23:55:05 CEST 2007
Author: mmassonnet
Date: 2007-10-10 21:55:04 +0000 (Wed, 10 Oct 2007)
New Revision: 3321
Modified:
xfce4-notes-plugin/trunk/panel-plugin/Makefile.am
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:
Make the notes plugin runable
Modified: xfce4-notes-plugin/trunk/panel-plugin/Makefile.am
===================================================================
--- xfce4-notes-plugin/trunk/panel-plugin/Makefile.am 2007-10-10 21:54:46 UTC (rev 3320)
+++ xfce4-notes-plugin/trunk/panel-plugin/Makefile.am 2007-10-10 21:55:04 UTC (rev 3321)
@@ -19,7 +19,7 @@
xfce4_notes_plugin_SOURCES = \
panel-plugin.c \
notes.c \
- notes.h \
+ notes.h
xfce4_notes_plugin_CFLAGS = \
-I$(top_srcdir) \
Modified: xfce4-notes-plugin/trunk/panel-plugin/notes.c
===================================================================
--- xfce4-notes-plugin/trunk/panel-plugin/notes.c 2007-10-10 21:54:46 UTC (rev 3320)
+++ xfce4-notes-plugin/trunk/panel-plugin/notes.c 2007-10-10 21:55:04 UTC (rev 3321)
@@ -21,7 +21,9 @@
#include <config.h>
#endif
+#include <glib/gstdio.h>
#include <gtk/gtk.h>
+#include <libxfce4panel/xfce-panel-convenience.h>
#include <libxfce4util/libxfce4util.h>
#include "notes.h"
@@ -30,41 +32,66 @@
-gchar *
+static gboolean notes_note_key_pressed (GtkWidget *widget,
+ GdkEventKey *event,
+ NotesNote *notes_note);
+static void notes_note_buffer_changed (GtkWidget *widget,
+ NotesNote *notes_note);
+static gboolean notes_note_rename (GtkWidget *widget,
+ GdkEventButton *event,
+ NotesNote *notes_note);
+static void notes_window_add_note (GtkWidget *widget,
+ NotesWindow *notes_window);
+static gboolean notes_window_delete_note (GtkWidget *widget,
+ NotesWindow *notes_window);
+static gboolean notes_window_start_move (GtkWidget *widget,
+ GdkEventButton *event,
+ NotesWindow *notes_window);
+static gboolean notes_window_shade (GtkWidget *widget,
+ GdkEventScroll *event,
+ NotesWindow *notes_window);
+static void notes_window_close_window (GtkWidget *widget,
+ NotesWindow *notes_window);
+
+
+
+const gchar *
notes_window_read_name (NotesPlugin *notes_plugin)
{
static GDir *dir = NULL;
static gchar *notes_path = NULL;
- static gchar *name = NULL;
+ static const gchar *window_name = NULL;
if (G_UNLIKELY (dir == NULL))
{
notes_path = notes_plugin->notes_path;
- dir = g_dir_open (notes_path);
+ dir = g_dir_open (notes_path, 0, NULL);
}
- g_free (name);
- if (G_UNLIKELY ((name = g_dir_read_name (dir)) == NULL))
+ window_name = g_dir_read_name (dir);
+ TRACE ("window_name: %s", window_name);
+ if (G_UNLIKELY (window_name == NULL))
{
g_dir_close (dir);
- DBG ("Notes dir closed: %p\n", dir);
dir = NULL;
}
- return name;
+ return window_name;
}
NotesWindow *
notes_window_new (NotesPlugin *notes_plugin,
- gchar *notes_window_name)
+ const gchar *notes_window_name)
{
+ DBG ("New window: %s", notes_window_name);
+
NotesWindow *notes_window;
GtkAccelGroup *accel_group;
GtkWidget *img_add, *img_del, *img_close;
notes_window = g_slice_new0 (NotesWindow);
notes_window->notes_plugin = notes_plugin;
- g_slist_append (notes_plugin->windows, notes_window);
+ notes_plugin->windows = g_slist_prepend (notes_plugin->windows, notes_window);
/* Window */
notes_window->window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
@@ -78,7 +105,7 @@
notes_window->frame = gtk_frame_new (NULL);
gtk_frame_set_shadow_type (GTK_FRAME (notes_window->frame), GTK_SHADOW_OUT);
gtk_container_add (GTK_CONTAINER (notes_window->window),
- note->frame);
+ notes_window->frame);
gtk_widget_show (notes_window->frame);
/* Vertical box */
@@ -128,13 +155,13 @@
/* Event box move */
notes_window->eb_move = gtk_event_box_new ();
gtk_event_box_set_visible_window (GTK_EVENT_BOX (notes_window->eb_move), FALSE);
- gtk_widget_realize (notes_window->eb_move);
gtk_box_pack_start (GTK_BOX (notes_window->hbox),
notes_window->eb_move,
TRUE,
TRUE,
0);
gtk_widget_show (notes_window->eb_move);
+ gtk_widget_realize (notes_window->eb_move);
/* Title */
notes_window->title = gtk_label_new (_("<b>Notes</b>"));
@@ -205,7 +232,7 @@
notes_plugin);
g_signal_connect (G_OBJECT (notes_window->eb_move),
"button-press-event",
- G_CALLBACK (notes_window_move),
+ G_CALLBACK (notes_window_start_move),
notes_window);
g_signal_connect (G_OBJECT (notes_window->eb_move),
"scroll-event",
@@ -231,9 +258,9 @@
if (G_LIKELY (notes_window->visible
&& notes_window->show_on_startup != NEVER))
- gtk_widget_show (notes_window->windows);
+ gtk_widget_show (notes_window->window);
else
- gtk_widget_hide (notes_window->windows);
+ gtk_widget_hide (notes_window->window);
return notes_window;
}
@@ -243,19 +270,20 @@
{
XfceRc *rc;
NotesNote *notes_note;
- gchar *note_name;
- gchar *window_name;
+ const gchar *note_name;
+ const gchar *window_name;
+ gchar *window_name_tmp;
- window_name = gtk_label_get_text (notes_window->title);
+ window_name = gtk_label_get_text (GTK_LABEL (notes_window->title));
if (G_UNLIKELY (g_ascii_strncasecmp (window_name, "", 1) == 0))
{
guint id = g_slist_length (notes_window->notes_plugin->windows);
if (G_LIKELY (id > 1))
- gchar *window_name_tmp = g_strdup_printf ("Notes %d", id);
+ window_name_tmp = g_strdup_printf ("Notes %d", id);
else
- gchar *window_name_tmp = g_strdup ("Notes");
- gtk_label_set_text (notes_window->title, window_name_tmp);
- window_name = gtk_label_get_text (notes_window->title);
+ window_name_tmp = g_strdup ("Notes");
+ gtk_label_set_text (GTK_LABEL (notes_window->title), window_name_tmp);
+ window_name = gtk_label_get_text (GTK_LABEL (notes_window->title));
g_free (window_name_tmp);
}
@@ -276,18 +304,18 @@
xfce_rc_close (rc);
+ note_name = notes_note_read_name (notes_window);
do
{
+ TRACE ("note_name: %s", note_name);
+ notes_note = notes_note_new (notes_window, note_name);
note_name = notes_note_read_name (notes_window);
- notes_note = notes_note_new (notes_window, note_name);
- notes_note->notes_window = notes_window;
- g_slist_append (notes_window->notes, notes_note);
}
while (G_LIKELY (note_name != NULL));
}
void
-notes_window_configure (NotesPlugin *notes_window)
+notes_window_configure (NotesWindow *notes_window)
{
}
@@ -302,25 +330,25 @@
notes_window_save (NotesWindow *notes_window)
{
XfceRc *rc;
- gchar *window_name;
+ const gchar *window_name;
- window_name = gtk_label_get_text (notes_window->title);
+ rc = xfce_rc_simple_open (notes_window->notes_plugin->config_file, FALSE);
+ g_return_if_fail (G_LIKELY (rc != NULL));
+ window_name = gtk_label_get_text (GTK_LABEL (notes_window->title));
+
+ xfce_rc_set_group (rc, window_name);
+
if (GTK_WIDGET_VISIBLE (notes_window->window))
{
gtk_window_get_position (GTK_WINDOW (notes_window->window),
¬es_window->x,
¬es_window->y);
- gtk_window_get_size (GTK_WINDOW (notes->note->window),
+ gtk_window_get_size (GTK_WINDOW (notes_window->window),
¬es_window->w,
¬es_window->h);
}
- rc = xfce_rc_simple_open (notes_window->notes_plugin->config_file, FALSE);
- g_return_if_fail (G_UNLIKELY (!rc));
-
- xfce_rc_set_group (rc, window_name);
-
xfce_rc_write_int_entry (rc, "PosX", notes_window->x);
xfce_rc_write_int_entry (rc, "PosY", notes_window->y);
xfce_rc_write_int_entry (rc, "Width", notes_window->w);
@@ -342,38 +370,79 @@
xfce_rc_close (rc);
}
+static void
+notes_window_add_note (GtkWidget *widget,
+ NotesWindow *notes_window)
+{
+}
+static gboolean
+notes_window_delete_note (GtkWidget *widget,
+ NotesWindow *notes_window)
+{
+ return FALSE;
+}
-gchar *
+static gboolean
+notes_window_start_move (GtkWidget *widget,
+ GdkEventButton *event,
+ NotesWindow *notes_window)
+{
+ return FALSE;
+}
+
+static gboolean
+notes_window_shade (GtkWidget *widget,
+ GdkEventScroll *event,
+ NotesWindow *notes_window)
+{
+ return FALSE;
+}
+
+static void
+notes_window_close_window (GtkWidget *widget,
+ NotesWindow *notes_window)
+{
+}
+
+
+
+const gchar *
notes_note_read_name (NotesWindow *notes_window)
{
static GDir *dir = NULL;
static gchar *notes_path = NULL;
- static gchar *window_title = NULL;
+ const gchar *window_name = NULL;
static gchar *path = NULL;
- static gchar *note_name = NULL;
+ const gchar *note_name = NULL;
+ TRACE ("NotesWindow: %p", notes_window);
if (G_UNLIKELY (dir == NULL))
{
if (G_UNLIKELY (notes_path == NULL))
{
notes_path = notes_window->notes_plugin->notes_path;
- notes_title = notes_window->title;
+ window_name = gtk_label_get_text (GTK_LABEL (notes_window->title));
path = g_build_path (G_DIR_SEPARATOR_S,
notes_path,
- notes_title,
+ window_name,
NULL);
+ TRACE ("path: %s", path);
}
- dir = g_dir_open (path);
- g_return_val_if_fail (G_UNLIKELY (!dir), NULL);
+
+ if (G_UNLIKELY (!g_file_test (path, (G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR))))
+ g_mkdir (path, 0755);
+
+ dir = g_dir_open (path, 0, NULL);
}
- g_free (note_name);
- if (G_UNLIKELY ((note_name = g_dir_read_name (dir)) == NULL))
+ note_name = g_dir_read_name (dir);
+ TRACE ("note_name: %s", note_name);
+ if (G_UNLIKELY (note_name == NULL))
{
g_dir_close (dir);
- DBG ("Notes dir closed: %p\n", dir);
dir = NULL;
+ g_free (path);
}
return note_name;
@@ -391,14 +460,16 @@
**/
NotesNote *
notes_note_new (NotesWindow *notes_window,
- gchar *notes_note_name)
+ const gchar *notes_note_name)
{
+ DBG ("New note: %s", notes_note_name);
+
NotesNote *notes_note;
GtkTextBuffer *buffer;
notes_note = g_slice_new0 (NotesNote);
notes_note->notes_window = notes_window;
- g_slist_append (notes_window->notes, notes_note);
+ notes_window->notes = g_slist_prepend (notes_window->notes, notes_note);
/* Label */
GtkWidget *eb_border = gtk_event_box_new ();
@@ -436,11 +507,11 @@
g_signal_connect (buffer,
"changed",
G_CALLBACK (notes_note_buffer_changed),
- notes_window->panel_plugin);
+ notes_note);
g_signal_connect (eb_border,
"button-press-event",
G_CALLBACK (notes_note_rename),
- notes_window);
+ notes_note);
/* Load data */
notes_note_load_data (notes_note, buffer);
@@ -453,27 +524,28 @@
}
void
-notes_note_load_data (NotesNote *notes_note
+notes_note_load_data (NotesNote *notes_note,
GtkTextBuffer *buffer)
{
- gchar *note_name;
+ const gchar *note_name;
+ gchar *note_name_tmp;
gchar *filename;
gchar *contents = NULL;
- note_name = gtk_label_get_text (notes_note->title);
+ note_name = gtk_label_get_text (GTK_LABEL (notes_note->title));
if (G_UNLIKELY (g_ascii_strncasecmp (note_name, "", 1) == 0))
{
guint id = g_slist_length (notes_note->notes_window->notes);
- gchar *note_name_tmp = g_strdup_printf ("%d", id);
- gtk_label_set_text (notes_note->title, note_name_tmp);
- note_name = gtk_label_get_text (notes_note->title);
+ note_name_tmp = g_strdup_printf ("%d", id);
+ gtk_label_set_text (GTK_LABEL (notes_note->title), note_name_tmp);
+ note_name = gtk_label_get_text (GTK_LABEL (notes_note->title));
g_free (note_name_tmp);
}
filename = g_build_path (G_DIR_SEPARATOR_S,
notes_note->notes_window->notes_plugin->notes_path,
notes_note->notes_window->title,
- notes_name,
+ note_name,
NULL);
if (G_LIKELY (g_file_get_contents (filename, &contents, NULL, NULL)))
@@ -486,3 +558,25 @@
g_free (filename);
}
+static gboolean
+notes_note_key_pressed (GtkWidget *widget,
+ GdkEventKey *event,
+ NotesNote *notes_note)
+{
+ return FALSE;
+}
+
+static void
+notes_note_buffer_changed (GtkWidget *widget,
+ NotesNote *notes_note)
+{
+}
+
+static gboolean
+notes_note_rename (GtkWidget *widget,
+ GdkEventButton *event,
+ NotesNote *notes_note)
+{
+ return FALSE;
+}
+
Modified: xfce4-notes-plugin/trunk/panel-plugin/notes.h
===================================================================
--- xfce4-notes-plugin/trunk/panel-plugin/notes.h 2007-10-10 21:54:46 UTC (rev 3320)
+++ xfce4-notes-plugin/trunk/panel-plugin/notes.h 2007-10-10 21:55:04 UTC (rev 3321)
@@ -20,6 +20,7 @@
#ifndef NOTES_H
#define NOTES_H
+#include <libxfce4panel/xfce-panel-plugin.h>
/* #include <gdk/gdkkeysyms.h> FIXME */
typedef struct _NotesPlugin NotesPlugin;
@@ -37,13 +38,12 @@
GtkTooltips *tooltips;
};
-typedef enum _ShowOnStartup ShowOnStartup;
-enum _ShowOnStartup
+typedef enum
{
LAST_STATE,
ALWAYS,
NEVER,
-};
+} ShowOnStartup;
typedef struct _NotesWindow NotesWindow;
struct _NotesWindow
@@ -87,10 +87,10 @@
{
};
-gchar * notes_window_read_name (NotesPlugin *notes_plugin);
+const gchar * notes_window_read_name (NotesPlugin *notes_plugin);
NotesWindow * notes_window_new (NotesPlugin *notes_plugin,
- gchar *notes_window_name);
+ const gchar *notes_window_name);
void notes_window_load_data (NotesWindow *notes_window);
void notes_window_configure (NotesWindow *notes_window);
@@ -98,10 +98,12 @@
void notes_window_response (GtkWidget *widget,
int response,
NotesWindow *notes_window);
-gchar * notes_note_read_name (NotesWindow *notes_window);
+void notes_window_save (NotesWindow *notes_window);
+const gchar * notes_note_read_name (NotesWindow *notes_window);
+
NotesNote * notes_note_new (NotesWindow *notes_window,
- gchar *notes_note_name);
+ const gchar *notes_note_name);
void notes_note_load_data (NotesNote *notes_note,
GtkTextBuffer *buffer);
Modified: xfce4-notes-plugin/trunk/panel-plugin/panel-plugin.c
===================================================================
--- xfce4-notes-plugin/trunk/panel-plugin/panel-plugin.c 2007-10-10 21:54:46 UTC (rev 3320)
+++ xfce4-notes-plugin/trunk/panel-plugin/panel-plugin.c 2007-10-10 21:55:04 UTC (rev 3321)
@@ -54,9 +54,9 @@
static gboolean notes_plugin_popup (NotesPlugin *notes_plugin);
/* TODO sort the next functions */
-static gboolean save_on_timeout_execute (NotesPlugin *notes_plugin);
+/*static gboolean save_on_timeout_execute (NotesPlugin *notes_plugin);
-static void save_on_timeout (NotesPlugin *notes);
+static void save_on_timeout (NotesPlugin *notes);*/
@@ -64,14 +64,14 @@
static void
notes_plugin_register (XfcePanelPlugin *panel_plugin)
{
- DBG ("Properties: size = %d, screen_position = %d",
+ DBG ("\nProperties: size = %d, screen_position = %d",
xfce_panel_plugin_get_size (panel_plugin),
xfce_panel_plugin_get_screen_position (panel_plugin));
xfce_textdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR, "UTF-8");
NotesPlugin *notes_plugin = notes_plugin_new (panel_plugin);
- g_return_if_fail (G_UNLIKELY (!notes_plugin));
+ g_return_if_fail (G_LIKELY (notes_plugin != NULL));
notes_plugin_load_data (notes_plugin);
}
@@ -91,58 +91,57 @@
gtk_container_add (GTK_CONTAINER (panel_plugin),
notes_plugin->btn_panel);
- xfce_panel_plugin_add_action_widget (panel_plugin, notes_plugin->btn_panel);
- xfce_panel_plugin_menu_show_configure (panel_plugin);
-
- g_signal_connect (panel_plugin,
- "configure-plugin",
- G_CALLBACK (notes_plugin_configure),
- notes_plugin);
- g_signal_connect (panel_plugin,
- "size-changed",
- G_CALLBACK (notes_plugin_set_size),
- notes_plugin);
+ g_signal_connect_swapped (panel_plugin,
+ "size-changed",
+ G_CALLBACK (notes_plugin_set_size),
+ notes_plugin);
g_signal_connect (notes_plugin->btn_panel,
"clicked",
G_CALLBACK (notes_plugin_popup),
notes_plugin);
+ g_signal_connect_swapped (panel_plugin,
+ "save",
+ G_CALLBACK (notes_plugin_save),
+ notes_plugin);
g_signal_connect (panel_plugin,
- "save",
- G_CALLBACK (notes_plugin_save),
- notes_plugin);
- g_signal_connect (panel_plugin,
"free-data",
G_CALLBACK (notes_plugin_free),
notes_plugin);
+ xfce_panel_plugin_add_action_widget (panel_plugin, notes_plugin->btn_panel);
+ gtk_widget_show_all (notes_plugin->btn_panel);
+
return notes_plugin;
}
static void
notes_plugin_load_data (NotesPlugin *notes_plugin)
{
- DBG ("Look up file: %s\nNotes path: %s", notes_plugin->config_file,
- notes_plugin->notes_path);
NotesWindow *notes_window;
- gchar *notes_window_name;
+ const gchar *window_name;
notes_plugin->notes_path =
xfce_resource_save_location (XFCE_RESOURCE_DATA,
"notes/",
TRUE);
- g_return_if_fail (G_UNLIKELY (!notes_plugin->notes_path));
+ g_return_if_fail (G_LIKELY (notes_plugin->notes_path != NULL));
notes_plugin->config_file =
- xfce_panel_plugin_lookup_rc_file (notes_plugin->panel_plugin);
- g_return_if_fail (G_UNLIKELY (!notes_plugin->config_file));
+ xfce_panel_plugin_save_location (notes_plugin->panel_plugin,
+ TRUE);
+ g_return_if_fail (G_LIKELY (notes_plugin->config_file != NULL));
+ DBG ("\nLook up file: %s\nNotes path: %s", notes_plugin->config_file,
+ notes_plugin->notes_path);
+ window_name = notes_window_read_name (notes_plugin);
do
{
- window_name = notes_window_read_name (notes_plugin);
+ TRACE ("window_name: %s", window_name);
notes_window = notes_window_new (notes_plugin, window_name);
- notes_window->notes_plugin = notes_plugin;
- g_slist_append (notes_plugin->windows, notes_window);
-
+ if (G_UNLIKELY (window_name != NULL))
+ /* If there was no window, don't try to read again since
+ * a first window has been created and would be read again. */
+ window_name = notes_window_read_name (notes_plugin);
}
while (G_LIKELY (window_name != NULL));
}
@@ -166,7 +165,7 @@
static void
notes_plugin_save (NotesPlugin *notes_plugin)
{
- g_slist_foreach (notes_plugin->windows, notes_window_save, NULL);
+ g_slist_foreach (notes_plugin->windows, (GFunc)notes_window_save, NULL);
}
static void
@@ -191,7 +190,7 @@
/* TODO sort the next functions */
-static gboolean
+/*static gboolean
save_on_timeout_execute (NotesPlugin *notes)
{
notes_save (notes->plugin, notes);
@@ -201,11 +200,11 @@
static void
save_on_timeout (NotesPlugin *notes)
{
- /*if (notes->timeout_id > 0)
+ 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);*/
-}
+ notes->timeout_id = g_timeout_add (60000, (GSourceFunc) save_on_timeout_execute, notes);
+}*/
More information about the Goodies-commits
mailing list