Mercurial > pidgin
comparison libpurple/plugins/offlinemsg.c @ 15822:32c366eeeb99
sed -ie 's/gaim/purple/g'
| author | Sean Egan <seanegan@gmail.com> |
|---|---|
| date | Mon, 19 Mar 2007 07:01:17 +0000 |
| parents | 5fe8042783c1 |
| children | 4999bbc52881 |
comparison
equal
deleted
inserted
replaced
| 15821:84b0f9b23ede | 15822:32c366eeeb99 |
|---|---|
| 24 #define PLUGIN_STATIC_NAME "offlinemsg" | 24 #define PLUGIN_STATIC_NAME "offlinemsg" |
| 25 #define PLUGIN_SUMMARY N_("Save messages sent to an offline user as pounce.") | 25 #define PLUGIN_SUMMARY N_("Save messages sent to an offline user as pounce.") |
| 26 #define PLUGIN_DESCRIPTION N_("Save messages sent to an offline user as pounce.") | 26 #define PLUGIN_DESCRIPTION N_("Save messages sent to an offline user as pounce.") |
| 27 #define PLUGIN_AUTHOR "Sadrul H Chowdhury <sadrul@users.sourceforge.net>" | 27 #define PLUGIN_AUTHOR "Sadrul H Chowdhury <sadrul@users.sourceforge.net>" |
| 28 | 28 |
| 29 /* Gaim headers */ | 29 /* Purple headers */ |
| 30 #include <version.h> | 30 #include <version.h> |
| 31 | 31 |
| 32 #include <blist.h> | 32 #include <blist.h> |
| 33 #include <conversation.h> | 33 #include <conversation.h> |
| 34 #include <core.h> | 34 #include <core.h> |
| 48 OFFLINE_MSG_NO | 48 OFFLINE_MSG_NO |
| 49 } OfflineMessageSetting; | 49 } OfflineMessageSetting; |
| 50 | 50 |
| 51 struct _OfflineMsg | 51 struct _OfflineMsg |
| 52 { | 52 { |
| 53 GaimAccount *account; | 53 PurpleAccount *account; |
| 54 GaimConversation *conv; | 54 PurpleConversation *conv; |
| 55 char *who; | 55 char *who; |
| 56 char *message; | 56 char *message; |
| 57 }; | 57 }; |
| 58 | 58 |
| 59 static void | 59 static void |
| 65 } | 65 } |
| 66 | 66 |
| 67 static void | 67 static void |
| 68 cancel_poune(OfflineMsg *offline) | 68 cancel_poune(OfflineMsg *offline) |
| 69 { | 69 { |
| 70 gaim_conversation_set_data(offline->conv, "plugin_pack:offlinemsg", | 70 purple_conversation_set_data(offline->conv, "plugin_pack:offlinemsg", |
| 71 GINT_TO_POINTER(OFFLINE_MSG_NO)); | 71 GINT_TO_POINTER(OFFLINE_MSG_NO)); |
| 72 gaim_conv_im_send_with_flags(GAIM_CONV_IM(offline->conv), offline->message, 0); | 72 purple_conv_im_send_with_flags(PURPLE_CONV_IM(offline->conv), offline->message, 0); |
| 73 discard_data(offline); | 73 discard_data(offline); |
| 74 } | 74 } |
| 75 | 75 |
| 76 static void | 76 static void |
| 77 record_pounce(OfflineMsg *offline) | 77 record_pounce(OfflineMsg *offline) |
| 78 { | 78 { |
| 79 GaimPounce *pounce; | 79 PurplePounce *pounce; |
| 80 GaimPounceEvent event; | 80 PurplePounceEvent event; |
| 81 GaimPounceOption option; | 81 PurplePounceOption option; |
| 82 GaimConversation *conv; | 82 PurpleConversation *conv; |
| 83 | 83 |
| 84 event = GAIM_POUNCE_SIGNON; | 84 event = PURPLE_POUNCE_SIGNON; |
| 85 option = GAIM_POUNCE_OPTION_NONE; | 85 option = PURPLE_POUNCE_OPTION_NONE; |
| 86 | 86 |
| 87 pounce = gaim_pounce_new(gaim_core_get_ui(), offline->account, offline->who, | 87 pounce = purple_pounce_new(purple_core_get_ui(), offline->account, offline->who, |
| 88 event, option); | 88 event, option); |
| 89 | 89 |
| 90 gaim_pounce_action_set_enabled(pounce, "send-message", TRUE); | 90 purple_pounce_action_set_enabled(pounce, "send-message", TRUE); |
| 91 gaim_pounce_action_set_attribute(pounce, "send-message", "message", offline->message); | 91 purple_pounce_action_set_attribute(pounce, "send-message", "message", offline->message); |
| 92 | 92 |
| 93 conv = offline->conv; | 93 conv = offline->conv; |
| 94 if (!gaim_conversation_get_data(conv, "plugin_pack:offlinemsg")) | 94 if (!purple_conversation_get_data(conv, "plugin_pack:offlinemsg")) |
| 95 gaim_conversation_write(conv, NULL, _("The rest of the messages will be saved " | 95 purple_conversation_write(conv, NULL, _("The rest of the messages will be saved " |
| 96 "as pounce. You can edit/delete the pounce from the `Buddy " | 96 "as pounce. You can edit/delete the pounce from the `Buddy " |
| 97 "Pounce' dialog."), | 97 "Pounce' dialog."), |
| 98 GAIM_MESSAGE_SYSTEM, time(NULL)); | 98 PURPLE_MESSAGE_SYSTEM, time(NULL)); |
| 99 gaim_conversation_set_data(conv, "plugin_pack:offlinemsg", | 99 purple_conversation_set_data(conv, "plugin_pack:offlinemsg", |
| 100 GINT_TO_POINTER(OFFLINE_MSG_YES)); | 100 GINT_TO_POINTER(OFFLINE_MSG_YES)); |
| 101 | 101 |
| 102 gaim_conv_im_write(GAIM_CONV_IM(conv), offline->who, offline->message, | 102 purple_conv_im_write(PURPLE_CONV_IM(conv), offline->who, offline->message, |
| 103 GAIM_MESSAGE_SEND, time(NULL)); | 103 PURPLE_MESSAGE_SEND, time(NULL)); |
| 104 | 104 |
| 105 discard_data(offline); | 105 discard_data(offline); |
| 106 } | 106 } |
| 107 | 107 |
| 108 static void | 108 static void |
| 109 sending_msg_cb(GaimAccount *account, const char *who, char **message, gpointer handle) | 109 sending_msg_cb(PurpleAccount *account, const char *who, char **message, gpointer handle) |
| 110 { | 110 { |
| 111 GaimBuddy *buddy; | 111 PurpleBuddy *buddy; |
| 112 OfflineMsg *offline; | 112 OfflineMsg *offline; |
| 113 GaimConversation *conv; | 113 PurpleConversation *conv; |
| 114 OfflineMessageSetting setting; | 114 OfflineMessageSetting setting; |
| 115 | 115 |
| 116 buddy = gaim_find_buddy(account, who); | 116 buddy = purple_find_buddy(account, who); |
| 117 if (!buddy) | 117 if (!buddy) |
| 118 return; | 118 return; |
| 119 | 119 |
| 120 if (gaim_presence_is_online(gaim_buddy_get_presence(buddy))) | 120 if (purple_presence_is_online(purple_buddy_get_presence(buddy))) |
| 121 return; | 121 return; |
| 122 | 122 |
| 123 if (gaim_account_supports_offline_message(account, buddy)) | 123 if (purple_account_supports_offline_message(account, buddy)) |
| 124 { | 124 { |
| 125 gaim_debug_info("offlinemsg", "Account \"%s\" supports offline message.", | 125 purple_debug_info("offlinemsg", "Account \"%s\" supports offline message.", |
| 126 gaim_account_get_username(account)); | 126 purple_account_get_username(account)); |
| 127 return; | 127 return; |
| 128 } | 128 } |
| 129 | 129 |
| 130 conv = gaim_find_conversation_with_account(GAIM_CONV_TYPE_IM, | 130 conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, |
| 131 who, account); | 131 who, account); |
| 132 | 132 |
| 133 if (!conv) | 133 if (!conv) |
| 134 return; | 134 return; |
| 135 | 135 |
| 136 setting = GPOINTER_TO_INT(gaim_conversation_get_data(conv, "plugin_pack:offlinemsg")); | 136 setting = GPOINTER_TO_INT(purple_conversation_get_data(conv, "plugin_pack:offlinemsg")); |
| 137 if (setting == OFFLINE_MSG_NO) | 137 if (setting == OFFLINE_MSG_NO) |
| 138 return; | 138 return; |
| 139 | 139 |
| 140 offline = g_new0(OfflineMsg, 1); | 140 offline = g_new0(OfflineMsg, 1); |
| 141 offline->conv = conv; | 141 offline->conv = conv; |
| 142 offline->account = account; | 142 offline->account = account; |
| 143 offline->who = g_strdup(who); | 143 offline->who = g_strdup(who); |
| 144 offline->message = *message; | 144 offline->message = *message; |
| 145 *message = NULL; | 145 *message = NULL; |
| 146 | 146 |
| 147 if (gaim_prefs_get_bool(PREF_ALWAYS) || setting == OFFLINE_MSG_YES) | 147 if (purple_prefs_get_bool(PREF_ALWAYS) || setting == OFFLINE_MSG_YES) |
| 148 record_pounce(offline); | 148 record_pounce(offline); |
| 149 else if (setting == OFFLINE_MSG_NONE) | 149 else if (setting == OFFLINE_MSG_NONE) |
| 150 { | 150 { |
| 151 char *ask; | 151 char *ask; |
| 152 ask = g_strdup_printf(_("\"%s\" is currently offline. Do you want to save the " | 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 " | 153 "rest of the messages in a pounce and automatically send them " |
| 154 "when \"%s\" logs back in?"), who, who); | 154 "when \"%s\" logs back in?"), who, who); |
| 155 | 155 |
| 156 gaim_request_action(handle, _("Offline Message"), ask, | 156 purple_request_action(handle, _("Offline Message"), ask, |
| 157 _("You can edit/delete the pounce from the `Buddy Pounces' dialog"), | 157 _("You can edit/delete the pounce from the `Buddy Pounces' dialog"), |
| 158 1, offline, 2, | 158 1, offline, 2, |
| 159 _("Yes"), record_pounce, | 159 _("Yes"), record_pounce, |
| 160 _("No"), cancel_poune); | 160 _("No"), cancel_poune); |
| 161 g_free(ask); | 161 g_free(ask); |
| 162 } | 162 } |
| 163 } | 163 } |
| 164 | 164 |
| 165 static gboolean | 165 static gboolean |
| 166 plugin_load(GaimPlugin *plugin) | 166 plugin_load(PurplePlugin *plugin) |
| 167 { | 167 { |
| 168 gaim_signal_connect(gaim_conversations_get_handle(), "sending-im-msg", | 168 purple_signal_connect(purple_conversations_get_handle(), "sending-im-msg", |
| 169 plugin, GAIM_CALLBACK(sending_msg_cb), plugin); | 169 plugin, PURPLE_CALLBACK(sending_msg_cb), plugin); |
| 170 return TRUE; | 170 return TRUE; |
| 171 } | 171 } |
| 172 | 172 |
| 173 static gboolean | 173 static gboolean |
| 174 plugin_unload(GaimPlugin *plugin) | 174 plugin_unload(PurplePlugin *plugin) |
| 175 { | 175 { |
| 176 return TRUE; | 176 return TRUE; |
| 177 } | 177 } |
| 178 | 178 |
| 179 static GaimPluginPrefFrame * | 179 static PurplePluginPrefFrame * |
| 180 get_plugin_pref_frame(GaimPlugin *plugin) | 180 get_plugin_pref_frame(PurplePlugin *plugin) |
| 181 { | 181 { |
| 182 GaimPluginPrefFrame *frame; | 182 PurplePluginPrefFrame *frame; |
| 183 GaimPluginPref *pref; | 183 PurplePluginPref *pref; |
| 184 | 184 |
| 185 frame = gaim_plugin_pref_frame_new(); | 185 frame = purple_plugin_pref_frame_new(); |
| 186 | 186 |
| 187 pref = gaim_plugin_pref_new_with_label(_("Save offline messages in pounce")); | 187 pref = purple_plugin_pref_new_with_label(_("Save offline messages in pounce")); |
| 188 gaim_plugin_pref_frame_add(frame, pref); | 188 purple_plugin_pref_frame_add(frame, pref); |
| 189 | 189 |
| 190 pref = gaim_plugin_pref_new_with_name_and_label(PREF_ALWAYS, | 190 pref = purple_plugin_pref_new_with_name_and_label(PREF_ALWAYS, |
| 191 _("Do not ask. Always save in pounce.")); | 191 _("Do not ask. Always save in pounce.")); |
| 192 gaim_plugin_pref_frame_add(frame, pref); | 192 purple_plugin_pref_frame_add(frame, pref); |
| 193 | 193 |
| 194 return frame; | 194 return frame; |
| 195 } | 195 } |
| 196 | 196 |
| 197 static GaimPluginUiInfo prefs_info = { | 197 static PurplePluginUiInfo prefs_info = { |
| 198 get_plugin_pref_frame, | 198 get_plugin_pref_frame, |
| 199 0, | 199 0, |
| 200 NULL | 200 NULL |
| 201 }; | 201 }; |
| 202 | 202 |
| 203 static GaimPluginInfo info = | 203 static PurplePluginInfo info = |
| 204 { | 204 { |
| 205 GAIM_PLUGIN_MAGIC, /* Magic */ | 205 PURPLE_PLUGIN_MAGIC, /* Magic */ |
| 206 GAIM_MAJOR_VERSION, /* Gaim Major Version */ | 206 PURPLE_MAJOR_VERSION, /* Purple Major Version */ |
| 207 GAIM_MINOR_VERSION, /* Gaim Minor Version */ | 207 PURPLE_MINOR_VERSION, /* Purple Minor Version */ |
| 208 GAIM_PLUGIN_STANDARD, /* plugin type */ | 208 PURPLE_PLUGIN_STANDARD, /* plugin type */ |
| 209 NULL, /* ui requirement */ | 209 NULL, /* ui requirement */ |
| 210 0, /* flags */ | 210 0, /* flags */ |
| 211 NULL, /* dependencies */ | 211 NULL, /* dependencies */ |
| 212 GAIM_PRIORITY_DEFAULT, /* priority */ | 212 PURPLE_PRIORITY_DEFAULT, /* priority */ |
| 213 | 213 |
| 214 PLUGIN_ID, /* plugin id */ | 214 PLUGIN_ID, /* plugin id */ |
| 215 PLUGIN_NAME, /* name */ | 215 PLUGIN_NAME, /* name */ |
| 216 VERSION, /* version */ | 216 VERSION, /* version */ |
| 217 PLUGIN_SUMMARY, /* summary */ | 217 PLUGIN_SUMMARY, /* summary */ |
| 218 PLUGIN_DESCRIPTION, /* description */ | 218 PLUGIN_DESCRIPTION, /* description */ |
| 219 PLUGIN_AUTHOR, /* author */ | 219 PLUGIN_AUTHOR, /* author */ |
| 220 GAIM_WEBSITE, /* website */ | 220 PURPLE_WEBSITE, /* website */ |
| 221 | 221 |
| 222 plugin_load, /* load */ | 222 plugin_load, /* load */ |
| 223 plugin_unload, /* unload */ | 223 plugin_unload, /* unload */ |
| 224 NULL, /* destroy */ | 224 NULL, /* destroy */ |
| 225 | 225 |
| 228 &prefs_info, /* prefs_info */ | 228 &prefs_info, /* prefs_info */ |
| 229 NULL /* actions */ | 229 NULL /* actions */ |
| 230 }; | 230 }; |
| 231 | 231 |
| 232 static void | 232 static void |
| 233 init_plugin(GaimPlugin *plugin) | 233 init_plugin(PurplePlugin *plugin) |
| 234 { | 234 { |
| 235 gaim_prefs_add_none(PREF_PREFIX); | 235 purple_prefs_add_none(PREF_PREFIX); |
| 236 gaim_prefs_add_bool(PREF_ALWAYS, FALSE); | 236 purple_prefs_add_bool(PREF_ALWAYS, FALSE); |
| 237 } | 237 } |
| 238 | 238 |
| 239 GAIM_INIT_PLUGIN(PLUGIN_STATIC_NAME, init_plugin, info) | 239 PURPLE_INIT_PLUGIN(PLUGIN_STATIC_NAME, init_plugin, info) |
