2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
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)
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
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
23 /* $TOG: IgnoreListUiItem.C /main/4 1997/09/03 17:38:42 mgreess $ */
27 * $TOG: IgnoreListUiItem.C /main/4 1997/09/03 17:38:42 mgreess $
29 * RESTRICTED CONFIDENTIAL INFORMATION:
31 * The information in this document is subject to special
32 * restrictions in a confidential disclosure agreement bertween
33 * HP, IBM, Sun, USL, SCO and Univel. Do not distribute this
34 * document outside HP, IBM, Sun, USL, SCO, or Univel wihtout
35 * Sun's specific written approval. This documment and all copies
36 * and derivative works thereof must be returned or destroyed at
39 * Copyright 1993 Sun Microsystems, Inc. All rights reserved.
46 #include <DtMail/options_util.h>
47 #include "options_ui.h"
48 #include <DtMail/PropUi.hh>
49 #include <DtMail/ListUiItem.hh>
50 #include <DtMail/IgnoreListUiItem.hh>
52 void handleIgnoreSelection(Widget w, XtPointer clientdata, XtPointer calldata);
53 extern Boolean props_changed;
55 // IgnoreListUiItem::IgnoreListUiItem
56 // IgnoreListUiItem ctor
57 ////////////////////////////////////////////////////////////////////
59 IgnoreListUiItem::IgnoreListUiItem(Widget w,
62 Widget text_entry_widget):ListUiItem(w, source, search_key, NULL)
64 source = source; search_key = search_key;
66 entry_field_widget = text_entry_widget;
73 XmNautomaticSelection, True,
74 XmNselectionPolicy, XmBROWSE_SELECT,
78 XmNbrowseSelectionCallback,
79 (XtCallbackProc)handleIgnoreSelection,
84 //---------------------------------------------------------------
85 void handleIgnoreSelection(Widget w, XtPointer, XtPointer calldata)
87 IgnoreListUiItem *item;
88 XmListCallbackStruct *list_info = (XmListCallbackStruct *)calldata;
89 char *selection_string = NULL;
90 DtVirtArray<PropStringPair *> *list_items;
96 list_items = item->getItemList();
98 if(list_items != NULL)
100 // motif index is 1 based
101 //virtarry is 0 based
102 PropStringPair *pair = (*list_items)[list_info->item_position - 1];
106 XtVaSetValues(item->getEntryFieldWidget(),
107 XmNvalue,pair->label,
115 // IgnoreListUiItem::writeFromUiToSource()
116 // Takes values in the UI and puts them into the source DB
117 ///////////////////////////////////////////////////////////////////
118 void IgnoreListUiItem::writeFromUiToSource()
120 Widget w = this->getWidget();
122 DtMail::Session * d_session = theRoamApp.session()->session();
123 DtMail::MailRc * mail_rc = d_session->mailRc(error);
126 if(deleted_items != NULL)
128 num_items = deleted_items->length();
130 for(i = 0; i < num_items; i++)
132 mail_rc->removeIgnore(error,(*deleted_items)[i]);
136 if(list_items != NULL)
138 num_items = list_items->length();
139 for(i = 0; i < num_items; i++)
141 mail_rc->addIgnore(error,(*list_items)[i]->label);
145 if(deleted_items != NULL)
147 delete deleted_items;
148 deleted_items = NULL;
152 // IgnoreListUiItem::writeFromSourceToUi()
153 // Takes values in the UI and puts them into the source DB
154 ///////////////////////////////////////////////////////////////////
155 void IgnoreListUiItem::writeFromSourceToUi()
158 DtMail::Session * d_session = theRoamApp.session()->session();
159 DtMail::MailRc * mail_rc = d_session->mailRc(error);
160 DtVirtArray<char *> *char_list = NULL;
162 PropStringPair *new_pair;
164 Widget w = this->getWidget();
166 XmListDeleteAllItems(w);
168 if(deleted_items != NULL)
170 delete deleted_items;
171 deleted_items = NULL;
174 if(list_items != NULL)
180 // ignore list code here...
181 char_list = mail_rc->getIgnoreList();
183 if(char_list != NULL)
185 list_len = char_list->length();
186 list_items = new DtVirtArray<PropStringPair *>(10);
188 for(i = 0; i < list_len; i++)
190 new_pair = new PropStringPair;
191 new_pair->label = strdup((*char_list)[i]);
192 new_pair->value = NULL;
194 list_items->append(new_pair);
198 options_list_init(w, char_list);
200 ///////////////////////////////////////////////////////////
201 void IgnoreListUiItem::handleAddButtonPress()
203 Widget entry_field = this->getEntryFieldWidget();
204 char *test_str = NULL;
205 PropStringPair *new_pair = NULL;
207 XtVaGetValues(entry_field,
212 if( (strlen(test_str) > 1) &&
213 (!XmListItemExists(this->getWidget(),
214 XmStringCreateLocalized(test_str))) )
216 new_pair = new PropStringPair;
217 int *pos_list, num_pos;
219 new_pair->label = strdup(test_str);
220 new_pair->value = NULL;
222 if(XmListGetSelectedPos(this->getWidget(),
226 if(list_items == NULL)
227 list_items = new DtVirtArray<PropStringPair *>(10);
229 list_items->insert(new_pair,pos_list[0] - 1);
230 XmListAddItem(this->getWidget(),
231 XmStringCreateLocalized(new_pair->label),
234 XmListSelectPos(this->getWidget(),
238 XmListSetPos(this->getWidget(),
243 if(list_items == NULL)
244 list_items = new DtVirtArray<PropStringPair *>(10);
246 list_items->insert(new_pair,0);
247 XmListAddItem(this->getWidget(),
248 XmStringCreateLocalized(new_pair->label),
250 XmListSelectPos(this->getWidget(),
254 XmListSetPos(this->getWidget(),
257 props_changed = TRUE;
260 ///////////////////////////////////////////////////////////
261 void IgnoreListUiItem::handleChangeButtonPress()
263 Widget entry_field = this->getEntryFieldWidget();
264 char *test_str = NULL;
265 PropStringPair *new_pair = NULL;
266 XmString replace_string;
267 int *pos_list, num_pos;
269 // if nothing selected nothing to change...
270 if(XmListGetSelectedPos(this->getWidget(),
274 XtVaGetValues(entry_field,
279 if(strlen(test_str) > 1)
282 new_pair = (*list_items)[pos_list[0] - 1];
284 if(deleted_items == NULL)
286 deleted_items = new DtVirtArray<char *>(10);
289 deleted_items->append(strdup((*list_items)[pos_list[0] -1]->label));
291 free(new_pair->label);
292 new_pair->label = strdup(test_str);
294 list_items->insert(new_pair,pos_list[0] - 1);
295 replace_string = XmStringCreateLocalized(new_pair->label);
297 XmListReplaceItemsPos(this->getWidget(),
302 XmListSelectPos(this->getWidget(),
306 props_changed = TRUE;
309 ///////////////////////////////////////////////////////////
310 void IgnoreListUiItem::handleDeleteButtonPress()
312 Widget list_widget = this->getWidget();
313 int *p_list, p_count;
315 // get the selected position
316 if(XmListGetSelectedPos(list_widget,
321 if(deleted_items == NULL)
323 deleted_items = new DtVirtArray<char *>(10);
326 deleted_items->append(strdup((*list_items)[p_list[0] -1]->label));
328 // delete the item from our list
329 this->list_items->remove(p_list[0] - 1); // remove only first
331 // delete the item from the widget
332 XmListDeletePos(list_widget, p_list[0]);
334 XtVaSetValues(this->getEntryFieldWidget(),
337 XmListSelectPos(list_widget,
340 props_changed = TRUE;
347 void IgnoreListUiItem::AddDefaults()
350 DtMail::Session * d_session = theRoamApp.session()->session();
351 DtMail::MailRc * mail_rc = d_session->mailRc(error);
352 DtVirtArray<char *> *char_list = NULL;
355 // ignore list code here...
356 char_list = mail_rc->getIgnoreList();
358 list_len = char_list->length();
361 XmTextFieldSetString(entry_field_widget,"Received");
362 handleAddButtonPress();
363 XmTextFieldSetString(entry_field_widget,"");
364 mail_rc->addIgnore(error,"Received");
365 mail_rc->update(error);