Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Unit Tests: Updated copyright year on modified files
[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         szrGeneral->Layout();
36         
37         // Add some values to the drop down box for IM types.
38         
39         cmbIMType->Append(wxT("AIM"));
40         cmbIMType->Append(wxT("Gadu-Gadu"));    
41         cmbIMType->Append(wxT("ICQ"));  
42         cmbIMType->Append(wxT("Skype"));
43         cmbIMType->Append(wxT("XMPP"));
44         cmbIMType->Append(wxT("Yahoo"));
45         cmbIMType->Append(_("Other"));
46         
47 }
49 void frmContactEditorIM::ProcessAction( wxCommandEvent& event )
50 {
52         // Process the action.
53         
54         long ListCtrlIndex;
55         
56         // Check if IM type is empty and if it is then
57         // throw an error message.
58                 
59         wxString strIMTypeValue;                
60         strIMTypeValue = cmbIMType->GetValue();         
61                 
62         if (strIMTypeValue.IsEmpty()){
63                 
64                 wxMessageDialog NopeDlg(this, _("IM Type is required."), _("Error"), wxOK|wxICON_ERROR, wxDefaultPosition);
65                 NopeDlg.ShowModal();
66                 return;
67                 
68         }
69                 
70         if (txtUsername->IsEmpty()){
71                 
72                 wxMessageDialog NopeDlg(this, _("Username/E-mail Address is required."), _("Error"), wxOK|wxICON_ERROR, wxDefaultPosition);
73                 NopeDlg.ShowModal();
74                 return;
75                 
76         }       
77         
78         if (EditorMode == FALSE){
79         
80                 // Add the address to the list (maps).
81                 
82                 wxString strIMAddress;
84                 // Strip out the colons.
85                 
86                 strIMAddress.Replace(wxT(":"), wxT(""), TRUE);
87                 
88                 // Specify the type.
89                 
90                 strIMTypeValue = cmbIMType->GetString(cmbIMType->GetSelection());
91                 
92                 if (strIMTypeValue == wxT("AIM")){
93                 
94                         strIMAddress.Append(wxT("aim"));
95                 
96                 } else if (strIMTypeValue == wxT("Gadu-Gadu")){
97                 
98                         strIMAddress.Append(wxT("gg"));
99                 
100                 } else if (strIMTypeValue == wxT("ICQ")){
101                 
102                         strIMAddress.Append(wxT("icq"));                        
103                 
104                 } else if (strIMTypeValue == wxT("Skype")){
105                 
106                         strIMAddress.Append(wxT("skype"));                      
107                 
108                 } else if (strIMTypeValue == wxT("XMPP")){
109                 
110                         strIMAddress.Append(wxT("xmpp"));                       
111                 
112                 } else if (strIMTypeValue == wxT("Yahoo")){
113                 
114                         strIMAddress.Append(wxT("yahoo"));                      
115                 
116                 } else {
117                 
118                         strIMAddress.Append(strIMTypeValue);
119                 
120                 }
121                 
122                 IMListTypeInfoPtr->insert(std::make_pair(IMListIndex, strIMAddress));
123                 IMListPtr->insert(std::make_pair(IMListIndex, txtUsername->GetValue()));
124                 
125                 // Set the type.
126                 
127                 if (EditSectionType == CE_GENERAL){
128                 
129                         IMListTypePtr->insert(std::make_pair(IMListIndex, wxT("")));
130                 
131                 } else if (EditSectionType == CE_HOME) {
132                 
133                         IMListTypePtr->insert(std::make_pair(IMListIndex, wxT("home")));
134                 
135                 } else if (EditSectionType == CE_WORK) {
136                 
137                         IMListTypePtr->insert(std::make_pair(IMListIndex, wxT("work")));
138                 
139                 }
140                 
141                 // Set the priority.
142                 
143                 if (priorityCtrl->IsPriorityChecked()){
144                 
145                         IMListPrefPtr->insert(std::make_pair(IMListIndex, priorityCtrl->GetValue()));
146                 
147                 } else {
148                 
149                         IMListPrefPtr->insert(std::make_pair(IMListIndex, 0));          
150                 
151                 }
152                 
153                 // Add to the form.
154                 
155                 wxListItem coldata;
156                 
157                 coldata.SetId(IMListIndex);
158                 coldata.SetData(IMListIndex);
159                 coldata.SetText(cmbIMType->GetValue());
160                 ListCtrlIndex = IMListCtrlPtr->InsertItem(coldata);
161                 
162                 IMListCtrlPtr->SetItem(ListCtrlIndex, 1, txtUsername->GetValue());
163                 
164                 if (priorityCtrl->IsPriorityChecked()){
165                 
166                         IMListCtrlPtr->SetItem(ListCtrlIndex, 2, wxString::Format(wxT("%i"), priorityCtrl->GetValue()));
167                 
168                 }
169                 
170                 this->Close();
171         
172         } else if (EditorMode == TRUE){
173         
174                 // Edit the address in the list.
175                 
176                 wxString strIMAddress;
177                 long longSelected = -1;
178                 
179                 // Specify the type.
180                 
181                 strIMTypeValue = cmbIMType->GetString(cmbIMType->GetSelection());
183                 if (strIMTypeValue == wxT("AIM")){
184                 
185                         strIMAddress.Append(wxT("aim"));
186                 
187                 } else if (strIMTypeValue == wxT("Gadu-Gadu")){
188                 
189                         strIMAddress.Append(wxT("gg"));
190                 
191                 } else if (strIMTypeValue == wxT("ICQ")){
192                 
193                         strIMAddress.Append(wxT("icq"));                        
194                 
195                 } else if (strIMTypeValue == wxT("Skype")){
196                 
197                         strIMAddress.Append(wxT("skype"));                      
198                 
199                 } else if (strIMTypeValue == wxT("XMPP")){
200                 
201                         strIMAddress.Append(wxT("xmpp"));                       
202                 
203                 } else if (strIMTypeValue == wxT("Yahoo")){
204                 
205                         strIMAddress.Append(wxT("yahoo"));                      
206                 
207                 } else {
208                 
209                         strIMAddress.Append(strIMTypeValue);
210                 
211                 }
213                 IMListPtr->erase(IMListIndex);
214                 IMListPtr->insert(std::make_pair(IMListIndex, txtUsername->GetValue()));
215                 
216                 IMListTypeInfoPtr->erase(IMListIndex);
217                 IMListTypeInfoPtr->insert(std::make_pair(IMListIndex, strIMAddress));
218                 
219                 // Set the priority.
220                 
221                 IMListPrefPtr->erase(IMListIndex);
222                 
223                 if (priorityCtrl->IsPriorityChecked()){
224                 
225                         IMListPrefPtr->insert(std::make_pair(IMListIndex, priorityCtrl->GetValue()));
226                 
227                 } else {
228                 
229                         IMListPrefPtr->insert(std::make_pair(IMListIndex, 0));          
230                 
231                 }
232                 
233                 // Modify the data on the form.
234                 
235                 longSelected = IMListCtrlPtr->GetNextItem(longSelected, 
236                         wxLIST_NEXT_ALL,
237                         wxLIST_STATE_SELECTED);
238                         
239                 if (longSelected == -1){
240                         return;
241                 }
242                 
243                 IMListCtrlPtr->SetItem(longSelected, 0, cmbIMType->GetValue());
244                 IMListCtrlPtr->SetItem(longSelected, 1, txtUsername->GetValue());
245                 
246                 if (priorityCtrl->IsPriorityChecked()){
247                 
248                         IMListCtrlPtr->SetItem(longSelected, 2, wxString::Format(wxT("%i"), priorityCtrl->GetValue()));
249                 
250                 } else {
251                 
252                         IMListCtrlPtr->SetItem(longSelected, 2, wxT(""));
253                 
254                 }
255                 
256                 this->Close();
257         
258         }
262 void frmContactEditorIM::CloseWindow( wxCommandEvent& event )
264         
265         // Close the window.
266         
267         this->Close();
268         
271 void frmContactEditorIM::SetEditorMode(bool EditMode, SectionType SectType)
273         
274         // Set the editor mode.
275         
276         // Set if the editor is adding or editing an address.
277         // FALSE = Add
278         // TRUE = Edit
279         
280         if (EditMode == FALSE){
281         
282                 EditorMode = FALSE;
283                 btnAction->SetLabel(_("Add"));
284                 this->SetTitle(_("Add IM"));
285         
286         } else if (EditMode == TRUE){
287         
288                 EditorMode = TRUE;
289                 btnAction->SetLabel(_("Modify"));
290                 this->SetTitle(_("Modify IM"));
291                 
292                 std::map<int,int>::iterator intiter;
293                 std::map<int,wxString>::iterator striter;
294                 wxString strValue;
295                 wxString strIMType;
296                 wxString strIMUser;
297                                 
298                 // Setup the IM Type.
299                 
300                 striter = IMListPtr->find(IMListIndex);
301                 
302                 if (striter->first == IMListIndex){
303                 
304                         strValue = striter->second;
305                 
306                 }
307                 
308                 if (IMListPtr->find(IMListIndex) != IMListPtr->end()){
309                   
310                         strIMUser = IMListPtr->find(IMListIndex)->second;
311                 
312                 }
313                 
314                 if (IMListTypeInfoPtr->find(IMListIndex) != IMListTypeInfoPtr->end()){
316                         strIMType = IMListTypeInfoPtr->find(IMListIndex)->second;
317                 
318                 }
319                 
320                 if (strIMType == wxT("aim")){
321                 
322                         cmbIMType->SetValue(wxT("AIM"));
323                         cmbIMType->SetSelection(0);
324                 
325                 } else if (strIMType == wxT("gg")){
326                 
327                         cmbIMType->SetValue(wxT("Gadu-Gadu"));
328                         cmbIMType->SetSelection(1);
329                 
330                 } else if (strIMType == wxT("icq")){
331                 
332                         cmbIMType->SetValue(wxT("ICQ"));                
333                         cmbIMType->SetSelection(2);
334                 
335                 } else if (strIMType == wxT("skype")){
336                 
337                         cmbIMType->SetValue(wxT("Skype"));
338                         cmbIMType->SetSelection(3);
339                 
340                 } else if (strIMType == wxT("xmpp")){
341                 
342                         cmbIMType->SetValue(wxT("XMPP"));
343                         cmbIMType->SetSelection(4);
344                 
345                 } else if (strIMType == wxT("yahoo")){
346                 
347                         cmbIMType->SetValue(wxT("Yahoo"));
348                         cmbIMType->SetSelection(5);
349                 
350                 } else {
351                 
352                         cmbIMType->SetValue(strIMType);
353                         cmbIMType->SetSelection(6);
354                 
355                 }
356                 
357                 // Setup the username.
358                 
359                 txtUsername->SetValue(strIMUser);
360                 
361                 // Setup the priority.
362                 
363                 intiter = IMListPrefPtr->find(IMListIndex);
364                 
365                 if (intiter->first == IMListIndex && intiter->second > 0 &&
366                         intiter != IMListPrefPtr->end()){
367                 
368                         priorityCtrl->SetValue(intiter->second);
369                         priorityCtrl->EnablePriority(true);
370                 
371                 }
372                 
373         }
374         
375         EditSectionType = SectType;     
376         
379 void frmContactEditorIM::SetupPointers( std::map<int, wxString> *IMList,
380         std::map<int, wxString> *IMListAltID,
381         std::map<int, wxString> *IMListPID,
382         std::map<int, wxString> *IMListType,
383         std::map<int, wxString> *IMListTypeInfo,
384         std::map<int, wxString> *IMListTokens,
385         std::map<int, wxString> *IMListMediatype,
386         std::map<int, int> *IMListPref,
387         wxListCtrl *IMListCtrl,
388         int IMIndex )
391         // Setup the pointers.
392         
393         IMListPtr = IMList;
394         IMListAltIDPtr = IMListAltID;
395         IMListPIDPtr = IMListPID;
396         IMListTypePtr = IMListType;
397         IMListTypeInfoPtr = IMListTypeInfo;
398         IMListTokensPtr = IMListTokens;
399         IMListMediatypePtr = IMListMediatype;
400         IMListPrefPtr = IMListPref;
401         IMListCtrlPtr = IMListCtrl;
402         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