2 * Offline Message Emulation - Save messages sent to an offline user as pounce
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.
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.
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., 51 Franklin Street, Fifth Floor, Boston, MA
22 #define PLUGIN_ID "core-plugin_pack-offlinemsg"
23 #define PLUGIN_NAME N_("Offline Message Emulation")
24 #define PLUGIN_CATEGORY N_("Utility")
25 #define PLUGIN_STATIC_NAME offlinemsg
26 #define PLUGIN_SUMMARY N_("Save messages sent to an offline user as pounce.")
27 #define PLUGIN_DESCRIPTION N_("Save messages sent to an offline user as pounce.")
28 #define PLUGIN_AUTHORS {"Sadrul H Chowdhury <sadrul@users.sourceforge.net>", NULL}
33 #include <buddylist.h>
34 #include <conversation.h>
40 #define PREF_PREFIX "/plugins/core/" PLUGIN_ID
41 #define PREF_ALWAYS PREF_PREFIX "/always"
43 typedef struct _OfflineMsg OfflineMsg
;
50 } OfflineMessageSetting
;
54 PurpleAccount
*account
;
55 PurpleConversation
*conv
;
61 discard_data(OfflineMsg
*offline
)
64 g_free(offline
->message
);
69 cancel_poune(OfflineMsg
*offline
)
71 g_object_set_data(G_OBJECT(offline
->conv
), "plugin_pack:offlinemsg",
72 GINT_TO_POINTER(OFFLINE_MSG_NO
));
73 purple_conversation_send_with_flags(offline
->conv
, offline
->message
, 0);
74 discard_data(offline
);
78 record_pounce(OfflineMsg
*offline
)
81 PurplePounceEvent event
;
82 PurplePounceOption option
;
83 PurpleConversation
*conv
;
86 event
= PURPLE_POUNCE_SIGNON
;
87 option
= PURPLE_POUNCE_OPTION_NONE
;
89 pounce
= purple_pounce_new(purple_core_get_ui(), offline
->account
, offline
->who
,
92 purple_pounce_action_set_enabled(pounce
, "send-message", TRUE
);
94 temp
= g_strdup_printf("(%s) %s", _("Offline message"),
96 purple_pounce_action_set_attribute(pounce
, "send-message", "message",
100 conv
= offline
->conv
;
101 if (!g_object_get_data(G_OBJECT(conv
), "plugin_pack:offlinemsg")) {
102 purple_conversation_write_system_message(conv
,
103 _("The rest of the messages will be saved "
104 "as pounces. You can edit/delete the pounce from the `Buddy "
105 "Pounce' dialog."), 0);
107 g_object_set_data(G_OBJECT(conv
), "plugin_pack:offlinemsg",
108 GINT_TO_POINTER(OFFLINE_MSG_YES
));
110 /* TODO: use a reference to a PurpleMessage */
111 purple_conversation_write_message(conv
,
112 purple_message_new_outgoing(offline
->who
, offline
->message
, 0));
114 discard_data(offline
);
118 sending_msg_cb(PurpleAccount
*account
, PurpleMessage
*msg
, gpointer handle
)
122 PurpleConversation
*conv
;
123 OfflineMessageSetting setting
;
124 const gchar
*who
= purple_message_get_recipient(msg
);
126 if (purple_message_is_empty(msg
))
129 buddy
= purple_blist_find_buddy(account
, who
);
133 if (purple_presence_is_online(purple_buddy_get_presence(buddy
)))
136 if (purple_account_supports_offline_message(account
, buddy
))
138 purple_debug_info("offlinemsg", "Account \"%s\" supports offline messages.\n",
139 purple_account_get_username(account
));
143 conv
= PURPLE_CONVERSATION(purple_conversations_find_im_with_account(who
, account
));
148 setting
= GPOINTER_TO_INT(g_object_get_data(G_OBJECT(conv
), "plugin_pack:offlinemsg"));
149 if (setting
== OFFLINE_MSG_NO
)
152 offline
= g_new0(OfflineMsg
, 1);
153 offline
->conv
= conv
;
154 offline
->account
= account
;
155 offline
->who
= g_strdup(who
);
156 offline
->message
= g_strdup(purple_message_get_contents(msg
));
157 purple_message_set_contents(msg
, NULL
);
159 if (purple_prefs_get_bool(PREF_ALWAYS
) || setting
== OFFLINE_MSG_YES
)
160 record_pounce(offline
);
161 else if (setting
== OFFLINE_MSG_NONE
)
164 ask
= g_strdup_printf(_("\"%s\" is currently offline. Do you want to save the "
165 "rest of the messages in a pounce and automatically send them "
166 "when \"%s\" logs back in?"), who
, who
);
168 purple_request_action(handle
, _("Offline Message"), ask
,
169 _("You can edit/delete the pounce from the `Buddy Pounces' dialog"),
170 0, purple_request_cpar_from_conversation(offline
->conv
),
172 _("Yes"), record_pounce
,
173 _("No"), cancel_poune
);
178 static PurplePluginPrefFrame
*
179 get_plugin_pref_frame(PurplePlugin
*plugin
)
181 PurplePluginPrefFrame
*frame
;
182 PurplePluginPref
*pref
;
184 frame
= purple_plugin_pref_frame_new();
186 pref
= purple_plugin_pref_new_with_label(_("Save offline messages in pounce"));
187 purple_plugin_pref_frame_add(frame
, pref
);
189 pref
= purple_plugin_pref_new_with_name_and_label(PREF_ALWAYS
,
190 _("Do not ask. Always save in pounce."));
191 purple_plugin_pref_frame_add(frame
, pref
);
196 static PurplePluginInfo
*
197 plugin_query(GError
**error
)
199 const gchar
* const authors
[] = PLUGIN_AUTHORS
;
201 return purple_plugin_info_new(
204 "version", DISPLAY_VERSION
,
205 "category", PLUGIN_CATEGORY
,
206 "summary", PLUGIN_SUMMARY
,
207 "description", PLUGIN_DESCRIPTION
,
209 "website", PURPLE_WEBSITE
,
210 "abi-version", PURPLE_ABI_VERSION
,
211 "pref-frame-cb", get_plugin_pref_frame
,
217 plugin_load(PurplePlugin
*plugin
, GError
**error
)
219 purple_prefs_add_none(PREF_PREFIX
);
220 purple_prefs_add_bool(PREF_ALWAYS
, FALSE
);
222 purple_signal_connect_priority(purple_conversations_get_handle(), "sending-im-msg",
223 plugin
, PURPLE_CALLBACK(sending_msg_cb
), plugin
, PURPLE_SIGNAL_PRIORITY_HIGHEST
);
228 plugin_unload(PurplePlugin
*plugin
, GError
**error
)
233 PURPLE_PLUGIN_INIT(PLUGIN_STATIC_NAME
, plugin_query
, plugin_load
, plugin_unload
);