[Xfce4-commits] <xfce4-clipman-plugin:master> QR-code encoder (bug 9528)

Mike Massonnet noreply at xfce.org
Sun Feb 2 16:36:01 CET 2014


Updating branch refs/heads/master
         to 4218a5125dc45e5df27b37ce5684317a738c464a (commit)
       from a5f5e091ab58eb639d321ebcd69a75079c1d1122 (commit)

commit 4218a5125dc45e5df27b37ce5684317a738c464a
Author: Christian Hesse <mail at eworm.de>
Date:   Thu Jul 4 22:43:39 2013 +0200

    QR-code encoder (bug 9528)
    
    Optional build, requires libqrencode >= 3.3.

 configure.ac.in                       |   11 +++
 panel-plugin/Makefile.am              |    2 +
 panel-plugin/common.h                 |    1 +
 panel-plugin/menu.c                   |  128 +++++++++++++++++++++++++++++++++
 panel-plugin/plugin.c                 |    5 ++
 panel-plugin/settings-dialog.ui       |   15 ++++
 panel-plugin/xfce4-clipman-settings.c |   10 +++
 7 files changed, 172 insertions(+)

diff --git a/configure.ac.in b/configure.ac.in
index f73924a..98159ec 100644
--- a/configure.ac.in
+++ b/configure.ac.in
@@ -81,6 +81,16 @@ else
 	enable_unique=no
 fi
 
+dnl *****************************
+dnl *** Check for libqrencode ***
+dnl *****************************
+XDT_CHECK_OPTIONAL_PACKAGE([QRENCODE], [libqrencode], [3.3.0], libqrencode, [QR Code support])
+if test x"$QRENCODE_FOUND" = x"yes"; then
+	enable_qrencode=yes
+else
+	enable_qrencode=no
+fi
+
 dnl *******************************
 dnl *** Check for documentation ***
 dnl *******************************
@@ -148,6 +158,7 @@ echo "Build Configuration:"
 echo
 echo "    * Debug Support:    $enable_debug"
 echo "    * Unique:           $enable_unique"
+echo "    * QR Code:          $enable_qrencode"
 echo
 if test "x$USE_MAINTAINER_MODE" = "xyes" ; then
 echo "Enable Documentation: $enable_gen_doc"
diff --git a/panel-plugin/Makefile.am b/panel-plugin/Makefile.am
index d3c1259..554455a 100644
--- a/panel-plugin/Makefile.am
+++ b/panel-plugin/Makefile.am
@@ -115,6 +115,7 @@ xfce4_clipman_LDADD =							\
 	@LIBXFCE4UTIL_LIBS@						\
 	@LIBXFCE4UI_LIBS@						\
 	@XFCONF_LIBS@							\
+	@QRENCODE_LIBS@							\
 	$(NULL)
 
 #
@@ -169,6 +170,7 @@ libclipman_la_LIBADD =							\
 	@LIBXFCE4UI_LIBS@						\
 	@LIBXFCE4PANEL_LIBS@						\
 	@XFCONF_LIBS@							\
+	@QRENCODE_LIBS@
 	$(NULL)
 
 #
diff --git a/panel-plugin/common.h b/panel-plugin/common.h
index 6b5fe0e..de5b17c 100644
--- a/panel-plugin/common.h
+++ b/panel-plugin/common.h
@@ -30,6 +30,7 @@
 #define DEFAULT_REORDER_ITEMS                           TRUE
 #define DEFAULT_SKIP_ACTION_ON_KEY_DOWN                 FALSE
 #define DEFAULT_ADD_PRIMARY_CLIPBOARD                   FALSE
+#define DEFAULT_SHOW_QR_CODE                            FALSE
 #define DEFAULT_HISTORY_IGNORE_PRIMARY_CLIPBOARD        TRUE
 #define DEFAULT_ENABLE_ACTIONS                          FALSE
 
diff --git a/panel-plugin/menu.c b/panel-plugin/menu.c
index bf4ae9e..a1af28b 100644
--- a/panel-plugin/menu.c
+++ b/panel-plugin/menu.c
@@ -28,6 +28,10 @@
 #include <X11/extensions/XTest.h>
 #include <X11/keysym.h>
 
