Wed, 25 Apr 2007 23:55:56 +0000
Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
| 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 | |
| 17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA | |
| 18 | * 02111-1307, USA. | |
| 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") |
| 15230 | 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 | ||
| 32 | #include <blist.h> | |
| 33 | #include <conversation.h> | |
| 34 | #include <core.h> | |
| 35 | #include <debug.h> | |
| 36 | #include <pounce.h> | |
| 37 | #include <request.h> | |
| 38 | ||
|
16478
19107605c565
Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@pidgin.im>
parents:
15884
diff
changeset
|
39 | #define PREF_PREFIX "/plugins/purple/" 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 | { | |
| 15884 | 70 | purple_conversation_set_data(offline->conv, "plugin_pack:offlinemsg", |
| 15230 | 71 | GINT_TO_POINTER(OFFLINE_MSG_NO)); |
| 15884 | 72 | purple_conv_im_send_with_flags(PURPLE_CONV_IM(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; | |
| 15230 | 83 | |
| 15884 | 84 | event = PURPLE_POUNCE_SIGNON; |
| 85 | option = PURPLE_POUNCE_OPTION_NONE; | |
| 15230 | 86 | |
| 15884 | 87 | pounce = purple_pounce_new(purple_core_get_ui(), offline->account, offline->who, |
| 15230 | 88 | event, option); |
| 89 | ||
| 15884 | 90 | purple_pounce_action_set_enabled(pounce, "send-message", TRUE); |
| 91 | purple_pounce_action_set_attribute(pounce, "send-message", "message", offline->message); | |
| 15230 | 92 | |
| 93 | conv = offline->conv; | |
| 15884 | 94 | if (!purple_conversation_get_data(conv, "plugin_pack:offlinemsg")) |
| 95 | purple_conversation_write(conv, NULL, _("The rest of the messages will be saved " | |
| 15230 | 96 | "as pounce. You can edit/delete the pounce from the `Buddy " |
| 97 | "Pounce' dialog."), | |
| 15884 | 98 | PURPLE_MESSAGE_SYSTEM, time(NULL)); |
| 99 | purple_conversation_set_data(conv, "plugin_pack:offlinemsg", | |
| 15230 | 100 | GINT_TO_POINTER(OFFLINE_MSG_YES)); |
| 101 | ||
| 15884 | 102 | purple_conv_im_write(PURPLE_CONV_IM(conv), offline->who, offline->message, |
| 103 | PURPLE_MESSAGE_SEND, time(NULL)); | |
| 15230 | 104 | |
| 105 | discard_data(offline); | |
| 106 | } | |
| 107 | ||
| 108 | static void | |
| 15884 | 109 | sending_msg_cb(PurpleAccount *account, const char *who, char **message, gpointer handle) |
| 15230 | 110 | { |
| 15884 | 111 | PurpleBuddy *buddy; |
| 15230 | 112 | OfflineMsg *offline; |
| 15884 | 113 | PurpleConversation *conv; |
| 15230 | 114 | OfflineMessageSetting setting; |
| 115 | ||
| 15884 | 116 | buddy = purple_find_buddy(account, who); |
| 15230 | 117 | if (!buddy) |
| 118 | return; | |
| 119 | ||
| 15884 | 120 | if (purple_presence_is_online(purple_buddy_get_presence(buddy))) |
| 15230 | 121 | return; |
| 122 | ||
| 15884 | 123 | if (purple_account_supports_offline_message(account, buddy)) |
| 15230 | 124 | { |
| 15884 | 125 | purple_debug_info("offlinemsg", "Account \"%s\" supports offline message.", |
| 126 | purple_account_get_username(account)); | |
| 15230 | 127 | return; |
| 128 | } | |
| 129 | ||
| 15884 | 130 | conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, |
| 15230 | 131 | who, account); |
| 132 | ||
| 133 | if (!conv) | |
| 134 | return; | |
| 135 | ||
| 15884 | 136 | setting = GPOINTER_TO_INT(purple_conversation_get_data(conv, "plugin_pack:offlinemsg")); |
| 15230 | 137 | if (setting == OFFLINE_MSG_NO) |
| 138 | return; | |
| 139 | ||
| 140 | offline = g_new0(OfflineMsg, 1); | |
| 141 | offline->conv = conv; | |
| 142 | offline->account = account; | |
| 143 | offline->who = g_strdup(who); | |
| 144 | offline->message = *message; | |
| 145 | *message = NULL; | |
| 146 | ||
| 15884 | 147 | if (purple_prefs_get_bool(PREF_ALWAYS) || setting == OFFLINE_MSG_YES) |
| 15230 | 148 | record_pounce(offline); |
| 149 | else if (setting == OFFLINE_MSG_NONE) | |
| 150 | { | |
| 151 | char *ask; | |
| 152 | ask = g_strdup_printf(_("\"%s\" is currently offline. Do you want to save the " | |
| 153 | "rest of the messages in a pounce and automatically send them " | |
| 154 | "when \"%s\" logs back in?"), who, who); | |
| 155 | ||
| 15884 | 156 | purple_request_action(handle, _("Offline Message"), ask, |
| 15230 | 157 | _("You can edit/delete the pounce from the `Buddy Pounces' dialog"), |
| 158 | 1, offline, 2, | |
| 159 | _("Yes"), record_pounce, | |
| 160 | _("No"), cancel_poune); | |
| 161 | g_free(ask); | |
| 162 | } | |
| 163 | } | |
| 164 | ||
| 165 | static gboolean | |
| 15884 | 166 | plugin_load(PurplePlugin *plugin) |
| 15230 | 167 | { |
| 15884 | 168 | purple_signal_connect(purple_conversations_get_handle(), "sending-im-msg", |
| 169 | plugin, PURPLE_CALLBACK(sending_msg_cb), plugin); | |
| 15230 | 170 | return TRUE; |
| 171 | } | |
| 172 | ||
| 173 | static gboolean | |
| 15884 | 174 | plugin_unload(PurplePlugin *plugin) |
| 15230 | 175 | { |
| 176 | return TRUE; | |
| 177 | } | |
| 178 | ||
| 15884 | 179 | static PurplePluginPrefFrame * |
| 180 | get_plugin_pref_frame(PurplePlugin *plugin) | |
| 15230 | 181 | { |
| 15884 | 182 | PurplePluginPrefFrame *frame; |
| 183 | PurplePluginPref *pref; | |
| 15230 | 184 | |
| 15884 | 185 | frame = purple_plugin_pref_frame_new(); |
| 15230 | 186 | |
| 15884 | 187 | pref = purple_plugin_pref_new_with_label(_("Save offline messages in pounce")); |
| 188 | purple_plugin_pref_frame_add(frame, pref); | |
| 15230 | 189 | |
| 15884 | 190 | pref = purple_plugin_pref_new_with_name_and_label(PREF_ALWAYS, |
| 15230 | 191 | _("Do not ask. Always save in pounce.")); |
| 15884 | 192 | purple_plugin_pref_frame_add(frame, pref); |
| 15230 | 193 | |
| 194 | return frame; | |
| 195 | } | |
| 196 | ||
| 15884 | 197 | static PurplePluginUiInfo prefs_info = { |
| 15230 | 198 | get_plugin_pref_frame, |
| 199 | 0, | |
| 200 | NULL | |
| 201 | }; | |
| 202 | ||
| 15884 | 203 | static PurplePluginInfo info = |
| 15230 | 204 | { |
| 15884 | 205 | PURPLE_PLUGIN_MAGIC, /* Magic */ |
| 206 | PURPLE_MAJOR_VERSION, /* Purple Major Version */ | |
| 207 | PURPLE_MINOR_VERSION, /* Purple Minor Version */ | |
| 208 | PURPLE_PLUGIN_STANDARD, /* plugin type */ | |
|
15418
bf287f742a5a
[gaim-migrate @ 18149]
Luke Schierer <lschiere@pidgin.im>
parents:
15230
diff
changeset
|
209 | NULL, /* ui requirement */ |
|
bf287f742a5a
[gaim-migrate @ 18149]
Luke Schierer <lschiere@pidgin.im>
parents:
15230
diff
changeset
|
210 | 0, /* flags */ |
|
bf287f742a5a
[gaim-migrate @ 18149]
Luke Schierer <lschiere@pidgin.im>
parents:
15230
diff
changeset
|
211 | NULL, /* dependencies */ |
| 15884 | 212 | PURPLE_PRIORITY_DEFAULT, /* priority */ |
| 15230 | 213 | |
|
15418
bf287f742a5a
[gaim-migrate @ 18149]
Luke Schierer <lschiere@pidgin.im>
parents:
15230
diff
changeset
|
214 | PLUGIN_ID, /* plugin id */ |
|
bf287f742a5a
[gaim-migrate @ 18149]
Luke Schierer <lschiere@pidgin.im>
parents:
15230
diff
changeset
|
215 | PLUGIN_NAME, /* name */ |
|
bf287f742a5a
[gaim-migrate @ 18149]
Luke Schierer <lschiere@pidgin.im>
parents:
15230
diff
changeset
|
216 | VERSION, /* version */ |
|
bf287f742a5a
[gaim-migrate @ 18149]
Luke Schierer <lschiere@pidgin.im>
parents:
15230
diff
changeset
|
217 | PLUGIN_SUMMARY, /* summary */ |
|
bf287f742a5a
[gaim-migrate @ 18149]
Luke Schierer <lschiere@pidgin.im>
parents:
15230
diff
changeset
|
218 | PLUGIN_DESCRIPTION, /* description */ |
| 15230 | 219 | PLUGIN_AUTHOR, /* author */ |
| 15884 | 220 | PURPLE_WEBSITE, /* website */ |
| 15230 | 221 | |
| 222 | plugin_load, /* load */ | |
| 223 | plugin_unload, /* unload */ | |
|
15418
bf287f742a5a
[gaim-migrate @ 18149]
Luke Schierer <lschiere@pidgin.im>
parents:
15230
diff
changeset
|
224 | NULL, /* destroy */ |
| 15230 | 225 | |
|
15418
bf287f742a5a
[gaim-migrate @ 18149]
Luke Schierer <lschiere@pidgin.im>
parents:
15230
diff
changeset
|
226 | NULL, /* ui_info */ |
|
bf287f742a5a
[gaim-migrate @ 18149]
Luke Schierer <lschiere@pidgin.im>
parents:
15230
diff
changeset
|
227 | NULL, /* extra_info */ |
| 15230 | 228 | &prefs_info, /* prefs_info */ |
|
15418
bf287f742a5a
[gaim-migrate @ 18149]
Luke Schierer <lschiere@pidgin.im>
parents:
15230
diff
changeset
|
229 | NULL /* actions */ |
| 15230 | 230 | }; |
| 231 | ||
| 232 | static void | |
| 15884 | 233 | init_plugin(PurplePlugin *plugin) |
| 15230 | 234 | { |
| 15884 | 235 | purple_prefs_add_none(PREF_PREFIX); |
| 236 | purple_prefs_add_bool(PREF_ALWAYS, FALSE); | |
| 15230 | 237 | } |
| 238 | ||
| 15884 | 239 | PURPLE_INIT_PLUGIN(PLUGIN_STATIC_NAME, init_plugin, info) |