Tue, 03 Jun 2003 05:33:46 +0000
[gaim-migrate @ 6109]
Updating the protocol type now updates the fields in the modify account
dialog. Also, fixed a bug that caused an infinite loop.
| 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 | |
|
5587
22cb9fe4798a
[gaim-migrate @ 5991]
Christian Hammond <chipx86@chipx86.com>
parents:
5530
diff
changeset
|
15 | static GaimConnection *gc = NULL; |
| 4103 | 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); | |
|
5587
22cb9fe4798a
[gaim-migrate @ 5991]
Christian Hammond <chipx86@chipx86.com>
parents:
5530
diff
changeset
|
20 | GaimAccount *account; |
|
22cb9fe4798a
[gaim-migrate @ 5991]
Christian Hammond <chipx86@chipx86.com>
parents:
5530
diff
changeset
|
21 | |
|
22cb9fe4798a
[gaim-migrate @ 5991]
Christian Hammond <chipx86@chipx86.com>
parents:
5530
diff
changeset
|
22 | if (!gc) |
| 4103 | 23 | return; |
|
5587
22cb9fe4798a
[gaim-migrate @ 5991]
Christian Hammond <chipx86@chipx86.com>
parents:
5530
diff
changeset
|
24 | |
|
22cb9fe4798a
[gaim-migrate @ 5991]
Christian Hammond <chipx86@chipx86.com>
parents:
5530
diff
changeset
|
25 | account = gaim_connection_get_account(gc); |
|
22cb9fe4798a
[gaim-migrate @ 5991]
Christian Hammond <chipx86@chipx86.com>
parents:
5530
diff
changeset
|
26 | |
|
5227
6b44f7901f94
[gaim-migrate @ 5597]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
27 | gaim_debug(GAIM_DEBUG_INFO, "idle", |
|
5587
22cb9fe4798a
[gaim-migrate @ 5991]
Christian Hammond <chipx86@chipx86.com>
parents:
5530
diff
changeset
|
28 | "setting idle time for %s to %d\n", |
|
22cb9fe4798a
[gaim-migrate @ 5991]
Christian Hammond <chipx86@chipx86.com>
parents:
5530
diff
changeset
|
29 | gaim_account_get_username(account), tm); |
| 4103 | 30 | time(&t); |
| 31 | t -= 60 * tm; | |
|
5587
22cb9fe4798a
[gaim-migrate @ 5991]
Christian Hammond <chipx86@chipx86.com>
parents:
5530
diff
changeset
|
32 | gc->last_sent_time = t; |
| 4103 | 33 | serv_set_idle(gc, 60 * tm); |
| 34 | gc->is_idle = 0; | |
| 35 | } | |
| 36 | ||
|
5587
22cb9fe4798a
[gaim-migrate @ 5991]
Christian Hammond <chipx86@chipx86.com>
parents:
5530
diff
changeset
|
37 | static void sel_gc(GtkWidget *opt, GaimConnection *g) { |
| 4103 | 38 | gc = g; |
| 39 | } | |
| 40 | ||
| 41 | static void make_connect_menu(GtkWidget *box) { | |
| 42 | GtkWidget *optmenu, *menu, *opt; | |
|
5587
22cb9fe4798a
[gaim-migrate @ 5991]
Christian Hammond <chipx86@chipx86.com>
parents:
5530
diff
changeset
|
43 | GaimAccount *account; |
|
22cb9fe4798a
[gaim-migrate @ 5991]
Christian Hammond <chipx86@chipx86.com>
parents:
5530
diff
changeset
|
44 | GList *c = gaim_connections_get_all(); |
|
22cb9fe4798a
[gaim-migrate @ 5991]
Christian Hammond <chipx86@chipx86.com>
parents:
5530
diff
changeset
|
45 | GaimConnection *g; |
| 4103 | 46 | |
| 47 | optmenu = gtk_option_menu_new(); | |
| 48 | gtk_box_pack_start(GTK_BOX(box), optmenu, FALSE, FALSE, 5); | |
| 49 | ||
| 50 | menu = gtk_menu_new(); | |
| 51 | ||
| 52 | while (c) { | |
|
5587
22cb9fe4798a
[gaim-migrate @ 5991]
Christian Hammond <chipx86@chipx86.com>
parents:
5530
diff
changeset
|
53 | g = (GaimConnection *)c->data; |
|
22cb9fe4798a
[gaim-migrate @ 5991]
Christian Hammond <chipx86@chipx86.com>
parents:
5530
diff
changeset
|
54 | account = gaim_connection_get_account(g); |
|
22cb9fe4798a
[gaim-migrate @ 5991]
Christian Hammond <chipx86@chipx86.com>
parents:
5530
diff
changeset
|
55 | |
|
5614
0cac63c743b1
[gaim-migrate @ 6021]
Christian Hammond <chipx86@chipx86.com>
parents:
5587
diff
changeset
|
56 | 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
|
57 | g_signal_connect(G_OBJECT(opt), "activate", |
|
4165
9d849f3a4dff
[gaim-migrate @ 4394]
Christian Hammond <chipx86@chipx86.com>
parents:
4103
diff
changeset
|
58 | G_CALLBACK(sel_gc), g); |
| 4635 | 59 | gtk_menu_shell_append(GTK_MENU_SHELL(menu), opt); |
| 4103 | 60 | gtk_widget_show(opt); |
|
5587
22cb9fe4798a
[gaim-migrate @ 5991]
Christian Hammond <chipx86@chipx86.com>
parents:
5530
diff
changeset
|
61 | c = g_list_next(c); |
| 4103 | 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 | ||
|
5587
22cb9fe4798a
[gaim-migrate @ 5991]
Christian Hammond <chipx86@chipx86.com>
parents:
5530
diff
changeset
|
68 | if (gaim_connections_get_all()) |
|
22cb9fe4798a
[gaim-migrate @ 5991]
Christian Hammond <chipx86@chipx86.com>
parents:
5530
diff
changeset
|
69 | gc = gaim_connections_get_all()->data; |
| 4103 | 70 | else |
| 71 | gc = NULL; | |
| 72 | } | |
| 73 | ||
|
5205
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
74 | static GtkWidget * |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
75 | get_config_frame(GaimPlugin *plugin) |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
76 | { |
| 4103 | 77 | GtkWidget *ret; |
| 78 | GtkWidget *frame, *label; | |
| 79 | GtkWidget *vbox, *hbox; | |
| 80 | GtkAdjustment *adj; | |
| 81 | GtkWidget *spinner, *button; | |
| 82 | ||
| 83 | ret = gtk_vbox_new(FALSE, 18); | |
| 84 | gtk_container_set_border_width(GTK_CONTAINER(ret), 12); | |
| 85 | ||
|
5530
ba1ad464b56f
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
86 | frame = gaim_gtk_make_frame(ret, _("Idle Time")); |
| 4103 | 87 | |
| 88 | vbox = gtk_vbox_new(FALSE, 5); | |
| 89 | gtk_container_add(GTK_CONTAINER(frame), vbox); | |
| 90 | ||
| 91 | hbox = gtk_hbox_new(FALSE, 5); | |
| 92 | gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 5); | |
| 93 | ||
|
4287
28045a1884e8
[gaim-migrate @ 4539]
Nicolás Lichtmaier <nico@lichtmaier.com.ar>
parents:
4260
diff
changeset
|
94 | label = gtk_label_new(_("Set")); |
| 4103 | 95 | gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 5); |
| 96 | ||
| 97 | make_connect_menu(hbox); | |
| 98 | ||
|
4287
28045a1884e8
[gaim-migrate @ 4539]
Nicolás Lichtmaier <nico@lichtmaier.com.ar>
parents:
4260
diff
changeset
|
99 | label = gtk_label_new(_("idle for")); |
| 4103 | 100 | gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 5); |
| 101 | ||
| 102 | adj = (GtkAdjustment *)gtk_adjustment_new(10, 0, G_MAXINT, 1, 0, 0); | |
| 103 | spinner = gtk_spin_button_new(adj, 0, 0); | |
| 104 | gtk_box_pack_start(GTK_BOX(hbox), spinner, TRUE, TRUE, 0); | |
| 105 | ||
|
4287
28045a1884e8
[gaim-migrate @ 4539]
Nicolás Lichtmaier <nico@lichtmaier.com.ar>
parents:
4260
diff
changeset
|
106 | label = gtk_label_new(_("minutes.")); |
| 4103 | 107 | gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 5); |
| 108 | ||
| 109 | hbox = gtk_hbox_new(TRUE, 5); | |
| 110 | gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 5); | |
| 111 | ||
| 112 | button = gtk_button_new_with_mnemonic(_("_Set")); | |
| 113 | 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
|
114 | g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(set_idle), spinner); |
| 4103 | 115 | |
| 116 | gtk_widget_show_all(ret); | |
| 117 | ||
| 118 | return ret; | |
| 119 | } | |
|
5205
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
120 | |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
121 | static GaimGtkPluginUiInfo ui_info = |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
122 | { |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
123 | get_config_frame |
|
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 | |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
126 | static GaimPluginInfo info = |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
127 | { |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
128 | 2, |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
129 | GAIM_PLUGIN_STANDARD, |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
130 | GAIM_GTK_PLUGIN_TYPE, |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
131 | 0, |
|
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 | GAIM_PRIORITY_DEFAULT, |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
134 | IDLE_PLUGIN_ID, |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
135 | N_("I'dle Mak'er"), |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
136 | VERSION, |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
137 | 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
|
138 | 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
|
139 | "Eric Warmenhoven <eric@warmenhoven.org>", |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
140 | WEBSITE, |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
141 | NULL, |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
142 | NULL, |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
143 | NULL, |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
144 | &ui_info, |
|
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 | }; |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
147 | |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
148 | static void |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
149 | __init_plugin(GaimPlugin *plugin) |
|
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 | |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
153 | GAIM_INIT_PLUGIN(idle, __init_plugin, info); |