1 #include "frmContactEditorIM.h"
3 #include <wx/tokenzr.h>
5 #include "../common/textprocessing.h"
7 frmContactEditorIM::frmContactEditorIM( wxWindow* parent )
9 frmContactEditorIMADT( parent )
12 sliPriority->Disable();
14 // Add some values to the drop down box for IM types.
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"));
25 void frmContactEditorIM::EnablePriority( wxCommandEvent& event )
27 if (chkUsePref->IsChecked()){
28 sliPriority->Enable();
30 sliPriority->Disable();
34 void frmContactEditorIM::ProcessAction( wxCommandEvent& event )
39 // Check if IM type is empty and if it is then
40 // throw an error message.
42 wxString strIMTypeValue;
43 strIMTypeValue = cmbIMType->GetValue();
45 if (strIMTypeValue.IsEmpty()){
47 wxMessageDialog NopeDlg(this, _("IM Type is required."), _("Error"), wxOK|wxICON_ERROR, wxDefaultPosition);
53 if (txtUsername->IsEmpty()){
55 wxMessageDialog NopeDlg(this, _("Username/E-mail Address is required."), _("Error"), wxOK|wxICON_ERROR, wxDefaultPosition);
61 if (EditorMode == FALSE){
63 // Add the address to the list (maps).
65 wxString strIMAddress;
68 // Strip out the colons.
70 strIMAddress.Replace(wxT(":"), wxT(""), TRUE);
74 strIMTypeValue = cmbIMType->GetString(cmbIMType->GetSelection());
76 if (strIMTypeValue == wxT("AIM")){
78 strIMAddress.Append(wxT("aim:"));
80 } else if (strIMTypeValue == wxT("Gadu-Gadu")){
82 strIMAddress.Append(wxT("gg:"));
84 } else if (strIMTypeValue == wxT("ICQ")){
86 strIMAddress.Append(wxT("icq:"));
88 } else if (strIMTypeValue == wxT("Skype")){
90 strIMAddress.Append(wxT("skype:"));
92 } else if (strIMTypeValue == wxT("XMPP")){
94 strIMAddress.Append(wxT("xmpp:"));
96 } else if (strIMTypeValue == wxT("Yahoo")){
98 strIMAddress.Append(wxT("yahoo:"));
102 strIMAddress.Append(strIMTypeValue + wxT(":"));
106 strIMAddress.Append(strValue);
107 strIMAddress.Append(txtUsername->GetValue());
109 IMListPtr->insert(std::make_pair(IMListIndex, strIMAddress));
113 if (EditSectionType == CE_GENERAL){
115 IMListTypePtr->insert(std::make_pair(IMListIndex, wxT("")));
117 } else if (EditSectionType == CE_HOME) {
119 IMListTypePtr->insert(std::make_pair(IMListIndex, wxT("home")));
121 } else if (EditSectionType == CE_WORK) {
123 IMListTypePtr->insert(std::make_pair(IMListIndex, wxT("work")));
129 if (chkUsePref->IsChecked()){
131 IMListPrefPtr->insert(std::make_pair(IMListIndex, sliPriority->GetValue()));
135 IMListPrefPtr->insert(std::make_pair(IMListIndex, 0));
143 coldata.SetId(IMListIndex);
144 coldata.SetData(IMListIndex);
145 coldata.SetText(cmbIMType->GetValue());
146 ListCtrlIndex = IMListCtrlPtr->InsertItem(coldata);
148 IMListCtrlPtr->SetItem(ListCtrlIndex, 1, txtUsername->GetValue());
150 if (chkUsePref->IsChecked()){
152 IMListCtrlPtr->SetItem(ListCtrlIndex, 2, wxString::Format(wxT("%i"), sliPriority->GetValue()));
158 } else if (EditorMode == TRUE){
160 // Edit the address in the list.
162 wxString strIMAddress;
164 long longSelected = -1;
166 // Strip out the colons.
168 strIMAddress.Replace(wxT(":"), wxT(""), TRUE);
172 strIMTypeValue = cmbIMType->GetString(cmbIMType->GetSelection());
174 if (strIMTypeValue == wxT("AIM")){
176 strIMAddress.Append(wxT("aim:"));
178 } else if (strIMTypeValue == wxT("Gadu-Gadu")){
180 strIMAddress.Append(wxT("gg:"));
182 } else if (strIMTypeValue == wxT("ICQ")){
184 strIMAddress.Append(wxT("icq:"));
186 } else if (strIMTypeValue == wxT("Skype")){
188 strIMAddress.Append(wxT("skype:"));
190 } else if (strIMTypeValue == wxT("XMPP")){
192 strIMAddress.Append(wxT("xmpp:"));
194 } else if (strIMTypeValue == wxT("Yahoo")){
196 strIMAddress.Append(wxT("yahoo:"));
200 strIMAddress.Append(strIMTypeValue + wxT(":"));
204 strIMAddress.Append(strValue);
205 strIMAddress.Append(txtUsername->GetValue());
207 IMListPtr->erase(IMListIndex);
208 IMListPtr->insert(std::make_pair(IMListIndex, strIMAddress));
212 IMListPrefPtr->erase(IMListIndex);
214 if (chkUsePref->IsChecked()){
216 IMListPrefPtr->insert(std::make_pair(IMListIndex, sliPriority->GetValue()));
220 IMListPrefPtr->insert(std::make_pair(IMListIndex, 0));
224 // Modify the data on the form.
226 longSelected = IMListCtrlPtr->GetNextItem(longSelected,
228 wxLIST_STATE_SELECTED);
230 if (longSelected == -1){
234 IMListCtrlPtr->SetItem(longSelected, 0, cmbIMType->GetValue());
235 IMListCtrlPtr->SetItem(longSelected, 1, txtUsername->GetValue());
237 if (chkUsePref->IsChecked()){
239 IMListCtrlPtr->SetItem(longSelected, 2, wxString::Format(wxT("%i"), sliPriority->GetValue()));
243 IMListCtrlPtr->SetItem(longSelected, 2, wxT(""));
253 void frmContactEditorIM::CloseWindow( wxCommandEvent& event )
258 void frmContactEditorIM::SetEditorMode(bool EditMode, SectionType SectType)
260 // Set if the editor is adding or editing an address.
264 if (EditMode == FALSE){
267 btnAction->SetLabel(_("Add"));
268 this->SetTitle(_("Add IM"));
270 } else if (EditMode == TRUE){
273 btnAction->SetLabel(_("Modify"));
274 this->SetTitle(_("Modify IM"));
276 std::map<int,int>::iterator intiter;
277 std::map<int,wxString>::iterator striter;
282 // Setup the IM Type.
284 striter = IMListPtr->find(IMListIndex);
286 if (striter->first == IMListIndex){
288 strValue = striter->second;
292 wxStringTokenizer IMAddressToken(strValue, wxT(":"));
293 strIMType = IMAddressToken.GetNextToken();
294 strIMUser = IMAddressToken.GetNextToken();
296 if (strIMType == wxT("aim")){
298 cmbIMType->SetValue(wxT("AIM"));
300 } else if (strIMType == wxT("gg")){
302 cmbIMType->SetValue(wxT("Gadu-Gadu"));
304 } else if (strIMType == wxT("icq")){
306 cmbIMType->SetValue(wxT("ICQ"));
308 } else if (strIMType == wxT("skype")){
310 cmbIMType->SetValue(wxT("Skype"));
312 } else if (strIMType == wxT("xmpp")){
314 cmbIMType->SetValue(wxT("XMPP"));
316 } else if (strIMType == wxT("yahoo")){
318 cmbIMType->SetValue(wxT("Yahoo"));
322 cmbIMType->SetValue(strIMType);
326 // Setup the username.
328 txtUsername->SetValue(strIMUser);
330 // Setup the priority.
332 intiter = IMListPrefPtr->find(IMListIndex);
334 if (intiter->first == IMListIndex && intiter->second > 0){
336 sliPriority->SetValue(intiter->second);
337 sliPriority->Enable();
338 chkUsePref->SetValue(TRUE);
344 EditSectionType = SectType;
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,
360 IMListAltIDPtr = IMListAltID;
361 IMListPIDPtr = IMListPID;
362 IMListTypePtr = IMListType;
363 IMListTokensPtr = IMListTokens;
364 IMListMediatypePtr = IMListMediatype;
365 IMListPrefPtr = IMListPref;
366 IMListCtrlPtr = IMListCtrl;
367 IMListIndex = IMIndex;