File: qmon_calendar.c

package info (click to toggle)
gridengine 8.1.9%2Bdfsg-13.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 57,140 kB
  • sloc: ansic: 432,689; java: 87,068; cpp: 31,958; sh: 29,445; jsp: 7,757; perl: 6,336; xml: 5,828; makefile: 4,704; csh: 3,934; ruby: 2,221; tcl: 1,676; lisp: 669; yacc: 519; python: 503; lex: 361; javascript: 200
file content (575 lines) | stat: -rw-r--r-- 16,985 bytes parent folder | download | duplicates (6)
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
/*___INFO__MARK_BEGIN__*/
/*************************************************************************
 * 
 *  The Contents of this file are made available subject to the terms of
 *  the Sun Industry Standards Source License Version 1.2
 * 
 *  Sun Microsystems Inc., March, 2001
 * 
 * 
 *  Sun Industry Standards Source License Version 1.2
 *  =================================================
 *  The contents of this file are subject to the Sun Industry Standards
 *  Source License Version 1.2 (the "License"); You may not use this file
 *  except in compliance with the License. You may obtain a copy of the
 *  License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html
 * 
 *  Software provided under this License is provided on an "AS IS" basis,
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 *  See the License for the specific provisions governing your rights and
 *  obligations concerning the Software.
 * 
 *   The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 * 
 *   Copyright: 2001 by Sun Microsystems, Inc.
 * 
 *   All Rights Reserved.
 * 
 ************************************************************************/
/*___INFO__MARK_END__*/
#include <stdio.h>
#include <ctype.h>

#include <Xm/Xm.h>
#include <Xm/List.h>

#include <Xmt/Xmt.h>
#include <Xmt/Create.h>
#include <Xmt/Layout.h>
#include <Xmt/Chooser.h>
#include <Xmt/Dialog.h>
#include <Xmt/Dialogs.h>
#include <Xmt/MsgLine.h>
#include <Xmt/InputField.h>

#include "qmon_proto.h"
#include "qmon_rmon.h"
#include "qmon_cull.h"
#include "qmon_util.h"
#include "qmon_appres.h"
#include "qmon_timer.h"
#include "qmon_comm.h"
#include "qmon_widgets.h"
#include "qmon_message.h"
#include "qmon_calendar.h"
#include "qmon_globals.h"

#include "uti/sge_dstring.h"

#include "sgeobj/sge_all_listsL.h"
#include "sgeobj/sge_answer.h"
#include "sgeobj/sge_calendar.h"

#include "gdi/sge_gdi.h"

static Widget qmon_cal = 0;
static Widget cal_names = 0;
static Widget cal_name_w = 0;
static Widget cal_year_w = 0;
static Widget cal_week_w = 0;
static Widget cal_ask_layout = 0;
static Widget cal_conf_list = 0;
static int add_mode = 0;

/*-------------------------------------------------------------------------*/
static void qmonPopdownCalendarConfig(Widget w, XtPointer cld, XtPointer cad);
static Widget qmonCreateCalendarConfig(Widget parent);
static void qmonCalendarFillConf(Widget w, lListElem *ep);
static void qmonSelectCalendar(Widget w, XtPointer cld, XtPointer cad);
static void qmonCalendarAdd(Widget w, XtPointer cld, XtPointer cad);
static void qmonCalendarModify(Widget w, XtPointer cld, XtPointer cad);
static void qmonCalendarDelete(Widget w, XtPointer cld, XtPointer cad);
static void qmonCalendarOk(Widget w, XtPointer cld, XtPointer cad);
static void qmonCalendarCancel(Widget w, XtPointer cld, XtPointer cad);
static void qmonCalendarResetAsk(void);
static void qmonCalendarSetAsk(lListElem *calp);
static Widget qmonCreateCalendarAsk(Widget parent);
static Boolean qmonCalendarGetAsk(lListElem *calp);

