Sat, 22 Jun 2013 22:47:05 +0530
Added purple_conversation_* functions to API to redirect to virtual methods
|
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; | |
|
32617
c74b4bd27e37
Use purple_conversation accessor methods.
Andrew Victor <andrew.victor@mxit.com>
parents:
26045
diff
changeset
|
33 | g_return_if_fail(purple_conversation_get_type(conv) == PURPLE_CONV_TYPE_IM); |
| 5267 | 34 | |
| 24761 | 35 | /* Prevent duplicate notifications for buddies in multiple groups */ |
|
25870
ccb76c75d39f
a few struct hiding clean ups
Gary Kramlich <grim@reaperworld.com>
parents:
24761
diff
changeset
|
36 | if (buddy != purple_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
|
37 | return; |
|
9f88e2d42845
Prevent the Buddy State Notification plugin from printing duplicate
Florian Quèze <florian@instantbird.org>
parents:
24531
diff
changeset
|
38 | |
| 15884 | 39 | who = purple_buddy_get_alias(buddy); |
|
10167
3f4db9c54e04
[gaim-migrate @ 11254]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9943
diff
changeset
|
40 | escaped = g_markup_escape_text(who, -1); |
| 5267 | 41 | |
|
10167
3f4db9c54e04
[gaim-migrate @ 11254]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9943
diff
changeset
|
42 | g_snprintf(buf, sizeof(buf), message, escaped); |
|
3f4db9c54e04
[gaim-migrate @ 11254]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9943
diff
changeset
|
43 | g_free(escaped); |
| 5267 | 44 | |
|
32619
1dc7c15bc3ef
More code changed to use the accessor functions.
Andrew Victor <andrew.victor@mxit.com>
parents:
32617
diff
changeset
|
45 | purple_conv_im_write(PURPLE_CONV_IM(conv), NULL, buf, PURPLE_MESSAGE_SYSTEM | PURPLE_MESSAGE_ACTIVE_ONLY | PURPLE_MESSAGE_NO_LINKIFY, time(NULL)); |
| 5267 | 46 | } |
| 47 | ||
| 48 | static void | |
| 15884 | 49 | buddy_status_changed_cb(PurpleBuddy *buddy, PurpleStatus *old_status, |
| 50 | PurpleStatus *status, void *data) | |
| 5267 | 51 | { |
| 11935 | 52 | gboolean available, old_available; |
| 53 | ||
|
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
|
54 | 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
|
55 | !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
|
56 | 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
|
57 | |
| 15884 | 58 | available = purple_status_is_available(status); |
| 59 | old_available = purple_status_is_available(old_status); | |
| 11935 | 60 | |
| 16481 | 61 | if (purple_prefs_get_bool("/plugins/core/statenotify/notify_away")) { |
| 11935 | 62 | if (available && !old_available) |
| 63 | write_status(buddy, _("%s is no longer away.")); | |
| 64 | else if (!available && old_available) | |
| 65 | write_status(buddy, _("%s has gone away.")); | |
| 66 | } | |
| 5267 | 67 | } |
| 68 | ||
| 69 | static void | |
| 15884 | 70 | buddy_idle_changed_cb(PurpleBuddy *buddy, gboolean old_idle, gboolean idle, |
| 11935 | 71 | void *data) |
| 5267 | 72 | { |
| 16481 | 73 | 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
|
74 | if (idle && !old_idle) { |
| 11935 | 75 | 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
|
76 | } else if (!idle && old_idle) { |
| 11935 | 77 | write_status(buddy, _("%s is no longer idle.")); |
| 78 | } | |
| 79 | } | |
| 9583 | 80 | } |
| 81 | ||
|
11901
34394921fe76
[gaim-migrate @ 14192]
Francesco Fracassi <ffracassi@users.sourceforge.net>
parents:
11338
diff
changeset
|
82 | static void |
| 15884 | 83 | buddy_signon_cb(PurpleBuddy *buddy, void *data) |
|
11901
34394921fe76
[gaim-migrate @ 14192]
Francesco Fracassi <ffracassi@users.sourceforge.net>
parents:
11338
diff
changeset
|
84 | { |
| 16481 | 85 | 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
|
86 | write_status(buddy, _("%s has signed on.")); |
|
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 | |
|
34394921fe76
[gaim-migrate @ 14192]
Francesco Fracassi <ffracassi@users.sourceforge.net>
parents:
11338
diff
changeset
|
89 | static void |
| 15884 | 90 | buddy_signoff_cb(PurpleBuddy *buddy, void *data) |
|
11901
34394921fe76
[gaim-migrate @ 14192]
Francesco Fracassi <ffracassi@users.sourceforge.net>
parents:
11338
diff
changeset
|
91 | { |
| 16481 | 92 | 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
|
93 | write_status(buddy, _("%s has signed off.")); |
|
34394921fe76
[gaim-migrate @ 14192]
Francesco Fracassi <ffracassi@users.sourceforge.net>
parents:
11338
diff
changeset
|
94 | } |
|
34394921fe76
[gaim-migrate @ 14192]
Francesco Fracassi <ffracassi@users.sourceforge.net>
parents:
11338
diff
changeset
|
95 | |
| 15884 | 96 | static PurplePluginPrefFrame * |
| 97 | get_plugin_pref_frame(PurplePlugin *plugin) | |
| 9583 | 98 | { |
| 15884 | 99 | PurplePluginPrefFrame *frame; |
| 100 | PurplePluginPref *ppref; | |
| 9583 | 101 | |
| 15884 | 102 | frame = purple_plugin_pref_frame_new(); |
| 9583 | 103 | |
| 15884 | 104 | ppref = purple_plugin_pref_new_with_label(_("Notify When")); |
| 105 | purple_plugin_pref_frame_add(frame, ppref); | |
| 9583 | 106 | |
| 16481 | 107 | ppref = purple_plugin_pref_new_with_name_and_label("/plugins/core/statenotify/notify_away", _("Buddy Goes _Away")); |
| 15884 | 108 | purple_plugin_pref_frame_add(frame, ppref); |
|
10246
aa5bff72f94c
[gaim-migrate @ 11386]
Mark Doliner <markdoliner@pidgin.im>
parents:
10167
diff
changeset
|
109 | |
| 16481 | 110 | ppref = purple_plugin_pref_new_with_name_and_label("/plugins/core/statenotify/notify_idle", _("Buddy Goes _Idle")); |
| 15884 | 111 | purple_plugin_pref_frame_add(frame, ppref); |
|
10246
aa5bff72f94c
[gaim-migrate @ 11386]
Mark Doliner <markdoliner@pidgin.im>
parents:
10167
diff
changeset
|
112 | |
| 16481 | 113 | ppref = purple_plugin_pref_new_with_name_and_label("/plugins/core/statenotify/notify_signon", _("Buddy _Signs On/Off")); |
| 15884 | 114 | purple_plugin_pref_frame_add(frame, ppref); |
|
11901
34394921fe76
[gaim-migrate @ 14192]
Francesco Fracassi <ffracassi@users.sourceforge.net>
parents:
11338
diff
changeset
|
115 | |
| 9583 | 116 | return frame; |
| 5267 | 117 | } |
| 118 | ||
| 119 | static gboolean | |
| 15884 | 120 | plugin_load(PurplePlugin *plugin) |
| 5267 | 121 | { |
| 15884 | 122 | void *blist_handle = purple_blist_get_handle(); |
|
6485
3c7ba18e32f1
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6441
diff
changeset
|
123 | |
| 15884 | 124 | purple_signal_connect(blist_handle, "buddy-status-changed", plugin, |
| 125 | PURPLE_CALLBACK(buddy_status_changed_cb), NULL); | |
| 126 | purple_signal_connect(blist_handle, "buddy-idle-changed", plugin, | |
| 127 | PURPLE_CALLBACK(buddy_idle_changed_cb), NULL); | |
| 128 | purple_signal_connect(blist_handle, "buddy-signed-on", plugin, | |
| 129 | PURPLE_CALLBACK(buddy_signon_cb), NULL); | |
| 130 | purple_signal_connect(blist_handle, "buddy-signed-off", plugin, | |
| 131 | PURPLE_CALLBACK(buddy_signoff_cb), NULL); | |
| 5267 | 132 | |
| 133 | return TRUE; | |
| 134 | } | |
| 135 | ||
| 15884 | 136 | static PurplePluginUiInfo prefs_info = |
| 9583 | 137 | { |
|
12600
7ecd4441fdc7
[gaim-migrate @ 14934]
Richard Laager <rlaager@pidgin.im>
parents:
11935
diff
changeset
|
138 | get_plugin_pref_frame, |
|
7ecd4441fdc7
[gaim-migrate @ 14934]
Richard Laager <rlaager@pidgin.im>
parents:
11935
diff
changeset
|
139 | 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
|
140 | 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
|
141 | |
|
df2c3d6b609a
And the rest of the plugins that are compiling for me by default...
Gary Kramlich <grim@reaperworld.com>
parents:
16481
diff
changeset
|
142 | /* padding */ |
|
df2c3d6b609a
And the rest of the plugins that are compiling for me by default...
Gary Kramlich <grim@reaperworld.com>
parents:
16481
diff
changeset
|
143 | NULL, |
|
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 |
| 9583 | 147 | }; |
| 148 | ||
| 15884 | 149 | static PurplePluginInfo info = |
| 5267 | 150 | { |
| 15884 | 151 | PURPLE_PLUGIN_MAGIC, |
| 152 | PURPLE_MAJOR_VERSION, | |
| 153 | PURPLE_MINOR_VERSION, | |
| 154 | PURPLE_PLUGIN_STANDARD, /**< type */ | |
| 5267 | 155 | NULL, /**< ui_requirement */ |
| 156 | 0, /**< flags */ | |
| 157 | NULL, /**< dependencies */ | |
| 15884 | 158 | PURPLE_PRIORITY_DEFAULT, /**< priority */ |
| 5267 | 159 | |
| 9583 | 160 | STATENOTIFY_PLUGIN_ID, /**< id */ |
| 5267 | 161 | N_("Buddy State Notification"), /**< name */ |
|
20288
5ca925a094e2
applied changes from 03b709ec2a153e7e82719df0ba4635108bb1d3c6
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
16745
diff
changeset
|
162 | DISPLAY_VERSION, /**< version */ |
| 5267 | 163 | /** summary */ |
| 164 | N_("Notifies in a conversation window when a buddy goes or returns from " | |
| 165 | "away or idle."), | |
| 166 | /** description */ | |
| 167 | N_("Notifies in a conversation window when a buddy goes or returns from " | |
| 168 | "away or idle."), | |
| 169 | "Christian Hammond <chipx86@gnupdate.org>", /**< author */ | |
| 15884 | 170 | PURPLE_WEBSITE, /**< homepage */ |
| 5267 | 171 | |
| 172 | plugin_load, /**< load */ | |
| 173 | NULL, /**< unload */ | |
| 174 | NULL, /**< destroy */ | |
| 175 | ||
| 176 | NULL, /**< ui_info */ | |
| 8993 | 177 | NULL, /**< extra_info */ |
| 9583 | 178 | &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
|
179 | NULL, |
|
df2c3d6b609a
And the rest of the plugins that are compiling for me by default...
Gary Kramlich <grim@reaperworld.com>
parents:
16481
diff
changeset
|
180 | |
|
df2c3d6b609a
And the rest of the plugins that are compiling for me by default...
Gary Kramlich <grim@reaperworld.com>
parents:
16481
diff
changeset
|
181 | /* padding */ |
|
df2c3d6b609a
And the rest of the plugins that are compiling for me by default...
Gary Kramlich <grim@reaperworld.com>
parents:
16481
diff
changeset
|
182 | NULL, |
|
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, |
| 8993 | 185 | NULL |
| 5267 | 186 | }; |
| 187 | ||
| 188 | static void | |
| 15884 | 189 | init_plugin(PurplePlugin *plugin) |
| 5267 | 190 | { |
| 16481 | 191 | purple_prefs_add_none("/plugins/core/statenotify"); |
| 192 | purple_prefs_add_bool("/plugins/core/statenotify/notify_away", TRUE); | |
| 193 | purple_prefs_add_bool("/plugins/core/statenotify/notify_idle", TRUE); | |
| 194 | purple_prefs_add_bool("/plugins/core/statenotify/notify_signon", TRUE); | |
| 5267 | 195 | } |
| 196 | ||
| 15884 | 197 | PURPLE_INIT_PLUGIN(statenotify, init_plugin, info) |