Sun, 15 May 2022 02:27:58 -0500
Remove a bunch of utility functions that were no longer used.
Testing Done:
compiled and ran the unit tests
Reviewed at https://reviews.imfreedom.org/r/1448/
| 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 | */ |
|
40439
e9838d634d5e
Make sure that internal.h can only be included by libpurple and split out some pieces to purpleprivate.h
Gary Kramlich <grim@reaperworld.com>
parents:
40254
diff
changeset
|
20 | |
|
e9838d634d5e
Make sure that internal.h can only be included by libpurple and split out some pieces to purpleprivate.h
Gary Kramlich <grim@reaperworld.com>
parents:
40254
diff
changeset
|
21 | #include <glib/gi18n-lib.h> |
| 15230 | 22 | |
| 23 | #define PLUGIN_ID "core-plugin_pack-autoaccept" | |
|
15418
bf287f742a5a
[gaim-migrate @ 18149]
Luke Schierer <lschiere@pidgin.im>
parents:
15230
diff
changeset
|
24 | #define PLUGIN_NAME N_("Autoaccept") |
| 36742 | 25 | #define PLUGIN_CATEGORY N_("Utility") |
|
25633
feee0c7e503f
Fix some more mis-identified plugins, like 3b3526a0...
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
24531
diff
changeset
|
26 | #define PLUGIN_STATIC_NAME Autoaccept |
|
15418
bf287f742a5a
[gaim-migrate @ 18149]
Luke Schierer <lschiere@pidgin.im>
parents:
15230
diff
changeset
|
27 | #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
|
28 | #define PLUGIN_DESCRIPTION N_("Auto-accept file transfer requests from selected users.") |
| 36742 | 29 | #define PLUGIN_AUTHORS {"Sadrul H Chowdhury <sadrul@users.sourceforge.net>", NULL} |
| 15230 | 30 | |
| 31 | /* System headers */ | |
| 32 | #include <glib.h> | |
|
29491
31c1d615772e
Kill off unneeded GLIB_CHECK_VERSION checks in libpurple. Refs #10024.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
25911
diff
changeset
|
33 | #include <glib/gstdio.h> |
| 15230 | 34 | |
|
40945
bbeb2e98ea5b
Use GPLUGIN_NATIVE_PLUGIN_DECLARE for all libpurple plugins and remove PURPLE_PLUGIN_INIT
Gary Kramlich <grim@reaperworld.com>
parents:
40439
diff
changeset
|
35 | #include <gplugin.h> |
|
bbeb2e98ea5b
Use GPLUGIN_NATIVE_PLUGIN_DECLARE for all libpurple plugins and remove PURPLE_PLUGIN_INIT
Gary Kramlich <grim@reaperworld.com>
parents:
40439
diff
changeset
|
36 | #include <gplugin-native.h> |
|
bbeb2e98ea5b
Use GPLUGIN_NATIVE_PLUGIN_DECLARE for all libpurple plugins and remove PURPLE_PLUGIN_INIT
Gary Kramlich <grim@reaperworld.com>
parents:
40439
diff
changeset
|
37 | |
|
39959
e47fcffd061b
migrate the libpurple plugins to using purple.h only
Gary Kramlich <grim@reaperworld.com>
parents:
39918
diff
changeset
|
38 | #include <purple.h> |
| 15230 | 39 | |
| 16481 | 40 | #define PREF_PREFIX "/plugins/core/" PLUGIN_ID |
| 15230 | 41 | #define PREF_PATH PREF_PREFIX "/path" |
|
31282
16eb735c55ae
Add additional options to the autoaccept plugin. Fixes #11459.
Rok Mandeljc <rok.mandeljc@gmail.com>
parents:
29491
diff
changeset
|
42 | #define PREF_STRANGER PREF_PREFIX "/stranger" |
| 15230 | 43 | #define PREF_NOTIFY PREF_PREFIX "/notify" |
|
23849
020974bf1759
Allow not creating a different directory for each user. Closes #5997.
Luke Bratch <l_bratch@yahoo.co.uk>
parents:
21897
diff
changeset
|
44 | #define PREF_NEWDIR PREF_PREFIX "/newdir" |
|
31282
16eb735c55ae
Add additional options to the autoaccept plugin. Fixes #11459.
Rok Mandeljc <rok.mandeljc@gmail.com>
parents:
29491
diff
changeset
|
45 | #define PREF_ESCAPE PREF_PREFIX "/escape" |
| 15230 | 46 | |
|
31283
df4184c594d7
Migrate the pref the previous commit dropped. Refs #11459.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
31282
diff
changeset
|
47 | #define PREF_STRANGER_OLD PREF_PREFIX "/reject_stranger" |
|
df4184c594d7
Migrate the pref the previous commit dropped. Refs #11459.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
31282
diff
changeset
|
48 | |
| 15230 | 49 | typedef enum |
| 50 | { | |
| 51 | FT_ASK, | |
| 52 | FT_ACCEPT, | |
| 53 | FT_REJECT | |
| 54 | } AutoAcceptSetting; | |
| 55 | ||
| 56 | static gboolean | |
| 57 | ensure_path_exists(const char *dir) | |
| 58 | { | |
| 59 | if (!g_file_test(dir, G_FILE_TEST_IS_DIR)) | |
| 60 | { | |
|
40124
cdce45867b10
Replace purple_build_dir with g_mkdir_with_parents.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39963
diff
changeset
|
61 | if (g_mkdir_with_parents(dir, S_IRUSR | S_IWUSR | S_IXUSR)) { |
| 15230 | 62 | return FALSE; |
|
40124
cdce45867b10
Replace purple_build_dir with g_mkdir_with_parents.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39963
diff
changeset
|
63 | } |
| 15230 | 64 | } |
| 65 | ||
| 66 | return TRUE; | |
| 67 | } | |
| 68 | ||
| 69 | static void | |
|
40254
09402b6a28cf
Remove xfer signals for status changes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40124
diff
changeset
|
70 | auto_accept_complete_cb(PurpleXfer *xfer, G_GNUC_UNUSED GParamSpec *pspec, |
|
09402b6a28cf
Remove xfer signals for status changes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40124
diff
changeset
|
71 | G_GNUC_UNUSED gpointer data) |
| 15230 | 72 | { |
|
40990
7988932faf91
Convert the libpurple plugins to use PurpleConversationManager
Gary Kramlich <grim@reaperworld.com>
parents:
40945
diff
changeset
|
73 | PurpleConversationManager *manager = NULL; |
|
7988932faf91
Convert the libpurple plugins to use PurpleConversationManager
Gary Kramlich <grim@reaperworld.com>
parents:
40945
diff
changeset
|
74 | |
|
40254
09402b6a28cf
Remove xfer signals for status changes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40124
diff
changeset
|
75 | if (purple_xfer_get_status(xfer) != PURPLE_XFER_STATUS_DONE) { |
|
09402b6a28cf
Remove xfer signals for status changes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40124
diff
changeset
|
76 | return; |
|
09402b6a28cf
Remove xfer signals for status changes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40124
diff
changeset
|
77 | } |
|
09402b6a28cf
Remove xfer signals for status changes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40124
diff
changeset
|
78 | |
|
40990
7988932faf91
Convert the libpurple plugins to use PurpleConversationManager
Gary Kramlich <grim@reaperworld.com>
parents:
40945
diff
changeset
|
79 | manager = purple_conversation_manager_get_default(); |
|
7988932faf91
Convert the libpurple plugins to use PurpleConversationManager
Gary Kramlich <grim@reaperworld.com>
parents:
40945
diff
changeset
|
80 | |
|
7988932faf91
Convert the libpurple plugins to use PurpleConversationManager
Gary Kramlich <grim@reaperworld.com>
parents:
40945
diff
changeset
|
81 | if(purple_prefs_get_bool(PREF_NOTIFY) && |
|
7988932faf91
Convert the libpurple plugins to use PurpleConversationManager
Gary Kramlich <grim@reaperworld.com>
parents:
40945
diff
changeset
|
82 | !purple_conversation_manager_find_im(manager, |
|
7988932faf91
Convert the libpurple plugins to use PurpleConversationManager
Gary Kramlich <grim@reaperworld.com>
parents:
40945
diff
changeset
|
83 | purple_xfer_get_account(xfer), |
|
7988932faf91
Convert the libpurple plugins to use PurpleConversationManager
Gary Kramlich <grim@reaperworld.com>
parents:
40945
diff
changeset
|
84 | purple_xfer_get_remote_user(xfer))) |
|
7988932faf91
Convert the libpurple plugins to use PurpleConversationManager
Gary Kramlich <grim@reaperworld.com>
parents:
40945
diff
changeset
|
85 | { |
| 15230 | 86 | char *message = g_strdup_printf(_("Autoaccepted file transfer of \"%s\" from \"%s\" completed."), |
|
32438
dc8991868906
A boring and large patch so I can merge heads.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31294
diff
changeset
|
87 | purple_xfer_get_filename(xfer), purple_xfer_get_remote_user(xfer)); |
|
34449
bbcb198650b7
Notify API: extend purple_notify_message with PurpleRequestCommonParameters
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
34338
diff
changeset
|
88 | purple_notify_info(NULL, _("Autoaccept complete"), message, |
|
bbcb198650b7
Notify API: extend purple_notify_message with PurpleRequestCommonParameters
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
34338
diff
changeset
|
89 | NULL, purple_request_cpar_from_account( |
|
bbcb198650b7
Notify API: extend purple_notify_message with PurpleRequestCommonParameters
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
34338
diff
changeset
|
90 | purple_xfer_get_account(xfer))); |
| 15230 | 91 | g_free(message); |
| 92 | } | |
| 93 | } | |
| 94 | ||
| 95 | static void | |
| 15884 | 96 | file_recv_request_cb(PurpleXfer *xfer, gpointer handle) |
| 15230 | 97 | { |
| 15884 | 98 | PurpleAccount *account; |
| 99 | PurpleBlistNode *node; | |
| 15230 | 100 | const char *pref; |
| 101 | char *filename; | |
| 102 | char *dirname; | |
| 103 | ||
|
31282
16eb735c55ae
Add additional options to the autoaccept plugin. Fixes #11459.
Rok Mandeljc <rok.mandeljc@gmail.com>
parents:
29491
diff
changeset
|
104 | int accept_setting; |
|
16eb735c55ae
Add additional options to the autoaccept plugin. Fixes #11459.
Rok Mandeljc <rok.mandeljc@gmail.com>
parents:
29491
diff
changeset
|
105 | |
|
32438
dc8991868906
A boring and large patch so I can merge heads.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31294
diff
changeset
|
106 | account = purple_xfer_get_account(xfer); |
|
34728
8efd73063ecf
Renamed buddy list functions to more appropriate/simler names.
Ankit Vani <a@nevitus.org>
parents:
34706
diff
changeset
|
107 | node = PURPLE_BLIST_NODE(purple_blist_find_buddy(account, purple_xfer_get_remote_user(xfer))); |
| 15230 | 108 | |
|
31282
16eb735c55ae
Add additional options to the autoaccept plugin. Fixes #11459.
Rok Mandeljc <rok.mandeljc@gmail.com>
parents:
29491
diff
changeset
|
109 | /* If person is on buddy list, use the buddy setting; otherwise, use the |
|
16eb735c55ae
Add additional options to the autoaccept plugin. Fixes #11459.
Rok Mandeljc <rok.mandeljc@gmail.com>
parents:
29491
diff
changeset
|
110 | stranger setting. */ |
|
16eb735c55ae
Add additional options to the autoaccept plugin. Fixes #11459.
Rok Mandeljc <rok.mandeljc@gmail.com>
parents:
29491
diff
changeset
|
111 | if (node) { |
|
16eb735c55ae
Add additional options to the autoaccept plugin. Fixes #11459.
Rok Mandeljc <rok.mandeljc@gmail.com>
parents:
29491
diff
changeset
|
112 | node = purple_blist_node_get_parent(node); |
|
34695
60a278f1365b
Refactored libpurple plugins with initial GObject blist API
Ankit Vani <a@nevitus.org>
parents:
34625
diff
changeset
|
113 | g_return_if_fail(PURPLE_IS_CONTACT(node)); |
|
31282
16eb735c55ae
Add additional options to the autoaccept plugin. Fixes #11459.
Rok Mandeljc <rok.mandeljc@gmail.com>
parents:
29491
diff
changeset
|
114 | accept_setting = purple_blist_node_get_int(node, "autoaccept"); |
|
16eb735c55ae
Add additional options to the autoaccept plugin. Fixes #11459.
Rok Mandeljc <rok.mandeljc@gmail.com>
parents:
29491
diff
changeset
|
115 | } else { |
|
16eb735c55ae
Add additional options to the autoaccept plugin. Fixes #11459.
Rok Mandeljc <rok.mandeljc@gmail.com>
parents:
29491
diff
changeset
|
116 | accept_setting = purple_prefs_get_int(PREF_STRANGER); |
| 15230 | 117 | } |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
31287
diff
changeset
|
118 | |
|
31282
16eb735c55ae
Add additional options to the autoaccept plugin. Fixes #11459.
Rok Mandeljc <rok.mandeljc@gmail.com>
parents:
29491
diff
changeset
|
119 | switch (accept_setting) |
| 15230 | 120 | { |
| 121 | case FT_ASK: | |
| 122 | break; | |
| 123 | case FT_ACCEPT: | |
|
31282
16eb735c55ae
Add additional options to the autoaccept plugin. Fixes #11459.
Rok Mandeljc <rok.mandeljc@gmail.com>
parents:
29491
diff
changeset
|
124 | pref = purple_prefs_get_string(PREF_PATH); |
| 15230 | 125 | if (ensure_path_exists(pref)) |
| 126 | { | |
|
21897
6de6b77176ac
Do not overwrite an existing file. Closes #3982.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
21895
diff
changeset
|
127 | int count = 1; |
|
6de6b77176ac
Do not overwrite an existing file. Closes #3982.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
21895
diff
changeset
|
128 | const char *escape; |
|
24266
d44f9c32397f
Uniquify auto-accepted file names to foo-2.tar.gz, not foo.tar.gz-2.
Will Thompson <resiak@pidgin.im>
parents:
23849
diff
changeset
|
129 | gchar **name_and_ext; |
|
d44f9c32397f
Uniquify auto-accepted file names to foo-2.tar.gz, not foo.tar.gz-2.
Will Thompson <resiak@pidgin.im>
parents:
23849
diff
changeset
|
130 | const gchar *name; |
|
d44f9c32397f
Uniquify auto-accepted file names to foo-2.tar.gz, not foo.tar.gz-2.
Will Thompson <resiak@pidgin.im>
parents:
23849
diff
changeset
|
131 | gchar *ext; |
|
23849
020974bf1759
Allow not creating a different directory for each user. Closes #5997.
Luke Bratch <l_bratch@yahoo.co.uk>
parents:
21897
diff
changeset
|
132 | |
|
020974bf1759
Allow not creating a different directory for each user. Closes #5997.
Luke Bratch <l_bratch@yahoo.co.uk>
parents:
21897
diff
changeset
|
133 | if (purple_prefs_get_bool(PREF_NEWDIR)) |
|
32438
dc8991868906
A boring and large patch so I can merge heads.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31294
diff
changeset
|
134 | dirname = g_build_filename(pref, purple_normalize(account, purple_xfer_get_remote_user(xfer)), NULL); |
|
23849
020974bf1759
Allow not creating a different directory for each user. Closes #5997.
Luke Bratch <l_bratch@yahoo.co.uk>
parents:
21897
diff
changeset
|
135 | else |
|
020974bf1759
Allow not creating a different directory for each user. Closes #5997.
Luke Bratch <l_bratch@yahoo.co.uk>
parents:
21897
diff
changeset
|
136 | dirname = g_build_filename(pref, NULL); |
| 15230 | 137 | |
| 138 | if (!ensure_path_exists(dirname)) | |
| 139 | { | |
| 140 | g_free(dirname); | |
| 141 | break; | |
| 142 | } | |
|
21895
26a49c68b5b6
Normalize and escape the filename when auto-accepting a file. References #3982.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
21630
diff
changeset
|
143 | |
|
31282
16eb735c55ae
Add additional options to the autoaccept plugin. Fixes #11459.
Rok Mandeljc <rok.mandeljc@gmail.com>
parents:
29491
diff
changeset
|
144 | /* Escape filename (if escaping is turned on) */ |
|
16eb735c55ae
Add additional options to the autoaccept plugin. Fixes #11459.
Rok Mandeljc <rok.mandeljc@gmail.com>
parents:
29491
diff
changeset
|
145 | if (purple_prefs_get_bool(PREF_ESCAPE)) { |
|
32438
dc8991868906
A boring and large patch so I can merge heads.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31294
diff
changeset
|
146 | escape = purple_escape_filename(purple_xfer_get_filename(xfer)); |
|
31282
16eb735c55ae
Add additional options to the autoaccept plugin. Fixes #11459.
Rok Mandeljc <rok.mandeljc@gmail.com>
parents:
29491
diff
changeset
|
147 | } else { |
|
32438
dc8991868906
A boring and large patch so I can merge heads.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31294
diff
changeset
|
148 | escape = purple_xfer_get_filename(xfer); |
|
31282
16eb735c55ae
Add additional options to the autoaccept plugin. Fixes #11459.
Rok Mandeljc <rok.mandeljc@gmail.com>
parents:
29491
diff
changeset
|
149 | } |
|
21897
6de6b77176ac
Do not overwrite an existing file. Closes #3982.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
21895
diff
changeset
|
150 | filename = g_build_filename(dirname, escape, NULL); |
|
6de6b77176ac
Do not overwrite an existing file. Closes #3982.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
21895
diff
changeset
|
151 | |
|
24266
d44f9c32397f
Uniquify auto-accepted file names to foo-2.tar.gz, not foo.tar.gz-2.
Will Thompson <resiak@pidgin.im>
parents:
23849
diff
changeset
|
152 | /* Split at the first dot, to avoid uniquifying "foo.tar.gz" to "foo.tar-2.gz" */ |
|
d44f9c32397f
Uniquify auto-accepted file names to foo-2.tar.gz, not foo.tar.gz-2.
Will Thompson <resiak@pidgin.im>
parents:
23849
diff
changeset
|
153 | name_and_ext = g_strsplit(escape, ".", 2); |
|
d44f9c32397f
Uniquify auto-accepted file names to foo-2.tar.gz, not foo.tar.gz-2.
Will Thompson <resiak@pidgin.im>
parents:
23849
diff
changeset
|
154 | name = name_and_ext[0]; |
|
39918
1c8e11f9274f
Fix several memory leaks.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39483
diff
changeset
|
155 | if (name == NULL) { |
|
1c8e11f9274f
Fix several memory leaks.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39483
diff
changeset
|
156 | g_strfreev(name_and_ext); |
|
1c8e11f9274f
Fix several memory leaks.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39483
diff
changeset
|
157 | g_return_if_reached(); |
|
1c8e11f9274f
Fix several memory leaks.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39483
diff
changeset
|
158 | } |
|
24266
d44f9c32397f
Uniquify auto-accepted file names to foo-2.tar.gz, not foo.tar.gz-2.
Will Thompson <resiak@pidgin.im>
parents:
23849
diff
changeset
|
159 | if (name_and_ext[1] != NULL) { |
|
d44f9c32397f
Uniquify auto-accepted file names to foo-2.tar.gz, not foo.tar.gz-2.
Will Thompson <resiak@pidgin.im>
parents:
23849
diff
changeset
|
160 | /* g_strsplit does not include the separator in each chunk. */ |
|
d44f9c32397f
Uniquify auto-accepted file names to foo-2.tar.gz, not foo.tar.gz-2.
Will Thompson <resiak@pidgin.im>
parents:
23849
diff
changeset
|
161 | ext = g_strdup_printf(".%s", name_and_ext[1]); |
|
d44f9c32397f
Uniquify auto-accepted file names to foo-2.tar.gz, not foo.tar.gz-2.
Will Thompson <resiak@pidgin.im>
parents:
23849
diff
changeset
|
162 | } else { |
|
d44f9c32397f
Uniquify auto-accepted file names to foo-2.tar.gz, not foo.tar.gz-2.
Will Thompson <resiak@pidgin.im>
parents:
23849
diff
changeset
|
163 | ext = g_strdup(""); |
|
d44f9c32397f
Uniquify auto-accepted file names to foo-2.tar.gz, not foo.tar.gz-2.
Will Thompson <resiak@pidgin.im>
parents:
23849
diff
changeset
|
164 | } |
|
d44f9c32397f
Uniquify auto-accepted file names to foo-2.tar.gz, not foo.tar.gz-2.
Will Thompson <resiak@pidgin.im>
parents:
23849
diff
changeset
|
165 | |
|
21897
6de6b77176ac
Do not overwrite an existing file. Closes #3982.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
21895
diff
changeset
|
166 | /* Make sure the file doesn't exist. Do we want some better checking than this? */ |
|
24266
d44f9c32397f
Uniquify auto-accepted file names to foo-2.tar.gz, not foo.tar.gz-2.
Will Thompson <resiak@pidgin.im>
parents:
23849
diff
changeset
|
167 | /* FIXME: There is a race here: if the newly uniquified file name gets created between |
|
d44f9c32397f
Uniquify auto-accepted file names to foo-2.tar.gz, not foo.tar.gz-2.
Will Thompson <resiak@pidgin.im>
parents:
23849
diff
changeset
|
168 | * this g_file_test and the transfer starting, the file created in the meantime |
|
d44f9c32397f
Uniquify auto-accepted file names to foo-2.tar.gz, not foo.tar.gz-2.
Will Thompson <resiak@pidgin.im>
parents:
23849
diff
changeset
|
169 | * will be clobbered. But it's not at all straightforward to fix. |
|
d44f9c32397f
Uniquify auto-accepted file names to foo-2.tar.gz, not foo.tar.gz-2.
Will Thompson <resiak@pidgin.im>
parents:
23849
diff
changeset
|
170 | */ |
|
21897
6de6b77176ac
Do not overwrite an existing file. Closes #3982.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
21895
diff
changeset
|
171 | while (g_file_test(filename, G_FILE_TEST_EXISTS)) { |
|
24266
d44f9c32397f
Uniquify auto-accepted file names to foo-2.tar.gz, not foo.tar.gz-2.
Will Thompson <resiak@pidgin.im>
parents:
23849
diff
changeset
|
172 | char *file = g_strdup_printf("%s-%d%s", name, count++, ext); |
|
21897
6de6b77176ac
Do not overwrite an existing file. Closes #3982.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
21895
diff
changeset
|
173 | g_free(filename); |
|
6de6b77176ac
Do not overwrite an existing file. Closes #3982.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
21895
diff
changeset
|
174 | filename = g_build_filename(dirname, file, NULL); |
|
6de6b77176ac
Do not overwrite an existing file. Closes #3982.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
21895
diff
changeset
|
175 | g_free(file); |
|
6de6b77176ac
Do not overwrite an existing file. Closes #3982.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
21895
diff
changeset
|
176 | } |
| 15230 | 177 | |
| 15884 | 178 | purple_xfer_request_accepted(xfer, filename); |
| 15230 | 179 | |
|
24266
d44f9c32397f
Uniquify auto-accepted file names to foo-2.tar.gz, not foo.tar.gz-2.
Will Thompson <resiak@pidgin.im>
parents:
23849
diff
changeset
|
180 | g_strfreev(name_and_ext); |
|
d44f9c32397f
Uniquify auto-accepted file names to foo-2.tar.gz, not foo.tar.gz-2.
Will Thompson <resiak@pidgin.im>
parents:
23849
diff
changeset
|
181 | g_free(ext); |
| 15230 | 182 | g_free(dirname); |
| 183 | g_free(filename); | |
| 184 | } | |
|
21895
26a49c68b5b6
Normalize and escape the filename when auto-accepting a file. References #3982.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
21630
diff
changeset
|
185 | |
|
40254
09402b6a28cf
Remove xfer signals for status changes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40124
diff
changeset
|
186 | g_signal_connect(xfer, "notify::status", |
|
09402b6a28cf
Remove xfer signals for status changes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40124
diff
changeset
|
187 | G_CALLBACK(auto_accept_complete_cb), NULL); |
| 15230 | 188 | break; |
| 189 | case FT_REJECT: | |
|
32438
dc8991868906
A boring and large patch so I can merge heads.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31294
diff
changeset
|
190 | purple_xfer_set_status(xfer, PURPLE_XFER_STATUS_CANCEL_LOCAL); |
| 15230 | 191 | break; |
| 192 | } | |
| 193 | } | |
| 194 | ||
| 195 | static void | |
| 15884 | 196 | save_cb(PurpleBlistNode *node, int choice) |
| 15230 | 197 | { |
|
34695
60a278f1365b
Refactored libpurple plugins with initial GObject blist API
Ankit Vani <a@nevitus.org>
parents:
34625
diff
changeset
|
198 | if (PURPLE_IS_BUDDY(node)) |
|
24531
76e72697f7d6
Hide the blistnode, buddy, contact, group, and chat structs
Gary Kramlich <grim@reaperworld.com>
parents:
24266
diff
changeset
|
199 | node = purple_blist_node_get_parent(node); |
|
34695
60a278f1365b
Refactored libpurple plugins with initial GObject blist API
Ankit Vani <a@nevitus.org>
parents:
34625
diff
changeset
|
200 | g_return_if_fail(PURPLE_IS_CONTACT(node)); |
| 15884 | 201 | purple_blist_node_set_int(node, "autoaccept", choice); |
| 15230 | 202 | } |
| 203 | ||
| 204 | static void | |
| 15884 | 205 | set_auto_accept_settings(PurpleBlistNode *node, gpointer plugin) |
| 15230 | 206 | { |
| 207 | char *message; | |
| 208 | ||
|
34695
60a278f1365b
Refactored libpurple plugins with initial GObject blist API
Ankit Vani <a@nevitus.org>
parents:
34625
diff
changeset
|
209 | if (PURPLE_IS_BUDDY(node)) |
|
24531
76e72697f7d6
Hide the blistnode, buddy, contact, group, and chat structs
Gary Kramlich <grim@reaperworld.com>
parents:
24266
diff
changeset
|
210 | node = purple_blist_node_get_parent(node); |
|
34695
60a278f1365b
Refactored libpurple plugins with initial GObject blist API
Ankit Vani <a@nevitus.org>
parents:
34625
diff
changeset
|
211 | g_return_if_fail(PURPLE_IS_CONTACT(node)); |
| 15230 | 212 | |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
31287
diff
changeset
|
213 | message = g_strdup_printf(_("When a file-transfer request arrives from %s"), |
|
34740
9401f9b1ca68
Used GObject-style casts in plugins.
Ankit Vani <a@nevitus.org>
parents:
34728
diff
changeset
|
214 | purple_contact_get_alias(PURPLE_CONTACT(node))); |
|
21175
c6d76b49c206
disapproval of revision '8ba833993a115415727bb1b70362e0bd1603c169'
Richard Laager <rlaager@pidgin.im>
parents:
21174
diff
changeset
|
215 | purple_request_choice(plugin, _("Set Autoaccept Setting"), message, |
|
34338
c652670afac5
Request API refactoring: custom PURPLE_REQUEST_CHOICE values, instead of indexes
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
34330
diff
changeset
|
216 | NULL, GINT_TO_POINTER(purple_blist_node_get_int(node, "autoaccept")), |
| 15230 | 217 | _("_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
|
218 | _("_Cancel"), NULL, |
|
34330
35d5e8fcc07b
Request API refactoring: switch purple_request_choice to PurpleRequestCommonParameters
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
33352
diff
changeset
|
219 | NULL, node, |
|
34338
c652670afac5
Request API refactoring: custom PURPLE_REQUEST_CHOICE values, instead of indexes
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
34330
diff
changeset
|
220 | _("Ask"), GINT_TO_POINTER(FT_ASK), |
|
c652670afac5
Request API refactoring: custom PURPLE_REQUEST_CHOICE values, instead of indexes
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
34330
diff
changeset
|
221 | _("Auto Accept"), GINT_TO_POINTER(FT_ACCEPT), |
|
c652670afac5
Request API refactoring: custom PURPLE_REQUEST_CHOICE values, instead of indexes
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
34330
diff
changeset
|
222 | _("Auto Reject"), GINT_TO_POINTER(FT_REJECT), |
|
19279
5e5883dbd532
Adding hints to libpurple/plugins/autoaccept.c
Gabriel Schulhof <nix@go-nix.ca>
parents:
19278
diff
changeset
|
223 | NULL); |
| 15230 | 224 | g_free(message); |
| 225 | } | |
| 226 | ||
| 227 | static void | |
| 15884 | 228 | context_menu(PurpleBlistNode *node, GList **menu, gpointer plugin) |
| 15230 | 229 | { |
|
39481
4db28449567d
Rename PurpleMenuAction to PurpleActionMenu
Gary Kramlich <grim@reaperworld.com>
parents:
39479
diff
changeset
|
230 | PurpleActionMenu *action; |
| 15230 | 231 | |
|
34695
60a278f1365b
Refactored libpurple plugins with initial GObject blist API
Ankit Vani <a@nevitus.org>
parents:
34625
diff
changeset
|
232 | if (!PURPLE_IS_BUDDY(node) && !PURPLE_IS_CONTACT(node) && |
|
34865
764a33b41ac7
Renamed blist node's dont_save to transient.
Ankit Vani <a@nevitus.org>
parents:
34864
diff
changeset
|
233 | !purple_blist_node_is_transient(node)) |
| 15230 | 234 | return; |
| 235 | ||
|
39483
ab4728087d87
Rename purple_menu_action_* to purple_action_menu_*
Gary Kramlich <grim@reaperworld.com>
parents:
39481
diff
changeset
|
236 | action = purple_action_menu_new(_("Autoaccept File Transfers..."), |
|
41314
0dc72eacd8bf
Replace PURPLE_CALLBACK by G_CALLBACK
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
41078
diff
changeset
|
237 | G_CALLBACK(set_auto_accept_settings), plugin, NULL); |
| 15230 | 238 | (*menu) = g_list_prepend(*menu, action); |
| 239 | } | |
| 240 | ||
| 15884 | 241 | static PurplePluginPrefFrame * |
| 242 | get_plugin_pref_frame(PurplePlugin *plugin) | |
| 15230 | 243 | { |
| 15884 | 244 | PurplePluginPrefFrame *frame; |
| 245 | PurplePluginPref *pref; | |
| 15230 | 246 | |
| 15884 | 247 | frame = purple_plugin_pref_frame_new(); |
| 15230 | 248 | |
| 249 | /* XXX: Is there a better way than this? There really should be. */ | |
| 15884 | 250 | pref = purple_plugin_pref_new_with_name_and_label(PREF_PATH, _("Path to save the files in\n" |
| 15230 | 251 | "(Please provide the full path)")); |
| 15884 | 252 | purple_plugin_pref_frame_add(frame, pref); |
| 15230 | 253 | |
| 15884 | 254 | pref = purple_plugin_pref_new_with_name_and_label(PREF_STRANGER, |
|
31282
16eb735c55ae
Add additional options to the autoaccept plugin. Fixes #11459.
Rok Mandeljc <rok.mandeljc@gmail.com>
parents:
29491
diff
changeset
|
255 | _("When a file-transfer request arrives from a user who is\n" |
|
16eb735c55ae
Add additional options to the autoaccept plugin. Fixes #11459.
Rok Mandeljc <rok.mandeljc@gmail.com>
parents:
29491
diff
changeset
|
256 | "*not* on your buddy list:")); |
|
35378
5d9e2581005b
gtk-doc prep: *_get_type() functions are hidden as standard GType-returning funcs, so rename them.
Ankit Vani <a@nevitus.org>
parents:
35045
diff
changeset
|
257 | purple_plugin_pref_set_pref_type(pref, PURPLE_PLUGIN_PREF_CHOICE); |
|
31282
16eb735c55ae
Add additional options to the autoaccept plugin. Fixes #11459.
Rok Mandeljc <rok.mandeljc@gmail.com>
parents:
29491
diff
changeset
|
258 | purple_plugin_pref_add_choice(pref, _("Ask"), GINT_TO_POINTER(FT_ASK)); |
|
16eb735c55ae
Add additional options to the autoaccept plugin. Fixes #11459.
Rok Mandeljc <rok.mandeljc@gmail.com>
parents:
29491
diff
changeset
|
259 | purple_plugin_pref_add_choice(pref, _("Auto Accept"), GINT_TO_POINTER(FT_ACCEPT)); |
|
16eb735c55ae
Add additional options to the autoaccept plugin. Fixes #11459.
Rok Mandeljc <rok.mandeljc@gmail.com>
parents:
29491
diff
changeset
|
260 | purple_plugin_pref_add_choice(pref, _("Auto Reject"), GINT_TO_POINTER(FT_REJECT)); |
| 15884 | 261 | purple_plugin_pref_frame_add(frame, pref); |
| 15230 | 262 | |
| 15884 | 263 | pref = purple_plugin_pref_new_with_name_and_label(PREF_NOTIFY, |
| 15230 | 264 | _("Notify with a popup when an autoaccepted file transfer is complete\n" |
| 265 | "(only when there's no conversation with the sender)")); | |
| 15884 | 266 | purple_plugin_pref_frame_add(frame, pref); |
| 15230 | 267 | |
|
23849
020974bf1759
Allow not creating a different directory for each user. Closes #5997.
Luke Bratch <l_bratch@yahoo.co.uk>
parents:
21897
diff
changeset
|
268 | pref = purple_plugin_pref_new_with_name_and_label(PREF_NEWDIR, |
|
020974bf1759
Allow not creating a different directory for each user. Closes #5997.
Luke Bratch <l_bratch@yahoo.co.uk>
parents:
21897
diff
changeset
|
269 | _("Create a new directory for each user")); |
|
020974bf1759
Allow not creating a different directory for each user. Closes #5997.
Luke Bratch <l_bratch@yahoo.co.uk>
parents:
21897
diff
changeset
|
270 | purple_plugin_pref_frame_add(frame, pref); |
|
020974bf1759
Allow not creating a different directory for each user. Closes #5997.
Luke Bratch <l_bratch@yahoo.co.uk>
parents:
21897
diff
changeset
|
271 | |
|
31282
16eb735c55ae
Add additional options to the autoaccept plugin. Fixes #11459.
Rok Mandeljc <rok.mandeljc@gmail.com>
parents:
29491
diff
changeset
|
272 | pref = purple_plugin_pref_new_with_name_and_label(PREF_ESCAPE, |
|
16eb735c55ae
Add additional options to the autoaccept plugin. Fixes #11459.
Rok Mandeljc <rok.mandeljc@gmail.com>
parents:
29491
diff
changeset
|
273 | _("Escape the filenames")); |
|
16eb735c55ae
Add additional options to the autoaccept plugin. Fixes #11459.
Rok Mandeljc <rok.mandeljc@gmail.com>
parents:
29491
diff
changeset
|
274 | purple_plugin_pref_frame_add(frame, pref); |
|
16eb735c55ae
Add additional options to the autoaccept plugin. Fixes #11459.
Rok Mandeljc <rok.mandeljc@gmail.com>
parents:
29491
diff
changeset
|
275 | |
| 15230 | 276 | return frame; |
| 277 | } | |
| 278 | ||
|
40945
bbeb2e98ea5b
Use GPLUGIN_NATIVE_PLUGIN_DECLARE for all libpurple plugins and remove PURPLE_PLUGIN_INIT
Gary Kramlich <grim@reaperworld.com>
parents:
40439
diff
changeset
|
279 | static GPluginPluginInfo * |
|
bbeb2e98ea5b
Use GPLUGIN_NATIVE_PLUGIN_DECLARE for all libpurple plugins and remove PURPLE_PLUGIN_INIT
Gary Kramlich <grim@reaperworld.com>
parents:
40439
diff
changeset
|
280 | auto_accept_query(GError **error) |
| 36742 | 281 | { |
| 282 | const gchar * const authors[] = PLUGIN_AUTHORS; | |
| 15230 | 283 | |
| 36742 | 284 | return purple_plugin_info_new( |
|
36934
e7268aeb3b89
Renamed plugin info callback properties to end with "-cb", and their respective symbols.
Ankit Vani <a@nevitus.org>
parents:
36929
diff
changeset
|
285 | "id", PLUGIN_ID, |
|
e7268aeb3b89
Renamed plugin info callback properties to end with "-cb", and their respective symbols.
Ankit Vani <a@nevitus.org>
parents:
36929
diff
changeset
|
286 | "name", PLUGIN_NAME, |
|
e7268aeb3b89
Renamed plugin info callback properties to end with "-cb", and their respective symbols.
Ankit Vani <a@nevitus.org>
parents:
36929
diff
changeset
|
287 | "version", DISPLAY_VERSION, |
|
e7268aeb3b89
Renamed plugin info callback properties to end with "-cb", and their respective symbols.
Ankit Vani <a@nevitus.org>
parents:
36929
diff
changeset
|
288 | "category", PLUGIN_CATEGORY, |
|
e7268aeb3b89
Renamed plugin info callback properties to end with "-cb", and their respective symbols.
Ankit Vani <a@nevitus.org>
parents:
36929
diff
changeset
|
289 | "summary", PLUGIN_SUMMARY, |
|
e7268aeb3b89
Renamed plugin info callback properties to end with "-cb", and their respective symbols.
Ankit Vani <a@nevitus.org>
parents:
36929
diff
changeset
|
290 | "description", PLUGIN_DESCRIPTION, |
|
e7268aeb3b89
Renamed plugin info callback properties to end with "-cb", and their respective symbols.
Ankit Vani <a@nevitus.org>
parents:
36929
diff
changeset
|
291 | "authors", authors, |
|
e7268aeb3b89
Renamed plugin info callback properties to end with "-cb", and their respective symbols.
Ankit Vani <a@nevitus.org>
parents:
36929
diff
changeset
|
292 | "website", PURPLE_WEBSITE, |
|
e7268aeb3b89
Renamed plugin info callback properties to end with "-cb", and their respective symbols.
Ankit Vani <a@nevitus.org>
parents:
36929
diff
changeset
|
293 | "abi-version", PURPLE_ABI_VERSION, |
|
e7268aeb3b89
Renamed plugin info callback properties to end with "-cb", and their respective symbols.
Ankit Vani <a@nevitus.org>
parents:
36929
diff
changeset
|
294 | "pref-frame-cb", get_plugin_pref_frame, |
| 36742 | 295 | NULL |
| 296 | ); | |
| 297 | } | |
| 15230 | 298 | |
| 36742 | 299 | static gboolean |
|
40945
bbeb2e98ea5b
Use GPLUGIN_NATIVE_PLUGIN_DECLARE for all libpurple plugins and remove PURPLE_PLUGIN_INIT
Gary Kramlich <grim@reaperworld.com>
parents:
40439
diff
changeset
|
300 | auto_accept_load(GPluginPlugin *plugin, GError **error) |
| 36742 | 301 | { |
| 15230 | 302 | char *dirname; |
| 303 | ||
|
39439
9a4c7434ea6c
Set default autoaccept dir to ~/Downloads/autoaccept.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
37075
diff
changeset
|
304 | dirname = g_build_filename(g_get_user_special_dir(G_USER_DIRECTORY_DOWNLOAD), "autoaccept", NULL); |
| 15884 | 305 | purple_prefs_add_none(PREF_PREFIX); |
| 306 | purple_prefs_add_string(PREF_PATH, dirname); | |
| 307 | purple_prefs_add_bool(PREF_NOTIFY, TRUE); | |
|
23849
020974bf1759
Allow not creating a different directory for each user. Closes #5997.
Luke Bratch <l_bratch@yahoo.co.uk>
parents:
21897
diff
changeset
|
308 | purple_prefs_add_bool(PREF_NEWDIR, TRUE); |
|
31282
16eb735c55ae
Add additional options to the autoaccept plugin. Fixes #11459.
Rok Mandeljc <rok.mandeljc@gmail.com>
parents:
29491
diff
changeset
|
309 | purple_prefs_add_bool(PREF_ESCAPE, TRUE); |
| 15230 | 310 | g_free(dirname); |
| 36742 | 311 | |
| 312 | /* migrate the old pref (we should only care if the plugin is actually *used*) */ | |
| 313 | /* | |
| 314 | * TODO: We should eventually call purple_prefs_remove(PREFS_STRANGER_OLD) | |
| 315 | * to clean up after ourselves, but we don't want to do it yet | |
| 316 | * so that we don't break users who share a .purple directory | |
| 317 | * between old libpurple clients and new libpurple clients. | |
| 318 | * --Mark Doliner, 2011-01-03 | |
| 319 | */ | |
| 320 | if (!purple_prefs_exists(PREF_STRANGER)) { | |
| 321 | if (purple_prefs_exists(PREF_STRANGER_OLD) && purple_prefs_get_bool(PREF_STRANGER_OLD)) | |
| 322 | purple_prefs_add_int(PREF_STRANGER, FT_REJECT); | |
| 323 | else | |
| 324 | purple_prefs_set_int(PREF_STRANGER, FT_ASK); | |
| 325 | } | |
| 326 | ||
| 327 | purple_signal_connect(purple_xfers_get_handle(), "file-recv-request", plugin, | |
|
41314
0dc72eacd8bf
Replace PURPLE_CALLBACK by G_CALLBACK
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
41078
diff
changeset
|
328 | G_CALLBACK(file_recv_request_cb), plugin); |
| 36742 | 329 | purple_signal_connect(purple_blist_get_handle(), "blist-node-extended-menu", plugin, |
|
41314
0dc72eacd8bf
Replace PURPLE_CALLBACK by G_CALLBACK
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
41078
diff
changeset
|
330 | G_CALLBACK(context_menu), plugin); |
| 36742 | 331 | return TRUE; |
| 15230 | 332 | } |
| 333 | ||
| 36742 | 334 | static gboolean |
|
41078
84e48180ef67
Update to gplugin 0.35.0
Gary Kramlich <grim@reaperworld.com>
parents:
40990
diff
changeset
|
335 | auto_accept_unload(GPluginPlugin *plugin, gboolean shutdown, GError **error) |
| 36742 | 336 | { |
| 337 | return TRUE; | |
| 338 | } | |
| 339 | ||
|
40945
bbeb2e98ea5b
Use GPLUGIN_NATIVE_PLUGIN_DECLARE for all libpurple plugins and remove PURPLE_PLUGIN_INIT
Gary Kramlich <grim@reaperworld.com>
parents:
40439
diff
changeset
|
340 | GPLUGIN_NATIVE_PLUGIN_DECLARE(auto_accept) |