Thu, 24 Oct 2013 23:56:44 +0530
Merged soc.2013.gobjectification branch
| 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") |
|
36747
0b84912ce764
Refactored rest of libpurple C plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
34940
diff
changeset
|
24 | #define PLUGIN_CATEGORY N_("Utility") |
|
25633
feee0c7e503f
Fix some more mis-identified plugins, like 3b3526a0...
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
22268
diff
changeset
|
25 | #define PLUGIN_STATIC_NAME offlinemsg |
|
15418
bf287f742a5a
[gaim-migrate @ 18149]
Luke Schierer <lschiere@pidgin.im>
parents:
15230
diff
changeset
|
26 | #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
|
27 | #define PLUGIN_DESCRIPTION N_("Save messages sent to an offline user as pounce.") |
|
36747
0b84912ce764
Refactored rest of libpurple C plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
34940
diff
changeset
|
28 | #define PLUGIN_AUTHORS {"Sadrul H Chowdhury <sadrul@users.sourceforge.net>", NULL} |
| 15230 | 29 | |
| 15884 | 30 | /* Purple headers */ |
| 15230 | 31 | #include <version.h> |
| 32 | ||
|
34706
02cb08146888
Renamed blist.[ch] to buddylist.[ch]
Ankit Vani <a@nevitus.org>
parents:
34678
diff
changeset
|
33 | #include <buddylist.h> |
| 15230 | 34 | #include <conversation.h> |
| 35 | #include <core.h> | |
| 36 | #include <debug.h> | |
| 37 | #include <pounce.h> | |
| 38 | #include <request.h> | |
| 39 | ||
| 16481 | 40 | #define PREF_PREFIX "/plugins/core/" PLUGIN_ID |
| 15230 | 41 | #define PREF_ALWAYS PREF_PREFIX "/always" |
| 42 | ||
| 43 | typedef struct _OfflineMsg OfflineMsg; | |
| 44 | ||
| 45 | typedef enum | |
| 46 | { | |
| 47 | OFFLINE_MSG_NONE, | |
| 48 | OFFLINE_MSG_YES, | |
| 49 | OFFLINE_MSG_NO | |
| 50 | } OfflineMessageSetting; | |
| 51 | ||
| 52 | struct _OfflineMsg | |
| 53 | { | |
| 15884 | 54 | PurpleAccount *account; |
| 55 | PurpleConversation *conv; | |
| 15230 | 56 | char *who; |
| 57 | char *message; | |
| 58 | }; | |
| 59 | ||
| 60 | static void | |
| 61 | discard_data(OfflineMsg *offline) | |
| 62 | { | |
| 63 | g_free(offline->who); | |
| 64 | g_free(offline->message); | |
| 65 | g_free(offline); | |
| 66 | } | |
| 67 | ||
| 68 | static void | |
| 69 | cancel_poune(OfflineMsg *offline) | |
| 70 | { | |
|
34678
40a30f74a7b8
Removed purple_conversation_[gs]et_data(). Used g_object_[gs]et_data() instead.
Ankit Vani <a@nevitus.org>
parents:
34652
diff
changeset
|
71 | g_object_set_data(G_OBJECT(offline->conv), "plugin_pack:offlinemsg", |
| 15230 | 72 | GINT_TO_POINTER(OFFLINE_MSG_NO)); |
|
34652
65a6bfb86d43
Updated libpurple plugins with the API changes
Ankit Vani <a@nevitus.org>
parents:
34632
diff
changeset
|
73 | purple_conversation_send_with_flags(offline->conv, offline->message, 0); |
| 15230 | 74 | discard_data(offline); |
| 75 | } | |
| 76 | ||
| 77 | static void | |
| 78 | record_pounce(OfflineMsg *offline) | |
| 79 | { | |
| 15884 | 80 | PurplePounce *pounce; |
| 81 | PurplePounceEvent event; | |
| 82 | PurplePounceOption option; | |
| 83 | 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
|
84 | char *temp; |
| 15230 | 85 | |
| 15884 | 86 | event = PURPLE_POUNCE_SIGNON; |
| 87 | option = PURPLE_POUNCE_OPTION_NONE; | |
| 15230 | 88 | |
| 15884 | 89 | pounce = purple_pounce_new(purple_core_get_ui(), offline->account, offline->who, |
| 15230 | 90 | event, option); |
| 91 | ||
| 15884 | 92 | 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
|
93 | |
|
d6ad5be6427a
The Offline Message Emulation plugin now adds a note that the message
Mark Doliner <markdoliner@pidgin.im>
parents:
31294
diff
changeset
|
94 | 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
|
95 | offline->message); |
|
d6ad5be6427a
The Offline Message Emulation plugin now adds a note that the message
Mark Doliner <markdoliner@pidgin.im>
parents:
31294
diff
changeset
|
96 | 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
|
97 | temp); |
|
d6ad5be6427a
The Offline Message Emulation plugin now adds a note that the message
Mark Doliner <markdoliner@pidgin.im>
parents:
31294
diff
changeset
|
98 | g_free(temp); |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
27525
diff
changeset
|
99 | |
| 15230 | 100 | 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
|
101 | if (!g_object_get_data(G_OBJECT(conv), "plugin_pack:offlinemsg")) |
| 15884 | 102 | 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
|
103 | "as pounces. You can edit/delete the pounce from the `Buddy " |
| 15230 | 104 | "Pounce' dialog."), |
| 15884 | 105 | 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
|
106 | g_object_set_data(G_OBJECT(conv), "plugin_pack:offlinemsg", |
| 15230 | 107 | GINT_TO_POINTER(OFFLINE_MSG_YES)); |
| 108 | ||
|
34628
014583658b51
Refactored libpurple/plugins to use the GObject-based PurpleConversation
Ankit Vani <a@nevitus.org>
parents:
34626
diff
changeset
|
109 | purple_conversation_write_message(conv, offline->who, offline->message, |
| 15884 | 110 | PURPLE_MESSAGE_SEND, time(NULL)); |
| 15230 | 111 | |
| 112 | discard_data(offline); | |
| 113 | } | |
| 114 | ||
| 115 | static void | |
| 15884 | 116 | sending_msg_cb(PurpleAccount *account, const char *who, char **message, gpointer handle) |
| 15230 | 117 | { |
| 15884 | 118 | PurpleBuddy *buddy; |
| 15230 | 119 | OfflineMsg *offline; |
| 15884 | 120 | PurpleConversation *conv; |
| 15230 | 121 | OfflineMessageSetting setting; |
| 122 | ||
|
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
|
123 | 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
|
124 | **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
|
125 | 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
|
126 | |
|
34728
8efd73063ecf
Renamed buddy list functions to more appropriate/simler names.
Ankit Vani <a@nevitus.org>
parents:
34706
diff
changeset
|
127 | buddy = purple_blist_find_buddy(account, who); |
| 15230 | 128 | if (!buddy) |
| 129 | return; | |
| 130 | ||
| 15884 | 131 | if (purple_presence_is_online(purple_buddy_get_presence(buddy))) |
| 15230 | 132 | return; |
| 133 | ||
| 15884 | 134 | if (purple_account_supports_offline_message(account, buddy)) |
| 15230 | 135 | { |
|
19832
84b69b21672b
Patch from QuLogic. Fixes #2903 ('Missing newlines in debug messages.')
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
19825
diff
changeset
|
136 | purple_debug_info("offlinemsg", "Account \"%s\" supports offline messages.\n", |
| 15884 | 137 | purple_account_get_username(account)); |
| 15230 | 138 | return; |
| 139 | } | |
| 140 | ||
|
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
|
141 | conv = PURPLE_CONVERSATION(purple_conversations_find_im_with_account(who, account)); |
| 15230 | 142 | |
| 143 | if (!conv) | |
| 144 | return; | |
| 145 | ||
|
34678
40a30f74a7b8
Removed purple_conversation_[gs]et_data(). Used g_object_[gs]et_data() instead.
Ankit Vani <a@nevitus.org>
parents:
34652
diff
changeset
|
146 | setting = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(conv), "plugin_pack:offlinemsg")); |
| 15230 | 147 | if (setting == OFFLINE_MSG_NO) |
| 148 | return; | |
| 149 | ||
| 150 | offline = g_new0(OfflineMsg, 1); | |
| 151 | offline->conv = conv; | |
| 152 | offline->account = account; | |
| 153 | offline->who = g_strdup(who); | |
| 154 | offline->message = *message; | |
| 155 | *message = NULL; | |
| 156 | ||
| 15884 | 157 | if (purple_prefs_get_bool(PREF_ALWAYS) || setting == OFFLINE_MSG_YES) |
| 15230 | 158 | record_pounce(offline); |
| 159 | else if (setting == OFFLINE_MSG_NONE) | |
| 160 | { | |
| 161 | char *ask; | |
| 162 | ask = g_strdup_printf(_("\"%s\" is currently offline. Do you want to save the " | |
| 163 | "rest of the messages in a pounce and automatically send them " | |
| 164 | "when \"%s\" logs back in?"), who, who); | |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
27525
diff
changeset
|
165 | |
|
21175
c6d76b49c206
disapproval of revision '8ba833993a115415727bb1b70362e0bd1603c169'
Richard Laager <rlaager@pidgin.im>
parents:
21174
diff
changeset
|
166 | purple_request_action(handle, _("Offline Message"), ask, |
| 15230 | 167 | _("You can edit/delete the pounce from the `Buddy Pounces' dialog"), |
|
34331
c8486462bb63
Request API refactoring: switch purple_request_action to PurpleRequestCommonParameters
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
32971
diff
changeset
|
168 | 0, purple_request_cpar_from_conversation(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 | ||
| 15884 | 176 | static PurplePluginPrefFrame * |
| 177 | get_plugin_pref_frame(PurplePlugin *plugin) | |
| 15230 | 178 | { |
| 15884 | 179 | PurplePluginPrefFrame *frame; |
| 180 | PurplePluginPref *pref; | |
| 15230 | 181 | |
| 15884 | 182 | frame = purple_plugin_pref_frame_new(); |
| 15230 | 183 | |
| 15884 | 184 | pref = purple_plugin_pref_new_with_label(_("Save offline messages in pounce")); |
| 185 | purple_plugin_pref_frame_add(frame, pref); | |
| 15230 | 186 | |
| 15884 | 187 | pref = purple_plugin_pref_new_with_name_and_label(PREF_ALWAYS, |
| 15230 | 188 | _("Do not ask. Always save in pounce.")); |
| 15884 | 189 | purple_plugin_pref_frame_add(frame, pref); |
| 15230 | 190 | |
| 191 | return frame; | |
| 192 | } | |
| 193 | ||
|
36747
0b84912ce764
Refactored rest of libpurple C plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
34940
diff
changeset
|
194 | static PurplePluginInfo * |
|
0b84912ce764
Refactored rest of libpurple C plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
34940
diff
changeset
|
195 | plugin_query(GError **error) |
| 15230 | 196 | { |
|
36747
0b84912ce764
Refactored rest of libpurple C plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
34940
diff
changeset
|
197 | const gchar * const authors[] = PLUGIN_AUTHORS; |
| 15230 | 198 | |
|
36747
0b84912ce764
Refactored rest of libpurple C plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
34940
diff
changeset
|
199 | return purple_plugin_info_new( |
|
0b84912ce764
Refactored rest of libpurple C plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
34940
diff
changeset
|
200 | "id", PLUGIN_ID, |
|
0b84912ce764
Refactored rest of libpurple C plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
34940
diff
changeset
|
201 | "name", PLUGIN_NAME, |
|
0b84912ce764
Refactored rest of libpurple C plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
34940
diff
changeset
|
202 | "version", DISPLAY_VERSION, |
|
0b84912ce764
Refactored rest of libpurple C plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
34940
diff
changeset
|
203 | "category", PLUGIN_CATEGORY, |
|
0b84912ce764
Refactored rest of libpurple C plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
34940
diff
changeset
|
204 | "summary", PLUGIN_SUMMARY, |
|
0b84912ce764
Refactored rest of libpurple C plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
34940
diff
changeset
|
205 | "description", PLUGIN_DESCRIPTION, |
|
0b84912ce764
Refactored rest of libpurple C plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
34940
diff
changeset
|
206 | "authors", authors, |
|
0b84912ce764
Refactored rest of libpurple C plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
34940
diff
changeset
|
207 | "website", PURPLE_WEBSITE, |
|
0b84912ce764
Refactored rest of libpurple C plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
34940
diff
changeset
|
208 | "abi-version", PURPLE_ABI_VERSION, |
|
0b84912ce764
Refactored rest of libpurple C plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
34940
diff
changeset
|
209 | "preferences-frame", get_plugin_pref_frame, |
|
0b84912ce764
Refactored rest of libpurple C plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
34940
diff
changeset
|
210 | NULL |
|
0b84912ce764
Refactored rest of libpurple C plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
34940
diff
changeset
|
211 | ); |
|
0b84912ce764
Refactored rest of libpurple C plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
34940
diff
changeset
|
212 | } |
| 15230 | 213 | |
|
36747
0b84912ce764
Refactored rest of libpurple C plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
34940
diff
changeset
|
214 | static gboolean |
|
0b84912ce764
Refactored rest of libpurple C plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
34940
diff
changeset
|
215 | plugin_load(PurplePlugin *plugin, GError **error) |
| 15230 | 216 | { |
| 15884 | 217 | purple_prefs_add_none(PREF_PREFIX); |
| 218 | purple_prefs_add_bool(PREF_ALWAYS, FALSE); | |
|
36747
0b84912ce764
Refactored rest of libpurple C plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
34940
diff
changeset
|
219 | |
|
0b84912ce764
Refactored rest of libpurple C plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
34940
diff
changeset
|
220 | purple_signal_connect_priority(purple_conversations_get_handle(), "sending-im-msg", |
|
0b84912ce764
Refactored rest of libpurple C plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
34940
diff
changeset
|
221 | plugin, PURPLE_CALLBACK(sending_msg_cb), plugin, PURPLE_SIGNAL_PRIORITY_HIGHEST); |
|
0b84912ce764
Refactored rest of libpurple C plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
34940
diff
changeset
|
222 | return TRUE; |
| 15230 | 223 | } |
| 224 | ||
|
36747
0b84912ce764
Refactored rest of libpurple C plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
34940
diff
changeset
|
225 | static gboolean |
|
0b84912ce764
Refactored rest of libpurple C plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
34940
diff
changeset
|
226 | plugin_unload(PurplePlugin *plugin, GError **error) |
|
0b84912ce764
Refactored rest of libpurple C plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
34940
diff
changeset
|
227 | { |
|
0b84912ce764
Refactored rest of libpurple C plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
34940
diff
changeset
|
228 | return TRUE; |
|
0b84912ce764
Refactored rest of libpurple C plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
34940
diff
changeset
|
229 | } |
|
0b84912ce764
Refactored rest of libpurple C plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
34940
diff
changeset
|
230 | |
|
0b84912ce764
Refactored rest of libpurple C plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
34940
diff
changeset
|
231 | PURPLE_PLUGIN_INIT(PLUGIN_STATIC_NAME, plugin_query, plugin_load, plugin_unload); |