Sat, 27 Aug 2016 18:16:01 -0500
connection: Add purple_connection_take_error()
This patch adds a purple_connection_take_error() function, which
is functionally equivalent to purple_connection_g_error(), except
that it takes ownership of the passed GError.
This is useful to simplify error handling so that the GError doesn't
have to be freed, or, in the future potentially copied, if it's no
longer needed where it's generated. It can also allow for GErrors
being generated without storing them in a variable. This would be
reasonably common if/when all PurpleConnection errors are passed
in via GError.
| 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") |
| 36742 | 24 | #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
|
25 | #define PLUGIN_STATIC_NAME Autoaccept |
|
15418
bf287f742a5a
[gaim-migrate @ 18149]
Luke Schierer <lschiere@pidgin.im>
parents:
15230
diff
changeset
|
26 | #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
|
27 | #define PLUGIN_DESCRIPTION N_("Auto-accept file transfer requests from selected users.") |
| 36742 | 28 | #define PLUGIN_AUTHORS {"Sadrul H Chowdhury <sadrul@users.sourceforge.net>", NULL} |
| 15230 | 29 | |
| 30 | /* System headers */ | |
| 31 | #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
|
32 | #include <glib/gstdio.h> |
| 15230 | 33 | |
| 15884 | 34 | /* Purple headers */ |
|
36367
891eea799578
Renamed plugin.[ch] to plugins.[ch], since we (will) no longer have a PurplePlugin structure.
Ankit Vani <a@nevitus.org>
parents:
34865
diff
changeset
|
35 | #include <plugins.h> |
| 15230 | 36 | #include <version.h> |
| 37 | ||
|
34706
02cb08146888
Renamed blist.[ch] to buddylist.[ch]
Ankit Vani <a@nevitus.org>
parents:
34699
diff
changeset
|
38 | #include <buddylist.h> |
| 15230 | 39 | #include <conversation.h> |
|
34910
60502558e400
Replacements for the GObject Xfer API
Ankit Vani <a@nevitus.org>
parents:
34865
diff
changeset
|
40 | #include <xfer.h> |
| 15230 | 41 | #include <request.h> |
| 42 | #include <notify.h> | |
| 43 | #include <util.h> | |
| 44 | ||
| 16481 | 45 | #define PREF_PREFIX "/plugins/core/" PLUGIN_ID |
| 15230 | 46 | #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
|
47 | #define PREF_STRANGER PREF_PREFIX "/stranger" |
| 15230 | 48 | #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
|
49 | #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
|
50 | #define PREF_ESCAPE PREF_PREFIX "/escape" |
| 15230 | 51 | |
|
31283
df4184c594d7
Migrate the pref the previous commit dropped. Refs #11459.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
31282
diff
changeset
|
52 | #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
|
53 | |
| 15230 | 54 | typedef enum |
| 55 | { | |
| 56 | FT_ASK, | |
| 57 | FT_ACCEPT, | |
| 58 | FT_REJECT | |
| 59 | } AutoAcceptSetting; | |
| 60 | ||
| 61 | static gboolean | |
| 62 | ensure_path_exists(const char *dir) | |
| 63 | { | |
| 64 | if (!g_file_test(dir, G_FILE_TEST_IS_DIR)) | |
| 65 | { | |
| 15884 | 66 | if (purple_build_dir(dir, S_IRUSR | S_IWUSR | S_IXUSR)) |
| 15230 | 67 | return FALSE; |
| 68 | } | |
| 69 | ||
| 70 | return TRUE; | |
| 71 | } | |
| 72 | ||
| 73 | static void | |
| 15884 | 74 | auto_accept_complete_cb(PurpleXfer *xfer, PurpleXfer *my) |
| 15230 | 75 | { |
| 15884 | 76 | if (xfer == my && purple_prefs_get_bool(PREF_NOTIFY) && |
|
34625
03d62b1660fc
Refactor code to remove conversation type from some instances of purple_conversations_find_with_account()
Ankit Vani <a@nevitus.org>
parents:
34622
diff
changeset
|
77 | !purple_conversations_find_im_with_account(purple_xfer_get_remote_user(xfer), purple_xfer_get_account(xfer))) |
| 15230 | 78 | { |
| 79 | 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
|
80 | 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
|
81 | 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
|
82 | NULL, purple_request_cpar_from_account( |
|
bbcb198650b7
Notify API: extend purple_notify_message with PurpleRequestCommonParameters
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
34338
diff
changeset
|
83 | purple_xfer_get_account(xfer))); |
| 15230 | 84 | g_free(message); |
| 85 | } | |
| 86 | } | |
| 87 | ||
| 88 | static void | |
| 15884 | 89 | file_recv_request_cb(PurpleXfer *xfer, gpointer handle) |
| 15230 | 90 | { |
| 15884 | 91 | PurpleAccount *account; |
| 92 | PurpleBlistNode *node; | |
| 15230 | 93 | const char *pref; |
| 94 | char *filename; | |
| 95 | char *dirname; | |
| 96 | ||
|
31282
16eb735c55ae
Add additional options to the autoaccept plugin. Fixes #11459.
Rok Mandeljc <rok.mandeljc@gmail.com>
parents:
29491
diff
changeset
|
97 | int accept_setting; |
|
16eb735c55ae
Add additional options to the autoaccept plugin. Fixes #11459.
Rok Mandeljc <rok.mandeljc@gmail.com>
parents:
29491
diff
changeset
|
98 | |
|
32438
dc8991868906
A boring and large patch so I can merge heads.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31294
diff
changeset
|
99 | 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
|
100 | node = PURPLE_BLIST_NODE(purple_blist_find_buddy(account, purple_xfer_get_remote_user(xfer))); |
| 15230 | 101 | |
|
31282
16eb735c55ae
Add additional options to the autoaccept plugin. Fixes #11459.
Rok Mandeljc <rok.mandeljc@gmail.com>
parents:
29491
diff
changeset
|
102 | /* 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
|
103 | stranger setting. */ |
|
16eb735c55ae
Add additional options to the autoaccept plugin. Fixes #11459.
Rok Mandeljc <rok.mandeljc@gmail.com>
parents:
29491
diff
changeset
|
104 | if (node) { |
|
16eb735c55ae
Add additional options to the autoaccept plugin. Fixes #11459.
Rok Mandeljc <rok.mandeljc@gmail.com>
parents:
29491
diff
changeset
|
105 | 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
|
106 | 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
|
107 | 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
|
108 | } else { |
|
16eb735c55ae
Add additional options to the autoaccept plugin. Fixes #11459.
Rok Mandeljc <rok.mandeljc@gmail.com>
parents:
29491
diff
changeset
|
109 | accept_setting = purple_prefs_get_int(PREF_STRANGER); |
| 15230 | 110 | } |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
31287
diff
changeset
|
111 | |
|
31282
16eb735c55ae
Add additional options to the autoaccept plugin. Fixes #11459.
Rok Mandeljc <rok.mandeljc@gmail.com>
parents:
29491
diff
changeset
|
112 | switch (accept_setting) |
| 15230 | 113 | { |
| 114 | case FT_ASK: | |
| 115 | break; | |
| 116 | case FT_ACCEPT: | |
|
31282
16eb735c55ae
Add additional options to the autoaccept plugin. Fixes #11459.
Rok Mandeljc <rok.mandeljc@gmail.com>
parents:
29491
diff
changeset
|
117 | pref = purple_prefs_get_string(PREF_PATH); |
| 15230 | 118 | if (ensure_path_exists(pref)) |
| 119 | { | |
|
21897
6de6b77176ac
Do not overwrite an existing file. Closes #3982.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
21895
diff
changeset
|
120 | int count = 1; |
|
6de6b77176ac
Do not overwrite an existing file. Closes #3982.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
21895
diff
changeset
|
121 | 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
|
122 | 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
|
123 | 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
|
124 | 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
|
125 | |
|
020974bf1759
Allow not creating a different directory for each user. Closes #5997.
Luke Bratch <l_bratch@yahoo.co.uk>
parents:
21897
diff
changeset
|
126 | 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
|
127 | 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
|
128 | else |
|
020974bf1759
Allow not creating a different directory for each user. Closes #5997.
Luke Bratch <l_bratch@yahoo.co.uk>
parents:
21897
diff
changeset
|
129 | dirname = g_build_filename(pref, NULL); |
| 15230 | 130 | |
| 131 | if (!ensure_path_exists(dirname)) | |
| 132 | { | |
| 133 | g_free(dirname); | |
| 134 | break; | |
| 135 | } | |
|
21895
26a49c68b5b6
Normalize and escape the filename when auto-accepting a file. References #3982.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
21630
diff
changeset
|
136 | |
|
31282
16eb735c55ae
Add additional options to the autoaccept plugin. Fixes #11459.
Rok Mandeljc <rok.mandeljc@gmail.com>
parents:
29491
diff
changeset
|
137 | /* 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
|
138 | 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
|
139 | 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
|
140 | } else { |
|
32438
dc8991868906
A boring and large patch so I can merge heads.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31294
diff
changeset
|
141 | 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
|
142 | } |
|
21897
6de6b77176ac
Do not overwrite an existing file. Closes #3982.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
21895
diff
changeset
|
143 | 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
|
144 | |
|
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
|
145 | /* 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
|
146 | 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
|
147 | name = name_and_ext[0]; |
|
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
|
148 | g_return_if_fail(name != 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
|
149 | 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
|
150 | /* 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
|
151 | 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
|
152 | } 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
|
153 | 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
|
154 | } |
|
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
|
155 | |
|
21897
6de6b77176ac
Do not overwrite an existing file. Closes #3982.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
21895
diff
changeset
|
156 | /* 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
|
157 | /* 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
|
158 | * 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
|
159 | * 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
|
160 | */ |
|
21897
6de6b77176ac
Do not overwrite an existing file. Closes #3982.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
21895
diff
changeset
|
161 | 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
|
162 | 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
|
163 | g_free(filename); |
|
6de6b77176ac
Do not overwrite an existing file. Closes #3982.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
21895
diff
changeset
|
164 | 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
|
165 | g_free(file); |
|
6de6b77176ac
Do not overwrite an existing file. Closes #3982.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
21895
diff
changeset
|
166 | } |
| 15230 | 167 | |
| 15884 | 168 | purple_xfer_request_accepted(xfer, filename); |
| 15230 | 169 | |
|
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
|
170 | 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
|
171 | g_free(ext); |
| 15230 | 172 | g_free(dirname); |
| 173 | g_free(filename); | |
| 174 | } | |
|
21895
26a49c68b5b6
Normalize and escape the filename when auto-accepting a file. References #3982.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
21630
diff
changeset
|
175 | |
| 15884 | 176 | purple_signal_connect(purple_xfers_get_handle(), "file-recv-complete", handle, |
| 177 | PURPLE_CALLBACK(auto_accept_complete_cb), xfer); | |
| 15230 | 178 | break; |
| 179 | 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
|
180 | purple_xfer_set_status(xfer, PURPLE_XFER_STATUS_CANCEL_LOCAL); |
| 15230 | 181 | break; |
| 182 | } | |
| 183 | } | |
| 184 | ||
| 185 | static void | |
| 15884 | 186 | save_cb(PurpleBlistNode *node, int choice) |
| 15230 | 187 | { |
|
34695
60a278f1365b
Refactored libpurple plugins with initial GObject blist API
Ankit Vani <a@nevitus.org>
parents:
34625
diff
changeset
|
188 | 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
|
189 | 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
|
190 | g_return_if_fail(PURPLE_IS_CONTACT(node)); |
| 15884 | 191 | purple_blist_node_set_int(node, "autoaccept", choice); |
| 15230 | 192 | } |
| 193 | ||
| 194 | static void | |
| 15884 | 195 | set_auto_accept_settings(PurpleBlistNode *node, gpointer plugin) |
| 15230 | 196 | { |
| 197 | char *message; | |
| 198 | ||
|
34695
60a278f1365b
Refactored libpurple plugins with initial GObject blist API
Ankit Vani <a@nevitus.org>
parents:
34625
diff
changeset
|
199 | 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
|
200 | 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
|
201 | g_return_if_fail(PURPLE_IS_CONTACT(node)); |
| 15230 | 202 | |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
31287
diff
changeset
|
203 | 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
|
204 | purple_contact_get_alias(PURPLE_CONTACT(node))); |
|
21175
c6d76b49c206
disapproval of revision '8ba833993a115415727bb1b70362e0bd1603c169'
Richard Laager <rlaager@pidgin.im>
parents:
21174
diff
changeset
|
205 | 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
|
206 | NULL, GINT_TO_POINTER(purple_blist_node_get_int(node, "autoaccept")), |
| 15230 | 207 | _("_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
|
208 | _("_Cancel"), NULL, |
|
34330
35d5e8fcc07b
Request API refactoring: switch purple_request_choice to PurpleRequestCommonParameters
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
33352
diff
changeset
|
209 | NULL, node, |
|
34338
c652670afac5
Request API refactoring: custom PURPLE_REQUEST_CHOICE values, instead of indexes
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
34330
diff
changeset
|
210 | _("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
|
211 | _("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
|
212 | _("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
|
213 | NULL); |
| 15230 | 214 | g_free(message); |
| 215 | } | |
| 216 | ||
| 217 | static void | |
| 15884 | 218 | context_menu(PurpleBlistNode *node, GList **menu, gpointer plugin) |
| 15230 | 219 | { |
| 15884 | 220 | PurpleMenuAction *action; |
| 15230 | 221 | |
|
34695
60a278f1365b
Refactored libpurple plugins with initial GObject blist API
Ankit Vani <a@nevitus.org>
parents:
34625
diff
changeset
|
222 | 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
|
223 | !purple_blist_node_is_transient(node)) |
| 15230 | 224 | return; |
| 225 | ||
| 15884 | 226 | action = purple_menu_action_new(_("Autoaccept File Transfers..."), |
| 227 | PURPLE_CALLBACK(set_auto_accept_settings), plugin, NULL); | |
| 15230 | 228 | (*menu) = g_list_prepend(*menu, action); |
| 229 | } | |
| 230 | ||
| 15884 | 231 | static PurplePluginPrefFrame * |
| 232 | get_plugin_pref_frame(PurplePlugin *plugin) | |
| 15230 | 233 | { |
| 15884 | 234 | PurplePluginPrefFrame *frame; |
| 235 | PurplePluginPref *pref; | |
| 15230 | 236 | |
| 15884 | 237 | frame = purple_plugin_pref_frame_new(); |
| 15230 | 238 | |
| 239 | /* XXX: Is there a better way than this? There really should be. */ | |
| 15884 | 240 | pref = purple_plugin_pref_new_with_name_and_label(PREF_PATH, _("Path to save the files in\n" |
| 15230 | 241 | "(Please provide the full path)")); |
| 15884 | 242 | purple_plugin_pref_frame_add(frame, pref); |
| 15230 | 243 | |
| 15884 | 244 | 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
|
245 | _("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
|
246 | "*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
|
247 | 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
|
248 | 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
|
249 | 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
|
250 | purple_plugin_pref_add_choice(pref, _("Auto Reject"), GINT_TO_POINTER(FT_REJECT)); |
| 15884 | 251 | purple_plugin_pref_frame_add(frame, pref); |
| 15230 | 252 | |
| 15884 | 253 | pref = purple_plugin_pref_new_with_name_and_label(PREF_NOTIFY, |
| 15230 | 254 | _("Notify with a popup when an autoaccepted file transfer is complete\n" |
| 255 | "(only when there's no conversation with the sender)")); | |
| 15884 | 256 | purple_plugin_pref_frame_add(frame, pref); |
| 15230 | 257 | |
|
23849
020974bf1759
Allow not creating a different directory for each user. Closes #5997.
Luke Bratch <l_bratch@yahoo.co.uk>
parents:
21897
diff
changeset
|
258 | 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
|
259 | _("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
|
260 | 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
|
261 | |
|
31282
16eb735c55ae
Add additional options to the autoaccept plugin. Fixes #11459.
Rok Mandeljc <rok.mandeljc@gmail.com>
parents:
29491
diff
changeset
|
262 | 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
|
263 | _("Escape the filenames")); |
|
16eb735c55ae
Add additional options to the autoaccept plugin. Fixes #11459.
Rok Mandeljc <rok.mandeljc@gmail.com>
parents:
29491
diff
changeset
|
264 | 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
|
265 | |
| 15230 | 266 | return frame; |
| 267 | } | |
| 268 | ||
| 36742 | 269 | static PurplePluginInfo * |
| 270 | plugin_query(GError **error) | |
| 271 | { | |
| 272 | const gchar * const authors[] = PLUGIN_AUTHORS; | |
| 15230 | 273 | |
| 36742 | 274 | 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
|
275 | "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
|
276 | "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
|
277 | "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
|
278 | "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
|
279 | "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
|
280 | "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
|
281 | "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
|
282 | "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
|
283 | "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
|
284 | "pref-frame-cb", get_plugin_pref_frame, |
| 36742 | 285 | NULL |
| 286 | ); | |
| 287 | } | |
| 15230 | 288 | |
| 36742 | 289 | static gboolean |
| 290 | plugin_load(PurplePlugin *plugin, GError **error) | |
| 291 | { | |
| 15230 | 292 | char *dirname; |
| 293 | ||
| 15884 | 294 | dirname = g_build_filename(purple_user_dir(), "autoaccept", NULL); |
| 295 | purple_prefs_add_none(PREF_PREFIX); | |
| 296 | purple_prefs_add_string(PREF_PATH, dirname); | |
| 297 | 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
|
298 | 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
|
299 | purple_prefs_add_bool(PREF_ESCAPE, TRUE); |
| 15230 | 300 | g_free(dirname); |
| 36742 | 301 | |
| 302 | /* migrate the old pref (we should only care if the plugin is actually *used*) */ | |
| 303 | /* | |
| 304 | * TODO: We should eventually call purple_prefs_remove(PREFS_STRANGER_OLD) | |
| 305 | * to clean up after ourselves, but we don't want to do it yet | |
| 306 | * so that we don't break users who share a .purple directory | |
| 307 | * between old libpurple clients and new libpurple clients. | |
| 308 | * --Mark Doliner, 2011-01-03 | |
| 309 | */ | |
| 310 | if (!purple_prefs_exists(PREF_STRANGER)) { | |
| 311 | if (purple_prefs_exists(PREF_STRANGER_OLD) && purple_prefs_get_bool(PREF_STRANGER_OLD)) | |
| 312 | purple_prefs_add_int(PREF_STRANGER, FT_REJECT); | |
| 313 | else | |
| 314 | purple_prefs_set_int(PREF_STRANGER, FT_ASK); | |
| 315 | } | |
| 316 | ||
| 317 | purple_signal_connect(purple_xfers_get_handle(), "file-recv-request", plugin, | |
| 318 | PURPLE_CALLBACK(file_recv_request_cb), plugin); | |
| 319 | purple_signal_connect(purple_blist_get_handle(), "blist-node-extended-menu", plugin, | |
| 320 | PURPLE_CALLBACK(context_menu), plugin); | |
| 321 | return TRUE; | |
| 15230 | 322 | } |
| 323 | ||
| 36742 | 324 | static gboolean |
| 325 | plugin_unload(PurplePlugin *plugin, GError **error) | |
| 326 | { | |
| 327 | return TRUE; | |
| 328 | } | |
| 329 | ||
| 330 | PURPLE_PLUGIN_INIT(PLUGIN_STATIC_NAME, plugin_query, plugin_load, plugin_unload); |