Merge lp:~elementary-apps/cable/pastebin into lp:cable

Proposed by Eduard Gotwig
Status: Work in progress
Proposed branch: lp:~elementary-apps/cable/pastebin
Merge into: lp:cable
Diff against target: 142 lines (+97/-1)
3 files modified
CMakeLists.txt (+6/-1)
src/Controller/Channel.vala (+4/-0)
src/Services/PasteBin.vala (+87/-0)
To merge this branch: bzr merge lp:~elementary-apps/cable/pastebin
Reviewer Review Type Date Requested Status
Eduard Gotwig (community) Needs Fixing
Review via email: mp+181002@code.launchpad.net

Description of the change

Auto Pastebin support

To post a comment you must log in.
Revision history for this message
Eduard Gotwig (gotwig) wrote :

Show the serverURL in the paste title;
provide a GUI in the settings for the auto-paste messages

review: Needs Fixing
lp:~elementary-apps/cable/pastebin updated
119. By Auroral Xylon

Made it get server name from variable

120. By Eduard Gotwig <email address hidden>

Add Hastebin support, now we have Pastebin.com and Hastebin.com support;
Add async;
Add json dependency

Revision history for this message
982c80311320c1b (alexander-wilms) wrote :

Why is there a GUI in the preferences window needed? Couldn't this be merged already?

Unmerged revisions

120. By Eduard Gotwig <email address hidden>

Add Hastebin support, now we have Pastebin.com and Hastebin.com support;
Add async;
Add json dependency

119. By Auroral Xylon

Made it get server name from variable

118. By Eduard Gotwig <email address hidden>

added some more infos, Freenode is a fixed value, have to fix this

117. By Julien Spautz

added copyright header

116. By Julien Spautz

long messages will be uploaded to pastebin

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'CMakeLists.txt'
--- CMakeLists.txt 2013-08-06 15:32:12 +0000
+++ CMakeLists.txt 2013-08-20 17:22:25 +0000
@@ -33,8 +33,10 @@
33 gio-2.0>=2.28.033 gio-2.0>=2.28.0
34 gtk+-3.0>=3.4.034 gtk+-3.0>=3.4.0
35 gee-1.035 gee-1.0
36 libnotify
36 unity37 unity
37 libnotify)38 json-glib-1.0
39 libsoup-2.4)
3840
39add_definitions(${DEPS_CFLAGS})41add_definitions(${DEPS_CFLAGS})
4042
@@ -76,6 +78,7 @@
7678
77 src/Services/Launcher.vala79 src/Services/Launcher.vala
78 src/Services/Notification.vala80 src/Services/Notification.vala
81 src/Services/PasteBin.vala
7982
80 src/Widgets/Window.vala83 src/Widgets/Window.vala
81 src/Widgets/Welcome.vala84 src/Widgets/Welcome.vala
@@ -100,6 +103,8 @@
100 granite103 granite
101 libnotify104 libnotify
102 unity105 unity
106 json-glib-1.0
107 libsoup-2.4
103 #WebKit-3.0108 #WebKit-3.0
104OPTIONS109OPTIONS
105 --target-glib=2.32110 --target-glib=2.32
106111
=== modified file 'src/Controller/Channel.vala'
--- src/Controller/Channel.vala 2013-08-08 00:37:02 +0000
+++ src/Controller/Channel.vala 2013-08-20 17:22:25 +0000
@@ -67,9 +67,13 @@
67 backend.send_join ();67 backend.send_join ();
68 });68 });
6969
70 int text_max_length = 600;
71
70 view.send_message.connect ((message) => {72 view.send_message.connect ((message) => {
71 if (message.has_prefix ("/"))73 if (message.has_prefix ("/"))
72 server.backend.send_raw (message.replace ("/", ""));74 server.backend.send_raw (message.replace ("/", ""));
75 else if (message.length > text_max_length)
76 server.backend.send_message (name, PasteBin.upload (message));
73 else77 else
74 server.backend.send_message (name, message);78 server.backend.send_message (name, message);
7579
7680
=== added file 'src/Services/PasteBin.vala'
--- src/Services/PasteBin.vala 1970-01-01 00:00:00 +0000
+++ src/Services/PasteBin.vala 2013-08-20 17:22:25 +0000
@@ -0,0 +1,87 @@
1/***
2 Copyright (C) 2013 Cable Developers
3
4 This program or library is free software; you can redistribute it
5 and/or modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 3 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General
15 Public License along with this library; if not, write to the
16 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301 USA.
18***/
19
20public class Cable.PasteBin : GLib.Object {
21
22// Choose "0" for Hastebin.com, "1" for Pastebin.com
23
24 static const string[] API_URLS = {
25 "http://hastebin.com/documents",
26 "http://pastebin.com/api/api_post.php"
27 };
28
29 /**
30 * Upload some text to a pastebin service.
31 * @param text The text you want to upload
32 * @return URL to the pasted text
33 */
34 public static string? upload (string text) {
35
36 string API_URL = API_URLS[1];
37
38 var session = new Soup.SessionAsync ();
39 var message = new Soup.Message ("POST", API_URL);
40
41 switch (API_URL){
42
43 case "http://hastebin.com/documents":
44 message.set_request ("text/plain", Soup.MemoryUse.COPY, text.data);
45 session.send_message (message);
46
47 try {
48 var parser = new Json.Parser ();
49 parser.load_from_data ((string) message.response_body.flatten ().data, -1);
50
51 var root_object = parser.get_root ().get_object ();
52 string key = root_object.get_string_member ("key");
53
54 return "http://hastebin.com/" + key;
55 } catch (Error e) {
56 stderr.printf ("I guess something is not working...\n");
57 return null;
58 }
59
60 case "http://pastebin.com/api/api_post.php":
61 var paste_id_len = 8;
62
63 var request = Soup.Form.encode ("api_option", "paste",
64 "api_dev_key", "8d48454cb95d0af70e72820b84629f02",
65 "api_paste_code", text,
66 "api_paste_name", _("Auto Pasted by Cable IRC Suite"),
67 "api_paste_private", "1",
68 "api_paste_expire_date", "1M",
69 "api_paste_format", "text");
70
71 message.set_request ("application/x-www-form-urlencoded", Soup.MemoryUse.COPY, request.data);
72 message.set_flags (Soup.MessageFlags.NO_REDIRECT);
73
74 session.send_message (message);
75
76 var output = (string) message.response_body.data;
77
78 if (output[0:6] != "ERROR:")
79 return output[0:20+paste_id_len];
80
81 return null;
82
83 default:
84 return null;
85 }
86 }
87}

Subscribers

People subscribed via source and target branches

to all changes: