comparison plugins/idle.c @ 4103:caa7701b67d1

[gaim-migrate @ 4318] (17:19:40) Ashaman TU: I don't suppose you guys could work the idlemaker pluggin into gaim? committer: Tailor Script <tailor@pidgin.im>
author Sean Egan <seanegan@gmail.com>
date Thu, 19 Dec 2002 23:05:22 +0000
parents
children 07a3d1fae88f
comparison
equal deleted inserted replaced
4102:c5ce82228a2f 4103:caa7701b67d1
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
6 #define GAIM_PLUGINS
7 #include "multi.h"
8 #include "gaim.h"
9 #include <sys/time.h>
10 #include "pixmaps/ok.xpm"
11
12 static struct gaim_connection *gc = NULL;
13
14 char *name() {
15 return "I'dle Mak'er";
16 }
17
18 char *description() {
19 return "Allows you to hand-configure how long you've been idle for";
20 }
21
22 char *gaim_plugin_init(GModule *module) {
23 return NULL;
24 }
25
26 static void set_idle(GtkWidget *button, GtkWidget *spinner) {
27 time_t t;
28 int tm = CLAMP(gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(spinner)), 0, G_MAXINT);
29 if (!gc) {
30 return;
31 }
32 debug_printf("setting idle time for %s to %d\n", gc->username, tm);
33 time(&t);
34 t -= 60 * tm;
35 gc->lastsent = t;
36 serv_set_idle(gc, 60 * tm);
37 gc->is_idle = 0;
38 }
39
40 static void sel_gc(GtkWidget *opt, struct gaim_connection *g) {
41 gc = g;
42 }
43
44 static void make_connect_menu(GtkWidget *box) {
45 GtkWidget *optmenu, *menu, *opt;
46 GSList *c = connections;
47 struct gaim_connection *g;
48
49 optmenu = gtk_option_menu_new();
50 gtk_box_pack_start(GTK_BOX(box), optmenu, FALSE, FALSE, 5);
51
52 menu = gtk_menu_new();
53
54 while (c) {
55 g = (struct gaim_connection *)c->data;
56 opt = gtk_menu_item_new_with_label(g->username);
57 gtk_signal_connect(GTK_OBJECT(opt), "activate",
58 GTK_SIGNAL_FUNC(sel_gc), g);
59 gtk_menu_append(GTK_MENU(menu), opt);
60 gtk_widget_show(opt);
61 c = g_slist_next(c);
62 }
63
64 gtk_option_menu_remove_menu(GTK_OPTION_MENU(optmenu));
65 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), menu);
66 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), 0);
67
68 if (connections)
69 gc = connections->data;
70 else
71 gc = NULL;
72 }
73
74 struct gaim_plugin_description desc;
75 struct gaim_plugin_description *gaim_plugin_desc() {
76 desc.api_version = PLUGIN_API_VERSION;
77 desc.name = g_strdup("I'dle Mak'er");
78 desc.version = g_strdup(VERSION);
79 desc.description = g_strdup("Allows you to hand-configure how long you've been idle for");
80 desc.authors = g_strdup("Eric Warmenhoven &lt;eric@warmenhoven.org>");
81 desc.url = g_strdup(WEBSITE);
82 return &desc;
83 }
84
85 GtkWidget *gaim_plugin_config_gtk() {
86 GtkWidget *ret;
87 GtkWidget *frame, *label;
88 GtkWidget *vbox, *hbox;
89 GtkAdjustment *adj;
90 GtkWidget *spinner, *button;
91
92 ret = gtk_vbox_new(FALSE, 18);
93 gtk_container_set_border_width(GTK_CONTAINER(ret), 12);
94
95 frame = make_frame(ret, _("Idle Time"));
96
97 vbox = gtk_vbox_new(FALSE, 5);
98 gtk_container_add(GTK_CONTAINER(frame), vbox);
99
100 hbox = gtk_hbox_new(FALSE, 5);
101 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 5);
102
103 label = gtk_label_new("Set");
104 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 5);
105
106 make_connect_menu(hbox);
107
108 label = gtk_label_new("idle for");
109 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 5);
110
111 adj = (GtkAdjustment *)gtk_adjustment_new(10, 0, G_MAXINT, 1, 0, 0);
112 spinner = gtk_spin_button_new(adj, 0, 0);
113 gtk_box_pack_start(GTK_BOX(hbox), spinner, TRUE, TRUE, 0);
114
115 label = gtk_label_new("minutes.");
116 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 5);
117
118 hbox = gtk_hbox_new(TRUE, 5);
119 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 5);
120
121 button = gtk_button_new_with_mnemonic(_("_Set"));
122 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 5);
123 gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(set_idle), spinner);
124
125 gtk_widget_show_all(ret);
126
127 return ret;
128 }