Author: nick
Date: 2008-04-10 10:24:38 +0000 (Thu, 10 Apr 2008)
New Revision: 26813

Added:
   xfce-mcs-plugins/branches/multi_device/xfce-mouse-accessibility.c
   xfce-mcs-plugins/branches/multi_device/xfce-mouse-accessibility.h
   xfce-mcs-plugins/branches/multi_device/xfce-mouse-themes.c
   xfce-mcs-plugins/branches/multi_device/xfce-mouse-themes.h
   xfce-mcs-plugins/branches/multi_device/xfce-settings-display
   xfce-mcs-plugins/branches/multi_device/xfce-settings-mouse
Modified:
   xfce-mcs-plugins/branches/multi_device/Makefile
   xfce-mcs-plugins/branches/multi_device/xfce-mouse-dialog.c
Log:
Dump some code since people are working on settings manager related code

Modified: xfce-mcs-plugins/branches/multi_device/Makefile
===================================================================
--- xfce-mcs-plugins/branches/multi_device/Makefile     2008-04-10 08:31:13 UTC 
(rev 26812)
+++ xfce-mcs-plugins/branches/multi_device/Makefile     2008-04-10 10:24:38 UTC 
(rev 26813)
@@ -9,8 +9,11 @@
        `pkg-config --cflags --libs libxfce4ui-1` \
        `pkg-config --cflags --libs libxfce4util-1.0` \
        `pkg-config --cflags --libs xi` \
+       `pkg-config --cflags --libs xcursor` \
        xfce-mouse-dialog.c xfce-mouse-dialog.h \
-       xfce-mouse-main.c -o xfce-mouse-settings
+       xfce-mouse-themes.c xfce-mouse-themes.h \
+       xfce-mouse-accessibility.c xfce-mouse-accessibility.h \
+       xfce-mouse-main.c -o xfce-settings-mouse
 
        $(CC) $(CFLAGS) \
        `pkg-config --cflags --libs gtk+-2.0` \
@@ -19,7 +22,7 @@
        `pkg-config --cflags --libs xrandr` \
        `pkg-config --cflags --libs xxf86vm` \
        xfce-display-dialog.c xfce-display-dialog.h \
-       xfce-display-main.c -o xfce-display-settings
+       xfce-display-main.c -o xfce-settings-display
 
 clean:
-       rm -f xfce-mouse-settings xfce-display-settings
+       rm -f xfce-settings-mouse xfce-settings-display

Added: xfce-mcs-plugins/branches/multi_device/xfce-mouse-accessibility.c
===================================================================
--- xfce-mcs-plugins/branches/multi_device/xfce-mouse-accessibility.c           
                (rev 0)
