9bf25848d62cfe256a4f80d27ed6bd59679666d7
[oweals/cde.git] / cde / programs / dtcm / dtcm / reminders.c
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these librararies and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /*******************************************************************************
24 **
25 **  reminders.c
26 **
27 **  $XConsortium: reminders.c /main/7 1996/08/06 11:41:54 barstow $
28 **
29 **  RESTRICTED CONFIDENTIAL INFORMATION:
30 **
31 **  The information in this document is subject to special
32 **  restrictions in a confidential disclosure agreement between
33 **  HP, IBM, Sun, USL, SCO and Univel.  Do not distribute this
34 **  document outside HP, IBM, Sun, USL, SCO, or Univel without
35 **  Sun's specific written approval.  This document and all copies
36 **  and derivative works thereof must be returned or destroyed at
37 **  Sun's request.
38 **
39 **  Copyright 1993 Sun Microsystems, Inc.  All rights reserved.
40 **
41 *******************************************************************************/
42
43 /*                                                                      *
44  * (c) Copyright 1993, 1994 Hewlett-Packard Company                     *
45  * (c) Copyright 1993, 1994 International Business Machines Corp.       *
46  * (c) Copyright 1993, 1994 Sun Microsystems, Inc.                      *
47  * (c) Copyright 1993, 1994 Novell, Inc.                                *
48  */
49
50 #include <EUSCompat.h>
51 #include <stdlib.h>
52 #include <stdarg.h>
53 #include <unistd.h>
54 #include <stdio.h>
55 #include <sys/param.h>
56 #include <ctype.h>
57 #include <Xm/Form.h>
58 #include <Xm/LabelG.h>
59 #include <Xm/RowColumn.h>
60 #include <Xm/Text.h>
61 #include <Xm/ToggleBG.h>
62 #include <Xm/ToggleB.h>
63 #include "reminders.h"
64 #include "props.h"
65 #include "help.h"
66 #include "props_pu.h"
67 #include "util.h"
68
69 extern  int _csa_duration_to_iso8601(int, char *);
70 extern  int _csa_iso8601_to_duration(char *, int*);
71
72 /*******************************************************************************
73 **
74 **  Static functions local to reminders.c only
75 **
76 *******************************************************************************/
77
78 static Reminder_val_op
79 r_validate_advance(char *advance_string) {
80
81         char    *c_p = advance_string;
82         char    *end_ptr;
83         Boolean scanned_sign = False;
84
85         /* crush out leading white space for the name
86            comparison/insert process */
87  
88         while ((*c_p == ' ') || (*c_p == '\t'))
89                 c_p++;
90  
91         /* compress off trailing whitespace */
92  
93         end_ptr = c_p;
94         while (*end_ptr)
95                 end_ptr++;
96         while ((end_ptr > c_p) &&
97                ((*(end_ptr - 1) == ' ') || (*(end_ptr - 1) == '\t')))
98                 end_ptr--;
99  
100         *end_ptr = 0;
101
102
103         if (blank_buf(c_p)) {
104                 return(ADVANCE_BLANK);
105         }
106
107         if (embedded_blank(c_p)) {
108                 return(ADVANCE_CONTAINS_BLANK);
109         }
110
111         while (c_p && *c_p) {
112                 if (isdigit(*c_p) || ((*c_p == '-') && (scanned_sign == False))) {
113                         if ((*c_p == '-') && (scanned_sign == False))
114                                 scanned_sign = True;
115                         c_p++;
116                 } else {
117                         return(ADVANCE_NONNUMERIC);
118
119                 }
120         }
121
122         return(REMINDERS_OK);
123 }
124
125 static Reminder_val_op
126 r_get_bfpm_vals(Widget toggle, Widget text, Reminders_val *val,
127                 Boolean convert_to_secs) {
128         char                    *cval;
129         Time_scope_menu_op      scope;
130         Reminder_val_op         status;
131
132         if (!XmToggleButtonGetState(toggle)) {
133                 val->selected = False;
134                 val->scope_val = -1;
135                 return(REMINDERS_OK);
136         }
137
138         val->selected = True;
139         cval = XmTextGetString(text);
140
141         if ((status = r_validate_advance(cval)) != REMINDERS_OK)
142                 return(status);
143
144         val->scope_val = atoi(cval);
145         XtFree(cval);
146
147         switch(val->scope) {
148         case TIME_DAYS:
149                 if (convert_to_secs)
150                         val->scope_val = days_to_seconds(val->scope_val);
151                 break;
152         case TIME_HRS:
153                 if (convert_to_secs)
154                         val->scope_val = hours_to_seconds(val->scope_val);
155                 break;
156         case TIME_MINS:
157         default:
158                 if (convert_to_secs)
159                         val->scope_val = minutes_to_seconds(val->scope_val);
160                 break;
161         }
162
163         return(REMINDERS_OK);
164 }
165
166 static void
167 r_get_mailto_val(Reminders *r) {
168         char    *c;
169
170         c = XmTextGetString(r->mailto_text);
171         if (!blank_buf(c))
172                 cm_strcpy(r->mailto_val, c);
173         else
174                 cm_strcpy(r->mailto_val, cm_get_credentials());
175         XtFree(c);
176 }
177
178 static void
179 r_set_bfpm_vals(
180         Widget          toggle, 
181         Widget          text, 
182         Widget          menu, 
183         Reminders_val  *val,
184         Boolean         compute_best_fit) 
185 {
186         char            buf[128];
187         Calendar       *c = calendar;
188         Widget          submenu;
189         int             n;
190         WidgetList      option_items;
191         Time_scope_menu_op      scope = val->scope;
192         XmString                xmstr;
193
194
195         if (!XtIsManaged(toggle))
196                 return;
197
198         XtVaGetValues(menu,
199                 XmNsubMenuId,   &submenu,
200                 NULL);
201         
202         XtVaGetValues(submenu,
203                 XmNchildren,    &option_items,
204                 XmNnumChildren, &n,
205                 NULL);
206
207         if (!val->selected) {
208                 XmToggleButtonSetState(toggle, False, True);
209                 XtVaSetValues(text, XmNvalue, "\0",
210                         NULL);
211
212                 switch ( scope ) {
213                   case TIME_MINS :
214                       xmstr = XmStringCreateLocalized(
215                 catgets( calendar->DT_catd, 1, 877, time_scope_str(scope) ) );
216                       break;
217                   case TIME_HRS :
218                       xmstr = XmStringCreateLocalized(
219                 catgets( calendar->DT_catd, 1, 878, time_scope_str(scope) ) );
220                       break;
221                   case TIME_DAYS :
222                       xmstr = XmStringCreateLocalized(
223                 catgets( calendar->DT_catd, 1, 879, time_scope_str(scope) ) );
224                       break;
225                   default :
226                       xmstr = XmStringCreateLocalized(time_scope_str(scope));
227                 }
228                 XtVaSetValues(XmOptionButtonGadget(menu), XmNlabelString, xmstr,
229                         NULL);
230                 XmStringFree(xmstr);
231
232                 return;
233         }
234
235         if (compute_best_fit) {
236                 if (val->scope_val % daysec == 0) {
237                         val->scope = TIME_DAYS;
238                         sprintf(buf, "%d", seconds_to_days(val->scope_val));
239                 } else if (val->scope_val % hrsec == 0) {
240                         val->scope = TIME_HRS;
241                         sprintf(buf, "%d", seconds_to_hours(val->scope_val));
242                 } else {
243                         val->scope = TIME_MINS;
244                         sprintf(buf, "%d", seconds_to_minutes(val->scope_val));
245                 }
246         } else
247                 sprintf(buf, "%d", val->scope_val);
248
249         switch ( scope ) {
250           case TIME_MINS :
251               xmstr = XmStringCreateLocalized(
252                 catgets( calendar->DT_catd, 1, 877, time_scope_str(scope) ) );
253               break;
254           case TIME_HRS :
255               xmstr = XmStringCreateLocalized(
256                 catgets( calendar->DT_catd, 1, 878, time_scope_str(scope) ) );
257               break;
258           case TIME_DAYS :
259               xmstr = XmStringCreateLocalized(
260                 catgets( calendar->DT_catd, 1, 879, time_scope_str(scope) ) );
261               break;
262           default :
263               xmstr = XmStringCreateLocalized(time_scope_str(scope));
264         }
265         XtVaSetValues(XmOptionButtonGadget(menu), XmNlabelString, xmstr,
266                 NULL);
267         XmStringFree(xmstr);
268
269         XmToggleButtonSetState(toggle, True, True);
270         XtVaSetValues(text, XmNvalue, buf,
271                 NULL);
272 }
273
274 static void
275 r_set_mailto_val(Reminders *r) {
276         XtVaSetValues(r->mailto_text, XmNvalue, r->mailto_val,
277                 NULL);
278 }
279
280 /*
281 **  The function ensures the user data is set properly for the time scope
282 **  menus.  This way, when the r_get_bfpm_vals function is called, it knows
283 **  how it should convert the value found in the text field.
284 */
285 static void
286 r_scope_menu_proc(Widget item, XtPointer client_data, XtPointer cbs) {
287         Reminders_val           *val = (Reminders_val *)client_data;
288         Time_scope_menu_op      scope;
289
290         XtVaGetValues(item, XmNuserData, &val->scope,
291                 NULL);
292 }
293
294 /*
295 **  Function sets the alarm text fields and menus sensitive/insensitive
296 **  depending on the state of the toggle button.
297 */
298 static void
299 r_alarm_toggle_proc(Widget toggle_w, XtPointer client_data, XtPointer cbs) {
300
301         Boolean         status = XmToggleButtonGetState(toggle_w);
302         Reminders       *r = (Reminders *)client_data;
303         Widget          text_w, menu_w;
304
305         if (!r)
306                 return;
307
308         if (toggle_w == r->beep_toggle) {
309                 XtVaSetValues(r->beep_text, XmNsensitive, status,
310                         NULL);
311                 XtVaSetValues(XmOptionButtonGadget(r->beep_menu),
312                         XmNsensitive, status,
313                         NULL);
314         } else if (toggle_w == r->flash_toggle) {
315                 XtVaSetValues(r->flash_text, XmNsensitive, status,
316                         NULL);
317                 XtVaSetValues(XmOptionButtonGadget(r->flash_menu),
318                         XmNsensitive, status,
319                         NULL);
320         } else if (toggle_w == r->popup_toggle) {
321                 XtVaSetValues(r->popup_text, XmNsensitive, status,
322                         NULL);
323                 XtVaSetValues(XmOptionButtonGadget(r->popup_menu),
324                         XmNsensitive, status,
325                         NULL);
326         } else if (toggle_w == r->mail_toggle) {
327                 XtVaSetValues(r->mail_text, XmNsensitive, status,
328                         NULL);
329                 XtVaSetValues(XmOptionButtonGadget(r->mail_menu),
330                         XmNsensitive, status,
331                         NULL);
332                 XtVaSetValues(r->mailto_label, XmNsensitive, status,
333                         NULL);
334                 XtVaSetValues(r->mailto_text, XmNsensitive, status,
335                         NULL);
336         }
337 }
338
339 /*******************************************************************************
340 **
341 **  External functions
342 **
343 *******************************************************************************/
344 extern void
345 build_reminders(Reminders *r, Calendar *c, Widget parent) {
346
347         Widget          widest_toggle;
348         Dimension       widest, highest;
349         Widget          prev, curr;
350         Dimension       _toText, _toOption;
351         XmString        xmstr;
352
353         r->cal = c;
354         r->parent = parent;
355
356         /*
357         **  Base form and label
358         */
359         r->bfpm_form_mgr = XtVaCreateWidget("bfpm_form_mgr",
360                 xmFormWidgetClass, parent,
361                 XmNautoUnmanage, False,
362                 NULL);
363
364         xmstr = XmStringCreateLocalized(
365                                 catgets(c->DT_catd, 1, 985, "Reminders"));
366         r->alarm_label = XtVaCreateWidget("Reminders",
367                 xmLabelGadgetClass, r->bfpm_form_mgr,
368                 XmNlabelString,         xmstr,
369                 XmNtopAttachment, XmATTACH_FORM,
370                 XmNtopOffset, 5,
371                 XmNleftAttachment, XmATTACH_FORM,
372                 XmNleftOffset, 5,
373                 NULL);
374         XmStringFree(xmstr);
375
376         /* Create the 4 toggle items to see which one is the longest */
377
378         xmstr = XmStringCreateLocalized(
379                                 catgets(c->DT_catd, 1, 986, "Beep"));
380         r->beep_toggle = XtVaCreateWidget("Beep",
381                 xmToggleButtonGadgetClass, r->bfpm_form_mgr,
382                 XmNlabelString,         xmstr,
383                 XmNnavigationType, XmTAB_GROUP,
384                 NULL);
385         XmStringFree(xmstr);
386
387
388         xmstr = XmStringCreateLocalized(
389                                 catgets(c->DT_catd, 1, 987, "Flash"));
390         r->flash_toggle = XtVaCreateWidget("Flash",
391                 xmToggleButtonGadgetClass, r->bfpm_form_mgr,
392                 XmNlabelString,         xmstr,
393                 XmNnavigationType, XmTAB_GROUP,
394                 NULL);
395         XmStringFree(xmstr);
396
397
398         xmstr = XmStringCreateLocalized(
399                                 catgets(c->DT_catd, 1, 988, "Popup"));
400         r->popup_toggle = XtVaCreateWidget("Popup",
401                 xmToggleButtonGadgetClass, r->bfpm_form_mgr,
402                 XmNlabelString,         xmstr,
403                 XmNnavigationType, XmTAB_GROUP,
404                 NULL);
405         XmStringFree(xmstr);
406
407
408         xmstr = XmStringCreateLocalized(
409                                 catgets(c->DT_catd, 1, 989, "Mail"));
410         r->mail_toggle = XtVaCreateWidget("Mail",
411                 xmToggleButtonGadgetClass, r->bfpm_form_mgr,
412                 XmNlabelString,         xmstr,
413                 XmNnavigationType, XmTAB_GROUP,
414                 NULL);
415         XmStringFree(xmstr);
416
417
418         xmstr = XmStringCreateLocalized(
419                            catgets(c->DT_catd, 1, 990, "Mail To:" ) );
420         r->mailto_label = XtVaCreateManagedWidget("MailTo",
421                 xmLabelGadgetClass, r->bfpm_form_mgr,
422                 XmNlabelString, xmstr,
423                 XmNsensitive, False,
424                 NULL);
425         XmStringFree(xmstr);
426
427
428         /*
429         **  Beep toggle, text, and menu
430         */
431         XtAddCallback(r->beep_toggle, XmNvalueChangedCallback,
432                 r_alarm_toggle_proc, r);
433
434         r->beep_text = XtVaCreateWidget("beep_text",
435                 xmTextWidgetClass, r->bfpm_form_mgr,
436                 XmNeditMode, XmSINGLE_LINE_EDIT,
437                 XmNsensitive, False,
438                 XmNmaxLength, REMINDER_SCOPE_LEN - 1,
439                 NULL);
440
441         r->beep_menu = (Widget)create_time_scope_menu(r->bfpm_form_mgr,
442                 NULL, r_scope_menu_proc, (XtPointer)&r->beep_val);
443         XtVaSetValues(r->beep_menu,
444                 XmNnavigationType, XmTAB_GROUP,
445                 NULL);
446
447         /*
448         **  Flash toggle, text, and menu
449         */
450         XtAddCallback(r->flash_toggle, XmNvalueChangedCallback,
451                 r_alarm_toggle_proc, r);
452
453         r->flash_text = XtVaCreateWidget("flash_text",
454                 xmTextWidgetClass, r->bfpm_form_mgr,
455                 XmNeditMode, XmSINGLE_LINE_EDIT,
456                 XmNsensitive, False,
457                 XmNmaxLength, REMINDER_SCOPE_LEN - 1,
458                 NULL);
459
460         r->flash_menu = (Widget)create_time_scope_menu(r->bfpm_form_mgr,
461                 NULL, r_scope_menu_proc, (XtPointer)&r->flash_val);
462         XtVaSetValues(r->flash_menu,
463                 XmNnavigationType, XmTAB_GROUP,
464                 NULL);
465
466         /*
467         **  Popup toggle, text, and menu
468         */
469         XtAddCallback(r->popup_toggle, XmNvalueChangedCallback,
470                 r_alarm_toggle_proc, r);
471
472         r->popup_text = XtVaCreateWidget("popup_text",
473                 xmTextWidgetClass, r->bfpm_form_mgr,
474                 XmNeditMode, XmSINGLE_LINE_EDIT,
475                 XmNsensitive, False,
476                 XmNmaxLength, REMINDER_SCOPE_LEN - 1,
477                 NULL);
478
479         r->popup_menu = (Widget)create_time_scope_menu(r->bfpm_form_mgr,
480                 NULL, r_scope_menu_proc, (XtPointer)&r->popup_val);
481         XtVaSetValues(r->popup_menu,
482                 XmNnavigationType, XmTAB_GROUP,
483                 NULL);
484
485         /*
486         **  Mail toggle, text, and menu
487         */
488         XtAddCallback(r->mail_toggle, XmNvalueChangedCallback,
489                 r_alarm_toggle_proc, r);
490
491         r->mail_text = XtVaCreateWidget("mail_text",
492                 xmTextWidgetClass, r->bfpm_form_mgr,
493                 XmNeditMode, XmSINGLE_LINE_EDIT,
494                 XmNsensitive, False,
495                 XmNmaxLength, REMINDER_SCOPE_LEN - 1,
496                 NULL);
497
498         r->mail_menu = (Widget)create_time_scope_menu(r->bfpm_form_mgr,
499                 NULL, r_scope_menu_proc, (XtPointer)&r->mail_val);
500         XtVaSetValues(r->mail_menu,
501                 XmNnavigationType, XmTAB_GROUP,
502                 NULL);
503
504         /*
505         **  Mailto text
506         */
507         r->mailto_text = XtVaCreateWidget("mailto_text",
508                 xmTextWidgetClass, r->bfpm_form_mgr,
509                 XmNeditMode, XmSINGLE_LINE_EDIT,
510                 XmNsensitive, False,
511                 XmNmaxLength, MAILTO_LEN - 1,
512                 NULL);
513         /*
514          * Here, we do a layout.
515          */
516
517         _i18n_WidestWidget( 5, &prev, &widest, r->beep_toggle, r->flash_toggle,
518                         r->popup_toggle, r->mail_toggle, r->mailto_label );
519         _toText = 5 + 10 + widest + 10;
520
521         _i18n_WidestWidget( 4, &prev, &widest, r->beep_text, r->flash_text,
522                         r->popup_text, r->mail_text );
523         _toOption = _toText + widest + 5;
524
525         /*
526          * r->beep_toggle,r->beep_text,r->beep_menu
527          */
528         prev = r->alarm_label;
529         _i18n_HighestWidgetAdjust( 3, &curr, &highest, r->beep_toggle,
530                          r->beep_text, r->beep_menu );
531         XtVaSetValues( curr,
532                         XmNtopAttachment, XmATTACH_WIDGET,
533                         XmNtopWidget, prev,
534                         XmNtopOffset, 10,
535                         NULL );
536         XtVaSetValues( r->beep_toggle,
537                         XmNleftAttachment, XmATTACH_FORM,
538                         XmNleftOffset, 5 + 10,
539                         NULL );
540         XtVaSetValues( r->beep_text,
541                         XmNleftAttachment, XmATTACH_FORM,
542                         XmNleftOffset, _toText,
543                         NULL );
544         XtVaSetValues( r->beep_menu,
545                         XmNleftAttachment, XmATTACH_FORM,
546                         XmNleftOffset, _toOption,
547                         NULL );
548         prev = curr;
549
550         /*
551          * r->flash_toggle,r->flash_text,r->flash_menu
552          */
553         _i18n_HighestWidgetAdjust( 3, &curr, &highest, r->flash_toggle,
554                         r->flash_text, r->flash_menu );
555         XtVaSetValues( curr,
556                         XmNtopAttachment, XmATTACH_WIDGET,
557                         XmNtopWidget, prev,
558                         XmNtopOffset, 10,
559                         NULL );
560         XtVaSetValues( r->flash_toggle,
561                         XmNleftAttachment, XmATTACH_FORM,
562                         XmNleftOffset, 5 + 10,
563                         NULL );
564         XtVaSetValues( r->flash_text,
565                         XmNleftAttachment, XmATTACH_FORM,
566                         XmNleftOffset, _toText,
567                         NULL );
568         XtVaSetValues( r->flash_menu,
569                         XmNleftAttachment, XmATTACH_FORM,
570                         XmNleftOffset, _toOption,
571                         NULL );
572         prev = curr;
573
574         /*
575          * r->popup_toggle,r->popup_text,r->popup_menu
576          */
577         _i18n_HighestWidgetAdjust( 3, &curr, &highest, r->popup_toggle,
578                         r->popup_text, r->popup_menu );
579         XtVaSetValues( curr,
580                         XmNtopAttachment, XmATTACH_WIDGET,
581                         XmNtopWidget, prev,
582                         XmNtopOffset, 10,
583                         NULL );
584         XtVaSetValues( r->popup_toggle,
585                         XmNleftAttachment, XmATTACH_FORM,
586                         XmNleftOffset, 5 + 10,
587                         NULL );
588         XtVaSetValues( r->popup_text,
589                         XmNleftAttachment, XmATTACH_FORM,
590                         XmNleftOffset, _toText,
591                         NULL );
592         XtVaSetValues( r->popup_menu,
593                         XmNleftAttachment, XmATTACH_FORM,
594                         XmNleftOffset, _toOption,
595                         NULL );
596         prev = curr;
597
598         /*
599          * r->mail_toggle,r->mail_text,r->mail_menu
600          */
601         _i18n_HighestWidgetAdjust( 3, &curr, &highest, r->mail_toggle,
602                                 r->mail_text, r->mail_menu );
603         XtVaSetValues( curr,
604                         XmNtopAttachment, XmATTACH_WIDGET,
605                         XmNtopWidget, prev,
606                         XmNtopOffset, 10,
607                         NULL );
608         XtVaSetValues( r->mail_toggle,
609                         XmNleftAttachment, XmATTACH_FORM,
610                         XmNleftOffset, 5 + 10,
611                         NULL );
612         XtVaSetValues( r->mail_text,
613                         XmNleftAttachment, XmATTACH_FORM,
614                         XmNleftOffset, _toText,
615                         NULL );
616         XtVaSetValues( r->mail_menu,
617                         XmNleftAttachment, XmATTACH_FORM,
618                         XmNleftOffset, _toOption,
619                         NULL );
620         prev = curr;
621
622         /*
623          * r->mailto_label,r->mailto_text
624          */
625         _i18n_HighestWidgetAdjust( 2, &curr, &highest, r->mailto_label,
626                                         r->mailto_text );
627         XtVaSetValues( curr,
628                         XmNtopAttachment, XmATTACH_WIDGET,
629                         XmNtopWidget, prev,
630                         XmNtopOffset, 20,
631                         NULL );
632         XtVaSetValues( r->mailto_label,
633                         XmNleftAttachment, XmATTACH_FORM,
634                         XmNleftOffset, 5 + 10,
635                         NULL );
636         XtVaSetValues( r->mailto_text,
637                         XmNleftAttachment, XmATTACH_FORM,
638                         XmNleftOffset, _toText,
639                         NULL );
640 }
641
642 extern Reminder_val_op
643 get_reminders_vals(Reminders *r, Boolean convert_to_secs) {
644
645         Reminder_val_op status;
646
647         if ((status = r_get_bfpm_vals(r->beep_toggle, r->beep_text, &r->beep_val,
648                         convert_to_secs)) != REMINDERS_OK)
649                 return(status);
650
651         if ((status = r_get_bfpm_vals(r->flash_toggle, r->flash_text, &r->flash_val,
652                         convert_to_secs)) != REMINDERS_OK)
653                 return(status);
654
655         if ((status = r_get_bfpm_vals(r->mail_toggle, r->mail_text, &r->mail_val,
656                         convert_to_secs)) != REMINDERS_OK)
657                 return(status);
658
659         if ((status = r_get_bfpm_vals(r->popup_toggle, r->popup_text, &r->popup_val,
660                         convert_to_secs)) != REMINDERS_OK)
661                 return(status);
662
663         r_get_mailto_val(r);
664
665         return(REMINDERS_OK);
666 }
667
668 static void
669 reminder_err_msg(Widget frame, char *name, Reminder_val_op op, Pixmap p) 
670 {
671         Calendar        *c = calendar;
672         char            buf[MAXNAMELEN], buf2[MAXNAMELEN * 2];
673         char            *title;
674         char            *ident1;
675
676         switch(op) {
677         case ADVANCE_BLANK:
678                 sprintf(buf, "%s", catgets(c->DT_catd, 1, 775, "You must specify a reminder advance\nOperation was cancelled.  Calendar"));
679                 break;
680         case ADVANCE_CONTAINS_BLANK:
681                 sprintf(buf, "%s", catgets(c->DT_catd, 1, 776, "A reminder advance may not contain an embedded blank\nOperation was cancelled.  Calendar"));
682                 break;
683         case ADVANCE_NONNUMERIC:
684                 sprintf(buf, "%s", catgets(c->DT_catd, 1, 777, "Advance values must be a number with an optional sign\nOperation was cancelled.  Calendar"));
685                 break;
686         case REMINDERS_OK:
687         default:
688                 return;
689         }
690
691  
692         sprintf(buf2, "%s %s", buf, name);
693         title = XtNewString(catgets(c->DT_catd, 1, 364,
694                         "Calendar : Error - Editor"));
695         ident1 = XtNewString(catgets(c->DT_catd, 1, 95, "Continue"));
696         dialog_popup(frame, DIALOG_TITLE, title,
697                 DIALOG_TEXT, buf2,
698                 BUTTON_IDENT, 1, ident1,
699                 BUTTON_HELP, ADVANCE_ERROR_HELP,
700                 DIALOG_IMAGE, p,
701                 NULL);
702         XtFree(ident1);
703         XtFree(title);
704 }
705
706
707 /*
708 **  This function will consume form values and stuff them into an appointment.
709 */
710 extern Boolean 
711 reminders_form_to_appt(Reminders *r, Dtcm_appointment *appt, char *name) {
712
713         Reminder_val_op status;
714         Props_pu        *pu = (Props_pu *)r->cal->properties_pu;
715
716         if (r->bfpm_form_mgr) {
717                 if ((status = get_reminders_vals(r, True)) != REMINDERS_OK) {
718                         reminder_err_msg(r->parent, name, status, 
719                                                         pu->xm_error_pixmap);
720                         return(False);
721                 }
722         }
723
724         if (!r->beep_val.selected) {
725                 free(appt->beep->value);
726                 appt->beep->value = NULL;
727         } else {
728                 appt->beep->value->item.reminder_value->lead_time = (char *) malloc(BUFSIZ);
729                 _csa_duration_to_iso8601(r->beep_val.scope_val, appt->beep->value->item.reminder_value->lead_time);
730                 appt->beep->value->item.reminder_value->reminder_data.data = NULL;
731                 appt->beep->value->item.reminder_value->reminder_data.size = 0;
732         }
733
734         if (!r->flash_val.selected) {
735                 free(appt->flash->value);
736                 appt->flash->value = NULL;
737         } else { 
738                 appt->flash->value->item.reminder_value->lead_time = (char *) malloc(BUFSIZ);
739                 _csa_duration_to_iso8601(r->flash_val.scope_val, appt->flash->value->item.reminder_value->lead_time);
740                 appt->flash->value->item.reminder_value->reminder_data.data = NULL;
741                 appt->flash->value->item.reminder_value->reminder_data.size = 0;
742         }
743
744         if (!r->popup_val.selected) {
745                 free(appt->popup->value);
746                 appt->popup->value = NULL;
747         } else {
748                 appt->popup->value->item.reminder_value->lead_time = (char *) malloc(BUFSIZ);
749                 _csa_duration_to_iso8601(r->popup_val.scope_val, appt->popup->value->item.reminder_value->lead_time);
750                 appt->popup->value->item.reminder_value->reminder_data.data = NULL;
751                 appt->popup->value->item.reminder_value->reminder_data.size = 0;
752         }
753
754         if (!r->mail_val.selected) {
755                 free(appt->mail->value);
756                 appt->mail->value = NULL;
757         } else {
758                 appt->mail->value->item.reminder_value->lead_time = (char *) malloc(BUFSIZ);
759                 _csa_duration_to_iso8601(r->mail_val.scope_val, appt->mail->value->item.reminder_value->lead_time);
760                 appt->mail->value->item.reminder_value->reminder_data.data = (CSA_uint8 *) cm_strdup(r->mailto_val);
761                 appt->mail->value->item.reminder_value->reminder_data.size = strlen(r->mailto_val);
762         }
763
764         return True;
765 }
766
767 /*
768 **  This function will take appointment values and stuff them into a form.
769 */
770 extern Boolean
771 reminders_appt_to_form(Reminders *r, CSA_entry_handle entry) {
772         Boolean                 ret_val;
773         CSA_return_code         stat;
774         Dtcm_appointment        *appt;
775
776         appt = allocate_appt_struct(appt_read,
777                                     r->cal->general->version,
778                                     CSA_ENTRY_ATTR_AUDIO_REMINDER_I,
779                                     CSA_ENTRY_ATTR_FLASHING_REMINDER_I,
780                                     CSA_ENTRY_ATTR_POPUP_REMINDER_I,
781                                     CSA_ENTRY_ATTR_MAIL_REMINDER_I,
782                                     NULL);
783         stat = query_appt_struct(r->cal->cal_handle, entry, appt);
784         backend_err_msg(r->cal->frame, r->cal->view->current_calendar, stat,
785                 ((Props_pu *)r->cal->properties_pu)->xm_error_pixmap);
786         if (stat != CSA_SUCCESS) {
787                 free_appt_struct(&appt);
788                 return False;
789         }
790
791         ret_val = reminders_attrs_to_form(r, appt);
792         free_appt_struct(&appt);
793
794         return ret_val;
795 }
796
797 extern Boolean
798 reminders_attrs_to_form(Reminders *r, Dtcm_appointment *appt) {
799
800         if (appt->beep && appt->beep->value) {
801                 r->beep_val.selected = True;
802                 _csa_iso8601_to_duration(appt->beep->value->item.reminder_value->lead_time, &r->beep_val.scope_val);
803         } else {
804                 r->beep_val.selected = False;
805                 r->beep_val.scope_val = -1;
806         }
807
808         if (appt->flash && appt->flash->value) {
809                 r->flash_val.selected = True;
810                 _csa_iso8601_to_duration(appt->flash->value->item.reminder_value->lead_time, &r->flash_val.scope_val);
811         } else {
812                 r->flash_val.selected = False;
813                 r->flash_val.scope_val = -1;
814         }
815
816         if (appt->popup && appt->popup->value) {
817                 r->popup_val.selected = True;
818                 _csa_iso8601_to_duration(appt->popup->value->item.reminder_value->lead_time, &r->popup_val.scope_val);;
819         } else {
820                 r->popup_val.selected = False;
821                 r->popup_val.scope_val = -1;
822         }
823         if (appt->mail && appt->mail->value) {
824                 r->mail_val.selected = True;
825                 _csa_iso8601_to_duration(appt->mail->value->item.reminder_value->lead_time, &r->mail_val.scope_val);
826                 memset(r->mailto_val, 0, MAILTO_LEN);
827                 strncpy(r->mailto_val, (char *) appt->mail->value->item.reminder_value->reminder_data.data, appt->mail->value->item.reminder_value->reminder_data.size);
828         } else {
829                 r->mail_val.selected = False;
830                 r->mail_val.scope_val = -1;
831                 r->mailto_val[0] = '\0';
832         }
833
834         set_reminders_vals(r, True);
835
836         return True;
837 }
838
839 extern void
840 set_reminders_defaults(Reminders *r) {
841         Props           *p = (Props *)r->cal->properties;
842         Reminders_val   *val;
843
844         val = &r->beep_val;
845         val->selected = convert_boolean_str(get_char_prop(p, CP_BEEPON));
846         val->scope = convert_time_scope_str(get_char_prop(p, CP_BEEPUNIT));
847         val->scope_val = get_int_prop(p, CP_BEEPADV);
848
849         val = &r->flash_val;
850         val->selected = convert_boolean_str(get_char_prop(p, CP_FLASHON));
851         val->scope = convert_time_scope_str(get_char_prop(p, CP_FLASHUNIT));
852         val->scope_val = get_int_prop(p, CP_FLASHADV);
853
854         val = &r->popup_val;
855         val->selected = convert_boolean_str(get_char_prop(p, CP_OPENON));
856         val->scope = convert_time_scope_str(get_char_prop(p, CP_OPENUNIT));
857         val->scope_val = get_int_prop(p, CP_OPENADV);
858
859         val = &r->mail_val;
860         val->selected = convert_boolean_str(get_char_prop(p, CP_MAILON));
861         val->scope = convert_time_scope_str(get_char_prop(p, CP_MAILUNIT));
862         val->scope_val = get_int_prop(p, CP_MAILADV);
863         strcpy(r->mailto_val, get_char_prop(p, CP_MAILTO));
864
865         set_reminders_vals(r, False);
866 }
867
868 extern void
869 set_reminders_vals(Reminders *r, Boolean compute_best_fit) {
870
871         r_set_bfpm_vals(r->beep_toggle, r->beep_text, r->beep_menu,
872                 &r->beep_val, compute_best_fit);
873         r_set_bfpm_vals(r->flash_toggle, r->flash_text, r->flash_menu,
874                 &r->flash_val, compute_best_fit);
875         r_set_bfpm_vals(r->mail_toggle, r->mail_text, r->mail_menu,
876                 &r->mail_val, compute_best_fit);
877         r_set_bfpm_vals(r->popup_toggle, r->popup_text, r->popup_menu,
878                 &r->popup_val, compute_best_fit);
879
880         r_set_mailto_val(r);
881 }
882
883 static int
884 convert_time_val(
885         int                     value,
886         Time_scope_menu_op      type)
887 {
888         switch(type) {
889         case TIME_DAYS:
890                 return days_to_seconds(value);
891         case TIME_HRS:
892                 return hours_to_seconds(value);
893         case TIME_MINS:
894         default:
895                 return minutes_to_seconds(value);
896         }
897 }
898
899 extern void
900 reminders_init(
901         Reminders       *r,
902         Calendar        *c,
903         Widget           parent)
904 {
905         Props           *p = (Props *)c->properties;
906         Reminders_val   *val;
907
908         r->parent = parent;
909         r->cal = c;
910
911         val = &r->beep_val;
912         val->selected = convert_boolean_str(get_char_prop(p, CP_BEEPON));
913         val->scope = convert_time_scope_str(get_char_prop(p, CP_BEEPUNIT));
914         val->scope_val = convert_time_val(get_int_prop(p, CP_BEEPADV), 
915                                           val->scope);
916
917         val = &r->flash_val;
918         val->selected = convert_boolean_str(get_char_prop(p, CP_FLASHON));
919         val->scope = convert_time_scope_str(get_char_prop(p, CP_FLASHUNIT));
920         val->scope_val = convert_time_val(get_int_prop(p, CP_FLASHADV), 
921                                           val->scope);
922
923         val = &r->popup_val;
924         val->selected = convert_boolean_str(get_char_prop(p, CP_OPENON));
925         val->scope = convert_time_scope_str(get_char_prop(p, CP_OPENUNIT));
926         val->scope_val = convert_time_val(get_int_prop(p, CP_OPENADV), 
927                                           val->scope);
928
929         val = &r->mail_val;
930         val->selected = convert_boolean_str(get_char_prop(p, CP_MAILON));
931         val->scope = convert_time_scope_str(get_char_prop(p, CP_MAILUNIT));
932         val->scope_val = convert_time_val(get_int_prop(p, CP_MAILADV), 
933                                           val->scope);
934         strcpy(r->mailto_val, get_char_prop(p, CP_MAILTO));
935
936 }
937