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 sliPriority->Disable();
35 // Add some values to the drop down box for IM types.
37 cmbIMType->Append(wxT("AIM"));
38 cmbIMType->Append(wxT("Gadu-Gadu"));
39 cmbIMType->Append(wxT("ICQ"));
40 cmbIMType->Append(wxT("Skype"));
41 cmbIMType->Append(wxT("XMPP"));
42 cmbIMType->Append(wxT("Yahoo"));
43 cmbIMType->Append(_("Other"));
47 void frmContactEditorIM::EnablePriority( wxCommandEvent& event )
50 // Enable/disable the priority setting.
52 if (chkUsePref->IsChecked()){
53 sliPriority->Enable();
55 sliPriority->Disable();
60 void frmContactEditorIM::ProcessAction( wxCommandEvent& event )
63 // Process the action.
67 // Check if IM type is empty and if it is then
68 // throw an error message.
70 wxString strIMTypeValue;
71 strIMTypeValue = cmbIMType->GetValue();
73 if (strIMTypeValue.IsEmpty()){
75 wxMessageDialog NopeDlg(this, _("IM Type is required."), _("Error"), wxOK|wxICON_ERROR, wxDefaultPosition);
81 if (txtUsername->IsEmpty()){
83 wxMessageDialog NopeDlg(this, _("Username/E-mail Address is required."), _("Error"), wxOK|wxICON_ERROR, wxDefaultPosition);
89 if (EditorMode == FALSE){
91 // Add the address to the list (maps).
93 wxString strIMAddress;
95 // Strip out the colons.
97 strIMAddress.Replace(wxT(":"), wxT(""), TRUE);
101 strIMTypeValue = cmbIMType->GetString(cmbIMType->GetSelection());
103 if (strIMTypeValue == wxT("AIM")){
105 strIMAddress.Append(wxT("aim"));
107 } else if (strIMTypeValue == wxT("Gadu-Gadu")){
109 strIMAddress.Append(wxT("gg"));
111 } else if (strIMTypeValue == wxT("ICQ")){
113 strIMAddress.Append(wxT("icq"));
115 } else if (strIMTypeValue == wxT("Skype")){
117 strIMAddress.Append(wxT("skype"));
119 } else if (strIMTypeValue == wxT("XMPP")){
121 strIMAddress.Append(wxT("xmpp"));
123 } else if (strIMTypeValue == wxT("Yahoo")){
125 strIMAddress.Append(wxT("yahoo"));
129 strIMAddress.Append(strIMTypeValue);
133 IMListTypeInfoPtr->insert(std::make_pair(IMListIndex, strIMAddress));
134 IMListPtr->insert(std::make_pair(IMListIndex, txtUsername->GetValue()));
138 if (EditSectionType == CE_GENERAL){
140 IMListTypePtr->insert(std::make_pair(IMListIndex, wxT("")));
142 } else if (EditSectionType == CE_HOME) {
144 IMListTypePtr->insert(std::make_pair(IMListIndex, wxT("home")));
146 } else if (EditSectionType == CE_WORK) {
148 IMListTypePtr->insert(std::make_pair(IMListIndex, wxT("work")));
154 if (chkUsePref->IsChecked()){
156 IMListPrefPtr->insert(std::make_pair(IMListIndex, sliPriority->GetValue()));
160 IMListPrefPtr->insert(std::make_pair(IMListIndex, 0));
168 coldata.SetId(IMListIndex);
169 coldata.SetData(IMListIndex);
170 coldata.SetText(cmbIMType->GetValue());
171 ListCtrlIndex = IMListCtrlPtr->InsertItem(coldata);
173 IMListCtrlPtr->SetItem(ListCtrlIndex, 1, txtUsername->GetValue());
175 if (chkUsePref->IsChecked()){
177 IMListCtrlPtr->SetItem(ListCtrlIndex, 2, wxString::Format(wxT("%i"), sliPriority->GetValue()));
183 } else if (EditorMode == TRUE){
185 // Edit the address in the list.
187 wxString strIMAddress;
188 long longSelected = -1;
192 strIMTypeValue = cmbIMType->GetString(cmbIMType->GetSelection());
194 if (strIMTypeValue == wxT("AIM")){
196 strIMAddress.Append(wxT("aim"));
198 } else if (strIMTypeValue == wxT("Gadu-Gadu")){
200 strIMAddress.Append(wxT("gg"));
202 } else if (strIMTypeValue == wxT("ICQ")){
204 strIMAddress.Append(wxT("icq"));
206 } else if (strIMTypeValue == wxT("Skype")){
208 strIMAddress.Append(wxT("skype"));
210 } else if (strIMTypeValue == wxT("XMPP")){
212 strIMAddress.Append(wxT("xmpp"));
214 } else if (strIMTypeValue == wxT("Yahoo")){
216 strIMAddress.Append(wxT("yahoo"));
220 strIMAddress.Append(strIMTypeValue);
224 IMListPtr->erase(IMListIndex);
225 IMListPtr->insert(std::make_pair(IMListIndex, txtUsername->GetValue()));
227 IMListTypeInfoPtr->erase(IMListIndex);
228 IMListTypeInfoPtr->insert(std::make_pair(IMListIndex, strIMAddress));
232 IMListPrefPtr->erase(IMListIndex);
234 if (chkUsePref->IsChecked()){
236 IMListPrefPtr->insert(std::make_pair(IMListIndex, sliPriority->GetValue()));
240 IMListPrefPtr->insert(std::make_pair(IMListIndex, 0));
244 // Modify the data on the form.
246 longSelected = IMListCtrlPtr->GetNextItem(longSelected,
248 wxLIST_STATE_SELECTED);
250 if (longSelected == -1){
254 IMListCtrlPtr->SetItem(longSelected, 0, cmbIMType->GetValue());
255 IMListCtrlPtr->SetItem(longSelected, 1, txtUsername->GetValue());
257 if (chkUsePref->IsChecked()){
259 IMListCtrlPtr->SetItem(longSelected, 2, wxString::Format(wxT("%i"), sliPriority->GetValue()));
263 IMListCtrlPtr->SetItem(longSelected, 2, wxT(""));
273 void frmContactEditorIM::CloseWindow( wxCommandEvent& event )
282 void frmContactEditorIM::SetEditorMode(bool EditMode, SectionType SectType)
285 // Set the editor mode.
287 // Set if the editor is adding or editing an address.
291 if (EditMode == FALSE){
294 btnAction->SetLabel(_("Add"));
295 this->SetTitle(_("Add IM"));
297 } else if (EditMode == TRUE){
300 btnAction->SetLabel(_("Modify"));
301 this->SetTitle(_("Modify IM"));
303 std::map<int,int>::iterator intiter;
304 std::map<int,wxString>::iterator striter;
309 // Setup the IM Type.
311 striter = IMListPtr->find(IMListIndex);
313 if (striter->first == IMListIndex){
315 strValue = striter->second;
319 if (IMListPtr->find(IMListIndex) != IMListPtr->end()){
321 strIMUser = IMListPtr->find(IMListIndex)->second;
325 if (IMListTypeInfoPtr->find(IMListIndex) != IMListTypeInfoPtr->end()){
327 strIMType = IMListTypeInfoPtr->find(IMListIndex)->second;
331 if (strIMType == wxT("aim")){
333 cmbIMType->SetValue(wxT("AIM"));
334 cmbIMType->SetSelection(0);
336 } else if (strIMType == wxT("gg")){
338 cmbIMType->SetValue(wxT("Gadu-Gadu"));
339 cmbIMType->SetSelection(1);
341 } else if (strIMType == wxT("icq")){
343 cmbIMType->SetValue(wxT("ICQ"));
344 cmbIMType->SetSelection(2);
346 } else if (strIMType == wxT("skype")){
348 cmbIMType->SetValue(wxT("Skype"));
349 cmbIMType->SetSelection(3);
351 } else if (strIMType == wxT("xmpp")){
353 cmbIMType->SetValue(wxT("XMPP"));
354 cmbIMType->SetSelection(4);
356 } else if (strIMType == wxT("yahoo")){
358 cmbIMType->SetValue(wxT("Yahoo"));
359 cmbIMType->SetSelection(5);
363 cmbIMType->SetValue(strIMType);
364 cmbIMType->SetSelection(6);
368 // Setup the username.
370 txtUsername->SetValue(strIMUser);
372 // Setup the priority.
374 intiter = IMListPrefPtr->find(IMListIndex);
376 if (intiter->first == IMListIndex && intiter->second > 0 &&
377 intiter != IMListPrefPtr->end()){
379 sliPriority->SetValue(intiter->second);
380 sliPriority->Enable();
381 chkUsePref->SetValue(TRUE);
387 EditSectionType = SectType;
391 void frmContactEditorIM::SetupPointers( std::map<int, wxString> *IMList,
392 std::map<int, wxString> *IMListAltID,
393 std::map<int, wxString> *IMListPID,
394 std::map<int, wxString> *IMListType,
395 std::map<int, wxString> *IMListTypeInfo,
396 std::map<int, wxString> *IMListTokens,
397 std::map<int, wxString> *IMListMediatype,
398 std::map<int, int> *IMListPref,
399 wxListCtrl *IMListCtrl,
403 // Setup the pointers.
406 IMListAltIDPtr = IMListAltID;
407 IMListPIDPtr = IMListPID;
408 IMListTypePtr = IMListType;
409 IMListTypeInfoPtr = IMListTypeInfo;
410 IMListTokensPtr = IMListTokens;
411 IMListMediatypePtr = IMListMediatype;
412 IMListPrefPtr = IMListPref;
413 IMListCtrlPtr = IMListCtrl;
414 IMListIndex = IMIndex;