+++ xfce-mcs-plugins/branches/multi_device/xfce-mouse-accessibility.c   
2008-04-10 10:24:38 UTC (rev 26813)
@@ -0,0 +1,218 @@
+/* $Id: xfce-mouse-dialog.c 26560 2008-01-11 17:53:46Z nick $ */
+/*
+ * Copyright 2005 Pasi Orovuo <[EMAIL PROTECTED]>
+ * Copyright 2005 Brian Tarricone <[EMAIL PROTECTED]>
+ * Copyright 2008 Nick Schermer <[EMAIL PROTECTED]>
+ *
+ * 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 <string.h>
+#include <math.h>
+
+#include <X11/Xlib.h>
+#include <X11/XKBlib.h>
+#include <gdk/gdkx.h>
+
+#include "xfce-mouse-accessibility.h"
+
+#define BORDER (6)
+
+
+
+static void xfce_mouse_accessibility_class_init (XfceMouseAccessibilityClass 
*klass);
+static void xfce_mouse_accessibility_init (XfceMouseAccessibility *box);
+static void xfce_mouse_accessibility_finalize (GObject *object);
+//static void xfce_mouse_accessibility_load (XfceMouseAccessibility *box);
+//static void xfce_mouse_accessibility_save (XfceMouseAccessibility *box);
+static void xfce_mouse_accessibility_toggled (GtkToggleButton *button, 
XfceMouseAccessibility *box);
+
+
+
+struct _XfceMouseAccessibilityClass
+{
+  GtkVBoxClass __parent__;
+};
+
+struct _XfceMouseAccessibility
+{
+  GtkVBox __parent__;
+  
+  GtkWidget *button;
+  GtkWidget *frame;
+  
+  GtkWidget *delay;
+  GtkWidget *interval;
+  GtkWidget *max_speed;
+  GtkWidget *time_to_max;
+};
+
+
+
+G_DEFINE_TYPE (XfceMouseAccessibility, xfce_mouse_accessibility, 
GTK_TYPE_VBOX);
+
+
+
+static void
+xfce_mouse_accessibility_class_init (XfceMouseAccessibilityClass *klass)
+{
+  GObjectClass   *gobject_class;
+
+  gobject_class = G_OBJECT_CLASS (klass);
+  gobject_class->finalize = xfce_mouse_accessibility_finalize;
+}
+
+
+
+static void
+xfce_mouse_accessibility_init (XfceMouseAccessibility *box)
+{
+  GtkWidget *button;
+  GtkWidget *table;
+  GtkWidget *frame;
+  GtkWidget *label;
+  GtkWidget *scale;
+  
+  gtk_box_set_spacing (GTK_BOX (box), BORDER * 2);
+  gtk_container_set_border_width (GTK_CONTAINER (box), BORDER);
+  
+  button = box->button = gtk_check_button_new_with_mnemonic ("Enable mouse 
_emulation");
+  gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 0);
+  gtk_widget_show (button);
+  
+  table = gtk_table_new (4, 2, FALSE);
+  gtk_table_set_row_spacings (GTK_TABLE (table), BORDER);
+  gtk_table_set_col_spacings (GTK_TABLE (table), BORDER * 2);
+  gtk_widget_show (table);
+  
+  frame = box->frame = xfce_gtk_frame_box_new_with_content (_("Settings"), 
table);
+  gtk_box_pack_start (GTK_BOX (box), frame, TRUE, TRUE, 0);
+  gtk_widget_show (frame);
+  
+  /* set sensitivity */
+  g_signal_connect (G_OBJECT (button), "toggled", G_CALLBACK 
(xfce_mouse_accessibility_toggled), box);
+  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), FALSE);
+  gtk_widget_set_sensitive (frame, FALSE);
+  
+  /* delay */
+  label = gtk_label_new_with_mnemonic ("De_lay:");
+  gtk_table_attach (GTK_TABLE (table), label, 0, 1, 0, 1, GTK_FILL, 0, 0, 0);
+  gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
+  gtk_widget_show (label);
+  
+  scale = box->delay = gtk_hscale_new_with_range (0, 250, 1);
+  gtk_table_attach (GTK_TABLE (table), scale, 1, 2, 0, 1, GTK_EXPAND | 
GTK_FILL, GTK_FILL, 0, 0);
+  gtk_scale_set_draw_value (GTK_SCALE (scale), FALSE);
+  gtk_label_set_mnemonic_widget (GTK_LABEL (label), scale);
+  gtk_widget_show (scale);
+  
+  /* interval */
+  label = gtk_label_new_with_mnemonic ("Inter_val:");
+  gtk_table_attach (GTK_TABLE (table), label, 0, 1, 1, 2, GTK_FILL, 0, 0, 0);
+  gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
+  gtk_widget_show (label);
+  
+  scale = box->interval = gtk_hscale_new_with_range (0, 250, 1);
+  gtk_table_attach (GTK_TABLE (table), scale, 1, 2, 1, 2, GTK_EXPAND | 
GTK_FILL, GTK_FILL, 0, 0);
+  gtk_scale_set_draw_value (GTK_SCALE (scale), FALSE);
+  gtk_label_set_mnemonic_widget (GTK_LABEL (label), scale);
+  gtk_widget_show (scale);
+  
+  /* maximum speed */
+  label = gtk_label_new_with_mnemonic ("M_aximum speed:");
+  gtk_table_attach (GTK_TABLE (table), label, 0, 1, 2, 3, GTK_FILL, 0, 0, 0);
+  gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
+  gtk_widget_show (label);
+  
+  scale = box->max_speed = gtk_hscale_new_with_range (0, 250, 1);
+  gtk_table_attach (GTK_TABLE (table), scale, 1, 2, 2, 3, GTK_EXPAND | 
GTK_FILL, GTK_FILL, 0, 0);
+  gtk_scale_set_draw_value (GTK_SCALE (scale), FALSE);
+  gtk_label_set_mnemonic_widget (GTK_LABEL (label), scale);
+  gtk_widget_show (scale);
+  
+  /* time to maximum speed */
+  label = gtk_label_new_with_mnemonic ("_Time to maximum:");
+  gtk_table_attach (GTK_TABLE (table), label, 0, 1, 3, 4, GTK_FILL, 0, 0, 0);
+  gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
+  gtk_widget_show (label);
+  
+  scale = box->time_to_max = gtk_hscale_new_with_range (0, 250, 1);
+  gtk_table_attach (GTK_TABLE (table), scale, 1, 2, 3, 4, GTK_EXPAND | 
GTK_FILL, GTK_FILL, 0, 0);
+  gtk_scale_set_draw_value (GTK_SCALE (scale), FALSE);
+  gtk_label_set_mnemonic_widget (GTK_LABEL (label), scale);
+  gtk_widget_show (scale);
+}
+
+
+
+static void
+xfce_mouse_accessibility_finalize (GObject *object)
+{
+  (*G_OBJECT_CLASS (xfce_mouse_accessibility_parent_class)->finalize) (object);
+}
+
+
+#if 0
+static void
+xfce_mouse_accessibility_load (XfceMouseAccessibility *box)
+{
+    
+}
+
+
+
+static void
+xfce_mouse_accessibility_save (XfceMouseAccessibility *box)
+{
+  XkbDescPtr xkb;
+  
+  /* allocate keyboard structure */
+  xkb = XkbAllocKeyboard ();
+  if (G_LIKELY (xkb))
+    {
+      
+      
+      /* cleanup */
+      XFree (xkb);    
+    }
+  
+}
+#endif
+
+
+static void
+xfce_mouse_accessibility_toggled (GtkToggleButton        *button, 
+                                  XfceMouseAccessibility *box)
+{
+  gboolean active;
+  
+  /* get toggle button state */
+  active = gtk_toggle_button_get_active (button);
+  
+  /* set sensiivity of the settings frame */
+  gtk_widget_set_sensitive (box->frame, active);
+}
+
+
+
+GtkWidget *
+xfce_mouse_accessibility_new (void)
+{
+  return g_object_new (XFCE_TYPE_MOUSE_ACCESSIBILITY, NULL);
+}

