Wed, 14 May 2003 04:35:09 +0000
[gaim-migrate @ 5744]
this won't make things worse, and it should at very least reduce the frequency with which gaim displays groups with negative counts
| 3598 | 1 | /* iChat-like timestamps by Sean Egan. |
| 4220 | 2 | * |
| 3 | * Modified by: Chris J. Friesen <Darth_Sebulba04@yahoo.com> Jan 05, 2003. | |
| 3598 | 4 | * <INSERT GPL HERE> */ |
| 5 | ||
|
4202
8b92de3b1c07
[gaim-migrate @ 4438]
Christian Hammond <chipx86@chipx86.com>
parents:
4201
diff
changeset
|
6 | #include "config.h" |
|
8b92de3b1c07
[gaim-migrate @ 4438]
Christian Hammond <chipx86@chipx86.com>
parents:
4201
diff
changeset
|
7 | |
| 3598 | 8 | #include <time.h> |
| 9 | #include "gaim.h" | |
| 10 | #include "gtkimhtml.h" | |
|
5205
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4586
diff
changeset
|
11 | #include "gtkplugin.h" |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4586
diff
changeset
|
12 | |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4586
diff
changeset
|
13 | #define TIMESTAMP_PLUGIN_ID "gtk-timestamp" |
| 3598 | 14 | |
| 4220 | 15 | //Set the default to 5 minutes. |
|
5205
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4586
diff
changeset
|
16 | static int timestamp = 5 * 60 * 1000; |
| 3598 | 17 | |
|
5205
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4586
diff
changeset
|
18 | static GSList *timestamp_timeouts; |
| 3598 | 19 | |
|
4201
547da94c5a14
[gaim-migrate @ 4432]
Christian Hammond <chipx86@chipx86.com>
parents:
4168
diff
changeset
|
20 | gboolean do_timestamp (gpointer data) |
| 3598 | 21 | { |
|
4359
cf899ee07d1d
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4220
diff
changeset
|
22 | struct gaim_conversation *c = (struct gaim_conversation *)data; |
| 3598 | 23 | char *buf; |
| 24 | char mdate[6]; | |
| 25 | time_t tim = time(NULL); | |
| 26 | ||
|
4376
88f8faf7cb61
[gaim-migrate @ 4642]
Christian Hammond <chipx86@chipx86.com>
parents:
4359
diff
changeset
|
27 | if (!g_list_find(gaim_get_conversations(), c)) |
| 3598 | 28 | return FALSE; |
| 29 | ||
| 30 | strftime(mdate, sizeof(mdate), "%H:%M", localtime(&tim)); | |
| 31 | buf = g_strdup_printf(" %s", mdate); | |
|
4475
26b1afb30359
[gaim-migrate @ 4750]
Christian Hammond <chipx86@chipx86.com>
parents:
4376
diff
changeset
|
32 | gaim_conversation_write(c, NULL, buf, -1, WFLAG_NOLOG, tim); |
| 3598 | 33 | g_free(buf); |
| 34 | return TRUE; | |
| 35 | } | |
| 36 | ||
| 37 | void timestamp_new_convo(char *name) | |
| 38 | { | |
|
4359
cf899ee07d1d
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4220
diff
changeset
|
39 | struct gaim_conversation *c = gaim_find_conversation(name); |
| 3598 | 40 | do_timestamp(c); |
| 4168 | 41 | |
| 3727 | 42 | timestamp_timeouts = g_slist_append(timestamp_timeouts, |
| 4220 | 43 | GINT_TO_POINTER(g_timeout_add(timestamp, do_timestamp, c))); |
| 3598 | 44 | |
| 45 | } | |
| 4220 | 46 | |
| 47 | static void set_timestamp(GtkWidget *button, GtkWidget *spinner) { | |
| 48 | int tm; | |
| 49 | ||
| 50 | tm = 0; | |
| 51 | ||
| 52 | tm = CLAMP(gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(spinner)), 1, G_MAXINT); | |
|
5227
6b44f7901f94
[gaim-migrate @ 5597]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
53 | gaim_debug(GAIM_DEBUG_MISC, "timestamp", "setting time to %d mins\n", tm); |
| 4220 | 54 | |
| 55 | tm = tm * 60 * 1000; | |
| 56 | ||
| 57 | timestamp = tm; | |
| 58 | } | |
| 59 | ||
|
5205
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4586
diff
changeset
|
60 | static GtkWidget * |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4586
diff
changeset
|
61 | get_config_frame(GaimPlugin *plugin) |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4586
diff
changeset
|
62 | { |
| 4220 | 63 | GtkWidget *ret; |
| 64 | GtkWidget *frame, *label; | |
| 65 | GtkWidget *vbox, *hbox; | |
| 66 | GtkAdjustment *adj; | |
| 67 | GtkWidget *spinner, *button; | |
| 68 | ||
| 69 | ret = gtk_vbox_new(FALSE, 18); | |
| 70 | gtk_container_set_border_width (GTK_CONTAINER (ret), 12); | |
| 71 | ||
| 72 | frame = make_frame(ret, _("iChat Timestamp")); | |
| 73 | vbox = gtk_vbox_new(FALSE, 5); | |
| 74 | gtk_container_add(GTK_CONTAINER(frame), vbox); | |
| 75 | ||
| 76 | hbox = gtk_hbox_new(FALSE, 5); | |
| 77 | gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 5); | |
| 78 | ||
| 4586 | 79 | label = gtk_label_new(_("Delay")); |
| 4220 | 80 | gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 5); |
| 81 | ||
| 82 | adj = (GtkAdjustment *)gtk_adjustment_new(timestamp/(60*1000), 1, G_MAXINT, 1, 0, 0); | |
| 83 | spinner = gtk_spin_button_new(adj, 0, 0); | |
| 84 | gtk_box_pack_start(GTK_BOX(hbox), spinner, TRUE, TRUE, 0); | |
| 85 | ||
| 4586 | 86 | label = gtk_label_new(_("minutes.")); |
| 4220 | 87 | gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 5); |
| 88 | ||
| 89 | hbox = gtk_hbox_new(TRUE, 5); | |
| 90 | gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 5); | |
| 91 | ||
| 92 | button = gtk_button_new_with_mnemonic(_("_Apply")); | |
| 93 | gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 5); | |
|
5314
56ef6a09fb99
[gaim-migrate @ 5686]
Christian Hammond <chipx86@chipx86.com>
parents:
5227
diff
changeset
|
94 | g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(set_timestamp), spinner); |
| 4220 | 95 | |
| 96 | gtk_widget_show_all(ret); | |
| 97 | return ret; | |
| 98 | } | |
| 99 | ||
|
5205
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4586
diff
changeset
|
100 | static gboolean |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4586
diff
changeset
|
101 | plugin_load(GaimPlugin *plugin) |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4586
diff
changeset
|
102 | { |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4586
diff
changeset
|
103 | GList *cnvs; |
|
4359
cf899ee07d1d
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4220
diff
changeset
|
104 | struct gaim_conversation *c; |
| 3598 | 105 | |
|
5205
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4586
diff
changeset
|
106 | for (cnvs = gaim_get_conversations(); cnvs != NULL; cnvs = cnvs->next) { |
| 3598 | 107 | c = cnvs->data; |
| 108 | timestamp_new_convo(c->name); | |
| 109 | } | |
|
5205
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4586
diff
changeset
|
110 | |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4586
diff
changeset
|
111 | gaim_signal_connect(plugin, event_new_conversation, |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4586
diff
changeset
|
112 | timestamp_new_convo, NULL); |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4586
diff
changeset
|
113 | |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4586
diff
changeset
|
114 | return TRUE; |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4586
diff
changeset
|
115 | } |
| 3598 | 116 | |
|
5205
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4586
diff
changeset
|
117 | static gboolean |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4586
diff
changeset
|
118 | plugin_unload(GaimPlugin *plugin) |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4586
diff
changeset
|
119 | { |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4586
diff
changeset
|
120 | GSList *to; |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4586
diff
changeset
|
121 | |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4586
diff
changeset
|
122 | for (to = timestamp_timeouts; to != NULL; to = to->next) |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4586
diff
changeset
|
123 | g_source_remove(GPOINTER_TO_INT(to->data)); |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4586
diff
changeset
|
124 | |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4586
diff
changeset
|
125 | g_slist_free(timestamp_timeouts); |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4586
diff
changeset
|
126 | |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4586
diff
changeset
|
127 | return TRUE; |
| 3598 | 128 | } |
| 129 | ||
|
5205
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4586
diff
changeset
|
130 | static GaimGtkPluginUiInfo ui_info = |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4586
diff
changeset
|
131 | { |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4586
diff
changeset
|
132 | get_config_frame |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4586
diff
changeset
|
133 | }; |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4586
diff
changeset
|
134 | |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4586
diff
changeset
|
135 | static GaimPluginInfo info = |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4586
diff
changeset
|
136 | { |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4586
diff
changeset
|
137 | 2, /**< api_version */ |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4586
diff
changeset
|
138 | GAIM_PLUGIN_STANDARD, /**< type */ |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4586
diff
changeset
|
139 | GAIM_GTK_PLUGIN_TYPE, /**< ui_requirement */ |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4586
diff
changeset
|
140 | 0, /**< flags */ |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4586
diff
changeset
|
141 | NULL, /**< dependencies */ |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4586
diff
changeset
|
142 | GAIM_PRIORITY_DEFAULT, /**< priority */ |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4586
diff
changeset
|
143 | |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4586
diff
changeset
|
144 | TIMESTAMP_PLUGIN_ID, /**< id */ |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4586
diff
changeset
|
145 | N_("Timestamp"), /**< name */ |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4586
diff
changeset
|
146 | VERSION, /**< version */ |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4586
diff
changeset
|
147 | /** summary */ |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4586
diff
changeset
|
148 | N_("Adds iChat-style timestamps to conversations every N minutes."), |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4586
diff
changeset
|
149 | /** description */ |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4586
diff
changeset
|
150 | N_("Adds iChat-style timestamps to conversations every N minutes."), |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4586
diff
changeset
|
151 | "Sean Egan <bj91704@binghamton.edu>", /**< author */ |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4586
diff
changeset
|
152 | WEBSITE, /**< homepage */ |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4586
diff
changeset
|
153 | |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4586
diff
changeset
|
154 | plugin_load, /**< load */ |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4586
diff
changeset
|
155 | plugin_unload, /**< unload */ |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4586
diff
changeset
|
156 | NULL, /**< destroy */ |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4586
diff
changeset
|
157 | |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4586
diff
changeset
|
158 | &ui_info, /**< ui_info */ |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4586
diff
changeset
|
159 | NULL /**< extra_info */ |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4586
diff
changeset
|
160 | }; |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4586
diff
changeset
|
161 | |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4586
diff
changeset
|
162 | static void |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4586
diff
changeset
|
163 | __init_plugin(GaimPlugin *plugin) |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4586
diff
changeset
|
164 | { |
| 3598 | 165 | } |
| 166 | ||
|
5205
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4586
diff
changeset
|
167 | GAIM_INIT_PLUGIN(timestamp, __init_plugin, info); |