Mon, 16 Sep 2013 16:48:10 +0530
Refactored joinpart to use the new plugin API
| 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)); |
| 15884 | 81 | purple_notify_info(NULL, _("Autoaccept complete"), message, NULL); |
| 15230 | 82 | g_free(message); |
| 83 | } | |
| 84 | } | |
| 85 | ||
| 86 | static void | |
| 15884 | 87 | file_recv_request_cb(PurpleXfer *xfer, gpointer handle) |
| 15230 | 88 | { |
| 15884 | 89 | PurpleAccount *account; |
| 90 | PurpleBlistNode *node; | |
| 15230 | 91 | const char *pref; |
| 92 | char *filename; | |
| 93 | char *dirname; | |
| 94 | ||
|
31282
16eb735c55ae
Add additional options to the autoaccept plugin. Fixes #11459.
Rok Mandeljc <rok.mandeljc@gmail.com>
parents:
29491
diff
changeset
|
95 | int accept_setting; |
|
16eb735c55ae
Add additional options to the autoaccept plugin. Fixes #11459.
Rok Mandeljc <rok.mandeljc@gmail.com>
parents:
29491
diff
changeset
|
96 | |
|
32438
dc8991868906
A boring and large patch so I can merge heads.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31294
diff
changeset
|
97 | 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
|
98 | node = PURPLE_BLIST_NODE(purple_blist_find_buddy(account, purple_xfer_get_remote_user(xfer))); |
| 15230 | 99 | |
|
31282
16eb735c55ae
Add additional options to the autoaccept plugin. Fixes #11459.
Rok Mandeljc <rok.mandeljc@gmail.com>
parents:
29491
diff
changeset
|
100 | /* 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
|
101 | stranger setting. */ |
|
16eb735c55ae
Add additional options to the autoaccept plugin. Fixes #11459.
Rok Mandeljc <rok.mandeljc@gmail.com>
parents:
29491
diff
changeset
|
102 | if (node) { |
|
16eb735c55ae
Add additional options to the autoaccept plugin. Fixes #11459.
Rok Mandeljc <rok.mandeljc@gmail.com>
parents:
29491
diff
changeset
|
103 | 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
|
104 | 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
|
105 | 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
|
106 | } else { |
|
16eb735c55ae
Add additional options to the autoaccept plugin. Fixes #11459.
Rok Mandeljc <rok.mandeljc@gmail.com>
parents:
29491
diff
changeset
|
107 | accept_setting = purple_prefs_get_int(PREF_STRANGER); |
| 15230 | 108 | } |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
31287
diff
changeset
|
109 | |
|
31282
16eb735c55ae
Add additional options to the autoaccept plugin. Fixes #11459.
Rok Mandeljc <rok.mandeljc@gmail.com>
parents:
29491
diff
changeset
|
110 | switch (accept_setting) |
| 15230 | 111 | { |
| 112 | case FT_ASK: | |
| 113 | break; | |
| 114 | case FT_ACCEPT: | |
|
31282
16eb735c55ae
Add additional options to the autoaccept plugin. Fixes #11459.
Rok Mandeljc <rok.mandeljc@gmail.com>
parents:
29491
diff
changeset
|
115 | pref = purple_prefs_get_string(PREF_PATH); |
| 15230 | 116 | if (ensure_path_exists(pref)) |
| 117 | { | |
|
21897
6de6b77176ac
Do not overwrite an existing file. Closes #3982.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
21895
diff
changeset
|
118 | int count = 1; |
|
6de6b77176ac
Do not overwrite an existing file. Closes #3982.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
21895
diff
changeset
|
119 | 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
|
120 | 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
|
121 | 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
|
122 | 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
|
123 | |
|
020974bf1759
Allow not creating a different directory for each user. Closes #5997.
Luke Bratch <l_bratch@yahoo.co.uk>
parents:
21897
diff
changeset
|
124 | 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
|
125 | 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
|
126 | else |
|
020974bf1759
Allow not creating a different directory for each user. Closes #5997.
Luke Bratch <l_bratch@yahoo.co.uk>
parents:
21897
diff
changeset
|
127 | dirname = g_build_filename(pref, NULL); |
| 15230 | 128 | |
| 129 | if (!ensure_path_exists(dirname)) | |
| 130 | { | |
| 131 | g_free(dirname); | |
| 132 | break; | |
| 133 | } | |
|
21895
26a49c68b5b6
Normalize and escape the filename when auto-accepting a file. References #3982.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
21630
diff
changeset
|
134 | |
|
31282
16eb735c55ae
Add additional options to the autoaccept plugin. Fixes #11459.
Rok Mandeljc <rok.mandeljc@gmail.com>
parents:
29491
diff
changeset
|
135 | /* 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
|
136 | 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
|
137 | 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
|
138 | } else { |
|
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_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 | } |
|
21897
6de6b77176ac
Do not overwrite an existing file. Closes #3982.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
21895
diff
changeset
|
141 | 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
|
142 | |
|
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
|
143 | /* 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
|
144 | 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
|
145 | 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
|
146 | 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
|
147 | 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
|
148 | /* 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
|
149 | 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
|
150 | } 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
|
151 | 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
|
152 | } |
|
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 | |
|
21897
6de6b77176ac
Do not overwrite an existing file. Closes #3982.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
21895
diff
changeset
|
154 | /* 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
|
155 | /* 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
|
156 | * 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
|
157 | * 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
|
158 | */ |
|
21897
6de6b77176ac
Do not overwrite an existing file. Closes #3982.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
21895
diff
changeset
|
159 | 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
|
160 | 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
|
161 | g_free(filename); |
|
6de6b77176ac
Do not overwrite an existing file. Closes #3982.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
21895
diff
changeset
|
162 | 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
|
163 | g_free(file); |
|
6de6b77176ac
Do not overwrite an existing file. Closes #3982.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
21895
diff
changeset
|
164 | } |
| 15230 | 165 | |
| 15884 | 166 | purple_xfer_request_accepted(xfer, filename); |
| 15230 | 167 | |
|
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
|
168 | 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
|
169 | g_free(ext); |
| 15230 | 170 | g_free(dirname); |
| 171 | g_free(filename); | |
| 172 | } | |
|
21895
26a49c68b5b6
Normalize and escape the filename when auto-accepting a file. References #3982.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
21630
diff
changeset
|
173 | |
| 15884 | 174 | purple_signal_connect(purple_xfers_get_handle(), "file-recv-complete", handle, |
| 175 | PURPLE_CALLBACK(auto_accept_complete_cb), xfer); | |
| 15230 | 176 | break; |
| 177 | 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
|
178 | purple_xfer_set_status(xfer, PURPLE_XFER_STATUS_CANCEL_LOCAL); |
| 15230 | 179 | break; |
| 180 | } | |
| 181 | } | |
| 182 | ||
| 183 | static void | |
| 15884 | 184 | save_cb(PurpleBlistNode *node, int choice) |
| 15230 | 185 | { |
|
34695
60a278f1365b
Refactored libpurple plugins with initial GObject blist API
Ankit Vani <a@nevitus.org>
parents:
34625
diff
changeset
|
186 | 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
|
187 | 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
|
188 | g_return_if_fail(PURPLE_IS_CONTACT(node)); |
| 15884 | 189 | purple_blist_node_set_int(node, "autoaccept", choice); |
| 15230 | 190 | } |
| 191 | ||
| 192 | static void | |
| 15884 | 193 | set_auto_accept_settings(PurpleBlistNode *node, gpointer plugin) |
| 15230 | 194 | { |
| 195 | char *message; | |
| 196 | ||
|
34695
60a278f1365b
Refactored libpurple plugins with initial GObject blist API
Ankit Vani <a@nevitus.org>
parents:
34625
diff
changeset
|
197 | 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
|
198 | 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
|
199 | g_return_if_fail(PURPLE_IS_CONTACT(node)); |
| 15230 | 200 | |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
31287
diff
changeset
|
201 | 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
|
202 | purple_contact_get_alias(PURPLE_CONTACT(node))); |
|
21175
c6d76b49c206
disapproval of revision '8ba833993a115415727bb1b70362e0bd1603c169'
Richard Laager <rlaager@pidgin.im>
parents:
21174
diff
changeset
|
203 | 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
|
204 | NULL, GINT_TO_POINTER(purple_blist_node_get_int(node, "autoaccept")), |
| 15230 | 205 | _("_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
|
206 | _("_Cancel"), NULL, |
|
34330
35d5e8fcc07b
Request API refactoring: switch purple_request_choice to PurpleRequestCommonParameters
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
33352
diff
changeset
|
207 | NULL, node, |
|
34338
c652670afac5
Request API refactoring: custom PURPLE_REQUEST_CHOICE values, instead of indexes
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
34330
diff
changeset
|
208 | _("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
|
209 | _("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
|
210 | _("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
|
211 | NULL); |
| 15230 | 212 | g_free(message); |
| 213 | } | |
| 214 | ||
| 215 | static void | |
| 15884 | 216 | context_menu(PurpleBlistNode *node, GList **menu, gpointer plugin) |
| 15230 | 217 | { |
| 15884 | 218 | PurpleMenuAction *action; |
| 15230 | 219 | |
|
34695
60a278f1365b
Refactored libpurple plugins with initial GObject blist API
Ankit Vani <a@nevitus.org>
parents:
34625
diff
changeset
|
220 | 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
|
221 | !purple_blist_node_is_transient(node)) |
| 15230 | 222 | return; |
| 223 | ||
| 15884 | 224 | action = purple_menu_action_new(_("Autoaccept File Transfers..."), |
| 225 | PURPLE_CALLBACK(set_auto_accept_settings), plugin, NULL); | |
| 15230 | 226 | (*menu) = g_list_prepend(*menu, action); |
| 227 | } | |
| 228 | ||
| 15884 | 229 | static PurplePluginPrefFrame * |
| 230 | get_plugin_pref_frame(PurplePlugin *plugin) | |
| 15230 | 231 | { |
| 15884 | 232 | PurplePluginPrefFrame *frame; |
| 233 | PurplePluginPref *pref; | |
| 15230 | 234 | |
| 15884 | 235 | frame = purple_plugin_pref_frame_new(); |
| 15230 | 236 | |
| 237 | /* XXX: Is there a better way than this? There really should be. */ | |
| 15884 | 238 | pref = purple_plugin_pref_new_with_name_and_label(PREF_PATH, _("Path to save the files in\n" |
| 15230 | 239 | "(Please provide the full path)")); |
| 15884 | 240 | purple_plugin_pref_frame_add(frame, pref); |
| 15230 | 241 | |
| 15884 | 242 | 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
|
243 | _("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
|
244 | "*not* on your buddy list:")); |
|
16eb735c55ae
Add additional options to the autoaccept plugin. Fixes #11459.
Rok Mandeljc <rok.mandeljc@gmail.com>
parents:
29491
diff
changeset
|
245 | purple_plugin_pref_set_type(pref, PURPLE_PLUGIN_PREF_CHOICE); |
|
16eb735c55ae
Add additional options to the autoaccept plugin. Fixes #11459.
Rok Mandeljc <rok.mandeljc@gmail.com>
parents:
29491
diff
changeset
|
246 | 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
|
247 | 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
|
248 | purple_plugin_pref_add_choice(pref, _("Auto Reject"), GINT_TO_POINTER(FT_REJECT)); |
| 15884 | 249 | purple_plugin_pref_frame_add(frame, pref); |
| 15230 | 250 | |
| 15884 | 251 | pref = purple_plugin_pref_new_with_name_and_label(PREF_NOTIFY, |
| 15230 | 252 | _("Notify with a popup when an autoaccepted file transfer is complete\n" |
| 253 | "(only when there's no conversation with the sender)")); | |
| 15884 | 254 | purple_plugin_pref_frame_add(frame, pref); |
| 15230 | 255 | |
|
23849
020974bf1759
Allow not creating a different directory for each user. Closes #5997.
Luke Bratch <l_bratch@yahoo.co.uk>
parents:
21897
diff
changeset
|
256 | 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
|
257 | _("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
|
258 | 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
|
259 | |
|
31282
16eb735c55ae
Add additional options to the autoaccept plugin. Fixes #11459.
Rok Mandeljc <rok.mandeljc@gmail.com>
parents:
29491
diff
changeset
|
260 | 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
|
261 | _("Escape the filenames")); |
|
16eb735c55ae
Add additional options to the autoaccept plugin. Fixes #11459.
Rok Mandeljc <rok.mandeljc@gmail.com>
parents:
29491
diff
changeset
|
262 | 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
|
263 | |
| 15230 | 264 | return frame; |
| 265 | } | |
| 266 | ||
| 36742 | 267 | static PurplePluginInfo * |
| 268 | plugin_query(GError **error) | |
| 269 | { | |
| 270 | const gchar * const authors[] = PLUGIN_AUTHORS; | |
| 15230 | 271 | |
| 36742 | 272 | return purple_plugin_info_new( |
| 273 | "id", PLUGIN_ID, | |
| 274 | "name", PLUGIN_NAME, | |
| 275 | "version", DISPLAY_VERSION, | |
| 276 | "category", PLUGIN_CATEGORY, | |
| 277 | "summary", PLUGIN_SUMMARY, | |
| 278 | "description", PLUGIN_DESCRIPTION, | |
| 279 | "authors", authors, | |
| 280 | "website", PURPLE_WEBSITE, | |
| 281 | "abi-version", PURPLE_ABI_VERSION, | |
| 282 | "preferences-frame", get_plugin_pref_frame, | |
| 283 | NULL | |
| 284 | ); | |
| 285 | } | |
| 15230 | 286 | |
| 36742 | 287 | static gboolean |
| 288 | plugin_load(PurplePlugin *plugin, GError **error) | |
| 289 | { | |
| 15230 | 290 | char *dirname; |
| 291 | ||
| 15884 | 292 | dirname = g_build_filename(purple_user_dir(), "autoaccept", NULL); |
| 293 | purple_prefs_add_none(PREF_PREFIX); | |
| 294 | purple_prefs_add_string(PREF_PATH, dirname); | |
| 295 | 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
|
296 | 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
|
297 | purple_prefs_add_bool(PREF_ESCAPE, TRUE); |
| 15230 | 298 | g_free(dirname); |
| 36742 | 299 | |
| 300 | /* migrate the old pref (we should only care if the plugin is actually *used*) */ | |
| 301 | /* | |
| 302 | * TODO: We should eventually call purple_prefs_remove(PREFS_STRANGER_OLD) | |
| 303 | * to clean up after ourselves, but we don't want to do it yet | |
| 304 | * so that we don't break users who share a .purple directory | |
| 305 | * between old libpurple clients and new libpurple clients. | |
| 306 | * --Mark Doliner, 2011-01-03 | |
| 307 | */ | |
| 308 | if (!purple_prefs_exists(PREF_STRANGER)) { | |
| 309 | if (purple_prefs_exists(PREF_STRANGER_OLD) && purple_prefs_get_bool(PREF_STRANGER_OLD)) | |
| 310 | purple_prefs_add_int(PREF_STRANGER, FT_REJECT); | |
| 311 | else | |
| 312 | purple_prefs_set_int(PREF_STRANGER, FT_ASK); | |
| 313 | } | |
| 314 | ||
| 315 | purple_signal_connect(purple_xfers_get_handle(), "file-recv-request", plugin, | |
| 316 | PURPLE_CALLBACK(file_recv_request_cb), plugin); | |
| 317 | purple_signal_connect(purple_blist_get_handle(), "blist-node-extended-menu", plugin, | |
| 318 | PURPLE_CALLBACK(context_menu), plugin); | |
| 319 | return TRUE; | |
| 15230 | 320 | } |
| 321 | ||
| 36742 | 322 | static gboolean |
| 323 | plugin_unload(PurplePlugin *plugin, GError **error) | |
| 324 | { | |
| 325 | return TRUE; | |
| 326 | } | |
| 327 | ||
| 328 | PURPLE_PLUGIN_INIT(PLUGIN_STATIC_NAME, plugin_query, plugin_load, plugin_unload); |