From 1f5d51d9a21ad160c6686d0dd3906a74e051e6d9 Mon Sep 17 00:00:00 2001 From: NikoKrause Date: Mon, 5 Mar 2018 23:04:08 +0100 Subject: [PATCH] clipboard-qr@wrouesnel: Fix for Cinnamon 3.6 and use of QR icon (#1651) * clipboard-qr@wrousenel: code cleanup fix whitespaces and remove unused variables * clipboard-qr@wrousenel: use qr code icons Use a qr code symbolic icon as applet panel icon. Use icon.png (qr code) for the about dialog icon. * clipboard-qr@wrousenel: Update README Use code style for installation instructions of python-zbar * clipboard-qr@wrouesnel: fix for Cinnamon 3.6 clipboard.get_text and clipboard.set_text changed in Mint 18.3 (needs two arguments instead of one) Added a check of the Cinnamon version to keep compatibility for Cinnamon versions minor than 3.6 Fixes: https://github.com/linuxmint/cinnamon-spices-applets/issues/1590 Thanks @alex-t-grecu --- clipboard-qr@wrouesnel/README.md | 6 +- .../files/clipboard-qr@wrouesnel/applet.js | 137 ++++++++++-------- .../files/clipboard-qr@wrouesnel/icon.png | Bin 0 -> 2436 bytes .../icons/qr-symbolic.svg | 58 ++++++++ .../clipboard-qr@wrouesnel/metadata.json | 1 - clipboard-qr@wrouesnel/icon.png | Bin 2436 -> 37 bytes 6 files changed, 142 insertions(+), 60 deletions(-) create mode 100644 clipboard-qr@wrouesnel/files/clipboard-qr@wrouesnel/icon.png create mode 100644 clipboard-qr@wrouesnel/files/clipboard-qr@wrouesnel/icons/qr-symbolic.svg mode change 100644 => 120000 clipboard-qr@wrouesnel/icon.png diff --git a/clipboard-qr@wrouesnel/README.md b/clipboard-qr@wrouesnel/README.md index dfbdc482007..2e99f94cd1a 100644 --- a/clipboard-qr@wrouesnel/README.md +++ b/clipboard-qr@wrouesnel/README.md @@ -4,7 +4,11 @@ Easily move snippets of text between your phone and your desktop or laptop using This handy applet uses the python-zbar library to fully support scanning QR codes (and barcodes!) directly into your clipboard with the click of a button. -You will need to "sudo apt-get install python-zbar" for scanning functionality to work but that's ALL you'll need to do. +You will need to +``` +sudo apt-get install python-zbar +``` +for scanning functionality to work but that's ALL you'll need to do. This is a fork of the original Clipboard QR Code applet by ebbes, with the added scanning functionality and general patches to make it work on modern Cinnamon. diff --git a/clipboard-qr@wrouesnel/files/clipboard-qr@wrouesnel/applet.js b/clipboard-qr@wrouesnel/files/clipboard-qr@wrouesnel/applet.js index 796247cd92c..b0b9f6705f3 100644 --- a/clipboard-qr@wrouesnel/files/clipboard-qr@wrouesnel/applet.js +++ b/clipboard-qr@wrouesnel/files/clipboard-qr@wrouesnel/applet.js @@ -16,16 +16,12 @@ */ const Applet = imports.ui.applet; const Lang = imports.lang; -const Clutter = imports.gi.Clutter; const St = imports.gi.St; const PopupMenu = imports.ui.popupMenu; const GLib = imports.gi.GLib; const Gio = imports.gi.Gio; -const Gdk = imports.gi.Gdk; const GUdev = imports.gi.GUdev; -const Main = imports.ui.main; - const AppletDir = imports.ui.appletManager.appletMeta['clipboard-qr@wrouesnel'].path; imports.ui.searchPath.unshift(AppletDir); const QRLib = imports.ui.QR; @@ -37,7 +33,7 @@ const MAX_BYTES = 1048576; const Gettext = imports.gettext; const UUID = "clipboard-qr@wrouesnel"; -Gettext.bindtextdomain(UUID, GLib.get_home_dir() + "/.local/share/locale") +Gettext.bindtextdomain(UUID, GLib.get_home_dir() + "/.local/share/locale"); function _(str) { return Gettext.dgettext(UUID, str); @@ -50,42 +46,42 @@ function MyApplet(orientation) { MyApplet.prototype = { __proto__: Applet.IconApplet.prototype, - _init: function(orientation) { + _init: function(orientation) { Applet.IconApplet.prototype._init.call(this, orientation); - + try { // Holds the subprocess reference to a zbarimg this._qrprocess = null; - + this.menuManager = new PopupMenu.PopupMenuManager(this); this.menu = new Applet.AppletPopupMenu(this, orientation); - this.menuManager.addMenu(this.menu); + this.menuManager.addMenu(this.menu); this.set_applet_tooltip(_("Create QR code from clipboard")); - this.set_applet_icon_symbolic_name('edit-paste-symbolic'); + this.set_applet_icon_symbolic_name('qr-symbolic'); - // The QR code error string + // The QR code error string this._errorString = new PopupMenu.PopupMenuItem('', { reactive: false }); this.menu.addMenuItem(this._errorString); - + // The QR code main window this._maincontainer = new St.BoxLayout({ style_class: 'qrappletqrcode' }); this.menu.addActor(this._maincontainer); - + // Add a separator this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem()); - + // Link to udev to track connected cameras and provide appropriate // capture items on the menu. this.camera_menus = {}; // Track which cameras we have in the menu - + this.udev_client = new GUdev.Client ({subsystems: ["video4linux"]}); - this.udev_client.connect ("uevent", Lang.bind(this, this.refresh_cameras)); - - // Populate the menu with an initial list of cameras - this.refresh_cameras(); + this.udev_client.connect ("uevent", Lang.bind(this, this.refresh_cameras)); + + // Populate the menu with an initial list of cameras + this.refresh_cameras(); this._qr = new QRLib.QR(0, this._maincontainer); - + this._maincontainer.add_actor(this._qr.actor); } @@ -97,21 +93,28 @@ MyApplet.prototype = { _launch_qr_reader: function (camera_path) { try { if (this._qrprocess == null) { - // Spawn the python helper + // Spawn the python helper this._qrprocess = Gio.Subprocess.new( [GLib.build_filenamev([AppletDir,QRReaderHelper]), camera_path], Gio.SubprocessFlags.STDOUT_PIPE); - // Read from stdout + // Read from stdout let streamOut = this._qrprocess.get_stdout_pipe(); streamOut.read_bytes_async(MAX_BYTES, 0, null, Lang.bind(this, function (o,result) { - let data = o.read_bytes_finish(result); - let clipboard = St.Clipboard.get_default(); - clipboard.set_text(data.get_data().toString()); + let data = o.read_bytes_finish(result); + let clipboard = St.Clipboard.get_default(); + // Check Cinnamon version + let cinn_ver = GLib.getenv('CINNAMON_VERSION'); + cinn_ver = cinn_ver.substring(0, cinn_ver.lastIndexOf(".")) + if (parseFloat(cinn_ver) <= 3.4) { + clipboard.set_text(data.get_data().toString()); + } else { + clipboard.set_text(St.ClipboardType.CLIPBOARD, data.get_data().toString()); + } })); this._qrprocess.wait_async(null, Lang.bind(this, function(o,result) { - this._qrprocess = null; - o.wait_finish(result); + this._qrprocess = null; + o.wait_finish(result); })); } } catch (e) { @@ -119,47 +122,65 @@ MyApplet.prototype = { } }, - // Dynamically updates the applet menu as cameras are plugged/unplugged - refresh_cameras: function () { - // Refresh camera list - for (item in this.camera_menus) { - this.menu.remove(item); - } - this.camera_menus = {}; - - let camera_devices = this.udev_client.query_by_subsystem ("video4linux"); - for (var n = 0; n < camera_devices.length; n++) { - let devfile = camera_devices[n].get_device_file (); - let description = camera_devices[n].get_property('ID_V4L_PRODUCT'); - + // Dynamically updates the applet menu as cameras are plugged/unplugged + refresh_cameras: function () { + // Refresh camera list + for (let item in this.camera_menus) { + this.menu.remove(item); + } + this.camera_menus = {}; + + let camera_devices = this.udev_client.query_by_subsystem ("video4linux"); + for (var n = 0; n < camera_devices.length; n++) { + let devfile = camera_devices[n].get_device_file (); + let description = camera_devices[n].get_property('ID_V4L_PRODUCT'); + let menuItem = new PopupMenu.PopupMenuItem(_("Scan QR Code") + ' (' + description +')'); - + menuItem.connect('activate', Lang.bind(this, function (menuItem, event) { - this._launch_qr_reader(devfile); - return false; + this._launch_qr_reader(devfile); + return false; })); - + this.menu.addMenuItem(menuItem); this.camera_menus[devfile+description] = menuItem; - } - }, + } + }, on_applet_clicked: function(event) { - let clipboard = St.Clipboard.get_default() + let clipboard = St.Clipboard.get_default(); + + // Check Cinnamon version + let cinn_ver = GLib.getenv('CINNAMON_VERSION'); + cinn_ver = cinn_ver.substring(0, cinn_ver.lastIndexOf(".")) + if (parseFloat(cinn_ver) <= 3.4) { clipboard.get_text(Lang.bind(this, - function(clipboard, text) { - this._qr.set_text(text); - try { - this._errorString.label.text = this._qr.error; - } catch (e) { - this._errorString.label.text = _("No QR code scanned."); - } - this.menu.toggle(); - })); + function(clipboard, text) { + this._qr.set_text(text); + try { + this._errorString.label.text = this._qr.error; + } catch (e) { + this._errorString.label.text = _("No QR code scanned."); + } + this.menu.toggle(); + })); + } else { + clipboard.get_text(St.ClipboardType.CLIPBOARD, Lang.bind(this, + function(clipboard, text) { + this._qr.set_text(text); + try { + this._errorString.label.text = this._qr.error; + } catch (e) { + this._errorString.label.text = _("No QR code scanned."); + } + this.menu.toggle(); + })); + } + } }; -function main(metadata, orientation) { +function main(metadata, orientation) { let myApplet = new MyApplet(orientation); - return myApplet; + return myApplet; } diff --git a/clipboard-qr@wrouesnel/files/clipboard-qr@wrouesnel/icon.png b/clipboard-qr@wrouesnel/files/clipboard-qr@wrouesnel/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..cbcd5523dda8169008ea5776928ff89c775a32c7 GIT binary patch literal 2436 zcmV-~348X5P)e zSad^gZEa<4bO1wgWnpw>WFU8GbZ8()Nlj2!fese{00`_!L_t(|+U=c5a@;r&Me!N% z!8*DZ_KAHrMcCPk8VF)wv5F9oD!sR{tdhj(Gc!L%{rvgU0)SH%ZUG=r00asM6aaw& zAW--s#MTGDfB)w0zz}}@`b7i?ElfI#6rUHr`AxOee>)JUA^m6>HINAw1HG+jhcAjJb9P(YvnZ()*V zF=9wsZ?ke{2;O(-WFdkA0tG;zfItB-Nhjz%PpS8OrZdOwZLo--000!J4&l--u_l37VD&)@TO>uhH}>S_BHdUHp$9Ke!9v%Oh!xr19h9 zBhV5GUX6TI?xH%Fnxh5ytX1Y_nGjFEd*&YWHo?tW)IwMYpWrHFYAe#1en*+(2N-AF zEfiX`5Ef;^)$xoE(6h!W!lOb6F(?rv;S*+y)V58bv5@TKBHFtl>TM7_EwnIixSfSy z+NSZcp`OGJKD^SZYulP605_f~grIyhldwqOA&lDkOAI0@3=W}I3zQ**XtqjLN*8YGYY=*y zt`YkcjWBzjdXh%Wt=he(m5-KtSXHvdEh!#m6{4B;;{CJ6GT{Kj3eeDqpxOSN0B%_B zbwawJ111Tau(pE+UB=x#Db5kSG9!kwc^We3X*ghSbGw(}t(D>>UERAvkdpOr0OppW z+nyxqP;ezyu|6nxjiE{-C>`#!!x!BX;~4 z*?x!0OcK!(=3~`;I2TepxDaQ<`NVZa@bJtsO#q*-*^o3du{;w@ckh(}BXN|u=)H=Y z_dSQa_XhQzA9d#1irj5Q4GQ2Of+qjFX&ZrpADOB&^^w~Go{Ul6p0u#52Y52>d4(FE z@$J2PA9^3-j6oQ&Xu+(FXwTf2Swr<2CW&YYzR0#hWFs$_mE7y!U&^*ohAYEx|K1R4 zV>~FmN#KR2R=1m7Fn^{oIeLuVdkLK}FuhITi05%Ek|rshs0r>e{a%Wv{)G8n$?7hi zXbL`Dyvh_$6ot9D-Ks*33fk-u|7`U1KF`L}lHIe0){W=^>?=}jQ@kp}odD)U(yjWI zHL$KT>!?9tejR!hXdXL73$zw2C#Rv*^By zHha&H8Zq>5)~2qbhge!RtK*X537arI!CNBEhDoCQgjwRe<#5Y#`BDqzhEic@^_gxV zYa8Ll@&`kZP$+nas3F99-_iTjq@MOL8gb5Fao(71bhrJTr8QI(U|fp7g~U>Y%Xe#H z0-s5}12{lde+v8RusVV_hN#WXhC{{i@?Vr=N5LWqtj(We_FQ#jrt8&2njBNL9 zZaysSCm(xRc&)6~dKfj)=)n;#_gZRQ)X{WY|M_A;=AkmL(1;=jVC!^0kWf$gW($^>hks0u18fh-GH%9c5j6oTy1uGxB?tvw5@60odY zI9z0+Lxh+wWO}%emQIs8)?|_1avI-?E}?Qn>A-ohe&Z z7pWyFK1da*wVIvOsF8FaSLt8JgVY4Z1*u)qZU>9oRppDmHz=}Hx%A5JH#6R0000 + + + + + image/svg+xml + + + + + + + + + + diff --git a/clipboard-qr@wrouesnel/files/clipboard-qr@wrouesnel/metadata.json b/clipboard-qr@wrouesnel/files/clipboard-qr@wrouesnel/metadata.json index e2e549ef154..c92db248619 100644 --- a/clipboard-qr@wrouesnel/files/clipboard-qr@wrouesnel/metadata.json +++ b/clipboard-qr@wrouesnel/files/clipboard-qr@wrouesnel/metadata.json @@ -2,7 +2,6 @@ "uuid": "clipboard-qr@wrouesnel", "name": "Clipboard QR code applet", "description": "Create QR codes from clipboard content", - "icon": "edit-paste-symbolic", "url" : "https://github.com/wrouesnel/clipboard-qr", "original-authors" : ["ebbes"], "version" : "1.12" diff --git a/clipboard-qr@wrouesnel/icon.png b/clipboard-qr@wrouesnel/icon.png deleted file mode 100644 index cbcd5523dda8169008ea5776928ff89c775a32c7..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2436 zcmV-~348X5P)e zSad^gZEa<4bO1wgWnpw>WFU8GbZ8()Nlj2!fese{00`_!L_t(|+U=c5a@;r&Me!N% z!8*DZ_KAHrMcCPk8VF)wv5F9oD!sR{tdhj(Gc!L%{rvgU0)SH%ZUG=r00asM6aaw& zAW--s#MTGDfB)w0zz}}@`b7i?ElfI#6rUHr`AxOee>)JUA^m6>HINAw1HG+jhcAjJb9P(YvnZ()*V zF=9wsZ?ke{2;O(-WFdkA0tG;zfItB-Nhjz%PpS8OrZdOwZLo--000!J4&l--u_l37VD&)@TO>uhH}>S_BHdUHp$9Ke!9v%Oh!xr19h9 zBhV5GUX6TI?xH%Fnxh5ytX1Y_nGjFEd*&YWHo?tW)IwMYpWrHFYAe#1en*+(2N-AF zEfiX`5Ef;^)$xoE(6h!W!lOb6F(?rv;S*+y)V58bv5@TKBHFtl>TM7_EwnIixSfSy z+NSZcp`OGJKD^SZYulP605_f~grIyhldwqOA&lDkOAI0@3=W}I3zQ**XtqjLN*8YGYY=*y zt`YkcjWBzjdXh%Wt=he(m5-KtSXHvdEh!#m6{4B;;{CJ6GT{Kj3eeDqpxOSN0B%_B zbwawJ111Tau(pE+UB=x#Db5kSG9!kwc^We3X*ghSbGw(}t(D>>UERAvkdpOr0OppW z+nyxqP;ezyu|6nxjiE{-C>`#!!x!BX;~4 z*?x!0OcK!(=3~`;I2TepxDaQ<`NVZa@bJtsO#q*-*^o3du{;w@ckh(}BXN|u=)H=Y z_dSQa_XhQzA9d#1irj5Q4GQ2Of+qjFX&ZrpADOB&^^w~Go{Ul6p0u#52Y52>d4(FE z@$J2PA9^3-j6oQ&Xu+(FXwTf2Swr<2CW&YYzR0#hWFs$_mE7y!U&^*ohAYEx|K1R4 zV>~FmN#KR2R=1m7Fn^{oIeLuVdkLK}FuhITi05%Ek|rshs0r>e{a%Wv{)G8n$?7hi zXbL`Dyvh_$6ot9D-Ks*33fk-u|7`U1KF`L}lHIe0){W=^>?=}jQ@kp}odD)U(yjWI zHL$KT>!?9tejR!hXdXL73$zw2C#Rv*^By zHha&H8Zq>5)~2qbhge!RtK*X537arI!CNBEhDoCQgjwRe<#5Y#`BDqzhEic@^_gxV zYa8Ll@&`kZP$+nas3F99-_iTjq@MOL8gb5Fao(71bhrJTr8QI(U|fp7g~U>Y%Xe#H z0-s5}12{lde+v8RusVV_hN#WXhC{{i@?Vr=N5LWqtj(We_FQ#jrt8&2njBNL9 zZaysSCm(xRc&)6~dKfj)=)n;#_gZRQ)X{WY|M_A;=AkmL(1;=jVC!^0kWf$gW($^>hks0u18fh-GH%9c5j6oTy1uGxB?tvw5@60odY zI9z0+Lxh+wWO}%emQIs8)?|_1avI-?E}?Qn>A-ohe&Z z7pWyFK1da*wVIvOsF8FaSLt8JgVY4Z1*u)qZU>9oRppDmHz=}Hx%A5JH#6R0000