Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
frmContactEditorIM: Implemented priority control
[xestiaab/.git] / source / contacteditor / frmContactEditorIM.cpp
1 // frmContactEditorIM.cpp - frmContactEditorIM form.
2 //
3 // (c) 2012-2015 Xestia Software Development.
4 //
5 // This file is part of Xestia Address Book.
6 //
7 // Xestia Address Book is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by the
9 // Free Software Foundation, version 3 of the license.
10 //
11 // Xestia Address Book is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License along
17 // with Xestia Address Book. If not, see <http://www.gnu.org/licenses/>
19 #include "frmContactEditorIM.h"
20 #include <wx/msgdlg.h>
21 #include <wx/tokenzr.h>
23 #include "../common/textprocessing.h"
25 frmContactEditorIM::frmContactEditorIM( wxWindow* parent )
26 :
27 frmContactEditorIMADT( parent )
28 {
29         
30         // Setup the window.
31         
32         EditorMode = FALSE;
33         priorityCtrl = new XABPriorityCtrl(tabGeneral);
34         szrGeneral->Add(priorityCtrl, 1, wxEXPAND, 5);
35         
36         // Add some values to the drop down box for IM types.
37         
38         cmbIMType->Append(wxT("AIM"));
39         cmbIMType->Append(wxT("Gadu-Gadu"));    
40         cmbIMType->Append(wxT("ICQ"));  
41         cmbIMType->Append(wxT("Skype"));
42         cmbIMType->Append(wxT("XMPP"));
43         cmbIMType->Append(wxT("Yahoo"));
44         cmbIMType->Append(_("Other"));
45         
46 }
48 void frmContactEditorIM::ProcessAction( wxCommandEvent& event )
49 {
51         // Process the action.
52         
53         long ListCtrlIndex;
54         
55         // Check if IM type is empty and if it is then
56         // throw an error message.
57                 
58         wxString strIMTypeValue;                
59         strIMTypeValue = cmbIMType->GetValue();         
60                 
61         if (strIMTypeValue.IsEmpty()){
62                 
63                 wxMessageDialog NopeDlg(this, _("IM Type is required."), _("Error"), wxOK|wxICON_ERROR, wxDefaultPosition);
64                 NopeDlg.ShowModal();
65                 return;
66                 
67         }
68                 
69         if (txtUsername->IsEmpty()){
70                 
71                 wxMessageDialog NopeDlg(this, _("Username/E-mail Address is required."), _("Error"), wxOK|wxICON_ERROR, wxDefaultPosition);
72                 NopeDlg.ShowModal();
73                 return;
74                 
75         }       
76         
77         if (EditorMode == FALSE){
78         
79                 // Add the address to the list (maps).
80                 
81                 wxString strIMAddress;
83                 // Strip out the colons.
84                 
85                 strIMAddress.Replace(wxT(":"), wxT(""), TRUE);
86                 
87                 // Specify the type.
88                 
89                 strIMTypeValue = cmbIMType->GetString(cmbIMType->GetSelection());
90                 
91                 if (strIMTypeValue == wxT("AIM")){
92                 
93                         strIMAddress.Append(wxT("aim"));
94                 
95                 } else if (strIMTypeValue == wxT("Gadu-Gadu")){
96                 
97                         strIMAddress.Append(wxT("gg"));
98                 
99                 } else if (strIMTypeValue == wxT("ICQ")){
100                 
101                         strIMAddress.Append(wxT("icq"));                        
102                 
103                 } else if (strIMTypeValue == wxT("Skype")){
104                 
105                         strIMAddress.Append(wxT("skype"));                      
106                 
107                 } else if (strIMTypeValue == wxT("XMPP")){
108                 
109                         strIMAddress.Append(wxT("xmpp"));                       
110                 
111                 } else if (strIMTypeValue == wxT("Yahoo")){
112                 
113                         strIMAddress.Append(wxT("yahoo"));                      
114                 
115                 } else {
116                 
117                         strIMAddress.Append(strIMTypeValue);
118                 
119                 }
120                 
121                 IMListTypeInfoPtr->insert(std::make_pair(IMListIndex, strIMAddress));
122                 IMListPtr->insert(std::make_pair(IMListIndex, txtUsername->GetValue()));
123                 
124                 // Set the type.
125                 
126                 if (EditSectionType == CE_GENERAL){
127                 
128                         IMListTypePtr->insert(std::make_pair(IMListIndex, wxT("")));
129                 
130                 } else if (EditSectionType == CE_HOME) {
131                 
132                         IMListTypePtr->insert(std::make_pair(IMListIndex, wxT("home")));
133                 
134                 } else if (EditSectionType == CE_WORK) {
135                 
136                         IMListTypePtr->insert(std::make_pair(IMListIndex, wxT("work")));
137                 
138                 }
139                 
140                 // Set the priority.
141                 
142                 if (priorityCtrl->IsPriorityChecked()){
143                 
144                         IMListPrefPtr->insert(std::make_pair(IMListIndex, priorityCtrl->GetValue()));
145                 
146                 } else {
147                 
148                         IMListPrefPtr->insert(std::make_pair(IMListIndex, 0));          
149                 
150                 }
151                 
152                 // Add to the form.
153                 
154                 wxListItem coldata;
155                 
156                 coldata.SetId(IMListIndex);
157                 coldata.SetData(IMListIndex);
158                 coldata.SetText(cmbIMType->GetValue());
159                 ListCtrlIndex = IMListCtrlPtr->InsertItem(coldata);
160                 
161                 IMListCtrlPtr->SetItem(ListCtrlIndex, 1, txtUsername->GetValue());
162                 
163                 if (priorityCtrl->IsPriorityChecked()){
164                 
165                         IMListCtrlPtr->SetItem(ListCtrlIndex, 2, wxString::Format(wxT("%i"), priorityCtrl->GetValue()));
166                 
167                 }
168                 
169                 this->Close();
170         
171         } else if (EditorMode == TRUE){
172         
173                 // Edit the address in the list.
174                 
175                 wxString strIMAddress;
176                 long longSelected = -1;
177                 
178                 // Specify the type.
179                 
180                 strIMTypeValue = cmbIMType->GetString(cmbIMType->GetSelection());
182                 if (strIMTypeValue == wxT("AIM")){
183                 
184                         strIMAddress.Append(wxT("aim"));
185                 
186                 } else if (strIMTypeValue == wxT("Gadu-Gadu")){
187                 
188                         strIMAddress.Append(wxT("gg"));
189                 
190                 } else if (strIMTypeValue == wxT("ICQ")){
191                 
192                         strIMAddress.Append(wxT("icq"));                        
193                 
194                 } else if (strIMTypeValue == wxT("Skype")){
195                 
196                         strIMAddress.Append(wxT("skype"));                      
197                 
198                 } else if (strIMTypeValue == wxT("XMPP")){
199                 
200                         strIMAddress.Append(wxT("xmpp"));                       
201                 
202                 } else if (strIMTypeValue == wxT("Yahoo")){
203                 
204                         strIMAddress.Append(wxT("yahoo"));                      
205                 
206                 } else {
207                 
208                         strIMAddress.Append(strIMTypeValue);
209                 
210                 }
212                 IMListPtr->erase(IMListIndex);
213                 IMListPtr->insert(std::make_pair(IMListIndex, txtUsername->GetValue()));
214                 
215                 IMListTypeInfoPtr->erase(IMListIndex);
216                 IMListTypeInfoPtr->insert(std::make_pair(IMListIndex, strIMAddress));
217                 
218                 // Set the priority.
219                 
220                 IMListPrefPtr->erase(IMListIndex);
221                 
222                 if (priorityCtrl->IsPriorityChecked()){
223                 
224                         IMListPrefPtr->insert(std::make_pair(IMListIndex, priorityCtrl->GetValue()));
225                 
226                 } else {
227                 
228                         IMListPrefPtr->insert(std::make_pair(IMListIndex, 0));          
229                 
230                 }
231                 
232                 // Modify the data on the form.
233                 
234                 longSelected = IMListCtrlPtr->GetNextItem(longSelected, 
235                         wxLIST_NEXT_ALL,
236                         wxLIST_STATE_SELECTED);
237                         
238                 if (longSelected == -1){
239                         return;
240                 }
241                 
242                 IMListCtrlPtr->SetItem(longSelected, 0, cmbIMType->GetValue());
243                 IMListCtrlPtr->SetItem(longSelected, 1, txtUsername->GetValue());
244                 
245                 if (priorityCtrl->IsPriorityChecked()){
246                 
247                         IMListCtrlPtr->SetItem(longSelected, 2, wxString::Format(wxT("%i"), priorityCtrl->GetValue()));
248                 
249                 } else {
250                 
251                         IMListCtrlPtr->SetItem(longSelected, 2, wxT(""));
252                 
253                 }
254                 
255                 this->Close();
256         
257         }
261 void frmContactEditorIM::CloseWindow( wxCommandEvent& event )
263         
264         // Close the window.
265         
266         this->Close();
267         
270 void frmContactEditorIM::SetEditorMode(bool EditMode, SectionType SectType)
272         
273         // Set the editor mode.
274         
275         // Set if the editor is adding or editing an address.
276         // FALSE = Add
277         // TRUE = Edit
278         
279         if (EditMode == FALSE){
280         
281                 EditorMode = FALSE;
282                 btnAction->SetLabel(_("Add"));
283                 this->SetTitle(_("Add IM"));
284         
285         } else if (EditMode == TRUE){
286         
287                 EditorMode = TRUE;
288                 btnAction->SetLabel(_("Modify"));
289                 this->SetTitle(_("Modify IM"));
290                 
291                 std::map<int,int>::iterator intiter;
292                 std::map<int,wxString>::iterator striter;
293                 wxString strValue;
294                 wxString strIMType;
295                 wxString strIMUser;
296                                 
297                 // Setup the IM Type.
298                 
299                 striter = IMListPtr->find(IMListIndex);
300                 
301                 if (striter->first == IMListIndex){
302                 
303                         strValue = striter->second;
304                 
305                 }
306                 
307                 if (IMListPtr->find(IMListIndex) != IMListPtr->end()){
308                   
309                         strIMUser = IMListPtr->find(IMListIndex)->second;
310                 
311                 }
312                 
313                 if (IMListTypeInfoPtr->find(IMListIndex) != IMListTypeInfoPtr->end()){
315                         strIMType = IMListTypeInfoPtr->find(IMListIndex)->second;
316                 
317                 }
318                 
319                 if (strIMType == wxT("aim")){
320                 
321                         cmbIMType->SetValue(wxT("AIM"));
322                         cmbIMType->SetSelection(0);
323                 
324                 } else if (strIMType == wxT("gg")){
325                 
326                         cmbIMType->SetValue(wxT("Gadu-Gadu"));
327                         cmbIMType->SetSelection(1);
328                 
329                 } else if (strIMType == wxT("icq")){
330                 
331                         cmbIMType->SetValue(wxT("ICQ"));                
332                         cmbIMType->SetSelection(2);
333                 
334                 } else if (strIMType == wxT("skype")){
335                 
336                         cmbIMType->SetValue(wxT("Skype"));
337                         cmbIMType->SetSelection(3);
338                 
339                 } else if (strIMType == wxT("xmpp")){
340                 
341                         cmbIMType->SetValue(wxT("XMPP"));
342                         cmbIMType->SetSelection(4);
343                 
344                 } else if (strIMType == wxT("yahoo")){
345                 
346                         cmbIMType->SetValue(wxT("Yahoo"));
347                         cmbIMType->SetSelection(5);
348                 
349                 } else {
350                 
351                         cmbIMType->SetValue(strIMType);
352                         cmbIMType->SetSelection(6);
353                 
354                 }
355                 
356                 // Setup the username.
357                 
358                 txtUsername->SetValue(strIMUser);
359                 
360                 // Setup the priority.
361                 
362                 intiter = IMListPrefPtr->find(IMListIndex);
363                 
364                 if (intiter->first == IMListIndex && intiter->second > 0 &&
365                         intiter != IMListPrefPtr->end()){
366                 
367                         priorityCtrl->SetValue(intiter->second);
368                         priorityCtrl->EnablePriority(true);
369                 
370                 }
371                 
372         }
373         
374         EditSectionType = SectType;     
375         
378 void frmContactEditorIM::SetupPointers( std::map<int, wxString> *IMList,
379         std::map<int, wxString> *IMListAltID,
380         std::map<int, wxString> *IMListPID,
381         std::map<int, wxString> *IMListType,
382         std::map<int, wxString> *IMListTypeInfo,
383         std::map<int, wxString> *IMListTokens,
384         std::map<int, wxString> *IMListMediatype,
385         std::map<int, int> *IMListPref,
386         wxListCtrl *IMListCtrl,
387         int IMIndex )
390         // Setup the pointers.
391         
392         IMListPtr = IMList;
393         IMListAltIDPtr = IMListAltID;
394         IMListPIDPtr = IMListPID;
395         IMListTypePtr = IMListType;
396         IMListTypeInfoPtr = IMListTypeInfo;
397         IMListTokensPtr = IMListTokens;
398         IMListMediatypePtr = IMListMediatype;
399         IMListPrefPtr = IMListPref;
400         IMListCtrlPtr = IMListCtrl;
401         IMListIndex = IMIndex;
Xestia Software Development
Yn Maystri
© 2006 - 2019 Xestia Software Development
Software

Xestia Address Book
Xestia Calendar
Development

Xestia Gelforn
Everything else

About
News
Privacy Policy