comparison plugins/timestamp.c @ 10404:ce098e226486

[gaim-migrate @ 11649] Make some things better, and some whitespace cleanup. committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Fri, 24 Dec 2004 00:05:36 +0000
parents 6a043ae92db6
children bb6fea81e770
comparison
equal deleted inserted replaced
10403:e5455f1dc9b6 10404:ce098e226486
17 * You should have received a copy of the GNU General Public License 17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software 18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 * 20 *
21 */ 21 */
22
23
24 22
25 #include "internal.h" 23 #include "internal.h"
26 24
27 #include "conversation.h" 25 #include "conversation.h"
28 #include "debug.h" 26 #include "debug.h"
39 /* Set the default to 5 minutes. */ 37 /* Set the default to 5 minutes. */
40 static int interval = 5 * 60 * 1000; 38 static int interval = 5 * 60 * 1000;
41 39
42 static GSList *timestamp_timeouts = NULL; 40 static GSList *timestamp_timeouts = NULL;
43 41
44 static gboolean do_timestamp (gpointer data) 42 static gboolean
43 do_timestamp(gpointer data)
45 { 44 {
46 GaimConversation *c = (GaimConversation *)data; 45 GaimConversation *c = (GaimConversation *)data;
47 GaimGtkConversation *conv = GAIM_GTK_CONVERSATION(c); 46 GaimGtkConversation *conv = GAIM_GTK_CONVERSATION(c);
48 GtkTextIter iter; 47 GtkTextIter iter;
49 char mdate[7]; 48 char mdate[7];
50 int is_conversation_active; 49 int is_conversation_active;
51 time_t tim = time(NULL); 50 time_t tim = time(NULL);
52 51
53 if (!g_list_find(gaim_get_conversations(), c)) 52 if (!g_list_find(gaim_get_conversations(), c))
54 return FALSE; 53 return FALSE;
55 54
56 /* is_conversation_active is true if an im has been displayed since the last timestamp */ 55 /* is_conversation_active is true if an im has been displayed since the last timestamp */
57 is_conversation_active = GPOINTER_TO_INT(gaim_conversation_get_data(c, "timestamp-conv-active")); 56 is_conversation_active = GPOINTER_TO_INT(gaim_conversation_get_data(c, "timestamp-conv-active"));
58 57
59 if (is_conversation_active){ 58 if (is_conversation_active){
60 int y, height; 59 int y, height;
61 GdkRectangle rect; 60 GdkRectangle rect;
62 gboolean scroll = TRUE; 61 gboolean scroll = TRUE;
63 GtkWidget *imhtml = conv->imhtml; 62 GtkWidget *imhtml = conv->imhtml;
71 && gtk_text_buffer_get_char_count(buffer)){ 70 && gtk_text_buffer_get_char_count(buffer)){
72 scroll = FALSE; 71 scroll = FALSE;
73 } 72 }
74 gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, mdate, strlen(mdate), "TIMESTAMP", NULL); 73 gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, mdate, strlen(mdate), "TIMESTAMP", NULL);
75 if (scroll) 74 if (scroll)
76 gtk_imhtml_scroll_to_end(imhtml); 75 gtk_imhtml_scroll_to_end(GTK_IMHTML(imhtml));
77 } 76 }
78 else 77 else
79 gaim_conversation_set_data(c, "timestamp-enabled", GINT_TO_POINTER(FALSE)); 78 gaim_conversation_set_data(c, "timestamp-enabled", GINT_TO_POINTER(FALSE));
80 79
81 return TRUE; 80 return TRUE;
82 } 81 }
83 82
84 83
85 static gboolean 84 static gboolean
86 timestamp_displaying_conv_msg(GaimAccount *account, GaimConversation *conv, 85 timestamp_displaying_conv_msg(GaimAccount *account, GaimConversation *conv,
87 char **buffer, void *data) 86 char **buffer, void *data)
88 { 87 {
89 int is_timestamp_enabled; 88 int is_timestamp_enabled;
90 89
91 if (!g_list_find(gaim_get_conversations(), conv)) 90 if (!g_list_find(gaim_get_conversations(), conv))
92 return FALSE; 91 return FALSE;
93 92
94 /* set to true, since there has been an im since the last timestamp */ 93 /* set to true, since there has been an im since the last timestamp */
95 gaim_conversation_set_data(conv, "timestamp-conv-active", GINT_TO_POINTER(TRUE)); 94 gaim_conversation_set_data(conv, "timestamp-conv-active", GINT_TO_POINTER(TRUE));
96 95
97 is_timestamp_enabled = GPOINTER_TO_INT(gaim_conversation_get_data(conv, "timestamp-enabled")); 96 is_timestamp_enabled = GPOINTER_TO_INT(gaim_conversation_get_data(conv, "timestamp-enabled"));
98 97
99 if (!is_timestamp_enabled){ 98 if (!is_timestamp_enabled){
100 gaim_conversation_set_data(conv, "timestamp-enabled", GINT_TO_POINTER(TRUE)); 99 gaim_conversation_set_data(conv, "timestamp-enabled", GINT_TO_POINTER(TRUE));
101 do_timestamp((gpointer)conv); 100 do_timestamp((gpointer)conv);
102 } 101 }
103 102
104 return FALSE; 103 return FALSE;
105 } 104 }
106 105
107 static gboolean 106 static gboolean
108 timestamp_receiving_msg(GaimAccount *account, char **sender, char **buffer, 107 timestamp_receiving_msg(GaimAccount *account, char **sender, char **buffer,
115 114
116 115
117 static void timestamp_new_convo(GaimConversation *conv) 116 static void timestamp_new_convo(GaimConversation *conv)
118 { 117 {
119 GaimGtkConversation *c = GAIM_GTK_CONVERSATION(conv); 118 GaimGtkConversation *c = GAIM_GTK_CONVERSATION(conv);
120 119
121 if (!g_list_find(gaim_get_conversations(), conv)) 120 if (!g_list_find(gaim_get_conversations(), conv))
122 return; 121 return;
123 122
124 gtk_imhtml_show_comments(GTK_IMHTML(c->imhtml), FALSE); 123 gtk_imhtml_show_comments(GTK_IMHTML(c->imhtml), FALSE);
125 124
126 /* 125 /*
127 This if statement stops conversations that have already been initialized for timestamps 126 This if statement stops conversations that have already been initialized for timestamps
128 from being reinitialized. This prevents every active conversation from immediately being spammed 127 from being reinitialized. This prevents every active conversation from immediately being spammed
149 148
150 for (to = timestamp_timeouts; to != NULL; to = to->next) 149 for (to = timestamp_timeouts; to != NULL; to = to->next)
151 g_source_remove(GPOINTER_TO_INT(to->data)); 150 g_source_remove(GPOINTER_TO_INT(to->data));
152 151
153 g_slist_free(timestamp_timeouts); 152 g_slist_free(timestamp_timeouts);
154 153
155 timestamp_timeouts = NULL; 154 timestamp_timeouts = NULL;
156 } 155 }
157 156
158 static void init_timer_list() 157 static void init_timer_list()
159 { 158 {
160 GList *cnvs; 159 GList *cnvs;
161 GaimConversation *c; 160 GaimConversation *c;
162 161
163 if (timestamp_timeouts != NULL) 162 if (timestamp_timeouts != NULL)
164 destroy_timer_list(); 163 destroy_timer_list();
165 164
166 for (cnvs = gaim_get_conversations(); cnvs != NULL; cnvs = cnvs->next) { 165 for (cnvs = gaim_get_conversations(); cnvs != NULL; cnvs = cnvs->next) {
167 c = cnvs->data; 166 c = cnvs->data;
168 timestamp_new_convo(c); 167 timestamp_new_convo(c);
169 } 168 }
170 } 169 }
181 180
182 tm = tm * 60 * 1000; 181 tm = tm * 60 * 1000;
183 182
184 interval = tm; 183 interval = tm;
185 gaim_prefs_set_int("/plugins/gtk/timestamp/interval", interval); 184 gaim_prefs_set_int("/plugins/gtk/timestamp/interval", interval);
186 185
187 destroy_timer_list(); 186 destroy_timer_list();
188 init_timer_list(); 187 init_timer_list();
189 } 188 }
190 189
191 static GtkWidget * 190 static GtkWidget *
231 230
232 static gboolean 231 static gboolean
233 plugin_load(GaimPlugin *plugin) 232 plugin_load(GaimPlugin *plugin)
234 { 233 {
235 void *conv_handle = gaim_conversations_get_handle(); 234 void *conv_handle = gaim_conversations_get_handle();
236 235
237 init_timer_list(); 236 init_timer_list();
238 237
239 gaim_signal_connect(conv_handle, "conversation-created", 238 gaim_signal_connect(conv_handle, "conversation-created",
240 plugin, GAIM_CALLBACK(timestamp_new_convo), NULL); 239 plugin, GAIM_CALLBACK(timestamp_new_convo), NULL);
241 240
262 plugin, GAIM_CALLBACK(timestamp_new_convo)); 261 plugin, GAIM_CALLBACK(timestamp_new_convo));
263 gaim_signal_disconnect(conv_handle, "receiving-im-msg", 262 gaim_signal_disconnect(conv_handle, "receiving-im-msg",
264 plugin, GAIM_CALLBACK(timestamp_receiving_msg)); 263 plugin, GAIM_CALLBACK(timestamp_receiving_msg));
265 gaim_signal_disconnect(conv_handle, "displaying-im-msg", 264 gaim_signal_disconnect(conv_handle, "displaying-im-msg",
266 plugin, GAIM_CALLBACK(timestamp_displaying_conv_msg)); 265 plugin, GAIM_CALLBACK(timestamp_displaying_conv_msg));
267 266
268 destroy_timer_list(); 267 destroy_timer_list();
269 268
270 for (cnvs = gaim_get_conversations(); cnvs != NULL; cnvs = cnvs->next) { 269 for (cnvs = gaim_get_conversations(); cnvs != NULL; cnvs = cnvs->next) {
271 GaimConversation *c = cnvs->data; 270 GaimConversation *c = cnvs->data;
272 GaimGtkConversation *conv = GAIM_GTK_CONVERSATION(c); 271 GaimGtkConversation *conv = GAIM_GTK_CONVERSATION(c);
306 plugin_unload, /**< unload */ 305 plugin_unload, /**< unload */
307 NULL, /**< destroy */ 306 NULL, /**< destroy */
308 307
309 &ui_info, /**< ui_info */ 308 &ui_info, /**< ui_info */
310 NULL, /**< extra_info */ 309 NULL, /**< extra_info */
311 NULL, 310 NULL,
312 NULL 311 NULL
313 }; 312 };
314 313
315 static void 314 static void
316 init_plugin(GaimPlugin *plugin) 315 init_plugin(GaimPlugin *plugin)