+#ifdef HAVE_QRENCODE
+#include <qrencode.h>
+#endif
+
 #include "common.h"
 #include "collector.h"
 #include "history.h"
@@ -48,6 +52,9 @@ struct _ClipmanMenuPrivate
   ClipmanHistory       *history;
   GSList               *list;
   gboolean              reverse_order;
+#ifdef HAVE_QRENCODE
+  gboolean              show_qr_code;
+#endif
   guint                 paste_on_activate;
   gboolean              never_confirm_history_clear;
 };
@@ -55,6 +62,9 @@ struct _ClipmanMenuPrivate
 enum
 {
   REVERSE_ORDER = 1,
+#ifdef HAVE_QRENCODE
+  SHOW_QR_CODE,
+#endif
   PASTE_ON_ACTIVATE,
   NEVER_CONFIRM_HISTORY_CLEAR,
 };
@@ -68,6 +78,10 @@ static void             clipman_menu_get_property       (GObject *object,
                                                          guint property_id,
                                                          GValue *value,
                                                          GParamSpec *pspec);
+#ifdef HAVE_QRENCODE
+GdkPixbuf *             clipman_menu_qrcode             (char *text);
+#endif
+
 
 /*
  * Private methods declarations
@@ -79,6 +93,10 @@ static void            _clipman_menu_free_list          (ClipmanMenu *menu);
  * Callbacks declarations
  */
 
+#ifdef HAVE_QRENCODE
+static void		cb_set_qrcode                   (GtkMenuItem *mi,
+                                                         const GdkPixbuf *pixbuf);
+#endif
 static void             cb_set_clipboard                (GtkMenuItem *mi,
                                                          const ClipmanHistoryItem *item);
 static void             cb_clear_history                (ClipmanMenu *menu);
@@ -89,6 +107,28 @@ static void             cb_clear_history                (ClipmanMenu *menu);
  * Callbacks
  */
 
+#ifdef HAVE_QRENCODE
+static void
+cb_set_qrcode (GtkMenuItem *mi, const GdkPixbuf *pixbuf)
+{
+  GtkClipboard *clipboard;
+  ClipmanCollector *collector;
+  ClipmanHistory *history;
+
+  collector = clipman_collector_get ();
+  clipman_collector_set_is_restoring (collector);
+  g_object_unref (collector);
+
+  history = clipman_history_get ();
+  clipman_history_add_image (history, pixbuf);
+
+  clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
+  gtk_clipboard_set_image (clipboard, GDK_PIXBUF (pixbuf));
+
+  g_object_unref (history);
+}
+#endif
+
 static void
 cb_set_clipboard (GtkMenuItem *mi, const ClipmanHistoryItem *item)
 {
@@ -235,6 +275,9 @@ static void
 _clipman_menu_update_list (ClipmanMenu *menu)
 {
   GtkWidget *mi, *image;
+#ifdef HAVE_QRENCODE
+  GdkPixbuf *pixbuf;
+#endif
   ClipmanHistoryItem *item;
   const ClipmanHistoryItem *item_to_restore;
   GSList *list, *l;
@@ -286,6 +329,37 @@ _clipman_menu_update_list (ClipmanMenu *menu)
       gtk_menu_shell_insert (GTK_MENU_SHELL (menu), mi, pos++);
       gtk_widget_show_all (mi);
     }
+
+#ifdef HAVE_QRENCODE
+  /* Draw QR Code if clipboard content is text */
+  if (menu->priv->show_qr_code && item_to_restore && item_to_restore->type == CLIPMAN_HISTORY_TYPE_TEXT)
+    {
+      mi = gtk_separator_menu_item_new ();
+      menu->priv->list = g_slist_prepend (menu->priv->list, mi);
+      gtk_menu_shell_insert (GTK_MENU_SHELL (menu), mi, pos++);
+      gtk_widget_show_all (mi);
+
+      if ((pixbuf = clipman_menu_qrcode (item_to_restore->content.text)) != NULL)
+        {
+          mi = gtk_image_menu_item_new ();
+          gtk_container_add (GTK_CONTAINER (mi), gtk_image_new_from_pixbuf (pixbuf));
+          g_signal_connect (mi, "activate", G_CALLBACK (cb_set_qrcode), pixbuf);
+          menu->priv->list = g_slist_prepend (menu->priv->list, mi);
+          gtk_menu_shell_insert (GTK_MENU_SHELL (menu), mi, pos++);
+          gtk_widget_show_all (mi);
+	  g_object_unref(pixbuf);
+        }
+      else
+        {
+          mi = gtk_menu_item_new_with_label (_("Could not generate QR-Code."));
+          menu->priv->list = g_slist_prepend (menu->priv->list, mi);
+          gtk_menu_shell_insert (GTK_MENU_SHELL (menu), mi, pos++);
+          gtk_widget_set_sensitive (mi, FALSE);
+          gtk_widget_show (mi);
+        }
+    }
+#endif
+
   g_slist_free (list);
 
   if (pos == 0)
@@ -347,6 +421,15 @@ clipman_menu_class_init (ClipmanMenuClass *klass)
                                                          FALSE,
                                                          G_PARAM_CONSTRUCT|G_PARAM_READWRITE));
 
