Mercurial > pidgin
annotate plugins/idle.c @ 5992:50624f0d2a25
[gaim-migrate @ 6440]
Mauricio de Lemos Rodrigues Collares Neto added a Portuguese (Brazilian) translation, but i cannot check
that it compiles correctly because gettext 0.12.1 is broken!!! fortunately, it seems my bug report is
being looked at and 0.12.2 might be fixed, whenever that is released.
committer: Tailor Script <tailor@pidgin.im>
author | Luke Schierer <lschiere@pidgin.im> |
---|---|
date | Wed, 02 Jul 2003 15:23:23 +0000 |
parents | 7d385de2f9cd |
children | 35679a3f2bcc |
rev | line source |
---|---|
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
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5614
diff
changeset
|
6 #include "internal.h" |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5614
diff
changeset
|
7 |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5614
diff
changeset
|
8 #include "connection.h" |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5614
diff
changeset
|
9 #include "debug.h" |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5614
diff
changeset
|
10 #include "server.h" |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5614
diff
changeset
|
11 |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5614
diff
changeset
|
12 #include "gtkplugin.h" |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5614
diff
changeset
|
13 #include "gtkutils.h" |
4202
59751fe608c5
[gaim-migrate @ 4438]
Christian Hammond <chipx86@chipx86.com>
parents:
4165
diff
changeset
|
14 |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
15 #define IDLE_PLUGIN_ID "gtk-idle" |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
16 |
5587
1c55b1540e18
[gaim-migrate @ 5991]
Christian Hammond <chipx86@chipx86.com>
parents:
5530
diff
changeset
|
17 static GaimConnection *gc = NULL; |
4103 | 18 |
19 static void set_idle(GtkWidget *button, GtkWidget *spinner) { | |
20 time_t t; | |
21 int tm = CLAMP(gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(spinner)), 0, G_MAXINT); | |
5587
1c55b1540e18
[gaim-migrate @ 5991]
Christian Hammond <chipx86@chipx86.com>
parents:
5530
diff
changeset
|
22 GaimAccount *account; |
1c55b1540e18
[gaim-migrate @ 5991]
Christian Hammond <chipx86@chipx86.com>
parents:
5530
diff
changeset
|
23 |
1c55b1540e18
[gaim-migrate @ 5991]
Christian Hammond <chipx86@chipx86.com>
parents:
5530
diff
changeset
|
24 if (!gc) |
4103 | 25 return; |
5587
1c55b1540e18
[gaim-migrate @ 5991]
Christian Hammond <chipx86@chipx86.com>
parents:
5530
diff
changeset
|
26 |
1c55b1540e18
[gaim-migrate @ 5991]
Christian Hammond <chipx86@chipx86.com>
parents:
5530
diff
changeset
|
27 account = gaim_connection_get_account(gc); |
1c55b1540e18
[gaim-migrate @ 5991]
Christian Hammond <chipx86@chipx86.com>
parents:
5530
diff
changeset
|
28 |
5227
6d1707dc8c3d
[gaim-migrate @ 5597]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
29 gaim_debug(GAIM_DEBUG_INFO, "idle", |
5587
1c55b1540e18
[gaim-migrate @ 5991]
Christian Hammond <chipx86@chipx86.com>
parents:
5530
diff
changeset
|
30 "setting idle time for %s to %d\n", |
1c55b1540e18
[gaim-migrate @ 5991]
Christian Hammond <chipx86@chipx86.com>
parents:
5530
diff
changeset
|
31 gaim_account_get_username(account), tm); |
4103 | 32 time(&t); |
33 t -= 60 * tm; | |
5587
1c55b1540e18
[gaim-migrate @ 5991]
Christian Hammond <chipx86@chipx86.com>
parents:
5530
diff
changeset
|
34 gc->last_sent_time = t; |
4103 | 35 serv_set_idle(gc, 60 * tm); |
36 gc->is_idle = 0; | |
37 } | |
38 | |
5587
1c55b1540e18
[gaim-migrate @ 5991]
Christian Hammond <chipx86@chipx86.com>
parents:
5530
diff
changeset
|
39 static void sel_gc(GtkWidget *opt, GaimConnection *g) { |
4103 | 40 gc = g; |
41 } | |
42 | |
43 static void make_connect_menu(GtkWidget *box) { | |
44 GtkWidget *optmenu, *menu, *opt; | |
5587
1c55b1540e18
[gaim-migrate @ 5991]
Christian Hammond <chipx86@chipx86.com>
parents:
5530
diff
changeset
|
45 GaimAccount *account; |
1c55b1540e18
[gaim-migrate @ 5991]
Christian Hammond <chipx86@chipx86.com>
parents:
5530
diff
changeset
|
46 GList *c = gaim_connections_get_all(); |
1c55b1540e18
[gaim-migrate @ 5991]
Christian Hammond <chipx86@chipx86.com>
parents:
5530
diff
changeset
|
47 GaimConnection *g; |
4103 | 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) { | |
5587
1c55b1540e18
[gaim-migrate @ 5991]
Christian Hammond <chipx86@chipx86.com>
parents:
5530
diff
changeset
|
55 g = (GaimConnection *)c->data; |
1c55b1540e18
[gaim-migrate @ 5991]
Christian Hammond <chipx86@chipx86.com>
parents:
5530
diff
changeset
|
56 account = gaim_connection_get_account(g); |
1c55b1540e18
[gaim-migrate @ 5991]
Christian Hammond <chipx86@chipx86.com>
parents:
5530
diff
changeset
|
57 |
5614
ff89436b30d2
[gaim-migrate @ 6021]
Christian Hammond <chipx86@chipx86.com>
parents:
5587
diff
changeset
|
58 opt = gtk_menu_item_new_with_label(gaim_account_get_username(account)); |
5314
1f901484599d
[gaim-migrate @ 5686]
Christian Hammond <chipx86@chipx86.com>
parents:
5227
diff
changeset
|
59 g_signal_connect(G_OBJECT(opt), "activate", |
4165
07a3d1fae88f
[gaim-migrate @ 4394]
Christian Hammond <chipx86@chipx86.com>
parents:
4103
diff
changeset
|
60 G_CALLBACK(sel_gc), g); |
4635 | 61 gtk_menu_shell_append(GTK_MENU_SHELL(menu), opt); |
4103 | 62 gtk_widget_show(opt); |
5587
1c55b1540e18
[gaim-migrate @ 5991]
Christian Hammond <chipx86@chipx86.com>
parents:
5530
diff
changeset
|
63 c = g_list_next(c); |
4103 | 64 } |
65 | |
66 gtk_option_menu_remove_menu(GTK_OPTION_MENU(optmenu)); | |
67 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), menu); | |
68 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), 0); | |
69 | |
5587
1c55b1540e18
[gaim-migrate @ 5991]
Christian Hammond <chipx86@chipx86.com>
parents:
5530
diff
changeset
|
70 if (gaim_connections_get_all()) |
1c55b1540e18
[gaim-migrate @ 5991]
Christian Hammond <chipx86@chipx86.com>
parents:
5530
diff
changeset
|
71 gc = gaim_connections_get_all()->data; |
4103 | 72 else |
73 gc = NULL; | |
74 } | |
75 | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
76 static GtkWidget * |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
77 get_config_frame(GaimPlugin *plugin) |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
78 { |
4103 | 79 GtkWidget *ret; |
80 GtkWidget *frame, *label; | |
81 GtkWidget *vbox, *hbox; | |
82 GtkAdjustment *adj; | |
83 GtkWidget *spinner, *button; | |
84 | |
85 ret = gtk_vbox_new(FALSE, 18); | |
86 gtk_container_set_border_width(GTK_CONTAINER(ret), 12); | |
87 | |
5530
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
88 frame = gaim_gtk_make_frame(ret, _("Idle Time")); |
4103 | 89 |
90 vbox = gtk_vbox_new(FALSE, 5); | |
91 gtk_container_add(GTK_CONTAINER(frame), vbox); | |
92 | |
93 hbox = gtk_hbox_new(FALSE, 5); | |
94 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 5); | |
95 | |
4287
f98e27e2cb10
[gaim-migrate @ 4539]
Christian Hammond <chipx86@chipx86.com>
parents:
4260
diff
changeset
|
96 label = gtk_label_new(_("Set")); |
4103 | 97 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 5); |
98 | |
99 make_connect_menu(hbox); | |
100 | |
4287
f98e27e2cb10
[gaim-migrate @ 4539]
Christian Hammond <chipx86@chipx86.com>
parents:
4260
diff
changeset
|
101 label = gtk_label_new(_("idle for")); |
4103 | 102 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 5); |
103 | |
104 adj = (GtkAdjustment *)gtk_adjustment_new(10, 0, G_MAXINT, 1, 0, 0); | |
105 spinner = gtk_spin_button_new(adj, 0, 0); | |
106 gtk_box_pack_start(GTK_BOX(hbox), spinner, TRUE, TRUE, 0); | |
107 | |
4287
f98e27e2cb10
[gaim-migrate @ 4539]
Christian Hammond <chipx86@chipx86.com>
parents:
4260
diff
changeset
|
108 label = gtk_label_new(_("minutes.")); |
4103 | 109 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 5); |
110 | |
111 hbox = gtk_hbox_new(TRUE, 5); | |
112 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 5); | |
113 | |
114 button = gtk_button_new_with_mnemonic(_("_Set")); | |
115 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 5); | |
5314
1f901484599d
[gaim-migrate @ 5686]
Christian Hammond <chipx86@chipx86.com>
parents:
5227
diff
changeset
|
116 g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(set_idle), spinner); |
4103 | 117 |
118 gtk_widget_show_all(ret); | |
119 | |
120 return ret; | |
121 } | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
122 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
123 static GaimGtkPluginUiInfo ui_info = |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
124 { |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
125 get_config_frame |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
126 }; |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
127 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
128 static GaimPluginInfo info = |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
129 { |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
130 2, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
131 GAIM_PLUGIN_STANDARD, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
132 GAIM_GTK_PLUGIN_TYPE, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
133 0, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
134 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
135 GAIM_PRIORITY_DEFAULT, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
136 IDLE_PLUGIN_ID, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
137 N_("I'dle Mak'er"), |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
138 VERSION, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
139 N_("Allows you to hand-configure how long you've been idle for"), |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
140 N_("Allows you to hand-configure how long you've been idle for"), |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
141 "Eric Warmenhoven <eric@warmenhoven.org>", |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
142 WEBSITE, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
143 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
144 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
145 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
146 &ui_info, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
147 NULL |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
148 }; |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
149 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
150 static void |
5920
7d385de2f9cd
[gaim-migrate @ 6360]
Christian Hammond <chipx86@chipx86.com>
parents:
5873
diff
changeset
|
151 init_plugin(GaimPlugin *plugin) |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
152 { |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
153 } |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4635
diff
changeset
|
154 |
5920
7d385de2f9cd
[gaim-migrate @ 6360]
Christian Hammond <chipx86@chipx86.com>
parents:
5873
diff
changeset
|
155 GAIM_INIT_PLUGIN(idle, init_plugin, info); |