1 // frmContactEditorIM.cpp - frmContactEditorIM form.
3 // (c) 2012-2015 Xestia Software Development.
5 // This file is part of Xestia Address Book.
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.
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.
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 )
27 frmContactEditorIMADT( parent )
33 priorityCtrl = new XABPriorityCtrl(tabGeneral);
34 szrGeneral->Add(priorityCtrl, 1, wxEXPAND, 5);
36 // Add some values to the drop down box for IM types.
38 cmbIMType->Append(wxT("AIM"));
39 cmbIMType->Append(wxT("Gadu-Gadu"));
40 cmbIMType->Append(wxT("ICQ"));
41 cmbIMType->Append(wxT("Skype"));
42 cmbIMType->Append(wxT("XMPP"));
43 cmbIMType->Append(wxT("Yahoo"));
44 cmbIMType->Append(_("Other"));
48 void frmContactEditorIM::ProcessAction( wxCommandEvent& event )
51 // Process the action.
55 // Check if IM type is empty and if it is then
56 // throw an error message.
58 wxString strIMTypeValue;
59 strIMTypeValue = cmbIMType->GetValue();
61 if (strIMTypeValue.IsEmpty()){
63 wxMessageDialog NopeDlg(this, _("IM Type is required."), _("Error"), wxOK|wxICON_ERROR, wxDefaultPosition);
69 if (txtUsername->IsEmpty()){
71 wxMessageDialog NopeDlg(this, _("Username/E-mail Address is required."), _("Error"), wxOK|wxICON_ERROR, wxDefaultPosition);
77 if (EditorMode == FALSE){
79 // Add the address to the list (maps).
81 wxString strIMAddress;
83 // Strip out the colons.
85 strIMAddress.Replace(wxT(":"), wxT(""), TRUE);
89 strIMTypeValue = cmbIMType->GetString(cmbIMType->GetSelection());
91 if (strIMTypeValue == wxT("AIM")){
93 strIMAddress.Append(wxT("aim"));
95 } else if (strIMTypeValue == wxT("Gadu-Gadu")){
97 strIMAddress.Append(wxT("gg"));
99 } else if (strIMTypeValue == wxT("ICQ")){
101 strIMAddress.Append(wxT("icq"));
103 } else if (strIMTypeValue == wxT("Skype")){
105 strIMAddress.Append(wxT("skype"));
107 } else if (strIMTypeValue == wxT("XMPP")){
109 strIMAddress.Append(wxT("xmpp"));
111 } else if (strIMTypeValue == wxT("Yahoo")){
113 strIMAddress.Append(wxT("yahoo"));
117 strIMAddress.Append(strIMTypeValue);
121 IMListTypeInfoPtr->insert(std::make_pair(IMListIndex, strIMAddress));
122 IMListPtr->insert(std::make_pair(IMListIndex, txtUsername->GetValue()));
126 if (EditSectionType == CE_GENERAL){
128 IMListTypePtr->insert(std::make_pair(IMListIndex, wxT("")));
130 } else if (EditSectionType == CE_HOME) {
132 IMListTypePtr->insert(std::make_pair(IMListIndex, wxT("home")));
134 } else if (EditSectionType == CE_WORK) {
136 IMListTypePtr->insert(std::make_pair(IMListIndex, wxT("work")));
142 if (priorityCtrl->IsPriorityChecked()){
144 IMListPrefPtr->insert(std::make_pair(IMListIndex, priorityCtrl->GetValue()));
148 IMListPrefPtr->insert(std::make_pair(IMListIndex, 0));
156 coldata.SetId(IMListIndex);
157 coldata.SetData(IMListIndex);
158 coldata.SetText(cmbIMType->GetValue());
159 ListCtrlIndex = IMListCtrlPtr->InsertItem(coldata);
161 IMListCtrlPtr->SetItem(ListCtrlIndex, 1, txtUsername->GetValue());
163 if (priorityCtrl->IsPriorityChecked()){
165 IMListCtrlPtr->SetItem(ListCtrlIndex, 2, wxString::Format(wxT("%i"), priorityCtrl->GetValue()));
171 } else if (EditorMode == TRUE){
173 // Edit the address in the list.
175 wxString strIMAddress;
176 long longSelected = -1;
180 strIMTypeValue = cmbIMType->GetString(cmbIMType->GetSelection());
182 if (strIMTypeValue == wxT("AIM")){
184 strIMAddress.Append(wxT("aim"));
186 } else if (strIMTypeValue == wxT("Gadu-Gadu")){
188 strIMAddress.Append(wxT("gg"));
190 } else if (strIMTypeValue == wxT("ICQ")){
192 strIMAddress.Append(wxT("icq"));
194 } else if (strIMTypeValue == wxT("Skype")){
196 strIMAddress.Append(wxT("skype"));
198 } else if (strIMTypeValue == wxT("XMPP")){
200 strIMAddress.Append(wxT("xmpp"));
202 } else if (strIMTypeValue == wxT("Yahoo")){
204 strIMAddress.Append(wxT("yahoo"));
208 strIMAddress.Append(strIMTypeValue);
212 IMListPtr->erase(IMListIndex);
213 IMListPtr->insert(std::make_pair(IMListIndex, txtUsername->GetValue()));
215 IMListTypeInfoPtr->erase(IMListIndex);
216 IMListTypeInfoPtr->insert(std::make_pair(IMListIndex, strIMAddress));
220 IMListPrefPtr->erase(IMListIndex);
222 if (priorityCtrl->IsPriorityChecked()){
224 IMListPrefPtr->insert(std::make_pair(IMListIndex, priorityCtrl->GetValue()));
228 IMListPrefPtr->insert(std::make_pair(IMListIndex, 0));
232 // Modify the data on the form.
234 longSelected = IMListCtrlPtr->GetNextItem(longSelected,
236 wxLIST_STATE_SELECTED);
238 if (longSelected == -1){
242 IMListCtrlPtr->SetItem(longSelected, 0, cmbIMType->GetValue());
243 IMListCtrlPtr->SetItem(longSelected, 1, txtUsername->GetValue());
245 if (priorityCtrl->IsPriorityChecked()){
247 IMListCtrlPtr->SetItem(longSelected, 2, wxString::Format(wxT("%i"), priorityCtrl->GetValue()));
251 IMListCtrlPtr->SetItem(longSelected, 2, wxT(""));
261 void frmContactEditorIM::CloseWindow( wxCommandEvent& event )
270 void frmContactEditorIM::SetEditorMode(bool EditMode, SectionType SectType)
273 // Set the editor mode.
275 // Set if the editor is adding or editing an address.
279 if (EditMode == FALSE){
282 btnAction->SetLabel(_("Add"));
283 this->SetTitle(_("Add IM"));
285 } else if (EditMode == TRUE){
288 btnAction->SetLabel(_("Modify"));
289 this->SetTitle(_("Modify IM"));
291 std::map<int,int>::iterator intiter;
292 std::map<int,wxString>::iterator striter;
297 // Setup the IM Type.
299 striter = IMListPtr->find(IMListIndex);
301 if (striter->first == IMListIndex){
303 strValue = striter->second;
307 if (IMListPtr->find(IMListIndex) != IMListPtr->end()){
309 strIMUser = IMListPtr->find(IMListIndex)->second;
313 if (IMListTypeInfoPtr->find(IMListIndex) != IMListTypeInfoPtr->end()){
315 strIMType = IMListTypeInfoPtr->find(IMListIndex)->second;
319 if (strIMType == wxT("aim")){
321 cmbIMType->SetValue(wxT("AIM"));
322 cmbIMType->SetSelection(0);
324 } else if (strIMType == wxT("gg")){
326 cmbIMType->SetValue(wxT("Gadu-Gadu"));
327 cmbIMType->SetSelection(1);
329 } else if (strIMType == wxT("icq")){
331 cmbIMType->SetValue(wxT("ICQ"));
332 cmbIMType->SetSelection(2);
334 } else if (strIMType == wxT("skype")){
336 cmbIMType->SetValue(wxT("Skype"));
337 cmbIMType->SetSelection(3);
339 } else if (strIMType == wxT("xmpp")){
341 cmbIMType->SetValue(wxT("XMPP"));
342 cmbIMType->SetSelection(4);
344 } else if (strIMType == wxT("yahoo")){
346 cmbIMType->SetValue(wxT("Yahoo"));
347 cmbIMType->SetSelection(5);
351 cmbIMType->SetValue(strIMType);
352 cmbIMType->SetSelection(6);
356 // Setup the username.
358 txtUsername->SetValue(strIMUser);
360 // Setup the priority.
362 intiter = IMListPrefPtr->find(IMListIndex);
364 if (intiter->first == IMListIndex && intiter->second > 0 &&
365 intiter != IMListPrefPtr->end()){
367 priorityCtrl->SetValue(intiter->second);
368 priorityCtrl->EnablePriority(true);
374 EditSectionType = SectType;
378 void frmContactEditorIM::SetupPointers( std::map<int, wxString> *IMList,
379 std::map<int, wxString> *IMListAltID,
380 std::map<int, wxString> *IMListPID,
381 std::map<int, wxString> *IMListType,
382 std::map<int, wxString> *IMListTypeInfo,
383 std::map<int, wxString> *IMListTokens,
384 std::map<int, wxString> *IMListMediatype,
385 std::map<int, int> *IMListPref,
386 wxListCtrl *IMListCtrl,
390 // Setup the pointers.
393 IMListAltIDPtr = IMListAltID;
394 IMListPIDPtr = IMListPID;
395 IMListTypePtr = IMListType;
396 IMListTypeInfoPtr = IMListTypeInfo;
397 IMListTokensPtr = IMListTokens;
398 IMListMediatypePtr = IMListMediatype;
399 IMListPrefPtr = IMListPref;
400 IMListCtrlPtr = IMListCtrl;
401 IMListIndex = IMIndex;