/*-------------------------------------------------------------------------*/
void qmonPopupCalendarConfig(Widget w, XtPointer cld, XtPointer cad)
{
   Widget shell;
   lList *alp = NULL;

   DENTER(GUI_LAYER, "qmonPopupCalendarConfig");

   /* set busy cursor */
   XmtDisplayBusyCursor(w);

   if (!qmon_cal) {
      shell = XmtGetTopLevelShell(w);
      qmon_cal = qmonCreateCalendarConfig(shell);
      XmtAddDeleteCallback(shell, XmDO_NOTHING, 
                              qmonPopdownCalendarConfig, NULL);
      /*
      ** create ask layout
      */
      cal_ask_layout = qmonCreateCalendarAsk(qmon_cal);

   } 
   XSync(XtDisplay(qmon_cal), 0);
   XmUpdateDisplay(qmon_cal);

   qmonMirrorMultiAnswer(CALENDAR_T, &alp);
   if (alp) {
      qmonMessageBox(w, alp, 0);
      lFreeList(&alp);
      /* set default cursor */
      XmtDisplayDefaultCursor(w);
      DEXIT;
      return;
   }
   qmonTimerAddUpdateProc(CALENDAR_T, "updateCalendarList", updateCalendarList);
   qmonStartTimer(CALENDAR_T);
   updateCalendarList();
   XmListSelectPos(cal_names, 1, True);

   XtManageChild(qmon_cal);
   XRaiseWindow(XtDisplay(XtParent(qmon_cal)), XtWindow(XtParent(qmon_cal)));

   /* set default cursor */
   XmtDisplayDefaultCursor(w);

   DEXIT;
}

/*-------------------------------------------------------------------------*/
void updateCalendarList(void)
{
   lList *cl;
   
   DENTER(GUI_LAYER, "updateCalendarList");

   cl = qmonMirrorList(SGE_CAL_LIST);
   lPSortList(cl, "%I+", CAL_name);
   UpdateXmListFromCull(cal_names, XmFONTLIST_DEFAULT_TAG, cl, CAL_name);

   DEXIT;
}


/*-------------------------------------------------------------------------*/
static void qmonPopdownCalendarConfig(Widget w, XtPointer cld, XtPointer cad)
{
   DENTER(GUI_LAYER, "qmonPopdownCalendarConfig");

   XtUnmanageChild(qmon_cal);
   qmonStopTimer(CALENDAR_T);
   qmonTimerRmUpdateProc(CALENDAR_T, "updateCalendarList");

   DEXIT;
}

/*-------------------------------------------------------------------------*/
static void qmonCalendarFillConf(
Widget w,
lListElem *ep 
) {
   XmString *items;
   Cardinal itemCount; 
   const char *s;
   int i;
   dstring sb = DSTRING_INIT;

   DENTER(GUI_LAYER, "qmonCalendarFillConf");
   
   if (!ep) {
      /*
      ** clear the cal_conf_list
      */
      XtVaSetValues( cal_conf_list, 
                  XmNitems, NULL,
                  XmNitemCount, 0,
                  NULL);
      DEXIT;
      return;
   }
   
   itemCount = 2;
   items = (XmString*) XtMalloc(sizeof(XmString)*itemCount); 

   i = 0;

   /* year calendar */
   sge_dstring_sprintf(&sb, "%-20.20s ", XmtLocalize(w, "Year", "Year"));
   sge_dstring_append(&sb, (s=lGetString(ep, CAL_year_calendar))?s:
                              XmtLocalize(w, "NONE", "NONE"));
   items[i++] = XmStringCreateLtoR(sb.s, "LIST");
   sge_dstring_free(&sb);

   /* week calendar */
   sge_dstring_sprintf(&sb, "%-20.20s ", XmtLocalize(w, "Week", "Week"));
   sge_dstring_append(&sb, (s=lGetString(ep, CAL_week_calendar))?s:
                              XmtLocalize(w, "NONE", "NONE"));
   items[i++] = XmStringCreateLtoR((char*)sge_dstring_get_string(&sb), "LIST");
   sge_dstring_free(&sb);

   XtVaSetValues( cal_conf_list, 
                  XmNitems, items,
                  XmNitemCount, itemCount,
                  NULL);
   XmStringTableFree(items, itemCount);

   DEXIT;
}

