File: action.c

package info (click to toggle)
ppxp 0.99120923-1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 2,812 kB
  • ctags: 3,704
  • sloc: ansic: 24,532; tcl: 3,992; makefile: 517; sh: 80
file content (182 lines) | stat: -rw-r--r-- 5,472 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#include <X11/Intrinsic.h>
#include <X11/StringDefs.h>
#include <stdio.h>
#include <stdlib.h>
#include <xcio.h>
#include "Parts.h"
#include "Indicator.h"
#include "Time.h"
#include "xppxp.h"

static int auto_state = False;

void
NewLabel(char *label)
{
        strncpy(sc_name, label, sizeof(sc_name)-1);
        sc_name[sizeof(sc_name)-1]=0;
        reload_label();
}

void
ButtonSet(int auto_b, int link_b)
{
        Boolean auto_s;
        Boolean connect_s;

        XtVaGetValues((Widget)button1, XtNstate, &auto_s, NULL);
        XtVaGetValues((Widget)button2, XtNstate, &connect_s, NULL);

        if (auto_b != BS_Unchange) {
                XtVaSetValues((Widget)button1, 
                              XtNstate, (Boolean)auto_b, NULL);
                if (auto_b) {
                        auto_state = True;
                } else {
                        auto_state = False;
                }
        }
        if (link_b != BS_Unchange) {
                XtVaSetValues((Widget)button2, 
                              XtNstate, (Boolean)link_b, NULL);
                XtVaSetValues((Widget)button3, 
                              XtNstate, (Boolean)(!link_b), NULL);
        }
}

void
showLeds(int p_auto, int p_chat, int p_estb, int p_line, int p_auth, int p_net)
{
        int l1 = p_auto;
        int l2 = (p_chat | p_estb);
        int l3 = p_line;
        int l4 = p_auth;
        int l5 = p_net;

        if (l1 != BS_Unchange)
                XtVaSetValues((Widget)led1, XtNstate, (Boolean)l1, NULL);
        if (l2 != BS_Unchange)
                XtVaSetValues((Widget)led2, XtNstate, (Boolean)l2, NULL);
        if (l3 != BS_Unchange)
                XtVaSetValues((Widget)led3, XtNstate, (Boolean)l3, NULL);
        if (l4 != BS_Unchange)
                XtVaSetValues((Widget)led4, XtNstate, (Boolean)l4, NULL);
        if (l5 != BS_Unchange)
                XtVaSetValues((Widget)led5, XtNstate, l5, NULL);
}

void
showMeters(int in, int out)
{
        if (in != BS_Unchange)
                XtVaSetValues((Widget)indc, XtNinRate,  in,  NULL);
        if (out != BS_Unchange)
                XtVaSetValues((Widget)indc, XtNoutRate, out, NULL);
}

void
showConnectTime(int ct)
{
        if (ct != BS_Unchange)
                XtVaSetValues((Widget)tdisp, XtNtime,  ct,  NULL);
}

void
AutoButton(Widget w, XButtonEvent *event)
{
        Boolean auto_s;
        XtVaGetValues((Widget)button1, XtNstate, &auto_s, NULL);

        if (event->type == ButtonPress) {
                if (!auto_s) {
                        XtVaSetValues(w, XtNstate, True, NULL);
                }
        } else if (event->type == ButtonRelease) {
                if (auto_state) {
                        XtVaSetValues(button1, XtNstate, False, NULL);
                        PPxPCommandv(ppxpFd, XCMD_AUTO, "off", NULL);
                        auto_state = False;
                } else {
                        PPxPCommandv(ppxpFd, XCMD_AUTO, NULL);
                        auto_state = True;
                }
        }
}

void
ConnectButton(Widget w, XButtonEvent *event)
{
        if (event->type == ButtonPress) {
                XtVaSetValues(w, XtNstate, True, NULL);
                XtVaSetValues(button3, XtNstate, False, NULL);
        } else if (event->type == ButtonRelease) {
                PPxPCommandv(ppxpFd, XCMD_CONNECT, NULL);
        }
}

void
DisconnectButton(Widget w, XButtonEvent *event)
{
        if (event->type == ButtonPress) {
                XtVaSetValues(w, XtNstate, True, NULL);
                XtVaSetValues(button2, XtNstate, False, NULL);
        } else if (event->type == ButtonRelease) {
                PPxPCommandv(ppxpFd, XCMD_DISCONNECT, NULL);
        }
}

void
ByeButton(Widget w, XButtonEvent *event)
{
        Dimension width, height;

        if (event->type == ButtonPress) {
                XtVaSetValues(w, XtNstate, True, NULL);
        } else if (event->type == ButtonRelease) {
                XtVaSetValues(w, XtNstate, False, NULL);
                XtVaGetValues(w, XtNwidth, &width, NULL);
                XtVaGetValues(w, XtNheight, &height, NULL);
                if (event->x >= 0 && event->x < width
                    && event->y >= 0 && event->y < height) {
                        PPxPCommandv(ppxpFd, XCMD_BYE, NULL);
                }
        }
}

void
QuitButton(Widget w, XButtonEvent *event)
{
        Dimension width, height;
        if (event->type == ButtonPress) {
                XtVaSetValues(w, XtNstate, True, NULL);
        } else if (event->type == ButtonRelease) {
                XtVaSetValues(w, XtNstate, False, NULL);
                XtVaGetValues(w, XtNwidth, &width, NULL);
                XtVaGetValues(w, XtNheight, &height, NULL);
                if (event->x >= 0 && event->x < width
                    && event->y >= 0 && event->y < height) {
                        PPxPCommandv(ppxpFd, XCMD_QUIT, NULL);
                }
        }
}

void
Idling(Widget w, XButtonEvent *event)
{
        if (event->type == ButtonPress) {
                PPxPCommandv(ppxpFd, XCMD_SET, "IDLE.TIME", "300", NULL);
        }
}

void
Terminal(Widget w, XButtonEvent *event)
{
        if (event->type == ButtonPress) {
                if (event->x >= 121 && event->x < 185
                    && event->y >= 4 && event->y < 28) {
                    if (fork()==0) {
                            execlp("xterm", "xterm", "-e", "ppxp", NULL);
                    }
                }
        }
}