Wed, 10 Jul 2013 01:57:42 +0530
Used GObject-style casts in plugins.
This will help people who refer to other plugins to write their own.
| 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") |
|
25633
feee0c7e503f
Fix some more mis-identified plugins, like 3b3526a0...
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
24531
diff
changeset
|
24 | #define PLUGIN_STATIC_NAME Autoaccept |
|
15418
bf287f742a5a
[gaim-migrate @ 18149]
Luke Schierer <lschiere@pidgin.im>
parents:
15230
diff
changeset
|
25 | #define PLUGIN_SUMMARY N_("Auto-accept file transfer requests from selected users.") |
|
bf287f742a5a
[gaim-migrate @ 18149]
Luke Schierer <lschiere@pidgin.im>
parents:
15230
diff
changeset
|
26 | #define PLUGIN_DESCRIPTION N_("Auto-accept file transfer requests from selected users.") |
| 15230 | 27 | #define PLUGIN_AUTHOR "Sadrul H Chowdhury <sadrul@users.sourceforge.net>" |
| 28 | ||
| 29 | /* System headers */ | |
| 30 | #include <glib.h> | |
|
29491
31c1d615772e
Kill off unneeded GLIB_CHECK_VERSION checks in libpurple. Refs #10024.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
25911
diff
changeset
|
31 | #include <glib/gstdio.h> |
| 15230 | 32 | |
| 15884 | 33 | /* Purple headers */ |
| 15230 | 34 | #include <plugin.h> |
| 35 | #include <version.h> | |
| 36 | ||
|
34706
02cb08146888
Renamed blist.[ch] to buddylist.[ch]
Ankit Vani <a@nevitus.org>
parents:
34699
diff
changeset
|
37 | #include <buddylist.h> |
| 15230 | 38 | #include <conversation.h> |
| 39 | #include <ft.h> | |
| 40 | #include <request.h> | |
| 41 | #include <notify.h> | |
| 42 | #include <util.h> | |
| 43 | ||
| 16481 | 44 | #define PREF_PREFIX "/plugins/core/" PLUGIN_ID |
| 15230 | 45 | #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
|
46 | #define PREF_STRANGER PREF_PREFIX "/stranger" |
| 15230 | 47 | #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
|
48 | #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
|
49 | #define PREF_ESCAPE PREF_PREFIX "/escape" |
| 15230 | 50 | |
|
31283
df4184c594d7
Migrate the pref the previous commit dropped. Refs #11459.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
31282
diff
changeset
|
51 | #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
|
52 | |
| 15230 | 53 | typedef enum |
| 54 | { | |
| 55 | FT_ASK, | |
| 56 | FT_ACCEPT, | |
| 57 | FT_REJECT | |
| 58 | } AutoAcceptSetting; | |
| 59 | ||
| 60 | static gboolean | |
| 61 | ensure_path_exists(const char *dir) | |
| 62 | { | |
| 63 | if (!g_file_test(dir, G_FILE_TEST_IS_DIR)) | |
| 64 | { | |
| 15884 | 65 | if (purple_build_dir(dir, S_IRUSR | S_IWUSR | S_IXUSR)) |
| 15230 | 66 | return FALSE; |
| 67 | } | |
| 68 | ||
| 69 | return TRUE; | |
| 70 | } | |
| 71 | ||
| 72 | static void | |
| 15884 | 73 | auto_accept_complete_cb(PurpleXfer *xfer, PurpleXfer *my) |
| 15230 | 74 | { |
| 15884 | 75 | 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
|
76 | !purple_conversations_find_im_with_account(purple_xfer_get_remote_user(xfer), purple_xfer_get_account(xfer))) |
| 15230 | 77 | { |
| 78 | 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
|
79 | purple_xfer_get_filename(xfer), purple_xfer_get_remote_user(xfer)); |
| 15884 | 80 | purple_notify_info(NULL, _("Autoaccept complete"), message, NULL); |
| 15230 | 81 | g_free(message); |
| 82 | } | |
| 83 | } | |
| 84 | ||
| 85 | static void | |
| 15884 | 86 | file_recv_request_cb(PurpleXfer *xfer, gpointer handle) |
| 15230 | 87 | { |
| 15884 | 88 | PurpleAccount *account; |
|
34699
09b2c9219b57
Renamed PurpleBlistNode to PurpleBListNode
Ankit Vani <a@nevitus.org>
parents:
34695
diff
changeset
|
89 | PurpleBListNode *node; |
| 15230 | 90 | const char *pref; |
| 91 | char *filename; | |
| 92 | char *dirname; | |
| 93 | ||
|
31282
16eb735c55ae
Add additional options to the autoaccept plugin. Fixes #11459.
Rok Mandeljc <rok.mandeljc@gmail.com>
parents:
29491
diff
changeset
|
94 | int accept_setting; |
|
16eb735c55ae
Add additional options to the autoaccept plugin. Fixes #11459.
Rok Mandeljc <rok.mandeljc@gmail.com>
parents:
29491
diff
changeset
|
95 | |
|
32438
dc8991868906
A boring and large patch so I can merge heads.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31294
diff
changeset
|
96 | 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
|
97 | node = PURPLE_BLIST_NODE(purple_blist_find_buddy(account, purple_xfer_get_remote_user(xfer))); |
| 15230 | 98 | |
|
31282
16eb735c55ae
Add additional options to the autoaccept plugin. Fixes #11459.
Rok Mandeljc <rok.mandeljc@gmail.com>
parents:
29491
diff
changeset
|
99 | /* 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
|
100 | stranger setting. */ |
|
16eb735c55ae
Add additional options to the autoaccept plugin. Fixes #11459.
Rok Mandeljc <rok.mandeljc@gmail.com>
parents:
29491
diff
changeset
|
101 | if (node) { |
|
16eb735c55ae
Add additional options to the autoaccept plugin. Fixes #11459.
Rok Mandeljc <rok.mandeljc@gmail.com>
parents:
29491
diff
changeset
|
102 | 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
|
103 | 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
|
104 | 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
|
105 | } else { |
|
16eb735c55ae
Add additional options to the autoaccept plugin. Fixes #11459.
Rok Mandeljc <rok.mandeljc@gmail.com>
parents:
29491
diff
changeset
|
106 | accept_setting = purple_prefs_get_int(PREF_STRANGER); |
| 15230 | 107 | } |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
31287
diff
changeset
|
108 | |
|
31282
16eb735c55ae
Add additional options to the autoaccept plugin. Fixes #11459.
Rok Mandeljc <rok.mandeljc@gmail.com>
parents:
29491
diff
changeset
|
109 | switch (accept_setting) |
| 15230 | 110 | { |
| 111 | case FT_ASK: | |
| 112 | break; | |
| 113 | case FT_ACCEPT: | |
|
31282
16eb735c55ae
Add additional options to the autoaccept plugin. Fixes #11459.
Rok Mandeljc <rok.mandeljc@gmail.com>
parents:
29491
diff
changeset
|
114 | pref = purple_prefs_get_string(PREF_PATH); |
| 15230 | 115 | if (ensure_path_exists(pref)) |
| 116 | { | |
|
21897
6de6b77176ac
Do not overwrite an existing file. Closes #3982.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
21895
diff
changeset
|
117 | int count = 1; |
|
6de6b77176ac
Do not overwrite an existing file. Closes #3982.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
21895
diff
changeset
|
118 | 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
|
119 | 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
|
120 | 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
|
121 | 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
|
122 | |
|
020974bf1759
Allow not creating a different directory for each user. Closes #5997.
Luke Bratch <l_bratch@yahoo.co.uk>
parents:
21897
diff
changeset
|
123 | 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
|
124 | 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
|
125 | else |
|
020974bf1759
Allow not creating a different directory for each user. Closes #5997.
Luke Bratch <l_bratch@yahoo.co.uk>
parents:
21897
diff
changeset
|
126 | dirname = g_build_filename(pref, NULL); |
| 15230 | 127 | |
| 128 | if (!ensure_path_exists(dirname)) | |
| 129 | { | |
| 130 | g_free(dirname); | |
| 131 | break; | |
| 132 | } | |
|
21895
26a49c68b5b6
Normalize and escape the filename when auto-accepting a file. References #3982.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
21630
diff
changeset
|
133 | |
|
31282
16eb735c55ae
Add additional options to the autoaccept plugin. Fixes #11459.
Rok Mandeljc <rok.mandeljc@gmail.com>
parents:
29491
diff
changeset
|
134 | /* 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
|
135 | 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
|
136 | 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
|
137 | } else { |
|
32438
dc8991868906
A boring and large patch so I can merge heads.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31294
diff
changeset
|
138 | 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
|
139 | } |
|
21897
6de6b77176ac
Do not overwrite an existing file. Closes #3982.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
21895
diff
changeset
|
140 | 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
|
141 | |
|
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
|
142 | /* 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
|
143 | 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
|
144 | 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
|
145 | 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
|
146 | 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
|
147 | /* 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
|
148 | 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
|
149 | } 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
|
150 | 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
|
151 | } |
|
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 | |
|
21897
6de6b77176ac
Do not overwrite an existing file. Closes #3982.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
21895
diff
changeset
|
153 | /* 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
|
154 | /* 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
|
155 | * 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
|
156 | * 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
|
157 | */ |
|
21897
6de6b77176ac
Do not overwrite an existing file. Closes #3982.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
21895
diff
changeset
|
158 | 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
|
159 | 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
|
160 | g_free(filename); |
|
6de6b77176ac
Do not overwrite an existing file. Closes #3982.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
21895
diff
changeset
|
161 | 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
|
162 | g_free(file); |
|
6de6b77176ac
Do not overwrite an existing file. Closes #3982.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
21895
diff
changeset
|
163 | } |
| 15230 | 164 | |
| 15884 | 165 | purple_xfer_request_accepted(xfer, filename); |
| 15230 | 166 | |
|
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 | 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
|
168 | g_free(ext); |
| 15230 | 169 | g_free(dirname); |
| 170 | g_free(filename); | |
| 171 | } | |
|
21895
26a49c68b5b6
Normalize and escape the filename when auto-accepting a file. References #3982.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
21630
diff
changeset
|
172 | |
| 15884 | 173 | purple_signal_connect(purple_xfers_get_handle(), "file-recv-complete", handle, |
| 174 | PURPLE_CALLBACK(auto_accept_complete_cb), xfer); | |
| 15230 | 175 | break; |
| 176 | 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
|
177 | purple_xfer_set_status(xfer, PURPLE_XFER_STATUS_CANCEL_LOCAL); |
| 15230 | 178 | break; |
| 179 | } | |
| 180 | } | |
| 181 | ||
| 182 | static void | |
|
34699
09b2c9219b57
Renamed PurpleBlistNode to PurpleBListNode
Ankit Vani <a@nevitus.org>
parents:
34695
diff
changeset
|
183 | save_cb(PurpleBListNode *node, int choice) |
| 15230 | 184 | { |
|
34695
60a278f1365b
Refactored libpurple plugins with initial GObject blist API
Ankit Vani <a@nevitus.org>
parents:
34625
diff
changeset
|
185 | 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
|
186 | 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
|
187 | g_return_if_fail(PURPLE_IS_CONTACT(node)); |
| 15884 | 188 | purple_blist_node_set_int(node, "autoaccept", choice); |
| 15230 | 189 | } |
| 190 | ||
| 191 | static void | |
|
34699
09b2c9219b57
Renamed PurpleBlistNode to PurpleBListNode
Ankit Vani <a@nevitus.org>
parents:
34695
diff
changeset
|
192 | set_auto_accept_settings(PurpleBListNode *node, gpointer plugin) |
| 15230 | 193 | { |
| 194 | char *message; | |
| 195 | ||
|
34695
60a278f1365b
Refactored libpurple plugins with initial GObject blist API
Ankit Vani <a@nevitus.org>
parents:
34625
diff
changeset
|
196 | 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
|
197 | 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
|
198 | g_return_if_fail(PURPLE_IS_CONTACT(node)); |
| 15230 | 199 | |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
31287
diff
changeset
|
200 | 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
|
201 | purple_contact_get_alias(PURPLE_CONTACT(node))); |
|
21175
c6d76b49c206
disapproval of revision '8ba833993a115415727bb1b70362e0bd1603c169'
Richard Laager <rlaager@pidgin.im>
parents:
21174
diff
changeset
|
202 | purple_request_choice(plugin, _("Set Autoaccept Setting"), message, |
| 15884 | 203 | NULL, purple_blist_node_get_int(node, "autoaccept"), |
| 15230 | 204 | _("_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
|
205 | _("_Cancel"), NULL, |
|
68c22924d66b
Added account, who, and conversation parameters to the request API calls, and updated all code to match. I can't compile the Perl module, so I'd appreciate it if someone who knows it would verify that this doesn't break Perl.
Evan Schoenberg <evands@pidgin.im>
parents:
16481
diff
changeset
|
206 | NULL, NULL, NULL, |
|
21175
c6d76b49c206
disapproval of revision '8ba833993a115415727bb1b70362e0bd1603c169'
Richard Laager <rlaager@pidgin.im>
parents:
21174
diff
changeset
|
207 | node, |
| 15230 | 208 | _("Ask"), FT_ASK, |
| 209 | _("Auto Accept"), FT_ACCEPT, | |
| 210 | _("Auto Reject"), FT_REJECT, | |
|
34740
9401f9b1ca68
Used GObject-style casts in plugins.
Ankit Vani <a@nevitus.org>
parents:
34728
diff
changeset
|
211 | NULL, purple_contact_get_alias(PURPLE_CONTACT(node)), NULL, |
|
19279
5e5883dbd532
Adding hints to libpurple/plugins/autoaccept.c
Gabriel Schulhof <nix@go-nix.ca>
parents:
19278
diff
changeset
|
212 | NULL); |
| 15230 | 213 | g_free(message); |
| 214 | } | |
| 215 | ||
| 216 | static void | |
|
34699
09b2c9219b57
Renamed PurpleBlistNode to PurpleBListNode
Ankit Vani <a@nevitus.org>
parents:
34695
diff
changeset
|
217 | context_menu(PurpleBListNode *node, GList **menu, gpointer plugin) |
| 15230 | 218 | { |
| 15884 | 219 | PurpleMenuAction *action; |
| 15230 | 220 | |
|
34695
60a278f1365b
Refactored libpurple plugins with initial GObject blist API
Ankit Vani <a@nevitus.org>
parents:
34625
diff
changeset
|
221 | if (!PURPLE_IS_BUDDY(node) && !PURPLE_IS_CONTACT(node) && |
|
60a278f1365b
Refactored libpurple plugins with initial GObject blist API
Ankit Vani <a@nevitus.org>
parents:
34625
diff
changeset
|
222 | !purple_blist_node_get_dont_save(node)) |
| 15230 | 223 | return; |
| 224 | ||
| 15884 | 225 | action = purple_menu_action_new(_("Autoaccept File Transfers..."), |
| 226 | PURPLE_CALLBACK(set_auto_accept_settings), plugin, NULL); | |
| 15230 | 227 | (*menu) = g_list_prepend(*menu, action); |
| 228 | } | |
| 229 | ||
| 230 | static gboolean | |
| 15884 | 231 | plugin_load(PurplePlugin *plugin) |
| 15230 | 232 | { |
|
31283
df4184c594d7
Migrate the pref the previous commit dropped. Refs #11459.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
31282
diff
changeset
|
233 | /* migrate the old pref (we should only care if the plugin is actually *used*) */ |
|
31287
e1c3051e704c
Add a comment that we should eventually remove this pref
Mark Doliner <markdoliner@pidgin.im>
parents:
31286
diff
changeset
|
234 | /* |
|
e1c3051e704c
Add a comment that we should eventually remove this pref
Mark Doliner <markdoliner@pidgin.im>
parents:
31286
diff
changeset
|
235 | * TODO: We should eventually call purple_prefs_remove(PREFS_STRANGER_OLD) |
|
e1c3051e704c
Add a comment that we should eventually remove this pref
Mark Doliner <markdoliner@pidgin.im>
parents:
31286
diff
changeset
|
236 | * to clean up after ourselves, but we don't want to do it yet |
|
e1c3051e704c
Add a comment that we should eventually remove this pref
Mark Doliner <markdoliner@pidgin.im>
parents:
31286
diff
changeset
|
237 | * so that we don't break users who share a .purple directory |
|
e1c3051e704c
Add a comment that we should eventually remove this pref
Mark Doliner <markdoliner@pidgin.im>
parents:
31286
diff
changeset
|
238 | * between old libpurple clients and new libpurple clients. |
|
e1c3051e704c
Add a comment that we should eventually remove this pref
Mark Doliner <markdoliner@pidgin.im>
parents:
31286
diff
changeset
|
239 | * --Mark Doliner, 2011-01-03 |
|
e1c3051e704c
Add a comment that we should eventually remove this pref
Mark Doliner <markdoliner@pidgin.im>
parents:
31286
diff
changeset
|
240 | */ |
|
32953
1edfa83f6ff8
Don't migrate the old autoaccept pref if the new one already exists.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
32438
diff
changeset
|
241 | if (!purple_prefs_exists(PREF_STRANGER)) { |
|
33352
fe562503e212
Check for old pref existence before using it.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
32965
diff
changeset
|
242 | if (purple_prefs_exists(PREF_STRANGER_OLD) && purple_prefs_get_bool(PREF_STRANGER_OLD)) |
|
32953
1edfa83f6ff8
Don't migrate the old autoaccept pref if the new one already exists.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
32438
diff
changeset
|
243 | purple_prefs_add_int(PREF_STRANGER, FT_REJECT); |
|
1edfa83f6ff8
Don't migrate the old autoaccept pref if the new one already exists.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
32438
diff
changeset
|
244 | else |
|
1edfa83f6ff8
Don't migrate the old autoaccept pref if the new one already exists.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
32438
diff
changeset
|
245 | purple_prefs_set_int(PREF_STRANGER, FT_ASK); |
|
1edfa83f6ff8
Don't migrate the old autoaccept pref if the new one already exists.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
32438
diff
changeset
|
246 | } |
|
31283
df4184c594d7
Migrate the pref the previous commit dropped. Refs #11459.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
31282
diff
changeset
|
247 | |
| 15884 | 248 | purple_signal_connect(purple_xfers_get_handle(), "file-recv-request", plugin, |
| 249 | PURPLE_CALLBACK(file_recv_request_cb), plugin); | |
| 250 | purple_signal_connect(purple_blist_get_handle(), "blist-node-extended-menu", plugin, | |
| 251 | PURPLE_CALLBACK(context_menu), plugin); | |
| 15230 | 252 | return TRUE; |
| 253 | } | |
| 254 | ||
| 255 | static gboolean | |
| 15884 | 256 | plugin_unload(PurplePlugin *plugin) |
| 15230 | 257 | { |
| 258 | return TRUE; | |
| 259 | } | |
| 260 | ||
| 15884 | 261 | static PurplePluginPrefFrame * |
| 262 | get_plugin_pref_frame(PurplePlugin *plugin) | |
| 15230 | 263 | { |
| 15884 | 264 | PurplePluginPrefFrame *frame; |
| 265 | PurplePluginPref *pref; | |
| 15230 | 266 | |
| 15884 | 267 | frame = purple_plugin_pref_frame_new(); |
| 15230 | 268 | |
| 269 | /* XXX: Is there a better way than this? There really should be. */ | |
| 15884 | 270 | pref = purple_plugin_pref_new_with_name_and_label(PREF_PATH, _("Path to save the files in\n" |
| 15230 | 271 | "(Please provide the full path)")); |
| 15884 | 272 | purple_plugin_pref_frame_add(frame, pref); |
| 15230 | 273 | |
| 15884 | 274 | 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
|
275 | _("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
|
276 | "*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
|
277 | 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
|
278 | 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
|
279 | 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
|
280 | purple_plugin_pref_add_choice(pref, _("Auto Reject"), GINT_TO_POINTER(FT_REJECT)); |
| 15884 | 281 | purple_plugin_pref_frame_add(frame, pref); |
| 15230 | 282 | |
| 15884 | 283 | pref = purple_plugin_pref_new_with_name_and_label(PREF_NOTIFY, |
| 15230 | 284 | _("Notify with a popup when an autoaccepted file transfer is complete\n" |
| 285 | "(only when there's no conversation with the sender)")); | |
| 15884 | 286 | purple_plugin_pref_frame_add(frame, pref); |
| 15230 | 287 | |
|
23849
020974bf1759
Allow not creating a different directory for each user. Closes #5997.
Luke Bratch <l_bratch@yahoo.co.uk>
parents:
21897
diff
changeset
|
288 | 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
|
289 | _("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
|
290 | 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
|
291 | |
|
31282
16eb735c55ae
Add additional options to the autoaccept plugin. Fixes #11459.
Rok Mandeljc <rok.mandeljc@gmail.com>
parents:
29491
diff
changeset
|
292 | 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
|
293 | _("Escape the filenames")); |
|
16eb735c55ae
Add additional options to the autoaccept plugin. Fixes #11459.
Rok Mandeljc <rok.mandeljc@gmail.com>
parents:
29491
diff
changeset
|
294 | 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
|
295 | |
| 15230 | 296 | return frame; |
| 297 | } | |
| 298 | ||
| 15884 | 299 | static PurplePluginUiInfo prefs_info = { |
| 15230 | 300 | get_plugin_pref_frame, |
| 301 | 0, | |
| 302 | NULL, | |
|
16745
df2c3d6b609a
And the rest of the plugins that are compiling for me by default...
Gary Kramlich <grim@reaperworld.com>
parents:
16490
diff
changeset
|
303 | |
|
df2c3d6b609a
And the rest of the plugins that are compiling for me by default...
Gary Kramlich <grim@reaperworld.com>
parents:
16490
diff
changeset
|
304 | /* padding */ |
|
df2c3d6b609a
And the rest of the plugins that are compiling for me by default...
Gary Kramlich <grim@reaperworld.com>
parents:
16490
diff
changeset
|
305 | NULL, |
|
df2c3d6b609a
And the rest of the plugins that are compiling for me by default...
Gary Kramlich <grim@reaperworld.com>
parents:
16490
diff
changeset
|
306 | NULL, |
|
df2c3d6b609a
And the rest of the plugins that are compiling for me by default...
Gary Kramlich <grim@reaperworld.com>
parents:
16490
diff
changeset
|
307 | NULL, |
|
df2c3d6b609a
And the rest of the plugins that are compiling for me by default...
Gary Kramlich <grim@reaperworld.com>
parents:
16490
diff
changeset
|
308 | NULL |
| 15230 | 309 | }; |
| 310 | ||
| 15884 | 311 | static PurplePluginInfo info = { |
| 312 | PURPLE_PLUGIN_MAGIC, /* Magic */ | |
| 313 | PURPLE_MAJOR_VERSION, /* Purple Major Version */ | |
| 314 | PURPLE_MINOR_VERSION, /* Purple Minor Version */ | |
| 315 | PURPLE_PLUGIN_STANDARD, /* plugin type */ | |
|
15418
bf287f742a5a
[gaim-migrate @ 18149]
Luke Schierer <lschiere@pidgin.im>
parents:
15230
diff
changeset
|
316 | NULL, /* ui requirement */ |
|
bf287f742a5a
[gaim-migrate @ 18149]
Luke Schierer <lschiere@pidgin.im>
parents:
15230
diff
changeset
|
317 | 0, /* flags */ |
|
bf287f742a5a
[gaim-migrate @ 18149]
Luke Schierer <lschiere@pidgin.im>
parents:
15230
diff
changeset
|
318 | NULL, /* dependencies */ |
| 15884 | 319 | PURPLE_PRIORITY_DEFAULT, /* priority */ |
| 15230 | 320 | |
|
15418
bf287f742a5a
[gaim-migrate @ 18149]
Luke Schierer <lschiere@pidgin.im>
parents:
15230
diff
changeset
|
321 | PLUGIN_ID, /* plugin id */ |
|
bf287f742a5a
[gaim-migrate @ 18149]
Luke Schierer <lschiere@pidgin.im>
parents:
15230
diff
changeset
|
322 | PLUGIN_NAME, /* name */ |
|
20288
5ca925a094e2
applied changes from 03b709ec2a153e7e82719df0ba4635108bb1d3c6
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
19859
diff
changeset
|
323 | DISPLAY_VERSION, /* version */ |
|
15418
bf287f742a5a
[gaim-migrate @ 18149]
Luke Schierer <lschiere@pidgin.im>
parents:
15230
diff
changeset
|
324 | PLUGIN_SUMMARY, /* summary */ |
|
bf287f742a5a
[gaim-migrate @ 18149]
Luke Schierer <lschiere@pidgin.im>
parents:
15230
diff
changeset
|
325 | PLUGIN_DESCRIPTION, /* description */ |
| 15230 | 326 | PLUGIN_AUTHOR, /* author */ |
| 15884 | 327 | PURPLE_WEBSITE, /* website */ |
| 15230 | 328 | |
| 329 | plugin_load, /* load */ | |
| 330 | plugin_unload, /* unload */ | |
|
15418
bf287f742a5a
[gaim-migrate @ 18149]
Luke Schierer <lschiere@pidgin.im>
parents:
15230
diff
changeset
|
331 | NULL, /* destroy */ |
| 15230 | 332 | |
|
15418
bf287f742a5a
[gaim-migrate @ 18149]
Luke Schierer <lschiere@pidgin.im>
parents:
15230
diff
changeset
|
333 | NULL, /* ui_info */ |
|
bf287f742a5a
[gaim-migrate @ 18149]
Luke Schierer <lschiere@pidgin.im>
parents:
15230
diff
changeset
|
334 | NULL, /* extra_info */ |
| 15230 | 335 | &prefs_info, /* prefs_info */ |
|
16745
df2c3d6b609a
And the rest of the plugins that are compiling for me by default...
Gary Kramlich <grim@reaperworld.com>
parents:
16490
diff
changeset
|
336 | NULL, /* actions */ |
|
df2c3d6b609a
And the rest of the plugins that are compiling for me by default...
Gary Kramlich <grim@reaperworld.com>
parents:
16490
diff
changeset
|
337 | |
|
df2c3d6b609a
And the rest of the plugins that are compiling for me by default...
Gary Kramlich <grim@reaperworld.com>
parents:
16490
diff
changeset
|
338 | /* padding */ |
|
df2c3d6b609a
And the rest of the plugins that are compiling for me by default...
Gary Kramlich <grim@reaperworld.com>
parents:
16490
diff
changeset
|
339 | NULL, |
|
df2c3d6b609a
And the rest of the plugins that are compiling for me by default...
Gary Kramlich <grim@reaperworld.com>
parents:
16490
diff
changeset
|
340 | NULL, |
|
df2c3d6b609a
And the rest of the plugins that are compiling for me by default...
Gary Kramlich <grim@reaperworld.com>
parents:
16490
diff
changeset
|
341 | NULL, |
|
df2c3d6b609a
And the rest of the plugins that are compiling for me by default...
Gary Kramlich <grim@reaperworld.com>
parents:
16490
diff
changeset
|
342 | NULL |
| 15230 | 343 | }; |
| 344 | ||
| 345 | static void | |
| 15884 | 346 | init_plugin(PurplePlugin *plugin) { |
| 15230 | 347 | char *dirname; |
| 348 | ||
| 15884 | 349 | dirname = g_build_filename(purple_user_dir(), "autoaccept", NULL); |
| 350 | purple_prefs_add_none(PREF_PREFIX); | |
| 351 | purple_prefs_add_string(PREF_PATH, dirname); | |
| 352 | 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
|
353 | 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
|
354 | purple_prefs_add_bool(PREF_ESCAPE, TRUE); |
| 15230 | 355 | g_free(dirname); |
| 356 | } | |
| 357 | ||
| 15884 | 358 | PURPLE_INIT_PLUGIN(PLUGIN_STATIC_NAME, init_plugin, info) |