/*-------------------------------------------------------------------------*/
static void qmonSelectCalendar(Widget w, XtPointer cld, XtPointer cad)
{
   XmListCallbackStruct *cbs = (XmListCallbackStruct*) cad;
   char *calname;
   lListElem *ep;
   
   DENTER(GUI_LAYER, "qmonSelectCalendar");

   if (! XmStringGetLtoR(cbs->item, XmFONTLIST_DEFAULT_TAG, &calname)) {
      fprintf(stderr, "XmStringGetLtoR failed\n");
      DEXIT;
      return;
   }

   ep = calendar_list_locate(qmonMirrorList(SGE_CAL_LIST), calname);

   XtFree((char*) calname);

   qmonCalendarFillConf(cal_conf_list, ep);
   
   DEXIT;
}


/*-------------------------------------------------------------------------*/
static Widget qmonCreateCalendarConfig(
Widget parent 
) {
   Widget cal_layout, cal_add, cal_delete, cal_modify, cal_done, cal_main_link;

   DENTER(GUI_LAYER, "qmonCreateCalendarConfig");
   
   cal_layout = XmtBuildQueryDialog( parent, "qmon_cal",
                           NULL, 0,
                           "cal_names", &cal_names,
                           "cal_conf_list", &cal_conf_list,
                           "cal_add", &cal_add,
                           "cal_delete", &cal_delete,
                           "cal_done", &cal_done,
                           "cal_modify", &cal_modify,
                           "cal_main_link", &cal_main_link,
                           NULL);

   XtAddCallback(cal_main_link, XmNactivateCallback, 
                     qmonMainControlRaise, NULL);
   XtAddCallback(cal_names, XmNbrowseSelectionCallback, 
                     qmonSelectCalendar, NULL);
   XtAddCallback(cal_done, XmNactivateCallback, 
                     qmonPopdownCalendarConfig, NULL);
   XtAddCallback(cal_add, XmNactivateCallback, 
                     qmonCalendarAdd, NULL); 
   XtAddCallback(cal_modify, XmNactivateCallback, 
                     qmonCalendarModify, NULL); 
   XtAddCallback(cal_delete, XmNactivateCallback, 
                     qmonCalendarDelete, NULL); 

   XtAddEventHandler(XtParent(cal_layout), StructureNotifyMask, False, 
                        SetMinShellSize, NULL);
   XtAddEventHandler(XtParent(cal_layout), StructureNotifyMask, False, 
                        SetMaxShellSize, NULL);

   DEXIT;
   return cal_layout;
}



/*-------------------------------------------------------------------------*/
static Widget qmonCreateCalendarAsk(
Widget parent 
) {
   Widget cal_ok, cal_cancel;

   DENTER(GUI_LAYER, "qmonCreateCalendarAsk");
   
   cal_ask_layout = XmtBuildQueryDialog( parent, "cal_ask_shell",
                           NULL, 0,
                           "cal_ok", &cal_ok,
                           "cal_cancel", &cal_cancel,
                           "cal_name", &cal_name_w,
                           "cal_year", &cal_year_w,
                           "cal_week", &cal_week_w,
                           NULL);

   XtAddCallback(cal_ok, XmNactivateCallback, 
                     qmonCalendarOk, NULL);
   XtAddCallback(cal_cancel, XmNactivateCallback, 
                     qmonCalendarCancel, NULL);

   XtAddEventHandler(XtParent(cal_ask_layout), StructureNotifyMask, False, 
                        SetMinShellSize, NULL);
   XtAddEventHandler(XtParent(cal_ask_layout), StructureNotifyMask, False, 
                        SetMaxShellSize, NULL);

   DEXIT;
   return cal_ask_layout;
}