Added: xfce-mcs-plugins/branches/multi_device/xfce-mouse-accessibility.h
===================================================================
--- xfce-mcs-plugins/branches/multi_device/xfce-mouse-accessibility.h           
                (rev 0)
+++ xfce-mcs-plugins/branches/multi_device/xfce-mouse-accessibility.h   
2008-04-10 10:24:38 UTC (rev 26813)
@@ -0,0 +1,44 @@
+/* $Id: xfce-mouse-dialog.h 26560 2008-01-11 17:53:46Z nick $ */
+/*
+ * Copyright 2008 Nick Schermer <[EMAIL PROTECTED]>
+ *
+ * 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
+ */
+
+#ifndef __XFCE_MOUSE_ACCESSIBILITY_H__
+#define __XFCE_MOUSE_ACCESSIBILITY_H__
+
+#include <libxfce4ui/libxfce4ui.h>
+#include <libxfce4util/libxfce4util.h>
+
+G_BEGIN_DECLS
+
+#define XFCE_TYPE_MOUSE_ACCESSIBILITY            
(xfce_mouse_accessibility_get_type ())
+#define XFCE_MOUSE_ACCESSIBILITY(obj)            (G_TYPE_CHECK_INSTANCE_CAST 
((obj), XFCE_TYPE_MOUSE_ACCESSIBILITY, XfceMouseAccessibility))
+#define XFCE_MOUSE_ACCESSIBILITY_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST 
((klass), XFCE_TYPE_MOUSE_ACCESSIBILITY, XfceMouseAccessibilityClass))
+#define XFCE_IS_MOUSE_ACCESSIBILITY(obj)         (G_TYPE_CHECK_INSTANCE_TYPE 
((obj), XFCE_TYPE_MOUSE_ACCESSIBILITY))
+#define XFCE_IS_MOUSE_ACCESSIBILITY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST 
((klass), XFCE_TYPE_MOUSE_ACCESSIBILITY))
+#define XFCE_MOUSE_ACCESSIBILITY_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS 
((obj), XFCE_TYPE_MOUSE_ACCESSIBILITY, XfceMouseAccessibilityClass))
+
+typedef struct _XfceMouseAccessibilityClass XfceMouseAccessibilityClass;
+typedef struct _XfceMouseAccessibility      XfceMouseAccessibility;
+
+GType      xfce_mouse_accessibility_get_type (void) G_GNUC_CONST;
+
+GtkWidget *xfce_mouse_accessibility_new      (void);
+
+G_END_DECLS
+
+#endif /* !__XFCE_MOUSE_ACCESSIBILITY_H__ */

Modified: xfce-mcs-plugins/branches/multi_device/xfce-mouse-dialog.c
===================================================================
--- xfce-mcs-plugins/branches/multi_device/xfce-mouse-dialog.c  2008-04-10 
08:31:13 UTC (rev 26812)
+++ xfce-mcs-plugins/branches/multi_device/xfce-mouse-dialog.c  2008-04-10 
10:24:38 UTC (rev 26813)
@@ -28,6 +28,8 @@
 #include <gdk/gdkx.h>
 
 #include "xfce-mouse-dialog.h"
+#include "xfce-mouse-themes.h"
+#include "xfce-mouse-accessibility.h"
 
 #define BORDER (6)
 
@@ -117,6 +119,8 @@
   GtkTreeSelection  *selection;
   GtkListStore      *store;
   GtkTreePath       *path;
+  GtkWidget         *themes;
+  GtkWidget         *accessibility;
 
   /* initialize */
   dialog->display = gdk_display_get_default ();
@@ -254,6 +258,18 @@
   /* release size group */
   g_object_unref (G_OBJECT (sg));
 
