Sat, 14 Jun 2003 23:21:02 +0000
[gaim-migrate @ 6304]
The legendary Header File Cleanup! Files now only include what they need.
This should reduce the number of files that must recompile when a header
file changes. It's a lot nicer. Trust me on it. I also added a couple new
header files. I hope I didn't break TOO much!
| 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 | ||
|
5872
754c63f29b77
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5614
diff
changeset
|
6 | #include "internal.h" |
|
754c63f29b77
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5614
diff
changeset
|
7 | |
|
754c63f29b77
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5614
diff
changeset
|
8 | #include "connection.h" |
|
754c63f29b77
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5614
diff
changeset
|
9 | #include "debug.h" |
|
754c63f29b77
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5614
diff
changeset
|
10 | #include "server.h" |
|
754c63f29b77
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5614
diff
changeset
|
11 | |
|
754c63f29b77
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5614
diff
changeset
|
12 | #include "gtkplugin.h" |
|
754c63f29b77
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5614
diff
changeset
|
13 | #include "gtkutils.h" |
|
4202
8b92de3b1c07
[gaim-migrate @ 4438]
Christian Hammond <chipx86@chipx86.com>
parents:
4165
diff
changeset
|
14 | |
| 4608 | 15 | #include "gaim.h" |
| 4103 | 16 | |
|
5205
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
17 | #define IDLE_PLUGIN_ID "gtk-idle" |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
18 | |
|
5587
22cb9fe4798a
[gaim-migrate @ 5991]
Christian Hammond <chipx86@chipx86.com>
parents:
5530
diff
changeset
|
19 | static GaimConnection *gc = NULL; |
| 4103 | 20 | |
| 21 | static void set_idle(GtkWidget *button, GtkWidget *spinner) { | |
| 22 | time_t t; | |
| 23 | int tm = CLAMP(gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(spinner)), 0, G_MAXINT); | |
|
5587
22cb9fe4798a
[gaim-migrate @ 5991]
Christian Hammond <chipx86@chipx86.com>
parents:
5530
diff
changeset
|
24 | GaimAccount *account; |
|
22cb9fe4798a
[gaim-migrate @ 5991]
Christian Hammond <chipx86@chipx86.com>
parents:
5530
diff
changeset
|
25 | |
|
22cb9fe4798a
[gaim-migrate @ 5991]
Christian Hammond <chipx86@chipx86.com>
parents:
5530
diff
changeset
|
26 | if (!gc) |
| 4103 | 27 | return; |
|
5587
22cb9fe4798a
[gaim-migrate @ 5991]
Christian Hammond <chipx86@chipx86.com>
parents:
5530
diff
changeset
|
28 | |
|
22cb9fe4798a
[gaim-migrate @ 5991]
Christian Hammond <chipx86@chipx86.com>
parents:
5530
diff
changeset
|
29 | account = gaim_connection_get_account(gc); |
|
22cb9fe4798a
[gaim-migrate @ 5991]
Christian Hammond <chipx86@chipx86.com>
parents:
5530
diff
changeset
|
30 | |
|
5227
6b44f7901f94
[gaim-migrate @ 5597]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
31 | gaim_debug(GAIM_DEBUG_INFO, "idle", |
|
5587
22cb9fe4798a
[gaim-migrate @ 5991]
Christian Hammond <chipx86@chipx86.com>
parents:
5530
diff
changeset
|
32 | "setting idle time for %s to %d\n", |
|
22cb9fe4798a
[gaim-migrate @ 5991]
Christian Hammond <chipx86@chipx86.com>
parents:
5530
diff
changeset
|
33 | gaim_account_get_username(account), tm); |
| 4103 | 34 | time(&t); |
| 35 | t -= 60 * tm; | |
|
5587
22cb9fe4798a
[gaim-migrate @ 5991]
Christian Hammond <chipx86@chipx86.com>
parents:
5530
diff
changeset
|
36 | gc->last_sent_time = t; |
| 4103 | 37 | serv_set_idle(gc, 60 * tm); |
| 38 | gc->is_idle = 0; | |
| 39 | } | |
| 40 | ||
|
5587
22cb9fe4798a
[gaim-migrate @ 5991]
Christian Hammond <chipx86@chipx86.com>
parents:
5530
diff
changeset
|
41 | static void sel_gc(GtkWidget *opt, GaimConnection *g) { |
| 4103 | 42 | gc = g; |
| 43 | } | |
| 44 | ||
| 45 | static void make_connect_menu(GtkWidget *box) { | |
| 46 | GtkWidget *optmenu, *menu, *opt; | |
|
5587
22cb9fe4798a
[gaim-migrate @ 5991]
Christian Hammond <chipx86@chipx86.com>
parents:
5530
diff
changeset
|
47 | GaimAccount *account; |
|
22cb9fe4798a
[gaim-migrate @ 5991]
Christian Hammond <chipx86@chipx86.com>
parents:
5530
diff
changeset
|
48 | GList *c = gaim_connections_get_all(); |
|
22cb9fe4798a
[gaim-migrate @ 5991]
Christian Hammond <chipx86@chipx86.com>
parents:
5530
diff
changeset
|
49 | GaimConnection *g; |
| 4103 | 50 | |
| 51 | optmenu = gtk_option_menu_new(); | |
| 52 | gtk_box_pack_start(GTK_BOX(box), optmenu, FALSE, FALSE, 5); | |
| 53 | ||
| 54 | menu = gtk_menu_new(); | |
| 55 | ||
| 56 | while (c) { | |
|
5587
22cb9fe4798a
[gaim-migrate @ 5991]
Christian Hammond <chipx86@chipx86.com>
parents:
5530
diff
changeset
|
57 | g = (GaimConnection *)c->data; |
|
22cb9fe4798a
[gaim-migrate @ 5991]
Christian Hammond <chipx86@chipx86.com>
parents:
5530
diff
changeset
|
58 | account = gaim_connection_get_account(g); |
|
22cb9fe4798a
[gaim-migrate @ 5991]
Christian Hammond <chipx86@chipx86.com>
parents:
5530
diff
changeset
|
59 | |
|
5614
0cac63c743b1
[gaim-migrate @ 6021]
Christian Hammond <chipx86@chipx86.com>
parents:
5587
diff
changeset
|
60 | opt = gtk_menu_item_new_with_label(gaim_account_get_username(account)); |
|
5314
56ef6a09fb99
[gaim-migrate @ 5686]
Christian Hammond <chipx86@chipx86.com>
parents:
5227
diff
changeset
|
61 | g_signal_connect(G_OBJECT(opt), "activate", |
|
4165
9d849f3a4dff
[gaim-migrate @ 4394]
Christian Hammond <chipx86@chipx86.com>
parents:
4103
diff
changeset
|
62 | G_CALLBACK(sel_gc), g); |
| 4635 | 63 | gtk_menu_shell_append(GTK_MENU_SHELL(menu), opt); |
| 4103 | 64 | gtk_widget_show(opt); |
|
5587
22cb9fe4798a
[gaim-migrate @ 5991]
Christian Hammond <chipx86@chipx86.com>
parents:
5530
diff
changeset
|
65 | c = g_list_next(c); |
| 4103 | 66 | } |
| 67 | ||
| 68 | gtk_option_menu_remove_menu(GTK_OPTION_MENU(optmenu)); | |
| 69 | gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), menu); | |
| 70 | gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), 0); | |
| 71 | ||
|
5587
22cb9fe4798a
[gaim-migrate @ 5991]
Christian Hammond <chipx86@chipx86.com>
parents:
5530
diff
changeset
|
72 | if (gaim_connections_get_all()) |
|
22cb9fe4798a
[gaim-migrate @ 5991]
Christian Hammond <chipx86@chipx86.com>
parents:
5530
diff
changeset
|
73 | gc = gaim_connections_get_all()->data; |
| 4103 | 74 | else |
| 75 | gc = NULL; | |
| 76 | } | |
| 77 | ||
|
5205
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
78 | static GtkWidget * |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
79 | get_config_frame(GaimPlugin *plugin) |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
80 | { |
| 4103 | 81 | GtkWidget *ret; |
| 82 | GtkWidget *frame, *label; | |
| 83 | GtkWidget *vbox, *hbox; | |
| 84 | GtkAdjustment *adj; | |
| 85 | GtkWidget *spinner, *button; | |
| 86 | ||
| 87 | ret = gtk_vbox_new(FALSE, 18); | |
| 88 | gtk_container_set_border_width(GTK_CONTAINER(ret), 12); | |
| 89 | ||
|
5530
ba1ad464b56f
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
90 | frame = gaim_gtk_make_frame(ret, _("Idle Time")); |
| 4103 | 91 | |
| 92 | vbox = gtk_vbox_new(FALSE, 5); | |
| 93 | gtk_container_add(GTK_CONTAINER(frame), vbox); | |
| 94 | ||
| 95 | hbox = gtk_hbox_new(FALSE, 5); | |
| 96 | gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 5); | |
| 97 | ||
|
4287
28045a1884e8
[gaim-migrate @ 4539]
Nicolás Lichtmaier <nico@lichtmaier.com.ar>
parents:
4260
diff
changeset
|
98 | label = gtk_label_new(_("Set")); |
| 4103 | 99 | gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 5); |
| 100 | ||
| 101 | make_connect_menu(hbox); | |
| 102 | ||
|
4287
28045a1884e8
[gaim-migrate @ 4539]
Nicolás Lichtmaier <nico@lichtmaier.com.ar>
parents:
4260
diff
changeset
|
103 | label = gtk_label_new(_("idle for")); |
| 4103 | 104 | gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 5); |
| 105 | ||
| 106 | adj = (GtkAdjustment *)gtk_adjustment_new(10, 0, G_MAXINT, 1, 0, 0); | |
| 107 | spinner = gtk_spin_button_new(adj, 0, 0); | |
| 108 | gtk_box_pack_start(GTK_BOX(hbox), spinner, TRUE, TRUE, 0); | |
| 109 | ||
|
4287
28045a1884e8
[gaim-migrate @ 4539]
Nicolás Lichtmaier <nico@lichtmaier.com.ar>
parents:
4260
diff
changeset
|
110 | label = gtk_label_new(_("minutes.")); |
| 4103 | 111 | gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 5); |
| 112 | ||
| 113 | hbox = gtk_hbox_new(TRUE, 5); | |
| 114 | gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 5); | |
| 115 | ||
| 116 | button = gtk_button_new_with_mnemonic(_("_Set")); | |
| 117 | gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 5); | |
|
5314
56ef6a09fb99
[gaim-migrate @ 5686]
Christian Hammond <chipx86@chipx86.com>
parents:
5227
diff
changeset
|
118 | g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(set_idle), spinner); |
| 4103 | 119 | |
| 120 | gtk_widget_show_all(ret); | |
| 121 | ||
| 122 | return ret; | |
| 123 | } | |
|
5205
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
124 | |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
125 | static GaimGtkPluginUiInfo ui_info = |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
126 | { |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
127 | get_config_frame |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
128 | }; |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
129 | |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
130 | static GaimPluginInfo info = |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
131 | { |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
132 | 2, |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
133 | GAIM_PLUGIN_STANDARD, |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
134 | GAIM_GTK_PLUGIN_TYPE, |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
135 | 0, |
|
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 | GAIM_PRIORITY_DEFAULT, |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
138 | IDLE_PLUGIN_ID, |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
139 | N_("I'dle Mak'er"), |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
140 | VERSION, |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
141 | 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
|
142 | 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
|
143 | "Eric Warmenhoven <eric@warmenhoven.org>", |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
144 | WEBSITE, |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
145 | NULL, |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
146 | NULL, |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
147 | NULL, |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
148 | &ui_info, |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
149 | NULL |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
150 | }; |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
151 | |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
152 | static void |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
153 | __init_plugin(GaimPlugin *plugin) |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
154 | { |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
155 | } |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
156 | |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
157 | GAIM_INIT_PLUGIN(idle, __init_plugin, info); |