Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
98ef20d3cb807ad52c18d4d0a0124a35632c3fc1
[xestiaab/.git] / source / contacteditor / frmContactEditorIM.cpp
1 #include "frmContactEditorIM.h"
2 #include <wx/msgdlg.h>
3 #include <wx/tokenzr.h>
5 #include "../common/textprocessing.h"
7 frmContactEditorIM::frmContactEditorIM( wxWindow* parent )
8 :
9 frmContactEditorIMADT( parent )
10 {
11         EditorMode = FALSE;
12         sliPriority->Disable();
13         
14         // Add some values to the drop down box for IM types.
15         
16         cmbIMType->Append(wxT("AIM"));
17         cmbIMType->Append(wxT("Gadu-Gadu"));    
18         cmbIMType->Append(wxT("ICQ"));  
19         cmbIMType->Append(wxT("Skype"));
20         cmbIMType->Append(wxT("XMPP"));
21         cmbIMType->Append(wxT("Yahoo"));
22         
23 }
25 void frmContactEditorIM::EnablePriority( wxCommandEvent& event )
26 {
27         if (chkUsePref->IsChecked()){
28                 sliPriority->Enable();
29         } else {
30                 sliPriority->Disable();
31         }
32 }
34 void frmContactEditorIM::ProcessAction( wxCommandEvent& event )
35 {
37         long ListCtrlIndex;
38         
39         // Check if IM type is empty and if it is then
40         // throw an error message.
41                 
42         wxString strIMTypeValue;                
43         strIMTypeValue = cmbIMType->GetValue();         
44                 
45         if (strIMTypeValue.IsEmpty()){
46                 
47                 wxMessageDialog NopeDlg(this, _("IM Type is required."), _("Error"), wxOK|wxICON_ERROR, wxDefaultPosition);
48                 NopeDlg.ShowModal();
49                 return;
50                 
51         }
52                 
53         if (txtUsername->IsEmpty()){
54                 
55                 wxMessageDialog NopeDlg(this, _("Username/E-mail Address is required."), _("Error"), wxOK|wxICON_ERROR, wxDefaultPosition);
56                 NopeDlg.ShowModal();
57                 return;
58                 
59         }       
60         
61         if (EditorMode == FALSE){
62         
63                 // Add the address to the list (maps).
64                 
65                 wxString strIMAddress;
66                 wxString strValue;              
67                 
68                 // Strip out the colons.
69                 
70                 strIMAddress.Replace(wxT(":"), wxT(""), TRUE);
71                 
72                 // Specify the type.
73                 
74                 strIMTypeValue = cmbIMType->GetString(cmbIMType->GetSelection());
75                 
76                 if (strIMTypeValue == wxT("AIM")){
77                 
78                         strIMAddress.Append(wxT("aim:"));
79                 
80                 } else if (strIMTypeValue == wxT("Gadu-Gadu")){
81                 
82                         strIMAddress.Append(wxT("gg:"));
83                 
84                 } else if (strIMTypeValue == wxT("ICQ")){
85                 
86                         strIMAddress.Append(wxT("icq:"));                       
87                 
88                 } else if (strIMTypeValue == wxT("Skype")){
89                 
90                         strIMAddress.Append(wxT("skype:"));                     
91                 
92                 } else if (strIMTypeValue == wxT("XMPP")){
93                 
94                         strIMAddress.Append(wxT("xmpp:"));                      
95                 
96                 } else if (strIMTypeValue == wxT("Yahoo")){
97                 
98                         strIMAddress.Append(wxT("yahoo:"));                     
99                 
100                 } else {
101                 
102                         strIMAddress.Append(strIMTypeValue + wxT(":"));
103                 
104                 }
105                 
106                 strIMAddress.Append(strValue);
107                 strIMAddress.Append(txtUsername->GetValue());
108                 
109                 IMListPtr->insert(std::make_pair(IMListIndex, strIMAddress));
110                 
111                 // Set the type.
112                 
113                 if (EditSectionType == CE_GENERAL){
114                 
115                         IMListTypePtr->insert(std::make_pair(IMListIndex, wxT("")));
116                 
117                 } else if (EditSectionType == CE_HOME) {
118                 
119                         IMListTypePtr->insert(std::make_pair(IMListIndex, wxT("home")));
120                 
121                 } else if (EditSectionType == CE_WORK) {
122                 
123                         IMListTypePtr->insert(std::make_pair(IMListIndex, wxT("work")));
124                 
125                 }
126                 
127                 // Set the priority.
128                 
129                 if (chkUsePref->IsChecked()){
130                 
131                         IMListPrefPtr->insert(std::make_pair(IMListIndex, sliPriority->GetValue()));
132                 
133                 } else {
134                 
135                         IMListPrefPtr->insert(std::make_pair(IMListIndex, 0));          
136                 
137                 }
138                 
139                 // Add to the form.
140                 
141                 wxListItem coldata;
142                 
143                 coldata.SetId(IMListIndex);
144                 coldata.SetData(IMListIndex);
145                 coldata.SetText(cmbIMType->GetValue());
146                 ListCtrlIndex = IMListCtrlPtr->InsertItem(coldata);
147                 
148                 IMListCtrlPtr->SetItem(ListCtrlIndex, 1, txtUsername->GetValue());
149                 
150                 if (chkUsePref->IsChecked()){
151                 
152                         IMListCtrlPtr->SetItem(ListCtrlIndex, 2, wxString::Format(wxT("%i"), sliPriority->GetValue()));
153                 
154                 }
155                 
156                 this->Close();
157         
158         } else if (EditorMode == TRUE){
159         
160                 // Edit the address in the list.
161                 
162                 wxString strIMAddress;
163                 wxString strValue;
164                 long longSelected = -1;
165                 
166                 // Strip out the colons.
167                 
168                 strIMAddress.Replace(wxT(":"), wxT(""), TRUE);
169                 
170                 // Specify the type.
171                 
172                 strIMTypeValue = cmbIMType->GetString(cmbIMType->GetSelection());
173                 
174                 if (strIMTypeValue == wxT("AIM")){
175                 
176                         strIMAddress.Append(wxT("aim:"));
177                 
178                 } else if (strIMTypeValue == wxT("Gadu-Gadu")){
179                 
180                         strIMAddress.Append(wxT("gg:"));
181                 
182                 } else if (strIMTypeValue == wxT("ICQ")){
183                 
184                         strIMAddress.Append(wxT("icq:"));                       
185                 
186                 } else if (strIMTypeValue == wxT("Skype")){
187                 
188                         strIMAddress.Append(wxT("skype:"));                     
189                 
190                 } else if (strIMTypeValue == wxT("XMPP")){
191                 
192                         strIMAddress.Append(wxT("xmpp:"));                      
193                 
194                 } else if (strIMTypeValue == wxT("Yahoo")){
195                 
196                         strIMAddress.Append(wxT("yahoo:"));                     
197                 
198                 } else {
199                 
200                         strIMAddress.Append(strIMTypeValue + wxT(":"));
201                 
202                 }
203                 
204                 strIMAddress.Append(strValue);
205                 strIMAddress.Append(txtUsername->GetValue());
206                 
207                 IMListPtr->erase(IMListIndex);
208                 IMListPtr->insert(std::make_pair(IMListIndex, strIMAddress));
209                 
210                 // Set the priority.
211                 
212                 IMListPrefPtr->erase(IMListIndex);
213                 
214                 if (chkUsePref->IsChecked()){
215                 
216                         IMListPrefPtr->insert(std::make_pair(IMListIndex, sliPriority->GetValue()));
217                 
218                 } else {
219                 
220                         IMListPrefPtr->insert(std::make_pair(IMListIndex, 0));          
221                 
222                 }
223                 
224                 // Modify the data on the form.
225                 
226                 longSelected = IMListCtrlPtr->GetNextItem(longSelected, 
227                         wxLIST_NEXT_ALL,
228                         wxLIST_STATE_SELECTED);
229                         
230                 if (longSelected == -1){
231                         return;
232                 }
233                 
234                 IMListCtrlPtr->SetItem(longSelected, 0, cmbIMType->GetValue());
235                 IMListCtrlPtr->SetItem(longSelected, 1, txtUsername->GetValue());
236                 
237                 if (chkUsePref->IsChecked()){
238                 
239                         IMListCtrlPtr->SetItem(longSelected, 2, wxString::Format(wxT("%i"), sliPriority->GetValue()));
240                 
241                 } else {
242                 
243                         IMListCtrlPtr->SetItem(longSelected, 2, wxT(""));
244                 
245                 }
246                 
247                 this->Close();
248         
249         }
253 void frmContactEditorIM::CloseWindow( wxCommandEvent& event )
255         this->Close();
258 void frmContactEditorIM::SetEditorMode(bool EditMode, SectionType SectType)
260         // Set if the editor is adding or editing an address.
261         // FALSE = Add
262         // TRUE = Edit
263         
264         if (EditMode == FALSE){
265         
266                 EditorMode = FALSE;
267                 btnAction->SetLabel(_("Add"));
268                 this->SetTitle(_("Add IM"));
269         
270         } else if (EditMode == TRUE){
271         
272                 EditorMode = TRUE;
273                 btnAction->SetLabel(_("Modify"));
274                 this->SetTitle(_("Modify IM"));
275                 
276                 std::map<int,int>::iterator intiter;
277                 std::map<int,wxString>::iterator striter;
278                 wxString strValue;
279                 wxString strIMType;
280                 wxString strIMUser;
281                 
282                 // Setup the IM Type.           
283                 
284                 striter = IMListPtr->find(IMListIndex);
285                 
286                 if (striter->first == IMListIndex){
287                 
288                         strValue = striter->second;
289                 
290                 }               
291                 
292                 wxStringTokenizer IMAddressToken(strValue, wxT(":"));
293                 strIMType = IMAddressToken.GetNextToken();
294                 strIMUser = IMAddressToken.GetNextToken();
295                 
296                 if (strIMType == wxT("aim")){
297                 
298                         cmbIMType->SetValue(wxT("AIM"));
299                 
300                 } else if (strIMType == wxT("gg")){
301                 
302                         cmbIMType->SetValue(wxT("Gadu-Gadu"));
303                 
304                 } else if (strIMType == wxT("icq")){
305                 
306                         cmbIMType->SetValue(wxT("ICQ"));                
307                 
308                 } else if (strIMType == wxT("skype")){
309                 
310                         cmbIMType->SetValue(wxT("Skype"));
311                 
312                 } else if (strIMType == wxT("xmpp")){
313                 
314                         cmbIMType->SetValue(wxT("XMPP"));                       
315                 
316                 } else if (strIMType == wxT("yahoo")){
317                 
318                         cmbIMType->SetValue(wxT("Yahoo"));
319                 
320                 } else {
321                 
322                         cmbIMType->SetValue(strIMType);
323                 
324                 }
325                 
326                 // Setup the username.
327                 
328                 txtUsername->SetValue(strIMUser);
329                 
330                 // Setup the priority.
331                 
332                 intiter = IMListPrefPtr->find(IMListIndex);
333                 
334                 if (intiter->first == IMListIndex && intiter->second > 0){
335                 
336                         sliPriority->SetValue(intiter->second);
337                         sliPriority->Enable();
338                         chkUsePref->SetValue(TRUE);
339                 
340                 }
341                 
342         }
343         
344         EditSectionType = SectType;     
345         
348 void frmContactEditorIM::SetupPointers( std::map<int, wxString> *IMList,
349         std::map<int, wxString> *IMListAltID,
350         std::map<int, wxString> *IMListPID,
351         std::map<int, wxString> *IMListType,
352         std::map<int, wxString> *IMListTokens,
353         std::map<int, wxString> *IMListMediatype,
354         std::map<int, int> *IMListPref,
355         wxListCtrl *IMListCtrl,
356         int IMIndex )
359         IMListPtr = IMList;
360         IMListAltIDPtr = IMListAltID;
361         IMListPIDPtr = IMListPID;
362         IMListTypePtr = IMListType;
363         IMListTokensPtr = IMListTokens;
364         IMListMediatypePtr = IMListMediatype;
365         IMListPrefPtr = IMListPref;
366         IMListCtrlPtr = IMListCtrl;
367         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