Sat, 06 Jul 2013 15:17:36 +0530
Renamed blist.[ch] to buddylist.[ch]
| 15230 | 1 | /* |
| 2 | * Offline Message Emulation - Save messages sent to an offline user as pounce | |
| 3 | * Copyright (C) 2004 | |
| 4 | * | |
| 5 | * This program is free software; you can redistribute it and/or | |
| 6 | * modify it under the terms of the GNU General Public License as | |
| 7 | * published by the Free Software Foundation; either version 2 of the | |
| 8 | * License, or (at your option) any later version. | |
| 9 | * | |
| 10 | * This program is distributed in the hope that it will be useful, but | |
| 11 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 13 | * General Public License for more details. | |
| 14 | * | |
| 15 | * You should have received a copy of the GNU General Public License | |
| 16 | * along with this program; if not, write to the Free Software | |
|
19859
71d37b57eff2
The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
19832
diff
changeset
|
17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
71d37b57eff2
The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
19832
diff
changeset
|
18 | * 02111-1301, USA. |
| 15230 | 19 | */ |
| 20 | #include "internal.h" | |
| 21 | ||
| 22 | #define PLUGIN_ID "core-plugin_pack-offlinemsg" | |
|
15418
bf287f742a5a
[gaim-migrate @ 18149]
Luke Schierer <lschiere@pidgin.im>
parents:
15230
diff
changeset
|
23 | #define PLUGIN_NAME N_("Offline Message Emulation") |
|
25633
feee0c7e503f
Fix some more mis-identified plugins, like 3b3526a0...
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
22268
diff
changeset
|
24 | #define PLUGIN_STATIC_NAME offlinemsg |
|
15418
bf287f742a5a
[gaim-migrate @ 18149]
Luke Schierer <lschiere@pidgin.im>
parents:
15230
diff
changeset
|
25 | #define PLUGIN_SUMMARY N_("Save messages sent to an offline user as pounce.") |
|
bf287f742a5a
[gaim-migrate @ 18149]
Luke Schierer <lschiere@pidgin.im>
parents:
15230
diff
changeset
|
26 | #define PLUGIN_DESCRIPTION N_("Save messages sent to an offline user as pounce.") |
| 15230 | 27 | #define PLUGIN_AUTHOR "Sadrul H Chowdhury <sadrul@users.sourceforge.net>" |
| 28 | ||
| 15884 | 29 | /* Purple headers */ |
| 15230 | 30 | #include <version.h> |
| 31 | ||
|
34706
02cb08146888
Renamed blist.[ch] to buddylist.[ch]
Ankit Vani <a@nevitus.org>
parents:
34678
diff
changeset
|
32 | #include <buddylist.h> |
| 15230 | 33 | #include <conversation.h> |
| 34 | #include <core.h> | |
| 35 | #include <debug.h> | |
| 36 | #include <pounce.h> | |
| 37 | #include <request.h> | |
| 38 | ||
| 16481 | 39 | #define PREF_PREFIX "/plugins/core/" PLUGIN_ID |
| 15230 | 40 | #define PREF_ALWAYS PREF_PREFIX "/always" |
| 41 | ||
| 42 | typedef struct _OfflineMsg OfflineMsg; | |
| 43 | ||
| 44 | typedef enum | |
| 45 | { | |
| 46 | OFFLINE_MSG_NONE, | |
| 47 | OFFLINE_MSG_YES, | |
| 48 | OFFLINE_MSG_NO | |
| 49 | } OfflineMessageSetting; | |
| 50 | ||
| 51 | struct _OfflineMsg | |
| 52 | { | |
| 15884 | 53 | PurpleAccount *account; |
| 54 | PurpleConversation *conv; | |
| 15230 | 55 | char *who; |
| 56 | char *message; | |
| 57 | }; | |
| 58 | ||
| 59 | static void | |
| 60 | discard_data(OfflineMsg *offline) | |
| 61 | { | |
| 62 | g_free(offline->who); | |
| 63 | g_free(offline->message); | |
| 64 | g_free(offline); | |
| 65 | } | |
| 66 | ||
| 67 | static void | |
| 68 | cancel_poune(OfflineMsg *offline) | |
| 69 | { | |
|
34678
40a30f74a7b8
Removed purple_conversation_[gs]et_data(). Used g_object_[gs]et_data() instead.
Ankit Vani <a@nevitus.org>
parents:
34652
diff
changeset
|
70 | g_object_set_data(G_OBJECT(offline->conv), "plugin_pack:offlinemsg", |
| 15230 | 71 | GINT_TO_POINTER(OFFLINE_MSG_NO)); |
|
34652
65a6bfb86d43
Updated libpurple plugins with the API changes
Ankit Vani <a@nevitus.org>
parents:
34632
diff
changeset
|
72 | purple_conversation_send_with_flags(offline->conv, offline->message, 0); |
| 15230 | 73 | discard_data(offline); |
| 74 | } | |
| 75 | ||
| 76 | static void | |
| 77 | record_pounce(OfflineMsg *offline) | |
| 78 | { | |
| 15884 | 79 | PurplePounce *pounce; |
| 80 | PurplePounceEvent event; | |
| 81 | PurplePounceOption option; | |
| 82 | PurpleConversation *conv; | |
|
32971
d6ad5be6427a
The Offline Message Emulation plugin now adds a note that the message
Mark Doliner <markdoliner@pidgin.im>
parents:
31294
diff
changeset
|
83 | char *temp; |
| 15230 | 84 | |
| 15884 | 85 | event = PURPLE_POUNCE_SIGNON; |
| 86 | option = PURPLE_POUNCE_OPTION_NONE; | |
| 15230 | 87 | |
| 15884 | 88 | pounce = purple_pounce_new(purple_core_get_ui(), offline->account, offline->who, |
| 15230 | 89 | event, option); |
| 90 | ||
| 15884 | 91 | purple_pounce_action_set_enabled(pounce, "send-message", TRUE); |
|
32971
d6ad5be6427a
The Offline Message Emulation plugin now adds a note that the message
Mark Doliner <markdoliner@pidgin.im>
parents:
31294
diff
changeset
|
92 | |
|
d6ad5be6427a
The Offline Message Emulation plugin now adds a note that the message
Mark Doliner <markdoliner@pidgin.im>
parents:
31294
diff
changeset
|
93 | temp = g_strdup_printf("(%s) %s", _("Offline message"), |
|
d6ad5be6427a
The Offline Message Emulation plugin now adds a note that the message
Mark Doliner <markdoliner@pidgin.im>
parents:
31294
diff
changeset
|
94 | offline->message); |
|
d6ad5be6427a
The Offline Message Emulation plugin now adds a note that the message
Mark Doliner <markdoliner@pidgin.im>
parents:
31294
diff
changeset
|
95 | purple_pounce_action_set_attribute(pounce, "send-message", "message", |
|
d6ad5be6427a
The Offline Message Emulation plugin now adds a note that the message
Mark Doliner <markdoliner@pidgin.im>
parents:
31294
diff
changeset
|
96 | temp); |
|
d6ad5be6427a
The Offline Message Emulation plugin now adds a note that the message
Mark Doliner <markdoliner@pidgin.im>
parents:
31294
diff
changeset
|
97 | g_free(temp); |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
27525
diff
changeset
|
98 | |
| 15230 | 99 | conv = offline->conv; |
|
34678
40a30f74a7b8
Removed purple_conversation_[gs]et_data(). Used g_object_[gs]et_data() instead.
Ankit Vani <a@nevitus.org>
parents:
34652
diff
changeset
|
100 | if (!g_object_get_data(G_OBJECT(conv), "plugin_pack:offlinemsg")) |
| 15884 | 101 | purple_conversation_write(conv, NULL, _("The rest of the messages will be saved " |
|
27525
579b9d64b364
A semi-random collection of English spelling and grammatical changes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25633
diff
changeset
|
102 | "as pounces. You can edit/delete the pounce from the `Buddy " |
| 15230 | 103 | "Pounce' dialog."), |
| 15884 | 104 | PURPLE_MESSAGE_SYSTEM, time(NULL)); |
|
34678
40a30f74a7b8
Removed purple_conversation_[gs]et_data(). Used g_object_[gs]et_data() instead.
Ankit Vani <a@nevitus.org>
parents:
34652
diff
changeset
|
105 | g_object_set_data(G_OBJECT(conv), "plugin_pack:offlinemsg", |
| 15230 | 106 | GINT_TO_POINTER(OFFLINE_MSG_YES)); |
| 107 | ||
|
34628
014583658b51
Refactored libpurple/plugins to use the GObject-based PurpleConversation
Ankit Vani <a@nevitus.org>
parents:
34626
diff
changeset
|
108 | purple_conversation_write_message(conv, offline->who, offline->message, |
| 15884 | 109 | PURPLE_MESSAGE_SEND, time(NULL)); |
| 15230 | 110 | |
| 111 | discard_data(offline); | |
| 112 | } | |
| 113 | ||
| 114 | static void | |
| 15884 | 115 | sending_msg_cb(PurpleAccount *account, const char *who, char **message, gpointer handle) |
| 15230 | 116 | { |
| 15884 | 117 | PurpleBuddy *buddy; |
| 15230 | 118 | OfflineMsg *offline; |
| 15884 | 119 | PurpleConversation *conv; |
| 15230 | 120 | OfflineMessageSetting setting; |
| 121 | ||
|
19825
9f31b80db6a9
Catch the event at the very end to make sure other plugins can play with it
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
16745
diff
changeset
|
122 | if (message == NULL || *message == NULL || |
|
9f31b80db6a9
Catch the event at the very end to make sure other plugins can play with it
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
16745
diff
changeset
|
123 | **message == '\0') |
|
9f31b80db6a9
Catch the event at the very end to make sure other plugins can play with it
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
16745
diff
changeset
|
124 | return; |
|
9f31b80db6a9
Catch the event at the very end to make sure other plugins can play with it
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
16745
diff
changeset
|
125 | |
| 15884 | 126 | buddy = purple_find_buddy(account, who); |
| 15230 | 127 | if (!buddy) |
| 128 | return; | |
| 129 | ||
| 15884 | 130 | if (purple_presence_is_online(purple_buddy_get_presence(buddy))) |
| 15230 | 131 | return; |
| 132 | ||
| 15884 | 133 | if (purple_account_supports_offline_message(account, buddy)) |
| 15230 | 134 | { |
|
19832
84b69b21672b
Patch from QuLogic. Fixes #2903 ('Missing newlines in debug messages.')
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
19825
diff
changeset
|
135 | purple_debug_info("offlinemsg", "Account \"%s\" supports offline messages.\n", |
| 15884 | 136 | purple_account_get_username(account)); |
| 15230 | 137 | return; |
| 138 | } | |
| 139 | ||
|
34632
ebe6b2a60305
Changed all arguments and return types of Chat and IMs to PurpleChatConversation and PurpleIMConversation.
Ankit Vani <a@nevitus.org>
parents:
34628
diff
changeset
|
140 | conv = PURPLE_CONVERSATION(purple_conversations_find_im_with_account(who, account)); |
| 15230 | 141 | |
| 142 | if (!conv) | |
| 143 | return; | |
| 144 | ||
|
34678
40a30f74a7b8
Removed purple_conversation_[gs]et_data(). Used g_object_[gs]et_data() instead.
Ankit Vani <a@nevitus.org>
parents:
34652
diff
changeset
|
145 | setting = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(conv), "plugin_pack:offlinemsg")); |
| 15230 | 146 | if (setting == OFFLINE_MSG_NO) |
| 147 | return; | |
| 148 | ||
| 149 | offline = g_new0(OfflineMsg, 1); | |
| 150 | offline->conv = conv; | |
| 151 | offline->account = account; | |
| 152 | offline->who = g_strdup(who); | |
| 153 | offline->message = *message; | |
| 154 | *message = NULL; | |
| 155 | ||
| 15884 | 156 | if (purple_prefs_get_bool(PREF_ALWAYS) || setting == OFFLINE_MSG_YES) |
| 15230 | 157 | record_pounce(offline); |
| 158 | else if (setting == OFFLINE_MSG_NONE) | |
| 159 | { | |
| 160 | char *ask; | |
| 161 | ask = g_strdup_printf(_("\"%s\" is currently offline. Do you want to save the " | |
| 162 | "rest of the messages in a pounce and automatically send them " | |
| 163 | "when \"%s\" logs back in?"), who, who); | |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
27525
diff
changeset
|
164 | |
|
21175
c6d76b49c206
disapproval of revision '8ba833993a115415727bb1b70362e0bd1603c169'
Richard Laager <rlaager@pidgin.im>
parents:
21174
diff
changeset
|
165 | purple_request_action(handle, _("Offline Message"), ask, |
| 15230 | 166 | _("You can edit/delete the pounce from the `Buddy Pounces' dialog"), |
|
22268
a6f48dec4ca5
A few more "purple_request_action" default action corrections
Mark Doliner <markdoliner@pidgin.im>
parents:
21630
diff
changeset
|
167 | 0, |
|
16490
68c22924d66b
Added account, who, and conversation parameters to the request API calls, and updated all code to match. I can't compile the Perl module, so I'd appreciate it if someone who knows it would verify that this doesn't break Perl.
Evan Schoenberg <evands@pidgin.im>
parents:
16481
diff
changeset
|
168 | offline->account, offline->who, offline->conv, |
|
21175
c6d76b49c206
disapproval of revision '8ba833993a115415727bb1b70362e0bd1603c169'
Richard Laager <rlaager@pidgin.im>
parents:
21174
diff
changeset
|
169 | offline, 2, |
| 15230 | 170 | _("Yes"), record_pounce, |
| 171 | _("No"), cancel_poune); | |
| 172 | g_free(ask); | |
| 173 | } | |
| 174 | } | |
| 175 | ||
| 176 | static gboolean | |
| 15884 | 177 | plugin_load(PurplePlugin *plugin) |
| 15230 | 178 | { |
|
19825
9f31b80db6a9
Catch the event at the very end to make sure other plugins can play with it
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
16745
diff
changeset
|
179 | purple_signal_connect_priority(purple_conversations_get_handle(), "sending-im-msg", |
|
9f31b80db6a9
Catch the event at the very end to make sure other plugins can play with it
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
16745
diff
changeset
|
180 | plugin, PURPLE_CALLBACK(sending_msg_cb), plugin, PURPLE_SIGNAL_PRIORITY_HIGHEST); |
| 15230 | 181 | return TRUE; |
| 182 | } | |
| 183 | ||
| 184 | static gboolean | |
| 15884 | 185 | plugin_unload(PurplePlugin *plugin) |
| 15230 | 186 | { |
| 187 | return TRUE; | |
| 188 | } | |
| 189 | ||
| 15884 | 190 | static PurplePluginPrefFrame * |
| 191 | get_plugin_pref_frame(PurplePlugin *plugin) | |
| 15230 | 192 | { |
| 15884 | 193 | PurplePluginPrefFrame *frame; |
| 194 | PurplePluginPref *pref; | |
| 15230 | 195 | |
| 15884 | 196 | frame = purple_plugin_pref_frame_new(); |
| 15230 | 197 | |
| 15884 | 198 | pref = purple_plugin_pref_new_with_label(_("Save offline messages in pounce")); |
| 199 | purple_plugin_pref_frame_add(frame, pref); | |
| 15230 | 200 | |
| 15884 | 201 | pref = purple_plugin_pref_new_with_name_and_label(PREF_ALWAYS, |
| 15230 | 202 | _("Do not ask. Always save in pounce.")); |
| 15884 | 203 | purple_plugin_pref_frame_add(frame, pref); |
| 15230 | 204 | |
| 205 | return frame; | |
| 206 | } | |
| 207 | ||
| 15884 | 208 | static PurplePluginUiInfo prefs_info = { |
| 15230 | 209 | get_plugin_pref_frame, |
| 210 | 0, | |
|
16745
df2c3d6b609a
And the rest of the plugins that are compiling for me by default...
Gary Kramlich <grim@reaperworld.com>
parents:
16490
diff
changeset
|
211 | NULL, |
|
df2c3d6b609a
And the rest of the plugins that are compiling for me by default...
Gary Kramlich <grim@reaperworld.com>
parents:
16490
diff
changeset
|
212 | |
|
df2c3d6b609a
And the rest of the plugins that are compiling for me by default...
Gary Kramlich <grim@reaperworld.com>
parents:
16490
diff
changeset
|
213 | /* padding */ |
|
df2c3d6b609a
And the rest of the plugins that are compiling for me by default...
Gary Kramlich <grim@reaperworld.com>
parents:
16490
diff
changeset
|
214 | NULL, |
|
df2c3d6b609a
And the rest of the plugins that are compiling for me by default...
Gary Kramlich <grim@reaperworld.com>
parents:
16490
diff
changeset
|
215 | NULL, |
|
df2c3d6b609a
And the rest of the plugins that are compiling for me by default...
Gary Kramlich <grim@reaperworld.com>
parents:
16490
diff
changeset
|
216 | NULL, |
| 15230 | 217 | NULL |
| 218 | }; | |
| 219 | ||
| 15884 | 220 | static PurplePluginInfo info = |
| 15230 | 221 | { |
| 15884 | 222 | PURPLE_PLUGIN_MAGIC, /* Magic */ |
| 223 | PURPLE_MAJOR_VERSION, /* Purple Major Version */ | |
| 224 | PURPLE_MINOR_VERSION, /* Purple Minor Version */ | |
| 225 | PURPLE_PLUGIN_STANDARD, /* plugin type */ | |
|
15418
bf287f742a5a
[gaim-migrate @ 18149]
Luke Schierer <lschiere@pidgin.im>
parents:
15230
diff
changeset
|
226 | NULL, /* ui requirement */ |
|
bf287f742a5a
[gaim-migrate @ 18149]
Luke Schierer <lschiere@pidgin.im>
parents:
15230
diff
changeset
|
227 | 0, /* flags */ |
|
bf287f742a5a
[gaim-migrate @ 18149]
Luke Schierer <lschiere@pidgin.im>
parents:
15230
diff
changeset
|
228 | NULL, /* dependencies */ |
| 15884 | 229 | PURPLE_PRIORITY_DEFAULT, /* priority */ |
| 15230 | 230 | |
|
15418
bf287f742a5a
[gaim-migrate @ 18149]
Luke Schierer <lschiere@pidgin.im>
parents:
15230
diff
changeset
|
231 | PLUGIN_ID, /* plugin id */ |
|
bf287f742a5a
[gaim-migrate @ 18149]
Luke Schierer <lschiere@pidgin.im>
parents:
15230
diff
changeset
|
232 | PLUGIN_NAME, /* name */ |
|
20288
5ca925a094e2
applied changes from 03b709ec2a153e7e82719df0ba4635108bb1d3c6
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
19859
diff
changeset
|
233 | DISPLAY_VERSION, /* version */ |
|
15418
bf287f742a5a
[gaim-migrate @ 18149]
Luke Schierer <lschiere@pidgin.im>
parents:
15230
diff
changeset
|
234 | PLUGIN_SUMMARY, /* summary */ |
|
bf287f742a5a
[gaim-migrate @ 18149]
Luke Schierer <lschiere@pidgin.im>
parents:
15230
diff
changeset
|
235 | PLUGIN_DESCRIPTION, /* description */ |
| 15230 | 236 | PLUGIN_AUTHOR, /* author */ |
| 15884 | 237 | PURPLE_WEBSITE, /* website */ |
| 15230 | 238 | |
| 239 | plugin_load, /* load */ | |
| 240 | plugin_unload, /* unload */ | |
|
15418
bf287f742a5a
[gaim-migrate @ 18149]
Luke Schierer <lschiere@pidgin.im>
parents:
15230
diff
changeset
|
241 | NULL, /* destroy */ |
| 15230 | 242 | |
|
15418
bf287f742a5a
[gaim-migrate @ 18149]
Luke Schierer <lschiere@pidgin.im>
parents:
15230
diff
changeset
|
243 | NULL, /* ui_info */ |
|
bf287f742a5a
[gaim-migrate @ 18149]
Luke Schierer <lschiere@pidgin.im>
parents:
15230
diff
changeset
|
244 | NULL, /* extra_info */ |
| 15230 | 245 | &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:
16490
diff
changeset
|
246 | NULL, /* actions */ |
|
df2c3d6b609a
And the rest of the plugins that are compiling for me by default...
Gary Kramlich <grim@reaperworld.com>
parents:
16490
diff
changeset
|
247 | |
|
df2c3d6b609a
And the rest of the plugins that are compiling for me by default...
Gary Kramlich <grim@reaperworld.com>
parents:
16490
diff
changeset
|
248 | /* padding */ |
|
df2c3d6b609a
And the rest of the plugins that are compiling for me by default...
Gary Kramlich <grim@reaperworld.com>
parents:
16490
diff
changeset
|
249 | NULL, |
|
df2c3d6b609a
And the rest of the plugins that are compiling for me by default...
Gary Kramlich <grim@reaperworld.com>
parents:
16490
diff
changeset
|
250 | NULL, |
|
df2c3d6b609a
And the rest of the plugins that are compiling for me by default...
Gary Kramlich <grim@reaperworld.com>
parents:
16490
diff
changeset
|
251 | NULL, |
|
df2c3d6b609a
And the rest of the plugins that are compiling for me by default...
Gary Kramlich <grim@reaperworld.com>
parents:
16490
diff
changeset
|
252 | NULL |
| 15230 | 253 | }; |
| 254 | ||
| 255 | static void | |
| 15884 | 256 | init_plugin(PurplePlugin *plugin) |
| 15230 | 257 | { |
| 15884 | 258 | purple_prefs_add_none(PREF_PREFIX); |
| 259 | purple_prefs_add_bool(PREF_ALWAYS, FALSE); | |
| 15230 | 260 | } |
| 261 | ||
| 15884 | 262 | PURPLE_INIT_PLUGIN(PLUGIN_STATIC_NAME, init_plugin, info) |