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

Subscribers

People subscribed via source and target branches

to all changes: