Sat, 26 Apr 2003 07:15:59 +0000
[gaim-migrate @ 5583]
More debug_printf -> gaim_debug.
| 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
8b92de3b1c07
[gaim-migrate @ 4438]
Christian Hammond <chipx86@chipx86.com>
parents:
4165
diff
changeset
|
6 | #include "config.h" |
|
8b92de3b1c07
[gaim-migrate @ 4438]
Christian Hammond <chipx86@chipx86.com>
parents:
4165
diff
changeset
|
7 | |
| 4608 | 8 | #include "gaim.h" |
| 4103 | 9 | #include "multi.h" |
|
5205
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
10 | #include "gtkplugin.h" |
| 4103 | 11 | #include <sys/time.h> |
| 12 | ||
|
5205
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
13 | #define IDLE_PLUGIN_ID "gtk-idle" |
|
242b8aa81328
[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
9d849f3a4dff
[gaim-migrate @ 4394]
Christian Hammond <chipx86@chipx86.com>
parents:
4103
diff
changeset
|
48 | g_signal_connect(GTK_OBJECT(opt), "activate", |
|
9d849f3a4dff
[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
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
65 | static GtkWidget * |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
66 | get_config_frame(GaimPlugin *plugin) |
|
242b8aa81328
[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
28045a1884e8
[gaim-migrate @ 4539]
Nicolás Lichtmaier <nico@lichtmaier.com.ar>
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
28045a1884e8
[gaim-migrate @ 4539]
Nicolás Lichtmaier <nico@lichtmaier.com.ar>
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
28045a1884e8
[gaim-migrate @ 4539]
Nicolás Lichtmaier <nico@lichtmaier.com.ar>
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
9d849f3a4dff
[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
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
111 | |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
112 | static GaimGtkPluginUiInfo ui_info = |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
113 | { |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
114 | get_config_frame |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
115 | }; |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
116 | |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
117 | static GaimPluginInfo info = |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
118 | { |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
119 | 2, |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
120 | GAIM_PLUGIN_STANDARD, |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
121 | GAIM_GTK_PLUGIN_TYPE, |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
122 | 0, |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
123 | NULL, |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
124 | GAIM_PRIORITY_DEFAULT, |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
125 | IDLE_PLUGIN_ID, |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
126 | N_("I'dle Mak'er"), |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
127 | VERSION, |
|
242b8aa81328
[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"), |
|
242b8aa81328
[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"), |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
130 | "Eric Warmenhoven <eric@warmenhoven.org>", |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
131 | WEBSITE, |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
132 | NULL, |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
133 | NULL, |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
134 | NULL, |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
135 | &ui_info, |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
136 | NULL |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
137 | }; |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
138 | |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
139 | static void |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
140 | __init_plugin(GaimPlugin *plugin) |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
141 | { |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
142 | } |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
143 | |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
144 | GAIM_INIT_PLUGIN(idle, __init_plugin, info); |