Annotation of libwww/Library/src/HTAlert.c, revision 2.50
2.18 frystyk 1: /* HTAlert.c
2.39 frystyk 2: ** DIALOG MANAGER
2.18 frystyk 3: **
2.23 frystyk 4: ** (c) COPYRIGHT MIT 1995.
2.18 frystyk 5: ** Please first read the full copyright statement in the file COPYRIGH.
2.50 ! frystyk 6: ** @(#) $Id: Date Author State $
1.1 timbl 7: **
8: ** REPLACE THIS MODULE with a GUI version in a GUI environment!
9: **
10: ** History:
11: ** Jun 92 Created May 1992 By C.T. Barker
12: ** Feb 93 Simplified, portablised TBL
2.8 luotonen 13: ** Sep 93 Corrected 3 bugs in HTConfirm() :-( AL
2.39 frystyk 14: ** Nov 95 Rewritten using callbacks HFN
1.1 timbl 15: */
16:
2.20 frystyk 17: /* Library include files */
2.29 frystyk 18: #include "WWWLib.h"
2.21 frystyk 19: #include "HTError.h" /* Implemented here */
20: #include "HTAlert.h" /* Implemented here */
1.1 timbl 21:
2.39 frystyk 22: typedef struct _HTAlert {
23: HTAlertCallback * cbf;
24: HTAlertOpcode opcode;
25: } HTAlert;
26:
27: struct _HTAlertPar {
28: char * message;
29: char * secret;
30: void * output;
31: };
2.28 frystyk 32:
2.25 frystyk 33: PRIVATE BOOL HTInteractive=YES; /* Any prompts from the Library? */
1.1 timbl 34:
2.39 frystyk 35: PRIVATE HTList * HTMessages = NULL; /* Global list of alert functions */
36:
2.21 frystyk 37: /* ------------------------------------------------------------------------- */
2.25 frystyk 38:
2.39 frystyk 39: /*
40: ** All messaging can be turned on or off as you like
41: */
42: PUBLIC void HTAlert_setInteractive (BOOL interactive)
2.25 frystyk 43: {
44: HTInteractive = interactive;
45: }
46:
2.39 frystyk 47: PUBLIC BOOL HTAlert_interactive (void)
2.25 frystyk 48: {
49: return HTInteractive;
50: }
2.21 frystyk 51:
2.39 frystyk 52: /* HTAlertCall_add
53: ** ---------------
54: ** Register a call back function that is to be called when generating
55: ** messages, dialog, prompts, progress reports etc.
56: **
57: ** The opcode signifies which call back function to call depending of the
58: ** type of the message. Opcode can be one of the enumerations defined
59: ** by HTAlertOpcode.
60: */
61: PUBLIC BOOL HTAlertCall_add (HTList * list, HTAlertCallback * cbf,
62: HTAlertOpcode opcode)
63: {
2.49 hallam 64: if (CORE_TRACE)
2.45 eric 65: HTTrace("Alert Add... HTAlertCallback %p\n", (void *) cbf);
2.39 frystyk 66: if (list && cbf) {
2.44 frystyk 67: HTAlert *me;
68: if ((me = (HTAlert *) HT_CALLOC(1, sizeof(HTAlert))) == NULL)
69: HT_OUTOFMEM("HTAlertCall_add");
2.39 frystyk 70: me->cbf = cbf;
71: me->opcode = opcode;
72: return HTList_addObject(list, (void *) me);
73: }
74: return NO;
75: }
76:
77: /* HTAlertCall_delete
78: ** ------------------
79: ** Unregister a call back function from a list
80: */
81: PUBLIC BOOL HTAlertCall_delete (HTList * list, HTAlertCallback *cbf)
82: {
2.49 hallam 83: if (CORE_TRACE)
2.45 eric 84: HTTrace("Call delete HTAlertCallback %p\n", (void *) cbf);
2.39 frystyk 85: if (list && cbf) {
86: HTList *cur = list;
87: HTAlert *pres;
88: while ((pres = (HTAlert *) HTList_nextObject(cur))) {
89: if (pres->cbf == cbf) {
90: HTList_removeObject(list, (void *) pres);
2.44 frystyk 91: HT_FREE(pres);
2.39 frystyk 92: return YES;
93: }
94: }
95: }
96: return NO;
97: }
2.28 frystyk 98:
2.39 frystyk 99: /* HTAlertCall_deleteAll
100: ** ---------------------
101: ** Unregisters all call back functions
102: */
103: PUBLIC BOOL HTAlertCall_deleteAll (HTList * list)
104: {
2.49 hallam 105: if (CORE_TRACE)
2.45 eric 106: HTTrace("Call delete All callback functions\n");
2.39 frystyk 107: if (list) {
108: HTList *cur = list;
109: HTAlert *pres;
110: while ((pres = (HTAlert *) HTList_nextObject(cur))) {
111: HTList_removeObject(list, (void *) pres);
2.44 frystyk 112: HT_FREE(pres);
2.39 frystyk 113: }
114: HTList_delete(list);
115: return YES;
2.28 frystyk 116: }
2.39 frystyk 117: return NO;
118: }
119:
120: /* HTAlertCall_find
121: ** ----------------
122: ** Finds a callback function corresponding to the opcode. If none has
123: ** been registered then NULL is returned.
124: */
125: PUBLIC HTAlertCallback * HTAlertCall_find (HTList * list, HTAlertOpcode opcode)
126: {
127: if (list && HTInteractive) {
128: HTAlert * pres;
129: while ((pres = (HTAlert *) HTList_nextObject(list)) != NULL) {
130: if (pres->opcode & opcode)
131: return pres->cbf;
2.28 frystyk 132: }
2.49 hallam 133: if (CORE_TRACE)
2.45 eric 134: HTTrace("Alert Find.. No entry found for opcode %d\n",opcode);
2.28 frystyk 135: }
2.39 frystyk 136: return NULL;
2.21 frystyk 137: }
138:
2.39 frystyk 139: /*
140: ** Global List of Alert functions. list can be NULL
141: */
142: PUBLIC void HTAlert_setGlobal (HTList * list)
143: {
144: HTMessages = list;
145: }
2.21 frystyk 146:
2.39 frystyk 147: PUBLIC HTList * HTAlert_global (void)
1.1 timbl 148: {
2.39 frystyk 149: return HTMessages;
1.1 timbl 150: }
151:
2.39 frystyk 152: PUBLIC BOOL HTAlert_add (HTAlertCallback * cbf, HTAlertOpcode opcode)
1.1 timbl 153: {
2.39 frystyk 154: if (!HTMessages) HTMessages = HTList_new();
155: return HTAlertCall_add(HTMessages, cbf, opcode);
1.1 timbl 156: }
157:
2.42 frystyk 158: PUBLIC BOOL HTAlert_delete (HTAlertCallback * cbf)
159: {
160: if (!HTMessages) HTMessages = HTList_new();
161: return HTAlertCall_delete(HTMessages, cbf);
162: }
163:
2.39 frystyk 164: /* HTAlert_find
165: ** ------------
166: ** Finds a global callback function corresponding to the opcode
1.1 timbl 167: */
2.39 frystyk 168: PUBLIC HTAlertCallback * HTAlert_find (HTAlertOpcode opcode)
1.1 timbl 169: {
2.39 frystyk 170: return HTAlertCall_find(HTMessages, opcode);
1.1 timbl 171: }
2.8 luotonen 172:
2.39 frystyk 173: PUBLIC HTAlertPar * HTAlert_newReply (void)
174: {
2.44 frystyk 175: HTAlertPar * me;
176: if ((me = (HTAlertPar *) HT_CALLOC(1, sizeof(HTAlertPar))) == NULL)
177: HT_OUTOFMEM("HTAlert_newReply");
2.39 frystyk 178: return me;
179: }
2.8 luotonen 180:
2.39 frystyk 181: /* HTAlert_deleteReply
182: ** -------------------
183: ** Delete reply structure but don't touch the replies themselves.
2.8 luotonen 184: */
2.39 frystyk 185: PUBLIC void HTAlert_deleteReply (HTAlertPar * old)
2.8 luotonen 186: {
2.48 frystyk 187: HT_FREE(old);
2.11 luotonen 188: }
189:
2.39 frystyk 190: PUBLIC char * HTAlert_replyMessage (HTAlertPar * me)
191: {
192: return me ? me->message : NULL;
193: }
2.11 luotonen 194:
2.47 frystyk 195: PUBLIC BOOL HTAlert_setReplyMessage (HTAlertPar * me, const char * message)
2.11 luotonen 196: {
2.39 frystyk 197: if (me && message) {
198: StrAllocCopy(me->message, message);
199: return YES;
200: }
201: return NO;
2.8 luotonen 202: }
203:
2.43 frystyk 204: PUBLIC BOOL HTAlert_assignReplyMessage (HTAlertPar * me, char * message)
205: {
206: if (me) me->message = message;
207: return YES;
208: }
209:
2.39 frystyk 210: PUBLIC char * HTAlert_replySecret (HTAlertPar * me)
211: {
212: return me ? me->secret : NULL;
213: }
2.21 frystyk 214:
2.47 frystyk 215: PUBLIC BOOL HTAlert_setReplySecret (HTAlertPar * me, const char * secret)
2.21 frystyk 216: {
2.39 frystyk 217: if (me && secret) {
218: StrAllocCopy(me->secret, secret);
219: return YES;
220: }
221: return NO;
222: }
2.21 frystyk 223:
2.39 frystyk 224: PUBLIC void * HTAlert_replyOutput (HTAlertPar * me)
225: {
226: return me ? me->output : NULL;
227: }
2.21 frystyk 228:
2.39 frystyk 229: PUBLIC BOOL HTAlert_setReplyOutput (HTAlertPar * me, void * output)
230: {
231: if (me) {
232: me->output = output;
233: return YES;
2.21 frystyk 234: }
2.39 frystyk 235: return NO;
2.21 frystyk 236: }
Webmaster