[polari] pasteManager: Make pasteImage() take a pixbuf
- From: Florian Müllner <fmuellner src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [polari] pasteManager: Make pasteImage() take a pixbuf
- Date: Thu, 18 Feb 2016 00:16:42 +0000 (UTC)
commit 6c5231b6e87d968bf756abd38a0c730093bd4f64
Author: Florian Müllner <fmuellner gnome org>
Date: Thu Feb 11 20:43:39 2016 +0100
pasteManager: Make pasteImage() take a pixbuf
Now that we don't have to go through GVariant, it is cleaner to keep
passing around the actual pixbuf and only serialize it once we hit
imgurPaste().
https://bugzilla.gnome.org/show_bug.cgi?id=760315
src/pasteManager.js | 9 +++------
src/utils.js | 10 +++++++---
2 files changed, 10 insertions(+), 9 deletions(-)
---
diff --git a/src/pasteManager.js b/src/pasteManager.js
index b5b6398..9ec3638 100644
--- a/src/pasteManager.js
+++ b/src/pasteManager.js
@@ -72,10 +72,7 @@ const PasteManager = new Lang.Class({
if (typeof content == 'string') {
this.pasteText(content);
} else if (content instanceof GdkPixbuf.Pixbuf) {
- let [success, buffer] = content.save_to_bufferv('png', [], []);
- if (!success)
- return;
- this.pasteImage(buffer);
+ this.pasteImage(content);
} else {
throw new Error('Unhandled content type');
}
@@ -112,7 +109,7 @@ const PasteManager = new Lang.Class({
}));
},
- pasteImage: function(data) {
+ pasteImage: function(pixbuf) {
let room = this._roomManager.getActiveRoom();
if (!room)
return;
@@ -125,7 +122,7 @@ const PasteManager = new Lang.Class({
else
title = _("Paste from %s").format(nick);
- Utils.imgurPaste(data, title, Lang.bind(this,
+ Utils.imgurPaste(pixbuf, title, Lang.bind(this,
function(url) {
if (!url)
return;
diff --git a/src/utils.js b/src/utils.js
index bdb1526..69235f9 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -215,12 +215,16 @@ function gpaste(text, title, callback) {
});
}
-function imgurPaste(data, title, callback) {
- let base64EncodedBuffer = GLib.base64_encode(data);
+function imgurPaste(pixbuf, title, callback) {
+ let [success, buffer] = pixbuf.save_to_bufferv('png', [], []);
+ if (!success) {
+ callback(null);
+ return;
+ }
let params = {
title: title,
- image: base64EncodedBuffer
+ image: GLib.base64_encode(buffer)
};
let session = new Soup.Session();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]