[Xfce4-commits] [panel-plugins/xfce4-xkb-plugin] 03/17: Add xfconf support

noreply at xfce.org noreply at xfce.org
Sat Jun 10 14:31:36 CEST 2017


This is an automated email from the git hooks/post-receive script.

n   i   n   e   t   l   s       p   u   s   h   e   d       a       c   o   m   m   i   t       t   o       b   r   a   n   c   h       m   a   s   t   e   r   
   in repository panel-plugins/xfce4-xkb-plugin.

commit 0f72f634988fe39eb9e07ec1803e2310957a50cb
Author: Viktor Odintsev <zakhams at gmail.com>
Date:   Wed Mar 15 22:06:11 2017 +0300

    Add xfconf support
---
 configure.ac.in                                    |   1 +
 panel-plugin/Makefile.am                           |   8 +-
 panel-plugin/xfce4-xkb-plugin.c                    | 155 ++++---------
 panel-plugin/xfce4-xkb-plugin.h                    |  20 +-
 panel-plugin/xkb-cairo.c                           |  15 +-
 panel-plugin/xkb-cairo.h                           |   5 +-
 panel-plugin/xkb-callbacks.c                       |  13 +-
 panel-plugin/xkb-config.h                          |   7 +-
 ...xfce4-xkb-plugin-private.h => xkb-properties.h} |  30 ++-
 panel-plugin/xkb-settings-dialog.c                 | 102 ++++-----
 panel-plugin/xkb-xfconf.c                          | 244 +++++++++++++++++++++
 panel-plugin/xkb-xfconf.h                          |  53 +++++
 12 files changed, 432 insertions(+), 221 deletions(-)

diff --git a/configure.ac.in b/configure.ac.in
index 933982d..4581ac1 100644
--- a/configure.ac.in
+++ b/configure.ac.in
@@ -75,6 +75,7 @@ XDT_CHECK_PACKAGE([GTK], [gtk+-3.0], [3.20.0])
 XDT_CHECK_PACKAGE([LIBXFCE4PANEL], [libxfce4panel-2.0], [4.12.0])
 XDT_CHECK_PACKAGE([LIBXFCE4UTIL], [libxfce4util-1.0], [4.12.0])
 XDT_CHECK_PACKAGE([LIBXFCE4UI], [libxfce4ui-2], [4.12.0])
+XDT_CHECK_PACKAGE([XFCONF], [libxfconf-0], [4.12.1])
 XDT_CHECK_PACKAGE([LIBXKLAVIER], [libxklavier], [5.4])
 XDT_CHECK_PACKAGE([LIBRSVG], [librsvg-2.0], [2.40])
 XDT_CHECK_PACKAGE([LIBWNCK], [libwnck-3.0], [3.14])
diff --git a/panel-plugin/Makefile.am b/panel-plugin/Makefile.am
index dc33005..b31f23f 100644
--- a/panel-plugin/Makefile.am
+++ b/panel-plugin/Makefile.am
@@ -8,7 +8,6 @@ plugin_LTLIBRARIES = \
 
 libxkb_la_SOURCES = \
 	xfce4-xkb-plugin.h \
-	xfce4-xkb-plugin-private.h \
 	xfce4-xkb-plugin.c \
 	xkb-settings-dialog.h \
 	xkb-settings-dialog.c \
@@ -19,7 +18,10 @@ libxkb_la_SOURCES = \
 	xkb-cairo.h \
 	xkb-cairo.c \
 	xkb-callbacks.h \
-	xkb-callbacks.c
+	xkb-callbacks.c \
+	xkb-properties.h \
+	xkb-xfconf.h \
+	xkb-xfconf.c
 
 libxkb_la_CPPFLAGS = \
 	-I$(top_srcdir) \
@@ -30,6 +32,7 @@ libxkb_la_CFLAGS = \
 	$(LIBXFCE4PANEL_CFLAGS) \
 	$(LIBXFCE4UTIL_CFLAGS) \
 	$(LIBXFCE4UI_CFLAGS) \
+	$(XFCONF_CFLAGS) \
 	$(LIBXKLAVIER_CFLAGS) \
 	$(LIBRSVG_CFLAGS) \
 	$(LIBWNCK_CFLAGS) \
@@ -50,6 +53,7 @@ libxkb_la_LIBADD = \
 	$(LIBXFCE4PANEL_LIBS) \
 	$(LIBXFCE4UTIL_LIBS) \
 	$(LIBXFCE4UI_LIBS) \
+	$(XFCONF_LIBS) \
 	$(LIBXKLAVIER_LIBS) \
 	$(LIBWNCK_LIBS) \
 	$(GARCON_LIBS) \
diff --git a/panel-plugin/xfce4-xkb-plugin.c b/panel-plugin/xfce4-xkb-plugin.c
index f3670de..8f59431 100644
--- a/panel-plugin/xfce4-xkb-plugin.c
+++ b/panel-plugin/xfce4-xkb-plugin.c
@@ -36,14 +36,11 @@
 #include <garcon/garcon.h>
 
 #include "xfce4-xkb-plugin.h"
-#include "xfce4-xkb-plugin-private.h"
 #include "xkb-settings-dialog.h"
 #include "xkb-util.h"
 #include "xkb-cairo.h"
 #include "xkb-callbacks.h"