/*-------------------------------------------------------------------------*/
static void qmonCalendarAdd(Widget w, XtPointer cld, XtPointer cad)
{
   DENTER(GUI_LAYER, "qmonCalendarAdd");

   qmonCalendarResetAsk();
   XtVaSetValues( cal_name_w,
                  XmNeditable, True,
                  NULL);
   add_mode = 1;
   XtManageChild(cal_ask_layout);

   DEXIT;
}

/*-------------------------------------------------------------------------*/
static void qmonCalendarModify(Widget w, XtPointer cld, XtPointer cad)
{
   XmString *calnames;
   Cardinal calnum;
   String calstr;
   lListElem *calp = NULL;

   DENTER(GUI_LAYER, "qmonCalendarModify");

   /*
   ** on opening the dialog fill in the old values
   */
   XtVaGetValues( cal_names,
                  XmNselectedItems, &calnames,
                  XmNselectedItemCount, &calnum,
                  NULL);
   if (calnum == 1 && 
         XmStringGetLtoR(calnames[0], XmFONTLIST_DEFAULT_TAG, &calstr)) {
      XmtInputFieldSetString(cal_name_w, calstr);
      XtVaSetValues( cal_name_w,
                     XmNeditable, False,
                     NULL);
      calp = calendar_list_locate(qmonMirrorList(SGE_CAL_LIST), calstr);
      XtFree((char*)calstr);
      if (calp) {
         add_mode = 0;
         qmonCalendarSetAsk(calp);
         XtManageChild(cal_ask_layout);
      }
   }

   DEXIT;
}



/*-------------------------------------------------------------------------*/
static void qmonCalendarOk(Widget w, XtPointer cld, XtPointer cad)
{
   lList *cal = NULL;
   lList *alp;
   lEnumeration *what;
   Boolean status = False;
   XmString xcalname = NULL;
   StringConst calname = NULL;

   DENTER(GUI_LAYER, "qmonCalendarOk");
   /*
   ** get the contents of the dialog fields here,
   ** build the cull list and send gdi request
   ** decalnding on success of gdi request close the dialog or stay ocaln
   */
   cal = lCreateElemList("CALENDAR_ADD", CAL_Type, 1);
   
   if (cal) {
      if (qmonCalendarGetAsk(lFirst(cal))) {
         calname = (StringConst)lGetString(lFirst(cal), CAL_name);
         /*
         ** gdi call 
         */
         what = lWhat("%T(ALL)", CAL_Type);
         
         if (add_mode) {
            alp = qmonAddList(SGE_CAL_LIST, 
                              qmonMirrorListRef(SGE_CAL_LIST),
                              CAL_name, &cal, NULL, what);
         }
         else {
            alp = qmonModList(SGE_CAL_LIST, 
                              qmonMirrorListRef(SGE_CAL_LIST),
                              CAL_name, &cal, NULL, what);
         }

         if (lFirst(alp) && lGetUlong(lFirst(alp), AN_status) == STATUS_OK)
            status = True;

         qmonMessageBox(w, alp, 0);

         if (status) {
            XtUnmanageChild(cal_ask_layout);
            updateCalendarList();
            /*
            ** select the modified or added Calendar
            */
            xcalname = XmtCreateXmString(calname);
            XmListSelectItem(cal_names, xcalname, True);
            XmStringFree(xcalname);
         }
         lFreeWhat(&what);
         lFreeList(&cal);
         lFreeList(&alp);
      }
   }


   DEXIT;
}



/*-------------------------------------------------------------------------*/
static void qmonCalendarCancel(Widget w, XtPointer cld, XtPointer cad)
{
   DENTER(GUI_LAYER, "qmonCalendarCancel");

   XtUnmanageChild(cal_ask_layout);

   DEXIT;
}

