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