-
-#define DISPLAY_TEXTSCALE_LARGE 100
-#define DISPLAY_IMGSCALE_LARGE  100
+#include "xkb-properties.h"
 
 /* ------------------------------------------------------------------ *
  *                     Panel Plugin Interface                         *
@@ -74,18 +71,20 @@ static gboolean     xkb_calculate_sizes                 (t_xkb *xkb,
                                                          GtkOrientation orientation,
                                                          gint panel_size);
 
-static gboolean     xkb_load_config                     (t_xkb *xkb,
-                                                         const gchar *filename);
-
-static void         xkb_load_default                    (t_xkb *xkb);
-
 static void         xkb_populate_popup_menu             (t_xkb *xkb);
 
 static void         xkb_destroy_popup_menu              (t_xkb *xkb);
 
+static void         xkb_refresh_gui                     (t_xkb *xkb);
+
 static void         xfce_xkb_configure_layout           (GtkWidget *widget,
                                                          gpointer user_data);
 
+static void         xkb_plugin_display_type_changed     (t_xkb *xkb);
+
+static void         xkb_plugin_display_scale_changed    (t_xkb *xkb);
+
+static void         xkb_plugin_group_policy_changed     (t_xkb *xkb);
 
 /* ================================================================== *
  *                        Implementation                              *
@@ -116,9 +115,6 @@ xfce_xkb_construct (XfcePanelPlugin *plugin)
     g_signal_connect (plugin, "free-data",
             G_CALLBACK (xfce_xkb_free_data), xkb);
 
-    g_signal_connect (plugin, "save",
-            G_CALLBACK (xfce_xkb_save_config), xkb);
-
     xfce_panel_plugin_menu_show_configure (plugin);
     g_signal_connect (plugin, "configure-plugin",
             G_CALLBACK (xfce_xkb_configure), xkb);
@@ -199,19 +195,19 @@ static t_xkb *
 xkb_new (XfcePanelPlugin *plugin)
 {
     t_xkb *xkb;
-    gchar *filename;
     WnckScreen *wnck_screen;
     GtkCssProvider *css_provider;
 
     xkb = panel_slice_new0 (t_xkb);
     xkb->plugin = plugin;
 
-    filename = xfce_panel_plugin_lookup_rc_file (plugin);
-    if ((!filename) || (!xkb_load_config (xkb, filename)))
-    {
-        xkb_load_default (xkb);
-    }
-    g_free (filename);
+    xkb->config = xkb_xfconf_new (xfce_panel_plugin_get_property_base (plugin));
+    g_signal_connect_swapped (G_OBJECT (xkb->config), "notify::" DISPLAY_TYPE,
+            G_CALLBACK (xkb_plugin_display_type_changed), xkb);
+    g_signal_connect_swapped (G_OBJECT (xkb->config), "notify::" DISPLAY_SCALE,
+            G_CALLBACK (xkb_plugin_display_scale_changed), xkb);
+    g_signal_connect_swapped (G_OBJECT (xkb->config), "notify::" GROUP_POLICY,
+            G_CALLBACK (xkb_plugin_group_policy_changed), xkb);
 
     xkb->btn = gtk_button_new ();
     gtk_button_set_relief (GTK_BUTTON (xkb->btn), GTK_RELIEF_NONE);
@@ -241,7 +237,7 @@ xkb_new (XfcePanelPlugin *plugin)
             G_CALLBACK (xkb_plugin_layout_image_draw), xkb);
     gtk_widget_show (GTK_WIDGET (xkb->layout_image));
 
-    if (xkb_config_initialize (xkb->group_policy, xkb_state_changed, xkb))
+    if (xkb_config_initialize (xkb_xfconf_get_group_policy (xkb->config), xkb_state_changed, xkb))
     {
         xkb_refresh_gui (xkb);
         xkb_populate_popup_menu (xkb);
@@ -267,88 +263,9 @@ xkb_free (t_xkb *xkb)
     gtk_widget_destroy (xkb->btn);
     xkb_destroy_popup_menu (xkb);
 
-    panel_slice_free (t_xkb, xkb);
-}
-
-void
-xfce_xkb_save_config (XfcePanelPlugin *plugin, t_xkb *xkb)
-{
-    gchar* filename;
-    XfceRc* rcfile;
-
-
-    filename = xfce_panel_plugin_save_location (plugin, TRUE);
-    if (!filename)
-        return;
-
-
-    rcfile = xfce_rc_simple_open (filename, FALSE);
-    if (!rcfile)
-    {
-        g_free (filename);
-        return;
-    }
-
-    xfce_rc_set_group (rcfile, NULL);
-
-    xfce_rc_write_int_entry (rcfile, "display_type", xkb->display_type);
-    xfce_rc_write_int_entry (rcfile, "display_textscale", xkb->display_text_scale);
-    xfce_rc_write_int_entry (rcfile, "display_imgscale", xkb->display_img_scale);
-    xfce_rc_write_int_entry (rcfile, "group_policy", xkb->group_policy);
-
-    xfce_rc_close (rcfile);
-    g_free (filename);
-}
-
-static gboolean
-xkb_load_config (t_xkb *xkb, const gchar *filename)
-{
-    XfceRc* rcfile;
-    gint text_scale;
-
-    if ((rcfile = xfce_rc_simple_open (filename, TRUE)))
-    {
-        xfce_rc_set_group (rcfile, NULL);
-
-        xkb->display_type = xfce_rc_read_int_entry (rcfile, "display_type", DISPLAY_TYPE_IMAGE);
-        text_scale = xfce_rc_read_int_entry (rcfile, "display_textscale", -1);
-        if (text_scale < 0)
-        {
-            /* Check if the old textsize value is there */
-            text_scale = xfce_rc_read_int_entry (rcfile, "display_textsize", -1);
-            switch (text_scale)
-            {
-            case DISPLAY_TEXTSIZE_SMALL:
-                text_scale = 47;
-                break;
-            case DISPLAY_TEXTSIZE_MEDIUM:
-                text_scale = 70;
-                break;
-            case DISPLAY_TEXTSIZE_LARGE:
-            default:
-                text_scale = DISPLAY_TEXTSCALE_LARGE;
-                break;
-            }
-        }
-        xkb->display_text_scale = text_scale;
-        xkb->display_img_scale = xfce_rc_read_int_entry (rcfile, "display_imgscale", DISPLAY_IMGSCALE_LARGE);
-        xkb->group_policy = xfce_rc_read_int_entry (rcfile, "group_policy", GROUP_POLICY_PER_APPLICATION);
-
-        xfce_rc_close (rcfile);
-
-        return TRUE;
-    }
-
-    return FALSE;
-}
+    g_object_unref (G_OBJECT (xkb->config));
 
