1 | /* GNOME modemlights applet |
---|
2 | * (C) 2000 John Ellis |
---|
3 | * |
---|
4 | * Authors: John Ellis |
---|
5 | * Martin Baulig |
---|
6 | * |
---|
7 | */ |
---|
8 | |
---|
9 | #include <panel-applet.h> |
---|
10 | #include <stdio.h> |
---|
11 | #include <string.h> |
---|
12 | #include <sys/stat.h> |
---|
13 | #include <sys/ioctl.h> |
---|
14 | #include <sys/socket.h> |
---|
15 | #include <time.h> |
---|
16 | #include <net/if.h> |
---|
17 | |
---|
18 | #ifdef __OpenBSD__ |
---|
19 | # include <net/bpf.h> |
---|
20 | # include <net/if_pppvar.h> |
---|
21 | # include <net/if_ppp.h> |
---|
22 | #endif /* __OpenBSD__ */ |
---|
23 | |
---|
24 | #ifdef __FreeBSD__ |
---|
25 | # include <net/if_ppp.h> |
---|
26 | #endif /* __FreeBSD__ */ |
---|
27 | |
---|
28 | #include <net/ppp_defs.h> |
---|
29 | |
---|
30 | #include <gnome.h> |
---|
31 | |
---|
32 | typedef enum { |
---|
33 | COLOR_RX = 0, |
---|
34 | COLOR_RX_BG, |
---|
35 | COLOR_TX, |
---|
36 | COLOR_TX_BG, |
---|
37 | COLOR_STATUS_BG, |
---|
38 | COLOR_STATUS_OK, |
---|
39 | COLOR_STATUS_WAIT, |
---|
40 | COLOR_TEXT_BG, |
---|
41 | COLOR_TEXT_FG, |
---|
42 | COLOR_TEXT_MID |
---|
43 | } ColorType; |
---|
44 | |
---|
45 | #define COLOR_COUNT 10 |
---|
46 | #define BUTTON_BLINK_INTERVAL 700 |
---|
47 | |
---|
48 | typedef enum { |
---|
49 | LAYOUT_HORIZONTAL = 0, |
---|
50 | LAYOUT_HORIZONTAL_EXTENDED = 1, |
---|
51 | LAYOUT_VERTICAL = 2, |
---|
52 | LAYOUT_VERTICAL_EXTENDED = 3, |
---|
53 | LAYOUT_SQUARE = 4 |
---|
54 | } DisplayLayout; |
---|
55 | |
---|
56 | typedef enum { |
---|
57 | STATUS_OFF, |
---|
58 | STATUS_ON, |
---|
59 | STATUS_WAIT |
---|
60 | } StatusType; |
---|
61 | |
---|
62 | typedef struct _DisplayData DisplayData; |
---|
63 | struct _DisplayData { |
---|
64 | DisplayLayout layout; |
---|
65 | gint width; |
---|
66 | gint height; |
---|
67 | gint button_x; /* connect button */ |
---|
68 | gint button_y; |
---|
69 | gint button_w; |
---|
70 | gint button_h; |
---|
71 | gint display_x; /* display pixmap */ |
---|
72 | gint display_y; |
---|
73 | gint display_w; |
---|
74 | gint display_h; |
---|
75 | gint load_x; /* load meter */ |
---|
76 | gint load_y; |
---|
77 | gint load_w; /* this must always be 18 (hard coded) */ |
---|
78 | gint load_h; |
---|
79 | gint tx_x; /* TX light */ |
---|
80 | gint tx_y; |
---|
81 | gint rx_x; /* RX light */ |
---|
82 | gint rx_y; |
---|
83 | gint bytes_x; /* bytes throughput , -1 to disable */ |
---|
84 | gint bytes_y; |
---|
85 | gint time_x; /* time connected, -1 to disable */ |
---|
86 | gint time_y; |
---|
87 | gint merge_extended_box; /* save space ? */ |
---|
88 | }; |
---|
89 | |
---|
90 | typedef struct _MLData MLData; |
---|
91 | |
---|
92 | struct _MLData |
---|
93 | { |
---|
94 | GtkWidget *applet; |
---|
95 | |
---|
96 | int load_hist[120]; |
---|
97 | int load_hist_pos; |
---|
98 | int load_hist_rx[20]; |
---|
99 | int load_hist_tx[20]; |
---|
100 | gint old_timer; |
---|
101 | gint old_bytes; |
---|
102 | gint old_rx_bytes; |
---|
103 | gint update_counter; |
---|
104 | int o_rx; |
---|
105 | int o_tx; |
---|
106 | int o_cd; |
---|
107 | int old_rx,old_tx; |
---|
108 | int load_count; |
---|
109 | int modem_was_on; |
---|
110 | int tooltip_counter; |
---|
111 | int load_rx,load_tx; |
---|
112 | gint last_time_was_connected; |
---|
113 | GdkColor display_color[COLOR_COUNT]; |
---|
114 | gchar *display_color_text[COLOR_COUNT]; |
---|
115 | gint UPDATE_DISPLAY; |
---|
116 | gint UPDATE_DELAY; |
---|
117 | gchar *lock_file; |
---|
118 | gint verify_lock_file; |
---|
119 | gchar *device_name; |
---|
120 | gchar *command_connect; |
---|
121 | gchar *command_disconnect; |
---|
122 | gint ask_for_confirmation; |
---|
123 | gint use_ISDN; |
---|
124 | gint show_extra_info; |
---|
125 | gint status_wait_blink; |
---|
126 | |
---|
127 | DisplayLayout layout; |
---|
128 | DisplayData *layout_current; |
---|
129 | |
---|
130 | GtkTooltips *tooltips; |
---|
131 | GtkWidget *frame; |
---|
132 | GtkWidget *display_area; |
---|
133 | GtkWidget *button; |
---|
134 | GtkWidget *button_image; |
---|
135 | GdkPixmap *display; |
---|
136 | GdkPixmap *digits; |
---|
137 | GdkPixmap *lights; |
---|
138 | GdkPixmap *button_on; |
---|
139 | GdkPixmap *button_off; |
---|
140 | GdkPixmap *button_wait; |
---|
141 | GdkBitmap *button_mask; |
---|
142 | |
---|
143 | GdkGC *gc; |
---|
144 | |
---|
145 | GtkWidget *about_dialog; |
---|
146 | GtkWidget *propwindow; |
---|
147 | GtkWidget *connect_entry; |
---|
148 | GtkWidget *disconnect_entry; |
---|
149 | GtkWidget *lockfile_entry; |
---|
150 | GtkWidget *device_entry; |
---|
151 | GtkWidget *verify_checkbox; |
---|
152 | |
---|
153 | GtkWidget *connect_dialog; |
---|
154 | GtkWidget *run_dialog; |
---|
155 | |
---|
156 | gint button_blinking; |
---|
157 | gint button_blink_on; |
---|
158 | gint button_blink_id; |
---|
159 | |
---|
160 | int update_timeout_id; |
---|
161 | int ip_socket; |
---|
162 | PanelAppletOrient orient; |
---|
163 | gint sizehint; |
---|
164 | gint setup_done; |
---|
165 | gint allocated; |
---|
166 | |
---|
167 | |
---|
168 | /* ISDN stuff */ |
---|
169 | time_t start_time; |
---|
170 | unsigned long *isdn_stats; |
---|
171 | |
---|
172 | }; |
---|
173 | |
---|
174 | |
---|
175 | void start_callback_update(MLData *mldata); |
---|
176 | void reset_orientation(MLData *mldata); |
---|
177 | void reset_colors(MLData *mldata); |
---|
178 | |
---|
179 | void property_load (MLData *mldata); |
---|
180 | void property_show (BonoboUIComponent *uic, |
---|
181 | MLData *mldata, |
---|
182 | const gchar *verbname); |
---|