Wed, 30 Jul 2008 03:58:21 +0000
Cleanup unnecessary casts and etc.
|
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 | { |
| 15884 | 18 | PurpleConversation *conv; |
|
6485
3c7ba18e32f1
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6441
diff
changeset
|
19 | const char *who; |
| 5267 | 20 | char buf[256]; |
|
10167
3f4db9c54e04
[gaim-migrate @ 11254]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9943
diff
changeset
|
21 | char *escaped; |
| 5267 | 22 | |
| 15884 | 23 | conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, |
|
10246
aa5bff72f94c
[gaim-migrate @ 11386]
Mark Doliner <markdoliner@pidgin.im>
parents:
10167
diff
changeset
|
24 | buddy->name, buddy->account); |
| 5267 | 25 | |
| 26 | if (conv == NULL) | |
| 27 | return; | |
| 15884 | 28 | g_return_if_fail(conv->type == PURPLE_CONV_TYPE_IM); |
| 5267 | 29 | |
| 15884 | 30 | who = purple_buddy_get_alias(buddy); |
|
10167
3f4db9c54e04
[gaim-migrate @ 11254]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9943
diff
changeset
|
31 | escaped = g_markup_escape_text(who, -1); |
| 5267 | 32 | |
|
10167
3f4db9c54e04
[gaim-migrate @ 11254]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9943
diff
changeset
|
33 | g_snprintf(buf, sizeof(buf), message, escaped); |
|
3f4db9c54e04
[gaim-migrate @ 11254]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9943
diff
changeset
|
34 | g_free(escaped); |
| 5267 | 35 | |
| 15884 | 36 | purple_conv_im_write(conv->u.im, NULL, buf, PURPLE_MESSAGE_SYSTEM | PURPLE_MESSAGE_ACTIVE_ONLY, time(NULL)); |
| 5267 | 37 | } |
| 38 | ||
| 39 | static void | |
| 15884 | 40 | buddy_status_changed_cb(PurpleBuddy *buddy, PurpleStatus *old_status, |
| 41 | PurpleStatus *status, void *data) | |
| 5267 | 42 | { |
| 11935 | 43 | gboolean available, old_available; |
| 44 | ||
|
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
|
45 | 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
|
46 | !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
|
47 | 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
|
48 | |
| 15884 | 49 | available = purple_status_is_available(status); |
| 50 | old_available = purple_status_is_available(old_status); | |
| 11935 | 51 | |
| 16481 | 52 | if (purple_prefs_get_bool("/plugins/core/statenotify/notify_away")) { |
| 11935 | 53 | if (available && !old_available) |
| 54 | write_status(buddy, _("%s is no longer away.")); | |
| 55 | else if (!available && old_available) | |
| 56 | write_status(buddy, _("%s has gone away.")); | |
| 57 | } | |
| 5267 | 58 | } |
| 59 | ||
| 60 | static void | |
| 15884 | 61 | buddy_idle_changed_cb(PurpleBuddy *buddy, gboolean old_idle, gboolean idle, |
| 11935 | 62 | void *data) |
| 5267 | 63 | { |
| 16481 | 64 | if (purple_prefs_get_bool("/plugins/core/statenotify/notify_idle")) { |
| 11935 | 65 | if (idle) { |
| 66 | write_status(buddy, _("%s has become idle.")); | |
| 67 | } else { | |
| 68 | write_status(buddy, _("%s is no longer idle.")); | |
| 69 | } | |
| 70 | } | |
| 9583 | 71 | } |
| 72 | ||
|
11901
34394921fe76
[gaim-migrate @ 14192]
Francesco Fracassi <ffracassi@users.sourceforge.net>
parents:
11338
diff
changeset
|
73 | static void |
| 15884 | 74 | buddy_signon_cb(PurpleBuddy *buddy, void *data) |
|
11901
34394921fe76
[gaim-migrate @ 14192]
Francesco Fracassi <ffracassi@users.sourceforge.net>
parents:
11338
diff
changeset
|
75 | { |
| 16481 | 76 | 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
|
77 | write_status(buddy, _("%s has signed on.")); |
|
34394921fe76
[gaim-migrate @ 14192]
Francesco Fracassi <ffracassi@users.sourceforge.net>
parents:
11338
diff
changeset
|
78 | } |
|
34394921fe76
[gaim-migrate @ 14192]
Francesco Fracassi <ffracassi@users.sourceforge.net>
parents:
11338
diff
changeset
|
79 | |
|
34394921fe76
[gaim-migrate @ 14192]
Francesco Fracassi <ffracassi@users.sourceforge.net>
parents:
11338
diff
changeset
|
80 | static void |
| 15884 | 81 | buddy_signoff_cb(PurpleBuddy *buddy, void *data) |
|
11901
34394921fe76
[gaim-migrate @ 14192]
Francesco Fracassi <ffracassi@users.sourceforge.net>
parents:
11338
diff
changeset
|
82 | { |
| 16481 | 83 | 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
|
84 | write_status(buddy, _("%s has signed off.")); |
|
34394921fe76
[gaim-migrate @ 14192]
Francesco Fracassi <ffracassi@users.sourceforge.net>
parents:
11338
diff
changeset
|
85 | } |
|
34394921fe76
[gaim-migrate @ 14192]
Francesco Fracassi <ffracassi@users.sourceforge.net>
parents:
11338
diff
changeset
|
86 | |
| 15884 | 87 | static PurplePluginPrefFrame * |
| 88 | get_plugin_pref_frame(PurplePlugin *plugin) | |
| 9583 | 89 | { |
| 15884 | 90 | PurplePluginPrefFrame *frame; |
| 91 | PurplePluginPref *ppref; | |
| 9583 | 92 | |
| 15884 | 93 | frame = purple_plugin_pref_frame_new(); |
| 9583 | 94 | |
| 15884 | 95 | ppref = purple_plugin_pref_new_with_label(_("Notify When")); |
| 96 | purple_plugin_pref_frame_add(frame, ppref); | |
| 9583 | 97 | |
| 16481 | 98 | ppref = purple_plugin_pref_new_with_name_and_label("/plugins/core/statenotify/notify_away", _("Buddy Goes _Away")); |
| 15884 | 99 | purple_plugin_pref_frame_add(frame, ppref); |
|
10246
aa5bff72f94c
[gaim-migrate @ 11386]
Mark Doliner <markdoliner@pidgin.im>
parents:
10167
diff
changeset
|
100 | |
| 16481 | 101 | ppref = purple_plugin_pref_new_with_name_and_label("/plugins/core/statenotify/notify_idle", _("Buddy Goes _Idle")); |
| 15884 | 102 | purple_plugin_pref_frame_add(frame, ppref); |
|
10246
aa5bff72f94c
[gaim-migrate @ 11386]
Mark Doliner <markdoliner@pidgin.im>
parents:
10167
diff
changeset
|
103 | |
| 16481 | 104 | ppref = purple_plugin_pref_new_with_name_and_label("/plugins/core/statenotify/notify_signon", _("Buddy _Signs On/Off")); |
| 15884 | 105 | purple_plugin_pref_frame_add(frame, ppref); |
|
11901
34394921fe76
[gaim-migrate @ 14192]
Francesco Fracassi <ffracassi@users.sourceforge.net>
parents:
11338
diff
changeset
|
106 | |
| 9583 | 107 | return frame; |
| 5267 | 108 | } |
| 109 | ||
| 110 | static gboolean | |
| 15884 | 111 | plugin_load(PurplePlugin *plugin) |
| 5267 | 112 | { |
| 15884 | 113 | void *blist_handle = purple_blist_get_handle(); |
|
6485
3c7ba18e32f1
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6441
diff
changeset
|
114 | |
| 15884 | 115 | purple_signal_connect(blist_handle, "buddy-status-changed", plugin, |
| 116 | PURPLE_CALLBACK(buddy_status_changed_cb), NULL); | |
| 117 | purple_signal_connect(blist_handle, "buddy-idle-changed", plugin, | |
| 118 | PURPLE_CALLBACK(buddy_idle_changed_cb), NULL); | |
| 119 | purple_signal_connect(blist_handle, "buddy-signed-on", plugin, | |
| 120 | PURPLE_CALLBACK(buddy_signon_cb), NULL); | |
| 121 | purple_signal_connect(blist_handle, "buddy-signed-off", plugin, | |
| 122 | PURPLE_CALLBACK(buddy_signoff_cb), NULL); | |
| 5267 | 123 | |
| 124 | return TRUE; | |
| 125 | } | |
| 126 | ||
| 15884 | 127 | static PurplePluginUiInfo prefs_info = |
| 9583 | 128 | { |
|
12600
7ecd4441fdc7
[gaim-migrate @ 14934]
Richard Laager <rlaager@pidgin.im>
parents:
11935
diff
changeset
|
129 | get_plugin_pref_frame, |
|
7ecd4441fdc7
[gaim-migrate @ 14934]
Richard Laager <rlaager@pidgin.im>
parents:
11935
diff
changeset
|
130 | 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
|
131 | 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
|
132 | |
|
df2c3d6b609a
And the rest of the plugins that are compiling for me by default...
Gary Kramlich <grim@reaperworld.com>
parents:
16481
diff
changeset
|
133 | /* padding */ |
|
df2c3d6b609a
And the rest of the plugins that are compiling for me by default...
Gary Kramlich <grim@reaperworld.com>
parents:
16481
diff
changeset
|
134 | NULL, |
|
df2c3d6b609a
And the rest of the plugins that are compiling for me by default...
Gary Kramlich <grim@reaperworld.com>
parents:
16481
diff
changeset
|
135 | NULL, |
|
df2c3d6b609a
And the rest of the plugins that are compiling for me by default...
Gary Kramlich <grim@reaperworld.com>
parents:
16481
diff
changeset
|
136 | NULL, |
|
df2c3d6b609a
And the rest of the plugins that are compiling for me by default...
Gary Kramlich <grim@reaperworld.com>
parents:
16481
diff
changeset
|
137 | NULL |
| 9583 | 138 | }; |
| 139 | ||
| 15884 | 140 | static PurplePluginInfo info = |
| 5267 | 141 | { |
| 15884 | 142 | PURPLE_PLUGIN_MAGIC, |
| 143 | PURPLE_MAJOR_VERSION, | |
| 144 | PURPLE_MINOR_VERSION, | |
| 145 | PURPLE_PLUGIN_STANDARD, /**< type */ | |
| 5267 | 146 | NULL, /**< ui_requirement */ |
| 147 | 0, /**< flags */ | |
| 148 | NULL, /**< dependencies */ | |
| 15884 | 149 | PURPLE_PRIORITY_DEFAULT, /**< priority */ |
| 5267 | 150 | |
| 9583 | 151 | STATENOTIFY_PLUGIN_ID, /**< id */ |
| 5267 | 152 | N_("Buddy State Notification"), /**< name */ |
|
20288
5ca925a094e2
applied changes from 03b709ec2a153e7e82719df0ba4635108bb1d3c6
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
16745
diff
changeset
|
153 | DISPLAY_VERSION, /**< version */ |
| 5267 | 154 | /** summary */ |
| 155 | N_("Notifies in a conversation window when a buddy goes or returns from " | |
| 156 | "away or idle."), | |
| 157 | /** description */ | |
| 158 | N_("Notifies in a conversation window when a buddy goes or returns from " | |
| 159 | "away or idle."), | |
| 160 | "Christian Hammond <chipx86@gnupdate.org>", /**< author */ | |
| 15884 | 161 | PURPLE_WEBSITE, /**< homepage */ |
| 5267 | 162 | |
| 163 | plugin_load, /**< load */ | |
| 164 | NULL, /**< unload */ | |
| 165 | NULL, /**< destroy */ | |
| 166 | ||
| 167 | NULL, /**< ui_info */ | |
| 8993 | 168 | NULL, /**< extra_info */ |
| 9583 | 169 | &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
|
170 | NULL, |
|
df2c3d6b609a
And the rest of the plugins that are compiling for me by default...
Gary Kramlich <grim@reaperworld.com>
parents:
16481
diff
changeset
|
171 | |
|
df2c3d6b609a
And the rest of the plugins that are compiling for me by default...
Gary Kramlich <grim@reaperworld.com>
parents:
16481
diff
changeset
|
172 | /* padding */ |
|
df2c3d6b609a
And the rest of the plugins that are compiling for me by default...
Gary Kramlich <grim@reaperworld.com>
parents:
16481
diff
changeset
|
173 | NULL, |
|
df2c3d6b609a
And the rest of the plugins that are compiling for me by default...
Gary Kramlich <grim@reaperworld.com>
parents:
16481
diff
changeset
|
174 | NULL, |
|
df2c3d6b609a
And the rest of the plugins that are compiling for me by default...
Gary Kramlich <grim@reaperworld.com>
parents:
16481
diff
changeset
|
175 | NULL, |
| 8993 | 176 | NULL |
| 5267 | 177 | }; |
| 178 | ||
| 179 | static void | |
| 15884 | 180 | init_plugin(PurplePlugin *plugin) |
| 5267 | 181 | { |
| 16481 | 182 | purple_prefs_add_none("/plugins/core/statenotify"); |
| 183 | purple_prefs_add_bool("/plugins/core/statenotify/notify_away", TRUE); | |
| 184 | purple_prefs_add_bool("/plugins/core/statenotify/notify_idle", TRUE); | |
| 185 | purple_prefs_add_bool("/plugins/core/statenotify/notify_signon", TRUE); | |
| 5267 | 186 | } |
| 187 | ||
| 15884 | 188 | PURPLE_INIT_PLUGIN(statenotify, init_plugin, info) |