15168
|
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"
|
|
23 #define PLUGIN_NAME "Offline Message Emulation"
|
|
24 #define PLUGIN_STATIC_NAME "offlinemsg"
|
|
25 #define PLUGIN_SUMMARY "Save messages sent to an offline user as pounce."
|
|
26 #define PLUGIN_DESCRIPTION "Save messages sent to an offline user as pounce."
|
|
27 #define PLUGIN_AUTHOR "Sadrul H Chowdhury <sadrul@users.sourceforge.net>"
|
|
28
|
|
29 /* Gaim headers */
|
|
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
|
|
39 #define PREF_PREFIX "/plugins/core/" PLUGIN_ID
|
|
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 {
|
|
53 GaimAccount *account;
|
|
54 GaimConversation *conv;
|
|
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 {
|
|
70 gaim_conversation_set_data(offline->conv, "plugin_pack:offlinemsg",
|
|
71 GINT_TO_POINTER(OFFLINE_MSG_NO));
|
|
72 gaim_conv_im_send_with_flags(GAIM_CONV_IM(offline->conv), offline->message, 0);
|
|
73 discard_data(offline);
|
|
74 }
|
|
75
|
|
76 static void
|
|
77 record_pounce(OfflineMsg *offline)
|
|
78 {
|
|
79 GaimPounce *pounce;
|
|
80 GaimPounceEvent event;
|
|
81 GaimPounceOption option;
|
|
82 GaimConversation *conv;
|
|
83
|
|
84 event = GAIM_POUNCE_SIGNON;
|
|
85 option = GAIM_POUNCE_OPTION_NONE;
|
|
86
|
|
87 pounce = gaim_pounce_new(gaim_core_get_ui(), offline->account, offline->who,
|
|
88 event, option);
|
|
89
|
|
90 gaim_pounce_action_set_enabled(pounce, "send-message", TRUE);
|
|
91 gaim_pounce_action_set_attribute(pounce, "send-message", "message", offline->message);
|
|
92
|
|
93 conv = offline->conv;
|
|
94 if (!gaim_conversation_get_data(conv, "plugin_pack:offlinemsg"))
|
|
95 gaim_conversation_write(conv, NULL, _("The rest of the messages will be saved "
|
|
96 "as pounce. You can edit/delete the pounce from the `Buddy "
|
|
97 "Pounce' dialog."),
|
|
98 GAIM_MESSAGE_SYSTEM, time(NULL));
|
|
99 gaim_conversation_set_data(conv, "plugin_pack:offlinemsg",
|
|
100 GINT_TO_POINTER(OFFLINE_MSG_YES));
|
|
101
|
|
102 gaim_conv_im_write(GAIM_CONV_IM(conv), offline->who, offline->message,
|
|
103 GAIM_MESSAGE_SEND, time(NULL));
|
|
104
|
|
105 discard_data(offline);
|
|
106 }
|
|
107
|
|
108 static void
|
|
109 sending_msg_cb(GaimAccount *account, const char *who, char **message, gpointer handle)
|
|
110 {
|
|
111 GaimBuddy *buddy;
|
|
112 OfflineMsg *offline;
|
|
113 GaimConversation *conv;
|
|
114 OfflineMessageSetting setting;
|
|
115
|
|
116 buddy = gaim_find_buddy(account, who);
|
|
117 if (!buddy)
|
|
118 return;
|
|
119
|
|
120 if (gaim_presence_is_online(gaim_buddy_get_presence(buddy)))
|
|
121 return;
|
|
122
|
|
123 if (gaim_account_supports_offline_message(account, buddy))
|
|
124 {
|
|
125 gaim_debug_info("offlinemsg", "Account \"%s\" supports offline message.",
|
|
126 gaim_account_get_username(account));
|
|
127 return;
|
|
128 }
|
|
129
|
|
130 conv = gaim_find_conversation_with_account(GAIM_CONV_TYPE_IM,
|
|
131 who, account);
|
|
132
|
|
133 if (!conv)
|
|
134 return;
|
|
135
|
|
136 setting = GPOINTER_TO_INT(gaim_conversation_get_data(conv, "plugin_pack:offlinemsg"));
|
|
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
|
|
147 if (gaim_prefs_get_bool(PREF_ALWAYS) || setting == OFFLINE_MSG_YES)
|
|
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
|
|
156 gaim_request_action(handle, _("Offline Message"), ask,
|
|
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
|
|
166 plugin_load(GaimPlugin *plugin)
|
|
167 {
|
|
168 gaim_signal_connect(gaim_conversations_get_handle(), "sending-im-msg",
|
|
169 plugin, GAIM_CALLBACK(sending_msg_cb), plugin);
|
|
170 return TRUE;
|
|
171 }
|
|
172
|
|
173 static gboolean
|
|
174 plugin_unload(GaimPlugin *plugin)
|
|
175 {
|
|
176 return TRUE;
|
|
177 }
|
|
178
|
|
179 static GaimPluginPrefFrame *
|
|
180 get_plugin_pref_frame(GaimPlugin *plugin)
|
|
181 {
|
|
182 GaimPluginPrefFrame *frame;
|
|
183 GaimPluginPref *pref;
|
|
184
|
|
185 frame = gaim_plugin_pref_frame_new();
|
|
186
|
|
187 pref = gaim_plugin_pref_new_with_label(_("Save offline messages in pounce"));
|
|
188 gaim_plugin_pref_frame_add(frame, pref);
|
|
189
|
|
190 pref = gaim_plugin_pref_new_with_name_and_label(PREF_ALWAYS,
|
|
191 _("Do not ask. Always save in pounce."));
|
|
192 gaim_plugin_pref_frame_add(frame, pref);
|
|
193
|
|
194 return frame;
|
|
195 }
|
|
196
|
|
197 static GaimPluginUiInfo prefs_info = {
|
|
198 get_plugin_pref_frame,
|
|
199 0,
|
|
200 NULL
|
|
201 };
|
|
202
|
|
203 static GaimPluginInfo info =
|
|
204 {
|
|
205 GAIM_PLUGIN_MAGIC, /* Magic */
|
|
206 GAIM_MAJOR_VERSION, /* Gaim Major Version */
|
|
207 GAIM_MINOR_VERSION, /* Gaim Minor Version */
|
|
208 GAIM_PLUGIN_STANDARD, /* plugin type */
|
|
209 NULL, /* ui requirement */
|
|
210 0, /* flags */
|
|
211 NULL, /* dependencies */
|
|
212 GAIM_PRIORITY_DEFAULT, /* priority */
|
|
213
|
|
214 PLUGIN_ID, /* plugin id */
|
|
215 N_(PLUGIN_NAME), /* name */
|
|
216 VERSION, /* version */
|
|
217 N_(PLUGIN_SUMMARY), /* summary */
|
|
218 N_(PLUGIN_DESCRIPTION), /* description */
|
|
219 PLUGIN_AUTHOR, /* author */
|
|
220 GAIM_WEBSITE, /* website */
|
|
221
|
|
222 plugin_load, /* load */
|
|
223 plugin_unload, /* unload */
|
|
224 NULL, /* destroy */
|
|
225
|
|
226 NULL, /* ui_info */
|
|
227 NULL, /* extra_info */
|
|
228 &prefs_info, /* prefs_info */
|
|
229 NULL /* actions */
|
|
230 };
|
|
231
|
|
232 static void
|
|
233 init_plugin(GaimPlugin *plugin)
|
|
234 {
|
|
235 gaim_prefs_add_none(PREF_PREFIX);
|
|
236 gaim_prefs_add_bool(PREF_ALWAYS, FALSE);
|
|
237 }
|
|
238
|
|
239 GAIM_INIT_PLUGIN(PLUGIN_STATIC_NAME, init_plugin, info)
|