After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 760346 - Use image paste service
Use image paste service
Status: RESOLVED FIXED
Product: polari
Classification: Applications
Component: general
unspecified
Other Linux
: Normal normal
: ---
Assigned To: Polari maintainers
Polari maintainers
: 755594 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2016-01-09 05:28 UTC by Kunaal Jain
Modified: 2016-02-12 21:10 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
[1] entryArea: Check if pasted text is not null (824 bytes, patch)
2016-01-09 05:30 UTC, Kunaal Jain
needs-work Details | Review
[2] Make paste functions generic (5.58 KB, patch)
2016-01-09 05:30 UTC, Kunaal Jain
needs-work Details | Review
[3] Add imgur paste service (4.57 KB, patch)
2016-01-09 05:31 UTC, Kunaal Jain
needs-work Details | Review
[4] handle paste service errors (2.67 KB, patch)
2016-01-09 05:31 UTC, Kunaal Jain
needs-work Details | Review
entryArea: Check if pasted text is not null (916 bytes, patch)
2016-02-10 12:20 UTC, Kunaal Jain
committed Details | Review
Make paste functions generic (4.62 KB, patch)
2016-02-10 12:20 UTC, Kunaal Jain
none Details | Review
Add support for pasting image to public image service (6.57 KB, patch)
2016-02-10 12:21 UTC, Kunaal Jain
none Details | Review
Make paste functions generic (3.69 KB, patch)
2016-02-11 04:20 UTC, Kunaal Jain
committed Details | Review
Add support for pasting image to public image service (7.16 KB, patch)
2016-02-11 04:21 UTC, Kunaal Jain
committed Details | Review

Description Kunaal Jain 2016-01-09 05:28:59 UTC
Use imgur as image paste service

Filing this bug for review of branch wip/kunaljain/image-paste-service
Comment 1 Kunaal Jain 2016-01-09 05:30:07 UTC
Created attachment 318560 [details] [review]
[1] entryArea: Check if pasted text is not null
Comment 2 Kunaal Jain 2016-01-09 05:30:33 UTC
Created attachment 318561 [details] [review]
[2] Make paste functions generic
Comment 3 Kunaal Jain 2016-01-09 05:31:02 UTC
Created attachment 318562 [details] [review]
[3] Add imgur paste service
Comment 4 Kunaal Jain 2016-01-09 05:31:30 UTC
Created attachment 318563 [details] [review]
[4] handle paste service errors
Comment 5 Bastian Ilsø 2016-01-17 18:01:09 UTC
Review of attachment 318560 [details] [review]:

beyond style nits, this patch looks good to me.