-static void
-xkb_load_default (t_xkb *xkb)
-{
-    xkb->display_type       = DISPLAY_TYPE_IMAGE;
-    xkb->display_text_scale = DISPLAY_TEXTSCALE_LARGE;
-    xkb->display_img_scale  = DISPLAY_IMGSCALE_LARGE;
-    xkb->group_policy       = GROUP_POLICY_PER_APPLICATION;
+    panel_slice_free (t_xkb, xkb);
 }
 
 static gboolean
@@ -357,10 +274,12 @@ xkb_calculate_sizes (t_xkb *xkb, GtkOrientation orientation, gint panel_size)
     guint nrows;
     gint hsize, vsize;
     gboolean proportional;
+    guint display_type;
 
-    nrows       = xfce_panel_plugin_get_nrows (xkb->plugin);
+    display_type = xkb_xfconf_get_display_type (xkb->config);
+    nrows = xfce_panel_plugin_get_nrows (xkb->plugin);
     panel_size /= nrows;
-    proportional = nrows > 1 || xkb->display_type == DISPLAY_TYPE_SYSTEM;
+    proportional = nrows > 1 || display_type == DISPLAY_TYPE_SYSTEM;
     TRACE ("calculate_sizes(%p: %d,%d)", xkb, panel_size, nrows);
 
     switch (orientation)
@@ -472,7 +391,7 @@ xkb_populate_popup_menu (t_xkb *xkb)
     }
 }
 
-void
+static void
 xkb_refresh_gui (t_xkb *xkb)
 {
     GdkDisplay * display;
@@ -491,14 +410,6 @@ xkb_refresh_gui (t_xkb *xkb)
     }
 }
 
-void
-xkb_refresh_gui_and_size (t_xkb *xkb)
-{
-    xkb_calculate_sizes (xkb,
-            xfce_panel_plugin_get_orientation (xkb->plugin),
-            xfce_panel_plugin_get_size (xkb->plugin));
-}
-
 static void
 xfce_xkb_configure_layout (GtkWidget *widget,
                            gpointer user_data)
@@ -527,3 +438,23 @@ xfce_xkb_configure_layout (GtkWidget *widget,
     }
     g_free (desktop_file);
 }
+
+static void
+xkb_plugin_display_type_changed (t_xkb *xkb)
+{
+    xkb_calculate_sizes (xkb,
+            xfce_panel_plugin_get_orientation (xkb->plugin),
+            xfce_panel_plugin_get_size (xkb->plugin));
+}
+
+static void
+xkb_plugin_display_scale_changed (t_xkb *xkb)
+{
+    xkb_refresh_gui (xkb);
+}
+
+static void
+xkb_plugin_group_policy_changed (t_xkb *xkb)
+{
+    xkb_config_set_group_policy (xkb_xfconf_get_group_policy (xkb->config));
+}
diff --git a/panel-plugin/xfce4-xkb-plugin.h b/panel-plugin/xfce4-xkb-plugin.h
index 2b1ecbb..614f1b4 100644
--- a/panel-plugin/xfce4-xkb-plugin.h
+++ b/panel-plugin/xfce4-xkb-plugin.h
@@ -27,6 +27,7 @@
 #define _XFCE_XKB_H_
 
 #include "xkb-config.h"
+#include "xkb-xfconf.h"
 
 #include <libxfce4util/libxfce4util.h>
 #include <libxfce4ui/libxfce4ui.h>
@@ -36,28 +37,11 @@
 #include <gtk/gtk.h>
 #include <glib.h>
 
