libpurple/plugins/joinpart.c

Mon, 16 Sep 2013 16:48:10 +0530

author
Ankit Vani <a@nevitus.org>
date
Mon, 16 Sep 2013 16:48:10 +0530
branch
soc.2013.gobjectification.plugins
changeset 36743
3d44db6dd9b4
parent 36574
e9b59dd16117
child 36747
0b84912ce764
permissions
-rw-r--r--

Refactored joinpart to use the new plugin API

15627
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
1 /**
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15627
diff changeset
2 * purple
15627
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
3 *
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15627
diff changeset
4 * Purple is the legal property of its developers, whose names are too numerous
15627
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
5 * to list here. Please refer to the COPYRIGHT file distributed with this
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
6 * source distribution.
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
7 *
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
8 * This program is free software; you can redistribute it and/or modify
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
9 * it under the terms of the GNU General Public License as published by
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
10 * the Free Software Foundation; either version 2 of the License, or
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
11 * (at your option) any later version.
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
12 *
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
13 * This program is distributed in the hope that it will be useful,
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
16 * GNU General Public License for more details.
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
17 *
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
18 * You should have received a copy of the GNU General Public License
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
19 * 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: 18122
diff changeset
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
15627
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
21 */
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
22
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
23 #include "internal.h"
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
24 #include "conversation.h"
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
25 #include "debug.h"
36367
891eea799578 Renamed plugin.[ch] to plugins.[ch], since we (will) no longer have a PurplePlugin structure.
Ankit Vani <a@nevitus.org>
parents: 34728
diff changeset
26 #include "plugins.h"
15627
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
27 #include "version.h"
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
28
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
29 #define JOINPART_PLUGIN_ID "core-rlaager-joinpart"
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
30
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
31
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
32 /* Preferences */
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
33
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
34 /* The number of minutes before a person is considered
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
35 * to have stopped being part of active conversation. */
16481
ba8653070600 Fix GTK Plugin prefs
Sean Egan <seanegan@pidgin.im>
parents: 16478
diff changeset
36 #define DELAY_PREF "/plugins/core/joinpart/delay"
15627
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
37 #define DELAY_DEFAULT 10
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
38
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
39 /* The number of people that must be in a room for this
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
40 * plugin to have any effect */
16481
ba8653070600 Fix GTK Plugin prefs
Sean Egan <seanegan@pidgin.im>
parents: 16478
diff changeset
41 #define THRESHOLD_PREF "/plugins/core/joinpart/threshold"
15627
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
42 #define THRESHOLD_DEFAULT 20
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
43
24135
3998dcd1e2fb In the Join/Part plugin, add the ability to apply the rules to
Richard Laager <rlaager@pidgin.im>
parents: 22606
diff changeset
44 /* Hide buddies */
3998dcd1e2fb In the Join/Part plugin, add the ability to apply the rules to
Richard Laager <rlaager@pidgin.im>
parents: 22606
diff changeset
45 #define HIDE_BUDDIES_PREF "/plugins/core/joinpart/hide_buddies"
3998dcd1e2fb In the Join/Part plugin, add the ability to apply the rules to
Richard Laager <rlaager@pidgin.im>
parents: 22606
diff changeset
46 #define HIDE_BUDDIES_DEFAULT FALSE
3998dcd1e2fb In the Join/Part plugin, add the ability to apply the rules to
Richard Laager <rlaager@pidgin.im>
parents: 22606
diff changeset
47
15627
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
48 struct joinpart_key
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
49 {
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15627
diff changeset
50 PurpleConversation *conv;
15627
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
51 char *user;
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
52 };
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
53
36743
3d44db6dd9b4 Refactored joinpart to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36574
diff changeset
54 static GHashTable *users;
3d44db6dd9b4 Refactored joinpart to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36574
diff changeset
55 static guint id;
3d44db6dd9b4 Refactored joinpart to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36574
diff changeset
56
3d44db6dd9b4 Refactored joinpart to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36574
diff changeset
57
15627
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
58 static guint joinpart_key_hash(const struct joinpart_key *key)
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
59 {
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
60 g_return_val_if_fail(key != NULL, 0);
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
61
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
62 return g_direct_hash(key->conv) + g_str_hash(key->user);
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
63 }
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
64
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
65 static gboolean joinpart_key_equal(const struct joinpart_key *a, const struct joinpart_key *b)
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
66 {
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
67 if (a == NULL)
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
68 return (b == NULL);
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
69 else if (b == NULL)
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
70 return FALSE;
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
71
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
72 return (a->conv == b->conv) && !strcmp(a->user, b->user);
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
73 }
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
74
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
75 static void joinpart_key_destroy(struct joinpart_key *key)
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
76 {
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
77 g_return_if_fail(key != NULL);
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
78
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
79 g_free(key->user);
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
80 g_free(key);
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
81 }
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
82
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15627
diff changeset
83 static gboolean should_hide_notice(PurpleConversation *conv, const char *name,
15627
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
84 GHashTable *users)
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
85 {
34622
753f46dd000f Global replace - renamed functions and types according to GObject-based PurpleConversation API
Ankit Vani <a@nevitus.org>
parents: 28060
diff changeset
86 PurpleChatConversation *chat;
34304
faf0414a8b51 Fix most of libpurple warnings about -Wsign-compare
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 28060
diff changeset
87 guint threshold;
22606
9bd736ad3f55 Fix a memory leak
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 20288
diff changeset
88 struct joinpart_key key;
15627
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
89 time_t *last_said;
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
90
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
91 g_return_val_if_fail(conv != NULL, FALSE);
34626
b8b3186aff95 Refactored some libpurple plugins for GObject-based PurpleConversation
Ankit Vani <a@nevitus.org>
parents: 34622
diff changeset
92 g_return_val_if_fail(PURPLE_IS_CHAT_CONVERSATION(conv), FALSE);
15627
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
93
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
94 /* If the room is small, don't bother. */
34628
014583658b51 Refactored libpurple/plugins to use the GObject-based PurpleConversation
Ankit Vani <a@nevitus.org>
parents: 34626
diff changeset
95 chat = PURPLE_CHAT_CONVERSATION(conv);
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15627
diff changeset
96 threshold = purple_prefs_get_int(THRESHOLD_PREF);
34622
753f46dd000f Global replace - renamed functions and types according to GObject-based PurpleConversation API
Ankit Vani <a@nevitus.org>
parents: 28060
diff changeset
97 if (g_list_length(purple_chat_conversation_get_users(chat)) < threshold)
15627
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
98 return FALSE;
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
99
24135
3998dcd1e2fb In the Join/Part plugin, add the ability to apply the rules to
Richard Laager <rlaager@pidgin.im>
parents: 22606
diff changeset
100 if (!purple_prefs_get_bool(HIDE_BUDDIES_PREF) &&
34728
8efd73063ecf Renamed buddy list functions to more appropriate/simler names.
Ankit Vani <a@nevitus.org>
parents: 34670
diff changeset
101 purple_blist_find_buddy(purple_conversation_get_account(conv), name))
15627
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
102 return FALSE;
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
103
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
104 /* Only show the notice if the user has spoken recently. */
22606
9bd736ad3f55 Fix a memory leak
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 20288
diff changeset
105 key.conv = conv;
9bd736ad3f55 Fix a memory leak
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 20288
diff changeset
106 key.user = (gchar *)name;
9bd736ad3f55 Fix a memory leak
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 20288
diff changeset
107 last_said = g_hash_table_lookup(users, &key);
15627
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
108 if (last_said != NULL)
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
109 {
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15627
diff changeset
110 int delay = purple_prefs_get_int(DELAY_PREF);
15627
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
111 if (delay > 0 && (*last_said + (delay * 60)) >= time(NULL))
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
112 return FALSE;
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
113 }
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
114
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
115 return TRUE;
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
116 }
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
117
34670
9bd5bd903dc7 Renamed chat buddies to chat users, and IM conversation typing state to IM typing state.
Ankit Vani <a@nevitus.org>
parents: 34628
diff changeset
118 static gboolean chat_user_leaving_cb(PurpleConversation *conv, const char *name,
15627
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
119 const char *reason, GHashTable *users)
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
120 {
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
121 return should_hide_notice(conv, name, users);
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
122 }
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
123
34670
9bd5bd903dc7 Renamed chat buddies to chat users, and IM conversation typing state to IM typing state.
Ankit Vani <a@nevitus.org>
parents: 34628
diff changeset
124 static gboolean chat_user_joining_cb(PurpleConversation *conv, const char *name,
9bd5bd903dc7 Renamed chat buddies to chat users, and IM conversation typing state to IM typing state.
Ankit Vani <a@nevitus.org>
parents: 34628
diff changeset
125 PurpleChatUserFlags flags,
15627
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
126 GHashTable *users)
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
127 {
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
128 return should_hide_notice(conv, name, users);
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
129 }
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
130
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15627
diff changeset
131 static void received_chat_msg_cb(PurpleAccount *account, char *sender,
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15627
diff changeset
132 char *message, PurpleConversation *conv,
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15627
diff changeset
133 PurpleMessageFlags flags, GHashTable *users)
15627
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
134 {
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
135 struct joinpart_key key;
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
136 time_t *last_said;
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
137
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
138 /* Most of the time, we'll already have tracked the user,
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
139 * so we avoid memory allocation here. */
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
140 key.conv = conv;
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
141 key.user = sender;
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
142 last_said = g_hash_table_lookup(users, &key);
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
143 if (last_said != NULL)
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
144 {
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
145 /* They just said something, so update the time. */
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
146 time(last_said);
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
147 }
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
148 else
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
149 {
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
150 struct joinpart_key *key2;
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
151
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
152 key2 = g_new(struct joinpart_key, 1);
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
153 key2->conv = conv;
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
154 key2->user = g_strdup(sender);
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
155
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
156 last_said = g_new(time_t, 1);
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
157 time(last_said);
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
158
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
159 g_hash_table_insert(users, key2, last_said);
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
160 }
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
161 }
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
162
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
163 static gboolean check_expire_time(struct joinpart_key *key,
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
164 time_t *last_said, time_t *limit)
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
165 {
17173
0ab8487ff12a We can't be sure that the conv still exists, so don't dereference it.
Daniel Atallah <datallah@pidgin.im>
parents: 16745
diff changeset
166 purple_debug_info("joinpart", "Removing key for %s\n", key->user);
15627
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
167 return (*last_said < *limit);
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
168 }
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
169
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
170 static gboolean clean_users_hash(GHashTable *users)
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
171 {
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15627
diff changeset
172 int delay = purple_prefs_get_int(DELAY_PREF);
15627
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
173 time_t limit = time(NULL) - (60 * delay);
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
174
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
175 g_hash_table_foreach_remove(users, (GHRFunc)check_expire_time, &limit);
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
176
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
177 return TRUE;
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
178 }
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
179
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15627
diff changeset
180 static PurplePluginPrefFrame *
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15627
diff changeset
181 get_plugin_pref_frame(PurplePlugin *plugin)
15627
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
182 {
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15627
diff changeset
183 PurplePluginPrefFrame *frame;
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15627
diff changeset
184 PurplePluginPref *ppref;
15627
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
185
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
186 g_return_val_if_fail(plugin != NULL, FALSE);
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
187
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15627
diff changeset
188 frame = purple_plugin_pref_frame_new();
15627
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
189
28060
0bba294c625e Drop a colon.
Paul Aurich <darkrain42@pidgin.im>
parents: 28059
diff changeset
190 ppref = purple_plugin_pref_new_with_label(_("Hide Joins/Parts"));
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15627
diff changeset
191 purple_plugin_pref_frame_add(frame, ppref);
15627
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
192
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15627
diff changeset
193 ppref = purple_plugin_pref_new_with_name_and_label(THRESHOLD_PREF,
28059
176739c0bbc3 Clarify the preference strings for the Join/Part hiding plugin.
Paul Aurich <darkrain42@pidgin.im>
parents: 25716
diff changeset
194 /* Translators: Followed by an input request a number of people */
176739c0bbc3 Clarify the preference strings for the Join/Part hiding plugin.
Paul Aurich <darkrain42@pidgin.im>
parents: 25716
diff changeset
195 _("For rooms with more than this many people"));
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15627
diff changeset
196 purple_plugin_pref_set_bounds(ppref, 0, 1000);
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15627
diff changeset
197 purple_plugin_pref_frame_add(frame, ppref);
15627
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
198
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15627
diff changeset
199 ppref = purple_plugin_pref_new_with_name_and_label(DELAY_PREF,
28059
176739c0bbc3 Clarify the preference strings for the Join/Part hiding plugin.
Paul Aurich <darkrain42@pidgin.im>
parents: 25716
diff changeset
200 _("If user has not spoken in this many minutes"));
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15627
diff changeset
201 purple_plugin_pref_set_bounds(ppref, 0, 8 * 60); /* 8 Hours */
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15627
diff changeset
202 purple_plugin_pref_frame_add(frame, ppref);
15627
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
203
24135
3998dcd1e2fb In the Join/Part plugin, add the ability to apply the rules to
Richard Laager <rlaager@pidgin.im>
parents: 22606
diff changeset
204 ppref = purple_plugin_pref_new_with_name_and_label(HIDE_BUDDIES_PREF,
3998dcd1e2fb In the Join/Part plugin, add the ability to apply the rules to
Richard Laager <rlaager@pidgin.im>
parents: 22606
diff changeset
205 _("Apply hiding rules to buddies"));
3998dcd1e2fb In the Join/Part plugin, add the ability to apply the rules to
Richard Laager <rlaager@pidgin.im>
parents: 22606
diff changeset
206 purple_plugin_pref_frame_add(frame, ppref);
3998dcd1e2fb In the Join/Part plugin, add the ability to apply the rules to
Richard Laager <rlaager@pidgin.im>
parents: 22606
diff changeset
207
15627
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
208 return frame;
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
209 }
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
210
36743
3d44db6dd9b4 Refactored joinpart to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36574
diff changeset
211 static PurplePluginInfo *
3d44db6dd9b4 Refactored joinpart to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36574
diff changeset
212 plugin_query(GError **error)
15627
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
213 {
36743
3d44db6dd9b4 Refactored joinpart to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36574
diff changeset
214 const gchar * const authors[] = {
3d44db6dd9b4 Refactored joinpart to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36574
diff changeset
215 "Richard Laager <rlaager@pidgin.im>",
3d44db6dd9b4 Refactored joinpart to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36574
diff changeset
216 NULL
3d44db6dd9b4 Refactored joinpart to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36574
diff changeset
217 };
15627
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
218
36743
3d44db6dd9b4 Refactored joinpart to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36574
diff changeset
219 return purple_plugin_info_new(
3d44db6dd9b4 Refactored joinpart to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36574
diff changeset
220 "id", JOINPART_PLUGIN_ID,
3d44db6dd9b4 Refactored joinpart to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36574
diff changeset
221 "name", N_("Join/Part Hiding"),
3d44db6dd9b4 Refactored joinpart to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36574
diff changeset
222 "version", DISPLAY_VERSION,
3d44db6dd9b4 Refactored joinpart to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36574
diff changeset
223 "category", N_("Utility"),
3d44db6dd9b4 Refactored joinpart to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36574
diff changeset
224 "summary", N_("Hides extraneous join/part messages."),
3d44db6dd9b4 Refactored joinpart to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36574
diff changeset
225 "description", N_("This plugin hides join/part messages in "
3d44db6dd9b4 Refactored joinpart to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36574
diff changeset
226 "large rooms, except for those users actively "
3d44db6dd9b4 Refactored joinpart to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36574
diff changeset
227 "taking part in a conversation."),
3d44db6dd9b4 Refactored joinpart to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36574
diff changeset
228 "authors", authors,
3d44db6dd9b4 Refactored joinpart to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36574
diff changeset
229 "website", PURPLE_WEBSITE,
3d44db6dd9b4 Refactored joinpart to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36574
diff changeset
230 "abi-version", PURPLE_ABI_VERSION,
3d44db6dd9b4 Refactored joinpart to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36574
diff changeset
231 "preferences-frame", get_plugin_pref_frame,
3d44db6dd9b4 Refactored joinpart to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36574
diff changeset
232 NULL
3d44db6dd9b4 Refactored joinpart to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36574
diff changeset
233 );
3d44db6dd9b4 Refactored joinpart to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36574
diff changeset
234 }
15627
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
235
36743
3d44db6dd9b4 Refactored joinpart to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36574
diff changeset
236 static gboolean plugin_load(PurplePlugin *plugin, GError **error)
3d44db6dd9b4 Refactored joinpart to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36574
diff changeset
237 {
3d44db6dd9b4 Refactored joinpart to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36574
diff changeset
238 void *conv_handle;
16745
df2c3d6b609a And the rest of the plugins that are compiling for me by default...
Gary Kramlich <grim@reaperworld.com>
parents: 16481
diff changeset
239
16481
ba8653070600 Fix GTK Plugin prefs
Sean Egan <seanegan@pidgin.im>
parents: 16478
diff changeset
240 purple_prefs_add_none("/plugins/core/joinpart");
15627
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
241
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15627
diff changeset
242 purple_prefs_add_int(DELAY_PREF, DELAY_DEFAULT);
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15627
diff changeset
243 purple_prefs_add_int(THRESHOLD_PREF, THRESHOLD_DEFAULT);
24135
3998dcd1e2fb In the Join/Part plugin, add the ability to apply the rules to
Richard Laager <rlaager@pidgin.im>
parents: 22606
diff changeset
244 purple_prefs_add_bool(HIDE_BUDDIES_PREF, HIDE_BUDDIES_DEFAULT);
36743
3d44db6dd9b4 Refactored joinpart to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36574
diff changeset
245
3d44db6dd9b4 Refactored joinpart to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36574
diff changeset
246 users = g_hash_table_new_full((GHashFunc)joinpart_key_hash,
3d44db6dd9b4 Refactored joinpart to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36574
diff changeset
247 (GEqualFunc)joinpart_key_equal,
3d44db6dd9b4 Refactored joinpart to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36574
diff changeset
248 (GDestroyNotify)joinpart_key_destroy,
3d44db6dd9b4 Refactored joinpart to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36574
diff changeset
249 g_free);
3d44db6dd9b4 Refactored joinpart to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36574
diff changeset
250
3d44db6dd9b4 Refactored joinpart to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36574
diff changeset
251 conv_handle = purple_conversations_get_handle();
3d44db6dd9b4 Refactored joinpart to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36574
diff changeset
252 purple_signal_connect(conv_handle, "chat-user-joining", plugin,
3d44db6dd9b4 Refactored joinpart to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36574
diff changeset
253 PURPLE_CALLBACK(chat_user_joining_cb), users);
3d44db6dd9b4 Refactored joinpart to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36574
diff changeset
254 purple_signal_connect(conv_handle, "chat-user-leaving", plugin,
3d44db6dd9b4 Refactored joinpart to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36574
diff changeset
255 PURPLE_CALLBACK(chat_user_leaving_cb), users);
3d44db6dd9b4 Refactored joinpart to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36574
diff changeset
256 purple_signal_connect(conv_handle, "received-chat-msg", plugin,
3d44db6dd9b4 Refactored joinpart to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36574
diff changeset
257 PURPLE_CALLBACK(received_chat_msg_cb), users);
3d44db6dd9b4 Refactored joinpart to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36574
diff changeset
258
3d44db6dd9b4 Refactored joinpart to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36574
diff changeset
259 /* Cleanup every 5 minutes */
3d44db6dd9b4 Refactored joinpart to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36574
diff changeset
260 id = purple_timeout_add_seconds(60 * 5, (GSourceFunc)clean_users_hash, users);
3d44db6dd9b4 Refactored joinpart to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36574
diff changeset
261
3d44db6dd9b4 Refactored joinpart to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36574
diff changeset
262 return TRUE;
15627
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
263 }
4be4b97cf1b7 I had this brilliant idea to deal with join/part notices "intelligently".
Richard Laager <rlaager@pidgin.im>
parents:
diff changeset
264
36743
3d44db6dd9b4 Refactored joinpart to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36574
diff changeset
265 static gboolean plugin_unload(PurplePlugin *plugin, GError **error)
3d44db6dd9b4 Refactored joinpart to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36574
diff changeset
266 {
3d44db6dd9b4 Refactored joinpart to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36574
diff changeset
267 /* Destroy the hash table. The core plugin code will
3d44db6dd9b4 Refactored joinpart to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36574
diff changeset
268 * disconnect the signals, and since Purple is single-threaded,
3d44db6dd9b4 Refactored joinpart to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36574
diff changeset
269 * we don't have to worry one will be called after this. */
3d44db6dd9b4 Refactored joinpart to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36574
diff changeset
270 g_hash_table_destroy(users);
3d44db6dd9b4 Refactored joinpart to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36574
diff changeset
271
3d44db6dd9b4 Refactored joinpart to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36574
diff changeset
272 purple_timeout_remove(id);
3d44db6dd9b4 Refactored joinpart to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36574
diff changeset
273
3d44db6dd9b4 Refactored joinpart to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36574
diff changeset
274 return TRUE;
3d44db6dd9b4 Refactored joinpart to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36574
diff changeset
275 }
3d44db6dd9b4 Refactored joinpart to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36574
diff changeset
276
3d44db6dd9b4 Refactored joinpart to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36574
diff changeset
277 PURPLE_PLUGIN_INIT(joinpart, plugin_query, plugin_load, plugin_unload);

mercurial