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