Mon, 24 Nov 2008 00:40:57 +0000
Prevent the Buddy State Notification plugin from printing duplicate
notifications when the same buddy is in multiple groups on protocols which
support it. Also prevent autolinkification of JID's, MSN passport addresses,
etc. in the notification messages. Fixes #7609.
committer: John Bailey <rekkanoryo@rekkanoryo.org>
|
5872
754c63f29b77
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5676
diff
changeset
|
1 | #include "internal.h" |
|
754c63f29b77
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5676
diff
changeset
|
2 | |
|
754c63f29b77
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5676
diff
changeset
|
3 | #include "blist.h" |
|
754c63f29b77
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5676
diff
changeset
|
4 | #include "conversation.h" |
|
754c63f29b77
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5676
diff
changeset
|
5 | #include "debug.h" |
|
6485
3c7ba18e32f1
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6441
diff
changeset
|
6 | #include "signals.h" |
| 9943 | 7 | #include "version.h" |
|
5872
754c63f29b77
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5676
diff
changeset
|
8 | |
| 9583 | 9 | #include "plugin.h" |
| 10 | #include "pluginpref.h" | |
| 11 | #include "prefs.h" | |
| 12 | ||
| 13 | #define STATENOTIFY_PLUGIN_ID "core-statenotify" | |
| 14 | ||
| 5267 | 15 | static void |
| 15884 | 16 | write_status(PurpleBuddy *buddy, const char *message) |
| 5267 | 17 | { |
|
24531
76e72697f7d6
Hide the blistnode, buddy, contact, group, and chat structs
Gary Kramlich <grim@reaperworld.com>
parents:
22880
diff
changeset
|
18 | PurpleAccount *account = NULL; |
| 15884 | 19 | PurpleConversation *conv; |
|
6485
3c7ba18e32f1
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6441
diff
changeset
|
20 | const char *who; |
| 5267 | 21 | char buf[256]; |
|
10167
3f4db9c54e04
[gaim-migrate @ 11254]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9943
diff
changeset
|
22 | char *escaped; |
|
24531
76e72697f7d6
Hide the blistnode, buddy, contact, group, and chat structs
Gary Kramlich <grim@reaperworld.com>
parents:
22880
diff
changeset
|
23 | const gchar *buddy_name = NULL; |
|
76e72697f7d6
Hide the blistnode, buddy, contact, group, and chat structs
Gary Kramlich <grim@reaperworld.com>
parents:
22880
diff
changeset
|
24 | |
|
76e72697f7d6
Hide the blistnode, buddy, contact, group, and chat structs
Gary Kramlich <grim@reaperworld.com>
parents:
22880
diff
changeset
|
25 | account = purple_buddy_get_account(buddy); |
|
76e72697f7d6
Hide the blistnode, buddy, contact, group, and chat structs
Gary Kramlich <grim@reaperworld.com>
parents:
22880
diff
changeset
|
26 | buddy_name = purple_buddy_get_name(buddy); |
| 5267 | 27 | |
| 15884 | 28 | conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, |
|
24531
76e72697f7d6
Hide the blistnode, buddy, contact, group, and chat structs
Gary Kramlich <grim@reaperworld.com>
parents:
22880
diff
changeset
|
29 | buddy_name, account); |
| 5267 | 30 | |
| 31 | if (conv == NULL) | |
| 32 | return; | |
| 15884 | 33 | g_return_if_fail(conv->type == PURPLE_CONV_TYPE_IM); |
| 5267 | 34 | |
|
24759
9f88e2d42845
Prevent the Buddy State Notification plugin from printing duplicate
Florian Quèze <florian@instantbird.org>
parents:
24531
diff
changeset
|
35 | /* Prevent duplicate notifications for buddies which are multiple times |
|
9f88e2d42845
Prevent the Buddy State Notification plugin from printing duplicate
Florian Quèze <florian@instantbird.org>
parents:
24531
diff
changeset
|
36 | in the buddy list */ |
|
9f88e2d42845
Prevent the Buddy State Notification plugin from printing duplicate
Florian Quèze <florian@instantbird.org>
parents:
24531
diff
changeset
|
37 | if (buddy != purple_find_buddy(buddy->account, buddy->name)) |
|
9f88e2d42845
Prevent the Buddy State Notification plugin from printing duplicate
Florian Quèze <florian@instantbird.org>
parents:
24531
diff
changeset
|
38 | return; |
|
9f88e2d42845
Prevent the Buddy State Notification plugin from printing duplicate
Florian Quèze <florian@instantbird.org>
parents:
24531
diff
changeset
|
39 | |
| 15884 | 40 | who = purple_buddy_get_alias(buddy); |
|
10167
3f4db9c54e04
[gaim-migrate @ 11254]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9943
diff
changeset
|
41 | escaped = g_markup_escape_text(who, -1); |
| 5267 | 42 | |
|
10167
3f4db9c54e04
[gaim-migrate @ 11254]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9943
diff
changeset
|
43 | g_snprintf(buf, sizeof(buf), message, escaped); |
|
3f4db9c54e04
[gaim-migrate @ 11254]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9943
diff
changeset
|
44 | g_free(escaped); |
| 5267 | 45 | |
|
24759
9f88e2d42845
Prevent the Buddy State Notification plugin from printing duplicate
Florian Quèze <florian@instantbird.org>
parents:
24531
diff
changeset
|
46 | purple_conv_im_write(conv->u.im, NULL, buf, PURPLE_MESSAGE_SYSTEM | PURPLE_MESSAGE_ACTIVE_ONLY | PURPLE_MESSAGE_NO_LINKIFY, time(NULL)); |
| 5267 | 47 | } |
| 48 | ||
| 49 | static void | |
| 15884 | 50 | buddy_status_changed_cb(PurpleBuddy *buddy, PurpleStatus *old_status, |
| 51 | PurpleStatus *status, void *data) | |
| 5267 | 52 | { |
| 11935 | 53 | gboolean available, old_available; |
| 54 | ||
|
22880
e44c97dec833
Do not show an erroneous message when the 'now listening' song for a
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
20288
diff
changeset
|
55 | if (!purple_status_is_exclusive(status) || |
|
e44c97dec833
Do not show an erroneous message when the 'now listening' song for a
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
20288
diff
changeset
|
56 | !purple_status_is_exclusive(old_status)) |
|
e44c97dec833
Do not show an erroneous message when the 'now listening' song for a
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
20288
diff
changeset
|
57 | return; |
|
e44c97dec833
Do not show an erroneous message when the 'now listening' song for a
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
20288
diff
changeset
|
58 | |
| 15884 | 59 | available = purple_status_is_available(status); |
| 60 | old_available = purple_status_is_available(old_status); | |
| 11935 | 61 | |
| 16481 | 62 | if (purple_prefs_get_bool("/plugins/core/statenotify/notify_away")) { |
| 11935 | 63 | if (available && !old_available) |
| 64 | write_status(buddy, _("%s is no longer away.")); | |
| 65 | else if (!available && old_available) | |
| 66 | write_status(buddy, _("%s has gone away.")); | |
| 67 | } | |
| 5267 | 68 | } |
| 69 | ||
| 70 | static void | |
| 15884 | 71 | buddy_idle_changed_cb(PurpleBuddy *buddy, gboolean old_idle, gboolean idle, |
| 11935 | 72 | void *data) |
| 5267 | 73 | { |
| 16481 | 74 | if (purple_prefs_get_bool("/plugins/core/statenotify/notify_idle")) { |
| 11935 | 75 | if (idle) { |
| 76 | write_status(buddy, _("%s has become idle.")); | |
| 77 | } else { | |
| 78 | write_status(buddy, _("%s is no longer idle.")); | |
| 79 | } | |
| 80 | } | |
| 9583 | 81 | } |
| 82 | ||
|
11901
34394921fe76
[gaim-migrate @ 14192]
Francesco Fracassi <ffracassi@users.sourceforge.net>
parents:
11338
diff
changeset
|
83 | static void |
| 15884 | 84 | buddy_signon_cb(PurpleBuddy *buddy, void *data) |
|
11901
34394921fe76
[gaim-migrate @ 14192]
Francesco Fracassi <ffracassi@users.sourceforge.net>
parents:
11338
diff
changeset
|
85 | { |
| 16481 | 86 | if (purple_prefs_get_bool("/plugins/core/statenotify/notify_signon")) |
|
11901
34394921fe76
[gaim-migrate @ 14192]
Francesco Fracassi <ffracassi@users.sourceforge.net>
parents:
11338
diff
changeset
|
87 | write_status(buddy, _("%s has signed on.")); |
|
34394921fe76
[gaim-migrate @ 14192]
Francesco Fracassi <ffracassi@users.sourceforge.net>
parents:
11338
diff
changeset
|
88 | } |
|
34394921fe76
[gaim-migrate @ 14192]
Francesco Fracassi <ffracassi@users.sourceforge.net>
parents:
11338
diff
changeset
|
89 | |
|
34394921fe76
[gaim-migrate @ 14192]
Francesco Fracassi <ffracassi@users.sourceforge.net>
parents:
11338
diff
changeset
|
90 | static void |
| 15884 | 91 | buddy_signoff_cb(PurpleBuddy *buddy, void *data) |
|
11901
34394921fe76
[gaim-migrate @ 14192]
Francesco Fracassi <ffracassi@users.sourceforge.net>
parents:
11338
diff
changeset
|
92 | { |
| 16481 | 93 | if (purple_prefs_get_bool("/plugins/core/statenotify/notify_signon")) |
|
11901
34394921fe76
[gaim-migrate @ 14192]
Francesco Fracassi <ffracassi@users.sourceforge.net>
parents:
11338
diff
changeset
|
94 | write_status(buddy, _("%s has signed off.")); |
|
34394921fe76
[gaim-migrate @ 14192]
Francesco Fracassi <ffracassi@users.sourceforge.net>
parents:
11338
diff
changeset
|
95 | } |
|
34394921fe76
[gaim-migrate @ 14192]
Francesco Fracassi <ffracassi@users.sourceforge.net>
parents:
11338
diff
changeset
|
96 | |
| 15884 | 97 | static PurplePluginPrefFrame * |
| 98 | get_plugin_pref_frame(PurplePlugin *plugin) | |
| 9583 | 99 | { |
| 15884 | 100 | PurplePluginPrefFrame *frame; |
| 101 | PurplePluginPref *ppref; | |
| 9583 | 102 | |
| 15884 | 103 | frame = purple_plugin_pref_frame_new(); |
| 9583 | 104 | |
| 15884 | 105 | ppref = purple_plugin_pref_new_with_label(_("Notify When")); |
| 106 | purple_plugin_pref_frame_add(frame, ppref); | |
| 9583 | 107 | |
| 16481 | 108 | ppref = purple_plugin_pref_new_with_name_and_label("/plugins/core/statenotify/notify_away", _("Buddy Goes _Away")); |
| 15884 | 109 | purple_plugin_pref_frame_add(frame, ppref); |
|
10246
aa5bff72f94c
[gaim-migrate @ 11386]
Mark Doliner <markdoliner@pidgin.im>
parents:
10167
diff
changeset
|
110 | |
| 16481 | 111 | ppref = purple_plugin_pref_new_with_name_and_label("/plugins/core/statenotify/notify_idle", _("Buddy Goes _Idle")); |
| 15884 | 112 | purple_plugin_pref_frame_add(frame, ppref); |
|
10246
aa5bff72f94c
[gaim-migrate @ 11386]
Mark Doliner <markdoliner@pidgin.im>
parents:
10167
diff
changeset
|
113 | |
| 16481 | 114 | ppref = purple_plugin_pref_new_with_name_and_label("/plugins/core/statenotify/notify_signon", _("Buddy _Signs On/Off")); |
| 15884 | 115 | purple_plugin_pref_frame_add(frame, ppref); |
|
11901
34394921fe76
[gaim-migrate @ 14192]
Francesco Fracassi <ffracassi@users.sourceforge.net>
parents:
11338
diff
changeset
|
116 | |
| 9583 | 117 | return frame; |
| 5267 | 118 | } |
| 119 | ||
| 120 | static gboolean | |
| 15884 | 121 | plugin_load(PurplePlugin *plugin) |
| 5267 | 122 | { |
| 15884 | 123 | void *blist_handle = purple_blist_get_handle(); |
|
6485
3c7ba18e32f1
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6441
diff
changeset
|
124 | |
| 15884 | 125 | purple_signal_connect(blist_handle, "buddy-status-changed", plugin, |
| 126 | PURPLE_CALLBACK(buddy_status_changed_cb), NULL); | |
| 127 | purple_signal_connect(blist_handle, "buddy-idle-changed", plugin, | |
| 128 | PURPLE_CALLBACK(buddy_idle_changed_cb), NULL); | |
| 129 | purple_signal_connect(blist_handle, "buddy-signed-on", plugin, | |
| 130 | PURPLE_CALLBACK(buddy_signon_cb), NULL); | |
| 131 | purple_signal_connect(blist_handle, "buddy-signed-off", plugin, | |
| 132 | PURPLE_CALLBACK(buddy_signoff_cb), NULL); | |
| 5267 | 133 | |
| 134 | return TRUE; | |
| 135 | } | |
| 136 | ||
| 15884 | 137 | static PurplePluginUiInfo prefs_info = |
| 9583 | 138 | { |
|
12600
7ecd4441fdc7
[gaim-migrate @ 14934]
Richard Laager <rlaager@pidgin.im>
parents:
11935
diff
changeset
|
139 | get_plugin_pref_frame, |
|
7ecd4441fdc7
[gaim-migrate @ 14934]
Richard Laager <rlaager@pidgin.im>
parents:
11935
diff
changeset
|
140 | 0, /* page_num (Reserved) */ |
|
16745
df2c3d6b609a
And the rest of the plugins that are compiling for me by default...
Gary Kramlich <grim@reaperworld.com>
parents:
16481
diff
changeset
|
141 | NULL, /* frame (Reserved) */ |
|
df2c3d6b609a
And the rest of the plugins that are compiling for me by default...
Gary Kramlich <grim@reaperworld.com>
parents:
16481
diff
changeset
|
142 | |
|
df2c3d6b609a
And the rest of the plugins that are compiling for me by default...
Gary Kramlich <grim@reaperworld.com>
parents:
16481
diff
changeset
|
143 | /* padding */ |
|
df2c3d6b609a
And the rest of the plugins that are compiling for me by default...
Gary Kramlich <grim@reaperworld.com>
parents:
16481
diff
changeset
|
144 | NULL, |
|
df2c3d6b609a
And the rest of the plugins that are compiling for me by default...
Gary Kramlich <grim@reaperworld.com>
parents:
16481
diff
changeset
|
145 | NULL, |
|
df2c3d6b609a
And the rest of the plugins that are compiling for me by default...
Gary Kramlich <grim@reaperworld.com>
parents:
16481
diff
changeset
|
146 | NULL, |
|
df2c3d6b609a
And the rest of the plugins that are compiling for me by default...
Gary Kramlich <grim@reaperworld.com>
parents:
16481
diff
changeset
|
147 | NULL |
| 9583 | 148 | }; |
| 149 | ||
| 15884 | 150 | static PurplePluginInfo info = |
| 5267 | 151 | { |
| 15884 | 152 | PURPLE_PLUGIN_MAGIC, |
| 153 | PURPLE_MAJOR_VERSION, | |
| 154 | PURPLE_MINOR_VERSION, | |
| 155 | PURPLE_PLUGIN_STANDARD, /**< type */ | |
| 5267 | 156 | NULL, /**< ui_requirement */ |
| 157 | 0, /**< flags */ | |
| 158 | NULL, /**< dependencies */ | |
| 15884 | 159 | PURPLE_PRIORITY_DEFAULT, /**< priority */ |
| 5267 | 160 | |
| 9583 | 161 | STATENOTIFY_PLUGIN_ID, /**< id */ |
| 5267 | 162 | N_("Buddy State Notification"), /**< name */ |
|
20288
5ca925a094e2
applied changes from 03b709ec2a153e7e82719df0ba4635108bb1d3c6
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
16745
diff
changeset
|
163 | DISPLAY_VERSION, /**< version */ |
| 5267 | 164 | /** summary */ |
| 165 | N_("Notifies in a conversation window when a buddy goes or returns from " | |
| 166 | "away or idle."), | |
| 167 | /** description */ | |
| 168 | N_("Notifies in a conversation window when a buddy goes or returns from " | |
| 169 | "away or idle."), | |
| 170 | "Christian Hammond <chipx86@gnupdate.org>", /**< author */ | |
| 15884 | 171 | PURPLE_WEBSITE, /**< homepage */ |
| 5267 | 172 | |
| 173 | plugin_load, /**< load */ | |
| 174 | NULL, /**< unload */ | |
| 175 | NULL, /**< destroy */ | |
| 176 | ||
| 177 | NULL, /**< ui_info */ | |
| 8993 | 178 | NULL, /**< extra_info */ |
| 9583 | 179 | &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:
16481
diff
changeset
|
180 | NULL, |
|
df2c3d6b609a
And the rest of the plugins that are compiling for me by default...
Gary Kramlich <grim@reaperworld.com>
parents:
16481
diff
changeset
|
181 | |
|
df2c3d6b609a
And the rest of the plugins that are compiling for me by default...
Gary Kramlich <grim@reaperworld.com>
parents:
16481
diff
changeset
|
182 | /* padding */ |
|
df2c3d6b609a
And the rest of the plugins that are compiling for me by default...
Gary Kramlich <grim@reaperworld.com>
parents:
16481
diff
changeset
|
183 | NULL, |
|
df2c3d6b609a
And the rest of the plugins that are compiling for me by default...
Gary Kramlich <grim@reaperworld.com>
parents:
16481
diff
changeset
|
184 | NULL, |
|
df2c3d6b609a
And the rest of the plugins that are compiling for me by default...
Gary Kramlich <grim@reaperworld.com>
parents:
16481
diff
changeset
|
185 | NULL, |
| 8993 | 186 | NULL |
| 5267 | 187 | }; |
| 188 | ||
| 189 | static void | |
| 15884 | 190 | init_plugin(PurplePlugin *plugin) |
| 5267 | 191 | { |
| 16481 | 192 | purple_prefs_add_none("/plugins/core/statenotify"); |
| 193 | purple_prefs_add_bool("/plugins/core/statenotify/notify_away", TRUE); | |
| 194 | purple_prefs_add_bool("/plugins/core/statenotify/notify_idle", TRUE); | |
| 195 | purple_prefs_add_bool("/plugins/core/statenotify/notify_signon", TRUE); | |
| 5267 | 196 | } |
| 197 | ||
| 15884 | 198 | PURPLE_INIT_PLUGIN(statenotify, init_plugin, info) |