Sat, 26 Apr 2003 17:36:52 +0000
[gaim-migrate @ 5597]
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 | } | |
|
5227
6b44f7901f94
[gaim-migrate @ 5597]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
23 | gaim_debug(GAIM_DEBUG_INFO, "idle", |
|
6b44f7901f94
[gaim-migrate @ 5597]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
24 | "setting idle time for %s to %d\n", gc->username, tm); |
| 4103 | 25 | time(&t); |
| 26 | t -= 60 * tm; | |
| 27 | gc->lastsent = t; | |
| 28 | serv_set_idle(gc, 60 * tm); | |
| 29 | gc->is_idle = 0; | |
| 30 | } | |
| 31 | ||
| 32 | static void sel_gc(GtkWidget *opt, struct gaim_connection *g) { | |
| 33 | gc = g; | |
| 34 | } | |
| 35 | ||
| 36 | static void make_connect_menu(GtkWidget *box) { | |
| 37 | GtkWidget *optmenu, *menu, *opt; | |
| 38 | GSList *c = connections; | |
| 39 | struct gaim_connection *g; | |
| 40 | ||
| 41 | optmenu = gtk_option_menu_new(); | |
| 42 | gtk_box_pack_start(GTK_BOX(box), optmenu, FALSE, FALSE, 5); | |
| 43 | ||
| 44 | menu = gtk_menu_new(); | |
| 45 | ||
| 46 | while (c) { | |
| 47 | g = (struct gaim_connection *)c->data; | |
| 48 | opt = gtk_menu_item_new_with_label(g->username); | |
|
4165
9d849f3a4dff
[gaim-migrate @ 4394]
Christian Hammond <chipx86@chipx86.com>
parents:
4103
diff
changeset
|
49 | g_signal_connect(GTK_OBJECT(opt), "activate", |
|
9d849f3a4dff
[gaim-migrate @ 4394]
Christian Hammond <chipx86@chipx86.com>
parents:
4103
diff
changeset
|
50 | G_CALLBACK(sel_gc), g); |
| 4635 | 51 | gtk_menu_shell_append(GTK_MENU_SHELL(menu), opt); |
| 4103 | 52 | gtk_widget_show(opt); |
| 53 | c = g_slist_next(c); | |
| 54 | } | |
| 55 | ||
| 56 | gtk_option_menu_remove_menu(GTK_OPTION_MENU(optmenu)); | |
| 57 | gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), menu); | |
| 58 | gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), 0); | |
| 59 | ||
| 60 | if (connections) | |
| 61 | gc = connections->data; | |
| 62 | else | |
| 63 | gc = NULL; | |
| 64 | } | |
| 65 | ||
|
5205
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
66 | static GtkWidget * |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
67 | get_config_frame(GaimPlugin *plugin) |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
68 | { |
| 4103 | 69 | GtkWidget *ret; |
| 70 | GtkWidget *frame, *label; | |
| 71 | GtkWidget *vbox, *hbox; | |
| 72 | GtkAdjustment *adj; | |
| 73 | GtkWidget *spinner, *button; | |
| 74 | ||
| 75 | ret = gtk_vbox_new(FALSE, 18); | |
| 76 | gtk_container_set_border_width(GTK_CONTAINER(ret), 12); | |
| 77 | ||
| 78 | frame = make_frame(ret, _("Idle Time")); | |
| 79 | ||
| 80 | vbox = gtk_vbox_new(FALSE, 5); | |
| 81 | gtk_container_add(GTK_CONTAINER(frame), vbox); | |
| 82 | ||
| 83 | hbox = gtk_hbox_new(FALSE, 5); | |
| 84 | gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 5); | |
| 85 | ||
|
4287
28045a1884e8
[gaim-migrate @ 4539]
Nicolás Lichtmaier <nico@lichtmaier.com.ar>
parents:
4260
diff
changeset
|
86 | label = gtk_label_new(_("Set")); |
| 4103 | 87 | gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 5); |
| 88 | ||
| 89 | make_connect_menu(hbox); | |
| 90 | ||
|
4287
28045a1884e8
[gaim-migrate @ 4539]
Nicolás Lichtmaier <nico@lichtmaier.com.ar>
parents:
4260
diff
changeset
|
91 | label = gtk_label_new(_("idle for")); |
| 4103 | 92 | gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 5); |
| 93 | ||
| 94 | adj = (GtkAdjustment *)gtk_adjustment_new(10, 0, G_MAXINT, 1, 0, 0); | |
| 95 | spinner = gtk_spin_button_new(adj, 0, 0); | |
| 96 | gtk_box_pack_start(GTK_BOX(hbox), spinner, TRUE, TRUE, 0); | |
| 97 | ||
|
4287
28045a1884e8
[gaim-migrate @ 4539]
Nicolás Lichtmaier <nico@lichtmaier.com.ar>
parents:
4260
diff
changeset
|
98 | label = gtk_label_new(_("minutes.")); |
| 4103 | 99 | gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 5); |
| 100 | ||
| 101 | hbox = gtk_hbox_new(TRUE, 5); | |
| 102 | gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 5); | |
| 103 | ||
| 104 | button = gtk_button_new_with_mnemonic(_("_Set")); | |
| 105 | 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
|
106 | g_signal_connect(GTK_OBJECT(button), "clicked", G_CALLBACK(set_idle), spinner); |
| 4103 | 107 | |
| 108 | gtk_widget_show_all(ret); | |
| 109 | ||
| 110 | return ret; | |
| 111 | } | |
|
5205
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
112 | |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
113 | static GaimGtkPluginUiInfo ui_info = |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
114 | { |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
115 | get_config_frame |
|
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 | |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
118 | static GaimPluginInfo info = |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
119 | { |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
120 | 2, |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
121 | GAIM_PLUGIN_STANDARD, |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
122 | GAIM_GTK_PLUGIN_TYPE, |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
123 | 0, |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
124 | NULL, |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
125 | GAIM_PRIORITY_DEFAULT, |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
126 | IDLE_PLUGIN_ID, |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
127 | N_("I'dle Mak'er"), |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
128 | VERSION, |
|
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 | 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
|
131 | "Eric Warmenhoven <eric@warmenhoven.org>", |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
132 | WEBSITE, |
|
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 | NULL, |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
136 | &ui_info, |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
137 | NULL |
|
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 | |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
140 | static void |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
141 | __init_plugin(GaimPlugin *plugin) |
|
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 | |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
145 | GAIM_INIT_PLUGIN(idle, __init_plugin, info); |