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);
37 // Add some values to the drop down box for IM types.
39 cmbIMType->Append(wxT("AIM"));
40 cmbIMType->Append(wxT("Gadu-Gadu"));
41 cmbIMType->Append(wxT("ICQ"));
42 cmbIMType->Append(wxT("Skype"));
43 cmbIMType->Append(wxT("XMPP"));
44 cmbIMType->Append(wxT("Yahoo"));
45 cmbIMType->Append(_("Other"));
49 void frmContactEditorIM::ProcessAction( wxCommandEvent& event )
52 // Process the action.
56 // Check if IM type is empty and if it is then
57 // throw an error message.
59 wxString strIMTypeValue;
60 strIMTypeValue = cmbIMType->GetValue();
62 if (strIMTypeValue.IsEmpty()){
64 wxMessageDialog NopeDlg(this, _("IM Type is required."), _("Error"), wxOK|wxICON_ERROR, wxDefaultPosition);
70 if (txtUsername->IsEmpty()){
72 wxMessageDialog NopeDlg(this, _("Username/E-mail Address is required."), _("Error"), wxOK|wxICON_ERROR, wxDefaultPosition);
78 if (EditorMode == FALSE){
80 // Add the address to the list (maps).
82 wxString strIMAddress;
84 // Strip out the colons.
86 strIMAddress.Replace(wxT(":"), wxT(""), TRUE);
90 strIMTypeValue = cmbIMType->GetString(cmbIMType->GetSelection());
92 if (strIMTypeValue == wxT("AIM")){
94 strIMAddress.Append(wxT("aim"));
96 } else if (strIMTypeValue == wxT("Gadu-Gadu")){
98 strIMAddress.Append(wxT("gg"));
100 } else if (strIMTypeValue == wxT("ICQ")){
102 strIMAddress.Append(wxT("icq"));
104 } else if (strIMTypeValue == wxT("Skype")){
106 strIMAddress.Append(wxT("skype"));
108 } else if (strIMTypeValue == wxT("XMPP")){
110 strIMAddress.Append(wxT("xmpp"));
112 } else if (strIMTypeValue == wxT("Yahoo")){
114 strIMAddress.Append(wxT("yahoo"));
118 strIMAddress.Append(strIMTypeValue);
122 IMListTypeInfoPtr->insert(std::make_pair(IMListIndex, strIMAddress));
123 IMListPtr->insert(std::make_pair(IMListIndex, txtUsername->GetValue()));
127 if (EditSectionType == CE_GENERAL){
129 IMListTypePtr->insert(std::make_pair(IMListIndex, wxT("")));
131 } else if (EditSectionType == CE_HOME) {
133 IMListTypePtr->insert(std::make_pair(IMListIndex, wxT("home")));
135 } else if (EditSectionType == CE_WORK) {
137 IMListTypePtr->insert(std::make_pair(IMListIndex, wxT("work")));
143 if (priorityCtrl->IsPriorityChecked()){
145 IMListPrefPtr->insert(std::make_pair(IMListIndex, priorityCtrl->GetValue()));
149 IMListPrefPtr->insert(std::make_pair(IMListIndex, 0));
157 coldata.SetId(IMListIndex);
158 coldata.SetData(IMListIndex);
159 coldata.SetText(cmbIMType->GetValue());
160 ListCtrlIndex = IMListCtrlPtr->InsertItem(coldata);
162 IMListCtrlPtr->SetItem(ListCtrlIndex, 1, txtUsername->GetValue());
164 if (priorityCtrl->IsPriorityChecked()){
166 IMListCtrlPtr->SetItem(ListCtrlIndex, 2, wxString::Format(wxT("%i"), priorityCtrl->GetValue()));
172 } else if (EditorMode == TRUE){
174 // Edit the address in the list.
176 wxString strIMAddress;
177 long longSelected = -1;
181 strIMTypeValue = cmbIMType->GetString(cmbIMType->GetSelection());
183 if (strIMTypeValue == wxT("AIM")){
185 strIMAddress.Append(wxT("aim"));
187 } else if (strIMTypeValue == wxT("Gadu-Gadu")){
189 strIMAddress.Append(wxT("gg"));
191 } else if (strIMTypeValue == wxT("ICQ")){
193 strIMAddress.Append(wxT("icq"));
195 } else if (strIMTypeValue == wxT("Skype")){
197 strIMAddress.Append(wxT("skype"));
199 } else if (strIMTypeValue == wxT("XMPP")){
201 strIMAddress.Append(wxT("xmpp"));
203 } else if (strIMTypeValue == wxT("Yahoo")){
205 strIMAddress.Append(wxT("yahoo"));
209 strIMAddress.Append(strIMTypeValue);
213 IMListPtr->erase(IMListIndex);
214 IMListPtr->insert(std::make_pair(IMListIndex, txtUsername->GetValue()));
216 IMListTypeInfoPtr->erase(IMListIndex);
217 IMListTypeInfoPtr->insert(std::make_pair(IMListIndex, strIMAddress));
221 IMListPrefPtr->erase(IMListIndex);
223 if (priorityCtrl->IsPriorityChecked()){
225 IMListPrefPtr->insert(std::make_pair(IMListIndex, priorityCtrl->GetValue()));
229 IMListPrefPtr->insert(std::make_pair(IMListIndex, 0));
233 // Modify the data on the form.
235 longSelected = IMListCtrlPtr->GetNextItem(longSelected,
237 wxLIST_STATE_SELECTED);
239 if (longSelected == -1){
243 IMListCtrlPtr->SetItem(longSelected, 0, cmbIMType->GetValue());
244 IMListCtrlPtr->SetItem(longSelected, 1, txtUsername->GetValue());
246 if (priorityCtrl->IsPriorityChecked()){
248 IMListCtrlPtr->SetItem(longSelected, 2, wxString::Format(wxT("%i"), priorityCtrl->GetValue()));
252 IMListCtrlPtr->SetItem(longSelected, 2, wxT(""));
262 void frmContactEditorIM::CloseWindow( wxCommandEvent& event )
271 void frmContactEditorIM::SetEditorMode(bool EditMode, SectionType SectType)
274 // Set the editor mode.
276 // Set if the editor is adding or editing an address.
280 if (EditMode == FALSE){
283 btnAction->SetLabel(_("Add"));
284 this->SetTitle(_("Add IM"));
286 } else if (EditMode == TRUE){
289 btnAction->SetLabel(_("Modify"));
290 this->SetTitle(_("Modify IM"));
292 std::map<int,int>::iterator intiter;
293 std::map<int,wxString>::iterator striter;
298 // Setup the IM Type.
300 striter = IMListPtr->find(IMListIndex);
302 if (striter->first == IMListIndex){
304 strValue = striter->second;
308 if (IMListPtr->find(IMListIndex) != IMListPtr->end()){
310 strIMUser = IMListPtr->find(IMListIndex)->second;
314 if (IMListTypeInfoPtr->find(IMListIndex) != IMListTypeInfoPtr->end()){
316 strIMType = IMListTypeInfoPtr->find(IMListIndex)->second;
320 if (strIMType == wxT("aim")){
322 cmbIMType->SetValue(wxT("AIM"));
323 cmbIMType->SetSelection(0);
325 } else if (strIMType == wxT("gg")){
327 cmbIMType->SetValue(wxT("Gadu-Gadu"));
328 cmbIMType->SetSelection(1);
330 } else if (strIMType == wxT("icq")){
332 cmbIMType->SetValue(wxT("ICQ"));
333 cmbIMType->SetSelection(2);
335 } else if (strIMType == wxT("skype")){
337 cmbIMType->SetValue(wxT("Skype"));
338 cmbIMType->SetSelection(3);
340 } else if (strIMType == wxT("xmpp")){
342 cmbIMType->SetValue(wxT("XMPP"));
343 cmbIMType->SetSelection(4);
345 } else if (strIMType == wxT("yahoo")){
347 cmbIMType->SetValue(wxT("Yahoo"));
348 cmbIMType->SetSelection(5);
352 cmbIMType->SetValue(strIMType);
353 cmbIMType->SetSelection(6);
357 // Setup the username.
359 txtUsername->SetValue(strIMUser);
361 // Setup the priority.
363 intiter = IMListPrefPtr->find(IMListIndex);
365 if (intiter->first == IMListIndex && intiter->second > 0 &&
366 intiter != IMListPrefPtr->end()){
368 priorityCtrl->SetValue(intiter->second);
369 priorityCtrl->EnablePriority(true);
375 EditSectionType = SectType;
379 void frmContactEditorIM::SetupPointers( std::map<int, wxString> *IMList,
380 std::map<int, wxString> *IMListAltID,
381 std::map<int, wxString> *IMListPID,
382 std::map<int, wxString> *IMListType,
383 std::map<int, wxString> *IMListTypeInfo,
384 std::map<int, wxString> *IMListTokens,
385 std::map<int, wxString> *IMListMediatype,
386 std::map<int, int> *IMListPref,
387 wxListCtrl *IMListCtrl,
391 // Setup the pointers.
394 IMListAltIDPtr = IMListAltID;
395 IMListPIDPtr = IMListPID;
396 IMListTypePtr = IMListType;
397 IMListTypeInfoPtr = IMListTypeInfo;
398 IMListTokensPtr = IMListTokens;
399 IMListMediatypePtr = IMListMediatype;
400 IMListPrefPtr = IMListPref;
401 IMListCtrlPtr = IMListCtrl;
402 IMListIndex = IMIndex;