Annotation of libwww/Library/src/HTAlert.c, revision 2.51
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.51 ! frystyk 6: ** @(#) $Id: HTAlert.c,v 2.50 1996/04/12 17:45:41 frystyk Exp $
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))) {
2.44 frystyk 111: HT_FREE(pres);
2.39 frystyk 112: }
113: HTList_delete(list);
114: return YES;
2.28 frystyk 115: }
2.39 frystyk 116: return NO;
117: }
118:
119: /* HTAlertCall_find
120: ** ----------------
121: ** Finds a callback function corresponding to the opcode. If none has
122: ** been registered then NULL is returned.
123: */
124: PUBLIC HTAlertCallback * HTAlertCall_find (HTList * list, HTAlertOpcode opcode)
125: {
126: if (list && HTInteractive) {
127: HTAlert * pres;
128: while ((pres = (HTAlert *) HTList_nextObject(list)) != NULL) {
129: if (pres->opcode & opcode)
130: return pres->cbf;
2.28 frystyk 131: }
2.49 hallam 132: if (CORE_TRACE)
2.45 eric 133: HTTrace("Alert Find.. No entry found for opcode %d\n",opcode);
2.28 frystyk 134: }
2.39 frystyk 135: return NULL;
2.21 frystyk 136: }
137:
2.39 frystyk 138: /*
139: ** Global List of Alert functions. list can be NULL
140: */
141: PUBLIC void HTAlert_setGlobal (HTList * list)
142: {
143: HTMessages = list;
144: }
2.21 frystyk 145:
2.39 frystyk 146: PUBLIC HTList * HTAlert_global (void)
1.1 timbl 147: {
2.39 frystyk 148: return HTMessages;
1.1 timbl 149: }
150:
2.39 frystyk 151: PUBLIC BOOL HTAlert_add (HTAlertCallback * cbf, HTAlertOpcode opcode)
1.1 timbl 152: {
2.39 frystyk 153: if (!HTMessages) HTMessages = HTList_new();
154: return HTAlertCall_add(HTMessages, cbf, opcode);
1.1 timbl 155: }
156:
2.42 frystyk 157: PUBLIC BOOL HTAlert_delete (HTAlertCallback * cbf)
158: {
159: if (!HTMessages) HTMessages = HTList_new();
160: return HTAlertCall_delete(HTMessages, cbf);
2.51 ! frystyk 161: }
! 162:
! 163: PUBLIC BOOL HTAlert_deleteAll (void)
! 164: {
! 165: BOOL status = NO;
! 166: if (HTMessages) {
! 167: status = HTAlertCall_deleteAll(HTMessages);
! 168: HTMessages = NULL;
! 169: }
! 170: return status;
2.42 frystyk 171: }
172:
2.39 frystyk 173: /* HTAlert_find
174: ** ------------
175: ** Finds a global callback function corresponding to the opcode
1.1 timbl 176: */
2.39 frystyk 177: PUBLIC HTAlertCallback * HTAlert_find (HTAlertOpcode opcode)
1.1 timbl 178: {
2.39 frystyk 179: return HTAlertCall_find(HTMessages, opcode);
1.1 timbl 180: }
2.8 luotonen 181:
2.39 frystyk 182: PUBLIC HTAlertPar * HTAlert_newReply (void)
183: {
2.44 frystyk 184: HTAlertPar * me;
185: if ((me = (HTAlertPar *) HT_CALLOC(1, sizeof(HTAlertPar))) == NULL)
186: HT_OUTOFMEM("HTAlert_newReply");
2.39 frystyk 187: return me;
188: }
2.8 luotonen 189:
2.39 frystyk 190: /* HTAlert_deleteReply
191: ** -------------------
192: ** Delete reply structure but don't touch the replies themselves.
2.8 luotonen 193: */
2.39 frystyk 194: PUBLIC void HTAlert_deleteReply (HTAlertPar * old)
2.8 luotonen 195: {
2.48 frystyk 196: HT_FREE(old);
2.11 luotonen 197: }
198:
2.39 frystyk 199: PUBLIC char * HTAlert_replyMessage (HTAlertPar * me)
200: {
201: return me ? me->message : NULL;
202: }
2.11 luotonen 203:
2.47 frystyk 204: PUBLIC BOOL HTAlert_setReplyMessage (HTAlertPar * me, const char * message)
2.11 luotonen 205: {
2.39 frystyk 206: if (me && message) {
207: StrAllocCopy(me->message, message);
208: return YES;
209: }
210: return NO;
2.8 luotonen 211: }
212:
2.43 frystyk 213: PUBLIC BOOL HTAlert_assignReplyMessage (HTAlertPar * me, char * message)
214: {
215: if (me) me->message = message;
216: return YES;
217: }
218:
2.39 frystyk 219: PUBLIC char * HTAlert_replySecret (HTAlertPar * me)
220: {
221: return me ? me->secret : NULL;
222: }
2.21 frystyk 223:
2.47 frystyk 224: PUBLIC BOOL HTAlert_setReplySecret (HTAlertPar * me, const char * secret)
2.21 frystyk 225: {
2.39 frystyk 226: if (me && secret) {
227: StrAllocCopy(me->secret, secret);
228: return YES;
229: }
230: return NO;
231: }
2.21 frystyk 232:
2.39 frystyk 233: PUBLIC void * HTAlert_replyOutput (HTAlertPar * me)
234: {
235: return me ? me->output : NULL;
236: }
2.21 frystyk 237:
2.39 frystyk 238: PUBLIC BOOL HTAlert_setReplyOutput (HTAlertPar * me, void * output)
239: {
240: if (me) {
241: me->output = output;
242: return YES;
2.21 frystyk 243: }
2.39 frystyk 244: return NO;
2.21 frystyk 245: }
Webmaster