Mercurial > pidgin
view plugins/lagmeter.c @ 1106:5bc8fdacd2cb
[gaim-migrate @ 1116]
lots of changes.
buddy.c: just in general tried to get things to work better. moving things in the edit list window and signing off should be handled better in the main buddy list window (watch out for flashes).
gaim.h: removed toc-specific things and moved them to toc.c and rvous.c as needed.
gtkhtml.c: possible fix for AOL 6.0 problems (I wasn't able to reproduce the problem before or after the fix, but i fixed what i think might have been causing the problem).
multi.c: moved LOGIN_STEPS from gaim.h here and actually use it now
oscar.c: moved an oscar-specific struct definition from gaim.h here and also handle problems better
perl.c: fix for stupid problem
rvous.c: first pass at attempt to be able to remove toc.c and rvous.c (though this will never happen; gaim will support toc as long as aol does) without cruft. gaim is now only dependent on toc.c and rvous.c for toc_build_config and parse_toc_buddy_list, which gaim needs to save and read its buddy list.
toc.c: rewrote the signin process so that the read()'s won't block. it's not actually a non-blocking read; it's just that it won't ever get to the read until there's data to be read (thanks to the gdk_input watcher). this means the cancel button should work after it's connected, but it's still not a non-blocking connect.
committer: Tailor Script <tailor@pidgin.im>
| author | Eric Warmenhoven <eric@warmenhoven.org> |
|---|---|
| date | Mon, 20 Nov 2000 07:24:18 +0000 |
| parents | 6b013aff4de3 |
| children | 889ca2b8697b |
line wrap: on
line source
/* KNOWN BUGS: * if you are also using notify.so, it will open a new window to yourself. * it will not, however, write anything in that window. this is a problem * with notify.c. maybe one day i'll modify notify.c so that these two * plugins are more compatible. we'll see. * * This lagometer has a tendency to not at all show the same lag that the * built-in lagometer shows. My guess as to why this is (because they use the * exact same code) is because it sends the string more often. That's why I * included the configuration option to set the delay between updates. * * You can load this plugin even when you're not signed on, even though it * modifies the buddy list. This is because it checks to see that the buddy * list is actually there. In every case that I've been able to think of so * far, it does the right thing (tm). */ #define GAIM_PLUGINS #include "gaim.h" #include <time.h> #include <sys/types.h> #include <sys/time.h> #include <unistd.h> #include <math.h> #define MY_LAG_STRING "ZYXCHECKLAGXYZ" void *handle; GtkWidget *lagbox; GtkWidget *my_lagometer; struct timeval my_lag_tv; int check_timeout = -1; guint delay = 10; static GtkWidget *confdlg; void update_lag(int us) { double pct; if (lagbox == NULL) { /* guess we better build it then :P */ GtkWidget *label = gtk_label_new("Lag-O-Meter: "); GList *tmp = gtk_container_children(GTK_CONTAINER(blist)); GtkWidget *vbox2 = (GtkWidget *)tmp->data; lagbox = gtk_hbox_new(FALSE, 0); my_lagometer = gtk_progress_bar_new(); gtk_box_pack_start(GTK_BOX(lagbox), label, FALSE, FALSE, 5); gtk_box_pack_start(GTK_BOX(lagbox), my_lagometer, TRUE, TRUE, 5); gtk_widget_set_usize(my_lagometer, 5, 5); gtk_widget_show(label); gtk_widget_show(my_lagometer); gtk_box_pack_start(GTK_BOX(vbox2), lagbox, FALSE, TRUE, 0); gtk_box_reorder_child(GTK_BOX(vbox2), lagbox, 1); gtk_widget_show(lagbox); } pct = us/100000; if (pct > 0) pct = 25 * log(pct); if (pct < 0) pct = 0; if (pct > 100) pct = 100; pct /= 100; gtk_progress_bar_update(GTK_PROGRESS_BAR(my_lagometer), pct); } void check_lag(struct gaim_connection *gc, char **who, char **message, void *m) { char *name = g_strdup(normalize(*who)); if (!strcasecmp(normalize(gc->username), name) && (*message != NULL) && !strcmp(*message, MY_LAG_STRING)) { struct timeval tv; int ms; gettimeofday(&tv, NULL); ms = 1000000 * (tv.tv_sec - my_lag_tv.tv_sec); ms += tv.tv_usec - my_lag_tv.tv_usec; update_lag(ms); *message = NULL; } g_free(name); } void send_lag(struct gaim_connection *gc) { gettimeofday(&my_lag_tv, NULL); serv_send_im(gc, gc->username, MY_LAG_STRING, 1); } void gaim_plugin_remove() { if (check_timeout != -1) gtk_timeout_remove(check_timeout); if (confdlg) gtk_widget_destroy(confdlg); if (lagbox) gtk_widget_destroy(lagbox); confdlg = NULL; lagbox = NULL; } void avail_now(struct gaim_connection *gc, void *m) { update_lag(0); gaim_signal_connect(handle, event_im_recv, check_lag, NULL); gaim_signal_connect(handle, event_signoff, gaim_plugin_remove, NULL); check_timeout = gtk_timeout_add(1000 * delay, (GtkFunction)send_lag, gc); } char *gaim_plugin_init(GModule *h) { handle = h; confdlg = NULL; lagbox = NULL; if (!blist) gaim_signal_connect(handle, event_signon, avail_now, NULL); else avail_now(connections->data, NULL); return NULL; } void adjust_timeout(GtkWidget *button, GtkWidget *spinner) { delay = CLAMP(gtk_spin_button_get_value_as_int( GTK_SPIN_BUTTON(spinner)), 0, 3600); sprintf(debug_buff, "new updates: %d\n", delay); debug_print(debug_buff); if (check_timeout >= 0) gtk_timeout_remove(check_timeout); check_timeout = gtk_timeout_add(1000 * delay, (GtkFunction)send_lag, NULL); gtk_widget_destroy(confdlg); confdlg = NULL; } void gaim_plugin_config() { GtkWidget *label; GtkAdjustment *adj; GtkWidget *spinner; GtkWidget *button; GtkWidget *box; if (confdlg) { gtk_widget_show_all(confdlg); return; } confdlg = gtk_window_new(GTK_WINDOW_DIALOG); gtk_window_set_title(GTK_WINDOW(confdlg), "Gaim Lag Delay"); box = gtk_hbox_new(FALSE, 0); gtk_container_set_border_width(GTK_CONTAINER(box), 5); gtk_container_add(GTK_CONTAINER(confdlg), box); label = gtk_label_new("Delay between updates: "); gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); gtk_box_pack_start(GTK_BOX(box), label, FALSE, TRUE, 0); adj = (GtkAdjustment *)gtk_adjustment_new(delay, 0, 3600, 1, 0, 0); spinner = gtk_spin_button_new(GTK_ADJUSTMENT(adj), 0, 0); gtk_box_pack_start(GTK_BOX(box), spinner, TRUE, TRUE, 0); button = gtk_button_new_with_label("OK"); gtk_signal_connect(GTK_OBJECT(button), "clicked", (GtkSignalFunc)adjust_timeout, spinner); gtk_box_pack_start(GTK_BOX(box), button, FALSE, TRUE, 0); gtk_widget_show_all(confdlg); } char *name() { return "Lag-O-Meter, Pluggified"; } char *description() { return "Your old familiar Lag-O-Meter, in a brand new form."; }
