Fri, 10 Mar 2017 20:36:55 -0600
Merge 2.12.0 into default
|
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 | |
|
34706
02cb08146888
Renamed blist.[ch] to buddylist.[ch]
Ankit Vani <a@nevitus.org>
parents:
34632
diff
changeset
|
3 | #include "buddylist.h" |
|
5872
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 | |
|
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
|
9 | #include "plugins.h" |
| 9583 | 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; |
|
34632
ebe6b2a60305
Changed all arguments and return types of Chat and IMs to PurpleChatConversation and PurpleIMConversation.
Ankit Vani <a@nevitus.org>
parents:
34628
diff
changeset
|
19 | PurpleIMConversation *im; |
|
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 | |
|
34632
ebe6b2a60305
Changed all arguments and return types of Chat and IMs to PurpleChatConversation and PurpleIMConversation.
Ankit Vani <a@nevitus.org>
parents:
34628
diff
changeset
|
28 | im = purple_conversations_find_im_with_account(buddy_name, account); |
| 5267 | 29 | |
|
34632
ebe6b2a60305
Changed all arguments and return types of Chat and IMs to PurpleChatConversation and PurpleIMConversation.
Ankit Vani <a@nevitus.org>
parents:
34628
diff
changeset
|
30 | if (im == NULL) |
| 5267 | 31 | return; |
| 32 | ||
| 24761 | 33 | /* Prevent duplicate notifications for buddies in multiple groups */ |
|
34728
8efd73063ecf
Renamed buddy list functions to more appropriate/simler names.
Ankit Vani <a@nevitus.org>
parents:
34706
diff
changeset
|
34 | if (buddy != purple_blist_find_buddy(account, buddy_name)) |
|
24759
9f88e2d42845
Prevent the Buddy State Notification plugin from printing duplicate
Florian Quèze <florian@instantbird.org>
parents:
24531
diff
changeset
|
35 | return; |
|
9f88e2d42845
Prevent the Buddy State Notification plugin from printing duplicate
Florian Quèze <florian@instantbird.org>
parents:
24531
diff
changeset
|
36 | |
| 15884 | 37 | who = purple_buddy_get_alias(buddy); |
|
10167
3f4db9c54e04
[gaim-migrate @ 11254]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9943
diff
changeset
|
38 | escaped = g_markup_escape_text(who, -1); |
| 5267 | 39 | |
|
10167
3f4db9c54e04
[gaim-migrate @ 11254]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9943
diff
changeset
|
40 | g_snprintf(buf, sizeof(buf), message, escaped); |
|
3f4db9c54e04
[gaim-migrate @ 11254]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9943
diff
changeset
|
41 | g_free(escaped); |
| 5267 | 42 | |
|
36084
2172bd6dad3e
Add purple_conversation_write_system_message
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35045
diff
changeset
|
43 | purple_conversation_write_system_message(PURPLE_CONVERSATION(im), buf, |
|
2172bd6dad3e
Add purple_conversation_write_system_message
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35045
diff
changeset
|
44 | PURPLE_MESSAGE_ACTIVE_ONLY | PURPLE_MESSAGE_NO_LINKIFY); |
| 5267 | 45 | } |
| 46 | ||
| 47 | static void | |
| 15884 | 48 | buddy_status_changed_cb(PurpleBuddy *buddy, PurpleStatus *old_status, |
| 49 | PurpleStatus *status, void *data) | |
| 5267 | 50 | { |
| 11935 | 51 | gboolean available, old_available; |
| 52 | ||
|
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
|
53 | 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
|
54 | !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
|
55 | 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
|
56 | |
| 15884 | 57 | available = purple_status_is_available(status); |
| 58 | old_available = purple_status_is_available(old_status); | |
| 11935 | 59 | |
| 16481 | 60 | if (purple_prefs_get_bool("/plugins/core/statenotify/notify_away")) { |
| 11935 | 61 | if (available && !old_available) |
| 62 | write_status(buddy, _("%s is no longer away.")); | |
| 63 | else if (!available && old_available) | |
| 64 | write_status(buddy, _("%s has gone away.")); | |
| 65 | } | |
| 5267 | 66 | } |
| 67 | ||
| 68 | static void | |
| 15884 | 69 | buddy_idle_changed_cb(PurpleBuddy *buddy, gboolean old_idle, gboolean idle, |
| 11935 | 70 | void *data) |
| 5267 | 71 | { |
| 16481 | 72 | if (purple_prefs_get_bool("/plugins/core/statenotify/notify_idle")) { |
|
25833
9cdd935e0aba
In the state notify plugin, don't print out a status change if we get an update
Marcus Lundblad <malu@pidgin.im>
parents:
24761
diff
changeset
|
73 | if (idle && !old_idle) { |
| 11935 | 74 | write_status(buddy, _("%s has become idle.")); |
|
25833
9cdd935e0aba
In the state notify plugin, don't print out a status change if we get an update
Marcus Lundblad <malu@pidgin.im>
parents:
24761
diff
changeset
|
75 | } else if (!idle && old_idle) { |
| 11935 | 76 | write_status(buddy, _("%s is no longer idle.")); |
| 77 | } | |
| 78 | } | |
| 9583 | 79 | } |
| 80 | ||
|
11901
34394921fe76
[gaim-migrate @ 14192]
Francesco Fracassi <ffracassi@users.sourceforge.net>
parents:
11338
diff
changeset
|
81 | static void |
| 15884 | 82 | buddy_signon_cb(PurpleBuddy *buddy, void *data) |
|
11901
34394921fe76
[gaim-migrate @ 14192]
Francesco Fracassi <ffracassi@users.sourceforge.net>
parents:
11338
diff
changeset
|
83 | { |
| 16481 | 84 | 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
|
85 | write_status(buddy, _("%s has signed on.")); |
|
34394921fe76
[gaim-migrate @ 14192]
Francesco Fracassi <ffracassi@users.sourceforge.net>
parents:
11338
diff
changeset
|
86 | } |
|
34394921fe76
[gaim-migrate @ 14192]
Francesco Fracassi <ffracassi@users.sourceforge.net>
parents:
11338
diff
changeset
|
87 | |
|
34394921fe76
[gaim-migrate @ 14192]
Francesco Fracassi <ffracassi@users.sourceforge.net>
parents:
11338
diff
changeset
|
88 | static void |
| 15884 | 89 | buddy_signoff_cb(PurpleBuddy *buddy, void *data) |
|
11901
34394921fe76
[gaim-migrate @ 14192]
Francesco Fracassi <ffracassi@users.sourceforge.net>
parents:
11338
diff
changeset
|
90 | { |
| 16481 | 91 | 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
|
92 | write_status(buddy, _("%s has signed off.")); |
|
34394921fe76
[gaim-migrate @ 14192]
Francesco Fracassi <ffracassi@users.sourceforge.net>
parents:
11338
diff
changeset
|
93 | } |
|
34394921fe76
[gaim-migrate @ 14192]
Francesco Fracassi <ffracassi@users.sourceforge.net>
parents:
11338
diff
changeset
|
94 | |
| 15884 | 95 | static PurplePluginPrefFrame * |
| 96 | get_plugin_pref_frame(PurplePlugin *plugin) | |
| 9583 | 97 | { |
| 15884 | 98 | PurplePluginPrefFrame *frame; |
| 99 | PurplePluginPref *ppref; | |
| 9583 | 100 | |
| 15884 | 101 | frame = purple_plugin_pref_frame_new(); |
| 9583 | 102 | |
| 15884 | 103 | ppref = purple_plugin_pref_new_with_label(_("Notify When")); |
| 104 | purple_plugin_pref_frame_add(frame, ppref); | |
| 9583 | 105 | |
| 16481 | 106 | ppref = purple_plugin_pref_new_with_name_and_label("/plugins/core/statenotify/notify_away", _("Buddy Goes _Away")); |
| 15884 | 107 | purple_plugin_pref_frame_add(frame, ppref); |
|
10246
aa5bff72f94c
[gaim-migrate @ 11386]
Mark Doliner <markdoliner@pidgin.im>
parents:
10167
diff
changeset
|
108 | |
| 16481 | 109 | ppref = purple_plugin_pref_new_with_name_and_label("/plugins/core/statenotify/notify_idle", _("Buddy Goes _Idle")); |
| 15884 | 110 | purple_plugin_pref_frame_add(frame, ppref); |
|
10246
aa5bff72f94c
[gaim-migrate @ 11386]
Mark Doliner <markdoliner@pidgin.im>
parents:
10167
diff
changeset
|
111 | |
| 16481 | 112 | ppref = purple_plugin_pref_new_with_name_and_label("/plugins/core/statenotify/notify_signon", _("Buddy _Signs On/Off")); |
| 15884 | 113 | purple_plugin_pref_frame_add(frame, ppref); |
|
11901
34394921fe76
[gaim-migrate @ 14192]
Francesco Fracassi <ffracassi@users.sourceforge.net>
parents:
11338
diff
changeset
|
114 | |
| 9583 | 115 | return frame; |
| 5267 | 116 | } |
| 117 | ||
|
36747
0b84912ce764
Refactored rest of libpurple C plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
36367
diff
changeset
|
118 | static PurplePluginInfo * |
|
0b84912ce764
Refactored rest of libpurple C plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
36367
diff
changeset
|
119 | plugin_query(GError **error) |
|
0b84912ce764
Refactored rest of libpurple C plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
36367
diff
changeset
|
120 | { |
|
0b84912ce764
Refactored rest of libpurple C plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
36367
diff
changeset
|
121 | const gchar * const authors[] = { |
|
0b84912ce764
Refactored rest of libpurple C plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
36367
diff
changeset
|
122 | "Christian Hammond <chipx86@gnupdate.org>", |
|
0b84912ce764
Refactored rest of libpurple C plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
36367
diff
changeset
|
123 | NULL |
|
0b84912ce764
Refactored rest of libpurple C plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
36367
diff
changeset
|
124 | }; |
|
0b84912ce764
Refactored rest of libpurple C plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
36367
diff
changeset
|
125 | |
|
0b84912ce764
Refactored rest of libpurple C plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
36367
diff
changeset
|
126 | return purple_plugin_info_new( |
|
36934
e7268aeb3b89
Renamed plugin info callback properties to end with "-cb", and their respective symbols.
Ankit Vani <a@nevitus.org>
parents:
36929
diff
changeset
|
127 | "id", STATENOTIFY_PLUGIN_ID, |
|
e7268aeb3b89
Renamed plugin info callback properties to end with "-cb", and their respective symbols.
Ankit Vani <a@nevitus.org>
parents:
36929
diff
changeset
|
128 | "name", N_("Buddy State Notification"), |
|
e7268aeb3b89
Renamed plugin info callback properties to end with "-cb", and their respective symbols.
Ankit Vani <a@nevitus.org>
parents:
36929
diff
changeset
|
129 | "version", DISPLAY_VERSION, |
|
e7268aeb3b89
Renamed plugin info callback properties to end with "-cb", and their respective symbols.
Ankit Vani <a@nevitus.org>
parents:
36929
diff
changeset
|
130 | "category", N_("Notification"), |
|
e7268aeb3b89
Renamed plugin info callback properties to end with "-cb", and their respective symbols.
Ankit Vani <a@nevitus.org>
parents:
36929
diff
changeset
|
131 | "summary", N_("Notifies in a conversation window when a " |
|
e7268aeb3b89
Renamed plugin info callback properties to end with "-cb", and their respective symbols.
Ankit Vani <a@nevitus.org>
parents:
36929
diff
changeset
|
132 | "buddy goes or returns from away or idle."), |
|
e7268aeb3b89
Renamed plugin info callback properties to end with "-cb", and their respective symbols.
Ankit Vani <a@nevitus.org>
parents:
36929
diff
changeset
|
133 | "description", N_("Notifies in a conversation window when a " |
|
e7268aeb3b89
Renamed plugin info callback properties to end with "-cb", and their respective symbols.
Ankit Vani <a@nevitus.org>
parents:
36929
diff
changeset
|
134 | "buddy goes or returns from away or idle."), |
|
e7268aeb3b89
Renamed plugin info callback properties to end with "-cb", and their respective symbols.
Ankit Vani <a@nevitus.org>
parents:
36929
diff
changeset
|
135 | "authors", authors, |
|
e7268aeb3b89
Renamed plugin info callback properties to end with "-cb", and their respective symbols.
Ankit Vani <a@nevitus.org>
parents:
36929
diff
changeset
|
136 | "website", PURPLE_WEBSITE, |
|
e7268aeb3b89
Renamed plugin info callback properties to end with "-cb", and their respective symbols.
Ankit Vani <a@nevitus.org>
parents:
36929
diff
changeset
|
137 | "abi-version", PURPLE_ABI_VERSION, |
|
e7268aeb3b89
Renamed plugin info callback properties to end with "-cb", and their respective symbols.
Ankit Vani <a@nevitus.org>
parents:
36929
diff
changeset
|
138 | "pref-frame-cb", get_plugin_pref_frame, |
|
36747
0b84912ce764
Refactored rest of libpurple C plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
36367
diff
changeset
|
139 | NULL |
|
0b84912ce764
Refactored rest of libpurple C plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
36367
diff
changeset
|
140 | ); |
|
0b84912ce764
Refactored rest of libpurple C plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
36367
diff
changeset
|
141 | } |
|
0b84912ce764
Refactored rest of libpurple C plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
36367
diff
changeset
|
142 | |
| 5267 | 143 | static gboolean |
|
36747
0b84912ce764
Refactored rest of libpurple C plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
36367
diff
changeset
|
144 | plugin_load(PurplePlugin *plugin, GError **error) |
| 5267 | 145 | { |
| 15884 | 146 | void *blist_handle = purple_blist_get_handle(); |
|
6485
3c7ba18e32f1
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6441
diff
changeset
|
147 | |
|
36747
0b84912ce764
Refactored rest of libpurple C plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
36367
diff
changeset
|
148 | purple_prefs_add_none("/plugins/core/statenotify"); |
|
0b84912ce764
Refactored rest of libpurple C plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
36367
diff
changeset
|
149 | purple_prefs_add_bool("/plugins/core/statenotify/notify_away", TRUE); |
|
0b84912ce764
Refactored rest of libpurple C plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
36367
diff
changeset
|
150 | purple_prefs_add_bool("/plugins/core/statenotify/notify_idle", TRUE); |
|
0b84912ce764
Refactored rest of libpurple C plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
36367
diff
changeset
|
151 | purple_prefs_add_bool("/plugins/core/statenotify/notify_signon", TRUE); |
|
0b84912ce764
Refactored rest of libpurple C plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
36367
diff
changeset
|
152 | |
| 15884 | 153 | purple_signal_connect(blist_handle, "buddy-status-changed", plugin, |
| 154 | PURPLE_CALLBACK(buddy_status_changed_cb), NULL); | |
| 155 | purple_signal_connect(blist_handle, "buddy-idle-changed", plugin, | |
| 156 | PURPLE_CALLBACK(buddy_idle_changed_cb), NULL); | |
| 157 | purple_signal_connect(blist_handle, "buddy-signed-on", plugin, | |
| 158 | PURPLE_CALLBACK(buddy_signon_cb), NULL); | |
| 159 | purple_signal_connect(blist_handle, "buddy-signed-off", plugin, | |
| 160 | PURPLE_CALLBACK(buddy_signoff_cb), NULL); | |
| 5267 | 161 | |
| 162 | return TRUE; | |
| 163 | } | |
| 164 | ||
|
36747
0b84912ce764
Refactored rest of libpurple C plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
36367
diff
changeset
|
165 | static gboolean |
|
0b84912ce764
Refactored rest of libpurple C plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
36367
diff
changeset
|
166 | plugin_unload(PurplePlugin *plugin, GError **error) |
| 5267 | 167 | { |
|
36747
0b84912ce764
Refactored rest of libpurple C plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
36367
diff
changeset
|
168 | return TRUE; |
| 5267 | 169 | } |
| 170 | ||
|
36747
0b84912ce764
Refactored rest of libpurple C plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
36367
diff
changeset
|
171 | PURPLE_PLUGIN_INIT(statenotify, plugin_query, plugin_load, plugin_unload); |