[polari/wip/fmuellner/paste-confirmation: 8/16] pasteManager: Make pasteImage() take a pixbuf



commit f69d177b236befa3d8edec7ce492c378619eceba
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().

 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 2d1fe15..0cc8d06 100644
--- a/src/pasteManager.js
+++ b/src/pasteManager.js
@@ -34,10 +34,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');
         }
@@ -74,7 +71,7 @@ const PasteManager = new Lang.Class({
             }));
     },
 
-    pasteImage: function(data) {
+    pasteImage: function(pixbuf) {
         let room = this._roomManager.getActiveRoom();
         if (!room)
             return;
@@ -87,7 +84,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]