+#ifdef HAVE_QRENCODE
+  g_object_class_install_property (object_class, SHOW_QR_CODE,
+                                   g_param_spec_boolean ("show-qr-code",
+                                                         "ShowQrCode",
+                                                         "Set to TRUE to display QR-Code in the menu",
+                                                         FALSE,
+                                                         G_PARAM_CONSTRUCT|G_PARAM_READWRITE));
+#endif
+
   g_object_class_install_property (object_class, PASTE_ON_ACTIVATE,
                                    g_param_spec_uint ("paste-on-activate",
                                                       "PasteOnActivate",
@@ -408,6 +491,12 @@ clipman_menu_set_property (GObject *object,
       priv->reverse_order = g_value_get_boolean (value);
       break;
 
+#ifdef HAVE_QRENCODE
+    case SHOW_QR_CODE:
+      priv->show_qr_code = g_value_get_boolean (value);
+      break;
+#endif
+
     case PASTE_ON_ACTIVATE:
       priv->paste_on_activate = g_value_get_uint (value);
       break;
@@ -448,3 +537,42 @@ clipman_menu_get_property (GObject *object,
     }
 }
 
+#ifdef HAVE_QRENCODE
+GdkPixbuf *
+clipman_menu_qrcode (char *text)
+{
+	QRcode *qrcode;
+	GdkPixbuf *pixbuf, *pixbuf_scaled;
+	int i, j, k, rowstride, channels;
+	guchar *pixel;
+	unsigned char *data;
+	
+	qrcode = QRcode_encodeString8bit(text, 0, QR_ECLEVEL_L);
+
+	if (qrcode == NULL)
+		return NULL;
+
+	data = qrcode->data;
+
+	pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, qrcode->width + 2, qrcode->width + 2);
+
+	pixel = gdk_pixbuf_get_pixels (pixbuf);
+	rowstride = gdk_pixbuf_get_rowstride (pixbuf);
+	channels = gdk_pixbuf_get_n_channels (pixbuf);
+
+	gdk_pixbuf_fill(pixbuf, 0xffffffff);
+	for (i = 1; i <= qrcode->width; i++)
+		for (j = 1; j <= qrcode->width; j++) {
+			for (k = 0; k < channels; k++)
+				pixel[i * rowstride + j * channels + k] = !(*data & 0x1) * 0xff;
+			data++;
+		}
+
+	pixbuf_scaled = gdk_pixbuf_scale_simple (pixbuf, (qrcode->width + 2) * 3, (qrcode->width + 2) * 3, GDK_INTERP_NEAREST);
+
+	QRcode_free(qrcode);
+	g_object_unref(pixbuf);
+	
+	return pixbuf_scaled;
+}
+#endif
diff --git a/panel-plugin/plugin.c b/panel-plugin/plugin.c
index 5f68fcf..81f37f6 100644
--- a/panel-plugin/plugin.c
+++ b/panel-plugin/plugin.c
@@ -113,6 +113,10 @@ plugin_register (void)
 
   /* ClipmanMenu */
   plugin->menu = clipman_menu_new ();
+#ifdef HAVE_QRENCODE
+  xfconf_g_property_bind (plugin->channel, "/settings/show-qr-code",
+                          G_TYPE_BOOLEAN, plugin->menu, "show-qr-code");
+#endif
   xfconf_g_property_bind (plugin->channel, "/tweaks/reverse-menu-order",
                           G_TYPE_BOOLEAN, plugin->menu, "reverse-order");
   xfconf_g_property_bind (plugin->channel, "/tweaks/paste-on-activate",
@@ -321,6 +325,7 @@ plugin_about (MyPlugin *plugin)
                              "",
                              _("Contributors:"),
                              "(c) 2008-2009 David Collins",
+			     "(c) 2013 Christian Hesse",
                              NULL, };
   const gchar *documenters[] = { "Mike Massonnet", NULL, };
   const gchar *license =
diff --git a/panel-plugin/settings-dialog.ui b/panel-plugin/settings-dialog.ui
index 7e4c6f1..a369607 100644
--- a/panel-plugin/settings-dialog.ui
+++ b/panel-plugin/settings-dialog.ui
@@ -70,6 +70,21 @@
                                 <property name="position">0</property>
                               </packing>
                             </child>
+                            <child>
+                              <object class="GtkCheckButton" id="show-qr-code">
+                                <property name="label" translatable="yes">Show _QR-Code</property>
+                                <property name="visible">True</property>
+                                <property name="can_focus">True</property>
+                                <property name="receives_default">False</property>
+                                <property name="has_tooltip">True</property>
+                                <property name="tooltip_text" translatable="yes">If checked, the menu shows a QR-Code of the corrently selected clipboard entry</property>
+                                <property name="use_underline">True</property>
+                                <property name="draw_indicator">True</property>
+                              </object>
+                              <packing>
+                                <property name="position">1</property>
+                              </packing>
+                            </child>
                           </object>
                         </child>
                       </object>
diff --git a/panel-plugin/xfce4-clipman-settings.c b/panel-plugin/xfce4-clipman-settings.c
index 6e87798..f7bb199 100644
--- a/panel-plugin/xfce4-clipman-settings.c
+++ b/panel-plugin/xfce4-clipman-settings.c
@@ -87,6 +87,12 @@ prop_dialog_run (void)
   /* General settings */
   gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (gtk_builder_get_object (builder, "add-selections")),
                                 DEFAULT_ADD_PRIMARY_CLIPBOARD);
