annotate plugins/idle.c @ 4456:1630b1dca931

[gaim-migrate @ 4731] Whoops. committer: Tailor Script <tailor@pidgin.im>
author Sean Egan <seanegan@gmail.com>
date Wed, 29 Jan 2003 00:25:37 +0000
parents cddb50734169
children 2427d847e39c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4103
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1 /* a nifty little plugin to set your idle time to whatever you want it to be.
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2 * useful for almost nothing. mostly just a demo plugin. but it's fun to have
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3 * 40-day idle times.
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4 */
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
5
4202
59751fe608c5 [gaim-migrate @ 4438]
Christian Hammond <chipx86@chipx86.com>
parents: 4165
diff changeset
6 #include "config.h"
59751fe608c5 [gaim-migrate @ 4438]
Christian Hammond <chipx86@chipx86.com>
parents: 4165
diff changeset
7
59751fe608c5 [gaim-migrate @ 4438]
Christian Hammond <chipx86@chipx86.com>
parents: 4165
diff changeset
8 #ifndef GAIM_PLUGINS
4103
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
9 #define GAIM_PLUGINS
4202
59751fe608c5 [gaim-migrate @ 4438]
Christian Hammond <chipx86@chipx86.com>
parents: 4165
diff changeset
10 #endif
59751fe608c5 [gaim-migrate @ 4438]
Christian Hammond <chipx86@chipx86.com>
parents: 4165
diff changeset
11
4103
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
12 #include "multi.h"
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
13 #include "gaim.h"
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
14 #include <sys/time.h>
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
15
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
16 static struct gaim_connection *gc = NULL;
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
17
4287
f98e27e2cb10 [gaim-migrate @ 4539]
Christian Hammond <chipx86@chipx86.com>
parents: 4260
diff changeset
18 const char *name() {
f98e27e2cb10 [gaim-migrate @ 4539]
Christian Hammond <chipx86@chipx86.com>
parents: 4260
diff changeset
19 return _("I'dle Mak'er");
4103
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
20 }
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
21
4287
f98e27e2cb10 [gaim-migrate @ 4539]
Christian Hammond <chipx86@chipx86.com>
parents: 4260
diff changeset
22 const char *description() {
f98e27e2cb10 [gaim-migrate @ 4539]
Christian Hammond <chipx86@chipx86.com>
parents: 4260
diff changeset
23 return _("Allows you to hand-configure how long you've been idle for");
4103
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
24 }
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
25
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
26 char *gaim_plugin_init(GModule *module) {
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
27 return NULL;
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
28 }
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
29
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
30 static void set_idle(GtkWidget *button, GtkWidget *spinner) {
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
31 time_t t;
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
32 int tm = CLAMP(gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(spinner)), 0, G_MAXINT);
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
33 if (!gc) {
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
34 return;
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
35 }
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
36 debug_printf("setting idle time for %s to %d\n", gc->username, tm);
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
37 time(&t);
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
38 t -= 60 * tm;
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
39 gc->lastsent = t;
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
40 serv_set_idle(gc, 60 * tm);
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
41 gc->is_idle = 0;
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
42 }
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
43
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
44 static void sel_gc(GtkWidget *opt, struct gaim_connection *g) {
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
45 gc = g;
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
46 }
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
47
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
48 static void make_connect_menu(GtkWidget *box) {
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
49 GtkWidget *optmenu, *menu, *opt;
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
50 GSList *c = connections;
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
51 struct gaim_connection *g;
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
52
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
53 optmenu = gtk_option_menu_new();
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
54 gtk_box_pack_start(GTK_BOX(box), optmenu, FALSE, FALSE, 5);
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
55
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
56 menu = gtk_menu_new();
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
57
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
58 while (c) {
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
59 g = (struct gaim_connection *)c->data;
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
60 opt = gtk_menu_item_new_with_label(g->username);
4165
07a3d1fae88f [gaim-migrate @ 4394]
Christian Hammond <chipx86@chipx86.com>
parents: 4103
diff changeset
61 g_signal_connect(GTK_OBJECT(opt), "activate",
07a3d1fae88f [gaim-migrate @ 4394]
Christian Hammond <chipx86@chipx86.com>
parents: 4103
diff changeset
62 G_CALLBACK(sel_gc), g);
4103
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
63 gtk_menu_append(GTK_MENU(menu), opt);
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
64 gtk_widget_show(opt);
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
65 c = g_slist_next(c);
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
66 }
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
67
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
68 gtk_option_menu_remove_menu(GTK_OPTION_MENU(optmenu));
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
69 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), menu);
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
70 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), 0);
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
71
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
72 if (connections)
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
73 gc = connections->data;
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
74 else
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
75 gc = NULL;
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
76 }
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
77
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
78 struct gaim_plugin_description desc;
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
79 struct gaim_plugin_description *gaim_plugin_desc() {
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
80 desc.api_version = PLUGIN_API_VERSION;
4260
43864b6a28a2 [gaim-migrate @ 4511]
Sean Egan <seanegan@gmail.com>
parents: 4259
diff changeset
81 desc.name = g_strdup("I'dle Mak'er");
4103
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
82 desc.version = g_strdup(VERSION);
4287
f98e27e2cb10 [gaim-migrate @ 4539]
Christian Hammond <chipx86@chipx86.com>
parents: 4260
diff changeset
83 desc.description = g_strdup(_("Allows you to hand-configure how long you've been idle for"));
4103
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
84 desc.authors = g_strdup("Eric Warmenhoven &lt;eric@warmenhoven.org>");
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
85 desc.url = g_strdup(WEBSITE);
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
86 return &desc;
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
87 }
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
88
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
89 GtkWidget *gaim_plugin_config_gtk() {
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
90 GtkWidget *ret;
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
91 GtkWidget *frame, *label;
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
92 GtkWidget *vbox, *hbox;
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
93 GtkAdjustment *adj;
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
94 GtkWidget *spinner, *button;
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
95
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
96 ret = gtk_vbox_new(FALSE, 18);
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
97 gtk_container_set_border_width(GTK_CONTAINER(ret), 12);
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
98
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
99 frame = make_frame(ret, _("Idle Time"));
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
100
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
101 vbox = gtk_vbox_new(FALSE, 5);
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
102 gtk_container_add(GTK_CONTAINER(frame), vbox);
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
103
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
104 hbox = gtk_hbox_new(FALSE, 5);
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
105 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 5);
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
106
4287
f98e27e2cb10 [gaim-migrate @ 4539]
Christian Hammond <chipx86@chipx86.com>
parents: 4260
diff changeset
107 label = gtk_label_new(_("Set"));
4103
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
108 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 5);
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
109
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
110 make_connect_menu(hbox);
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
111
4287
f98e27e2cb10 [gaim-migrate @ 4539]
Christian Hammond <chipx86@chipx86.com>
parents: 4260
diff changeset
112 label = gtk_label_new(_("idle for"));
4103
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
113 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 5);
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
114
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
115 adj = (GtkAdjustment *)gtk_adjustment_new(10, 0, G_MAXINT, 1, 0, 0);
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
116 spinner = gtk_spin_button_new(adj, 0, 0);
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
117 gtk_box_pack_start(GTK_BOX(hbox), spinner, TRUE, TRUE, 0);
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
118
4287
f98e27e2cb10 [gaim-migrate @ 4539]
Christian Hammond <chipx86@chipx86.com>
parents: 4260
diff changeset
119 label = gtk_label_new(_("minutes."));
4103
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
120 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 5);
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
121
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
122 hbox = gtk_hbox_new(TRUE, 5);
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
123 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 5);
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
124
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
125 button = gtk_button_new_with_mnemonic(_("_Set"));
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
126 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 5);
4165
07a3d1fae88f [gaim-migrate @ 4394]
Christian Hammond <chipx86@chipx86.com>
parents: 4103
diff changeset
127 g_signal_connect(GTK_OBJECT(button), "clicked", G_CALLBACK(set_idle), spinner);
4103
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
128
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
129 gtk_widget_show_all(ret);
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
130
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
131 return ret;
caa7701b67d1 [gaim-migrate @ 4318]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
132 }