annotate libgaim/plugins/autoaccept.c @ 15171:a00712d0522e

[gaim-migrate @ 17957] Show 'ABC is typing...' in the conversation window for typing notification. seanegan suggested this, and it sounded like an interesting thing to do. The change in gnttextview.c will need some more work if it is to be used for some other task, but its current use should be OK. committer: Tailor Script <tailor@pidgin.im>
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Mon, 11 Dec 2006 06:02:15 +0000
parents 630b794db0c8
children 2db21e0292b8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15168
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
1 /*
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
2 * Autoaccept - Auto-accept file transfers from selected users
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
3 * Copyright (C) 2006
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
4 *
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
5 * This program is free software; you can redistribute it and/or
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
6 * modify it under the terms of the GNU General Public License as
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
7 * published by the Free Software Foundation; either version 2 of the
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
8 * License, or (at your option) any later version.
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
9 *
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
10 * This program is distributed in the hope that it will be useful, but
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
13 * General Public License for more details.
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
14 *
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
16 * along with this program; if not, write to the Free Software
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
18 * 02111-1307, USA.
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
19 */
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
20 #include "internal.h"
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
21
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
22 #define PLUGIN_ID "core-plugin_pack-autoaccept"
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
23 #define PLUGIN_NAME "Autoaccept"
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
24 #define PLUGIN_STATIC_NAME "Autoaccept"
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
25 #define PLUGIN_SUMMARY "Auto-accept file transfer requests from selected users."
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
26 #define PLUGIN_DESCRIPTION "Auto-accept file transfer requests from selected users."
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
27 #define PLUGIN_AUTHOR "Sadrul H Chowdhury <sadrul@users.sourceforge.net>"
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
28
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
29 /* System headers */
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
30 #include <glib.h>
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
31 #if GLIB_CHECK_VERSION(2,6,0)
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
32 # include <glib/gstdio.h>
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
33 #else
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
34 # include <sys/types.h>
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
35 # include <sys/stat.h>
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
36 # define g_mkdir mkdir
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
37 #endif
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
38
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
39 /* Gaim headers */
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
40 #include <plugin.h>
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
41 #include <version.h>
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
42
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
43 #include <blist.h>
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
44 #include <conversation.h>
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
45 #include <ft.h>
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
46 #include <request.h>
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
47 #include <notify.h>
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
48 #include <util.h>
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
49
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
50 #define PREF_PREFIX "/plugins/core/" PLUGIN_ID
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
51 #define PREF_PATH PREF_PREFIX "/path"
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
52 #define PREF_STRANGER PREF_PREFIX "/reject_stranger"
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
53 #define PREF_NOTIFY PREF_PREFIX "/notify"
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
54
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
55 typedef enum
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
56 {
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
57 FT_ASK,
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
58 FT_ACCEPT,
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
59 FT_REJECT
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
60 } AutoAcceptSetting;
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
61
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
62 static gboolean
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
63 ensure_path_exists(const char *dir)
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
64 {
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
65 if (!g_file_test(dir, G_FILE_TEST_IS_DIR))
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
66 {
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
67 if (gaim_build_dir(dir, S_IRUSR | S_IWUSR | S_IXUSR))
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
68 return FALSE;
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
69 }
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
70
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
71 return TRUE;
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
72 }
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
73
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
74 static void
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
75 auto_accept_complete_cb(GaimXfer *xfer, GaimXfer *my)
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
76 {
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
77 if (xfer == my && gaim_prefs_get_bool(PREF_NOTIFY) &&
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
78 !gaim_find_conversation_with_account(GAIM_CONV_TYPE_IM, xfer->who, xfer->account))
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
79 {
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
80 char *message = g_strdup_printf(_("Autoaccepted file transfer of \"%s\" from \"%s\" completed."),
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
81 xfer->filename, xfer->who);
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
82 gaim_notify_info(NULL, _("Autoaccept complete"), message, NULL);
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
83 g_free(message);
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
84 }
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
85 }
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
86
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
87 static void
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
88 file_recv_request_cb(GaimXfer *xfer, gpointer handle)
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
89 {
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
90 GaimAccount *account;
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
91 GaimBlistNode *node;
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
92 const char *pref;
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
93 char *filename;
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
94 char *dirname;
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
95
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
96 account = xfer->account;
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
97 node = (GaimBlistNode *)gaim_find_buddy(account, xfer->who);
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
98
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
99 if (!node)
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
100 {
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
101 if (gaim_prefs_get_bool(PREF_STRANGER))
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
102 xfer->status = GAIM_XFER_STATUS_CANCEL_LOCAL;
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
103 return;
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
104 }
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
105
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
106 node = node->parent;
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
107 g_return_if_fail(GAIM_BLIST_NODE_IS_CONTACT(node));
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
108
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
109 pref = gaim_prefs_get_string(PREF_PATH);
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
110 switch (gaim_blist_node_get_int(node, "autoaccept"))
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
111 {
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
112 case FT_ASK:
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
113 break;
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
114 case FT_ACCEPT:
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
115 if (ensure_path_exists(pref))
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
116 {
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
117 dirname = g_build_filename(pref, xfer->who, NULL);
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
118
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
119 if (!ensure_path_exists(dirname))
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
120 {
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
121 g_free(dirname);
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
122 break;
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
123 }
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
124
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
125 filename = g_build_filename(dirname, xfer->filename, NULL);
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
126
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
127 gaim_xfer_request_accepted(xfer, filename);
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
128
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
129 g_free(dirname);
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
130 g_free(filename);
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
131 }
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
132
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
133 gaim_signal_connect(gaim_xfers_get_handle(), "file-recv-complete", handle,
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
134 GAIM_CALLBACK(auto_accept_complete_cb), xfer);
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
135 break;
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
136 case FT_REJECT:
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
137 xfer->status = GAIM_XFER_STATUS_CANCEL_LOCAL;
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
138 break;
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
139 }
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
140 }
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
141
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
142 static void
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
143 save_cb(GaimBlistNode *node, int choice)
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
144 {
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
145 if (GAIM_BLIST_NODE_IS_BUDDY(node))
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
146 node = node->parent;
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
147 g_return_if_fail(GAIM_BLIST_NODE_IS_CONTACT(node));
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
148 gaim_blist_node_set_int(node, "autoaccept", choice);
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
149 }
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
150
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
151 static void
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
152 set_auto_accept_settings(GaimBlistNode *node, gpointer plugin)
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
153 {
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
154 char *message;
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
155
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
156 if (GAIM_BLIST_NODE_IS_BUDDY(node))
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
157 node = node->parent;
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
158 g_return_if_fail(GAIM_BLIST_NODE_IS_CONTACT(node));
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
159
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
160 message = g_strdup_printf(_("When a file-transfer request arrives from %s"),
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
161 gaim_contact_get_alias((GaimContact *)node));
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
162 gaim_request_choice(plugin, _("Set Autoaccept Setting"), message,
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
163 NULL, gaim_blist_node_get_int(node, "autoaccept"),
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
164 _("_Save"), G_CALLBACK(save_cb),
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
165 _("_Cancel"), NULL, node,
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
166 _("Ask"), FT_ASK,
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
167 _("Auto Accept"), FT_ACCEPT,
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
168 _("Auto Reject"), FT_REJECT,
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
169 NULL);
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
170 g_free(message);
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
171 }
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
172
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
173 static void
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
174 context_menu(GaimBlistNode *node, GList **menu, gpointer plugin)
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
175 {
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
176 GaimMenuAction *action;
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
177
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
178 if (!GAIM_BLIST_NODE_IS_BUDDY(node) && !GAIM_BLIST_NODE_IS_CONTACT(node))
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
179 return;
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
180
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
181 action = gaim_menu_action_new(_("Autoaccept File Transfers..."),
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
182 GAIM_CALLBACK(set_auto_accept_settings), plugin, NULL);
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
183 (*menu) = g_list_prepend(*menu, action);
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
184 }
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
185
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
186 static gboolean
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
187 plugin_load(GaimPlugin *plugin)
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
188 {
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
189 gaim_signal_connect(gaim_xfers_get_handle(), "file-recv-request", plugin,
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
190 GAIM_CALLBACK(file_recv_request_cb), plugin);
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
191 gaim_signal_connect(gaim_blist_get_handle(), "blist-node-extended-menu", plugin,
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
192 GAIM_CALLBACK(context_menu), plugin);
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
193 return TRUE;
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
194 }
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
195
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
196 static gboolean
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
197 plugin_unload(GaimPlugin *plugin)
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
198 {
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
199 return TRUE;
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
200 }
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
201
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
202 static GaimPluginPrefFrame *
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
203 get_plugin_pref_frame(GaimPlugin *plugin)
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
204 {
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
205 GaimPluginPrefFrame *frame;
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
206 GaimPluginPref *pref;
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
207
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
208 frame = gaim_plugin_pref_frame_new();
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
209
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
210 /* XXX: Is there a better way than this? There really should be. */
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
211 pref = gaim_plugin_pref_new_with_name_and_label(PREF_PATH, _("Path to save the files in\n"
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
212 "(Please provide the full path)"));
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
213 gaim_plugin_pref_frame_add(frame, pref);
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
214
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
215 pref = gaim_plugin_pref_new_with_name_and_label(PREF_STRANGER,
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
216 _("Automatically reject from users not in buddy list"));
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
217 gaim_plugin_pref_frame_add(frame, pref);
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
218
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
219 pref = gaim_plugin_pref_new_with_name_and_label(PREF_NOTIFY,
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
220 _("Notify with a popup when an autoaccepted file transfer is complete\n"
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
221 "(only when there's no conversation with the sender)"));
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
222 gaim_plugin_pref_frame_add(frame, pref);
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
223
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
224 return frame;
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
225 }
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
226
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
227 static GaimPluginUiInfo prefs_info = {
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
228 get_plugin_pref_frame,
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
229 0,
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
230 NULL,
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
231 };
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
232
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
233 static GaimPluginInfo info = {
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
234 GAIM_PLUGIN_MAGIC, /* Magic */
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
235 GAIM_MAJOR_VERSION, /* Gaim Major Version */
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
236 GAIM_MINOR_VERSION, /* Gaim Minor Version */
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
237 GAIM_PLUGIN_STANDARD, /* plugin type */
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
238 NULL, /* ui requirement */
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
239 0, /* flags */
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
240 NULL, /* dependencies */
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
241 GAIM_PRIORITY_DEFAULT, /* priority */
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
242
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
243 PLUGIN_ID, /* plugin id */
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
244 N_(PLUGIN_NAME), /* name */
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
245 VERSION, /* version */
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
246 N_(PLUGIN_SUMMARY), /* summary */
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
247 N_(PLUGIN_DESCRIPTION), /* description */
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
248 PLUGIN_AUTHOR, /* author */
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
249 GAIM_WEBSITE, /* website */
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
250
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
251 plugin_load, /* load */
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
252 plugin_unload, /* unload */
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
253 NULL, /* destroy */
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
254
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
255 NULL, /* ui_info */
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
256 NULL, /* extra_info */
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
257 &prefs_info, /* prefs_info */
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
258 NULL /* actions */
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
259 };
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
260
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
261 static void
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
262 init_plugin(GaimPlugin *plugin) {
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
263 char *dirname;
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
264
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
265 dirname = g_build_filename(gaim_user_dir(), "autoaccept", NULL);
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
266 gaim_prefs_add_none(PREF_PREFIX);
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
267 gaim_prefs_add_string(PREF_PATH, dirname);
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
268 gaim_prefs_add_bool(PREF_STRANGER, TRUE);
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
269 gaim_prefs_add_bool(PREF_NOTIFY, TRUE);
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
270 g_free(dirname);
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
271 }
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
272
630b794db0c8 [gaim-migrate @ 17954]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
273 GAIM_INIT_PLUGIN(PLUGIN_STATIC_NAME, init_plugin, info)