Skip to content

Commit

Permalink
clipboard-qr@wrouesnel: Fix for Cinnamon 3.6 and use of QR icon (#1651)
Browse files Browse the repository at this point in the history
* 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: #1590
Thanks @alex-t-grecu
  • Loading branch information
NikoKrause committed Mar 5, 2018
1 parent aea7067 commit 1f5d51d
Show file tree
Hide file tree
Showing 6 changed files with 142 additions and 60 deletions.
6 changes: 5 additions & 1 deletion clipboard-qr@wrouesnel/README.md
Expand Up @@ -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.

Expand Down
137 changes: 79 additions & 58 deletions clipboard-qr@wrouesnel/files/clipboard-qr@wrouesnel/applet.js
Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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);

}
Expand All @@ -97,69 +93,94 @@ 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) {
global.logError(e);
}
},

// 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;
}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Expand Up @@ -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"
Expand Down
Binary file removed clipboard-qr@wrouesnel/icon.png
Binary file not shown.
1 change: 1 addition & 0 deletions clipboard-qr@wrouesnel/icon.png

0 comments on commit 1f5d51d

Please sign in to comment.