1 /*
2 * spopt.c
3 *
4 * Functions to look after the Short Packet window.
5 */
6 #include "config.h"
7
8 #ifdef SHORT_PACKETS
9 #include "copyright.h"
10
11 #include <stdio.h>
12
13 #include "Wlib.h"
14 #include "defs.h"
15 #include "struct.h"
16 #include "data.h"
17 #include "packets.h"
18
19 #include "short.h"
20
21 #include "spopt.h"
22
sprefresh(int i)23 void sprefresh(int i)
24 /*
25 * Refresh button i in the Short Packed Window.
26 *
27 * Buttons are:
28 * SPK_VFIELD - Variable short packets.
29 * SPK_MFIELD - Messages.
30 * SPK_KFIELD - Kill Messages.
31 * SPK_WFIELD - Warn Messages.
32 * SPK_TFIELD - Recieve Threshold.
33 * SPK_DONE - Done.
34 */
35 {
36 char buf[BUFSIZ];
37
38 switch (i)
39 {
40
41 case SPK_VFIELD:
42 sprintf(buf, "%seceive variable and short packets",
43 recv_short ? "R" : "Don't r");
44 break;
45 case SPK_MFIELD:
46 sprintf(buf, "%seceive messages", recv_mesg ? "R" : "Don't r");
47 break;
48 case SPK_KFIELD:
49 sprintf(buf, "%seceive kill messages", recv_kmesg ? "R" : "Don't r");
50 break;
51 case SPK_WFIELD:
52 sprintf(buf, "%seceive warning messages", recv_warn ? "R" : "Don't r");
53 break;
54 case SPK_TFIELD:
55 sprintf(buf, "Receive threshold: %s_", recv_threshold_s);
56 break;
57 case SPK_DONE:
58 sprintf(buf, "Done");
59 break;
60 }
61
62 W_WriteText(spWin, 0, i, textColor, buf, strlen(buf), 0);
63 }
64
65
spaction(W_Event * data)66 void spaction(W_Event * data)
67 /*
68 * Handle a button press.
69 */
70 {
71 int v;
72 register int i;
73 register char *cp;
74
75 switch (data->y)
76 {
77
78 case SPK_VFIELD:
79 if (data->type == W_EV_BUTTON)
80 {
81 if (recv_short)
82 sendShortReq(SPK_VOFF);
83 else
84 sendShortReq(SPK_VON);
85 }
86 break;
87
88 case SPK_MFIELD:
89 if (data->type == W_EV_BUTTON)
90 {
91 if (recv_mesg)
92 sendShortReq(SPK_MOFF);
93 else
94 sendShortReq(SPK_MON);
95 }
96 break;
97
98 case SPK_KFIELD:
99 if (data->type == W_EV_BUTTON)
100 {
101 if (recv_kmesg)
102 sendShortReq(SPK_M_NOKILLS);
103 else
104 sendShortReq(SPK_M_KILLS);
105 }
106 break;
107
108 case SPK_WFIELD:
109 if (data->type == W_EV_BUTTON)
110 {
111 if (recv_warn)
112 sendShortReq(SPK_M_NOWARN);
113 else
114 sendShortReq(SPK_M_WARN);
115 }
116 break;
117
118 case SPK_TFIELD:
119 if (data->type == W_EV_KEY)
120 {
121 switch (data->key)
122 {
123 case '\b':
124 case '\177':
125 cp = recv_threshold_s;
126 i = strlen(cp);
127 if (i > 0)
128 {
129 cp += i - 1;
130 *cp = '\0';
131 }
132 break;
133 case '\025':
134 case '\030':
135 recv_threshold_s[0] = '\0';
136 break;
137
138 default:
139 if (data->key >= '0' && data->key <= '9')
140 {
141 cp = recv_threshold_s;
142 i = strlen(cp);
143 if (i < 4)
144 {
145 cp += i;
146 cp[1] = '\0';
147 cp[0] = data->key;
148 }
149 }
150 break;
151 }
152 sprefresh(SPK_TFIELD);
153 }
154 break;
155
156 case SPK_DONE:
157
158 if (data->type == W_EV_BUTTON)
159 {
160 if (sscanf(recv_threshold_s, "%d", &v) != 1)
161 strcpy(recv_threshold_s, "0");
162 else if (recv_threshold != v)
163 {
164 recv_threshold = v;
165 sendThreshold(recv_threshold);
166 }
167
168 spdone();
169 }
170 break;
171
172 }
173 }
174
175
spwindow(void)176 void spwindow(void)
177 {
178 register int i;
179
180 for (i = 0; i < SPK_NUMFIELDS; i++)
181 sprefresh(i);
182
183 /* Map window */
184 W_MapWindow(spWin);
185 }
186
187
spdone(void)188 void spdone(void)
189 {
190 /* Unmap window */
191 W_UnmapWindow(spWin);
192 }
193 #endif
194