Mercurial > pidgin.yaz
comparison plugins/lagmeter.c @ 1377:569835fcabc3
[gaim-migrate @ 1387]
ok, this should fix quite a few problems with the lagmeter.
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Thu, 04 Jan 2001 23:29:52 +0000 |
parents | 13e68fb13744 |
children | 94e81315be2a |
comparison
equal
deleted
inserted
replaced
1376:730a1a19b4cc | 1377:569835fcabc3 |
---|---|
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 | 1 #define GAIM_PLUGINS |
19 #include "gaim.h" | 2 #include "gaim.h" |
20 | 3 |
21 #include <time.h> | 4 #include <time.h> |
22 #include <sys/types.h> | 5 #include <sys/types.h> |
26 #include <math.h> | 9 #include <math.h> |
27 | 10 |
28 #define MY_LAG_STRING "ZYXCHECKLAGXYZ" | 11 #define MY_LAG_STRING "ZYXCHECKLAGXYZ" |
29 | 12 |
30 GModule *handle; | 13 GModule *handle; |
31 GtkWidget *lagbox; | 14 GtkWidget *lagbox = NULL; |
32 GtkWidget *my_lagometer; | 15 GtkWidget *my_lagometer; |
33 struct timeval my_lag_tv; | 16 struct timeval my_lag_tv; |
34 guint check_timeout = 0; | 17 guint check_timeout = 0; |
35 guint delay = 10; | 18 guint delay = 10; |
36 static GtkWidget *confdlg; | 19 static GtkWidget *confdlg = NULL; |
37 struct gaim_connection *my_gc = NULL; | 20 struct gaim_connection *my_gc = NULL; |
38 | 21 |
39 static void avail_now(struct gaim_connection *, void *); | 22 static void avail_now(struct gaim_connection *, void *); |
40 | 23 |
41 static void update_lag(int us) { | 24 static void update_lag(int us) { |
95 *message = NULL; | 78 *message = NULL; |
96 } | 79 } |
97 g_free(name); | 80 g_free(name); |
98 } | 81 } |
99 | 82 |
100 static gint send_lag(struct gaim_connection *gc) { | 83 static gint send_lag() { |
101 gettimeofday(&my_lag_tv, NULL); | 84 gettimeofday(&my_lag_tv, NULL); |
102 if (g_slist_find(connections, gc)) { | 85 if (g_slist_find(connections, my_gc)) { |
103 char *m = g_strdup(MY_LAG_STRING); | 86 char *m = g_strdup(MY_LAG_STRING); |
104 serv_send_im(gc, gc->username, m, 1); | 87 serv_send_im(my_gc, my_gc->username, m, 1); |
105 g_free(m); | 88 g_free(m); |
106 return TRUE; | 89 return TRUE; |
107 } else { | 90 } else { |
108 debug_printf("LAGMETER: send_lag called for connection that no longer exists\n"); | 91 debug_printf("LAGMETER: send_lag called for connection that no longer exists\n"); |
109 check_timeout = 0; | 92 check_timeout = 0; |
126 if (lagbox) | 109 if (lagbox) |
127 gtk_widget_destroy(lagbox); | 110 gtk_widget_destroy(lagbox); |
128 lagbox = NULL; | 111 lagbox = NULL; |
129 | 112 |
130 if (g_slist_length(connections) > 1) { | 113 if (g_slist_length(connections) > 1) { |
131 if (connections->data == my_gc) | 114 if (connections->data == my_gc) { |
115 my_gc = NULL; | |
132 avail_now(connections->next->data, NULL); | 116 avail_now(connections->next->data, NULL); |
133 else | 117 } else { |
118 my_gc = NULL; | |
134 avail_now(connections->data, NULL); | 119 avail_now(connections->data, NULL); |
120 } | |
135 } else { | 121 } else { |
136 my_gc = NULL; | 122 my_gc = NULL; |
137 } | 123 } |
138 } | 124 } |
139 | 125 |
140 static void avail_now(struct gaim_connection *gc, void *m) { | 126 static void avail_now(struct gaim_connection *gc, void *m) { |
127 if (my_gc) | |
128 return; | |
141 update_lag(0); | 129 update_lag(0); |
142 check_timeout = gtk_timeout_add(1000 * delay, (GtkFunction)send_lag, gc); | 130 check_timeout = gtk_timeout_add(1000 * delay, (GtkFunction)send_lag, NULL); |
143 my_gc = gc; | 131 my_gc = gc; |
144 } | 132 } |
145 | 133 |
146 void gaim_plugin_remove() { | 134 void gaim_plugin_remove() { |
147 if (check_timeout > 0) | 135 if (check_timeout > 0) |
160 char *gaim_plugin_init(GModule *h) { | 148 char *gaim_plugin_init(GModule *h) { |
161 handle = h; | 149 handle = h; |
162 | 150 |
163 confdlg = NULL; | 151 confdlg = NULL; |
164 lagbox = NULL; | 152 lagbox = NULL; |
165 | 153 my_gc = NULL; |
154 | |
155 gaim_signal_connect(handle, event_signon, avail_now, NULL); | |
166 gaim_signal_connect(handle, event_im_recv, check_lag, NULL); | 156 gaim_signal_connect(handle, event_im_recv, check_lag, NULL); |
167 gaim_signal_connect(handle, event_signoff, got_signoff, NULL); | 157 gaim_signal_connect(handle, event_signoff, got_signoff, NULL); |
168 | 158 |
169 if (!connections) | 159 if (connections) |
170 gaim_signal_connect(handle, event_signon, avail_now, NULL); | |
171 else | |
172 avail_now(connections->data, NULL); | 160 avail_now(connections->data, NULL); |
173 | 161 |
174 return NULL; | 162 return NULL; |
175 } | 163 } |
176 | 164 |
180 debug_printf("LAGMETER: new updates: %d\n", delay); | 168 debug_printf("LAGMETER: new updates: %d\n", delay); |
181 if (check_timeout > 0) | 169 if (check_timeout > 0) |
182 gtk_timeout_remove(check_timeout); | 170 gtk_timeout_remove(check_timeout); |
183 check_timeout = 0; | 171 check_timeout = 0; |
184 if (my_gc) | 172 if (my_gc) |
185 check_timeout = gtk_timeout_add(1000 * delay, (GtkFunction)send_lag, my_gc); | 173 check_timeout = gtk_timeout_add(1000 * delay, (GtkFunction)send_lag, NULL); |
186 gtk_widget_destroy(confdlg); | 174 gtk_widget_destroy(confdlg); |
187 confdlg = NULL; | 175 confdlg = NULL; |
188 } | 176 } |
189 | 177 |
190 void gaim_plugin_config() { | 178 void gaim_plugin_config() { |