dthelp: Change to ANSI function definitions
[oweals/cde.git] / cde / programs / dtmail / dtmail / AttachCmds.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 libraries 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  *+SNOTICE
25  *
26  *      $TOG: AttachCmds.C /main/8 1999/07/02 14:33:38 mgreess $
27  *
28  *      RESTRICTED CONFIDENTIAL INFORMATION:
29  *      
30  *      The information in this document is subject to special
31  *      restrictions in a confidential disclosure agreement between
32  *      HP, IBM, Sun, USL, SCO and Univel.  Do not distribute this
33  *      document outside HP, IBM, Sun, USL, SCO, or Univel without
34  *      Sun's specific written approval.  This document and all copies
35  *      and derivative works thereof must be returned or destroyed at
36  *      Sun's request.
37  *
38  *      Copyright 1993 Sun Microsystems, Inc.  All rights reserved.
39  *
40  *+ENOTICE
41  */
42
43 #include <Xm/Xm.h>
44 #include <Xm/FileSB.h>
45 #include <Xm/SelectioB.h>
46 #include <Xm/MessageB.h>
47 #include <fcntl.h>
48 #include <stdio.h>
49 #include <sys/stat.h>
50 #include <sys/types.h>
51 #include <sys/uio.h>
52 #include <unistd.h>
53 #include <stdlib.h>
54 #include <pwd.h>
55 #include "Application.h"
56 #include "AttachArea.h"
57 #include "Attachment.h"
58 #include "Icon.h"
59 #include "AttachCmds.h"
60 #include "InfoDialogManager.h"
61 #ifdef DEAD_WOOD
62 #include "QuestionDialogManager.h"
63 #endif /* DEAD_WOOD */
64 #include "RoamMenuWindow.h"
65 #include <DtMail/DtMailError.hh>
66 #include <DtMail/DtMail.hh>
67 #include "RoamApp.h"
68 #include "ViewMsgDialog.h"
69 #include "MailMsg.h"
70
71
72 extern "C" {
73 extern XtPointer _XmStringUngenerate (
74                                 XmString string,
75                                 XmStringTag tag,
76                                 XmTextType tag_type,
77                                 XmTextType output_type);
78 }
79
80 extern nl_catd  DtMailMsgCat;
81
82 static void okcb(XtPointer);
83
84 AttachAddCmd::AttachAddCmd ( AttachArea *attachArea, 
85                              Widget parent, 
86                              Widget clipWindow, 
87                              char *name, 
88                              char *label,
89                              int active ) : Cmd ( name, label, active )
90 {
91
92     _attachArea = attachArea;
93     _clipWindow = clipWindow;
94     _parent     = parent;
95
96 }
97
98 void AttachAddCmd::doit()
99 {
100     FSState fsstate;
101     Widget fsdialog;
102     char *home;
103     struct passwd *pwd;
104
105     fsdialog = _attachArea->getFsDialog();
106     if(fsdialog == NULL) {
107         fsdialog = XmCreateFileSelectionDialog(_parent, "fsdialog", NULL, 0);
108         XtUnmanageChild(
109                 XmFileSelectionBoxGetChild(fsdialog, XmDIALOG_HELP_BUTTON));
110         XtVaSetValues(XmFileSelectionBoxGetChild(fsdialog, XmDIALOG_LIST),
111             XmNselectionPolicy, XmBROWSE_SELECT,
112             NULL);
113         pwd = getpwuid(getuid());
114         home = pwd->pw_dir;
115         XtVaSetValues(fsdialog,
116             XtVaTypedArg, XmNdirectory, XtRString,
117             home, strlen(home)+1,
118             NULL);
119         _attachArea->setFsDialog(fsdialog);
120         XtAddCallback(fsdialog, XmNcancelCallback, 
121                           &AttachAddCmd::cancelCallback,
122                           (XtPointer) this );
123     }
124     fsstate = _attachArea->getFsState();
125     if(fsdialog) {
126         switch(fsstate) {
127         case ADD:       // Do nothing
128             break;
129         case SAVEAS:
130             // Remove callbacks
131             XtRemoveAllCallbacks(fsdialog, XmNokCallback);
132             // Fall Through
133         case NOTSET:
134             // Install callbacks
135             XtAddCallback(fsdialog, XmNokCallback, 
136                               &AttachAddCmd::okCallback,
137                               (XtPointer) this );
138             break;
139         }
140         XtVaSetValues(XtParent(fsdialog),
141                 XmNtitle, GETMSG(DT_catd, 14, 1, "Add Attachment"),
142                 NULL);
143         XtManageChild(fsdialog);
144     }
145     XtVaSetValues(fsdialog, 
146                     XmNfileTypeMask, XmFILE_REGULAR, 
147                     NULL);
148     _attachArea->setFsState(ADD);
149     _attachArea->activateDeactivate();
150     XRaiseWindow(XtDisplay(fsdialog), XtWindow(XtParent(fsdialog)) );
151 }      
152
153 void AttachAddCmd::undoit()
154 {
155     // Just print a message that allows us to trace the execution
156     
157 }       
158
159 void AttachAddCmd::okCallback ( Widget w, XtPointer clientData, XtPointer callData )
160 {
161     AttachAddCmd *obj = (AttachAddCmd *) clientData;
162
163     obj->ok( w, callData );
164     //XtUnmanageChild( w );
165 }
166
167 void AttachAddCmd::ok( Widget , XtPointer callData )
168 {
169     XmFileSelectionBoxCallbackStruct *cbs = 
170             (XmFileSelectionBoxCallbackStruct *)callData;
171     int count, i;
172     XmStringTable string_table;
173     char *filename;
174
175     XtVaGetValues(XmFileSelectionBoxGetChild(_attachArea->getFsDialog(),
176                         XmDIALOG_LIST),
177         XmNselectedItems, &string_table,
178         XmNselectedItemCount, &count,
179         NULL);
180
181     if(count == 0) {
182         filename = NULL;
183         filename = (char *) _XmStringUngenerate(
184                                         cbs->value, NULL,
185                                         XmMULTIBYTE_TEXT, XmMULTIBYTE_TEXT);
186         if (NULL == filename) return; // internal error
187         add_file(filename);
188     } else {
189         for(i=0;i<count;i++) {
190             filename = NULL;
191             filename = (char *) _XmStringUngenerate(
192                                         string_table[i], NULL,
193                                         XmMULTIBYTE_TEXT, XmMULTIBYTE_TEXT);
194             if (NULL == filename) return; // internal error
195             add_file(filename);
196         }
197     }
198
199 }
200
201 void AttachAddCmd::add_file( char *filename )
202 {
203     int fd;
204     struct stat s;
205 //    ExecState executable;
206     Boolean validtype = TRUE;
207     char *errormsg = new char[512];
208
209     if(stat(filename, &s) == -1) {
210         sprintf(errormsg, 
211                 GETMSG(DT_catd, 14, 2, "Unable to open %s"), 
212                 filename
213         );
214                 
215 //      theInfoDialogManager->post(
216 //                  errormsg,
217 //                  (void *)NULL,
218 //                  okcb);
219         delete [] errormsg;
220         return;
221     }
222
223     if(S_ISFIFO(s.st_mode)) {
224         sprintf(errormsg,
225                 GETMSG(DT_catd, 14, 3,
226                     "Cannot attach FIFO files: %s"), filename
227         );
228         validtype = FALSE;
229     } else if(S_ISCHR(s.st_mode)) {
230         sprintf(errormsg,
231                 GETMSG(DT_catd, 14, 4,
232                     "Cannot attach character special files: %s"), filename
233         );
234         validtype = FALSE;
235     } else if(S_ISDIR(s.st_mode)) {
236         sprintf(errormsg,
237                 GETMSG(DT_catd, 14, 5,
238                     "Cannot attach directories: %s"), filename
239         );
240         validtype = FALSE;
241     } else if(S_ISBLK(s.st_mode)) {
242         sprintf(errormsg,
243                 GETMSG(DT_catd, 14, 6,
244                     "Cannot attach block special files: %s"), filename
245         );
246         validtype = FALSE;
247     } else if(S_ISSOCK(s.st_mode)) {
248         sprintf(errormsg,
249                 GETMSG(DT_catd, 14, 7,
250                     "Cannot attach socket files: %s"), filename
251         );
252         validtype = FALSE;
253     }
254     if(validtype == FALSE) {
255 //      theInfoDialogManager->post(
256 //                  errormsg,
257 //                  (void *)NULL,
258 //                  okcb);
259         delete [] errormsg;
260         return;
261
262     }
263     fd = open(filename, O_RDONLY);
264     if(fd == -1) {
265         sprintf(errormsg, 
266                 GETMSG(DT_catd, 14, 8,
267                     "Unable to open %s"),filename
268         );
269
270 //      theInfoDialogManager->post(
271 //                  errormsg,
272 //                  (void *)NULL,
273 //                  okcb);
274         delete [] errormsg;
275         return;
276     } else {
277         
278         // We open and close this file just to make sure that we can
279         // The attachment constructor must have a valid, openable, file
280         close(fd);
281     }
282
283 //     Attachment *attachment = new Attachment(
284 //                                      _attachArea, 
285 //                                      filename);
286 // 
287 //     attachment->setAttachArea(_attachArea);
288 //     attachment->initialize();
289 //     _attachArea->calcSizeOfAA();
290 // 
291 //     // Call CalcAttachmentPosition() before adding the attachment
292 //     // to the list so that we can successfully find the last attachment
293 //     // in the list
294 //     _attachArea->CalcAttachmentPosition(attachment);
295 //     _attachArea->addToList( attachment );
296     XtFree(filename);
297     _attachArea->CalcLastRow();
298     _attachArea->AdjustCurrentRow();
299     _attachArea->SetScrollBarSize(_attachArea->getLastRow()+1);
300     _attachArea->DisplayAttachmentsInRow(_attachArea->getCurrentRow());
301     delete [] errormsg;
302 }
303
304 void AttachAddCmd::cancelCallback ( Widget, XtPointer clientData, XtPointer callData )
305 {
306     AttachAddCmd *obj = (AttachAddCmd *) clientData;
307
308     obj->cancel( callData );
309 }
310
311 void AttachAddCmd::cancel( XtPointer )
312 {
313     Widget fsdialog = _attachArea->getFsDialog();
314
315     XtUnmanageChild(fsdialog);
316 }
317
318 AttachFetchCmd::AttachFetchCmd ( AttachArea *attachArea, 
319                                  char *name, 
320                                  char *label,
321                                  int active ) : Cmd ( name, label, active )
322 {
323     _attachArea = attachArea;
324 }
325
326 void AttachFetchCmd::doit()
327 {
328 //    int i;
329 //  Attachment **list = _attachArea->getList();
330 //    String contents;
331 //    unsigned long size;
332 //    char error[1024];
333 //    Boolean compressed;
334
335 //    if(_attachArea->get_mailbox()->get_disconnected() == TRUE)
336 //      return;
337 //     for(i=0;i<_attachArea->getIconCount();i++) {
338 //      if(((list[i]->get_ac_state() == ROAM_AVAILABLE) ||
339 //          (list[i]->get_ac_state() == ROAM_CACHED)) &&
340 //         (list[i]->getIcon()->isSelected() == TRUE)) {
341 //          RoamMenuWindow *rmw = 
342 //                      (RoamMenuWindow*)_attachArea->owner()->owner();
343 // 
344 // //       contents = (char * ) _attachArea->get_mailbox()->get_data(
345 // //                               rmw->msgno(),
346 // //                               list[i]->getSection(),
347 // //                               &size,
348 // //                               &compressed);
349 // 
350 //          contents = NULL;
351 //          list[i]->set_compressed(compressed);
352 //          // If contents is NULL then we were unable to get the contents
353 //          if(contents == NULL) {
354 //              sprintf(error, 
355 //                      GETMSG(DT_catd, 14, 9,
356 //                          "File contents unavailable: %s"),
357 //                           list[i]->getLabel()
358 //              );
359 // //           theInfoDialogManager->post(
360 // //               error,
361 // //               (void *)NULL,
362 // //               (DialogCallback)okcb);
363 //              return;
364 //          }
365 //          list[i]->setContents(contents);
366 //          list[i]->setFilesize( size );
367 //          list[i]->set_ac_state(ROAM_LOCAL);
368 // //       if(list[i]->getRow() == _attachArea->getCurrentRow())
369 // //           list[i]->getIcon()->expose((XtPointer)NULL);
370 //      }
371 //     }
372 }      
373
374 void AttachFetchCmd::undoit()
375 {
376     // Just print a message that allows us to trace the execution
377
378 }       
379
380 AttachDeleteCmd::AttachDeleteCmd ( AttachArea *attachArea, 
381                                    char *name, 
382                                    char *label,
383                                    int active ) : Cmd ( name, label, active )
384 {
385     _attachArea = attachArea;
386 }
387
388 void AttachDeleteCmd::doit()
389 {
390 //    int i, j;
391     WidgetList deleteList;
392
393     deleteList = (WidgetList)XtMalloc(sizeof(Widget)*_attachArea->getIconCount());
394 //     Attachment **list = _attachArea->getList();
395 //     for(i=0, j=0;i<_attachArea->getIconCount();i++)
396 //      if(list[i]->getIcon()->isSelected() == TRUE) {
397 //          deleteList[j++] = list[i]->baseWidget();
398 //          list[i]->getIcon()->unselect();
399 //          _attachArea->incDeleteCount();
400 //          _attachArea->setAttachmentsLabel();
401 //          list[i]->deleteIt();
402 //      }
403 //     XtUnmanageChildren(deleteList, j);
404 //     XtFree((char *)deleteList);
405 //     _attachArea->activateDeactivate();
406 //     _attachArea->CalcAllAttachmentPositions();
407 //     _attachArea->CalcLastRow();
408 //     _attachArea->AdjustCurrentRow();
409 //     _attachArea->SetScrollBarSize(_attachArea->getLastRow()+1);
410 //     _attachArea->DisplayAttachmentsInRow(_attachArea->getCurrentRow());
411 }      
412
413 void AttachDeleteCmd::undoit()
414 {
415     // Just print a message that allows us to trace the execution
416     
417 }       
418
419 AttachOpenCmd::AttachOpenCmd ( AttachArea *attachArea, 
420                                char *name, 
421                                char *label,
422                                int active ) : Cmd ( name, label, active )
423 {
424     _attachArea = attachArea;
425 }
426
427 void AttachOpenCmd::doit()
428 {
429 //    int i;
430
431 //     Attachment **list = _attachArea->getList();
432 //     for(i=0;i<_attachArea->getIconCount();i++)
433 //      if(list[i]->getIcon()->isSelected() == TRUE) {
434 //          list[i]->executeOpenMethod();
435 //          // Break after finding a selected file
436 //          break;
437 // 
438 //      }
439     
440 }      
441
442 void AttachOpenCmd::undoit()
443 {
444     // Just print a message that allows us to trace the execution
445     
446 }       
447
448 AttachRenameCmd::AttachRenameCmd ( AttachArea *attachArea, 
449                                    Widget parent, 
450                                    char *name, 
451                                    char *label,
452                                    int active ) : Cmd ( name, label, active )
453 {
454     Widget renameDialog;
455     XmString message;
456
457     _attachArea = attachArea;
458     renameDialog = XmCreatePromptDialog(parent, "renameDialog", NULL, 0);
459     message = XmStringCreateLocalized(attachArea->getRenameMessageString());
460     XtVaSetValues(renameDialog, XmNselectionLabelString, message, NULL);
461     XmStringFree(message);
462     XtVaSetValues(XtParent(renameDialog),
463             XmNtitle, GETMSG(DT_catd, 14, 9, "Mailer - Rename Attachment"),
464             NULL);
465     XtUnmanageChild(
466         XmSelectionBoxGetChild(renameDialog, XmDIALOG_HELP_BUTTON)
467     );
468     _attachArea->setRenameDialog(renameDialog);
469     XtAddCallback(renameDialog, XmNcancelCallback, 
470                       &AttachRenameCmd::cancelCallback,
471                       (XtPointer) this );
472     XtAddCallback(renameDialog, XmNokCallback, 
473                       &AttachRenameCmd::okCallback,
474                       (XtPointer) this );
475 }
476
477 void AttachRenameCmd::doit()
478 {
479     Widget renameDialog;
480
481     renameDialog = _attachArea->getRenameDialog();
482     XtManageChild(renameDialog);
483     XtPopup(XtParent(renameDialog), XtGrabNone);
484 }      
485
486 void AttachRenameCmd::undoit()
487 {
488     // Just print a message that allows us to trace the execution
489     
490 }       
491
492 void AttachRenameCmd::cancelCallback ( Widget, XtPointer clientData, XtPointer callData )
493 {
494     AttachRenameCmd *obj = (AttachRenameCmd *) clientData;
495
496     obj->cancel( callData );
497 }
498
499 void AttachRenameCmd::cancel( XtPointer )
500 {
501     Widget renameDialog = _attachArea->getRenameDialog();
502
503     XtUnmanageChild(renameDialog);
504 }
505
506 void AttachRenameCmd::okCallback ( Widget, XtPointer clientData, XtPointer callData )
507 {
508     AttachRenameCmd *obj = (AttachRenameCmd *) clientData;
509
510     obj->ok( callData );
511 }
512
513 void AttachRenameCmd::ok( XtPointer callData )
514 {
515     XmSelectionBoxCallbackStruct *cbs = 
516             (XmSelectionBoxCallbackStruct *)callData;
517     String label = NULL;
518
519     if(_attachArea->getIconSelectedCount() != 1) {
520 //      theInfoDialogManager->post(
521 //                  GETMSG(DT_catd, 14, 12,
522 //      "Please select only one attachment to rename"),
523 //                  (void *)NULL,
524 //                  okcb);
525         return;
526     }
527 //     Attachment **list = _attachArea->getList();
528 //     for(i=0;i<_attachArea->getIconCount();i++)
529 //      if(list[i]->getIcon()->isSelected()) {
530 //          label = NULL;
531 //          label = (char *) _XmStringUngenerate(
532 //                                      cbs->value, NULL,
533 //                                      XmMULTIBYTE_TEXT, XmMULTIBYTE_TEXT);
534 //          if (NULL == label) return; // internal error
535 //          list[i]->setLabelAndCenter(label);
536 //      }
537 }
538
539 AttachDescriptionCmd::AttachDescriptionCmd ( AttachArea *attachArea, 
540                                              Widget parent, 
541                                              char *name, 
542                                              char *label,
543                                              int active ) 
544                         : Cmd ( name, label, active )
545 {
546     Widget descriptionDialog;
547     XmString message;
548
549     _attachArea = attachArea;
550     descriptionDialog = XmCreatePromptDialog(parent, "descriptionDialog", NULL, 0);
551     message = XmStringCreateLocalized(attachArea->getDescriptionMessageString());
552     XtVaSetValues(descriptionDialog, XmNselectionLabelString, message, NULL);
553     XmStringFree(message);
554     XtVaSetValues(XtParent(descriptionDialog),
555             XmNtitle, GETMSG(DT_catd, 14, 10, "Description"),
556             NULL);
557     XtUnmanageChild(XmSelectionBoxGetChild(descriptionDialog, XmDIALOG_HELP_BUTTON));
558     _attachArea->setDescriptionDialog(descriptionDialog);
559     XtAddCallback(descriptionDialog, XmNcancelCallback, 
560                       &AttachDescriptionCmd::cancelCallback,
561                       (XtPointer) this );
562     XtAddCallback(descriptionDialog, XmNokCallback, 
563                       &AttachDescriptionCmd::okCallback,
564                       (XtPointer) this );
565 }
566
567 void AttachDescriptionCmd::doit()
568 {
569 //     Attachment **list = _attachArea->getList();
570 //     Widget descriptionDialog;
571 //     Widget text;
572 //     int i;
573 // 
574 //     descriptionDialog = _attachArea->getDescriptionDialog();
575 //     text = XmSelectionBoxGetChild(descriptionDialog, XmDIALOG_TEXT);
576 //     for(i=0;i<_attachArea->getIconCount();i++) {
577 //      if(list[i]->getIcon()->isSelected()) {
578 //          XtVaSetValues(text,
579 //              XmNvalue, list[i]->get_description() ?
580 //                          list[i]->get_description() : "",
581 //              NULL);
582 //          break;
583 //      }
584 //     }
585 //    XtManageChild(descriptionDialog);
586 }      
587
588 void AttachDescriptionCmd::undoit()
589 {
590     // Just print a message that allows us to trace the execution
591     
592 }       
593
594 void AttachDescriptionCmd::cancelCallback ( Widget, XtPointer clientData, XtPointer callData )
595 {
596     AttachDescriptionCmd *obj = (AttachDescriptionCmd *) clientData;
597
598     obj->cancel( callData );
599 }
600
601 void AttachDescriptionCmd::cancel( XtPointer )
602 {
603     Widget descriptionDialog = _attachArea->getDescriptionDialog();
604
605     XtUnmanageChild(descriptionDialog);
606 }
607
608 void AttachDescriptionCmd::okCallback ( Widget, XtPointer clientData, XtPointer callData )
609 {
610     AttachDescriptionCmd *obj = (AttachDescriptionCmd *) clientData;
611
612     obj->ok( callData );
613 }
614
615 void AttachDescriptionCmd::ok( XtPointer callData )
616 {
617     XmSelectionBoxCallbackStruct *cbs = 
618             (XmSelectionBoxCallbackStruct *)callData;
619     String label = NULL;
620
621     if(_attachArea->getIconSelectedCount() != 1) {
622 //      theInfoDialogManager->post(
623 //                  GETMSG(DT_catd, 14, 12,
624 //                          "Please select only one attachment to describe"),
625 //                  (void *)NULL,
626 //                  okcb);
627         return;
628     }
629 //     Attachment **list = _attachArea->getList();
630 //     for(i=0;i<_attachArea->getIconCount();i++)
631 //      if(list[i]->getIcon()->isSelected()) {
632 //          label = NULL;
633 //          label = (char *) _XmStringUngenerate(
634 //                                      cbs->value, NULL,
635 //                                      XmMULTIBYTE_TEXT, XmMULTIBYTE_TEXT);
636 //          if (NULL == label) return; // internal error
637 //          list[i]->set_description(label);
638 //      }
639 }
640
641 AttachSaveAsCmd::AttachSaveAsCmd ( AttachArea *attachArea, 
642                                    Widget parent, 
643                                    Widget clipWindow, 
644                                    char *name, 
645                                    char *label,
646                                    int active ) : Cmd ( name, label, active )
647 {
648     _attachArea = attachArea;
649     _clipWindow = clipWindow;
650     _parent     = parent;
651 }
652
653 void AttachSaveAsCmd::doit()
654 {
655     FSState fsstate;
656     Widget fsdialog;
657     struct passwd *pwd;
658     char *home;
659     
660     fsdialog = _attachArea->getFsDialog();
661     if(fsdialog == NULL) {
662         fsdialog = XmCreateFileSelectionDialog(_parent, "fsdialog", NULL, 0);
663         XtUnmanageChild(
664                 XmFileSelectionBoxGetChild(fsdialog, XmDIALOG_HELP_BUTTON));
665         XtVaSetValues(XmFileSelectionBoxGetChild(fsdialog, XmDIALOG_LIST),
666             XmNselectionPolicy, XmBROWSE_SELECT,
667             NULL);
668         pwd = getpwuid(getuid());
669         home = pwd->pw_dir;
670         XtVaSetValues(fsdialog,
671             XtVaTypedArg, XmNdirectory, XtRString,
672             home, strlen(home)+1,
673             NULL);
674         _attachArea->setFsDialog(fsdialog);
675         XtAddCallback(fsdialog, XmNcancelCallback, 
676                           &AttachSaveAsCmd::cancelCallback,
677                           (XtPointer) this );
678     }
679     
680     fsstate = _attachArea->getFsState();
681     if(fsdialog) {
682         switch(fsstate) {
683         case SAVEAS:    // Do nothing
684             break;
685         case ADD:
686             // Remove callbacks
687             XtRemoveAllCallbacks(fsdialog, XmNokCallback);
688             // Fall Through
689         case NOTSET:
690             // Install callbacks
691             XtAddCallback(fsdialog, XmNokCallback, 
692                               &AttachSaveAsCmd::okCallback,
693                               (XtPointer) this );
694             break;
695         }
696         XtVaSetValues(XtParent(fsdialog),
697                 XmNtitle, GETMSG(DT_catd, 14, 11, "Save Attachment As"),
698                 NULL);
699         XtManageChild(fsdialog);
700     }
701     XtVaSetValues(fsdialog, 
702                     XmNfileTypeMask, XmFILE_DIRECTORY, 
703                     NULL);
704     _attachArea->setFsState(SAVEAS);
705     _attachArea->activateDeactivate();
706     XRaiseWindow( XtDisplay(fsdialog), XtWindow(XtParent(fsdialog)) );
707
708 }      
709
710 void AttachSaveAsCmd::undoit()
711 {
712     // Just print a message that allows us to trace the execution
713     
714 }       
715
716 void AttachSaveAsCmd::okCallback ( Widget w, XtPointer clientData, XtPointer callData )
717 {
718     AttachSaveAsCmd *obj = (AttachSaveAsCmd *) clientData;
719
720     obj->ok( callData );
721     XtUnmanageChild( w );
722 }
723
724 void ConfirmCallback( XtPointer)
725 {
726 //     Attachment *attachment = (Attachment *)clientData;
727 //     int fd;
728 //     char error[1024];
729 //     AttachArea *attachArea = attachment->parent();
730 //     String filecontents;
731 //     unsigned long size;
732 //     ssize_t retval;
733 //     Boolean compressed;
734 // 
735 //     RoamMenuWindow *rmw = (RoamMenuWindow *)attachArea->owner()->owner();
736 //     
737 //     switch(attachment->get_ac_state()) {
738 //     case ROAM_LOCAL:
739 //      break;
740 //     case ROAM_AVAILABLE:
741 //     case ROAM_CACHED:
742 // 
743 //      attachment->setContents(NULL);
744 // //                   (char *)
745 // //                   attachArea->get_mailbox()->get_data(
746 // //                   rmw->msgno(),
747 // //                   attachment->getSection(),
748 // //                   &size,
749 // //                   &compressed));
750 //      attachment->set_compressed(compressed);
751 //      attachment->setFilesize( size );
752 //      attachment->set_ac_state(ROAM_LOCAL);
753 // //   attachment->getIcon()->expose((XtPointer)NULL);
754 //      break;
755 //     case ROAM_UNAVAILABLE:
756 // //   theInfoDialogManager->post(
757 // //       GETMSG(DT_catd, 14, 15, "File Contents Unavailable"),
758 // //       (void *)NULL,
759 // //       (DialogCallback)okcb);
760 //          return;
761 //     }
762 //     (void)attachment->open_and_write(attachment->getSaveAsFilename());
763 }
764
765 void AttachSaveAsCmd::ok( XtPointer callData )
766 {
767     XmFileSelectionBoxCallbackStruct *cbs = 
768             (XmFileSelectionBoxCallbackStruct *)callData;
769     char *dirname = NULL;
770 //    struct stat s;
771 //     Attachment **list = _attachArea->getList();
772 //     char error[1024];
773 //     int i, fd;
774 //     SaveFileState sfs = OK;
775 //     char buf[1024];
776 //     String completefilename;
777 //     String filecontents;
778 //     unsigned long size;
779 //     ssize_t retval;
780 //     Boolean compressed;
781 // 
782 //      dirname = NULL;
783 //      dirname = (char *) _XmStringUngenerate(
784 //                                      cbs->value, NULL,
785 //                                      XmMULTIBYTE_TEXT, XmMULTIBYTE_TEXT);
786 //      if (NULL == dirname) return; // internal error
787 //     //
788 //     // If more than one attachment is selected then the selection
789 //     // specification must be a directory and must already exist.
790 //     //
791 //     //if(_attachArea->getIconSelectedCount() != 1) {
792 //      // This should not be able to happen
793 //      //printf("AttachSaveAsCmd::ok: getIconSelectedCount != 1. This can't happen\n");
794 //     //} else {
795 //     for(i=0;i<_attachArea->getIconCount();i++) {
796 //      if(list[i]->getIcon()->isSelected() == TRUE) {
797 //      //
798 //      // If a directory then keep the same file name and write to 
799 //      // that directory
800 //      //
801 //      // If it is a file that does not exist then we will try to
802 //      // create it (later)
803 //      //
804 //      // If the file already exists then we must prompt the user
805 //      // to see if he wants to overwrite the file.
806 //      //
807 //          if(stat(dirname, &s) != -1) {       // The file already exists
808 //              // This shouldn't happen because we make the fsdialog
809 //              // show directories only.  However, the user could enter
810 //              // the name of an existing file.
811 //              if(S_ISREG(s.st_mode)) {
812 //                  // If the user is trying to write multiple attachments
813 //                  // to a single existing file then we barf!
814 //                  if(_attachArea->getIconSelectedCount() != 1) {
815 //                      sprintf(error, 
816 //                              GETMSG(DT_catd, 14, 16, "Cannot create"));
817 //                      sfs = CONFIRM;
818 //                  } else {
819 //                      // The file already exists
820 //                      completefilename = dirname;
821 //                      sprintf(error, 
822 //                              GETMSG(DT_catd, 14, 17,
823 //                                  "File %s exists. Overwrite?"),
824 //                                          completefilename);
825 //                      sfs = CONFIRM;
826 //                  }
827 //              } else if(S_ISDIR(s.st_mode)) {
828 //                  sfs = OK;
829 //                  sprintf(buf, "%s%s", dirname, list[i]->getLabel());
830 //                  completefilename = buf;
831 //                  if(stat(buf, &s) != -1) {   // The file exists
832 //                      if(S_ISREG(s.st_mode)) {
833 //                          sprintf(error, 
834 //                              GETMSG(DT_catd, 14, 18,
835 //              "File %s exists. Overwrite?"), 
836 //                              completefilename);
837 //                          sfs = CONFIRM;
838 //                      } else {
839 //                          // We're trying to overwrite something other
840 //                          // than a regular file. FAIL!
841 //                          sprintf(error, 
842 //              GETMSG(14, 19, "Cannot create"));
843 //                          sfs = CONFIRM;
844 //                      }
845 //                  }
846 //              } else {
847 //                  // The file already exists but is not a regular file
848 //                  completefilename = dirname;
849 //                  sprintf(error,
850 //                          GETMSG(
851 //    DT_catd, 14, 20, "Cannot create %s"), completefilename);
852 //                  sfs = ERR;
853 //              }
854 //          } else {    // The file does not exist. Maybe the user entered
855 //                      // a new file name in an existing directory.
856 //              completefilename = dirname;
857 //          }
858 //          list[i]->setSaveAsFilename(strdup(completefilename));
859 //          switch(sfs) {
860 //          case ERR:
861 // //           theInfoDialogManager->post(
862 // //               error,
863 // //               (void *)NULL,
864 // //               (DialogCallback)okcb);
865 //              break;
866 //          case CONFIRM:
867 // //           theQuestionDialogManager->post(error,
868 // //                                          (XtPointer)list[i],
869 // //                                          ConfirmCallback,
870 // //                                          okcb     // Cancel button
871 // //                                          );
872 //              break;
873 //          case OK:
874 //              RoamMenuWindow *rmw = 
875 //                  (RoamMenuWindow*)_attachArea->owner()->owner();
876 // 
877 //              switch(list[i]->get_ac_state()) {
878 //              case ROAM_LOCAL:
879 //                  break;
880 //              case ROAM_CACHED:
881 //              case ROAM_AVAILABLE:
882 //                  list[i]->setContents(NULL);
883 // 
884 // //                   (char * )_attachArea->get_mailbox()->get_data(
885 // //                           rmw->msgno(),
886 // //                           list[i]->getSection(),
887 // //                           &size,
888 // //                           &compressed));
889 // 
890 //                  list[i]->set_compressed(compressed);
891 //                  list[i]->setFilesize( size );
892 //                  list[i]->set_ac_state(ROAM_LOCAL);
893 // //               list[i]->getIcon()->expose((XtPointer)NULL);
894 //                  break;
895 //              case ROAM_UNAVAILABLE:
896 // //               theInfoDialogManager->post(
897 // //                   GETMSG(DT_catd, 14. 21, "File Contents Unavailable"),
898 // //                   (void *)NULL, (DialogCallback)okcb);
899 //                      return;
900 //              }
901 //              (void)list[i]->open_and_write(completefilename);
902 //              break;
903 //          }
904 //      }
905 //     }
906 //     XtFree(dirname);
907 }
908
909 void AttachSaveAsCmd::cancelCallback ( Widget, XtPointer clientData, XtPointer callData )
910 {
911     AttachSaveAsCmd *obj = (AttachSaveAsCmd *) clientData;
912
913     obj->cancel( callData );
914 }
915
916 void AttachSaveAsCmd::cancel( XtPointer )
917 {
918     XtUnmanageChild(_attachArea->getFsDialog());
919 }
920
921 AttachSelectAllCmd::AttachSelectAllCmd ( AttachArea *attachArea, 
922                                          char *name, 
923                                          char *label,
924                                          int active ) 
925                                 : Cmd ( name, label, active )
926 {
927     _attachArea = attachArea;
928 }
929
930 void AttachSelectAllCmd::doit()
931 {
932 //    int i;
933 //    Boolean disconnected;
934
935 //    Attachment **list = _attachArea->getList();
936 // //    disconnected = _attachArea->get_mailbox()->get_disconnected();
937 //     for(i=0;i<_attachArea->getIconCount();i++) {
938 //      // Select the icon if and only if it is currently:
939 //      //     1) not selected, 2) not deleted, and 3) not disconnected
940 //      if(list[i]->getIcon()->isSelected() == FALSE &&
941 //                      list[i]->isDeleted() == FALSE && 
942 //                      list[i]->get_ac_state() != ROAM_UNAVAILABLE) {
943 //              list[i]->getIcon()->select();
944 //      }
945 //     }
946 }
947
948 void AttachSelectAllCmd::undoit()
949 {
950     // Just print a message that allows us to trace the execution
951     
952 }       
953
954 AttachUndeleteCmd::AttachUndeleteCmd ( AttachArea *attachArea, 
955                                        char *name, 
956                                        char *label,
957                                        int active ) 
958                         : Cmd ( name, label, active )
959 {
960     _attachArea = attachArea;
961 }
962
963 void AttachUndeleteCmd::doit()
964 {
965 //    int i;
966
967 //     Attachment **list = _attachArea->getList();
968 //     for(i=0;i<_attachArea->getIconCount();i++)
969 //      if(list[i]->isDeleted() == TRUE) {
970 //          list[i]->manage();
971 //          _attachArea->decDeleteCount();
972 //          _attachArea->setAttachmentsLabel();
973 //          list[i]->unDeleteIt();
974 //      }
975 // 
976 //     _attachArea->activateDeactivate();
977 //     _attachArea->CalcAllAttachmentPositions();
978 //     _attachArea->CalcLastRow();
979 //     _attachArea->AdjustCurrentRow();
980 //     _attachArea->SetScrollBarSize(_attachArea->getLastRow()+1);
981 //     _attachArea->DisplayAttachmentsInRow(_attachArea->getCurrentRow());
982 }      
983
984 void AttachUndeleteCmd::undoit()
985 {
986     // Just print a message that allows us to trace the execution
987     
988 }       
989
990 AttachUnselectAllCmd::AttachUnselectAllCmd ( AttachArea *attachArea, 
991                                              char *name, 
992                                              char *label,
993                                              int active ) 
994                         : Cmd ( name, label, active )
995 {
996     _attachArea = attachArea;
997 }
998
999 void AttachUnselectAllCmd::doit()
1000 {
1001 //    int i;
1002
1003 //     Attachment **list = _attachArea->getList();
1004 //     for(i=0;i<_attachArea->getIconCount();i++)
1005 //      if(list[i]->getIcon()->isSelected() == TRUE)
1006 //          list[i]->getIcon()->unselect();
1007 }      
1008
1009 void AttachUnselectAllCmd::undoit()
1010 {
1011     // Just print a message that allows us to trace the execution
1012     
1013 }       
1014
1015 AttachInfoCmd::AttachInfoCmd ( AttachArea *attachArea, 
1016                                char *name, 
1017                                char *label,
1018                                int active ) 
1019                         : Cmd ( name, label, active )
1020 {
1021     _attachArea = attachArea;
1022     _info_dialog = NULL;
1023     _attachInfoDialogManager = NULL;
1024 }
1025
1026 void AttachInfoCmd::doit()
1027 {
1028
1029     // Stubbed out. 
1030
1031 //     ViewAttachArea *vaa = (ViewAttachArea *)_attachArea;
1032 //     int i;
1033 // 
1034 //     Attachment **list = _attachArea->getList();
1035 //     for(i=0;i<_attachArea->getIconCount();i++)
1036 //      if(list[i]->getIcon()->isSelected() == TRUE) {
1037 //          vaa->show_info(list[i]);
1038 //          break;
1039 //      }
1040
1041 }
1042
1043 void AttachInfoCmd::undoit()
1044 {
1045     // Just print a message that allows us to trace the execution
1046     
1047 }       
1048
1049 AttachInfoCmd::~AttachInfoCmd()
1050 {
1051     if(_info_dialog)
1052         XtDestroyWidget(_info_dialog);
1053 }
1054
1055 static void okcb( XtPointer )
1056 {
1057     //Empty
1058     // This function exists so that the OK button will appear on the
1059     // Info Dialog. It doesn't have to do anything because the dialog
1060     // automatically pops down. It is for information only.
1061 }