Sat, 13 Oct 2007 21:55:41 +0000
A patch from QuLogic to eliminate some duplication in the aMSN code, also
from QuLogic. Fixes #3497 (again).
| 15230 | 1 | /* |
| 2 | * Autoaccept - Auto-accept file transfers from selected users | |
| 3 | * Copyright (C) 2006 | |
| 4 | * | |
| 5 | * This program is free software; you can redistribute it and/or | |
| 6 | * modify it under the terms of the GNU General Public License as | |
| 7 | * published by the Free Software Foundation; either version 2 of the | |
| 8 | * License, or (at your option) any later version. | |
| 9 | * | |
| 10 | * This program is distributed in the hope that it will be useful, but | |
| 11 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 13 | * General Public License for more details. | |
| 14 | * | |
| 15 | * You should have received a copy of the GNU General Public License | |
| 16 | * along with this program; if not, write to the Free Software | |
|
19859
71d37b57eff2
The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
19733
diff
changeset
|
17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
71d37b57eff2
The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
19733
diff
changeset
|
18 | * 02111-1301, USA. |
| 15230 | 19 | */ |
| 20 | #include "internal.h" | |
| 21 | ||
| 22 | #define PLUGIN_ID "core-plugin_pack-autoaccept" | |
|
15418
bf287f742a5a
[gaim-migrate @ 18149]
Luke Schierer <lschiere@pidgin.im>
parents:
15230
diff
changeset
|
23 | #define PLUGIN_NAME N_("Autoaccept") |
| 15230 | 24 | #define PLUGIN_STATIC_NAME "Autoaccept" |
|
15418
bf287f742a5a
[gaim-migrate @ 18149]
Luke Schierer <lschiere@pidgin.im>
parents:
15230
diff
changeset
|
25 | #define PLUGIN_SUMMARY N_("Auto-accept file transfer requests from selected users.") |
|
bf287f742a5a
[gaim-migrate @ 18149]
Luke Schierer <lschiere@pidgin.im>
parents:
15230
diff
changeset
|
26 | #define PLUGIN_DESCRIPTION N_("Auto-accept file transfer requests from selected users.") |
| 15230 | 27 | #define PLUGIN_AUTHOR "Sadrul H Chowdhury <sadrul@users.sourceforge.net>" |
| 28 | ||
| 29 | /* System headers */ | |
| 30 | #include <glib.h> | |
| 31 | #if GLIB_CHECK_VERSION(2,6,0) | |
| 32 | # include <glib/gstdio.h> | |
| 33 | #else | |
| 34 | # include <sys/types.h> | |
| 35 | # include <sys/stat.h> | |
| 36 | # define g_mkdir mkdir | |
| 37 | #endif | |
| 38 | ||
| 15884 | 39 | /* Purple headers */ |
| 15230 | 40 | #include <plugin.h> |
| 41 | #include <version.h> | |
| 42 | ||
| 43 | #include <blist.h> | |
| 44 | #include <conversation.h> | |
| 45 | #include <ft.h> | |
| 46 | #include <request.h> | |
| 47 | #include <notify.h> | |
| 48 | #include <util.h> | |
| 49 | ||
| 16481 | 50 | #define PREF_PREFIX "/plugins/core/" PLUGIN_ID |
| 15230 | 51 | #define PREF_PATH PREF_PREFIX "/path" |
| 52 | #define PREF_STRANGER PREF_PREFIX "/reject_stranger" | |
| 53 | #define PREF_NOTIFY PREF_PREFIX "/notify" | |
| 54 | ||
| 55 | typedef enum | |
| 56 | { | |
| 57 | FT_ASK, | |
| 58 | FT_ACCEPT, | |
| 59 | FT_REJECT | |
| 60 | } AutoAcceptSetting; | |
| 61 | ||
| 62 | static gboolean | |
| 63 | ensure_path_exists(const char *dir) | |
| 64 | { | |
| 65 | if (!g_file_test(dir, G_FILE_TEST_IS_DIR)) | |
| 66 | { | |
| 15884 | 67 | if (purple_build_dir(dir, S_IRUSR | S_IWUSR | S_IXUSR)) |
| 15230 | 68 | return FALSE; |
| 69 | } | |
| 70 | ||
| 71 | return TRUE; | |
| 72 | } | |
| 73 | ||
| 74 | static void | |
| 15884 | 75 | auto_accept_complete_cb(PurpleXfer *xfer, PurpleXfer *my) |
| 15230 | 76 | { |
| 15884 | 77 | if (xfer == my && purple_prefs_get_bool(PREF_NOTIFY) && |
| 78 | !purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, xfer->who, xfer->account)) | |
| 15230 | 79 | { |
| 80 | char *message = g_strdup_printf(_("Autoaccepted file transfer of \"%s\" from \"%s\" completed."), | |
| 81 | xfer->filename, xfer->who); | |
| 15884 | 82 | purple_notify_info(NULL, _("Autoaccept complete"), message, NULL); |
| 15230 | 83 | g_free(message); |
| 84 | } | |
| 85 | } | |
| 86 | ||
| 87 | static void | |
| 15884 | 88 | file_recv_request_cb(PurpleXfer *xfer, gpointer handle) |
| 15230 | 89 | { |
| 15884 | 90 | PurpleAccount *account; |
| 91 | PurpleBlistNode *node; | |
| 15230 | 92 | const char *pref; |
| 93 | char *filename; | |
| 94 | char *dirname; | |
| 95 | ||
| 96 | account = xfer->account; | |
| 15884 | 97 | node = (PurpleBlistNode *)purple_find_buddy(account, xfer->who); |
| 15230 | 98 | |
| 99 | if (!node) | |
| 100 | { | |
| 15884 | 101 | if (purple_prefs_get_bool(PREF_STRANGER)) |
| 102 | xfer->status = PURPLE_XFER_STATUS_CANCEL_LOCAL; | |
| 15230 | 103 | return; |
| 104 | } | |
| 105 | ||
| 106 | node = node->parent; | |
| 15884 | 107 | g_return_if_fail(PURPLE_BLIST_NODE_IS_CONTACT(node)); |
| 15230 | 108 | |
|
19733
ec657d978c5a
disapproval of revision 'f08436883bb16f29affdc63e9fd86ff278ed368f'
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
19732
diff
changeset
|
109 | pref = purple_prefs_get_string(PREF_PATH); |
| 15884 | 110 | switch (purple_blist_node_get_int(node, "autoaccept")) |
| 15230 | 111 | { |
| 112 | case FT_ASK: | |
| 113 | break; | |
| 114 | case FT_ACCEPT: | |
| 115 | if (ensure_path_exists(pref)) | |
| 116 | { | |
| 117 | dirname = g_build_filename(pref, xfer->who, NULL); | |
| 118 | ||
| 119 | if (!ensure_path_exists(dirname)) | |
| 120 | { | |
| 121 | g_free(dirname); | |
| 122 | break; | |
| 123 | } | |
| 124 | ||
| 125 | filename = g_build_filename(dirname, xfer->filename, NULL); | |
| 126 | ||
| 15884 | 127 | purple_xfer_request_accepted(xfer, filename); |
| 15230 | 128 | |
| 129 | g_free(dirname); | |
| 130 | g_free(filename); | |
| 131 | } | |
| 132 | ||
| 15884 | 133 | purple_signal_connect(purple_xfers_get_handle(), "file-recv-complete", handle, |
| 134 | PURPLE_CALLBACK(auto_accept_complete_cb), xfer); | |
| 15230 | 135 | break; |
| 136 | case FT_REJECT: | |
| 15884 | 137 | xfer->status = PURPLE_XFER_STATUS_CANCEL_LOCAL; |
| 15230 | 138 | break; |
| 139 | } | |
| 140 | } | |
| 141 | ||
| 142 | static void | |
| 15884 | 143 | save_cb(PurpleBlistNode *node, int choice) |
| 15230 | 144 | { |
| 15884 | 145 | if (PURPLE_BLIST_NODE_IS_BUDDY(node)) |
| 15230 | 146 | node = node->parent; |
| 15884 | 147 | g_return_if_fail(PURPLE_BLIST_NODE_IS_CONTACT(node)); |
| 148 | purple_blist_node_set_int(node, "autoaccept", choice); | |
| 15230 | 149 | } |
| 150 | ||
| 151 | static void | |
| 15884 | 152 | set_auto_accept_settings(PurpleBlistNode *node, gpointer plugin) |
| 15230 | 153 | { |
| 154 | char *message; | |
| 155 | ||
| 15884 | 156 | if (PURPLE_BLIST_NODE_IS_BUDDY(node)) |
| 15230 | 157 | node = node->parent; |
| 15884 | 158 | g_return_if_fail(PURPLE_BLIST_NODE_IS_CONTACT(node)); |
| 15230 | 159 | |
| 160 | message = g_strdup_printf(_("When a file-transfer request arrives from %s"), | |
| 15884 | 161 | purple_contact_get_alias((PurpleContact *)node)); |
| 162 | purple_request_choice(plugin, _("Set Autoaccept Setting"), message, | |
| 163 | NULL, purple_blist_node_get_int(node, "autoaccept"), | |
| 15230 | 164 | _("_Save"), G_CALLBACK(save_cb), |
|
16490
68c22924d66b
Added account, who, and conversation parameters to the request API calls, and updated all code to match. I can't compile the Perl module, so I'd appreciate it if someone who knows it would verify that this doesn't break Perl.
Evan Schoenberg <evands@pidgin.im>
parents:
16481
diff
changeset
|
165 | _("_Cancel"), NULL, |
|
68c22924d66b
Added account, who, and conversation parameters to the request API calls, and updated all code to match. I can't compile the Perl module, so I'd appreciate it if someone who knows it would verify that this doesn't break Perl.
Evan Schoenberg <evands@pidgin.im>
parents:
16481
diff
changeset
|
166 | NULL, NULL, NULL, |
|
68c22924d66b
Added account, who, and conversation parameters to the request API calls, and updated all code to match. I can't compile the Perl module, so I'd appreciate it if someone who knows it would verify that this doesn't break Perl.
Evan Schoenberg <evands@pidgin.im>
parents:
16481
diff
changeset
|
167 | node, |
| 15230 | 168 | _("Ask"), FT_ASK, |
| 169 | _("Auto Accept"), FT_ACCEPT, | |
| 170 | _("Auto Reject"), FT_REJECT, | |
|
16490
68c22924d66b
Added account, who, and conversation parameters to the request API calls, and updated all code to match. I can't compile the Perl module, so I'd appreciate it if someone who knows it would verify that this doesn't break Perl.
Evan Schoenberg <evands@pidgin.im>
parents:
16481
diff
changeset
|
171 | NULL, purple_contact_get_alias((PurpleContact *)node), NULL, |
| 15230 | 172 | NULL); |
| 173 | g_free(message); | |
| 174 | } | |
| 175 | ||
| 176 | static void | |
| 15884 | 177 | context_menu(PurpleBlistNode *node, GList **menu, gpointer plugin) |
| 15230 | 178 | { |
| 15884 | 179 | PurpleMenuAction *action; |
| 15230 | 180 | |
|
18594
b4e1f5a7d2bf
Don't allow setting auto-accept preferences for blist nodes that won't be
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16745
diff
changeset
|
181 | if (!PURPLE_BLIST_NODE_IS_BUDDY(node) && !PURPLE_BLIST_NODE_IS_CONTACT(node) && |
|
b4e1f5a7d2bf
Don't allow setting auto-accept preferences for blist nodes that won't be
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16745
diff
changeset
|
182 | !(purple_blist_node_get_flags(node) & PURPLE_BLIST_NODE_FLAG_NO_SAVE)) |
| 15230 | 183 | return; |
| 184 | ||
| 15884 | 185 | action = purple_menu_action_new(_("Autoaccept File Transfers..."), |
| 186 | PURPLE_CALLBACK(set_auto_accept_settings), plugin, NULL); | |
| 15230 | 187 | (*menu) = g_list_prepend(*menu, action); |
| 188 | } | |
| 189 | ||
| 190 | static gboolean | |
| 15884 | 191 | plugin_load(PurplePlugin *plugin) |
| 15230 | 192 | { |
| 15884 | 193 | purple_signal_connect(purple_xfers_get_handle(), "file-recv-request", plugin, |
| 194 | PURPLE_CALLBACK(file_recv_request_cb), plugin); | |
| 195 | purple_signal_connect(purple_blist_get_handle(), "blist-node-extended-menu", plugin, | |
| 196 | PURPLE_CALLBACK(context_menu), plugin); | |
| 15230 | 197 | return TRUE; |
| 198 | } | |
| 199 | ||
| 200 | static gboolean | |
| 15884 | 201 | plugin_unload(PurplePlugin *plugin) |
| 15230 | 202 | { |
| 203 | return TRUE; | |
| 204 | } | |
| 205 | ||
| 15884 | 206 | static PurplePluginPrefFrame * |
| 207 | get_plugin_pref_frame(PurplePlugin *plugin) | |
| 15230 | 208 | { |
| 15884 | 209 | PurplePluginPrefFrame *frame; |
| 210 | PurplePluginPref *pref; | |
| 15230 | 211 | |
| 15884 | 212 | frame = purple_plugin_pref_frame_new(); |
| 15230 | 213 | |
| 214 | /* XXX: Is there a better way than this? There really should be. */ | |
| 15884 | 215 | pref = purple_plugin_pref_new_with_name_and_label(PREF_PATH, _("Path to save the files in\n" |
| 15230 | 216 | "(Please provide the full path)")); |
| 15884 | 217 | purple_plugin_pref_frame_add(frame, pref); |
| 15230 | 218 | |
| 15884 | 219 | pref = purple_plugin_pref_new_with_name_and_label(PREF_STRANGER, |
| 15230 | 220 | _("Automatically reject from users not in buddy list")); |
| 15884 | 221 | purple_plugin_pref_frame_add(frame, pref); |
| 15230 | 222 | |
| 15884 | 223 | pref = purple_plugin_pref_new_with_name_and_label(PREF_NOTIFY, |
| 15230 | 224 | _("Notify with a popup when an autoaccepted file transfer is complete\n" |
| 225 | "(only when there's no conversation with the sender)")); | |
| 15884 | 226 | purple_plugin_pref_frame_add(frame, pref); |
| 15230 | 227 | |
| 228 | return frame; | |
| 229 | } | |
| 230 | ||
| 15884 | 231 | static PurplePluginUiInfo prefs_info = { |
| 15230 | 232 | get_plugin_pref_frame, |
| 233 | 0, | |
| 234 | NULL, | |
|
16745
df2c3d6b609a
And the rest of the plugins that are compiling for me by default...
Gary Kramlich <grim@reaperworld.com>
parents:
16490
diff
changeset
|
235 | |
|
df2c3d6b609a
And the rest of the plugins that are compiling for me by default...
Gary Kramlich <grim@reaperworld.com>
parents:
16490
diff
changeset
|
236 | /* padding */ |
|
df2c3d6b609a
And the rest of the plugins that are compiling for me by default...
Gary Kramlich <grim@reaperworld.com>
parents:
16490
diff
changeset
|
237 | NULL, |
|
df2c3d6b609a
And the rest of the plugins that are compiling for me by default...
Gary Kramlich <grim@reaperworld.com>
parents:
16490
diff
changeset
|
238 | NULL, |
|
df2c3d6b609a
And the rest of the plugins that are compiling for me by default...
Gary Kramlich <grim@reaperworld.com>
parents:
16490
diff
changeset
|
239 | NULL, |
|
df2c3d6b609a
And the rest of the plugins that are compiling for me by default...
Gary Kramlich <grim@reaperworld.com>
parents:
16490
diff
changeset
|
240 | NULL |
| 15230 | 241 | }; |
| 242 | ||
| 15884 | 243 | static PurplePluginInfo info = { |
| 244 | PURPLE_PLUGIN_MAGIC, /* Magic */ | |
| 245 | PURPLE_MAJOR_VERSION, /* Purple Major Version */ | |
| 246 | PURPLE_MINOR_VERSION, /* Purple Minor Version */ | |
| 247 | PURPLE_PLUGIN_STANDARD, /* plugin type */ | |
|
15418
bf287f742a5a
[gaim-migrate @ 18149]
Luke Schierer <lschiere@pidgin.im>
parents:
15230
diff
changeset
|
248 | NULL, /* ui requirement */ |
|
bf287f742a5a
[gaim-migrate @ 18149]
Luke Schierer <lschiere@pidgin.im>
parents:
15230
diff
changeset
|
249 | 0, /* flags */ |
|
bf287f742a5a
[gaim-migrate @ 18149]
Luke Schierer <lschiere@pidgin.im>
parents:
15230
diff
changeset
|
250 | NULL, /* dependencies */ |
| 15884 | 251 | PURPLE_PRIORITY_DEFAULT, /* priority */ |
| 15230 | 252 | |
|
15418
bf287f742a5a
[gaim-migrate @ 18149]
Luke Schierer <lschiere@pidgin.im>
parents:
15230
diff
changeset
|
253 | PLUGIN_ID, /* plugin id */ |
|
bf287f742a5a
[gaim-migrate @ 18149]
Luke Schierer <lschiere@pidgin.im>
parents:
15230
diff
changeset
|
254 | PLUGIN_NAME, /* name */ |
|
bf287f742a5a
[gaim-migrate @ 18149]
Luke Schierer <lschiere@pidgin.im>
parents:
15230
diff
changeset
|
255 | VERSION, /* version */ |
|
bf287f742a5a
[gaim-migrate @ 18149]
Luke Schierer <lschiere@pidgin.im>
parents:
15230
diff
changeset
|
256 | PLUGIN_SUMMARY, /* summary */ |
|
bf287f742a5a
[gaim-migrate @ 18149]
Luke Schierer <lschiere@pidgin.im>
parents:
15230
diff
changeset
|
257 | PLUGIN_DESCRIPTION, /* description */ |
| 15230 | 258 | PLUGIN_AUTHOR, /* author */ |
| 15884 | 259 | PURPLE_WEBSITE, /* website */ |
| 15230 | 260 | |
| 261 | plugin_load, /* load */ | |
| 262 | plugin_unload, /* unload */ | |
|
15418
bf287f742a5a
[gaim-migrate @ 18149]
Luke Schierer <lschiere@pidgin.im>
parents:
15230
diff
changeset
|
263 | NULL, /* destroy */ |
| 15230 | 264 | |
|
15418
bf287f742a5a
[gaim-migrate @ 18149]
Luke Schierer <lschiere@pidgin.im>
parents:
15230
diff
changeset
|
265 | NULL, /* ui_info */ |
|
bf287f742a5a
[gaim-migrate @ 18149]
Luke Schierer <lschiere@pidgin.im>
parents:
15230
diff
changeset
|
266 | NULL, /* extra_info */ |
| 15230 | 267 | &prefs_info, /* prefs_info */ |
|
16745
df2c3d6b609a
And the rest of the plugins that are compiling for me by default...
Gary Kramlich <grim@reaperworld.com>
parents:
16490
diff
changeset
|
268 | NULL, /* actions */ |
|
df2c3d6b609a
And the rest of the plugins that are compiling for me by default...
Gary Kramlich <grim@reaperworld.com>
parents:
16490
diff
changeset
|
269 | |
|
df2c3d6b609a
And the rest of the plugins that are compiling for me by default...
Gary Kramlich <grim@reaperworld.com>
parents:
16490
diff
changeset
|
270 | /* padding */ |
|
df2c3d6b609a
And the rest of the plugins that are compiling for me by default...
Gary Kramlich <grim@reaperworld.com>
parents:
16490
diff
changeset
|
271 | NULL, |
|
df2c3d6b609a
And the rest of the plugins that are compiling for me by default...
Gary Kramlich <grim@reaperworld.com>
parents:
16490
diff
changeset
|
272 | NULL, |
|
df2c3d6b609a
And the rest of the plugins that are compiling for me by default...
Gary Kramlich <grim@reaperworld.com>
parents:
16490
diff
changeset
|
273 | NULL, |
|
df2c3d6b609a
And the rest of the plugins that are compiling for me by default...
Gary Kramlich <grim@reaperworld.com>
parents:
16490
diff
changeset
|
274 | NULL |
| 15230 | 275 | }; |
| 276 | ||
| 277 | static void | |
| 15884 | 278 | init_plugin(PurplePlugin *plugin) { |
| 15230 | 279 | char *dirname; |
| 280 | ||
| 15884 | 281 | dirname = g_build_filename(purple_user_dir(), "autoaccept", NULL); |
| 282 | purple_prefs_add_none(PREF_PREFIX); | |
| 283 | purple_prefs_add_string(PREF_PATH, dirname); | |
| 284 | purple_prefs_add_bool(PREF_STRANGER, TRUE); | |
| 285 | purple_prefs_add_bool(PREF_NOTIFY, TRUE); | |
| 15230 | 286 | g_free(dirname); |
| 287 | } | |
| 288 | ||
| 15884 | 289 | PURPLE_INIT_PLUGIN(PLUGIN_STATIC_NAME, init_plugin, info) |