Mercurial > pidgin
annotate plugins/statenotify.c @ 11901:077f956e41a1
[gaim-migrate @ 14192]
Patch 1342474 from Francesco Fracassi - add buddy signon & signoff to the
buddy state notification plugin
committer: Tailor Script <tailor@pidgin.im>
author | Stu Tomlinson <stu@nosnilmot.com> |
---|---|
date | Sun, 30 Oct 2005 17:18:20 +0000 |
parents | 17142948653e |
children | cb73483c9f63 |
rev | line source |
---|---|
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5676
diff
changeset
|
1 #include "internal.h" |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5676
diff
changeset
|
2 |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5676
diff
changeset
|
3 #include "blist.h" |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5676
diff
changeset
|
4 #include "conversation.h" |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5676
diff
changeset
|
5 #include "debug.h" |
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6441
diff
changeset
|
6 #include "signals.h" |
9943 | 7 #include "version.h" |
5872
059d95c67cda
[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 |
6695 | 16 write_status(GaimBuddy *buddy, const char *message) |
5267 | 17 { |
5676
dae79aefac8d
[gaim-migrate @ 6094]
Christian Hammond <chipx86@chipx86.com>
parents:
5587
diff
changeset
|
18 GaimConversation *conv; |
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6441
diff
changeset
|
19 const char *who; |
5267 | 20 char buf[256]; |
10167 | 21 char *escaped; |
5267 | 22 |
11338 | 23 conv = gaim_find_conversation_with_account(GAIM_CONV_TYPE_IM, |
10246 | 24 buddy->name, buddy->account); |
5267 | 25 |
26 if (conv == NULL) | |
27 return; | |
28 | |
9620 | 29 who = gaim_buddy_get_alias(buddy); |
10167 | 30 escaped = g_markup_escape_text(who, -1); |
5267 | 31 |
10167 | 32 g_snprintf(buf, sizeof(buf), message, escaped); |
33 g_free(escaped); | |
5267 | 34 |
6982 | 35 gaim_conversation_write(conv, NULL, buf, GAIM_MESSAGE_SYSTEM, time(NULL)); |
5267 | 36 } |
37 | |
38 static void | |
6695 | 39 buddy_away_cb(GaimBuddy *buddy, void *data) |
5267 | 40 { |
9583 | 41 if (gaim_prefs_get_bool("/plugins/core/statenotify/notify_away")) |
42 write_status(buddy, _("%s has gone away.")); | |
5267 | 43 } |
44 | |
45 static void | |
6695 | 46 buddy_unaway_cb(GaimBuddy *buddy, void *data) |
5267 | 47 { |
9583 | 48 if (gaim_prefs_get_bool("/plugins/core/statenotify/notify_away")) |
49 write_status(buddy, _("%s is no longer away.")); | |
5267 | 50 } |
51 | |
52 static void | |
6695 | 53 buddy_idle_cb(GaimBuddy *buddy, void *data) |
5267 | 54 { |
9583 | 55 if (gaim_prefs_get_bool("/plugins/core/statenotify/notify_idle")) |
56 write_status(buddy, _("%s has become idle.")); | |
5267 | 57 } |
58 | |
59 static void | |
6695 | 60 buddy_unidle_cb(GaimBuddy *buddy, void *data) |
5267 | 61 { |
9583 | 62 if (gaim_prefs_get_bool("/plugins/core/statenotify/notify_idle")) |
63 write_status(buddy, _("%s is no longer idle.")); | |
64 } | |
65 | |
11901 | 66 static void |
67 buddy_signon_cb(GaimBuddy *buddy, void *data) | |
68 { | |
69 if (gaim_prefs_get_bool("/plugins/core/statenotify/notify_signon")) | |
70 write_status(buddy, _("%s has signed on.")); | |
71 } | |
72 | |
73 static void | |
74 buddy_signoff_cb(GaimBuddy *buddy, void *data) | |
75 { | |
76 if (gaim_prefs_get_bool("/plugins/core/statenotify/notify_signon")) | |
77 write_status(buddy, _("%s has signed off.")); | |
78 } | |
79 | |
9583 | 80 static GaimPluginPrefFrame * |
81 get_plugin_pref_frame(GaimPlugin *plugin) | |
82 { | |
83 GaimPluginPrefFrame *frame; | |
84 GaimPluginPref *ppref; | |
85 | |
86 frame = gaim_plugin_pref_frame_new(); | |
87 | |
9648 | 88 ppref = gaim_plugin_pref_new_with_label(_("Notify When")); |
9583 | 89 gaim_plugin_pref_frame_add(frame, ppref); |
90 | |
9648 | 91 ppref = gaim_plugin_pref_new_with_name_and_label("/plugins/core/statenotify/notify_away", _("Buddy Goes _Away")); |
9583 | 92 gaim_plugin_pref_frame_add(frame, ppref); |
10246 | 93 |
9648 | 94 ppref = gaim_plugin_pref_new_with_name_and_label("/plugins/core/statenotify/notify_idle", _("Buddy Goes _Idle")); |
9583 | 95 gaim_plugin_pref_frame_add(frame, ppref); |
10246 | 96 |
11901 | 97 ppref = gaim_plugin_pref_new_with_name_and_label("/plugins/core/statenotify/notify_signon", _("Buddy _Signs On/Off")); |
98 gaim_plugin_pref_frame_add(frame, ppref); | |
99 | |
9583 | 100 return frame; |
5267 | 101 } |
102 | |
103 static gboolean | |
104 plugin_load(GaimPlugin *plugin) | |
105 { | |
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6441
diff
changeset
|
106 void *blist_handle = gaim_blist_get_handle(); |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6441
diff
changeset
|
107 |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6441
diff
changeset
|
108 gaim_signal_connect(blist_handle, "buddy-away", |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6441
diff
changeset
|
109 plugin, GAIM_CALLBACK(buddy_away_cb), NULL); |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6441
diff
changeset
|
110 gaim_signal_connect(blist_handle, "buddy-back", |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6441
diff
changeset
|
111 plugin, GAIM_CALLBACK(buddy_unaway_cb), NULL); |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6441
diff
changeset
|
112 gaim_signal_connect(blist_handle, "buddy-idle", |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6441
diff
changeset
|
113 plugin, GAIM_CALLBACK(buddy_idle_cb), NULL); |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6441
diff
changeset
|
114 gaim_signal_connect(blist_handle, "buddy-unidle", |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6441
diff
changeset
|
115 plugin, GAIM_CALLBACK(buddy_unidle_cb), NULL); |
11901 | 116 gaim_signal_connect(blist_handle, "buddy-signed-on", |
117 plugin, GAIM_CALLBACK(buddy_signon_cb), NULL); | |
118 gaim_signal_connect(blist_handle, "buddy-signed-off", | |
119 plugin, GAIM_CALLBACK(buddy_signoff_cb), NULL); | |
5267 | 120 |
121 return TRUE; | |
122 } | |
123 | |
9583 | 124 static GaimPluginUiInfo prefs_info = |
125 { | |
126 get_plugin_pref_frame | |
127 }; | |
128 | |
5267 | 129 static GaimPluginInfo info = |
130 { | |
9943 | 131 GAIM_PLUGIN_MAGIC, |
132 GAIM_MAJOR_VERSION, | |
133 GAIM_MINOR_VERSION, | |
5267 | 134 GAIM_PLUGIN_STANDARD, /**< type */ |
135 NULL, /**< ui_requirement */ | |
136 0, /**< flags */ | |
137 NULL, /**< dependencies */ | |
138 GAIM_PRIORITY_DEFAULT, /**< priority */ | |
139 | |
9583 | 140 STATENOTIFY_PLUGIN_ID, /**< id */ |
5267 | 141 N_("Buddy State Notification"), /**< name */ |
142 VERSION, /**< version */ | |
143 /** summary */ | |
144 N_("Notifies in a conversation window when a buddy goes or returns from " | |
145 "away or idle."), | |
146 /** description */ | |
147 N_("Notifies in a conversation window when a buddy goes or returns from " | |
148 "away or idle."), | |
149 "Christian Hammond <chipx86@gnupdate.org>", /**< author */ | |
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6441
diff
changeset
|
150 GAIM_WEBSITE, /**< homepage */ |
5267 | 151 |
152 plugin_load, /**< load */ | |
153 NULL, /**< unload */ | |
154 NULL, /**< destroy */ | |
155 | |
156 NULL, /**< ui_info */ | |
8993 | 157 NULL, /**< extra_info */ |
9583 | 158 &prefs_info, /**< prefs_info */ |
8993 | 159 NULL |
5267 | 160 }; |
161 | |
162 static void | |
5920
7d385de2f9cd
[gaim-migrate @ 6360]
Christian Hammond <chipx86@chipx86.com>
parents:
5873
diff
changeset
|
163 init_plugin(GaimPlugin *plugin) |
5267 | 164 { |
9583 | 165 gaim_prefs_add_none("/plugins/core/statenotify"); |
166 gaim_prefs_add_bool("/plugins/core/statenotify/notify_away", TRUE); | |
167 gaim_prefs_add_bool("/plugins/core/statenotify/notify_idle", TRUE); | |
11901 | 168 gaim_prefs_add_bool("/plugins/core/statenotify/notify_signon", TRUE); |
5267 | 169 } |
170 | |
6063 | 171 GAIM_INIT_PLUGIN(statenotify, init_plugin, info) |