annotate plugins/lagmeter.c @ 2120:9e2475cb0010

[gaim-migrate @ 2130] this is fixed better now. committer: Tailor Script <tailor@pidgin.im>
author Eric Warmenhoven <eric@warmenhoven.org>
date Fri, 03 Aug 2001 18:29:47 +0000
parents c9c20663e05b
children 4e2d8992774e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
193
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1 #define GAIM_PLUGINS
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2 #include "gaim.h"
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
4 #include <time.h>
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
5 #include <sys/types.h>
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
6 #include <sys/time.h>
1167
5d1ded9f88b7 [gaim-migrate @ 1177]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1122
diff changeset
7 #include <string.h>
193
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
8 #include <unistd.h>
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
9 #include <math.h>
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
10
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
11 #define MY_LAG_STRING "ZYXCHECKLAGXYZ"
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
12
1122
889ca2b8697b [gaim-migrate @ 1132]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1073
diff changeset
13 GModule *handle;
1377
569835fcabc3 [gaim-migrate @ 1387]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1295
diff changeset
14 GtkWidget *lagbox = NULL;
193
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
15 GtkWidget *my_lagometer;
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
16 struct timeval my_lag_tv;
1122
889ca2b8697b [gaim-migrate @ 1132]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1073
diff changeset
17 guint check_timeout = 0;
193
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
18 guint delay = 10;
1377
569835fcabc3 [gaim-migrate @ 1387]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1295
diff changeset
19 static GtkWidget *confdlg = NULL;
1122
889ca2b8697b [gaim-migrate @ 1132]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1073
diff changeset
20 struct gaim_connection *my_gc = NULL;
193
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
21
1122
889ca2b8697b [gaim-migrate @ 1132]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1073
diff changeset
22 static void avail_now(struct gaim_connection *, void *);
889ca2b8697b [gaim-migrate @ 1132]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1073
diff changeset
23
889ca2b8697b [gaim-migrate @ 1132]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1073
diff changeset
24 static void update_lag(int us) {
193
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
25 double pct;
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
26
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
27 if (lagbox == NULL) {
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
28 /* guess we better build it then :P */
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
29 GtkWidget *label = gtk_label_new("Lag-O-Meter: ");
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
30 GList *tmp = gtk_container_children(GTK_CONTAINER(blist));
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
31 GtkWidget *vbox2 = (GtkWidget *)tmp->data;
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
32 lagbox = gtk_hbox_new(FALSE, 0);
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
33 my_lagometer = gtk_progress_bar_new();
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
34
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
35 gtk_box_pack_start(GTK_BOX(lagbox), label, FALSE, FALSE, 5);
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
36 gtk_box_pack_start(GTK_BOX(lagbox), my_lagometer, TRUE, TRUE, 5);
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
37 gtk_widget_set_usize(my_lagometer, 5, 5);
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
38
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
39 gtk_widget_show(label);
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
40 gtk_widget_show(my_lagometer);
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
41
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
42 gtk_box_pack_start(GTK_BOX(vbox2), lagbox, FALSE, TRUE, 0);
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
43 gtk_box_reorder_child(GTK_BOX(vbox2), lagbox, 1);
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
44 gtk_widget_show(lagbox);
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
45 }
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
46
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
47 pct = us/100000;
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
48 if (pct > 0)
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
49 pct = 25 * log(pct);
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
50 if (pct < 0)
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
51 pct = 0;
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
52 if (pct > 100)
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
53 pct = 100;
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
54 pct /= 100;
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
55
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
56 gtk_progress_bar_update(GTK_PROGRESS_BAR(my_lagometer), pct);
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
57 }
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
58
1122
889ca2b8697b [gaim-migrate @ 1132]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1073
diff changeset
59 static void check_lag(struct gaim_connection *gc, char **who, char **message, void *m) {
889ca2b8697b [gaim-migrate @ 1132]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1073
diff changeset
60 char *name;
889ca2b8697b [gaim-migrate @ 1132]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1073
diff changeset
61 if (gc != my_gc)
889ca2b8697b [gaim-migrate @ 1132]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1073
diff changeset
62 return;
889ca2b8697b [gaim-migrate @ 1132]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1073
diff changeset
63
889ca2b8697b [gaim-migrate @ 1132]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1073
diff changeset
64 name = g_strdup(normalize(*who));
1000
91b7377e7b45 [gaim-migrate @ 1010]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 983
diff changeset
65 if (!strcasecmp(normalize(gc->username), name) &&
983
a05ad732b613 [gaim-migrate @ 993]
Rob Flynn <gaim@robflynn.com>
parents: 848
diff changeset
66 (*message != NULL) &&
193
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
67 !strcmp(*message, MY_LAG_STRING)) {
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
68 struct timeval tv;
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
69 int ms;
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
70
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
71 gettimeofday(&tv, NULL);
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
72
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
73 ms = 1000000 * (tv.tv_sec - my_lag_tv.tv_sec);
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
74
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
75 ms += tv.tv_usec - my_lag_tv.tv_usec;
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
76
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
77 update_lag(ms);
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
78 *message = NULL;
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
79 }
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
80 g_free(name);
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
81 }
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
82
1377
569835fcabc3 [gaim-migrate @ 1387]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1295
diff changeset
83 static gint send_lag() {
193
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
84 gettimeofday(&my_lag_tv, NULL);
1377
569835fcabc3 [gaim-migrate @ 1387]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1295
diff changeset
85 if (g_slist_find(connections, my_gc)) {
1295
13e68fb13744 [gaim-migrate @ 1305]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1167
diff changeset
86 char *m = g_strdup(MY_LAG_STRING);
1377
569835fcabc3 [gaim-migrate @ 1387]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1295
diff changeset
87 serv_send_im(my_gc, my_gc->username, m, 1);
1295
13e68fb13744 [gaim-migrate @ 1305]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1167
diff changeset
88 g_free(m);
1122
889ca2b8697b [gaim-migrate @ 1132]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1073
diff changeset
89 return TRUE;
889ca2b8697b [gaim-migrate @ 1132]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1073
diff changeset
90 } else {
889ca2b8697b [gaim-migrate @ 1132]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1073
diff changeset
91 debug_printf("LAGMETER: send_lag called for connection that no longer exists\n");
889ca2b8697b [gaim-migrate @ 1132]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1073
diff changeset
92 check_timeout = 0;
889ca2b8697b [gaim-migrate @ 1132]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1073
diff changeset
93 return FALSE;
889ca2b8697b [gaim-migrate @ 1132]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1073
diff changeset
94 }
889ca2b8697b [gaim-migrate @ 1132]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1073
diff changeset
95 }
889ca2b8697b [gaim-migrate @ 1132]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1073
diff changeset
96
889ca2b8697b [gaim-migrate @ 1132]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1073
diff changeset
97 static void got_signoff(struct gaim_connection *gc, void *m) {
889ca2b8697b [gaim-migrate @ 1132]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1073
diff changeset
98 if (gc != my_gc)
889ca2b8697b [gaim-migrate @ 1132]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1073
diff changeset
99 return;
889ca2b8697b [gaim-migrate @ 1132]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1073
diff changeset
100
889ca2b8697b [gaim-migrate @ 1132]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1073
diff changeset
101 if (check_timeout > 0)
889ca2b8697b [gaim-migrate @ 1132]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1073
diff changeset
102 gtk_timeout_remove(check_timeout);
889ca2b8697b [gaim-migrate @ 1132]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1073
diff changeset
103 check_timeout = 0;
889ca2b8697b [gaim-migrate @ 1132]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1073
diff changeset
104
889ca2b8697b [gaim-migrate @ 1132]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1073
diff changeset
105 if (confdlg)
889ca2b8697b [gaim-migrate @ 1132]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1073
diff changeset
106 gtk_widget_destroy(confdlg);
889ca2b8697b [gaim-migrate @ 1132]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1073
diff changeset
107 confdlg = NULL;
889ca2b8697b [gaim-migrate @ 1132]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1073
diff changeset
108
889ca2b8697b [gaim-migrate @ 1132]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1073
diff changeset
109 if (lagbox)
889ca2b8697b [gaim-migrate @ 1132]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1073
diff changeset
110 gtk_widget_destroy(lagbox);
889ca2b8697b [gaim-migrate @ 1132]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1073
diff changeset
111 lagbox = NULL;
889ca2b8697b [gaim-migrate @ 1132]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1073
diff changeset
112
889ca2b8697b [gaim-migrate @ 1132]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1073
diff changeset
113 if (g_slist_length(connections) > 1) {
1377
569835fcabc3 [gaim-migrate @ 1387]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1295
diff changeset
114 if (connections->data == my_gc) {
569835fcabc3 [gaim-migrate @ 1387]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1295
diff changeset
115 my_gc = NULL;
1122
889ca2b8697b [gaim-migrate @ 1132]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1073
diff changeset
116 avail_now(connections->next->data, NULL);
1377
569835fcabc3 [gaim-migrate @ 1387]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1295
diff changeset
117 } else {
569835fcabc3 [gaim-migrate @ 1387]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1295
diff changeset
118 my_gc = NULL;
1122
889ca2b8697b [gaim-migrate @ 1132]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1073
diff changeset
119 avail_now(connections->data, NULL);
1377
569835fcabc3 [gaim-migrate @ 1387]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1295
diff changeset
120 }
1122
889ca2b8697b [gaim-migrate @ 1132]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1073
diff changeset
121 } else {
889ca2b8697b [gaim-migrate @ 1132]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1073
diff changeset
122 my_gc = NULL;
889ca2b8697b [gaim-migrate @ 1132]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1073
diff changeset
123 }
889ca2b8697b [gaim-migrate @ 1132]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1073
diff changeset
124 }
889ca2b8697b [gaim-migrate @ 1132]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1073
diff changeset
125
889ca2b8697b [gaim-migrate @ 1132]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1073
diff changeset
126 static void avail_now(struct gaim_connection *gc, void *m) {
1377
569835fcabc3 [gaim-migrate @ 1387]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1295
diff changeset
127 if (my_gc)
569835fcabc3 [gaim-migrate @ 1387]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1295
diff changeset
128 return;
1122
889ca2b8697b [gaim-migrate @ 1132]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1073
diff changeset
129 update_lag(0);
1377
569835fcabc3 [gaim-migrate @ 1387]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1295
diff changeset
130 check_timeout = gtk_timeout_add(1000 * delay, (GtkFunction)send_lag, NULL);
1122
889ca2b8697b [gaim-migrate @ 1132]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1073
diff changeset
131 my_gc = gc;
193
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
132 }
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
133
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
134 void gaim_plugin_remove() {
1122
889ca2b8697b [gaim-migrate @ 1132]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1073
diff changeset
135 if (check_timeout > 0)
848
5f19ec4a91f7 [gaim-migrate @ 858]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 193
diff changeset
136 gtk_timeout_remove(check_timeout);
1122
889ca2b8697b [gaim-migrate @ 1132]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1073
diff changeset
137 check_timeout = 0;
193
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
138 if (confdlg)
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
139 gtk_widget_destroy(confdlg);
983
a05ad732b613 [gaim-migrate @ 993]
Rob Flynn <gaim@robflynn.com>
parents: 848
diff changeset
140 if (lagbox)
a05ad732b613 [gaim-migrate @ 993]
Rob Flynn <gaim@robflynn.com>
parents: 848
diff changeset
141 gtk_widget_destroy(lagbox);
a05ad732b613 [gaim-migrate @ 993]
Rob Flynn <gaim@robflynn.com>
parents: 848
diff changeset
142
193
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
143 confdlg = NULL;
983
a05ad732b613 [gaim-migrate @ 993]
Rob Flynn <gaim@robflynn.com>
parents: 848
diff changeset
144 lagbox = NULL;
1122
889ca2b8697b [gaim-migrate @ 1132]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1073
diff changeset
145 my_gc = NULL;
193
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
146 }
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
147
1047
ece2d1543b20 [gaim-migrate @ 1057]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1000
diff changeset
148 char *gaim_plugin_init(GModule *h) {
193
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
149 handle = h;
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
150
983
a05ad732b613 [gaim-migrate @ 993]
Rob Flynn <gaim@robflynn.com>
parents: 848
diff changeset
151 confdlg = NULL;
a05ad732b613 [gaim-migrate @ 993]
Rob Flynn <gaim@robflynn.com>
parents: 848
diff changeset
152 lagbox = NULL;
1377
569835fcabc3 [gaim-migrate @ 1387]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1295
diff changeset
153 my_gc = NULL;
983
a05ad732b613 [gaim-migrate @ 993]
Rob Flynn <gaim@robflynn.com>
parents: 848
diff changeset
154
1377
569835fcabc3 [gaim-migrate @ 1387]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1295
diff changeset
155 gaim_signal_connect(handle, event_signon, avail_now, NULL);
1122
889ca2b8697b [gaim-migrate @ 1132]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1073
diff changeset
156 gaim_signal_connect(handle, event_im_recv, check_lag, NULL);
889ca2b8697b [gaim-migrate @ 1132]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1073
diff changeset
157 gaim_signal_connect(handle, event_signoff, got_signoff, NULL);
889ca2b8697b [gaim-migrate @ 1132]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1073
diff changeset
158
1377
569835fcabc3 [gaim-migrate @ 1387]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1295
diff changeset
159 if (connections)
1000
91b7377e7b45 [gaim-migrate @ 1010]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 983
diff changeset
160 avail_now(connections->data, NULL);
1073
6b013aff4de3 [gaim-migrate @ 1083]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1047
diff changeset
161
6b013aff4de3 [gaim-migrate @ 1083]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1047
diff changeset
162 return NULL;
193
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
163 }
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
164
1122
889ca2b8697b [gaim-migrate @ 1132]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1073
diff changeset
165 static void adjust_timeout(GtkWidget *button, GtkWidget *spinner) {
193
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
166 delay = CLAMP(gtk_spin_button_get_value_as_int(
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
167 GTK_SPIN_BUTTON(spinner)), 0, 3600);
1122
889ca2b8697b [gaim-migrate @ 1132]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1073
diff changeset
168 debug_printf("LAGMETER: new updates: %d\n", delay);
889ca2b8697b [gaim-migrate @ 1132]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1073
diff changeset
169 if (check_timeout > 0)
848
5f19ec4a91f7 [gaim-migrate @ 858]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 193
diff changeset
170 gtk_timeout_remove(check_timeout);
1122
889ca2b8697b [gaim-migrate @ 1132]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1073
diff changeset
171 check_timeout = 0;
889ca2b8697b [gaim-migrate @ 1132]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1073
diff changeset
172 if (my_gc)
1377
569835fcabc3 [gaim-migrate @ 1387]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1295
diff changeset
173 check_timeout = gtk_timeout_add(1000 * delay, (GtkFunction)send_lag, NULL);
193
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
174 gtk_widget_destroy(confdlg);
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
175 confdlg = NULL;
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
176 }
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
177
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
178 void gaim_plugin_config() {
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
179 GtkWidget *label;
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
180 GtkAdjustment *adj;
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
181 GtkWidget *spinner;
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
182 GtkWidget *button;
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
183 GtkWidget *box;
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
184
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
185 if (confdlg) {
983
a05ad732b613 [gaim-migrate @ 993]
Rob Flynn <gaim@robflynn.com>
parents: 848
diff changeset
186 gtk_widget_show_all(confdlg);
193
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
187 return;
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
188 }
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
189
1956
c9c20663e05b [gaim-migrate @ 1966]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1943
diff changeset
190 confdlg = gtk_window_new(GTK_WINDOW_DIALOG);
193
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
191 gtk_window_set_title(GTK_WINDOW(confdlg), "Gaim Lag Delay");
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
192
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
193 box = gtk_hbox_new(FALSE, 0);
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
194 gtk_container_set_border_width(GTK_CONTAINER(box), 5);
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
195 gtk_container_add(GTK_CONTAINER(confdlg), box);
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
196
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
197 label = gtk_label_new("Delay between updates: ");
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
198 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
199 gtk_box_pack_start(GTK_BOX(box), label, FALSE, TRUE, 0);
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
200
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
201 adj = (GtkAdjustment *)gtk_adjustment_new(delay, 0, 3600, 1, 0, 0);
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
202 spinner = gtk_spin_button_new(GTK_ADJUSTMENT(adj), 0, 0);
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
203 gtk_box_pack_start(GTK_BOX(box), spinner, TRUE, TRUE, 0);
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
204
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
205 button = gtk_button_new_with_label("OK");
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
206 gtk_signal_connect(GTK_OBJECT(button), "clicked",
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
207 (GtkSignalFunc)adjust_timeout, spinner);
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
208 gtk_box_pack_start(GTK_BOX(box), button, FALSE, TRUE, 0);
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
209
983
a05ad732b613 [gaim-migrate @ 993]
Rob Flynn <gaim@robflynn.com>
parents: 848
diff changeset
210 gtk_widget_show_all(confdlg);
193
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
211 }
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
212
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
213 char *name() {
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
214 return "Lag-O-Meter, Pluggified";
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
215 }
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
216
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
217 char *description() {
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
218 return "Your old familiar Lag-O-Meter, in a brand new form.";
6af9b88e4f90 [gaim-migrate @ 203]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
219 }