comparison plugins/timestamp.c @ 6485:70d5122bc3ff

[gaim-migrate @ 6999] Removed the old event system and replaced it with a much better signal system. There will most likely be some bugs in this, but it seems to be working for now. Plugins can now generate their own signals, and other plugins can find those plugins and connect to them. This could give plugins a form of IPC. It's also useful for other things. It's rather flexible, except for the damn marshalling, but there's no way around that that I or the glib people can see. committer: Tailor Script <tailor@pidgin.im>
author Christian Hammond <chipx86@chipx86.com>
date Mon, 18 Aug 2003 01:03:43 +0000
parents 8f94cce8faa5
children 42fdf16f1dad
comparison
equal deleted inserted replaced
6484:5ced8e111473 6485:70d5122bc3ff
5 5
6 #include "internal.h" 6 #include "internal.h"
7 7
8 #include "conversation.h" 8 #include "conversation.h"
9 #include "debug.h" 9 #include "debug.h"
10 #include "signals.h"
10 11
11 #include "gtkimhtml.h" 12 #include "gtkimhtml.h"
12 #include "gtkplugin.h" 13 #include "gtkplugin.h"
13 #include "gtkutils.h" 14 #include "gtkutils.h"
14 15
17 /* Set the default to 5 minutes. */ 18 /* Set the default to 5 minutes. */
18 static int timestamp = 5 * 60 * 1000; 19 static int timestamp = 5 * 60 * 1000;
19 20
20 static GSList *timestamp_timeouts; 21 static GSList *timestamp_timeouts;
21 22
22 gboolean do_timestamp (gpointer data) 23 static gboolean do_timestamp (gpointer data)
23 { 24 {
24 GaimConversation *c = (GaimConversation *)data; 25 GaimConversation *c = (GaimConversation *)data;
25 char *buf; 26 char *buf;
26 char mdate[6]; 27 char mdate[6];
27 time_t tim = time(NULL); 28 time_t tim = time(NULL);
34 gaim_conversation_write(c, NULL, buf, -1, WFLAG_NOLOG, tim); 35 gaim_conversation_write(c, NULL, buf, -1, WFLAG_NOLOG, tim);
35 g_free(buf); 36 g_free(buf);
36 return TRUE; 37 return TRUE;
37 } 38 }
38 39
39 void timestamp_new_convo(char *name) 40 static void timestamp_new_convo(GaimConversation *conv)
40 { 41 {
41 GaimConversation *c = gaim_find_conversation(name); 42 do_timestamp(conv);
42 do_timestamp(c);
43 43
44 timestamp_timeouts = g_slist_append(timestamp_timeouts, 44 timestamp_timeouts = g_slist_append(timestamp_timeouts,
45 GINT_TO_POINTER(g_timeout_add(timestamp, do_timestamp, c))); 45 GINT_TO_POINTER(g_timeout_add(timestamp, do_timestamp, conv)));
46 46
47 } 47 }
48 48
49 static void set_timestamp(GtkWidget *button, GtkWidget *spinner) { 49 static void set_timestamp(GtkWidget *button, GtkWidget *spinner) {
50 int tm; 50 int tm;
51 51
52 tm = 0; 52 tm = 0;
53 53
54 tm = CLAMP(gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(spinner)), 1, G_MAXINT); 54 tm = CLAMP(gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(spinner)), 1, G_MAXINT);
55 gaim_debug(GAIM_DEBUG_MISC, "timestamp", "setting time to %d mins\n", tm); 55 gaim_debug(GAIM_DEBUG_MISC, "timestamp", "setting time to %d mins\n", tm);
56 56
57 tm = tm * 60 * 1000; 57 tm = tm * 60 * 1000;
58 58
59 timestamp = tm; 59 timestamp = tm;
60 } 60 }
61 61
65 GtkWidget *ret; 65 GtkWidget *ret;
66 GtkWidget *frame, *label; 66 GtkWidget *frame, *label;
67 GtkWidget *vbox, *hbox; 67 GtkWidget *vbox, *hbox;
68 GtkAdjustment *adj; 68 GtkAdjustment *adj;
69 GtkWidget *spinner, *button; 69 GtkWidget *spinner, *button;
70 70
71 ret = gtk_vbox_new(FALSE, 18); 71 ret = gtk_vbox_new(FALSE, 18);
72 gtk_container_set_border_width (GTK_CONTAINER (ret), 12); 72 gtk_container_set_border_width (GTK_CONTAINER (ret), 12);
73 73
74 frame = gaim_gtk_make_frame(ret, _("iChat Timestamp")); 74 frame = gaim_gtk_make_frame(ret, _("iChat Timestamp"));
75 vbox = gtk_vbox_new(FALSE, 5); 75 vbox = gtk_vbox_new(FALSE, 5);
78 hbox = gtk_hbox_new(FALSE, 5); 78 hbox = gtk_hbox_new(FALSE, 5);
79 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 5); 79 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 5);
80 80
81 label = gtk_label_new(_("Delay")); 81 label = gtk_label_new(_("Delay"));
82 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 5); 82 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 5);
83 83
84 adj = (GtkAdjustment *)gtk_adjustment_new(timestamp/(60*1000), 1, G_MAXINT, 1, 0, 0); 84 adj = (GtkAdjustment *)gtk_adjustment_new(timestamp/(60*1000), 1, G_MAXINT, 1, 0, 0);
85 spinner = gtk_spin_button_new(adj, 0, 0); 85 spinner = gtk_spin_button_new(adj, 0, 0);
86 gtk_box_pack_start(GTK_BOX(hbox), spinner, TRUE, TRUE, 0); 86 gtk_box_pack_start(GTK_BOX(hbox), spinner, TRUE, TRUE, 0);
87 87
88 label = gtk_label_new(_("minutes.")); 88 label = gtk_label_new(_("minutes."));
89 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 5); 89 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 5);
90 90
91 hbox = gtk_hbox_new(TRUE, 5); 91 hbox = gtk_hbox_new(TRUE, 5);
92 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 5); 92 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 5);
93 93
94 button = gtk_button_new_with_mnemonic(_("_Apply")); 94 button = gtk_button_new_with_mnemonic(_("_Apply"));
95 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 5); 95 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 5);
96 g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(set_timestamp), spinner); 96 g_signal_connect(G_OBJECT(button), "clicked",
97 97 G_CALLBACK(set_timestamp), spinner);
98
98 gtk_widget_show_all(ret); 99 gtk_widget_show_all(ret);
99 return ret; 100 return ret;
100 } 101 }
101 102
102 static gboolean 103 static gboolean
106 GaimConversation *c; 107 GaimConversation *c;
107 108
108 timestamp_timeouts = NULL; 109 timestamp_timeouts = NULL;
109 for (cnvs = gaim_get_conversations(); cnvs != NULL; cnvs = cnvs->next) { 110 for (cnvs = gaim_get_conversations(); cnvs != NULL; cnvs = cnvs->next) {
110 c = cnvs->data; 111 c = cnvs->data;
111 timestamp_new_convo(c->name); 112 timestamp_new_convo(c);
112 } 113 }
113 114
114 gaim_signal_connect(plugin, event_new_conversation, 115 gaim_signal_connect(gaim_conversations_get_handle(),
115 timestamp_new_convo, NULL); 116 "conversation-created",
117 plugin, GAIM_CALLBACK(timestamp_new_convo), NULL);
116 118
117 return TRUE; 119 return TRUE;
118 } 120 }
119 121
120 static gboolean 122 static gboolean
150 /** summary */ 152 /** summary */
151 N_("Adds iChat-style timestamps to conversations every N minutes."), 153 N_("Adds iChat-style timestamps to conversations every N minutes."),
152 /** description */ 154 /** description */
153 N_("Adds iChat-style timestamps to conversations every N minutes."), 155 N_("Adds iChat-style timestamps to conversations every N minutes."),
154 "Sean Egan <bj91704@binghamton.edu>", /**< author */ 156 "Sean Egan <bj91704@binghamton.edu>", /**< author */
155 GAIM_WEBSITE, /**< homepage */ 157 GAIM_WEBSITE, /**< homepage */
156 158
157 plugin_load, /**< load */ 159 plugin_load, /**< load */
158 plugin_unload, /**< unload */ 160 plugin_unload, /**< unload */
159 NULL, /**< destroy */ 161 NULL, /**< destroy */
160 162