comparison libpurple/plugins/autoaccept.c @ 31364:ea2a155b4439

propagate from branch 'im.pidgin.pidgin' (head 7d1d85421a7221e67b586df32625c65c1434f195) to branch 'im.pidgin.pidgin.next.minor' (head 5806c0bc47c791300ede51ab92336dd817bd149c)
author John Bailey <rekkanoryo@rekkanoryo.org>
date Sat, 08 Jan 2011 03:10:40 +0000
parents a8cc50c2279f
children 26a4f6fc8024 bba25395d28e
comparison
equal deleted inserted replaced
31363:539aa44be788 31364:ea2a155b4439
41 #include <notify.h> 41 #include <notify.h>
42 #include <util.h> 42 #include <util.h>
43 43
44 #define PREF_PREFIX "/plugins/core/" PLUGIN_ID 44 #define PREF_PREFIX "/plugins/core/" PLUGIN_ID
45 #define PREF_PATH PREF_PREFIX "/path" 45 #define PREF_PATH PREF_PREFIX "/path"
46 #define PREF_STRANGER PREF_PREFIX "/reject_stranger" 46 #define PREF_STRANGER PREF_PREFIX "/stranger"
47 #define PREF_NOTIFY PREF_PREFIX "/notify" 47 #define PREF_NOTIFY PREF_PREFIX "/notify"
48 #define PREF_NEWDIR PREF_PREFIX "/newdir" 48 #define PREF_NEWDIR PREF_PREFIX "/newdir"
49 #define PREF_ESCAPE PREF_PREFIX "/escape"
50
51 #define PREF_STRANGER_OLD PREF_PREFIX "/reject_stranger"
49 52
50 typedef enum 53 typedef enum
51 { 54 {
52 FT_ASK, 55 FT_ASK,
53 FT_ACCEPT, 56 FT_ACCEPT,
86 PurpleBlistNode *node; 89 PurpleBlistNode *node;
87 const char *pref; 90 const char *pref;
88 char *filename; 91 char *filename;
89 char *dirname; 92 char *dirname;
90 93
94 int accept_setting;
95
91 account = xfer->account; 96 account = xfer->account;
92 node = PURPLE_BLIST_NODE(purple_find_buddy(account, xfer->who)); 97 node = PURPLE_BLIST_NODE(purple_find_buddy(account, xfer->who));
93 98
94 if (!node) 99 /* If person is on buddy list, use the buddy setting; otherwise, use the
95 { 100 stranger setting. */
96 if (purple_prefs_get_bool(PREF_STRANGER)) 101 if (node) {
97 xfer->status = PURPLE_XFER_STATUS_CANCEL_LOCAL; 102 node = purple_blist_node_get_parent(node);
98 return; 103 g_return_if_fail(PURPLE_BLIST_NODE_IS_CONTACT(node));
104 accept_setting = purple_blist_node_get_int(node, "autoaccept");
105 } else {
106 accept_setting = purple_prefs_get_int(PREF_STRANGER);
99 } 107 }
100 108
101 node = purple_blist_node_get_parent(node); 109 switch (accept_setting)
102 g_return_if_fail(PURPLE_BLIST_NODE_IS_CONTACT(node));
103
104 pref = purple_prefs_get_string(PREF_PATH);
105 switch (purple_blist_node_get_int(node, "autoaccept"))
106 { 110 {
107 case FT_ASK: 111 case FT_ASK:
108 break; 112 break;
109 case FT_ACCEPT: 113 case FT_ACCEPT:
114 pref = purple_prefs_get_string(PREF_PATH);
110 if (ensure_path_exists(pref)) 115 if (ensure_path_exists(pref))
111 { 116 {
112 int count = 1; 117 int count = 1;
113 const char *escape; 118 const char *escape;
114 gchar **name_and_ext; 119 gchar **name_and_ext;
124 { 129 {
125 g_free(dirname); 130 g_free(dirname);
126 break; 131 break;
127 } 132 }
128 133
129 escape = purple_escape_filename(xfer->filename); 134 /* Escape filename (if escaping is turned on) */
135 if (purple_prefs_get_bool(PREF_ESCAPE)) {
136 escape = purple_escape_filename(xfer->filename);
137 } else {
138 escape = xfer->filename;
139 }
130 filename = g_build_filename(dirname, escape, NULL); 140 filename = g_build_filename(dirname, escape, NULL);
131 141
132 /* Split at the first dot, to avoid uniquifying "foo.tar.gz" to "foo.tar-2.gz" */ 142 /* Split at the first dot, to avoid uniquifying "foo.tar.gz" to "foo.tar-2.gz" */
133 name_and_ext = g_strsplit(escape, ".", 2); 143 name_and_ext = g_strsplit(escape, ".", 2);
134 name = name_and_ext[0]; 144 name = name_and_ext[0];
185 195
186 if (PURPLE_BLIST_NODE_IS_BUDDY(node)) 196 if (PURPLE_BLIST_NODE_IS_BUDDY(node))
187 node = purple_blist_node_get_parent(node); 197 node = purple_blist_node_get_parent(node);
188 g_return_if_fail(PURPLE_BLIST_NODE_IS_CONTACT(node)); 198 g_return_if_fail(PURPLE_BLIST_NODE_IS_CONTACT(node));
189 199
190 message = g_strdup_printf(_("When a file-transfer request arrives from %s"), 200 message = g_strdup_printf(_("When a file-transfer request arrives from %s"),
191 purple_contact_get_alias((PurpleContact *)node)); 201 purple_contact_get_alias((PurpleContact *)node));
192 purple_request_choice(plugin, _("Set Autoaccept Setting"), message, 202 purple_request_choice(plugin, _("Set Autoaccept Setting"), message,
193 NULL, purple_blist_node_get_int(node, "autoaccept"), 203 NULL, purple_blist_node_get_int(node, "autoaccept"),
194 _("_Save"), G_CALLBACK(save_cb), 204 _("_Save"), G_CALLBACK(save_cb),
195 _("_Cancel"), NULL, 205 _("_Cancel"), NULL,
218 } 228 }
219 229
220 static gboolean 230 static gboolean
221 plugin_load(PurplePlugin *plugin) 231 plugin_load(PurplePlugin *plugin)
222 { 232 {
233 /* migrate the old pref (we should only care if the plugin is actually *used*) */
234 /*
235 * TODO: We should eventually call purple_prefs_remove(PREFS_STRANGER_OLD)
236 * to clean up after ourselves, but we don't want to do it yet
237 * so that we don't break users who share a .purple directory
238 * between old libpurple clients and new libpurple clients.
239 * --Mark Doliner, 2011-01-03
240 */
241 if(purple_prefs_get_bool(PREF_STRANGER_OLD))
242 purple_prefs_set_int(PREF_STRANGER, FT_REJECT);
243
223 purple_signal_connect(purple_xfers_get_handle(), "file-recv-request", plugin, 244 purple_signal_connect(purple_xfers_get_handle(), "file-recv-request", plugin,
224 PURPLE_CALLBACK(file_recv_request_cb), plugin); 245 PURPLE_CALLBACK(file_recv_request_cb), plugin);
225 purple_signal_connect(purple_blist_get_handle(), "blist-node-extended-menu", plugin, 246 purple_signal_connect(purple_blist_get_handle(), "blist-node-extended-menu", plugin,
226 PURPLE_CALLBACK(context_menu), plugin); 247 PURPLE_CALLBACK(context_menu), plugin);
227 return TRUE; 248 return TRUE;
245 pref = purple_plugin_pref_new_with_name_and_label(PREF_PATH, _("Path to save the files in\n" 266 pref = purple_plugin_pref_new_with_name_and_label(PREF_PATH, _("Path to save the files in\n"
246 "(Please provide the full path)")); 267 "(Please provide the full path)"));
247 purple_plugin_pref_frame_add(frame, pref); 268 purple_plugin_pref_frame_add(frame, pref);
248 269
249 pref = purple_plugin_pref_new_with_name_and_label(PREF_STRANGER, 270 pref = purple_plugin_pref_new_with_name_and_label(PREF_STRANGER,
250 _("Automatically reject from users not in buddy list")); 271 _("When a file-transfer request arrives from a user who is\n"
272 "*not* on your buddy list:"));
273 purple_plugin_pref_set_type(pref, PURPLE_PLUGIN_PREF_CHOICE);
274 purple_plugin_pref_add_choice(pref, _("Ask"), GINT_TO_POINTER(FT_ASK));
275 purple_plugin_pref_add_choice(pref, _("Auto Accept"), GINT_TO_POINTER(FT_ACCEPT));
276 purple_plugin_pref_add_choice(pref, _("Auto Reject"), GINT_TO_POINTER(FT_REJECT));
251 purple_plugin_pref_frame_add(frame, pref); 277 purple_plugin_pref_frame_add(frame, pref);
252 278
253 pref = purple_plugin_pref_new_with_name_and_label(PREF_NOTIFY, 279 pref = purple_plugin_pref_new_with_name_and_label(PREF_NOTIFY,
254 _("Notify with a popup when an autoaccepted file transfer is complete\n" 280 _("Notify with a popup when an autoaccepted file transfer is complete\n"
255 "(only when there's no conversation with the sender)")); 281 "(only when there's no conversation with the sender)"));
256 purple_plugin_pref_frame_add(frame, pref); 282 purple_plugin_pref_frame_add(frame, pref);
257 283
258 pref = purple_plugin_pref_new_with_name_and_label(PREF_NEWDIR, 284 pref = purple_plugin_pref_new_with_name_and_label(PREF_NEWDIR,
259 _("Create a new directory for each user")); 285 _("Create a new directory for each user"));
286 purple_plugin_pref_frame_add(frame, pref);
287
288 pref = purple_plugin_pref_new_with_name_and_label(PREF_ESCAPE,
289 _("Escape the filenames"));
260 purple_plugin_pref_frame_add(frame, pref); 290 purple_plugin_pref_frame_add(frame, pref);
261 291
262 return frame; 292 return frame;
263 } 293 }
264 294
313 char *dirname; 343 char *dirname;
314 344
315 dirname = g_build_filename(purple_user_dir(), "autoaccept", NULL); 345 dirname = g_build_filename(purple_user_dir(), "autoaccept", NULL);
316 purple_prefs_add_none(PREF_PREFIX); 346 purple_prefs_add_none(PREF_PREFIX);
317 purple_prefs_add_string(PREF_PATH, dirname); 347 purple_prefs_add_string(PREF_PATH, dirname);
318 purple_prefs_add_bool(PREF_STRANGER, TRUE); 348 purple_prefs_add_int(PREF_STRANGER, FT_ASK);
319 purple_prefs_add_bool(PREF_NOTIFY, TRUE); 349 purple_prefs_add_bool(PREF_NOTIFY, TRUE);
320 purple_prefs_add_bool(PREF_NEWDIR, TRUE); 350 purple_prefs_add_bool(PREF_NEWDIR, TRUE);
351 purple_prefs_add_bool(PREF_ESCAPE, TRUE);
321 g_free(dirname); 352 g_free(dirname);
322 } 353 }
323 354
324 PURPLE_INIT_PLUGIN(PLUGIN_STATIC_NAME, init_plugin, info) 355 PURPLE_INIT_PLUGIN(PLUGIN_STATIC_NAME, init_plugin, info)