[polari/wip/kunaljain/image-paste-service: 3/4] Make paste functions generic
- From: Kunal Jain <kunaljain src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [polari/wip/kunaljain/image-paste-service: 3/4] Make paste functions generic
- Date: Thu, 7 Jan 2016 18:46:22 +0000 (UTC)
commit 39f2e867d319fcaf00941b301b066be2d6eca42e
Author: Kunaal Jain <kunaalus gmail com>
Date: Fri Jan 8 00:02:49 2016 +0530
Make paste functions generic
src/application.js | 12 ++++++------
src/entryArea.js | 4 ++--
src/pasteManager.js | 13 ++++++++-----
src/utils.js | 12 ++++++++----
4 files changed, 24 insertions(+), 17 deletions(-)
---
diff --git a/src/application.js b/src/application.js
index 3d67ad7..55deb42 100644
--- a/src/application.js
+++ b/src/application.js
@@ -70,9 +70,9 @@ const Application = new Lang.Class({
{ name: 'message-user',
activate: Lang.bind(this, this._onMessageUser),
parameter_type: GLib.VariantType.new('(ssu)') },
- { name: 'paste-text',
- activate: Lang.bind(this, this._onPasteText),
- parameter_type: GLib.VariantType.new('s') },
+ { name: 'paste-content',
+ activate: Lang.bind(this, this._onPasteContent),
+ parameter_type: GLib.VariantType.new('(si)') },
{ name: 'leave-room',
activate: Lang.bind(this, this._onLeaveRoom),
parameter_type: GLib.VariantType.new('(ss)') },
@@ -354,9 +354,9 @@ const Application = new Lang.Class({
contactName, time);
},
- _onPasteText: function(action, parameter) {
- let text = parameter.deep_unpack();
- this.pasteManager.pasteText(text);
+ _onPasteContent: function(action, parameter) {
+ let [data, type] = parameter.deep_unpack();
+ this.pasteManager.pasteContent(data, type);
},
_onLeaveRoom: function(action, parameter) {
diff --git a/src/entryArea.js b/src/entryArea.js
index 48590fe..4e62326 100644
--- a/src/entryArea.js
+++ b/src/entryArea.js
@@ -149,7 +149,7 @@ const EntryArea = new Lang.Class({
this._pasteButton = new Gtk.Button({ label: _("_Paste"),
use_underline: true,
- action_name: 'app.paste-text' });
+ action_name: 'app.paste-content' });
this._pasteButton.get_style_context().add_class('suggested-action');
this._pasteButton.connect('clicked',
Lang.bind(this, this._onButtonClicked));
@@ -229,7 +229,7 @@ const EntryArea = new Lang.Class({
ngettext("Paste %s line of text to public paste service?",
"Paste %s lines of text to public paste service?",
nLines).format(nLines);
- this._pasteButton.action_target = new GLib.Variant('s', text);
+ this._pasteButton.action_target = new GLib.Variant('(si)', [text, 0]);
this.widget.visible_child_name = 'multiline';
this._pasteButton.grab_focus();
},
diff --git a/src/pasteManager.js b/src/pasteManager.js
index 2207751..94dbb1d 100644
--- a/src/pasteManager.js
+++ b/src/pasteManager.js
@@ -73,15 +73,18 @@ const PasteManager = new Lang.Class({
this._widgets.push(widget);
},
- pasteText: function(text) {
+ pasteContent: function(data, type) {
let app = Gio.Application.get_default();
- let n = new UploadNotification("text");
+ let n;
+ if (type==0)
+ n = new UploadNotification("text");
+
app.notificationQueue.addNotification(n);
- this._pasteText(text, n);
+ this._pasteContent(data, type, n);
},
- _pasteText: function(text, notification) {
+ _pasteContent: function(data, datatype, notification) {
let room = this._roomManager.getActiveRoom();
if (!room) {
notification.close();
@@ -99,7 +102,7 @@ const PasteManager = new Lang.Class({
if (title.length > MAX_PASTE_TITLE_LENGTH)
title = title.substr(0, MAX_PASTE_TITLE_LENGTH - 1) + '…';
- Utils.gpaste(text, title, Lang.bind(this,
+ Utils.gpaste(data, datatype, title, Lang.bind(this,
function(url) {
if (!url) {
notification.close();
diff --git a/src/utils.js b/src/utils.js
index 3961b01..725aad4 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -30,7 +30,7 @@ const Tp = imports.gi.TelepathyGLib;
const AppNotifications = imports.appNotifications;
const Signals = imports.signals;
-const GPASTE_BASEURL = 'https://paste.gnome.org/'
+const GPASTE_TEXT_BASEURL = 'https://paste.gnome.org/';
// http://daringfireball.net/2010/07/improved_regex_for_matching_urls
const _balancedParens = '\\((?:[^\\s()<>]+|(?:\\(?:[^\\s()<>]+\\)))*\\)';
@@ -137,7 +137,11 @@ function openURL(url, timestamp) {
}
}
-function gpaste(text, title, callback) {
+function gpaste(data, datatype, title, callback) {
+ if (datatype==0) pasteText(data, title, callback);
+}
+
+function pasteText(text, title, callback) {
let params = {
title: title,
data: text,
@@ -145,7 +149,7 @@ function gpaste(text, title, callback) {
};
let session = new Soup.Session();
- let createUrl = GPASTE_BASEURL + 'api/json/create';
+ let createUrl = GPASTE_TEXT_BASEURL + 'api/json/create';
let message = Soup.form_request_new_from_hash('POST', createUrl, params);
session.queue_message(message,
function(session, message) {
@@ -161,7 +165,7 @@ function gpaste(text, title, callback) {
log(e.message);
}
if (info.result && info.result.id)
- callback(GPASTE_BASEURL + info.result.id);
+ callback(GPASTE_TEXT_BASEURL + info.result.id);
else
callback(null);
});
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]