Mercurial > pidgin
annotate plugins/idle.c @ 5216:00bd3019749e
[gaim-migrate @ 5586]
debug_printf -> gaim_debug
committer: Tailor Script <tailor@pidgin.im>
author | Christian Hammond <chipx86@chipx86.com> |
---|---|
date | Sat, 26 Apr 2003 07:55:04 +0000 |
parents | fefad67de2c7 |
children | 6d1707dc8c3d |
rev | line source |
---|---|
4103 | 1 /* a nifty little plugin to set your idle time to whatever you want it to be. |
2 * useful for almost nothing. mostly just a demo plugin. but it's fun to have | |
3 * 40-day idle times. | |
4 */ | |
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 |
4608 | 8 #include "gaim.h" |
4103 | 9 #include "multi.h" |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
10 #include "gtkplugin.h" |
4103 | 11 #include <sys/time.h> |
12 | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
13 #define IDLE_PLUGIN_ID "gtk-idle" |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
14 |
4103 | 15 static struct gaim_connection *gc = NULL; |
16 | |
17 static void set_idle(GtkWidget *button, GtkWidget *spinner) { | |
18 time_t t; | |
19 int tm = CLAMP(gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(spinner)), 0, G_MAXINT); | |
20 if (!gc) { | |
21 return; | |
22 } | |
23 debug_printf("setting idle time for %s to %d\n", gc->username, tm); | |
24 time(&t); | |
25 t -= 60 * tm; | |
26 gc->lastsent = t; | |
27 serv_set_idle(gc, 60 * tm); | |
28 gc->is_idle = 0; | |
29 } | |
30 | |
31 static void sel_gc(GtkWidget *opt, struct gaim_connection *g) { | |
32 gc = g; | |
33 } | |
34 | |
35 static void make_connect_menu(GtkWidget *box) { | |
36 GtkWidget *optmenu, *menu, *opt; | |
37 GSList *c = connections; | |
38 struct gaim_connection *g; | |
39 | |
40 optmenu = gtk_option_menu_new(); | |
41 gtk_box_pack_start(GTK_BOX(box), optmenu, FALSE, FALSE, 5); | |
42 | |
43 menu = gtk_menu_new(); | |
44 | |
45 while (c) { | |
46 g = (struct gaim_connection *)c->data; | |
47 opt = gtk_menu_item_new_with_label(g->username); | |
4165
07a3d1fae88f
[gaim-migrate @ 4394]
Christian Hammond <chipx86@chipx86.com>
parents:
4103
diff
changeset
|
48 g_signal_connect(GTK_OBJECT(opt), "activate", |
07a3d1fae88f
[gaim-migrate @ 4394]
Christian Hammond <chipx86@chipx86.com>
parents:
4103
diff
changeset
|
49 G_CALLBACK(sel_gc), g); |
4635 | 50 gtk_menu_shell_append(GTK_MENU_SHELL(menu), opt); |
4103 | 51 gtk_widget_show(opt); |
52 c = g_slist_next(c); | |
53 } | |
54 | |
55 gtk_option_menu_remove_menu(GTK_OPTION_MENU(optmenu)); | |
56 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), menu); | |
57 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), 0); | |
58 | |
59 if (connections) | |
60 gc = connections->data; | |
61 else | |
62 gc = NULL; | |
63 } | |
64 | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
65 static GtkWidget * |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
66 get_config_frame(GaimPlugin *plugin) |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
67 { |
4103 | 68 GtkWidget *ret; |
69 GtkWidget *frame, *label; | |
70 GtkWidget *vbox, *hbox; | |
71 GtkAdjustment *adj; | |
72 GtkWidget *spinner, *button; | |
73 | |
74 ret = gtk_vbox_new(FALSE, 18); | |
75 gtk_container_set_border_width(GTK_CONTAINER(ret), 12); | |
76 | |
77 frame = make_frame(ret, _("Idle Time")); | |
78 | |
79 vbox = gtk_vbox_new(FALSE, 5); | |
80 gtk_container_add(GTK_CONTAINER(frame), vbox); | |
81 | |
82 hbox = gtk_hbox_new(FALSE, 5); | |
83 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 5); | |
84 | |
4287
f98e27e2cb10
[gaim-migrate @ 4539]
Christian Hammond <chipx86@chipx86.com>
parents:
4260
diff
changeset
|
85 label = gtk_label_new(_("Set")); |
4103 | 86 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 5); |
87 | |
88 make_connect_menu(hbox); | |
89 | |
4287
f98e27e2cb10
[gaim-migrate @ 4539]
Christian Hammond <chipx86@chipx86.com>
parents:
4260
diff
changeset
|
90 label = gtk_label_new(_("idle for")); |
4103 | 91 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 5); |
92 | |
93 adj = (GtkAdjustment *)gtk_adjustment_new(10, 0, G_MAXINT, 1, 0, 0); | |
94 spinner = gtk_spin_button_new(adj, 0, 0); | |
95 gtk_box_pack_start(GTK_BOX(hbox), spinner, TRUE, TRUE, 0); | |
96 | |
4287
f98e27e2cb10
[gaim-migrate @ 4539]
Christian Hammond <chipx86@chipx86.com>
parents:
4260
diff
changeset
|
97 label = gtk_label_new(_("minutes.")); |
4103 | 98 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 5); |
99 | |
100 hbox = gtk_hbox_new(TRUE, 5); | |
101 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 5); | |
102 | |
103 button = gtk_button_new_with_mnemonic(_("_Set")); | |
104 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
|
105 g_signal_connect(GTK_OBJECT(button), "clicked", G_CALLBACK(set_idle), spinner); |
4103 | 106 |
107 gtk_widget_show_all(ret); | |
108 | |
109 return ret; | |
110 } | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
111 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
112 static GaimGtkPluginUiInfo ui_info = |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
113 { |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
114 get_config_frame |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
115 }; |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
116 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
117 static GaimPluginInfo info = |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
118 { |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
119 2, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
120 GAIM_PLUGIN_STANDARD, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
121 GAIM_GTK_PLUGIN_TYPE, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
122 0, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
123 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
124 GAIM_PRIORITY_DEFAULT, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
125 IDLE_PLUGIN_ID, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
126 N_("I'dle Mak'er"), |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
127 VERSION, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
128 N_("Allows you to hand-configure how long you've been idle for"), |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
129 N_("Allows you to hand-configure how long you've been idle for"), |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
130 "Eric Warmenhoven <eric@warmenhoven.org>", |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
131 WEBSITE, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
132 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
133 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
134 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
135 &ui_info, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
136 NULL |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
137 }; |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
138 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
139 static void |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
140 __init_plugin(GaimPlugin *plugin) |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
141 { |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
142 } |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
143 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
144 GAIM_INIT_PLUGIN(idle, __init_plugin, info); |