-typedef enum
-{
-    DISPLAY_TYPE_IMAGE = 0,
-    DISPLAY_TYPE_TEXT = 1,
-    DISPLAY_TYPE_SYSTEM = 2
-} t_display_type;
-
-typedef enum
-{
-    DISPLAY_TEXTSIZE_SMALL = 0,
-    DISPLAY_TEXTSIZE_MEDIUM = 1,
-    DISPLAY_TEXTSIZE_LARGE = 2
-} t_display_textsize;
-
 typedef struct
 {
     XfcePanelPlugin *plugin;
 
-    t_display_type display_type;  /* display layout as image ot text */
-    guint display_text_scale; /* text scale % for text layout */
-    guint display_img_scale;  /* image scale % for flag layout */
-    t_group_policy group_policy;     /* per-app/window/global policy */
+    XkbXfconf *config;
 
     /* widgets */
     GtkWidget *btn;
diff --git a/panel-plugin/xkb-cairo.c b/panel-plugin/xkb-cairo.c
index 21deea5..c0b8387 100644
--- a/panel-plugin/xkb-cairo.c
+++ b/panel-plugin/xkb-cairo.c
@@ -38,8 +38,7 @@ xkb_cairo_draw_flag (cairo_t *cr,
                      gint actual_height,
                      gint variant_markers_count,
                      guint max_variant_markers_count,
-                     guint img_scale,
-                     guint text_scale,
+                     guint scale,
                      GdkRGBA rgba)
 {
     gchar *filename;
@@ -65,7 +64,7 @@ xkb_cairo_draw_flag (cairo_t *cr,
         xkb_cairo_draw_label (cr, group_name,
                 actual_width, actual_height,
                 variant_markers_count,
-                text_scale,
+                scale,
                 rgba);
         return;
     }
@@ -75,8 +74,8 @@ xkb_cairo_draw_flag (cairo_t *cr,
     scalex = (double) (actual_width - 4) / dim.width;
     scaley = (double) (actual_height - 4) / dim.height;
 
-    scalex *= img_scale / 100.0;
-    scaley *= img_scale / 100.0;
+    scalex *= scale / 100.0;
+    scaley *= scale / 100.0;
 
     img_width  = dim.width * scalex;
     img_height = dim.height * scaley;
@@ -165,7 +164,7 @@ xkb_cairo_draw_label (cairo_t *cr,
                       const gint actual_width,
                       const gint actual_height,
                       const gint variant_markers_count,
-                      const guint text_scale,
+                      const guint scale,
                       const GdkRGBA rgba)
 {
     gchar *normalized_group_name;
@@ -204,7 +203,7 @@ xkb_cairo_draw_label (cairo_t *cr,
     pango_layout_get_pixel_size (layout, &pango_width, &pango_height);
     DBG ("pango_width/height: %d/%d", pango_width, pango_height);
 
-    scalex = scaley = text_scale / 100.0;
+    scalex = scaley = scale / 100.0;
 
     DBG ("txt size scale x/y: %.2f/%.2f", scalex, scaley);
 
@@ -218,7 +217,7 @@ xkb_cairo_draw_label (cairo_t *cr,
     {
         text_width = actual_width - 3 - (variant_markers_count) * diameter;
     }
-    else if (text_scale >= 99.5)
+    else if (scale >= 99.5)
     {
         text_width -= 3;
     }
diff --git a/panel-plugin/xkb-cairo.h b/panel-plugin/xkb-cairo.h
index e9c77b9..b08b1e3 100644
--- a/panel-plugin/xkb-cairo.h
+++ b/panel-plugin/xkb-cairo.h
@@ -38,8 +38,7 @@ void        xkb_cairo_draw_flag         (cairo_t *cr,
                                          gint actual_height,
                                          gint variant_markers_count,
                                          guint max_variant_markers_count,
-                                         guint img_scale,
-                                         guint text_scale,
+                                         guint scale,
                                          GdkRGBA rgba);
 
 void        xkb_cairo_draw_label        (cairo_t *cr,
@@ -47,7 +46,7 @@ void        xkb_cairo_draw_label        (cairo_t *cr,
                                          const gint actual_width,
                                          const gint actual_height,
                                          const gint variant_markers_count,
-                                         const guint text_scale,
+                                         const guint scale,
                                          const GdkRGBA rgba);
 
 void        xkb_cairo_draw_label_system (cairo_t *cr,
diff --git a/panel-plugin/xkb-callbacks.c b/panel-plugin/xkb-callbacks.c
index 0071dd3..de8902d 100644
--- a/panel-plugin/xkb-callbacks.c
+++ b/panel-plugin/xkb-callbacks.c
@@ -82,6 +82,10 @@ xkb_plugin_layout_image_draw (GtkWidget *widget,
     PangoFontDescription *desc;
     GdkRGBA rgba;
     gint actual_hsize, actual_vsize;
+    gint display_type, display_scale;
+
+    display_type = xkb_xfconf_get_display_type (xkb->config);
+    display_scale = xkb_xfconf_get_display_scale (xkb->config);
 
     gtk_widget_get_allocation (GTK_WIDGET (widget), &allocation);
     actual_hsize = allocation.width;
@@ -95,23 +99,22 @@ xkb_plugin_layout_image_draw (GtkWidget *widget,
     DBG ("img_exposed: actual h/v (%d/%d)",
          actual_hsize, actual_vsize);
 
-    if (xkb->display_type == DISPLAY_TYPE_IMAGE)
+    if (display_type == DISPLAY_TYPE_IMAGE)
     {
         xkb_cairo_draw_flag (cr, group_name,
                 actual_hsize, actual_vsize,
                 xkb_config_variant_index_for_group (-1),
                 xkb_config_get_max_group_count (),
-                xkb->display_img_scale,
-                xkb->display_text_scale,
+                display_scale,
                 rgba
         );
     }
-    else if (xkb->display_type == DISPLAY_TYPE_TEXT)
+    else if (display_type == DISPLAY_TYPE_TEXT)
     {
         xkb_cairo_draw_label (cr, group_name,
                 actual_hsize, actual_vsize,
                 xkb_config_variant_index_for_group (-1),
-                xkb->display_text_scale,
+                display_scale,
                 rgba
         );
     }
diff --git a/panel-plugin/xkb-config.h b/panel-plugin/xkb-config.h
index 072adca..c06cd16 100644
--- a/panel-plugin/xkb-config.h
+++ b/panel-plugin/xkb-config.h
@@ -35,12 +35,7 @@
 #include <gdk/gdk.h>
 #include <libxklavier/xklavier.h>
 
-typedef enum
-{
-    GROUP_POLICY_GLOBAL     = 0,
-    GROUP_POLICY_PER_WINDOW     = 1,
-    GROUP_POLICY_PER_APPLICATION    = 2
-} t_group_policy;
+#include "xkb-properties.h"
 
 typedef void        (*XkbCallback)                  (gint current_group,
                                                      gboolean groups_changed,
diff --git a/panel-plugin/xfce4-xkb-plugin-private.h b/panel-plugin/xkb-properties.h
similarity index 66%
rename from panel-plugin/xfce4-xkb-plugin-private.h
rename to panel-plugin/xkb-properties.h
index 98468dc..960fc6e 100644
--- a/panel-plugin/xfce4-xkb-plugin-private.h
+++ b/panel-plugin/xkb-properties.h
@@ -1,10 +1,10 @@
 /* vim: set backspace=2 ts=4 softtabstop=4 sw=4 cinoptions=>4 expandtab autoindent smartindent: */
-/* xfce4-xkb-plugin-private.h
+/* xkb-properties.h
  * Copyright (C) 2008 Alexander Iliev <sasoiliev at mamul.org>
  *
  * Parts of this program comes from the XfKC tool:
  * Copyright (C) 2006 Gauvain Pocentek <gauvainpocentek at gmail.com>
- * 
+ *
  * A part of this file comes from the gnome keyboard capplet (control-center):
  * Copyright (C) 2003 Sergey V. Oudaltsov <svu at users.sourceforge.net>
  *
@@ -23,15 +23,29 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
-#ifndef _XFCE_XKB_PRIVATE_H_
-#define _XFCE_XKB_PRIVATE_H_
+#ifndef _XKB_PROPERTIES_H_
+#define _XKB_PROPERTIES_H_
+
+#define DISPLAY_TYPE "display-type"
+#define DISPLAY_SCALE "display-scale"
+#define GROUP_POLICY "group-policy"
 
-void            xfce_xkb_save_config        (XfcePanelPlugin *plugin,
-                                             t_xkb *xkb);
+typedef enum
+{
+    DISPLAY_TYPE_IMAGE              = 0,
+    DISPLAY_TYPE_TEXT               = 1,
+    DISPLAY_TYPE_SYSTEM             = 2
+} t_display_type;
 
-void            xkb_refresh_gui             (t_xkb *xkb);
+#define DISPLAY_SCALE_MIN             0
+#define DISPLAY_SCALE_MAX             100
 
-void            xkb_refresh_gui_and_size    (t_xkb *xkb);
+typedef enum
+{
+    GROUP_POLICY_GLOBAL             = 0,
+    GROUP_POLICY_PER_WINDOW         = 1,
+    GROUP_POLICY_PER_APPLICATION    = 2
+} t_group_policy;
 
 #endif
 
diff --git a/panel-plugin/xkb-settings-dialog.c b/panel-plugin/xkb-settings-dialog.c
index 0c1d5ea..e370eae 100644
--- a/panel-plugin/xkb-settings-dialog.c
+++ b/panel-plugin/xkb-settings-dialog.c
@@ -35,7 +35,6 @@
 #include <libxfce4ui/libxfce4ui.h>
 
 #include "xfce4-xkb-plugin.h"
-#include "xfce4-xkb-plugin-private.h"
 #include "xkb-settings-dialog.h"
 #include "xkb-util.h"
 
@@ -43,6 +42,12 @@ GtkTreeIter current_iter;
 GtkWidget *settings_dialog;
 GtkWidget *default_layout_menu;
 
+typedef struct
+{
+    t_xkb *xkb;
+    GtkWidget *display_scale_range;
+} DialogInstance;
+
 enum combo_enum
 {
     DESC = 0,
@@ -69,41 +74,19 @@ enum enumeration
 /**************************************************************/
 
 static void
-on_settings_close (GtkDialog *dialog, gint response, t_xkb *xkb)
+on_settings_close (GtkDialog *dialog, gint response, DialogInstance *instance)
 {
-    xfce_panel_plugin_unblock_menu (xkb->plugin);
-
-    xfce_xkb_save_config (xkb->plugin, xkb);
-
+    xfce_panel_plugin_unblock_menu (instance->xkb->plugin);
     gtk_widget_destroy (GTK_WIDGET (dialog));
+    g_free (instance);
 }
 
 static void
-on_display_type_changed (GtkComboBox *cb, t_xkb *xkb)
+on_display_type_changed (GtkComboBox *cb, DialogInstance *instance)
 {
-    xkb->display_type = gtk_combo_box_get_active (cb);
-    xkb_refresh_gui_and_size (xkb);
-}
-
-static void
-on_display_textsize_changed (GtkHScale *scale, t_xkb *xkb)
-{
-    xkb->display_text_scale = gtk_range_get_value (GTK_RANGE (scale));
-    xkb_refresh_gui (xkb);
-}
-
-static void
-on_display_imgsize_changed (GtkHScale *scale, t_xkb *xkb)
-{
-    xkb->display_img_scale = gtk_range_get_value (GTK_RANGE (scale));
-    xkb_refresh_gui (xkb);
-}
-
-static void
-on_group_policy_changed (GtkComboBox *cb, t_xkb *xkb)
-{
-    xkb->group_policy = gtk_combo_box_get_active (cb);
-    xkb_config_set_group_policy (xkb->group_policy);
+    gint active = gtk_combo_box_get_active (cb);
+    gtk_widget_set_sensitive (instance->display_scale_range,
+            active == DISPLAY_TYPE_IMAGE || active == DISPLAY_TYPE_TEXT);
 }
 
 void
@@ -112,11 +95,14 @@ xfce_xkb_configure (XfcePanelPlugin *plugin,
 {
     GtkWidget *display_type_optmenu, *group_policy_combo;
     GtkWidget *vbox, *display_type_frame, *group_policy_frame, *bin;
-    GtkWidget *display_textsize_frame, *display_textsize_scale;
-    GtkWidget *display_imgsize_frame, *display_imgsize_scale;
+    GtkWidget *display_scale_frame, *display_scale_range;
+    DialogInstance *instance;
 
     xfce_panel_plugin_block_menu (plugin);
 
+    instance = g_new0 (DialogInstance, 1);
+    instance->xkb = xkb;
+
     settings_dialog = xfce_titled_dialog_new_with_buttons (_("Keyboard Layouts"),
             NULL, 0, "gtk-close", GTK_RESPONSE_OK, NULL);
     gtk_window_set_icon_name (GTK_WINDOW (settings_dialog), "xfce4-settings");
@@ -142,25 +128,16 @@ xfce_xkb_configure (XfcePanelPlugin *plugin,
     gtk_widget_set_size_request (display_type_optmenu, 230, -1);
     gtk_container_add (GTK_CONTAINER (bin), display_type_optmenu);
 
-    /* text size option */
-    display_textsize_frame = xfce_gtk_frame_box_new (_("Text size:"), &bin);
-    gtk_widget_show (display_textsize_frame);
-    gtk_box_pack_start (GTK_BOX (vbox), display_textsize_frame, TRUE, TRUE, 2);
-
-    display_textsize_scale = gtk_scale_new_with_range (GTK_ORIENTATION_HORIZONTAL, 0, 100, 1);
-    gtk_scale_set_value_pos (GTK_SCALE (display_textsize_scale), GTK_POS_RIGHT);
-    gtk_widget_set_size_request (display_textsize_scale, 230, -1);
-    gtk_container_add (GTK_CONTAINER (bin), display_textsize_scale);
-
-    /* image size option */
-    display_imgsize_frame = xfce_gtk_frame_box_new (_("Image size:"), &bin);
-    gtk_widget_show (display_imgsize_frame);
-    gtk_box_pack_start (GTK_BOX (vbox), display_imgsize_frame, TRUE, TRUE, 2);
+    display_scale_frame = xfce_gtk_frame_box_new (_("Widget size:"), &bin);
+    gtk_widget_show (display_scale_frame);
+    gtk_box_pack_start (GTK_BOX (vbox), display_scale_frame, TRUE, TRUE, 2);
 
-    display_imgsize_scale = gtk_scale_new_with_range (GTK_ORIENTATION_HORIZONTAL, 0, 100, 1);
-    gtk_scale_set_value_pos (GTK_SCALE (display_imgsize_scale), GTK_POS_RIGHT);
-    gtk_widget_set_size_request (display_imgsize_scale, 230, -1);
-    gtk_container_add (GTK_CONTAINER (bin), display_imgsize_scale);
+    display_scale_range = gtk_scale_new_with_range (GTK_ORIENTATION_HORIZONTAL,
+            DISPLAY_SCALE_MIN, DISPLAY_SCALE_MAX, 1);
+    instance->display_scale_range = display_scale_range;
+    gtk_scale_set_value_pos (GTK_SCALE (display_scale_range), GTK_POS_RIGHT);
+    gtk_widget_set_size_request (display_scale_range, 230, -1);
+    gtk_container_add (GTK_CONTAINER (bin), display_scale_range);
 
     group_policy_frame = xfce_gtk_frame_box_new (_("Manage layout:"), &bin);
     gtk_widget_show (group_policy_frame);
@@ -177,17 +154,24 @@ xfce_xkb_configure (XfcePanelPlugin *plugin,
     gtk_widget_show_all (vbox);
 
     g_signal_connect ((gpointer) settings_dialog, "response",
-            G_CALLBACK (on_settings_close), xkb);
+            G_CALLBACK (on_settings_close), instance);
+
+    /* enable or disable display_scale_range depending on display type */
+    g_signal_connect (display_type_optmenu, "changed",
+            G_CALLBACK (on_display_type_changed), instance);
+    on_display_type_changed (GTK_COMBO_BOX (display_type_optmenu), instance);
+
+    g_object_bind_property (G_OBJECT (xkb->config), DISPLAY_TYPE,
+            G_OBJECT (display_type_optmenu),
+            "active", G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);
 
-    gtk_combo_box_set_active (GTK_COMBO_BOX (display_type_optmenu), xkb->display_type);
-    gtk_range_set_value (GTK_RANGE (display_textsize_scale), xkb->display_text_scale);
-    gtk_range_set_value (GTK_RANGE (display_imgsize_scale), xkb->display_img_scale);
-    gtk_combo_box_set_active (GTK_COMBO_BOX (group_policy_combo), xkb->group_policy);
+    g_object_bind_property (G_OBJECT (xkb->config), DISPLAY_SCALE,
+            G_OBJECT (gtk_range_get_adjustment (GTK_RANGE (display_scale_range))),
+            "value", G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);
 
-    g_signal_connect (display_type_optmenu, "changed", G_CALLBACK (on_display_type_changed), xkb);
-    g_signal_connect (group_policy_combo, "changed", G_CALLBACK (on_group_policy_changed), xkb);
-    g_signal_connect (display_textsize_scale, "value_changed", G_CALLBACK (on_display_textsize_changed), xkb);
-    g_signal_connect (display_imgsize_scale, "value_changed", G_CALLBACK (on_display_imgsize_changed), xkb);
+    g_object_bind_property (G_OBJECT (xkb->config), GROUP_POLICY,
+            G_OBJECT (group_policy_combo),
+            "active", G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);
 
     gtk_widget_show (settings_dialog);
 }
diff --git a/panel-plugin/xkb-xfconf.c b/panel-plugin/xkb-xfconf.c
new file mode 100644
index 0000000..9ade5fd
--- /dev/null
+++ b/panel-plugin/xkb-xfconf.c
@@ -0,0 +1,244 @@
+/* vim: set backspace=2 ts=4 softtabstop=4 sw=4 cinoptions=>4 expandtab autoindent smartindent: */
+/* xkb-xfconf.c
+ * Copyright (C) 2008 Alexander Iliev <sasoiliev at mamul.org>
+ *
+ * Parts of this program comes from the XfKC tool:
+ * Copyright (C) 2006 Gauvain Pocentek <gauvainpocentek at gmail.com>
+ *
+ * A part of this file comes from the gnome keyboard capplet (control-center):
+ * Copyright (C) 2003 Sergey V. Oudaltsov <svu at users.sourceforge.net>
+ *
+ * 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, 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., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "xkb-properties.h"
+#include "xkb-xfconf.h"
+
+#include <string.h>
+
+#include <xfconf/xfconf.h>
+
+#define DEFAULT_DISPLAY_TYPE                DISPLAY_TYPE_IMAGE
+#define DEFAULT_DISPLAY_SCALE               DISPLAY_SCALE_MAX
+#define DEFAULT_GROUP_POLICY                GROUP_POLICY_PER_APPLICATION
+
+static void            xkb_xfconf_finalize            (GObject          *object);
+static void            xkb_xfconf_get_property        (GObject          *object,
+                                                       guint             prop_id,
+                                                       GValue           *value,
+                                                       GParamSpec       *pspec);
+static void            xkb_xfconf_set_property        (GObject          *object,
+                                                       guint             prop_id,
+                                                       const GValue     *value,
+                                                       GParamSpec       *pspec);
+
+struct _XkbXfconfClass
+{
+    GObjectClass __parent__;
+};
+
+struct _XkbXfconf
+{
+    GObject __parent__;
+
+    guint display_type;
+    guint display_scale;
+    guint group_policy;
+};
+
+enum
+{
+    PROP_0,
+    PROP_DISPLAY_TYPE,
+    PROP_DISPLAY_SCALE,
+    PROP_GROUP_POLICY,
+    N_PROPERTIES,
+};
+
+enum
+{
+    CONFIGURATION_CHANGED,
+    LAST_SIGNAL
+};
+
+static guint xkb_xfconf_signals [LAST_SIGNAL] = { NULL, };
+
+G_DEFINE_TYPE (XkbXfconf, xkb_xfconf, G_TYPE_OBJECT)
+
+static void
+xkb_xfconf_class_init (XkbXfconfClass *klass)
+{
+    GObjectClass *gobject_class;
+
+    gobject_class = G_OBJECT_CLASS (klass);
+    gobject_class->finalize = xkb_xfconf_finalize;
+    gobject_class->get_property = xkb_xfconf_get_property;
+    gobject_class->set_property = xkb_xfconf_set_property;
+
+    g_object_class_install_property (gobject_class, PROP_DISPLAY_TYPE,
+            g_param_spec_uint (DISPLAY_TYPE, NULL, NULL,
+                    DISPLAY_TYPE_IMAGE, DISPLAY_TYPE_SYSTEM, DEFAULT_DISPLAY_TYPE,
+                    G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
+    g_object_class_install_property (gobject_class, PROP_DISPLAY_SCALE,
+            g_param_spec_uint (DISPLAY_SCALE, NULL, NULL,
+                    DISPLAY_SCALE_MIN, DISPLAY_SCALE_MAX, DEFAULT_DISPLAY_SCALE,
+                    G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
+    g_object_class_install_property (gobject_class, PROP_GROUP_POLICY,
+            g_param_spec_uint (GROUP_POLICY, NULL, NULL,
+                    GROUP_POLICY_GLOBAL, GROUP_POLICY_PER_APPLICATION, DEFAULT_GROUP_POLICY,
+                    G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
+    xkb_xfconf_signals[CONFIGURATION_CHANGED] =
+            g_signal_new (g_intern_static_string ("configuration-changed"),
+                    G_TYPE_FROM_CLASS (gobject_class),
+                    G_SIGNAL_RUN_LAST,
+                    0, NULL, NULL,
+                    g_cclosure_marshal_VOID__VOID,
+                    G_TYPE_NONE, 0);
+}
+
+static void
+xkb_xfconf_init (XkbXfconf *config)
+{
+    config->display_type = DEFAULT_DISPLAY_TYPE;
+    config->display_scale = DEFAULT_DISPLAY_SCALE;
+    config->group_policy = DEFAULT_GROUP_POLICY;
+}
+
+static void
+xkb_xfconf_finalize (GObject *object)
+{
+    xfconf_shutdown ();
+    G_OBJECT_CLASS (xkb_xfconf_parent_class)->finalize (object);
+}
+
+static void
+xkb_xfconf_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
+{
+    XkbXfconf *config = XKB_XFCONF (object);
+
+    switch (prop_id)
+    {
+        case PROP_DISPLAY_TYPE:
+            g_value_set_uint (value, config->display_type);
+            break;
+        case PROP_DISPLAY_SCALE:
+            g_value_set_uint (value, config->display_scale);
+            break;
+        case PROP_GROUP_POLICY:
+            g_value_set_uint (value, config->group_policy);
+            break;
+        default:
+            G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+            break;
+    }
+}
+
+static void
+xkb_xfconf_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
+{
+    XkbXfconf *config = XKB_XFCONF (object);
+    guint val_uint;
+
+    switch (prop_id)
+    {
+        case PROP_DISPLAY_TYPE:
+            val_uint = g_value_get_uint (value);
+            if (config->display_type != val_uint)
+            {
+                config->display_type = val_uint;
+                g_object_notify (G_OBJECT (config), DISPLAY_TYPE);
+                g_signal_emit (G_OBJECT (config), xkb_xfconf_signals [CONFIGURATION_CHANGED], 0);
+            }
+            break;
+        case PROP_DISPLAY_SCALE:
+            val_uint = g_value_get_uint (value);
+            if (config->display_scale != val_uint)
+            {
+                config->display_scale = val_uint;
+                g_object_notify (G_OBJECT (config), DISPLAY_SCALE);
+                g_signal_emit (G_OBJECT (config), xkb_xfconf_signals [CONFIGURATION_CHANGED], 0);
+            }
+            break;
+        case PROP_GROUP_POLICY:
+            val_uint = g_value_get_uint (value);
+            if (config->group_policy != val_uint)
+            {
+                config->group_policy = val_uint;
+                g_object_notify (G_OBJECT (config), GROUP_POLICY);
+                g_signal_emit (G_OBJECT (config), xkb_xfconf_signals [CONFIGURATION_CHANGED], 0);
+            }
+            break;
+        default:
+            G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+            break;
+    }
+}
+
+guint
+xkb_xfconf_get_display_type (XkbXfconf *config)
+{
+    g_return_val_if_fail (IS_XKB_XFCONF (config), DEFAULT_DISPLAY_TYPE);
+    return config->display_type;
+}
+
+guint
+xkb_xfconf_get_display_scale (XkbXfconf *config)
+{
+    g_return_val_if_fail (IS_XKB_XFCONF (config), DEFAULT_DISPLAY_SCALE);
+    return config->display_scale;
+}
+
+guint
+xkb_xfconf_get_group_policy (XkbXfconf *config)
+{
+    g_return_val_if_fail (IS_XKB_XFCONF (config), DEFAULT_GROUP_POLICY);
+    return config->group_policy;
+}
+
+XkbXfconf *
+xkb_xfconf_new (const gchar *property_base)
+{
+    XkbXfconf *config;
+    XfconfChannel *channel;
+    gchar *property;
+
+    config = g_object_new (TYPE_XKB_XFCONF, NULL);
+
+    if (xfconf_init (NULL))
+    {
+        channel = xfconf_channel_get ("xfce4-panel");
+
+        property = g_strconcat (property_base, "/" DISPLAY_TYPE, NULL);
+        xfconf_g_property_bind (channel, property, G_TYPE_UINT, config, DISPLAY_TYPE);
+        g_free (property);
+
+        property = g_strconcat (property_base, "/" DISPLAY_SCALE, NULL);
+        xfconf_g_property_bind (channel, property, G_TYPE_UINT, config, DISPLAY_SCALE);
+        g_free (property);
+
+        property = g_strconcat (property_base, "/" GROUP_POLICY, NULL);
+        xfconf_g_property_bind (channel, property, G_TYPE_UINT, config, GROUP_POLICY);
+        g_free (property);
+    }
+
+    return config;
+}
diff --git a/panel-plugin/xkb-xfconf.h b/panel-plugin/xkb-xfconf.h
new file mode 100644
index 0000000..c1e8603
--- /dev/null
+++ b/panel-plugin/xkb-xfconf.h
@@ -0,0 +1,53 @@
+/* vim: set backspace=2 ts=4 softtabstop=4 sw=4 cinoptions=>4 expandtab autoindent smartindent: */
+/* xkb-xfconf.h
+ * Copyright (C) 2008 Alexander Iliev <sasoiliev at mamul.org>
+ *
+ * Parts of this program comes from the XfKC tool:
+ * Copyright (C) 2006 Gauvain Pocentek <gauvainpocentek at gmail.com>
+ *
+ * A part of this file comes from the gnome keyboard capplet (control-center):
+ * Copyright (C) 2003 Sergey V. Oudaltsov <svu at users.sourceforge.net>
+ *
+ * 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, 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., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#ifndef _XKB_XFCONF_H_
+#define _XKB_XFCONF_H_
+
+#include <gdk/gdk.h>
+
+G_BEGIN_DECLS
+
+typedef struct _XkbXfconfClass      XkbXfconfClass;
+typedef struct _XkbXfconf           XkbXfconf;
+
+#define TYPE_XKB_XFCONF             (xkb_xfconf_get_type ())
+#define XKB_XFCONF(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_XKB_XFCONF, XkbXfconf))
+#define XKB_XFCONF_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST ((klass),  TYPE_XKB_XFCONF, XkbXfconfClass))
+#define IS_XKB_XFCONF(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_XKB_XFCONF))
+#define IS_XKB_XFCONF_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE ((klass),  TYPE_XKB_XFCONF))
+#define XKB_XFCONF_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj),  TYPE_XKB_XFCONF, XkbXfconfClass))
+
+GType           xkb_xfconf_get_type                        (void)                           G_GNUC_CONST;
+
+XkbXfconf      *xkb_xfconf_new                             (const gchar   *property_base);
+
+guint           xkb_xfconf_get_display_type                (XkbXfconf     *config);
+guint           xkb_xfconf_get_display_scale               (XkbXfconf     *config);
+guint           xkb_xfconf_get_group_policy                (XkbXfconf     *config);
+
+G_END_DECLS
+
+#endif

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list