+#ifdef HAVE_QRENCODE
+  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (gtk_builder_get_object (builder, "show-qr-code")),
+                                DEFAULT_SHOW_QR_CODE);
+#else
+  gtk_widget_hide(GTK_WIDGET (gtk_builder_get_object (builder, "show-qr-code")));
+#endif
   gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (gtk_builder_get_object (builder, "history-ignore-selections")),
                                 DEFAULT_HISTORY_IGNORE_PRIMARY_CLIPBOARD);
   gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (gtk_builder_get_object (builder, "save-on-quit")),
@@ -98,6 +104,10 @@ prop_dialog_run (void)
 
   xfconf_g_property_bind (xfconf_channel, "/settings/add-primary-clipboard", G_TYPE_BOOLEAN,
                           gtk_builder_get_object (builder, "add-selections"), "active");
+#ifdef HAVE_QRENCODE
+  xfconf_g_property_bind (xfconf_channel, "/settings/show-qr-code", G_TYPE_BOOLEAN,
+                          gtk_builder_get_object (builder, "show-qr-code"), "active");
+#endif
   xfconf_g_property_bind (xfconf_channel, "/settings/history-ignore-primary-clipboard", G_TYPE_BOOLEAN,
                           gtk_builder_get_object (builder, "history-ignore-selections"), "active");
   xfconf_g_property_bind (xfconf_channel, "/settings/save-on-quit", G_TYPE_BOOLEAN,


More information about the Xfce4-commits mailing list