Mercurial > pidgin.yaz
annotate plugins/lagmeter.c @ 1073:6b013aff4de3
[gaim-migrate @ 1083]
this proves my stupidity knows no bounds. thanks decklin
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Mon, 06 Nov 2000 22:42:25 +0000 |
parents | ece2d1543b20 |
children | 889ca2b8697b |
rev | line source |
---|---|
193 | 1 /* KNOWN BUGS: |
2 * if you are also using notify.so, it will open a new window to yourself. | |
3 * it will not, however, write anything in that window. this is a problem | |
4 * with notify.c. maybe one day i'll modify notify.c so that these two | |
5 * plugins are more compatible. we'll see. | |
6 * | |
7 * This lagometer has a tendency to not at all show the same lag that the | |
8 * built-in lagometer shows. My guess as to why this is (because they use the | |
9 * exact same code) is because it sends the string more often. That's why I | |
10 * included the configuration option to set the delay between updates. | |
11 * | |
12 * You can load this plugin even when you're not signed on, even though it | |
13 * modifies the buddy list. This is because it checks to see that the buddy | |
14 * list is actually there. In every case that I've been able to think of so | |
15 * far, it does the right thing (tm). | |
16 */ | |
17 | |
18 #define GAIM_PLUGINS | |
19 #include "gaim.h" | |
20 | |
21 #include <time.h> | |
22 #include <sys/types.h> | |
23 #include <sys/time.h> | |
24 #include <unistd.h> | |
25 #include <math.h> | |
26 | |
27 #define MY_LAG_STRING "ZYXCHECKLAGXYZ" | |
28 | |
29 void *handle; | |
30 GtkWidget *lagbox; | |
31 GtkWidget *my_lagometer; | |
32 struct timeval my_lag_tv; | |
848
5f19ec4a91f7
[gaim-migrate @ 858]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
193
diff
changeset
|
33 int check_timeout = -1; |
193 | 34 guint delay = 10; |
35 static GtkWidget *confdlg; | |
36 | |
37 void update_lag(int us) { | |
38 double pct; | |
39 | |
40 if (lagbox == NULL) { | |
41 /* guess we better build it then :P */ | |
42 GtkWidget *label = gtk_label_new("Lag-O-Meter: "); | |
43 GList *tmp = gtk_container_children(GTK_CONTAINER(blist)); | |
44 GtkWidget *vbox2 = (GtkWidget *)tmp->data; | |
45 lagbox = gtk_hbox_new(FALSE, 0); | |
46 my_lagometer = gtk_progress_bar_new(); | |
47 | |
48 gtk_box_pack_start(GTK_BOX(lagbox), label, FALSE, FALSE, 5); | |
49 gtk_box_pack_start(GTK_BOX(lagbox), my_lagometer, TRUE, TRUE, 5); | |
50 gtk_widget_set_usize(my_lagometer, 5, 5); | |
51 | |
52 gtk_widget_show(label); | |
53 gtk_widget_show(my_lagometer); | |
54 | |
55 gtk_box_pack_start(GTK_BOX(vbox2), lagbox, FALSE, TRUE, 0); | |
56 gtk_box_reorder_child(GTK_BOX(vbox2), lagbox, 1); | |
57 gtk_widget_show(lagbox); | |
58 } | |
59 | |
60 pct = us/100000; | |
61 if (pct > 0) | |
62 pct = 25 * log(pct); | |
63 if (pct < 0) | |
64 pct = 0; | |
65 if (pct > 100) | |
66 pct = 100; | |
67 pct /= 100; | |
68 | |
69 gtk_progress_bar_update(GTK_PROGRESS_BAR(my_lagometer), pct); | |
70 } | |
71 | |
1000
91b7377e7b45
[gaim-migrate @ 1010]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
983
diff
changeset
|
72 void check_lag(struct gaim_connection *gc, char **who, char **message, void *m) { |
193 | 73 char *name = g_strdup(normalize(*who)); |
1000
91b7377e7b45
[gaim-migrate @ 1010]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
983
diff
changeset
|
74 if (!strcasecmp(normalize(gc->username), name) && |
983 | 75 (*message != NULL) && |
193 | 76 !strcmp(*message, MY_LAG_STRING)) { |
77 struct timeval tv; | |
78 int ms; | |
79 | |
80 gettimeofday(&tv, NULL); | |
81 | |
82 ms = 1000000 * (tv.tv_sec - my_lag_tv.tv_sec); | |
83 | |
84 ms += tv.tv_usec - my_lag_tv.tv_usec; | |
85 | |
86 update_lag(ms); | |
87 *message = NULL; | |
88 } | |
89 g_free(name); | |
90 } | |
91 | |
1000
91b7377e7b45
[gaim-migrate @ 1010]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
983
diff
changeset
|
92 void send_lag(struct gaim_connection *gc) { |
193 | 93 gettimeofday(&my_lag_tv, NULL); |
1000
91b7377e7b45
[gaim-migrate @ 1010]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
983
diff
changeset
|
94 serv_send_im(gc, gc->username, MY_LAG_STRING, 1); |
193 | 95 } |
96 | |
97 void gaim_plugin_remove() { | |
848
5f19ec4a91f7
[gaim-migrate @ 858]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
193
diff
changeset
|
98 if (check_timeout != -1) |
5f19ec4a91f7
[gaim-migrate @ 858]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
193
diff
changeset
|
99 gtk_timeout_remove(check_timeout); |
193 | 100 if (confdlg) |
101 gtk_widget_destroy(confdlg); | |
983 | 102 if (lagbox) |
103 gtk_widget_destroy(lagbox); | |
104 | |
193 | 105 confdlg = NULL; |
983 | 106 lagbox = NULL; |
193 | 107 } |
108 | |
1000
91b7377e7b45
[gaim-migrate @ 1010]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
983
diff
changeset
|
109 void avail_now(struct gaim_connection *gc, void *m) { |
193 | 110 update_lag(0); |
111 gaim_signal_connect(handle, event_im_recv, check_lag, NULL); | |
112 gaim_signal_connect(handle, event_signoff, gaim_plugin_remove, NULL); | |
1000
91b7377e7b45
[gaim-migrate @ 1010]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
983
diff
changeset
|
113 check_timeout = gtk_timeout_add(1000 * delay, (GtkFunction)send_lag, gc); |
193 | 114 } |
115 | |
1047
ece2d1543b20
[gaim-migrate @ 1057]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1000
diff
changeset
|
116 char *gaim_plugin_init(GModule *h) { |
193 | 117 handle = h; |
118 | |
983 | 119 confdlg = NULL; |
120 lagbox = NULL; | |
121 | |
193 | 122 if (!blist) |
123 gaim_signal_connect(handle, event_signon, avail_now, NULL); | |
124 else | |
1000
91b7377e7b45
[gaim-migrate @ 1010]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
983
diff
changeset
|
125 avail_now(connections->data, NULL); |
1073
6b013aff4de3
[gaim-migrate @ 1083]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1047
diff
changeset
|
126 |
6b013aff4de3
[gaim-migrate @ 1083]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1047
diff
changeset
|
127 return NULL; |
193 | 128 } |
129 | |
130 void adjust_timeout(GtkWidget *button, GtkWidget *spinner) { | |
131 delay = CLAMP(gtk_spin_button_get_value_as_int( | |
132 GTK_SPIN_BUTTON(spinner)), 0, 3600); | |
133 sprintf(debug_buff, "new updates: %d\n", delay); | |
134 debug_print(debug_buff); | |
848
5f19ec4a91f7
[gaim-migrate @ 858]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
193
diff
changeset
|
135 if (check_timeout >= 0) |
5f19ec4a91f7
[gaim-migrate @ 858]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
193
diff
changeset
|
136 gtk_timeout_remove(check_timeout); |
193 | 137 check_timeout = gtk_timeout_add(1000 * delay, (GtkFunction)send_lag, NULL); |
138 gtk_widget_destroy(confdlg); | |
139 confdlg = NULL; | |
140 } | |
141 | |
142 void gaim_plugin_config() { | |
143 GtkWidget *label; | |
144 GtkAdjustment *adj; | |
145 GtkWidget *spinner; | |
146 GtkWidget *button; | |
147 GtkWidget *box; | |
148 | |
149 if (confdlg) { | |
983 | 150 gtk_widget_show_all(confdlg); |
193 | 151 return; |
152 } | |
153 | |
154 confdlg = gtk_window_new(GTK_WINDOW_DIALOG); | |
155 gtk_window_set_title(GTK_WINDOW(confdlg), "Gaim Lag Delay"); | |
156 | |
157 box = gtk_hbox_new(FALSE, 0); | |
158 gtk_container_set_border_width(GTK_CONTAINER(box), 5); | |
159 gtk_container_add(GTK_CONTAINER(confdlg), box); | |
160 | |
161 label = gtk_label_new("Delay between updates: "); | |
162 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
163 gtk_box_pack_start(GTK_BOX(box), label, FALSE, TRUE, 0); | |
164 | |
165 adj = (GtkAdjustment *)gtk_adjustment_new(delay, 0, 3600, 1, 0, 0); | |
166 spinner = gtk_spin_button_new(GTK_ADJUSTMENT(adj), 0, 0); | |
167 gtk_box_pack_start(GTK_BOX(box), spinner, TRUE, TRUE, 0); | |
168 | |
169 button = gtk_button_new_with_label("OK"); | |
170 gtk_signal_connect(GTK_OBJECT(button), "clicked", | |
171 (GtkSignalFunc)adjust_timeout, spinner); | |
172 gtk_box_pack_start(GTK_BOX(box), button, FALSE, TRUE, 0); | |
173 | |
983 | 174 gtk_widget_show_all(confdlg); |
193 | 175 } |
176 | |
177 char *name() { | |
178 return "Lag-O-Meter, Pluggified"; | |
179 } | |
180 | |
181 char *description() { | |
182 return "Your old familiar Lag-O-Meter, in a brand new form."; | |
183 } |