Mercurial > pidgin
annotate finch/plugins/gnttinyurl.c @ 31602:7d75ffbde679
Added Croatian translation from Sabina Drempeti¸««. Closes #13595
author | Paul Aurich <paul@darkrain42.org> |
---|---|
date | Thu, 12 May 2011 02:58:18 +0000 |
parents | 6b328370cad0 |
children | 904686722499 |
rev | line source |
---|---|
26500
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
1 /** |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
2 * @file gnttinyurl.c |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
3 * |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
4 * Copyright (C) 2009 Richard Nelson <wabz@whatsbeef.net> |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
5 * |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
6 * This program is free software; you can redistribute it and/or modify |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
7 * it under the terms of the GNU General Public License as published by |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
8 * the Free Software Foundation; either version 2 of the License, or |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
9 * (at your option) any later version. |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
10 * |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
11 * This program is distributed in the hope that it will be useful, |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
14 * GNU General Public License for more details. |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
15 * |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
16 * You should have received a copy of the GNU General Public License |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
17 * along with this program; if not, write to the Free Software |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
19 */ |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
20 |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
21 |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
22 #include "internal.h" |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
23 #include <glib.h> |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
24 |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
25 #define PLUGIN_STATIC_NAME TinyURL |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
26 #define PREFS_BASE "/plugins/gnt/tinyurl" |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
27 #define PREF_LENGTH PREFS_BASE "/length" |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
28 #define PREF_URL PREFS_BASE "/url" |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
29 |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
30 |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
31 #include <conversation.h> |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
32 #include <signals.h> |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
33 |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
34 #include <glib.h> |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
35 |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
36 #include <plugin.h> |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
37 #include <version.h> |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
38 #include <debug.h> |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
39 #include <notify.h> |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
40 |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
41 #include <gntconv.h> |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
42 |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
43 #include <gntplugin.h> |
28309
7eaf2561b6dd
Extend the TinyURL plugin.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27988
diff
changeset
|
44 |
7eaf2561b6dd
Extend the TinyURL plugin.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27988
diff
changeset
|
45 #include <gntlabel.h> |
26500
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
46 #include <gnttextview.h> |
28309
7eaf2561b6dd
Extend the TinyURL plugin.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27988
diff
changeset
|
47 #include <gntwindow.h> |
26500
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
48 |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
49 static int tag_num = 0; |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
50 |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
51 typedef struct |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
52 { |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
53 PurpleConversation *conv; |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
54 gchar *tag; |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
55 int num; |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
56 } CbInfo; |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
57 |
28309
7eaf2561b6dd
Extend the TinyURL plugin.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27988
diff
changeset
|
58 static void process_urls(PurpleConversation *conv, GList *urls); |
7eaf2561b6dd
Extend the TinyURL plugin.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27988
diff
changeset
|
59 |
26500
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
60 /* 3 functions from util.c */ |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
61 static gboolean |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
62 badchar(char c) |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
63 { |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
64 switch (c) { |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
65 case ' ': |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
66 case ',': |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
67 case '\0': |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
68 case '\n': |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
69 case '\r': |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
70 case '<': |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
71 case '>': |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
72 case '"': |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
73 case '\'': |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
74 return TRUE; |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
75 default: |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
76 return FALSE; |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
77 } |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
78 } |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
79 |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
80 static gboolean |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
81 badentity(const char *c) |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
82 { |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
83 if (!g_ascii_strncasecmp(c, "<", 4) || |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
84 !g_ascii_strncasecmp(c, ">", 4) || |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
85 !g_ascii_strncasecmp(c, """, 6)) { |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
86 return TRUE; |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
87 } |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
88 return FALSE; |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
89 } |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
90 |
28309
7eaf2561b6dd
Extend the TinyURL plugin.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27988
diff
changeset
|
91 static GList *extract_urls(const char *text) |
7eaf2561b6dd
Extend the TinyURL plugin.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27988
diff
changeset
|
92 { |
26500
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
93 const char *t, *c, *q = NULL; |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
94 char *url_buf; |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
95 GList *ret = NULL; |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
96 gboolean inside_html = FALSE; |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
97 int inside_paren = 0; |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
98 c = text; |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
99 while (*c) { |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
100 if (*c == '(' && !inside_html) { |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
101 inside_paren++; |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
102 c++; |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
103 } |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
104 if (inside_html) { |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
105 if (*c == '>') { |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
106 inside_html = FALSE; |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
107 } else if (!q && (*c == '\"' || *c == '\'')) { |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
108 q = c; |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
109 } else if(q) { |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
110 if(*c == *q) |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
111 q = NULL; |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
112 } |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
113 } else if (*c == '<') { |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
114 inside_html = TRUE; |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
115 if (!g_ascii_strncasecmp(c, "<A", 2)) { |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
116 while (1) { |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
117 if (*c == '>') { |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
118 inside_html = FALSE; |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
119 break; |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
120 } |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
121 c++; |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
122 if (!(*c)) |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
123 break; |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
124 } |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
125 } |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
126 } else if ((*c=='h') && (!g_ascii_strncasecmp(c, "http://", 7) || |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
127 (!g_ascii_strncasecmp(c, "https://", 8)))) { |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
128 t = c; |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
129 while (1) { |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
130 if (badchar(*t) || badentity(t)) { |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
131 |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
132 if ((!g_ascii_strncasecmp(c, "http://", 7) && (t - c == 7)) || |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
133 (!g_ascii_strncasecmp(c, "https://", 8) && (t - c == 8))) { |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
134 break; |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
135 } |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
136 |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
137 if (*(t) == ',' && (*(t + 1) != ' ')) { |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
138 t++; |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
139 continue; |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
140 } |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
141 |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
142 if (*(t - 1) == '.') |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
143 t--; |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
144 if ((*(t - 1) == ')' && (inside_paren > 0))) { |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
145 t--; |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
146 } |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
147 |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
148 url_buf = g_strndup(c, t - c); |
26502
f9a923fde1e4
Remove usage of g_strcmp0 (which would bump the glib version requirement) where strcmp will do nicely
Richard Nelson <wabz@pidgin.im>
parents:
26500
diff
changeset
|
149 if (!g_list_find_custom(ret, url_buf, (GCompareFunc)strcmp)) { |
26500
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
150 purple_debug_info("TinyURL", "Added URL %s\n", url_buf); |
28344
6b328370cad0
Fix leaks, and a bug.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28309
diff
changeset
|
151 ret = g_list_append(ret, url_buf); |
6b328370cad0
Fix leaks, and a bug.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28309
diff
changeset
|
152 } else { |
6b328370cad0
Fix leaks, and a bug.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28309
diff
changeset
|
153 g_free(url_buf); |
26500
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
154 } |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
155 c = t; |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
156 break; |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
157 } |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
158 t++; |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
159 |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
160 } |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
161 } else if (!g_ascii_strncasecmp(c, "www.", 4) && (c == text || badchar(c[-1]) || badentity(c-1))) { |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
162 if (c[4] != '.') { |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
163 t = c; |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
164 while (1) { |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
165 if (badchar(*t) || badentity(t)) { |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
166 if (t - c == 4) { |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
167 break; |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
168 } |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
169 |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
170 if (*(t) == ',' && (*(t + 1) != ' ')) { |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
171 t++; |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
172 continue; |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
173 } |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
174 |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
175 if (*(t - 1) == '.') |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
176 t--; |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
177 if ((*(t - 1) == ')' && (inside_paren > 0))) { |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
178 t--; |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
179 } |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
180 url_buf = g_strndup(c, t - c); |
26502
f9a923fde1e4
Remove usage of g_strcmp0 (which would bump the glib version requirement) where strcmp will do nicely
Richard Nelson <wabz@pidgin.im>
parents:
26500
diff
changeset
|
181 if (!g_list_find_custom(ret, url_buf, (GCompareFunc)strcmp)) { |
26500
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
182 purple_debug_info("TinyURL", "Added URL %s\n", url_buf); |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
183 ret = g_list_append(ret, url_buf); |
28344
6b328370cad0
Fix leaks, and a bug.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28309
diff
changeset
|
184 } else { |
6b328370cad0
Fix leaks, and a bug.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28309
diff
changeset
|
185 g_free(url_buf); |
26500
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
186 } |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
187 c = t; |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
188 break; |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
189 } |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
190 t++; |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
191 } |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
192 } |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
193 } |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
194 if (*c == ')' && !inside_html) { |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
195 inside_paren--; |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
196 c++; |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
197 } |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
198 if (*c == 0) |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
199 break; |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
200 c++; |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
201 } |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
202 return ret; |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
203 } |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
204 |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
205 static void url_fetched(PurpleUtilFetchUrlData *url_data, gpointer cb_data, |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
206 const gchar *url_text, gsize len, const gchar *error_message) |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
207 { |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
208 CbInfo *data = (CbInfo *)cb_data; |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
209 PurpleConversation *conv = data->conv; |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
210 GList *convs = purple_get_conversations(); |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
211 /* ensure the conversation still exists */ |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
212 for (; convs; convs = convs->next) { |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
213 if ((PurpleConversation *)(convs->data) == conv) { |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
214 FinchConv *fconv = FINCH_CONV(conv); |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
215 gchar *str = g_strdup_printf("[%d] %s", data->num, url_text); |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
216 GntTextView *tv = GNT_TEXT_VIEW(fconv->tv); |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
217 gnt_text_view_tag_change(tv, data->tag, str, FALSE); |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
218 g_free(str); |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
219 g_free(data->tag); |
28309
7eaf2561b6dd
Extend the TinyURL plugin.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27988
diff
changeset
|
220 g_free(data); |
26500
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
221 return; |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
222 } |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
223 } |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
224 g_free(data->tag); |
28309
7eaf2561b6dd
Extend the TinyURL plugin.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27988
diff
changeset
|
225 g_free(data); |
26500
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
226 purple_debug_info("TinyURL", "Conversation no longer exists... :(\n"); |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
227 } |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
228 |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
229 static void free_urls(gpointer data, gpointer null) |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
230 { |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
231 g_free(data); |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
232 } |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
233 |
28309
7eaf2561b6dd
Extend the TinyURL plugin.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27988
diff
changeset
|
234 static gboolean writing_msg(PurpleAccount *account, char *sender, char **message, |
7eaf2561b6dd
Extend the TinyURL plugin.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27988
diff
changeset
|
235 PurpleConversation *conv, PurpleMessageFlags flags) |
7eaf2561b6dd
Extend the TinyURL plugin.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27988
diff
changeset
|
236 { |
26500
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
237 GString *t; |
28344
6b328370cad0
Fix leaks, and a bug.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28309
diff
changeset
|
238 GList *iter, *urls, *next; |
26500
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
239 int c = 0; |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
240 |
28309
7eaf2561b6dd
Extend the TinyURL plugin.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27988
diff
changeset
|
241 if ((flags & (PURPLE_MESSAGE_SEND | PURPLE_MESSAGE_INVISIBLE))) |
26500
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
242 return FALSE; |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
243 |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
244 urls = purple_conversation_get_data(conv, "TinyURLs"); |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
245 if (urls != NULL) /* message was cancelled somewhere? Reset. */ |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
246 g_list_foreach(urls, free_urls, NULL); |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
247 g_list_free(urls); |
26949
0f1b41c2f835
Reduce work if there is no URL in the incoming message.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
26507
diff
changeset
|
248 urls = extract_urls(*message); |
0f1b41c2f835
Reduce work if there is no URL in the incoming message.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
26507
diff
changeset
|
249 if (!urls) |
0f1b41c2f835
Reduce work if there is no URL in the incoming message.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
26507
diff
changeset
|
250 return FALSE; |
0f1b41c2f835
Reduce work if there is no URL in the incoming message.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
26507
diff
changeset
|
251 |
0f1b41c2f835
Reduce work if there is no URL in the incoming message.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
26507
diff
changeset
|
252 t = g_string_new(*message); |
26500
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
253 g_free(*message); |
28344
6b328370cad0
Fix leaks, and a bug.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28309
diff
changeset
|
254 for (iter = urls; iter; iter = next) { |
6b328370cad0
Fix leaks, and a bug.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28309
diff
changeset
|
255 next = iter->next; |
26500
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
256 if (g_utf8_strlen((char *)iter->data, -1) >= purple_prefs_get_int(PREF_LENGTH)) { |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
257 int pos, x = 0; |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
258 gchar *j, *s, *str, *orig; |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
259 glong len = g_utf8_strlen(iter->data, -1); |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
260 s = g_strdup(t->str); |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
261 orig = s; |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
262 str = g_strdup_printf("[%d]", ++c); |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
263 while ((j = strstr(s, iter->data))) { /* replace all occurrences */ |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
264 pos = j - orig + (x++ * 3); |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
265 s = j + len; |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
266 t = g_string_insert(t, pos + len, str); |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
267 if (*s == '\0') break; |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
268 } |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
269 g_free(orig); |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
270 g_free(str); |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
271 continue; |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
272 } else { |
28344
6b328370cad0
Fix leaks, and a bug.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28309
diff
changeset
|
273 g_free(iter->data); |
6b328370cad0
Fix leaks, and a bug.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28309
diff
changeset
|
274 urls = g_list_delete_link(urls, iter); |
26500
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
275 } |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
276 } |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
277 *message = t->str; |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
278 g_string_free(t, FALSE); |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
279 if (conv == NULL) |
28309
7eaf2561b6dd
Extend the TinyURL plugin.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27988
diff
changeset
|
280 conv = purple_conversation_new(PURPLE_CONV_TYPE_IM, account, sender); |
26500
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
281 purple_conversation_set_data(conv, "TinyURLs", urls); |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
282 return FALSE; |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
283 } |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
284 |
28309
7eaf2561b6dd
Extend the TinyURL plugin.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27988
diff
changeset
|
285 static void wrote_msg(PurpleAccount *account, char *sender, char *message, |
7eaf2561b6dd
Extend the TinyURL plugin.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27988
diff
changeset
|
286 PurpleConversation *conv, PurpleMessageFlags flags) |
7eaf2561b6dd
Extend the TinyURL plugin.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27988
diff
changeset
|
287 { |
7eaf2561b6dd
Extend the TinyURL plugin.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27988
diff
changeset
|
288 GList *urls; |
7eaf2561b6dd
Extend the TinyURL plugin.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27988
diff
changeset
|
289 |
7eaf2561b6dd
Extend the TinyURL plugin.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27988
diff
changeset
|
290 urls = purple_conversation_get_data(conv, "TinyURLs"); |
7eaf2561b6dd
Extend the TinyURL plugin.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27988
diff
changeset
|
291 if ((flags & PURPLE_MESSAGE_SEND) || urls == NULL) |
7eaf2561b6dd
Extend the TinyURL plugin.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27988
diff
changeset
|
292 return; |
7eaf2561b6dd
Extend the TinyURL plugin.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27988
diff
changeset
|
293 |
7eaf2561b6dd
Extend the TinyURL plugin.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27988
diff
changeset
|
294 process_urls(conv, urls); |
7eaf2561b6dd
Extend the TinyURL plugin.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27988
diff
changeset
|
295 purple_conversation_set_data(conv, "TinyURLs", NULL); |
7eaf2561b6dd
Extend the TinyURL plugin.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27988
diff
changeset
|
296 } |
7eaf2561b6dd
Extend the TinyURL plugin.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27988
diff
changeset
|
297 |
7eaf2561b6dd
Extend the TinyURL plugin.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27988
diff
changeset
|
298 /* Frees 'urls' */ |
7eaf2561b6dd
Extend the TinyURL plugin.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27988
diff
changeset
|
299 static void |
7eaf2561b6dd
Extend the TinyURL plugin.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27988
diff
changeset
|
300 process_urls(PurpleConversation *conv, GList *urls) |
7eaf2561b6dd
Extend the TinyURL plugin.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27988
diff
changeset
|
301 { |
7eaf2561b6dd
Extend the TinyURL plugin.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27988
diff
changeset
|
302 GList *iter; |
26500
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
303 int c; |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
304 FinchConv *fconv = FINCH_CONV(conv); |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
305 GntTextView *tv = GNT_TEXT_VIEW(fconv->tv); |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
306 |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
307 for (iter = urls, c = 0; iter; iter = iter->next) { |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
308 int i; |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
309 CbInfo *cbdata; |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
310 gchar *url, *str, *tmp; |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
311 cbdata = g_new(CbInfo, 1); |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
312 cbdata->num = ++c; |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
313 cbdata->tag = g_strdup_printf("%s%d", "tiny_", tag_num++); |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
314 cbdata->conv = conv; |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
315 tmp = purple_unescape_html((char *)iter->data); |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
316 if (g_ascii_strncasecmp(tmp, "http://", 7) && g_ascii_strncasecmp(tmp, "https://", 8)) { |
26507
c5920a8cf83f
encode urls passed to tinyurl
Richard Nelson <wabz@pidgin.im>
parents:
26502
diff
changeset
|
317 url = g_strdup_printf("%shttp%%3A%%2F%%2F%s", purple_prefs_get_string(PREF_URL), purple_url_encode(tmp)); |
26500
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
318 } else { |
26507
c5920a8cf83f
encode urls passed to tinyurl
Richard Nelson <wabz@pidgin.im>
parents:
26502
diff
changeset
|
319 url = g_strdup_printf("%s%s", purple_prefs_get_string(PREF_URL), purple_url_encode(tmp)); |
26500
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
320 } |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
321 g_free(tmp); |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
322 purple_util_fetch_url(url, TRUE, "finch", FALSE, url_fetched, cbdata); |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
323 i = gnt_text_view_get_lines_below(tv); |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
324 str = g_strdup_printf(_("\nFetching TinyURL...")); |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
325 gnt_text_view_append_text_with_tag((tv), str, GNT_TEXT_FLAG_DIM, cbdata->tag); |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
326 g_free(str); |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
327 if (i == 0) |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
328 gnt_text_view_scroll(tv, 0); |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
329 g_free(iter->data); |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
330 g_free(url); |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
331 } |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
332 g_list_free(urls); |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
333 } |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
334 |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
335 static void |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
336 free_conv_urls(PurpleConversation *conv) |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
337 { |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
338 GList *urls = purple_conversation_get_data(conv, "TinyURLs"); |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
339 if (urls) |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
340 g_list_foreach(urls, free_urls, NULL); |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
341 g_list_free(urls); |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
342 } |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
343 |
28309
7eaf2561b6dd
Extend the TinyURL plugin.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27988
diff
changeset
|
344 static void tinyurl_notify_fetch_cb(PurpleUtilFetchUrlData *urldata, gpointer cbdata, |
7eaf2561b6dd
Extend the TinyURL plugin.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27988
diff
changeset
|
345 const gchar *urltext, gsize len, const gchar *error) |
7eaf2561b6dd
Extend the TinyURL plugin.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27988
diff
changeset
|
346 { |
7eaf2561b6dd
Extend the TinyURL plugin.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27988
diff
changeset
|
347 GntWidget *win = cbdata; |
7eaf2561b6dd
Extend the TinyURL plugin.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27988
diff
changeset
|
348 GntWidget *label = g_object_get_data(G_OBJECT(win), "info-widget"); |
7eaf2561b6dd
Extend the TinyURL plugin.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27988
diff
changeset
|
349 char *message; |
7eaf2561b6dd
Extend the TinyURL plugin.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27988
diff
changeset
|
350 |
7eaf2561b6dd
Extend the TinyURL plugin.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27988
diff
changeset
|
351 message = g_strdup_printf(_("TinyURL for above: %s"), urltext); |
7eaf2561b6dd
Extend the TinyURL plugin.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27988
diff
changeset
|
352 gnt_label_set_text(GNT_LABEL(label), message); |
7eaf2561b6dd
Extend the TinyURL plugin.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27988
diff
changeset
|
353 g_free(message); |
7eaf2561b6dd
Extend the TinyURL plugin.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27988
diff
changeset
|
354 |
7eaf2561b6dd
Extend the TinyURL plugin.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27988
diff
changeset
|
355 g_signal_handlers_disconnect_matched(G_OBJECT(win), G_SIGNAL_MATCH_FUNC, |
7eaf2561b6dd
Extend the TinyURL plugin.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27988
diff
changeset
|
356 0, 0, NULL, |
7eaf2561b6dd
Extend the TinyURL plugin.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27988
diff
changeset
|
357 G_CALLBACK(purple_util_fetch_url_cancel), NULL); |
7eaf2561b6dd
Extend the TinyURL plugin.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27988
diff
changeset
|
358 } |
7eaf2561b6dd
Extend the TinyURL plugin.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27988
diff
changeset
|
359 |
7eaf2561b6dd
Extend the TinyURL plugin.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27988
diff
changeset
|
360 static void * |
7eaf2561b6dd
Extend the TinyURL plugin.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27988
diff
changeset
|
361 tinyurl_notify_uri(const char *uri) |
7eaf2561b6dd
Extend the TinyURL plugin.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27988
diff
changeset
|
362 { |
7eaf2561b6dd
Extend the TinyURL plugin.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27988
diff
changeset
|
363 char *fullurl = NULL; |
7eaf2561b6dd
Extend the TinyURL plugin.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27988
diff
changeset
|
364 GntWidget *win; |
7eaf2561b6dd
Extend the TinyURL plugin.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27988
diff
changeset
|
365 PurpleUtilFetchUrlData *urlcb; |
7eaf2561b6dd
Extend the TinyURL plugin.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27988
diff
changeset
|
366 |
7eaf2561b6dd
Extend the TinyURL plugin.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27988
diff
changeset
|
367 /* XXX: The following expects that finch_notify_message gets called. This |
7eaf2561b6dd
Extend the TinyURL plugin.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27988
diff
changeset
|
368 * may not always happen, e.g. when another plugin sets its own |
7eaf2561b6dd
Extend the TinyURL plugin.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27988
diff
changeset
|
369 * notify_message. So tread carefully. */ |
7eaf2561b6dd
Extend the TinyURL plugin.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27988
diff
changeset
|
370 win = purple_notify_message(NULL, PURPLE_NOTIFY_URI, _("URI"), uri, |
7eaf2561b6dd
Extend the TinyURL plugin.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27988
diff
changeset
|
371 _("Please wait while TinyURL fetches a shorter URL ..."), NULL, NULL); |
7eaf2561b6dd
Extend the TinyURL plugin.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27988
diff
changeset
|
372 if (!GNT_IS_WINDOW(win) || !g_object_get_data(G_OBJECT(win), "info-widget")) |
7eaf2561b6dd
Extend the TinyURL plugin.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27988
diff
changeset
|
373 return win; |
7eaf2561b6dd
Extend the TinyURL plugin.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27988
diff
changeset
|
374 |
7eaf2561b6dd
Extend the TinyURL plugin.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27988
diff
changeset
|
375 if (g_ascii_strncasecmp(uri, "http://", 7) && g_ascii_strncasecmp(uri, "https://", 8)) { |
7eaf2561b6dd
Extend the TinyURL plugin.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27988
diff
changeset
|
376 fullurl = g_strdup_printf("%shttp%%3A%%2F%%2F%s", |
7eaf2561b6dd
Extend the TinyURL plugin.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27988
diff
changeset
|
377 purple_prefs_get_string(PREF_URL), purple_url_encode(uri)); |
7eaf2561b6dd
Extend the TinyURL plugin.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27988
diff
changeset
|
378 } else { |
7eaf2561b6dd
Extend the TinyURL plugin.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27988
diff
changeset
|
379 fullurl = g_strdup_printf("%s%s", purple_prefs_get_string(PREF_URL), |
7eaf2561b6dd
Extend the TinyURL plugin.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27988
diff
changeset
|
380 purple_url_encode(uri)); |
7eaf2561b6dd
Extend the TinyURL plugin.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27988
diff
changeset
|
381 } |
7eaf2561b6dd
Extend the TinyURL plugin.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27988
diff
changeset
|
382 |
7eaf2561b6dd
Extend the TinyURL plugin.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27988
diff
changeset
|
383 /* Store the return value of _fetch_url and destroy that when win is |
7eaf2561b6dd
Extend the TinyURL plugin.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27988
diff
changeset
|
384 destroyed, so that the callback for _fetch_url does not try to molest a |
7eaf2561b6dd
Extend the TinyURL plugin.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27988
diff
changeset
|
385 non-existent window */ |
7eaf2561b6dd
Extend the TinyURL plugin.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27988
diff
changeset
|
386 urlcb = purple_util_fetch_url(fullurl, TRUE, "finch", FALSE, tinyurl_notify_fetch_cb, win); |
7eaf2561b6dd
Extend the TinyURL plugin.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27988
diff
changeset
|
387 g_free(fullurl); |
7eaf2561b6dd
Extend the TinyURL plugin.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27988
diff
changeset
|
388 g_signal_connect_swapped(G_OBJECT(win), "destroy", |
7eaf2561b6dd
Extend the TinyURL plugin.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27988
diff
changeset
|
389 G_CALLBACK(purple_util_fetch_url_cancel), urlcb); |
7eaf2561b6dd
Extend the TinyURL plugin.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27988
diff
changeset
|
390 |
7eaf2561b6dd
Extend the TinyURL plugin.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27988
diff
changeset
|
391 return win; |
7eaf2561b6dd
Extend the TinyURL plugin.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27988
diff
changeset
|
392 } |
7eaf2561b6dd
Extend the TinyURL plugin.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27988
diff
changeset
|
393 |
26500
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
394 static gboolean |
28309
7eaf2561b6dd
Extend the TinyURL plugin.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27988
diff
changeset
|
395 plugin_load(PurplePlugin *plugin) |
7eaf2561b6dd
Extend the TinyURL plugin.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27988
diff
changeset
|
396 { |
7eaf2561b6dd
Extend the TinyURL plugin.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27988
diff
changeset
|
397 PurpleNotifyUiOps *ops = purple_notify_get_ui_ops(); |
7eaf2561b6dd
Extend the TinyURL plugin.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27988
diff
changeset
|
398 plugin->extra = ops->notify_uri; |
7eaf2561b6dd
Extend the TinyURL plugin.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27988
diff
changeset
|
399 ops->notify_uri = tinyurl_notify_uri; |
7eaf2561b6dd
Extend the TinyURL plugin.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27988
diff
changeset
|
400 |
26500
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
401 purple_signal_connect(purple_conversations_get_handle(), |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
402 "wrote-im-msg", |
28309
7eaf2561b6dd
Extend the TinyURL plugin.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27988
diff
changeset
|
403 plugin, PURPLE_CALLBACK(wrote_msg), NULL); |
26500
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
404 purple_signal_connect(purple_conversations_get_handle(), |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
405 "wrote-chat-msg", |
28309
7eaf2561b6dd
Extend the TinyURL plugin.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27988
diff
changeset
|
406 plugin, PURPLE_CALLBACK(wrote_msg), NULL); |
26500
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
407 purple_signal_connect(purple_conversations_get_handle(), |
28309
7eaf2561b6dd
Extend the TinyURL plugin.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27988
diff
changeset
|
408 "writing-im-msg", |
7eaf2561b6dd
Extend the TinyURL plugin.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27988
diff
changeset
|
409 plugin, PURPLE_CALLBACK(writing_msg), NULL); |
26500
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
410 purple_signal_connect(purple_conversations_get_handle(), |
28309
7eaf2561b6dd
Extend the TinyURL plugin.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27988
diff
changeset
|
411 "writing-chat-msg", |
7eaf2561b6dd
Extend the TinyURL plugin.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27988
diff
changeset
|
412 plugin, PURPLE_CALLBACK(writing_msg), NULL); |
26500
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
413 purple_signal_connect(purple_conversations_get_handle(), |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
414 "deleting-conversation", |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
415 plugin, PURPLE_CALLBACK(free_conv_urls), NULL); |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
416 |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
417 return TRUE; |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
418 } |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
419 |
28309
7eaf2561b6dd
Extend the TinyURL plugin.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27988
diff
changeset
|
420 static gboolean |
7eaf2561b6dd
Extend the TinyURL plugin.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27988
diff
changeset
|
421 plugin_unload(PurplePlugin *plugin) |
7eaf2561b6dd
Extend the TinyURL plugin.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27988
diff
changeset
|
422 { |
7eaf2561b6dd
Extend the TinyURL plugin.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27988
diff
changeset
|
423 PurpleNotifyUiOps *ops = purple_notify_get_ui_ops(); |
7eaf2561b6dd
Extend the TinyURL plugin.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27988
diff
changeset
|
424 if (ops->notify_uri == tinyurl_notify_uri) |
7eaf2561b6dd
Extend the TinyURL plugin.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27988
diff
changeset
|
425 ops->notify_uri = plugin->extra; |
7eaf2561b6dd
Extend the TinyURL plugin.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27988
diff
changeset
|
426 return TRUE; |
7eaf2561b6dd
Extend the TinyURL plugin.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27988
diff
changeset
|
427 } |
7eaf2561b6dd
Extend the TinyURL plugin.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27988
diff
changeset
|
428 |
26500
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
429 static PurplePluginPrefFrame * |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
430 get_plugin_pref_frame(PurplePlugin *plugin) { |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
431 |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
432 PurplePluginPrefFrame *frame; |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
433 PurplePluginPref *pref; |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
434 |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
435 frame = purple_plugin_pref_frame_new(); |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
436 |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
437 pref = purple_plugin_pref_new_with_name(PREF_LENGTH); |
27987
6aa8e64fdbb7
Capitalize the abbreviation "URL," as suggested by F Wolff on the
Mark Doliner <mark@kingant.net>
parents:
26949
diff
changeset
|
438 purple_plugin_pref_set_label(pref, _("Only create TinyURL for URLs" |
26500
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
439 " of this length or greater")); |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
440 purple_plugin_pref_frame_add(frame, pref); |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
441 pref = purple_plugin_pref_new_with_name(PREF_URL); |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
442 purple_plugin_pref_set_label(pref, _("TinyURL (or other) address prefix")); |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
443 purple_plugin_pref_frame_add(frame, pref); |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
444 |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
445 return frame; |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
446 } |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
447 |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
448 static PurplePluginUiInfo prefs_info = { |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
449 get_plugin_pref_frame, |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
450 0, /* page_num (Reserved) */ |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
451 NULL, /* frame (Reserved) */ |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
452 |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
453 /* padding */ |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
454 NULL, |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
455 NULL, |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
456 NULL, |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
457 NULL |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
458 }; |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
459 |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
460 static PurplePluginInfo info = |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
461 { |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
462 PURPLE_PLUGIN_MAGIC, |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
463 PURPLE_MAJOR_VERSION, |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
464 PURPLE_MINOR_VERSION, |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
465 PURPLE_PLUGIN_STANDARD, |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
466 FINCH_PLUGIN_TYPE, |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
467 0, |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
468 NULL, |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
469 PURPLE_PRIORITY_DEFAULT, |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
470 "TinyURL", |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
471 N_("TinyURL"), |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
472 DISPLAY_VERSION, |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
473 N_("TinyURL plugin"), |
27988
4e7b8902da90
Add a verb to this sentence, as suggested by F Wolff on the translators
Mark Doliner <mark@kingant.net>
parents:
27987
diff
changeset
|
474 N_("When receiving a message with URL(s), use TinyURL for easier copying"), |
26500
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
475 "Richard Nelson <wabz@whatsbeef.net>", |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
476 PURPLE_WEBSITE, |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
477 plugin_load, |
28309
7eaf2561b6dd
Extend the TinyURL plugin.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27988
diff
changeset
|
478 plugin_unload, |
26500
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
479 NULL, |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
480 NULL, |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
481 NULL, |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
482 &prefs_info, /**< prefs_info */ |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
483 NULL, |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
484 |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
485 /* padding */ |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
486 NULL, |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
487 NULL, |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
488 NULL, |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
489 NULL |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
490 }; |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
491 |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
492 static void |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
493 init_plugin(PurplePlugin *plugin) { |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
494 purple_prefs_add_none(PREFS_BASE); |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
495 purple_prefs_add_int(PREF_LENGTH, 30); |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
496 purple_prefs_add_string(PREF_URL, "http://tinyurl.com/api-create.php?url="); |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
497 } |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
498 |
8986c3804ada
Add a gnt TinyURL plugin. Closes #2017
Richard Nelson <wabz@pidgin.im>
parents:
diff
changeset
|
499 PURPLE_INIT_PLUGIN(PLUGIN_STATIC_NAME, init_plugin, info) |