/*-------------------------------------------------------------------------*/
static void qmonCalendarDelete(Widget w, XtPointer cld, XtPointer cad)
{
   lList *lp = NULL;
   lList *alp = NULL;
   lEnumeration *what = NULL;
   Cardinal itemCount = 0;
   Boolean status, answer;

   DENTER(GUI_LAYER, "qmonCalendarDelete");
    
   lp = XmStringToCull(cal_names, CAL_Type, CAL_name, SELECTED_ITEMS); 

   if (lp) {
      status = XmtAskForBoolean(w, "xmtBooleanDialog", 
                     "@{calendar.askdel.Do you really want to delete the\nselected Calendar Configuration ?}",
                     "@{Delete}", "@{Cancel}", NULL, XmtNoButton, XmDIALOG_WARNING, 
                     False, &answer, NULL);
      if (answer) { 
         what = lWhat("%T(ALL)", CAL_Type);
         alp = qmonDelList(SGE_CAL_LIST, 
                           qmonMirrorListRef(SGE_CAL_LIST),
                                 CAL_name, &lp, NULL, what);

         qmonMessageBox(w, alp, 0);

         lFreeWhat(&what);
         lFreeList(&alp);

         updateCalendarList();
         XtVaGetValues( cal_names,
                        XmNitemCount, &itemCount,
                        NULL);
         if (itemCount) {
            XmListSelectPos(cal_names, 1, True);
         } else {
            qmonCalendarFillConf(cal_names, NULL);
         }   

      }
      lFreeList(&lp);
   }
   DEXIT;
}

/*-------------------------------------------------------------------------*/
static void qmonCalendarSetAsk(
lListElem *calp 
) {
   StringConst cal_name = NULL;
   StringConst year_calendar = NULL;
   StringConst week_calendar = NULL;

   DENTER(GUI_LAYER, "qmonCalendarSetAsk");

   if (!calp) {
      DEXIT;
      return;
   }

   cal_name = (StringConst)lGetString(calp, CAL_name);
   if (cal_name)
      XmtInputFieldSetString(cal_name_w, cal_name);

   year_calendar = (StringConst)lGetString(calp, CAL_year_calendar);
   if (year_calendar)
      XmtInputFieldSetString(cal_year_w, year_calendar);

   week_calendar = (StringConst)lGetString(calp, CAL_week_calendar);
   if (week_calendar)
      XmtInputFieldSetString(cal_week_w, week_calendar);

   DEXIT;
}

/*-------------------------------------------------------------------------*/
static void qmonCalendarResetAsk(void)
{

   DENTER(GUI_LAYER, "qmonCalendarResetAsk");

   XmtInputFieldSetString(cal_name_w, "");

   XmtInputFieldSetString(cal_year_w, "");

   XmtInputFieldSetString(cal_week_w, "");

   DEXIT;
}

/*-------------------------------------------------------------------------*/
static Boolean qmonCalendarGetAsk(
lListElem *calp 
) {
   String cal_name = NULL;
   String year_calendar = NULL;
   String week_calendar = NULL;

   DENTER(GUI_LAYER, "qmonCalendarGetAsk");

   if (!calp) {
      DEXIT;
      return False;
   }

   cal_name = XmtInputFieldGetString(cal_name_w);
   if (!cal_name || cal_name[0] == '\0') {
      qmonMessageShow(cal_ask_layout, True, "Calendar name required !");
      DEXIT;
      return False;
   }
   lSetString(calp, CAL_name, cal_name);
  
   year_calendar = XmtInputFieldGetString(cal_year_w);
   if (year_calendar && year_calendar[0] != '\0') {
      year_calendar = qmon_trim(year_calendar);
      lSetString(calp, CAL_year_calendar, year_calendar);
   } else {
      lSetString(calp, CAL_year_calendar, "NONE");
   }   

   week_calendar = XmtInputFieldGetString(cal_week_w);
   if (week_calendar && week_calendar[0] != '\0') {
      week_calendar = qmon_trim(week_calendar);
      lSetString(calp, CAL_week_calendar, week_calendar);
   } else {  
      lSetString(calp, CAL_week_calendar, "NONE");
   }

   DEXIT;
   return True;
}