Thu, 09 Mar 2006 04:02:09 +0000
[gaim-migrate @ 15852]
Add GAIM_MESSAGE_ACTIVE_ONLY:
This allows core plugins to hint to the UI that it should not show a message if a conversation is "inactive". For the GTK+ UI, this means conversations that aren't the active conversation in a contact-aware conversation.
With the GTK+ UI, to avoid having such a message logged, you need to either call gaim_conv_im_write() (which will drop the message before logging, or allow it through for both logging and displaying) or set the GAIM_MESSAGE_NO_LOG flag (which obviously suppresses all logging). Look at the Buddy State Notification and Psychic plugins for the examples of each of these techniques, respectively.
This fixes a ShowStopperBug.
Also, rearrange some stuff in gtkconv.c to make things more clear and remove unused code.
|
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 |
| 6695 | 16 | write_status(GaimBuddy *buddy, const char *message) |
| 5267 | 17 | { |
|
5676
d3c2fdaf4821
[gaim-migrate @ 6094]
Christian Hammond <chipx86@chipx86.com>
parents:
5587
diff
changeset
|
18 | GaimConversation *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 | |
|
11338
1a3663ac9b05
[gaim-migrate @ 13551]
Mark Doliner <markdoliner@pidgin.im>
parents:
10246
diff
changeset
|
23 | conv = gaim_find_conversation_with_account(GAIM_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; | |
|
13477
aa1863ed7f63
[gaim-migrate @ 15852]
Richard Laager <rlaager@pidgin.im>
parents:
12600
diff
changeset
|
28 | g_return_if_fail(conv->type == GAIM_CONV_TYPE_IM); |
| 5267 | 29 | |
|
9620
fe99fcea5c1c
[gaim-migrate @ 10464]
Christopher O'Brien <siege@pidgin.im>
parents:
9583
diff
changeset
|
30 | who = gaim_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 | |
|
13477
aa1863ed7f63
[gaim-migrate @ 15852]
Richard Laager <rlaager@pidgin.im>
parents:
12600
diff
changeset
|
36 | gaim_conv_im_write(conv->u.im, NULL, buf, GAIM_MESSAGE_SYSTEM | GAIM_MESSAGE_ACTIVE_ONLY, time(NULL)); |
| 5267 | 37 | } |
| 38 | ||
| 39 | static void | |
| 11935 | 40 | buddy_status_changed_cb(GaimBuddy *buddy, GaimStatus *old_status, |
| 41 | GaimStatus *status, void *data) | |
| 5267 | 42 | { |
| 11935 | 43 | gboolean available, old_available; |
| 44 | ||
| 45 | available = gaim_status_is_available(status); | |
| 46 | old_available = gaim_status_is_available(old_status); | |
| 47 | ||
| 48 | if (gaim_prefs_get_bool("/plugins/core/statenotify/notify_away")) { | |
| 49 | if (available && !old_available) | |
| 50 | write_status(buddy, _("%s is no longer away.")); | |
| 51 | else if (!available && old_available) | |
| 52 | write_status(buddy, _("%s has gone away.")); | |
| 53 | } | |
| 5267 | 54 | } |
| 55 | ||
| 56 | static void | |
| 11935 | 57 | buddy_idle_changed_cb(GaimBuddy *buddy, gboolean old_idle, gboolean idle, |
| 58 | void *data) | |
| 5267 | 59 | { |
| 11935 | 60 | if (gaim_prefs_get_bool("/plugins/core/statenotify/notify_idle")) { |
| 61 | if (idle) { | |
| 62 | write_status(buddy, _("%s has become idle.")); | |
| 63 | } else { | |
| 64 | write_status(buddy, _("%s is no longer idle.")); | |
| 65 | } | |
| 66 | } | |
| 9583 | 67 | } |
| 68 | ||
|
11901
34394921fe76
[gaim-migrate @ 14192]
Francesco Fracassi <ffracassi@users.sourceforge.net>
parents:
11338
diff
changeset
|
69 | static void |
|
34394921fe76
[gaim-migrate @ 14192]
Francesco Fracassi <ffracassi@users.sourceforge.net>
parents:
11338
diff
changeset
|
70 | buddy_signon_cb(GaimBuddy *buddy, void *data) |
|
34394921fe76
[gaim-migrate @ 14192]
Francesco Fracassi <ffracassi@users.sourceforge.net>
parents:
11338
diff
changeset
|
71 | { |
|
34394921fe76
[gaim-migrate @ 14192]
Francesco Fracassi <ffracassi@users.sourceforge.net>
parents:
11338
diff
changeset
|
72 | if (gaim_prefs_get_bool("/plugins/core/statenotify/notify_signon")) |
|
34394921fe76
[gaim-migrate @ 14192]
Francesco Fracassi <ffracassi@users.sourceforge.net>
parents:
11338
diff
changeset
|
73 | write_status(buddy, _("%s has signed on.")); |
|
34394921fe76
[gaim-migrate @ 14192]
Francesco Fracassi <ffracassi@users.sourceforge.net>
parents:
11338
diff
changeset
|
74 | } |
|
34394921fe76
[gaim-migrate @ 14192]
Francesco Fracassi <ffracassi@users.sourceforge.net>
parents:
11338
diff
changeset
|
75 | |
|
34394921fe76
[gaim-migrate @ 14192]
Francesco Fracassi <ffracassi@users.sourceforge.net>
parents:
11338
diff
changeset
|
76 | static void |
|
34394921fe76
[gaim-migrate @ 14192]
Francesco Fracassi <ffracassi@users.sourceforge.net>
parents:
11338
diff
changeset
|
77 | buddy_signoff_cb(GaimBuddy *buddy, void *data) |
|
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 | if (gaim_prefs_get_bool("/plugins/core/statenotify/notify_signon")) |
|
34394921fe76
[gaim-migrate @ 14192]
Francesco Fracassi <ffracassi@users.sourceforge.net>
parents:
11338
diff
changeset
|
80 | write_status(buddy, _("%s has signed off.")); |
|
34394921fe76
[gaim-migrate @ 14192]
Francesco Fracassi <ffracassi@users.sourceforge.net>
parents:
11338
diff
changeset
|
81 | } |
|
34394921fe76
[gaim-migrate @ 14192]
Francesco Fracassi <ffracassi@users.sourceforge.net>
parents:
11338
diff
changeset
|
82 | |
| 9583 | 83 | static GaimPluginPrefFrame * |
| 84 | get_plugin_pref_frame(GaimPlugin *plugin) | |
| 85 | { | |
| 86 | GaimPluginPrefFrame *frame; | |
| 87 | GaimPluginPref *ppref; | |
| 88 | ||
| 89 | frame = gaim_plugin_pref_frame_new(); | |
| 90 | ||
|
9648
34a457599c78
[gaim-migrate @ 10496]
Mark Doliner <markdoliner@pidgin.im>
parents:
9620
diff
changeset
|
91 | ppref = gaim_plugin_pref_new_with_label(_("Notify When")); |
| 9583 | 92 | gaim_plugin_pref_frame_add(frame, ppref); |
| 93 | ||
|
9648
34a457599c78
[gaim-migrate @ 10496]
Mark Doliner <markdoliner@pidgin.im>
parents:
9620
diff
changeset
|
94 | ppref = gaim_plugin_pref_new_with_name_and_label("/plugins/core/statenotify/notify_away", _("Buddy Goes _Away")); |
| 9583 | 95 | gaim_plugin_pref_frame_add(frame, ppref); |
|
10246
aa5bff72f94c
[gaim-migrate @ 11386]
Mark Doliner <markdoliner@pidgin.im>
parents:
10167
diff
changeset
|
96 | |
|
9648
34a457599c78
[gaim-migrate @ 10496]
Mark Doliner <markdoliner@pidgin.im>
parents:
9620
diff
changeset
|
97 | ppref = gaim_plugin_pref_new_with_name_and_label("/plugins/core/statenotify/notify_idle", _("Buddy Goes _Idle")); |
| 9583 | 98 | gaim_plugin_pref_frame_add(frame, ppref); |
|
10246
aa5bff72f94c
[gaim-migrate @ 11386]
Mark Doliner <markdoliner@pidgin.im>
parents:
10167
diff
changeset
|
99 | |
|
11901
34394921fe76
[gaim-migrate @ 14192]
Francesco Fracassi <ffracassi@users.sourceforge.net>
parents:
11338
diff
changeset
|
100 | ppref = gaim_plugin_pref_new_with_name_and_label("/plugins/core/statenotify/notify_signon", _("Buddy _Signs On/Off")); |
|
34394921fe76
[gaim-migrate @ 14192]
Francesco Fracassi <ffracassi@users.sourceforge.net>
parents:
11338
diff
changeset
|
101 | gaim_plugin_pref_frame_add(frame, ppref); |
|
34394921fe76
[gaim-migrate @ 14192]
Francesco Fracassi <ffracassi@users.sourceforge.net>
parents:
11338
diff
changeset
|
102 | |
| 9583 | 103 | return frame; |
| 5267 | 104 | } |
| 105 | ||
| 106 | static gboolean | |
| 107 | plugin_load(GaimPlugin *plugin) | |
| 108 | { | |
|
6485
3c7ba18e32f1
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6441
diff
changeset
|
109 | void *blist_handle = gaim_blist_get_handle(); |
|
3c7ba18e32f1
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6441
diff
changeset
|
110 | |
| 11935 | 111 | gaim_signal_connect(blist_handle, "buddy-status-changed", plugin, |
| 112 | GAIM_CALLBACK(buddy_status_changed_cb), NULL); | |
| 113 | gaim_signal_connect(blist_handle, "buddy-idle-changed", plugin, | |
| 114 | GAIM_CALLBACK(buddy_idle_changed_cb), NULL); | |
| 115 | gaim_signal_connect(blist_handle, "buddy-signed-on", plugin, | |
| 116 | GAIM_CALLBACK(buddy_signon_cb), NULL); | |
| 117 | gaim_signal_connect(blist_handle, "buddy-signed-off", plugin, | |
| 118 | GAIM_CALLBACK(buddy_signoff_cb), NULL); | |
| 5267 | 119 | |
| 120 | return TRUE; | |
| 121 | } | |
| 122 | ||
| 9583 | 123 | static GaimPluginUiInfo prefs_info = |
| 124 | { | |
|
12600
7ecd4441fdc7
[gaim-migrate @ 14934]
Richard Laager <rlaager@pidgin.im>
parents:
11935
diff
changeset
|
125 | get_plugin_pref_frame, |
|
7ecd4441fdc7
[gaim-migrate @ 14934]
Richard Laager <rlaager@pidgin.im>
parents:
11935
diff
changeset
|
126 | 0, /* page_num (Reserved) */ |
|
7ecd4441fdc7
[gaim-migrate @ 14934]
Richard Laager <rlaager@pidgin.im>
parents:
11935
diff
changeset
|
127 | NULL /* frame (Reserved) */ |
| 9583 | 128 | }; |
| 129 | ||
| 5267 | 130 | static GaimPluginInfo info = |
| 131 | { | |
| 9943 | 132 | GAIM_PLUGIN_MAGIC, |
| 133 | GAIM_MAJOR_VERSION, | |
| 134 | GAIM_MINOR_VERSION, | |
| 5267 | 135 | GAIM_PLUGIN_STANDARD, /**< type */ |
| 136 | NULL, /**< ui_requirement */ | |
| 137 | 0, /**< flags */ | |
| 138 | NULL, /**< dependencies */ | |
| 139 | GAIM_PRIORITY_DEFAULT, /**< priority */ | |
| 140 | ||
| 9583 | 141 | STATENOTIFY_PLUGIN_ID, /**< id */ |
| 5267 | 142 | N_("Buddy State Notification"), /**< name */ |
| 143 | VERSION, /**< version */ | |
| 144 | /** summary */ | |
| 145 | N_("Notifies in a conversation window when a buddy goes or returns from " | |
| 146 | "away or idle."), | |
| 147 | /** description */ | |
| 148 | N_("Notifies in a conversation window when a buddy goes or returns from " | |
| 149 | "away or idle."), | |
| 150 | "Christian Hammond <chipx86@gnupdate.org>", /**< author */ | |
|
6485
3c7ba18e32f1
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6441
diff
changeset
|
151 | GAIM_WEBSITE, /**< homepage */ |
| 5267 | 152 | |
| 153 | plugin_load, /**< load */ | |
| 154 | NULL, /**< unload */ | |
| 155 | NULL, /**< destroy */ | |
| 156 | ||
| 157 | NULL, /**< ui_info */ | |
| 8993 | 158 | NULL, /**< extra_info */ |
| 9583 | 159 | &prefs_info, /**< prefs_info */ |
| 8993 | 160 | NULL |
| 5267 | 161 | }; |
| 162 | ||
| 163 | static void | |
|
5920
963bfdefee02
[gaim-migrate @ 6360]
Christian Hammond <chipx86@chipx86.com>
parents:
5873
diff
changeset
|
164 | init_plugin(GaimPlugin *plugin) |
| 5267 | 165 | { |
| 9583 | 166 | gaim_prefs_add_none("/plugins/core/statenotify"); |
| 167 | gaim_prefs_add_bool("/plugins/core/statenotify/notify_away", TRUE); | |
| 168 | gaim_prefs_add_bool("/plugins/core/statenotify/notify_idle", TRUE); | |
|
11901
34394921fe76
[gaim-migrate @ 14192]
Francesco Fracassi <ffracassi@users.sourceforge.net>
parents:
11338
diff
changeset
|
169 | gaim_prefs_add_bool("/plugins/core/statenotify/notify_signon", TRUE); |
| 5267 | 170 | } |
| 171 | ||
| 6063 | 172 | GAIM_INIT_PLUGIN(statenotify, init_plugin, info) |