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