::: src/entryArea.js
@@ +36,3 @@
         clipboard.request_text(Lang.bind(this,
             function(clipboard, text) {
+                if(text==null) return;

style nit: space around operator
return should be on its own line.
Comment 6 Bastian Ilsø 2016-01-17 18:08:42 UTC
Review of attachment 318561 [details] [review]:

::: src/entryArea.js
@@ +230,3 @@
                      "Paste %s lines of text to public paste service?",
                      nLines).format(nLines);
+        this._pasteButton.action_target = new GLib.Variant('(si)', [text, 0]);

perhaps it would be more clean if we make an enum instead of using an integer directly to represent paste content type? alternatively (and shorter) we could send a string around fx 'text'.

::: src/pasteManager.js
@@ +78,3 @@
+        let n;
+        if (type==0)
+            n = new UploadNotification("text");

..then we also wouldnt have to do this check but just parse the type directly to the upload notification.
Comment 7 Bastian Ilsø 2016-01-17 18:12:29 UTC
Review of attachment 318562 [details] [review]:

::: src/entryArea.js
@@ +51,3 @@
+        clipboard.request_image(Lang.bind(this,
+            function(clipboard, pixbuf) {
+                if(pixbuf==null) return;

style nit: spacing around operator.
style nit: return should be on line below.

@@ +249,3 @@
+        if (!success)
+            return;
+        let encoded_buffer = GLib.base64_encode(buffer);

perhaps line 248-251 belongs better inside clipboard.request_image() ? (so clipboard.request_text and clipboard.request_image match in terms of what they do + _onTextPasted and _onImagePasted match in terms of what they do)
Comment 8 Bastian Ilsø 2016-01-17 18:44:42 UTC
Review of attachment 318563 [details] [review]:

::: src/pasteManager.js
@@ +13,3 @@
+const Mainloop = imports.mainloop;
+
+const ERROR_NOTIFICATION_REVEAL_TIME = 5;

I suggest we use a longer reveal time (nautilus uses 8 seconds i think) but then make the in-app error notification user dismissable. (Provide an X next to the message to dismiss the message, see https://developer.gnome.org/hig/stable/in-app-notifications.html.en )

@@ +327,1 @@
+        label = new Gtk.Label({ label: _("Error in uploading %s").format(content) });

Hmm, maybe a better label is "Failed to upload %s."?
Comment 9 Kunaal Jain 2016-01-28 18:26:13 UTC
Thanks Bastian for review. Was waiting for patches on bug 760872 to land, and rebase the existing patches on them. Florian, want to add anything more to the reviews?
Comment 10 Florian Müllner 2016-01-28 21:12:12 UTC
Review of attachment 318561 [details] [review]:

::: src/application.js
@@ +73,3 @@
+          { name: 'paste-content',
+            activate: Lang.bind(this, this._onPasteContent),
+            parameter_type: GLib.VariantType.new('(si)') },

We generally use "s" to mean "UTF-8 string". For arbitrary data, use "ay"

::: src/entryArea.js
@@ +230,3 @@
                      "Paste %s lines of text to public paste service?",
                      nLines).format(nLines);
+        this._pasteButton.action_target = new GLib.Variant('(si)', [text, 0]);

I agree with Bastian - no magic numbers. We already have DndTargetType in pasteManager

::: src/pasteManager.js
@@ +85,3 @@
     },
 
+    _pasteContent: function(data, datatype, notification) {

1) this obviously breaks the call to _pasteText()
    in _handleFileContent()
 2) the split looks wrong - the ellipsization shenanigans
    are workarounds for limitations of paste.gnome.org, so
    it's a bit silly to apply them to imgur.com as well

::: src/utils.js
@@ +138,3 @@
 }
 
+function gpaste(data, datatype, title, callback) {

"gpaste" == "gnome paste" (used to be "fpaste" when using fpaste.org)

So no, please leave this as a helper function to paste text to paste.gnome.org (read: don't touch utils.js in this patch) - just add imgurPaste(pixbuf, title, callback) or so in the follow-up patch
Comment 11 Florian Müllner 2016-01-28 21:12:31 UTC
Review of attachment 318562 [details] [review]:

::: src/entryArea.js
@@ +20,3 @@
     Signals: { 'text-pasted': { param_types: [GObject.TYPE_STRING,
+                                              GObject.TYPE_INT] },
+               'image-pasted': { param_types: [GObject.TYPE_OBJECT] } },

Or more precise: GdkPixbuf.Pixbuf.$gtype

@@ +244,3 @@
 
+    _onImagePasted: function(entry, data) {
+        this._multiLinelabel.label = "Paste image to imgur paste service?";

Not sure we need the service name here. But we definitively want to mark the string for translation

::: src/utils.js
@@ +33,3 @@
 const GPASTE_TEXT_BASEURL = 'https://paste.gnome.org/';
 
+const IMGUR_CLIENT_ID = '4109e59177ec95e';

Is this a valid ID, or do we still need to request one?
Comment 12 Florian Müllner 2016-01-28 21:12:41 UTC
Review of attachment 318563 [details] [review]:

Let's keep this on bug 756855?
Comment 13 Florian Müllner 2016-01-28 21:15:34 UTC
Also please take some time to write proper commit messages.
Comment 14 Kunaal Jain 2016-02-10 12:20:00 UTC
Created attachment 320790 [details] [review]
entryArea: Check if pasted text is not null

We should check if text is null before pasting text,
and emitting corresponding signals.
Comment 15 Kunaal Jain 2016-02-10 12:20:40 UTC
Created attachment 320791 [details] [review]
Make paste functions generic

Change the name of the functions, signals, actions
to generic paste-content rather than paste-text, as
soon we will be adding support for pasting image, and
most of the code for pasting text and image is same,
so reuse the code.
Comment 16 Kunaal Jain 2016-02-10 12:21:07 UTC
Created attachment 320792 [details] [review]
Add support for pasting image to public image service

Support pasting images in polari by uploading them
to public image service (currently Imgur).
Comment 17 Florian Müllner 2016-02-10 19:48:43 UTC
Review of attachment 320790 [details] [review]:

OK
Comment 18 Florian Müllner 2016-02-10 19:48:45 UTC
Review of attachment 320791 [details] [review]:

::: src/application.js
@@ +70,3 @@
+          { name: 'paste-content',
+            activate: Lang.bind(this, this._onPasteContent),
+            parameter_type: GLib.VariantType.new('(si)') },

As mentioned previously, the convention is to use 's' for UTF8-encoded strings - assuming that all 'content' is in that format is a bit odd (see also the comment about not base64-encoding the image data immediately). Simply for semantic reasons, 'ay' (array of bytes) looks like a better choice (even though that means you'll have to call data.toString() to treat it like text)

::: src/pasteManager.js
@@ +77,1 @@
         let app = Gio.Application.get_default();

So this is the line that ends up being shared for the different types - not the biggest win ;-)

How about doing the type handling in _onPasteContent (in application.js) instead:

  let [data, type] = parameter.deep_unpack();
  switch (type) {
    case PasteManager.DndTargetType.TEXT:
      this._pasteManager.pasteText(data);
      break;
    default:
      log('Unhandled paste content of type %d'.format(type));
  }
Comment 19 Florian Müllner 2016-02-10 19:48:47 UTC
Review of attachment 320792 [details] [review]:

::: src/entryArea.js
@@ +233,3 @@
+        if (!success)
+            return;
+        let encoded_buffer = GLib.base64_encode(buffer);

Style-nit: camel case in JS code

I'm also not quite sure this is the right place - "images are represented as base64 encoded strings" looks more like an implementation detail of the paste service, so maybe only convert the raw data in Utils.imgurPaste()?
Comment 20 Kunaal Jain 2016-02-11 04:20:19 UTC
Created attachment 320848 [details] [review]
Make paste functions generic

Change the name of the functions, signals, actions
to generic paste-content rather than paste-text, as
soon we will be adding support for pasting image, and
most of the code for pasting text and image is same,
so reuse the code.
Comment 21 Kunaal Jain 2016-02-11 04:21:05 UTC
Created attachment 320849 [details] [review]
Add support for pasting image to public image service

Support pasting images in polari by uploading them
to public image service (currently Imgur).
Comment 22 Kunaal Jain 2016-02-11 04:23:16 UTC
(In reply to Florian Müllner from comment #18)
> Review of attachment 320791 [details] [review] [review]:
> 
> ::: src/pasteManager.js
> @@ +77,1 @@
>          let app = Gio.Application.get_default();
> 
> So this is the line that ends up being shared for the different types - not
> the biggest win ;-)
> 
> How about doing the type handling in _onPasteContent (in application.js)
> instead:
> 
>   let [data, type] = parameter.deep_unpack();
>   switch (type) {
>     case PasteManager.DndTargetType.TEXT:
>       this._pasteManager.pasteText(data);
>       break;
>     default:
>       log('Unhandled paste content of type %d'.format(type));
>   }

I uploaded the new patch as you said, but didn't get why you asked so? The let app line still gets in both functions pasteText and pasteImage instead of pasteContent. What do you mean by line end up being shared ?
Comment 23 Florian Müllner 2016-02-11 10:57:33 UTC
(In reply to Kunaal Jain from comment #22)
> I uploaded the new patch as you said, but didn't get why you asked so? The
> let app line still gets in both functions pasteText and pasteImage instead
> of pasteContent. What do you mean by line end up being shared ?

I mean pasteText(text) and pasteImage(image) are more readable than pasteContent(data, type). In the case of the action handling, the benefit of avoiding code duplication outweighs that, but there's little benefit in not duplicating a single line ...
Comment 24 Kunaal Jain 2016-02-11 17:09:57 UTC
(In reply to Florian Müllner from comment #23)
> (In reply to Kunaal Jain from comment #22)
> > I uploaded the new patch as you said, but didn't get why you asked so? The
> > let app line still gets in both functions pasteText and pasteImage instead
> > of pasteContent. What do you mean by line end up being shared ?
> 
> I mean pasteText(text) and pasteImage(image) are more readable than
> pasteContent(data, type). In the case of the action handling, the benefit of
> avoiding code duplication outweighs that, but there's little benefit in not
> duplicating a single line ...

Ah, now I get it. Well the current patch separates the function calls.
Comment 25 Florian Müllner 2016-02-11 17:10:48 UTC
Review of attachment 320848 [details] [review]:

LGTM
Comment 26 Florian Müllner 2016-02-11 17:10:58 UTC
Review of attachment 320849 [details] [review]:

Dto.
Comment 27 Kunaal Jain 2016-02-11 18:37:36 UTC
Attachment 320790 [details] pushed as 26e95fd - entryArea: Check if pasted text is not null
Attachment 320848 [details] pushed as 8a67ef0 - Make paste functions generic
Attachment 320849 [details] pushed as e5c4189 - Add support for pasting image to public image service
Comment 28 Kunaal Jain 2016-02-12 08:37:07 UTC
(In reply to Florian Müllner from comment #23)
> (In reply to Kunaal Jain from comment #22)
> > I uploaded the new patch as you said, but didn't get why you asked so? The
> > let app line still gets in both functions pasteText and pasteImage instead
> > of pasteContent. What do you mean by line end up being shared ?
> 
> I mean pasteText(text) and pasteImage(image) are more readable than
> pasteContent(data, type). In the case of the action handling, the benefit of
> avoiding code duplication outweighs that, but there's little benefit in not
> duplicating a single line ...

Florian, I ended up committing the current patches. But you told on IRC that you figured out a way to get me the abstraction of pasteContent :-) , no harm in another commit for abstracting it. What you figured out?
Comment 29 Florian Müllner 2016-02-12 21:10:00 UTC
*** Bug 755594 has been marked as a duplicate of this bug. ***