Mercurial > pidgin
annotate plugins/statenotify.c @ 12645:fc28451f5d96
[gaim-migrate @ 14983]
SF Patch #1314512 from Sadrul (who has a patch for everything)
"This patch introduces a flag for protocol plugins that
support offline messages (like Y!M and ICQ). This was
encouraged by the following conversation:
<sadrul> should offline buddies be listed/enabled in
the send-to menu?
<rekkanoryo> i would think only for protocols that
support offline messaging, if it's indicated that the
buddy is offline
-- <snip> --
<Bleeter> sadrul: personally, I'd like to see a
'supports offline' flag of some description
<Bleeter> one could then redirect (via plugins) through
email or alternative methods
<Bleeter> just a thought
<Paco-Paco> yeah, that sounds like a reasonble thing to have
This patch uses this flag to disable the buddies in the
send-to menu who are offline and the protocol doesn't
support offline messages."
I made this make the label insensitive instead of the whole menuitem. This
should address SimGuy's concerns about inconsistency (i.e. you could create a
conversation with someone via the buddy list that you couldn't create via the
Send To menu). I also hacked up some voodoo to show the label as sensitive when
moused-over, as that looks better (given the label-insensitive thing is itself a
hack). I think this works quite well.
BUG NOTE:
This makes more obvious an existing bug. The Send To menu isn't updated when
buddies sign on or off or change status (at least under some circumstances).
We need to fix that anyway, so I'm not going to let it hold up this commit.
Switching tabs will clear it up. I'm thinking we just might want to build the
contents of that menu when it is selected. That would save us a mess of
inefficient signal callbacks that update the Send To menus in open windows all
the time.
AIM NOTE:
This assumes that AIM can't offline message. That's not strictly true. You can
message invisible users on AIM. However, by design, we can't tell when a user
is invisible without resorting to dirty hackery. In practice, this isn't a
problem, as you can still select the AIM user from the menu. And really, how
often will you be choosing the Invisible contact, rather than the user going
Invisible in the middle of a conversation or IMing you while they're Invisible?
JABBER NOTE:
This assumes that Jabber can always offline message. This isn't strictly true.
Sadrul said:
I have updated Jabber according to this link which seems to
talk about how to determine the existence offline-message
support in a server:
http://www.jabber.org/jeps/jep-0013.html#discover
However, jabber.org doesn't seem to send the required
info. So I am not sure about it.
He later said:
I talked to Nathan and he said offline message support is
mostly assumed for most jabber servers. GTalk doesn't yet
support it, but they are working on it. So I have made
jabber to always return TRUE.
If there is truly no way to detect offline messaging capability, then this is
an acceptable solution. We could special case Google Talk because of its
popularity, and remove that later. It's probably not worth it though.
MSN NOTE:
This assumes that MSN can never offline message. That's effectively true, but
to be technically correct, MSN can offline message if there's already a
switchboard conversation open with a user. We could write an offline_message
function in the MSN prpl to detect that, but it'd be of limited usefulness,
especially given that under most circumstances (where this might matter), the
switchboard connection will be closed almost immediately.
CVS NOTE:
I'm writing to share a tragic little story.
I have a PC that I use for Gaim development. One day, I was writing a commit
message on it, when all of a suddent it went berserk. The screen started
flashing, and the whole commit message just disappeared. All of it. And it was
a good commit message! I had to cram and rewrite it really quickly. Needless to
say, my rushed commit message wasn't nearly as good, and I blame the PC for that.
Seriously, though, what kind of version control system loses your commit
message on a broken connection to the server? Stupid!
committer: Tailor Script <tailor@pidgin.im>
| author | Richard Laager <rlaager@wiktel.com> |
|---|---|
| date | Fri, 23 Dec 2005 19:26:04 +0000 |
| parents | e856f985a0b9 |
| children | 465c368366f8 |
| 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 | |
|
11935
cb73483c9f63
[gaim-migrate @ 14226]
Etan Reisner <pidgin@unreliablesource.net>
parents:
11901
diff
changeset
|
39 buddy_status_changed_cb(GaimBuddy *buddy, GaimStatus *old_status, |
|
cb73483c9f63
[gaim-migrate @ 14226]
Etan Reisner <pidgin@unreliablesource.net>
parents:
11901
diff
changeset
|
40 GaimStatus *status, void *data) |
| 5267 | 41 { |
|
11935
cb73483c9f63
[gaim-migrate @ 14226]
Etan Reisner <pidgin@unreliablesource.net>
parents:
11901
diff
changeset
|
42 gboolean available, old_available; |
|
cb73483c9f63
[gaim-migrate @ 14226]
Etan Reisner <pidgin@unreliablesource.net>
parents:
11901
diff
changeset
|
43 |
|
cb73483c9f63
[gaim-migrate @ 14226]
Etan Reisner <pidgin@unreliablesource.net>
parents:
11901
diff
changeset
|
44 available = gaim_status_is_available(status); |
|
cb73483c9f63
[gaim-migrate @ 14226]
Etan Reisner <pidgin@unreliablesource.net>
parents:
11901
diff
changeset
|
45 old_available = gaim_status_is_available(old_status); |
|
cb73483c9f63
[gaim-migrate @ 14226]
Etan Reisner <pidgin@unreliablesource.net>
parents:
11901
diff
changeset
|
46 |
|
cb73483c9f63
[gaim-migrate @ 14226]
Etan Reisner <pidgin@unreliablesource.net>
parents:
11901
diff
changeset
|
47 if (gaim_prefs_get_bool("/plugins/core/statenotify/notify_away")) { |
|
cb73483c9f63
[gaim-migrate @ 14226]
Etan Reisner <pidgin@unreliablesource.net>
parents:
11901
diff
changeset
|
48 if (available && !old_available) |
|
cb73483c9f63
[gaim-migrate @ 14226]
Etan Reisner <pidgin@unreliablesource.net>
parents:
11901
diff
changeset
|
49 write_status(buddy, _("%s is no longer away.")); |
|
cb73483c9f63
[gaim-migrate @ 14226]
Etan Reisner <pidgin@unreliablesource.net>
parents:
11901
diff
changeset
|
50 else if (!available && old_available) |
|
cb73483c9f63
[gaim-migrate @ 14226]
Etan Reisner <pidgin@unreliablesource.net>
parents:
11901
diff
changeset
|
51 write_status(buddy, _("%s has gone away.")); |
|
cb73483c9f63
[gaim-migrate @ 14226]
Etan Reisner <pidgin@unreliablesource.net>
parents:
11901
diff
changeset
|
52 } |
| 5267 | 53 } |
| 54 | |
| 55 static void | |
|
11935
cb73483c9f63
[gaim-migrate @ 14226]
Etan Reisner <pidgin@unreliablesource.net>
parents:
11901
diff
changeset
|
56 buddy_idle_changed_cb(GaimBuddy *buddy, gboolean old_idle, gboolean idle, |
|
cb73483c9f63
[gaim-migrate @ 14226]
Etan Reisner <pidgin@unreliablesource.net>
parents:
11901
diff
changeset
|
57 void *data) |
| 5267 | 58 { |
|
11935
cb73483c9f63
[gaim-migrate @ 14226]
Etan Reisner <pidgin@unreliablesource.net>
parents:
11901
diff
changeset
|
59 if (gaim_prefs_get_bool("/plugins/core/statenotify/notify_idle")) { |
|
cb73483c9f63
[gaim-migrate @ 14226]
Etan Reisner <pidgin@unreliablesource.net>
parents:
11901
diff
changeset
|
60 if (idle) { |
|
cb73483c9f63
[gaim-migrate @ 14226]
Etan Reisner <pidgin@unreliablesource.net>
parents:
11901
diff
changeset
|
61 write_status(buddy, _("%s has become idle.")); |
|
cb73483c9f63
[gaim-migrate @ 14226]
Etan Reisner <pidgin@unreliablesource.net>
parents:
11901
diff
changeset
|
62 } else { |
|
cb73483c9f63
[gaim-migrate @ 14226]
Etan Reisner <pidgin@unreliablesource.net>
parents:
11901
diff
changeset
|
63 write_status(buddy, _("%s is no longer idle.")); |
|
cb73483c9f63
[gaim-migrate @ 14226]
Etan Reisner <pidgin@unreliablesource.net>
parents:
11901
diff
changeset
|
64 } |
|
cb73483c9f63
[gaim-migrate @ 14226]
Etan Reisner <pidgin@unreliablesource.net>
parents:
11901
diff
changeset
|
65 } |
| 9583 | 66 } |
| 67 | |
| 11901 | 68 static void |
| 69 buddy_signon_cb(GaimBuddy *buddy, void *data) | |
| 70 { | |
| 71 if (gaim_prefs_get_bool("/plugins/core/statenotify/notify_signon")) | |
| 72 write_status(buddy, _("%s has signed on.")); | |
| 73 } | |
| 74 | |
| 75 static void | |
| 76 buddy_signoff_cb(GaimBuddy *buddy, void *data) | |
| 77 { | |
| 78 if (gaim_prefs_get_bool("/plugins/core/statenotify/notify_signon")) | |
| 79 write_status(buddy, _("%s has signed off.")); | |
| 80 } | |
| 81 | |
| 9583 | 82 static GaimPluginPrefFrame * |
| 83 get_plugin_pref_frame(GaimPlugin *plugin) | |
| 84 { | |
| 85 GaimPluginPrefFrame *frame; | |
| 86 GaimPluginPref *ppref; | |
| 87 | |
| 88 frame = gaim_plugin_pref_frame_new(); | |
| 89 | |
| 9648 | 90 ppref = gaim_plugin_pref_new_with_label(_("Notify When")); |
| 9583 | 91 gaim_plugin_pref_frame_add(frame, ppref); |
| 92 | |
| 9648 | 93 ppref = gaim_plugin_pref_new_with_name_and_label("/plugins/core/statenotify/notify_away", _("Buddy Goes _Away")); |
| 9583 | 94 gaim_plugin_pref_frame_add(frame, ppref); |
| 10246 | 95 |
| 9648 | 96 ppref = gaim_plugin_pref_new_with_name_and_label("/plugins/core/statenotify/notify_idle", _("Buddy Goes _Idle")); |
| 9583 | 97 gaim_plugin_pref_frame_add(frame, ppref); |
| 10246 | 98 |
| 11901 | 99 ppref = gaim_plugin_pref_new_with_name_and_label("/plugins/core/statenotify/notify_signon", _("Buddy _Signs On/Off")); |
| 100 gaim_plugin_pref_frame_add(frame, ppref); | |
| 101 | |
| 9583 | 102 return frame; |
| 5267 | 103 } |
| 104 | |
| 105 static gboolean | |
| 106 plugin_load(GaimPlugin *plugin) | |
| 107 { | |
|
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6441
diff
changeset
|
108 void *blist_handle = gaim_blist_get_handle(); |
|
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6441
diff
changeset
|
109 |
|
11935
cb73483c9f63
[gaim-migrate @ 14226]
Etan Reisner <pidgin@unreliablesource.net>
parents:
11901
diff
changeset
|
110 gaim_signal_connect(blist_handle, "buddy-status-changed", plugin, |
|
cb73483c9f63
[gaim-migrate @ 14226]
Etan Reisner <pidgin@unreliablesource.net>
parents:
11901
diff
changeset
|
111 GAIM_CALLBACK(buddy_status_changed_cb), NULL); |
|
cb73483c9f63
[gaim-migrate @ 14226]
Etan Reisner <pidgin@unreliablesource.net>
parents:
11901
diff
changeset
|
112 gaim_signal_connect(blist_handle, "buddy-idle-changed", plugin, |
|
cb73483c9f63
[gaim-migrate @ 14226]
Etan Reisner <pidgin@unreliablesource.net>
parents:
11901
diff
changeset
|
113 GAIM_CALLBACK(buddy_idle_changed_cb), NULL); |
|
cb73483c9f63
[gaim-migrate @ 14226]
Etan Reisner <pidgin@unreliablesource.net>
parents:
11901
diff
changeset
|
114 gaim_signal_connect(blist_handle, "buddy-signed-on", plugin, |
|
cb73483c9f63
[gaim-migrate @ 14226]
Etan Reisner <pidgin@unreliablesource.net>
parents:
11901
diff
changeset
|
115 GAIM_CALLBACK(buddy_signon_cb), NULL); |
|
cb73483c9f63
[gaim-migrate @ 14226]
Etan Reisner <pidgin@unreliablesource.net>
parents:
11901
diff
changeset
|
116 gaim_signal_connect(blist_handle, "buddy-signed-off", plugin, |
|
cb73483c9f63
[gaim-migrate @ 14226]
Etan Reisner <pidgin@unreliablesource.net>
parents:
11901
diff
changeset
|
117 GAIM_CALLBACK(buddy_signoff_cb), NULL); |
| 5267 | 118 |
| 119 return TRUE; | |
| 120 } | |
| 121 | |
| 9583 | 122 static GaimPluginUiInfo prefs_info = |
| 123 { | |
|
12600
e856f985a0b9
[gaim-migrate @ 14934]
Richard Laager <rlaager@wiktel.com>
parents:
11935
diff
changeset
|
124 get_plugin_pref_frame, |
|
e856f985a0b9
[gaim-migrate @ 14934]
Richard Laager <rlaager@wiktel.com>
parents:
11935
diff
changeset
|
125 0, /* page_num (Reserved) */ |
|
e856f985a0b9
[gaim-migrate @ 14934]
Richard Laager <rlaager@wiktel.com>
parents:
11935
diff
changeset
|
126 NULL /* frame (Reserved) */ |
| 9583 | 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) |
