annotate plugins/timestamp.c @ 5199:a2f2b12f5557

[gaim-migrate @ 5565] Thanks, Jeff Smith. committer: Tailor Script <tailor@pidgin.im>
author Sean Egan <seanegan@gmail.com>
date Wed, 23 Apr 2003 13:00:21 +0000
parents c7986b4d182a
children fefad67de2c7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3598
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1 /* iChat-like timestamps by Sean Egan.
4220
0cff8ec38935 [gaim-migrate @ 4464]
Luke Schierer <lschiere@pidgin.im>
parents: 4202
diff changeset
2 *
0cff8ec38935 [gaim-migrate @ 4464]
Luke Schierer <lschiere@pidgin.im>
parents: 4202
diff changeset
3 * Modified by: Chris J. Friesen <Darth_Sebulba04@yahoo.com> Jan 05, 2003.
3598
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4 * <INSERT GPL HERE> */
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
5
4202
59751fe608c5 [gaim-migrate @ 4438]
Christian Hammond <chipx86@chipx86.com>
parents: 4201
diff changeset
6 #include "config.h"
59751fe608c5 [gaim-migrate @ 4438]
Christian Hammond <chipx86@chipx86.com>
parents: 4201
diff changeset
7
59751fe608c5 [gaim-migrate @ 4438]
Christian Hammond <chipx86@chipx86.com>
parents: 4201
diff changeset
8 #ifndef GAIM_PLUGINS
3598
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
9 #define GAIM_PLUGINS
4202
59751fe608c5 [gaim-migrate @ 4438]
Christian Hammond <chipx86@chipx86.com>
parents: 4201
diff changeset
10 #endif
59751fe608c5 [gaim-migrate @ 4438]
Christian Hammond <chipx86@chipx86.com>
parents: 4201
diff changeset
11
3598
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
12 #include <time.h>
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
13 #include "gaim.h"
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
14 #include "gtkimhtml.h"
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
15
4220
0cff8ec38935 [gaim-migrate @ 4464]
Luke Schierer <lschiere@pidgin.im>
parents: 4202
diff changeset
16 //Set the default to 5 minutes.
0cff8ec38935 [gaim-migrate @ 4464]
Luke Schierer <lschiere@pidgin.im>
parents: 4202
diff changeset
17 int timestamp = 5 * 60 * 1000;
3598
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
18
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
19 GModule *handle;
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
20 GSList *timestamp_timeouts;
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
21
4201
511c2b63caa4 [gaim-migrate @ 4432]
Christian Hammond <chipx86@chipx86.com>
parents: 4168
diff changeset
22 gboolean do_timestamp (gpointer data)
3598
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
23 {
4359
5fb47ec9bfe4 [gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents: 4220
diff changeset
24 struct gaim_conversation *c = (struct gaim_conversation *)data;
3598
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
25 char *buf;
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
26 char mdate[6];
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
27 time_t tim = time(NULL);
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
28
4376
2c985a9e994c [gaim-migrate @ 4642]
Christian Hammond <chipx86@chipx86.com>
parents: 4359
diff changeset
29 if (!g_list_find(gaim_get_conversations(), c))
3598
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
30 return FALSE;
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
31
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
32 strftime(mdate, sizeof(mdate), "%H:%M", localtime(&tim));
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
33 buf = g_strdup_printf(" %s", mdate);
4475
1f3241831734 [gaim-migrate @ 4750]
Christian Hammond <chipx86@chipx86.com>
parents: 4376
diff changeset
34 gaim_conversation_write(c, NULL, buf, -1, WFLAG_NOLOG, tim);
3598
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
35 g_free(buf);
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
36 return TRUE;
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
37 }
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
38
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
39 void timestamp_new_convo(char *name)
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
40 {
4359
5fb47ec9bfe4 [gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents: 4220
diff changeset
41 struct gaim_conversation *c = gaim_find_conversation(name);
3598
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
42 do_timestamp(c);
4168
ebfb80bbe1ed [gaim-migrate @ 4397]
Luke Schierer <lschiere@pidgin.im>
parents: 4113
diff changeset
43
3727
dadb43e0bcae [gaim-migrate @ 3864]
Luke Schierer <lschiere@pidgin.im>
parents: 3598
diff changeset
44 timestamp_timeouts = g_slist_append(timestamp_timeouts,
4220
0cff8ec38935 [gaim-migrate @ 4464]
Luke Schierer <lschiere@pidgin.im>
parents: 4202
diff changeset
45 GINT_TO_POINTER(g_timeout_add(timestamp, do_timestamp, c)));
3598
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
46
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
47 }
4220
0cff8ec38935 [gaim-migrate @ 4464]
Luke Schierer <lschiere@pidgin.im>
parents: 4202
diff changeset
48
0cff8ec38935 [gaim-migrate @ 4464]
Luke Schierer <lschiere@pidgin.im>
parents: 4202
diff changeset
49 static void set_timestamp(GtkWidget *button, GtkWidget *spinner) {
0cff8ec38935 [gaim-migrate @ 4464]
Luke Schierer <lschiere@pidgin.im>
parents: 4202
diff changeset
50 int tm;
0cff8ec38935 [gaim-migrate @ 4464]
Luke Schierer <lschiere@pidgin.im>
parents: 4202
diff changeset
51
0cff8ec38935 [gaim-migrate @ 4464]
Luke Schierer <lschiere@pidgin.im>
parents: 4202
diff changeset
52 tm = 0;
0cff8ec38935 [gaim-migrate @ 4464]
Luke Schierer <lschiere@pidgin.im>
parents: 4202
diff changeset
53
0cff8ec38935 [gaim-migrate @ 4464]
Luke Schierer <lschiere@pidgin.im>
parents: 4202
diff changeset
54 tm = CLAMP(gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(spinner)), 1, G_MAXINT);
0cff8ec38935 [gaim-migrate @ 4464]
Luke Schierer <lschiere@pidgin.im>
parents: 4202
diff changeset
55 debug_printf("setting time to %d mins\n", tm);
0cff8ec38935 [gaim-migrate @ 4464]
Luke Schierer <lschiere@pidgin.im>
parents: 4202
diff changeset
56
0cff8ec38935 [gaim-migrate @ 4464]
Luke Schierer <lschiere@pidgin.im>
parents: 4202
diff changeset
57 tm = tm * 60 * 1000;
0cff8ec38935 [gaim-migrate @ 4464]
Luke Schierer <lschiere@pidgin.im>
parents: 4202
diff changeset
58
0cff8ec38935 [gaim-migrate @ 4464]
Luke Schierer <lschiere@pidgin.im>
parents: 4202
diff changeset
59 timestamp = tm;
0cff8ec38935 [gaim-migrate @ 4464]
Luke Schierer <lschiere@pidgin.im>
parents: 4202
diff changeset
60 }
0cff8ec38935 [gaim-migrate @ 4464]
Luke Schierer <lschiere@pidgin.im>
parents: 4202
diff changeset
61
0cff8ec38935 [gaim-migrate @ 4464]
Luke Schierer <lschiere@pidgin.im>
parents: 4202
diff changeset
62 GtkWidget *gaim_plugin_config_gtk() {
0cff8ec38935 [gaim-migrate @ 4464]
Luke Schierer <lschiere@pidgin.im>
parents: 4202
diff changeset
63 GtkWidget *ret;
0cff8ec38935 [gaim-migrate @ 4464]
Luke Schierer <lschiere@pidgin.im>
parents: 4202
diff changeset
64 GtkWidget *frame, *label;
0cff8ec38935 [gaim-migrate @ 4464]
Luke Schierer <lschiere@pidgin.im>
parents: 4202
diff changeset
65 GtkWidget *vbox, *hbox;
0cff8ec38935 [gaim-migrate @ 4464]
Luke Schierer <lschiere@pidgin.im>
parents: 4202
diff changeset
66 GtkAdjustment *adj;
0cff8ec38935 [gaim-migrate @ 4464]
Luke Schierer <lschiere@pidgin.im>
parents: 4202
diff changeset
67 GtkWidget *spinner, *button;
0cff8ec38935 [gaim-migrate @ 4464]
Luke Schierer <lschiere@pidgin.im>
parents: 4202
diff changeset
68
0cff8ec38935 [gaim-migrate @ 4464]
Luke Schierer <lschiere@pidgin.im>
parents: 4202
diff changeset
69 ret = gtk_vbox_new(FALSE, 18);
0cff8ec38935 [gaim-migrate @ 4464]
Luke Schierer <lschiere@pidgin.im>
parents: 4202
diff changeset
70 gtk_container_set_border_width (GTK_CONTAINER (ret), 12);
0cff8ec38935 [gaim-migrate @ 4464]
Luke Schierer <lschiere@pidgin.im>
parents: 4202
diff changeset
71
0cff8ec38935 [gaim-migrate @ 4464]
Luke Schierer <lschiere@pidgin.im>
parents: 4202
diff changeset
72 frame = make_frame(ret, _("iChat Timestamp"));
0cff8ec38935 [gaim-migrate @ 4464]
Luke Schierer <lschiere@pidgin.im>
parents: 4202
diff changeset
73 vbox = gtk_vbox_new(FALSE, 5);
0cff8ec38935 [gaim-migrate @ 4464]
Luke Schierer <lschiere@pidgin.im>
parents: 4202
diff changeset
74 gtk_container_add(GTK_CONTAINER(frame), vbox);
0cff8ec38935 [gaim-migrate @ 4464]
Luke Schierer <lschiere@pidgin.im>
parents: 4202
diff changeset
75
0cff8ec38935 [gaim-migrate @ 4464]
Luke Schierer <lschiere@pidgin.im>
parents: 4202
diff changeset
76 hbox = gtk_hbox_new(FALSE, 5);
0cff8ec38935 [gaim-migrate @ 4464]
Luke Schierer <lschiere@pidgin.im>
parents: 4202
diff changeset
77 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 5);
0cff8ec38935 [gaim-migrate @ 4464]
Luke Schierer <lschiere@pidgin.im>
parents: 4202
diff changeset
78
4586
c7986b4d182a [gaim-migrate @ 4870]
Luke Schierer <lschiere@pidgin.im>
parents: 4475
diff changeset
79 label = gtk_label_new(_("Delay"));
4220
0cff8ec38935 [gaim-migrate @ 4464]
Luke Schierer <lschiere@pidgin.im>
parents: 4202
diff changeset
80 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 5);
0cff8ec38935 [gaim-migrate @ 4464]
Luke Schierer <lschiere@pidgin.im>
parents: 4202
diff changeset
81
0cff8ec38935 [gaim-migrate @ 4464]
Luke Schierer <lschiere@pidgin.im>
parents: 4202
diff changeset
82 adj = (GtkAdjustment *)gtk_adjustment_new(timestamp/(60*1000), 1, G_MAXINT, 1, 0, 0);
0cff8ec38935 [gaim-migrate @ 4464]
Luke Schierer <lschiere@pidgin.im>
parents: 4202
diff changeset
83 spinner = gtk_spin_button_new(adj, 0, 0);
0cff8ec38935 [gaim-migrate @ 4464]
Luke Schierer <lschiere@pidgin.im>
parents: 4202
diff changeset
84 gtk_box_pack_start(GTK_BOX(hbox), spinner, TRUE, TRUE, 0);
0cff8ec38935 [gaim-migrate @ 4464]
Luke Schierer <lschiere@pidgin.im>
parents: 4202
diff changeset
85
4586
c7986b4d182a [gaim-migrate @ 4870]
Luke Schierer <lschiere@pidgin.im>
parents: 4475
diff changeset
86 label = gtk_label_new(_("minutes."));
4220
0cff8ec38935 [gaim-migrate @ 4464]
Luke Schierer <lschiere@pidgin.im>
parents: 4202
diff changeset
87 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 5);
0cff8ec38935 [gaim-migrate @ 4464]
Luke Schierer <lschiere@pidgin.im>
parents: 4202
diff changeset
88
0cff8ec38935 [gaim-migrate @ 4464]
Luke Schierer <lschiere@pidgin.im>
parents: 4202
diff changeset
89 hbox = gtk_hbox_new(TRUE, 5);
0cff8ec38935 [gaim-migrate @ 4464]
Luke Schierer <lschiere@pidgin.im>
parents: 4202
diff changeset
90 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 5);
0cff8ec38935 [gaim-migrate @ 4464]
Luke Schierer <lschiere@pidgin.im>
parents: 4202
diff changeset
91
0cff8ec38935 [gaim-migrate @ 4464]
Luke Schierer <lschiere@pidgin.im>
parents: 4202
diff changeset
92 button = gtk_button_new_with_mnemonic(_("_Apply"));
0cff8ec38935 [gaim-migrate @ 4464]
Luke Schierer <lschiere@pidgin.im>
parents: 4202
diff changeset
93 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 5);
0cff8ec38935 [gaim-migrate @ 4464]
Luke Schierer <lschiere@pidgin.im>
parents: 4202
diff changeset
94 g_signal_connect(GTK_OBJECT(button), "clicked", G_CALLBACK(set_timestamp), spinner);
0cff8ec38935 [gaim-migrate @ 4464]
Luke Schierer <lschiere@pidgin.im>
parents: 4202
diff changeset
95
0cff8ec38935 [gaim-migrate @ 4464]
Luke Schierer <lschiere@pidgin.im>
parents: 4202
diff changeset
96 gtk_widget_show_all(ret);
0cff8ec38935 [gaim-migrate @ 4464]
Luke Schierer <lschiere@pidgin.im>
parents: 4202
diff changeset
97 return ret;
0cff8ec38935 [gaim-migrate @ 4464]
Luke Schierer <lschiere@pidgin.im>
parents: 4202
diff changeset
98 }
0cff8ec38935 [gaim-migrate @ 4464]
Luke Schierer <lschiere@pidgin.im>
parents: 4202
diff changeset
99
0cff8ec38935 [gaim-migrate @ 4464]
Luke Schierer <lschiere@pidgin.im>
parents: 4202
diff changeset
100
3598
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
101 char *gaim_plugin_init(GModule *h) {
4376
2c985a9e994c [gaim-migrate @ 4642]
Christian Hammond <chipx86@chipx86.com>
parents: 4359
diff changeset
102 GList *cnvs = gaim_get_conversations();
4359
5fb47ec9bfe4 [gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents: 4220
diff changeset
103 struct gaim_conversation *c;
3598
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
104 handle = h;
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
105
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
106 while (cnvs) {
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
107 c = cnvs->data;
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
108 timestamp_new_convo(c->name);
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
109 cnvs = cnvs->next;
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
110 }
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
111 gaim_signal_connect(handle, event_new_conversation, timestamp_new_convo, NULL);
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
112
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
113 return NULL;
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
114 }
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
115
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
116 void gaim_plugin_remove() {
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
117 GSList *to;
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
118 to = timestamp_timeouts;
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
119 while (to) {
4168
ebfb80bbe1ed [gaim-migrate @ 4397]
Luke Schierer <lschiere@pidgin.im>
parents: 4113
diff changeset
120 g_source_remove(GPOINTER_TO_INT(to->data));
3598
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
121 to = to->next;
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
122 }
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
123 g_slist_free(timestamp_timeouts);
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
124 }
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
125
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
126 struct gaim_plugin_description desc;
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
127 struct gaim_plugin_description *gaim_plugin_desc() {
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
128 desc.api_version = PLUGIN_API_VERSION;
4113
74d27aa5b686 [gaim-migrate @ 4329]
Luke Schierer <lschiere@pidgin.im>
parents: 3727
diff changeset
129 desc.name = g_strdup(_("Timestamp"));
3598
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
130 desc.version = g_strdup(VERSION);
4220
0cff8ec38935 [gaim-migrate @ 4464]
Luke Schierer <lschiere@pidgin.im>
parents: 4202
diff changeset
131 desc.description = g_strdup(_("Adds iChat-style timestamps to conversations every N minutes."));
3598
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
132 desc.authors = g_strdup("Sean Egan &lt;bj91704@binghamton.edu>");
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
133 desc.url = g_strdup(WEBSITE);
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
134 return &desc;
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
135 }