Mercurial > pidgin
comparison libpurple/plugins/autoaccept.c @ 31079:5f4329c3eafe
Add additional options to the autoaccept plugin. Fixes #11459.
committer: John Bailey <rekkanoryo@rekkanoryo.org>
author | rok.mandeljc@gmail.com |
---|---|
date | Thu, 30 Dec 2010 00:42:24 +0000 |
parents | 39716f7d2c93 |
children | 40e5d8c3acca |
comparison
equal
deleted
inserted
replaced
31078:3a94faf350c7 | 31079:5f4329c3eafe |
---|---|
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" | |
49 | 50 |
50 typedef enum | 51 typedef enum |
51 { | 52 { |
52 FT_ASK, | 53 FT_ASK, |
53 FT_ACCEPT, | 54 FT_ACCEPT, |
86 PurpleBlistNode *node; | 87 PurpleBlistNode *node; |
87 const char *pref; | 88 const char *pref; |
88 char *filename; | 89 char *filename; |
89 char *dirname; | 90 char *dirname; |
90 | 91 |
92 int accept_setting; | |
93 | |
91 account = xfer->account; | 94 account = xfer->account; |
92 node = PURPLE_BLIST_NODE(purple_find_buddy(account, xfer->who)); | 95 node = PURPLE_BLIST_NODE(purple_find_buddy(account, xfer->who)); |
93 | 96 |
94 if (!node) | 97 /* If person is on buddy list, use the buddy setting; otherwise, use the |
95 { | 98 stranger setting. */ |
96 if (purple_prefs_get_bool(PREF_STRANGER)) | 99 if (node) { |
97 xfer->status = PURPLE_XFER_STATUS_CANCEL_LOCAL; | 100 node = purple_blist_node_get_parent(node); |
98 return; | 101 g_return_if_fail(PURPLE_BLIST_NODE_IS_CONTACT(node)); |
102 accept_setting = purple_blist_node_get_int(node, "autoaccept"); | |
103 } else { | |
104 accept_setting = purple_prefs_get_int(PREF_STRANGER); | |
99 } | 105 } |
100 | 106 |
101 node = purple_blist_node_get_parent(node); | 107 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 { | 108 { |
107 case FT_ASK: | 109 case FT_ASK: |
108 break; | 110 break; |
109 case FT_ACCEPT: | 111 case FT_ACCEPT: |
112 pref = purple_prefs_get_string(PREF_PATH); | |
110 if (ensure_path_exists(pref)) | 113 if (ensure_path_exists(pref)) |
111 { | 114 { |
112 int count = 1; | 115 int count = 1; |
113 const char *escape; | 116 const char *escape; |
114 gchar **name_and_ext; | 117 gchar **name_and_ext; |
124 { | 127 { |
125 g_free(dirname); | 128 g_free(dirname); |
126 break; | 129 break; |
127 } | 130 } |
128 | 131 |
129 escape = purple_escape_filename(xfer->filename); | 132 /* Escape filename (if escaping is turned on) */ |
133 if (purple_prefs_get_bool(PREF_ESCAPE)) { | |
134 escape = purple_escape_filename(xfer->filename); | |
135 } else { | |
136 escape = xfer->filename; | |
137 } | |
130 filename = g_build_filename(dirname, escape, NULL); | 138 filename = g_build_filename(dirname, escape, NULL); |
131 | 139 |
132 /* Split at the first dot, to avoid uniquifying "foo.tar.gz" to "foo.tar-2.gz" */ | 140 /* Split at the first dot, to avoid uniquifying "foo.tar.gz" to "foo.tar-2.gz" */ |
133 name_and_ext = g_strsplit(escape, ".", 2); | 141 name_and_ext = g_strsplit(escape, ".", 2); |
134 name = name_and_ext[0]; | 142 name = name_and_ext[0]; |
245 pref = purple_plugin_pref_new_with_name_and_label(PREF_PATH, _("Path to save the files in\n" | 253 pref = purple_plugin_pref_new_with_name_and_label(PREF_PATH, _("Path to save the files in\n" |
246 "(Please provide the full path)")); | 254 "(Please provide the full path)")); |
247 purple_plugin_pref_frame_add(frame, pref); | 255 purple_plugin_pref_frame_add(frame, pref); |
248 | 256 |
249 pref = purple_plugin_pref_new_with_name_and_label(PREF_STRANGER, | 257 pref = purple_plugin_pref_new_with_name_and_label(PREF_STRANGER, |
250 _("Automatically reject from users not in buddy list")); | 258 _("When a file-transfer request arrives from a user who is\n" |
259 "*not* on your buddy list:")); | |
260 purple_plugin_pref_set_type(pref, PURPLE_PLUGIN_PREF_CHOICE); | |
261 purple_plugin_pref_add_choice(pref, _("Ask"), GINT_TO_POINTER(FT_ASK)); | |
262 purple_plugin_pref_add_choice(pref, _("Auto Accept"), GINT_TO_POINTER(FT_ACCEPT)); | |
263 purple_plugin_pref_add_choice(pref, _("Auto Reject"), GINT_TO_POINTER(FT_REJECT)); | |
251 purple_plugin_pref_frame_add(frame, pref); | 264 purple_plugin_pref_frame_add(frame, pref); |
252 | 265 |
253 pref = purple_plugin_pref_new_with_name_and_label(PREF_NOTIFY, | 266 pref = purple_plugin_pref_new_with_name_and_label(PREF_NOTIFY, |
254 _("Notify with a popup when an autoaccepted file transfer is complete\n" | 267 _("Notify with a popup when an autoaccepted file transfer is complete\n" |
255 "(only when there's no conversation with the sender)")); | 268 "(only when there's no conversation with the sender)")); |
256 purple_plugin_pref_frame_add(frame, pref); | 269 purple_plugin_pref_frame_add(frame, pref); |
257 | 270 |
258 pref = purple_plugin_pref_new_with_name_and_label(PREF_NEWDIR, | 271 pref = purple_plugin_pref_new_with_name_and_label(PREF_NEWDIR, |
259 _("Create a new directory for each user")); | 272 _("Create a new directory for each user")); |
273 purple_plugin_pref_frame_add(frame, pref); | |
274 | |
275 pref = purple_plugin_pref_new_with_name_and_label(PREF_ESCAPE, | |
276 _("Escape the filenames")); | |
260 purple_plugin_pref_frame_add(frame, pref); | 277 purple_plugin_pref_frame_add(frame, pref); |
261 | 278 |
262 return frame; | 279 return frame; |
263 } | 280 } |
264 | 281 |
313 char *dirname; | 330 char *dirname; |
314 | 331 |
315 dirname = g_build_filename(purple_user_dir(), "autoaccept", NULL); | 332 dirname = g_build_filename(purple_user_dir(), "autoaccept", NULL); |
316 purple_prefs_add_none(PREF_PREFIX); | 333 purple_prefs_add_none(PREF_PREFIX); |
317 purple_prefs_add_string(PREF_PATH, dirname); | 334 purple_prefs_add_string(PREF_PATH, dirname); |
318 purple_prefs_add_bool(PREF_STRANGER, TRUE); | 335 purple_prefs_add_int(PREF_STRANGER, FT_ASK); |
319 purple_prefs_add_bool(PREF_NOTIFY, TRUE); | 336 purple_prefs_add_bool(PREF_NOTIFY, TRUE); |
320 purple_prefs_add_bool(PREF_NEWDIR, TRUE); | 337 purple_prefs_add_bool(PREF_NEWDIR, TRUE); |
338 purple_prefs_add_bool(PREF_ESCAPE, TRUE); | |
321 g_free(dirname); | 339 g_free(dirname); |
322 } | 340 } |
323 | 341 |
324 PURPLE_INIT_PLUGIN(PLUGIN_STATIC_NAME, init_plugin, info) | 342 PURPLE_INIT_PLUGIN(PLUGIN_STATIC_NAME, init_plugin, info) |