+  /* themes tab */
+  themes = xfce_mouse_themes_new ();
+  gtk_container_add (GTK_CONTAINER (notebook), themes);
+  gtk_notebook_set_tab_label_text (GTK_NOTEBOOK (notebook), themes, _("Cursor 
Themes"));
+  gtk_widget_show (themes);
+
+  /* accessibility tab */
+  accessibility = xfce_mouse_accessibility_new ();
+  gtk_container_add (GTK_CONTAINER (notebook), accessibility);
+  gtk_notebook_set_tab_label_text (GTK_NOTEBOOK (notebook), accessibility, 
_("Accessibility"));
+  gtk_widget_show (accessibility);
+
   /* select the first mouse in the tree */
   path = gtk_tree_path_new_first ();
   gtk_tree_selection_select_path (selection, path);

Added: xfce-mcs-plugins/branches/multi_device/xfce-mouse-themes.c
===================================================================
--- xfce-mcs-plugins/branches/multi_device/xfce-mouse-themes.c                  
        (rev 0)
+++ xfce-mcs-plugins/branches/multi_device/xfce-mouse-themes.c  2008-04-10 
10:24:38 UTC (rev 26813)
@@ -0,0 +1,602 @@
+/* $Id: xfce-mouse-dialog.c 26560 2008-01-11 17:53:46Z nick $ */
+/*
+ * Copyright 2005 Pasi Orovuo <[EMAIL PROTECTED]>
+ * Copyright 2005 Brian Tarricone <[EMAIL PROTECTED]>
+ * Copyright 2008 Nick Schermer <[EMAIL PROTECTED]>
+ *
+ * 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 <string.h>
+#include <math.h>
+
+#include <X11/Xlib.h>
+#include <X11/Xcursor/Xcursor.h>
+#include <gdk/gdkx.h>
+
+#include "xfce-mouse-themes.h"
+
+#define BORDER          (6)
+#define PREVIEW_ROWS    (3)
+#define PREVIEW_COLUMNS (6)
+#define PREVIEW_SIZE    (24)
+#define PREVIEW_SPACING (2)
+
+
+
+static void xfce_mouse_themes_class_init (XfceMouseThemesClass *klass);
+static void xfce_mouse_themes_init (XfceMouseThemes *box);
+static void xfce_mouse_themes_finalize (GObject *object);
+static void xfce_mouse_themes_populate_store (GtkListStore *store);
+static void xfce_mouse_themes_selection_changed (GtkTreeSelection *selection, 
XfceMouseThemes *box);
+static void xfce_mouse_themes_write_config (XfceMouseThemes *box);
+static GdkPixbuf *xfce_mouse_themes_pixbuf_from_filename (const gchar 
*filename, gint size);
+static GdkPixbuf *xfce_mouse_themes_preview_icon (const gchar *path);
+static void xfce_mouse_themes_preview_image (const gchar *path, GtkWidget 
*image);
+
+
+enum
+{
+  COLUMN_THEME_PIXBUF,
+  COLUMN_THEME_PATH,
+  COLUMN_THEME_NAME,
+  COLUMN_THEME_REAL_NAME,
+  COLUMN_THEME_COMMENT,
+  N_THEME_COLUMNS
+};
+
+
+
+static const gchar *preview_names[] = {
+  "left_ptr",            "left_ptr_watch",    "watch",             "hand2",
+  "question_arrow",      "sb_h_double_arrow", "sb_v_double_arrow", 
"bottom_left_corner",
+  "bottom_right_corner", "fleur",             "pirate",            "cross",
+  "X_cursor",            "right_ptr",         "right_side",        "right_tee",
+  "sb_right_arrow",      "sb_right_tee",      "base_arrow_down",   
"base_arrow_up",
+  "bottom_side",         "bottom_tee",        "center_ptr",        "circle",
+  "dot",                 "dot_box_mask",      "dot_box_mask",      
"double_arrow",
+  "draped_box",          "left_side",         "left_tee",          "ll_angle",
+  "top_side",            "top_tee"
+};
+
+
+
+struct _XfceMouseThemesClass
+{
+  GtkHBoxClass __parent__;
+};
+
+struct _XfceMouseThemes
+{
+  GtkHBox __parent__;
+
+  /* box widgets */
+  GtkWidget *treeview;
+  GtkWidget *size;
+  GtkWidget *image;
+};
+
+
+
+G_DEFINE_TYPE (XfceMouseThemes, xfce_mouse_themes, GTK_TYPE_HBOX);
+
+
+
+static void
+xfce_mouse_themes_class_init (XfceMouseThemesClass *klass)
+{
+  GObjectClass   *gobject_class;
+
+  gobject_class = G_OBJECT_CLASS (klass);
+  gobject_class->finalize = xfce_mouse_themes_finalize;
+}
+
+
+
+static void
+xfce_mouse_themes_init (XfceMouseThemes *box)
+{
+  GtkWidget         *scroll;
+  GtkWidget         *treeview;
+  GtkTreeViewColumn *column;
+  GtkCellRenderer   *renderer;
+  GtkListStore      *store;
+  GtkWidget         *vbox;
+  GtkWidget         *image;
+  GtkWidget         *frame;
+  GtkWidget         *hbox;
+  GtkWidget         *label;
+  GtkWidget         *button;
+  GtkTreeSelection  *selection;
+
+  gtk_box_set_spacing (GTK_BOX (box), BORDER * 2);
+  gtk_container_set_border_width (GTK_CONTAINER (box), BORDER);
+
+  scroll = gtk_scrolled_window_new (NULL, NULL);
+  gtk_box_pack_start (GTK_BOX (box), scroll, TRUE, TRUE, 0);
+  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll), 
GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
+  gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scroll), 
GTK_SHADOW_IN);
+  gtk_widget_show (scroll);
+
+  store = gtk_list_store_new (N_THEME_COLUMNS, GDK_TYPE_PIXBUF, G_TYPE_STRING, 
G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING);
+  gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store), 
COLUMN_THEME_REAL_NAME, GTK_SORT_ASCENDING);
+
+  xfce_mouse_themes_populate_store (store);
+
+  treeview = box->treeview = gtk_tree_view_new_with_model (GTK_TREE_MODEL 
(store));
+  gtk_container_add (GTK_CONTAINER (scroll), treeview);
+  gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (treeview), FALSE);
+#if GTK_CHECK_VERSION (2, 12, 0)
+  gtk_tree_view_set_tooltip_column (GTK_TREE_VIEW (treeview), 
COLUMN_THEME_COMMENT);
+#endif
+  gtk_widget_show (treeview);
+
+  /* release store */
+  g_object_unref (G_OBJECT (store));
+
+  renderer = gtk_cell_renderer_pixbuf_new ();
+  column = gtk_tree_view_column_new_with_attributes ("", renderer, "pixbuf", 
COLUMN_THEME_PIXBUF, NULL);
+  gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
+
+  renderer = gtk_cell_renderer_text_new ();
+  column = gtk_tree_view_column_new_with_attributes ("", renderer, "text", 
COLUMN_THEME_REAL_NAME, NULL);
+  g_object_set (G_OBJECT (renderer), "ellipsize", PANGO_ELLIPSIZE_END, NULL);
+  gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
+
+  vbox = gtk_vbox_new (FALSE, BORDER);
+  gtk_box_pack_start (GTK_BOX (box), vbox, FALSE, FALSE, 0);
+  gtk_widget_show (vbox);
+
+  hbox = gtk_hbox_new (FALSE, BORDER);
+  gtk_widget_show (hbox);
+
+  frame = xfce_gtk_frame_box_new_with_content (_("Size"), hbox);
+  gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
+  gtk_widget_show (frame);
+
+  label = gtk_label_new_with_mnemonic (_("Cursor _size:"));
+  gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
+  gtk_widget_show (label);
+
+  button = box->size = gtk_spin_button_new_with_range (8, 64, 1);
+  gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
+  gtk_label_set_mnemonic_widget (GTK_LABEL (label), button);
+  gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (button), TRUE);
+  g_signal_connect_swapped (G_OBJECT (button), "value-changed", G_CALLBACK 
(xfce_mouse_themes_write_config), box);
+  gtk_widget_show (button);
+
+  image = box->image = gtk_image_new ();
+  gtk_widget_show (image);
+
+  frame = xfce_gtk_frame_box_new_with_content (_("Preview"), image);
+  gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
+  gtk_widget_show (frame);
+
+  selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview));
+  gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
+  g_signal_connect (G_OBJECT (selection), "changed", G_CALLBACK 
(xfce_mouse_themes_selection_changed), box);
+}
+
+
+
+static void
+xfce_mouse_themes_finalize (GObject *object)
+{
+  (*G_OBJECT_CLASS (xfce_mouse_themes_parent_class)->finalize) (object);
+}
+
+
+
+static void
+xfce_mouse_themes_populate_store (GtkListStore *store)
+{
+  const gchar  *path;
+  gchar       **basedirs;
+  gint          i;
+  gchar        *homedir;
+  GDir         *dir;
+  const gchar  *theme;
+  gchar        *filename;
+  gchar        *index_file;
+  XfceRc       *rc;
+  const gchar  *name;
+  const gchar  *comment;
+  GtkTreeIter   iter;
+  gint          position = 0;
+  GdkPixbuf    *pixbuf;
+
+  /* get the cursor paths */
+#if XCURSOR_LIB_MAJOR == 1 && XCURSOR_LIB_MINOR < 1
+  path = 
"~/.icons:/usr/share/icons:/usr/share/pixmaps:/usr/X11R6/lib/X11/icons";
+#else
+  path = XcursorLibraryPath ();
+#endif
+
+  /* split the paths */
+  basedirs = g_strsplit (path, ":", -1);
+
+  if (G_LIKELY (basedirs))
+    {
+      /* walk the base directories */
+      for (i = 0; basedirs[i] != NULL; i++)
+        {
+          /* init */
+          homedir = NULL;
+
+          /* parse the homedir if needed */
+          if (strstr (basedirs[i], "~/") != NULL)
+            path = homedir = g_strconcat (g_get_home_dir (), basedirs[i] + 1, 
NULL);
+          else
+            path = basedirs[i];
+
+          /* open directory */
+          dir = g_dir_open (path, 0, NULL);
+          if (G_LIKELY (dir))
+            {
+              for (;;)
+                {
+                  /* get the directory name */
+                  theme = g_dir_read_name (dir);
+                  if (G_UNLIKELY (theme == NULL))
+                    break;
+
+                  /* build the full cursor path */
+                  filename = g_build_filename (path, theme, "cursors", NULL);
+
+                  /* check if it looks like a cursor theme */
+                  if (g_file_test (filename, G_FILE_TEST_IS_DIR))
+                    {
+                      /* try to load a pixbuf */
+                      pixbuf = xfce_mouse_themes_preview_icon (filename);
+
+                      /* insert in the store */
+                      gtk_list_store_insert_with_values (store, &iter, 
position++,
+                                                         COLUMN_THEME_PIXBUF, 
pixbuf,
+                                                         COLUMN_THEME_NAME, 
theme,
+                                                         
COLUMN_THEME_REAL_NAME, theme,
+                                                         COLUMN_THEME_PATH, 
filename, -1);
+
+                      /* release pixbuf */
+                      if (G_LIKELY (pixbuf))
+                        g_object_unref (G_OBJECT (pixbuf));
+
+                      /* check for a index.theme file for additional 
information */
+                      index_file = g_build_filename (path, theme, 
"index.theme", NULL);
+                      if (g_file_test (index_file, G_FILE_TEST_IS_REGULAR))
+                        {
+                          /* open theme desktop file */
+                          rc = xfce_rc_simple_open (index_file, TRUE);
+                          if (G_LIKELY (rc))
+                            {
+                              /* check for the theme group */
+                              if (xfce_rc_has_group (rc, "Icon Theme"))
+                                {
+                                  /* set group */
+                                  xfce_rc_set_group (rc, "Icon Theme");
+
+                                  /* read values */
+                                  name = xfce_rc_read_entry (rc, "Name", 
theme);
+                                  comment = xfce_rc_read_entry (rc, "Comment", 
NULL);
+
+                                  /* update store */
+                                  gtk_list_store_set (store, &iter,
+                                                      COLUMN_THEME_REAL_NAME, 
name,
+                                                      COLUMN_THEME_COMMENT, 
comment, -1);
+                                }
+
+                              /* close rc file */
+                              xfce_rc_close (rc);
+                            }
+                        }
+
+                      /* cleanup */
+                      g_free (index_file);
+                    }
+
+                  /* cleanup */
+                  g_free (filename);
+                }
+
+              /* close directory */
+              g_dir_close (dir);
+            }
+
+          /* cleanup */
+          g_free (homedir);
+        }
+
+      /* cleanup */
+      g_strfreev (basedirs);
+    }
+}
+
+
+
+static void
+xfce_mouse_themes_selection_changed (GtkTreeSelection *selection,
+                                     XfceMouseThemes  *box)
+{
+  GtkTreeModel *model;
+  GtkTreeIter   iter;
+  gboolean      has_selection;
+  gchar        *path;
+
+  has_selection = gtk_tree_selection_get_selected (selection, &model, &iter);
+  if (G_LIKELY (has_selection))
+    {
+      /* get theme information from model */
+      gtk_tree_model_get (model, &iter, COLUMN_THEME_PATH, &path, -1);
+
+      /* update the preview widget */
+      xfce_mouse_themes_preview_image (path, box->image);
+
+      /* write configuration */
+      xfce_mouse_themes_write_config (box);
+
+      /* cleanup */
+      g_free (path);
+    }
+}
+
+
+
+static void
+xfce_mouse_themes_write_config (XfceMouseThemes *box)
+{
+  GtkTreeSelection *selection;
+  GtkTreeModel     *model;
+  GtkTreeIter       iter;
+  gboolean          has_selection;
+  gchar            *theme;
+  gchar            *filename;
+  gint              size;
+  gchar            *contents;
+  GError           *error = NULL;
+  gchar            *command;
+
+  /* get the selected theme */
+  selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (box->treeview));
+  has_selection = gtk_tree_selection_get_selected (selection, &model, &iter);
+  if (G_LIKELY (has_selection))
+    {
+      /* get theme information from model */
+      gtk_tree_model_get (model, &iter, COLUMN_THEME_NAME, &theme, -1);
+
+      /* get the cursor size */
+      size = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (box->size));
+
+      /* get the xrdb config filename */
+      filename = xfce_resource_save_location (XFCE_RESOURCE_CONFIG, 
"xfce4/Xcursor.xrdb", TRUE);
+      if (G_LIKELY (filename))
+        {
+          /* generate the file contents */
+          contents = g_strdup_printf ("Xcursor.theme: %s\n"
+                                      "Xcursor.theme_core: true\n"
+                                      "Xcursor.size: %d\n", theme, size);
+
+          /* write the contents to the file */
+          if (G_LIKELY (g_file_set_contents (filename, contents, -1, &error)))
+            {
+              /* create command to merge with the x resource database */
+              command = g_strdup_printf ("xrdb -nocpp -merge \"%s\"", 
filename);
+
+              /* run the command */
+              if (G_UNLIKELY (g_spawn_command_line_async (command, &error) == 
FALSE))
+                {
+                  /* print warning */
+                  g_critical (_("Failed to run xrdb: %s."), error->message);
+
+                  /* cleanup */
+                  g_error_free (error);
+                }
+
+              /* cleanup */
+              g_free (command);
+            }
+          else
+            {
+              /* print warning */
+              g_critical (_("Failed to write to \"%s\": %s."), filename, 
error->message);
+
+              /* cleanup */
+              g_error_free (error);
+            }
+
+          /* cleanup */
+          g_free (contents);
+          g_free (filename);
+        }
+      else
+        {
+          /* print warning */
+          g_critical (_("Failed to create \"%s\"."), 
"~/.config/xfce4/Xcursor.xrdb");
+        }
+
+      /* cleanup */
+      g_free (theme);
+    }
+}
+
+
+
+static GdkPixbuf *
+xfce_mouse_themes_pixbuf_from_filename (const gchar *filename,
+                                        gint         size)
+{
+  XcursorImage *image;
+  GdkPixbuf    *scaled, *pixbuf = NULL;
+  gsize         bsize;
+  guchar       *buffer, *p, tmp;
+  gdouble       wratio, hratio;
+  gint          dest_width, dest_height;
+
+  /* load the image */
+  image = XcursorFilenameLoadImage (filename, size);
+  if (G_LIKELY (image))
+    {
+      /* buffer size */
+      bsize = image->width * image->height * 4;
+
+      /* allocate buffer */
+      buffer = g_malloc (bsize);
+
+      /* copy pixel data to buffer */
+      memcpy (buffer, image->pixels, bsize);
+
+      /* swap bits */
+      for (p = buffer; p < buffer + bsize; p += 4)
+        {
+          tmp = p[0];
+          p[0] = p[2];
+          p[2] = tmp;
+        }
+
+      /* create pixbuf */
+      pixbuf = gdk_pixbuf_new_from_data (buffer, GDK_COLORSPACE_RGB, TRUE,
+                                         8, image->width, image->height,
+                                         4 * image->width,
+                                         (GdkPixbufDestroyNotify) g_free, 
NULL);
+
+      /* don't leak when creating the pixbuf failed */
+      if (G_UNLIKELY (pixbuf == NULL))
+        g_free (buffer);
+
+      /* scale pixbuf if needed */
+      if (pixbuf && (image->height > size || image->width > size))
+        {
+          /* calculate the ratio */
+          wratio = (gdouble) image->width / (gdouble) size;
+          hratio = (gdouble) image->height / (gdouble) size;
+
+          /* init */
+          dest_width = dest_height = size;
+
+          /* set dest size */
+          if (hratio > wratio)
+            dest_width  = rint (image->width / hratio);
+          else
+            dest_height = rint (image->height / wratio);
+
+          /* scale pixbuf */
+          scaled = gdk_pixbuf_scale_simple (pixbuf, MAX (dest_width, 1), MAX 
(dest_height, 1), GDK_INTERP_BILINEAR);
+
+          /* release and set scaled pixbuf */
+          g_object_unref (G_OBJECT (pixbuf));
+          pixbuf = scaled;
+        }
+
+      /* cleanup */
+      XcursorImageDestroy (image);
+    }
+
+  return pixbuf;
+}
+
+
+
+static GdkPixbuf *
+xfce_mouse_themes_preview_icon (const gchar *path)
+{
+  GdkPixbuf *pixbuf = NULL;
+  gchar     *filename;
+
+  /* we only try the normal cursor, it is (most likely) always there */
+  filename = g_build_filename (path, "left_ptr", NULL);
+
+  /* try to load the pixbuf */
+  pixbuf = xfce_mouse_themes_pixbuf_from_filename (filename, PREVIEW_SIZE);
+
+  /* cleanup */
+  g_free (filename);
+
+  return pixbuf;
+}
+
+
+
+static void
+xfce_mouse_themes_preview_image (const gchar *path,
+                                 GtkWidget   *image)
+{
+  GdkPixbuf *pixbuf;
+  GdkPixbuf *preview;
+  gint       i, position;
+  gchar     *filename;
+  gint       dest_x, dest_y;
+
+  /* create an empty preview image */
+  preview = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8,
+                            (PREVIEW_SIZE + PREVIEW_SPACING) * PREVIEW_COLUMNS 
- PREVIEW_SPACING,
+                            (PREVIEW_SIZE + PREVIEW_SPACING) * PREVIEW_ROWS - 
PREVIEW_SPACING);
+
+  if (G_LIKELY (preview))
+    {
+      /* make the pixbuf transparent */
+      gdk_pixbuf_fill (preview, 0x00000000);
+
+      for (i = 0, position = 0; i < G_N_ELEMENTS (preview_names); i++)
+        {
+          /* create cursor filename and try to load the pixbuf */
+          filename = g_build_filename (path, preview_names[i], NULL);
+          pixbuf = xfce_mouse_themes_pixbuf_from_filename (filename, 
PREVIEW_SIZE);
+          g_free (filename);
+
+          if (G_LIKELY (pixbuf))
+            {
+              /* calculate the icon position */
+              dest_x = (position % PREVIEW_COLUMNS) * (PREVIEW_SIZE + 
PREVIEW_SPACING);
+              dest_y = (position / PREVIEW_COLUMNS) * (PREVIEW_SIZE + 
PREVIEW_SPACING);
+
+              /* render it in the preview */
+              gdk_pixbuf_scale (pixbuf, preview, dest_x, dest_y,
+                                gdk_pixbuf_get_width (pixbuf),
+                                gdk_pixbuf_get_height (pixbuf),
+                                dest_x, dest_y,
+                                1.00, 1.00, GDK_INTERP_BILINEAR);
+
+
+              /* release the pixbuf */
+              g_object_unref (G_OBJECT (pixbuf));
+
+              /* break if we've added enough icons */
+              if (++position >= PREVIEW_ROWS * PREVIEW_COLUMNS)
+                break;
+            }
+        }
+
+      /* set the image */
+      gtk_image_set_from_pixbuf (GTK_IMAGE (image), preview);
+
+      /* release the pixbuf */
+      g_object_unref (G_OBJECT (preview));
+    }
+  else
+    {
+      /* clear the image */
+      gtk_image_clear (GTK_IMAGE (image));
+    }
+}
+
+
+
+GtkWidget *
+xfce_mouse_themes_new (void)
+{
+  return g_object_new (XFCE_TYPE_MOUSE_THEMES, NULL);
+}

