Even more spelling fixed
[oweals/cde.git] / cde / programs / dtmail / dtmail / Undelete.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: Undelete.C /main/9 1998/09/24 17:33:53 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/Form.h>
44 #include <Xm/LabelG.h>
45 #include <Xm/RowColumn.h>
46 #include "Undelete.hh"
47 #include "MsgScrollingList.hh"
48 #include "RoamMenuWindow.h"
49 #ifdef DEAD_WOOD
50 #include "QueryDialogManager.hh"
51 #endif /* DEAD_WOOD */
52 #include "DialogShell.h"
53 #include "Application.h"
54 #include "ButtonInterface.h"
55 #include "RoamCmds.h"
56 #include "RoamApp.h"
57 #include "CmdList.h"
58 #include "MsgHndArray.hh"
59 #include "Help.hh"
60 #include "MemUtils.hh"
61 #include "MailMsg.h"
62 #include "DtMailGenDialog.hh"
63
64
65 UndelMsgScrollingList::UndelMsgScrollingList (RoamMenuWindow *rmw, Widget w,
66                                                 char *string)
67     : MsgScrollingList(rmw, w, string) 
68 {
69 }
70
71 UndelMsgScrollingList::~UndelMsgScrollingList()
72 {
73 }
74
75 void
76 UndelMsgScrollingList::extended_selection(DtMailEnv &, int)
77 {
78 }
79
80
81 void
82 UndelMsgScrollingList::deleteSelected(Boolean)
83 {
84     // SR - Added stuff below.  Made code more efficient also.
85     FORCE_SEGV_DECL(MsgStruct, a_del_msg_struct);
86     FORCE_SEGV_DECL(MsgStruct, tmpMS);
87     int  position_in_list, i;
88     FORCE_SEGV_DECL(int, position_list);
89     int position_count;
90     Boolean any_selected;
91     int num_msgs;
92  
93  
94
95     XtVaGetValues( _w,
96                    XmNitemCount, &num_msgs,
97                    NULL );
98  
99     any_selected = XmListGetSelectedPos(_w,
100                                         &position_list,
101                                         &position_count);
102  
103     if (!any_selected) return;
104  
105     for (i=0; i < position_count; i++ ) {
106         position_in_list = *(position_list + i);
107  
108         a_del_msg_struct = get_message_struct(position_in_list);
109         _msgs->mark_for_delete(position_in_list - 1);
110            
111     }
112  
113     _msgs->compact(0);
114  
115  
116     // Delete the items from the scrolling list
117      XmListDeletePositions(_w,
118                           position_list,
119                           position_count);
120  
121     // XnListGetSelectedPos allocated memory for the array and
122     // wants us to free it.  See documentation.
123  
124  
125     num_msgs = _msgs->length();
126     XtFree((char*) position_list);
127 }
128  
129 void
130 UndelMsgScrollingList::insertMsg(DtMailMessageHandle tmpMH)
131 {
132     MsgScrollingList::insertMsg(tmpMH);
133 }
134
135 void
136 UndelMsgScrollingList::insertMsg(
137     DtMailEnv &mail_error, 
138     MsgStruct *tmpMS
139 )
140 {
141     XmString item;
142
143     _msgs->append(tmpMS);
144
145     DtMailHeaderLine info;
146
147     DtMail::MailBox * mbox = this->parent()->mailbox();
148
149     mbox->getMessageSummary(mail_error,
150                             tmpMS->message_handle, 
151                             _header_info, 
152                             info);
153     DtMail::Message * msg = mbox->getMessage(mail_error, tmpMS->message_handle);
154
155
156     if (mail_error.isSet()) {
157         return;
158     }
159
160     item = formatHeader(info,
161                         tmpMS->sessionNumber,
162                         show_with_attachments(msg),
163                         msg->flagIsSet(mail_error, DtMailMessageNew));
164     XmListAddItem( _w , item, 0 );
165     XmStringFree( item );
166  
167     scroll_to_bottom();
168 }
169
170 void
171 UndelMsgScrollingList::loadMsgs(
172     DtMailEnv &mail_error, 
173     MsgHndArray *deleted_msgs,
174     int count
175 )
176 {
177     MsgStruct *tmpMS;
178     XmString *msg_hdrs;
179     int i;
180     DtMailHeaderLine info;
181     DtMail::Message * msg;
182
183
184     msg_hdrs = (XmString *)malloc(sizeof(XmString) * count);
185     memset(msg_hdrs, 0, sizeof(XmString) * count);    
186
187     DtMail::MailBox * mbox = this->parent()->mailbox();
188
189     for (i = 0; i < count; i ++) {
190         tmpMS = deleted_msgs->at(i);
191         _msgs->append(tmpMS);
192         
193         mbox->getMessageSummary(mail_error,
194                             tmpMS->message_handle, 
195                             _header_info, 
196                             info);
197
198         msg =  mbox->getMessage(mail_error, tmpMS->message_handle);
199
200         if (mail_error.isSet()) {
201             return;
202         }
203
204         msg_hdrs[i] = formatHeader(info,
205                                 tmpMS->sessionNumber,
206                                 show_with_attachments(msg),
207                                 msg->flagIsSet(mail_error, DtMailMessageNew));
208     }
209
210     XmListAddItems(_w, msg_hdrs, count, 0);
211
212     // Free the strings we added to the header array.
213     for (i = 0; i < count; i++) {
214         XmStringFree(msg_hdrs[i]);
215     }
216
217     free (msg_hdrs);
218
219     scroll_to_bottom();
220 }
221
222 void
223 UndelFromListDialog::loadMsgs(
224     DtMailEnv &mail_error, 
225     MsgHndArray *deleted_msgs,
226     int count
227 )
228 {
229     _list->loadMsgs(mail_error, deleted_msgs, count);
230 }
231
232 UndelFromListDialog::UndelFromListDialog ( 
233     char *name, 
234     RoamMenuWindow *parent
235 ) : DialogShell ( name, parent )
236 {
237     assert (theApplication != NULL);
238     _list = NULL;
239     _undelete_button = NULL;
240     _close_button = NULL;
241     _undel_list_button = NULL;
242     rowOfLabels = NULL;
243     rowOfButtons = NULL;
244     rowOfMessageStatus = NULL;
245     my_owner = NULL;
246 }
247
248 UndelFromListDialog::~UndelFromListDialog()
249 {
250 }
251
252 void
253 UndelFromListDialog::popped_down()
254 {
255     XtUnmapWidget(this->baseWidget());
256 }
257
258 void
259 UndelFromListDialog::popped_up()
260 {
261     if (_workArea)
262         XtMapWidget(this->baseWidget());
263 }
264
265 void
266 UndelFromListDialog::initialize()
267 {
268     DialogShell::initialize();
269 }
270
271 void
272 UndelFromListDialog::quit()
273 {
274     // Pop down the dialog
275     this->popped_down();
276 }
277
278 Widget
279 UndelFromListDialog::createWorkArea ( Widget parent )
280 {
281
282     XmString labelStr;
283     Widget l1, l2, l3, l4;
284     Widget form1;
285     XtWidgetGeometry size;
286
287     form1 = XmCreateForm(parent, "Work_Area",  NULL, 0);
288
289     // add help callback
290     printHelpId("form1", form1);
291
292     rowOfLabels = XtCreateManagedWidget ("rowOfLabels",
293                         xmFormWidgetClass, 
294                         form1,
295                         NULL, 0);
296
297
298     printHelpId("rowOfLabels", rowOfLabels);
299     // add help callback
300
301     size.request_mode = CWHeight;
302     XtQueryGeometry(rowOfLabels, NULL, &size);
303     XtVaSetValues(rowOfLabels,
304                 XmNpaneMaximum, size.height,
305                 XmNpaneMinimum, size.height,
306                 XmNrightAttachment, XmATTACH_FORM,
307                 XmNleftAttachment, XmATTACH_FORM,
308                 XmNtopAttachment, XmATTACH_FORM,
309                 XmNtopOffset, 5,
310                 XmNorientation, XmHORIZONTAL,
311                 XmNspacing, 120,
312                 XmNmarginWidth, 20,
313                 XmNentryAlignment, XmALIGNMENT_CENTER,
314                 NULL);
315
316     labelStr = XmStringCreateLocalized(GETMSG(DT_catd, 1, 14,
317            "Sender"));
318
319     l1 = XtVaCreateManagedWidget("Label1", xmLabelGadgetClass,
320                 rowOfLabels,
321                 XmNlabelString, labelStr,
322                 NULL);
323
324     XmStringFree(labelStr);
325     printHelpId("l1", l1);
326     /* add help callback */
327     // XtAddCallback(l1, XmNhelpCallback, HelpCB, helpId);
328
329
330     labelStr = XmStringCreateLocalized(GETMSG(DT_catd, 1, 15,
331            "Subject"));
332     l2 = XtVaCreateManagedWidget("Label2",
333                                 xmLabelGadgetClass, rowOfLabels,
334                                 XmNlabelString, labelStr,
335                                 NULL);
336
337
338
339     XmStringFree(labelStr);
340     printHelpId("l2", l2);
341     /* add help callback */
342     // XtAddCallback(l2, XmNhelpCallback, HelpCB, helpId);
343
344     labelStr = XmStringCreateLocalized(GETMSG(DT_catd, 1, 16,
345            "Date and Time"));
346     l3 = XtVaCreateManagedWidget("Label3",
347                         xmLabelGadgetClass, rowOfLabels,
348                         XmNlabelString, labelStr,
349                         NULL);
350
351     XmStringFree(labelStr);
352     printHelpId("l3", l3);
353     /* add help callback */
354     // XtAddCallback(l3, XmNhelpCallback, HelpCB, helpId);
355
356     labelStr = XmStringCreateLocalized(GETMSG(DT_catd, 1, 17,
357            "Size"));
358     l4 = XtVaCreateManagedWidget("Label4",
359                 xmLabelGadgetClass, rowOfLabels,
360                 XmNlabelString, labelStr,
361                 NULL);
362
363     XmStringFree(labelStr);
364     printHelpId("l4", l4);
365     /* add help callback */
366
367     _list = new UndelMsgScrollingList( this->parent(), form1, "Message_List");
368
369     DtMailEnv error;
370     DtMail::Session * d_session = theRoamApp.session()->session();
371     DtMail::MailRc * mailrc = d_session->mailRc(error);
372     const char * value;
373     int msgnums = False;
374
375     mailrc->getValue(error, "showmsgnum", &value);
376     if (error.isNotSet()) {
377         msgnums = True;
378     }
379     if (NULL != value)
380       free((void*) value);
381
382     // Adjust labels so the align on the columns
383     _list->layoutLabels(l1, l2, l3, l4);
384
385
386     rowOfButtons = XtCreateManagedWidget("RowColumn",
387                                         xmFormWidgetClass,
388                                         form1,
389                                         NULL, 0);
390     // add help callback
391     printHelpId ("rowOfButtons", rowOfButtons);
392
393     XtVaSetValues(XtParent(_list->get_scrolling_list()),
394                 XmNrightAttachment, XmATTACH_FORM,
395                 XmNleftAttachment, XmATTACH_FORM,
396                 XmNtopAttachment, XmATTACH_WIDGET,
397                 XmNtopWidget, rowOfLabels,
398                 XmNtopOffset, 3,
399                 XmNbottomAttachment, XmATTACH_WIDGET,
400                 XmNbottomWidget, rowOfButtons,
401                 XmNbottomOffset, 7,
402                 NULL);
403
404     XtVaSetValues(rowOfButtons,
405                 XmNorientation, XmHORIZONTAL,
406                 XmNpaneMaximum, size.height,
407                 XmNpaneMinimum, size.height,
408                 XmNrightAttachment, XmATTACH_FORM,
409                 XmNleftAttachment, XmATTACH_FORM,
410                 XmNbottomAttachment, XmATTACH_FORM,
411                 XmNfractionBase, 100,
412                 XmNresizable, FALSE,
413                 NULL);
414     
415     // Create undelete and close buttons.
416     this->addToRowOfButtons();
417
418
419
420     // Label should go here that says in how many days
421     // deleted messages will be destroyed, and for status.
422     rowOfMessageStatus = XtCreateManagedWidget("Message_Status",
423                                 xmFormWidgetClass,
424                                 form1, NULL, 0);
425     XtVaSetValues(rowOfMessageStatus,
426                 XmNrightAttachment, XmATTACH_FORM,
427                 XmNleftAttachment, XmATTACH_FORM,
428                 XmNtopAttachment, XmATTACH_FORM,
429                 XmNtopOffset, 5,
430                 NULL);
431
432
433     XtManageChild(_list->baseWidget());
434     XtManageChild(form1);
435
436     // return the widget
437     return(form1);
438 }
439     
440 void
441 UndelFromListDialog::insertMsg(DtMailEnv &mail_error, MsgStruct *tmpMS)
442 {
443     _list->insertMsg(mail_error, tmpMS);
444 }
445
446 void
447 UndelFromListDialog::undelLast()
448 {
449     int len;
450
451     len = _list->get_messages()->length();
452     _list->get_messages()->mark_for_delete(len - 1);
453     _list->get_messages()->compact(0);
454     XmListDeletePos(_list->get_scrolling_list(), len);
455
456 }
457
458
459 void
460 UndelFromListDialog::undelSelected()
461 {
462     FORCE_SEGV_DECL(int, position_list);
463     FORCE_SEGV_DECL(MsgHndArray, tmpMHlist);
464     int position_count;
465     Boolean any_selected = FALSE;
466
467     any_selected = XmListGetSelectedPos(_list->get_scrolling_list(),
468                                         &position_list,
469                                         &position_count);
470
471     // Don't do anything if there aren't any messages selected.
472
473     if ((!any_selected) || (position_count <= 0)) return;
474
475
476         // Put the selected messages from the Deleted Messages List
477         // into the RoamMenuWindow Message Scrolling List.
478
479
480         // This is kind of tricky, because we have to get the list of
481         // selected messages before we delete the selected messages,
482         // but we have to delete the selected messages before we
483         // pass them to undelete_messages().  The reason for this
484         // is that deleteSelected() changes the is_deleted attribute
485         // of the message handle to TRUE, which will undo undelete_messages()
486         // setting is_deleted to FALSE!  Did you follow all that?
487
488     tmpMHlist = _list->selected();
489
490         // Remove the selected messages from the Deleted Messages Dialog.
491     _list->deleteSelected();
492
493         // Add the messages to the RoamMenuWindow scrolling list.
494     MsgScrollingList *msl = parent()->list();
495     msl->undelete_messages(tmpMHlist);
496
497     XtFree((char*) position_list);
498
499 }
500
501 void
502 UndelFromListDialog::addToRowOfButtons()
503 {
504     FORCE_SEGV_DECL(CmdInterface, ci);
505     Widget w, prev_widget;
506
507     _undelete_button = new DoUndeleteCmd(
508                                 "Undelete", 
509                                 GETMSG(DT_catd, 1, 115, "Undelete"), 
510                                 TRUE, 
511                                 this);
512     ci = new ButtonInterface (rowOfButtons, _undelete_button);
513
514     w = ci->baseWidget();
515     XtVaSetValues(w,
516         XmNleftAttachment, XmATTACH_POSITION,
517         XmNleftPosition, 35,          // centralized tUndelete and Close buttons
518         XmNbottomAttachment, XmATTACH_FORM,
519         NULL );
520     ci->manage();
521     prev_widget = w;
522
523     _close_button = new CloseUndelCmd(
524                                 "Close",
525                                 GETMSG(DT_catd, 1, 116, "Close"), 
526                                 TRUE, 
527                                 this);
528     ci = new ButtonInterface (rowOfButtons, _close_button);
529     w = ci->baseWidget();
530     XtVaSetValues(w,
531         XmNleftAttachment, XmATTACH_WIDGET,
532         XmNleftWidget, prev_widget,
533         XmNleftOffset, 30,
534         XmNbottomAttachment, XmATTACH_FORM,
535         NULL );
536     ci->manage();
537
538 }
539
540 void
541 UndelFromListDialog::expunge(void)
542 {
543     for (int pos = 0; pos < _list->get_num_messages(); pos++) {
544         _list->get_messages()->mark_for_delete(pos);
545     }
546
547     _list->get_messages()->compact(0);
548
549     XmListDeleteAllItems(_list->get_scrolling_list());
550 }
551