[Goodies-commits] r1788 - xfce4-notes-plugin/trunk/panel-plugin
Mike Massonnet
mmassonnet at xfce.org
Mon Jul 24 21:59:44 CEST 2006
Author: mmassonnet
Date: 2006-07-24 19:59:41 +0000 (Mon, 24 Jul 2006)
New Revision: 1788
Added:
xfce4-notes-plugin/trunk/panel-plugin/notes-options.c
xfce4-notes-plugin/trunk/panel-plugin/notes-options.h
xfce4-notes-plugin/trunk/panel-plugin/notes-window.c
xfce4-notes-plugin/trunk/panel-plugin/notes-window.h
Removed:
xfce4-notes-plugin/trunk/panel-plugin/note.h
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
Log:
* Code cleaning. Separate files.
* Options including:
- Show notes on startup
- Show in task switcher (Alt-Tab)
- Always on top
- Stick mode
Modified: xfce4-notes-plugin/trunk/panel-plugin/Makefile.am
===================================================================
--- xfce4-notes-plugin/trunk/panel-plugin/Makefile.am 2006-07-24 19:57:11 UTC (rev 1787)
+++ xfce4-notes-plugin/trunk/panel-plugin/Makefile.am 2006-07-24 19:59:41 UTC (rev 1788)
@@ -1,21 +1,24 @@
plugindir = $(libexecdir)/xfce4/panel-plugins
plugin_PROGRAMS = xfce4-notes-plugin
-xfce4_notes_plugin_SOURCES = \
- notes.h \
- notes.c \
- note.h
+xfce4_notes_plugin_SOURCES = \
+ notes.c \
+ notes-window.c \
+ notes-options.c \
+ notes.h \
+ notes-window.h \
+ notes-options.h
-xfce4_notes_plugin_CFLAGS = \
- -I$(top_srcdir) \
- @LIBXFCE4PANEL_CFLAGS@ \
- @LIBXFCEGUI4_CFLAGS@ \
- @LIBXFCE4UTIL_CFLAGS@ \
+xfce4_notes_plugin_CFLAGS = \
+ -I$(top_srcdir) \
+ @LIBXFCE4PANEL_CFLAGS@ \
+ @LIBXFCEGUI4_CFLAGS@ \
+ @LIBXFCE4UTIL_CFLAGS@ \
-DPACKAGE_LOCALE_DIR=\"$(localedir)\"
-xfce4_notes_plugin_LDFLAGS = \
- @LIBXFCE4PANEL_LIBS@ \
- @LIBXFCEGUI4_LIBS@ \
+xfce4_notes_plugin_LDFLAGS = \
+ @LIBXFCE4PANEL_LIBS@ \
+ @LIBXFCEGUI4_LIBS@ \
@LIBXFCE4UTIL_LIBS@
desktop_in_in_files = xfce4-notes-plugin.desktop.in.in
Deleted: xfce4-notes-plugin/trunk/panel-plugin/note.h
Added: xfce4-notes-plugin/trunk/panel-plugin/notes-options.c
===================================================================
--- xfce4-notes-plugin/trunk/panel-plugin/notes-options.c (rev 0)
+++ xfce4-notes-plugin/trunk/panel-plugin/notes-options.c 2006-07-24 19:59:41 UTC (rev 1788)
@@ -0,0 +1,164 @@
+/* $Id$
+ *
+ * Notes - panel plugin for Xfce Desktop Environment
+ * Copyright (C) 2003 Jakob Henriksson <b0kaj+dev at lysator.liu.se>
+ * 2006 Mike Massonnet <mmassonnet at gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.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"
+
+#define PLUGIN_NAME "xfce4-notes-plugin"
+
+
+static void on_toggle_show (GtkWidget *, NotesPlugin *);
+static void on_toggle_task_switcher (GtkWidget *, NotesPlugin *);
+static void on_toggle_always_on_top (GtkWidget *, NotesPlugin *);
+static void on_toggle_stick (GtkWidget *, NotesPlugin *);
+
+
+GtkWidget *
+notes_options_new (NotesPlugin *notes)
+{
+ GtkWidget *dialog, *vbox;
+ GtkWidget *cb_show, *cb_task_switcher, *cb_always_on_top, *cb_stick;
+ NotesOptions *options;
+
+ DBG ("New Notes Options");
+
+ options = ¬es->options;
+
+ dialog =
+ xfce_titled_dialog_new_with_buttons (_("Notes Plugin"), NULL,
+ GTK_DIALOG_NO_SEPARATOR,
+ GTK_STOCK_CLOSE, GTK_RESPONSE_OK,
+ NULL);
+ xfce_titled_dialog_set_subtitle (XFCE_TITLED_DIALOG (dialog),
+ _("Properties"));
+
+ gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER);
+ gtk_window_set_icon_name (GTK_WINDOW (dialog), "xfce4-panel");
+ gtk_window_set_keep_above (GTK_WINDOW (dialog), TRUE);
+ gtk_window_stick (GTK_WINDOW (dialog));
+
+ vbox = GTK_DIALOG (dialog)->vbox;
+ gtk_box_set_spacing (GTK_BOX (vbox), 2);
+
+ cb_show = gtk_check_button_new_with_label (_("Show the notes on startup"));
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (cb_show), options->show);
+ gtk_box_pack_start (GTK_BOX (vbox), cb_show, FALSE, FALSE, 0);
+ gtk_widget_show (cb_show);
+
+ g_signal_connect (cb_show, "toggled", G_CALLBACK (on_toggle_show), notes);
+
+ cb_task_switcher =
+ gtk_check_button_new_with_label (_("Show in the task switcher"));
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (cb_task_switcher),
+ options->task_switcher);
+ gtk_box_pack_start (GTK_BOX (vbox), cb_task_switcher, FALSE, FALSE, 0);
+ gtk_widget_show (cb_task_switcher);
+
+ g_signal_connect (cb_task_switcher, "toggled",
+ G_CALLBACK (on_toggle_task_switcher), notes);
+
+ cb_always_on_top =
+ gtk_check_button_new_with_label (_("Always on top"));
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (cb_always_on_top),
+ options->always_on_top);
+ gtk_box_pack_start (GTK_BOX (vbox), cb_always_on_top, FALSE, FALSE, 0);
+ gtk_widget_show (cb_always_on_top);
+
+ g_signal_connect (cb_always_on_top, "toggled",
+ G_CALLBACK (on_toggle_always_on_top), notes);
+
+ cb_stick = gtk_check_button_new_with_label (_("Stick mode"));
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (cb_stick), options->stick);
+ gtk_box_pack_start (GTK_BOX (vbox), cb_stick, FALSE, FALSE, 0);
+ gtk_widget_show (cb_stick);
+
+ g_signal_connect (cb_stick, "toggled", G_CALLBACK (on_toggle_stick), notes);
+
+ gtk_widget_show (dialog);
+
+ return dialog;
+}
+
+static void
+on_toggle_show (GtkWidget *widget, NotesPlugin *notes)
+{
+ gboolean toggle_value;
+
+ g_object_get (G_OBJECT (widget), "active", &toggle_value, NULL);
+ notes->options.show = toggle_value;
+
+ DBG ("Set option show: %d", toggle_value);
+}
+
+static void
+on_toggle_task_switcher (GtkWidget *widget, NotesPlugin *notes)
+{
+ gboolean toggle_value;
+
+ g_object_get (G_OBJECT (widget), "active", &toggle_value, NULL);
+ notes->options.task_switcher = toggle_value;
+
+ gtk_window_set_skip_pager_hint (GTK_WINDOW (notes->note->window),
+ !toggle_value);
+ gtk_window_set_skip_taskbar_hint (GTK_WINDOW (notes->note->window),
+ !toggle_value);
+
+ DBG ("Set option task_switcher: %d", toggle_value);
+}
+
+static void
+on_toggle_always_on_top (GtkWidget *widget, NotesPlugin *notes)
+{
+ gboolean toggle_value;
+
+ g_object_get (G_OBJECT (widget), "active", &toggle_value, NULL);
+ notes->options.always_on_top = toggle_value;
+
+ gtk_window_set_keep_above (GTK_WINDOW (notes->note->window), toggle_value);
+
+ DBG ("Set option always_on_top: %d", toggle_value);
+}
+
+static void
+on_toggle_stick (GtkWidget *widget, NotesPlugin *notes)
+{
+ gboolean toggle_value;
+
+ g_object_get (G_OBJECT (widget), "active", &toggle_value, NULL);
+ notes->options.stick = toggle_value;
+
+ if (toggle_value)
+ gtk_window_stick (GTK_WINDOW (notes->note->window));
+ else
+ gtk_window_unstick (GTK_WINDOW (notes->note->window));
+
+ DBG ("Set option stick: %d", toggle_value);
+}
Added: xfce4-notes-plugin/trunk/panel-plugin/notes-options.h
===================================================================
--- xfce4-notes-plugin/trunk/panel-plugin/notes-options.h (rev 0)
+++ xfce4-notes-plugin/trunk/panel-plugin/notes-options.h 2006-07-24 19:59:41 UTC (rev 1788)
@@ -0,0 +1,25 @@
+/* $Id$
+ *
+ * Copyright (c) 2006 Mike Massonnet <mmassonnet at gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef NOTES_OPTIONS_H
+#define NOTES_OPTIONS_H
+
+GtkWidget * notes_options_new (NotesPlugin *);
+
+#endif
Added: xfce4-notes-plugin/trunk/panel-plugin/notes-window.c
===================================================================
--- xfce4-notes-plugin/trunk/panel-plugin/notes-window.c (rev 0)
+++ xfce4-notes-plugin/trunk/panel-plugin/notes-window.c 2006-07-24 19:59:41 UTC (rev 1788)
@@ -0,0 +1,189 @@
+/* $Id$
+ *
+ * Copyright (c) 2006 Mike Massonnet <mmassonnet at gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.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"
+
+#define PLUGIN_NAME "xfce4-notes-plugin"
+
+
+static gboolean on_note_delete ();
+static gboolean on_title_press (GtkWidget *, GdkEventButton *, GtkWindow *);
+static gboolean on_title_scroll (GtkWidget *, GdkEventScroll *, Note *);
+
+
+Note *
+note_new (XfcePanelPlugin *plugin)
+{
+ Note *note;
+
+ DBG ("Create Note Window");
+
+ note = g_new0 (Note, 1);
+
+
+ /* Window */
+ note->window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+
+ gtk_window_set_default_size (GTK_WINDOW (note->window), 242, 200);
+ gtk_window_set_decorated (GTK_WINDOW (note->window), FALSE);
+ gtk_window_set_icon_name (GTK_WINDOW (note->window), GTK_STOCK_EDIT);
+
+ /* Prevent close window */
+ g_signal_connect (note->window, "delete-event", G_CALLBACK (on_note_delete),
+ NULL);
+
+
+ /* Frame */
+ note->frame = gtk_frame_new (NULL);
+ gtk_widget_show (note->frame);
+
+ gtk_frame_set_shadow_type (GTK_FRAME (note->frame), GTK_SHADOW_OUT);
+ gtk_container_add (GTK_CONTAINER (note->window), note->frame);
+
+
+ /* Vertical box */
+ note->vbox = gtk_vbox_new (FALSE, 0);
+ gtk_widget_show (note->vbox);
+
+ gtk_box_set_spacing (GTK_BOX (note->vbox), 2);
+ gtk_container_add (GTK_CONTAINER (note->frame), note->vbox);
+
+
+ /* Horizontal box: icon + title + close button */
+ note->hbox = gtk_hbox_new (FALSE, 2);
+ gtk_widget_show (note->hbox);
+
+ gtk_box_pack_start (GTK_BOX (note->vbox), note->hbox, FALSE, FALSE, 0);
+
+ /* Icon */
+ note->icon = gtk_image_new_from_stock (GTK_STOCK_EDIT,
+ GTK_ICON_SIZE_MENU);
+ gtk_widget_show (note->icon);
+
+ gtk_box_pack_start (GTK_BOX (note->hbox), note->icon, FALSE, FALSE, 0);
+
+ /* Event box move + Title */
+ note->move_event_box = gtk_event_box_new ();
+ gtk_widget_show (note->move_event_box);
+
+ gtk_box_pack_start (GTK_BOX (note->hbox), note->move_event_box, TRUE, TRUE,
+ 0);
+ g_signal_connect (G_OBJECT (note->move_event_box), "button-press-event",
+ G_CALLBACK (on_title_press), note->window);
+
+ g_signal_connect (G_OBJECT (note->move_event_box), "scroll-event",
+ G_CALLBACK (on_title_scroll), note);
+
+ gtk_widget_realize (note->move_event_box);
+
+ note->title = gtk_label_new (_("<b>Notes</b>"));
+ gtk_label_set_use_markup (GTK_LABEL (note->title), TRUE);
+ gtk_widget_show (note->title);
+
+ gtk_container_add (GTK_CONTAINER (note->move_event_box), note->title);
+
+ /* Close button + icon */
+ note->close_button = xfce_create_panel_button ();
+ gtk_widget_show (note->close_button);
+
+ gtk_widget_set_size_request (note->close_button, 16, 16);
+ gtk_box_pack_start (GTK_BOX (note->hbox), note->close_button, FALSE, FALSE,
+ 0);
+
+ note->close_icon = gtk_image_new_from_stock (GTK_STOCK_CLOSE,
+ GTK_ICON_SIZE_MENU);
+ gtk_widget_show (note->close_icon);
+
+ gtk_container_add (GTK_CONTAINER (note->close_button), note->close_icon);
+
+
+ /* Scrolled window + Text view */
+ note->scroll = gtk_scrolled_window_new (NULL, NULL);
+ gtk_widget_show (note->scroll);
+
+ gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (note->scroll),
+ GTK_SHADOW_IN);
+ gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (note->scroll),
+ GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS);
+ gtk_box_pack_start (GTK_BOX (note->vbox), note->scroll, TRUE, TRUE, 0);
+
+ /* Text view */
+ note->text = gtk_text_view_new ();
+ gtk_widget_show (note->text);
+
+ gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (note->text), GTK_WRAP_WORD);
+ gtk_container_add (GTK_CONTAINER (note->scroll), note->text);
+
+ return note;
+}
+
+static gboolean
+on_note_delete ()
+{
+ /* Prevent close window (Alt-F4) */
+ return TRUE;
+}
+
+static gboolean
+on_title_press (GtkWidget *widget, GdkEventButton *event, GtkWindow *window)
+{
+ if (event->type == GDK_BUTTON_PRESS && event->button == 1)
+ /* Move the window */
+ gtk_window_begin_move_drag (window, event->button, event->x_root,
+ event->y_root, event->time);
+
+ return FALSE;
+}
+
+static gboolean
+on_title_scroll (GtkWidget *widget, GdkEventScroll *event, Note *note)
+{
+ gint width, height;
+
+ gtk_window_get_default_size (GTK_WINDOW (note->window), &width, &height);
+
+ if (event->type == GDK_SCROLL)
+ {
+ if (event->direction == GDK_SCROLL_UP)
+ {
+ /* Hide the text view */
+ gtk_widget_hide (note->scroll);
+ gtk_window_resize (GTK_WINDOW (note->window), width, 1);
+ }
+ else if (event->direction == GDK_SCROLL_DOWN)
+ {
+ /* Show the text view */
+ gtk_widget_show (note->scroll);
+ gtk_window_resize (GTK_WINDOW (note->window), width, height);
+ }
+ }
+
+ return FALSE;
+}
Added: xfce4-notes-plugin/trunk/panel-plugin/notes-window.h
===================================================================
--- xfce4-notes-plugin/trunk/panel-plugin/notes-window.h (rev 0)
+++ xfce4-notes-plugin/trunk/panel-plugin/notes-window.h 2006-07-24 19:59:41 UTC (rev 1788)
@@ -0,0 +1,48 @@
+/* $Id$
+ *
+ * Copyright (c) 2006 Mike Massonnet <mmassonnet at gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef NOTES_WINDOW_H
+#define NOTES_WINDOW_H
+
+typedef struct
+{
+ GtkWidget *window;
+
+ GtkWidget *frame;
+
+ GtkWidget *icon;
+ GtkWidget *move_event_box;
+ GtkWidget *title;
+ GtkWidget *close_button;
+ GtkWidget *close_icon;
+
+ GtkWidget *scroll;
+ GtkWidget *text;
+
+ GtkWidget *vbox;
+ GtkWidget *hbox;
+
+ /* Window position */
+ gint x, y;
+}
+Note;
+
+Note * note_new (XfcePanelPlugin *);
+
+#endif
Modified: xfce4-notes-plugin/trunk/panel-plugin/notes.c
===================================================================
--- xfce4-notes-plugin/trunk/panel-plugin/notes.c 2006-07-24 19:57:11 UTC (rev 1787)
+++ xfce4-notes-plugin/trunk/panel-plugin/notes.c 2006-07-24 19:59:41 UTC (rev 1788)
@@ -30,20 +30,34 @@
#include <libxfce4panel/xfce-panel-plugin.h>
#include <libxfce4panel/xfce-panel-convenience.h>
-#include "note.h"
#include "notes.h"
+#include "notes-options.h"
#define PLUGIN_NAME "xfce4-notes-plugin"
+static void notes_construct (XfcePanelPlugin *);
+static void notes_free_data (XfcePanelPlugin *, NotesPlugin *);
+static void notes_save (XfcePanelPlugin *, NotesPlugin *);
+gboolean save_on_timeout (NotesPlugin *);
+static void notes_configure (XfcePanelPlugin *, NotesPlugin *);
+static gboolean notes_set_size (XfcePanelPlugin *, int size, NotesPlugin *);
+static void notes_load_data (XfcePanelPlugin *, NotesPlugin *);
+static void notes_button_toggled (XfcePanelPlugin *, NotesPlugin *);
+static void on_note_close (GtkWidget *, GtkToggleButton *);
+static gboolean on_note_key_press (GtkWidget *, GdkEventKey *, NotesPlugin *);
+static void on_note_changed (GtkWidget *widget, NotesPlugin *notes);
+static void on_options_response (GtkWidget *, int response, NotesPlugin *);
+
+
/* Panel Plugin Interface */
-XFCE_PANEL_PLUGIN_REGISTER_EXTERNAL(notes_construct);
+XFCE_PANEL_PLUGIN_REGISTER_EXTERNAL (notes_construct);
/* internal functions */
-static void
+static void
notes_free_data (XfcePanelPlugin *plugin, NotesPlugin *notes)
{
if (notes->timeout_id > 0)
@@ -55,7 +69,7 @@
gtk_main_quit ();
}
-static void
+static void
notes_save (XfcePanelPlugin *plugin, NotesPlugin *notes)
{
char *file;
@@ -77,7 +91,7 @@
{
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (notes->note->text));
gtk_text_buffer_get_bounds (buffer, &start, &end);
- text = gtk_text_buffer_get_text (GTK_TEXT_BUFFER (buffer), &start,
+ text = gtk_text_buffer_get_text (GTK_TEXT_BUFFER (buffer), &start,
&end, TRUE);
xfce_rc_write_entry (rc, "note", text);
@@ -85,13 +99,20 @@
if (GTK_WIDGET_VISIBLE (notes->note->window))
{
- gtk_window_get_position (GTK_WINDOW (notes->note->window),
+ gtk_window_get_position (GTK_WINDOW (notes->note->window),
¬es->note->x, ¬es->note->y);
}
xfce_rc_write_int_entry (rc, "pos_x", notes->note->x);
xfce_rc_write_int_entry (rc, "pos_y", notes->note->y);
+ xfce_rc_write_bool_entry (rc, "show", notes->options.show);
+ xfce_rc_write_bool_entry (rc, "task_switcher",
+ notes->options.task_switcher);
+ xfce_rc_write_bool_entry (rc, "always_on_top",
+ notes->options.always_on_top);
+ xfce_rc_write_bool_entry (rc, "stick", notes->options.stick);
+
xfce_rc_close (rc);
}
}
@@ -107,10 +128,20 @@
static void
notes_configure (XfcePanelPlugin *plugin, NotesPlugin *notes)
{
+ GtkWidget *dialog;
+
DBG ("Configure: %s", PLUGIN_NAME);
+
+ xfce_panel_plugin_block_menu (plugin);
+ dialog = notes_options_new (notes);
+
+ g_object_set_data (G_OBJECT (notes->plugin), "configure", dialog);
+
+ g_signal_connect (dialog, "response", G_CALLBACK (on_options_response),
+ notes);
}
-static gboolean
+static gboolean
notes_set_size (XfcePanelPlugin *plugin, int size, NotesPlugin *notes)
{
GdkPixbuf *pixbuf;
@@ -129,42 +160,45 @@
}
-/* create widgets and connect to signals */
+/* create widgets and connect to signals */
-static void
+static void
notes_construct (XfcePanelPlugin *plugin)
{
NotesPlugin *notes;
-
- xfce_textdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR, "UTF-8");
+ xfce_textdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR, "UTF-8");
+
DBG ("Construct: %s", PLUGIN_NAME);
-
- DBG ("Properties: size = %d, panel_position = %d",
+
+ DBG ("Properties: size = %d, panel_position = %d",
xfce_panel_plugin_get_size (plugin),
xfce_panel_plugin_get_screen_position (plugin));
notes = notes_new (plugin);
-
+
gtk_container_add (GTK_CONTAINER (plugin), notes->button);
xfce_panel_plugin_add_action_widget (plugin, notes->button);
- g_signal_connect (plugin, "free-data",
+ g_signal_connect (plugin, "free-data",
G_CALLBACK (notes_free_data), notes);
g_signal_connect (notes->button, "toggled",
G_CALLBACK (notes_button_toggled), notes);
- g_signal_connect (plugin, "save",
+ g_signal_connect (plugin, "save",
G_CALLBACK (notes_save), notes);
- g_signal_connect (plugin, "size-changed",
+ g_signal_connect (plugin, "size-changed",
G_CALLBACK (notes_set_size), notes);
xfce_panel_plugin_menu_show_configure (plugin);
- g_signal_connect (plugin, "configure-plugin",
+ g_signal_connect (plugin, "configure-plugin",
G_CALLBACK (notes_configure), notes);
+
+ if (notes->options.show)
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (notes->button), TRUE);
}
NotesPlugin *
@@ -176,10 +210,10 @@
DBG ("New Notes Plugin");
notes = g_new0 (NotesPlugin, 1);
-
+
notes->plugin = plugin;
notes->timeout_id = 0;
-
+
notes->button = xfce_create_panel_toggle_button ();
gtk_widget_show (notes->button);
@@ -188,16 +222,17 @@
gtk_container_add (GTK_CONTAINER (notes->button), notes->icon);
notes->tooltips = gtk_tooltips_new ();
- gtk_tooltips_set_tip (GTK_TOOLTIPS (notes->tooltips), notes->button,
+ gtk_tooltips_set_tip (GTK_TOOLTIPS (notes->tooltips), notes->button,
_("Notes\nClick this button to show/hide your notes"),
NULL);
notes->note = note_new (plugin);
+ notes_load_data (plugin, notes);
- g_signal_connect (notes->note->close_button, "clicked",
+ g_signal_connect (notes->note->close_button, "clicked",
G_CALLBACK (on_note_close), notes->button);
- g_signal_connect (notes->note->text, "key-press-event",
+ g_signal_connect (notes->note->text, "key-press-event",
G_CALLBACK (on_note_key_press), notes);
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (notes->note->text));
@@ -207,22 +242,69 @@
}
static void
+notes_load_data (XfcePanelPlugin *plugin, NotesPlugin *notes)
+{
+ char *file;
+ XfceRc *rc;
+
+ GtkTextBuffer *buffer;
+ const gchar *text;
+
+ if (!(file = xfce_panel_plugin_lookup_rc_file (plugin)))
+ return;
+
+ DBG ("Look up file (%s)", file);
+
+ rc = xfce_rc_simple_open (file, FALSE);
+ g_free (file);
+
+ if (rc)
+ {
+ text = xfce_rc_read_entry (rc, "note", "");
+
+ buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (notes->note->text));
+ gtk_text_buffer_set_text (buffer, text, -1);
+
+ gtk_text_view_set_buffer (GTK_TEXT_VIEW (notes->note->text), buffer);
+
+ notes->note->x = xfce_rc_read_int_entry (rc, "pos_x", -1);
+ notes->note->y = xfce_rc_read_int_entry (rc, "pos_y", -1);
+
+ notes->options.show = xfce_rc_read_bool_entry (rc, "show", FALSE);
+ notes->options.task_switcher =
+ xfce_rc_read_bool_entry (rc, "task_switcher", FALSE);
+ notes->options.always_on_top =
+ xfce_rc_read_bool_entry (rc, "always_on_top", FALSE);
+ notes->options.stick = xfce_rc_read_bool_entry (rc, "stick", FALSE);
+
+ xfce_rc_close (rc);
+ }
+}
+
+static void
notes_button_toggled (XfcePanelPlugin *plugin, NotesPlugin *notes)
{
+ DBG ("Notes Button Toggled");
+
/* Show/hide the note */
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (notes->button)))
{
- gtk_window_move (GTK_WINDOW (notes->note->window), notes->note->x,
+ gtk_window_move (GTK_WINDOW (notes->note->window), notes->note->x,
notes->note->y);
gtk_widget_show (notes->note->window);
- gtk_window_set_keep_above (GTK_WINDOW (notes->note->window), FALSE);
- gtk_window_stick (GTK_WINDOW (notes->note->window));
+ gtk_window_set_keep_above (GTK_WINDOW (notes->note->window),
+ notes->options.always_on_top);
+
+ if (notes->options.stick)
+ gtk_window_stick (GTK_WINDOW (notes->note->window));
+ else
+ gtk_window_unstick (GTK_WINDOW (notes->note->window));
}
else
{
- gtk_window_get_position (GTK_WINDOW (notes->note->window),
+ gtk_window_get_position (GTK_WINDOW (notes->note->window),
¬es->note->x, ¬es->note->y);
gtk_widget_hide (notes->note->window);
@@ -253,6 +335,15 @@
notes->timeout_id = 0;
}
- notes->timeout_id = g_timeout_add (5000, (GSourceFunc) save_on_timeout,
+ notes->timeout_id = g_timeout_add (5000, (GSourceFunc) save_on_timeout,
notes);
}
+
+static void
+on_options_response (GtkWidget *widget, int response, NotesPlugin *notes)
+{
+ xfce_panel_plugin_unblock_menu (notes->plugin);
+ gtk_widget_destroy (widget);
+
+ notes_save (notes->plugin, notes);
+}
Modified: xfce4-notes-plugin/trunk/panel-plugin/notes.h
===================================================================
--- xfce4-notes-plugin/trunk/panel-plugin/notes.h 2006-07-24 19:57:11 UTC (rev 1787)
+++ xfce4-notes-plugin/trunk/panel-plugin/notes.h 2006-07-24 19:59:41 UTC (rev 1788)
@@ -22,37 +22,33 @@
#include <gdk/gdkkeysyms.h>
+#include "notes-window.h"
+
typedef struct
{
+ gboolean show;
+ gboolean task_switcher;
+ gboolean always_on_top;
+ gboolean stick;
+}
+NotesOptions;
+
+typedef struct
+{
XfcePanelPlugin *plugin;
-
+
GtkWidget *button;
GtkWidget *icon;
GtkTooltips *tooltips;
Note *note;
+ NotesOptions options;
- /* Stored state */
- gboolean show;
- gboolean task_switcher;
- gboolean always_on_top;
- gboolean stick;
-
guint timeout_id;
}
NotesPlugin;
-static void notes_construct (XfcePanelPlugin *);
-static void notes_free_data (XfcePanelPlugin *, NotesPlugin *);
-static void notes_save (XfcePanelPlugin *, NotesPlugin *);
-gboolean save_on_timeout (NotesPlugin *);
-static void notes_configure (XfcePanelPlugin *, NotesPlugin *);
-static gboolean notes_set_size (XfcePanelPlugin *, int size, NotesPlugin *);
NotesPlugin * notes_new (XfcePanelPlugin *);
-static void notes_button_toggled (XfcePanelPlugin *, NotesPlugin *);
-static void on_note_close (GtkWidget *, GtkToggleButton *);
-static gboolean on_note_key_press (GtkWidget *, GdkEventKey *, NotesPlugin *);
-static void on_note_changed (GtkWidget *widget, NotesPlugin *notes);
#endif
More information about the Goodies-commits
mailing list