Added: xfce-mcs-plugins/branches/multi_device/xfce-mouse-themes.h
===================================================================
--- xfce-mcs-plugins/branches/multi_device/xfce-mouse-themes.h                  
        (rev 0)
+++ xfce-mcs-plugins/branches/multi_device/xfce-mouse-themes.h  2008-04-10 
10:24:38 UTC (rev 26813)
@@ -0,0 +1,44 @@
+/* $Id: xfce-mouse-dialog.h 26560 2008-01-11 17:53:46Z nick $ */
+/*
+ * Copyright 2008 Nick Schermer <[EMAIL PROTECTED]>
+ *
+ * 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
+ */
+
+#ifndef __XFCE_MOUSE_THEMES_H__
+#define __XFCE_MOUSE_THEMES_H__
+
+#include <libxfce4ui/libxfce4ui.h>
+#include <libxfce4util/libxfce4util.h>
+
+G_BEGIN_DECLS
+
+#define XFCE_TYPE_MOUSE_THEMES            (xfce_mouse_themes_get_type ())
+#define XFCE_MOUSE_THEMES(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), 
XFCE_TYPE_MOUSE_THEMES, XfceMouseThemes))
+#define XFCE_MOUSE_THEMES_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), 
XFCE_TYPE_MOUSE_THEMES, XfceMouseThemesClass))
+#define XFCE_IS_MOUSE_THEMES(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), 
XFCE_TYPE_MOUSE_THEMES))
+#define XFCE_IS_MOUSE_THEMES_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), 
XFCE_TYPE_MOUSE_THEMES))
+#define XFCE_MOUSE_THEMES_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), 
XFCE_TYPE_MOUSE_THEMES, XfceMouseThemesClass))
+
+typedef struct _XfceMouseThemesClass XfceMouseThemesClass;
+typedef struct _XfceMouseThemes      XfceMouseThemes;
+
+GType      xfce_mouse_themes_get_type (void) G_GNUC_CONST;
+
+GtkWidget *xfce_mouse_themes_new      (void);
+
+G_END_DECLS
+
+#endif /* !__XFCE_MOUSE_THEMES_H__ */

Added: xfce-mcs-plugins/branches/multi_device/xfce-settings-display
===================================================================
(Binary files differ)


Property changes on: 
xfce-mcs-plugins/branches/multi_device/xfce-settings-display
___________________________________________________________________
Name: svn:executable
   + *
Name: svn:mime-type
   + application/octet-stream

Added: xfce-mcs-plugins/branches/multi_device/xfce-settings-mouse
===================================================================
(Binary files differ)


Property changes on: xfce-mcs-plugins/branches/multi_device/xfce-settings-mouse
___________________________________________________________________
Name: svn:executable
   + *
Name: svn:mime-type
   + application/octet-stream

_______________________________________________
Xfce4-commits mailing list
Xfce4-commits@xfce.org
http://foo-projects.org/mailman/listinfo/xfce4-commits

Reply via email to